Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

init

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

File

lib/std/zig/llvm/Builder.zig:8732

Code

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 = .empty,

        .string_map = .empty,
        .string_indices = .empty,
        .string_bytes = .empty,

        .types = .empty,
        .next_unnamed_type = @fromBackingInt(@intCast(0)),
        .next_unique_type_id = .empty,
        .type_map = .empty,
        .type_items = .empty,
        .type_extra = .empty,

        .attributes = .empty,
        .attributes_map = .empty,
        .attributes_indices = .empty,
        .attributes_extra = .empty,

        .function_attributes_set = .empty,

        .globals = .empty,
        .next_unnamed_global = @fromBackingInt(@intCast(0)),
        .next_replaced_global = .none,
        .next_unique_global_id = .empty,
        .aliases = .empty,
        .variables = .empty,
        .functions = .empty,

        .strtab_string_map = .empty,
        .strtab_string_indices = .empty,
        .strtab_string_bytes = .empty,

        .constant_map = .empty,
        .constant_items = .empty,
        .constant_extra = .empty,
        .constant_limbs = .empty,

        .alignment_forward_references = .empty,

        .metadata_map = .empty,
        .metadata_items = .empty,
        .metadata_extra = .empty,
        .metadata_limbs = .empty,
        .metadata_forward_references = .empty,
        .metadata_named = .empty,
        .metadata_string_map = .empty,
        .metadata_string_indices = .empty,
        .metadata_string_bytes = .empty,
    };
    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".field_names.len - 1;
        try self.type_map.ensureTotalCapacity(self.gpa, static_len);
        try self.type_items.ensureTotalCapacity(self.gpa, static_len);
        const info = @typeInfo(Type.Simple).@"enum";
        inline for (info.field_names, info.field_values) |simple_field_name, simple_field_value| {
            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 = @fromBackingInt(@intCast(addr_space_index));
            assert(self.ptrTypeAssumeCapacity(addr_space) ==
                @field(Type, std.fmt.comptimePrint("ptr{f}", .{addr_space.fmt(" ")})));
        }
    }

    {
        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.metadataTuple(&.{}) == Metadata.empty_tuple);

    try self.metadata_string_indices.append(self.gpa, 0);

    return self;
}