v2.ssa #
fn Builder.new #
fn Builder.new(mod &Module) &Builder
fn Module.new #
fn Module.new(name string) &Module
fn TypeStore.new #
fn TypeStore.new() &TypeStore
type BlockID #
type BlockID = int
type TypeID #
type TypeID = int
type ValueID #
type ValueID = int
enum AtomicOrdering #
enum AtomicOrdering {
not_atomic
unordered
monotonic
acquire
release
acq_rel
seq_cst
}
enum CallConv #
enum CallConv {
c_decl
fast_call
wasm_std
}
enum Linkage #
enum Linkage {
external
private
internal
}
enum OpCode #
enum OpCode {
// Terminators
ret
br
jmp
switch_
unreachable
// Binary
add
sub
mul
sdiv
udiv
srem
urem
// Bitwise
shl
lshr
ashr
and_
or_
xor
// Memory
alloca
load
store
get_element_ptr
fence
cmpxchg
atomicrmw
// Conversion
trunc
zext
sext
fptoui
fptosi
uitofp
sitofp
bitcast
// Comparisons
lt
gt
le
ge
eq
ne
// Other
phi
call
select
assign // copy for phi elimination
}
enum TypeKind #
enum TypeKind {
void_t
int_t
float_t
ptr_t
array_t
struct_t
func_t
label_t
metadata_t
}
enum ValueKind #
enum ValueKind {
unknown
constant
argument
global
instruction
basic_block
}
struct BasicBlock #
struct BasicBlock {
pub:
id BlockID
val_id ValueID
name string
parent int // Function ID
pub mut:
instrs []ValueID
// Control Flow Graph
preds []BlockID
succs []BlockID
// Dominators
idom BlockID
dom_tree []BlockID
}
struct Builder #
struct Builder {
mut:
mod &Module
cur_func int = -1
cur_block BlockID = -1
// Maps AST variable name to SSA ValueID (pointer to stack slot)
vars map[string]ValueID
// Maps variable name to struct type name (for method resolution)
var_struct_types map[string]string
// Stack for break/continue targets
loop_stack []LoopInfo
// Maps struct name to TypeID
struct_types map[string]TypeID
}
fn (Builder) build #
fn (mut b Builder) build(file ast.File)
struct ConstantData #
struct ConstantData {
pub:
int_val i64
float_val f64
str_val string
}
struct Function #
struct Function {
pub:
id int
name string
typ TypeID
pub mut:
blocks []BlockID
params []ValueID
linkage Linkage
call_conv CallConv
}
struct GlobalVar #
struct GlobalVar {
pub:
name string
typ TypeID
linkage Linkage
alignment int
is_constant bool
}
struct Instruction #
struct Instruction {
pub mut:
op OpCode
// Operands are IDs of other Values
operands []ValueID
pub:
block BlockID
typ TypeID // Result type
pos token.Pos
atomic_ord AtomicOrdering
}
struct Module #
@[heap]
struct Module {
pub mut:
name string
target TargetData
type_store TypeStore
// Arenas
values []Value
instrs []Instruction
blocks []BasicBlock
funcs []Function
globals []GlobalVar
}
fn (Module) add_block #
fn (mut m Module) add_block(func_id int, name string) BlockID
fn (Module) add_global #
fn (mut m Module) add_global(name string, typ TypeID, is_const bool) int
fn (Module) add_instr #
fn (mut m Module) add_instr(op OpCode, block BlockID, typ TypeID, operands []ValueID) ValueID
fn (Module) add_instr_front #
fn (mut m Module) add_instr_front(op OpCode, block BlockID, typ TypeID, operands []ValueID) ValueID
fn (Module) add_value_node #
fn (mut m Module) add_value_node(kind ValueKind, typ TypeID, name string, index int) ValueID
Updated to accept 'index'
fn (Module) get_block_from_val #
fn (m Module) get_block_from_val(val_id int) int
fn (Module) new_function #
fn (mut m Module) new_function(name string, ret TypeID, params []TypeID) int
fn (Module) optimize #
fn (mut m Module) optimize()
Optimize Module
fn (Module) replace_uses #
fn (mut m Module) replace_uses(old_val int, new_val int)
struct TargetData #
struct TargetData {
pub:
ptr_size int
endian_little bool
}
struct Type #
struct Type {
pub:
kind TypeKind
width int // Bit width
elem_type TypeID // For Ptr, Array
len int // For Array
fields []TypeID // For Structs
field_names []string // Field names for Structs
params []TypeID // For Funcs
ret_type TypeID
}
struct TypeStore #
struct TypeStore {
pub mut:
types []Type
cache map[string]TypeID
}
fn (TypeStore) get_int #
fn (mut ts TypeStore) get_int(width int) TypeID
fn (TypeStore) get_float #
fn (mut ts TypeStore) get_float(width int) TypeID
fn (TypeStore) get_ptr #
fn (mut ts TypeStore) get_ptr(elem TypeID) TypeID
struct Value #
struct Value {
pub:
id ValueID
typ TypeID
// Index into the specific arena (instrs, blocks, globals)
index int
pub mut:
kind ValueKind
name string
uses []ValueID
}
- fn Builder.new
- fn Module.new
- fn TypeStore.new
- type BlockID
- type TypeID
- type ValueID
- enum AtomicOrdering
- enum CallConv
- enum Linkage
- enum OpCode
- enum TypeKind
- enum ValueKind
- struct BasicBlock
- struct Builder
- struct ConstantData
- struct Function
- struct GlobalVar
- struct Instruction
- struct Module
- struct TargetData
- struct Type
- struct TypeStore
- struct Value