implements PR-O1.5

This commit is contained in:
2026-03-24 13:42:26 +00:00
parent e36c59fe26
commit b5622bd9df
4 changed files with 110 additions and 20 deletions
@@ -116,6 +116,33 @@ class BytecodeEmitterTest {
assertEquals(0x2000, readU32(module.code(), 2));
}
@Test
void emitMustProducePcToSpanForEveryInstructionStartWhenSpansAreProvided() {
final var emitter = new BytecodeEmitter();
final var module = emitter.emit(new BytecodeEmitter.EmissionPlan(
0,
ReadOnlyList.empty(),
ReadOnlyList.empty(),
ReadOnlyList.from(
new BytecodeEmitter.FunctionPlan(
"main",
0,
0,
0,
4,
ReadOnlyList.from(
BytecodeEmitter.Operation.halt(new BytecodeModule.SourceSpan(1, 0, 1)),
BytecodeEmitter.Operation.callFunc(0, new BytecodeModule.SourceSpan(1, 2, 3)),
BytecodeEmitter.Operation.intrinsic(0x2000, new BytecodeModule.SourceSpan(1, 4, 5)),
BytecodeEmitter.Operation.ret(new BytecodeModule.SourceSpan(1, 6, 7)))))));
assertEquals(4, module.debugInfo().pcToSpan().size());
assertEquals(0, module.debugInfo().pcToSpan().get(0).pc());
assertEquals(2, module.debugInfo().pcToSpan().get(1).pc());
assertEquals(8, module.debugInfo().pcToSpan().get(2).pc());
assertEquals(14, module.debugInfo().pcToSpan().get(3).pc());
}
private static int readU16(final byte[] bytes, final int offset) {
return ByteBuffer.wrap(bytes, offset, 2).order(ByteOrder.LITTLE_ENDIAN).getShort() & 0xFFFF;
}
@@ -124,4 +151,3 @@ class BytecodeEmitterTest {
return ByteBuffer.wrap(bytes, offset, 4).order(ByteOrder.LITTLE_ENDIAN).getInt();
}
}
@@ -52,6 +52,7 @@ class LowerToIRVMServiceTest {
final var emissionOps = lowered.emissionPlan().functions().getFirst().operations();
assertEquals(p.studio.compiler.backend.bytecode.BytecodeEmitter.OperationKind.HOSTCALL, emissionOps.get(0).kind());
assertEquals(p.studio.compiler.backend.bytecode.BytecodeEmitter.OperationKind.INTRINSIC, emissionOps.get(1).kind());
assertTrue(emissionOps.stream().allMatch(op -> op.span() != null));
}
@Test