History

Fixed the string representation of Instruction instances.

David Boddie committed 9 years ago

Commit a07a3ba1 parent 28c97921 file · +29 −34Browse files

Unified · Split

dis.py+29−34
@@ -185,40 +185,6 @@ class Instruction: · 184 unmodified lines
185 destination = self.address_mode & 0x07185 destination = self.address_mode & 0x07
186 self.destination, self.destination_type = self.read_operand(destination, f)186 self.destination, self.destination_type = self.read_operand(destination, f)
187 187
188 def __repr__(self):
189
190 try:
191 name = opcodes.names[self.opcode]
192 except IndexError:
193 name = hex(self.opcode)
194
195 operands = []
196 comments = []
197
198 for op, optype in (self.source, self.source_type), \
199 (self.destination, self.destination_type):
200
201 if optype == "LO(MP)":
202 operands.append(op)
203 comments.append(optype)
204 elif optype == "LO(FP)":
205 operands.append(op)
206 comments.append(optype)
207 elif optype == "$OP":
208 operands.append(op)
209 comments.append(optype)
210 elif optype == "SO(SO(MP))":
211 operands += list(op)
212 comments.append(optype)
213 elif optype == "SO(SO(FP))":
214 operands += list(op)
215 comments.append(optype)
216
217 if comments:
218 return name + " " + ", ".join(map(str, operands)) + " ; " + ", ".join(comments)
219 else:
220 return name + " " + ", ".join(map(str, operands))
221
222 def read_operand(self, operand, f):188 def read_operand(self, operand, f):
223 189
224 if operand == 0x00:190 if operand == 0x00:
@@ -241,3 +207,32 @@ class Instruction: · 16 unmodified lines
241 operand_type = None207 operand_type = None
242 208
243 return operand, operand_type209 return operand, operand_type
210
211 def __repr__(self):
212
213 try:
214 name = opcodes.names[self.opcode]
215 except IndexError:
216 name = hex(self.opcode)
217
218 operands = []
219 comments = []
220
221 for op, optype in (self.source, self.source_type), \
222 (self.middle, self.middle_type), \
223 (self.destination, self.destination_type):
224
225 if optype in ["$SI", "SO(FP)", "SO(MP)"]:
226 operands.append(op)
227 comments.append(optype)
228 elif optype in ["LO(MP)", "LO(FP)", "$OP"]:
229 operands.append(op)
230 comments.append(optype)
231 elif optype in ["SO(SO(MP))", "SO(SO(FP))"]:
232 operands += list(op)
233 comments.append(optype)
234
235 if comments:
236 return name + " " + ", ".join(map(hex, operands)) + " ; " + ", ".join(comments)
237 else:
238 return name + " " + ", ".join(map(hex, operands))