re-shape of compiler pipeline
This commit is contained in:
+3
-3
@@ -1,15 +1,15 @@
|
||||
package p.studio.compiler.models;
|
||||
|
||||
import p.studio.compiler.messages.BuildingIssue;
|
||||
import p.studio.compiler.source.tables.FileTable;
|
||||
import p.studio.compiler.source.tables.FileTableReader;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record AnalysisSnapshot(
|
||||
List<BuildingIssue> diagnostics,
|
||||
ResolvedWorkspace resolvedWorkspace,
|
||||
FileTable fileTable,
|
||||
IRBackend irBackend) {
|
||||
FileTableReader fileTable,
|
||||
IRBackendReader irBackend) {
|
||||
public AnalysisSnapshot {
|
||||
diagnostics = List.copyOf(diagnostics);
|
||||
}
|
||||
|
||||
+32
-40
@@ -3,9 +3,9 @@ package p.studio.compiler.workspaces;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import p.studio.compiler.exceptions.BuildException;
|
||||
import p.studio.compiler.messages.BuildingIssue;
|
||||
import p.studio.compiler.models.BuilderPipelineContext;
|
||||
import p.studio.compiler.models.AnalysisSnapshot;
|
||||
import p.studio.compiler.models.BuildResult;
|
||||
import p.studio.compiler.models.BuilderPipelineContext;
|
||||
import p.studio.compiler.models.CompileResult;
|
||||
import p.studio.compiler.workspaces.stages.*;
|
||||
import p.studio.utilities.logs.LogAggregator;
|
||||
@@ -19,30 +19,45 @@ public class BuilderPipelineService {
|
||||
public final static BuilderPipelineService INSTANCE;
|
||||
|
||||
static {
|
||||
final var stages = List.<PipelineStage>of(
|
||||
|
||||
final var analyses = List.<PipelineStage>of(
|
||||
new ResolveDepsPipelineStage(),
|
||||
new LoadSourcesPipelineStage(),
|
||||
new FrontendPhasePipelineStage(),
|
||||
new FrontendPhasePipelineStage()
|
||||
);
|
||||
|
||||
final var compile = List.<PipelineStage>of(
|
||||
new LowerToIRVMPipelineStage(),
|
||||
new OptimizeIRVMPipelineStage(),
|
||||
new EmitBytecodePipelineStage(),
|
||||
new LinkBytecodePipelineStage(),
|
||||
new VerifyBytecodePipelineStage(),
|
||||
new VerifyBytecodePipelineStage()
|
||||
);
|
||||
|
||||
final var build = List.<PipelineStage>of(
|
||||
new WriteBytecodeArtifactPipelineStage()
|
||||
);
|
||||
INSTANCE = new BuilderPipelineService(stages);
|
||||
|
||||
INSTANCE = new BuilderPipelineService(analyses, compile, build);
|
||||
}
|
||||
|
||||
private final List<PipelineStage> stages;
|
||||
private final List<PipelineStage> analyses;
|
||||
private final List<PipelineStage> compile;
|
||||
private final List<PipelineStage> build;
|
||||
|
||||
BuilderPipelineService(List<PipelineStage> stages) {
|
||||
this.stages = stages;
|
||||
BuilderPipelineService(
|
||||
final List<PipelineStage> analyses,
|
||||
final List<PipelineStage> compile,
|
||||
final List<PipelineStage> build) {
|
||||
this.analyses = analyses;
|
||||
this.compile = compile;
|
||||
this.build = build;
|
||||
}
|
||||
|
||||
public AnalysisSnapshot analyze(
|
||||
final BuilderPipelineContext ctx,
|
||||
final LogAggregator logs) {
|
||||
final var diagnostics = runToTerminal(ctx, logs, FrontendPhasePipelineStage.class);
|
||||
final var diagnostics = run(ctx, logs, analyses, new ArrayList<>());
|
||||
return new AnalysisSnapshot(
|
||||
diagnostics,
|
||||
ctx.resolvedWorkspace,
|
||||
@@ -53,12 +68,8 @@ public class BuilderPipelineService {
|
||||
public CompileResult compile(
|
||||
final BuilderPipelineContext ctx,
|
||||
final LogAggregator logs) {
|
||||
final var diagnostics = runToTerminal(ctx, logs, VerifyBytecodePipelineStage.class);
|
||||
final var analysisSnapshot = new AnalysisSnapshot(
|
||||
diagnostics,
|
||||
ctx.resolvedWorkspace,
|
||||
ctx.fileTable,
|
||||
ctx.irBackend);
|
||||
final var analysisSnapshot = this.analyze(ctx, logs);
|
||||
final var diagnostics = run(ctx, logs, compile, new ArrayList<>(analysisSnapshot.diagnostics()));
|
||||
return new CompileResult(
|
||||
analysisSnapshot,
|
||||
diagnostics,
|
||||
@@ -71,31 +82,19 @@ public class BuilderPipelineService {
|
||||
public BuildResult build(
|
||||
final BuilderPipelineContext ctx,
|
||||
final LogAggregator logs) {
|
||||
final var diagnostics = runToTerminal(ctx, logs, WriteBytecodeArtifactPipelineStage.class);
|
||||
final var analysisSnapshot = new AnalysisSnapshot(
|
||||
diagnostics,
|
||||
ctx.resolvedWorkspace,
|
||||
ctx.fileTable,
|
||||
ctx.irBackend);
|
||||
final var compileResult = new CompileResult(
|
||||
analysisSnapshot,
|
||||
diagnostics,
|
||||
ctx.irvm,
|
||||
ctx.optimizedIrvm,
|
||||
ctx.bytecodeModule,
|
||||
ctx.bytecodeBytes);
|
||||
final var compileResult = this.compile(ctx, logs);
|
||||
final var diagnostics = run(ctx, logs, build, new ArrayList<>(compileResult.diagnostics()));
|
||||
return new BuildResult(
|
||||
compileResult,
|
||||
diagnostics,
|
||||
ctx.bytecodeArtifactPath);
|
||||
}
|
||||
|
||||
private List<BuildingIssue> runToTerminal(
|
||||
private List<BuildingIssue> run(
|
||||
final BuilderPipelineContext ctx,
|
||||
final LogAggregator logs,
|
||||
final Class<? extends PipelineStage> terminalStage) {
|
||||
final var diagnostics = new ArrayList<BuildingIssue>();
|
||||
var completed = false;
|
||||
final List<PipelineStage> stages,
|
||||
final List<BuildingIssue> diagnostics) {
|
||||
for (final var builderPipelineStage : stages) {
|
||||
final var issues = builderPipelineStage.run(ctx, logs);
|
||||
diagnostics.addAll(issues.asCollection());
|
||||
@@ -103,15 +102,8 @@ public class BuilderPipelineService {
|
||||
if (issues.hasErrors()) {
|
||||
throw new BuildException("issues found on pipeline stage: " + builderPipelineStage.getClass().getSimpleName());
|
||||
}
|
||||
if (terminalStage.isInstance(builderPipelineStage)) {
|
||||
completed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!completed) {
|
||||
throw new BuildException("terminal stage not found on builder pipeline: " + terminalStage.getSimpleName());
|
||||
}
|
||||
logs.using(log).info("builder pipeline completed successfully through " + terminalStage.getSimpleName());
|
||||
logs.using(log).info("builder pipeline completed successfully");
|
||||
return List.copyOf(diagnostics);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user