diff --git a/libIRDB/include/core/instruction.hpp b/libIRDB/include/core/instruction.hpp index 3ec134ba2a3216e3b701dbea3990cc8a543a6986..bc2acd7e26007cac5b9632878c428103140c87a6 100644 --- a/libIRDB/include/core/instruction.hpp +++ b/libIRDB/include/core/instruction.hpp @@ -38,7 +38,7 @@ class Instruction_t : public BaseObj_t void WriteToDB() { assert(0); } std::string WriteToDB(File_t *fid, db_id_t newid, bool p_withHeader); - int Disassemble(DISASM &d); + int Disassemble(DISASM &d) const; std::string getDisassembly(); bool Assemble(std::string assembly); diff --git a/libIRDB/src/core/fileir.cpp b/libIRDB/src/core/fileir.cpp index 9535dcdef7bcdf4c1aaf1253e7b2bb33600b0941..60ea3115dcf90bbb29114a86789fb8d1d093bbdb 100644 --- a/libIRDB/src/core/fileir.cpp +++ b/libIRDB/src/core/fileir.cpp @@ -460,6 +460,36 @@ void FileIR_t::WriteToDB() q=string(""); for(std::set<Instruction_t*>::const_iterator i=insns.begin(); i!=insns.end(); ++i) { + Instruction_t const * const insnp=*i; + DISASM disasm; + insnp->Disassemble(disasm); + + // we have a few new requirements for instructions that doesn't correspond to original program insns. + if(insnp->GetOriginalAddressID() == NOT_IN_DATABASE) + { + + if(insnp->GetFallthrough()==NULL && + disasm.Instruction.BranchType!=RetType && disasm.Instruction.BranchType!=JmpType ) + { + // instructions that fall through are required to either specify a fallthrough that's + // in the IRDB, or have an associated "old" instruction. + // without these bits of information, the new instruction can't possibly execute correctly. + // and we won't have the information necessary to emit spri. + assert(0); + abort(); + } + if(insnp->GetTarget()==NULL && disasm.Instruction.BranchType!=0 && + disasm.Instruction.BranchType!=RetType ) + { + // instructions that jump are required to either specify a target that's + // in the IRDB, or have an associated "old" instruction. + // without these bits of information, the new instruction can't possibly execute correctly. + // and we won't have the information necessary to emit spri. + assert(0); + abort(); + } + } + q+=(*i)->WriteToDB(fileptr,j,withHeader); withHeader = false; if(q.size()>1024*1024) diff --git a/libIRDB/src/core/instruction.cpp b/libIRDB/src/core/instruction.cpp index be3678efd691da52e68630b5ac0dd5e76ba19b6f..6c8c58a1935591eedb31c57ae0da415ab8813b34 100644 --- a/libIRDB/src/core/instruction.cpp +++ b/libIRDB/src/core/instruction.cpp @@ -48,7 +48,8 @@ Instruction_t::Instruction_t(db_id_t id, target=NULL; } -int Instruction_t::Disassemble(DISASM &disasm){ +int Instruction_t::Disassemble(DISASM &disasm) const +{ memset(&disasm, 0, sizeof(DISASM));