def disasm_format(out, isa, dialect, data, opt_addr=False, opt_raw=False, opt_cfmt=False): for idx in xrange(len(data)//16): inst = struct.unpack(b'<IIII', data[idx*16:idx*16+16]) if opt_addr: if opt_cfmt: out.write('/* ') out.write('%3i: ' % idx) if opt_cfmt: out.write('*/ ') if opt_cfmt: out.write('0x%08x, 0x%08x, 0x%08x, 0x%08x, ' % inst) elif opt_raw: out.write('%08x %08x %08x %08x ' % inst) warnings = [] parsed = disassemble(isa, dialect, inst, warnings) text = format_instruction(isa, dialect, parsed) if opt_cfmt: out.write('/* ') out.write(text) if opt_cfmt: out.write(' */') if warnings: out.write('\t; ') out.write(' '.join(warnings)) out.write('\n')
def generate_code(self): rv = [] for inst in self.instructions: warnings = [] if inst.addr is not None: # fill in labels try: addr = AddrOperand(self.labels[inst.addr.addr]) except LookupError: self.errors.append((inst.linenr, 'Unknown label ' + inst.addr.addr)) addr = AddrOperand(0) # dummy inst = inst._replace(addr=addr) inst_out = assemble(self.isa, inst, warnings) rv.append(inst_out) dis_i = disassemble(self.isa, inst_out, warnings) if not compare_inst(inst, dis_i, warnings): # Assembly did not match disassembly, print details warnings.append('%08x %08x %08x %08x %s' % ( inst_out[0], inst_out[1], inst_out[2], inst_out[3], format_instruction(self.isa, dis_i))) warnings.append(' orig : %s' % (self.source[inst.linenr-1])) for warning in warnings: self.errors.append((inst.linenr, warning)) if self.errors: return None return rv
def disasm_format(out, isa, dialect, data, opt_addr=False, opt_raw=False, opt_cfmt=False): for idx in xrange(len(data) // 16): inst = struct.unpack(b'<IIII', data[idx * 16:idx * 16 + 16]) if opt_addr: if opt_cfmt: out.write('/* ') out.write('%3i: ' % idx) if opt_cfmt: out.write('*/ ') if opt_cfmt: out.write('0x%08x, 0x%08x, 0x%08x, 0x%08x, ' % inst) elif opt_raw: out.write('%08x %08x %08x %08x ' % inst) warnings = [] parsed = disassemble(isa, dialect, inst, warnings) text = format_instruction(isa, dialect, parsed) if opt_cfmt: out.write('/* ') out.write(text) if opt_cfmt: out.write(' */') if warnings: out.write('\t; ') out.write(' '.join(warnings)) out.write('\n')
def generate_code(self): rv = [] for inst in self.instructions: warnings = [] # fill in labels in addr operand if inst.addr is not None and isinstance(inst.addr.addr, (str,unicode)): try: addr = AddrOperand(self.labels[inst.addr.addr]) except LookupError: self.errors.append((inst.linenr, 'Unknown label ' + inst.addr.addr)) addr = AddrOperand(0) # dummy inst = inst._replace(addr=addr) # fill in labels in other operands for i,src in enumerate(inst.src): if isinstance(src, SrcOperandImm) and isinstance(src.imm, (str,unicode)): inst.src[i] = src._replace(imm=self.labels[src.imm]) inst_out = assemble(self.isa, self.dialect, inst, warnings) rv.append(inst_out) # sanity check: disassemble and see if the instruction matches dis_i = disassemble(self.isa, self.dialect, inst_out, warnings) if not compare_inst(inst, dis_i, warnings): # Assembly did not match disassembly, print details warnings.append('%08x %08x %08x %08x %s' % ( inst_out[0], inst_out[1], inst_out[2], inst_out[3], format_instruction(self.isa, dis_i))) warnings.append(' orig : %s' % (self.source[inst.linenr-1])) for warning in warnings: self.errors.append((inst.linenr, warning)) if self.errors: return None return rv
def generate_code(self): rv = [] for inst in self.instructions: warnings = [] if inst.addr is not None: # fill in labels try: addr = AddrOperand(self.labels[inst.addr.addr]) except LookupError: self.errors.append( (inst.linenr, 'Unknown label ' + inst.addr.addr)) addr = AddrOperand(0) # dummy inst = inst._replace(addr=addr) inst_out = assemble(self.isa, inst, warnings) rv.append(inst_out) # sanity check: disassemble and see if the instruction matches dis_i = disassemble(self.isa, inst_out, warnings) if not compare_inst(inst, dis_i, warnings): # Assembly did not match disassembly, print details warnings.append( '%08x %08x %08x %08x %s' % (inst_out[0], inst_out[1], inst_out[2], inst_out[3], format_instruction(self.isa, dis_i))) warnings.append(' orig : %s' % (self.source[inst.linenr - 1])) for warning in warnings: self.errors.append((inst.linenr, warning)) if self.errors: return None return rv
def disassemble(self, out, stype, mem, count): out.write('[%s code]:\n' % stype) for idx in xrange(count): inst = (int(mem[idx*4+0]), int(mem[idx*4+1]), int(mem[idx*4+2]), int(mem[idx*4+3])) out.write(' %3x: ' % idx) out.write('%08x %08x %08x %08x ' % inst) warnings = [] parsed = disassemble(self.isa, inst, warnings) text = format_instruction(self.isa, parsed) out.write(text) if warnings: out.write(' ; ') out.write(' '.join(warnings)) # XXX show current values when loading from uniforms out.write('\n')
def generate_code(self): rv = [] for inst in self.instructions: warnings = [] # fill in labels in addr operand if inst.addr is not None and isinstance(inst.addr.addr, (str, unicode)): try: addr = AddrOperand(self.labels[inst.addr.addr]) except LookupError: self.errors.append( (inst.linenr, 'Unknown label ' + inst.addr.addr)) addr = AddrOperand(0) # dummy inst = inst._replace(addr=addr) # fill in labels in other operands for i, src in enumerate(inst.src): if isinstance(src, SrcOperandImm) and isinstance( src.imm, (str, unicode)): inst.src[i] = src._replace(imm=self.labels[src.imm]) inst_out = assemble(self.isa, self.dialect, inst, warnings) rv.append(inst_out) # sanity check: disassemble and see if the instruction matches dis_i = disassemble(self.isa, self.dialect, inst_out, warnings) if not compare_inst(inst, dis_i, warnings): # Assembly did not match disassembly, print details warnings.append( '%08x %08x %08x %08x %s' % (inst_out[0], inst_out[1], inst_out[2], inst_out[3], format_instruction(self.isa, dis_i))) warnings.append(' orig : %s' % (self.source[inst.linenr - 1])) for warning in warnings: self.errors.append((inst.linenr, warning)) if self.errors: return None return rv
def main(): args = parse_arguments() out = sys.stdout isa = parse_rng_file(args.isa_file) with open(args.input, 'rb') as f: data = f.read() if len(data)%16: print >>sys.stderr,'Size of code must be multiple of 16.' exit(1) for idx in xrange(len(data)//16): inst = struct.unpack(b'<IIII', data[idx*16:idx*16+16]) if args.addr: out.write('%3x: ' % idx) if args.raw: out.write('%08x %08x %08x %08x ' % inst) warnings = [] parsed = disassemble(isa, inst, warnings) text = format_instruction(isa, parsed) out.write(text) if warnings: out.write(' ; ') out.write(' '.join(warnings)) out.write('\n')
def main(): args = parse_arguments() out = sys.stdout isa = parse_rng_file(args.isa_file) with open(args.input, 'rb') as f: data = f.read() if len(data) % 16: print >> sys.stderr, 'Size of code must be multiple of 16.' exit(1) for idx in xrange(len(data) // 16): inst = struct.unpack(b'<IIII', data[idx * 16:idx * 16 + 16]) if args.addr: out.write('%3x: ' % idx) if args.raw: out.write('%08x %08x %08x %08x ' % inst) warnings = [] parsed = disassemble(isa, inst, warnings) text = format_instruction(isa, parsed) out.write(text) if warnings: out.write(' ; ') out.write(' '.join(warnings)) out.write('\n')