Commit 2801bf6400

antlilja <liljaanton2001@gmail.com>
2023-08-26 18:34:14
LLVM Builder: Add strtab helper to String
1 parent 9ccd715
Changed files (1)
src
codegen
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;
         }