aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-05-04 20:38:53 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-05-04 20:38:53 -0700
commit1b432b557608bd047afaad71ffb7bd2ddf23c444 (patch)
tree0930ca5f5f1e78460a75dc5d86e243fccb5027ba /src/Module.zig
parent0bebb688fbc4c6ffb88a2b0aefcf536143bb5f2e (diff)
downloadzig-1b432b557608bd047afaad71ffb7bd2ddf23c444.tar.gz
zig-1b432b557608bd047afaad71ffb7bd2ddf23c444.zip
stage2: implement global assembly
So far it's supported by the LLVM backend only. I recommend for the other backends to wait for the resolution of #10761 before adding support for this feature.
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);
+}