From 0fbf33915ec02413c745eeb5da30e724c3535525 Mon Sep 17 00:00:00 2001
From: jdh8d <jdh8d@git.zephyr-software.com>
Date: Fri, 6 Dec 2013 19:16:31 +0000
Subject: [PATCH] Former-commit-id: d3e65b80e2c6e5afa68d2a1ac94b27274d26ca78

---
 libIRDB/include/core/instruction.hpp |  2 +-
 libIRDB/src/core/fileir.cpp          | 30 ++++++++++++++++++++++++++++
 libIRDB/src/core/instruction.cpp     |  3 ++-
 3 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/libIRDB/include/core/instruction.hpp b/libIRDB/include/core/instruction.hpp
index 3ec134ba2..bc2acd7e2 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 9535dcdef..60ea3115d 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 be3678efd..6c8c58a19 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));
   
-- 
GitLab