Files
hakorune/docs/LLVM_HARNESS.md
Selfhosting Dev c04b0c059d feat(llvm): Major refactor - BuilderCursor全域化 & Resolver API導入
Added:
- Resolver API (resolve_i64) for unified value resolution with per-block cache
- llvmlite harness (Python) for rapid PHI/SSA verification
- Comprehensive LLVM documentation suite:
  - LLVM_LAYER_OVERVIEW.md: Overall architecture and invariants
  - RESOLVER_API.md: Value resolution strategy
  - LLVM_HARNESS.md: Python verification harness

Updated:
- BuilderCursor applied to ALL lowering paths (externcall/newbox/arrays/maps/call)
- localize_to_i64 for dominance safety in strings/compare/flow
- NYASH_LLVM_DUMP_ON_FAIL=1 for debug IR output

Key insight: LoopForm didn't cause problems, it just exposed existing design flaws:
- Scattered value resolution (now unified via Resolver)
- Inconsistent type conversion placement
- Ambiguous PHI wiring responsibilities

Next: Wire Resolver throughout, achieve sealed=ON green for dep_tree_min_string
2025-09-12 20:06:48 +09:00

1.6 KiB

llvmlite Harness (Experimental)

Purpose

  • Provide a fast, scriptable LLVM emission path using Python + llvmlite for validation and prototyping.
  • Run in parallel with the Rust/inkwell path; keep outputs functionally equivalent for targeted smokes.

Switch

  • Set NYASH_LLVM_USE_HARNESS=1 to prefer the harness (future: wired in LLVM backend entry).

Protocol (tentative)

  • Input: MIR14 JSON file path (subset sufficient for dep_tree_min_string initially).
  • Output: .o object file written to NYASH_AOT_OBJECT_OUT or --out path.
  • Entry function: ny_main(i64 argc, i8** argv) -> i64 (returns app exit code/box-handle per ABI).

Quick Start

  • Install deps: python3 -m pip install llvmlite
  • Generate a dummy object to validate toolchain:
    • python3 tools/llvmlite_harness.py --out /tmp/dummy.o
    • Link with NyRT as usual to produce an executable.

Intended Wiring (Rust side)

  • LLVM backend checks NYASH_LLVM_USE_HARNESS=1 and, if set, exports MIR14 of the target module to a temp JSON, then invokes:
    • python3 tools/llvmlite_harness.py --in <mir.json> --out <obj.o>
  • On success, the normal link step continues using <obj.o>.

Scope (Phase 15)

  • Minimal ops: i64 arithmetic, comparisons, branches, PHI(Sealed), basic string ops through NyRT shims.
  • Target case: apps/selfhost/tools/dep_tree_min_string.nyash builds and runs.

Acceptance

  • A5: Harness ON vs OFF produce functionally equivalent output for the target smoke.

Notes

  • The first version may ignore MIR details and emit a fixed ny_main body for smoke scaffolding; then iterate to lower MIR ops.
  • Keep the harness self-contained; no external state besides inputs and env.