implements PR-O4.1
This commit is contained in:
+16
-14
@@ -15,6 +15,7 @@ public class LowerToIRVMService {
|
||||
private static final Comparator<IRBackendExecutableFunction> FUNCTION_ORDER = Comparator
|
||||
.comparing(IRBackendExecutableFunction::moduleKey)
|
||||
.thenComparing(IRBackendExecutableFunction::callableName)
|
||||
.thenComparingInt(IRBackendExecutableFunction::callableId)
|
||||
.thenComparingInt(IRBackendExecutableFunction::sourceStart);
|
||||
|
||||
private final IRVMValidator validator;
|
||||
@@ -35,11 +36,14 @@ public class LowerToIRVMService {
|
||||
}
|
||||
|
||||
final var ordered = orderFunctions(backend.getExecutableFunctions());
|
||||
final var funcIdByModuleAndName = new HashMap<String, Integer>();
|
||||
final var funcIdByCallableId = new HashMap<Integer, Integer>();
|
||||
for (var i = 0; i < ordered.size(); i++) {
|
||||
final var fn = ordered.get(i);
|
||||
final var key = callableKey(fn.moduleKey(), fn.callableName());
|
||||
funcIdByModuleAndName.putIfAbsent(key, i);
|
||||
if (funcIdByCallableId.putIfAbsent(fn.callableId(), i) != null) {
|
||||
throw new IRVMLoweringException(
|
||||
IRVMLoweringErrorCode.LOWER_IRVM_MISSING_CALLEE,
|
||||
"duplicate callable id in executable set: " + fn.callableId());
|
||||
}
|
||||
}
|
||||
|
||||
final var loweredFunctions = new ArrayList<IRVMFunction>(ordered.size());
|
||||
@@ -66,12 +70,16 @@ public class LowerToIRVMService {
|
||||
functionPc += IRVMOp.RET.immediateSize() + 2;
|
||||
}
|
||||
case CALL_FUNC -> {
|
||||
final var key = callableKey(instr.calleeModuleKey(), instr.calleeCallableName());
|
||||
final var calleeId = funcIdByModuleAndName.get(key);
|
||||
if (instr.calleeCallableId() == null) {
|
||||
throw new IRVMLoweringException(
|
||||
IRVMLoweringErrorCode.LOWER_IRVM_MISSING_CALLEE,
|
||||
"missing callee callable id");
|
||||
}
|
||||
final var calleeId = funcIdByCallableId.get(instr.calleeCallableId());
|
||||
if (calleeId == null) {
|
||||
throw new IRVMLoweringException(
|
||||
IRVMLoweringErrorCode.LOWER_IRVM_MISSING_CALLEE,
|
||||
"missing callee function: " + key);
|
||||
"missing callee function for callable_id=" + instr.calleeCallableId());
|
||||
}
|
||||
final var calleeFunction = ordered.get(calleeId);
|
||||
if (instr.expectedArgSlots() != null
|
||||
@@ -79,7 +87,7 @@ public class LowerToIRVMService {
|
||||
throw new IRVMLoweringException(
|
||||
IRVMLoweringErrorCode.LOWER_IRVM_CALL_ARG_SLOTS_MISMATCH,
|
||||
"call arg_slots mismatch for %s. expected=%d actual=%d".formatted(
|
||||
key,
|
||||
instr.calleeCallableName(),
|
||||
instr.expectedArgSlots(),
|
||||
calleeFunction.paramSlots()));
|
||||
}
|
||||
@@ -88,7 +96,7 @@ public class LowerToIRVMService {
|
||||
throw new IRVMLoweringException(
|
||||
IRVMLoweringErrorCode.LOWER_IRVM_CALL_RET_SLOTS_MISMATCH,
|
||||
"call ret_slots mismatch for %s. expected=%d actual=%d".formatted(
|
||||
key,
|
||||
instr.calleeCallableName(),
|
||||
instr.expectedRetSlots(),
|
||||
calleeFunction.returnSlots()));
|
||||
}
|
||||
@@ -213,12 +221,6 @@ public class LowerToIRVMService {
|
||||
return ReadOnlyList.wrap(ordered);
|
||||
}
|
||||
|
||||
private String callableKey(
|
||||
final String moduleKey,
|
||||
final String callableName) {
|
||||
return (moduleKey == null ? "" : moduleKey) + "::" + callableName;
|
||||
}
|
||||
|
||||
private BytecodeModule.SourceSpan toBytecodeSpan(
|
||||
final int fallbackFileId,
|
||||
final Span span) {
|
||||
|
||||
Reference in New Issue
Block a user