pub fn addGlobalAssumeCapacity(self: *Builder, name: StrtabString, global: Global) Global.Index self: *Buildername: StrtabStringglobal: Global10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255pub fn addGlobalAssumeCapacity(self: *Builder, name: StrtabString, global: Global) Global.Index {
_ = self.ptrTypeAssumeCapacity(global.addr_space);
var id = name;
if (name == .empty) {
id = self.next_unnamed_global;
assert(id != self.next_replaced_global);
self.next_unnamed_global = @fromBackingInt(@backingInt(id) + 1);
}
while (true) {
const global_gop = self.globals.getOrPutAssumeCapacity(id);
if (!global_gop.found_existing) {
global_gop.value_ptr.* = global;
const global_index: Global.Index = @fromBackingInt(@intCast(global_gop.index));
global_index.updateDsoLocal(self);
return global_index;
}
const unique_gop = self.next_unique_global_id.getOrPutAssumeCapacity(name);
if (!unique_gop.found_existing) unique_gop.value_ptr.* = 2;
id = self.strtabStringFmtAssumeCapacity("{s}.{d}", .{ name.slice(self).?, unique_gop.value_ptr.* });
unique_gop.value_ptr.* += 1;
}
}