✨ Python LLVM backend implementation (experimental)
- Created llvmlite-based LLVM backend in src/llvm_py/ - Implemented all MIR14 instructions (const, binop, jump, branch, ret, compare, phi, call, boxcall, externcall, typeop, newbox, safepoint, barrier) - Experimental LoopForm support - ~2000 lines of clean Python code vs complex Rust/inkwell - Useful for PHI/SSA validation and rapid prototyping - Added documentation to CLAUDE.md This was created while waiting for ChatGPT's investigation of BuilderCursor issues.
This commit is contained in:
@ -4,7 +4,7 @@ Parses Nyash MIR JSON format into Python structures
|
||||
"""
|
||||
|
||||
from dataclasses import dataclass
|
||||
from typing import Dict, List, Any, Optional, Union
|
||||
from typing import Dict, List, Any, Optional, Union, Tuple
|
||||
from enum import Enum
|
||||
|
||||
class MirType(Enum):
|
||||
@ -113,4 +113,30 @@ def parse_instruction(data: Dict[str, Any]) -> MirInstruction:
|
||||
if "args" in data:
|
||||
instr.args = data["args"]
|
||||
|
||||
return instr
|
||||
return instr
|
||||
|
||||
class MIRReader:
|
||||
"""MIR JSON reader wrapper"""
|
||||
def __init__(self, mir_json: Dict[str, Any]):
|
||||
self.mir_json = mir_json
|
||||
self.functions = None
|
||||
|
||||
def get_functions(self) -> List[Dict[str, Any]]:
|
||||
"""Get functions in the expected format for llvm_builder"""
|
||||
if self.functions is not None:
|
||||
return self.functions
|
||||
|
||||
# Convert from the existing JSON format to what llvm_builder expects
|
||||
self.functions = []
|
||||
|
||||
funcs = self.mir_json.get("functions", [])
|
||||
if isinstance(funcs, list):
|
||||
# Already in list format
|
||||
self.functions = funcs
|
||||
elif isinstance(funcs, dict):
|
||||
# Convert dict format to list
|
||||
for name, func_data in funcs.items():
|
||||
func_data["name"] = name
|
||||
self.functions.append(func_data)
|
||||
|
||||
return self.functions
|
||||
Reference in New Issue
Block a user