AST works for variable reassignment
kinda coded horribly tho lol
This commit is contained in:
37
main.py
37
main.py
@@ -3,14 +3,16 @@ from plasma_parser import Parser
|
||||
from compiler import Compiler
|
||||
from AST import Program
|
||||
import json
|
||||
import time
|
||||
|
||||
from llvmlite import ir
|
||||
from llvmlite.binding import targets
|
||||
import llvmlite.binding as llvm
|
||||
from ctypes import CFUNCTYPE, c_int, c_float
|
||||
|
||||
LEXER_DEBUG: bool = False
|
||||
PARSER_DEBUG: bool = False
|
||||
COMPILER_DEBUG: bool = True
|
||||
RUN_CODE: bool = False
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
@@ -44,8 +46,37 @@ if __name__ == "__main__":
|
||||
c.compile(program)
|
||||
|
||||
module: ir.Module = c.module
|
||||
module.triple = targets.get_default_triple()
|
||||
module.triple = llvm.get_default_triple()
|
||||
|
||||
if COMPILER_DEBUG:
|
||||
with open("debug/ir.ll", "w") as f:
|
||||
f.write(str(module))
|
||||
f.write(str(module))
|
||||
|
||||
if RUN_CODE:
|
||||
#llvm.initialize()
|
||||
llvm.initialize_native_target()
|
||||
llvm.initialize_native_asmparser()
|
||||
llvm.initialize_native_asmprinter()
|
||||
|
||||
try:
|
||||
llvm_ir_parsed = llvm.parse_assembly(str(module))
|
||||
llvm_ir_parsed.verify()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
raise
|
||||
|
||||
target_machine = llvm.Target.from_default_triple().create_target_machine()
|
||||
|
||||
engine = llvm.create_mcjit_compiler(llvm_ir_parsed, target_machine)
|
||||
engine.finalize_object()
|
||||
|
||||
entry = engine.get_function_address("main")
|
||||
cfunc = CFUNCTYPE(c_int)(entry)
|
||||
|
||||
st = time.time()
|
||||
|
||||
result = cfunc()
|
||||
|
||||
et = time.time()
|
||||
|
||||
print(f"\n\nProgram returned: {result}\n=== Executed in {round((et - st) * 1000, 6)} ms. ===")
|
||||
Reference in New Issue
Block a user