comparison python/ir/instruction.py @ 205:d77cb5962cc5

Added some handcoded arm code generation
author Windel Bouwman
date Sun, 23 Jun 2013 18:23:18 +0200
parents de3a68f677a5
children 07bfea4c1ed7
comparison
equal deleted inserted replaced
204:de3a68f677a5 205:d77cb5962cc5
1 from .basicblock import BasicBlock 1 from .basicblock import BasicBlock
2 from .function import Function 2 from .function import Function
3
3 4
4 class Value: 5 class Value:
5 """ Temporary SSA value (value that is assigned only once! """ 6 """ Temporary SSA value (value that is assigned only once! """
6 def __init__(self, name): 7 def __init__(self, name):
7 # TODO: add typing? for now only handle integers 8 # TODO: add typing? for now only handle integers
11 return '{0}'.format(self.name) # + str(self.IsUsed) 12 return '{0}'.format(self.name) # + str(self.IsUsed)
12 @property 13 @property
13 def IsUsed(self): 14 def IsUsed(self):
14 return len(self.used_by) > 0 15 return len(self.used_by) > 0
15 16
17 class Variable(Value):
18 pass
19
16 class Use: 20 class Use:
17 def __init__(self, user, val): 21 def __init__(self, user, val):
18 self.user = user 22 self.user = user
19 assert type(val) is Value 23 assert isinstance(val, Value)
20 self.val = val 24 self.val = val
21 self.val.used_by.append(self.user) 25 self.val.used_by.append(self.user)
22 def delete(self): 26 def delete(self):
23 self.val.used_by.remove(self.user) 27 self.val.used_by.remove(self.user)
24 28
128 # Memory functions: 132 # Memory functions:
129 class Load(Instruction): 133 class Load(Instruction):
130 def __init__(self, location, value): 134 def __init__(self, location, value):
131 super().__init__() 135 super().__init__()
132 assert type(value) is Value 136 assert type(value) is Value
133 assert type(location) is Value, "Location must be a value" 137 assert isinstance(location, Value), "Location must be a value"
134 self.value = value 138 self.value = value
135 self.addDef(value) 139 self.addDef(value)
136 self.location = location 140 self.location = location
137 self.addUse(self.location) 141 self.addUse(self.location)
138 def __repr__(self): 142 def __repr__(self):
140 144
141 class Store(Instruction): 145 class Store(Instruction):
142 def __init__(self, location, value): 146 def __init__(self, location, value):
143 super().__init__() 147 super().__init__()
144 assert type(value) is Value 148 assert type(value) is Value
145 assert type(location) is Value, "Location must be a value" 149 assert isinstance(location, Value), "Location must be a value"
146 self.location = location 150 self.location = location
147 self.value = value 151 self.value = value
148 self.addUse(value) 152 self.addUse(value)
149 self.addUse(location) 153 self.addUse(location)
150 def __repr__(self): 154 def __repr__(self):