Files
GroundPY/main.py

42 lines
878 B
Python
Raw Normal View History

2025-09-02 15:55:21 +10:00
from tokenizer import tokenize
from ground_ast import generate_ast
from rich import print
from time import time
from generators import x86_64
from os import system, remove
from error import traceback
def main():
in_path = "test2.grnd"
out_path = "out"
arch = "x86_64"
start = time()
file = open(in_path, "r")
code = file.read()
file.close()
tokens = tokenize(code)
ast = generate_ast(tokens, code)
generator = None
if arch == "x86_64":
generator = x86_64.X86_64Generator(ast, code, out_path)
else:
traceback(code, "fatal error", f"unkown architecture \"{arch}\"")
generator.init()
system(f"nasm -felf64 {out_path}.asm")
2025-09-02 16:01:11 +10:00
system(f"ld -m elf_{arch} -o {out_path} {out_path}.o")
2025-09-02 15:55:21 +10:00
remove(out_path + ".o")
#remove(out_path + ".asm")
2025-09-07 13:38:16 +10:00
compile_time = time()-start
print(f"Compiled in {round(compile_time, 3)} seconds.")
2025-09-02 15:55:21 +10:00
if __name__ == "__main__":
main()