Skip to content

v.gen.amd64 #

Linux AMD64 backend

Build and run a Linux x86-64 executable with ./v -b amd64 run program.v. Add -prod before run to enable SSA optimization and register allocation. The backend is experimental and currently uses no garbage collector. Debug builds include native backtrace helpers.

Single-file programs that only print string literals use the shared native SSA reduced runtime. Debug, profiling, and object builds retain the ordinary runtime.

Concrete generic sum types retain their variant tags and payload layouts, including recursive pointer variants such as Tree[T] = Empty | &Node[T]. The binary search tree regression exercises insertion, deletion, recursive methods, and floating-point values in normal, production, and serial compilation modes:

./v vlib/v/gen/amd64/native_generic_sum_test.v

Custom errors returned as pointers preserve their concrete type and message when stored in IError, including inside a Result. Test both native compilation modes with:

./v -b amd64 vlib/v/tests/result_custom_error_pointer_test.v
./v -prod -b amd64 vlib/v/tests/result_custom_error_pointer_test.v

See the native backend section in the language documentation for platform and C interoperability restrictions.

fn Gen.new #

fn Gen.new(m &ssa.Module) &Gen

new creates an x86-64 generator for an SSA module without runtime optimizations.

fn Gen.new_with_options #

fn Gen.new_with_options(m &ssa.Module, opts GenOptions) &Gen

new_with_options creates an x86-64 generator with explicit optimization options.

struct Gen #

struct Gen {
	m &ssa.Module
mut:
	elf              &elf.ElfObject
	optimize_runtime bool

	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
	reg_use_counts  []int
	reg_use_stamps  []int
	reg_seen_stamps []int
	reg_stamp       int

	cur_func_ret_type         int
	cur_func_abi_ret_indirect bool
	cur_func_param_indirect   []bool
	sret_save_offset          int
}

fn (Gen) validate_c_extern_calls #

fn (g &Gen) validate_c_extern_calls() !

validate_c_extern_calls rejects C calling conventions that this backend cannot yet lower.

fn (Gen) gen #

fn (mut g Gen) gen()

gen emits all functions, data, and relocations for the module.

fn (Gen) write_file #

fn (mut g Gen) write_file(path string)

write_file writes the generated ELF64 relocatable object to path.

struct GenOptions #

struct GenOptions {
pub:
	optimize_runtime bool
}

GenOptions controls optional amd64 code-generation optimizations.