v2.gen.arm64 #
fn Gen.new #
fn Gen.new(mod &mir.Module) &Gen
fn Linker.new #
fn Linker.new(macho &MachOObject) &Linker
fn MachOObject.new #
fn MachOObject.new() &MachOObject
struct Gen #
struct Gen {
mod &mir.Module
mut:
macho &MachOObject
pub mut:
stack_map map[int]int
alloca_offsets map[int]int
stack_size int
curr_offset int
block_offsets map[int]int
pending_labels map[int][]int
// Register allocation
reg_map map[int]int
used_regs []int
next_blk int
// Track which string literals have been materialized (value_id -> str_data offset)
string_literal_offsets map[int]int
// Cache for parsed constant integer values (value_id -> parsed i64)
const_cache map[int]i64
// Current function's return type (for handling struct returns)
cur_func_ret_type int
cur_func_name string
// Stack offset where x8 (indirect return pointer) is saved for large struct returns
x8_save_offset int
// Cache for deduplicating string data in cstring section (content -> offset)
string_data_cache map[string]int
}
fn (Gen) gen #
fn (mut g Gen) gen()
fn (Gen) write_file #
fn (mut g Gen) write_file(path string)
fn (Gen) link_executable #
fn (mut g Gen) link_executable(output_path string)
struct Linker #
struct Linker {
macho &MachOObject
mut:
// Output buffer
buf []u8
// Segment/section info
text_vmaddr u64
text_fileoff int
text_size int
data_vmaddr u64
data_fileoff int
data_size int
linkedit_off int
linkedit_size int
// External symbols needing binding
extern_syms []string
// GOT entries for external symbols
got_offset int // Offset within __DATA segment
got_size int
// Stubs for external function calls
stubs_offset int
stubs_size int
// Symbol to GOT index mapping
sym_to_got map[string]int
// Code start offset (after header + load commands)
code_start int
}
vfmt on
fn (Linker) link #
fn (mut l Linker) link(output_path string, entry_name string)
struct MachOObject #
struct MachOObject {
pub mut:
text_data []u8
str_data []u8
data_data []u8
relocs []RelocationInfo
symbols []Symbol
str_table []u8
}
fn (MachOObject) add_symbol #
fn (mut m MachOObject) add_symbol(name string, addr u64, is_ext bool, sect u8) int
fn (MachOObject) add_undefined #
fn (mut m MachOObject) add_undefined(name string) int
fn (MachOObject) add_reloc #
fn (mut m MachOObject) add_reloc(addr int, sym_idx int, typ int, pcrel bool)
fn (MachOObject) write #
fn (mut m MachOObject) write(path string)