LLVM Builder: Add strtab helper to String

This commit is contained in:
antlilja 2023-08-26 18:34:14 +02:00
parent 9ccd7158b9
commit 2801bf6400

View File

@ -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;
}