implements one-shot PBS boot guard in published wrapper lowering
This commit is contained in:
+20
@@ -35,6 +35,8 @@ public class BytecodeEmitter {
|
||||
private static final int OP_LTE = 0x3C;
|
||||
private static final int OP_GTE = 0x3D;
|
||||
private static final int OP_NEG = 0x3E;
|
||||
private static final int OP_GET_GLOBAL = 0x40;
|
||||
private static final int OP_SET_GLOBAL = 0x41;
|
||||
private static final int OP_GET_LOCAL = 0x42;
|
||||
private static final int OP_SET_LOCAL = 0x43;
|
||||
private static final int OP_PUSH_I32 = 0x17;
|
||||
@@ -81,10 +83,18 @@ public class BytecodeEmitter {
|
||||
writeOpU32(code, OP_GET_LOCAL, op.immediate());
|
||||
spans.add(new BytecodeFunctionLayoutBuilder.InstructionSpan(pc, spanOrUnknown(op.span())));
|
||||
}
|
||||
case GET_GLOBAL -> {
|
||||
writeOpU32(code, OP_GET_GLOBAL, op.immediate());
|
||||
spans.add(new BytecodeFunctionLayoutBuilder.InstructionSpan(pc, spanOrUnknown(op.span())));
|
||||
}
|
||||
case SET_LOCAL -> {
|
||||
writeOpU32(code, OP_SET_LOCAL, op.immediate());
|
||||
spans.add(new BytecodeFunctionLayoutBuilder.InstructionSpan(pc, spanOrUnknown(op.span())));
|
||||
}
|
||||
case SET_GLOBAL -> {
|
||||
writeOpU32(code, OP_SET_GLOBAL, op.immediate());
|
||||
spans.add(new BytecodeFunctionLayoutBuilder.InstructionSpan(pc, spanOrUnknown(op.span())));
|
||||
}
|
||||
case PUSH_BOOL -> {
|
||||
writeOpU8(code, OP_PUSH_BOOL, op.immediate() == 0 ? 0 : 1);
|
||||
spans.add(new BytecodeFunctionLayoutBuilder.InstructionSpan(pc, spanOrUnknown(op.span())));
|
||||
@@ -307,7 +317,9 @@ public class BytecodeEmitter {
|
||||
PUSH_CONST,
|
||||
POP,
|
||||
GET_LOCAL,
|
||||
GET_GLOBAL,
|
||||
SET_LOCAL,
|
||||
SET_GLOBAL,
|
||||
PUSH_BOOL,
|
||||
PUSH_I32,
|
||||
ADD,
|
||||
@@ -397,10 +409,18 @@ public class BytecodeEmitter {
|
||||
return new Operation(OperationKind.GET_LOCAL, slot, null, null, null, span);
|
||||
}
|
||||
|
||||
public static Operation getGlobal(final int slot, final BytecodeModule.SourceSpan span) {
|
||||
return new Operation(OperationKind.GET_GLOBAL, slot, null, null, null, span);
|
||||
}
|
||||
|
||||
public static Operation setLocal(final int slot, final BytecodeModule.SourceSpan span) {
|
||||
return new Operation(OperationKind.SET_LOCAL, slot, null, null, null, span);
|
||||
}
|
||||
|
||||
public static Operation setGlobal(final int slot, final BytecodeModule.SourceSpan span) {
|
||||
return new Operation(OperationKind.SET_GLOBAL, slot, null, null, null, span);
|
||||
}
|
||||
|
||||
public static Operation pushBool(final boolean value, final BytecodeModule.SourceSpan span) {
|
||||
return new Operation(OperationKind.PUSH_BOOL, value ? 1 : 0, null, null, null, span);
|
||||
}
|
||||
|
||||
+2
@@ -37,6 +37,8 @@ public record IRVMOp(
|
||||
public static final IRVMOp LTE = new IRVMOp("LTE", 0x3C, 0, 2, 1, false, false, false);
|
||||
public static final IRVMOp GTE = new IRVMOp("GTE", 0x3D, 0, 2, 1, false, false, false);
|
||||
public static final IRVMOp NEG = new IRVMOp("NEG", 0x3E, 0, 1, 1, false, false, false);
|
||||
public static final IRVMOp GET_GLOBAL = new IRVMOp("GET_GLOBAL", 0x40, 4, 0, 1, false, false, false);
|
||||
public static final IRVMOp SET_GLOBAL = new IRVMOp("SET_GLOBAL", 0x41, 4, 1, 0, false, false, false);
|
||||
public static final IRVMOp GET_LOCAL = new IRVMOp("GET_LOCAL", 0x42, 4, 0, 1, false, false, false);
|
||||
public static final IRVMOp SET_LOCAL = new IRVMOp("SET_LOCAL", 0x43, 4, 1, 0, false, false, false);
|
||||
public static final IRVMOp INTERNAL_EXT = new IRVMOp("IRVM_EXT_NOP", 0xFFFF, 0, 0, 0, false, false, true);
|
||||
|
||||
+4
@@ -13,7 +13,9 @@ public final class IRVMProfileFeatureGate {
|
||||
IRVMOp.RET,
|
||||
IRVMOp.PUSH_CONST,
|
||||
IRVMOp.POP,
|
||||
IRVMOp.GET_GLOBAL,
|
||||
IRVMOp.GET_LOCAL,
|
||||
IRVMOp.SET_GLOBAL,
|
||||
IRVMOp.SET_LOCAL,
|
||||
IRVMOp.CALL,
|
||||
IRVMOp.JMP,
|
||||
@@ -43,7 +45,9 @@ public final class IRVMProfileFeatureGate {
|
||||
IRVMOp.RET,
|
||||
IRVMOp.PUSH_CONST,
|
||||
IRVMOp.POP,
|
||||
IRVMOp.GET_GLOBAL,
|
||||
IRVMOp.GET_LOCAL,
|
||||
IRVMOp.SET_GLOBAL,
|
||||
IRVMOp.SET_LOCAL,
|
||||
IRVMOp.CALL,
|
||||
IRVMOp.JMP,
|
||||
|
||||
+6
@@ -94,7 +94,9 @@ public record IRVMProgram(
|
||||
case 0x10 -> operation.kind() == BytecodeEmitter.OperationKind.PUSH_CONST && operation.immediate() == immediate;
|
||||
case 0x11 -> operation.kind() == BytecodeEmitter.OperationKind.POP;
|
||||
case 0x16 -> operation.kind() == BytecodeEmitter.OperationKind.PUSH_BOOL;
|
||||
case 0x40 -> operation.kind() == BytecodeEmitter.OperationKind.GET_GLOBAL && operation.immediate() == immediate;
|
||||
case 0x42 -> operation.kind() == BytecodeEmitter.OperationKind.GET_LOCAL && operation.immediate() == immediate;
|
||||
case 0x41 -> operation.kind() == BytecodeEmitter.OperationKind.SET_GLOBAL && operation.immediate() == immediate;
|
||||
case 0x43 -> operation.kind() == BytecodeEmitter.OperationKind.SET_LOCAL && operation.immediate() == immediate;
|
||||
case 0x17 -> operation.kind() == BytecodeEmitter.OperationKind.PUSH_I32 && operation.immediate() == immediate;
|
||||
case 0x20 -> operation.kind() == BytecodeEmitter.OperationKind.ADD;
|
||||
@@ -176,7 +178,9 @@ public record IRVMProgram(
|
||||
case 0x10 -> BytecodeEmitter.Operation.pushConst(immediate, null);
|
||||
case 0x11 -> BytecodeEmitter.Operation.pop(null);
|
||||
case 0x16 -> BytecodeEmitter.Operation.pushBool(immediate != 0, null);
|
||||
case 0x40 -> BytecodeEmitter.Operation.getGlobal(immediate, null);
|
||||
case 0x42 -> BytecodeEmitter.Operation.getLocal(immediate, null);
|
||||
case 0x41 -> BytecodeEmitter.Operation.setGlobal(immediate, null);
|
||||
case 0x43 -> BytecodeEmitter.Operation.setLocal(immediate, null);
|
||||
case 0x17 -> BytecodeEmitter.Operation.pushI32(immediate, null);
|
||||
case 0x20 -> BytecodeEmitter.Operation.add(null);
|
||||
@@ -248,7 +252,9 @@ public record IRVMProgram(
|
||||
case PUSH_CONST -> new IRVMInstruction(IRVMOp.PUSH_CONST, operation.immediate());
|
||||
case POP -> new IRVMInstruction(IRVMOp.POP, null);
|
||||
case PUSH_BOOL -> new IRVMInstruction(IRVMOp.PUSH_BOOL, operation.immediate());
|
||||
case GET_GLOBAL -> new IRVMInstruction(IRVMOp.GET_GLOBAL, operation.immediate());
|
||||
case GET_LOCAL -> new IRVMInstruction(IRVMOp.GET_LOCAL, operation.immediate());
|
||||
case SET_GLOBAL -> new IRVMInstruction(IRVMOp.SET_GLOBAL, operation.immediate());
|
||||
case SET_LOCAL -> new IRVMInstruction(IRVMOp.SET_LOCAL, operation.immediate());
|
||||
case PUSH_I32 -> new IRVMInstruction(IRVMOp.PUSH_I32, operation.immediate());
|
||||
case ADD -> new IRVMInstruction(IRVMOp.ADD, null);
|
||||
|
||||
+26
@@ -124,6 +124,19 @@ public class LowerToIRVMService {
|
||||
operations.add(BytecodeEmitter.Operation.getLocal(slot, sourceSpan));
|
||||
functionPc += IRVMOp.GET_LOCAL.immediateSize() + 2;
|
||||
}
|
||||
case GET_GLOBAL -> {
|
||||
final var slot = instr.expectedArgSlots();
|
||||
if (slot == null) {
|
||||
throw loweringError(
|
||||
fn,
|
||||
instr,
|
||||
IRVMLoweringErrorCode.LOWER_IRVM_MISSING_CALLEE,
|
||||
"missing global slot for GET_GLOBAL");
|
||||
}
|
||||
instructions.add(new IRVMInstruction(IRVMOp.GET_GLOBAL, slot));
|
||||
operations.add(BytecodeEmitter.Operation.getGlobal(slot, sourceSpan));
|
||||
functionPc += IRVMOp.GET_GLOBAL.immediateSize() + 2;
|
||||
}
|
||||
case SET_LOCAL -> {
|
||||
final var slot = instr.expectedArgSlots();
|
||||
if (slot == null) {
|
||||
@@ -137,6 +150,19 @@ public class LowerToIRVMService {
|
||||
operations.add(BytecodeEmitter.Operation.setLocal(slot, sourceSpan));
|
||||
functionPc += IRVMOp.SET_LOCAL.immediateSize() + 2;
|
||||
}
|
||||
case SET_GLOBAL -> {
|
||||
final var slot = instr.expectedArgSlots();
|
||||
if (slot == null) {
|
||||
throw loweringError(
|
||||
fn,
|
||||
instr,
|
||||
IRVMLoweringErrorCode.LOWER_IRVM_MISSING_CALLEE,
|
||||
"missing global slot for SET_GLOBAL");
|
||||
}
|
||||
instructions.add(new IRVMInstruction(IRVMOp.SET_GLOBAL, slot));
|
||||
operations.add(BytecodeEmitter.Operation.setGlobal(slot, sourceSpan));
|
||||
functionPc += IRVMOp.SET_GLOBAL.immediateSize() + 2;
|
||||
}
|
||||
case POP -> {
|
||||
instructions.add(new IRVMInstruction(IRVMOp.POP, null));
|
||||
operations.add(BytecodeEmitter.Operation.pop(sourceSpan));
|
||||
|
||||
Reference in New Issue
Block a user