@@ -11,21 +11,31 @@ def __str__(self):
1111 for (l ,ss ) in self .body .items ():
1212 if l == label_name ('main' ):
1313 result += '\t .globl ' + label_name ('main' ) + '\n '
14+ result += '\t .align 16\n '
1415 result += l + ':\n '
1516 indent ()
16- result += '\n ' .join ([str (s ) for s in ss ]) + '\n \n '
17+ result += '' .join ([str (s ) for s in ss ]) + '\n '
1718 dedent ()
1819 else :
1920 result += '\t .globl ' + label_name ('main' ) + '\n ' + \
2021 label_name ('main' ) + ':\n '
2122 indent ()
22- result += '\n ' .join ([str (s ) for s in self .body ])
23+ result += '' .join ([str (s ) for s in self .body ])
2324 dedent ()
2425 result += '\n '
2526 return result
2627 def __repr__ (self ):
2728 return 'X86Program(' + repr (self .body ) + ')'
28-
29+
30+ class X86ProgramDefs :
31+ __match_args__ = ("defs" ,)
32+ def __init__ (self , defs ):
33+ self .defs = defs
34+ def __str__ (self ):
35+ return '\n ' .join ([str (d ) for d in self .defs ])
36+ def __repr__ (self ):
37+ return 'X86ProgramDefs(' + repr (self .defs ) + ')'
38+
2939class instr : ...
3040class arg : ...
3141class location (arg ): ...
@@ -43,7 +53,7 @@ def source(self):
4353 def target (self ):
4454 return self .args [- 1 ]
4555 def __str__ (self ):
46- return indent_stmt () + self .instr + ' ' + ', ' .join (str (a ) for a in self .args )
56+ return indent_stmt () + self .instr + ' ' + ', ' .join (str (a ) for a in self .args ) + ' \n '
4757 def __repr__ (self ):
4858 return 'Instr(' + repr (self .instr ) + ', ' + repr (self .args ) + ')'
4959
@@ -53,9 +63,19 @@ def __init__(self, func, num_args):
5363 self .func = func
5464 self .num_args = num_args
5565 def __str__ (self ):
56- return indent_stmt () + 'callq' + ' ' + self .func
66+ return indent_stmt () + 'callq' + ' ' + self .func + ' \n '
5767 def __repr__ (self ):
5868 return 'Callq(' + repr (self .func ) + ', ' + repr (self .num_args ) + ')'
69+
70+ class IndirectCallq (instr ):
71+ __match_args__ = ("func" , "num_args" )
72+ def __init__ (self , func , num_args ):
73+ self .func = func
74+ self .num_args = num_args
75+ def __str__ (self ):
76+ return indent_stmt () + 'callq' + ' *' + str (self .func ) + '\n '
77+ def __repr__ (self ):
78+ return 'IndirectCallq(' + repr (self .func ) + ', ' + repr (self .num_args ) + ')'
5979
6080class JumpIf (instr ):
6181 cc : str
@@ -66,7 +86,7 @@ def __init__(self, cc, label):
6686 self .cc = cc
6787 self .label = label
6888 def __str__ (self ):
69- return indent_stmt () + 'j' + self .cc + ' ' + self .label
89+ return indent_stmt () + 'j' + self .cc + ' ' + self .label + ' \n '
7090 def __repr__ (self ):
7191 return 'JumpIf(' + repr (self .cc ) + ', ' + repr (self .label ) + ')'
7292
@@ -77,10 +97,29 @@ class Jump(instr):
7797 def __init__ (self , label ):
7898 self .label = label
7999 def __str__ (self ):
80- return indent_stmt () + 'jmp ' + self .label
100+ return indent_stmt () + 'jmp ' + self .label + ' \n '
81101 def __repr__ (self ):
82102 return 'Jump(' + repr (self .label ) + ')'
83103
104+ class IndirectJump (instr ):
105+ __match_args__ = ("target" ,)
106+ def __init__ (self , target ):
107+ self .target = target
108+ def __str__ (self ):
109+ return indent_stmt () + 'jmp *' + str (self .target ) + '\n '
110+ def __repr__ (self ):
111+ return 'IndirectJump(' + repr (self .target ) + ')'
112+
113+ class TailJump (instr ):
114+ __match_args__ = ("func" ,"arity" )
115+ def __init__ (self , func , arity ):
116+ self .func = func
117+ self .arity = arity
118+ def __str__ (self ):
119+ return indent_stmt () + 'tailjmp ' + str (self .func ) + '\n '
120+ def __repr__ (self ):
121+ return 'TailJump(' + repr (self .func ) + ',' + repr (self .arity ) + ')'
122+
84123class Variable (location ):
85124 __match_args__ = ("id" ,)
86125 def __init__ (self , id ):
0 commit comments