authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-06-19 01:18:40-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-19 13:12:04-07:00
log8fcc28d30275bf76313765616a2d2bdcaeb4faf2
treeda1579b5330fc3d202a91f932c374520e04ad4bc
parente6e8cacab904f10d6e5a773867826570783d0bf4

Module: add support for multiple global asm blocks per decl

Closes #16076

2 files changed, 11 insertions(+), 6 deletions(-)

src/Module.zig+8-6
...@@ -6636,12 +6636,14 @@ fn markDeclIndexAlive(mod: *Module, decl_index: Decl.Index) Allocator.Error!void...@@ -6636,12 +6636,14 @@ fn markDeclIndexAlive(mod: *Module, decl_index: Decl.Index) Allocator.Error!void
6636}6636}
66376637
6638pub fn addGlobalAssembly(mod: *Module, decl_index: Decl.Index, source: []const u8) !void {6638pub fn addGlobalAssembly(mod: *Module, decl_index: Decl.Index, source: []const u8) !void {
6639 try mod.global_assembly.ensureUnusedCapacity(mod.gpa, 1);6639 const gop = try mod.global_assembly.getOrPut(mod.gpa, decl_index);
66406640 if (gop.found_existing) {
6641 const duped_source = try mod.gpa.dupe(u8, source);6641 const new_value = try std.fmt.allocPrint(mod.gpa, "{s}\n{s}", .{ gop.value_ptr.*, source });
6642 errdefer mod.gpa.free(duped_source);6642 mod.gpa.free(gop.value_ptr.*);
66436643 gop.value_ptr.* = new_value;
6644 mod.global_assembly.putAssumeCapacityNoClobber(decl_index, duped_source);6644 } else {
6645 gop.value_ptr.* = try mod.gpa.dupe(u8, source);
6646 }
6645}6647}
66466648
6647pub fn wantDllExports(mod: Module) bool {6649pub fn wantDllExports(mod: Module) bool {
test/behavior/asm.zig+3
...@@ -12,6 +12,9 @@ comptime {...@@ -12,6 +12,9 @@ comptime {
12 {12 {
13 asm (13 asm (
14 \\.globl this_is_my_alias;14 \\.globl this_is_my_alias;
15 );
16 // test multiple asm per comptime block
17 asm (
15 \\.type this_is_my_alias, @function;18 \\.type this_is_my_alias, @function;
16 \\.set this_is_my_alias, derp;19 \\.set this_is_my_alias, derp;
17 );20 );