← ClaudeAtlas

codegen-validationlisted

Use when building or debugging a compiler backend, codegen, or assembler and you need to prove the generated machine code is correct by executing it on a real CPU or a fast emulator, not just inspecting the output
Midstall/claude-for-hardware · ★ 1 · Code & Development · score 74
Install: claude install-skill Midstall/claude-for-hardware
# Codegen Validation ## Overview A codegen backend is correct when the code it emits computes the right answer on a real machine. Reading the assembly proves nothing; a plausible-looking instruction sequence with a wrong ABI detail or a clobbered callee-saved register passes every eyeball review and fails on hardware. **Core principle:** Execution-validate. Compile a known program, run the output on a real CPU or a fast emulator, and assert the observed result. If you didn't run it, you don't know it works. ## When to Use - Bringing up a new codegen target or instruction selection - Implementing calling conventions, stack frames, register spilling, relocations - Debugging "the assembly looks right but the answer is wrong" - Adding an optimization pass and needing to prove it preserves behavior ## The Validation Loop ``` known program (expected result known) -> codegen -> machine code -> run on real CPU / fast emulator -> assert observed result == expected ``` - **Pick programs with known answers.** Start tiny: return a constant, add two args, a call to a leaf function, a loop that sums. Each isolates one capability (literals, ABI, calls, control flow). - **Run on something real and fast.** A native emulator for your target CPU closes the loop in milliseconds, so it can run on every build. The point is real execution semantics, not a model of what you think the instruction does. - **Assert the observed value**, not "it didn't crash." Read the result register o