aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-05-05 12:53:23 -0400
committerGitHub <noreply@github.com>2022-05-05 12:53:23 -0400
commit59905a62f9da9946a797cc35a2523c9929663600 (patch)
tree93ca52f59d1803fca320819fc5a7058fbb58e61b /src/Module.zig
parent49a7ceb5bcd87d8aeb7b25f8b2972ad4ec0b9e24 (diff)
parent44252f4d352d53afd86d678c0b0a40b3f681c7eb (diff)
downloadzig-59905a62f9da9946a797cc35a2523c9929663600.tar.gz
zig-59905a62f9da9946a797cc35a2523c9929663600.zip
Merge pull request #11583 from ziglang/stage2-test-behavior
stage2 behavior tests for all targets passing with the LLVM backend
Diffstat (limited to 'src/Module.zig')
-rw-r--r--src/Module.zig15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/Module.zig b/src/Module.zig
index 55ec1fdd2c..864663ada2 100644
--- a/src/Module.zig
+++ b/src/Module.zig
@@ -151,6 +151,8 @@ allocated_decls: std.SegmentedList(Decl, 0) = .{},
/// When a Decl object is freed from `allocated_decls`, it is pushed into this stack.
decls_free_list: std.ArrayListUnmanaged(Decl.Index) = .{},
+global_assembly: std.AutoHashMapUnmanaged(Decl.Index, []u8) = .{},
+
const MonomorphedFuncsSet = std.HashMapUnmanaged(
*Fn,
void,
@@ -2831,6 +2833,7 @@ pub fn deinit(mod: *Module) void {
mod.decls_free_list.deinit(gpa);
mod.allocated_decls.deinit(gpa);
+ mod.global_assembly.deinit(gpa);
}
pub fn destroyDecl(mod: *Module, decl_index: Decl.Index) void {
@@ -2842,6 +2845,9 @@ pub fn destroyDecl(mod: *Module, decl_index: Decl.Index) void {
if (decl.deletion_flag) {
assert(mod.deletion_set.swapRemove(decl_index));
}
+ if (mod.global_assembly.fetchRemove(decl_index)) |kv| {
+ gpa.free(kv.value);
+ }
if (decl.has_tv) {
if (decl.getInnerNamespace()) |namespace| {
namespace.destroyDecls(mod);
@@ -5714,3 +5720,12 @@ pub fn markDeclAlive(mod: *Module, decl: *Decl) void {
fn markDeclIndexAlive(mod: *Module, decl_index: Decl.Index) void {
return mod.markDeclAlive(mod.declPtr(decl_index));
}
+
+pub fn addGlobalAssembly(mod: *Module, decl_index: Decl.Index, source: []const u8) !void {
+ try mod.global_assembly.ensureUnusedCapacity(mod.gpa, 1);
+
+ const duped_source = try mod.gpa.dupe(u8, source);
+ errdefer mod.gpa.free(duped_source);
+
+ mod.global_assembly.putAssumeCapacityNoClobber(decl_index, duped_source);
+}