-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoding.py
More file actions
39 lines (34 loc) · 1.04 KB
/
coding.py
File metadata and controls
39 lines (34 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import make_tree as tree
def generator(lis):
if lis.kind == tree.TK_NUM:
print(" push" ,lis.val)
return
generator(lis.lhs)
generator(lis.rhs)
print( " pop rdi")
print( " pop rax")
if lis.kind == tree.ND_ADD:
print(" add rax, rdi")
if lis.kind == tree.ND_SUB:
print(" sub rax, rdi")
if lis.kind == tree.ND_MUL:
print(" imul rax, rdi")
if lis.kind == tree.ND_DIV:
print(" idiv rax, rdi")
if lis.kind == tree.ND_EQ:
print(" cmp rax, al")
print(" sete al")
print(" movzb rax, al")
if lis.kind == tree.ND_NE:
print(" cmp rax, al")
print(" setne al")
print(" movzb rax, al")
if lis.kind == tree.ND_LT:
print(" cmp rax, al")
print(" setl al")
print(" movzb rax, al")
if lis.kind == tree.ND_LE:
print(" cmp rax, al")
print(" setle al")
print(" movzb rax, al")
print(" push rax")