zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 2801bf6400123b72ec1dcac7552a35c41bec365e (tree)
parent 9ccd7158b90ac773c0ab09bf5512f2d3d4ef87c2
Author: antlilja <liljaanton2001@gmail.com>
Date:   Sat, 26 Aug 2023 18:34:14 +0200

LLVM Builder: Add strtab helper to String

Diffstat:
Msrc/codegen/llvm/Builder.zig | 17+++++++++++++++++
1 file changed, 17 insertions(+), 0 deletions(-)

diff --git a/src/codegen/llvm/Builder.zig b/src/codegen/llvm/Builder.zig @@ -130,6 +130,11 @@ pub const String = enum(u32) { }; }; +pub const StrtabString = struct { + offset: usize, + size: usize, +}; + pub const Type = enum(u32) { void, half, @@ -2159,6 +2164,18 @@ pub const Global = struct { return builder.globals.keys()[@intFromEnum(self.unwrap(builder))]; } + pub fn strtab(self: Index, builder: *const Builder) StrtabString { + const name_index = self.name(builder).toIndex() orelse return .{ + .offset = 0, + .size = 0, + }; + + return .{ + .offset = builder.string_indices.items[name_index], + .size = builder.string_indices.items[name_index + 1] - builder.string_indices.items[name_index] - 1, + }; + } + pub fn typeOf(self: Index, builder: *const Builder) Type { return self.ptrConst(builder).type; }