Module: add support for multiple global asm blocks per decl

Closes #16076
This commit is contained in:
Jacob Young 2023-06-19 01:18:40 -04:00 committed by Andrew Kelley
parent e6e8cacab9
commit 8fcc28d302
2 changed files with 11 additions and 6 deletions

View file

@ -6636,12 +6636,14 @@ fn markDeclIndexAlive(mod: *Module, decl_index: Decl.Index) Allocator.Error!void
}
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);
const gop = try mod.global_assembly.getOrPut(mod.gpa, decl_index);
if (gop.found_existing) {
const new_value = try std.fmt.allocPrint(mod.gpa, "{s}\n{s}", .{ gop.value_ptr.*, source });
mod.gpa.free(gop.value_ptr.*);
gop.value_ptr.* = new_value;
} else {
gop.value_ptr.* = try mod.gpa.dupe(u8, source);
}
}
pub fn wantDllExports(mod: Module) bool {

View file

@ -12,6 +12,9 @@ comptime {
{
asm (
\\.globl this_is_my_alias;
);
// test multiple asm per comptime block
asm (
\\.type this_is_my_alias, @function;
\\.set this_is_my_alias, derp;
);