Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
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 standard library. Public Enum

Value

Public Enum
std.zig.llvm.Builder.Value
pub const Value = enum(u32)

Structs

Types

Values

Functions

pub fn typeOfWip(self: Value, wip: *const WipFunction) Type
pub fn typeOf(self: Value, function: Function.Index, builder: *Builder) Type
pub fn toConst(self: Value) ?Constant
fn format(data: FormatData, w: *Writer) Writer.Error!void
pub fn fmt(self: Value, function: Function.Index, builder: *Builder, flags: FormatFlags) std.fmt.Alt(FormatData, format)

File

zig/llvm/Builder.zig:9011
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
pub const Value = enum(u32) {
    none = maxInt(u31),
    false = first_constant + @backingInt(Constant.false),
    true = first_constant + @backingInt(Constant.true),
    @"0" = first_constant + @backingInt(Constant.@"0"),
    @"1" = first_constant + @backingInt(Constant.@"1"),
    _,

    const first_constant = 1 << 30;
    const first_metadata = 1 << 31;

    pub fn unwrap(self: Value) union(enum) {
        instruction: Function.Instruction.Index,
        constant: Constant,
        metadata: Metadata,
    } {
        return if (@backingInt(self) < first_constant)
            .{ .instruction = @fromBackingInt(@backingInt(self)) }
        else if (@backingInt(self) < first_metadata)
            .{ .constant = @fromBackingInt(@backingInt(self) - first_constant) }
        else
            .{ .metadata = @bitCast(@backingInt(self) - first_metadata) };
    }

    pub fn typeOfWip(self: Value, wip: *const WipFunction) Type {
        return switch (self.unwrap()) {
            .instruction => |instruction| instruction.typeOfWip(wip),
            .constant => |constant| constant.typeOf(wip.builder),
            .metadata => .metadata,
        };
    }

    pub fn typeOf(self: Value, function: Function.Index, builder: *Builder) Type {
        return switch (self.unwrap()) {
            .instruction => |instruction| instruction.typeOf(function, builder),
            .constant => |constant| constant.typeOf(builder),
            .metadata => .metadata,
        };
    }

    pub fn toConst(self: Value) ?Constant {
        return switch (self.unwrap()) {
            .instruction, .metadata => null,
            .constant => |constant| constant,
        };
    }

    const FormatData = struct {
        value: Value,
        function: Function.Index,
        builder: *Builder,
        flags: FormatFlags,
    };
    fn format(data: FormatData, w: *Writer) Writer.Error!void {
        switch (data.value.unwrap()) {
            .instruction => |instruction| try Function.Instruction.Index.format(.{
                .instruction = instruction,
                .function = data.function,
                .builder = data.builder,
                .flags = data.flags,
            }, w),
            .constant => |constant| try Constant.format(.{
                .constant = constant,
                .builder = data.builder,
                .flags = data.flags,
            }, w),
            .metadata => unreachable,
        }
    }
    pub fn fmt(self: Value, function: Function.Index, builder: *Builder, flags: FormatFlags) std.fmt.Alt(FormatData, format) {
        return .{ .data = .{ .value = self, .function = function, .builder = builder, .flags = flags } };
    }
}