implements PR-05.0.3
This commit is contained in:
parent
bafab68eac
commit
0149b85e7d
@ -15,7 +15,9 @@ import p.studio.compiler.pbs.semantics.PbsFlowSemanticsValidator;
|
|||||||
import p.studio.compiler.pbs.semantics.PbsSemanticsErrors;
|
import p.studio.compiler.pbs.semantics.PbsSemanticsErrors;
|
||||||
import p.studio.compiler.source.diagnostics.DiagnosticSink;
|
import p.studio.compiler.source.diagnostics.DiagnosticSink;
|
||||||
import p.studio.compiler.source.diagnostics.DiagnosticPhase;
|
import p.studio.compiler.source.diagnostics.DiagnosticPhase;
|
||||||
|
import p.studio.compiler.source.identifiers.CallableId;
|
||||||
import p.studio.compiler.source.identifiers.FileId;
|
import p.studio.compiler.source.identifiers.FileId;
|
||||||
|
import p.studio.compiler.source.identifiers.IntrinsicId;
|
||||||
import p.studio.compiler.source.tables.CallableSignatureRef;
|
import p.studio.compiler.source.tables.CallableSignatureRef;
|
||||||
import p.studio.compiler.source.tables.CallableTable;
|
import p.studio.compiler.source.tables.CallableTable;
|
||||||
import p.studio.compiler.source.tables.IntrinsicReference;
|
import p.studio.compiler.source.tables.IntrinsicReference;
|
||||||
@ -186,17 +188,16 @@ public final class PbsFrontendCompiler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
final var callableIdTable = new CallableTable();
|
final var callableIdTable = new CallableTable();
|
||||||
final var callableIdsByNameAndArity = new HashMap<String, List<Integer>>();
|
final var callableIdsByNameAndArity = new HashMap<String, List<CallableId>>();
|
||||||
final var callableIdByDeclaration = new HashMap<PbsAst.FunctionDecl, Integer>();
|
final var callableIdByDeclaration = new HashMap<PbsAst.FunctionDecl, CallableId>();
|
||||||
final var returnSlotsByCallableId = new HashMap<Integer, Integer>();
|
final var returnSlotsByCallableId = new HashMap<CallableId, Integer>();
|
||||||
final var intrinsicIdTable = new IntrinsicTable();
|
final var intrinsicIdTable = new IntrinsicTable();
|
||||||
for (final var declaredFn : ast.functions()) {
|
for (final var declaredFn : ast.functions()) {
|
||||||
final var callableId = callableIdTable.register(
|
final var callableId = callableIdTable.register(
|
||||||
normalizedModuleKey,
|
normalizedModuleKey,
|
||||||
declaredFn.name(),
|
declaredFn.name(),
|
||||||
declaredFn.parameters().size(),
|
declaredFn.parameters().size(),
|
||||||
callableShapeKey(declaredFn))
|
callableShapeKey(declaredFn));
|
||||||
.getId();
|
|
||||||
callableIdByDeclaration.put(declaredFn, callableId);
|
callableIdByDeclaration.put(declaredFn, callableId);
|
||||||
callableIdsByNameAndArity
|
callableIdsByNameAndArity
|
||||||
.computeIfAbsent(callableArityKey(declaredFn.name(), declaredFn.parameters().size()), ignored -> new ArrayList<>())
|
.computeIfAbsent(callableArityKey(declaredFn.name(), declaredFn.parameters().size()), ignored -> new ArrayList<>())
|
||||||
@ -255,7 +256,7 @@ public final class PbsFrontendCompiler {
|
|||||||
intrinsic.canonicalVersion(),
|
intrinsic.canonicalVersion(),
|
||||||
intrinsicIdTable
|
intrinsicIdTable
|
||||||
.register(intrinsic.canonicalName(), intrinsic.canonicalVersion())
|
.register(intrinsic.canonicalName(), intrinsic.canonicalVersion())
|
||||||
.getId()),
|
),
|
||||||
callExpr.span()));
|
callExpr.span()));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -65,15 +65,15 @@ class PbsGoldenArtifactsTest {
|
|||||||
.append("::")
|
.append("::")
|
||||||
.append(fn.callableName())
|
.append(fn.callableName())
|
||||||
.append(" id=")
|
.append(" id=")
|
||||||
.append(fn.callableId())
|
.append(fn.callableId().getId())
|
||||||
.append('\n');
|
.append('\n');
|
||||||
for (final var instruction : fn.instructions()) {
|
for (final var instruction : fn.instructions()) {
|
||||||
out.append(" ")
|
out.append(" ")
|
||||||
.append(instruction.kind())
|
.append(instruction.kind())
|
||||||
.append(" calleeId=")
|
.append(" calleeId=")
|
||||||
.append(instruction.calleeCallableId() == null ? "-" : instruction.calleeCallableId())
|
.append(instruction.calleeCallableId() == null ? "-" : instruction.calleeCallableId().getId())
|
||||||
.append(" intrinsicId=")
|
.append(" intrinsicId=")
|
||||||
.append(instruction.intrinsicCall() == null ? "-" : instruction.intrinsicCall().intrinsicId())
|
.append(instruction.intrinsicCall() == null ? "-" : instruction.intrinsicCall().intrinsicId().getId())
|
||||||
.append('\n');
|
.append('\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import p.studio.compiler.backend.bytecode.BytecodeModule;
|
|||||||
import p.studio.compiler.models.IRBackend;
|
import p.studio.compiler.models.IRBackend;
|
||||||
import p.studio.compiler.models.IRBackendExecutableFunction;
|
import p.studio.compiler.models.IRBackendExecutableFunction;
|
||||||
import p.studio.compiler.source.Span;
|
import p.studio.compiler.source.Span;
|
||||||
|
import p.studio.compiler.source.identifiers.CallableId;
|
||||||
import p.studio.utilities.structures.ReadOnlyList;
|
import p.studio.utilities.structures.ReadOnlyList;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -15,7 +16,7 @@ public class LowerToIRVMService {
|
|||||||
private static final Comparator<IRBackendExecutableFunction> FUNCTION_ORDER = Comparator
|
private static final Comparator<IRBackendExecutableFunction> FUNCTION_ORDER = Comparator
|
||||||
.comparing(IRBackendExecutableFunction::moduleKey)
|
.comparing(IRBackendExecutableFunction::moduleKey)
|
||||||
.thenComparing(IRBackendExecutableFunction::callableName)
|
.thenComparing(IRBackendExecutableFunction::callableName)
|
||||||
.thenComparingInt(IRBackendExecutableFunction::callableId)
|
.thenComparingInt(function -> function.callableId().getIndex())
|
||||||
.thenComparingInt(IRBackendExecutableFunction::sourceStart);
|
.thenComparingInt(IRBackendExecutableFunction::sourceStart);
|
||||||
|
|
||||||
private final IRVMValidator validator;
|
private final IRVMValidator validator;
|
||||||
@ -42,7 +43,7 @@ public class LowerToIRVMService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final var ordered = orderFunctions(backend.getExecutableFunctions());
|
final var ordered = orderFunctions(backend.getExecutableFunctions());
|
||||||
final var funcIdByCallableId = new HashMap<Integer, Integer>();
|
final var funcIdByCallableId = new HashMap<CallableId, Integer>();
|
||||||
for (var i = 0; i < ordered.size(); i++) {
|
for (var i = 0; i < ordered.size(); i++) {
|
||||||
final var fn = ordered.get(i);
|
final var fn = ordered.get(i);
|
||||||
if (funcIdByCallableId.putIfAbsent(fn.callableId(), i) != null) {
|
if (funcIdByCallableId.putIfAbsent(fn.callableId(), i) != null) {
|
||||||
@ -127,13 +128,14 @@ public class LowerToIRVMService {
|
|||||||
}
|
}
|
||||||
case CALL_INTRINSIC -> {
|
case CALL_INTRINSIC -> {
|
||||||
final var intrinsic = instr.intrinsicCall();
|
final var intrinsic = instr.intrinsicCall();
|
||||||
if (intrinsic.intrinsicId() < 0 || intrinsic.intrinsicId() >= backend.getIntrinsicPool().size()) {
|
final var intrinsicIndex = intrinsic.intrinsicId().getIndex();
|
||||||
|
if (intrinsicIndex < 0 || intrinsicIndex >= backend.getIntrinsicPool().size()) {
|
||||||
throw new IRVMLoweringException(
|
throw new IRVMLoweringException(
|
||||||
IRVMLoweringErrorCode.LOWER_IRVM_INVALID_INTRINSIC_ID,
|
IRVMLoweringErrorCode.LOWER_IRVM_INVALID_INTRINSIC_ID,
|
||||||
"invalid intrinsic id: " + intrinsic.intrinsicId());
|
"invalid intrinsic id: " + intrinsic.intrinsicId());
|
||||||
}
|
}
|
||||||
instructions.add(new IRVMInstruction(IRVMOp.INTRINSIC, intrinsic.intrinsicId()));
|
instructions.add(new IRVMInstruction(IRVMOp.INTRINSIC, intrinsicIndex));
|
||||||
operations.add(BytecodeEmitter.Operation.intrinsic(intrinsic.intrinsicId(), sourceSpan));
|
operations.add(BytecodeEmitter.Operation.intrinsic(intrinsicIndex, sourceSpan));
|
||||||
functionPc += IRVMOp.INTRINSIC.immediateSize() + 2;
|
functionPc += IRVMOp.INTRINSIC.immediateSize() + 2;
|
||||||
}
|
}
|
||||||
case LABEL -> {
|
case LABEL -> {
|
||||||
|
|||||||
@ -6,7 +6,9 @@ import p.studio.compiler.backend.irvm.LowerToIRVMService;
|
|||||||
import p.studio.compiler.models.IRBackend;
|
import p.studio.compiler.models.IRBackend;
|
||||||
import p.studio.compiler.models.IRBackendExecutableFunction;
|
import p.studio.compiler.models.IRBackendExecutableFunction;
|
||||||
import p.studio.compiler.source.Span;
|
import p.studio.compiler.source.Span;
|
||||||
|
import p.studio.compiler.source.identifiers.CallableId;
|
||||||
import p.studio.compiler.source.identifiers.FileId;
|
import p.studio.compiler.source.identifiers.FileId;
|
||||||
|
import p.studio.compiler.source.identifiers.IntrinsicId;
|
||||||
import p.studio.compiler.source.tables.IntrinsicReference;
|
import p.studio.compiler.source.tables.IntrinsicReference;
|
||||||
import p.studio.utilities.structures.ReadOnlyList;
|
import p.studio.utilities.structures.ReadOnlyList;
|
||||||
|
|
||||||
@ -45,7 +47,7 @@ class GoldenArtifactsTest {
|
|||||||
new FileId(1),
|
new FileId(1),
|
||||||
"app/main",
|
"app/main",
|
||||||
"main",
|
"main",
|
||||||
0,
|
new CallableId(0),
|
||||||
0,
|
0,
|
||||||
20,
|
20,
|
||||||
0,
|
0,
|
||||||
@ -66,7 +68,7 @@ class GoldenArtifactsTest {
|
|||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
null,
|
null,
|
||||||
new IRBackendExecutableFunction.IntrinsicCallMetadata("core.color.pack", 1, 0),
|
new IRBackendExecutableFunction.IntrinsicCallMetadata("core.color.pack", 1, new IntrinsicId(0)),
|
||||||
Span.none()),
|
Span.none()),
|
||||||
new IRBackendExecutableFunction.Instruction(
|
new IRBackendExecutableFunction.Instruction(
|
||||||
IRBackendExecutableFunction.InstructionKind.RET,
|
IRBackendExecutableFunction.InstructionKind.RET,
|
||||||
|
|||||||
@ -4,7 +4,9 @@ import org.junit.jupiter.api.Test;
|
|||||||
import p.studio.compiler.models.IRBackend;
|
import p.studio.compiler.models.IRBackend;
|
||||||
import p.studio.compiler.models.IRBackendExecutableFunction;
|
import p.studio.compiler.models.IRBackendExecutableFunction;
|
||||||
import p.studio.compiler.source.Span;
|
import p.studio.compiler.source.Span;
|
||||||
|
import p.studio.compiler.source.identifiers.CallableId;
|
||||||
import p.studio.compiler.source.identifiers.FileId;
|
import p.studio.compiler.source.identifiers.FileId;
|
||||||
|
import p.studio.compiler.source.identifiers.IntrinsicId;
|
||||||
import p.studio.compiler.source.tables.IntrinsicReference;
|
import p.studio.compiler.source.tables.IntrinsicReference;
|
||||||
import p.studio.utilities.structures.ReadOnlyList;
|
import p.studio.utilities.structures.ReadOnlyList;
|
||||||
|
|
||||||
@ -137,7 +139,7 @@ class LowerToIRVMServiceTest {
|
|||||||
new FileId(0),
|
new FileId(0),
|
||||||
moduleKey,
|
moduleKey,
|
||||||
name,
|
name,
|
||||||
callableId,
|
new CallableId(callableId),
|
||||||
0,
|
0,
|
||||||
10,
|
10,
|
||||||
0,
|
0,
|
||||||
@ -166,7 +168,7 @@ class LowerToIRVMServiceTest {
|
|||||||
IRBackendExecutableFunction.InstructionKind.CALL_FUNC,
|
IRBackendExecutableFunction.InstructionKind.CALL_FUNC,
|
||||||
moduleKey,
|
moduleKey,
|
||||||
name,
|
name,
|
||||||
calleeCallableId,
|
new CallableId(calleeCallableId),
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
Span.none());
|
Span.none());
|
||||||
@ -182,7 +184,7 @@ class LowerToIRVMServiceTest {
|
|||||||
IRBackendExecutableFunction.InstructionKind.CALL_FUNC,
|
IRBackendExecutableFunction.InstructionKind.CALL_FUNC,
|
||||||
moduleKey,
|
moduleKey,
|
||||||
name,
|
name,
|
||||||
calleeCallableId,
|
new CallableId(calleeCallableId),
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
expectedArgSlots,
|
expectedArgSlots,
|
||||||
@ -214,7 +216,7 @@ class LowerToIRVMServiceTest {
|
|||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
null,
|
null,
|
||||||
new IRBackendExecutableFunction.IntrinsicCallMetadata(canonicalName, canonicalVersion, intrinsicId),
|
new IRBackendExecutableFunction.IntrinsicCallMetadata(canonicalName, canonicalVersion, new IntrinsicId(intrinsicId)),
|
||||||
Span.none());
|
Span.none());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -10,7 +10,9 @@ import p.studio.compiler.models.BuilderPipelineContext;
|
|||||||
import p.studio.compiler.models.IRBackend;
|
import p.studio.compiler.models.IRBackend;
|
||||||
import p.studio.compiler.models.IRBackendExecutableFunction;
|
import p.studio.compiler.models.IRBackendExecutableFunction;
|
||||||
import p.studio.compiler.source.Span;
|
import p.studio.compiler.source.Span;
|
||||||
|
import p.studio.compiler.source.identifiers.CallableId;
|
||||||
import p.studio.compiler.source.identifiers.FileId;
|
import p.studio.compiler.source.identifiers.FileId;
|
||||||
|
import p.studio.compiler.source.identifiers.IntrinsicId;
|
||||||
import p.studio.compiler.source.tables.IntrinsicReference;
|
import p.studio.compiler.source.tables.IntrinsicReference;
|
||||||
import p.studio.compiler.workspaces.stages.EmitBytecodePipelineStage;
|
import p.studio.compiler.workspaces.stages.EmitBytecodePipelineStage;
|
||||||
import p.studio.compiler.workspaces.stages.LowerToIRVMPipelineStage;
|
import p.studio.compiler.workspaces.stages.LowerToIRVMPipelineStage;
|
||||||
@ -188,7 +190,7 @@ class BackendGateIIntegrationTest {
|
|||||||
new FileId(1),
|
new FileId(1),
|
||||||
"app/main",
|
"app/main",
|
||||||
name,
|
name,
|
||||||
1,
|
new CallableId(1),
|
||||||
0,
|
0,
|
||||||
10,
|
10,
|
||||||
0,
|
0,
|
||||||
@ -233,7 +235,7 @@ class BackendGateIIntegrationTest {
|
|||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
null,
|
null,
|
||||||
new IRBackendExecutableFunction.IntrinsicCallMetadata(canonicalName, canonicalVersion, intrinsicId),
|
new IRBackendExecutableFunction.IntrinsicCallMetadata(canonicalName, canonicalVersion, new IntrinsicId(intrinsicId)),
|
||||||
Span.none());
|
Span.none());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import p.studio.compiler.models.BuilderPipelineContext;
|
|||||||
import p.studio.compiler.models.IRBackend;
|
import p.studio.compiler.models.IRBackend;
|
||||||
import p.studio.compiler.models.IRBackendExecutableFunction;
|
import p.studio.compiler.models.IRBackendExecutableFunction;
|
||||||
import p.studio.compiler.source.Span;
|
import p.studio.compiler.source.Span;
|
||||||
|
import p.studio.compiler.source.identifiers.CallableId;
|
||||||
import p.studio.compiler.source.identifiers.FileId;
|
import p.studio.compiler.source.identifiers.FileId;
|
||||||
import p.studio.utilities.logs.LogAggregator;
|
import p.studio.utilities.logs.LogAggregator;
|
||||||
import p.studio.utilities.structures.ReadOnlyList;
|
import p.studio.utilities.structures.ReadOnlyList;
|
||||||
@ -29,7 +30,7 @@ class BackendSafetyGateSUTest {
|
|||||||
new FileId(1),
|
new FileId(1),
|
||||||
"app",
|
"app",
|
||||||
"main",
|
"main",
|
||||||
1,
|
new CallableId(1),
|
||||||
0,
|
0,
|
||||||
10,
|
10,
|
||||||
0,
|
0,
|
||||||
@ -41,7 +42,7 @@ class BackendSafetyGateSUTest {
|
|||||||
IRBackendExecutableFunction.InstructionKind.CALL_FUNC,
|
IRBackendExecutableFunction.InstructionKind.CALL_FUNC,
|
||||||
"app",
|
"app",
|
||||||
"missing",
|
"missing",
|
||||||
99,
|
new CallableId(99),
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
0,
|
0,
|
||||||
@ -114,7 +115,7 @@ class BackendSafetyGateSUTest {
|
|||||||
new FileId(1),
|
new FileId(1),
|
||||||
"app",
|
"app",
|
||||||
"main",
|
"main",
|
||||||
1,
|
new CallableId(1),
|
||||||
0,
|
0,
|
||||||
10,
|
10,
|
||||||
0,
|
0,
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import p.studio.compiler.models.BuilderPipelineContext;
|
|||||||
import p.studio.compiler.models.IRBackend;
|
import p.studio.compiler.models.IRBackend;
|
||||||
import p.studio.compiler.models.IRBackendExecutableFunction;
|
import p.studio.compiler.models.IRBackendExecutableFunction;
|
||||||
import p.studio.compiler.source.Span;
|
import p.studio.compiler.source.Span;
|
||||||
|
import p.studio.compiler.source.identifiers.CallableId;
|
||||||
import p.studio.compiler.source.identifiers.FileId;
|
import p.studio.compiler.source.identifiers.FileId;
|
||||||
import p.studio.utilities.logs.LogAggregator;
|
import p.studio.utilities.logs.LogAggregator;
|
||||||
import p.studio.utilities.structures.ReadOnlyList;
|
import p.studio.utilities.structures.ReadOnlyList;
|
||||||
@ -39,7 +40,7 @@ class LowerToIRVMPipelineStageTest {
|
|||||||
new FileId(0),
|
new FileId(0),
|
||||||
"app",
|
"app",
|
||||||
"main",
|
"main",
|
||||||
1,
|
new CallableId(1),
|
||||||
0,
|
0,
|
||||||
10,
|
10,
|
||||||
0,
|
0,
|
||||||
@ -72,7 +73,7 @@ class LowerToIRVMPipelineStageTest {
|
|||||||
new FileId(0),
|
new FileId(0),
|
||||||
"app",
|
"app",
|
||||||
"main",
|
"main",
|
||||||
1,
|
new CallableId(1),
|
||||||
0,
|
0,
|
||||||
10,
|
10,
|
||||||
0,
|
0,
|
||||||
|
|||||||
@ -10,4 +10,8 @@ public class CallableId extends SourceIdentifier {
|
|||||||
public static CallableId none() {
|
public static CallableId none() {
|
||||||
return NONE;
|
return NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isNone() {
|
||||||
|
return this == NONE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,8 @@ package p.studio.compiler.models;
|
|||||||
|
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import p.studio.compiler.source.identifiers.CallableId;
|
||||||
|
import p.studio.compiler.source.identifiers.IntrinsicId;
|
||||||
import p.studio.compiler.source.tables.CallableSignatureRef;
|
import p.studio.compiler.source.tables.CallableSignatureRef;
|
||||||
import p.studio.compiler.source.tables.CallableTable;
|
import p.studio.compiler.source.tables.CallableTable;
|
||||||
import p.studio.compiler.source.tables.IntrinsicReference;
|
import p.studio.compiler.source.tables.IntrinsicReference;
|
||||||
@ -56,24 +58,24 @@ public class IRBackend {
|
|||||||
requiredCapabilities.addAll(metadata.requiredCapabilities().asList());
|
requiredCapabilities.addAll(metadata.requiredCapabilities().asList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private int[] reindexCallables(final ReadOnlyList<CallableSignatureRef> localCallableSignatures) {
|
private CallableId[] reindexCallables(final ReadOnlyList<CallableSignatureRef> localCallableSignatures) {
|
||||||
if (localCallableSignatures == null || localCallableSignatures.isEmpty()) {
|
if (localCallableSignatures == null || localCallableSignatures.isEmpty()) {
|
||||||
return new int[0];
|
return new CallableId[0];
|
||||||
}
|
}
|
||||||
final var remap = new int[localCallableSignatures.size()];
|
final var remap = new CallableId[localCallableSignatures.size()];
|
||||||
for (var i = 0; i < localCallableSignatures.size(); i++) {
|
for (var i = 0; i < localCallableSignatures.size(); i++) {
|
||||||
remap[i] = callableTable.register(localCallableSignatures.get(i)).getId();
|
remap[i] = callableTable.register(localCallableSignatures.get(i));
|
||||||
}
|
}
|
||||||
return remap;
|
return remap;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IRBackendExecutableFunction remapExecutableFunction(
|
private IRBackendExecutableFunction remapExecutableFunction(
|
||||||
final IRBackendExecutableFunction function,
|
final IRBackendExecutableFunction function,
|
||||||
final int[] callableRemap,
|
final CallableId[] callableRemap,
|
||||||
final int[] intrinsicRemap) {
|
final IntrinsicId[] intrinsicRemap) {
|
||||||
final var remappedInstructions = new ArrayList<IRBackendExecutableFunction.Instruction>(function.instructions().size());
|
final var remappedInstructions = new ArrayList<IRBackendExecutableFunction.Instruction>(function.instructions().size());
|
||||||
for (final var instruction : function.instructions()) {
|
for (final var instruction : function.instructions()) {
|
||||||
final Integer remappedCallee;
|
final CallableId remappedCallee;
|
||||||
if (instruction.calleeCallableId() == null) {
|
if (instruction.calleeCallableId() == null) {
|
||||||
remappedCallee = null;
|
remappedCallee = null;
|
||||||
} else {
|
} else {
|
||||||
@ -117,34 +119,36 @@ public class IRBackend {
|
|||||||
function.span());
|
function.span());
|
||||||
}
|
}
|
||||||
|
|
||||||
private int remapCallableId(
|
private CallableId remapCallableId(
|
||||||
final int localCallableId,
|
final CallableId localCallableId,
|
||||||
final int[] callableRemap,
|
final CallableId[] callableRemap,
|
||||||
final String label) {
|
final String label) {
|
||||||
if (localCallableId < 0 || localCallableId >= callableRemap.length) {
|
final var localIndex = localCallableId.getIndex();
|
||||||
|
if (localIndex < 0 || localIndex >= callableRemap.length) {
|
||||||
throw new IllegalArgumentException("invalid local " + label + " callable id: " + localCallableId);
|
throw new IllegalArgumentException("invalid local " + label + " callable id: " + localCallableId);
|
||||||
}
|
}
|
||||||
return callableRemap[localCallableId];
|
return callableRemap[localIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
private int[] reindexIntrinsics(final ReadOnlyList<IntrinsicReference> localIntrinsicPool) {
|
private IntrinsicId[] reindexIntrinsics(final ReadOnlyList<IntrinsicReference> localIntrinsicPool) {
|
||||||
if (localIntrinsicPool == null || localIntrinsicPool.isEmpty()) {
|
if (localIntrinsicPool == null || localIntrinsicPool.isEmpty()) {
|
||||||
return new int[0];
|
return new IntrinsicId[0];
|
||||||
}
|
}
|
||||||
final var remap = new int[localIntrinsicPool.size()];
|
final var remap = new IntrinsicId[localIntrinsicPool.size()];
|
||||||
for (var i = 0; i < localIntrinsicPool.size(); i++) {
|
for (var i = 0; i < localIntrinsicPool.size(); i++) {
|
||||||
remap[i] = intrinsicTable.register(localIntrinsicPool.get(i)).getId();
|
remap[i] = intrinsicTable.register(localIntrinsicPool.get(i));
|
||||||
}
|
}
|
||||||
return remap;
|
return remap;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int remapIntrinsicId(
|
private IntrinsicId remapIntrinsicId(
|
||||||
final int localIntrinsicId,
|
final IntrinsicId localIntrinsicId,
|
||||||
final int[] intrinsicRemap) {
|
final IntrinsicId[] intrinsicRemap) {
|
||||||
if (localIntrinsicId < 0 || localIntrinsicId >= intrinsicRemap.length) {
|
final var localIndex = localIntrinsicId.getIndex();
|
||||||
|
if (localIndex < 0 || localIndex >= intrinsicRemap.length) {
|
||||||
throw new IllegalArgumentException("invalid local intrinsic id: " + localIntrinsicId);
|
throw new IllegalArgumentException("invalid local intrinsic id: " + localIntrinsicId);
|
||||||
}
|
}
|
||||||
return intrinsicRemap[localIntrinsicId];
|
return intrinsicRemap[localIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
private ReadOnlyList<CallableSignatureRef> emitCallableSignatures() {
|
private ReadOnlyList<CallableSignatureRef> emitCallableSignatures() {
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
package p.studio.compiler.models;
|
package p.studio.compiler.models;
|
||||||
|
|
||||||
import p.studio.compiler.source.Span;
|
import p.studio.compiler.source.Span;
|
||||||
|
import p.studio.compiler.source.identifiers.CallableId;
|
||||||
import p.studio.compiler.source.identifiers.FileId;
|
import p.studio.compiler.source.identifiers.FileId;
|
||||||
|
import p.studio.compiler.source.identifiers.IntrinsicId;
|
||||||
import p.studio.utilities.structures.ReadOnlyList;
|
import p.studio.utilities.structures.ReadOnlyList;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -10,7 +12,7 @@ public record IRBackendExecutableFunction(
|
|||||||
FileId fileId,
|
FileId fileId,
|
||||||
String moduleKey,
|
String moduleKey,
|
||||||
String callableName,
|
String callableName,
|
||||||
int callableId,
|
CallableId callableId,
|
||||||
int sourceStart,
|
int sourceStart,
|
||||||
int sourceEnd,
|
int sourceEnd,
|
||||||
int paramSlots,
|
int paramSlots,
|
||||||
@ -27,9 +29,11 @@ public record IRBackendExecutableFunction(
|
|||||||
if (callableName.isBlank()) {
|
if (callableName.isBlank()) {
|
||||||
throw new IllegalArgumentException("callableName must not be blank");
|
throw new IllegalArgumentException("callableName must not be blank");
|
||||||
}
|
}
|
||||||
if (callableId < 0) {
|
callableId = Objects.requireNonNull(callableId, "callableId");
|
||||||
throw new IllegalArgumentException("callableId must be non-negative");
|
if (callableId.isNone()) {
|
||||||
|
throw new IllegalArgumentException("callableId must not be none");
|
||||||
}
|
}
|
||||||
|
callableId.getIndex();
|
||||||
if (sourceStart < 0 || sourceEnd < 0 || sourceEnd < sourceStart) {
|
if (sourceStart < 0 || sourceEnd < 0 || sourceEnd < sourceStart) {
|
||||||
throw new IllegalArgumentException("invalid source span bounds");
|
throw new IllegalArgumentException("invalid source span bounds");
|
||||||
}
|
}
|
||||||
@ -50,7 +54,7 @@ public record IRBackendExecutableFunction(
|
|||||||
InstructionKind kind,
|
InstructionKind kind,
|
||||||
String calleeModuleKey,
|
String calleeModuleKey,
|
||||||
String calleeCallableName,
|
String calleeCallableName,
|
||||||
Integer calleeCallableId,
|
CallableId calleeCallableId,
|
||||||
HostCallMetadata hostCall,
|
HostCallMetadata hostCall,
|
||||||
IntrinsicCallMetadata intrinsicCall,
|
IntrinsicCallMetadata intrinsicCall,
|
||||||
String label,
|
String label,
|
||||||
@ -62,7 +66,7 @@ public record IRBackendExecutableFunction(
|
|||||||
final InstructionKind kind,
|
final InstructionKind kind,
|
||||||
final String calleeModuleKey,
|
final String calleeModuleKey,
|
||||||
final String calleeCallableName,
|
final String calleeCallableName,
|
||||||
final Integer calleeCallableId,
|
final CallableId calleeCallableId,
|
||||||
final HostCallMetadata hostCall,
|
final HostCallMetadata hostCall,
|
||||||
final IntrinsicCallMetadata intrinsicCall,
|
final IntrinsicCallMetadata intrinsicCall,
|
||||||
final Span span) {
|
final Span span) {
|
||||||
@ -73,7 +77,7 @@ public record IRBackendExecutableFunction(
|
|||||||
final InstructionKind kind,
|
final InstructionKind kind,
|
||||||
final String calleeModuleKey,
|
final String calleeModuleKey,
|
||||||
final String calleeCallableName,
|
final String calleeCallableName,
|
||||||
final Integer calleeCallableId,
|
final CallableId calleeCallableId,
|
||||||
final HostCallMetadata hostCall,
|
final HostCallMetadata hostCall,
|
||||||
final IntrinsicCallMetadata intrinsicCall,
|
final IntrinsicCallMetadata intrinsicCall,
|
||||||
final Integer expectedArgSlots,
|
final Integer expectedArgSlots,
|
||||||
@ -111,8 +115,11 @@ public record IRBackendExecutableFunction(
|
|||||||
calleeCallableName = calleeCallableName == null ? "" : calleeCallableName;
|
calleeCallableName = calleeCallableName == null ? "" : calleeCallableName;
|
||||||
label = label == null ? "" : label;
|
label = label == null ? "" : label;
|
||||||
targetLabel = targetLabel == null ? "" : targetLabel;
|
targetLabel = targetLabel == null ? "" : targetLabel;
|
||||||
if (calleeCallableId != null && calleeCallableId < 0) {
|
if (calleeCallableId != null && calleeCallableId.isNone()) {
|
||||||
throw new IllegalArgumentException("calleeCallableId must be non-negative");
|
throw new IllegalArgumentException("calleeCallableId must not be none");
|
||||||
|
}
|
||||||
|
if (calleeCallableId != null) {
|
||||||
|
calleeCallableId.getIndex();
|
||||||
}
|
}
|
||||||
if (expectedArgSlots != null && expectedArgSlots < 0) {
|
if (expectedArgSlots != null && expectedArgSlots < 0) {
|
||||||
throw new IllegalArgumentException("expectedArgSlots must be non-negative");
|
throw new IllegalArgumentException("expectedArgSlots must be non-negative");
|
||||||
@ -224,7 +231,7 @@ public record IRBackendExecutableFunction(
|
|||||||
public record IntrinsicCallMetadata(
|
public record IntrinsicCallMetadata(
|
||||||
String canonicalName,
|
String canonicalName,
|
||||||
long canonicalVersion,
|
long canonicalVersion,
|
||||||
int intrinsicId) {
|
IntrinsicId intrinsicId) {
|
||||||
public IntrinsicCallMetadata {
|
public IntrinsicCallMetadata {
|
||||||
canonicalName = Objects.requireNonNull(canonicalName, "canonicalName");
|
canonicalName = Objects.requireNonNull(canonicalName, "canonicalName");
|
||||||
if (canonicalName.isBlank()) {
|
if (canonicalName.isBlank()) {
|
||||||
@ -233,6 +240,11 @@ public record IRBackendExecutableFunction(
|
|||||||
if (canonicalVersion < 0) {
|
if (canonicalVersion < 0) {
|
||||||
throw new IllegalArgumentException("canonicalVersion must be non-negative");
|
throw new IllegalArgumentException("canonicalVersion must be non-negative");
|
||||||
}
|
}
|
||||||
|
intrinsicId = Objects.requireNonNull(intrinsicId, "intrinsicId");
|
||||||
|
if (intrinsicId.isNone()) {
|
||||||
|
throw new IllegalArgumentException("intrinsicId must not be none");
|
||||||
|
}
|
||||||
|
intrinsicId.getIndex();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,9 @@ package p.studio.compiler.models;
|
|||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import p.studio.compiler.source.Span;
|
import p.studio.compiler.source.Span;
|
||||||
|
import p.studio.compiler.source.identifiers.CallableId;
|
||||||
import p.studio.compiler.source.identifiers.FileId;
|
import p.studio.compiler.source.identifiers.FileId;
|
||||||
|
import p.studio.compiler.source.identifiers.IntrinsicId;
|
||||||
import p.studio.compiler.source.tables.CallableSignatureRef;
|
import p.studio.compiler.source.tables.CallableSignatureRef;
|
||||||
import p.studio.compiler.source.tables.IntrinsicReference;
|
import p.studio.compiler.source.tables.IntrinsicReference;
|
||||||
import p.studio.utilities.structures.ReadOnlyList;
|
import p.studio.utilities.structures.ReadOnlyList;
|
||||||
@ -27,7 +29,7 @@ class IRBackendExecutableContractTest {
|
|||||||
IRBackendExecutableFunction.InstructionKind.CALL_FUNC,
|
IRBackendExecutableFunction.InstructionKind.CALL_FUNC,
|
||||||
"app/main",
|
"app/main",
|
||||||
"foo",
|
"foo",
|
||||||
7,
|
new CallableId(7),
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
Span.none());
|
Span.none());
|
||||||
@ -40,7 +42,7 @@ class IRBackendExecutableContractTest {
|
|||||||
new FileId(1),
|
new FileId(1),
|
||||||
"app",
|
"app",
|
||||||
"main",
|
"main",
|
||||||
1,
|
new CallableId(1),
|
||||||
10,
|
10,
|
||||||
5,
|
5,
|
||||||
0,
|
0,
|
||||||
@ -54,7 +56,7 @@ class IRBackendExecutableContractTest {
|
|||||||
new FileId(1),
|
new FileId(1),
|
||||||
"app",
|
"app",
|
||||||
"main",
|
"main",
|
||||||
1,
|
new CallableId(1),
|
||||||
0,
|
0,
|
||||||
10,
|
10,
|
||||||
0,
|
0,
|
||||||
@ -72,7 +74,7 @@ class IRBackendExecutableContractTest {
|
|||||||
IRBackendExecutableFunction.InstructionKind.CALL_FUNC,
|
IRBackendExecutableFunction.InstructionKind.CALL_FUNC,
|
||||||
"app/main",
|
"app/main",
|
||||||
"foo",
|
"foo",
|
||||||
1,
|
new CallableId(1),
|
||||||
new IRBackendExecutableFunction.HostCallMetadata("gfx", "draw", 1, 0, 0),
|
new IRBackendExecutableFunction.HostCallMetadata("gfx", "draw", 1, 0, 0),
|
||||||
null,
|
null,
|
||||||
Span.none()));
|
Span.none()));
|
||||||
@ -123,7 +125,7 @@ class IRBackendExecutableContractTest {
|
|||||||
new FileId(1),
|
new FileId(1),
|
||||||
"app/main",
|
"app/main",
|
||||||
"entry",
|
"entry",
|
||||||
0,
|
new CallableId(0),
|
||||||
0,
|
0,
|
||||||
10,
|
10,
|
||||||
0,
|
0,
|
||||||
@ -149,7 +151,7 @@ class IRBackendExecutableContractTest {
|
|||||||
new FileId(2),
|
new FileId(2),
|
||||||
"app/main",
|
"app/main",
|
||||||
"aux",
|
"aux",
|
||||||
0,
|
new CallableId(0),
|
||||||
11,
|
11,
|
||||||
20,
|
20,
|
||||||
0,
|
0,
|
||||||
@ -189,7 +191,7 @@ class IRBackendExecutableContractTest {
|
|||||||
new FileId(1),
|
new FileId(1),
|
||||||
"app/main",
|
"app/main",
|
||||||
"entry",
|
"entry",
|
||||||
0,
|
new CallableId(0),
|
||||||
0,
|
0,
|
||||||
10,
|
10,
|
||||||
0,
|
0,
|
||||||
@ -201,7 +203,7 @@ class IRBackendExecutableContractTest {
|
|||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
null,
|
null,
|
||||||
new IRBackendExecutableFunction.IntrinsicCallMetadata("core.color.pack", 1, 0),
|
new IRBackendExecutableFunction.IntrinsicCallMetadata("core.color.pack", 1, new IntrinsicId(0)),
|
||||||
Span.none())),
|
Span.none())),
|
||||||
Span.none())),
|
Span.none())),
|
||||||
IRReservedMetadata.empty(),
|
IRReservedMetadata.empty(),
|
||||||
@ -214,7 +216,7 @@ class IRBackendExecutableContractTest {
|
|||||||
new FileId(2),
|
new FileId(2),
|
||||||
"app/main",
|
"app/main",
|
||||||
"aux",
|
"aux",
|
||||||
0,
|
new CallableId(0),
|
||||||
11,
|
11,
|
||||||
20,
|
20,
|
||||||
0,
|
0,
|
||||||
@ -226,7 +228,7 @@ class IRBackendExecutableContractTest {
|
|||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
null,
|
null,
|
||||||
new IRBackendExecutableFunction.IntrinsicCallMetadata("core.color.pack", 1, 0),
|
new IRBackendExecutableFunction.IntrinsicCallMetadata("core.color.pack", 1, new IntrinsicId(0)),
|
||||||
Span.none())),
|
Span.none())),
|
||||||
Span.none())),
|
Span.none())),
|
||||||
IRReservedMetadata.empty(),
|
IRReservedMetadata.empty(),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user