More work on LLOperand,
Adding accessors for src operand to LLIns
This commit is contained in:
parent
26b9ab1e00
commit
61392772e1
@ -185,7 +185,6 @@ struct LLOperand
|
||||
proc.proc=0;
|
||||
proc.cb=0;
|
||||
}
|
||||
uint32_t op() const {return opz;}
|
||||
int64_t getImm2() const {return opz;}
|
||||
void SetImmediateOp(uint32_t dw)
|
||||
{
|
||||
@ -221,7 +220,7 @@ public:
|
||||
uint8_t numBytes; /* Number of bytes this instr */
|
||||
uint32_t label; /* offset in image (20-bit adr) */
|
||||
LLOperand dst; /* destination operand */
|
||||
LLOperand src; /* source operand */
|
||||
LLOperand m_src; /* source operand */
|
||||
DU flagDU; /* def/use of flags */
|
||||
struct { /* Case table if op==JMP && !I */
|
||||
int numEntries; /* # entries in case table */
|
||||
@ -248,7 +247,7 @@ public:
|
||||
|
||||
uint32_t GetLlLabel() const { return label;}
|
||||
|
||||
void SetImmediateOp(uint32_t dw) {src.SetImmediateOp(dw);}
|
||||
void SetImmediateOp(uint32_t dw) {m_src.SetImmediateOp(dw);}
|
||||
|
||||
|
||||
bool match(llIcode op)
|
||||
@ -265,11 +264,11 @@ public:
|
||||
}
|
||||
bool match(llIcode op,eReg dest,eReg src_reg)
|
||||
{
|
||||
return (getOpcode()==op)&&(dst.regi==dest)&&(src.regi==src_reg);
|
||||
return (getOpcode()==op)&&(dst.regi==dest)&&(m_src.regi==src_reg);
|
||||
}
|
||||
bool match(eReg dest,eReg src_reg)
|
||||
{
|
||||
return (dst.regi==dest)&&(src.regi==src_reg);
|
||||
return (dst.regi==dest)&&(m_src.regi==src_reg);
|
||||
}
|
||||
bool match(eReg dest)
|
||||
{
|
||||
@ -300,6 +299,20 @@ public:
|
||||
caseTbl.numEntries=0;
|
||||
setOpcode(0);
|
||||
}
|
||||
const LLOperand &src() const {return m_src;}
|
||||
LLOperand &src() {return m_src;}
|
||||
void replaceSrc(const LLOperand &with)
|
||||
{
|
||||
m_src = with;
|
||||
}
|
||||
void replaceSrc(eReg r)
|
||||
{
|
||||
m_src = LLOperand::CreateReg2(r);
|
||||
}
|
||||
void replaceSrc(int64_t r)
|
||||
{
|
||||
m_src = LLOperand::CreateImm2(r);
|
||||
}
|
||||
void replaceDst(const LLOperand &with)
|
||||
{
|
||||
dst = with;
|
||||
@ -309,6 +322,8 @@ public:
|
||||
dst = LLOperand::CreateReg2(r);
|
||||
}
|
||||
ICODE *m_link;
|
||||
const LLOperand * get(opLoc sd) const { return (sd == SRC) ? &src() : &dst; }
|
||||
LLOperand * get(opLoc sd) { return (sd == SRC) ? &src() : &dst; }
|
||||
};
|
||||
|
||||
/* Icode definition: LOW_LEVEL and HIGH_LEVEL */
|
||||
|
||||
12
src/ast.cpp
12
src/ast.cpp
@ -255,11 +255,11 @@ COND_EXPR *COND_EXPR::idLong(LOCAL_ID *localId, opLoc sd, iICODE pIcode, hlFirst
|
||||
{
|
||||
newExp->expr.ident.idType = CONSTANT;
|
||||
if (f == HIGH_FIRST)
|
||||
newExp->expr.ident.idNode.kte.kte = (pIcode->ll()->src.op() << 16) +
|
||||
atOffset->ll()->src.op();
|
||||
newExp->expr.ident.idNode.kte.kte = (pIcode->ll()->src().getImm2() << 16) +
|
||||
atOffset->ll()->src().getImm2();
|
||||
else /* LOW_FIRST */
|
||||
newExp->expr.ident.idNode.kte.kte =
|
||||
(atOffset->ll()->src.op() << 16)+ pIcode->ll()->src.op();
|
||||
(atOffset->ll()->src().getImm2() << 16)+ pIcode->ll()->src().getImm2();
|
||||
newExp->expr.ident.idNode.kte.size = 4;
|
||||
}
|
||||
/* Save it as a long expression (reg, stack or glob) */
|
||||
@ -337,7 +337,7 @@ COND_EXPR *COND_EXPR::id(const LLInst &ll_insn, opLoc sd, Function * pProc, iICO
|
||||
|
||||
int idx; /* idx into pIcode->localId table */
|
||||
|
||||
const LLOperand &pm((sd == SRC) ? ll_insn.src : ll_insn.dst);
|
||||
const LLOperand &pm((sd == SRC) ? ll_insn.src() : ll_insn.dst);
|
||||
|
||||
if ( ((sd == DST) && ll_insn.testFlags(IM_DST)) or
|
||||
((sd == SRC) && ll_insn.testFlags(IM_SRC)) or
|
||||
@ -356,7 +356,7 @@ COND_EXPR *COND_EXPR::id(const LLInst &ll_insn, opLoc sd, Function * pProc, iICO
|
||||
}
|
||||
|
||||
else if ((sd == SRC) && ll_insn.testFlags(I)) /* constant */
|
||||
newExp = COND_EXPR::idKte (ll_insn.src.op(), 2);
|
||||
newExp = COND_EXPR::idKte (ll_insn.src().getImm2(), 2);
|
||||
else if (pm.regi == rUNDEF) /* global variable */
|
||||
newExp = GlobalVariable::Create(pm.segValue, pm.off);
|
||||
else if ( pm.isReg() ) /* register */
|
||||
@ -426,7 +426,7 @@ COND_EXPR *COND_EXPR::id(const LLInst &ll_insn, opLoc sd, Function * pProc, iICO
|
||||
/* Returns the identifier type */
|
||||
condId ICODE::idType(opLoc sd)
|
||||
{
|
||||
LLOperand &pm((sd == SRC) ? ll()->src : ll()->dst);
|
||||
LLOperand &pm(*ll()->get(sd));
|
||||
|
||||
if ((sd == SRC) && ll()->testFlags(I))
|
||||
return (CONSTANT);
|
||||
|
||||
@ -150,16 +150,17 @@ static const char *intOthers[] = {
|
||||
* string s. */
|
||||
void LLInst::writeIntComment (std::ostringstream &s)
|
||||
{
|
||||
uint32_t src_immed=src().getImm2();
|
||||
s<<"\t/* ";
|
||||
if (src.op() == 0x21)
|
||||
if (src_immed == 0x21)
|
||||
{
|
||||
s <<int21h[dst.off];
|
||||
}
|
||||
else if (src.op() > 0x1F && src.op() < 0x2F)
|
||||
else if (src_immed > 0x1F && src_immed < 0x2F)
|
||||
{
|
||||
s <<intOthers[src.op() - 0x20];
|
||||
s <<intOthers[src_immed - 0x20];
|
||||
}
|
||||
else if (src.op() == 0x2F)
|
||||
else if (src_immed == 0x2F)
|
||||
{
|
||||
switch (dst.off)
|
||||
{
|
||||
|
||||
@ -95,8 +95,8 @@ static COND_EXPR *srcIdent (const LLInst &ll_insn, Function * pProc, iICODE i, I
|
||||
if (ll_insn.testFlags(I)) /* immediate operand */
|
||||
{
|
||||
if (ll_insn.testFlags(B))
|
||||
return COND_EXPR::idKte (ll_insn.src.op(), 1);
|
||||
return COND_EXPR::idKte (ll_insn.src.op(), 2);
|
||||
return COND_EXPR::idKte (ll_insn.src().getImm2(), 1);
|
||||
return COND_EXPR::idKte (ll_insn.src().getImm2(), 2);
|
||||
}
|
||||
// otherwise
|
||||
return COND_EXPR::id (ll_insn, SRC, pProc, i, duIcode, du);
|
||||
|
||||
@ -110,10 +110,10 @@ void LLInst::findJumpTargets(CIcodeRec &_pc)
|
||||
if (testFlags(I) && ! testFlags(JMP_ICODE) && isJmpInst())
|
||||
{
|
||||
/* Replace the immediate operand with an icode index */
|
||||
iICODE labTgt=_pc.labelSrch(src.op());
|
||||
iICODE labTgt=_pc.labelSrch(src().getImm2());
|
||||
if (labTgt!=_pc.end())
|
||||
{
|
||||
src.SetImmediateOp(labTgt->loc_ip);
|
||||
m_src.SetImmediateOp(labTgt->loc_ip);
|
||||
/* This icode is the target of a jump */
|
||||
labTgt->ll()->setFlags(TARGET);
|
||||
setFlags(JMP_ICODE); /* So its not done twice */
|
||||
@ -307,7 +307,7 @@ void Disassembler::dis1Line(LLInst &inst,int loc_ip, int pass)
|
||||
case iPUSH:
|
||||
if (inst.testFlags(I))
|
||||
{
|
||||
operands_s<<strHex(inst.src.op());
|
||||
operands_s<<strHex(inst.src().getImm2());
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -319,11 +319,11 @@ void Disassembler::dis1Line(LLInst &inst,int loc_ip, int pass)
|
||||
if (inst.testFlags(I))
|
||||
{
|
||||
strDst(operands_s,inst.getFlag(), inst.dst) <<", ";
|
||||
formatRM(operands_s, inst.getFlag(), inst.src);
|
||||
formatRM(operands_s, inst.getFlag(), inst.src());
|
||||
inst.strSrc(operands_s);
|
||||
}
|
||||
else
|
||||
strDst(operands_s,inst.getFlag() | I, inst.src);
|
||||
strDst(operands_s,inst.getFlag() | I, inst.src());
|
||||
break;
|
||||
|
||||
case iLDS: case iLES: case iBOUND:
|
||||
@ -340,9 +340,9 @@ void Disassembler::dis1Line(LLInst &inst,int loc_ip, int pass)
|
||||
|
||||
/* Check if there is a symbol here */
|
||||
{
|
||||
ICODE *lab=pc.GetIcode(inst.src.op());
|
||||
ICODE *lab=pc.GetIcode(inst.src().getImm2());
|
||||
selectTable(Label);
|
||||
if ((inst.src.op() < (uint32_t)numIcode) && /* Ensure in range */
|
||||
if ((inst.src().getImm2() < (uint32_t)numIcode) && /* Ensure in range */
|
||||
readVal(operands_s, lab->ll()->label, 0))
|
||||
{
|
||||
break; /* Symbolic label. Done */
|
||||
@ -352,11 +352,11 @@ void Disassembler::dis1Line(LLInst &inst,int loc_ip, int pass)
|
||||
if (inst.testFlags(NO_LABEL))
|
||||
{
|
||||
//strcpy(p + WID_PTR, strHex(pIcode->ll()->immed.op));
|
||||
operands_s<<strHex(inst.src.op());
|
||||
operands_s<<strHex(inst.src().getImm2());
|
||||
}
|
||||
else if (inst.testFlags(I) )
|
||||
{
|
||||
j = inst.src.op();
|
||||
j = inst.src().getImm2();
|
||||
if (pl.count(j)==0) /* Forward jump */
|
||||
{
|
||||
pl[j] = ++g_lab;
|
||||
@ -374,7 +374,7 @@ void Disassembler::dis1Line(LLInst &inst,int loc_ip, int pass)
|
||||
}
|
||||
else
|
||||
{
|
||||
strDst(operands_s,I, inst.src);
|
||||
strDst(operands_s,I, inst.src());
|
||||
}
|
||||
break;
|
||||
|
||||
@ -385,7 +385,7 @@ void Disassembler::dis1Line(LLInst &inst,int loc_ip, int pass)
|
||||
operands_s<< "near";
|
||||
else
|
||||
operands_s<< " far";
|
||||
operands_s<<" ptr "<<(inst.src.proc.proc)->name;
|
||||
operands_s<<" ptr "<<(inst.src().proc.proc)->name;
|
||||
}
|
||||
else if (inst.getOpcode() == iCALLF)
|
||||
{
|
||||
@ -393,18 +393,18 @@ void Disassembler::dis1Line(LLInst &inst,int loc_ip, int pass)
|
||||
inst.strSrc(operands_s,true);
|
||||
}
|
||||
else
|
||||
strDst(operands_s,I, inst.src);
|
||||
strDst(operands_s,I, inst.src());
|
||||
break;
|
||||
|
||||
case iENTER:
|
||||
operands_s<<strHex(inst.dst.off)<<", ";
|
||||
operands_s<<strHex(inst.src.op());
|
||||
operands_s<<strHex(inst.src().getImm2());
|
||||
break;
|
||||
|
||||
case iRET: case iRETF: case iINT:
|
||||
if (inst.testFlags(I))
|
||||
{
|
||||
operands_s<<strHex(inst.src.op());
|
||||
operands_s<<strHex(inst.src().getImm2());
|
||||
}
|
||||
break;
|
||||
|
||||
@ -415,7 +415,7 @@ void Disassembler::dis1Line(LLInst &inst,int loc_ip, int pass)
|
||||
case iMOVS: case iREP_MOVS:
|
||||
case iINS: case iREP_INS:
|
||||
case iOUTS: case iREP_OUTS:
|
||||
if (inst.src.segOver)
|
||||
if (inst.src().segOver)
|
||||
{
|
||||
bool is_dx_src=(inst.getOpcode() == iOUTS || inst.getOpcode() == iREP_OUTS);
|
||||
if(is_dx_src)
|
||||
@ -427,11 +427,11 @@ void Disassembler::dis1Line(LLInst &inst,int loc_ip, int pass)
|
||||
inst.getOpcode() == iOUTS ||
|
||||
inst.getOpcode() == iREP_OUTS)
|
||||
{
|
||||
operands_s<<Machine_X86::regName(inst.src.segOver); // szWreg[src.segOver-rAX]
|
||||
operands_s<<Machine_X86::regName(inst.src().segOver); // szWreg[src.segOver-rAX]
|
||||
}
|
||||
else
|
||||
{
|
||||
operands_s<<"es:[di], "<<Machine_X86::regName(inst.src.segOver);
|
||||
operands_s<<"es:[di], "<<Machine_X86::regName(inst.src().segOver);
|
||||
}
|
||||
operands_s<<":[si]";
|
||||
}
|
||||
@ -442,21 +442,21 @@ void Disassembler::dis1Line(LLInst &inst,int loc_ip, int pass)
|
||||
break;
|
||||
|
||||
case iXLAT:
|
||||
if (inst.src.segOver)
|
||||
if (inst.src().segOver)
|
||||
{
|
||||
operands_s<<" "<<szPtr[1];
|
||||
operands_s<<Machine_X86::regName(inst.src.segOver)<<":[bx]";
|
||||
operands_s<<Machine_X86::regName(inst.src().segOver)<<":[bx]";
|
||||
}
|
||||
break;
|
||||
|
||||
case iIN:
|
||||
(inst.getFlag() & B)? operands_s<<"al, " : operands_s<< "ax, ";
|
||||
(inst.testFlags(I))? operands_s << strHex(inst.src.op()) : operands_s<< "dx";
|
||||
(inst.testFlags(I))? operands_s << strHex(inst.src().getImm2()) : operands_s<< "dx";
|
||||
break;
|
||||
|
||||
case iOUT:
|
||||
{
|
||||
std::string d1=((inst.testFlags(I))? strHex(inst.src.op()): "dx");
|
||||
std::string d1=((inst.testFlags(I))? strHex(inst.src().getImm2()): "dx");
|
||||
std::string d2=((inst.getFlag() & B) ? ", al": ", ax");
|
||||
operands_s<<d1 << d2;
|
||||
}
|
||||
@ -608,11 +608,11 @@ ostringstream &LLInst::strSrc(ostringstream &os,bool skip_comma)
|
||||
if(false==skip_comma)
|
||||
os<<", ";
|
||||
if (testFlags(I))
|
||||
os<<strHex(src.op());
|
||||
os<<strHex(src().getImm2());
|
||||
else if (testFlags(IM_SRC)) /* level 2 */
|
||||
os<<"dx:ax";
|
||||
else
|
||||
formatRM(os, getFlag(), src);
|
||||
formatRM(os, getFlag(), src());
|
||||
|
||||
return os;
|
||||
}
|
||||
@ -644,7 +644,7 @@ void interactDis(Function * initProc, int initIC)
|
||||
void LLInst::flops(std::ostringstream &out)
|
||||
{
|
||||
char bf[30];
|
||||
uint8_t op = (uint8_t)src.op();
|
||||
uint8_t op = (uint8_t)src().getImm2();
|
||||
|
||||
/* Note that op is set to the escape number, e.g.
|
||||
esc 0x38 is FILD */
|
||||
|
||||
@ -72,7 +72,7 @@ CondJumps:
|
||||
pBB->edges.pop_back();
|
||||
}
|
||||
else
|
||||
pBB->edges[1].ip = ll->src.op();
|
||||
pBB->edges[1].ip = ll->src().getImm2();
|
||||
break;
|
||||
|
||||
case iLOOP: case iLOOPE: case iLOOPNE:
|
||||
@ -94,7 +94,7 @@ CondJumps:
|
||||
//pBB = BB::Create(start, ip, ONE_BRANCH, 1, this);
|
||||
pBB = BB::Create(iStart, pIcode, ONE_BRANCH, 1, this);
|
||||
|
||||
pBB->edges[0].ip = ll->src.op();
|
||||
pBB->edges[0].ip = ll->src().getImm2();
|
||||
}
|
||||
else
|
||||
BB::Create(iStart, pIcode, NOWHERE_NODE, 0, this);
|
||||
@ -103,7 +103,7 @@ CondJumps:
|
||||
|
||||
case iCALLF: case iCALL:
|
||||
{
|
||||
Function * p = ll->src.proc.proc;
|
||||
Function * p = ll->src().proc.proc;
|
||||
if (p)
|
||||
i = ((p->flg) & TERMINATES) ? 0 : 1;
|
||||
else
|
||||
@ -309,7 +309,7 @@ BB *BB::rmJMP(int marker, BB * pBB)
|
||||
{
|
||||
/* We are going around in circles */
|
||||
pBB->nodeType = NOWHERE_NODE;
|
||||
pBB->front().ll()->src.SetImmediateOp(pBB->front().loc_ip);
|
||||
pBB->front().ll()->replaceSrc(LLOperand::CreateImm2(pBB->front().loc_ip));
|
||||
//pBB->front().ll()->src.immed.op = pBB->front().loc_ip;
|
||||
do {
|
||||
pBB = pBB->edges[0].BBptr;
|
||||
|
||||
@ -42,11 +42,11 @@ void ICODE::newCallHl()
|
||||
{
|
||||
type = HIGH_LEVEL;
|
||||
hl()->opcode = HLI_CALL;
|
||||
hl()->call.proc = ll()->src.proc.proc;
|
||||
hl()->call.proc = ll()->src().proc.proc;
|
||||
hl()->call.args = new STKFRAME;
|
||||
|
||||
if (ll()->src.proc.cb != 0)
|
||||
hl()->call.args->cb = ll()->src.proc.cb;
|
||||
if (ll()->src().proc.cb != 0)
|
||||
hl()->call.args->cb = ll()->src().proc.cb;
|
||||
else if(hl()->call.proc)
|
||||
hl()->call.args->cb =hl()->call.proc->cbParam;
|
||||
else
|
||||
@ -117,11 +117,11 @@ bool ICODE::removeDefRegi (eReg regi, int thisDefIdx, LOCAL_ID *locId)
|
||||
HLTYPE LLInst::createCall()
|
||||
{
|
||||
HLTYPE res(HLI_CALL);
|
||||
res.call.proc = src.proc.proc;
|
||||
res.call.proc = src().proc.proc;
|
||||
res.call.args = new STKFRAME;
|
||||
|
||||
if (src.proc.cb != 0)
|
||||
res.call.args->cb = src.proc.cb;
|
||||
if (src().proc.cb != 0)
|
||||
res.call.args->cb = src().proc.cb;
|
||||
else if(res.call.proc)
|
||||
res.call.args->cb =res.call.proc->cbParam;
|
||||
else
|
||||
|
||||
@ -94,3 +94,9 @@ bool LLOperand::isReg() const
|
||||
{
|
||||
return (regi>=rAX) && (regi<=rTMP);
|
||||
}
|
||||
void LLOperand::addProcInformation(int param_count, uint32_t call_conv)
|
||||
{
|
||||
proc.proc->cbParam = (int16_t)param_count;
|
||||
proc.cb = param_count;
|
||||
proc.proc->flg |= call_conv;
|
||||
}
|
||||
|
||||
@ -116,12 +116,12 @@ void Function::findIdioms()
|
||||
case iCALL: case iCALLF:
|
||||
/* Check for library functions that return a long register.
|
||||
* Propagate this result */
|
||||
if (pIcode->ll()->src.proc.proc != 0)
|
||||
if ((pIcode->ll()->src.proc.proc->flg & PROC_ISLIB) &&
|
||||
(pIcode->ll()->src.proc.proc->flg & PROC_IS_FUNC))
|
||||
if (pIcode->ll()->src().proc.proc != 0)
|
||||
if ((pIcode->ll()->src().proc.proc->flg & PROC_ISLIB) &&
|
||||
(pIcode->ll()->src().proc.proc->flg & PROC_IS_FUNC))
|
||||
{
|
||||
if ((pIcode->ll()->src.proc.proc->retVal.type==TYPE_LONG_SIGN)
|
||||
|| (pIcode->ll()->src.proc.proc->retVal.type == TYPE_LONG_UNSIGN))
|
||||
if ((pIcode->ll()->src().proc.proc->retVal.type==TYPE_LONG_SIGN)
|
||||
|| (pIcode->ll()->src().proc.proc->retVal.type == TYPE_LONG_UNSIGN))
|
||||
localId.newLongReg(TYPE_LONG_SIGN, rDX, rAX, pIcode/*ip*/);
|
||||
}
|
||||
|
||||
@ -230,12 +230,12 @@ void Function::bindIcodeOff()
|
||||
pIcode = Icode.begin();
|
||||
|
||||
/* Flag all jump targets for BB construction and disassembly stage 2 */
|
||||
for(ICODE &c : Icode)
|
||||
for(ICODE &c : Icode) // TODO: use filtered here
|
||||
{
|
||||
LLInst *ll=c.ll();
|
||||
if (ll->testFlags(I) && ll->isJmpInst())
|
||||
{
|
||||
iICODE loc=Icode.labelSrch(ll->src.op());
|
||||
iICODE loc=Icode.labelSrch(ll->src().getImm2());
|
||||
if (loc!=Icode.end())
|
||||
loc->ll()->setFlags(TARGET);
|
||||
}
|
||||
@ -253,10 +253,10 @@ void Function::bindIcodeOff()
|
||||
if (ll->testFlags(I) )
|
||||
{
|
||||
uint32_t found;
|
||||
if (! Icode.labelSrch(ll->src.op(), found))
|
||||
if (! Icode.labelSrch(ll->src().getImm2(), found))
|
||||
ll->setFlags( NO_LABEL );
|
||||
else
|
||||
ll->src.SetImmediateOp(found);
|
||||
ll->replaceSrc(LLOperand::CreateImm2(found));
|
||||
|
||||
}
|
||||
else if (ll->testFlags(SWITCH) )
|
||||
|
||||
@ -128,7 +128,7 @@ bool Idiom18::match(iICODE picode)
|
||||
break;
|
||||
case 1: /* register variable */
|
||||
/* Check previous instruction for a MOV */
|
||||
if (m_icodes[0]->ll()->match(iMOV) && (m_icodes[0]->ll()->src.regi == m_icodes[1]->ll()->dst.regi))
|
||||
if (m_icodes[0]->ll()->match(iMOV) && (m_icodes[0]->ll()->src().regi == m_icodes[1]->ll()->dst.regi))
|
||||
{
|
||||
regi = m_icodes[0]->ll()->dst.regi;
|
||||
if ( m_icodes[0]->ll()->dst.isReg() )
|
||||
@ -140,7 +140,7 @@ bool Idiom18::match(iICODE picode)
|
||||
}
|
||||
break;
|
||||
case 2: /* local */
|
||||
if (m_icodes[0]->ll()->match(iMOV) && (m_icodes[0]->ll()->src.off == m_icodes[1]->ll()->dst.off))
|
||||
if (m_icodes[0]->ll()->match(iMOV) && (m_icodes[0]->ll()->src().off == m_icodes[1]->ll()->dst.off))
|
||||
{
|
||||
regi = m_icodes[0]->ll()->dst.regi;
|
||||
if ( m_icodes[0]->ll()->dst.isReg() )
|
||||
@ -273,7 +273,7 @@ bool Idiom20::match(iICODE picode)
|
||||
if (type == 1) /* register variable */
|
||||
{
|
||||
if (m_icodes[1]->ll()->match(iMOV) &&
|
||||
(m_icodes[1]->ll()->src.regi == ll_dest.regi))
|
||||
(m_icodes[1]->ll()->src().regi == ll_dest.regi))
|
||||
{
|
||||
regi = m_icodes[1]->ll()->dst.regi;
|
||||
if ( m_icodes[1]->ll()->dst.isReg() )
|
||||
@ -287,7 +287,7 @@ bool Idiom20::match(iICODE picode)
|
||||
else if (type == 2) /* local */
|
||||
{
|
||||
if ( m_icodes[0]->ll()->match(iMOV) &&
|
||||
(m_icodes[1]->ll()->src.off == ll_dest.off))
|
||||
(m_icodes[1]->ll()->src().off == ll_dest.off))
|
||||
{
|
||||
regi = m_icodes[1]->ll()->dst.regi;
|
||||
if ( m_icodes[1]->ll()->dst.isReg() )
|
||||
|
||||
@ -24,7 +24,7 @@ bool Idiom3::match(iICODE picode)
|
||||
m_icodes[i] = picode++;
|
||||
if ( m_icodes[1]->ll()->testFlags(I) && m_icodes[1]->ll()->match(iADD,rSP))
|
||||
{
|
||||
m_param_count = m_icodes[1]->ll()->src.op();
|
||||
m_param_count = m_icodes[1]->ll()->src().getImm2();
|
||||
return true;
|
||||
}
|
||||
else if (m_icodes[1]->ll()->match(iMOV,rSP,rBP))
|
||||
@ -38,9 +38,7 @@ int Idiom3::action()
|
||||
{
|
||||
if (m_icodes[0]->ll()->testFlags(I) )
|
||||
{
|
||||
m_icodes[0]->ll()->src.proc.proc->cbParam = (int16_t)m_param_count;
|
||||
m_icodes[0]->ll()->src.proc.cb = m_param_count;
|
||||
m_icodes[0]->ll()->src.proc.proc->flg |= CALL_C;
|
||||
m_icodes[0]->ll()->src().addProcInformation(m_param_count,CALL_C);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -98,9 +96,7 @@ int Idiom17::action()
|
||||
{
|
||||
if (m_icodes[0]->ll()->testFlags(I))
|
||||
{
|
||||
m_icodes[0]->ll()->src.proc.proc->cbParam = (int16_t)m_param_count;
|
||||
m_icodes[0]->ll()->src.proc.cb = m_param_count;
|
||||
m_icodes[0]->ll()->src.proc.proc->flg |= CALL_C;
|
||||
m_icodes[0]->ll()->src().addProcInformation(m_param_count,CALL_C);
|
||||
for(size_t idx=1; idx<m_icodes.size(); ++idx)
|
||||
{
|
||||
m_icodes[idx]->invalidate();
|
||||
|
||||
@ -131,7 +131,7 @@ bool Idiom4::match(iICODE pIcode)
|
||||
/* Check for RET(F) immed */
|
||||
if (pIcode->ll()->testFlags(I) )
|
||||
{
|
||||
m_param_count = (int16_t)pIcode->ll()->src.op();
|
||||
m_param_count = (int16_t)pIcode->ll()->src().getImm2();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@ -60,7 +60,7 @@ bool Idiom1::match(iICODE picode)
|
||||
m_icodes.clear();
|
||||
m_min_off = 0;
|
||||
/* PUSH BP as first instruction of procedure */
|
||||
if ( (not picode->ll()->testFlags(I)) && picode->ll()->src.regi == rBP)
|
||||
if ( (not picode->ll()->testFlags(I)) && picode->ll()->src().regi == rBP)
|
||||
{
|
||||
m_icodes.push_back( picode++ ); // insert iPUSH
|
||||
if(picode==m_end)
|
||||
|
||||
@ -35,7 +35,7 @@ bool Idiom14::match(iICODE pIcode)
|
||||
if (m_icodes[1]->ll()->match(iXOR) && not m_icodes[1]->ll()->testFlags(I))
|
||||
{
|
||||
m_regH = m_icodes[1]->ll()->dst.regi;
|
||||
if (m_regH == m_icodes[1]->ll()->src.regi)
|
||||
if (m_regH == m_icodes[1]->ll()->src().getReg2())
|
||||
{
|
||||
if ((m_regL == rAX) && (m_regH == rDX))
|
||||
return true;
|
||||
@ -84,9 +84,9 @@ bool Idiom13::match(iICODE pIcode)
|
||||
if (not m_icodes[0]->ll()->testFlags(I) && (regi >= rAL) && (regi <= rBH))
|
||||
{
|
||||
/* Check for MOV regH, 0 */
|
||||
if (m_icodes[1]->ll()->match(iMOV) && m_icodes[1]->ll()->testFlags(I) && (m_icodes[1]->ll()->src.op() == 0))
|
||||
if (m_icodes[1]->ll()->match(iMOV) && m_icodes[1]->ll()->testFlags(I) && (m_icodes[1]->ll()->src().getImm2() == 0))
|
||||
{
|
||||
if (m_icodes[1]->ll()->dst.regi == (regi + 4)) //TODO: based on distance between AH-AL,BH-BL etc.
|
||||
if (m_icodes[1]->ll()->dst.regi == (regi + 4)) //WARNING: based on distance between AH-AL,BH-BL etc.
|
||||
{
|
||||
m_loaded_reg=(eReg)(regi - rAL + rAX);
|
||||
return true;
|
||||
|
||||
@ -83,7 +83,7 @@ bool Idiom16::match (iICODE picode)
|
||||
if ((regi >= rAX) && (regi < INDEX_BX_SI))
|
||||
{
|
||||
if (m_icodes[1]->ll()->match(iSBB) && m_icodes[2]->ll()->match(iINC))
|
||||
if ((m_icodes[1]->ll()->dst.regi == (m_icodes[1]->ll()->src.regi)) &&
|
||||
if ((m_icodes[1]->ll()->dst.regi == (m_icodes[1]->ll()->src().getReg2())) &&
|
||||
m_icodes[1]->ll()->match((eReg)regi) &&
|
||||
m_icodes[2]->ll()->match((eReg)regi))
|
||||
return true;
|
||||
|
||||
@ -18,9 +18,9 @@ bool Idiom8::match(iICODE pIcode)
|
||||
return false;
|
||||
m_icodes[0]=pIcode++;
|
||||
m_icodes[1]=pIcode++;
|
||||
if (m_icodes[0]->ll()->testFlags(I) && (m_icodes[0]->ll()->src.op() == 1))
|
||||
if (m_icodes[0]->ll()->testFlags(I) && (m_icodes[0]->ll()->src().getImm2() == 1))
|
||||
if ( m_icodes[1]->ll()->match(iRCR,I) &&
|
||||
(m_icodes[1]->ll()->src.op() == 1))
|
||||
(m_icodes[1]->ll()->src().getImm2() == 1))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
@ -62,14 +62,14 @@ bool Idiom15::match(iICODE pIcode)
|
||||
if(distance(pIcode,m_end)<2)
|
||||
return false;
|
||||
/* Match SHL reg, 1 */
|
||||
if (not pIcode->ll()->testFlags(I) or (pIcode->ll()->src.op() != 1))
|
||||
if (not pIcode->ll()->testFlags(I) or (pIcode->ll()->src().getImm2() != 1))
|
||||
return false;
|
||||
m_icodes.clear();
|
||||
regi = pIcode->ll()->dst.regi;
|
||||
m_icodes.push_back(pIcode++);
|
||||
while( (pIcode!=m_end) and
|
||||
pIcode->ll()->match(iSHL,(eReg)regi,I) and
|
||||
(pIcode->ll()->src.op() == 1) )
|
||||
(pIcode->ll()->src().getImm2() == 1) )
|
||||
{
|
||||
m_icodes.push_back(pIcode++);
|
||||
}
|
||||
@ -107,8 +107,8 @@ bool Idiom12::match(iICODE pIcode)
|
||||
return false;
|
||||
m_icodes[0]=pIcode++;
|
||||
m_icodes[1]=pIcode++;
|
||||
if (m_icodes[0]->ll()->testFlags(I) && (m_icodes[0]->ll()->src.op() == 1))
|
||||
if (m_icodes[1]->ll()->match(iRCL,I) && (m_icodes[1]->ll()->src.op() == 1))
|
||||
if (m_icodes[0]->ll()->testFlags(I) && (m_icodes[0]->ll()->src().getImm2() == 1))
|
||||
if (m_icodes[1]->ll()->match(iRCL,I) && (m_icodes[1]->ll()->src().getImm2() == 1))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
@ -146,8 +146,8 @@ bool Idiom9::match(iICODE pIcode)
|
||||
return false;
|
||||
m_icodes[0]=pIcode++;
|
||||
m_icodes[1]=pIcode++;
|
||||
if (m_icodes[0]->ll()->testFlags(I) && (m_icodes[0]->ll()->src.op() == 1))
|
||||
if (m_icodes[1]->ll()->match(iRCR,I) && (m_icodes[1]->ll()->src.op() == 1))
|
||||
if (m_icodes[0]->ll()->testFlags(I) && (m_icodes[0]->ll()->src().getImm2() == 1))
|
||||
if (m_icodes[1]->ll()->match(iRCR,I) && (m_icodes[1]->ll()->src().getImm2() == 1))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -27,12 +27,12 @@ bool Idiom21::match (iICODE picode)
|
||||
return false;
|
||||
|
||||
dst = &m_icodes[0]->ll()->dst;
|
||||
src = &m_icodes[0]->ll()->src;
|
||||
if ((dst->regi == src->regi) && (dst->regi > 0) && (dst->regi < INDEX_BX_SI))
|
||||
src = &m_icodes[0]->ll()->src();
|
||||
if ((dst->regi == src->getReg2()) && (dst->getReg2() > 0) && (dst->getReg2() < INDEX_BX_SI))
|
||||
{
|
||||
if ((dst->regi == rDX) && m_icodes[1]->ll()->match(rAX))
|
||||
if ((dst->getReg2() == rDX) && m_icodes[1]->ll()->match(rAX))
|
||||
return true;
|
||||
if ((dst->regi == rCX) && m_icodes[1]->ll()->match(rBX))
|
||||
if ((dst->getReg2() == rCX) && m_icodes[1]->ll()->match(rBX))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -41,7 +41,7 @@ int Idiom21::action()
|
||||
{
|
||||
COND_EXPR *lhs,*rhs;
|
||||
lhs = COND_EXPR::idLong (&m_func->localId, DST, m_icodes[0],HIGH_FIRST, m_icodes[0], eDEF, m_icodes[1]);
|
||||
rhs = COND_EXPR::idKte (m_icodes[1]->ll()->src.op() , 4);
|
||||
rhs = COND_EXPR::idKte (m_icodes[1]->ll()->src().getImm2() , 4);
|
||||
m_icodes[0]->setAsgn(lhs, rhs);
|
||||
m_icodes[0]->du.use = 0; /* clear register used in iXOR */
|
||||
m_icodes[1]->invalidate();
|
||||
@ -62,7 +62,7 @@ bool Idiom7::match(iICODE picode)
|
||||
LLOperand *dst, *src;
|
||||
m_icode=picode;
|
||||
dst = &picode->ll()->dst;
|
||||
src = &picode->ll()->src;
|
||||
src = &picode->ll()->src();
|
||||
if (dst->regi == 0) /* global variable */
|
||||
{
|
||||
if ((dst->segValue == src->segValue) && (dst->off == src->off))
|
||||
@ -114,9 +114,8 @@ bool Idiom10::match(iICODE pIcode)
|
||||
m_icodes[1]=pIcode++;
|
||||
/* Check OR reg, reg */
|
||||
if (not m_icodes[0]->ll()->testFlags(I) &&
|
||||
(m_icodes[0]->ll()->src.regi > 0) &&
|
||||
(m_icodes[0]->ll()->src.regi < INDEX_BX_SI) &&
|
||||
(m_icodes[0]->ll()->src.regi == m_icodes[0]->ll()->dst.regi))
|
||||
m_icodes[0]->ll()->src().isReg() &&
|
||||
(m_icodes[0]->ll()->src().getReg2() == m_icodes[0]->ll()->dst.getReg2()))
|
||||
if (m_icodes[1]->ll()->match(iJNE)) //.conditionalJump()
|
||||
{
|
||||
return true;
|
||||
@ -127,7 +126,7 @@ bool Idiom10::match(iICODE pIcode)
|
||||
int Idiom10::action()
|
||||
{
|
||||
m_icodes[0]->ll()->set(iCMP,I);
|
||||
m_icodes[0]->ll()->src.SetImmediateOp(0); //TODO: check if proc should be zeroed too
|
||||
m_icodes[0]->ll()->replaceSrc(LLOperand::CreateImm2(0));
|
||||
m_icodes[0]->du.def = 0;
|
||||
m_icodes[0]->du1.numRegsDef = 0;
|
||||
return 2;
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
#include "dcc.h"
|
||||
bool LONGID_TYPE::srcDstRegMatch(iICODE a, iICODE b) const
|
||||
{
|
||||
return (a->ll()->src.getReg2()==l) and (b->ll()->dst.getReg2()==h);
|
||||
return (a->ll()->src().getReg2()==l) and (b->ll()->dst.getReg2()==h);
|
||||
}
|
||||
|
||||
|
||||
@ -279,18 +279,16 @@ int LOCAL_ID::newLong(opLoc sd, iICODE pIcode, hlFirst f, iICODE ix,operDu du, i
|
||||
{
|
||||
size_t idx;
|
||||
LLOperand *pmH, *pmL;
|
||||
// iICODE atOffset(pIcode);
|
||||
// advance(atOffset,off);
|
||||
|
||||
LLInst &p_ll(*pIcode->ll());
|
||||
if (f == LOW_FIRST)
|
||||
{
|
||||
pmL = (sd == SRC) ? &pIcode->ll()->src : &pIcode->ll()->dst;
|
||||
pmH = (sd == SRC) ? &atOffset->ll()->src : &atOffset->ll()->dst;
|
||||
pmL = pIcode->ll()->get(sd);
|
||||
pmH = atOffset->ll()->get(sd);
|
||||
}
|
||||
else /* HIGH_FIRST */
|
||||
{
|
||||
pmH = (sd == SRC) ? &pIcode->ll()->src : &pIcode->ll()->dst;
|
||||
pmL = (sd == SRC) ? &atOffset->ll()->src : &atOffset->ll()->dst;
|
||||
pmL = atOffset->ll()->get(sd);
|
||||
pmH = pIcode->ll()->get(sd);
|
||||
}
|
||||
|
||||
if (pmL->regi == 0) /* global variable */
|
||||
@ -340,8 +338,8 @@ boolT checkLongEq (LONG_STKID_TYPE longId, iICODE pIcode, int i, Function * pPro
|
||||
|
||||
pmHdst = &pIcode->ll()->dst;
|
||||
pmLdst = &atOffset->ll()->dst;
|
||||
pmHsrc = &pIcode->ll()->src;
|
||||
pmLsrc = &atOffset->ll()->src;
|
||||
pmHsrc = &pIcode->ll()->src();
|
||||
pmLsrc = &atOffset->ll()->src();
|
||||
|
||||
if ((longId.offH == pmHdst->off) && (longId.offL == pmLdst->off))
|
||||
{
|
||||
@ -381,8 +379,8 @@ boolT checkLongRegEq (LONGID_TYPE longId, iICODE pIcode, int i,
|
||||
|
||||
pmHdst = &pIcode->ll()->dst;
|
||||
pmLdst = &atOffset->ll()->dst;
|
||||
pmHsrc = &pIcode->ll()->src;
|
||||
pmLsrc = &atOffset->ll()->src;
|
||||
pmHsrc = &pIcode->ll()->src();
|
||||
pmLsrc = &atOffset->ll()->src();
|
||||
|
||||
if ((longId.h == pmHdst->regi) && (longId.l == pmLdst->regi))
|
||||
{
|
||||
|
||||
102
src/parser.cpp
102
src/parser.cpp
@ -135,7 +135,7 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
|
||||
{ /* Synthetic jump */
|
||||
_Icode.type = LOW_LEVEL;
|
||||
ll->set(iJMP,I | SYNTHETIC | NO_OPS);
|
||||
ll->src.SetImmediateOp(labLoc->ll()->GetLlLabel());
|
||||
ll->replaceSrc(LLOperand::CreateImm2(labLoc->ll()->GetLlLabel()));
|
||||
ll->label = SynthLab++;
|
||||
}
|
||||
|
||||
@ -144,21 +144,21 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
|
||||
{
|
||||
/* MOV rTMP, reg */
|
||||
eIcode = ICODE();
|
||||
|
||||
eIcode.type = LOW_LEVEL;
|
||||
eIcode.ll()->set(iMOV,0);
|
||||
eIcode.ll()->dst.regi = rTMP;
|
||||
eIcode.ll()->replaceDst(rTMP);
|
||||
if (ll->testFlags(B) )
|
||||
{
|
||||
eIcode.ll()->setFlags( B );
|
||||
eIcode.ll()->src.regi = rAX;
|
||||
eIcode.setRegDU( rAX, eUSE);
|
||||
eIcode.ll()->replaceSrc(rAX);
|
||||
}
|
||||
else /* implicit dx:ax */
|
||||
{
|
||||
eIcode.ll()->setFlags( IM_SRC );
|
||||
eIcode.setRegDU( rAX, eUSE);
|
||||
eIcode.setRegDU( rDX, eUSE);
|
||||
}
|
||||
eIcode.setRegDU( rAX, eUSE);
|
||||
eIcode.setRegDU( rTMP, eDEF);
|
||||
eIcode.ll()->setFlags( SYNTHETIC );
|
||||
/* eIcode.ll()->label = SynthLab++; */
|
||||
@ -172,7 +172,7 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
|
||||
eIcode = ICODE();
|
||||
eIcode.type = LOW_LEVEL;
|
||||
eIcode.ll()->set(iMOD,0);
|
||||
eIcode.ll()->src = _Icode.ll()->src;
|
||||
eIcode.ll()->replaceSrc(_Icode.ll()->src());
|
||||
eIcode.du = _Icode.du;
|
||||
eIcode.ll()->setFlags( ( ll->getFlag() | SYNTHETIC | IM_TMP_DST) );
|
||||
eIcode.ll()->label = SynthLab++;
|
||||
@ -184,13 +184,14 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
|
||||
eIcode = ICODE();
|
||||
eIcode.type = LOW_LEVEL;
|
||||
eIcode.ll()->set(iMOV,SYNTHETIC);
|
||||
eIcode.ll()->dst.regi = rTMP;
|
||||
eIcode.ll()->src = _Icode.ll()->dst;
|
||||
eIcode.ll()->replaceDst(LLOperand::CreateReg2(rTMP));
|
||||
eIcode.ll()->replaceSrc(_Icode.ll()->dst);
|
||||
eIcode.setRegDU( rTMP, eDEF);
|
||||
if(eIcode.ll()->src.regi)
|
||||
if(eIcode.ll()->src().getReg2())
|
||||
{
|
||||
eIcode.setRegDU( eIcode.ll()->src.regi, eUSE);
|
||||
if((eIcode.ll()->src.regi>=rAL) && (eIcode.ll()->src.regi<=rBH))
|
||||
eReg srcreg=eIcode.ll()->src().getReg2();
|
||||
eIcode.setRegDU( srcreg, eUSE);
|
||||
if((srcreg>=rAL) && (srcreg<=rBH))
|
||||
eIcode.ll()->setFlags( B );
|
||||
}
|
||||
eIcode.ll()->label = _Icode.ll()->label;
|
||||
@ -205,14 +206,14 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
|
||||
eIcode = ICODE();
|
||||
eIcode.type = LOW_LEVEL;
|
||||
eIcode.ll()->set(iMOV,SYNTHETIC);
|
||||
eIcode.ll()->dst = ll->src;
|
||||
eIcode.ll()->replaceDst(ll->src());
|
||||
if(eIcode.ll()->dst.regi)
|
||||
{
|
||||
if((eIcode.ll()->dst.regi>=rAL) && (eIcode.ll()->dst.regi<=rBH))
|
||||
eIcode.ll()->setFlags( B );
|
||||
eIcode.setRegDU( eIcode.ll()->dst.regi, eDEF);
|
||||
}
|
||||
eIcode.ll()->src.regi = rTMP;
|
||||
eIcode.ll()->replaceSrc(rTMP);
|
||||
eIcode.setRegDU( rTMP, eUSE);
|
||||
eIcode.ll()->label = SynthLab++;
|
||||
pIcode = Icode.addIcode(&eIcode);
|
||||
@ -240,12 +241,12 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
|
||||
*/
|
||||
if (ip > 0 && prev.ll()->getOpcode() == iCMP && (prev.ll()->testFlags(I)))
|
||||
{
|
||||
pstate->JCond.immed = (int16_t)prev.ll()->src.op();
|
||||
pstate->JCond.immed = (int16_t)prev.ll()->src().getImm2();
|
||||
if (ll->match(iJA) || ll->match(iJBE) )
|
||||
pstate->JCond.immed++;
|
||||
if (ll->getOpcode() == iJAE || ll->getOpcode() == iJA)
|
||||
pstate->JCond.regi = prev.ll()->dst.regi;
|
||||
fBranch = (boolT)
|
||||
fBranch = (bool)
|
||||
(ll->getOpcode() == iJB || ll->getOpcode() == iJBE);
|
||||
}
|
||||
StCopy = *pstate;
|
||||
@ -288,7 +289,7 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
|
||||
break;
|
||||
|
||||
case iINT:
|
||||
if (ll->src.op() == 0x21 && pstate->f[rAH])
|
||||
if (ll->src().getImm2() == 0x21 && pstate->f[rAH])
|
||||
{
|
||||
int funcNum = pstate->r[rAH];
|
||||
int operand;
|
||||
@ -314,13 +315,13 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
|
||||
global_symbol_table.updateSymType (operand, TypeContainer(TYPE_STR, size));
|
||||
}
|
||||
}
|
||||
else if ((ll->src.op() == 0x2F) && (pstate->f[rAH]))
|
||||
else if ((ll->src().getImm2() == 0x2F) && (pstate->f[rAH]))
|
||||
{
|
||||
Icode.back().ll()->dst.off = pstate->r[rAH];
|
||||
}
|
||||
else /* Program termination: int20h, int27h */
|
||||
done = (boolT)(ll->src.op() == 0x20 ||
|
||||
ll->src.op() == 0x27);
|
||||
done = (boolT)(ll->src().getImm2() == 0x20 ||
|
||||
ll->src().getImm2() == 0x27);
|
||||
if (done)
|
||||
pIcode->ll()->setFlags(TERMINATES);
|
||||
break;
|
||||
@ -336,20 +337,21 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
|
||||
|
||||
case iSHL:
|
||||
if (pstate->JCond.regi == ll->dst.regi)
|
||||
if ((ll->testFlags(I)) && ll->src.op() == 1)
|
||||
if ((ll->testFlags(I)) && ll->src().getImm2() == 1)
|
||||
pstate->JCond.immed *= 2;
|
||||
else
|
||||
pstate->JCond.regi = 0;
|
||||
break;
|
||||
|
||||
case iLEA:
|
||||
if (ll->src.regi == 0) /* direct mem offset */
|
||||
pstate->setState( ll->dst.regi, ll->src.off);
|
||||
if (ll->src().getReg2()== rUNDEF) /* direct mem offset */
|
||||
pstate->setState( ll->dst.getReg2(), ll->src().off);
|
||||
break;
|
||||
|
||||
case iLDS: case iLES:
|
||||
if ((psym = lookupAddr(&ll->src, pstate, 4, eDuVal::USE))
|
||||
/* && (Icode.ll()->flg & SEG_IMMED) */ ) {
|
||||
if ((psym = lookupAddr(&ll->src(), pstate, 4, eDuVal::USE))
|
||||
/* && (Icode.ll()->flg & SEG_IMMED) */ )
|
||||
{
|
||||
offset = LH(&prog.Image[psym->label]);
|
||||
pstate->setState( (ll->getOpcode() == iLDS)? rDS: rES,
|
||||
LH(&prog.Image[psym->label + 2]));
|
||||
@ -390,7 +392,7 @@ boolT Function::process_JMP (ICODE & pIcode, STATE *pstate, CALL_GRAPH * pcallGr
|
||||
{
|
||||
if (pIcode.ll()->getOpcode() == iJMPF)
|
||||
pstate->setState( rCS, LH(prog.Image + pIcode.ll()->label + 3));
|
||||
i = pstate->IP = pIcode.ll()->src.op();
|
||||
uint32_t i = pstate->IP = pIcode.ll()->src().getImm2();
|
||||
if ((long)i < 0)
|
||||
{
|
||||
exit(1);
|
||||
@ -402,17 +404,17 @@ boolT Function::process_JMP (ICODE & pIcode, STATE *pstate, CALL_GRAPH * pcallGr
|
||||
|
||||
/* We've got an indirect JMP - look for switch() stmt. idiom of the form
|
||||
* JMP uint16_t ptr word_offset[rBX | rSI | rDI] */
|
||||
seg = (pIcode.ll()->src.seg)? pIcode.ll()->src.seg: rDS;
|
||||
seg = (pIcode.ll()->src().seg)? pIcode.ll()->src().seg: rDS;
|
||||
|
||||
/* Ensure we have a uint16_t offset & valid seg */
|
||||
if (pIcode.ll()->match(iJMP) and (pIcode.ll()->testFlags(WORD_OFF)) &&
|
||||
pstate->f[seg] &&
|
||||
(pIcode.ll()->src.regi == INDEX_SI ||
|
||||
pIcode.ll()->src.regi == INDEX_DI || /* Idx reg. BX, SI, DI */
|
||||
pIcode.ll()->src.regi == INDEX_BX))
|
||||
(pIcode.ll()->src().regi == INDEX_SI ||
|
||||
pIcode.ll()->src().regi == INDEX_DI || /* Idx reg. BX, SI, DI */
|
||||
pIcode.ll()->src().regi == INDEX_BX))
|
||||
{
|
||||
|
||||
offTable = ((uint32_t)(uint16_t)pstate->r[seg] << 4) + pIcode.ll()->src.off;
|
||||
offTable = ((uint32_t)(uint16_t)pstate->r[seg] << 4) + pIcode.ll()->src().off;
|
||||
|
||||
/* Firstly look for a leading range check of the form:-
|
||||
* CMP {BX | SI | DI}, immed
|
||||
@ -420,7 +422,7 @@ boolT Function::process_JMP (ICODE & pIcode, STATE *pstate, CALL_GRAPH * pcallGr
|
||||
* This is stored in the current state as if we had just
|
||||
* followed a JBE branch (i.e. [reg] lies between 0 - immed).
|
||||
*/
|
||||
if (pstate->JCond.regi == i2r[pIcode.ll()->src.regi-(INDEX_BX_SI+4)])
|
||||
if (pstate->JCond.regi == i2r[pIcode.ll()->src().regi-(INDEX_BX_SI+4)])
|
||||
endTable = offTable + pstate->JCond.immed;
|
||||
else
|
||||
endTable = (uint32_t)prog.cbImage;
|
||||
@ -563,7 +565,7 @@ boolT Function::process_CALL (ICODE & pIcode, CALL_GRAPH * pcallGraph, STATE *ps
|
||||
tgtAddr= LH(&prog.Image[off]) + (uint32_t)(LH(&prog.Image[off+2])) << 4;
|
||||
else
|
||||
tgtAddr= LH(&prog.Image[off]) + (uint32_t)(uint16_t)state.r[rCS] << 4;
|
||||
pIcode.ll()->src.SetImmediateOp( tgtAddr );
|
||||
pIcode.ll()->replaceSrc(LLOperand::CreateImm2( tgtAddr ) );
|
||||
pIcode.ll()->setFlags(I);
|
||||
indirect = true;
|
||||
}
|
||||
@ -572,14 +574,14 @@ boolT Function::process_CALL (ICODE & pIcode, CALL_GRAPH * pcallGraph, STATE *ps
|
||||
if (pIcode.ll()->testFlags(I))
|
||||
{
|
||||
/* Search procedure list for one with appropriate entry point */
|
||||
ilFunction iter = g_proj.findByEntry(pIcode.ll()->src.op());
|
||||
ilFunction iter = g_proj.findByEntry(pIcode.ll()->src().getImm2());
|
||||
|
||||
/* Create a new procedure node and save copy of the state */
|
||||
if ( not g_proj.valid(iter) )
|
||||
{
|
||||
iter = g_proj.createFunction();
|
||||
Function &x(*iter);
|
||||
x.procEntry = pIcode.ll()->src.op();
|
||||
x.procEntry = pIcode.ll()->src().getImm2();
|
||||
LibCheck(x);
|
||||
|
||||
if (x.flg & PROC_ISLIB)
|
||||
@ -587,7 +589,7 @@ boolT Function::process_CALL (ICODE & pIcode, CALL_GRAPH * pcallGraph, STATE *ps
|
||||
/* A library function. No need to do any more to it */
|
||||
pcallGraph->insertCallGraph (this, iter);
|
||||
//iter = (++pProcList.rbegin()).base();
|
||||
last_insn.ll()->src.proc.proc = &x;
|
||||
last_insn.ll()->src().proc.proc = &x;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -605,7 +607,7 @@ boolT Function::process_CALL (ICODE & pIcode, CALL_GRAPH * pcallGraph, STATE *ps
|
||||
|
||||
/* Save machine state in localState, load up IP and CS.*/
|
||||
localState = *pstate;
|
||||
pstate->IP = pIcode.ll()->src.op();
|
||||
pstate->IP = pIcode.ll()->src().getImm2();
|
||||
if (pIcode.ll()->getOpcode() == iCALLF)
|
||||
pstate->setState( rCS, LH(prog.Image + pIcode.ll()->label + 3));
|
||||
x.state = *pstate;
|
||||
@ -627,7 +629,7 @@ boolT Function::process_CALL (ICODE & pIcode, CALL_GRAPH * pcallGraph, STATE *ps
|
||||
else
|
||||
g_proj.callGraph->insertCallGraph (this, iter);
|
||||
|
||||
last_insn.ll()->src.proc.proc = &(*iter); // ^ target proc
|
||||
last_insn.ll()->src().proc.proc = &(*iter); // ^ target proc
|
||||
|
||||
/* return ((p->flg & TERMINATES) != 0); */
|
||||
}
|
||||
@ -641,14 +643,14 @@ static void process_MOV(LLInst & ll, STATE * pstate)
|
||||
PROG &prog(Project::get()->prog);
|
||||
SYM * psym, *psym2; /* Pointer to symbol in global symbol table */
|
||||
uint8_t dstReg = ll.dst.regi;
|
||||
uint8_t srcReg = ll.src.regi;
|
||||
uint8_t srcReg = ll.src().regi;
|
||||
if (dstReg > 0 && dstReg < INDEX_BX_SI)
|
||||
{
|
||||
if (ll.testFlags(I))
|
||||
pstate->setState( dstReg, (int16_t)ll.src.op());
|
||||
pstate->setState( dstReg, (int16_t)ll.src().getImm2());
|
||||
else if (srcReg == 0) /* direct memory offset */
|
||||
{
|
||||
psym = lookupAddr(&ll.src, pstate, 2, eDuVal::USE);
|
||||
psym = lookupAddr(&ll.src(), pstate, 2, eDuVal::USE);
|
||||
if (psym && ((psym->flg & SEG_IMMED) || psym->duVal.val))
|
||||
pstate->setState( dstReg, LH(&prog.Image[psym->label]));
|
||||
}
|
||||
@ -663,20 +665,20 @@ static void process_MOV(LLInst & ll, STATE * pstate)
|
||||
}
|
||||
else if (dstReg == 0) { /* direct memory offset */
|
||||
int size=2;
|
||||
if((ll.src.regi>=rAL)&&(ll.src.regi<=rBH))
|
||||
if((ll.src().regi>=rAL)&&(ll.src().regi<=rBH))
|
||||
size=1;
|
||||
psym = lookupAddr (&ll.dst, pstate, size, eDEF);
|
||||
if (psym && ! (psym->duVal.val)) /* no initial value yet */
|
||||
if (ll.testFlags(I)) /* immediate */
|
||||
{
|
||||
prog.Image[psym->label] = (uint8_t)ll.src.op();
|
||||
prog.Image[psym->label] = (uint8_t)ll.src().getImm2();
|
||||
if(psym->size>1)
|
||||
prog.Image[psym->label+1] = (uint8_t)(ll.src.op()>>8);
|
||||
prog.Image[psym->label+1] = (uint8_t)(ll.src().getImm2()>>8);
|
||||
psym->duVal.val = 1;
|
||||
}
|
||||
else if (srcReg == 0) /* direct mem offset */
|
||||
{
|
||||
psym2 = lookupAddr (&ll.src, pstate, 2, eDuVal::USE);
|
||||
psym2 = lookupAddr (&ll.src(), pstate, 2, eDuVal::USE);
|
||||
if (psym2 && ((psym->flg & SEG_IMMED) || (psym->duVal.val)))
|
||||
{
|
||||
prog.Image[psym->label] = (uint8_t)prog.Image[psym2->label];
|
||||
@ -855,7 +857,7 @@ std::bitset<32> duReg[] = { 0x00,
|
||||
0x40, 0x80, 0x20, 0x08 };
|
||||
|
||||
|
||||
/* Checks which registers where used and updates the du.u flag.
|
||||
/* Checks which registers were used and updates the du.u flag.
|
||||
* Places local variables on the local symbol table.
|
||||
* Arguments: d : SRC or DST icode operand
|
||||
* pIcode: ptr to icode instruction
|
||||
@ -865,7 +867,7 @@ std::bitset<32> duReg[] = { 0x00,
|
||||
* ix : current index into icode array */
|
||||
static void use (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int size, int ix)
|
||||
{
|
||||
LLOperand * pm = (d == SRC)? &pIcode.ll()->src: &pIcode.ll()->dst;
|
||||
const LLOperand * pm = pIcode.ll()->get(d) ;
|
||||
SYM * psym;
|
||||
|
||||
if ( Machine_X86::isMemOff(pm->regi) )
|
||||
@ -892,7 +894,7 @@ static void use (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int
|
||||
pIcode.du.use |= duReg[pm->regi];
|
||||
}
|
||||
|
||||
else if (psym = lookupAddr(pm, pstate, size, eDuVal::USE))
|
||||
else if (psym = lookupAddr(const_cast<LLOperand *>(pm), pstate, size, eDuVal::USE))
|
||||
{
|
||||
setBits (BM_DATA, psym->label, (uint32_t)size);
|
||||
pIcode.ll()->setFlags(SYM_USE);
|
||||
@ -913,7 +915,7 @@ static void use (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int
|
||||
static void def (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int size,
|
||||
int ix)
|
||||
{
|
||||
LLOperand *pm = (d == SRC)? &pIcode.ll()->src: &pIcode.ll()->dst;
|
||||
LLOperand *pm = pIcode.ll()->get(d);
|
||||
SYM * psym;
|
||||
|
||||
if (pm->regi == 0 || pm->regi >= INDEX_BX_SI)
|
||||
@ -965,7 +967,7 @@ static void def (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int
|
||||
static void use_def(opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int cb,
|
||||
int ix)
|
||||
{
|
||||
LLOperand * pm = (d == SRC)? &pIcode.ll()->src: &pIcode.ll()->dst;
|
||||
const LLOperand * pm = pIcode.ll()->get(d);
|
||||
|
||||
use (d, pIcode, pProc, pstate, cb, ix);
|
||||
|
||||
@ -983,7 +985,7 @@ void Function::process_operands(ICODE & pIcode, STATE * pstate)
|
||||
{
|
||||
int ix=Icode.size();
|
||||
int i;
|
||||
int sseg = (pIcode.ll()->src.seg)? pIcode.ll()->src.seg: rDS;
|
||||
int sseg = (pIcode.ll()->src().seg)? pIcode.ll()->src().seg: rDS;
|
||||
int cb = pIcode.ll()->testFlags(B) ? 1: 2;
|
||||
uint32_t Imm = (pIcode.ll()->testFlags(I));
|
||||
|
||||
|
||||
@ -398,10 +398,10 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be
|
||||
switch (pIcode->ll()->getOpcode())
|
||||
{
|
||||
case iMOV:
|
||||
if ((pLocId.id.longId.h == pIcode->ll()->src.regi) &&
|
||||
(pLocId.id.longId.l == next1->ll()->src.regi))
|
||||
if ((pLocId.id.longId.h == pIcode->ll()->src().getReg2()) &&
|
||||
(pLocId.id.longId.l == next1->ll()->src().getReg2()))
|
||||
{
|
||||
pIcode->setRegDU( next1->ll()->src.regi, eUSE);
|
||||
pIcode->setRegDU( next1->ll()->src().getReg2(), eUSE);
|
||||
|
||||
asgn.rhs = COND_EXPR::idLongIdx (loc_ident_idx);
|
||||
asgn.lhs = COND_EXPR::idLong (&this->localId, DST, pIcode,HIGH_FIRST, pIcode, eDEF, next1);
|
||||
@ -413,11 +413,11 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be
|
||||
break;
|
||||
|
||||
case iPUSH:
|
||||
if ((pLocId.id.longId.h == pIcode->ll()->src.regi) &&
|
||||
(pLocId.id.longId.l == next1->ll()->src.regi))
|
||||
if ((pLocId.id.longId.h == pIcode->ll()->src().getReg2()) &&
|
||||
(pLocId.id.longId.l == next1->ll()->src().getReg2()))
|
||||
{
|
||||
asgn.rhs = COND_EXPR::idLongIdx (loc_ident_idx);
|
||||
pIcode->setRegDU( next1->ll()->src.regi, eUSE);
|
||||
pIcode->setRegDU( next1->ll()->src().getReg2(), eUSE);
|
||||
pIcode->setUnary(HLI_PUSH, asgn.rhs);
|
||||
next1->invalidate();
|
||||
}
|
||||
|
||||
@ -412,10 +412,9 @@ static void setAddress(int i, boolT fdst, uint16_t seg, int16_t reg, uint16_t of
|
||||
{
|
||||
LLOperand *pm;
|
||||
|
||||
/* If not to register (i.e. to r/m), and talking about r/m,
|
||||
then this is dest */
|
||||
/* If not to register (i.e. to r/m), and talking about r/m, then this is dest */
|
||||
pm = (!(stateTable[i].flg & TO_REG) == fdst) ?
|
||||
&pIcode->ll()->dst : &pIcode->ll()->src;
|
||||
&pIcode->ll()->dst : &pIcode->ll()->src();
|
||||
|
||||
/* Set segment. A later procedure (lookupAddr in proclist.c) will
|
||||
* provide the value of this segment in the field segValue. */
|
||||
@ -425,8 +424,7 @@ static void setAddress(int i, boolT fdst, uint16_t seg, int16_t reg, uint16_t of
|
||||
}
|
||||
else
|
||||
{ /* no override, check indexed register */
|
||||
if ((reg >= INDEX_BX_SI) && (reg == INDEX_BP_SI ||
|
||||
reg == INDEX_BP_DI || reg == INDEX_BP))
|
||||
if ((reg >= INDEX_BX_SI) && (reg == INDEX_BP_SI || reg == INDEX_BP_DI || reg == INDEX_BP))
|
||||
{
|
||||
pm->seg = rSS; /* indexed on bp */
|
||||
}
|
||||
@ -482,8 +480,8 @@ static void rm(int i)
|
||||
break;
|
||||
}
|
||||
|
||||
if ((stateTable[i].flg & NSP) && (pIcode->ll()->src.regi==rSP ||
|
||||
pIcode->ll()->dst.regi==rSP))
|
||||
if ((stateTable[i].flg & NSP) && (pIcode->ll()->src().getReg2()==rSP ||
|
||||
pIcode->ll()->dst.getReg2()==rSP))
|
||||
pIcode->ll()->setFlags(NOT_HLL);
|
||||
}
|
||||
|
||||
@ -520,7 +518,8 @@ static void segrm(int i)
|
||||
static void regop(int i)
|
||||
{
|
||||
setAddress(i, false, 0, ((int16_t)i & 7) + rAX, 0);
|
||||
pIcode->ll()->dst.regi = pIcode->ll()->src.regi;
|
||||
pIcode->ll()->replaceDst(LLOperand::CreateReg2(pIcode->ll()->src().getReg2()));
|
||||
// pIcode->ll()->dst.regi = pIcode->ll()->src.regi;
|
||||
}
|
||||
|
||||
|
||||
@ -544,13 +543,13 @@ static void axImp(int i)
|
||||
/* Implied AX source */
|
||||
static void axSrcIm (int )
|
||||
{
|
||||
pIcode->ll()->src.regi = rAX;
|
||||
pIcode->ll()->replaceSrc(rAX);//src.regi = rAX;
|
||||
}
|
||||
|
||||
/* Implied AL source */
|
||||
static void alImp (int )
|
||||
{
|
||||
pIcode->ll()->src.regi = rAL;
|
||||
pIcode->ll()->replaceSrc(rAL);//src.regi = rAL;
|
||||
}
|
||||
|
||||
|
||||
@ -620,7 +619,7 @@ static void shift(int i)
|
||||
pIcode->ll()->flagDU.u = uf[REG(*pInst)];
|
||||
pIcode->ll()->flagDU.d = df[REG(*pInst)];
|
||||
rm(i);
|
||||
pIcode->ll()->src.regi = rCL;
|
||||
pIcode->ll()->replaceSrc(rCL); //src.regi =
|
||||
}
|
||||
|
||||
|
||||
@ -640,7 +639,7 @@ static void trans(int i)
|
||||
ll->setOpcode(transTable[REG(*pInst)]); /* valid on bytes */
|
||||
ll->flagDU.d = df[REG(*pInst)];
|
||||
rm(i);
|
||||
ll->src = pIcode->ll()->dst;
|
||||
ll->replaceSrc( pIcode->ll()->dst );
|
||||
if (ll->match(iJMP) || ll->match(iCALL) || ll->match(iCALLF))
|
||||
ll->setFlags(NO_OPS);
|
||||
else if (ll->match(iINC) || ll->match(iPUSH) || ll->match(iDEC))
|
||||
@ -676,7 +675,7 @@ static void arith(int i)
|
||||
}
|
||||
else if (!(opcode == iNOT || opcode == iNEG))
|
||||
{
|
||||
pIcode->ll()->src = pIcode->ll()->dst;
|
||||
pIcode->ll()->replaceSrc( pIcode->ll()->dst );
|
||||
setAddress(i, true, 0, rAX, 0); /* dst = AX */
|
||||
}
|
||||
else if (opcode == iNEG || opcode == iNOT)
|
||||
@ -695,7 +694,7 @@ static void arith(int i)
|
||||
*****************************************************************************/
|
||||
static void data1(int i)
|
||||
{
|
||||
pIcode->ll()->src.SetImmediateOp( (stateTable[i].flg & S_EXT)? signex(*pInst++): *pInst++ );
|
||||
pIcode->ll()->replaceSrc(LLOperand::CreateImm2((stateTable[i].flg & S_EXT)? signex(*pInst++): *pInst++));
|
||||
pIcode->ll()->setFlags(I);
|
||||
}
|
||||
|
||||
@ -719,7 +718,7 @@ static void data2(int )
|
||||
pIcode->ll()->setFlags(NO_OPS);
|
||||
}
|
||||
else
|
||||
pIcode->ll()->src.SetImmediateOp(getWord());
|
||||
pIcode->ll()->replaceSrc(getWord());
|
||||
pIcode->ll()->setFlags(I);
|
||||
}
|
||||
|
||||
@ -745,7 +744,7 @@ static void dispN(int )
|
||||
/* Note: the result of the subtraction could be between 32k and 64k, and
|
||||
still be positive; it is an offset from prog.Image. So this must be
|
||||
treated as unsigned */
|
||||
pIcode->ll()->src.SetImmediateOp((uint32_t)(off + (unsigned)(pInst - prog.Image)));
|
||||
pIcode->ll()->replaceSrc((uint32_t)(off + (unsigned)(pInst - prog.Image)));
|
||||
pIcode->ll()->setFlags(I);
|
||||
}
|
||||
|
||||
@ -758,7 +757,7 @@ static void dispS(int )
|
||||
PROG &prog(Project::get()->prog);
|
||||
long off = signex(*pInst++); /* Signed displacement */
|
||||
|
||||
pIcode->ll()->src.SetImmediateOp((uint32_t)(off + (unsigned)(pInst - prog.Image)));
|
||||
pIcode->ll()->replaceSrc((uint32_t)(off + (unsigned)(pInst - prog.Image)));
|
||||
pIcode->ll()->setFlags(I);
|
||||
}
|
||||
|
||||
@ -771,7 +770,7 @@ static void dispF(int )
|
||||
uint32_t off = (unsigned)getWord();
|
||||
uint32_t seg = (unsigned)getWord();
|
||||
|
||||
pIcode->ll()->src.SetImmediateOp(off + ((uint32_t)(unsigned)seg << 4));
|
||||
pIcode->ll()->replaceSrc(off + ((uint32_t)(unsigned)seg << 4));
|
||||
pIcode->ll()->setFlags(I);
|
||||
}
|
||||
|
||||
@ -820,7 +819,7 @@ static void strop(int )
|
||||
***************************************************************************/
|
||||
static void escop(int i)
|
||||
{
|
||||
pIcode->ll()->src.SetImmediateOp(REG(*pInst) + (uint32_t)((i & 7) << 3));
|
||||
pIcode->ll()->replaceSrc(REG(*pInst) + (uint32_t)((i & 7) << 3));
|
||||
pIcode->ll()->setFlags(I);
|
||||
rm(i);
|
||||
}
|
||||
@ -831,7 +830,7 @@ static void escop(int i)
|
||||
****************************************************************************/
|
||||
static void const1(int )
|
||||
{
|
||||
pIcode->ll()->src.SetImmediateOp(1);
|
||||
pIcode->ll()->replaceSrc(1);
|
||||
pIcode->ll()->setFlags(I);
|
||||
}
|
||||
|
||||
@ -841,7 +840,7 @@ static void const1(int )
|
||||
****************************************************************************/
|
||||
static void const3(int )
|
||||
{
|
||||
pIcode->ll()->src.SetImmediateOp(3);
|
||||
pIcode->ll()->replaceSrc(3);
|
||||
pIcode->ll()->setFlags(I);
|
||||
}
|
||||
|
||||
@ -868,12 +867,12 @@ static void none2(int )
|
||||
****************************************************************************/
|
||||
static void checkInt(int )
|
||||
{
|
||||
uint16_t wOp = (uint16_t) pIcode->ll()->src.op();
|
||||
uint16_t wOp = (uint16_t) pIcode->ll()->src().getImm2();
|
||||
if ((wOp >= 0x34) && (wOp <= 0x3B))
|
||||
{
|
||||
/* This is a Borland/Microsoft floating point emulation instruction.
|
||||
Treat as if it is an ESC opcode */
|
||||
pIcode->ll()->src.SetImmediateOp(wOp - 0x34);
|
||||
pIcode->ll()->replaceSrc(wOp - 0x34);
|
||||
pIcode->ll()->set(iESC,FLOAT_OP);
|
||||
|
||||
escop(wOp - 0x34 + 0xD8);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user