feat(asm): Phase B.0 — validate asm shape in the compile path

Restructures the .asm_expr lowering arm into lowerAsmExpr, which validates the
asm shape with specific named diagnostics BEFORE the not-yet-implemented codegen
bail, so the user sees the real problem first. Two checklist items enforced:

- template must be a compile-time-known string ("..." or #string), not a
  runtime expression;
- an asm with no value outputs must be `volatile` (else its effects could be
  deleted) — mirrors Zig's rule.

Valid shapes still bail with the "codegen not yet implemented" message. Result-
type derivation + the operand auto-naming rule stay deferred to Phase C, where a
real IR op makes the result type observable/testable.

Locked with 1641-platform-asm-missing-volatile (the volatile error) and
1642-platform-asm-nop-volatile (no-output + volatile accepted → codegen bail).

zig build test green (650 corpus, 445 unit).
This commit is contained in:
agra
2026-06-15 20:35:43 +03:00
parent f8e029d719
commit 1040b8c776
11 changed files with 97 additions and 19 deletions

View File

@@ -0,0 +1,6 @@
// ASM stream Phase B — an asm with no value outputs yields no result, so its
// effects could be deleted unless it is marked `volatile`. This omits
// `volatile` ⇒ a compile error. Pins that diagnostic (mirrors Zig's rule).
// Called from `main` so lowering reaches the asm body.
nope :: () { asm { "nop" }; }
main :: () { nope(); }

View File

@@ -0,0 +1,5 @@
// ASM stream Phase B — the no-output form IS accepted when `volatile` is
// present: validation passes, and lowering then bails on the not-yet-
// implemented codegen (Phases CE). Confirms the volatile rule's positive side.
nop :: () { asm volatile { "nop" }; }
main :: () { nop(); }

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1,5 @@
error: asm expression with no outputs must be marked `volatile`
--> examples/1641-platform-asm-missing-volatile.sx:5:14
|
5 | nope :: () { asm { "nop" }; }
| ^^^^^^^^^^^^^

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1,5 @@
error: inline assembly codegen is not yet implemented (ASM stream: lowering + emit land in Phases CE)
--> examples/1642-platform-asm-nop-volatile.sx:4:13
|
4 | nop :: () { asm volatile { "nop" }; }
| ^^^^^^^^^^^^^^^^^^^^^^

View File

@@ -0,0 +1 @@