def format(self, assembly_format, indent): from peachpy.x86_64.operand import format_operand text = "\t" * self._indent_level if indent else "" if assembly_format == "peachpy": return text + str(self) elif assembly_format == "nasm": return text + str(self) elif assembly_format == "gas": return text + str(self) elif assembly_format == "go": if self.go_name: from peachpy.util import is_int if self.name == "CMP" and is_int(self.operands[1]): # CMP instruction with an immediate operand has operands in normal (non-reversed) order return ( text + str(self.go_name) + " " + ", ".join(format_operand(op, assembly_format) for op in self.operands) ) elif self.operands: return ( text + str(self.go_name) + " " + ", ".join(format_operand(op, assembly_format) for op in reversed(self.operands)) ) else: return text + str(self.go_name) else: return text + "; ".join(map(lambda b: "BYTE $0x%02X" % b, self.encode())) + " // " + str(self)
def format(self, assembly_format, indent): from peachpy.x86_64.operand import format_operand text = "\t" * self._indent_level if indent else "" if assembly_format == "peachpy": return text + str(self) elif assembly_format == "nasm": return text + str(self) elif assembly_format == "gas": return text + str(self) elif assembly_format == "go": if self.go_name: from peachpy.util import is_int if self.name == "CMP" and is_int(self.operands[1]): # CMP instruction with an immediate operand has operands in normal (non-reversed) order return text + str(self.go_name) + " " + \ ", ".join(format_operand(op, assembly_format) for op in self.operands) elif self.operands: return text + str(self.go_name) + " " + \ ", ".join(format_operand(op, assembly_format) for op in reversed(self.operands)) else: return text + str(self.go_name) else: return text + "; ".join( ["BYTE $0x%02X" % b for b in self.encode()]) + " // " + str(self)
def format(self, assembly_format, indent): from peachpy.x86_64.operand import format_operand text = "\t" * self._indent_level if indent else "" if assembly_format == "peachpy": return text + str(self) elif assembly_format == "nasm": return text + str(self) elif assembly_format == "gas": return text + str(self) elif assembly_format == "go": if self.go_name: if self.operands: out_operands = [ op for (is_out, op) in zip(self.out_operands, self.operands) if is_out ] in_operands = [ op for (is_out, op) in zip(self.out_operands, self.operands) if not is_out ] return text + str(self.go_name) + " " + \ ", ".join(map(lambda op: format_operand(op, assembly_format), in_operands + out_operands)) else: return text + str(self.go_name) else: return text + "; ".join( map(lambda b: "BYTE $0x%02X" % b, self.encode())) + " // " + str(self)
def format(self, assembly_format, indent): assert assembly_format in {"peachpy", "go"}, \ "Supported assembly formats are 'peachpy' and 'go'" text = "\t" if indent else "" if assembly_format == "go": from peachpy.x86_64.registers import MMXRegister, XMMRegister from peachpy.x86_64.operand import format_operand if isinstance(self.operands[0], MMXRegister): mov_name = {4: "MOVD", 8: "MOVQ"}[self.destination_size] elif isinstance(self.operands[0], XMMRegister): if self.destination_type.is_floating_point: mov_name = { 4: "MOVSS", 8: "MOVSD" }[self.destination_size] else: mov_name = { 4: "MOVD", 8: "MOVQ" }[self.destination_size] else: mov_name = { 1: "MOVB", 2: "MOVW", 4: "MOVL", 8: "MOVQ" }[self.destination_size] return text + "%s %s, ret+%d(FP)" % \ (mov_name, format_operand(self.operands[0], "go"), self.destination_offset) else: return text + str(self)
def format(self, assembly_format, indent=False, line_number=None): from peachpy.x86_64.operand import format_operand text = "\t" * self._indent_level if indent else "" if assembly_format == "peachpy": return text + str(self) elif assembly_format == "nasm": return text + str(self) elif assembly_format == "gas": if self.operands: from peachpy.x86_64.pseudo import Label if line_number is not None and len( self.operands) == 1 and isinstance( self.operands[0], Label ) and self.operands[0].line_number is not None: label = self.operands[0] return "{indent}{mnemonic} {label_line}{direction} # {label_name}".format( indent=text, mnemonic=self.gas_name, label_line=self.operands[0].line_number, label_name=str(self.operands[0]), direction="b" if self.operands[0].line_number < line_number else "f") else: return text + self.gas_name + " " + ", ".join( format_operand(op, assembly_format) for op in reversed(self.operands)) else: return text + self.gas_name elif assembly_format == "go": if self.go_name: from peachpy.util import is_int if self.name == "CMP" and is_int(self.operands[1]): # CMP instruction with an immediate operand has operands in normal (non-reversed) order return text + str(self.go_name) + " " + \ ", ".join(format_operand(op, assembly_format) for op in self.operands) elif self.operands: return text + str(self.go_name) + " " + \ ", ".join(format_operand(op, assembly_format) for op in reversed(self.operands)) else: return text + str(self.go_name) else: return text + "; ".join( map(lambda b: "BYTE $0x%02X" % b, self.encode())) + " // " + str(self)
def format(self, assembly_format, indent): from peachpy.x86_64.operand import format_operand text = "\t" * self._indent_level if indent else "" if assembly_format == "peachpy": return text + str(self) elif assembly_format == "nasm": return text + str(self) elif assembly_format == "gas": return text + str(self) elif assembly_format == "go": if self.go_name: if self.operands: out_operands = [op for (is_out, op) in zip(self.out_operands, self.operands) if is_out] in_operands = [op for (is_out, op) in zip(self.out_operands, self.operands) if not is_out] return text + str(self.go_name) + " " + \ ", ".join(map(lambda op: format_operand(op, assembly_format), in_operands + out_operands)) else: return text + str(self.go_name) else: return text + "; ".join(map(lambda b: "BYTE $0x%02X" % b, self.encode())) + " // " + str(self)
def format(self, assembly_format, indent): assert assembly_format in {"peachpy", "go"}, \ "Supported assembly formats are 'peachpy' and 'go'" text = "\t" if indent else "" if assembly_format == "go": from peachpy.x86_64.registers import MMXRegister, XMMRegister from peachpy.x86_64.operand import format_operand if isinstance(self.operands[0], MMXRegister): mov_name = { 4: "MOVD", 8: "MOVQ" }[self.destination_size] elif isinstance(self.operands[0], XMMRegister): if self.destination_type.is_floating_point: mov_name = { 4: "MOVSS", 8: "MOVSD" }[self.destination_size] else: mov_name = { 4: "MOVD", 8: "MOVQ" }[self.destination_size] else: mov_name = { 1: "MOVB", 2: "MOVW", 4: "MOVL", 8: "MOVQ" }[self.destination_size] return text + "%s %s, ret+%d(FP)" % \ (mov_name, format_operand(self.operands[0], "go"), self.destination_offset) else: return text + str(self)