package p.studio.compiler.backend.irvm;

import java.util.Objects;

public record IRVMInstruction(
        IRVMOp op,
        Integer immediate) {
    public IRVMInstruction {
        Objects.requireNonNull(op, "op");
        if (op.immediateSize() > 0 && immediate == null) {
            throw new IllegalArgumentException("immediate is required for opcode: " + op.name());
        }
        if (op.immediateSize() == 0 && immediate != null) {
            throw new IllegalArgumentException("immediate is not allowed for opcode: " + op.name());
        }
    }

    public int encodedSize() {
        return 2 + op.immediateSize();
    }
}

