Phase 20.34: add MirBuilderBox + LLVMEmitBox (Hako, delegate/provider stubs with stable tags); add quick canaries (phase2034) for presence and SKIP policy; update phase docs + CURRENT_TASK
This commit is contained in:
50
lang/src/llvm_ir/emit/LLVMEmitBox.hako
Normal file
50
lang/src/llvm_ir/emit/LLVMEmitBox.hako
Normal file
@ -0,0 +1,50 @@
|
||||
// LLVMEmitBox — MIR(JSON v0) → Object (.o)
|
||||
// Contract (Phase 20.34, staged):
|
||||
// - I/F is stable; implementation starts as a provider call via Plugin v2 (planned).
|
||||
// - Until provider lands, expose stable tags and allow canaries to SKIP.
|
||||
//
|
||||
// API
|
||||
// - emit_object(mir_json: String, opts: Map|Null) -> String|Null
|
||||
// Returns output path string on success; otherwise prints a tag and returns null.
|
||||
//
|
||||
// Notes
|
||||
// - Provider examples: ny-llvmc wrapper or llvmlite harness via a Plugin box `LLVMCodegenBox.emit_object/2`.
|
||||
// - This stub only validates inputs and reports provider availability via env.
|
||||
|
||||
static box LLVMEmitBox {
|
||||
// Availability probe (for canaries)
|
||||
is_available() {
|
||||
// Treat HAKO_LLVM_EMIT_PROVIDER=ny-llvmc|llvmlite as availability hint
|
||||
local p = env.get("HAKO_LLVM_EMIT_PROVIDER")
|
||||
if p == null { return 0 }
|
||||
local v = "" + p
|
||||
if v == "ny-llvmc" || v == "llvmlite" { return 1 } else { return 0 }
|
||||
}
|
||||
|
||||
// Main entry
|
||||
emit_object(mir_json, opts) {
|
||||
if mir_json == null {
|
||||
print("[llvmemit/input/null] mir_json is null")
|
||||
return null
|
||||
}
|
||||
local s = "" + mir_json
|
||||
if !(s.contains("\"functions\"")) || !(s.contains("\"blocks\"")) {
|
||||
print("[llvmemit/input/invalid] missing functions/blocks keys")
|
||||
return null
|
||||
}
|
||||
local p = env.get("HAKO_LLVM_EMIT_PROVIDER")
|
||||
if p == null {
|
||||
print("[llvmemit/provider/missing] set HAKO_LLVM_EMIT_PROVIDER=ny-llvmc|llvmlite")
|
||||
return null
|
||||
}
|
||||
local pv = "" + p
|
||||
if pv != "ny-llvmc" && pv != "llvmlite" {
|
||||
print("[llvmemit/provider/unsupported] " + pv)
|
||||
return null
|
||||
}
|
||||
// Provider path not wired yet in this stub
|
||||
print("[llvmemit/skip] provider stub; implement Plugin v2 call")
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
46
lang/src/mir/builder/MirBuilderBox.hako
Normal file
46
lang/src/mir/builder/MirBuilderBox.hako
Normal file
@ -0,0 +1,46 @@
|
||||
// MirBuilderBox — Program(JSON v0) → MIR(JSON v0)
|
||||
// Contract (Phase 20.34, staged):
|
||||
// - I/F is stable; implementation starts as a delegate to Runner path.
|
||||
// - Unsupported or unavailable paths must Fail‑Fast with stable tags (no silent fallback).
|
||||
//
|
||||
// API
|
||||
// - emit_from_program_json_v0(program_json: String, opts: Map|Null) -> String|Null
|
||||
// Returns MIR(JSON v0) on success, or prints a tag and returns null on failure/skip.
|
||||
//
|
||||
// Toggles (delegate first):
|
||||
// - HAKO_MIR_BUILDER_DELEGATE=1 — implementation delegated to Runner (--program-json-to-mir).
|
||||
// In this initial stub, we only indicate delegation via a stable tag.
|
||||
|
||||
static box MirBuilderBox {
|
||||
// Availability probe (for canaries)
|
||||
is_available() {
|
||||
// For now, availability means delegate toggle is present
|
||||
local t = env.get("HAKO_MIR_BUILDER_DELEGATE")
|
||||
if t == null { return 0 }
|
||||
if ("" + t) == "1" { return 1 } else { return 0 }
|
||||
}
|
||||
|
||||
// Main entry
|
||||
emit_from_program_json_v0(program_json, opts) {
|
||||
if program_json == null {
|
||||
print("[mirbuilder/input/null] program_json is null")
|
||||
return null
|
||||
}
|
||||
// Minimal validation: must include version/kind
|
||||
local s = "" + program_json
|
||||
if !(s.contains("\"version\"")) || !(s.contains("\"kind\"")) {
|
||||
print("[mirbuilder/input/invalid] missing version/kind keys")
|
||||
return null
|
||||
}
|
||||
// Delegate-first policy (Phase 20.34 Milestone A)
|
||||
local d = env.get("HAKO_MIR_BUILDER_DELEGATE")
|
||||
if d != null && ("" + d) == "1" {
|
||||
print("[mirbuilder/delegate] use Runner --program-json-to-mir")
|
||||
return null
|
||||
}
|
||||
// Provider not wired yet
|
||||
print("[mirbuilder/delegate/missing] no provider; enable HAKO_MIR_BUILDER_DELEGATE=1")
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user