ITS GENERATING AN EXECUTABLE LETS GOOOO
This commit is contained in:
22
generators/x86_64.py
Normal file
22
generators/x86_64.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from generators.generator import Generator
|
||||
from ground_ast import *
|
||||
from error import traceback
|
||||
|
||||
class X86_64Generator(Generator):
|
||||
def init(self):
|
||||
self.lines.append("global _start\n\n")
|
||||
self.lines.append("_start:\n\t")
|
||||
self.generate()
|
||||
|
||||
def generate_InstructionNode(self, node: InstructionNode):
|
||||
if node.instruction == "end":
|
||||
if len(node.arguments) == 0:
|
||||
traceback(self.code, "TypeError", "end expects atleast 1 argument.")
|
||||
elif len(node.arguments) > 1:
|
||||
traceback(self.code, "TypeError", "end expects only 1 argument.")
|
||||
if not isinstance(node.arguments[0], NumberNode):
|
||||
traceback(self.code, "TypeError", f"end expects an integer, not {type(node.arguments[0])}")
|
||||
|
||||
self.lines.append("mov rax, 60\n\t")
|
||||
self.lines.append("mov rdi, " + str(node.arguments[0].value) + "\n\t")
|
||||
self.lines.append("syscall\n\n\t")
|
Reference in New Issue
Block a user