diff --git a/generators/x86_64.py b/generators/x86_64.py index de1f285..b587227 100644 --- a/generators/x86_64.py +++ b/generators/x86_64.py @@ -402,8 +402,7 @@ class X86_64Generator(Generator): self.change_variable(var_name, "rax") else: - self.lines.append("; FUCK\n\t") - #raise NotImplementedError(f"A generate method hasn't been made for the \"{node.instruction}\" instruction.") + raise NotImplementedError(f"A generate method hasn't been made for the \"{node.instruction}\" instruction.") diff --git a/optimizers/optimizer.py b/optimizers/optimizer.py index 00ee9cf..c144e52 100644 --- a/optimizers/optimizer.py +++ b/optimizers/optimizer.py @@ -21,7 +21,7 @@ class Optimizer: self.rules: list[PeepholeRule] = [] def match_instruction(self, pattern: Instruction, instr: Instruction, bindings: Dict[str, str]) -> bool: - #print(pattern.opcode == instr.opcode, instr.opcode, instr.operands, pattern.opcode) + print(pattern.opcode == instr.opcode, instr.opcode, instr.operands, pattern.opcode) if pattern.opcode != instr.opcode: return False if len(pattern.operands) != len(instr.operands): @@ -37,6 +37,7 @@ class Optimizer: else: if p_op != i_op: return False + return True def match_window(self, patterns: List[Instruction], window: List[Instruction]) -> Union[Dict[str, str], None]: @@ -88,6 +89,7 @@ class Optimizer: matched = True break if not matched: + print('next') i += 1 self.lines = [f"{line.opcode} {', '.join(line.operands)}\n" for line in self.lines] diff --git a/optimizers/x86_64.py b/optimizers/x86_64.py index 9c504ee..48c2f82 100644 --- a/optimizers/x86_64.py +++ b/optimizers/x86_64.py @@ -124,13 +124,13 @@ class X86_64Optimizer(Optimizer): PeepholeRule( match=[ - Instruction("mov", ["a", "b"]), - Instruction("mov", ["c", "d"]), - Instruction("cmp", ["a", "d"]) + Instruction("mov", ["rax", "y"]), + Instruction("mov", ["rbx", "x"]), + Instruction("cmp", ["rax", "rbx"]) ], replace=[ - Instruction("mov", ["c", "d"]), - Instruction("cmp", ["b", "c"]) + Instruction("mov", ["rax", "y"]), + Instruction("cmp", ["rax", "x"]) ] ) ] \ No newline at end of file diff --git a/out b/out index b0bed4d..878b3e5 100644 Binary files a/out and b/out differ diff --git a/out.asm b/out.asm index 012f102..18a8f72 100644 --- a/out.asm +++ b/out.asm @@ -5,15 +5,11 @@ section .text global _start _start: push 0 -push 1 -.loop: -mov rax, [rsp + 8] -add rax, 1 -mov QWORD [rsp + 8], rax -mov rax, 100000000 -mov rbx, [rsp + 8] -cmp rax, rbx -jg .loop +mov rax, 1000 +cmp rax, [rsp + 0] +setg al +movzx rax, al +push rax mov rax, 60 -mov rdi, [rsp + 8] +mov rdi, [rsp + 0] syscall diff --git a/test2.grnd b/test2.grnd index 573e90f..b3e36af 100644 --- a/test2.grnd +++ b/test2.grnd @@ -1,7 +1,3 @@ set &var 0 -set &cond true -@loop -add $var 1 &var -greater 100000000 $var &cond -if $cond %loop -end $var \ No newline at end of file +greater 1000 $var &cond +end $cond \ No newline at end of file