Skip to content

Commit edd0c83

Browse files
committed
fixup! use dataclasses in x86_ast
1 parent e52d3d0 commit edd0c83

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

x86_ast.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
import ast
44
from dataclasses import dataclass
5-
from typing import List
5+
from typing import Iterable
66

77
from utils import dedent, indent, indent_stmt, label_name
88

99

10-
@dataclass(frozen=True)
10+
@dataclass
1111
class X86Program:
1212
body: dict[str, list[instr]] | list[instr]
1313

@@ -31,7 +31,7 @@ def __str__(self):
3131
result += '\n'
3232
return result
3333

34-
@dataclass(frozen=True)
34+
@dataclass
3535
class X86ProgramDefs:
3636
defs: list[ast.FunctionDef]
3737

@@ -42,10 +42,14 @@ class instr: ...
4242
class arg: ...
4343
class location(arg): ...
4444

45-
@dataclass(frozen=True)
45+
@dataclass(frozen=True, eq=False)
4646
class Instr(instr):
4747
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))
4953

5054
def source(self):
5155
return self.args[0]
@@ -54,45 +58,45 @@ def target(self):
5458
def __str__(self):
5559
return indent_stmt() + self.instr + ' ' + ', '.join(str(a) for a in self.args) + '\n'
5660

57-
@dataclass(frozen=True)
61+
@dataclass(frozen=True, eq=False)
5862
class Callq(instr):
5963
func: str
6064
num_args: int
6165

6266
def __str__(self):
6367
return indent_stmt() + 'callq' + ' ' + self.func + '\n'
6468

65-
@dataclass(frozen=True)
69+
@dataclass(frozen=True, eq=False)
6670
class IndirectCallq(instr):
6771
func: arg
6872
num_args: int
6973

7074
def __str__(self):
7175
return indent_stmt() + 'callq' + ' *' + str(self.func) + '\n'
7276

73-
@dataclass(frozen=True)
77+
@dataclass(frozen=True, eq=False)
7478
class JumpIf(instr):
7579
cc: str
7680
label: str
7781

7882
def __str__(self):
7983
return indent_stmt() + 'j' + self.cc + ' ' + self.label + '\n'
8084

81-
@dataclass(frozen=True)
85+
@dataclass(frozen=True, eq=False)
8286
class Jump(instr):
8387
label: str
8488

8589
def __str__(self):
8690
return indent_stmt() + 'jmp ' + self.label + '\n'
8791

88-
@dataclass(frozen=True)
92+
@dataclass(frozen=True, eq=False)
8993
class IndirectJump(instr):
9094
target: location
9195

9296
def __str__(self):
9397
return indent_stmt() + 'jmp *' + str(self.target) + '\n'
9498

95-
@dataclass(frozen=True)
99+
@dataclass(frozen=True, eq=False)
96100
class TailJump(instr):
97101
func: arg
98102
arity: int

0 commit comments

Comments
 (0)