Mercurial > lcfOS
comparison python/ir/instruction.py @ 175:a51b3c956386
Added function call in expressions
author | Windel Bouwman |
---|---|
date | Fri, 19 Apr 2013 22:15:54 +0200 |
parents | 3eb06f5fb987 |
children | 5fd02aa38b42 |
comparison
equal
deleted
inserted
replaced
174:3eb06f5fb987 | 175:a51b3c956386 |
---|---|
1 from .basicblock import BasicBlock | 1 from .basicblock import BasicBlock |
2 from .function import Function | |
2 | 3 |
3 class Value: | 4 class Value: |
4 """ Temporary SSA value (value that is assigned only once! """ | 5 """ Temporary SSA value (value that is assigned only once! """ |
5 def __init__(self, name): | 6 def __init__(self, name): |
6 # TODO: add typing? for now only handle integers | 7 # TODO: add typing? for now only handle integers |
52 def Targets(self): | 53 def Targets(self): |
53 return self.getTargets() | 54 return self.getTargets() |
54 | 55 |
55 # Function calling: | 56 # Function calling: |
56 class Call(Instruction): | 57 class Call(Instruction): |
57 def __init__(self, callee, arguments): | 58 def __init__(self, callee, arguments, result=None): |
58 super().__init__() | 59 super().__init__() |
59 self.callee = callee | 60 self.callee = callee |
61 assert type(callee) is Function | |
60 self.arguments = arguments | 62 self.arguments = arguments |
63 for arg in arguments: | |
64 assert type(arg) is Value | |
65 self.addUse(arg) | |
66 self.result = result | |
67 if result: | |
68 assert type(result) is Value | |
69 self.addDef(result) | |
61 def __repr__(self): | 70 def __repr__(self): |
62 return 'CALL {0}'.format(self.callee) | 71 if self.result: |
72 pfx = '{0} = '.format(self.result) | |
73 else: | |
74 pfx = '' | |
75 args = ','.join([str(arg) for arg in self.arguments]) | |
76 return pfx + '{0}({1})'.format(self.callee.name, args) | |
63 | 77 |
64 class Return(Instruction): | 78 class Return(Instruction): |
65 def __init__(self, value=None): | 79 def __init__(self, value=None): |
66 super().__init__() | 80 super().__init__() |
67 self.value = value | 81 self.value = value |
128 assert type(value) is Value | 142 assert type(value) is Value |
129 assert type(location) is Value, "Location must be a value" | 143 assert type(location) is Value, "Location must be a value" |
130 self.location = location | 144 self.location = location |
131 self.value = value | 145 self.value = value |
132 self.addUse(value) | 146 self.addUse(value) |
147 self.addUse(location) | |
133 def __repr__(self): | 148 def __repr__(self): |
134 return '[{0}] = {1}'.format(self.location, self.value) | 149 return '[{0}] = {1}'.format(self.location, self.value) |
135 | 150 |
136 # Branching: | 151 # Branching: |
137 class Branch(Instruction): | 152 class Branch(Instruction): |