added frontend compile phase
This commit is contained in:
parent
31c59f670e
commit
c7c6c8bef5
@ -5,5 +5,6 @@ plugins {
|
||||
dependencies {
|
||||
implementation(project(":prometeu-infra"))
|
||||
|
||||
implementation(project(":prometeu-compiler:prometeu-frontend-api"))
|
||||
implementation(project(":prometeu-compiler:prometeu-compiler-core"))
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
package p.studio.compiler.services;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import p.studio.compiler.messages.BuildingIssueSink;
|
||||
import p.studio.compiler.messages.FrontendPhaseContext;
|
||||
import p.studio.compiler.models.IRBackend;
|
||||
import p.studio.utilities.logs.LogAggregator;
|
||||
|
||||
@Slf4j
|
||||
public class PBSFrontendPhaseService implements FrontendPhaseService {
|
||||
@Override
|
||||
public IRBackend compile(final FrontendPhaseContext ctx, final LogAggregator logs, final BuildingIssueSink issues) {
|
||||
for (final var pId : ctx.stack.reverseTopologicalOrder) {
|
||||
for (final var fId : ctx.fileTable.getFiles(pId)) {
|
||||
final var sourceHandle = ctx.fileTable.get(fId);
|
||||
sourceHandle.readUtf8().ifPresentOrElse(
|
||||
utf8Content -> logs.using(log).info("File content: %s".formatted(utf8Content)),
|
||||
() -> issues.report(builder -> builder
|
||||
.error(true)
|
||||
.message("Failed to read file content: %s".formatted(sourceHandle.toString()))));
|
||||
}
|
||||
}
|
||||
return new IRBackend();
|
||||
}
|
||||
}
|
||||
@ -6,4 +6,6 @@ dependencies {
|
||||
api(project(":prometeu-infra"))
|
||||
implementation(project(":prometeu-compiler:prometeu-deps"))
|
||||
implementation(project(":prometeu-compiler:prometeu-compiler-core"))
|
||||
implementation(project(":prometeu-compiler:prometeu-frontend-api"))
|
||||
implementation(project(":prometeu-compiler:prometeu-frontend-registry"))
|
||||
}
|
||||
@ -14,6 +14,7 @@ public class BuilderPipelineContext {
|
||||
public ResolvedWorkspace resolvedWorkspace;
|
||||
|
||||
public FileTable fileTable;
|
||||
public IRBackend irBackend;
|
||||
|
||||
private BuilderPipelineContext(
|
||||
final BuilderPipelineConfig config,
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
package p.studio.compiler.workspaces.stages;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import p.studio.compiler.FrontendRegistryService;
|
||||
import p.studio.compiler.messages.BuildingIssueSink;
|
||||
import p.studio.compiler.messages.FrontendPhaseContext;
|
||||
import p.studio.compiler.models.BuilderPipelineContext;
|
||||
import p.studio.compiler.workspaces.PipelineStage;
|
||||
import p.studio.utilities.logs.LogAggregator;
|
||||
@ -9,7 +11,20 @@ import p.studio.utilities.logs.LogAggregator;
|
||||
@Slf4j
|
||||
public class FrontendPhasePipelineStage implements PipelineStage {
|
||||
@Override
|
||||
public BuildingIssueSink run(BuilderPipelineContext ctx, LogAggregator logs) {
|
||||
return BuildingIssueSink.empty();
|
||||
public BuildingIssueSink run(final BuilderPipelineContext ctx, final LogAggregator logs) {
|
||||
final var frontedSpec = ctx.resolvedWorkspace.frontendSpec();
|
||||
final var service = FrontendRegistryService.getFrontendPhaseService(frontedSpec.getLanguageId());
|
||||
if (service.isEmpty()) {
|
||||
return BuildingIssueSink.empty()
|
||||
.report(builder -> builder
|
||||
.error(true)
|
||||
.message("[BUILD]: unable to find a service for frontend phase: " + frontedSpec.getLanguageId()));
|
||||
}
|
||||
final var projectTable = ctx.resolvedWorkspace.graph().projectTable();
|
||||
final var fileTable = ctx.fileTable;
|
||||
final var frontendPhaseContext = new FrontendPhaseContext(projectTable, fileTable, ctx.resolvedWorkspace.stack());
|
||||
final var issues = BuildingIssueSink.empty();
|
||||
ctx.irBackend = service.get().compile(frontendPhaseContext, logs, issues);
|
||||
return issues;
|
||||
}
|
||||
}
|
||||
|
||||
@ -82,7 +82,6 @@ public class LoadSourcesPipelineStage implements PipelineStage {
|
||||
// register in dense tables
|
||||
final var relativePath = pd.getRootPath().relativize(canonPath);
|
||||
final var sourceHandle = new SourceHandle(pId, relativePath, canonPath, size, lastModified, ctx.sourceProviderFactory);
|
||||
logs.using(log).debug("Registering: " + sourceHandle);
|
||||
ctx.fileTable.register(sourceHandle);
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,6 +12,7 @@ import java.nio.file.Path;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Optional;
|
||||
|
||||
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
|
||||
public class SourceHandle {
|
||||
@ -46,12 +47,16 @@ public class SourceHandle {
|
||||
this.provider = factory.create(canonPath);
|
||||
}
|
||||
|
||||
public byte[] readBytes() throws IOException {
|
||||
return provider.read();
|
||||
public Optional<byte[]> readBytes() {
|
||||
try {
|
||||
return Optional.ofNullable(provider.read());
|
||||
} catch (IOException e) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
public String readUtf8() throws IOException {
|
||||
return new String(readBytes(), StandardCharsets.UTF_8);
|
||||
public Optional<String> readUtf8() {
|
||||
return readBytes().map(bytes -> new String(bytes, StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -0,0 +1,20 @@
|
||||
package p.studio.compiler.messages;
|
||||
|
||||
import p.studio.compiler.models.BuildStack;
|
||||
import p.studio.compiler.source.tables.FileTableReader;
|
||||
import p.studio.compiler.source.tables.ProjectTableReader;
|
||||
|
||||
public class FrontendPhaseContext {
|
||||
public final ProjectTableReader projectTable;
|
||||
public final FileTableReader fileTable;
|
||||
public final BuildStack stack;
|
||||
|
||||
public FrontendPhaseContext(
|
||||
final ProjectTableReader projectTable,
|
||||
final FileTableReader fileTable,
|
||||
final BuildStack stack) {
|
||||
this.projectTable = projectTable;
|
||||
this.fileTable = fileTable;
|
||||
this.stack = stack;
|
||||
}
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
package p.studio.compiler.messages;
|
||||
|
||||
import p.studio.compiler.source.tables.FileTableReader;
|
||||
import p.studio.compiler.source.tables.ProjectTableReader;
|
||||
|
||||
public record FrontendPhaseRequest(
|
||||
ProjectTableReader projectTable,
|
||||
FileTableReader fileTable) {
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
package p.studio.compiler.models;
|
||||
|
||||
public class IRBackend {
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
package p.studio.compiler.services;
|
||||
|
||||
import p.studio.compiler.messages.BuildingIssueSink;
|
||||
import p.studio.compiler.messages.FrontendPhaseContext;
|
||||
import p.studio.compiler.models.IRBackend;
|
||||
import p.studio.utilities.logs.LogAggregator;
|
||||
|
||||
public interface FrontendPhaseService {
|
||||
IRBackend compile(FrontendPhaseContext request, LogAggregator logs, BuildingIssueSink empty);
|
||||
}
|
||||
@ -6,5 +6,7 @@ dependencies {
|
||||
implementation(project(":prometeu-infra"))
|
||||
implementation(project(":prometeu-compiler:prometeu-compiler-core"))
|
||||
|
||||
implementation(project(":prometeu-compiler:prometeu-frontend-api"))
|
||||
|
||||
implementation(project(":prometeu-compiler:frontends:prometeu-frontend-pbs"))
|
||||
}
|
||||
@ -1,31 +1,31 @@
|
||||
package p.studio.compiler;
|
||||
|
||||
import p.studio.compiler.models.FrontendSpec;
|
||||
import p.studio.compiler.services.FrontendPhaseService;
|
||||
import p.studio.compiler.services.PBSFrontendPhaseService;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class FrontendRegistryService {
|
||||
private static final FrontendSpec[] FRONTEND_SPECS = {
|
||||
PBSDefinitions.PBS,
|
||||
};
|
||||
|
||||
private static final Map<String, FrontendSpec> FRONTENDS = new HashMap<>();
|
||||
private static final Map<String, FrontendSpec> FRONTEND_SPECS = new HashMap<>();
|
||||
private static final Map<String, FrontendPhaseService> FRONTEND_PHASE_SERVICES = new HashMap<>();
|
||||
|
||||
static {
|
||||
for (final var frontendSpec : FRONTEND_SPECS) {
|
||||
FRONTENDS.put(frontendSpec.getLanguageId(), frontendSpec);
|
||||
}
|
||||
if (FRONTENDS.size() != FRONTEND_SPECS.length)
|
||||
throw new IllegalStateException("Duplicate frontend specs found");
|
||||
FRONTEND_SPECS.put(PBSDefinitions.PBS.getLanguageId(), PBSDefinitions.PBS);
|
||||
FRONTEND_PHASE_SERVICES.put(PBSDefinitions.PBS.getLanguageId(), new PBSFrontendPhaseService());
|
||||
}
|
||||
|
||||
public static FrontendSpec getDefaultFrontendSpec() {
|
||||
return FRONTENDS.get(PBSDefinitions.PBS.getLanguageId());
|
||||
return FRONTEND_SPECS.get(PBSDefinitions.PBS.getLanguageId());
|
||||
}
|
||||
|
||||
public static Optional<FrontendSpec> getFrontendSpec(final String languageId) {
|
||||
return Optional.ofNullable(FRONTENDS.get(languageId));
|
||||
return Optional.ofNullable(FRONTEND_SPECS.get(languageId));
|
||||
}
|
||||
|
||||
public static Optional<FrontendPhaseService> getFrontendPhaseService(final String languageId) {
|
||||
return Optional.ofNullable(FRONTEND_PHASE_SERVICES.get(languageId));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
module-a.barrel: content
|
||||
@ -0,0 +1 @@
|
||||
source-1.pbs content
|
||||
@ -0,0 +1 @@
|
||||
source-2.pbs content
|
||||
@ -0,0 +1 @@
|
||||
source-3.pbs content
|
||||
Loading…
x
Reference in New Issue
Block a user