def disassemClicked(self): code = self.binary.toPlainText() tokens = sap1.tokenize(code) asm = sap1.disassemble(tokens) if type(asm) == str: self.errorMessage.setText(asm) self.errorMessage.show() self.errorMessage.setStyleSheet("color: rgb(200,10,10);") self.assembly.setPlainText("") else: self.errorMessage.show() self.errorMessage.setStyleSheet("color: black") self.errorMessage.setText("Assembling...") self.outputAsm(asm) self.errorMessage.setText("Done.")
next = stack.pop() if "Code" in next.types: interpret( code, next.value, fail=fail_continuation ) elif "Lambda" in next.types: next.value( fail=fail_continuation ) else: fail_continuation() elif inst[0] == "FAIL": fail_continuation() elif inst[0] == "RETURN": return ip += 1 if __name__ == "__main__": import sys for path in sys.argv[1:]: openfile = open(path) data = openfile.read() openfile.close() if not data.startswith( assembler.magic_number ): data = assembler.assemble( data ) code, jumptable = assembler.disassemble( data ) for name, addr in jumptable.iteritems(): namespace[name] = Value( types=["Code"], value=addr ) interpret( code, ip=jumptable["start"] )
return " popd eax\n mov eax, [eax]\n pushd eax\n" elif instr == "CALL": return " popd eax\n call eax\n" elif instr == "INT": return " pushd %s\n" % args[0] print "Unknown instruction:", instr raise Exception def ProduceCode( code ): output = "" for instruction in code: output += ProduceInstructionCode( instruction ) return output if __name__ == "__main__": import sys for path in sys.argv[1:]: openfile = open(path) data = openfile.read() openfile.close() code = assembler.disassemble( assembler.assemble( data ) ) print code asm = ProduceCode( code ) print asm