authorgravatar for liljaanton2001@gmail.comantlilja <liljaanton2001@gmail.com> 2023-08-26 18:34:14+02:00
committergravatar for liljaanton2001@gmail.comantlilja <liljaanton2001@gmail.com> 2024-02-21 16:24:59+01:00
log2801bf6400123b72ec1dcac7552a35c41bec365e
tree51350dca775211e3c214fb40c3b7f70b803a1764
parent9ccd7158b90ac773c0ab09bf5512f2d3d4ef87c2

LLVM Builder: Add strtab helper to String


1 files changed, 17 insertions(+), 0 deletions(-)

src/codegen/llvm/Builder.zig+17
...@@ -130,6 +130,11 @@ pub const String = enum(u32) {...@@ -130,6 +130,11 @@ pub const String = enum(u32) {
130 };130 };
131};131};
132132
133pub const StrtabString = struct {
134 offset: usize,
135 size: usize,
136};
137
133pub const Type = enum(u32) {138pub const Type = enum(u32) {
134 void,139 void,
135 half,140 half,
...@@ -2159,6 +2164,18 @@ pub const Global = struct {...@@ -2159,6 +2164,18 @@ pub const Global = struct {
2159 return builder.globals.keys()[@intFromEnum(self.unwrap(builder))];2164 return builder.globals.keys()[@intFromEnum(self.unwrap(builder))];
2160 }2165 }
21612166
2167 pub fn strtab(self: Index, builder: *const Builder) StrtabString {
2168 const name_index = self.name(builder).toIndex() orelse return .{
2169 .offset = 0,
2170 .size = 0,
2171 };
2172
2173 return .{
2174 .offset = builder.string_indices.items[name_index],
2175 .size = builder.string_indices.items[name_index + 1] - builder.string_indices.items[name_index] - 1,
2176 };
2177 }
2178
2162 pub fn typeOf(self: Index, builder: *const Builder) Type {2179 pub fn typeOf(self: Index, builder: *const Builder) Type {
2163 return self.ptrConst(builder).type;2180 return self.ptrConst(builder).type;
2164 }2181 }