Function init [src]

Prototype

pub fn init(options: Options) Allocator.Error!Builder

Parameters

options: Options

Source

pub fn init(options: Options) Allocator.Error!Builder { var self: Builder = .{ .gpa = options.allocator, .strip = options.strip, .source_filename = .none, .data_layout = .none, .target_triple = .none, .module_asm = .{}, .string_map = .{}, .string_indices = .{}, .string_bytes = .{}, .types = .{}, .next_unnamed_type = @enumFromInt(0), .next_unique_type_id = .{}, .type_map = .{}, .type_items = .{}, .type_extra = .{}, .attributes = .{}, .attributes_map = .{}, .attributes_indices = .{}, .attributes_extra = .{}, .function_attributes_set = .{}, .globals = .{}, .next_unnamed_global = @enumFromInt(0), .next_replaced_global = .none, .next_unique_global_id = .{}, .aliases = .{}, .variables = .{}, .functions = .{}, .strtab_string_map = .{}, .strtab_string_indices = .{}, .strtab_string_bytes = .{}, .constant_map = .{}, .constant_items = .{}, .constant_extra = .{}, .constant_limbs = .{}, .metadata_map = .{}, .metadata_items = .{}, .metadata_extra = .{}, .metadata_limbs = .{}, .metadata_forward_references = .{}, .metadata_named = .{}, .metadata_string_map = .{}, .metadata_string_indices = .{}, .metadata_string_bytes = .{}, }; errdefer self.deinit(); try self.string_indices.append(self.gpa, 0); assert(try self.string("") == .empty); try self.strtab_string_indices.append(self.gpa, 0); assert(try self.strtabString("") == .empty); if (options.name.len > 0) self.source_filename = try self.string(options.name); if (options.triple.len > 0) { self.target_triple = try self.string(options.triple); } { const static_len = @typeInfo(Type).@"enum".fields.len - 1; try self.type_map.ensureTotalCapacity(self.gpa, static_len); try self.type_items.ensureTotalCapacity(self.gpa, static_len); inline for (@typeInfo(Type.Simple).@"enum".fields) |simple_field| { const result = self.getOrPutTypeNoExtraAssumeCapacity( .{ .tag = .simple, .data = simple_field.value }, ); assert(result.new and result.type == @field(Type, simple_field.name)); } inline for (.{ 1, 8, 16, 29, 32, 64, 80, 128 }) |bits| assert(self.intTypeAssumeCapacity(bits) == @field(Type, std.fmt.comptimePrint("i{d}", .{bits}))); inline for (.{ 0, 4 }) |addr_space_index| { const addr_space: AddrSpace = @enumFromInt(addr_space_index); assert(self.ptrTypeAssumeCapacity(addr_space) == @field(Type, std.fmt.comptimePrint("ptr{ }", .{addr_space}))); } } { try self.attributes_indices.append(self.gpa, 0); assert(try self.attrs(&.{}) == .none); assert(try self.fnAttrs(&.{}) == .none); } assert(try self.intConst(.i1, 0) == .false); assert(try self.intConst(.i1, 1) == .true); assert(try self.intConst(.i32, 0) == .@"0"); assert(try self.intConst(.i32, 1) == .@"1"); assert(try self.noneConst(.token) == .none); assert(try self.metadataNone() == .none); assert(try self.metadataTuple(&.{}) == .empty_tuple); try self.metadata_string_indices.append(self.gpa, 0); assert(try self.metadataString("") == .none); return self; }