From c2bdf555e472ec63fd1141ddd48e0c926dc1ed39 Mon Sep 17 00:00:00 2001 From: SpookyDervish <78246495+SpookyDervish@users.noreply.github.com> Date: Tue, 9 Sep 2025 17:47:43 +1000 Subject: [PATCH] =?UTF-8?q?optimizer=20fixed=20=F0=9F=91=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- generators/x86_64.py | 3 +-- optimizers/optimizer.py | 4 +++- optimizers/x86_64.py | 10 +++++----- out | Bin 4712 -> 4664 bytes out.asm | 16 ++++++---------- test2.grnd | 8 ++------ 6 files changed, 17 insertions(+), 24 deletions(-) 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 b0bed4dfe432cdcefb9573659eb9b226821f17ad..878b3e5d6a7063c531caa1ddce001755aa5410d6 100644 GIT binary patch delta 183 zcmaE%vO{Hp2Gb9LiCTG_atsh4w{c-2zs!yo%nS@3)+{Rg^AC9NZ#xjM!v-kr(QTu` z&pL6V)MO6<2}wSnhyVj4kZ^!#g_4|;Cklv9o**E>C^Pw>fa2tL0#y?auuRSnRN#PF rGI62AftE5bO};9q&A9<8qd1vU$ei;c5>Flgx>6&! delta 209 zcmdm?@