Documentation
¶
Overview ¶
Package jit provides a best-effort native compilation path for CEL programs.
Index ¶
- Variables
- func Allocate(p *Program) (map[VReg]Location, int)
- func TryEvaluate(eval NativeEvalFunc, activationType reflect.Type, input any) (bool, bool)
- type BuiltinID
- type CallerSave
- type Instr
- type Interval
- type Label
- type Location
- type NativeEvalFunc
- type NativeProgram
- type Opcode
- type Program
- type Type
- type VReg
Constants ¶
This section is empty.
Variables ¶
var ErrCodegenUnsupported = errors.New("native code generation unsupported")
ErrCodegenUnsupported indicates machine-code generation is not available for translated IR.
var ErrTranslateUnsupported = errors.New("expression translation unsupported")
ErrTranslateUnsupported indicates the expression cannot be translated into JIT IR.
Functions ¶
func Allocate ¶
Allocate runs linear-scan allocation for the current runtime architecture. Returns the location map and the number of spill slots used.
func TryEvaluate ¶
TryEvaluate checks the dynamic type against the configured activation type, extracts the underlying struct pointer, and calls the native eval function. Returns (result, true) on success, or (false, false) if the input type does not match.
Types ¶
type BuiltinID ¶
type BuiltinID uint16
BuiltinID identifies a pre-registered builtin helper.
const ( BuiltinStrEq BuiltinID = iota BuiltinStrNe BuiltinStrContains BuiltinStrStarts BuiltinStrEnds BuiltinStrConcat BuiltinStrSize BuiltinListContainsStringSlice BuiltinListContainsStringArray BuiltinListContainsIntSlice BuiltinListContainsIntArray BuiltinListContainsUintSlice BuiltinListContainsUintArray BuiltinListContainsFloatSlice BuiltinListContainsFloatArray BuiltinListContainsBoolSlice BuiltinListContainsBoolArray )
type CallerSave ¶ added in v0.27.3
type CallerSave struct {
Reg int16 // Primary physical register.
Reg2 int16 // Secondary register for string pairs (-1 if unused).
Slot int // Sequential save slot index for this entry.
IsFloat bool // True if this is a float register (Reg >= 100).
}
CallerSave describes a physical register that must be saved/restored around a CALL_BUILTIN instruction because it is caller-saved and live across the call.
type Instr ¶
type Instr struct {
Op Opcode
Dst VReg
Src1 VReg
Src2 VReg
Imm int64
Lbl Label
Type Type
BuiltinID BuiltinID
}
Instr is a TAC instruction.
type NativeEvalFunc ¶
type NativeProgram ¶
type NativeProgram struct {
ActivationType reflect.Type
EvalFunc NativeEvalFunc
}
type Opcode ¶
type Opcode uint16
Opcode is the operation identifier for a TAC instruction.
const ( OP_UNSPECIFIED Opcode = iota // Constants. CONST_INT CONST_UINT CONST_FLOAT CONST_BOOL CONST_STRING // Slot / type conversion. LOAD_FIELD LOAD_FIELD_SLICE LOAD_FIELD_ARRAY // Arithmetic. ADD_INT SUB_INT MUL_INT DIV_INT MOD_INT NEG_INT ADD_UINT SUB_UINT MUL_UINT DIV_UINT MOD_UINT ADD_FLOAT SUB_FLOAT MUL_FLOAT DIV_FLOAT NEG_FLOAT // Comparisons. EQ_INT NE_INT LT_INT LE_INT GT_INT GE_INT EQ_UINT NE_UINT LT_UINT LE_UINT GT_UINT GE_UINT EQ_FLOAT NE_FLOAT LT_FLOAT LE_FLOAT GT_FLOAT GE_FLOAT // Logical and misc. NOT MOVE // Control flow. LABEL BR BR_TRUE BR_FALSE // Calls and returns. CALL_BUILTIN RETURN // Spill reload/store (inserted by Rewrite after register allocation). SPILL_LOAD // Dst = load from spill slot at byte offset Imm. SPILL_STORE // Src1 = store to spill slot at byte offset Imm. )
type Program ¶
Program is the output of the translate pass.
func Rewrite ¶ added in v0.27.3
func Rewrite( prog *Program, vregLocs map[VReg]Location, spillSlots int, spillOff int, ) (*Program, error)
Rewrite rewrites the instruction stream to replace spilled vreg references with explicit SPILL_LOAD/SPILL_STORE instructions using fresh virtual registers.
For each instruction that uses a spilled vreg as a source, a SPILL_LOAD is inserted before it, loading the value from the spill slot into a fresh vreg. For each instruction that defines a spilled vreg, the destination is replaced with a fresh vreg and a SPILL_STORE is inserted after.
The fresh vregs are not assigned physical registers here; a subsequent register allocation pass handles that. Returns the rewritten instruction stream and the new NumVRegs count.
func Translate ¶
Translate turns a checked AST into an IR program that loads variables directly from a concrete pointer-to-struct input.
Constraints:
- expression result type must be bool
- struct field types must exactly match CEL variable types
- supported scalar field kinds: int64/int, uint64/uint, float64, bool, string
- supported list membership field kinds for in_list: []string, [N]string