implements PR-08.3

This commit is contained in:
2026-03-24 13:42:33 +00:00
parent 0490f64870
commit 2a68d27eca
5 changed files with 118 additions and 5 deletions
@@ -23,6 +23,8 @@ public class IRBackend {
@Builder.Default
private final String entryPointCallableName = "main";
@Builder.Default
private final ModuleId entryPointModuleId = ModuleId.none();
@Builder.Default
private final ReadOnlyList<IRFunction> functions = ReadOnlyList.empty();
@Builder.Default
private final ReadOnlyList<IRBackendExecutableFunction> executableFunctions = ReadOnlyList.empty();
@@ -41,6 +43,7 @@ public class IRBackend {
public static final class IRBackendAggregator {
private String entryPointCallableName;
private ModuleId entryPointModuleId = ModuleId.none();
private final ArrayList<IRFunction> functions = new ArrayList<>();
private final ArrayList<IRBackendExecutableFunction> executableFunctions = new ArrayList<>();
private final ModuleTable moduleTable = new ModuleTable();
@@ -76,6 +79,13 @@ public class IRBackend {
return this;
}
public IRBackendAggregator entryPointModuleId(final ModuleId moduleId) {
if (moduleId != null) {
entryPointModuleId = moduleId;
}
return this;
}
private ModuleId[] reindexModules(final ReadOnlyList<ModuleReference> localModulePool) {
if (localModulePool == null || localModulePool.isEmpty()) {
return new ModuleId[0];
@@ -273,6 +283,7 @@ public class IRBackend {
return IRBackend
.builder()
.entryPointCallableName(resolveEntryPointCallableName())
.entryPointModuleId(resolveEntryPointModuleId())
.functions(ReadOnlyList.wrap(functions))
.executableFunctions(ReadOnlyList.wrap(executableFunctions))
.modulePool(emitModulePool())
@@ -291,12 +302,18 @@ public class IRBackend {
? "main"
: entryPointCallableName;
}
private ModuleId resolveEntryPointModuleId() {
return entryPointModuleId == null ? ModuleId.none() : entryPointModuleId;
}
}
@Override
public String toString() {
final var sb = new StringBuilder();
sb.append("IRBackend{entrypoint=").append(entryPointCallableName)
.append('@')
.append(entryPointModuleId == null || entryPointModuleId.isNone() ? "-" : entryPointModuleId.getIndex())
.append(", functions=").append(functions.size())
.append(", executableFunctions=").append(executableFunctions.size())
.append(", modulePool=").append(modulePool.size())