Started separation between Low level and higher level instructions
This commit is contained in:
parent
0eab9d1db5
commit
6b7d3f6209
@ -1,3 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
cd bld
|
||||||
|
make -j5
|
||||||
|
cd ..
|
||||||
./test_use_base.sh
|
./test_use_base.sh
|
||||||
./regression_tester.rb ./bld/dcc_original -s -c 2>stderr >stdout; diff tests/prev/ tests/outputs/
|
./regression_tester.rb ./bld/dcc_original -s -c 2>stderr >stdout; diff tests/prev/ tests/outputs/
|
||||||
|
|||||||
@ -45,7 +45,7 @@ struct DU
|
|||||||
|
|
||||||
/* Definition-use chain for level 1 (within a basic block) */
|
/* Definition-use chain for level 1 (within a basic block) */
|
||||||
#define MAX_REGS_DEF 2 /* 2 regs def'd for long-reg vars */
|
#define MAX_REGS_DEF 2 /* 2 regs def'd for long-reg vars */
|
||||||
#define MAX_USES 5
|
//#define MAX_USES 5
|
||||||
|
|
||||||
|
|
||||||
struct COND_EXPR;
|
struct COND_EXPR;
|
||||||
@ -162,11 +162,14 @@ struct LLOperand //: public llvm::MCOperand
|
|||||||
void SetImmediateOp(uint32_t dw) {opz=dw;}
|
void SetImmediateOp(uint32_t dw) {opz=dw;}
|
||||||
|
|
||||||
};
|
};
|
||||||
struct LLInst : public llvm::MCInst
|
struct LLInst : public llvm::ilist_node<LLInst>
|
||||||
{
|
{
|
||||||
|
protected:
|
||||||
|
uint32_t flg; /* icode flags */
|
||||||
|
public:
|
||||||
|
int codeIdx; /* Index into cCode.code */
|
||||||
llIcode opcode; /* llIcode instruction */
|
llIcode opcode; /* llIcode instruction */
|
||||||
uint8_t numBytes; /* Number of bytes this instr */
|
uint8_t numBytes; /* Number of bytes this instr */
|
||||||
uint32_t flg; /* icode flags */
|
|
||||||
uint32_t label; /* offset in image (20-bit adr) */
|
uint32_t label; /* offset in image (20-bit adr) */
|
||||||
LLOperand dst; /* destination operand */
|
LLOperand dst; /* destination operand */
|
||||||
LLOperand src; /* source operand */
|
LLOperand src; /* source operand */
|
||||||
@ -181,7 +184,18 @@ struct LLInst : public llvm::MCInst
|
|||||||
{
|
{
|
||||||
return (opcode >= iJB) && (opcode < iJCXZ);
|
return (opcode >= iJB) && (opcode < iJCXZ);
|
||||||
}
|
}
|
||||||
bool anyFlagSet(uint32_t x) const { return (flg & x)!=0;}
|
bool isLlFlag(uint32_t x) const { return (flg & x)!=0;}
|
||||||
|
void SetLlFlag(uint32_t flag) {flg |= flag;}
|
||||||
|
void ClrLlFlag(uint32_t flag) {flg &= ~flag;}
|
||||||
|
|
||||||
|
uint32_t GetLlFlag() const {return flg;}
|
||||||
|
llIcode GetLlOpcode() const { return opcode; }
|
||||||
|
|
||||||
|
uint32_t GetLlLabel() const { return label;}
|
||||||
|
|
||||||
|
void SetImmediateOp(uint32_t dw) {src.SetImmediateOp(dw);}
|
||||||
|
|
||||||
|
|
||||||
bool match(llIcode op)
|
bool match(llIcode op)
|
||||||
{
|
{
|
||||||
return (opcode==op);
|
return (opcode==op);
|
||||||
@ -190,6 +204,10 @@ struct LLInst : public llvm::MCInst
|
|||||||
{
|
{
|
||||||
return (opcode==op)&&dst.regi==dest;
|
return (opcode==op)&&dst.regi==dest;
|
||||||
}
|
}
|
||||||
|
bool match(llIcode op,eReg dest,uint32_t flgs)
|
||||||
|
{
|
||||||
|
return (opcode==op) and (dst.regi==dest) and isLlFlag(flgs);
|
||||||
|
}
|
||||||
bool match(llIcode op,eReg dest,eReg src_reg)
|
bool match(llIcode op,eReg dest,eReg src_reg)
|
||||||
{
|
{
|
||||||
return (opcode==op)&&(dst.regi==dest)&&(src.regi==src_reg);
|
return (opcode==op)&&(dst.regi==dest)&&(src.regi==src_reg);
|
||||||
@ -202,16 +220,25 @@ struct LLInst : public llvm::MCInst
|
|||||||
{
|
{
|
||||||
return (dst.regi==dest);
|
return (dst.regi==dest);
|
||||||
}
|
}
|
||||||
|
bool match(llIcode op,uint32_t flgs)
|
||||||
|
{
|
||||||
|
return (opcode==op) and isLlFlag(flgs);
|
||||||
|
}
|
||||||
void set(llIcode op,uint32_t flags)
|
void set(llIcode op,uint32_t flags)
|
||||||
{
|
{
|
||||||
opcode = op;
|
opcode = op;
|
||||||
flg =flags;
|
flg =flags;
|
||||||
}
|
}
|
||||||
|
void emitGotoLabel(int indLevel);
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Icode definition: LOW_LEVEL and HIGH_LEVEL */
|
/* Icode definition: LOW_LEVEL and HIGH_LEVEL */
|
||||||
struct ICODE
|
struct ICODE
|
||||||
{
|
{
|
||||||
|
protected:
|
||||||
|
LLInst m_ll;
|
||||||
|
HLTYPE m_hl;
|
||||||
|
public:
|
||||||
/* Def/Use of registers and stack variables */
|
/* Def/Use of registers and stack variables */
|
||||||
struct DU_ICODE
|
struct DU_ICODE
|
||||||
{
|
{
|
||||||
@ -273,22 +300,12 @@ struct ICODE
|
|||||||
BB *inBB; /* BB to which this icode belongs */
|
BB *inBB; /* BB to which this icode belongs */
|
||||||
DU_ICODE du; /* Def/use regs/vars */
|
DU_ICODE du; /* Def/use regs/vars */
|
||||||
DU1 du1; /* du chain 1 */
|
DU1 du1; /* du chain 1 */
|
||||||
int codeIdx; /* Index into cCode.code */
|
LLInst * ll() { return &m_ll;}
|
||||||
struct IC { /* Different types of icodes */
|
const LLInst * ll() const { return &m_ll;}
|
||||||
LLInst ll;
|
HLTYPE * hl() { return &m_hl;}
|
||||||
HLTYPE hl; /* For HIGH_LEVEL icodes */
|
const HLTYPE * hl() const { return &m_hl;}
|
||||||
};
|
|
||||||
IC ic;/* intermediate code */
|
|
||||||
int loc_ip; // used by CICodeRec to number ICODEs
|
int loc_ip; // used by CICodeRec to number ICODEs
|
||||||
|
|
||||||
void ClrLlFlag(uint32_t flag) {ic.ll.flg &= ~flag;}
|
|
||||||
void SetLlFlag(uint32_t flag) {ic.ll.flg |= flag;}
|
|
||||||
uint32_t GetLlFlag() {return ic.ll.flg;}
|
|
||||||
bool isLlFlag(uint32_t flg) {return (ic.ll.flg&flg)!=0;}
|
|
||||||
llIcode GetLlOpcode() const { return ic.ll.opcode; }
|
|
||||||
uint32_t GetLlLabel() const { return ic.ll.label;}
|
|
||||||
void SetImmediateOp(uint32_t dw) {ic.ll.src.SetImmediateOp(dw);}
|
|
||||||
|
|
||||||
void writeIntComment(std::ostringstream &s);
|
void writeIntComment(std::ostringstream &s);
|
||||||
void setRegDU(uint8_t regi, operDu du_in);
|
void setRegDU(uint8_t regi, operDu du_in);
|
||||||
void invalidate();
|
void invalidate();
|
||||||
@ -307,7 +324,7 @@ public:
|
|||||||
void checkHlCall();
|
void checkHlCall();
|
||||||
bool newStkArg(COND_EXPR *exp, llIcode opcode, Function *pproc)
|
bool newStkArg(COND_EXPR *exp, llIcode opcode, Function *pproc)
|
||||||
{
|
{
|
||||||
return ic.hl.call.newStkArg(exp,opcode,pproc);
|
return hl()->call.newStkArg(exp,opcode,pproc);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -146,7 +146,7 @@ void BB::writeCode (int indLevel, Function * pProc , int *numLoc,int latchNode,
|
|||||||
picode = &this->back();
|
picode = &this->back();
|
||||||
|
|
||||||
/* Check for error in while condition */
|
/* Check for error in while condition */
|
||||||
if (picode->ic.hl.opcode != HLI_JCOND)
|
if (picode->hl()->opcode != HLI_JCOND)
|
||||||
reportError (WHILE_FAIL);
|
reportError (WHILE_FAIL);
|
||||||
|
|
||||||
/* Check if condition is more than 1 HL instruction */
|
/* Check if condition is more than 1 HL instruction */
|
||||||
@ -161,13 +161,13 @@ void BB::writeCode (int indLevel, Function * pProc , int *numLoc,int latchNode,
|
|||||||
* the THEN path of the header node */
|
* the THEN path of the header node */
|
||||||
if (edges[ELSE].BBptr->dfsLastNum == loopFollow)
|
if (edges[ELSE].BBptr->dfsLastNum == loopFollow)
|
||||||
{
|
{
|
||||||
COND_EXPR *old_expr=picode->ic.hl.expr();
|
COND_EXPR *old_expr=picode->hl()->expr();
|
||||||
string e=walkCondExpr (old_expr, pProc, numLoc);
|
string e=walkCondExpr (old_expr, pProc, numLoc);
|
||||||
picode->ic.hl.expr(picode->ic.hl.expr()->inverse());
|
picode->hl()->expr(picode->hl()->expr()->inverse());
|
||||||
delete old_expr;
|
delete old_expr;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
string e=walkCondExpr (picode->ic.hl.expr(), pProc, numLoc);
|
string e=walkCondExpr (picode->hl()->expr(), pProc, numLoc);
|
||||||
cCode.appendCode( "\n%swhile (%s) {\n", indent(indLevel),e.c_str());
|
cCode.appendCode( "\n%swhile (%s) {\n", indent(indLevel),e.c_str());
|
||||||
}
|
}
|
||||||
picode->invalidate();
|
picode->invalidate();
|
||||||
@ -213,7 +213,7 @@ void BB::writeCode (int indLevel, Function * pProc , int *numLoc,int latchNode,
|
|||||||
if (succ->traversed != DFS_ALPHA)
|
if (succ->traversed != DFS_ALPHA)
|
||||||
succ->writeCode (indLevel, pProc, numLoc, latch->dfsLastNum,_ifFollow);
|
succ->writeCode (indLevel, pProc, numLoc, latch->dfsLastNum,_ifFollow);
|
||||||
else /* has been traversed so we need a goto */
|
else /* has been traversed so we need a goto */
|
||||||
succ->front().emitGotoLabel (indLevel);
|
succ->front().ll()->emitGotoLabel (indLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Loop epilogue: generate the loop trailer */
|
/* Loop epilogue: generate the loop trailer */
|
||||||
@ -230,10 +230,10 @@ void BB::writeCode (int indLevel, Function * pProc , int *numLoc,int latchNode,
|
|||||||
cCode.appendCode( "%s} /* end of loop */\n",indent(indLevel));
|
cCode.appendCode( "%s} /* end of loop */\n",indent(indLevel));
|
||||||
else if (_loopType == REPEAT_TYPE)
|
else if (_loopType == REPEAT_TYPE)
|
||||||
{
|
{
|
||||||
if (picode->ic.hl.opcode != HLI_JCOND)
|
if (picode->hl()->opcode != HLI_JCOND)
|
||||||
reportError (REPEAT_FAIL);
|
reportError (REPEAT_FAIL);
|
||||||
{
|
{
|
||||||
string e=walkCondExpr (picode->ic.hl.expr(), pProc, numLoc);
|
string e=walkCondExpr (picode->hl()->expr(), pProc, numLoc);
|
||||||
cCode.appendCode( "%s} while (%s);\n", indent(indLevel),e.c_str());
|
cCode.appendCode( "%s} while (%s);\n", indent(indLevel),e.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -245,7 +245,7 @@ void BB::writeCode (int indLevel, Function * pProc , int *numLoc,int latchNode,
|
|||||||
if (succ->traversed != DFS_ALPHA)
|
if (succ->traversed != DFS_ALPHA)
|
||||||
succ->writeCode (indLevel, pProc, numLoc, latchNode, _ifFollow);
|
succ->writeCode (indLevel, pProc, numLoc, latchNode, _ifFollow);
|
||||||
else /* has been traversed so we need a goto */
|
else /* has been traversed so we need a goto */
|
||||||
succ->front().emitGotoLabel (indLevel);
|
succ->front().ll()->emitGotoLabel (indLevel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,20 +266,20 @@ void BB::writeCode (int indLevel, Function * pProc , int *numLoc,int latchNode,
|
|||||||
{
|
{
|
||||||
if (succ->dfsLastNum != follow) /* THEN part */
|
if (succ->dfsLastNum != follow) /* THEN part */
|
||||||
{
|
{
|
||||||
l = writeJcond ( back().ic.hl, pProc, numLoc);
|
l = writeJcond ( *back().hl(), pProc, numLoc);
|
||||||
cCode.appendCode( "\n%s%s", indent(indLevel-1), l);
|
cCode.appendCode( "\n%s%s", indent(indLevel-1), l);
|
||||||
succ->writeCode (indLevel, pProc, numLoc, latchNode,follow);
|
succ->writeCode (indLevel, pProc, numLoc, latchNode,follow);
|
||||||
}
|
}
|
||||||
else /* empty THEN part => negate ELSE part */
|
else /* empty THEN part => negate ELSE part */
|
||||||
{
|
{
|
||||||
l = writeJcondInv ( back().ic.hl, pProc, numLoc);
|
l = writeJcondInv ( *back().hl(), pProc, numLoc);
|
||||||
cCode.appendCode( "\n%s%s", indent(indLevel-1), l);
|
cCode.appendCode( "\n%s%s", indent(indLevel-1), l);
|
||||||
edges[ELSE].BBptr->writeCode (indLevel, pProc, numLoc, latchNode, follow);
|
edges[ELSE].BBptr->writeCode (indLevel, pProc, numLoc, latchNode, follow);
|
||||||
emptyThen = true;
|
emptyThen = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else /* already visited => emit label */
|
else /* already visited => emit label */
|
||||||
succ->front().emitGotoLabel(indLevel);
|
succ->front().ll()->emitGotoLabel(indLevel);
|
||||||
|
|
||||||
/* process the ELSE part */
|
/* process the ELSE part */
|
||||||
succ = edges[ELSE].BBptr;
|
succ = edges[ELSE].BBptr;
|
||||||
@ -297,7 +297,7 @@ void BB::writeCode (int indLevel, Function * pProc , int *numLoc,int latchNode,
|
|||||||
{
|
{
|
||||||
cCode.appendCode( "%s}\n%selse {\n",
|
cCode.appendCode( "%s}\n%selse {\n",
|
||||||
indent(indLevel-1), indent(indLevel - 1));
|
indent(indLevel-1), indent(indLevel - 1));
|
||||||
succ->front().emitGotoLabel (indLevel);
|
succ->front().ll()->emitGotoLabel (indLevel);
|
||||||
}
|
}
|
||||||
cCode.appendCode( "%s}\n", indent(--indLevel));
|
cCode.appendCode( "%s}\n", indent(--indLevel));
|
||||||
|
|
||||||
@ -308,8 +308,7 @@ void BB::writeCode (int indLevel, Function * pProc , int *numLoc,int latchNode,
|
|||||||
}
|
}
|
||||||
else /* no follow => if..then..else */
|
else /* no follow => if..then..else */
|
||||||
{
|
{
|
||||||
l = writeJcond (
|
l = writeJcond ( *back().hl(), pProc, numLoc);
|
||||||
back().ic.hl, pProc, numLoc);
|
|
||||||
cCode.appendCode( "%s%s", indent(indLevel-1), l);
|
cCode.appendCode( "%s%s", indent(indLevel-1), l);
|
||||||
edges[THEN].BBptr->writeCode (indLevel, pProc, numLoc, latchNode, _ifFollow);
|
edges[THEN].BBptr->writeCode (indLevel, pProc, numLoc, latchNode, _ifFollow);
|
||||||
cCode.appendCode( "%s}\n%selse {\n", indent(indLevel-1), indent(indLevel - 1));
|
cCode.appendCode( "%s}\n%selse {\n", indent(indLevel-1), indent(indLevel - 1));
|
||||||
@ -334,7 +333,7 @@ void BB::writeBB(int lev, Function * pProc, int *numLoc)
|
|||||||
{
|
{
|
||||||
/* Save the index into the code table in case there is a later goto
|
/* Save the index into the code table in case there is a later goto
|
||||||
* into this instruction (first instruction of the BB) */
|
* into this instruction (first instruction of the BB) */
|
||||||
front().codeIdx = nextBundleIdx (&cCode.code);
|
front().ll()->codeIdx = nextBundleIdx (&cCode.code);
|
||||||
//hli[start].codeIdx = nextBundleIdx (&cCode.code);
|
//hli[start].codeIdx = nextBundleIdx (&cCode.code);
|
||||||
//for (i = start, last = i + length; i < last; i++)
|
//for (i = start, last = i + length; i < last; i++)
|
||||||
|
|
||||||
@ -344,7 +343,7 @@ void BB::writeBB(int lev, Function * pProc, int *numLoc)
|
|||||||
{
|
{
|
||||||
if ((hli->type == HIGH_LEVEL) && (hli->invalid == FALSE))
|
if ((hli->type == HIGH_LEVEL) && (hli->invalid == FALSE))
|
||||||
{
|
{
|
||||||
std::string line = hli->ic.hl.write1HlIcode(pProc, numLoc);
|
std::string line = hli->hl()->write1HlIcode(pProc, numLoc);
|
||||||
if (!line.empty())
|
if (!line.empty())
|
||||||
{
|
{
|
||||||
cCode.appendCode( "%s%s", indent(lev), line.c_str());
|
cCode.appendCode( "%s%s", indent(lev), line.c_str());
|
||||||
|
|||||||
33
src/ast.cpp
33
src/ast.cpp
@ -66,7 +66,7 @@ void ICODE::setRegDU (uint8_t regi, operDu du_in)
|
|||||||
/* Copies the def, use, or def and use fields of duIcode into pIcode */
|
/* Copies the def, use, or def and use fields of duIcode into pIcode */
|
||||||
void ICODE::copyDU(const ICODE &duIcode, operDu _du, operDu duDu)
|
void ICODE::copyDU(const ICODE &duIcode, operDu _du, operDu duDu)
|
||||||
{
|
{
|
||||||
// printf("%s %d,%d from %d to %d\n",__FUNCTION__,int(du),int(duDu),duIcode->ic.ll.opcode,pIcode->ic.ll.opcode);
|
// printf("%s %d,%d from %d to %d\n",__FUNCTION__,int(du),int(duDu),duIcode->ll()->opcode,pIcode->ll()->opcode);
|
||||||
switch (_du)
|
switch (_du)
|
||||||
{
|
{
|
||||||
case eDEF:
|
case eDEF:
|
||||||
@ -258,17 +258,17 @@ COND_EXPR *COND_EXPR::idLong(LOCAL_ID *localId, opLoc sd, iICODE pIcode, hlFirst
|
|||||||
int idx;
|
int idx;
|
||||||
COND_EXPR *newExp = new COND_EXPR(IDENTIFIER);
|
COND_EXPR *newExp = new COND_EXPR(IDENTIFIER);
|
||||||
/* Check for long constant and save it as a constant expression */
|
/* Check for long constant and save it as a constant expression */
|
||||||
if ((sd == SRC) && ((pIcode->ic.ll.flg & I) == I)) /* constant */
|
if ((sd == SRC) && pIcode->ll()->isLlFlag(I)) /* constant */
|
||||||
{
|
{
|
||||||
iICODE atOffset=pIcode;
|
iICODE atOffset=pIcode;
|
||||||
advance(atOffset,off);
|
advance(atOffset,off);
|
||||||
newExp->expr.ident.idType = CONSTANT;
|
newExp->expr.ident.idType = CONSTANT;
|
||||||
if (f == HIGH_FIRST)
|
if (f == HIGH_FIRST)
|
||||||
newExp->expr.ident.idNode.kte.kte = (pIcode->ic.ll.src.op() << 16) +
|
newExp->expr.ident.idNode.kte.kte = (pIcode->ll()->src.op() << 16) +
|
||||||
atOffset->ic.ll.src.op();
|
atOffset->ll()->src.op();
|
||||||
else /* LOW_FIRST */
|
else /* LOW_FIRST */
|
||||||
newExp->expr.ident.idNode.kte.kte =
|
newExp->expr.ident.idNode.kte.kte =
|
||||||
(atOffset->ic.ll.src.op() << 16)+ pIcode->ic.ll.src.op();
|
(atOffset->ll()->src.op() << 16)+ pIcode->ll()->src.op();
|
||||||
newExp->expr.ident.idNode.kte.size = 4;
|
newExp->expr.ident.idNode.kte.size = 4;
|
||||||
}
|
}
|
||||||
/* Save it as a long expression (reg, stack or glob) */
|
/* Save it as a long expression (reg, stack or glob) */
|
||||||
@ -337,7 +337,7 @@ COND_EXPR *COND_EXPR::idID (const ID *retVal, LOCAL_ID *locsym, iICODE ix_)
|
|||||||
|
|
||||||
/* Returns an identifier conditional expression node, according to the given
|
/* Returns an identifier conditional expression node, according to the given
|
||||||
* type.
|
* type.
|
||||||
* Arguments: i : index into the icode array, used for newLongRegId only.
|
* Arguments:
|
||||||
* duIcode: icode instruction that needs the du set.
|
* duIcode: icode instruction that needs the du set.
|
||||||
* du: operand is defined or used in current instruction. */
|
* du: operand is defined or used in current instruction. */
|
||||||
COND_EXPR *COND_EXPR::id(const ICODE &pIcode, opLoc sd, Function * pProc, iICODE ix_,ICODE &duIcode, operDu du)
|
COND_EXPR *COND_EXPR::id(const ICODE &pIcode, opLoc sd, Function * pProc, iICODE ix_,ICODE &duIcode, operDu du)
|
||||||
@ -346,10 +346,10 @@ COND_EXPR *COND_EXPR::id(const ICODE &pIcode, opLoc sd, Function * pProc, iICODE
|
|||||||
|
|
||||||
int idx; /* idx into pIcode->localId table */
|
int idx; /* idx into pIcode->localId table */
|
||||||
|
|
||||||
const LLOperand &pm((sd == SRC) ? pIcode.ic.ll.src : pIcode.ic.ll.dst);
|
const LLOperand &pm((sd == SRC) ? pIcode.ll()->src : pIcode.ll()->dst);
|
||||||
|
|
||||||
if ( ((sd == DST) && pIcode.ic.ll.anyFlagSet(IM_DST)) or
|
if ( ((sd == DST) && pIcode.ll()->isLlFlag(IM_DST)) or
|
||||||
((sd == SRC) && pIcode.ic.ll.anyFlagSet(IM_SRC)) or
|
((sd == SRC) && pIcode.ll()->isLlFlag(IM_SRC)) or
|
||||||
(sd == LHS_OP)) /* for MUL lhs */
|
(sd == LHS_OP)) /* for MUL lhs */
|
||||||
{ /* implicit dx:ax */
|
{ /* implicit dx:ax */
|
||||||
idx = pProc->localId.newLongReg (TYPE_LONG_SIGN, rDX, rAX, ix_);
|
idx = pProc->localId.newLongReg (TYPE_LONG_SIGN, rDX, rAX, ix_);
|
||||||
@ -358,20 +358,21 @@ COND_EXPR *COND_EXPR::id(const ICODE &pIcode, opLoc sd, Function * pProc, iICODE
|
|||||||
duIcode.setRegDU (rAX, du);
|
duIcode.setRegDU (rAX, du);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if ((sd == DST) && pIcode.ic.ll.anyFlagSet(IM_TMP_DST))
|
else if ((sd == DST) && pIcode.ll()->isLlFlag(IM_TMP_DST))
|
||||||
{ /* implicit tmp */
|
{ /* implicit tmp */
|
||||||
newExp = COND_EXPR::idReg (rTMP, 0, &pProc->localId);
|
newExp = COND_EXPR::idReg (rTMP, 0, &pProc->localId);
|
||||||
duIcode.setRegDU(rTMP, (operDu)eUSE);
|
duIcode.setRegDU(rTMP, (operDu)eUSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if ((sd == SRC) && pIcode.ic.ll.anyFlagSet(I)) /* constant */
|
else if ((sd == SRC) && pIcode.ll()->isLlFlag(I)) /* constant */
|
||||||
newExp = COND_EXPR::idKte (pIcode.ic.ll.src.op(), 2);
|
newExp = COND_EXPR::idKte (pIcode.ll()->src.op(), 2);
|
||||||
else if (pm.regi == 0) /* global variable */
|
else if (pm.regi == 0) /* global variable */
|
||||||
newExp = COND_EXPR::idGlob(pm.segValue, pm.off);
|
newExp = COND_EXPR::idGlob(pm.segValue, pm.off);
|
||||||
else if (pm.regi < INDEXBASE) /* register */
|
else if (pm.regi < INDEXBASE) /* register */
|
||||||
{
|
{
|
||||||
newExp = COND_EXPR::idReg (pm.regi, (sd == SRC) ? pIcode.ic.ll.flg :
|
newExp = COND_EXPR::idReg (pm.regi, (sd == SRC) ? pIcode.ll()->GetLlFlag() :
|
||||||
pIcode.ic.ll.flg & NO_SRC_B, &pProc->localId);
|
pIcode.ll()->GetLlFlag() & NO_SRC_B,
|
||||||
|
&pProc->localId);
|
||||||
duIcode.setRegDU( pm.regi, du);
|
duIcode.setRegDU( pm.regi, du);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -430,9 +431,9 @@ COND_EXPR *COND_EXPR::id(const ICODE &pIcode, opLoc sd, Function * pProc, iICODE
|
|||||||
/* Returns the identifier type */
|
/* Returns the identifier type */
|
||||||
condId ICODE::idType(opLoc sd)
|
condId ICODE::idType(opLoc sd)
|
||||||
{
|
{
|
||||||
LLOperand &pm((sd == SRC) ? ic.ll.src : ic.ll.dst);
|
LLOperand &pm((sd == SRC) ? ll()->src : ll()->dst);
|
||||||
|
|
||||||
if ((sd == SRC) && ((ic.ll.flg & I) == I))
|
if ((sd == SRC) && ll()->isLlFlag(I))
|
||||||
return (CONSTANT);
|
return (CONSTANT);
|
||||||
else if (pm.regi == 0)
|
else if (pm.regi == 0)
|
||||||
return (GLOB_VAR);
|
return (GLOB_VAR);
|
||||||
|
|||||||
@ -64,8 +64,8 @@ static void fixupLabels (PPROC pProc)
|
|||||||
dfsLast = pProc->dfsLast;
|
dfsLast = pProc->dfsLast;
|
||||||
for (i = 0; i < pProc->numBBs; i++)
|
for (i = 0; i < pProc->numBBs; i++)
|
||||||
if (dfsLast[i]->flg/* & BB_HAS_LABEL*/) {
|
if (dfsLast[i]->flg/* & BB_HAS_LABEL*/) {
|
||||||
pProc->Icode.icode[dfsLast[i]->start].ic.ll.flg |= HLL_LABEL;
|
pProc->Icode.icode[dfsLast[i]->start].ll()->flg |= HLL_LABEL;
|
||||||
pProc->Icode.icode[dfsLast[i]->start].ic.ll.hllLabNum = getNextLabel();
|
pProc->Icode.icode[dfsLast[i]->start].ll()->hllLabNum = getNextLabel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -225,14 +225,13 @@ static void writeBitVector (const std::bitset<32> ®i)
|
|||||||
* the code; that is, the target code has not been traversed yet. */
|
* the code; that is, the target code has not been traversed yet. */
|
||||||
static void emitFwdGotoLabel (ICODE * pt, int indLevel)
|
static void emitFwdGotoLabel (ICODE * pt, int indLevel)
|
||||||
{
|
{
|
||||||
if (! (pt->ic.ll.flg & HLL_LABEL)) /* node hasn't got a lab */
|
if ( not pt->ll()->isLlFlag(HLL_LABEL)) /* node hasn't got a lab */
|
||||||
{
|
{
|
||||||
/* Generate new label */
|
/* Generate new label */
|
||||||
pt->ic.ll.hllLabNum = getNextLabel();
|
pt->ll()->hllLabNum = getNextLabel();
|
||||||
pt->ic.ll.flg |= HLL_LABEL;
|
pt->ll()->SetLlFlag(HLL_LABEL);
|
||||||
}
|
}
|
||||||
cCode.appendCode( "%sgoto l%ld;\n", indent(indLevel),
|
cCode.appendCode( "%sgoto l%ld;\n", indent(indLevel), pt->ll()->hllLabNum);
|
||||||
pt->ic.ll.hllLabNum);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -150,17 +150,17 @@ static const char *intOthers[] = {
|
|||||||
void ICODE::writeIntComment (std::ostringstream &s)
|
void ICODE::writeIntComment (std::ostringstream &s)
|
||||||
{
|
{
|
||||||
s<<"\t/* ";
|
s<<"\t/* ";
|
||||||
if (ic.ll.src.op() == 0x21)
|
if (ll()->src.op() == 0x21)
|
||||||
{
|
{
|
||||||
s <<int21h[ic.ll.dst.off];
|
s <<int21h[ll()->dst.off];
|
||||||
}
|
}
|
||||||
else if (ic.ll.src.op() > 0x1F && ic.ll.src.op() < 0x2F)
|
else if (ll()->src.op() > 0x1F && ll()->src.op() < 0x2F)
|
||||||
{
|
{
|
||||||
s <<intOthers[ic.ll.src.op() - 0x20];
|
s <<intOthers[ll()->src.op() - 0x20];
|
||||||
}
|
}
|
||||||
else if (ic.ll.src.op() == 0x2F)
|
else if (ll()->src.op() == 0x2F)
|
||||||
{
|
{
|
||||||
switch (ic.ll.dst.off)
|
switch (ll()->dst.off)
|
||||||
{
|
{
|
||||||
case 0x01 :
|
case 0x01 :
|
||||||
s << "Print spooler";
|
s << "Print spooler";
|
||||||
|
|||||||
@ -180,7 +180,7 @@ static void findNodesInLoop(BB * latchNode,BB * head,Function * pProc,queue &int
|
|||||||
head->loopFollow = latchNode->edges[ELSE].BBptr->dfsLastNum;
|
head->loopFollow = latchNode->edges[ELSE].BBptr->dfsLastNum;
|
||||||
else
|
else
|
||||||
head->loopFollow = latchNode->edges[THEN].BBptr->dfsLastNum;
|
head->loopFollow = latchNode->edges[THEN].BBptr->dfsLastNum;
|
||||||
latchNode->back().SetLlFlag(JX_LOOP);
|
latchNode->back().ll()->SetLlFlag(JX_LOOP);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -189,7 +189,7 @@ static void findNodesInLoop(BB * latchNode,BB * head,Function * pProc,queue &int
|
|||||||
head->loopFollow = head->edges[ELSE].BBptr->dfsLastNum;
|
head->loopFollow = head->edges[ELSE].BBptr->dfsLastNum;
|
||||||
else
|
else
|
||||||
head->loopFollow = head->edges[THEN].BBptr->dfsLastNum;
|
head->loopFollow = head->edges[THEN].BBptr->dfsLastNum;
|
||||||
head->back().SetLlFlag(JX_LOOP);
|
head->back().ll()->SetLlFlag(JX_LOOP);
|
||||||
}
|
}
|
||||||
else /* head = anything besides 2-way, latch = 2-way */
|
else /* head = anything besides 2-way, latch = 2-way */
|
||||||
{
|
{
|
||||||
@ -198,7 +198,7 @@ static void findNodesInLoop(BB * latchNode,BB * head,Function * pProc,queue &int
|
|||||||
head->loopFollow = latchNode->edges[ELSE].BBptr->dfsLastNum;
|
head->loopFollow = latchNode->edges[ELSE].BBptr->dfsLastNum;
|
||||||
else
|
else
|
||||||
head->loopFollow = latchNode->edges[THEN].BBptr->dfsLastNum;
|
head->loopFollow = latchNode->edges[THEN].BBptr->dfsLastNum;
|
||||||
latchNode->back().SetLlFlag(JX_LOOP);
|
latchNode->back().ll()->SetLlFlag(JX_LOOP);
|
||||||
}
|
}
|
||||||
else /* latch = 1-way */
|
else /* latch = 1-way */
|
||||||
if (latchNode->nodeType == LOOP_NODE)
|
if (latchNode->nodeType == LOOP_NODE)
|
||||||
@ -237,7 +237,7 @@ static void findNodesInLoop(BB * latchNode,BB * head,Function * pProc,queue &int
|
|||||||
}
|
}
|
||||||
if (pbb->dfsLastNum > head->dfsLastNum)
|
if (pbb->dfsLastNum > head->dfsLastNum)
|
||||||
pProc->m_dfsLast[head->loopFollow]->loopHead = NO_NODE; /*****/
|
pProc->m_dfsLast[head->loopFollow]->loopHead = NO_NODE; /*****/
|
||||||
head->back().SetLlFlag(JX_LOOP);
|
head->back().ll()->SetLlFlag(JX_LOOP);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -450,7 +450,7 @@ void Function::structIfs ()
|
|||||||
if (currNode->flg & INVALID_BB) /* Do not process invalid BBs */
|
if (currNode->flg & INVALID_BB) /* Do not process invalid BBs */
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ((currNode->nodeType == TWO_BRANCH) && (!currNode->back().isLlFlag(JX_LOOP)))
|
if ((currNode->nodeType == TWO_BRANCH) && (!currNode->back().ll()->isLlFlag(JX_LOOP)))
|
||||||
{
|
{
|
||||||
followInEdges = 0;
|
followInEdges = 0;
|
||||||
follow = 0;
|
follow = 0;
|
||||||
@ -526,7 +526,7 @@ void Function::compoundCond()
|
|||||||
/* Construct compound DBL_OR expression */
|
/* Construct compound DBL_OR expression */
|
||||||
picode = &pbb->back();
|
picode = &pbb->back();
|
||||||
ticode = &t->back();
|
ticode = &t->back();
|
||||||
picode->ic.hl.expr(COND_EXPR::boolOp (picode->ic.hl.expr(), ticode->ic.hl.expr(), DBL_OR));
|
picode->hl()->expr(COND_EXPR::boolOp (picode->hl()->expr(), ticode->hl()->expr(), DBL_OR));
|
||||||
|
|
||||||
/* Replace in-edge to obb from t to pbb */
|
/* Replace in-edge to obb from t to pbb */
|
||||||
{
|
{
|
||||||
@ -562,11 +562,11 @@ void Function::compoundCond()
|
|||||||
picode = &pbb->back();
|
picode = &pbb->back();
|
||||||
ticode = &t->back();
|
ticode = &t->back();
|
||||||
|
|
||||||
COND_EXPR *oldexpr=picode->ic.hl.expr();
|
COND_EXPR *oldexpr=picode->hl()->expr();
|
||||||
picode->ic.hl.expr(picode->ic.hl.expr()->inverse());
|
picode->hl()->expr(picode->hl()->expr()->inverse());
|
||||||
delete oldexpr;
|
delete oldexpr;
|
||||||
|
|
||||||
picode->ic.hl.expr(COND_EXPR::boolOp (picode->ic.hl.expr(), ticode->ic.hl.expr(), DBL_AND));
|
picode->hl()->expr(COND_EXPR::boolOp (picode->hl()->expr(), ticode->hl()->expr(), DBL_AND));
|
||||||
|
|
||||||
/* Replace in-edge to obb from t to pbb */
|
/* Replace in-edge to obb from t to pbb */
|
||||||
auto iter=std::find(obb->inEdges.begin(),obb->inEdges.end(),t);
|
auto iter=std::find(obb->inEdges.begin(),obb->inEdges.end(),t);
|
||||||
@ -600,7 +600,7 @@ void Function::compoundCond()
|
|||||||
/* Construct compound DBL_AND expression */
|
/* Construct compound DBL_AND expression */
|
||||||
picode = &pbb->back();
|
picode = &pbb->back();
|
||||||
ticode = &t->back();
|
ticode = &t->back();
|
||||||
picode->ic.hl.expr(COND_EXPR::boolOp (picode->ic.hl.expr(),ticode->ic.hl.expr(), DBL_AND));
|
picode->hl()->expr(COND_EXPR::boolOp (picode->hl()->expr(),ticode->hl()->expr(), DBL_AND));
|
||||||
|
|
||||||
/* Replace in-edge to obb from e to pbb */
|
/* Replace in-edge to obb from e to pbb */
|
||||||
auto iter = std::find(obb->inEdges.begin(),obb->inEdges.end(),e);
|
auto iter = std::find(obb->inEdges.begin(),obb->inEdges.end(),e);
|
||||||
@ -632,11 +632,11 @@ void Function::compoundCond()
|
|||||||
/* Construct compound DBL_OR expression */
|
/* Construct compound DBL_OR expression */
|
||||||
picode = &pbb->back();
|
picode = &pbb->back();
|
||||||
ticode = &t->back();
|
ticode = &t->back();
|
||||||
COND_EXPR *oldexp=picode->ic.hl.expr();
|
COND_EXPR *oldexp=picode->hl()->expr();
|
||||||
picode->ic.hl.expr(picode->ic.hl.expr()->inverse());
|
picode->hl()->expr(picode->hl()->expr()->inverse());
|
||||||
delete oldexp;
|
delete oldexp;
|
||||||
picode->ic.hl.expr(COND_EXPR::boolOp (picode->ic.hl.expr(), ticode->ic.hl.expr(), DBL_OR));
|
picode->hl()->expr(COND_EXPR::boolOp (picode->hl()->expr(), ticode->hl()->expr(), DBL_OR));
|
||||||
//picode->ic.hl.expr() = exp;
|
//picode->hl()->expr() = exp;
|
||||||
|
|
||||||
/* Replace in-edge to obb from e to pbb */
|
/* Replace in-edge to obb from e to pbb */
|
||||||
auto iter = std::find(obb->inEdges.begin(),obb->inEdges.end(),e);
|
auto iter = std::find(obb->inEdges.begin(),obb->inEdges.end(),e);
|
||||||
|
|||||||
203
src/dataflow.cpp
203
src/dataflow.cpp
@ -83,11 +83,11 @@ int STKFRAME::getLocVar(int off)
|
|||||||
/* Returns a string with the source operand of Icode */
|
/* Returns a string with the source operand of Icode */
|
||||||
static COND_EXPR *srcIdent (const ICODE &Icode, Function * pProc, iICODE i, ICODE & duIcode, operDu du)
|
static COND_EXPR *srcIdent (const ICODE &Icode, Function * pProc, iICODE i, ICODE & duIcode, operDu du)
|
||||||
{
|
{
|
||||||
if (Icode.ic.ll.flg & I) /* immediate operand */
|
if (Icode.ll()->isLlFlag(I)) /* immediate operand */
|
||||||
{
|
{
|
||||||
if (Icode.ic.ll.flg & B)
|
if (Icode.ll()->isLlFlag(B))
|
||||||
return COND_EXPR::idKte (Icode.ic.ll.src.op(), 1);
|
return COND_EXPR::idKte (Icode.ll()->src.op(), 1);
|
||||||
return COND_EXPR::idKte (Icode.ic.ll.src.op(), 2);
|
return COND_EXPR::idKte (Icode.ll()->src.op(), 2);
|
||||||
}
|
}
|
||||||
// otherwise
|
// otherwise
|
||||||
return COND_EXPR::id (Icode, SRC, pProc, i, duIcode, du);
|
return COND_EXPR::id (Icode, SRC, pProc, i, duIcode, du);
|
||||||
@ -99,7 +99,7 @@ static COND_EXPR *dstIdent (const ICODE & Icode, Function * pProc, iICODE i, ICO
|
|||||||
{
|
{
|
||||||
COND_EXPR *n;
|
COND_EXPR *n;
|
||||||
n = COND_EXPR::id (Icode, DST, pProc, i, duIcode, du);
|
n = COND_EXPR::id (Icode, DST, pProc, i, duIcode, du);
|
||||||
/** Is it needed? (pIcode->ic.ll.flg) & NO_SRC_B **/
|
/** Is it needed? (pIcode->ll()->flg) & NO_SRC_B **/
|
||||||
return (n);
|
return (n);
|
||||||
}
|
}
|
||||||
/* Eliminates all condition codes and generates new hlIcode instructions */
|
/* Eliminates all condition codes and generates new hlIcode instructions */
|
||||||
@ -124,21 +124,22 @@ void Function::elimCondCodes ()
|
|||||||
|
|
||||||
for (useAt = pBB->rbegin2(); useAt != pBB->rend2(); useAt++)
|
for (useAt = pBB->rbegin2(); useAt != pBB->rend2(); useAt++)
|
||||||
{
|
{
|
||||||
if ((useAt->type == LOW_LEVEL) && (useAt->valid()) && (use = useAt->ic.ll.flagDU.u))
|
llIcode useAtOp = useAt->ll()->GetLlOpcode();
|
||||||
|
if ((useAt->type == LOW_LEVEL) && (useAt->valid()) && (use = useAt->ll()->flagDU.u))
|
||||||
{
|
{
|
||||||
/* Find definition within the same basic block */
|
/* Find definition within the same basic block */
|
||||||
defAt=useAt;
|
defAt=useAt;
|
||||||
++defAt;
|
++defAt;
|
||||||
for (; defAt != pBB->rend2(); defAt++)
|
for (; defAt != pBB->rend2(); defAt++)
|
||||||
{
|
{
|
||||||
def = defAt->ic.ll.flagDU.d;
|
def = defAt->ll()->flagDU.d;
|
||||||
if ((use & def) != use)
|
if ((use & def) != use)
|
||||||
continue;
|
continue;
|
||||||
notSup = FALSE;
|
notSup = FALSE;
|
||||||
if ((useAt->GetLlOpcode() >= iJB) && (useAt->GetLlOpcode() <= iJNS))
|
if ((useAtOp >= iJB) && (useAtOp <= iJNS))
|
||||||
{
|
{
|
||||||
iICODE befDefAt = (++riICODE(defAt)).base();
|
iICODE befDefAt = (++riICODE(defAt)).base();
|
||||||
switch (defAt->GetLlOpcode())
|
switch (defAt->ll()->GetLlOpcode())
|
||||||
{
|
{
|
||||||
case iCMP:
|
case iCMP:
|
||||||
rhs = srcIdent (*defAt, this, befDefAt,*useAt, eUSE);
|
rhs = srcIdent (*defAt, this, befDefAt,*useAt, eUSE);
|
||||||
@ -146,9 +147,9 @@ void Function::elimCondCodes ()
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case iOR:
|
case iOR:
|
||||||
lhs = defAt->ic.hl.asgn.lhs->clone();
|
lhs = defAt->hl()->asgn.lhs->clone();
|
||||||
useAt->copyDU(*defAt, eUSE, eDEF);
|
useAt->copyDU(*defAt, eUSE, eDEF);
|
||||||
if (defAt->isLlFlag(B))
|
if (defAt->ll()->isLlFlag(B))
|
||||||
rhs = COND_EXPR::idKte (0, 1);
|
rhs = COND_EXPR::idKte (0, 1);
|
||||||
else
|
else
|
||||||
rhs = COND_EXPR::idKte (0, 2);
|
rhs = COND_EXPR::idKte (0, 2);
|
||||||
@ -158,7 +159,7 @@ void Function::elimCondCodes ()
|
|||||||
rhs = srcIdent (*defAt,this, befDefAt,*useAt, eUSE);
|
rhs = srcIdent (*defAt,this, befDefAt,*useAt, eUSE);
|
||||||
lhs = dstIdent (*defAt,this, befDefAt,*useAt, eUSE);
|
lhs = dstIdent (*defAt,this, befDefAt,*useAt, eUSE);
|
||||||
lhs = COND_EXPR::boolOp (lhs, rhs, AND);
|
lhs = COND_EXPR::boolOp (lhs, rhs, AND);
|
||||||
if (defAt->isLlFlag(B))
|
if (defAt->ll()->isLlFlag(B))
|
||||||
rhs = COND_EXPR::idKte (0, 1);
|
rhs = COND_EXPR::idKte (0, 1);
|
||||||
else
|
else
|
||||||
rhs = COND_EXPR::idKte (0, 2);
|
rhs = COND_EXPR::idKte (0, 2);
|
||||||
@ -167,17 +168,17 @@ void Function::elimCondCodes ()
|
|||||||
default:
|
default:
|
||||||
notSup = TRUE;
|
notSup = TRUE;
|
||||||
std::cout << hex<<defAt->loc_ip;
|
std::cout << hex<<defAt->loc_ip;
|
||||||
reportError (JX_NOT_DEF, defAt->GetLlOpcode());
|
reportError (JX_NOT_DEF, defAt->ll()->GetLlOpcode());
|
||||||
flg |= PROC_ASM; /* generate asm */
|
flg |= PROC_ASM; /* generate asm */
|
||||||
}
|
}
|
||||||
if (! notSup)
|
if (! notSup)
|
||||||
{
|
{
|
||||||
exp = COND_EXPR::boolOp (lhs, rhs,condOpJCond[useAt->GetLlOpcode()-iJB]);
|
exp = COND_EXPR::boolOp (lhs, rhs,condOpJCond[useAtOp-iJB]);
|
||||||
useAt->setJCond(exp);
|
useAt->setJCond(exp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (useAt->GetLlOpcode() == iJCXZ)
|
else if (useAtOp == iJCXZ)
|
||||||
{
|
{
|
||||||
lhs = COND_EXPR::idReg (rCX, 0, &localId);
|
lhs = COND_EXPR::idReg (rCX, 0, &localId);
|
||||||
useAt->setRegDU (rCX, eUSE);
|
useAt->setRegDU (rCX, eUSE);
|
||||||
@ -191,7 +192,7 @@ void Function::elimCondCodes ()
|
|||||||
// ICODE &b(*useAt);
|
// ICODE &b(*useAt);
|
||||||
// if(a.GetLlOpcode() == iRCL)
|
// if(a.GetLlOpcode() == iRCL)
|
||||||
// {
|
// {
|
||||||
// if ((b.ic.ll.flg & NO_SRC) != NO_SRC) /* if there is src op */
|
// if ((b.ll()->flg & NO_SRC) != NO_SRC) /* if there is src op */
|
||||||
// rhs = COND_EXPR::id (*useAt, SRC, this, Icode.end(), *useAt, NONE);
|
// rhs = COND_EXPR::id (*useAt, SRC, this, Icode.end(), *useAt, NONE);
|
||||||
// lhs = COND_EXPR::id (*useAt, DST, this, Icode.end(), *useAt, USE_DEF);
|
// lhs = COND_EXPR::id (*useAt, DST, this, Icode.end(), *useAt, USE_DEF);
|
||||||
|
|
||||||
@ -205,20 +206,20 @@ void Function::elimCondCodes ()
|
|||||||
{
|
{
|
||||||
ICODE &a(*defAt);
|
ICODE &a(*defAt);
|
||||||
ICODE &b(*useAt);
|
ICODE &b(*useAt);
|
||||||
reportError (NOT_DEF_USE,a.GetLlOpcode(),b.GetLlOpcode());
|
reportError (NOT_DEF_USE,a.ll()->GetLlOpcode(),b.ll()->GetLlOpcode());
|
||||||
flg |= PROC_ASM; /* generate asm */
|
flg |= PROC_ASM; /* generate asm */
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check for extended basic block */
|
/* Check for extended basic block */
|
||||||
if ((pBB->size() == 1) &&(useAt->GetLlOpcode() >= iJB) && (useAt->GetLlOpcode() <= iJNS))
|
if ((pBB->size() == 1) &&(useAtOp >= iJB) && (useAtOp <= iJNS))
|
||||||
{
|
{
|
||||||
ICODE & prev(pBB->back()); /* For extended basic blocks - previous icode inst */
|
ICODE & prev(pBB->back()); /* For extended basic blocks - previous icode inst */
|
||||||
if (prev.ic.hl.opcode == HLI_JCOND)
|
if (prev.hl()->opcode == HLI_JCOND)
|
||||||
{
|
{
|
||||||
exp = prev.ic.hl.expr()->clone();
|
exp = prev.hl()->expr()->clone();
|
||||||
exp->changeBoolOp (condOpJCond[useAt->GetLlOpcode()-iJB]);
|
exp->changeBoolOp (condOpJCond[useAtOp-iJB]);
|
||||||
useAt->copyDU(prev, eUSE, eUSE);
|
useAt->copyDU(prev, eUSE, eUSE);
|
||||||
useAt->setJCond(exp);
|
useAt->setJCond(exp);
|
||||||
}
|
}
|
||||||
@ -226,7 +227,7 @@ void Function::elimCondCodes ()
|
|||||||
/* Error - definition not found for use of a cond code */
|
/* Error - definition not found for use of a cond code */
|
||||||
else if (defAt == pBB->rend2())
|
else if (defAt == pBB->rend2())
|
||||||
{
|
{
|
||||||
reportError(DEF_NOT_FOUND,useAt->GetLlOpcode());
|
reportError(DEF_NOT_FOUND,useAtOp);
|
||||||
//fatalError (DEF_NOT_FOUND, Icode.GetLlOpcode(useAt-1));
|
//fatalError (DEF_NOT_FOUND, Icode.GetLlOpcode(useAt-1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -311,10 +312,10 @@ void Function::liveRegAnalysis (std::bitset<32> &in_liveOut)
|
|||||||
if (flg & PROC_IS_FUNC)
|
if (flg & PROC_IS_FUNC)
|
||||||
{
|
{
|
||||||
auto picode = pbb->rbegin2(); /* icode of function return */
|
auto picode = pbb->rbegin2(); /* icode of function return */
|
||||||
if (picode->ic.hl.opcode == HLI_RET)
|
if (picode->hl()->opcode == HLI_RET)
|
||||||
{
|
{
|
||||||
//pbb->back().loc_ip
|
//pbb->back().loc_ip
|
||||||
picode->ic.hl.expr(COND_EXPR::idID (&retVal, &localId, (++pbb->rbegin2()).base()));
|
picode->hl()->expr(COND_EXPR::idID (&retVal, &localId, (++pbb->rbegin2()).base()));
|
||||||
picode->du.use = in_liveOut;
|
picode->du.use = in_liveOut;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -328,7 +329,7 @@ void Function::liveRegAnalysis (std::bitset<32> &in_liveOut)
|
|||||||
if (pbb->nodeType == CALL_NODE)
|
if (pbb->nodeType == CALL_NODE)
|
||||||
{
|
{
|
||||||
ICODE &ticode(pbb->back());
|
ICODE &ticode(pbb->back());
|
||||||
pcallee = ticode.ic.hl.call.proc;
|
pcallee = ticode.hl()->call.proc;
|
||||||
|
|
||||||
/* user/runtime routine */
|
/* user/runtime routine */
|
||||||
if (! (pcallee->flg & PROC_ISLIB))
|
if (! (pcallee->flg & PROC_ISLIB))
|
||||||
@ -414,10 +415,13 @@ void BB::genDU1()
|
|||||||
regi = 0;
|
regi = 0;
|
||||||
defRegIdx = 0;
|
defRegIdx = 0;
|
||||||
// foreach defined register
|
// foreach defined register
|
||||||
|
bitset<32> processed=0;
|
||||||
for (k = 0; k < INDEXBASE; k++)
|
for (k = 0; k < INDEXBASE; k++)
|
||||||
{
|
{
|
||||||
if (not picode->du.def.test(k))
|
if (not picode->du.def.test(k))
|
||||||
continue;
|
continue;
|
||||||
|
//printf("Processing reg")
|
||||||
|
processed |= duReg[k];
|
||||||
regi = (uint8_t)(k + 1); /* defined register */
|
regi = (uint8_t)(k + 1); /* defined register */
|
||||||
picode->du1.regi[defRegIdx] = regi;
|
picode->du1.regi[defRegIdx] = regi;
|
||||||
|
|
||||||
@ -443,7 +447,6 @@ void BB::genDU1()
|
|||||||
if ((ricode->du.def & duReg[regi]).any())
|
if ((ricode->du.def & duReg[regi]).any())
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if last definition of this register */
|
/* Check if last definition of this register */
|
||||||
if ((not (ticode->du.def & duReg[regi]).any()) and (this->liveOut & duReg[regi]).any())
|
if ((not (ticode->du.def & duReg[regi]).any()) and (this->liveOut & duReg[regi]).any())
|
||||||
picode->du.lastDefRegi |= duReg[regi];
|
picode->du.lastDefRegi |= duReg[regi];
|
||||||
@ -459,8 +462,8 @@ void BB::genDU1()
|
|||||||
* that are functions. The target icode is in the
|
* that are functions. The target icode is in the
|
||||||
* next basic block (unoptimized code) or somewhere else
|
* next basic block (unoptimized code) or somewhere else
|
||||||
* on optimized code. */
|
* on optimized code. */
|
||||||
if ((picode->ic.hl.opcode == HLI_CALL) &&
|
if ((picode->hl()->opcode == HLI_CALL) &&
|
||||||
(picode->ic.hl.call.proc->flg & PROC_IS_FUNC))
|
(picode->hl()->call.proc->flg & PROC_IS_FUNC))
|
||||||
{
|
{
|
||||||
tbb = this->edges[0].BBptr;
|
tbb = this->edges[0].BBptr;
|
||||||
for (ticode = tbb->begin2(); ticode != tbb->end2(); ticode++)
|
for (ticode = tbb->begin2(); ticode != tbb->end2(); ticode++)
|
||||||
@ -490,8 +493,8 @@ void BB::genDU1()
|
|||||||
* account by the programmer). */
|
* account by the programmer). */
|
||||||
if (picode->valid() and not picode->du1.used(defRegIdx) and
|
if (picode->valid() and not picode->du1.used(defRegIdx) and
|
||||||
(not (picode->du.lastDefRegi & duReg[regi]).any()) &&
|
(not (picode->du.lastDefRegi & duReg[regi]).any()) &&
|
||||||
(not ((picode->ic.hl.opcode == HLI_CALL) &&
|
(not ((picode->hl()->opcode == HLI_CALL) &&
|
||||||
(picode->ic.hl.call.proc->flg & PROC_ISLIB))))
|
(picode->hl()->call.proc->flg & PROC_ISLIB))))
|
||||||
{
|
{
|
||||||
if (! (this->liveOut & duReg[regi]).any()) /* not liveOut */
|
if (! (this->liveOut & duReg[regi]).any()) /* not liveOut */
|
||||||
{
|
{
|
||||||
@ -553,7 +556,7 @@ static void forwardSubs (COND_EXPR *lhs, COND_EXPR *rhs, iICODE picode,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
/* Insert on rhs of ticode, if possible */
|
/* Insert on rhs of ticode, if possible */
|
||||||
res = insertSubTreeReg (rhs, &ticode->ic.hl.asgn.rhs,
|
res = insertSubTreeReg (rhs, &ticode->hl()->asgn.rhs,
|
||||||
locsym->id_arr[lhs->expr.ident.idNode.regiIdx].id.regi,
|
locsym->id_arr[lhs->expr.ident.idNode.regiIdx].id.regi,
|
||||||
locsym);
|
locsym);
|
||||||
if (res)
|
if (res)
|
||||||
@ -564,7 +567,7 @@ static void forwardSubs (COND_EXPR *lhs, COND_EXPR *rhs, iICODE picode,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Try to insert it on lhs of ticode*/
|
/* Try to insert it on lhs of ticode*/
|
||||||
res = insertSubTreeReg (rhs, &ticode->ic.hl.asgn.lhs,
|
res = insertSubTreeReg (rhs, &ticode->hl()->asgn.lhs,
|
||||||
locsym->id_arr[lhs->expr.ident.idNode.regiIdx].id.regi,
|
locsym->id_arr[lhs->expr.ident.idNode.regiIdx].id.regi,
|
||||||
locsym);
|
locsym);
|
||||||
if (res)
|
if (res)
|
||||||
@ -587,7 +590,7 @@ static void forwardSubsLong (int longIdx, COND_EXPR *exp, iICODE picode,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
/* Insert on rhs of ticode, if possible */
|
/* Insert on rhs of ticode, if possible */
|
||||||
res = insertSubTreeLongReg (exp, &ticode->ic.hl.asgn.rhs, longIdx);
|
res = insertSubTreeLongReg (exp, &ticode->hl()->asgn.rhs, longIdx);
|
||||||
if (res)
|
if (res)
|
||||||
{
|
{
|
||||||
picode->invalidate();
|
picode->invalidate();
|
||||||
@ -596,7 +599,7 @@ static void forwardSubsLong (int longIdx, COND_EXPR *exp, iICODE picode,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Try to insert it on lhs of ticode*/
|
/* Try to insert it on lhs of ticode*/
|
||||||
res = insertSubTreeLongReg (exp, &ticode->ic.hl.asgn.lhs, longIdx);
|
res = insertSubTreeLongReg (exp, &ticode->hl()->asgn.lhs, longIdx);
|
||||||
if (res)
|
if (res)
|
||||||
{
|
{
|
||||||
picode->invalidate();
|
picode->invalidate();
|
||||||
@ -677,13 +680,13 @@ static void processCArg (Function * pp, Function * pProc, ICODE * picode, int nu
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
adjustActArgType (exp, pp->args.sym[numArgs].type, pProc);
|
adjustActArgType (exp, pp->args.sym[numArgs].type, pProc);
|
||||||
res = picode->newStkArg (exp, picode->ic.ll.opcode, pProc);
|
res = picode->newStkArg (exp, picode->ll()->opcode, pProc);
|
||||||
}
|
}
|
||||||
else /* user function */
|
else /* user function */
|
||||||
{
|
{
|
||||||
if (pp->args.numArgs > 0)
|
if (pp->args.numArgs > 0)
|
||||||
pp->args.adjustForArgType (numArgs, expType (exp, pProc));
|
pp->args.adjustForArgType (numArgs, expType (exp, pProc));
|
||||||
res = picode->newStkArg (exp, picode->ic.ll.opcode, pProc);
|
res = picode->newStkArg (exp, picode->ll()->opcode, pProc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Do not update the size of k if the expression was a segment register
|
/* Do not update the size of k if the expression was a segment register
|
||||||
@ -738,33 +741,33 @@ void Function::findExps()
|
|||||||
regi = picode->du1.regi[0];
|
regi = picode->du1.regi[0];
|
||||||
|
|
||||||
/* Check if we can forward substitute this register */
|
/* Check if we can forward substitute this register */
|
||||||
switch (picode->ic.hl.opcode)
|
switch (picode->hl()->opcode)
|
||||||
{
|
{
|
||||||
case HLI_ASSIGN:
|
case HLI_ASSIGN:
|
||||||
/* Replace rhs of current icode into target
|
/* Replace rhs of current icode into target
|
||||||
* icode expression */
|
* icode expression */
|
||||||
ticode = picode->du1.idx[0].uses.front();
|
ticode = picode->du1.idx[0].uses.front();
|
||||||
if ((picode->du.lastDefRegi & duReg[regi]).any() &&
|
if ((picode->du.lastDefRegi & duReg[regi]).any() &&
|
||||||
((ticode->ic.hl.opcode != HLI_CALL) &&
|
((ticode->hl()->opcode != HLI_CALL) &&
|
||||||
(ticode->ic.hl.opcode != HLI_RET)))
|
(ticode->hl()->opcode != HLI_RET)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (xClear (picode->ic.hl.asgn.rhs, picode,
|
if (xClear (picode->hl()->asgn.rhs, picode,
|
||||||
picode->du1.idx[0].uses[0], lastInst, this))
|
picode->du1.idx[0].uses[0], lastInst, this))
|
||||||
{
|
{
|
||||||
switch (ticode->ic.hl.opcode) {
|
switch (ticode->hl()->opcode) {
|
||||||
case HLI_ASSIGN:
|
case HLI_ASSIGN:
|
||||||
forwardSubs (picode->ic.hl.asgn.lhs,
|
forwardSubs (picode->hl()->asgn.lhs,
|
||||||
picode->ic.hl.asgn.rhs,
|
picode->hl()->asgn.rhs,
|
||||||
picode, ticode, &localId,
|
picode, ticode, &localId,
|
||||||
numHlIcodes);
|
numHlIcodes);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HLI_JCOND: case HLI_PUSH: case HLI_RET:
|
case HLI_JCOND: case HLI_PUSH: case HLI_RET:
|
||||||
res = insertSubTreeReg (
|
res = insertSubTreeReg (
|
||||||
picode->ic.hl.asgn.rhs,
|
picode->hl()->asgn.rhs,
|
||||||
&ticode->ic.hl.exp.v,
|
&ticode->hl()->exp.v,
|
||||||
localId.id_arr[picode->ic.hl.asgn.lhs->expr.ident.idNode.regiIdx].id.regi,
|
localId.id_arr[picode->hl()->asgn.lhs->expr.ident.idNode.regiIdx].id.regi,
|
||||||
&localId);
|
&localId);
|
||||||
if (res)
|
if (res)
|
||||||
{
|
{
|
||||||
@ -785,22 +788,22 @@ void Function::findExps()
|
|||||||
case HLI_POP:
|
case HLI_POP:
|
||||||
ticode = picode->du1.idx[0].uses.front();
|
ticode = picode->du1.idx[0].uses.front();
|
||||||
if ((picode->du.lastDefRegi & duReg[regi]).any() &&
|
if ((picode->du.lastDefRegi & duReg[regi]).any() &&
|
||||||
((ticode->ic.hl.opcode != HLI_CALL) &&
|
((ticode->hl()->opcode != HLI_CALL) &&
|
||||||
(ticode->ic.hl.opcode != HLI_RET)))
|
(ticode->hl()->opcode != HLI_RET)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
exp = g_exp_stk.pop(); /* pop last exp pushed */
|
exp = g_exp_stk.pop(); /* pop last exp pushed */
|
||||||
switch (ticode->ic.hl.opcode) {
|
switch (ticode->hl()->opcode) {
|
||||||
case HLI_ASSIGN:
|
case HLI_ASSIGN:
|
||||||
forwardSubs (picode->ic.hl.expr(), exp,
|
forwardSubs (picode->hl()->expr(), exp,
|
||||||
picode, ticode, &localId,
|
picode, ticode, &localId,
|
||||||
numHlIcodes);
|
numHlIcodes);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HLI_JCOND: case HLI_PUSH: case HLI_RET:
|
case HLI_JCOND: case HLI_PUSH: case HLI_RET:
|
||||||
res = insertSubTreeReg (exp,
|
res = insertSubTreeReg (exp,
|
||||||
&ticode->ic.hl.exp.v,
|
&ticode->hl()->exp.v,
|
||||||
localId.id_arr[picode->ic.hl.expr()->expr.ident.idNode.regiIdx].id.regi,
|
localId.id_arr[picode->hl()->expr()->expr.ident.idNode.regiIdx].id.regi,
|
||||||
&localId);
|
&localId);
|
||||||
if (res)
|
if (res)
|
||||||
{
|
{
|
||||||
@ -819,19 +822,19 @@ void Function::findExps()
|
|||||||
|
|
||||||
case HLI_CALL:
|
case HLI_CALL:
|
||||||
ticode = picode->du1.idx[0].uses.front();
|
ticode = picode->du1.idx[0].uses.front();
|
||||||
switch (ticode->ic.hl.opcode) {
|
switch (ticode->hl()->opcode) {
|
||||||
case HLI_ASSIGN:
|
case HLI_ASSIGN:
|
||||||
exp = COND_EXPR::idFunc (
|
exp = COND_EXPR::idFunc (
|
||||||
picode->ic.hl.call.proc,
|
picode->hl()->call.proc,
|
||||||
picode->ic.hl.call.args);
|
picode->hl()->call.args);
|
||||||
res = insertSubTreeReg (exp,
|
res = insertSubTreeReg (exp,
|
||||||
&ticode->ic.hl.asgn.rhs,
|
&ticode->hl()->asgn.rhs,
|
||||||
picode->ic.hl.call.proc->retVal.id.regi,
|
picode->hl()->call.proc->retVal.id.regi,
|
||||||
&localId);
|
&localId);
|
||||||
if (! res)
|
if (! res)
|
||||||
insertSubTreeReg (exp,
|
insertSubTreeReg (exp,
|
||||||
&ticode->ic.hl.asgn.lhs,
|
&ticode->hl()->asgn.lhs,
|
||||||
picode->ic.hl.call.proc->retVal.id.regi,
|
picode->hl()->call.proc->retVal.id.regi,
|
||||||
&localId);
|
&localId);
|
||||||
/*** TODO: HERE missing: 2 regs ****/
|
/*** TODO: HERE missing: 2 regs ****/
|
||||||
picode->invalidate();
|
picode->invalidate();
|
||||||
@ -839,16 +842,16 @@ void Function::findExps()
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case HLI_PUSH: case HLI_RET:
|
case HLI_PUSH: case HLI_RET:
|
||||||
ticode->ic.hl.expr( COND_EXPR::idFunc ( picode->ic.hl.call.proc, picode->ic.hl.call.args) );
|
ticode->hl()->expr( COND_EXPR::idFunc ( picode->hl()->call.proc, picode->hl()->call.args) );
|
||||||
picode->invalidate();
|
picode->invalidate();
|
||||||
numHlIcodes--;
|
numHlIcodes--;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HLI_JCOND:
|
case HLI_JCOND:
|
||||||
exp = COND_EXPR::idFunc ( picode->ic.hl.call.proc, picode->ic.hl.call.args);
|
exp = COND_EXPR::idFunc ( picode->hl()->call.proc, picode->hl()->call.args);
|
||||||
retVal = &picode->ic.hl.call.proc->retVal,
|
retVal = &picode->hl()->call.proc->retVal,
|
||||||
res = insertSubTreeReg (exp,
|
res = insertSubTreeReg (exp,
|
||||||
&ticode->ic.hl.exp.v,
|
&ticode->hl()->exp.v,
|
||||||
retVal->id.regi, &localId);
|
retVal->id.regi, &localId);
|
||||||
if (res) /* was substituted */
|
if (res) /* was substituted */
|
||||||
{
|
{
|
||||||
@ -873,7 +876,7 @@ void Function::findExps()
|
|||||||
/* Check for only one use of these registers */
|
/* Check for only one use of these registers */
|
||||||
if ((picode->du1.numUses(0) == 1) and (picode->du1.numUses(1) == 1))
|
if ((picode->du1.numUses(0) == 1) and (picode->du1.numUses(1) == 1))
|
||||||
{
|
{
|
||||||
switch (picode->ic.hl.opcode) {
|
switch (picode->hl()->opcode) {
|
||||||
case HLI_ASSIGN:
|
case HLI_ASSIGN:
|
||||||
/* Replace rhs of current icode into target
|
/* Replace rhs of current icode into target
|
||||||
* icode expression */
|
* icode expression */
|
||||||
@ -881,22 +884,22 @@ void Function::findExps()
|
|||||||
{
|
{
|
||||||
ticode = picode->du1.idx[0].uses.front();
|
ticode = picode->du1.idx[0].uses.front();
|
||||||
if ((picode->du.lastDefRegi & duReg[regi]).any() &&
|
if ((picode->du.lastDefRegi & duReg[regi]).any() &&
|
||||||
((ticode->ic.hl.opcode != HLI_CALL) &&
|
((ticode->hl()->opcode != HLI_CALL) &&
|
||||||
(ticode->ic.hl.opcode != HLI_RET)))
|
(ticode->hl()->opcode != HLI_RET)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
switch (ticode->ic.hl.opcode) {
|
switch (ticode->hl()->opcode) {
|
||||||
case HLI_ASSIGN:
|
case HLI_ASSIGN:
|
||||||
forwardSubsLong (picode->ic.hl.asgn.lhs->expr.ident.idNode.longIdx,
|
forwardSubsLong (picode->hl()->asgn.lhs->expr.ident.idNode.longIdx,
|
||||||
picode->ic.hl.asgn.rhs, picode,ticode,
|
picode->hl()->asgn.rhs, picode,ticode,
|
||||||
&numHlIcodes);
|
&numHlIcodes);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HLI_JCOND: case HLI_PUSH: case HLI_RET:
|
case HLI_JCOND: case HLI_PUSH: case HLI_RET:
|
||||||
res = insertSubTreeLongReg (
|
res = insertSubTreeLongReg (
|
||||||
picode->ic.hl.asgn.rhs,
|
picode->hl()->asgn.rhs,
|
||||||
&ticode->ic.hl.exp.v,
|
&ticode->hl()->exp.v,
|
||||||
picode->ic.hl.asgn.lhs->expr.ident.idNode.longIdx);
|
picode->hl()->asgn.lhs->expr.ident.idNode.longIdx);
|
||||||
if (res)
|
if (res)
|
||||||
{
|
{
|
||||||
picode->invalidate();
|
picode->invalidate();
|
||||||
@ -918,20 +921,20 @@ void Function::findExps()
|
|||||||
{
|
{
|
||||||
ticode = picode->du1.idx[0].uses.front();
|
ticode = picode->du1.idx[0].uses.front();
|
||||||
if ((picode->du.lastDefRegi & duReg[regi]).any() &&
|
if ((picode->du.lastDefRegi & duReg[regi]).any() &&
|
||||||
((ticode->ic.hl.opcode != HLI_CALL) &&
|
((ticode->hl()->opcode != HLI_CALL) &&
|
||||||
(ticode->ic.hl.opcode != HLI_RET)))
|
(ticode->hl()->opcode != HLI_RET)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
exp = g_exp_stk.pop(); /* pop last exp pushed */
|
exp = g_exp_stk.pop(); /* pop last exp pushed */
|
||||||
switch (ticode->ic.hl.opcode) {
|
switch (ticode->hl()->opcode) {
|
||||||
case HLI_ASSIGN:
|
case HLI_ASSIGN:
|
||||||
forwardSubsLong (picode->ic.hl.expr()->expr.ident.idNode.longIdx,
|
forwardSubsLong (picode->hl()->expr()->expr.ident.idNode.longIdx,
|
||||||
exp, picode, ticode, &numHlIcodes);
|
exp, picode, ticode, &numHlIcodes);
|
||||||
break;
|
break;
|
||||||
case HLI_JCOND: case HLI_PUSH:
|
case HLI_JCOND: case HLI_PUSH:
|
||||||
res = insertSubTreeLongReg (exp,
|
res = insertSubTreeLongReg (exp,
|
||||||
&ticode->ic.hl.exp.v,
|
&ticode->hl()->exp.v,
|
||||||
picode->ic.hl.asgn.lhs->expr.ident.idNode.longIdx);
|
picode->hl()->asgn.lhs->expr.ident.idNode.longIdx);
|
||||||
if (res)
|
if (res)
|
||||||
{
|
{
|
||||||
picode->invalidate();
|
picode->invalidate();
|
||||||
@ -946,30 +949,30 @@ void Function::findExps()
|
|||||||
|
|
||||||
case HLI_CALL: /* check for function return */
|
case HLI_CALL: /* check for function return */
|
||||||
ticode = picode->du1.idx[0].uses.front();
|
ticode = picode->du1.idx[0].uses.front();
|
||||||
switch (ticode->ic.hl.opcode)
|
switch (ticode->hl()->opcode)
|
||||||
{
|
{
|
||||||
case HLI_ASSIGN:
|
case HLI_ASSIGN:
|
||||||
exp = COND_EXPR::idFunc (
|
exp = COND_EXPR::idFunc (
|
||||||
picode->ic.hl.call.proc,
|
picode->hl()->call.proc,
|
||||||
picode->ic.hl.call.args);
|
picode->hl()->call.args);
|
||||||
ticode->ic.hl.asgn.lhs =
|
ticode->hl()->asgn.lhs =
|
||||||
COND_EXPR::idLong(&localId, DST, ticode,HIGH_FIRST, picode, eDEF, 1);
|
COND_EXPR::idLong(&localId, DST, ticode,HIGH_FIRST, picode, eDEF, 1);
|
||||||
ticode->ic.hl.asgn.rhs = exp;
|
ticode->hl()->asgn.rhs = exp;
|
||||||
picode->invalidate();
|
picode->invalidate();
|
||||||
numHlIcodes--;
|
numHlIcodes--;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HLI_PUSH: case HLI_RET:
|
case HLI_PUSH: case HLI_RET:
|
||||||
ticode->ic.hl.expr( COND_EXPR::idFunc ( picode->ic.hl.call.proc, picode->ic.hl.call.args) );
|
ticode->hl()->expr( COND_EXPR::idFunc ( picode->hl()->call.proc, picode->hl()->call.args) );
|
||||||
picode->invalidate();
|
picode->invalidate();
|
||||||
numHlIcodes--;
|
numHlIcodes--;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HLI_JCOND:
|
case HLI_JCOND:
|
||||||
exp = COND_EXPR::idFunc ( picode->ic.hl.call.proc, picode->ic.hl.call.args);
|
exp = COND_EXPR::idFunc ( picode->hl()->call.proc, picode->hl()->call.args);
|
||||||
retVal = &picode->ic.hl.call.proc->retVal;
|
retVal = &picode->hl()->call.proc->retVal;
|
||||||
res = insertSubTreeLongReg (exp,
|
res = insertSubTreeLongReg (exp,
|
||||||
&ticode->ic.hl.exp.v,
|
&ticode->hl()->exp.v,
|
||||||
localId.newLongReg ( retVal->type, retVal->id.longId.h,
|
localId.newLongReg ( retVal->type, retVal->id.longId.h,
|
||||||
retVal->id.longId.l, picode));
|
retVal->id.longId.l, picode));
|
||||||
if (res) /* was substituted */
|
if (res) /* was substituted */
|
||||||
@ -991,9 +994,9 @@ void Function::findExps()
|
|||||||
/* HLI_PUSH doesn't define any registers, only uses registers.
|
/* HLI_PUSH doesn't define any registers, only uses registers.
|
||||||
* Push the associated expression to the register on the local
|
* Push the associated expression to the register on the local
|
||||||
* expression stack */
|
* expression stack */
|
||||||
else if (picode->ic.hl.opcode == HLI_PUSH)
|
else if (picode->hl()->opcode == HLI_PUSH)
|
||||||
{
|
{
|
||||||
g_exp_stk.push(picode->ic.hl.expr());
|
g_exp_stk.push(picode->hl()->expr());
|
||||||
picode->invalidate();
|
picode->invalidate();
|
||||||
numHlIcodes--;
|
numHlIcodes--;
|
||||||
}
|
}
|
||||||
@ -1001,13 +1004,13 @@ void Function::findExps()
|
|||||||
/* For HLI_CALL instructions that use arguments from the stack,
|
/* For HLI_CALL instructions that use arguments from the stack,
|
||||||
* pop them from the expression stack and place them on the
|
* pop them from the expression stack and place them on the
|
||||||
* procedure's argument list */
|
* procedure's argument list */
|
||||||
if ((picode->ic.hl.opcode == HLI_CALL) &&
|
if ((picode->hl()->opcode == HLI_CALL) &&
|
||||||
! (picode->ic.hl.call.proc->flg & REG_ARGS))
|
! (picode->hl()->call.proc->flg & REG_ARGS))
|
||||||
{ Function * pp;
|
{ Function * pp;
|
||||||
int cb, numArgs;
|
int cb, numArgs;
|
||||||
boolT res;
|
boolT res;
|
||||||
|
|
||||||
pp = picode->ic.hl.call.proc;
|
pp = picode->hl()->call.proc;
|
||||||
if (pp->flg & CALL_PASCAL)
|
if (pp->flg & CALL_PASCAL)
|
||||||
{
|
{
|
||||||
cb = pp->cbParam; /* fixed # arguments */
|
cb = pp->cbParam; /* fixed # arguments */
|
||||||
@ -1018,13 +1021,13 @@ void Function::findExps()
|
|||||||
{
|
{
|
||||||
if (pp->args.numArgs > 0)
|
if (pp->args.numArgs > 0)
|
||||||
adjustActArgType(exp, pp->args.sym[numArgs].type, this);
|
adjustActArgType(exp, pp->args.sym[numArgs].type, this);
|
||||||
res = picode->newStkArg (exp, picode->ic.ll.opcode, this);
|
res = picode->newStkArg (exp, picode->ll()->opcode, this);
|
||||||
}
|
}
|
||||||
else /* user function */
|
else /* user function */
|
||||||
{
|
{
|
||||||
if (pp->args.numArgs >0)
|
if (pp->args.numArgs >0)
|
||||||
pp->args.adjustForArgType (numArgs,expType (exp, this));
|
pp->args.adjustForArgType (numArgs,expType (exp, this));
|
||||||
res = picode->newStkArg (exp,picode->ic.ll.opcode, this);
|
res = picode->newStkArg (exp,picode->ll()->opcode, this);
|
||||||
}
|
}
|
||||||
if (res == FALSE)
|
if (res == FALSE)
|
||||||
k += hlTypeSize (exp, this);
|
k += hlTypeSize (exp, this);
|
||||||
@ -1032,12 +1035,12 @@ void Function::findExps()
|
|||||||
}
|
}
|
||||||
else /* CALL_C */
|
else /* CALL_C */
|
||||||
{
|
{
|
||||||
cb = picode->ic.hl.call.args->cb;
|
cb = picode->hl()->call.args->cb;
|
||||||
numArgs = 0;
|
numArgs = 0;
|
||||||
if (cb)
|
if (cb)
|
||||||
for (k = 0; k < cb; numArgs++)
|
for (k = 0; k < cb; numArgs++)
|
||||||
processCArg (pp, this, &(*picode), numArgs, &k);
|
processCArg (pp, this, &(*picode), numArgs, &k);
|
||||||
else if ((cb == 0) && (picode->ic.ll.flg & REST_STK))
|
else if ((cb == 0) && picode->ll()->isLlFlag(REST_STK))
|
||||||
while (! g_exp_stk.empty())
|
while (! g_exp_stk.empty())
|
||||||
{
|
{
|
||||||
processCArg (pp, this, &(*picode), numArgs, &k);
|
processCArg (pp, this, &(*picode), numArgs, &k);
|
||||||
@ -1048,13 +1051,13 @@ void Function::findExps()
|
|||||||
|
|
||||||
/* If we could not substitute the result of a function,
|
/* If we could not substitute the result of a function,
|
||||||
* assign it to the corresponding registers */
|
* assign it to the corresponding registers */
|
||||||
if ((picode->ic.hl.opcode == HLI_CALL) &&
|
if ((picode->hl()->opcode == HLI_CALL) &&
|
||||||
((picode->ic.hl.call.proc->flg & PROC_ISLIB) !=
|
((picode->hl()->call.proc->flg & PROC_ISLIB) !=
|
||||||
PROC_ISLIB) && (not picode->du1.used(0)) &&
|
PROC_ISLIB) && (not picode->du1.used(0)) &&
|
||||||
(picode->du1.numRegsDef > 0))
|
(picode->du1.numRegsDef > 0))
|
||||||
{
|
{
|
||||||
exp = COND_EXPR::idFunc (picode->ic.hl.call.proc, picode->ic.hl.call.args);
|
exp = COND_EXPR::idFunc (picode->hl()->call.proc, picode->hl()->call.args);
|
||||||
lhs = COND_EXPR::idID (&picode->ic.hl.call.proc->retVal, &localId, picode);
|
lhs = COND_EXPR::idID (&picode->hl()->call.proc->retVal, &localId, picode);
|
||||||
picode->setAsgn(lhs, exp);
|
picode->setAsgn(lhs, exp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
106
src/disassem.cpp
106
src/disassem.cpp
@ -213,22 +213,22 @@ void disassem(int pass, Function * ppProc)
|
|||||||
//for (i = 0; i < numIcode; i++)
|
//for (i = 0; i < numIcode; i++)
|
||||||
for( ICODE &icode : pc)
|
for( ICODE &icode : pc)
|
||||||
{
|
{
|
||||||
if ((icode.ic.ll.flg & I) && !(icode.ic.ll.flg & JMP_ICODE) &&
|
LLInst *ll=icode.ll();
|
||||||
JmpInst(icode.ic.ll.opcode))
|
if (ll->isLlFlag(I) && ! ll->isLlFlag(JMP_ICODE) && JmpInst(ll->opcode))
|
||||||
{
|
{
|
||||||
/* Replace the immediate operand with an icode index */
|
/* Replace the immediate operand with an icode index */
|
||||||
iICODE labTgt=pc.labelSrch(icode.ic.ll.src.op());
|
iICODE labTgt=pc.labelSrch(ll->src.op());
|
||||||
if (labTgt!=pc.end())
|
if (labTgt!=pc.end())
|
||||||
{
|
{
|
||||||
icode.ic.ll.src.SetImmediateOp(labTgt->loc_ip);
|
ll->src.SetImmediateOp(labTgt->loc_ip);
|
||||||
/* This icode is the target of a jump */
|
/* This icode is the target of a jump */
|
||||||
labTgt->ic.ll.flg |= TARGET;
|
labTgt->ll()->SetLlFlag(TARGET);
|
||||||
icode.ic.ll.flg |= JMP_ICODE; /* So its not done twice */
|
ll->SetLlFlag(JMP_ICODE); /* So its not done twice */
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* This jump cannot be linked to a label */
|
/* This jump cannot be linked to a label */
|
||||||
icode.ic.ll.flg |= NO_LABEL;
|
ll->SetLlFlag(NO_LABEL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -271,21 +271,21 @@ static void dis1Line(ICODE &icode_iter, int pass)
|
|||||||
|
|
||||||
oper_stream << uppercase;
|
oper_stream << uppercase;
|
||||||
hex_bytes << uppercase;
|
hex_bytes << uppercase;
|
||||||
LLInst &_IcLL(icode_iter.ic.ll);
|
LLInst &_IcLL(*icode_iter.ll());
|
||||||
/* Disassembly stage 1 --
|
/* Disassembly stage 1 --
|
||||||
* Do not try to display NO_CODE entries or synthetic instructions,
|
* Do not try to display NO_CODE entries or synthetic instructions,
|
||||||
* other than JMPs, that have been introduced for def/use analysis. */
|
* other than JMPs, that have been introduced for def/use analysis. */
|
||||||
if ((option.asm1) &&
|
if ((option.asm1) &&
|
||||||
((_IcLL.flg & NO_CODE) ||
|
( _IcLL.isLlFlag(NO_CODE) ||
|
||||||
((_IcLL.flg & SYNTHETIC) && (_IcLL.opcode != iJMP))))
|
(_IcLL.isLlFlag(SYNTHETIC) && (_IcLL.opcode != iJMP))))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (_IcLL.flg & NO_CODE)
|
else if (_IcLL.isLlFlag(NO_CODE))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_IcLL.flg & (TARGET | CASE))
|
if (_IcLL.isLlFlag(TARGET | CASE))
|
||||||
{
|
{
|
||||||
if (pass == 3)
|
if (pass == 3)
|
||||||
cCode.appendCode("\n"); /* Print to c code buffer */
|
cCode.appendCode("\n"); /* Print to c code buffer */
|
||||||
@ -294,7 +294,7 @@ static void dis1Line(ICODE &icode_iter, int pass)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Find next instruction label and print hex bytes */
|
/* Find next instruction label and print hex bytes */
|
||||||
if (_IcLL.flg & SYNTHETIC)
|
if (_IcLL.isLlFlag(SYNTHETIC))
|
||||||
nextInst = _IcLL.label;
|
nextInst = _IcLL.label;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -321,7 +321,7 @@ static void dis1Line(ICODE &icode_iter, int pass)
|
|||||||
{
|
{
|
||||||
lab_contents << ':'; /* Also removes the null */
|
lab_contents << ':'; /* Also removes the null */
|
||||||
}
|
}
|
||||||
else if (_IcLL.flg & TARGET) /* Symbols override Lnn labels */
|
else if (_IcLL.isLlFlag(TARGET)) /* Symbols override Lnn labels */
|
||||||
{
|
{
|
||||||
/* Print label */
|
/* Print label */
|
||||||
if (pl.count(icode_iter.loc_ip)==0)
|
if (pl.count(icode_iter.loc_ip)==0)
|
||||||
@ -332,7 +332,7 @@ static void dis1Line(ICODE &icode_iter, int pass)
|
|||||||
}
|
}
|
||||||
oper_stream<< lab_contents.str();
|
oper_stream<< lab_contents.str();
|
||||||
}
|
}
|
||||||
if (_IcLL.opcode == iSIGNEX && (_IcLL.flg & B))
|
if (_IcLL.opcode == iSIGNEX && _IcLL.isLlFlag(B))
|
||||||
{
|
{
|
||||||
_IcLL.opcode = iCBW;
|
_IcLL.opcode = iCBW;
|
||||||
}
|
}
|
||||||
@ -342,7 +342,7 @@ static void dis1Line(ICODE &icode_iter, int pass)
|
|||||||
{
|
{
|
||||||
case iADD: case iADC: case iSUB: case iSBB: case iAND: case iOR:
|
case iADD: case iADC: case iSUB: case iSBB: case iAND: case iOR:
|
||||||
case iXOR: case iTEST: case iCMP: case iMOV: case iLEA: case iXCHG:
|
case iXOR: case iTEST: case iCMP: case iMOV: case iLEA: case iXCHG:
|
||||||
strDst(oper_stream,_IcLL.flg, _IcLL.dst);
|
strDst(oper_stream,_IcLL.GetLlFlag(), _IcLL.dst);
|
||||||
strSrc(oper_stream,_IcLL);
|
strSrc(oper_stream,_IcLL);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -352,42 +352,42 @@ static void dis1Line(ICODE &icode_iter, int pass)
|
|||||||
|
|
||||||
case iSAR: case iSHL: case iSHR: case iRCL: case iRCR: case iROL:
|
case iSAR: case iSHL: case iSHR: case iRCL: case iRCR: case iROL:
|
||||||
case iROR:
|
case iROR:
|
||||||
strDst(oper_stream,_IcLL.flg | I, _IcLL.dst);
|
strDst(oper_stream,_IcLL.GetLlFlag() | I, _IcLL.dst);
|
||||||
if(_IcLL.flg & I)
|
if(_IcLL.isLlFlag(I))
|
||||||
strSrc(oper_stream,_IcLL);
|
strSrc(oper_stream,_IcLL);
|
||||||
else
|
else
|
||||||
oper_stream<<", cl";
|
oper_stream<<", cl";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case iINC: case iDEC: case iNEG: case iNOT: case iPOP:
|
case iINC: case iDEC: case iNEG: case iNOT: case iPOP:
|
||||||
strDst(oper_stream,_IcLL.flg | I, _IcLL.dst);
|
strDst(oper_stream,_IcLL.GetLlFlag() | I, _IcLL.dst);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case iPUSH:
|
case iPUSH:
|
||||||
if (_IcLL.flg & I)
|
if (_IcLL.isLlFlag(I))
|
||||||
{
|
{
|
||||||
oper_stream<<strHex(_IcLL.src.op());
|
oper_stream<<strHex(_IcLL.src.op());
|
||||||
// strcpy(p + WID_PTR, strHex(pIcode->ic.ll.immed.op));
|
// strcpy(p + WID_PTR, strHex(pIcode->ll()->immed.op));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strDst(oper_stream,_IcLL.flg | I, _IcLL.dst);
|
strDst(oper_stream,_IcLL.GetLlFlag() | I, _IcLL.dst);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case iDIV: case iIDIV: case iMUL: case iIMUL: case iMOD:
|
case iDIV: case iIDIV: case iMUL: case iIMUL: case iMOD:
|
||||||
if (_IcLL.flg & I)
|
if (_IcLL.isLlFlag(I))
|
||||||
{
|
{
|
||||||
strDst(oper_stream,_IcLL.flg, _IcLL.dst) <<", ";
|
strDst(oper_stream,_IcLL.GetLlFlag(), _IcLL.dst) <<", ";
|
||||||
formatRM(oper_stream, _IcLL.flg, _IcLL.src);
|
formatRM(oper_stream, _IcLL.GetLlFlag(), _IcLL.src);
|
||||||
strSrc(oper_stream,_IcLL);
|
strSrc(oper_stream,_IcLL);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
strDst(oper_stream,_IcLL.flg | I, _IcLL.src);
|
strDst(oper_stream,_IcLL.GetLlFlag() | I, _IcLL.src);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case iLDS: case iLES: case iBOUND:
|
case iLDS: case iLES: case iBOUND:
|
||||||
strDst(oper_stream,_IcLL.flg, _IcLL.dst)<<", dword ptr";
|
strDst(oper_stream,_IcLL.GetLlFlag(), _IcLL.dst)<<", dword ptr";
|
||||||
strSrc(oper_stream,_IcLL,true);
|
strSrc(oper_stream,_IcLL,true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -403,18 +403,18 @@ static void dis1Line(ICODE &icode_iter, int pass)
|
|||||||
ICODE *lab=pc.GetIcode(_IcLL.src.op());
|
ICODE *lab=pc.GetIcode(_IcLL.src.op());
|
||||||
selectTable(Label);
|
selectTable(Label);
|
||||||
if ((_IcLL.src.op() < (uint32_t)numIcode) && /* Ensure in range */
|
if ((_IcLL.src.op() < (uint32_t)numIcode) && /* Ensure in range */
|
||||||
readVal(oper_stream, lab->ic.ll.label, 0))
|
readVal(oper_stream, lab->ll()->label, 0))
|
||||||
{
|
{
|
||||||
break; /* Symbolic label. Done */
|
break; /* Symbolic label. Done */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_IcLL.flg & NO_LABEL)
|
if (_IcLL.isLlFlag(NO_LABEL))
|
||||||
{
|
{
|
||||||
//strcpy(p + WID_PTR, strHex(pIcode->ic.ll.immed.op));
|
//strcpy(p + WID_PTR, strHex(pIcode->ll()->immed.op));
|
||||||
oper_stream<<strHex(_IcLL.src.op());
|
oper_stream<<strHex(_IcLL.src.op());
|
||||||
}
|
}
|
||||||
else if (_IcLL.flg & I)
|
else if (_IcLL.isLlFlag(I) )
|
||||||
{
|
{
|
||||||
j = _IcLL.src.op();
|
j = _IcLL.src.op();
|
||||||
if (pl.count(j)==0) /* Forward jump */
|
if (pl.count(j)==0) /* Forward jump */
|
||||||
@ -439,7 +439,7 @@ static void dis1Line(ICODE &icode_iter, int pass)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case iCALL: case iCALLF:
|
case iCALL: case iCALLF:
|
||||||
if (_IcLL.flg & I)
|
if (_IcLL.isLlFlag(I))
|
||||||
{
|
{
|
||||||
if((_IcLL.opcode == iCALL))
|
if((_IcLL.opcode == iCALL))
|
||||||
oper_stream<< "near";
|
oper_stream<< "near";
|
||||||
@ -462,7 +462,7 @@ static void dis1Line(ICODE &icode_iter, int pass)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case iRET: case iRETF: case iINT:
|
case iRET: case iRETF: case iINT:
|
||||||
if (_IcLL.flg & I)
|
if (_IcLL.isLlFlag(I))
|
||||||
{
|
{
|
||||||
oper_stream<<strHex(_IcLL.src.op());
|
oper_stream<<strHex(_IcLL.src.op());
|
||||||
}
|
}
|
||||||
@ -479,9 +479,9 @@ static void dis1Line(ICODE &icode_iter, int pass)
|
|||||||
{
|
{
|
||||||
bool is_dx_src=(_IcLL.opcode == iOUTS || _IcLL.opcode == iREP_OUTS);
|
bool is_dx_src=(_IcLL.opcode == iOUTS || _IcLL.opcode == iREP_OUTS);
|
||||||
if(is_dx_src)
|
if(is_dx_src)
|
||||||
oper_stream<<"dx, "<<szPtr[_IcLL.flg & B];
|
oper_stream<<"dx, "<<szPtr[_IcLL.GetLlFlag() & B];
|
||||||
else
|
else
|
||||||
oper_stream<<szPtr[_IcLL.flg & B];
|
oper_stream<<szPtr[_IcLL.GetLlFlag() & B];
|
||||||
if (_IcLL.opcode == iLODS ||
|
if (_IcLL.opcode == iLODS ||
|
||||||
_IcLL.opcode == iREP_LODS ||
|
_IcLL.opcode == iREP_LODS ||
|
||||||
_IcLL.opcode == iOUTS ||
|
_IcLL.opcode == iOUTS ||
|
||||||
@ -496,7 +496,7 @@ static void dis1Line(ICODE &icode_iter, int pass)
|
|||||||
oper_stream<<":[si]";
|
oper_stream<<":[si]";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
oper_stream<<(_IcLL.flg & B)? "B": "W";
|
oper_stream<<(_IcLL.GetLlFlag() & B)? "B": "W";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case iXLAT:
|
case iXLAT:
|
||||||
@ -508,13 +508,13 @@ static void dis1Line(ICODE &icode_iter, int pass)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case iIN:
|
case iIN:
|
||||||
oper_stream<<(_IcLL.flg & B)?"al, ": "ax, ";
|
oper_stream<<(_IcLL.GetLlFlag() & B)?"al, ": "ax, ";
|
||||||
oper_stream<<(_IcLL.flg & I)? strHex(_IcLL.src.op()): "dx";
|
oper_stream<<(_IcLL.isLlFlag(I))? strHex(_IcLL.src.op()): "dx";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case iOUT:
|
case iOUT:
|
||||||
oper_stream<<(_IcLL.flg & I)? strHex(_IcLL.src.op()): "dx";
|
oper_stream<<(_IcLL.isLlFlag(I))? strHex(_IcLL.src.op()): "dx";
|
||||||
oper_stream<<(_IcLL.flg & B)?", al": ", ax";
|
oper_stream<<(_IcLL.GetLlFlag() & B)?", al": ", ax";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -522,7 +522,7 @@ static void dis1Line(ICODE &icode_iter, int pass)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Comments */
|
/* Comments */
|
||||||
if (_IcLL.flg & SYNTHETIC)
|
if (_IcLL.isLlFlag(SYNTHETIC))
|
||||||
{
|
{
|
||||||
fImpure = FALSE;
|
fImpure = FALSE;
|
||||||
}
|
}
|
||||||
@ -542,13 +542,13 @@ static void dis1Line(ICODE &icode_iter, int pass)
|
|||||||
{
|
{
|
||||||
result_stream <<"; "<<cbuf.str();
|
result_stream <<"; "<<cbuf.str();
|
||||||
}
|
}
|
||||||
else if (fImpure || (_IcLL.flg & (SWITCH | CASE | SEG_IMMED | IMPURE | SYNTHETIC | TERMINATES)))
|
else if (fImpure || (_IcLL.isLlFlag(SWITCH | CASE | SEG_IMMED | IMPURE | SYNTHETIC | TERMINATES)))
|
||||||
{
|
{
|
||||||
if (_IcLL.flg & CASE)
|
if (_IcLL.isLlFlag(CASE))
|
||||||
{
|
{
|
||||||
result_stream << ";Case l"<< _IcLL.caseTbl.numEntries;
|
result_stream << ";Case l"<< _IcLL.caseTbl.numEntries;
|
||||||
}
|
}
|
||||||
if (_IcLL.flg & SWITCH)
|
if (_IcLL.isLlFlag(SWITCH))
|
||||||
{
|
{
|
||||||
result_stream << ";Switch ";
|
result_stream << ";Switch ";
|
||||||
}
|
}
|
||||||
@ -556,15 +556,15 @@ static void dis1Line(ICODE &icode_iter, int pass)
|
|||||||
{
|
{
|
||||||
result_stream << ";Accessed as data ";
|
result_stream << ";Accessed as data ";
|
||||||
}
|
}
|
||||||
if (_IcLL.flg & IMPURE)
|
if (_IcLL.isLlFlag(IMPURE))
|
||||||
{
|
{
|
||||||
result_stream << ";Impure operand ";
|
result_stream << ";Impure operand ";
|
||||||
}
|
}
|
||||||
if (_IcLL.flg & SEG_IMMED)
|
if (_IcLL.isLlFlag(SEG_IMMED))
|
||||||
{
|
{
|
||||||
result_stream << ";Segment constant";
|
result_stream << ";Segment constant";
|
||||||
}
|
}
|
||||||
if (_IcLL.flg & TERMINATES)
|
if (_IcLL.isLlFlag(TERMINATES))
|
||||||
{
|
{
|
||||||
result_stream << ";Exit to DOS";
|
result_stream << ";Exit to DOS";
|
||||||
}
|
}
|
||||||
@ -578,7 +578,7 @@ static void dis1Line(ICODE &icode_iter, int pass)
|
|||||||
if(pass==3)
|
if(pass==3)
|
||||||
{
|
{
|
||||||
/* output to .b code buffer */
|
/* output to .b code buffer */
|
||||||
if (_IcLL.anyFlagSet(SYNTHETIC))
|
if (_IcLL.isLlFlag(SYNTHETIC))
|
||||||
result_stream<<";Synthetic inst";
|
result_stream<<";Synthetic inst";
|
||||||
if (pass == 3) /* output to .b code buffer */
|
if (pass == 3) /* output to .b code buffer */
|
||||||
cCode.appendCode("%s\n", result_stream.str().c_str());
|
cCode.appendCode("%s\n", result_stream.str().c_str());
|
||||||
@ -586,7 +586,7 @@ static void dis1Line(ICODE &icode_iter, int pass)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (not _IcLL.anyFlagSet(SYNTHETIC) )
|
if (not _IcLL.isLlFlag(SYNTHETIC) )
|
||||||
{
|
{
|
||||||
/* output to .a1 or .a2 file */
|
/* output to .a1 or .a2 file */
|
||||||
fprintf (fp, "%03ld %06lX %s\n", icode_iter.loc_ip, _IcLL.label, result_stream.str().c_str());
|
fprintf (fp, "%03ld %06lX %s\n", icode_iter.loc_ip, _IcLL.label, result_stream.str().c_str());
|
||||||
@ -670,12 +670,12 @@ static ostringstream &strSrc(ostringstream &os,const LLInst &l_ins,bool skip_com
|
|||||||
static char buf[30] = {", "};
|
static char buf[30] = {", "};
|
||||||
if(false==skip_comma)
|
if(false==skip_comma)
|
||||||
os<<", ";
|
os<<", ";
|
||||||
if (l_ins.flg & I)
|
if (l_ins.isLlFlag(I))
|
||||||
os<<strHex(l_ins.src.op());
|
os<<strHex(l_ins.src.op());
|
||||||
else if (l_ins.flg & IM_SRC) /* level 2 */
|
else if (l_ins.isLlFlag(IM_SRC)) /* level 2 */
|
||||||
os<<"dx:ax";
|
os<<"dx:ax";
|
||||||
else
|
else
|
||||||
formatRM(os, l_ins.flg, l_ins.src);
|
formatRM(os, l_ins.GetLlFlag(), l_ins.src);
|
||||||
|
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
@ -748,7 +748,7 @@ void flops(LLInst &pIcode,std::ostringstream &out)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
formatRM(out, pIcode.flg, pIcode.dst);
|
formatRM(out, pIcode.GetLlFlag(), pIcode.dst);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -41,20 +41,21 @@ void Function::createCFG()
|
|||||||
stats.numBBbef = stats.numBBaft = 0;
|
stats.numBBbef = stats.numBBaft = 0;
|
||||||
for (ip = start = 0; pIcode!=Icode.end(); ip++, pIcode++)
|
for (ip = start = 0; pIcode!=Icode.end(); ip++, pIcode++)
|
||||||
{
|
{
|
||||||
|
LLInst *ll = pIcode->ll();
|
||||||
/* Stick a NOWHERE_NODE on the end if we terminate
|
/* Stick a NOWHERE_NODE on the end if we terminate
|
||||||
* with anything other than a ret, jump or terminate */
|
* with anything other than a ret, jump or terminate */
|
||||||
if (ip + 1 == Icode.size() &&
|
if (ip + 1 == Icode.size() &&
|
||||||
! (pIcode->ic.ll.flg & TERMINATES) &&
|
(not ll->isLlFlag(TERMINATES)) &&
|
||||||
pIcode->ic.ll.opcode != iJMP && pIcode->ic.ll.opcode != iJMPF &&
|
ll->opcode != iJMP && ll->opcode != iJMPF &&
|
||||||
pIcode->ic.ll.opcode != iRET && pIcode->ic.ll.opcode != iRETF)
|
ll->opcode != iRET && ll->opcode != iRETF)
|
||||||
{
|
{
|
||||||
pBB=BB::Create(start, ip, NOWHERE_NODE, 0, this);
|
pBB=BB::Create(start, ip, NOWHERE_NODE, 0, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Only process icodes that have valid instructions */
|
/* Only process icodes that have valid instructions */
|
||||||
else if ((pIcode->ic.ll.flg & NO_CODE) != NO_CODE)
|
else if (not ll->isLlFlag(NO_CODE) )
|
||||||
{
|
{
|
||||||
switch (pIcode->ic.ll.opcode) {
|
switch (ll->opcode) {
|
||||||
case iJB: case iJBE: case iJAE: case iJA:
|
case iJB: case iJBE: case iJAE: case iJA:
|
||||||
case iJL: case iJLE: case iJGE: case iJG:
|
case iJL: case iJLE: case iJGE: case iJG:
|
||||||
case iJE: case iJNE: case iJS: case iJNS:
|
case iJE: case iJNE: case iJS: case iJNS:
|
||||||
@ -65,12 +66,12 @@ CondJumps:
|
|||||||
start = ip + 1;
|
start = ip + 1;
|
||||||
pBB->edges[0].ip = (uint32_t)start;
|
pBB->edges[0].ip = (uint32_t)start;
|
||||||
/* This is for jumps off into nowhere */
|
/* This is for jumps off into nowhere */
|
||||||
if (pIcode->ic.ll.flg & NO_LABEL)
|
if ( ll->isLlFlag(NO_LABEL) )
|
||||||
{
|
{
|
||||||
pBB->edges.pop_back();
|
pBB->edges.pop_back();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
pBB->edges[1].ip = pIcode->ic.ll.src.op();
|
pBB->edges[1].ip = ll->src.op();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case iLOOP: case iLOOPE: case iLOOPNE:
|
case iLOOP: case iLOOPE: case iLOOPNE:
|
||||||
@ -78,17 +79,17 @@ CondJumps:
|
|||||||
goto CondJumps;
|
goto CondJumps;
|
||||||
|
|
||||||
case iJMPF: case iJMP:
|
case iJMPF: case iJMP:
|
||||||
if (pIcode->ic.ll.flg & SWITCH)
|
if (ll->isLlFlag(SWITCH))
|
||||||
{
|
{
|
||||||
pBB = BB::Create(start, ip, MULTI_BRANCH, pIcode->ic.ll.caseTbl.numEntries, this);
|
pBB = BB::Create(start, ip, MULTI_BRANCH, ll->caseTbl.numEntries, this);
|
||||||
for (i = 0; i < pIcode->ic.ll.caseTbl.numEntries; i++)
|
for (i = 0; i < ll->caseTbl.numEntries; i++)
|
||||||
pBB->edges[i].ip = pIcode->ic.ll.caseTbl.entries[i];
|
pBB->edges[i].ip = ll->caseTbl.entries[i];
|
||||||
hasCase = TRUE;
|
hasCase = TRUE;
|
||||||
}
|
}
|
||||||
else if ((pIcode->ic.ll.flg & (I | NO_LABEL)) == I)
|
else if ((ll->GetLlFlag() & (I | NO_LABEL)) == I) //TODO: WHY NO_LABEL TESTIT
|
||||||
{
|
{
|
||||||
pBB = BB::Create(start, ip, ONE_BRANCH, 1, this);
|
pBB = BB::Create(start, ip, ONE_BRANCH, 1, this);
|
||||||
pBB->edges[0].ip = pIcode->ic.ll.src.op();
|
pBB->edges[0].ip = ll->src.op();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
BB::Create(start, ip, NOWHERE_NODE, 0, this);
|
BB::Create(start, ip, NOWHERE_NODE, 0, this);
|
||||||
@ -97,7 +98,7 @@ CondJumps:
|
|||||||
|
|
||||||
case iCALLF: case iCALL:
|
case iCALLF: case iCALL:
|
||||||
{
|
{
|
||||||
Function * p = pIcode->ic.ll.src.proc.proc;
|
Function * p = ll->src.proc.proc;
|
||||||
if (p)
|
if (p)
|
||||||
i = ((p->flg) & TERMINATES) ? 0 : 1;
|
i = ((p->flg) & TERMINATES) ? 0 : 1;
|
||||||
else
|
else
|
||||||
@ -117,7 +118,7 @@ CondJumps:
|
|||||||
default:
|
default:
|
||||||
/* Check for exit to DOS */
|
/* Check for exit to DOS */
|
||||||
iICODE next1=++iICODE(pIcode);
|
iICODE next1=++iICODE(pIcode);
|
||||||
if (pIcode->ic.ll.flg & TERMINATES)
|
if ( ll->isLlFlag(TERMINATES) )
|
||||||
{
|
{
|
||||||
pBB = BB::Create(start, ip, TERMINATE_NODE, 0, this);
|
pBB = BB::Create(start, ip, TERMINATE_NODE, 0, this);
|
||||||
start = ip + 1;
|
start = ip + 1;
|
||||||
@ -126,7 +127,7 @@ CondJumps:
|
|||||||
else if (next1 != Icode.end())
|
else if (next1 != Icode.end())
|
||||||
{
|
{
|
||||||
assert(next1->loc_ip==ip+1);
|
assert(next1->loc_ip==ip+1);
|
||||||
if (next1->ic.ll.flg & (TARGET | CASE))
|
if (next1->ll()->isLlFlag(TARGET | CASE))
|
||||||
{
|
{
|
||||||
pBB = BB::Create(start, ip, FALL_NODE, 1, this);
|
pBB = BB::Create(start, ip, FALL_NODE, 1, this);
|
||||||
start = ip + 1;
|
start = ip + 1;
|
||||||
@ -166,14 +167,14 @@ void Function::markImpure()
|
|||||||
SYM * psym;
|
SYM * psym;
|
||||||
for(ICODE &icod : Icode)
|
for(ICODE &icod : Icode)
|
||||||
{
|
{
|
||||||
if ( not icod.isLlFlag(SYM_USE | SYM_DEF))
|
if ( not icod.ll()->isLlFlag(SYM_USE | SYM_DEF))
|
||||||
continue;
|
continue;
|
||||||
psym = &symtab[icod.ic.ll.caseTbl.numEntries];
|
psym = &symtab[icod.ll()->caseTbl.numEntries];
|
||||||
for (int c = (int)psym->label; c < (int)psym->label+psym->size; c++)
|
for (int c = (int)psym->label; c < (int)psym->label+psym->size; c++)
|
||||||
{
|
{
|
||||||
if (BITMAP(c, BM_CODE))
|
if (BITMAP(c, BM_CODE))
|
||||||
{
|
{
|
||||||
icod.SetLlFlag(IMPURE);
|
icod.ll()->SetLlFlag(IMPURE);
|
||||||
flg |= IMPURE;
|
flg |= IMPURE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -223,7 +224,7 @@ void Function::compressCFG()
|
|||||||
{
|
{
|
||||||
pBB->edges[i].BBptr = pNxt;
|
pBB->edges[i].BBptr = pNxt;
|
||||||
assert(pBB->back().loc_ip==ip);
|
assert(pBB->back().loc_ip==ip);
|
||||||
pBB->back().SetImmediateOp((uint32_t)pNxt->begin());
|
pBB->back().ll()->SetImmediateOp((uint32_t)pNxt->begin());
|
||||||
//Icode[ip].SetImmediateOp((uint32_t)pNxt->begin());
|
//Icode[ip].SetImmediateOp((uint32_t)pNxt->begin());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -286,7 +287,7 @@ BB *BB::rmJMP(int marker, BB * pBB)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pBB->front().SetLlFlag(NO_CODE);
|
pBB->front().ll()->SetLlFlag(NO_CODE);
|
||||||
pBB->front().invalidate(); //pProc->Icode.SetLlInvalid(pBB->begin(), TRUE);
|
pBB->front().invalidate(); //pProc->Icode.SetLlInvalid(pBB->begin(), TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -296,14 +297,14 @@ BB *BB::rmJMP(int marker, BB * pBB)
|
|||||||
{
|
{
|
||||||
/* We are going around in circles */
|
/* We are going around in circles */
|
||||||
pBB->nodeType = NOWHERE_NODE;
|
pBB->nodeType = NOWHERE_NODE;
|
||||||
pBB->front().ic.ll.src.SetImmediateOp(pBB->front().loc_ip);
|
pBB->front().ll()->src.SetImmediateOp(pBB->front().loc_ip);
|
||||||
//pBB->front().ic.ll.src.immed.op = pBB->front().loc_ip;
|
//pBB->front().ll()->src.immed.op = pBB->front().loc_ip;
|
||||||
do {
|
do {
|
||||||
pBB = pBB->edges[0].BBptr;
|
pBB = pBB->edges[0].BBptr;
|
||||||
pBB->inEdges.pop_back(); // was --numInedges
|
pBB->inEdges.pop_back(); // was --numInedges
|
||||||
if (! pBB->inEdges.empty())
|
if (! pBB->inEdges.empty())
|
||||||
{
|
{
|
||||||
pBB->front().SetLlFlag(NO_CODE);
|
pBB->front().ll()->SetLlFlag(NO_CODE);
|
||||||
pBB->front().invalidate();
|
pBB->front().invalidate();
|
||||||
// pProc->Icode.SetLlFlag(pBB->start, NO_CODE);
|
// pProc->Icode.SetLlFlag(pBB->start, NO_CODE);
|
||||||
// pProc->Icode.SetLlInvalid(pBB->start, TRUE);
|
// pProc->Icode.SetLlInvalid(pBB->start, TRUE);
|
||||||
@ -339,11 +340,11 @@ void BB::mergeFallThrough( CIcodeRec &Icode)
|
|||||||
if(back().loc_ip>pChild->front().loc_ip) // back edege
|
if(back().loc_ip>pChild->front().loc_ip) // back edege
|
||||||
break;
|
break;
|
||||||
auto iter=std::find_if(this->end2(),pChild->begin2(),[](ICODE &c)
|
auto iter=std::find_if(this->end2(),pChild->begin2(),[](ICODE &c)
|
||||||
{return not c.isLlFlag(NO_CODE);});
|
{return not c.ll()->isLlFlag(NO_CODE);});
|
||||||
|
|
||||||
if (iter != pChild->begin2())
|
if (iter != pChild->begin2())
|
||||||
break;
|
break;
|
||||||
back().SetLlFlag(NO_CODE);
|
back().ll()->SetLlFlag(NO_CODE);
|
||||||
back().invalidate();
|
back().invalidate();
|
||||||
nodeType = FALL_NODE;
|
nodeType = FALL_NODE;
|
||||||
length--;
|
length--;
|
||||||
@ -355,7 +356,7 @@ void BB::mergeFallThrough( CIcodeRec &Icode)
|
|||||||
|
|
||||||
nodeType = pChild->nodeType;
|
nodeType = pChild->nodeType;
|
||||||
length = (pChild->start - start) + pChild->length ;
|
length = (pChild->start - start) + pChild->length ;
|
||||||
pChild->front().ClrLlFlag(TARGET);
|
pChild->front().ll()->ClrLlFlag(TARGET);
|
||||||
edges.swap(pChild->edges);
|
edges.swap(pChild->edges);
|
||||||
|
|
||||||
pChild->inEdges.clear();
|
pChild->inEdges.clear();
|
||||||
|
|||||||
@ -31,29 +31,29 @@ static char buf[lineSize]; /* Line buffer for hl icode output */
|
|||||||
void ICODE::setAsgn(COND_EXPR *lhs, COND_EXPR *rhs)
|
void ICODE::setAsgn(COND_EXPR *lhs, COND_EXPR *rhs)
|
||||||
{
|
{
|
||||||
type = HIGH_LEVEL;
|
type = HIGH_LEVEL;
|
||||||
ic.hl.set(lhs,rhs);
|
hl()->set(lhs,rhs);
|
||||||
|
|
||||||
}
|
}
|
||||||
void ICODE::checkHlCall()
|
void ICODE::checkHlCall()
|
||||||
{
|
{
|
||||||
//assert((ic.ll.immed.proc.cb != 0)||ic.ll.immed.proc.proc!=0);
|
//assert((ll()->immed.proc.cb != 0)||ll()->immed.proc.proc!=0);
|
||||||
}
|
}
|
||||||
/* Places the new HLI_CALL high-level operand in the high-level icode array */
|
/* Places the new HLI_CALL high-level operand in the high-level icode array */
|
||||||
void ICODE::newCallHl()
|
void ICODE::newCallHl()
|
||||||
{
|
{
|
||||||
type = HIGH_LEVEL;
|
type = HIGH_LEVEL;
|
||||||
ic.hl.opcode = HLI_CALL;
|
hl()->opcode = HLI_CALL;
|
||||||
ic.hl.call.proc = ic.ll.src.proc.proc;
|
hl()->call.proc = ll()->src.proc.proc;
|
||||||
ic.hl.call.args = new STKFRAME;
|
hl()->call.args = new STKFRAME;
|
||||||
|
|
||||||
if (ic.ll.src.proc.cb != 0)
|
if (ll()->src.proc.cb != 0)
|
||||||
ic.hl.call.args->cb = ic.ll.src.proc.cb;
|
hl()->call.args->cb = ll()->src.proc.cb;
|
||||||
else if(ic.hl.call.proc)
|
else if(hl()->call.proc)
|
||||||
ic.hl.call.args->cb =ic.hl.call.proc->cbParam;
|
hl()->call.args->cb =hl()->call.proc->cbParam;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("Function with no cb set, and no valid oper.call.proc , probaby indirect call\n");
|
printf("Function with no cb set, and no valid oper.call.proc , probaby indirect call\n");
|
||||||
ic.hl.call.args->cb = 0;
|
hl()->call.args->cb = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ void ICODE::newCallHl()
|
|||||||
void ICODE::setUnary(hlIcode op, COND_EXPR *exp)
|
void ICODE::setUnary(hlIcode op, COND_EXPR *exp)
|
||||||
{
|
{
|
||||||
type = HIGH_LEVEL;
|
type = HIGH_LEVEL;
|
||||||
ic.hl.set(op,exp);
|
hl()->set(op,exp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ void ICODE::setUnary(hlIcode op, COND_EXPR *exp)
|
|||||||
void ICODE::setJCond(COND_EXPR *cexp)
|
void ICODE::setJCond(COND_EXPR *cexp)
|
||||||
{
|
{
|
||||||
type = HIGH_LEVEL;
|
type = HIGH_LEVEL;
|
||||||
ic.hl.set(HLI_JCOND,cexp);
|
hl()->set(HLI_JCOND,cexp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -116,7 +116,7 @@ bool ICODE::removeDefRegi (uint8_t regi, int thisDefIdx, LOCAL_ID *locId)
|
|||||||
invalidate();
|
invalidate();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
HlTypeSupport *p=ic.hl.get();
|
HlTypeSupport *p=hl()->get();
|
||||||
if(p and p->removeRegFromLong(regi,locId))
|
if(p and p->removeRegFromLong(regi,locId))
|
||||||
{
|
{
|
||||||
du1.numRegsDef--;
|
du1.numRegsDef--;
|
||||||
@ -141,11 +141,12 @@ void Function::highLevelGen()
|
|||||||
{
|
{
|
||||||
assert(numIcode==Icode.size());
|
assert(numIcode==Icode.size());
|
||||||
pIcode = i; //Icode.GetIcode(i)
|
pIcode = i; //Icode.GetIcode(i)
|
||||||
if ((pIcode->ic.ll.flg & NOT_HLL) == NOT_HLL)
|
LLInst *ll = pIcode->ll();
|
||||||
|
if ( ll->isLlFlag(NOT_HLL) )
|
||||||
pIcode->invalidate();
|
pIcode->invalidate();
|
||||||
if ((pIcode->type == LOW_LEVEL) && (pIcode->invalid == FALSE))
|
if ((pIcode->type == LOW_LEVEL) && pIcode->valid() )
|
||||||
{
|
{
|
||||||
flg = pIcode->ic.ll.flg;
|
flg = ll->GetLlFlag();
|
||||||
if ((flg & IM_OPS) != IM_OPS) /* not processing IM_OPS yet */
|
if ((flg & IM_OPS) != IM_OPS) /* not processing IM_OPS yet */
|
||||||
if ((flg & NO_OPS) != NO_OPS) /* if there are opers */
|
if ((flg & NO_OPS) != NO_OPS) /* if there are opers */
|
||||||
{
|
{
|
||||||
@ -154,7 +155,7 @@ void Function::highLevelGen()
|
|||||||
lhs = COND_EXPR::id (*pIcode, DST, this, i, *pIcode, NONE);
|
lhs = COND_EXPR::id (*pIcode, DST, this, i, *pIcode, NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (pIcode->ic.ll.opcode)
|
switch (ll->opcode)
|
||||||
{
|
{
|
||||||
case iADD:
|
case iADD:
|
||||||
rhs = COND_EXPR::boolOp (lhs, rhs, ADD);
|
rhs = COND_EXPR::boolOp (lhs, rhs, ADD);
|
||||||
@ -181,7 +182,7 @@ void Function::highLevelGen()
|
|||||||
case iDIV:
|
case iDIV:
|
||||||
case iIDIV:/* should be signed div */
|
case iIDIV:/* should be signed div */
|
||||||
rhs = COND_EXPR::boolOp (lhs, rhs, DIV);
|
rhs = COND_EXPR::boolOp (lhs, rhs, DIV);
|
||||||
if (pIcode->ic.ll.flg & B)
|
if ( ll->isLlFlag(B) )
|
||||||
{
|
{
|
||||||
lhs = COND_EXPR::idReg (rAL, 0, &localId);
|
lhs = COND_EXPR::idReg (rAL, 0, &localId);
|
||||||
pIcode->setRegDU( rAL, eDEF);
|
pIcode->setRegDU( rAL, eDEF);
|
||||||
@ -206,12 +207,14 @@ void Function::highLevelGen()
|
|||||||
pIcode->setAsgn(lhs, rhs);
|
pIcode->setAsgn(lhs, rhs);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case iLEA: rhs = COND_EXPR::unary (ADDRESSOF, rhs);
|
case iLEA:
|
||||||
|
rhs = COND_EXPR::unary (ADDRESSOF, rhs);
|
||||||
pIcode->setAsgn(lhs, rhs);
|
pIcode->setAsgn(lhs, rhs);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case iMOD: rhs = COND_EXPR::boolOp (lhs, rhs, MOD);
|
case iMOD:
|
||||||
if (pIcode->ic.ll.flg & B)
|
rhs = COND_EXPR::boolOp (lhs, rhs, MOD);
|
||||||
|
if ( ll->isLlFlag(B) )
|
||||||
{
|
{
|
||||||
lhs = COND_EXPR::idReg (rAH, 0, &localId);
|
lhs = COND_EXPR::idReg (rAH, 0, &localId);
|
||||||
pIcode->setRegDU( rAH, eDEF);
|
pIcode->setRegDU( rAH, eDEF);
|
||||||
@ -494,8 +497,8 @@ void ICODE::writeDU(int idx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* For HLI_CALL, print # parameter bytes */
|
/* For HLI_CALL, print # parameter bytes */
|
||||||
if (ic.hl.opcode == HLI_CALL)
|
if (hl()->opcode == HLI_CALL)
|
||||||
printf ("# param bytes = %d\n", ic.hl.call.args->cb);
|
printf ("# param bytes = %d\n", hl()->call.args->cb);
|
||||||
printf ("\n");
|
printf ("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -50,7 +50,7 @@ bool CIcodeRec::labelSrch(uint32_t target, uint32_t &pIndex)
|
|||||||
CIcodeRec::iterator CIcodeRec::labelSrch(uint32_t target)
|
CIcodeRec::iterator CIcodeRec::labelSrch(uint32_t target)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
return find_if(begin(),end(),[target](ICODE &l) -> bool {return l.ic.ll.label==target;});
|
return find_if(begin(),end(),[target](ICODE &l) -> bool {return l.ll()->label==target;});
|
||||||
}
|
}
|
||||||
ICODE * CIcodeRec::GetIcode(int ip)
|
ICODE * CIcodeRec::GetIcode(int ip)
|
||||||
{
|
{
|
||||||
@ -68,19 +68,19 @@ extern bundle cCode;
|
|||||||
* is created and a goto is also emitted.
|
* is created and a goto is also emitted.
|
||||||
* Note: this procedure is to be used when the label is to be backpatched
|
* Note: this procedure is to be used when the label is to be backpatched
|
||||||
* onto code in cCode.code */
|
* onto code in cCode.code */
|
||||||
void ICODE::emitGotoLabel (int indLevel)
|
void LLInst::emitGotoLabel (int indLevel)
|
||||||
{
|
{
|
||||||
if (! (ic.ll.flg & HLL_LABEL)) /* node hasn't got a lab */
|
if ( not isLlFlag(HLL_LABEL) ) /* node hasn't got a lab */
|
||||||
{
|
{
|
||||||
/* Generate new label */
|
/* Generate new label */
|
||||||
ic.ll.hllLabNum = getNextLabel();
|
hllLabNum = getNextLabel();
|
||||||
ic.ll.flg |= HLL_LABEL;
|
SetLlFlag(HLL_LABEL);
|
||||||
|
|
||||||
/* Node has been traversed already, so backpatch this label into
|
/* Node has been traversed already, so backpatch this label into
|
||||||
* the code */
|
* the code */
|
||||||
addLabelBundle (cCode.code, codeIdx, ic.ll.hllLabNum);
|
addLabelBundle (cCode.code, codeIdx, hllLabNum);
|
||||||
}
|
}
|
||||||
cCode.appendCode( "%sgoto L%ld;\n", indent(indLevel), ic.ll.hllLabNum);
|
cCode.appendCode( "%sgoto L%ld;\n", indent(indLevel), hllLabNum);
|
||||||
stats.numHLIcode++;
|
stats.numHLIcode++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -77,7 +77,7 @@ void Function::findIdioms()
|
|||||||
typedef boost::filter_iterator<is_valid,iICODE> ifICODE;
|
typedef boost::filter_iterator<is_valid,iICODE> ifICODE;
|
||||||
while (pIcode != pEnd)
|
while (pIcode != pEnd)
|
||||||
{
|
{
|
||||||
switch (pIcode->ic.ll.opcode)
|
switch (pIcode->ll()->opcode)
|
||||||
{
|
{
|
||||||
case iDEC: case iINC:
|
case iDEC: case iINC:
|
||||||
if (i18.match(pIcode))
|
if (i18.match(pIcode))
|
||||||
@ -114,12 +114,12 @@ void Function::findIdioms()
|
|||||||
case iCALL: case iCALLF:
|
case iCALL: case iCALLF:
|
||||||
/* Check for library functions that return a long register.
|
/* Check for library functions that return a long register.
|
||||||
* Propagate this result */
|
* Propagate this result */
|
||||||
if (pIcode->ic.ll.src.proc.proc != 0)
|
if (pIcode->ll()->src.proc.proc != 0)
|
||||||
if ((pIcode->ic.ll.src.proc.proc->flg & PROC_ISLIB) &&
|
if ((pIcode->ll()->src.proc.proc->flg & PROC_ISLIB) &&
|
||||||
(pIcode->ic.ll.src.proc.proc->flg & PROC_IS_FUNC))
|
(pIcode->ll()->src.proc.proc->flg & PROC_IS_FUNC))
|
||||||
{
|
{
|
||||||
if ((pIcode->ic.ll.src.proc.proc->retVal.type==TYPE_LONG_SIGN)
|
if ((pIcode->ll()->src.proc.proc->retVal.type==TYPE_LONG_SIGN)
|
||||||
|| (pIcode->ic.ll.src.proc.proc->retVal.type == TYPE_LONG_UNSIGN))
|
|| (pIcode->ll()->src.proc.proc->retVal.type == TYPE_LONG_UNSIGN))
|
||||||
localId.newLongReg(TYPE_LONG_SIGN, rDX, rAX, pIcode/*ip*/);
|
localId.newLongReg(TYPE_LONG_SIGN, rDX, rAX, pIcode/*ip*/);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,20 +230,14 @@ void Function::bindIcodeOff()
|
|||||||
/* Flag all jump targets for BB construction and disassembly stage 2 */
|
/* Flag all jump targets for BB construction and disassembly stage 2 */
|
||||||
for(ICODE &c : Icode)
|
for(ICODE &c : Icode)
|
||||||
{
|
{
|
||||||
if ((c.ic.ll.flg & I) && JmpInst(c.ic.ll.opcode))
|
LLInst *ll=c.ll();
|
||||||
|
if (ll->isLlFlag(I) && JmpInst(ll->opcode))
|
||||||
{
|
{
|
||||||
iICODE loc=Icode.labelSrch(c.ic.ll.src.op());
|
iICODE loc=Icode.labelSrch(ll->src.op());
|
||||||
if (loc!=Icode.end())
|
if (loc!=Icode.end())
|
||||||
loc->ic.ll.flg |= TARGET;
|
loc->ll()->SetLlFlag(TARGET);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// for (i = 0; i < Icode.size(); i++)
|
|
||||||
// if ((pIcode[i].ic.ll.flg & I) && JmpInst(pIcode[i].ic.ll.opcode))
|
|
||||||
// {
|
|
||||||
// iICODE loc=Icode.labelSrch(pIcode[i].ic.ll.src.op());
|
|
||||||
// if (loc!=Icode.end())
|
|
||||||
// loc->ic.ll.flg |= TARGET;
|
|
||||||
// }
|
|
||||||
|
|
||||||
/* Finally bind jump targets to Icode offsets. Jumps for which no label
|
/* Finally bind jump targets to Icode offsets. Jumps for which no label
|
||||||
* is found (no code at dest. of jump) are simply left unlinked and
|
* is found (no code at dest. of jump) are simply left unlinked and
|
||||||
@ -251,21 +245,22 @@ void Function::bindIcodeOff()
|
|||||||
//for (pIcode = Icode.begin(); pIcode!= Icode.end(); pIcode++)
|
//for (pIcode = Icode.begin(); pIcode!= Icode.end(); pIcode++)
|
||||||
for(ICODE &icode : Icode)
|
for(ICODE &icode : Icode)
|
||||||
{
|
{
|
||||||
if (not JmpInst(icode.ic.ll.opcode))
|
LLInst *ll=icode.ll();
|
||||||
|
if (not JmpInst(ll->opcode))
|
||||||
continue;
|
continue;
|
||||||
if (icode.ic.ll.flg & I)
|
if (ll->isLlFlag(I) )
|
||||||
{
|
{
|
||||||
uint32_t found;
|
uint32_t found;
|
||||||
if (! Icode.labelSrch(icode.ic.ll.src.op(), found))
|
if (! Icode.labelSrch(ll->src.op(), found))
|
||||||
icode.ic.ll.flg |= NO_LABEL;
|
ll->SetLlFlag( NO_LABEL );
|
||||||
else
|
else
|
||||||
icode.ic.ll.src.SetImmediateOp(found);
|
ll->src.SetImmediateOp(found);
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (icode.ic.ll.flg & SWITCH)
|
else if (ll->isLlFlag(SWITCH) )
|
||||||
{
|
{
|
||||||
p = icode.ic.ll.caseTbl.entries;
|
p = ll->caseTbl.entries;
|
||||||
for (int j = 0; j < icode.ic.ll.caseTbl.numEntries; j++, p++)
|
for (int j = 0; j < ll->caseTbl.numEntries; j++, p++)
|
||||||
Icode.labelSrch(*p, *p);
|
Icode.labelSrch(*p, *p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,7 @@ bool Idiom5::match(iICODE pIcode)
|
|||||||
return false;
|
return false;
|
||||||
m_icodes[0]=pIcode++;
|
m_icodes[0]=pIcode++;
|
||||||
m_icodes[1]=pIcode++;
|
m_icodes[1]=pIcode++;
|
||||||
if (m_icodes[1]->ic.ll.match(iADC))
|
if (m_icodes[1]->ll()->match(iADC))
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -51,7 +51,7 @@ bool Idiom6::match(iICODE pIcode)
|
|||||||
return false;
|
return false;
|
||||||
m_icodes[0]=pIcode++;
|
m_icodes[0]=pIcode++;
|
||||||
m_icodes[1]=pIcode++;
|
m_icodes[1]=pIcode++;
|
||||||
if (m_icodes[1]->ic.ll.match(iSBB))
|
if (m_icodes[1]->ll()->match(iSBB))
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -93,24 +93,24 @@ bool Idiom18::match(iICODE picode)
|
|||||||
for(int i=0; i<4; ++i)
|
for(int i=0; i<4; ++i)
|
||||||
m_icodes[i] =picode++;
|
m_icodes[i] =picode++;
|
||||||
|
|
||||||
m_is_dec = m_icodes[1]->ic.ll.match(iDEC);
|
m_is_dec = m_icodes[1]->ll()->match(iDEC);
|
||||||
int type = -1; /* type of variable: 1 = reg-var, 2 = local */
|
int type = -1; /* type of variable: 1 = reg-var, 2 = local */
|
||||||
uint8_t regi; /* register of the MOV */
|
uint8_t regi; /* register of the MOV */
|
||||||
|
|
||||||
/* Get variable */
|
/* Get variable */
|
||||||
if (m_icodes[1]->ic.ll.dst.regi == 0) /* global variable */
|
if (m_icodes[1]->ll()->dst.regi == 0) /* global variable */
|
||||||
{
|
{
|
||||||
/* not supported yet */
|
/* not supported yet */
|
||||||
type = 0;
|
type = 0;
|
||||||
}
|
}
|
||||||
else if (m_icodes[1]->ic.ll.dst.regi < INDEXBASE) /* register */
|
else if (m_icodes[1]->ll()->dst.regi < INDEXBASE) /* register */
|
||||||
{
|
{
|
||||||
if ((m_icodes[1]->ic.ll.dst.regi == rSI) && (m_func->flg & SI_REGVAR))
|
if ((m_icodes[1]->ll()->dst.regi == rSI) && (m_func->flg & SI_REGVAR))
|
||||||
type = 1;
|
type = 1;
|
||||||
else if ((m_icodes[1]->ic.ll.dst.regi == rDI) && (m_func->flg & DI_REGVAR))
|
else if ((m_icodes[1]->ll()->dst.regi == rDI) && (m_func->flg & DI_REGVAR))
|
||||||
type = 1;
|
type = 1;
|
||||||
}
|
}
|
||||||
else if (m_icodes[1]->ic.ll.dst.off) /* local variable */
|
else if (m_icodes[1]->ll()->dst.off) /* local variable */
|
||||||
type = 2;
|
type = 2;
|
||||||
else /* indexed */
|
else /* indexed */
|
||||||
{
|
{
|
||||||
@ -126,25 +126,25 @@ bool Idiom18::match(iICODE picode)
|
|||||||
break;
|
break;
|
||||||
case 1: /* register variable */
|
case 1: /* register variable */
|
||||||
/* Check previous instruction for a MOV */
|
/* Check previous instruction for a MOV */
|
||||||
if (m_icodes[0]->ic.ll.match(iMOV) && (m_icodes[0]->ic.ll.src.regi == m_icodes[1]->ic.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]->ic.ll.dst.regi;
|
regi = m_icodes[0]->ll()->dst.regi;
|
||||||
if ((regi > 0) && (regi < INDEXBASE))
|
if ((regi > 0) && (regi < INDEXBASE))
|
||||||
{
|
{
|
||||||
if ( m_icodes[2]->ic.ll.match(iCMP) && (m_icodes[2]->ic.ll.dst.regi == regi) &&
|
if ( m_icodes[2]->ll()->match(iCMP) && (m_icodes[2]->ll()->dst.regi == regi) &&
|
||||||
m_icodes[3]->ic.ll.conditionalJump() )
|
m_icodes[3]->ll()->conditionalJump() )
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 2: /* local */
|
case 2: /* local */
|
||||||
if (m_icodes[0]->ic.ll.match(iMOV) && (m_icodes[0]->ic.ll.src.off == m_icodes[1]->ic.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]->ic.ll.dst.regi;
|
regi = m_icodes[0]->ll()->dst.regi;
|
||||||
if ((regi > 0) && (regi < INDEXBASE))
|
if ((regi > 0) && (regi < INDEXBASE))
|
||||||
{
|
{
|
||||||
if ( m_icodes[2]->ic.ll.match(iCMP) && (m_icodes[2]->ic.ll.dst.regi == regi) &&
|
if ( m_icodes[2]->ll()->match(iCMP) && (m_icodes[2]->ll()->dst.regi == regi) &&
|
||||||
m_icodes[3]->ic.ll.conditionalJump() )
|
m_icodes[3]->ll()->conditionalJump() )
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -163,7 +163,7 @@ int Idiom18::action() // action length
|
|||||||
lhs = COND_EXPR::id (*m_icodes[0], SRC, m_func, m_icodes[1], *m_icodes[1], eUSE);
|
lhs = COND_EXPR::id (*m_icodes[0], SRC, m_func, m_icodes[1], *m_icodes[1], eUSE);
|
||||||
lhs = COND_EXPR::unary ( m_is_dec ? POST_DEC : POST_INC, lhs);
|
lhs = COND_EXPR::unary ( m_is_dec ? POST_DEC : POST_INC, lhs);
|
||||||
rhs = COND_EXPR::id (*m_icodes[2], SRC, m_func, m_icodes[1], *m_icodes[3], eUSE);
|
rhs = COND_EXPR::id (*m_icodes[2], SRC, m_func, m_icodes[1], *m_icodes[3], eUSE);
|
||||||
expr = COND_EXPR::boolOp (lhs, rhs, condOpJCond[m_icodes[3]->ic.ll.opcode - iJB]);
|
expr = COND_EXPR::boolOp (lhs, rhs, condOpJCond[m_icodes[3]->ll()->opcode - iJB]);
|
||||||
m_icodes[3]->setJCond(expr);
|
m_icodes[3]->setJCond(expr);
|
||||||
|
|
||||||
m_icodes[0]->invalidate();
|
m_icodes[0]->invalidate();
|
||||||
@ -189,19 +189,19 @@ bool Idiom19::match(iICODE picode)
|
|||||||
|
|
||||||
for(int i=0; i<2; ++i)
|
for(int i=0; i<2; ++i)
|
||||||
m_icodes[i] =picode++;
|
m_icodes[i] =picode++;
|
||||||
m_is_dec = m_icodes[0]->ic.ll.match(iDEC);
|
m_is_dec = m_icodes[0]->ll()->match(iDEC);
|
||||||
if (m_icodes[0]->ic.ll.dst.regi == 0) /* global variable */
|
if (m_icodes[0]->ll()->dst.regi == 0) /* global variable */
|
||||||
/* not supported yet */ ;
|
/* not supported yet */ ;
|
||||||
else if (m_icodes[0]->ic.ll.dst.regi < INDEXBASE) /* register */
|
else if (m_icodes[0]->ll()->dst.regi < INDEXBASE) /* register */
|
||||||
{
|
{
|
||||||
// if (((picode->ic.ll.dst.regi == rSI) && (pproc->flg & SI_REGVAR)) ||
|
// if (((picode->ll()->dst.regi == rSI) && (pproc->flg & SI_REGVAR)) ||
|
||||||
// ((picode->ic.ll.dst.regi == rDI) && (pproc->flg & DI_REGVAR)))
|
// ((picode->ll()->dst.regi == rDI) && (pproc->flg & DI_REGVAR)))
|
||||||
if (m_icodes[1]->ic.ll.conditionalJump())
|
if (m_icodes[1]->ll()->conditionalJump())
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (m_icodes[0]->ic.ll.dst.off) /* stack variable */
|
else if (m_icodes[0]->ll()->dst.off) /* stack variable */
|
||||||
{
|
{
|
||||||
if ( m_icodes[1]->ic.ll.conditionalJump() )
|
if ( m_icodes[1]->ll()->conditionalJump() )
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else /* indexed */
|
else /* indexed */
|
||||||
@ -214,7 +214,7 @@ int Idiom19::action()
|
|||||||
lhs = COND_EXPR::id (*m_icodes[1], DST, m_func, m_icodes[0], *m_icodes[1], eUSE);
|
lhs = COND_EXPR::id (*m_icodes[1], DST, m_func, m_icodes[0], *m_icodes[1], eUSE);
|
||||||
lhs = COND_EXPR::unary (m_is_dec ? PRE_DEC : PRE_INC, lhs);
|
lhs = COND_EXPR::unary (m_is_dec ? PRE_DEC : PRE_INC, lhs);
|
||||||
rhs = COND_EXPR::idKte (0, 2);
|
rhs = COND_EXPR::idKte (0, 2);
|
||||||
expr = COND_EXPR::boolOp (lhs, rhs, condOpJCond[m_icodes[1]->ic.ll.opcode - iJB]);
|
expr = COND_EXPR::boolOp (lhs, rhs, condOpJCond[m_icodes[1]->ll()->opcode - iJB]);
|
||||||
m_icodes[1]->setJCond(expr);
|
m_icodes[1]->setJCond(expr);
|
||||||
m_icodes[0]->invalidate();
|
m_icodes[0]->invalidate();
|
||||||
return 2;
|
return 2;
|
||||||
@ -244,21 +244,21 @@ bool Idiom20::match(iICODE picode)
|
|||||||
for(int i=0; i<4; ++i)
|
for(int i=0; i<4; ++i)
|
||||||
m_icodes[i] =picode++;
|
m_icodes[i] =picode++;
|
||||||
|
|
||||||
m_is_dec = m_icodes[0]->ic.ll.match(iDEC);
|
m_is_dec = m_icodes[0]->ll()->match(iDEC);
|
||||||
|
|
||||||
/* Get variable */
|
/* Get variable */
|
||||||
if (m_icodes[0]->ic.ll.dst.regi == 0) /* global variable */
|
if (m_icodes[0]->ll()->dst.regi == 0) /* global variable */
|
||||||
{
|
{
|
||||||
/* not supported yet */ ;
|
/* not supported yet */ ;
|
||||||
}
|
}
|
||||||
else if (m_icodes[0]->ic.ll.dst.regi < INDEXBASE) /* register */
|
else if (m_icodes[0]->ll()->dst.regi < INDEXBASE) /* register */
|
||||||
{
|
{
|
||||||
if ((m_icodes[0]->ic.ll.dst.regi == rSI) && (m_func->flg & SI_REGVAR))
|
if ((m_icodes[0]->ll()->dst.regi == rSI) && (m_func->flg & SI_REGVAR))
|
||||||
type = 1;
|
type = 1;
|
||||||
else if ((m_icodes[0]->ic.ll.dst.regi == rDI) && (m_func->flg & DI_REGVAR))
|
else if ((m_icodes[0]->ll()->dst.regi == rDI) && (m_func->flg & DI_REGVAR))
|
||||||
type = 1;
|
type = 1;
|
||||||
}
|
}
|
||||||
else if (m_icodes[0]->ic.ll.dst.off) /* local variable */
|
else if (m_icodes[0]->ll()->dst.off) /* local variable */
|
||||||
type = 2;
|
type = 2;
|
||||||
else /* indexed */
|
else /* indexed */
|
||||||
{
|
{
|
||||||
@ -269,28 +269,28 @@ bool Idiom20::match(iICODE picode)
|
|||||||
/* Check previous instruction for a MOV */
|
/* Check previous instruction for a MOV */
|
||||||
if (type == 1) /* register variable */
|
if (type == 1) /* register variable */
|
||||||
{
|
{
|
||||||
if (m_icodes[1]->ic.ll.match(iMOV) &&
|
if (m_icodes[1]->ll()->match(iMOV) &&
|
||||||
(m_icodes[1]->ic.ll.src.regi == m_icodes[0]->ic.ll.dst.regi))
|
(m_icodes[1]->ll()->src.regi == m_icodes[0]->ll()->dst.regi))
|
||||||
{
|
{
|
||||||
regi = m_icodes[1]->ic.ll.dst.regi;
|
regi = m_icodes[1]->ll()->dst.regi;
|
||||||
if ((regi > 0) && (regi < INDEXBASE))
|
if ((regi > 0) && (regi < INDEXBASE))
|
||||||
{
|
{
|
||||||
if (m_icodes[2]->ic.ll.match(iCMP,(eReg)regi) &&
|
if (m_icodes[2]->ll()->match(iCMP,(eReg)regi) &&
|
||||||
m_icodes[3]->ic.ll.conditionalJump())
|
m_icodes[3]->ll()->conditionalJump())
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (type == 2) /* local */
|
else if (type == 2) /* local */
|
||||||
{
|
{
|
||||||
if ( m_icodes[0]->ic.ll.match(iMOV) &&
|
if ( m_icodes[0]->ll()->match(iMOV) &&
|
||||||
(m_icodes[1]->ic.ll.src.off == m_icodes[0]->ic.ll.dst.off))
|
(m_icodes[1]->ll()->src.off == m_icodes[0]->ll()->dst.off))
|
||||||
{
|
{
|
||||||
regi = m_icodes[1]->ic.ll.dst.regi;
|
regi = m_icodes[1]->ll()->dst.regi;
|
||||||
if ((regi > 0) && (regi < INDEXBASE))
|
if ((regi > 0) && (regi < INDEXBASE))
|
||||||
{
|
{
|
||||||
if (m_icodes[2]->ic.ll.match(iCMP,(eReg)regi) &&
|
if (m_icodes[2]->ll()->match(iCMP,(eReg)regi) &&
|
||||||
m_icodes[3]->ic.ll.conditionalJump())
|
m_icodes[3]->ll()->conditionalJump())
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -303,7 +303,7 @@ int Idiom20::action()
|
|||||||
lhs = COND_EXPR::id (*m_icodes[1], SRC, m_func, m_icodes[0], *m_icodes[0], eUSE);
|
lhs = COND_EXPR::id (*m_icodes[1], SRC, m_func, m_icodes[0], *m_icodes[0], eUSE);
|
||||||
lhs = COND_EXPR::unary (m_is_dec ? PRE_DEC : PRE_INC, lhs);
|
lhs = COND_EXPR::unary (m_is_dec ? PRE_DEC : PRE_INC, lhs);
|
||||||
rhs = COND_EXPR::id (*m_icodes[2], SRC, m_func, m_icodes[0], *m_icodes[3], eUSE);
|
rhs = COND_EXPR::id (*m_icodes[2], SRC, m_func, m_icodes[0], *m_icodes[3], eUSE);
|
||||||
expr = COND_EXPR::boolOp (lhs, rhs, condOpJCond[m_icodes[3]->ic.ll.opcode - iJB]);
|
expr = COND_EXPR::boolOp (lhs, rhs, condOpJCond[m_icodes[3]->ll()->opcode - iJB]);
|
||||||
m_icodes[3]->setJCond(expr);
|
m_icodes[3]->setJCond(expr);
|
||||||
for(int i=0; i<3; ++i)
|
for(int i=0; i<3; ++i)
|
||||||
m_icodes[i]->invalidate();
|
m_icodes[i]->invalidate();
|
||||||
|
|||||||
@ -22,25 +22,25 @@ bool Idiom3::match(iICODE picode)
|
|||||||
/* Match ADD SP, immed */
|
/* Match ADD SP, immed */
|
||||||
for(int i=0; i<2; ++i)
|
for(int i=0; i<2; ++i)
|
||||||
m_icodes[i] = picode++;
|
m_icodes[i] = picode++;
|
||||||
if ( (m_icodes[1]->ic.ll.flg & I) && m_icodes[1]->ic.ll.match(iADD,rSP))
|
if ( m_icodes[1]->ll()->isLlFlag(I) && m_icodes[1]->ll()->match(iADD,rSP))
|
||||||
{
|
{
|
||||||
m_param_count = m_icodes[1]->ic.ll.src.op();
|
m_param_count = m_icodes[1]->ll()->src.op();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (m_icodes[1]->ic.ll.match(iMOV,rSP,rBP))
|
else if (m_icodes[1]->ll()->match(iMOV,rSP,rBP))
|
||||||
{
|
{
|
||||||
m_icodes[0]->ic.ll.flg |= REST_STK;
|
m_icodes[0]->ll()->SetLlFlag(REST_STK);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int Idiom3::action()
|
int Idiom3::action()
|
||||||
{
|
{
|
||||||
if (m_icodes[0]->ic.ll.flg & I)
|
if (m_icodes[0]->ll()->isLlFlag(I) )
|
||||||
{
|
{
|
||||||
m_icodes[0]->ic.ll.src.proc.proc->cbParam = (int16_t)m_param_count;
|
m_icodes[0]->ll()->src.proc.proc->cbParam = (int16_t)m_param_count;
|
||||||
m_icodes[0]->ic.ll.src.proc.cb = m_param_count;
|
m_icodes[0]->ll()->src.proc.cb = m_param_count;
|
||||||
m_icodes[0]->ic.ll.src.proc.proc->flg |= CALL_C;
|
m_icodes[0]->ll()->src.proc.proc->flg |= CALL_C;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -76,16 +76,16 @@ bool Idiom17::match(iICODE picode)
|
|||||||
uint8_t regi;
|
uint8_t regi;
|
||||||
|
|
||||||
/* Match POP reg */
|
/* Match POP reg */
|
||||||
if (m_icodes[1]->ic.ll.match(iPOP))
|
if (m_icodes[1]->ll()->match(iPOP))
|
||||||
{
|
{
|
||||||
int i=0;
|
int i=0;
|
||||||
regi = m_icodes[1]->ic.ll.dst.regi;
|
regi = m_icodes[1]->ll()->dst.regi;
|
||||||
if ((regi >= rAX) && (regi <= rBX))
|
if ((regi >= rAX) && (regi <= rBX))
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
while (picode != m_end && picode->ic.ll.match(iPOP))
|
while (picode != m_end && picode->ll()->match(iPOP))
|
||||||
{
|
{
|
||||||
if (picode->ic.ll.dst.regi != regi)
|
if (picode->ll()->dst.regi != regi)
|
||||||
break;
|
break;
|
||||||
i++;
|
i++;
|
||||||
m_icodes.push_back(picode++);
|
m_icodes.push_back(picode++);
|
||||||
@ -96,11 +96,11 @@ bool Idiom17::match(iICODE picode)
|
|||||||
}
|
}
|
||||||
int Idiom17::action()
|
int Idiom17::action()
|
||||||
{
|
{
|
||||||
if (m_icodes[0]->isLlFlag(I))
|
if (m_icodes[0]->ll()->isLlFlag(I))
|
||||||
{
|
{
|
||||||
m_icodes[0]->ic.ll.src.proc.proc->cbParam = (int16_t)m_param_count;
|
m_icodes[0]->ll()->src.proc.proc->cbParam = (int16_t)m_param_count;
|
||||||
m_icodes[0]->ic.ll.src.proc.cb = m_param_count;
|
m_icodes[0]->ll()->src.proc.cb = m_param_count;
|
||||||
m_icodes[0]->ic.ll.src.proc.proc->flg |= CALL_C;
|
m_icodes[0]->ll()->src.proc.proc->flg |= CALL_C;
|
||||||
for(int idx=1; idx<m_icodes.size(); ++idx)
|
for(int idx=1; idx<m_icodes.size(); ++idx)
|
||||||
{
|
{
|
||||||
m_icodes[idx]->invalidate();
|
m_icodes[idx]->invalidate();
|
||||||
|
|||||||
@ -12,22 +12,22 @@ void EpilogIdiom::popStkVars(iICODE pIcode)
|
|||||||
{
|
{
|
||||||
// TODO : only process SI-DI DI-SI pairings, no SI-SI, DI-DI like it's now
|
// TODO : only process SI-DI DI-SI pairings, no SI-SI, DI-DI like it's now
|
||||||
/* Match [POP DI] */
|
/* Match [POP DI] */
|
||||||
if (pIcode->ic.ll.match(iPOP))
|
if (pIcode->ll()->match(iPOP))
|
||||||
{
|
{
|
||||||
if ((m_func->flg & DI_REGVAR) && pIcode->ic.ll.match(rDI))
|
if ((m_func->flg & DI_REGVAR) && pIcode->ll()->match(rDI))
|
||||||
m_icodes.push_front(pIcode);
|
m_icodes.push_front(pIcode);
|
||||||
else if ((m_func->flg & SI_REGVAR) && pIcode->ic.ll.match(rSI))
|
else if ((m_func->flg & SI_REGVAR) && pIcode->ll()->match(rSI))
|
||||||
m_icodes.push_front(pIcode);
|
m_icodes.push_front(pIcode);
|
||||||
}
|
}
|
||||||
++pIcode;
|
++pIcode;
|
||||||
if(pIcode==m_end)
|
if(pIcode==m_end)
|
||||||
return;
|
return;
|
||||||
/* Match [POP SI] */
|
/* Match [POP SI] */
|
||||||
if (pIcode->ic.ll.match(iPOP))
|
if (pIcode->ll()->match(iPOP))
|
||||||
{
|
{
|
||||||
if ((m_func->flg & SI_REGVAR) && pIcode->ic.ll.match(rSI))
|
if ((m_func->flg & SI_REGVAR) && pIcode->ll()->match(rSI))
|
||||||
m_icodes.push_front(pIcode);
|
m_icodes.push_front(pIcode);
|
||||||
else if ((m_func->flg & DI_REGVAR) && pIcode->ic.ll.match(rDI))
|
else if ((m_func->flg & DI_REGVAR) && pIcode->ll()->match(rDI))
|
||||||
m_icodes.push_front(pIcode);
|
m_icodes.push_front(pIcode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -46,7 +46,7 @@ bool Idiom2::match(iICODE pIcode)
|
|||||||
iICODE nicode;
|
iICODE nicode;
|
||||||
if(pIcode==m_func->Icode.begin()) // pIcode->loc_ip == 0
|
if(pIcode==m_func->Icode.begin()) // pIcode->loc_ip == 0
|
||||||
return false;
|
return false;
|
||||||
if ( ((pIcode->ic.ll.flg & I) == I) || not pIcode->ic.ll.match(rSP,rBP))
|
if ( pIcode->ll()->isLlFlag(I) || (not pIcode->ll()->match(rSP,rBP)) )
|
||||||
return false;
|
return false;
|
||||||
if(distance(pIcode,m_end)<3)
|
if(distance(pIcode,m_end)<3)
|
||||||
return false;
|
return false;
|
||||||
@ -55,21 +55,21 @@ bool Idiom2::match(iICODE pIcode)
|
|||||||
m_icodes.push_back(pIcode);
|
m_icodes.push_back(pIcode);
|
||||||
/* Get next icode, skip over holes in the icode array */
|
/* Get next icode, skip over holes in the icode array */
|
||||||
nicode = ++iICODE(pIcode);
|
nicode = ++iICODE(pIcode);
|
||||||
while (nicode->ic.ll.flg & NO_CODE && (nicode != m_end))
|
while (nicode->ll()->isLlFlag(NO_CODE) && (nicode != m_end))
|
||||||
{
|
{
|
||||||
nicode++;
|
nicode++;
|
||||||
}
|
}
|
||||||
if(nicode == m_end)
|
if(nicode == m_end)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (nicode->ic.ll.match(iPOP,rBP) && ! (nicode->ic.ll.flg & (I | TARGET | CASE)) )
|
if (nicode->ll()->match(iPOP,rBP) && ! (nicode->ll()->isLlFlag(I | TARGET | CASE)) )
|
||||||
{
|
{
|
||||||
m_icodes.push_back(nicode++); // Matched POP BP
|
m_icodes.push_back(nicode++); // Matched POP BP
|
||||||
|
|
||||||
/* Match RET(F) */
|
/* Match RET(F) */
|
||||||
if ( nicode != m_end &&
|
if ( nicode != m_end &&
|
||||||
!(nicode->ic.ll.flg & (I | TARGET | CASE)) &&
|
!(nicode->ll()->isLlFlag(I | TARGET | CASE)) &&
|
||||||
(nicode->ic.ll.match(iRET) || nicode->ic.ll.match(iRETF))
|
(nicode->ll()->match(iRET) || nicode->ll()->match(iRETF))
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
m_icodes.push_back(nicode); // Matched RET
|
m_icodes.push_back(nicode); // Matched RET
|
||||||
@ -118,7 +118,7 @@ bool Idiom4::match(iICODE pIcode)
|
|||||||
{
|
{
|
||||||
iICODE prev1 = --iICODE(pIcode);
|
iICODE prev1 = --iICODE(pIcode);
|
||||||
/* Check for POP BP */
|
/* Check for POP BP */
|
||||||
if (prev1->ic.ll.match(iPOP,rBP) && not prev1->ic.ll.anyFlagSet(I) )
|
if (prev1->ll()->match(iPOP,rBP) && not prev1->ll()->isLlFlag(I) )
|
||||||
m_icodes.push_back(prev1);
|
m_icodes.push_back(prev1);
|
||||||
else if(prev1!=m_func->Icode.begin())
|
else if(prev1!=m_func->Icode.begin())
|
||||||
{
|
{
|
||||||
@ -129,9 +129,9 @@ bool Idiom4::match(iICODE pIcode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check for RET(F) immed */
|
/* Check for RET(F) immed */
|
||||||
if (pIcode->ic.ll.flg & I)
|
if (pIcode->ll()->isLlFlag(I) )
|
||||||
{
|
{
|
||||||
m_param_count = (int16_t)pIcode->ic.ll.src.op();
|
m_param_count = (int16_t)pIcode->ll()->src.op();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int Idiom4::action()
|
int Idiom4::action()
|
||||||
|
|||||||
@ -15,18 +15,18 @@ int Idiom1::checkStkVars (iICODE pIcode)
|
|||||||
int di_matched=0;
|
int di_matched=0;
|
||||||
if(pIcode==m_end)
|
if(pIcode==m_end)
|
||||||
return 0;
|
return 0;
|
||||||
if (pIcode->ic.ll.match(iPUSH,rSI))
|
if (pIcode->ll()->match(iPUSH,rSI))
|
||||||
{
|
{
|
||||||
si_matched = 1;
|
si_matched = 1;
|
||||||
++pIcode;
|
++pIcode;
|
||||||
if ((pIcode != m_end) && pIcode->ic.ll.match(iPUSH,rDI)) // Look for PUSH DI
|
if ((pIcode != m_end) && pIcode->ll()->match(iPUSH,rDI)) // Look for PUSH DI
|
||||||
di_matched = 1;
|
di_matched = 1;
|
||||||
}
|
}
|
||||||
else if (pIcode->ic.ll.match(iPUSH,rDI))
|
else if (pIcode->ll()->match(iPUSH,rDI))
|
||||||
{
|
{
|
||||||
di_matched = 1;
|
di_matched = 1;
|
||||||
++pIcode;
|
++pIcode;
|
||||||
if ((pIcode != m_end) && pIcode->ic.ll.match(iPUSH,rSI)) // Look for PUSH SI
|
if ((pIcode != m_end) && pIcode->ll()->match(iPUSH,rSI)) // Look for PUSH SI
|
||||||
si_matched = 1;
|
si_matched = 1;
|
||||||
}
|
}
|
||||||
m_func->flg |= (si_matched ? SI_REGVAR : 0) | (di_matched ? DI_REGVAR : 0);
|
m_func->flg |= (si_matched ? SI_REGVAR : 0) | (di_matched ? DI_REGVAR : 0);
|
||||||
@ -60,13 +60,13 @@ bool Idiom1::match(iICODE picode)
|
|||||||
m_icodes.clear();
|
m_icodes.clear();
|
||||||
m_min_off = 0;
|
m_min_off = 0;
|
||||||
/* PUSH BP as first instruction of procedure */
|
/* PUSH BP as first instruction of procedure */
|
||||||
if ( !(picode->ic.ll.flg & I) && picode->ic.ll.src.regi == rBP)
|
if ( (not picode->ll()->isLlFlag(I)) && picode->ll()->src.regi == rBP)
|
||||||
{
|
{
|
||||||
m_icodes.push_back( picode++ ); // insert iPUSH
|
m_icodes.push_back( picode++ ); // insert iPUSH
|
||||||
if(picode==m_end)
|
if(picode==m_end)
|
||||||
return false;
|
return false;
|
||||||
/* MOV BP, SP as next instruction */
|
/* MOV BP, SP as next instruction */
|
||||||
if ( !picode->ic.ll.anyFlagSet(I | TARGET | CASE) && picode->ic.ll.match(iMOV ,rBP,rSP) )
|
if ( !picode->ll()->isLlFlag(I | TARGET | CASE) && picode->ll()->match(iMOV ,rBP,rSP) )
|
||||||
{
|
{
|
||||||
m_icodes.push_back( picode++ ); // insert iMOV
|
m_icodes.push_back( picode++ ); // insert iMOV
|
||||||
if(picode==m_end)
|
if(picode==m_end)
|
||||||
@ -75,7 +75,7 @@ bool Idiom1::match(iICODE picode)
|
|||||||
|
|
||||||
/* Look for SUB SP, immed */
|
/* Look for SUB SP, immed */
|
||||||
if (
|
if (
|
||||||
picode->ic.ll.anyFlagSet(I | TARGET | CASE) && picode->ic.ll.match(iSUB,rSP)
|
picode->ll()->isLlFlag(I | TARGET | CASE) && picode->ll()->match(iSUB,rSP)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
m_icodes.push_back( picode++ ); // insert iSUB
|
m_icodes.push_back( picode++ ); // insert iSUB
|
||||||
@ -99,8 +99,8 @@ bool Idiom1::match(iICODE picode)
|
|||||||
return false;
|
return false;
|
||||||
/* Look for MOV BP, SP */
|
/* Look for MOV BP, SP */
|
||||||
if ( picode != m_end &&
|
if ( picode != m_end &&
|
||||||
!picode->ic.ll.anyFlagSet(I | TARGET | CASE) &&
|
!picode->ll()->isLlFlag(I | TARGET | CASE) &&
|
||||||
picode->ic.ll.match(iMOV,rBP,rSP))
|
picode->ll()->match(iMOV,rBP,rSP))
|
||||||
{
|
{
|
||||||
m_icodes.push_back(picode);
|
m_icodes.push_back(picode);
|
||||||
m_min_off = 2 + (n * 2);
|
m_min_off = 2 + (n * 2);
|
||||||
|
|||||||
@ -28,14 +28,14 @@ bool Idiom14::match(iICODE pIcode)
|
|||||||
m_icodes[0]=pIcode++;
|
m_icodes[0]=pIcode++;
|
||||||
m_icodes[1]=pIcode++;
|
m_icodes[1]=pIcode++;
|
||||||
/* Check for regL */
|
/* Check for regL */
|
||||||
m_regL = m_icodes[0]->ic.ll.dst.regi;
|
m_regL = m_icodes[0]->ll()->dst.regi;
|
||||||
if (not m_icodes[0]->isLlFlag(I) && ((m_regL == rAX) || (m_regL ==rBX)))
|
if (not m_icodes[0]->ll()->isLlFlag(I) && ((m_regL == rAX) || (m_regL ==rBX)))
|
||||||
{
|
{
|
||||||
/* Check for XOR regH, regH */
|
/* Check for XOR regH, regH */
|
||||||
if (m_icodes[1]->ic.ll.match(iXOR) && not m_icodes[1]->isLlFlag(I))
|
if (m_icodes[1]->ll()->match(iXOR) && not m_icodes[1]->ll()->isLlFlag(I))
|
||||||
{
|
{
|
||||||
m_regH = m_icodes[1]->ic.ll.dst.regi;
|
m_regH = m_icodes[1]->ll()->dst.regi;
|
||||||
if (m_regH == m_icodes[1]->ic.ll.src.regi)
|
if (m_regH == m_icodes[1]->ll()->src.regi)
|
||||||
{
|
{
|
||||||
if ((m_regL == rAX) && (m_regH == rDX))
|
if ((m_regL == rAX) && (m_regH == rDX))
|
||||||
return true;
|
return true;
|
||||||
@ -80,13 +80,13 @@ bool Idiom13::match(iICODE pIcode)
|
|||||||
uint8_t regi;
|
uint8_t regi;
|
||||||
|
|
||||||
/* Check for regL */
|
/* Check for regL */
|
||||||
regi = m_icodes[0]->ic.ll.dst.regi;
|
regi = m_icodes[0]->ll()->dst.regi;
|
||||||
if (not m_icodes[0]->isLlFlag(I) && (regi >= rAL) && (regi <= rBH))
|
if (not m_icodes[0]->ll()->isLlFlag(I) && (regi >= rAL) && (regi <= rBH))
|
||||||
{
|
{
|
||||||
/* Check for MOV regH, 0 */
|
/* Check for MOV regH, 0 */
|
||||||
if (m_icodes[1]->ic.ll.match(iMOV) && m_icodes[1]->isLlFlag(I) && (m_icodes[1]->ic.ll.src.op() == 0))
|
if (m_icodes[1]->ll()->match(iMOV) && m_icodes[1]->ll()->isLlFlag(I) && (m_icodes[1]->ll()->src.op() == 0))
|
||||||
{
|
{
|
||||||
if (m_icodes[1]->ic.ll.dst.regi == (regi + 4)) //TODO: based on distance between AH-AL,BH-BL etc.
|
if (m_icodes[1]->ll()->dst.regi == (regi + 4)) //TODO: based on distance between AH-AL,BH-BL etc.
|
||||||
{
|
{
|
||||||
m_loaded_reg=(regi - rAL + rAX);
|
m_loaded_reg=(regi - rAL + rAX);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@ -27,22 +27,22 @@ bool Idiom11::match (iICODE picode)
|
|||||||
return false;
|
return false;
|
||||||
/* Check NEG reg/mem
|
/* Check NEG reg/mem
|
||||||
* SBB reg/mem, 0*/
|
* SBB reg/mem, 0*/
|
||||||
if (not m_icodes[1]->ic.ll.match(iNEG) or not m_icodes[2]->ic.ll.match(iSBB))
|
if (not m_icodes[1]->ll()->match(iNEG) or not m_icodes[2]->ll()->match(iSBB))
|
||||||
return false;
|
return false;
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case GLOB_VAR:
|
case GLOB_VAR:
|
||||||
if ((m_icodes[2]->ic.ll.dst.segValue == m_icodes[0]->ic.ll.dst.segValue) &&
|
if ((m_icodes[2]->ll()->dst.segValue == m_icodes[0]->ll()->dst.segValue) &&
|
||||||
(m_icodes[2]->ic.ll.dst.off == m_icodes[0]->ic.ll.dst.off))
|
(m_icodes[2]->ll()->dst.off == m_icodes[0]->ll()->dst.off))
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
case REGISTER:
|
case REGISTER:
|
||||||
if (m_icodes[2]->ic.ll.dst.regi == m_icodes[0]->ic.ll.dst.regi)
|
if (m_icodes[2]->ll()->dst.regi == m_icodes[0]->ll()->dst.regi)
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
case PARAM:
|
case PARAM:
|
||||||
case LOCAL_VAR:
|
case LOCAL_VAR:
|
||||||
if (m_icodes[2]->ic.ll.dst.off == m_icodes[0]->ic.ll.dst.off)
|
if (m_icodes[2]->ll()->dst.off == m_icodes[0]->ll()->dst.off)
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -79,13 +79,13 @@ bool Idiom16::match (iICODE picode)
|
|||||||
for(int i=0; i<3; ++i)
|
for(int i=0; i<3; ++i)
|
||||||
m_icodes[i]=picode++;
|
m_icodes[i]=picode++;
|
||||||
|
|
||||||
uint8_t regi = m_icodes[0]->ic.ll.dst.regi;
|
uint8_t regi = m_icodes[0]->ll()->dst.regi;
|
||||||
if ((regi >= rAX) && (regi < INDEXBASE))
|
if ((regi >= rAX) && (regi < INDEXBASE))
|
||||||
{
|
{
|
||||||
if (m_icodes[1]->ic.ll.match(iSBB) && m_icodes[2]->ic.ll.match(iINC))
|
if (m_icodes[1]->ll()->match(iSBB) && m_icodes[2]->ll()->match(iINC))
|
||||||
if ((m_icodes[1]->ic.ll.dst.regi == (m_icodes[1]->ic.ll.src.regi)) &&
|
if ((m_icodes[1]->ll()->dst.regi == (m_icodes[1]->ll()->src.regi)) &&
|
||||||
m_icodes[1]->ic.ll.match((eReg)regi) &&
|
m_icodes[1]->ll()->match((eReg)regi) &&
|
||||||
m_icodes[2]->ic.ll.match((eReg)regi))
|
m_icodes[2]->ll()->match((eReg)regi))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -93,7 +93,7 @@ bool Idiom16::match (iICODE picode)
|
|||||||
int Idiom16::action()
|
int Idiom16::action()
|
||||||
{
|
{
|
||||||
COND_EXPR *lhs,*rhs;
|
COND_EXPR *lhs,*rhs;
|
||||||
lhs = COND_EXPR::idReg (m_icodes[0]->ic.ll.dst.regi, m_icodes[0]->ic.ll.flg,&m_func->localId);
|
lhs = COND_EXPR::idReg (m_icodes[0]->ll()->dst.regi, m_icodes[0]->ll()->GetLlFlag(),&m_func->localId);
|
||||||
rhs = COND_EXPR::unary (NEGATION, lhs->clone());
|
rhs = COND_EXPR::unary (NEGATION, lhs->clone());
|
||||||
m_icodes[0]->setAsgn(lhs, rhs);
|
m_icodes[0]->setAsgn(lhs, rhs);
|
||||||
m_icodes[1]->invalidate();
|
m_icodes[1]->invalidate();
|
||||||
|
|||||||
@ -18,10 +18,9 @@ bool Idiom8::match(iICODE pIcode)
|
|||||||
return false;
|
return false;
|
||||||
m_icodes[0]=pIcode++;
|
m_icodes[0]=pIcode++;
|
||||||
m_icodes[1]=pIcode++;
|
m_icodes[1]=pIcode++;
|
||||||
if (m_icodes[0]->isLlFlag(I) && (m_icodes[0]->ic.ll.src.op() == 1))
|
if (m_icodes[0]->ll()->isLlFlag(I) && (m_icodes[0]->ll()->src.op() == 1))
|
||||||
if (m_icodes[1]->ic.ll.match(iRCR) &&
|
if ( m_icodes[1]->ll()->match(iRCR,I) &&
|
||||||
m_icodes[1]->isLlFlag(I) &&
|
(m_icodes[1]->ll()->src.op() == 1))
|
||||||
(m_icodes[1]->ic.ll.src.op() == 1))
|
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -31,8 +30,8 @@ int Idiom8::action()
|
|||||||
int idx;
|
int idx;
|
||||||
COND_EXPR *rhs,*lhs,*expr;
|
COND_EXPR *rhs,*lhs,*expr;
|
||||||
uint8_t regH,regL;
|
uint8_t regH,regL;
|
||||||
regH=m_icodes[0]->ic.ll.dst.regi;
|
regH=m_icodes[0]->ll()->dst.regi;
|
||||||
regL=m_icodes[1]->ic.ll.dst.regi;
|
regL=m_icodes[1]->ll()->dst.regi;
|
||||||
idx = m_func->localId.newLongReg (TYPE_LONG_SIGN, regH, regL, m_icodes[0]);
|
idx = m_func->localId.newLongReg (TYPE_LONG_SIGN, regH, regL, m_icodes[0]);
|
||||||
lhs = COND_EXPR::idLongIdx (idx);
|
lhs = COND_EXPR::idLongIdx (idx);
|
||||||
m_icodes[0]->setRegDU( regL, USE_DEF);
|
m_icodes[0]->setRegDU( regL, USE_DEF);
|
||||||
@ -64,15 +63,14 @@ bool Idiom15::match(iICODE pIcode)
|
|||||||
if(distance(pIcode,m_end)<2)
|
if(distance(pIcode,m_end)<2)
|
||||||
return false;
|
return false;
|
||||||
/* Match SHL reg, 1 */
|
/* Match SHL reg, 1 */
|
||||||
if (not pIcode->isLlFlag(I) or (pIcode->ic.ll.src.op() != 1))
|
if (not pIcode->ll()->isLlFlag(I) or (pIcode->ll()->src.op() != 1))
|
||||||
return false;
|
return false;
|
||||||
m_icodes.clear();
|
m_icodes.clear();
|
||||||
regi = pIcode->ic.ll.dst.regi;
|
regi = pIcode->ll()->dst.regi;
|
||||||
m_icodes.push_back(pIcode++);
|
m_icodes.push_back(pIcode++);
|
||||||
while( (pIcode!=m_end) and
|
while( (pIcode!=m_end) and
|
||||||
pIcode->ic.ll.match(iSHL,(eReg)regi) and
|
pIcode->ll()->match(iSHL,(eReg)regi,I) and
|
||||||
pIcode->isLlFlag(I) and
|
(pIcode->ll()->src.op() == 1) )
|
||||||
(pIcode->ic.ll.src.op() == 1) )
|
|
||||||
{
|
{
|
||||||
n++;
|
n++;
|
||||||
m_icodes.push_back(pIcode++);
|
m_icodes.push_back(pIcode++);
|
||||||
@ -83,9 +81,9 @@ bool Idiom15::match(iICODE pIcode)
|
|||||||
int Idiom15::action()
|
int Idiom15::action()
|
||||||
{
|
{
|
||||||
COND_EXPR *lhs,*rhs,*exp;
|
COND_EXPR *lhs,*rhs,*exp;
|
||||||
lhs = COND_EXPR::idReg (m_icodes[0]->ic.ll.dst.regi,
|
lhs = COND_EXPR::idReg (m_icodes[0]->ll()->dst.regi,
|
||||||
m_icodes[0]->ic.ll.flg & NO_SRC_B,
|
m_icodes[0]->ll()->GetLlFlag() & NO_SRC_B,
|
||||||
&m_func->localId);
|
&m_func->localId);
|
||||||
rhs = COND_EXPR::idKte (m_icodes.size(), 2);
|
rhs = COND_EXPR::idKte (m_icodes.size(), 2);
|
||||||
exp = COND_EXPR::boolOp (lhs, rhs, SHL);
|
exp = COND_EXPR::boolOp (lhs, rhs, SHL);
|
||||||
m_icodes[0]->setAsgn(lhs, exp);
|
m_icodes[0]->setAsgn(lhs, exp);
|
||||||
@ -111,9 +109,8 @@ bool Idiom12::match(iICODE pIcode)
|
|||||||
return false;
|
return false;
|
||||||
m_icodes[0]=pIcode++;
|
m_icodes[0]=pIcode++;
|
||||||
m_icodes[1]=pIcode++;
|
m_icodes[1]=pIcode++;
|
||||||
if (m_icodes[0]->isLlFlag(I) && (m_icodes[0]->ic.ll.src.op() == 1))
|
if (m_icodes[0]->ll()->isLlFlag(I) && (m_icodes[0]->ll()->src.op() == 1))
|
||||||
if (m_icodes[1]->ic.ll.match(iRCL) &&
|
if (m_icodes[1]->ll()->match(iRCL,I) && (m_icodes[1]->ll()->src.op() == 1))
|
||||||
m_icodes[1]->isLlFlag(I) && (m_icodes[1]->ic.ll.src.op() == 1))
|
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -123,8 +120,8 @@ int Idiom12::action()
|
|||||||
int idx;
|
int idx;
|
||||||
COND_EXPR *rhs,*lhs,*expr;
|
COND_EXPR *rhs,*lhs,*expr;
|
||||||
uint8_t regH,regL;
|
uint8_t regH,regL;
|
||||||
regL=m_icodes[0]->ic.ll.dst.regi;
|
regL=m_icodes[0]->ll()->dst.regi;
|
||||||
regH=m_icodes[1]->ic.ll.dst.regi;
|
regH=m_icodes[1]->ll()->dst.regi;
|
||||||
|
|
||||||
idx = m_func->localId.newLongReg (TYPE_LONG_UNSIGN, regH, regL,m_icodes[0]);
|
idx = m_func->localId.newLongReg (TYPE_LONG_UNSIGN, regH, regL,m_icodes[0]);
|
||||||
lhs = COND_EXPR::idLongIdx (idx);
|
lhs = COND_EXPR::idLongIdx (idx);
|
||||||
@ -151,9 +148,8 @@ bool Idiom9::match(iICODE pIcode)
|
|||||||
return false;
|
return false;
|
||||||
m_icodes[0]=pIcode++;
|
m_icodes[0]=pIcode++;
|
||||||
m_icodes[1]=pIcode++;
|
m_icodes[1]=pIcode++;
|
||||||
if (m_icodes[0]->isLlFlag(I) && (m_icodes[0]->ic.ll.src.op() == 1))
|
if (m_icodes[0]->ll()->isLlFlag(I) && (m_icodes[0]->ll()->src.op() == 1))
|
||||||
if (m_icodes[1]->ic.ll.match(iRCR) &&
|
if (m_icodes[1]->ll()->match(iRCR,I) && (m_icodes[1]->ll()->src.op() == 1))
|
||||||
m_icodes[1]->isLlFlag(I) && (m_icodes[1]->ic.ll.src.op() == 1))
|
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -163,8 +159,8 @@ int Idiom9::action()
|
|||||||
int idx;
|
int idx;
|
||||||
COND_EXPR *rhs,*lhs,*expr;
|
COND_EXPR *rhs,*lhs,*expr;
|
||||||
uint8_t regH,regL;
|
uint8_t regH,regL;
|
||||||
regL=m_icodes[1]->ic.ll.dst.regi;
|
regL=m_icodes[1]->ll()->dst.regi;
|
||||||
regH=m_icodes[0]->ic.ll.dst.regi;
|
regH=m_icodes[0]->ll()->dst.regi;
|
||||||
idx = m_func->localId.newLongReg (TYPE_LONG_UNSIGN,regH,regL,m_icodes[0]);
|
idx = m_func->localId.newLongReg (TYPE_LONG_UNSIGN,regH,regL,m_icodes[0]);
|
||||||
lhs = COND_EXPR::idLongIdx (idx);
|
lhs = COND_EXPR::idLongIdx (idx);
|
||||||
m_icodes[0]->setRegDU(regL, USE_DEF);
|
m_icodes[0]->setRegDU(regL, USE_DEF);
|
||||||
|
|||||||
@ -23,16 +23,16 @@ bool Idiom21::match (iICODE picode)
|
|||||||
m_icodes[0]=picode++;
|
m_icodes[0]=picode++;
|
||||||
m_icodes[1]=picode++;
|
m_icodes[1]=picode++;
|
||||||
|
|
||||||
if (not m_icodes[1]->isLlFlag(I))
|
if (not m_icodes[1]->ll()->isLlFlag(I))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
dst = &m_icodes[0]->ic.ll.dst;
|
dst = &m_icodes[0]->ll()->dst;
|
||||||
src = &m_icodes[0]->ic.ll.src;
|
src = &m_icodes[0]->ll()->src;
|
||||||
if ((dst->regi == src->regi) && (dst->regi > 0) && (dst->regi < INDEXBASE))
|
if ((dst->regi == src->regi) && (dst->regi > 0) && (dst->regi < INDEXBASE))
|
||||||
{
|
{
|
||||||
if ((dst->regi == rDX) && m_icodes[1]->ic.ll.match(rAX))
|
if ((dst->regi == rDX) && m_icodes[1]->ll()->match(rAX))
|
||||||
return true;
|
return true;
|
||||||
if ((dst->regi == rCX) && m_icodes[1]->ic.ll.match(rBX))
|
if ((dst->regi == rCX) && m_icodes[1]->ll()->match(rBX))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -41,7 +41,7 @@ int Idiom21::action()
|
|||||||
{
|
{
|
||||||
COND_EXPR *lhs,*rhs;
|
COND_EXPR *lhs,*rhs;
|
||||||
lhs = COND_EXPR::idLong (&m_func->localId, DST, m_icodes[0],HIGH_FIRST, m_icodes[0], eDEF, 1);
|
lhs = COND_EXPR::idLong (&m_func->localId, DST, m_icodes[0],HIGH_FIRST, m_icodes[0], eDEF, 1);
|
||||||
rhs = COND_EXPR::idKte (m_icodes[1]->ic.ll.src.op() , 4);
|
rhs = COND_EXPR::idKte (m_icodes[1]->ll()->src.op() , 4);
|
||||||
m_icodes[0]->setAsgn(lhs, rhs);
|
m_icodes[0]->setAsgn(lhs, rhs);
|
||||||
m_icodes[0]->du.use = 0; /* clear register used in iXOR */
|
m_icodes[0]->du.use = 0; /* clear register used in iXOR */
|
||||||
m_icodes[1]->invalidate();
|
m_icodes[1]->invalidate();
|
||||||
@ -61,8 +61,8 @@ bool Idiom7::match(iICODE picode)
|
|||||||
return false;
|
return false;
|
||||||
LLOperand *dst, *src;
|
LLOperand *dst, *src;
|
||||||
m_icode=picode;
|
m_icode=picode;
|
||||||
dst = &picode->ic.ll.dst;
|
dst = &picode->ll()->dst;
|
||||||
src = &picode->ic.ll.src;
|
src = &picode->ll()->src;
|
||||||
if (dst->regi == 0) /* global variable */
|
if (dst->regi == 0) /* global variable */
|
||||||
{
|
{
|
||||||
if ((dst->segValue == src->segValue) && (dst->off == src->off))
|
if ((dst->segValue == src->segValue) && (dst->off == src->off))
|
||||||
@ -87,7 +87,7 @@ int Idiom7::action()
|
|||||||
rhs = COND_EXPR::idKte (0, 2);
|
rhs = COND_EXPR::idKte (0, 2);
|
||||||
m_icode->setAsgn(lhs, rhs);
|
m_icode->setAsgn(lhs, rhs);
|
||||||
m_icode->du.use = 0; /* clear register used in iXOR */
|
m_icode->du.use = 0; /* clear register used in iXOR */
|
||||||
m_icode->ic.ll.flg |= I;
|
m_icode->ll()->SetLlFlag(I);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,11 +113,11 @@ bool Idiom10::match(iICODE pIcode)
|
|||||||
m_icodes[0]=pIcode++;
|
m_icodes[0]=pIcode++;
|
||||||
m_icodes[1]=pIcode++;
|
m_icodes[1]=pIcode++;
|
||||||
/* Check OR reg, reg */
|
/* Check OR reg, reg */
|
||||||
if (not m_icodes[0]->isLlFlag(I) &&
|
if (not m_icodes[0]->ll()->isLlFlag(I) &&
|
||||||
(m_icodes[0]->ic.ll.src.regi > 0) &&
|
(m_icodes[0]->ll()->src.regi > 0) &&
|
||||||
(m_icodes[0]->ic.ll.src.regi < INDEXBASE) &&
|
(m_icodes[0]->ll()->src.regi < INDEXBASE) &&
|
||||||
(m_icodes[0]->ic.ll.src.regi == m_icodes[0]->ic.ll.dst.regi))
|
(m_icodes[0]->ll()->src.regi == m_icodes[0]->ll()->dst.regi))
|
||||||
if (m_icodes[1]->ic.ll.match(iJNE)) //.conditionalJump()
|
if (m_icodes[1]->ll()->match(iJNE)) //.conditionalJump()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -126,9 +126,9 @@ bool Idiom10::match(iICODE pIcode)
|
|||||||
|
|
||||||
int Idiom10::action()
|
int Idiom10::action()
|
||||||
{
|
{
|
||||||
m_icodes[0]->ic.ll.opcode = iCMP;
|
m_icodes[0]->ll()->opcode = iCMP;
|
||||||
m_icodes[0]->ic.ll.flg |= I;
|
m_icodes[0]->ll()->SetLlFlag(I);
|
||||||
m_icodes[0]->ic.ll.src.SetImmediateOp(0); // todo check if proc should be zeroed too
|
m_icodes[0]->ll()->src.SetImmediateOp(0); // todo check if proc should be zeroed too
|
||||||
m_icodes[0]->du.def = 0;
|
m_icodes[0]->du.def = 0;
|
||||||
m_icodes[0]->du1.numRegsDef = 0;
|
m_icodes[0]->du1.numRegsDef = 0;
|
||||||
return 2;
|
return 2;
|
||||||
|
|||||||
@ -273,13 +273,13 @@ int LOCAL_ID::newLong(opLoc sd, iICODE pIcode, hlFirst f, iICODE ix,operDu du, i
|
|||||||
|
|
||||||
if (f == LOW_FIRST)
|
if (f == LOW_FIRST)
|
||||||
{
|
{
|
||||||
pmL = (sd == SRC) ? &pIcode->ic.ll.src : &pIcode->ic.ll.dst;
|
pmL = (sd == SRC) ? &pIcode->ll()->src : &pIcode->ll()->dst;
|
||||||
pmH = (sd == SRC) ? &atOffset->ic.ll.src : &atOffset->ic.ll.dst;
|
pmH = (sd == SRC) ? &atOffset->ll()->src : &atOffset->ll()->dst;
|
||||||
}
|
}
|
||||||
else /* HIGH_FIRST */
|
else /* HIGH_FIRST */
|
||||||
{
|
{
|
||||||
pmH = (sd == SRC) ? &pIcode->ic.ll.src : &pIcode->ic.ll.dst;
|
pmH = (sd == SRC) ? &pIcode->ll()->src : &pIcode->ll()->dst;
|
||||||
pmL = (sd == SRC) ? &atOffset->ic.ll.src : &atOffset->ic.ll.dst;
|
pmL = (sd == SRC) ? &atOffset->ll()->src : &atOffset->ll()->dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pmL->regi == 0) /* global variable */
|
if (pmL->regi == 0) /* global variable */
|
||||||
@ -330,16 +330,16 @@ boolT checkLongEq (LONG_STKID_TYPE longId, iICODE pIcode, int i,
|
|||||||
iICODE atOffset(pIcode);
|
iICODE atOffset(pIcode);
|
||||||
advance(atOffset,off);
|
advance(atOffset,off);
|
||||||
|
|
||||||
pmHdst = &pIcode->ic.ll.dst;
|
pmHdst = &pIcode->ll()->dst;
|
||||||
pmLdst = &atOffset->ic.ll.dst;
|
pmLdst = &atOffset->ll()->dst;
|
||||||
pmHsrc = &pIcode->ic.ll.src;
|
pmHsrc = &pIcode->ll()->src;
|
||||||
pmLsrc = &atOffset->ic.ll.src;
|
pmLsrc = &atOffset->ll()->src;
|
||||||
|
|
||||||
if ((longId.offH == pmHdst->off) && (longId.offL == pmLdst->off))
|
if ((longId.offH == pmHdst->off) && (longId.offL == pmLdst->off))
|
||||||
{
|
{
|
||||||
asgn.lhs = COND_EXPR::idLongIdx (i);
|
asgn.lhs = COND_EXPR::idLongIdx (i);
|
||||||
|
|
||||||
if ((pIcode->ic.ll.flg & NO_SRC) != NO_SRC)
|
if ( not pIcode->ll()->isLlFlag(NO_SRC) )
|
||||||
{
|
{
|
||||||
asgn.rhs = COND_EXPR::idLong (&pProc->localId, SRC, pIcode, HIGH_FIRST, pIcode, eUSE, off);
|
asgn.rhs = COND_EXPR::idLong (&pProc->localId, SRC, pIcode, HIGH_FIRST, pIcode, eUSE, off);
|
||||||
}
|
}
|
||||||
@ -371,15 +371,15 @@ boolT checkLongRegEq (LONGID_TYPE longId, iICODE pIcode, int i,
|
|||||||
iICODE atOffset(pIcode);
|
iICODE atOffset(pIcode);
|
||||||
advance(atOffset,off);
|
advance(atOffset,off);
|
||||||
|
|
||||||
pmHdst = &pIcode->ic.ll.dst;
|
pmHdst = &pIcode->ll()->dst;
|
||||||
pmLdst = &atOffset->ic.ll.dst;
|
pmLdst = &atOffset->ll()->dst;
|
||||||
pmHsrc = &pIcode->ic.ll.src;
|
pmHsrc = &pIcode->ll()->src;
|
||||||
pmLsrc = &atOffset->ic.ll.src;
|
pmLsrc = &atOffset->ll()->src;
|
||||||
|
|
||||||
if ((longId.h == pmHdst->regi) && (longId.l == pmLdst->regi))
|
if ((longId.h == pmHdst->regi) && (longId.l == pmLdst->regi))
|
||||||
{
|
{
|
||||||
lhs = COND_EXPR::idLongIdx (i);
|
lhs = COND_EXPR::idLongIdx (i);
|
||||||
if ((pIcode->ic.ll.flg & NO_SRC) != NO_SRC)
|
if ( not pIcode->ll()->isLlFlag(NO_SRC) )
|
||||||
{
|
{
|
||||||
rhs = COND_EXPR::idLong (&pProc->localId, SRC, pIcode, HIGH_FIRST, pIcode, eUSE, off);
|
rhs = COND_EXPR::idLong (&pProc->localId, SRC, pIcode, HIGH_FIRST, pIcode, eUSE, off);
|
||||||
}
|
}
|
||||||
|
|||||||
277
src/parser.cpp
277
src/parser.cpp
@ -15,7 +15,7 @@ using namespace std;
|
|||||||
static boolT process_JMP (ICODE * pIcode, STATE * pstate, CALL_GRAPH * pcallGraph);
|
static boolT process_JMP (ICODE * pIcode, STATE * pstate, CALL_GRAPH * pcallGraph);
|
||||||
static void setBits(int16_t type, uint32_t start, uint32_t len);
|
static void setBits(int16_t type, uint32_t start, uint32_t len);
|
||||||
static SYM * updateGlobSym(uint32_t operand, int size, uint16_t duFlag);
|
static SYM * updateGlobSym(uint32_t operand, int size, uint16_t duFlag);
|
||||||
static void process_MOV(ICODE & pIcode, STATE * pstate);
|
static void process_MOV(LLInst &ll, STATE * pstate);
|
||||||
static SYM * lookupAddr (LLOperand *pm, STATE * pstate, int size, uint16_t duFlag);
|
static SYM * lookupAddr (LLOperand *pm, STATE * pstate, int size, uint16_t duFlag);
|
||||||
void interactDis(Function * initProc, int ic);
|
void interactDis(Function * initProc, int ic);
|
||||||
static uint32_t SynthLab;
|
static uint32_t SynthLab;
|
||||||
@ -28,7 +28,6 @@ void parse (CALL_GRAPH * *pcallGraph)
|
|||||||
STATE state;
|
STATE state;
|
||||||
|
|
||||||
/* Set initial state */
|
/* Set initial state */
|
||||||
memset(&state, 0, sizeof(STATE));
|
|
||||||
state.setState(rES, 0); /* PSP segment */
|
state.setState(rES, 0); /* PSP segment */
|
||||||
state.setState(rDS, 0);
|
state.setState(rDS, 0);
|
||||||
state.setState(rCS, prog.initCS);
|
state.setState(rCS, prog.initCS);
|
||||||
@ -134,101 +133,102 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
|
|||||||
|
|
||||||
while (! done && ! (err = scan(pstate->IP, _Icode)))
|
while (! done && ! (err = scan(pstate->IP, _Icode)))
|
||||||
{
|
{
|
||||||
pstate->IP += (uint32_t)_Icode.ic.ll.numBytes;
|
LLInst *ll = _Icode.ll();
|
||||||
setBits(BM_CODE, _Icode.ic.ll.label, (uint32_t)_Icode.ic.ll.numBytes);
|
pstate->IP += (uint32_t)ll->numBytes;
|
||||||
|
setBits(BM_CODE, ll->label, (uint32_t)ll->numBytes);
|
||||||
|
|
||||||
process_operands(_Icode,pstate);
|
process_operands(_Icode,pstate);
|
||||||
|
|
||||||
/* Keep track of interesting instruction flags in procedure */
|
/* Keep track of interesting instruction flags in procedure */
|
||||||
flg |= (_Icode.ic.ll.flg & (NOT_HLL | FLOAT_OP));
|
flg |= (ll->GetLlFlag() & (NOT_HLL | FLOAT_OP));
|
||||||
|
|
||||||
/* Check if this instruction has already been parsed */
|
/* Check if this instruction has already been parsed */
|
||||||
iICODE labLoc = Icode.labelSrch(_Icode.ic.ll.label);
|
iICODE labLoc = Icode.labelSrch(ll->label);
|
||||||
if (Icode.end()!=labLoc)
|
if (Icode.end()!=labLoc)
|
||||||
{ /* Synthetic jump */
|
{ /* Synthetic jump */
|
||||||
_Icode.type = LOW_LEVEL;
|
_Icode.type = LOW_LEVEL;
|
||||||
_Icode.ic.ll.set(iJMP,I | SYNTHETIC | NO_OPS);
|
ll->set(iJMP,I | SYNTHETIC | NO_OPS);
|
||||||
_Icode.ic.ll.src.SetImmediateOp(labLoc->GetLlLabel());
|
ll->src.SetImmediateOp(labLoc->ll()->GetLlLabel());
|
||||||
_Icode.ic.ll.label = SynthLab++;
|
ll->label = SynthLab++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy Icode to Proc */
|
/* Copy Icode to Proc */
|
||||||
if ((_Icode.ic.ll.opcode == iDIV) || (_Icode.ic.ll.opcode == iIDIV))
|
if ((_Icode.ll()->opcode == iDIV) || (_Icode.ll()->opcode == iIDIV))
|
||||||
{
|
{
|
||||||
/* MOV rTMP, reg */
|
/* MOV rTMP, reg */
|
||||||
memset (&eIcode, 0, sizeof (ICODE));
|
eIcode = ICODE();
|
||||||
eIcode.type = LOW_LEVEL;
|
eIcode.type = LOW_LEVEL;
|
||||||
eIcode.ic.ll.opcode = iMOV;
|
eIcode.ll()->opcode = iMOV;
|
||||||
eIcode.ic.ll.dst.regi = rTMP;
|
eIcode.ll()->dst.regi = rTMP;
|
||||||
if (_Icode.ic.ll.flg & B)
|
if (ll->isLlFlag(B) )
|
||||||
{
|
{
|
||||||
eIcode.ic.ll.flg |= B;
|
eIcode.ll()->SetLlFlag( B );
|
||||||
eIcode.ic.ll.src.regi = rAX;
|
eIcode.ll()->src.regi = rAX;
|
||||||
eIcode.setRegDU( rAX, eUSE);
|
eIcode.setRegDU( rAX, eUSE);
|
||||||
}
|
}
|
||||||
else /* implicit dx:ax */
|
else /* implicit dx:ax */
|
||||||
{
|
{
|
||||||
eIcode.ic.ll.flg |= IM_SRC;
|
eIcode.ll()->SetLlFlag( IM_SRC );
|
||||||
eIcode.setRegDU( rAX, eUSE);
|
eIcode.setRegDU( rAX, eUSE);
|
||||||
eIcode.setRegDU( rDX, eUSE);
|
eIcode.setRegDU( rDX, eUSE);
|
||||||
}
|
}
|
||||||
eIcode.setRegDU( rTMP, eDEF);
|
eIcode.setRegDU( rTMP, eDEF);
|
||||||
eIcode.ic.ll.flg |= SYNTHETIC;
|
eIcode.ll()->SetLlFlag( SYNTHETIC );
|
||||||
/* eIcode.ic.ll.label = SynthLab++; */
|
/* eIcode.ll()->label = SynthLab++; */
|
||||||
eIcode.ic.ll.label = _Icode.ic.ll.label;
|
eIcode.ll()->label = _Icode.ll()->label;
|
||||||
Icode.addIcode(&eIcode);
|
Icode.addIcode(&eIcode);
|
||||||
|
|
||||||
/* iDIV, iIDIV */
|
/* iDIV, iIDIV */
|
||||||
Icode.addIcode(&_Icode);
|
Icode.addIcode(&_Icode);
|
||||||
|
|
||||||
/* iMOD */
|
/* iMOD */
|
||||||
memset (&eIcode, 0, sizeof (ICODE));
|
eIcode = ICODE();
|
||||||
eIcode.type = LOW_LEVEL;
|
eIcode.type = LOW_LEVEL;
|
||||||
eIcode.ic.ll.opcode = iMOD;
|
eIcode.ll()->opcode = iMOD;
|
||||||
eIcode.ic.ll.src = _Icode.ic.ll.src;
|
eIcode.ll()->src = _Icode.ll()->src;
|
||||||
eIcode.du = _Icode.du;
|
eIcode.du = _Icode.du;
|
||||||
eIcode.ic.ll.flg = (_Icode.ic.ll.flg | SYNTHETIC);
|
eIcode.ll()->SetLlFlag( ( ll->GetLlFlag() | SYNTHETIC) );
|
||||||
eIcode.ic.ll.label = SynthLab++;
|
eIcode.ll()->label = SynthLab++;
|
||||||
pIcode = Icode.addIcode(&eIcode);
|
pIcode = Icode.addIcode(&eIcode);
|
||||||
}
|
}
|
||||||
else if (_Icode.ic.ll.opcode == iXCHG)
|
else if (_Icode.ll()->opcode == iXCHG)
|
||||||
{
|
{
|
||||||
/* MOV rTMP, regDst */
|
/* MOV rTMP, regDst */
|
||||||
memset (&eIcode, 0, sizeof (ICODE));
|
eIcode = ICODE();
|
||||||
eIcode.type = LOW_LEVEL;
|
eIcode.type = LOW_LEVEL;
|
||||||
eIcode.ic.ll.opcode = iMOV;
|
eIcode.ll()->opcode = iMOV;
|
||||||
eIcode.ic.ll.dst.regi = rTMP;
|
eIcode.ll()->dst.regi = rTMP;
|
||||||
eIcode.ic.ll.src.regi = _Icode.ic.ll.dst.regi;
|
eIcode.ll()->src.regi = _Icode.ll()->dst.regi;
|
||||||
eIcode.setRegDU( rTMP, eDEF);
|
eIcode.setRegDU( rTMP, eDEF);
|
||||||
eIcode.setRegDU( eIcode.ic.ll.src.regi, eUSE);
|
eIcode.setRegDU( eIcode.ll()->src.regi, eUSE);
|
||||||
eIcode.ic.ll.flg |= SYNTHETIC;
|
eIcode.ll()->SetLlFlag( SYNTHETIC );
|
||||||
/* eIcode.ic.ll.label = SynthLab++; */
|
/* eIcode.ll()->label = SynthLab++; */
|
||||||
eIcode.ic.ll.label = _Icode.ic.ll.label;
|
eIcode.ll()->label = _Icode.ll()->label;
|
||||||
Icode.addIcode(&eIcode);
|
Icode.addIcode(&eIcode);
|
||||||
|
|
||||||
/* MOV regDst, regSrc */
|
/* MOV regDst, regSrc */
|
||||||
_Icode.ic.ll.opcode = iMOV;
|
_Icode.ll()->opcode = iMOV;
|
||||||
_Icode.ic.ll.flg |= SYNTHETIC;
|
ll->SetLlFlag( SYNTHETIC );
|
||||||
/* Icode.ic.ll.label = SynthLab++; */
|
/* Icode.ll()->label = SynthLab++; */
|
||||||
Icode.addIcode(&_Icode);
|
Icode.addIcode(&_Icode);
|
||||||
_Icode.ic.ll.opcode = iXCHG; /* for next case */
|
ll->opcode = iXCHG; /* for next case */
|
||||||
|
|
||||||
/* MOV regSrc, rTMP */
|
/* MOV regSrc, rTMP */
|
||||||
memset (&eIcode, 0, sizeof (ICODE));
|
eIcode = ICODE();
|
||||||
eIcode.type = LOW_LEVEL;
|
eIcode.type = LOW_LEVEL;
|
||||||
eIcode.ic.ll.opcode = iMOV;
|
eIcode.ll()->opcode = iMOV;
|
||||||
eIcode.ic.ll.dst.regi = _Icode.ic.ll.src.regi;
|
eIcode.ll()->dst.regi = ll->src.regi;
|
||||||
eIcode.ic.ll.src.regi = rTMP;
|
eIcode.ll()->src.regi = rTMP;
|
||||||
eIcode.setRegDU( eIcode.ic.ll.dst.regi, eDEF);
|
eIcode.setRegDU( eIcode.ll()->dst.regi, eDEF);
|
||||||
eIcode.setRegDU( rTMP, eUSE);
|
eIcode.setRegDU( rTMP, eUSE);
|
||||||
eIcode.ic.ll.flg |= SYNTHETIC;
|
eIcode.ll()->SetLlFlag(SYNTHETIC);
|
||||||
eIcode.ic.ll.label = SynthLab++;
|
eIcode.ll()->label = SynthLab++;
|
||||||
pIcode = Icode.addIcode(&eIcode);
|
pIcode = Icode.addIcode(&eIcode);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
pIcode = Icode.addIcode(&_Icode);
|
pIcode = Icode.addIcode(&_Icode);
|
||||||
|
|
||||||
switch (_Icode.ic.ll.opcode) {
|
switch (ll->opcode) {
|
||||||
/*** Conditional jumps ***/
|
/*** Conditional jumps ***/
|
||||||
case iLOOP: case iLOOPE: case iLOOPNE:
|
case iLOOP: case iLOOPE: case iLOOPNE:
|
||||||
case iJB: case iJBE: case iJAE: case iJA:
|
case iJB: case iJBE: case iJAE: case iJA:
|
||||||
@ -246,15 +246,15 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
|
|||||||
/* This sets up range check for indexed JMPs hopefully
|
/* This sets up range check for indexed JMPs hopefully
|
||||||
* Handles JA/JAE for fall through and JB/JBE on branch
|
* Handles JA/JAE for fall through and JB/JBE on branch
|
||||||
*/
|
*/
|
||||||
if (ip > 0 && prev.ic.ll.opcode == iCMP && (prev.ic.ll.flg & I))
|
if (ip > 0 && prev.ll()->opcode == iCMP && (prev.ll()->isLlFlag(I)))
|
||||||
{
|
{
|
||||||
pstate->JCond.immed = (int16_t)prev.ic.ll.src.op();
|
pstate->JCond.immed = (int16_t)prev.ll()->src.op();
|
||||||
if (_Icode.ic.ll.opcode == iJA || _Icode.ic.ll.opcode == iJBE)
|
if (ll->opcode == iJA || ll->opcode == iJBE)
|
||||||
pstate->JCond.immed++;
|
pstate->JCond.immed++;
|
||||||
if (_Icode.ic.ll.opcode == iJAE || _Icode.ic.ll.opcode == iJA)
|
if (ll->opcode == iJAE || ll->opcode == iJA)
|
||||||
pstate->JCond.regi = prev.ic.ll.dst.regi;
|
pstate->JCond.regi = prev.ll()->dst.regi;
|
||||||
fBranch = (boolT)
|
fBranch = (boolT)
|
||||||
(_Icode.ic.ll.opcode == iJB || _Icode.ic.ll.opcode == iJBE);
|
(ll->opcode == iJB || ll->opcode == iJBE);
|
||||||
}
|
}
|
||||||
StCopy = *pstate;
|
StCopy = *pstate;
|
||||||
//memcpy(&StCopy, pstate, sizeof(STATE));
|
//memcpy(&StCopy, pstate, sizeof(STATE));
|
||||||
@ -264,7 +264,7 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
|
|||||||
|
|
||||||
if (fBranch) /* Do branching code */
|
if (fBranch) /* Do branching code */
|
||||||
{
|
{
|
||||||
pstate->JCond.regi = prev.ic.ll.dst.regi;
|
pstate->JCond.regi = prev.ll()->dst.regi;
|
||||||
}
|
}
|
||||||
/* Next icode. Note: not the same as GetLastIcode() because of the call
|
/* Next icode. Note: not the same as GetLastIcode() because of the call
|
||||||
to FollowCtrl() */
|
to FollowCtrl() */
|
||||||
@ -286,7 +286,7 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
|
|||||||
/*** Returns ***/
|
/*** Returns ***/
|
||||||
case iRET:
|
case iRET:
|
||||||
case iRETF:
|
case iRETF:
|
||||||
this->flg |= (_Icode.ic.ll.opcode == iRET)? PROC_NEAR:PROC_FAR;
|
this->flg |= (ll->opcode == iRET)? PROC_NEAR:PROC_FAR;
|
||||||
/* Fall through */
|
/* Fall through */
|
||||||
case iIRET:
|
case iIRET:
|
||||||
this->flg &= ~TERMINATES;
|
this->flg &= ~TERMINATES;
|
||||||
@ -294,14 +294,14 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case iINT:
|
case iINT:
|
||||||
if (_Icode.ic.ll.src.op() == 0x21 && pstate->f[rAH])
|
if (ll->src.op() == 0x21 && pstate->f[rAH])
|
||||||
{
|
{
|
||||||
int funcNum = pstate->r[rAH];
|
int funcNum = pstate->r[rAH];
|
||||||
int operand;
|
int operand;
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
/* Save function number */
|
/* Save function number */
|
||||||
Icode.back().ic.ll.dst.off = (int16_t)funcNum;
|
Icode.back().ll()->dst.off = (int16_t)funcNum;
|
||||||
//Icode.GetIcode(Icode.GetNumIcodes() - 1)->
|
//Icode.GetIcode(Icode.GetNumIcodes() - 1)->
|
||||||
|
|
||||||
/* Program termination: int21h, fn 00h, 31h, 4Ch */
|
/* Program termination: int21h, fn 00h, 31h, 4Ch */
|
||||||
@ -320,19 +320,19 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
|
|||||||
updateSymType (operand, TYPE_STR, size);
|
updateSymType (operand, TYPE_STR, size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ((_Icode.ic.ll.src.op() == 0x2F) && (pstate->f[rAH]))
|
else if ((ll->src.op() == 0x2F) && (pstate->f[rAH]))
|
||||||
{
|
{
|
||||||
Icode.back().ic.ll.dst.off = pstate->r[rAH];
|
Icode.back().ll()->dst.off = pstate->r[rAH];
|
||||||
}
|
}
|
||||||
else /* Program termination: int20h, int27h */
|
else /* Program termination: int20h, int27h */
|
||||||
done = (boolT)(_Icode.ic.ll.src.op() == 0x20 ||
|
done = (boolT)(ll->src.op() == 0x20 ||
|
||||||
_Icode.ic.ll.src.op() == 0x27);
|
ll->src.op() == 0x27);
|
||||||
if (done)
|
if (done)
|
||||||
pIcode->ic.ll.flg |= TERMINATES;
|
pIcode->ll()->SetLlFlag(TERMINATES);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case iMOV:
|
case iMOV:
|
||||||
process_MOV(*pIcode, pstate);
|
process_MOV(*pIcode->ll(), pstate);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* case iXCHG:
|
/* case iXCHG:
|
||||||
@ -341,25 +341,25 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
|
|||||||
break; **** HERE ***/
|
break; **** HERE ***/
|
||||||
|
|
||||||
case iSHL:
|
case iSHL:
|
||||||
if (pstate->JCond.regi == _Icode.ic.ll.dst.regi)
|
if (pstate->JCond.regi == ll->dst.regi)
|
||||||
if ((_Icode.ic.ll.flg & I) && _Icode.ic.ll.src.op() == 1)
|
if ((ll->isLlFlag(I)) && ll->src.op() == 1)
|
||||||
pstate->JCond.immed *= 2;
|
pstate->JCond.immed *= 2;
|
||||||
else
|
else
|
||||||
pstate->JCond.regi = 0;
|
pstate->JCond.regi = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case iLEA:
|
case iLEA:
|
||||||
if (_Icode.ic.ll.src.regi == 0) /* direct mem offset */
|
if (ll->src.regi == 0) /* direct mem offset */
|
||||||
pstate->setState( _Icode.ic.ll.dst.regi, _Icode.ic.ll.src.off);
|
pstate->setState( ll->dst.regi, ll->src.off);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case iLDS: case iLES:
|
case iLDS: case iLES:
|
||||||
if ((psym = lookupAddr(&_Icode.ic.ll.src, pstate, 4, eDuVal::USE))
|
if ((psym = lookupAddr(&ll->src, pstate, 4, eDuVal::USE))
|
||||||
/* && (Icode.ic.ll.flg & SEG_IMMED) */ ) {
|
/* && (Icode.ll()->flg & SEG_IMMED) */ ) {
|
||||||
offset = LH(&prog.Image[psym->label]);
|
offset = LH(&prog.Image[psym->label]);
|
||||||
pstate->setState( (_Icode.ic.ll.opcode == iLDS)? rDS: rES,
|
pstate->setState( (ll->opcode == iLDS)? rDS: rES,
|
||||||
LH(&prog.Image[psym->label + 2]));
|
LH(&prog.Image[psym->label + 2]));
|
||||||
pstate->setState( _Icode.ic.ll.dst.regi, (int16_t)offset);
|
pstate->setState( ll->dst.regi, (int16_t)offset);
|
||||||
psym->type = TYPE_PTR;
|
psym->type = TYPE_PTR;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -371,13 +371,13 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
|
|||||||
|
|
||||||
if (err == INVALID_386OP || err == INVALID_OPCODE)
|
if (err == INVALID_386OP || err == INVALID_OPCODE)
|
||||||
{
|
{
|
||||||
fatalError(err, prog.Image[_Icode.ic.ll.label], _Icode.ic.ll.label);
|
fatalError(err, prog.Image[_Icode.ll()->label], _Icode.ll()->label);
|
||||||
this->flg |= PROC_BADINST;
|
this->flg |= PROC_BADINST;
|
||||||
}
|
}
|
||||||
else if (err == IP_OUT_OF_RANGE)
|
else if (err == IP_OUT_OF_RANGE)
|
||||||
fatalError (err, _Icode.ic.ll.label);
|
fatalError (err, _Icode.ll()->label);
|
||||||
else
|
else
|
||||||
reportError(err, _Icode.ic.ll.label);
|
reportError(err, _Icode.ll()->label);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -391,11 +391,11 @@ boolT Function::process_JMP (ICODE & pIcode, STATE *pstate, CALL_GRAPH * pcallGr
|
|||||||
uint32_t i, k, seg, target;
|
uint32_t i, k, seg, target;
|
||||||
uint32_t tmp;
|
uint32_t tmp;
|
||||||
|
|
||||||
if (pIcode.ic.ll.flg & I)
|
if (pIcode.ll()->isLlFlag(I))
|
||||||
{
|
{
|
||||||
if (pIcode.ic.ll.opcode == iJMPF)
|
if (pIcode.ll()->opcode == iJMPF)
|
||||||
pstate->setState( rCS, LH(prog.Image + pIcode.ic.ll.label + 3));
|
pstate->setState( rCS, LH(prog.Image + pIcode.ll()->label + 3));
|
||||||
i = pstate->IP = pIcode.ic.ll.src.op();
|
i = pstate->IP = pIcode.ll()->src.op();
|
||||||
if ((long)i < 0)
|
if ((long)i < 0)
|
||||||
{
|
{
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -407,17 +407,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
|
/* We've got an indirect JMP - look for switch() stmt. idiom of the form
|
||||||
* JMP uint16_t ptr word_offset[rBX | rSI | rDI] */
|
* JMP uint16_t ptr word_offset[rBX | rSI | rDI] */
|
||||||
seg = (pIcode.ic.ll.src.seg)? pIcode.ic.ll.src.seg: rDS;
|
seg = (pIcode.ll()->src.seg)? pIcode.ll()->src.seg: rDS;
|
||||||
|
|
||||||
/* Ensure we have a uint16_t offset & valid seg */
|
/* Ensure we have a uint16_t offset & valid seg */
|
||||||
if (pIcode.ic.ll.opcode == iJMP && (pIcode.ic.ll.flg & WORD_OFF) &&
|
if (pIcode.ll()->match(iJMP) and (pIcode.ll()->isLlFlag(WORD_OFF)) &&
|
||||||
pstate->f[seg] &&
|
pstate->f[seg] &&
|
||||||
(pIcode.ic.ll.src.regi == INDEXBASE + 4 ||
|
(pIcode.ll()->src.regi == INDEXBASE + 4 ||
|
||||||
pIcode.ic.ll.src.regi == INDEXBASE + 5 || /* Idx reg. BX, SI, DI */
|
pIcode.ll()->src.regi == INDEXBASE + 5 || /* Idx reg. BX, SI, DI */
|
||||||
pIcode.ic.ll.src.regi == INDEXBASE + 7))
|
pIcode.ll()->src.regi == INDEXBASE + 7))
|
||||||
{
|
{
|
||||||
|
|
||||||
offTable = ((uint32_t)(uint16_t)pstate->r[seg] << 4) + pIcode.ic.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:-
|
/* Firstly look for a leading range check of the form:-
|
||||||
* CMP {BX | SI | DI}, immed
|
* CMP {BX | SI | DI}, immed
|
||||||
@ -425,7 +425,7 @@ boolT Function::process_JMP (ICODE & pIcode, STATE *pstate, CALL_GRAPH * pcallGr
|
|||||||
* This is stored in the current state as if we had just
|
* This is stored in the current state as if we had just
|
||||||
* followed a JBE branch (i.e. [reg] lies between 0 - immed).
|
* followed a JBE branch (i.e. [reg] lies between 0 - immed).
|
||||||
*/
|
*/
|
||||||
if (pstate->JCond.regi == i2r[pIcode.ic.ll.src.regi-(INDEXBASE+4)])
|
if (pstate->JCond.regi == i2r[pIcode.ll()->src.regi-(INDEXBASE+4)])
|
||||||
endTable = offTable + pstate->JCond.immed;
|
endTable = offTable + pstate->JCond.immed;
|
||||||
else
|
else
|
||||||
endTable = (uint32_t)prog.cbImage;
|
endTable = (uint32_t)prog.cbImage;
|
||||||
@ -468,10 +468,10 @@ boolT Function::process_JMP (ICODE & pIcode, STATE *pstate, CALL_GRAPH * pcallGr
|
|||||||
|
|
||||||
setBits(BM_DATA, offTable, endTable - offTable);
|
setBits(BM_DATA, offTable, endTable - offTable);
|
||||||
|
|
||||||
pIcode.ic.ll.flg |= SWITCH;
|
pIcode.ll()->SetLlFlag(SWITCH);
|
||||||
pIcode.ic.ll.caseTbl.numEntries = (endTable - offTable) / 2;
|
pIcode.ll()->caseTbl.numEntries = (endTable - offTable) / 2;
|
||||||
psw = (uint32_t*)allocMem(pIcode.ic.ll.caseTbl.numEntries*sizeof(uint32_t));
|
psw = (uint32_t*)allocMem(pIcode.ll()->caseTbl.numEntries*sizeof(uint32_t));
|
||||||
pIcode.ic.ll.caseTbl.entries = psw;
|
pIcode.ll()->caseTbl.entries = psw;
|
||||||
|
|
||||||
for (i = offTable, k = 0; i < endTable; i += 2)
|
for (i = offTable, k = 0; i < endTable; i += 2)
|
||||||
{
|
{
|
||||||
@ -482,9 +482,9 @@ boolT Function::process_JMP (ICODE & pIcode, STATE *pstate, CALL_GRAPH * pcallGr
|
|||||||
|
|
||||||
FollowCtrl (pcallGraph, &StCopy);
|
FollowCtrl (pcallGraph, &StCopy);
|
||||||
++last_current_insn;
|
++last_current_insn;
|
||||||
last_current_insn->ic.ll.caseTbl.numEntries = k++;
|
last_current_insn->ll()->caseTbl.numEntries = k++;
|
||||||
last_current_insn->ic.ll.flg |= CASE;
|
last_current_insn->ll()->SetLlFlag(CASE);
|
||||||
*psw++ = last_current_insn->GetLlLabel();
|
*psw++ = last_current_insn->ll()->GetLlLabel();
|
||||||
|
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -518,12 +518,12 @@ boolT Function::process_CALL (ICODE & pIcode, CALL_GRAPH * pcallGraph, STATE *ps
|
|||||||
|
|
||||||
/* For Indirect Calls, find the function address */
|
/* For Indirect Calls, find the function address */
|
||||||
indirect = FALSE;
|
indirect = FALSE;
|
||||||
//pIcode.ic.ll.immed.proc.proc=fakeproc;
|
//pIcode.ll()->immed.proc.proc=fakeproc;
|
||||||
if ( not pIcode.isLlFlag(I) )
|
if ( not pIcode.ll()->isLlFlag(I) )
|
||||||
{
|
{
|
||||||
/* Not immediate, i.e. indirect call */
|
/* Not immediate, i.e. indirect call */
|
||||||
|
|
||||||
if (pIcode.ic.ll.dst.regi && (!option.Calls))
|
if (pIcode.ll()->dst.regi && (!option.Calls))
|
||||||
{
|
{
|
||||||
/* We have not set the brave option to attempt to follow
|
/* We have not set the brave option to attempt to follow
|
||||||
the execution path through register indirect calls.
|
the execution path through register indirect calls.
|
||||||
@ -539,28 +539,28 @@ boolT Function::process_CALL (ICODE & pIcode, CALL_GRAPH * pcallGraph, STATE *ps
|
|||||||
usually wrong! Consider also CALL [BP+0E] in which the
|
usually wrong! Consider also CALL [BP+0E] in which the
|
||||||
segment for the pointer is in SS! - Mike */
|
segment for the pointer is in SS! - Mike */
|
||||||
|
|
||||||
off = (uint32_t)(uint16_t)pIcode.ic.ll.dst.off +
|
off = (uint32_t)(uint16_t)pIcode.ll()->dst.off +
|
||||||
((uint32_t)(uint16_t)pIcode.ic.ll.dst.segValue << 4);
|
((uint32_t)(uint16_t)pIcode.ll()->dst.segValue << 4);
|
||||||
|
|
||||||
/* Address of function is given by 4 (CALLF) or 2 (CALL) bytes at
|
/* Address of function is given by 4 (CALLF) or 2 (CALL) bytes at
|
||||||
* previous offset into the program image */
|
* previous offset into the program image */
|
||||||
uint32_t tgtAddr=0;
|
uint32_t tgtAddr=0;
|
||||||
if (pIcode.ic.ll.opcode == iCALLF)
|
if (pIcode.ll()->opcode == iCALLF)
|
||||||
tgtAddr= LH(&prog.Image[off]) + (uint32_t)(LH(&prog.Image[off+2])) << 4;
|
tgtAddr= LH(&prog.Image[off]) + (uint32_t)(LH(&prog.Image[off+2])) << 4;
|
||||||
else
|
else
|
||||||
tgtAddr= LH(&prog.Image[off]) + (uint32_t)(uint16_t)state.r[rCS] << 4;
|
tgtAddr= LH(&prog.Image[off]) + (uint32_t)(uint16_t)state.r[rCS] << 4;
|
||||||
pIcode.ic.ll.src.SetImmediateOp( tgtAddr );
|
pIcode.ll()->src.SetImmediateOp( tgtAddr );
|
||||||
pIcode.ic.ll.flg |= I;
|
pIcode.ll()->SetLlFlag(I);
|
||||||
indirect = TRUE;
|
indirect = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Process CALL. Function address is located in pIcode.ic.ll.immed.op */
|
/* Process CALL. Function address is located in pIcode.ll()->immed.op */
|
||||||
if (pIcode.ic.ll.flg & I)
|
if (pIcode.ll()->isLlFlag(I))
|
||||||
{
|
{
|
||||||
/* Search procedure list for one with appropriate entry point */
|
/* Search procedure list for one with appropriate entry point */
|
||||||
ilFunction iter= std::find_if(pProcList.begin(),pProcList.end(),
|
ilFunction iter= std::find_if(pProcList.begin(),pProcList.end(),
|
||||||
[pIcode](const Function &f) ->
|
[pIcode](const Function &f) ->
|
||||||
bool { return f.procEntry==pIcode.ic.ll.src.op(); });
|
bool { return f.procEntry==pIcode.ll()->src.op(); });
|
||||||
|
|
||||||
/* Create a new procedure node and save copy of the state */
|
/* Create a new procedure node and save copy of the state */
|
||||||
if (iter==pProcList.end())
|
if (iter==pProcList.end())
|
||||||
@ -568,7 +568,7 @@ boolT Function::process_CALL (ICODE & pIcode, CALL_GRAPH * pcallGraph, STATE *ps
|
|||||||
pProcList.push_back(Function::Create());
|
pProcList.push_back(Function::Create());
|
||||||
Function &x(pProcList.back());
|
Function &x(pProcList.back());
|
||||||
iter = (++pProcList.rbegin()).base();
|
iter = (++pProcList.rbegin()).base();
|
||||||
x.procEntry = pIcode.ic.ll.src.op();
|
x.procEntry = pIcode.ll()->src.op();
|
||||||
LibCheck(x);
|
LibCheck(x);
|
||||||
|
|
||||||
if (x.flg & PROC_ISLIB)
|
if (x.flg & PROC_ISLIB)
|
||||||
@ -576,7 +576,7 @@ boolT Function::process_CALL (ICODE & pIcode, CALL_GRAPH * pcallGraph, STATE *ps
|
|||||||
/* A library function. No need to do any more to it */
|
/* A library function. No need to do any more to it */
|
||||||
pcallGraph->insertCallGraph (this, iter);
|
pcallGraph->insertCallGraph (this, iter);
|
||||||
iter = (++pProcList.rbegin()).base();
|
iter = (++pProcList.rbegin()).base();
|
||||||
last_insn.ic.ll.src.proc.proc = &x;
|
last_insn.ll()->src.proc.proc = &x;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -594,9 +594,9 @@ boolT Function::process_CALL (ICODE & pIcode, CALL_GRAPH * pcallGraph, STATE *ps
|
|||||||
|
|
||||||
/* Save machine state in localState, load up IP and CS.*/
|
/* Save machine state in localState, load up IP and CS.*/
|
||||||
localState = *pstate;
|
localState = *pstate;
|
||||||
pstate->IP = pIcode.ic.ll.src.op();
|
pstate->IP = pIcode.ll()->src.op();
|
||||||
if (pIcode.ic.ll.opcode == iCALLF)
|
if (pIcode.ll()->opcode == iCALLF)
|
||||||
pstate->setState( rCS, LH(prog.Image + pIcode.ic.ll.label + 3));
|
pstate->setState( rCS, LH(prog.Image + pIcode.ll()->label + 3));
|
||||||
x.state = *pstate;
|
x.state = *pstate;
|
||||||
|
|
||||||
/* Insert new procedure in call graph */
|
/* Insert new procedure in call graph */
|
||||||
@ -616,7 +616,7 @@ boolT Function::process_CALL (ICODE & pIcode, CALL_GRAPH * pcallGraph, STATE *ps
|
|||||||
else
|
else
|
||||||
pcallGraph->insertCallGraph (this, iter);
|
pcallGraph->insertCallGraph (this, iter);
|
||||||
|
|
||||||
last_insn.ic.ll.src.proc.proc = &(*iter); // ^ target proc
|
last_insn.ll()->src.proc.proc = &(*iter); // ^ target proc
|
||||||
|
|
||||||
/* return ((p->flg & TERMINATES) != 0); */
|
/* return ((p->flg & TERMINATES) != 0); */
|
||||||
}
|
}
|
||||||
@ -625,19 +625,18 @@ boolT Function::process_CALL (ICODE & pIcode, CALL_GRAPH * pcallGraph, STATE *ps
|
|||||||
|
|
||||||
|
|
||||||
/* process_MOV - Handles state changes due to simple assignments */
|
/* process_MOV - Handles state changes due to simple assignments */
|
||||||
static void process_MOV(ICODE & pIcode, STATE * pstate)
|
static void process_MOV(LLInst & ll, STATE * pstate)
|
||||||
{
|
{
|
||||||
SYM * psym, *psym2; /* Pointer to symbol in global symbol table */
|
SYM * psym, *psym2; /* Pointer to symbol in global symbol table */
|
||||||
uint8_t dstReg = pIcode.ic.ll.dst.regi;
|
uint8_t dstReg = ll.dst.regi;
|
||||||
uint8_t srcReg = pIcode.ic.ll.src.regi;
|
uint8_t srcReg = ll.src.regi;
|
||||||
|
|
||||||
if (dstReg > 0 && dstReg < INDEXBASE)
|
if (dstReg > 0 && dstReg < INDEXBASE)
|
||||||
{
|
{
|
||||||
if (pIcode.ic.ll.flg & I)
|
if (ll.isLlFlag(I))
|
||||||
pstate->setState( dstReg, (int16_t)pIcode.ic.ll.src.op());
|
pstate->setState( dstReg, (int16_t)ll.src.op());
|
||||||
else if (srcReg == 0) /* direct memory offset */
|
else if (srcReg == 0) /* direct memory offset */
|
||||||
{
|
{
|
||||||
psym = lookupAddr(&pIcode.ic.ll.src, pstate, 2, eDuVal::USE);
|
psym = lookupAddr(&ll.src, pstate, 2, eDuVal::USE);
|
||||||
if (psym && ((psym->flg & SEG_IMMED) || psym->duVal.val))
|
if (psym && ((psym->flg & SEG_IMMED) || psym->duVal.val))
|
||||||
pstate->setState( dstReg, LH(&prog.Image[psym->label]));
|
pstate->setState( dstReg, LH(&prog.Image[psym->label]));
|
||||||
}
|
}
|
||||||
@ -652,20 +651,20 @@ static void process_MOV(ICODE & pIcode, STATE * pstate)
|
|||||||
}
|
}
|
||||||
else if (dstReg == 0) { /* direct memory offset */
|
else if (dstReg == 0) { /* direct memory offset */
|
||||||
int size=2;
|
int size=2;
|
||||||
if((pIcode.ic.ll.src.regi>=rAL)&&(pIcode.ic.ll.src.regi<=rBH))
|
if((ll.src.regi>=rAL)&&(ll.src.regi<=rBH))
|
||||||
size=1;
|
size=1;
|
||||||
psym = lookupAddr (&pIcode.ic.ll.dst, pstate, size, eDEF);
|
psym = lookupAddr (&ll.dst, pstate, size, eDEF);
|
||||||
if (psym && ! (psym->duVal.val)) /* no initial value yet */
|
if (psym && ! (psym->duVal.val)) /* no initial value yet */
|
||||||
if (pIcode.ic.ll.flg & I) /* immediate */
|
if (ll.isLlFlag(I)) /* immediate */
|
||||||
{
|
{
|
||||||
prog.Image[psym->label] = (uint8_t)pIcode.ic.ll.src.op();
|
prog.Image[psym->label] = (uint8_t)ll.src.op();
|
||||||
if(psym->size>1)
|
if(psym->size>1)
|
||||||
prog.Image[psym->label+1] = (uint8_t)(pIcode.ic.ll.src.op()>>8);
|
prog.Image[psym->label+1] = (uint8_t)(ll.src.op()>>8);
|
||||||
psym->duVal.val = 1;
|
psym->duVal.val = 1;
|
||||||
}
|
}
|
||||||
else if (srcReg == 0) /* direct mem offset */
|
else if (srcReg == 0) /* direct mem offset */
|
||||||
{
|
{
|
||||||
psym2 = lookupAddr (&pIcode.ic.ll.src, pstate, 2, eDuVal::USE);
|
psym2 = lookupAddr (&ll.src, pstate, 2, eDuVal::USE);
|
||||||
if (psym2 && ((psym->flg & SEG_IMMED) || (psym->duVal.val)))
|
if (psym2 && ((psym->flg & SEG_IMMED) || (psym->duVal.val)))
|
||||||
{
|
{
|
||||||
prog.Image[psym->label] = (uint8_t)prog.Image[psym2->label];
|
prog.Image[psym->label] = (uint8_t)prog.Image[psym2->label];
|
||||||
@ -902,7 +901,7 @@ std::bitset<32> duReg[] = { 0x00,
|
|||||||
* ix : current index into icode array */
|
* ix : current index into icode array */
|
||||||
static void use (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int size, int ix)
|
static void use (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int size, int ix)
|
||||||
{
|
{
|
||||||
LLOperand * pm = (d == SRC)? &pIcode.ic.ll.src: &pIcode.ic.ll.dst;
|
LLOperand * pm = (d == SRC)? &pIcode.ll()->src: &pIcode.ll()->dst;
|
||||||
SYM * psym;
|
SYM * psym;
|
||||||
|
|
||||||
if (pm->regi == 0 || pm->regi >= INDEXBASE)
|
if (pm->regi == 0 || pm->regi >= INDEXBASE)
|
||||||
@ -932,13 +931,13 @@ static void use (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int
|
|||||||
else if (psym = lookupAddr(pm, pstate, size, eDuVal::USE))
|
else if (psym = lookupAddr(pm, pstate, size, eDuVal::USE))
|
||||||
{
|
{
|
||||||
setBits (BM_DATA, psym->label, (uint32_t)size);
|
setBits (BM_DATA, psym->label, (uint32_t)size);
|
||||||
pIcode.ic.ll.flg |= SYM_USE;
|
pIcode.ll()->SetLlFlag(SYM_USE);
|
||||||
pIcode.ic.ll.caseTbl.numEntries = psym - &symtab[0];
|
pIcode.ll()->caseTbl.numEntries = psym - &symtab[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Use of register */
|
/* Use of register */
|
||||||
else if ((d == DST) || ((d == SRC) && (pIcode.ic.ll.flg & I) != I))
|
else if ((d == DST) || ((d == SRC) && (not pIcode.ll()->isLlFlag(I))))
|
||||||
pIcode.du.use |= duReg[pm->regi];
|
pIcode.du.use |= duReg[pm->regi];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -949,7 +948,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,
|
static void def (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int size,
|
||||||
int ix)
|
int ix)
|
||||||
{
|
{
|
||||||
LLOperand *pm = (d == SRC)? &pIcode.ic.ll.src: &pIcode.ic.ll.dst;
|
LLOperand *pm = (d == SRC)? &pIcode.ll()->src: &pIcode.ll()->dst;
|
||||||
SYM * psym;
|
SYM * psym;
|
||||||
|
|
||||||
if (pm->regi == 0 || pm->regi >= INDEXBASE)
|
if (pm->regi == 0 || pm->regi >= INDEXBASE)
|
||||||
@ -981,13 +980,13 @@ static void def (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int
|
|||||||
else if (psym = lookupAddr(pm, pstate, size, eDEF))
|
else if (psym = lookupAddr(pm, pstate, size, eDEF))
|
||||||
{
|
{
|
||||||
setBits(BM_DATA, psym->label, (uint32_t)size);
|
setBits(BM_DATA, psym->label, (uint32_t)size);
|
||||||
pIcode.ic.ll.flg |= SYM_DEF;
|
pIcode.ll()->SetLlFlag(SYM_DEF);
|
||||||
pIcode.ic.ll.caseTbl.numEntries = psym - &symtab[0];
|
pIcode.ll()->caseTbl.numEntries = psym - &symtab[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Definition of register */
|
/* Definition of register */
|
||||||
else if ((d == DST) || ((d == SRC) && (pIcode.ic.ll.flg & I) != I))
|
else if ((d == DST) || ((d == SRC) && (not pIcode.ll()->isLlFlag(I))))
|
||||||
{
|
{
|
||||||
pIcode.du.def |= duReg[pm->regi];
|
pIcode.du.def |= duReg[pm->regi];
|
||||||
pIcode.du1.numRegsDef++;
|
pIcode.du1.numRegsDef++;
|
||||||
@ -1001,7 +1000,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,
|
static void use_def(opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int cb,
|
||||||
int ix)
|
int ix)
|
||||||
{
|
{
|
||||||
LLOperand * pm = (d == SRC)? &pIcode.ic.ll.src: &pIcode.ic.ll.dst;
|
LLOperand * pm = (d == SRC)? &pIcode.ll()->src: &pIcode.ll()->dst;
|
||||||
|
|
||||||
use (d, pIcode, pProc, pstate, cb, ix);
|
use (d, pIcode, pProc, pstate, cb, ix);
|
||||||
|
|
||||||
@ -1019,11 +1018,11 @@ void Function::process_operands(ICODE & pIcode, STATE * pstate)
|
|||||||
{
|
{
|
||||||
int ix=Icode.size();
|
int ix=Icode.size();
|
||||||
int i;
|
int i;
|
||||||
int sseg = (pIcode.ic.ll.src.seg)? pIcode.ic.ll.src.seg: rDS;
|
int sseg = (pIcode.ll()->src.seg)? pIcode.ll()->src.seg: rDS;
|
||||||
int cb = (pIcode.ic.ll.flg & B) ? 1: 2;
|
int cb = pIcode.ll()->isLlFlag(B) ? 1: 2;
|
||||||
uint32_t Imm = (pIcode.ic.ll.flg & I);
|
uint32_t Imm = (pIcode.ll()->isLlFlag(I));
|
||||||
|
|
||||||
switch (pIcode.ic.ll.opcode) {
|
switch (pIcode.ll()->opcode) {
|
||||||
case iAND: case iOR: case iXOR:
|
case iAND: case iOR: case iXOR:
|
||||||
case iSAR: case iSHL: case iSHR:
|
case iSAR: case iSHL: case iSHR:
|
||||||
case iRCL: case iRCR: case iROL: case iROR:
|
case iRCL: case iRCR: case iROL: case iROR:
|
||||||
@ -1078,7 +1077,7 @@ void Function::process_operands(ICODE & pIcode, STATE * pstate)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case iSIGNEX:
|
case iSIGNEX:
|
||||||
cb = (pIcode.ic.ll.flg & SRC_B) ? 1 : 2;
|
cb = pIcode.ll()->isLlFlag(SRC_B) ? 1 : 2;
|
||||||
if (cb == 1) /* uint8_t */
|
if (cb == 1) /* uint8_t */
|
||||||
{
|
{
|
||||||
pIcode.du.def |= duReg[rAX];
|
pIcode.du.def |= duReg[rAX];
|
||||||
@ -1097,7 +1096,7 @@ void Function::process_operands(ICODE & pIcode, STATE * pstate)
|
|||||||
cb = 4;
|
cb = 4;
|
||||||
case iCALL: case iPUSH: case iPOP:
|
case iCALL: case iPUSH: case iPOP:
|
||||||
if (! Imm) {
|
if (! Imm) {
|
||||||
if (pIcode.ic.ll.opcode == iPOP)
|
if (pIcode.ll()->opcode == iPOP)
|
||||||
def(DST, pIcode, this, pstate, cb, ix);
|
def(DST, pIcode, this, pstate, cb, ix);
|
||||||
else
|
else
|
||||||
use(DST, pIcode, this, pstate, cb, ix);
|
use(DST, pIcode, this, pstate, cb, ix);
|
||||||
@ -1109,7 +1108,7 @@ void Function::process_operands(ICODE & pIcode, STATE * pstate)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case iLDS: case iLES:
|
case iLDS: case iLES:
|
||||||
pIcode.du.def |= duReg[(pIcode.ic.ll.opcode == iLDS) ? rDS : rES];
|
pIcode.du.def |= duReg[(pIcode.ll()->opcode == iLDS) ? rDS : rES];
|
||||||
pIcode.du1.numRegsDef++;
|
pIcode.du1.numRegsDef++;
|
||||||
cb = 4;
|
cb = 4;
|
||||||
case iMOV:
|
case iMOV:
|
||||||
@ -1158,7 +1157,7 @@ void Function::process_operands(ICODE & pIcode, STATE * pstate)
|
|||||||
case iSCAS: case iSTOS: case iINS:
|
case iSCAS: case iSTOS: case iINS:
|
||||||
pIcode.du.def |= duReg[rDI];
|
pIcode.du.def |= duReg[rDI];
|
||||||
pIcode.du1.numRegsDef++;
|
pIcode.du1.numRegsDef++;
|
||||||
if (pIcode.ic.ll.opcode == iREP_INS || pIcode.ic.ll.opcode== iINS)
|
if (pIcode.ll()->opcode == iREP_INS || pIcode.ll()->opcode== iINS)
|
||||||
{
|
{
|
||||||
pIcode.du.use |= duReg[rDI] | duReg[rES] | duReg[rDX];
|
pIcode.du.use |= duReg[rDI] | duReg[rES] | duReg[rDX];
|
||||||
}
|
}
|
||||||
@ -1198,7 +1197,7 @@ void Function::process_operands(ICODE & pIcode, STATE * pstate)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (i = rSP; i <= rBH; i++) /* Kill all defined registers */
|
for (i = rSP; i <= rBH; i++) /* Kill all defined registers */
|
||||||
if (pIcode.ic.ll.flagDU.d & (1 << i))
|
if (pIcode.ll()->flagDU.d & (1 << i))
|
||||||
pstate->f[i] = FALSE;
|
pstate->f[i] = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -106,13 +106,13 @@ void Function::newRegArg(iICODE picode, iICODE ticode)
|
|||||||
uint8_t regL, regH; /* Registers involved in arguments */
|
uint8_t regL, regH; /* Registers involved in arguments */
|
||||||
|
|
||||||
/* Flag ticode as having register arguments */
|
/* Flag ticode as having register arguments */
|
||||||
tproc = ticode->ic.hl.call.proc;
|
tproc = ticode->hl()->call.proc;
|
||||||
tproc->flg |= REG_ARGS;
|
tproc->flg |= REG_ARGS;
|
||||||
|
|
||||||
/* Get registers and index into target procedure's local list */
|
/* Get registers and index into target procedure's local list */
|
||||||
ps = ticode->ic.hl.call.args;
|
ps = ticode->hl()->call.args;
|
||||||
ts = &tproc->args;
|
ts = &tproc->args;
|
||||||
lhs = picode->ic.hl.asgn.lhs;
|
lhs = picode->hl()->asgn.lhs;
|
||||||
type = lhs->expr.ident.idType;
|
type = lhs->expr.ident.idType;
|
||||||
if (type == REGISTER)
|
if (type == REGISTER)
|
||||||
{
|
{
|
||||||
@ -187,7 +187,7 @@ void Function::newRegArg(iICODE picode, iICODE ticode)
|
|||||||
/* Do ps (actual arguments) */
|
/* Do ps (actual arguments) */
|
||||||
STKSYM newsym;
|
STKSYM newsym;
|
||||||
sprintf (newsym.name, "arg%ld", ps->sym.size());
|
sprintf (newsym.name, "arg%ld", ps->sym.size());
|
||||||
newsym.actual = picode->ic.hl.asgn.rhs;
|
newsym.actual = picode->hl()->asgn.rhs;
|
||||||
newsym.regs = lhs;
|
newsym.regs = lhs;
|
||||||
/* Mask off high and low register(s) in picode */
|
/* Mask off high and low register(s) in picode */
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
|||||||
@ -35,7 +35,7 @@ static boolT isLong23 (iICODE iter, BB * pbb, int *off, int *arc)
|
|||||||
if ((t->size() == 1) && (t->nodeType == TWO_BRANCH) && (t->inEdges.size() == 1))
|
if ((t->size() == 1) && (t->nodeType == TWO_BRANCH) && (t->inEdges.size() == 1))
|
||||||
{
|
{
|
||||||
obb2 = t->edges[THEN].BBptr;
|
obb2 = t->edges[THEN].BBptr;
|
||||||
if ((obb2->size() == 2) && (obb2->nodeType == TWO_BRANCH) && (obb2->front().ic.ll.opcode == iCMP))
|
if ((obb2->size() == 2) && (obb2->nodeType == TWO_BRANCH) && (obb2->front().ll()->opcode == iCMP))
|
||||||
{
|
{
|
||||||
*off = std::distance(iter,obb2->begin2());
|
*off = std::distance(iter,obb2->begin2());
|
||||||
*arc = THEN;
|
*arc = THEN;
|
||||||
@ -47,7 +47,7 @@ static boolT isLong23 (iICODE iter, BB * pbb, int *off, int *arc)
|
|||||||
else if ((e->size() == 1) && (e->nodeType == TWO_BRANCH) && (e->inEdges.size() == 1))
|
else if ((e->size() == 1) && (e->nodeType == TWO_BRANCH) && (e->inEdges.size() == 1))
|
||||||
{
|
{
|
||||||
obb2 = e->edges[THEN].BBptr;
|
obb2 = e->edges[THEN].BBptr;
|
||||||
if ((obb2->size() == 2) && (obb2->nodeType == TWO_BRANCH) && (obb2->front().ic.ll.opcode == iCMP))
|
if ((obb2->size() == 2) && (obb2->nodeType == TWO_BRANCH) && (obb2->front().ll()->opcode == iCMP))
|
||||||
{
|
{
|
||||||
*off = std::distance(iter,obb2->begin2());//obb2->front().loc_ip - i;
|
*off = std::distance(iter,obb2->begin2());//obb2->front().loc_ip - i;
|
||||||
*arc = ELSE;
|
*arc = ELSE;
|
||||||
@ -65,9 +65,9 @@ static boolT isLong22 (iICODE pIcode, iICODE pEnd, int *off)
|
|||||||
return false;
|
return false;
|
||||||
// preincrement because pIcode is not checked here
|
// preincrement because pIcode is not checked here
|
||||||
iICODE icodes[] = { ++pIcode,++pIcode,++pIcode };
|
iICODE icodes[] = { ++pIcode,++pIcode,++pIcode };
|
||||||
if ( icodes[1]->ic.ll.match(iCMP) &&
|
if ( icodes[1]->ll()->match(iCMP) &&
|
||||||
(isJCond (icodes[0]->ic.ll.opcode)) &&
|
(isJCond (icodes[0]->ll()->opcode)) &&
|
||||||
(isJCond (icodes[2]->ic.ll.opcode)))
|
(isJCond (icodes[2]->ll()->opcode)))
|
||||||
{
|
{
|
||||||
*off = 2;
|
*off = 2;
|
||||||
return true;
|
return true;
|
||||||
@ -142,7 +142,7 @@ static int longJCond23 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode, int arc,
|
|||||||
advance(atOffset,off);
|
advance(atOffset,off);
|
||||||
advance(atOffset1,off+1);
|
advance(atOffset1,off+1);
|
||||||
/* Create new HLI_JCOND and condition */
|
/* Create new HLI_JCOND and condition */
|
||||||
lhs = COND_EXPR::boolOp (lhs, rhs, condOpJCond[atOffset1->ic.ll.opcode-iJB]);
|
lhs = COND_EXPR::boolOp (lhs, rhs, condOpJCond[atOffset1->ll()->opcode-iJB]);
|
||||||
next1->setJCond(lhs);
|
next1->setJCond(lhs);
|
||||||
next1->copyDU(*pIcode, eUSE, eUSE);
|
next1->copyDU(*pIcode, eUSE, eUSE);
|
||||||
next1->du.use |= atOffset->du.use;
|
next1->du.use |= atOffset->du.use;
|
||||||
@ -177,7 +177,7 @@ static int longJCond22 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode,iICODE pEn
|
|||||||
iICODE icodes[] = { pIcode++,pIcode++,pIcode++,pIcode++ };
|
iICODE icodes[] = { pIcode++,pIcode++,pIcode++,pIcode++ };
|
||||||
|
|
||||||
/* Form conditional expression */
|
/* Form conditional expression */
|
||||||
lhs = COND_EXPR::boolOp (lhs, rhs, condOpJCond[icodes[3]->ic.ll.opcode - iJB]);
|
lhs = COND_EXPR::boolOp (lhs, rhs, condOpJCond[icodes[3]->ll()->opcode - iJB]);
|
||||||
icodes[1]->setJCond(lhs);
|
icodes[1]->setJCond(lhs);
|
||||||
icodes[1]->copyDU (*icodes[0], eUSE, eUSE);
|
icodes[1]->copyDU (*icodes[0], eUSE, eUSE);
|
||||||
icodes[1]->du.use |= icodes[2]->du.use;
|
icodes[1]->du.use |= icodes[2]->du.use;
|
||||||
@ -198,7 +198,7 @@ static int longJCond22 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode,iICODE pEn
|
|||||||
assert(iter!=tbb->inEdges.end());
|
assert(iter!=tbb->inEdges.end());
|
||||||
tbb->inEdges.erase(iter);
|
tbb->inEdges.erase(iter);
|
||||||
|
|
||||||
if (icodes[3]->ic.ll.opcode != iJE)
|
if (icodes[3]->ll()->opcode != iJE)
|
||||||
tbb->inEdges.push_back(pbb); /* iJNE => replace arc */
|
tbb->inEdges.push_back(pbb); /* iJNE => replace arc */
|
||||||
|
|
||||||
/* Modify ELSE out edge of header basic block */
|
/* Modify ELSE out edge of header basic block */
|
||||||
@ -208,7 +208,7 @@ static int longJCond22 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode,iICODE pEn
|
|||||||
iter=std::find(tbb->inEdges.begin(),tbb->inEdges.end(),obb1);
|
iter=std::find(tbb->inEdges.begin(),tbb->inEdges.end(),obb1);
|
||||||
assert(iter!=tbb->inEdges.end());
|
assert(iter!=tbb->inEdges.end());
|
||||||
tbb->inEdges.erase(iter);
|
tbb->inEdges.erase(iter);
|
||||||
if (icodes[3]->ic.ll.opcode == iJE) /* replace */
|
if (icodes[3]->ll()->opcode == iJE) /* replace */
|
||||||
tbb->inEdges.push_back(pbb);
|
tbb->inEdges.push_back(pbb);
|
||||||
|
|
||||||
/* Update statistics */
|
/* Update statistics */
|
||||||
@ -246,9 +246,9 @@ void Function::propLongStk (int i, const ID &pLocId)
|
|||||||
break;
|
break;
|
||||||
if ((pIcode->type == HIGH_LEVEL) || (pIcode->invalid == TRUE))
|
if ((pIcode->type == HIGH_LEVEL) || (pIcode->invalid == TRUE))
|
||||||
continue;
|
continue;
|
||||||
if (pIcode->ic.ll.opcode == next1->ic.ll.opcode)
|
if (pIcode->ll()->opcode == next1->ll()->opcode)
|
||||||
{
|
{
|
||||||
switch (pIcode->ic.ll.opcode)
|
switch (pIcode->ll()->opcode)
|
||||||
{
|
{
|
||||||
case iMOV:
|
case iMOV:
|
||||||
if (checkLongEq (pLocId.id.longStkId, pIcode, i, this, asgn, 1) == TRUE)
|
if (checkLongEq (pLocId.id.longStkId, pIcode, i, this, asgn, 1) == TRUE)
|
||||||
@ -261,7 +261,7 @@ void Function::propLongStk (int i, const ID &pLocId)
|
|||||||
case iAND: case iOR: case iXOR:
|
case iAND: case iOR: case iXOR:
|
||||||
if (checkLongEq (pLocId.id.longStkId, pIcode, i, this, asgn, 1) == TRUE)
|
if (checkLongEq (pLocId.id.longStkId, pIcode, i, this, asgn, 1) == TRUE)
|
||||||
{
|
{
|
||||||
switch (pIcode->ic.ll.opcode)
|
switch (pIcode->ll()->opcode)
|
||||||
{
|
{
|
||||||
case iAND: asgn.rhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, AND); break;
|
case iAND: asgn.rhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, AND); break;
|
||||||
case iOR: asgn.rhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, OR); break;
|
case iOR: asgn.rhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, OR); break;
|
||||||
@ -283,7 +283,7 @@ void Function::propLongStk (int i, const ID &pLocId)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check long conditional (i.e. 2 CMPs and 3 branches */
|
/* Check long conditional (i.e. 2 CMPs and 3 branches */
|
||||||
else if ((pIcode->ic.ll.opcode == iCMP) && (isLong23 (pIcode, pIcode->inBB, &off, &arc)))
|
else if ((pIcode->ll()->opcode == iCMP) && (isLong23 (pIcode, pIcode->inBB, &off, &arc)))
|
||||||
{
|
{
|
||||||
if ( checkLongEq (pLocId.id.longStkId, pIcode, i, this, asgn, off) )
|
if ( checkLongEq (pLocId.id.longStkId, pIcode, i, this, asgn, off) )
|
||||||
{
|
{
|
||||||
@ -293,7 +293,7 @@ void Function::propLongStk (int i, const ID &pLocId)
|
|||||||
|
|
||||||
/* Check for long conditional equality or inequality. This requires
|
/* Check for long conditional equality or inequality. This requires
|
||||||
* 2 CMPs and 2 branches */
|
* 2 CMPs and 2 branches */
|
||||||
else if ((pIcode->ic.ll.opcode == iCMP) && isLong22 (pIcode, pEnd, &off))
|
else if ((pIcode->ll()->opcode == iCMP) && isLong22 (pIcode, pEnd, &off))
|
||||||
{
|
{
|
||||||
if ( checkLongEq (pLocId.id.longStkId, pIcode, i, this,asgn, off) )
|
if ( checkLongEq (pLocId.id.longStkId, pIcode, i, this,asgn, off) )
|
||||||
{
|
{
|
||||||
@ -318,14 +318,14 @@ int Function::findBackwarLongDefs(int loc_ident_idx, const ID &pLocId, iICODE be
|
|||||||
|
|
||||||
if ((icode.type == HIGH_LEVEL) || (icode.invalid == TRUE))
|
if ((icode.type == HIGH_LEVEL) || (icode.invalid == TRUE))
|
||||||
continue;
|
continue;
|
||||||
if (icode.ic.ll.opcode != next1.ic.ll.opcode)
|
if (icode.ll()->opcode != next1.ll()->opcode)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
switch (icode.ic.ll.opcode)
|
switch (icode.ll()->opcode)
|
||||||
{
|
{
|
||||||
case iMOV:
|
case iMOV:
|
||||||
pmH = &icode.ic.ll.dst;
|
pmH = &icode.ll()->dst;
|
||||||
pmL = &next1.ic.ll.dst;
|
pmL = &next1.ll()->dst;
|
||||||
if ((pLocId.id.longId.h == pmH->regi) && (pLocId.id.longId.l == pmL->regi))
|
if ((pLocId.id.longId.h == pmH->regi) && (pLocId.id.longId.l == pmL->regi))
|
||||||
{
|
{
|
||||||
localId.id_arr[loc_ident_idx].idx.push_back(pIcode);//idx-1//insert
|
localId.id_arr[loc_ident_idx].idx.push_back(pIcode);//idx-1//insert
|
||||||
@ -339,8 +339,8 @@ int Function::findBackwarLongDefs(int loc_ident_idx, const ID &pLocId, iICODE be
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case iPOP:
|
case iPOP:
|
||||||
pmH = &next1.ic.ll.dst;
|
pmH = &next1.ll()->dst;
|
||||||
pmL = &icode.ic.ll.dst;
|
pmL = &icode.ll()->dst;
|
||||||
if ((pLocId.id.longId.h == pmH->regi) && (pLocId.id.longId.l == pmL->regi))
|
if ((pLocId.id.longId.h == pmH->regi) && (pLocId.id.longId.l == pmL->regi))
|
||||||
{
|
{
|
||||||
asgn.lhs = COND_EXPR::idLongIdx (loc_ident_idx);
|
asgn.lhs = COND_EXPR::idLongIdx (loc_ident_idx);
|
||||||
@ -355,14 +355,14 @@ int Function::findBackwarLongDefs(int loc_ident_idx, const ID &pLocId, iICODE be
|
|||||||
// /**** others missing ***/
|
// /**** others missing ***/
|
||||||
|
|
||||||
case iAND: case iOR: case iXOR:
|
case iAND: case iOR: case iXOR:
|
||||||
pmL = &icode.ic.ll.dst;
|
pmL = &icode.ll()->dst;
|
||||||
pmH = &next1.ic.ll.dst;
|
pmH = &next1.ll()->dst;
|
||||||
if ((pLocId.id.longId.h == pmH->regi) && (pLocId.id.longId.l == pmL->regi))
|
if ((pLocId.id.longId.h == pmH->regi) && (pLocId.id.longId.l == pmL->regi))
|
||||||
{
|
{
|
||||||
asgn.lhs = COND_EXPR::idLongIdx (loc_ident_idx);
|
asgn.lhs = COND_EXPR::idLongIdx (loc_ident_idx);
|
||||||
asgn.rhs = COND_EXPR::idLong (&this->localId, SRC, pIcode, LOW_FIRST, pIcode/*idx*/, eUSE, 1);
|
asgn.rhs = COND_EXPR::idLong (&this->localId, SRC, pIcode, LOW_FIRST, pIcode/*idx*/, eUSE, 1);
|
||||||
icode.setRegDU( pmH->regi, USE_DEF);
|
icode.setRegDU( pmH->regi, USE_DEF);
|
||||||
switch (icode.ic.ll.opcode)
|
switch (icode.ll()->opcode)
|
||||||
{
|
{
|
||||||
case iAND: asgn.rhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, AND);
|
case iAND: asgn.rhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, AND);
|
||||||
break;
|
break;
|
||||||
@ -397,14 +397,14 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be
|
|||||||
if ((pIcode->type == HIGH_LEVEL) || (pIcode->invalid == TRUE))
|
if ((pIcode->type == HIGH_LEVEL) || (pIcode->invalid == TRUE))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (pIcode->ic.ll.opcode == next1->ic.ll.opcode)
|
if (pIcode->ll()->opcode == next1->ll()->opcode)
|
||||||
switch (pIcode->ic.ll.opcode)
|
switch (pIcode->ll()->opcode)
|
||||||
{
|
{
|
||||||
case iMOV:
|
case iMOV:
|
||||||
if ((pLocId.id.longId.h == pIcode->ic.ll.src.regi) &&
|
if ((pLocId.id.longId.h == pIcode->ll()->src.regi) &&
|
||||||
(pLocId.id.longId.l == next1->ic.ll.src.regi))
|
(pLocId.id.longId.l == next1->ll()->src.regi))
|
||||||
{
|
{
|
||||||
pIcode->setRegDU( next1->ic.ll.src.regi, eUSE);
|
pIcode->setRegDU( next1->ll()->src.regi, eUSE);
|
||||||
|
|
||||||
asgn.rhs = COND_EXPR::idLongIdx (loc_ident_idx);
|
asgn.rhs = COND_EXPR::idLongIdx (loc_ident_idx);
|
||||||
asgn.lhs = COND_EXPR::idLong (&this->localId, DST, pIcode,HIGH_FIRST, pIcode, eDEF, 1);
|
asgn.lhs = COND_EXPR::idLong (&this->localId, DST, pIcode,HIGH_FIRST, pIcode, eDEF, 1);
|
||||||
@ -416,11 +416,11 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case iPUSH:
|
case iPUSH:
|
||||||
if ((pLocId.id.longId.h == pIcode->ic.ll.src.regi) &&
|
if ((pLocId.id.longId.h == pIcode->ll()->src.regi) &&
|
||||||
(pLocId.id.longId.l == next1->ic.ll.src.regi))
|
(pLocId.id.longId.l == next1->ll()->src.regi))
|
||||||
{
|
{
|
||||||
asgn.rhs = COND_EXPR::idLongIdx (loc_ident_idx);
|
asgn.rhs = COND_EXPR::idLongIdx (loc_ident_idx);
|
||||||
pIcode->setRegDU( next1->ic.ll.src.regi, eUSE);
|
pIcode->setRegDU( next1->ll()->src.regi, eUSE);
|
||||||
pIcode->setUnary(HLI_PUSH, asgn.rhs);
|
pIcode->setUnary(HLI_PUSH, asgn.rhs);
|
||||||
next1->invalidate();
|
next1->invalidate();
|
||||||
}
|
}
|
||||||
@ -430,8 +430,8 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be
|
|||||||
/*** others missing ****/
|
/*** others missing ****/
|
||||||
|
|
||||||
case iAND: case iOR: case iXOR:
|
case iAND: case iOR: case iXOR:
|
||||||
pmL = &pIcode->ic.ll.dst;
|
pmL = &pIcode->ll()->dst;
|
||||||
pmH = &next1->ic.ll.dst;
|
pmH = &next1->ll()->dst;
|
||||||
if ((pLocId.id.longId.h == pmH->regi) &&
|
if ((pLocId.id.longId.h == pmH->regi) &&
|
||||||
(pLocId.id.longId.l == pmL->regi))
|
(pLocId.id.longId.l == pmL->regi))
|
||||||
{
|
{
|
||||||
@ -439,7 +439,7 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be
|
|||||||
pIcode->setRegDU( pmH->regi, USE_DEF);
|
pIcode->setRegDU( pmH->regi, USE_DEF);
|
||||||
asgn.rhs = COND_EXPR::idLong (&this->localId, SRC, pIcode,
|
asgn.rhs = COND_EXPR::idLong (&this->localId, SRC, pIcode,
|
||||||
LOW_FIRST, pIcode/*idx*/, eUSE, 1);
|
LOW_FIRST, pIcode/*idx*/, eUSE, 1);
|
||||||
switch (pIcode->ic.ll.opcode) {
|
switch (pIcode->ll()->opcode) {
|
||||||
case iAND: asgn.rhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, AND);
|
case iAND: asgn.rhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, AND);
|
||||||
break;
|
break;
|
||||||
case iOR: asgn.rhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, OR);
|
case iOR: asgn.rhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, OR);
|
||||||
@ -458,7 +458,7 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be
|
|||||||
} /* eos */
|
} /* eos */
|
||||||
|
|
||||||
/* Check long conditional (i.e. 2 CMPs and 3 branches */
|
/* Check long conditional (i.e. 2 CMPs and 3 branches */
|
||||||
else if ((pIcode->ic.ll.opcode == iCMP) && (isLong23 (pIcode, pIcode->inBB, &off, &arc)))
|
else if ((pIcode->ll()->opcode == iCMP) && (isLong23 (pIcode, pIcode->inBB, &off, &arc)))
|
||||||
{
|
{
|
||||||
if (checkLongRegEq (pLocId.id.longId, pIcode, loc_ident_idx, this, asgn.rhs, asgn.lhs, off) == TRUE)
|
if (checkLongRegEq (pLocId.id.longId, pIcode, loc_ident_idx, this, asgn.rhs, asgn.lhs, off) == TRUE)
|
||||||
{
|
{
|
||||||
@ -469,7 +469,7 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be
|
|||||||
|
|
||||||
/* Check for long conditional equality or inequality. This requires
|
/* Check for long conditional equality or inequality. This requires
|
||||||
* 2 CMPs and 2 branches */
|
* 2 CMPs and 2 branches */
|
||||||
else if (pIcode->ic.ll.match(iCMP) && (isLong22 (pIcode, pEnd, &off)))
|
else if (pIcode->ll()->match(iCMP) && (isLong22 (pIcode, pEnd, &off)))
|
||||||
{
|
{
|
||||||
if (checkLongRegEq (pLocId.id.longId, pIcode, loc_ident_idx, this, asgn.rhs, asgn.lhs, off) == TRUE)
|
if (checkLongRegEq (pLocId.id.longId, pIcode, loc_ident_idx, this, asgn.rhs, asgn.lhs, off) == TRUE)
|
||||||
{
|
{
|
||||||
@ -481,13 +481,13 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be
|
|||||||
* JX lab
|
* JX lab
|
||||||
* => HLI_JCOND (regH:regL X 0) lab
|
* => HLI_JCOND (regH:regL X 0) lab
|
||||||
* This is better code than HLI_JCOND (HI(regH:regL) | LO(regH:regL)) */
|
* This is better code than HLI_JCOND (HI(regH:regL) | LO(regH:regL)) */
|
||||||
else if (pIcode->ic.ll.match(iOR) && (next1 != pEnd) && (isJCond (next1->ic.ll.opcode)))
|
else if (pIcode->ll()->match(iOR) && (next1 != pEnd) && (isJCond (next1->ll()->opcode)))
|
||||||
{
|
{
|
||||||
if ((pIcode->ic.ll.dst.regi == pLocId.id.longId.h) && (pIcode->ic.ll.src.regi == pLocId.id.longId.l))
|
if ((pIcode->ll()->dst.regi == pLocId.id.longId.h) && (pIcode->ll()->src.regi == pLocId.id.longId.l))
|
||||||
{
|
{
|
||||||
asgn.lhs = COND_EXPR::idLongIdx (loc_ident_idx);
|
asgn.lhs = COND_EXPR::idLongIdx (loc_ident_idx);
|
||||||
asgn.rhs = COND_EXPR::idKte (0, 4); /* long 0 */
|
asgn.rhs = COND_EXPR::idKte (0, 4); /* long 0 */
|
||||||
asgn.lhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, condOpJCond[next1->ic.ll.opcode - iJB]);
|
asgn.lhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, condOpJCond[next1->ll()->opcode - iJB]);
|
||||||
next1->setJCond(asgn.lhs);
|
next1->setJCond(asgn.lhs);
|
||||||
next1->copyDU(*pIcode, eUSE, eUSE);
|
next1->copyDU(*pIcode, eUSE, eUSE);
|
||||||
pIcode->invalidate();
|
pIcode->invalidate();
|
||||||
|
|||||||
159
src/scanner.cpp
159
src/scanner.cpp
@ -329,7 +329,7 @@ eErrorId scan(uint32_t ip, ICODE &p)
|
|||||||
int op;
|
int op;
|
||||||
p = ICODE();
|
p = ICODE();
|
||||||
p.type = LOW_LEVEL;
|
p.type = LOW_LEVEL;
|
||||||
p.ic.ll.label = ip; /* ip is absolute offset into image*/
|
p.ll()->label = ip; /* ip is absolute offset into image*/
|
||||||
if (ip >= (uint32_t)prog.cbImage)
|
if (ip >= (uint32_t)prog.cbImage)
|
||||||
{
|
{
|
||||||
return (IP_OUT_OF_RANGE);
|
return (IP_OUT_OF_RANGE);
|
||||||
@ -342,20 +342,20 @@ eErrorId scan(uint32_t ip, ICODE &p)
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
op = *pInst++; /* First state - trivial */
|
op = *pInst++; /* First state - trivial */
|
||||||
p.ic.ll.opcode = stateTable[op].opcode; /* Convert to Icode.opcode */
|
/* Convert to Icode.opcode */
|
||||||
p.ic.ll.flg = stateTable[op].flg & ICODEMASK;
|
p.ll()->set(stateTable[op].opcode,stateTable[op].flg & ICODEMASK);
|
||||||
p.ic.ll.flagDU.d = stateTable[op].df;
|
p.ll()->flagDU.d = stateTable[op].df;
|
||||||
p.ic.ll.flagDU.u = stateTable[op].uf;
|
p.ll()->flagDU.u = stateTable[op].uf;
|
||||||
|
|
||||||
(*stateTable[op].state1)(op); /* Second state */
|
(*stateTable[op].state1)(op); /* Second state */
|
||||||
(*stateTable[op].state2)(op); /* Third state */
|
(*stateTable[op].state2)(op); /* Third state */
|
||||||
|
|
||||||
} while (stateTable[op].state1 == prefix); /* Loop if prefix */
|
} while (stateTable[op].state1 == prefix); /* Loop if prefix */
|
||||||
|
|
||||||
if (p.ic.ll.opcode)
|
if (p.ll()->opcode)
|
||||||
{
|
{
|
||||||
/* Save bytes of image used */
|
/* Save bytes of image used */
|
||||||
p.ic.ll.numBytes = (uint8_t)((pInst - prog.Image) - ip);
|
p.ll()->numBytes = (uint8_t)((pInst - prog.Image) - ip);
|
||||||
return ((SegPrefix)? FUNNY_SEGOVR: /* Seg. Override invalid */
|
return ((SegPrefix)? FUNNY_SEGOVR: /* Seg. Override invalid */
|
||||||
(RepPrefix ? FUNNY_REP: NO_ERR));/* REP prefix invalid */
|
(RepPrefix ? FUNNY_REP: NO_ERR));/* REP prefix invalid */
|
||||||
}
|
}
|
||||||
@ -413,7 +413,7 @@ static void setAddress(int i, boolT fdst, uint16_t seg, int16_t reg, uint16_t of
|
|||||||
/* If not to register (i.e. to r/m), and talking about r/m,
|
/* If not to register (i.e. to r/m), and talking about r/m,
|
||||||
then this is dest */
|
then this is dest */
|
||||||
pm = (!(stateTable[i].flg & TO_REG) == fdst) ?
|
pm = (!(stateTable[i].flg & TO_REG) == fdst) ?
|
||||||
&pIcode->ic.ll.dst : &pIcode->ic.ll.src;
|
&pIcode->ll()->dst : &pIcode->ll()->src;
|
||||||
|
|
||||||
/* Set segment. A later procedure (lookupAddr in proclist.c) will
|
/* Set segment. A later procedure (lookupAddr in proclist.c) will
|
||||||
* provide the value of this segment in the field segValue. */
|
* provide the value of this segment in the field segValue. */
|
||||||
@ -459,9 +459,10 @@ static void rm(int i)
|
|||||||
case 0: /* No disp unless rm == 6 */
|
case 0: /* No disp unless rm == 6 */
|
||||||
if (rm == 6) {
|
if (rm == 6) {
|
||||||
setAddress(i, TRUE, SegPrefix, 0, getWord());
|
setAddress(i, TRUE, SegPrefix, 0, getWord());
|
||||||
pIcode->ic.ll.flg |= WORD_OFF;
|
pIcode->ll()->SetLlFlag(WORD_OFF);
|
||||||
}
|
}
|
||||||
else setAddress(i, TRUE, SegPrefix, rm + INDEXBASE, 0);
|
else
|
||||||
|
setAddress(i, TRUE, SegPrefix, rm + INDEXBASE, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1: /* 1 uint8_t disp */
|
case 1: /* 1 uint8_t disp */
|
||||||
@ -470,7 +471,7 @@ static void rm(int i)
|
|||||||
|
|
||||||
case 2: /* 2 uint8_t disp */
|
case 2: /* 2 uint8_t disp */
|
||||||
setAddress(i, TRUE, SegPrefix, rm + INDEXBASE, getWord());
|
setAddress(i, TRUE, SegPrefix, rm + INDEXBASE, getWord());
|
||||||
pIcode->ic.ll.flg |= WORD_OFF;
|
pIcode->ll()->SetLlFlag(WORD_OFF);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3: /* reg */
|
case 3: /* reg */
|
||||||
@ -478,9 +479,9 @@ static void rm(int i)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((stateTable[i].flg & NSP) && (pIcode->ic.ll.src.regi==rSP ||
|
if ((stateTable[i].flg & NSP) && (pIcode->ll()->src.regi==rSP ||
|
||||||
pIcode->ic.ll.dst.regi==rSP))
|
pIcode->ll()->dst.regi==rSP))
|
||||||
pIcode->ic.ll.flg |= NOT_HLL;
|
pIcode->ll()->SetLlFlag(NOT_HLL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -502,7 +503,7 @@ static void segrm(int i)
|
|||||||
int reg = REG(*pInst) + rES;
|
int reg = REG(*pInst) + rES;
|
||||||
|
|
||||||
if (reg > rDS || (reg == rCS && (stateTable[i].flg & TO_REG)))
|
if (reg > rDS || (reg == rCS && (stateTable[i].flg & TO_REG)))
|
||||||
pIcode->ic.ll.opcode = (llIcode)0;
|
pIcode->ll()->opcode = (llIcode)0;
|
||||||
else {
|
else {
|
||||||
setAddress(i, FALSE, 0, (int16_t)reg, 0);
|
setAddress(i, FALSE, 0, (int16_t)reg, 0);
|
||||||
rm(i);
|
rm(i);
|
||||||
@ -516,7 +517,7 @@ static void segrm(int i)
|
|||||||
static void regop(int i)
|
static void regop(int i)
|
||||||
{
|
{
|
||||||
setAddress(i, FALSE, 0, ((int16_t)i & 7) + rAX, 0);
|
setAddress(i, FALSE, 0, ((int16_t)i & 7) + rAX, 0);
|
||||||
pIcode->ic.ll.dst.regi = pIcode->ic.ll.src.regi;
|
pIcode->ll()->dst.regi = pIcode->ll()->src.regi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -540,13 +541,13 @@ static void axImp(int i)
|
|||||||
/* Implied AX source */
|
/* Implied AX source */
|
||||||
static void axSrcIm (int )
|
static void axSrcIm (int )
|
||||||
{
|
{
|
||||||
pIcode->ic.ll.src.regi = rAX;
|
pIcode->ll()->src.regi = rAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Implied AL source */
|
/* Implied AL source */
|
||||||
static void alImp (int )
|
static void alImp (int )
|
||||||
{
|
{
|
||||||
pIcode->ic.ll.src.regi = rAL;
|
pIcode->ll()->src.regi = rAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -565,7 +566,7 @@ static void memImp(int i)
|
|||||||
static void memOnly(int )
|
static void memOnly(int )
|
||||||
{
|
{
|
||||||
if ((*pInst & 0xC0) == 0xC0)
|
if ((*pInst & 0xC0) == 0xC0)
|
||||||
pIcode->ic.ll.opcode = (llIcode)0;
|
pIcode->ll()->opcode = (llIcode)0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -575,7 +576,7 @@ static void memOnly(int )
|
|||||||
static void memReg0(int i)
|
static void memReg0(int i)
|
||||||
{
|
{
|
||||||
if (REG(*pInst) || (*pInst & 0xC0) == 0xC0)
|
if (REG(*pInst) || (*pInst & 0xC0) == 0xC0)
|
||||||
pIcode->ic.ll.opcode = (llIcode)0;
|
pIcode->ll()->opcode = (llIcode)0;
|
||||||
else
|
else
|
||||||
rm(i);
|
rm(i);
|
||||||
}
|
}
|
||||||
@ -589,13 +590,13 @@ static void immed(int i)
|
|||||||
static llIcode immedTable[8] = {iADD, iOR, iADC, iSBB, iAND, iSUB, iXOR, iCMP};
|
static llIcode immedTable[8] = {iADD, iOR, iADC, iSBB, iAND, iSUB, iXOR, iCMP};
|
||||||
static uint8_t uf[8] = { 0, 0, Cf, Cf, 0, 0, 0, 0 };
|
static uint8_t uf[8] = { 0, 0, Cf, Cf, 0, 0, 0, 0 };
|
||||||
|
|
||||||
pIcode->ic.ll.opcode = immedTable[REG(*pInst)];
|
pIcode->ll()->opcode = immedTable[REG(*pInst)];
|
||||||
pIcode->ic.ll.flagDU.u = uf[REG(*pInst)];
|
pIcode->ll()->flagDU.u = uf[REG(*pInst)];
|
||||||
pIcode->ic.ll.flagDU.d = (Sf | Zf | Cf);
|
pIcode->ll()->flagDU.d = (Sf | Zf | Cf);
|
||||||
rm(i);
|
rm(i);
|
||||||
|
|
||||||
if (pIcode->ic.ll.opcode == iADD || pIcode->ic.ll.opcode == iSUB)
|
if (pIcode->ll()->opcode == iADD || pIcode->ll()->opcode == iSUB)
|
||||||
pIcode->ic.ll.flg &= ~NOT_HLL; /* Allow ADD/SUB SP, immed */
|
pIcode->ll()->ClrLlFlag(NOT_HLL); /* Allow ADD/SUB SP, immed */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -612,11 +613,11 @@ static void shift(int i)
|
|||||||
static uint8_t df[8] = {Cf, Cf, Cf, Cf, Sf | Zf | Cf,
|
static uint8_t df[8] = {Cf, Cf, Cf, Cf, Sf | Zf | Cf,
|
||||||
Sf | Zf | Cf, 0, Sf | Zf | Cf};
|
Sf | Zf | Cf, 0, Sf | Zf | Cf};
|
||||||
|
|
||||||
pIcode->ic.ll.opcode = shiftTable[REG(*pInst)];
|
pIcode->ll()->opcode = shiftTable[REG(*pInst)];
|
||||||
pIcode->ic.ll.flagDU.u = uf[REG(*pInst)];
|
pIcode->ll()->flagDU.u = uf[REG(*pInst)];
|
||||||
pIcode->ic.ll.flagDU.d = df[REG(*pInst)];
|
pIcode->ll()->flagDU.d = df[REG(*pInst)];
|
||||||
rm(i);
|
rm(i);
|
||||||
pIcode->ic.ll.src.regi = rCL;
|
pIcode->ll()->src.regi = rCL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -631,16 +632,16 @@ static void trans(int i)
|
|||||||
(llIcode)iJMP, (llIcode)iJMPF,(llIcode)iPUSH, (llIcode)0
|
(llIcode)iJMP, (llIcode)iJMPF,(llIcode)iPUSH, (llIcode)0
|
||||||
};
|
};
|
||||||
static uint8_t df[8] = {Sf | Zf, Sf | Zf, 0, 0, 0, 0, 0, 0};
|
static uint8_t df[8] = {Sf | Zf, Sf | Zf, 0, 0, 0, 0, 0, 0};
|
||||||
|
LLInst *ll = pIcode->ll();
|
||||||
if ((uint8_t)REG(*pInst) < 2 || !(stateTable[i].flg & B)) { /* INC & DEC */
|
if ((uint8_t)REG(*pInst) < 2 || !(stateTable[i].flg & B)) { /* INC & DEC */
|
||||||
pIcode->ic.ll.opcode = transTable[REG(*pInst)]; /* valid on bytes */
|
ll->opcode = transTable[REG(*pInst)]; /* valid on bytes */
|
||||||
pIcode->ic.ll.flagDU.d = df[REG(*pInst)];
|
ll->flagDU.d = df[REG(*pInst)];
|
||||||
rm(i);
|
rm(i);
|
||||||
pIcode->ic.ll.src = pIcode->ic.ll.dst;
|
ll->src = pIcode->ll()->dst;
|
||||||
if (pIcode->ic.ll.opcode == iJMP || pIcode->ic.ll.opcode == iCALL || pIcode->ic.ll.opcode == iCALLF)
|
if (ll->opcode == iJMP || ll->opcode == iCALL || ll->opcode == iCALLF)
|
||||||
pIcode->ic.ll.flg |= NO_OPS;
|
ll->SetLlFlag(NO_OPS);
|
||||||
else if (pIcode->ic.ll.opcode == iINC || pIcode->ic.ll.opcode == iPUSH || pIcode->ic.ll.opcode == iDEC)
|
else if (ll->opcode == iINC || ll->opcode == iPUSH || ll->opcode == iDEC)
|
||||||
pIcode->ic.ll.flg |= NO_SRC;
|
ll->SetLlFlag(NO_SRC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -659,8 +660,8 @@ static void arith(int i)
|
|||||||
Sf | Zf | Cf, Sf | Zf | Cf, Sf | Zf | Cf,
|
Sf | Zf | Cf, Sf | Zf | Cf, Sf | Zf | Cf,
|
||||||
Sf | Zf | Cf};
|
Sf | Zf | Cf};
|
||||||
|
|
||||||
opcode = pIcode->ic.ll.opcode = arithTable[REG(*pInst)];
|
opcode = pIcode->ll()->opcode = arithTable[REG(*pInst)];
|
||||||
pIcode->ic.ll.flagDU.d = df[REG(*pInst)];
|
pIcode->ll()->flagDU.d = df[REG(*pInst)];
|
||||||
rm(i);
|
rm(i);
|
||||||
if (opcode == iTEST)
|
if (opcode == iTEST)
|
||||||
{
|
{
|
||||||
@ -671,16 +672,16 @@ static void arith(int i)
|
|||||||
}
|
}
|
||||||
else if (!(opcode == iNOT || opcode == iNEG))
|
else if (!(opcode == iNOT || opcode == iNEG))
|
||||||
{
|
{
|
||||||
pIcode->ic.ll.src = pIcode->ic.ll.dst;
|
pIcode->ll()->src = pIcode->ll()->dst;
|
||||||
setAddress(i, TRUE, 0, rAX, 0); /* dst = AX */
|
setAddress(i, TRUE, 0, rAX, 0); /* dst = AX */
|
||||||
}
|
}
|
||||||
else if (opcode == iNEG || opcode == iNOT)
|
else if (opcode == iNEG || opcode == iNOT)
|
||||||
pIcode->ic.ll.flg |= NO_SRC;
|
pIcode->ll()->SetLlFlag(NO_SRC);
|
||||||
|
|
||||||
if ((opcode == iDIV) || (opcode == iIDIV))
|
if ((opcode == iDIV) || (opcode == iIDIV))
|
||||||
{
|
{
|
||||||
if ((pIcode->ic.ll.flg & B) != B)
|
if ( not pIcode->ll()->isLlFlag(B) )
|
||||||
pIcode->ic.ll.flg |= IM_TMP_DST;
|
pIcode->ll()->SetLlFlag(IM_TMP_DST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -690,8 +691,8 @@ static void arith(int i)
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
static void data1(int i)
|
static void data1(int i)
|
||||||
{
|
{
|
||||||
pIcode->ic.ll.src.SetImmediateOp( (stateTable[i].flg & S_EXT)? signex(*pInst++): *pInst++ );
|
pIcode->ll()->src.SetImmediateOp( (stateTable[i].flg & S_EXT)? signex(*pInst++): *pInst++ );
|
||||||
pIcode->ic.ll.flg |= I;
|
pIcode->ll()->SetLlFlag(I);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -701,21 +702,21 @@ static void data1(int i)
|
|||||||
static void data2(int )
|
static void data2(int )
|
||||||
{
|
{
|
||||||
if (relocItem(pInst))
|
if (relocItem(pInst))
|
||||||
pIcode->ic.ll.flg |= SEG_IMMED;
|
pIcode->ll()->SetLlFlag(SEG_IMMED);
|
||||||
|
|
||||||
/* ENTER is a special case, it does not take a destination operand,
|
/* ENTER is a special case, it does not take a destination operand,
|
||||||
* but this field is being used as the number of bytes to allocate
|
* but this field is being used as the number of bytes to allocate
|
||||||
* on the stack. The procedure level is stored in the immediate
|
* on the stack. The procedure level is stored in the immediate
|
||||||
* field. There is no source operand; therefore, the flag flg is
|
* field. There is no source operand; therefore, the flag flg is
|
||||||
* set to NO_OPS. */
|
* set to NO_OPS. */
|
||||||
if (pIcode->ic.ll.opcode == iENTER)
|
if (pIcode->ll()->opcode == iENTER)
|
||||||
{
|
{
|
||||||
pIcode->ic.ll.dst.off = getWord();
|
pIcode->ll()->dst.off = getWord();
|
||||||
pIcode->ic.ll.flg |= NO_OPS;
|
pIcode->ll()->SetLlFlag(NO_OPS);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
pIcode->ic.ll.src.SetImmediateOp(getWord());
|
pIcode->ll()->src.SetImmediateOp(getWord());
|
||||||
pIcode->ic.ll.flg |= I;
|
pIcode->ll()->SetLlFlag(I);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -739,8 +740,8 @@ static void dispN(int )
|
|||||||
/* Note: the result of the subtraction could be between 32k and 64k, and
|
/* 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
|
still be positive; it is an offset from prog.Image. So this must be
|
||||||
treated as unsigned */
|
treated as unsigned */
|
||||||
pIcode->ic.ll.src.SetImmediateOp((uint32_t)(off + (unsigned)(pInst - prog.Image)));
|
pIcode->ll()->src.SetImmediateOp((uint32_t)(off + (unsigned)(pInst - prog.Image)));
|
||||||
pIcode->ic.ll.flg |= I;
|
pIcode->ll()->SetLlFlag(I);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -751,8 +752,8 @@ static void dispS(int )
|
|||||||
{
|
{
|
||||||
long off = signex(*pInst++); /* Signed displacement */
|
long off = signex(*pInst++); /* Signed displacement */
|
||||||
|
|
||||||
pIcode->ic.ll.src.SetImmediateOp((uint32_t)(off + (unsigned)(pInst - prog.Image)));
|
pIcode->ll()->src.SetImmediateOp((uint32_t)(off + (unsigned)(pInst - prog.Image)));
|
||||||
pIcode->ic.ll.flg |= I;
|
pIcode->ll()->SetLlFlag(I);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -764,8 +765,8 @@ static void dispF(int )
|
|||||||
uint32_t off = (unsigned)getWord();
|
uint32_t off = (unsigned)getWord();
|
||||||
uint32_t seg = (unsigned)getWord();
|
uint32_t seg = (unsigned)getWord();
|
||||||
|
|
||||||
pIcode->ic.ll.src.SetImmediateOp(off + ((uint32_t)(unsigned)seg << 4));
|
pIcode->ll()->src.SetImmediateOp(off + ((uint32_t)(unsigned)seg << 4));
|
||||||
pIcode->ic.ll.flg |= I;
|
pIcode->ll()->SetLlFlag(I);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -775,10 +776,10 @@ static void dispF(int )
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
static void prefix(int )
|
static void prefix(int )
|
||||||
{
|
{
|
||||||
if (pIcode->ic.ll.opcode == iREPE || pIcode->ic.ll.opcode == iREPNE)
|
if (pIcode->ll()->opcode == iREPE || pIcode->ll()->opcode == iREPNE)
|
||||||
RepPrefix = pIcode->ic.ll.opcode;
|
RepPrefix = pIcode->ll()->opcode;
|
||||||
else
|
else
|
||||||
SegPrefix = pIcode->ic.ll.opcode;
|
SegPrefix = pIcode->ll()->opcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void BumpOpcode(llIcode& ic)
|
inline void BumpOpcode(llIcode& ic)
|
||||||
@ -793,15 +794,15 @@ static void strop(int )
|
|||||||
{
|
{
|
||||||
if (RepPrefix)
|
if (RepPrefix)
|
||||||
{
|
{
|
||||||
// pIcode->ic.ll.opcode += ((pIcode->ic.ll.opcode == iCMPS ||
|
// pIcode->ll()->opcode += ((pIcode->ll()->opcode == iCMPS ||
|
||||||
// pIcode->ic.ll.opcode == iSCAS)
|
// pIcode->ll()->opcode == iSCAS)
|
||||||
// && RepPrefix == iREPE)? 2: 1;
|
// && RepPrefix == iREPE)? 2: 1;
|
||||||
if ((pIcode->ic.ll.opcode == iCMPS || pIcode->ic.ll.opcode == iSCAS)
|
if ((pIcode->ll()->opcode == iCMPS || pIcode->ll()->opcode == iSCAS)
|
||||||
&& RepPrefix == iREPE)
|
&& RepPrefix == iREPE)
|
||||||
BumpOpcode(pIcode->ic.ll.opcode); // += 2
|
BumpOpcode(pIcode->ll()->opcode); // += 2
|
||||||
BumpOpcode(pIcode->ic.ll.opcode); // else += 1
|
BumpOpcode(pIcode->ll()->opcode); // else += 1
|
||||||
if (pIcode->ic.ll.opcode == iREP_LODS)
|
if (pIcode->ll()->opcode == iREP_LODS)
|
||||||
pIcode->ic.ll.flg |= NOT_HLL;
|
pIcode->ll()->SetLlFlag(NOT_HLL);
|
||||||
RepPrefix = 0;
|
RepPrefix = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -812,8 +813,8 @@ static void strop(int )
|
|||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
static void escop(int i)
|
static void escop(int i)
|
||||||
{
|
{
|
||||||
pIcode->ic.ll.src.SetImmediateOp(REG(*pInst) + (uint32_t)((i & 7) << 3));
|
pIcode->ll()->src.SetImmediateOp(REG(*pInst) + (uint32_t)((i & 7) << 3));
|
||||||
pIcode->ic.ll.flg |= I;
|
pIcode->ll()->SetLlFlag(I);
|
||||||
rm(i);
|
rm(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -823,8 +824,8 @@ static void escop(int i)
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
static void const1(int )
|
static void const1(int )
|
||||||
{
|
{
|
||||||
pIcode->ic.ll.src.SetImmediateOp(1);
|
pIcode->ll()->src.SetImmediateOp(1);
|
||||||
pIcode->ic.ll.flg |= I;
|
pIcode->ll()->SetLlFlag(I);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -833,8 +834,8 @@ static void const1(int )
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
static void const3(int )
|
static void const3(int )
|
||||||
{
|
{
|
||||||
pIcode->ic.ll.src.SetImmediateOp(3);
|
pIcode->ll()->src.SetImmediateOp(3);
|
||||||
pIcode->ic.ll.flg |= I;
|
pIcode->ll()->SetLlFlag(I);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -851,8 +852,8 @@ static void none1(int )
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
static void none2(int )
|
static void none2(int )
|
||||||
{
|
{
|
||||||
if (pIcode->ic.ll.flg & I)
|
if ( pIcode->ll()->isLlFlag(I) )
|
||||||
pIcode->ic.ll.flg |= NO_OPS;
|
pIcode->ll()->SetLlFlag(NO_OPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -860,14 +861,14 @@ static void none2(int )
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
static void checkInt(int )
|
static void checkInt(int )
|
||||||
{
|
{
|
||||||
uint16_t wOp = (uint16_t) pIcode->ic.ll.src.op();
|
uint16_t wOp = (uint16_t) pIcode->ll()->src.op();
|
||||||
if ((wOp >= 0x34) && (wOp <= 0x3B))
|
if ((wOp >= 0x34) && (wOp <= 0x3B))
|
||||||
{
|
{
|
||||||
/* This is a Borland/Microsoft floating point emulation instruction.
|
/* This is a Borland/Microsoft floating point emulation instruction.
|
||||||
Treat as if it is an ESC opcode */
|
Treat as if it is an ESC opcode */
|
||||||
pIcode->ic.ll.src.SetImmediateOp(wOp - 0x34);
|
pIcode->ll()->src.SetImmediateOp(wOp - 0x34);
|
||||||
pIcode->ic.ll.opcode = iESC;
|
pIcode->ll()->opcode = iESC;
|
||||||
pIcode->ic.ll.flg |= FLOAT_OP;
|
pIcode->ll()->SetLlFlag(FLOAT_OP);
|
||||||
|
|
||||||
escop(wOp - 0x34 + 0xD8);
|
escop(wOp - 0x34 + 0xD8);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user