Skip to content

v.gen.native #

Constants #

const inline_builtins = ['assert', 'print', 'eprint', 'println', 'eprintln', 'exit', 'C.syscall'] // classic V builtin functios accessible to the user get inlined

fn gen #

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

struct Amd64 #

struct Amd64 {
	g &Gen = unsafe { nil }
// arm64 specific stuff for code generation
	is_16bit_aligned bool

fn (Amd64) gen_exit #

fn (mut a Amd64) gen_exit(mut g Gen, node ast.Expr)

struct Arm64 #

struct Arm64 {
	g &Gen = unsafe { nil }
// arm64 specific stuff for code generation

fn (Arm64) gen_exit #

fn (mut c Arm64) gen_exit(mut g Gen, expr ast.Expr)

struct Gen #

struct Gen {
	out_name string
	pref     &pref.Preferences = unsafe { nil } // Preferences shared from V struct
	files    []&ast.File
	code_gen             CodeGen
	table                &ast.Table = unsafe { nil }
	buf                  []u8
	sect_header_name_pos int
	offset               i64
	file_size_pos        i64
	elf_text_header_addr i64 = -1
	elf_rela_section     Section
	main_fn_addr         i64
	main_fn_size         i64
	start_symbol_addr    i64
	code_start_pos       i64 // location of the start of the assembly instructions
	symbol_table         []SymbolTableSection
	extern_symbols       []string
	extern_fn_calls      map[i64]string
	fn_addr              map[string]i64
	var_offset           map[string]int // local var stack offset
	var_alloc_size       map[string]int // local var allocation size
	stack_var_pos        int
	debug_pos            int
	errors               []errors.Error
	warnings             []errors.Warning
	syms                 []Symbol
	size_pos             []int
	nlines               int
	callpatches          []CallPatch
	strs                 []String
	labels               &LabelTable = unsafe { nil }
	defer_stmts          []ast.DeferStmt
	builtins             map[Builtin]BuiltinFn
	structs              []Struct
	eval                 eval.Eval
	enum_vals            map[string]Enum
	return_type          ast.Type
// macho specific
	macho_ncmds   int
	macho_cmdsize int

	requires_linking bool

fn (Gen) add #

fn (mut g Gen) add(reg Register, val int)

fn (Gen) add8 #

fn (mut g Gen) add8(reg Register, val int)

fn (Gen) allocate_array #

fn (mut g Gen) allocate_array(name string, size int, items int) int

fn (Gen) allocate_string #

fn (mut g Gen) allocate_string(s string, opsize int, typ RelocType) int

fn (Gen) allocate_var #

fn (mut g Gen) allocate_var(name string, size int, initial_val int) int

fn (Gen) apicall #

fn (mut g Gen) apicall(s string)

fn (Gen) ast_has_external_functions #

fn (mut g Gen) ast_has_external_functions() bool

fn (Gen) builtin_decl_amd64 #

fn (mut g Gen) builtin_decl_amd64(builtin BuiltinFn)

fn (Gen) calculate_all_size_align #

fn (mut g Gen) calculate_all_size_align()

fn (Gen) calculate_enum_fields #

fn (mut g Gen) calculate_enum_fields()

fn (Gen) call_builtin #

fn (mut g Gen) call_builtin(name Builtin)

fn (Gen) call_fn_amd64 #

fn (mut g Gen) call_fn_amd64(node ast.CallExpr)

fn (Gen) call_fn_arm64 #

fn (mut g Gen) call_fn_arm64(node ast.CallExpr)

fn (Gen) cld #

fn (mut g Gen) cld()

fn (Gen) cld_repne_scasb #

fn (mut g Gen) cld_repne_scasb()

fn (Gen) create_executable #

fn (mut g Gen) create_executable()

fn (Gen) elf_string_table #

fn (mut g Gen) elf_string_table()

fn (Gen) find_o_path #

fn (mut g Gen) find_o_path(fname string) string

fn (Gen) fn_decl_arm64 #

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

fn (Gen) gen_amd64_exit #

fn (mut g Gen) gen_amd64_exit(expr ast.Expr)

fn (Gen) gen_arm64_exit #

fn (mut g Gen) gen_arm64_exit(expr ast.Expr)

fn (Gen) gen_exit #

fn (mut g Gen) gen_exit(node ast.Expr)

fn (Gen) gen_loop_end #

fn (mut g Gen) gen_loop_end(to int, label int)

fn (Gen) gen_loop_start #

fn (mut g Gen) gen_loop_start(from int) int

returns label's relative address

fn (Gen) gen_print #

fn (mut g Gen) gen_print(s string, fd int)

fn (Gen) gen_print_from_expr #

fn (mut g Gen) gen_print_from_expr(expr ast.Expr, typ ast.Type, name string)

fn (Gen) gen_print_reg #

fn (mut g Gen) gen_print_reg(r Register, n int, fd int)

TODO: strlen of string at runtime

fn (Gen) gen_rela_section #

fn (mut g Gen) gen_rela_section()

fn (Gen) generate_builtins #

fn (mut g Gen) generate_builtins()

fn (Gen) generate_header #

fn (mut g Gen) generate_header()

fn (Gen) generate_linkable_elf_header #

fn (mut g Gen) generate_linkable_elf_header()

fn (Gen) generate_macho_header #

fn (mut g Gen) generate_macho_header()

fn (Gen) generate_macho_object_header #

fn (mut g Gen) generate_macho_object_header()

fn (Gen) generate_pe_header #

fn (mut g Gen) generate_pe_header()

fn (Gen) generate_simple_elf_header #

fn (mut g Gen) generate_simple_elf_header()

fn (Gen) get_builtin_arg_reg #

fn (mut g Gen) get_builtin_arg_reg(name Builtin, index int) Register

fn (Gen) get_lpaths #

fn (mut g Gen) get_lpaths() string

fn (Gen) init_builtins #

fn (mut g Gen) init_builtins()

fn (Gen) inline_strlen #

fn (mut g Gen) inline_strlen(r Register)

return length in .rax of string pointed by given register

fn (Gen) n_error #

fn (mut g Gen) n_error(s string)

fn (Gen) pop #

fn (mut g Gen) pop(reg Register)

fn (Gen) pop_sse #

fn (mut g Gen) pop_sse(reg SSERegister)

fn (Gen) pos #

fn (g &Gen) pos() i64

fn (Gen) prepend_vobjpath #

fn (mut g Gen) prepend_vobjpath(paths []string) []string

fn (Gen) push #

fn (mut g Gen) push(reg Register)

fn (Gen) push_sse #

fn (mut g Gen) push_sse(reg SSERegister)

fn (Gen) register_function_address #

fn (mut g Gen) register_function_address(name string)

fn (Gen) rep_stosb #

fn (mut g Gen) rep_stosb()

fn (Gen) ret #

fn (mut g Gen) ret()

fn (Gen) std #

fn (mut g Gen) std()

fn (Gen) stmts #

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

fn (Gen) sub #

fn (mut g Gen) sub(reg Register, val int)

fn (Gen) sub8 #

fn (mut g Gen) sub8(reg Register, val int)

fn (Gen) symtab_get_index #

fn (mut g Gen) symtab_get_index(symbols []SymbolTableSection, name string) int

fn (Gen) test_reg #

fn (mut g Gen) test_reg(r Register)

fn (Gen) typ #

fn (mut g Gen) typ(a int) &ast.TypeSymbol

fn (Gen) v_error #

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

fn (Gen) var_zero #

fn (mut g Gen) var_zero(vo int, size int)

not used?

fn (Gen) warning #

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

fn (Gen) write_dos_header #

fn (mut g Gen) write_dos_header()

fn (Gen) write_dos_stub #

fn (mut g Gen) write_dos_stub()

size is 0xb8

fn (Gen) write_pe_header #

fn (mut g Gen) write_pe_header()

fn (Gen) xor #

fn (mut g Gen) xor(r Register, v int)

fn (Gen) zeroes #

fn (mut g Gen) zeroes(n int)