Files
hakorune/docs/LLVM_HARNESS.md
Selfhosting Dev 2a9aa5368d harness(llvm/py): fix PHI/dominance via Resolver-only; per-pred localization and constant GEPs; stabilize Main.esc_json/1, dirname/1, node_json/3; docs: add NYASH_LLVM_TRACE_FINAL and Resolver-only invariants
- Resolver-only reads across BBs; remove vmap fallbacks
- Create PHIs at block start; insert casts in preds before terminators
- Re-materialize int in preds to satisfy dominance (add/zext/trunc)
- Use constant GEP for method strings to avoid order dependency
- Order non-PHI lowering to preserve producer→consumer dominance
- Update docs: RESOLVER_API.md, LLVM_HARNESS.md
- compare_harness_on_off: ON/OFF exits match; linking green
2025-09-13 19:49:03 +09:00

46 lines
2.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# llvmlite Harness正式導入・Rust LLVM 対置運用)
Purpose
- Python + llvmlite による高速・柔軟な LLVM 生成経路を提供(検証・プロトタイプと将来の主役)。
- Rust/inkwell 経路と並走し、代表ケースで機能同値(戻り値・検証)を維持。
Switch
- `NYASH_LLVM_USE_HARNESS=1` でハーネス優先LLVM バックエンド入口から起動)。
Tracing
- `NYASH_LLVM_TRACE_FINAL=1` を設定すると、代表コール(`Main.node_json/3`, `Main.esc_json/1`, `main` 等)を標準出力へ簡易トレースします。
ON/OFF の最終 JSON 突合の補助に使用してください。
Protocol
- Input: MIR14 JSONRust 前段で Resolver/LoopForm 規約を満たした形)。
- Output: `.o` オブジェクト(既定: `NYASH_AOT_OBJECT_OUT` または `NYASH_LLVM_OBJ_OUT`)。
- 入口: `ny_main() -> i64`(戻り値は exit code 相当。必要時 handle 正規化を行う)。
Quick Start
- 依存: `python3 -m pip install llvmlite`
- ダミー生成(配線検証):
- `python3 tools/llvmlite_harness.py --out /tmp/dummy.o`
- NyRTlibnyrt.aとリンクして EXE 化(例: `cc /tmp/dummy.o -L target/release -Wl,--whole-archive -lnyrt -Wl,--no-whole-archive -lpthread -ldl -lm -o app_dummy`)。
WiringRust 側)
- `NYASH_LLVM_USE_HARNESS=1` のとき:
1) `--emit-mir-json <path>` 等で MIR(JSON) を出力
2) `python3 tools/llvmlite_harness.py --in <mir.json> --out <obj.o>` を起動
3) 成功後は通常のリンク手順NyRT とリンク)
ScopePhase 15
- 最小命令: Const/BinOp/Compare/Phi/Branch/Jump/Return
- 文字列: NyRT Shim`nyash.string.len_h`, `charCodeAt_h`, `concat_hh`, `eq_hh`)を declare → call
- NewBox/ExternCall/BoxCall: まずは固定シンボルby-id を優先(段階導入)
- 目標: `apps/selfhost/tools/dep_tree_min_string.nyash``.ll verify green → .o` 安定化
Acceptance
- Harness ON/OFF で機能同値(戻り値/検証)。代表ケースで `.ll verify green``.o` 生成成功。
Notes
- 初版は固定 `ny_main` から開始してもよい配線確認。以降、MIR 命令を順次対応。
- ハーネスは自律(外部状態に依存しない)。エラーは即 stderr に詳細を出す。
Appendix: 静的リンクについて
- 生成 EXE は NyRTlibnyrt.aを静的リンク。完全静的-staticは musl 推奨dlopen 不可になるため動的プラグインは使用不可)。