lowerAsmExpr stops bailing and builds the inline_asm op: resolves each operand's
effective name (§II.5 — explicit [name] else the {reg} pin), interns
template/constraints/clobbers, lowers input Refs, derives the result TypeId
(0→void, 1→T). Adds the last deferred validation (every %[name] must name an
operand). Multi-output (N>1) bails with a named "Phase E" diagnostic.
emitInlineAsm (backend/llvm/ops.zig) ports Zig's airAssembly: assembles the LLVM
constraint string (outputs → inputs → ~{clobber}, ',' → '|'), rewrites the
template (%[name]→${N}, %%→%, $→$$, %=→${:uid}), then LLVMGetInlineAsm +
LLVMBuildCall2 (AT&T dialect). Dispatch wired in emit_llvm.zig (replacing the C.0
@panic tripwire).
inferType gains an .asm_expr arm (expr_typer.zig) so a bare `x := asm {…-> T}`
binding types correctly — without it the binding inferred .unresolved and
silently produced 0.
llvm_shim.c: LLVMInitializeNativeAsmParser() — the JIT must assemble inline asm
at run time.
Verified end-to-end on the aarch64 host: `mov`/`add` with register-class inputs
and a value output run (exit 42/99), `nop volatile` runs (exit 0). IR is
textbook: `call i64 asm "add ${0},${1},${2}", "=r,r,r"(…)`.
Locked with 1645 (aarch64 add, runs; ir-only on non-aarch64) + 1646 (:= binding).
Updated 1640 (now Phase-E bail) + 1642 (now runs).
zig build test green (654 corpus, 446 unit).
21 lines
774 B
Plaintext
21 lines
774 B
Plaintext
// ASM stream — `asm { … }` parses + validates the full rich shape: named value
|
|
// outputs (`[quot] "={rax}" -> u64`), register-pinned inputs, and a
|
|
// `clobbers(.…)` clause, all accepted. This is a MULTI-output (tuple-returning)
|
|
// asm, which is deferred to Phase E — so lowering bails LOUD + named with the
|
|
// specific "Phase E" diagnostic (single-output asm already runs; see 1645).
|
|
// Called from `main` so lowering reaches the asm body (lazy lowering skips
|
|
// uncalled functions).
|
|
divmod :: (n: u64, d: u64) -> (quot: u64, rem: u64) {
|
|
return asm {
|
|
"divq %[d]",
|
|
[quot] "={rax}" -> u64,
|
|
[rem] "={rdx}" -> u64,
|
|
"{rax}" = n, "{rdx}" = 0, [d] "r" = d,
|
|
clobbers(.cc),
|
|
};
|
|
}
|
|
|
|
main :: () {
|
|
q, r := divmod(17, 5);
|
|
}
|