2
2
3
3
import ast
4
4
from dataclasses import dataclass
5
- from typing import List
5
+ from typing import Iterable
6
6
7
7
from utils import dedent , indent , indent_stmt , label_name
8
8
9
9
10
- @dataclass ( frozen = True )
10
+ @dataclass
11
11
class X86Program :
12
12
body : dict [str , list [instr ]] | list [instr ]
13
13
@@ -31,7 +31,7 @@ def __str__(self):
31
31
result += '\n '
32
32
return result
33
33
34
- @dataclass ( frozen = True )
34
+ @dataclass
35
35
class X86ProgramDefs :
36
36
defs : list [ast .FunctionDef ]
37
37
@@ -42,10 +42,14 @@ class instr: ...
42
42
class arg : ...
43
43
class location (arg ): ...
44
44
45
- @dataclass (frozen = True )
45
+ @dataclass (frozen = True , eq = False )
46
46
class Instr (instr ):
47
47
instr : str
48
- args : List [arg ]
48
+ args : tuple [arg , ...]
49
+
50
+ def __init__ (self , name : str , args : Iterable [arg ]):
51
+ object .__setattr__ (self , 'instr' , name )
52
+ object .__setattr__ (self , 'args' , tuple (args ))
49
53
50
54
def source (self ):
51
55
return self .args [0 ]
@@ -54,45 +58,45 @@ def target(self):
54
58
def __str__ (self ):
55
59
return indent_stmt () + self .instr + ' ' + ', ' .join (str (a ) for a in self .args ) + '\n '
56
60
57
- @dataclass (frozen = True )
61
+ @dataclass (frozen = True , eq = False )
58
62
class Callq (instr ):
59
63
func : str
60
64
num_args : int
61
65
62
66
def __str__ (self ):
63
67
return indent_stmt () + 'callq' + ' ' + self .func + '\n '
64
68
65
- @dataclass (frozen = True )
69
+ @dataclass (frozen = True , eq = False )
66
70
class IndirectCallq (instr ):
67
71
func : arg
68
72
num_args : int
69
73
70
74
def __str__ (self ):
71
75
return indent_stmt () + 'callq' + ' *' + str (self .func ) + '\n '
72
76
73
- @dataclass (frozen = True )
77
+ @dataclass (frozen = True , eq = False )
74
78
class JumpIf (instr ):
75
79
cc : str
76
80
label : str
77
81
78
82
def __str__ (self ):
79
83
return indent_stmt () + 'j' + self .cc + ' ' + self .label + '\n '
80
84
81
- @dataclass (frozen = True )
85
+ @dataclass (frozen = True , eq = False )
82
86
class Jump (instr ):
83
87
label : str
84
88
85
89
def __str__ (self ):
86
90
return indent_stmt () + 'jmp ' + self .label + '\n '
87
91
88
- @dataclass (frozen = True )
92
+ @dataclass (frozen = True , eq = False )
89
93
class IndirectJump (instr ):
90
94
target : location
91
95
92
96
def __str__ (self ):
93
97
return indent_stmt () + 'jmp *' + str (self .target ) + '\n '
94
98
95
- @dataclass (frozen = True )
99
+ @dataclass (frozen = True , eq = False )
96
100
class TailJump (instr ):
97
101
func : arg
98
102
arity : int
0 commit comments