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:
1
examples/expected/1648-platform-asm-global.build
Normal file
1
examples/expected/1648-platform-asm-global.build
Normal file
@@ -0,0 +1 @@
|
||||
{ "aot": true, "target": "macos" }
|
||||
1
examples/expected/1648-platform-asm-global.exit
Normal file
1
examples/expected/1648-platform-asm-global.exit
Normal file
@@ -0,0 +1 @@
|
||||
42
|
||||
16
examples/expected/1648-platform-asm-global.ir
Normal file
16
examples/expected/1648-platform-asm-global.ir
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
module asm ".global _my_add"
|
||||
module asm "_my_add:"
|
||||
module asm " add x0, x0, x1"
|
||||
module asm " ret"
|
||||
|
||||
; Function Attrs: nounwind
|
||||
declare i64 @my_add(i64, i64) #0
|
||||
|
||||
; Function Attrs: nounwind
|
||||
define i32 @main() #0 {
|
||||
entry:
|
||||
%call = call i64 @my_add(i64 40, i64 2)
|
||||
%ca.tr = trunc i64 %call to i32
|
||||
ret i32 %ca.tr
|
||||
}
|
||||
1
examples/expected/1648-platform-asm-global.stderr
Normal file
1
examples/expected/1648-platform-asm-global.stderr
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
1
examples/expected/1648-platform-asm-global.stdout
Normal file
1
examples/expected/1648-platform-asm-global.stdout
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
Reference in New Issue
Block a user