Skip to content

v.gen.native #

Constants #

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

fn escape_string #

fn escape_string(s string) string

fn gen #

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

fn macho_test_new_gen #

fn macho_test_new_gen(p &pref.Preferences, out_name string) &Gen

used in macho_test.v

struct Amd64 #

struct Amd64 {
mut:
	g &Gen = unsafe { nil }

	fn_arg_registers     []Amd64Register
	fn_arg_sse_registers []Amd64SSERegister
	// amd64 specific stuff for code generation
	is_16bit_aligned bool
}

fn (Amd64) pop #

fn (mut c Amd64) pop(reg Amd64Register)

fn (Amd64) sub8 #

fn (mut c Amd64) sub8(reg Amd64Register, val i32)

fn (Amd64) sub #

fn (mut c Amd64) sub(reg Amd64Register, val i32)

fn (Amd64) add #

fn (mut c Amd64) add(r Register, val i32)

fn (Amd64) add8 #

fn (mut c Amd64) add8(reg Amd64Register, val i32)

fn (Amd64) var_zero #

fn (mut c Amd64) var_zero(vo i32, size i32)

not used?

fn (Amd64) rep_stosb #

fn (mut c Amd64) rep_stosb()

fn (Amd64) std #

fn (mut c Amd64) std()

fn (Amd64) cld #

fn (mut c Amd64) cld()

fn (Amd64) cld_repne_scasb #

fn (mut c Amd64) cld_repne_scasb()

fn (Amd64) xor #

fn (mut c Amd64) xor(r Amd64Register, v i32)

fn (Amd64) test_reg #

fn (mut c Amd64) test_reg(r Amd64Register)

fn (Amd64) inline_strlen #

fn (mut c Amd64) inline_strlen(r Amd64Register)

return length in .rax of string pointed by given register

fn (Amd64) get_dllcall_addr #

fn (mut c Amd64) get_dllcall_addr(import_addr i64) i64

fn (Amd64) dllcall #

fn (mut c Amd64) dllcall(symbol string)

fn (Amd64) gen_print_reg #

fn (mut c Amd64) gen_print_reg(r Register, n i32, fd i32)

fn (Amd64) gen_exit #

fn (mut c Amd64) gen_exit(expr ast.Expr)

fn (Amd64) call_fn #

fn (mut c Amd64) call_fn(node ast.CallExpr)

fn (Amd64) builtin_decl #

fn (mut c Amd64) builtin_decl(builtin BuiltinFn)

fn (Amd64) allocate_var_two_step #

fn (mut c Amd64) allocate_var_two_step(name string, size i32, initial_val i32) i32

fn (Amd64) allocate_var #

fn (mut c Amd64) allocate_var(name string, size i32, initial_val i32) i32

struct Arm64 #

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

fn (Arm64) fn_decl #

fn (mut c Arm64) fn_decl(node ast.FnDecl)

fn (Arm64) call_fn #

fn (mut c Arm64) call_fn(node ast.CallExpr)

fn (Arm64) gen_exit #

fn (mut c Arm64) gen_exit(expr ast.Expr)

fn (Arm64) gen_arm64_exit #

fn (mut c Arm64) gen_arm64_exit(expr ast.Expr)

fn (Arm64) add #

fn (mut c Arm64) add(r Register, val i32)

struct Gen #

@[heap]
@[minify]
struct Gen {
	out_name string
	pref     &pref.Preferences = unsafe { nil } // Preferences shared from V struct
	files    []&ast.File
mut:
	code_gen                  CodeGen
	table                     &ast.Table = unsafe { nil }
	buf                       []u8
	sect_header_name_pos      i32
	offset                    i64
	file_size_pos             i64
	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
	linker_include_paths      []string
	linker_libs               []string
	extern_fn_calls           map[i64]string
	fn_addr                   map[string]i64
	var_offset                map[string]i32 // local var stack offset
	var_alloc_size            map[string]i32 // local var allocation size
	stack_var_pos             i32
	stack_depth               i32
	debug_pos                 i32
	current_file              &ast.File = unsafe { nil }
	errors                    []errors.Error
	warnings                  []errors.Warning
	syms                      []Symbol
	size_pos                  []i32
	nlines                    i32
	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
	comptime_omitted_branches []ast.IfBranch
	// elf specific
	elf_text_header_addr i64 = -1
	elf_rela_section     Section
	// macho specific
	macho_ncmds   i32
	macho_cmdsize i32
	// pe specific
	pe_coff_hdr_pos    i64
	pe_opt_hdr_pos     i64
	pe_text_size_pos   i64
	pe_data_dirs       PeDataDirs = get_pe_data_dirs()
	pe_sections        []PeSection
	pe_dll_relocations map[string]i64

	requires_linking bool
	is_builtin_mod   bool // true for .v files inside `builtin`
}

fn (Gen) ast_fetch_external_deps #

fn (mut g Gen) ast_fetch_external_deps()

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) 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) gen_dos_header #

fn (mut g Gen) gen_dos_header()

fn (Gen) gen_dos_stub #

fn (mut g Gen) gen_dos_stub()

size is 0xb8

fn (Gen) gen_pe_header #

fn (mut g Gen) gen_pe_header()

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 i32) Register

fn (Gen) get_lpaths #

fn (mut g Gen) get_lpaths() string

fn (Gen) has_external_deps #

fn (mut g Gen) has_external_deps() bool

fn (Gen) init_builtins #

fn (mut g Gen) init_builtins()

fn (Gen) n_error #

fn (mut g Gen) n_error(s string)

fn (Gen) pos #

fn (g &Gen) pos() i64

fn (Gen) prepend_vobjpath #

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

fn (Gen) register_function_address #

fn (mut g Gen) register_function_address(name string)

fn (Gen) stmts #

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

fn (Gen) styp #

fn (mut g Gen) styp(a ast.Type) &ast.TypeSymbol

fn (Gen) symtab_get_index #

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

fn (Gen) v_error #

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

fn (Gen) warning #

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

fn (Gen) zeroes #

fn (mut g Gen) zeroes(n i32)