Skip to content

v.gen.wasm #

fn calc_align #

fn calc_align(value int, alignment int) int

fn calc_padding #

fn calc_padding(value int, alignment int) int

fn gen #

fn gen(files []&ast.File, mut table ast.Table, out_name string, w_pref &pref.Preferences)

fn log2 #

fn log2(size int) int

fn unpack_literal_int #

fn unpack_literal_int(typ ast.Type) ast.Type

struct Gen #

@[heap]
@[minify]
struct Gen {
	out_name string
	pref     &pref.Preferences = unsafe { nil } // Preferences shared from V struct
	files    []&ast.File
mut:
	file_path string // current ast.File path
	warnings  []errors.Warning
	errors    []errors.Error
	table     &ast.Table = unsafe { nil }
	eval      eval.Eval
	enum_vals map[string]Enum
	//
	mod                    wasm.Module
	pool                   serialise.Pool
	func                   wasm.Function
	local_vars             []Var
	global_vars            map[string]Global
	ret_rvars              []Var
	ret                    ast.Type
	ret_types              []ast.Type
	ret_br                 wasm.LabelIndex
	bp_idx                 wasm.LocalIndex = -1 // Base pointer temporary's index for function, if needed (-1 for none)
	sp_global              ?wasm.GlobalIndex
	heap_base              ?wasm.GlobalIndex
	fn_local_idx_end       int
	fn_name                string
	stack_frame            int             // Size of the current stack frame, if needed
	is_leaf_function       bool = true
	loop_breakpoint_stack  []LoopBreakpoint
	stack_top              int // position in linear memory
	data_base              int // position in linear memory
	needs_address          bool
	defer_vars             []Var
	is_direct_array_access bool // inside a `[direct_array_access]` function
}

fn (Gen) as_numtype #

fn (mut g Gen) as_numtype(a wasm.ValType) wasm.NumType

fn (Gen) asm_call #

fn (mut g Gen) asm_call(node ast.AsmTemplate)

fn (Gen) asm_global_get_or_set #

fn (mut g Gen) asm_global_get_or_set(node ast.AsmTemplate, vars AsmVars)

fn (Gen) asm_literal_arg #

fn (mut g Gen) asm_literal_arg(node ast.AsmTemplate)

fn (Gen) asm_load_or_store #

fn (mut g Gen) asm_load_or_store(node ast.AsmTemplate)

fn (Gen) asm_local_get_set_or_tee #

fn (mut g Gen) asm_local_get_set_or_tee(node ast.AsmTemplate, vars AsmVars)

fn (Gen) asm_parse_align_offset #

fn (mut g Gen) asm_parse_align_offset(node ast.AsmTemplate) (int, int)

fn (Gen) asm_stmt #

fn (mut g Gen) asm_stmt(node ast.AsmStmt)

fn (Gen) asm_template #

fn (mut g Gen) asm_template(parent ast.AsmStmt, node ast.AsmTemplate, vars AsmVars)

fn (Gen) bare_function_end #

fn (mut g Gen) bare_function_end()

fn (Gen) bare_function_frame #

fn (mut g Gen) bare_function_frame(func_start wasm.PatchPos)

fn (Gen) bp #

fn (mut g Gen) bp() wasm.LocalIndex

fn (Gen) calculate_enum_fields #

fn (mut g Gen) calculate_enum_fields()

fn (Gen) call_expr #

fn (mut g Gen) call_expr(node ast.CallExpr, expected ast.Type, existing_rvars []Var)

fn (Gen) cast #

fn (mut g Gen) cast(typ ast.Type, expected_type ast.Type)

fn (Gen) comptime_cond #

fn (mut g Gen) comptime_cond(cond ast.Expr, pkg_exists bool) bool

fn (Gen) comptime_if_expr #

fn (mut g Gen) comptime_if_expr(node ast.IfExpr, expected ast.Type, existing_rvars []Var)

fn (Gen) comptime_if_to_ifdef #

fn (mut g Gen) comptime_if_to_ifdef(name string, is_comptime_option bool) bool

fn (Gen) dbg_type_name #

fn (mut g Gen) dbg_type_name(name string, typ ast.Type) string

fn (Gen) expr #

fn (mut g Gen) expr(node ast.Expr, expected ast.Type)

fn (Gen) expr_stmt #

fn (mut g Gen) expr_stmt(node ast.Stmt, expected ast.Type)

fn (Gen) expr_stmts #

fn (mut g Gen) expr_stmts(stmts []ast.Stmt, expected ast.Type)

fn (Gen) expr_with_cast #

fn (mut g Gen) expr_with_cast(expr ast.Expr, got_type_raw ast.Type, expected_type ast.Type)

fn (Gen) field_offset #

fn (mut g Gen) field_offset(typ ast.Type, name string)

fn (Gen) file_pos #

fn (g &Gen) file_pos(pos token.Pos) string

fn (Gen) fn_decl #

fn (mut g Gen) fn_decl(node ast.FnDecl)

fn (Gen) fn_external_import #

fn (mut g Gen) fn_external_import(node ast.FnDecl)

fn (Gen) get #

fn (mut g Gen) get(v Var)

fn (Gen) get_field_offset #

fn (mut g Gen) get_field_offset(typ ast.Type, name string) int

fn (Gen) get_ns_plus_name #

fn (g &Gen) get_ns_plus_name(default_name string, attrs []ast.Attr) (string, string)

fn (Gen) get_var_from_expr #

fn (mut g Gen) get_var_from_expr(node ast.Expr) ?Var

fn (Gen) get_var_from_ident #

fn (mut g Gen) get_var_from_ident(ident ast.Ident) Var

fn (Gen) get_var_or_make_from_expr #

fn (mut g Gen) get_var_or_make_from_expr(node ast.Expr, typ ast.Type) Var

ONLY call this with the LHS of an assign, an lvalue use get_var_from_expr in all other cases

fn (Gen) get_wasm_type #

fn (mut g Gen) get_wasm_type(typ_ ast.Type) wasm.ValType

"Register size" types such as int, i64 and bool boil down to their WASM counterparts. Structures and unions are pointers, i32.

fn (Gen) get_wasm_type_int_literal #

fn (mut g Gen) get_wasm_type_int_literal(typ_ ast.Type) wasm.ValType

unwraps int_literal to i64_t

fn (Gen) handle_ptr_arithmetic #

fn (mut g Gen) handle_ptr_arithmetic(typ ast.Type)

fn (Gen) housekeeping #

fn (mut g Gen) housekeeping()

fn (Gen) hp #

fn (mut g Gen) hp() wasm.GlobalIndex

fn (Gen) if_branch #

fn (mut g Gen) if_branch(ifexpr ast.IfExpr, expected ast.Type, unpacked_params []wasm.ValType, idx int, existing_rvars []Var)

fn (Gen) if_expr #

fn (mut g Gen) if_expr(ifexpr ast.IfExpr, expected ast.Type, existing_rvars []Var)

fn (Gen) infix_expr #

fn (mut g Gen) infix_expr(node ast.InfixExpr, expected ast.Type)

fn (Gen) infix_from_typ #

fn (mut g Gen) infix_from_typ(typ ast.Type, op token.Kind)

fn (Gen) is_param #

fn (g &Gen) is_param(v Var) bool

fn (Gen) is_param_type #

fn (g Gen) is_param_type(typ ast.Type) bool

fn (Gen) is_pure_type #

fn (g Gen) is_pure_type(typ ast.Type) bool

is_pure_type(voidptr) == true is_pure_type(&Struct) == false

fn (Gen) literal #

fn (mut g Gen) literal(val string, expected ast.Type)

fn (Gen) literal_to_constant_expression #

fn (mut g Gen) literal_to_constant_expression(typ_ ast.Type, init ast.Expr) ?wasm.ConstExpression

fn (Gen) literalint #

fn (mut g Gen) literalint(val i64, expected ast.Type)

fn (Gen) load #

fn (mut g Gen) load(typ ast.Type, offset int)

fn (Gen) load_field #

fn (mut g Gen) load_field(typ ast.Type, ftyp ast.Type, name string)

fn (Gen) make_vinit #

fn (mut g Gen) make_vinit()

fn (Gen) mov #

fn (mut g Gen) mov(to Var, v Var)

fn (Gen) new_global #

fn (mut g Gen) new_global(name string, typ_ ast.Type, init ast.Expr, is_global_mut bool) Global

fn (Gen) new_local #

fn (mut g Gen) new_local(name string, typ_ ast.Type) Var

fn (Gen) offset #

fn (mut g Gen) offset(v Var, typ ast.Type, offset int) Var

creates a new pointer variable with the offset offset and type typ

fn (Gen) prefix_expr #

fn (mut g Gen) prefix_expr(node ast.PrefixExpr, expected ast.Type)

fn (Gen) ref #

fn (mut g Gen) ref(v Var)

fn (Gen) ref_ignore_offset #

fn (mut g Gen) ref_ignore_offset(v Var)

fn (Gen) rvar_expr_stmts #

fn (mut g Gen) rvar_expr_stmts(stmts []ast.Stmt, expected ast.Type, existing_rvars []Var)

fn (Gen) set #

fn (mut g Gen) set(v Var)

set structures with pointer, memcpy set pointers with value, get local, store value set value, set local -- set works with a single value present on the stack beforehand -- not optimal for copying stack memory or shuffling structs -- use mov instead

fn (Gen) set_prepare #

fn (mut g Gen) set_prepare(v Var)

fn (Gen) set_set #

fn (mut g Gen) set_set(v Var)

fn (Gen) set_with_expr #

fn (mut g Gen) set_with_expr(init ast.Expr, v Var)

fn (Gen) set_with_multi_expr #

fn (mut g Gen) set_with_multi_expr(init ast.Expr, expected ast.Type, existing_rvars []Var)

fn (Gen) sp #

fn (mut g Gen) sp() wasm.GlobalIndex

fn (Gen) store #

fn (mut g Gen) store(typ ast.Type, offset int)

fn (Gen) store_field #

fn (mut g Gen) store_field(typ ast.Type, ftyp ast.Type, name string)

fn (Gen) tee #

fn (mut g Gen) tee(v Var)

to satisfy inline assembly needs never used by actual codegen

fn (Gen) toplevel_stmt #

fn (mut g Gen) toplevel_stmt(node ast.Stmt)

fn (Gen) toplevel_stmts #

fn (mut g Gen) toplevel_stmts(stmts []ast.Stmt)

fn (Gen) unpack_type #

fn (g Gen) unpack_type(typ ast.Type) []ast.Type

fn (Gen) v_error #

fn (mut g Gen) v_error(s string, pos token.Pos)

fn (Gen) w_error #

fn (mut g Gen) w_error(s string)

fn (Gen) warning #

fn (mut g Gen) warning(s string, pos token.Pos)

fn (Gen) zero_fill #

fn (mut g Gen) zero_fill(v Var, size int)

struct LoopBreakpoint #

struct LoopBreakpoint {
	c_continue wasm.LabelIndex
	c_break    wasm.LabelIndex
	name       string
}

struct Var #

struct Var {
	name string
mut:
	typ        ast.Type
	idx        wasm.LocalIndex
	is_address bool
	is_global  bool
	g_idx      wasm.GlobalIndex
	offset     int
}