feat(asm): Phase F — global (module-scope) asm
A top-level `asm { "tmpl", };` block (template only) lowers to LLVM `module asm`;
a lib-less `extern` declaration calls into the symbols it defines (the import
direction reuses the existing C-FFI extern path — no new surface).
- ast.zig: asm_global node (AsmGlobal { template }).
- parser.zig: parseAsmGlobal, dispatched from parseTopLevel on kw_asm — rejects
`volatile` and any operands/clobbers (template only). The in-function asm
expression form stays in parsePrimary.
- module.zig: Module.global_asm list; lower/decl.zig captures each template in
lowerMainAndComptime (the real top-level pass — lowerDecls is dead for
top-level); emit_llvm.zig emit() appends each via LLVMAppendModuleInlineAsm in
source order.
- the new node forced asm_global arms in sema.zig (analyzeNode +
findNodeAtOffset) and semantic_diagnostics.zig (checkBindingNames).
Verified end-to-end: an aarch64 `_my_add` global routine, called via `extern`,
returns 42 — AOT only (the ORC JIT doesn't link module-asm symbols; global-asm
symbols live in the final linked binary). Locked with 1648-platform-asm-global
({ "aot": true, "target": "macos" } → AOT build+run on aarch64, ir-only else).
zig build test green (656 corpus, 446 unit).
This commit is contained in:
@@ -51,6 +51,10 @@ pub const Module = struct {
|
||||
/// (trampoline emission, +alloc/-dealloc synthesis) can re-walk
|
||||
/// `members` for fields / methods / `#extends` / `#implements`.
|
||||
objc_defined_class_cache: std.ArrayList(ObjcDefinedClassEntry),
|
||||
/// Top-level `asm { … }` blocks (ASM stream Phase F), in source order.
|
||||
/// Each is verbatim assembly appended to the LLVM module via
|
||||
/// `LLVMAppendModuleInlineAsm` at emit time; multiple blocks concatenate.
|
||||
global_asm: std.ArrayList([]const u8),
|
||||
alloc: Allocator,
|
||||
/// Owns the per-instruction operand slices the Builder dupes (aggregate
|
||||
/// fields, call args, branch args, switch cases, block params). These live
|
||||
@@ -100,6 +104,7 @@ pub const Module = struct {
|
||||
.objc_selector_cache = std.ArrayList(ObjcSelectorEntry).empty,
|
||||
.objc_class_cache = std.ArrayList(ObjcClassEntry).empty,
|
||||
.objc_defined_class_cache = std.ArrayList(ObjcDefinedClassEntry).empty,
|
||||
.global_asm = std.ArrayList([]const u8).empty,
|
||||
.alloc = alloc,
|
||||
.slice_arena = std.heap.ArenaAllocator.init(alloc),
|
||||
};
|
||||
@@ -115,6 +120,7 @@ pub const Module = struct {
|
||||
self.objc_selector_cache.deinit(self.alloc);
|
||||
self.objc_class_cache.deinit(self.alloc);
|
||||
self.objc_defined_class_cache.deinit(self.alloc);
|
||||
self.global_asm.deinit(self.alloc);
|
||||
self.types.deinit();
|
||||
self.slice_arena.deinit();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user