From b9a3b32e648c9031da56303505a6e42f38e27acc Mon Sep 17 00:00:00 2001
From: clc5q <clc5q@git.zephyr-software.com>
Date: Tue, 15 Apr 2008 18:56:09 +0000
Subject: [PATCH] o_mem type has no base register ever.

---
 SMPInstr.cpp | 33 ++++++++++++++++++++++++++++-----
 1 file changed, 28 insertions(+), 5 deletions(-)

diff --git a/SMPInstr.cpp b/SMPInstr.cpp
index 4304cdaa..99ce1556 100644
--- a/SMPInstr.cpp
+++ b/SMPInstr.cpp
@@ -637,7 +637,8 @@ void SMPInstr::Analyze(void) {
 // Fill the Defs and Uses private data members.
 void SMPInstr::BuildSMPDefUseLists(void) {
 	size_t OpNum;
-	
+	bool DebugFlag = (0x804837b == this->GetAddr());
+
 	this->Defs.clear();
 	this->Uses.clear();
 
@@ -646,6 +647,11 @@ void SMPInstr::BuildSMPDefUseLists(void) {
 		if (this->features & DefMacros[OpNum]) { // DEF
 			op_t TempOp = this->SMPcmd.Operands[OpNum];
 			if (MDKnownOperandType(TempOp)) {
+				if (DebugFlag) {
+					msg("DEBUG: Setting DEF for: ");
+					PrintOperand(TempOp);
+					msg("\n");
+				}
 				if (o_reg == TempOp.type) {
 					// We want to map AH, AL, and AX to EAX, etc. throughout our data flow
 					//  analysis and type inference systems.
@@ -672,6 +678,11 @@ void SMPInstr::BuildSMPDefUseLists(void) {
 		if (this->features & UseMacros[OpNum]) { // USE
 			op_t TempOp = this->SMPcmd.Operands[OpNum];
 			if (MDKnownOperandType(TempOp)) {
+				if (DebugFlag) {
+					msg("DEBUG: Setting USE for: ");
+					PrintOperand(TempOp);
+					msg("\n");
+				}
 				if (o_reg == TempOp.type) {
 					// We want to map AH, AL, and AX to EAX, etc. throughout our data flow
 					//  analysis and type inference systems.
@@ -720,11 +731,19 @@ void SMPInstr::MDFixupDefUseLists(void) {
 	//  care whether we are dealing with a memory destination operand or source
 	//  operand, because register USEs, not DEFs, happen within the addressing expressions.
 	size_t OpNum;
-	bool DebugFlag = (this->GetAddr() == 0x80482b8);
+	bool DebugFlag = (this->GetAddr() == 0x804837b);
+	if (DebugFlag) {
+		msg("DEBUG: Fixing up DEF-USE lists for debug location\n");
+		this->Dump();
+	}
+
 	for (OpNum = 0; OpNum < UA_MAXOP; ++OpNum) {
 		op_t Opnd = SMPcmd.Operands[OpNum];
 		if ((Opnd.type == o_phrase) || (Opnd.type == o_displ) || (Opnd.type == o_mem)) {
 			if (Opnd.hasSIB) {
+				if (DebugFlag) {
+					msg("DEBUG: hasSIB\n");
+				}
 				int BaseReg = sib_base(Opnd);
 				short IndexReg = sib_index(Opnd);
 				if (R_none != BaseReg) {
@@ -769,11 +788,11 @@ void SMPInstr::MDFixupDefUseLists(void) {
 				BaseOpnd.reg = BaseReg;
 				BaseOpnd.hasSIB = 0;
 				BaseOpnd.set_showed();
-				if (BaseOpnd.is_reg(R_bp) && (Opnd.type == o_mem)) {
-					if (DebugFlag) msg("EBP base reg ignored at %x\n", this->GetAddr());
+				if (Opnd.type == o_mem) {
+					if (!BaseOpnd.is_reg(0)) msg("base reg %d ignored at %x\n", 
+						BaseOpnd.reg, this->GetAddr());
 				}
 				else {
-					if (DebugFlag) msg("base reg %d not ignored at %x\n", BaseReg, this->GetAddr());
 					// We want to map AH, AL, and AX to EAX, etc. throughout our data flow
 					//  analysis and type inference systems.
 					BaseOpnd.reg = MDCanonicalizeSubReg(BaseOpnd.reg);
@@ -923,6 +942,10 @@ void SMPInstr::MDFixupDefUseLists(void) {
 	}
 #endif
 
+	if (DebugFlag) {
+		msg("DEBUG after MDFixupDefuseLists:\n");
+		this->Dump();
+	}
 	return;
 } // end of SMPInstr::MDFixupDefUseLists()
 
-- 
GitLab