Compare commits
2 Commits
132ed8ed12
...
ab207d982c
Author | SHA1 | Date | |
---|---|---|---|
![]() |
ab207d982c | ||
![]() |
c2bdf555e4 |
@@ -402,8 +402,7 @@ class X86_64Generator(Generator):
|
|||||||
self.change_variable(var_name, "rax")
|
self.change_variable(var_name, "rax")
|
||||||
|
|
||||||
else:
|
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.")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -37,6 +37,7 @@ class Optimizer:
|
|||||||
else:
|
else:
|
||||||
if p_op != i_op:
|
if p_op != i_op:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def match_window(self, patterns: List[Instruction], window: List[Instruction]) -> Union[Dict[str, str], None]:
|
def match_window(self, patterns: List[Instruction], window: List[Instruction]) -> Union[Dict[str, str], None]:
|
||||||
@@ -88,6 +89,7 @@ class Optimizer:
|
|||||||
matched = True
|
matched = True
|
||||||
break
|
break
|
||||||
if not matched:
|
if not matched:
|
||||||
|
#print('next')
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
self.lines = [f"{line.opcode} {', '.join(line.operands)}\n" for line in self.lines]
|
self.lines = [f"{line.opcode} {', '.join(line.operands)}\n" for line in self.lines]
|
||||||
|
@@ -124,13 +124,13 @@ class X86_64Optimizer(Optimizer):
|
|||||||
|
|
||||||
PeepholeRule(
|
PeepholeRule(
|
||||||
match=[
|
match=[
|
||||||
Instruction("mov", ["a", "b"]),
|
Instruction("mov", ["rax", "y"]),
|
||||||
Instruction("mov", ["c", "d"]),
|
Instruction("mov", ["rbx", "x"]),
|
||||||
Instruction("cmp", ["a", "d"])
|
Instruction("cmp", ["rax", "rbx"])
|
||||||
],
|
],
|
||||||
replace=[
|
replace=[
|
||||||
Instruction("mov", ["c", "d"]),
|
Instruction("mov", ["rax", "y"]),
|
||||||
Instruction("cmp", ["b", "c"])
|
Instruction("cmp", ["rax", "x"])
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
]
|
]
|
16
out.asm
16
out.asm
@@ -5,15 +5,11 @@ section .text
|
|||||||
global _start
|
global _start
|
||||||
_start:
|
_start:
|
||||||
push 0
|
push 0
|
||||||
push 1
|
mov rax, 1000
|
||||||
.loop:
|
cmp rax, [rsp + 0]
|
||||||
mov rax, [rsp + 8]
|
setg al
|
||||||
add rax, 1
|
movzx rax, al
|
||||||
mov QWORD [rsp + 8], rax
|
push rax
|
||||||
mov rax, 100000000
|
|
||||||
mov rbx, [rsp + 8]
|
|
||||||
cmp rax, rbx
|
|
||||||
jg .loop
|
|
||||||
mov rax, 60
|
mov rax, 60
|
||||||
mov rdi, [rsp + 8]
|
mov rdi, [rsp + 0]
|
||||||
syscall
|
syscall
|
||||||
|
@@ -1,7 +1,3 @@
|
|||||||
set &var 0
|
set &var 0
|
||||||
set &cond true
|
greater 1000 $var &cond
|
||||||
@loop
|
end $cond
|
||||||
add $var 1 &var
|
|
||||||
greater 100000000 $var &cond
|
|
||||||
if $cond %loop
|
|
||||||
end $var
|
|
Reference in New Issue
Block a user