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

Alignment

Public Enum
std.zig.llvm.Builder.Alignment
pub const Alignment = enum(u6)

Structs

Types

Functions

pub fn fromByteUnits(bytes: u64) Alignment
pub fn toByteUnits(self: Alignment) ?u64
pub fn max(lhs: Alignment, rhs: Alignment) Alignment

Asserts that neither lhs nor rhs is .default.

pub fn order(lhs: Alignment, rhs: Alignment) std.math.Order

Asserts that neither lhs nor rhs is .default.

pub fn toLlvm(self: Alignment) u6
pub fn fmt(alignment: Alignment, prefix: []const u8) Prefixed

File

zig/llvm/Builder.zig:2953
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
pub const Alignment = enum(u6) {
    default = maxInt(u6),
    _,

    pub const Lazy = enum(u32) {
        /// Values which fit in a `u6` are already-resolved `Alignment` values. Other values are
        /// indices into `Builder.alignment_forward_references`, offset by `maxInt(u6)`.
        _,

        pub fn wrap(a: Alignment) Lazy {
            return @fromBackingInt(@backingInt(a));
        }
        pub fn resolve(l: Lazy, b: *const Builder) Alignment {
            return switch (@backingInt(l)) {
                0...maxInt(u6) => |raw| @fromBackingInt(@intCast(raw)),
                else => |offset_index| b.alignment_forward_references.items[offset_index - maxInt(u6)],
            };
        }

        fn fromFwdRefIndex(index: usize) Lazy {
            return @fromBackingInt(@intCast(index + maxInt(u6)));
        }
        fn toFwdRefIndex(l: Lazy) usize {
            return @backingInt(l) - maxInt(u6);
        }
    };

    pub fn fromByteUnits(bytes: u64) Alignment {
        if (bytes == 0) return .default;
        assert(std.math.isPowerOfTwo(bytes));
        assert(bytes <= 1 << 32);
        return @fromBackingInt(@intCast(@ctz(bytes)));
    }

    pub fn toByteUnits(self: Alignment) ?u64 {
        return switch (self) {
            .default => null,
            else => @as(u64, 1) << @backingInt(self),
        };
    }

    /// Asserts that neither `lhs` nor `rhs` is `.default`.
    pub fn max(lhs: Alignment, rhs: Alignment) Alignment {
        assert(lhs != .default);
        assert(rhs != .default);
        return @fromBackingInt(@max(@backingInt(lhs), @backingInt(rhs)));
    }

    /// Asserts that neither `lhs` nor `rhs` is `.default`.
    pub fn order(lhs: Alignment, rhs: Alignment) std.math.Order {
        assert(lhs != .default);
        assert(rhs != .default);
        return std.math.order(@backingInt(lhs), @backingInt(rhs));
    }

    pub fn toLlvm(self: Alignment) u6 {
        return switch (self) {
            .default => 0,
            else => @backingInt(self) + 1,
        };
    }

    pub const Prefixed = struct {
        alignment: Alignment,
        prefix: []const u8,

        pub fn format(p: Prefixed, w: *Writer) Writer.Error!void {
            const byte_units = p.alignment.toByteUnits() orelse return;
            return w.print("{s}align {d}", .{ p.prefix, byte_units });
        }
    };

    pub fn fmt(alignment: Alignment, prefix: []const u8) Prefixed {
        return .{ .alignment = alignment, .prefix = prefix };
    }
}