Moved most of register definitions to use eReg enum
This commit is contained in:
parent
2a99eef3a1
commit
e0740f5ff7
7
.gitignore
vendored
7
.gitignore
vendored
@ -1,2 +1,7 @@
|
||||
coverage
|
||||
tests/inputs
|
||||
tests/prev
|
||||
tests/outputs/*
|
||||
bld
|
||||
tests/errors
|
||||
*.autosave
|
||||
bld*
|
||||
@ -2,6 +2,7 @@
|
||||
/* Machine registers */
|
||||
enum eReg
|
||||
{
|
||||
rUNDEF = 0,
|
||||
rAX = 1, /* These are numbered relative to real 8086 */
|
||||
rCX = 2,
|
||||
rDX = 3,
|
||||
|
||||
@ -165,6 +165,6 @@ protected:
|
||||
void findIdioms();
|
||||
void propLong();
|
||||
void genLiveKtes();
|
||||
uint8_t findDerivedSeq (derSeq *derivedGi);
|
||||
bool nextOrderGraph(derSeq *derivedGi);
|
||||
uint8_t findDerivedSeq (derSeq &derivedGi);
|
||||
bool nextOrderGraph(derSeq &derivedGi);
|
||||
};
|
||||
|
||||
@ -74,7 +74,7 @@ public:
|
||||
static COND_EXPR *idRegIdx(int idx, regType reg_type);
|
||||
static COND_EXPR *idKte(uint32_t kte, uint8_t size);
|
||||
static COND_EXPR *idLoc(int off, LOCAL_ID *localId);
|
||||
static COND_EXPR *idReg(uint8_t regi, uint32_t icodeFlg, LOCAL_ID *locsym);
|
||||
static COND_EXPR *idReg(eReg regi, uint32_t icodeFlg, LOCAL_ID *locsym);
|
||||
static COND_EXPR *idLongIdx(int idx);
|
||||
static COND_EXPR *idOther(uint8_t seg, uint8_t regi, int16_t off);
|
||||
static COND_EXPR *idParam(int off, const STKFRAME *argSymtab);
|
||||
@ -85,7 +85,7 @@ public:
|
||||
static COND_EXPR * id(const LLInst &ll_insn, opLoc sd, Function *pProc, iICODE ix_, ICODE &duIcode, operDu du);
|
||||
static COND_EXPR *boolOp(COND_EXPR *_lhs, COND_EXPR *_rhs, condOp _op);
|
||||
static bool insertSubTreeLongReg(COND_EXPR *exp, COND_EXPR **tree, int longIdx);
|
||||
static bool insertSubTreeReg(COND_EXPR *&tree, COND_EXPR *_expr, uint8_t regi, LOCAL_ID *locsym);
|
||||
static bool insertSubTreeReg(COND_EXPR *&tree, COND_EXPR *_expr, eReg regi, LOCAL_ID *locsym);
|
||||
public:
|
||||
virtual COND_EXPR *clone();
|
||||
void release();
|
||||
@ -106,7 +106,7 @@ public:
|
||||
public:
|
||||
virtual COND_EXPR *inverse(); // return new COND_EXPR that is invarse of this
|
||||
virtual bool xClear(iICODE f, iICODE t, iICODE lastBBinst, Function *pproc);
|
||||
virtual COND_EXPR *insertSubTreeReg(COND_EXPR *_expr, uint8_t regi, LOCAL_ID *locsym);
|
||||
virtual COND_EXPR *insertSubTreeReg(COND_EXPR *_expr, eReg regi, LOCAL_ID *locsym);
|
||||
virtual COND_EXPR *insertSubTreeLongReg(COND_EXPR *_expr, int longIdx);
|
||||
};
|
||||
struct BinaryOperator : public COND_EXPR
|
||||
@ -124,7 +124,7 @@ struct BinaryOperator : public COND_EXPR
|
||||
virtual COND_EXPR *inverse();
|
||||
virtual COND_EXPR *clone();
|
||||
virtual bool xClear(iICODE f, iICODE t, iICODE lastBBinst, Function *pproc);
|
||||
virtual COND_EXPR *insertSubTreeReg(COND_EXPR *_expr, uint8_t regi, LOCAL_ID *locsym);
|
||||
virtual COND_EXPR *insertSubTreeReg(COND_EXPR *_expr, eReg regi, LOCAL_ID *locsym);
|
||||
virtual COND_EXPR *insertSubTreeLongReg(COND_EXPR *_expr, int longIdx);
|
||||
|
||||
COND_EXPR *lhs()
|
||||
|
||||
@ -101,7 +101,7 @@ extern PROG prog; /* Loaded program image parameters */
|
||||
extern std::bitset<32> duReg[30]; /* def/use bits for registers */
|
||||
|
||||
//extern uint32_t duReg[30]; /* def/use bits for registers */
|
||||
extern uint32_t maskDuReg[30]; /* masks off du bits for regs */
|
||||
extern std::bitset<32> maskDuReg[30]; /* masks off du bits for regs */
|
||||
|
||||
/* Registers used by icode instructions */
|
||||
static constexpr const char *allRegs[21] = {"ax", "cx", "dx", "bx", "sp", "bp",
|
||||
@ -174,4 +174,4 @@ int power2 (int);
|
||||
/* Exported funcions from locident.c */
|
||||
boolT checkLongEq (LONG_STKID_TYPE, iICODE, int, Function *, Assignment &asgn, iICODE atOffset);
|
||||
boolT checkLongRegEq (LONGID_TYPE, iICODE, int, Function *, Assignment &asgn, iICODE);
|
||||
uint8_t otherLongRegi (uint8_t, int, LOCAL_ID *);
|
||||
eReg otherLongRegi(eReg, int, LOCAL_ID *);
|
||||
|
||||
@ -45,10 +45,10 @@ struct COND_EXPR;
|
||||
struct HlTypeSupport
|
||||
{
|
||||
//hlIcode opcode; /* hlIcode opcode */
|
||||
virtual bool removeRegFromLong(uint8_t regi, LOCAL_ID *locId)=0;
|
||||
virtual bool removeRegFromLong(eReg regi, LOCAL_ID *locId)=0;
|
||||
virtual std::string writeOut(Function *pProc, int *numLoc)=0;
|
||||
protected:
|
||||
void performLongRemoval (uint8_t regi, LOCAL_ID *locId, COND_EXPR *tree);
|
||||
void performLongRemoval (eReg regi, LOCAL_ID *locId, COND_EXPR *tree);
|
||||
};
|
||||
|
||||
struct CallType : public HlTypeSupport
|
||||
@ -60,7 +60,7 @@ struct CallType : public HlTypeSupport
|
||||
bool newStkArg(COND_EXPR *exp, llIcode opcode, Function *pproc);
|
||||
void placeStkArg(COND_EXPR *exp, int pos);
|
||||
public:
|
||||
bool removeRegFromLong(uint8_t regi, LOCAL_ID *locId)
|
||||
bool removeRegFromLong(eReg regi, LOCAL_ID *locId)
|
||||
{
|
||||
printf("CallType : removeRegFromLong not supproted");
|
||||
return false;
|
||||
@ -72,7 +72,7 @@ struct AssignType : public HlTypeSupport
|
||||
/* for HLI_ASSIGN */
|
||||
COND_EXPR *lhs;
|
||||
COND_EXPR *rhs;
|
||||
bool removeRegFromLong(uint8_t regi, LOCAL_ID *locId)
|
||||
bool removeRegFromLong(eReg regi, LOCAL_ID *locId)
|
||||
{
|
||||
performLongRemoval(regi,locId,lhs);
|
||||
return true;
|
||||
@ -83,7 +83,7 @@ struct ExpType : public HlTypeSupport
|
||||
{
|
||||
/* for HLI_JCOND, HLI_RET, HLI_PUSH, HLI_POP*/
|
||||
COND_EXPR *v;
|
||||
bool removeRegFromLong(uint8_t regi, LOCAL_ID *locId)
|
||||
bool removeRegFromLong(eReg regi, LOCAL_ID *locId)
|
||||
{
|
||||
performLongRemoval(regi,locId,v);
|
||||
return true;
|
||||
@ -156,7 +156,7 @@ struct LLOperand //: public llvm::MCOperand
|
||||
uint8_t seg; /* CS, DS, ES, SS */
|
||||
int16_t segValue; /* Value of segment seg during analysis */
|
||||
uint8_t segOver; /* CS, DS, ES, SS if segment override */
|
||||
uint8_t regi; /* 0 < regs < INDEXBASE <= index modes */
|
||||
eReg regi; /* 0 < regs < INDEXBASE <= index modes */
|
||||
int16_t off; /* memory address offset */
|
||||
uint32_t opz; /* idx of immed src op */
|
||||
//union {/* Source operand if (flg & I) */
|
||||
@ -352,7 +352,7 @@ public:
|
||||
void copyDU(const ICODE &duIcode, operDu _du, operDu duDu);
|
||||
bool valid() {return not invalid;}
|
||||
public:
|
||||
bool removeDefRegi(uint8_t regi, int thisDefIdx, LOCAL_ID *locId);
|
||||
bool removeDefRegi(eReg regi, int thisDefIdx, LOCAL_ID *locId);
|
||||
void checkHlCall();
|
||||
bool newStkArg(COND_EXPR *exp, llIcode opcode, Function *pproc)
|
||||
{
|
||||
@ -372,3 +372,11 @@ public:
|
||||
iterator labelSrch(uint32_t target);
|
||||
ICODE * GetIcode(int ip);
|
||||
};
|
||||
constexpr eReg subRegH(eReg reg)
|
||||
{
|
||||
return eReg((int)reg + (int)rAH-(int)rAX);
|
||||
}
|
||||
constexpr eReg subRegL(eReg reg)
|
||||
{
|
||||
return eReg((int)reg + (int)rAL-(int)rAX);
|
||||
}
|
||||
|
||||
@ -8,11 +8,11 @@ struct Idiom14 : public Idiom
|
||||
{
|
||||
protected:
|
||||
iICODE m_icodes[2];
|
||||
uint8_t m_regL;
|
||||
uint8_t m_regH;
|
||||
eReg m_regL;
|
||||
eReg m_regH;
|
||||
public:
|
||||
virtual ~Idiom14() {}
|
||||
Idiom14(Function *f) : Idiom(f),m_regL(0),m_regH(0)
|
||||
Idiom14(Function *f) : Idiom(f),m_regL(rUNDEF),m_regH(rUNDEF)
|
||||
{
|
||||
}
|
||||
uint8_t minimum_match_length() {return 2;}
|
||||
@ -24,7 +24,7 @@ struct Idiom13 : public Idiom
|
||||
{
|
||||
protected:
|
||||
iICODE m_icodes[2];
|
||||
uint8_t m_loaded_reg;
|
||||
eReg m_loaded_reg;
|
||||
public:
|
||||
virtual ~Idiom13() {}
|
||||
Idiom13(Function *f) : Idiom(f)
|
||||
|
||||
@ -55,8 +55,8 @@ typedef struct
|
||||
} LONG_STKID_TYPE;
|
||||
typedef struct
|
||||
{ /* For TYPE_LONG_(UN)SIGN registers */
|
||||
uint8_t h; /* high register */
|
||||
uint8_t l; /* low register */
|
||||
eReg h; /* high register */
|
||||
eReg l; /* low register */
|
||||
} LONGID_TYPE;
|
||||
|
||||
|
||||
@ -72,7 +72,7 @@ struct ID
|
||||
char macro[10]; /* Macro for this identifier */
|
||||
char name[20]; /* Identifier's name */
|
||||
union { /* Different types of identifiers */
|
||||
uint8_t regi; /* For TYPE_BYTE(uint16_t)_(UN)SIGN registers */
|
||||
eReg regi; /* For TYPE_BYTE(uint16_t)_(UN)SIGN registers */
|
||||
struct { /* For TYPE_BYTE(uint16_t)_(UN)SIGN on the stack */
|
||||
uint8_t regOff; /* register offset (if any) */
|
||||
int off; /* offset from BP */
|
||||
@ -113,10 +113,10 @@ public:
|
||||
{
|
||||
id_arr.reserve(256);
|
||||
}
|
||||
int newByteWordReg(hlType t, uint8_t regi);
|
||||
int newByteWordReg(hlType t, eReg regi);
|
||||
int newByteWordStk(hlType t, int off, uint8_t regOff);
|
||||
int newIntIdx(int16_t seg, int16_t off, uint8_t regi, int ix, hlType t);
|
||||
int newLongReg(hlType t, uint8_t regH, uint8_t regL, iICODE ix_);
|
||||
int newLongReg(hlType t, eReg regH, eReg regL, iICODE ix_);
|
||||
int newLong(opLoc sd, iICODE pIcode, hlFirst f, iICODE ix, operDu du, int off);
|
||||
int newLong(opLoc sd, iICODE pIcode, hlFirst f, iICODE ix, operDu du, iICODE atOffset);
|
||||
void newIdent(hlType t, frameType f);
|
||||
|
||||
@ -101,8 +101,14 @@ void BB::displayDfs()
|
||||
printf("----\n");
|
||||
|
||||
/* Recursive call on successors of current node */
|
||||
#ifdef _lint
|
||||
for (auto ik=edges.begin(); ik!=edges.end(); ++ik)
|
||||
{
|
||||
TYPEADR_TYPE &pb(*ik);
|
||||
#else
|
||||
for(TYPEADR_TYPE &pb : edges)
|
||||
{
|
||||
#endif
|
||||
if (pb.BBptr->traversed != DFS_DISP)
|
||||
pb.BBptr->displayDfs();
|
||||
}
|
||||
|
||||
108
src/ast.cpp
108
src/ast.cpp
@ -15,12 +15,12 @@
|
||||
using namespace std;
|
||||
// Index registers **** temp solution
|
||||
static const char * const idxReg[8] = {"bx+si", "bx+di", "bp+si", "bp+di",
|
||||
"si", "di", "bp", "bx" };
|
||||
"si", "di", "bp", "bx" };
|
||||
// Conditional operator symbols in C. Index by condOp enumeration type
|
||||
static const char * const condOpSym[] = { " <= ", " < ", " == ", " != ", " > ", " >= ",
|
||||
" & ", " | ", " ^ ", " ~ ",
|
||||
" + ", " - ", " * ", " / ",
|
||||
" >> ", " << ", " % ", " && ", " || " };
|
||||
" & ", " | ", " ^ ", " ~ ",
|
||||
" + ", " - ", " * ", " / ",
|
||||
" >> ", " << ", " % ", " && ", " || " };
|
||||
|
||||
//#define EXP_SIZE 200 /* Size of the expression buffer */
|
||||
|
||||
@ -132,6 +132,7 @@ COND_EXPR *GlobalVariable::Create(int16_t segValue, int16_t off)
|
||||
if (i == symtab.size())
|
||||
{
|
||||
printf ("Error, glob var not found in symtab\n");
|
||||
delete newExp;
|
||||
return 0;
|
||||
}
|
||||
newExp->expr.ident.idNode.globIdx = i;
|
||||
@ -140,7 +141,7 @@ COND_EXPR *GlobalVariable::Create(int16_t segValue, int16_t off)
|
||||
|
||||
|
||||
/* Returns an identifier conditional expression node of type REGISTER */
|
||||
COND_EXPR *COND_EXPR::idReg(uint8_t regi, uint32_t icodeFlg, LOCAL_ID *locsym)
|
||||
COND_EXPR *COND_EXPR::idReg(eReg regi, uint32_t icodeFlg, LOCAL_ID *locsym)
|
||||
{
|
||||
COND_EXPR *newExp;
|
||||
|
||||
@ -369,7 +370,7 @@ COND_EXPR *COND_EXPR::id(const LLInst &ll_insn, opLoc sd, Function * pProc, iICO
|
||||
else if (pm.regi < INDEXBASE) /* register */
|
||||
{
|
||||
newExp = COND_EXPR::idReg (pm.regi, (sd == SRC) ? ll_insn.getFlag() :
|
||||
ll_insn.getFlag() & NO_SRC_B,
|
||||
ll_insn.getFlag() & NO_SRC_B,
|
||||
&pProc->localId);
|
||||
duIcode.setRegDU( pm.regi, du);
|
||||
}
|
||||
@ -576,10 +577,10 @@ hlType expType (const COND_EXPR *expr, Function * pproc)
|
||||
/* Removes the register from the tree. If the register was part of a long
|
||||
* register (eg. dx:ax), the node gets transformed into an integer register
|
||||
* node. */
|
||||
void HlTypeSupport::performLongRemoval (uint8_t regi, LOCAL_ID *locId, COND_EXPR *tree)
|
||||
void HlTypeSupport::performLongRemoval (eReg regi, LOCAL_ID *locId, COND_EXPR *tree)
|
||||
{
|
||||
IDENTTYPE* ident; /* ptr to an identifier */
|
||||
uint8_t otherRegi; /* high or low part of long register */
|
||||
eReg otherRegi; /* high or low part of long register */
|
||||
|
||||
switch (tree->type) {
|
||||
case BOOLEAN_OP:
|
||||
@ -791,6 +792,7 @@ string walkCondExpr (const COND_EXPR* expr, Function * pProc, int* numLoc)
|
||||
|
||||
/* Makes a copy of the given expression. Allocates newExp storage for each
|
||||
* node. Returns the copy. */
|
||||
//lint -sem(COND_EXPR::clone, @p!=0)
|
||||
COND_EXPR *COND_EXPR::clone()
|
||||
{
|
||||
COND_EXPR* newExp=0; /* Expression node copy */
|
||||
@ -825,7 +827,7 @@ void COND_EXPR::changeBoolOp (condOp newOp)
|
||||
|
||||
/* Inserts the expression exp into the tree at the location specified by the
|
||||
* register regi */
|
||||
bool COND_EXPR::insertSubTreeReg (COND_EXPR *&tree, COND_EXPR *_expr, uint8_t regi,LOCAL_ID *locsym)
|
||||
bool COND_EXPR::insertSubTreeReg (COND_EXPR *&tree, COND_EXPR *_expr, eReg regi,LOCAL_ID *locsym)
|
||||
{
|
||||
if (tree == NULL)
|
||||
return false;
|
||||
@ -837,10 +839,16 @@ bool COND_EXPR::insertSubTreeReg (COND_EXPR *&tree, COND_EXPR *_expr, uint8_t re
|
||||
}
|
||||
return false;
|
||||
}
|
||||
COND_EXPR *COND_EXPR::insertSubTreeReg (COND_EXPR *_expr, uint8_t regi,LOCAL_ID *locsym)
|
||||
bool isSubRegisterOf(eReg reg,eReg parent)
|
||||
{
|
||||
HlTypeSupport *set_val;
|
||||
uint8_t treeReg;
|
||||
if ((parent < rAX) || (parent > rBX))
|
||||
return false; // only AX -> BX are coverede by subregisters
|
||||
return ((reg==subRegH(parent)) || (reg == subRegL(parent)));
|
||||
}
|
||||
COND_EXPR *COND_EXPR::insertSubTreeReg (COND_EXPR *_expr, eReg regi,LOCAL_ID *locsym)
|
||||
{
|
||||
//HlTypeSupport *set_val;
|
||||
eReg treeReg;
|
||||
COND_EXPR *temp;
|
||||
|
||||
switch (type) {
|
||||
@ -852,12 +860,9 @@ COND_EXPR *COND_EXPR::insertSubTreeReg (COND_EXPR *_expr, uint8_t regi,LOCAL_ID
|
||||
{
|
||||
return _expr;
|
||||
}
|
||||
else if ((regi >= rAX) && (regi <= rBX)) /* uint16_t/uint8_t reg */
|
||||
else if(isSubRegisterOf(treeReg,regi)) /* uint16_t/uint8_t reg */
|
||||
{
|
||||
if ((treeReg == (regi + rAL-1)) || (treeReg == (regi + rAH-1)))
|
||||
{
|
||||
return _expr;
|
||||
}
|
||||
return _expr;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
@ -887,10 +892,10 @@ COND_EXPR *COND_EXPR::insertSubTreeReg (COND_EXPR *_expr, uint8_t regi,LOCAL_ID
|
||||
return this;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
COND_EXPR *BinaryOperator::insertSubTreeReg(COND_EXPR *_expr, uint8_t regi, LOCAL_ID *locsym)
|
||||
COND_EXPR *BinaryOperator::insertSubTreeReg(COND_EXPR *_expr, eReg regi, LOCAL_ID *locsym)
|
||||
{
|
||||
COND_EXPR *r;
|
||||
r=m_lhs->insertSubTreeReg(_expr,regi,locsym);
|
||||
@ -924,7 +929,7 @@ bool COND_EXPR::insertSubTreeLongReg(COND_EXPR *_expr, COND_EXPR **tree, int lon
|
||||
}
|
||||
COND_EXPR *COND_EXPR::insertSubTreeLongReg(COND_EXPR *_expr, int longIdx)
|
||||
{
|
||||
COND_EXPR *temp;
|
||||
COND_EXPR *temp;
|
||||
switch (type)
|
||||
{
|
||||
case IDENTIFIER:
|
||||
@ -952,12 +957,12 @@ COND_EXPR *COND_EXPR::insertSubTreeLongReg(COND_EXPR *_expr, int longIdx)
|
||||
case NEGATION:
|
||||
case ADDRESSOF:
|
||||
case DEREFERENCE:
|
||||
COND_EXPR *temp = expr.unaryExp->insertSubTreeLongReg(_expr,longIdx);
|
||||
temp = expr.unaryExp->insertSubTreeLongReg(_expr,longIdx);
|
||||
if (nullptr!=temp)
|
||||
{
|
||||
expr.unaryExp = temp;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
return nullptr;
|
||||
@ -999,38 +1004,9 @@ void COND_EXPR::release()
|
||||
}
|
||||
delete (this);
|
||||
}
|
||||
|
||||
//
|
||||
COND_EXPR *BinaryOperator::inverse()
|
||||
{
|
||||
static condOp invCondOp[] = {GREATER, GREATER_EQUAL, NOT_EQUAL, EQUAL,
|
||||
LESS_EQUAL, LESS, DUMMY,DUMMY,DUMMY,DUMMY,
|
||||
DUMMY, DUMMY, DUMMY, DUMMY, DUMMY, DUMMY,
|
||||
DUMMY, DBL_OR, DBL_AND};
|
||||
BinaryOperator *res=0;
|
||||
switch (m_op)
|
||||
{
|
||||
case LESS_EQUAL: case LESS: case EQUAL:
|
||||
case NOT_EQUAL: case GREATER: case GREATER_EQUAL:
|
||||
res = static_cast<BinaryOperator *>(clone());
|
||||
res->m_op = invCondOp[m_op];
|
||||
return res;
|
||||
|
||||
case AND: case OR: case XOR: case NOT: case ADD:
|
||||
case SUB: case MUL: case DIV: case SHR: case SHL: case MOD:
|
||||
return COND_EXPR::unary (NEGATION, clone());
|
||||
|
||||
case DBL_AND: case DBL_OR:
|
||||
res = static_cast<BinaryOperator *>(clone());
|
||||
res->m_op = invCondOp[m_op];
|
||||
res->m_lhs=m_lhs->inverse ();
|
||||
res->m_rhs=m_rhs->inverse ();
|
||||
return res;
|
||||
} /* eos */
|
||||
assert(false);
|
||||
}
|
||||
/* Makes a copy of the given expression. Allocates newExp storage for each
|
||||
* node. Returns the copy. */
|
||||
//lint -sem(BinaryOperator::clone, @p!=0)
|
||||
COND_EXPR *BinaryOperator::clone()
|
||||
{
|
||||
BinaryOperator* newExp=new BinaryOperator(m_op); /* Expression node copy */
|
||||
@ -1038,3 +1014,31 @@ COND_EXPR *BinaryOperator::clone()
|
||||
newExp->m_rhs = m_rhs->clone();
|
||||
return newExp;
|
||||
}
|
||||
|
||||
COND_EXPR *BinaryOperator::inverse()
|
||||
{
|
||||
static condOp invCondOp[] = {GREATER, GREATER_EQUAL, NOT_EQUAL, EQUAL,
|
||||
LESS_EQUAL, LESS, DUMMY,DUMMY,DUMMY,DUMMY,
|
||||
DUMMY, DUMMY, DUMMY, DUMMY, DUMMY, DUMMY,
|
||||
DUMMY, DBL_OR, DBL_AND};
|
||||
BinaryOperator *res=reinterpret_cast<BinaryOperator *>(this->clone());
|
||||
switch (m_op)
|
||||
{
|
||||
case LESS_EQUAL: case LESS: case EQUAL:
|
||||
case NOT_EQUAL: case GREATER: case GREATER_EQUAL:
|
||||
res->m_op = invCondOp[m_op];
|
||||
return res;
|
||||
|
||||
case AND: case OR: case XOR: case NOT: case ADD:
|
||||
case SUB: case MUL: case DIV: case SHR: case SHL: case MOD:
|
||||
return COND_EXPR::unary (NEGATION, res);
|
||||
|
||||
case DBL_AND: case DBL_OR:
|
||||
res->m_op = invCondOp[m_op];
|
||||
res->m_lhs=m_lhs->inverse ();
|
||||
res->m_rhs=m_rhs->inverse ();
|
||||
return res;
|
||||
} /* eos */
|
||||
assert(false);
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -225,7 +225,7 @@ static void writeBitVector (const std::bitset<32> ®i)
|
||||
* the code; that is, the target code has not been traversed yet. */
|
||||
static void emitFwdGotoLabel (ICODE * pt, int indLevel)
|
||||
{
|
||||
if ( not pt->ll()->testFlags(HLL_LABEL)) /* node hasn't got a lab */
|
||||
if ( ! pt->ll()->testFlags(HLL_LABEL) ) /* node hasn't got a lab */
|
||||
{
|
||||
/* Generate new label */
|
||||
pt->ll()->hllLabNum = getNextLabel();
|
||||
|
||||
@ -76,8 +76,16 @@ void Function::findImmedDom ()
|
||||
currNode = m_dfsLast[currIdx];
|
||||
if (currNode->flg & INVALID_BB) /* Do not process invalid BBs */
|
||||
continue;
|
||||
#ifdef _lint
|
||||
BB * inedge=0;
|
||||
for (auto i=currNode->inEdges.begin(); i!=currNode->inEdges.end(); ++i)
|
||||
{
|
||||
inedge=*i;
|
||||
|
||||
#else
|
||||
for (BB * inedge : currNode->inEdges)
|
||||
{
|
||||
#endif
|
||||
predIdx = inedge->dfsLastNum;
|
||||
if (predIdx < currIdx)
|
||||
currNode->immedDom = commonDom (currNode->immedDom, predIdx, this);
|
||||
@ -255,12 +263,32 @@ static void findNodesInInt (queue &intNodes, int level, interval *Ii)
|
||||
{
|
||||
if (level == 1)
|
||||
{
|
||||
#ifdef _lint
|
||||
BB * en=0;
|
||||
for (auto i=Ii->nodes.begin(); i!=Ii->nodes.end(); ++i)
|
||||
{
|
||||
en=*i;
|
||||
|
||||
#else
|
||||
for(BB *en : Ii->nodes)
|
||||
{
|
||||
#endif
|
||||
appendQueue(intNodes,en);
|
||||
}
|
||||
}
|
||||
else
|
||||
#ifdef _lint
|
||||
BB * en=0;
|
||||
for (auto i=Ii->nodes.begin(); i!=Ii->nodes.end(); ++i)
|
||||
{
|
||||
en=*i;
|
||||
|
||||
#else
|
||||
for(BB *en : Ii->nodes)
|
||||
{
|
||||
#endif
|
||||
findNodesInInt(intNodes,level-1,en->correspInt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -403,8 +431,14 @@ void Function::structCases()
|
||||
* header field with caseHeader. */
|
||||
insertList (caseNodes, i);
|
||||
m_dfsLast[i]->caseHead = i;
|
||||
#ifdef _lint
|
||||
for (auto ki=caseHeader->edges.begin(); ki!=caseHeader->edges.end(); ++ki)
|
||||
{
|
||||
TYPEADR_TYPE &pb(*ki);
|
||||
#else
|
||||
for(TYPEADR_TYPE &pb : caseHeader->edges)
|
||||
{
|
||||
#endif
|
||||
tagNodesInCase(pb.BBptr, caseNodes, i, exitNode);
|
||||
}
|
||||
//for (j = 0; j < caseHeader->edges[j]; j++)
|
||||
|
||||
@ -317,8 +317,16 @@ void Function::liveRegAnalysis (std::bitset<32> &in_liveOut)
|
||||
}
|
||||
else /* Check successors */
|
||||
{
|
||||
#ifdef _lint
|
||||
for (auto i=pbb->edges.begin(); i!=pbb->edges.end(); ++i)
|
||||
{
|
||||
TYPEADR_TYPE &e(*i);
|
||||
#else
|
||||
for(TYPEADR_TYPE &e : pbb->edges)
|
||||
{
|
||||
#endif
|
||||
pbb->liveOut |= e.BBptr->liveIn;
|
||||
}
|
||||
|
||||
/* propagate to invoked procedure */
|
||||
if (pbb->nodeType == CALL_NODE)
|
||||
@ -392,7 +400,8 @@ void Function::liveRegAnalysis (std::bitset<32> &in_liveOut)
|
||||
|
||||
void BB::genDU1()
|
||||
{
|
||||
uint8_t regi; /* Register that was defined */
|
||||
eReg regi; /* Register that was defined */
|
||||
|
||||
int k, defRegIdx, useIdx;
|
||||
iICODE picode, ticode,lastInst;
|
||||
BB *tbb; /* Target basic block */
|
||||
@ -407,7 +416,7 @@ void BB::genDU1()
|
||||
{
|
||||
if (picode->type != HIGH_LEVEL)
|
||||
continue;
|
||||
regi = 0;
|
||||
regi = rUNDEF;
|
||||
defRegIdx = 0;
|
||||
// foreach defined register
|
||||
bitset<32> processed=0;
|
||||
@ -417,7 +426,7 @@ void BB::genDU1()
|
||||
continue;
|
||||
//printf("Processing reg")
|
||||
processed |= duReg[k];
|
||||
regi = (uint8_t)(k + 1); /* defined register */
|
||||
regi = (eReg)(k + 1); /* defined register */
|
||||
picode->du1.regi[defRegIdx] = regi;
|
||||
|
||||
/* Check remaining instructions of the BB for all uses
|
||||
@ -486,9 +495,9 @@ void BB::genDU1()
|
||||
* from a library function (routines such as printf
|
||||
* return an integer, which is normally not taken into
|
||||
* account by the programmer). */
|
||||
if (picode->valid() and not picode->du1.used(defRegIdx) and
|
||||
(not (picode->du.lastDefRegi & duReg[regi]).any()) &&
|
||||
(not ((picode->hl()->opcode == HLI_CALL) &&
|
||||
if (picode->valid() && ! picode->du1.used(defRegIdx) &&
|
||||
( ! (picode->du.lastDefRegi & duReg[regi]).any()) &&
|
||||
( ! ((picode->hl()->opcode == HLI_CALL) &&
|
||||
(picode->hl()->call.proc->flg & PROC_ISLIB))))
|
||||
{
|
||||
if (! (this->liveOut & duReg[regi]).any()) /* not liveOut */
|
||||
@ -521,17 +530,16 @@ void BB::genDU1()
|
||||
/* Generates the du chain of each instruction in a basic block */
|
||||
void Function::genDU1 ()
|
||||
{
|
||||
uint8_t regi; /* Register that was defined */
|
||||
int i, k, defRegIdx, useIdx;
|
||||
iICODE picode, ticode,lastInst;/* Current and target bb */
|
||||
BB * pbb, *tbb; /* Current and target basic block */
|
||||
bool res;
|
||||
//COND_EXPR *exp, *lhs;
|
||||
|
||||
/* Traverse tree in dfsLast order */
|
||||
assert(m_dfsLast.size()==numBBs);
|
||||
#ifdef _lint
|
||||
for (auto i=m_dfsLast.begin(); i!=m_dfsLast.end(); ++i)
|
||||
{
|
||||
BB *pbb(*i);
|
||||
#else
|
||||
for(BB *pbb : m_dfsLast)
|
||||
{
|
||||
#endif
|
||||
if (pbb->flg & INVALID_BB)
|
||||
continue;
|
||||
pbb->genDU1();
|
||||
@ -665,7 +673,7 @@ bool BinaryOperator::xClear(iICODE f, iICODE t, iICODE lastBBinst, Function *ppr
|
||||
{
|
||||
if(0==m_rhs)
|
||||
return false;
|
||||
if ( not m_rhs->xClear (f, t, lastBBinst, pproc) )
|
||||
if ( ! m_rhs->xClear (f, t, lastBBinst, pproc) )
|
||||
return false;
|
||||
if(0==m_lhs)
|
||||
return false;
|
||||
|
||||
@ -229,8 +229,14 @@ void disassem(int pass, Function * ppProc)
|
||||
{
|
||||
/* Bind jump offsets to labels */
|
||||
//for (i = 0; i < numIcode; i++)
|
||||
#ifdef _lint
|
||||
for (auto i=pc.begin(); i!=pc.end(); ++i)
|
||||
{
|
||||
ICODE &icode(*i);
|
||||
#else
|
||||
for( ICODE &icode : pc)
|
||||
{
|
||||
#endif
|
||||
LLInst *ll=icode.ll();
|
||||
ll->findJumpTargets(pc);
|
||||
}
|
||||
@ -245,8 +251,14 @@ void disassem(int pass, Function * ppProc)
|
||||
|
||||
/* Loop over array printing each record */
|
||||
nextInst = 0;
|
||||
#ifdef _lint
|
||||
for (auto i=pc.begin(); i!=pc.end(); ++i)
|
||||
{
|
||||
ICODE &icode(*i);
|
||||
#else
|
||||
for( ICODE &icode : pc)
|
||||
{
|
||||
#endif
|
||||
icode.ll()->dis1Line(icode.loc_ip,pass);
|
||||
}
|
||||
|
||||
|
||||
@ -10,28 +10,32 @@
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "dcc.h"
|
||||
#ifdef _lint
|
||||
static std::map<eErrorId,std::string> errorMessage;
|
||||
#else
|
||||
static std::map<eErrorId,std::string> errorMessage =
|
||||
{
|
||||
{INVALID_ARG ,"Invalid option -%c\n"},
|
||||
{INVALID_OPCODE ,"Invalid instruction %02X at location %06lX\n"},
|
||||
{INVALID_386OP ,"Don't understand 80386 instruction %02X at location %06lX\n"},
|
||||
{FUNNY_SEGOVR ,"Segment override with no memory operand at location %06lX\n"},
|
||||
{FUNNY_REP ,"REP prefix without a string instruction at location %06lX\n"},
|
||||
{CANNOT_OPEN ,"Cannot open %s\n"},
|
||||
{CANNOT_READ ,"Error while reading %s\n"},
|
||||
{MALLOC_FAILED ,"malloc of %ld bytes failed\n"},
|
||||
{NEWEXE_FORMAT ,"Don't understand new EXE format\n"},
|
||||
{NO_BB ,"Failed to find a BB for jump to %ld in proc %s\n"},
|
||||
{INVALID_SYNTHETIC_BB,"Basic Block is a synthetic jump\n"},
|
||||
{INVALID_INT_BB ,"Failed to find a BB for interval\n"},
|
||||
{IP_OUT_OF_RANGE ,"Instruction at location %06lX goes beyond loaded image\n"},
|
||||
{DEF_NOT_FOUND ,"Definition not found for condition code usage at opcode %d\n"},
|
||||
{JX_NOT_DEF ,"JX use, definition not supported at opcode #%d\n"},
|
||||
{NOT_DEF_USE ,"Def - use not supported. Def op = %d, use op = %d.\n"},
|
||||
{REPEAT_FAIL ,"Failed to construct repeat..until() condition.\n"},
|
||||
{WHILE_FAIL ,"Failed to construct while() condition.\n"},
|
||||
};
|
||||
#endif
|
||||
|
||||
static std::map<eErrorId,std::string> errorMessage =
|
||||
{
|
||||
{INVALID_ARG ,"Invalid option -%c\n"},
|
||||
{INVALID_OPCODE ,"Invalid instruction %02X at location %06lX\n"},
|
||||
{INVALID_386OP ,"Don't understand 80386 instruction %02X at location %06lX\n"},
|
||||
{FUNNY_SEGOVR ,"Segment override with no memory operand at location %06lX\n"},
|
||||
{FUNNY_REP ,"REP prefix without a string instruction at location %06lX\n"},
|
||||
{CANNOT_OPEN ,"Cannot open %s\n"},
|
||||
{CANNOT_READ ,"Error while reading %s\n"},
|
||||
{MALLOC_FAILED ,"malloc of %ld bytes failed\n"},
|
||||
{NEWEXE_FORMAT ,"Don't understand new EXE format\n"},
|
||||
{NO_BB ,"Failed to find a BB for jump to %ld in proc %s\n"},
|
||||
{INVALID_SYNTHETIC_BB,"Basic Block is a synthetic jump\n"},
|
||||
{INVALID_INT_BB ,"Failed to find a BB for interval\n"},
|
||||
{IP_OUT_OF_RANGE ,"Instruction at location %06lX goes beyond loaded image\n"},
|
||||
{DEF_NOT_FOUND ,"Definition not found for condition code usage at opcode %d\n"},
|
||||
{JX_NOT_DEF ,"JX use, definition not supported at opcode #%d\n"},
|
||||
{NOT_DEF_USE ,"Def - use not supported. Def op = %d, use op = %d.\n"},
|
||||
{REPEAT_FAIL ,"Failed to construct repeat..until() condition.\n"},
|
||||
{WHILE_FAIL ,"Failed to construct while() condition.\n"},
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
fatalError: displays error message and exits the program.
|
||||
|
||||
@ -75,8 +75,14 @@ void FrontEnd (char *filename, CALL_GRAPH * *pcallGraph)
|
||||
}
|
||||
|
||||
/* Search through code looking for impure references and flag them */
|
||||
#ifdef _lint
|
||||
for (auto i=pProcList.begin(); i!=pProcList.end(); ++i)
|
||||
{
|
||||
Function &f(*i);
|
||||
#else
|
||||
for(Function &f : pProcList)
|
||||
{
|
||||
#endif
|
||||
f.markImpure();
|
||||
if (option.asm1)
|
||||
disassem(1, &f);
|
||||
@ -87,9 +93,16 @@ void FrontEnd (char *filename, CALL_GRAPH * *pcallGraph)
|
||||
}
|
||||
|
||||
/* Converts jump target addresses to icode offsets */
|
||||
#ifdef _lint
|
||||
for (auto i=pProcList.begin(); i!=pProcList.end(); ++i)
|
||||
{
|
||||
Function &f(*i);
|
||||
#else
|
||||
for(Function &f : pProcList)
|
||||
{
|
||||
#endif
|
||||
f.bindIcodeOff();
|
||||
|
||||
}
|
||||
/* Print memory bitmap */
|
||||
if (option.Map)
|
||||
displayMemMap();
|
||||
|
||||
@ -157,7 +157,7 @@ CondJumps:
|
||||
fatalError(NO_BB, ip, name.c_str());
|
||||
psBB = *iter2;
|
||||
pBB->edges[i].BBptr = psBB;
|
||||
psBB->inEdges.push_back(0);
|
||||
psBB->inEdges.push_back((BB *)nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -165,8 +165,14 @@ CondJumps:
|
||||
void Function::markImpure()
|
||||
{
|
||||
SYM * psym;
|
||||
#ifdef _lint
|
||||
for (auto i=Icode.begin(); i!=Icode.end(); ++i)
|
||||
{
|
||||
ICODE &icod(*i);
|
||||
#else
|
||||
for(ICODE &icod : Icode)
|
||||
{
|
||||
#endif
|
||||
if ( not icod.ll()->testFlags(SYM_USE | SYM_DEF))
|
||||
continue;
|
||||
psym = &symtab[icod.ll()->caseTbl.numEntries];
|
||||
@ -194,8 +200,16 @@ void Function::markImpure()
|
||||
****************************************************************************/
|
||||
void Function::freeCFG()
|
||||
{
|
||||
#ifdef _lint
|
||||
for (auto i=heldBBs.begin(); i!=heldBBs.end(); ++i)
|
||||
{
|
||||
BB *p(*i);
|
||||
#else
|
||||
for(BB *p : heldBBs)
|
||||
{
|
||||
#endif
|
||||
delete p;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -283,7 +297,7 @@ BB *BB::rmJMP(int marker, BB * pBB)
|
||||
pBB->inEdges.pop_back();
|
||||
if (not pBB->inEdges.empty())
|
||||
{
|
||||
pBB->edges[0].BBptr->inEdges.push_back(0);
|
||||
pBB->edges[0].BBptr->inEdges.push_back((BB *)nullptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -383,8 +397,14 @@ void BB::dfsNumbering(std::vector<BB *> &dfsLast, int *first, int *last)
|
||||
|
||||
/* index is being used as an index to inEdges[]. */
|
||||
// for (i = 0; i < edges.size(); i++)
|
||||
for (auto edge : edges)
|
||||
#ifdef _lint
|
||||
for (auto i=edges.begin(); i!=edges.end(); ++i)
|
||||
{
|
||||
auto edge(*i);
|
||||
#else
|
||||
for(auto edge : edges)
|
||||
{
|
||||
#endif
|
||||
pChild = edge.BBptr;
|
||||
pChild->inEdges[pChild->index++] = this;
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@ using namespace std;
|
||||
#define ICODE_DELTA 25
|
||||
|
||||
/* Masks off bits set by duReg[] */
|
||||
uint32_t maskDuReg[] = { 0x00,
|
||||
std::bitset<32> maskDuReg[] = { 0x00,
|
||||
0xFEEFFE, 0xFDDFFD, 0xFBB00B, 0xF77007, /* uint16_t regs */
|
||||
0xFFFFEF, 0xFFFFDF, 0xFFFFBF, 0xFFFF7F,
|
||||
0xFFFEFF, 0xFFFDFF, 0xFFFBFF, 0xFFF7FF, /* seg regs */
|
||||
@ -86,7 +86,7 @@ void ICODE ::invalidate()
|
||||
* If all registers
|
||||
* of this instruction are unused, the instruction is invalidated (ie. removed)
|
||||
*/
|
||||
bool ICODE::removeDefRegi (uint8_t regi, int thisDefIdx, LOCAL_ID *locId)
|
||||
bool ICODE::removeDefRegi (eReg regi, int thisDefIdx, LOCAL_ID *locId)
|
||||
{
|
||||
int numDefs;
|
||||
|
||||
@ -634,8 +634,14 @@ void ICODE::writeDU(int idx)
|
||||
if (du1.used(i))
|
||||
{
|
||||
printf ("%d: du1[%d][] = ", idx, i);
|
||||
for(std::list<ICODE>::iterator j : du1.idx[i].uses)
|
||||
#ifdef _lint
|
||||
for (auto ik=du1.idx[i].uses.begin(); ik!=du1.idx[i].uses.end(); ++ik)
|
||||
{
|
||||
auto j(*ik);
|
||||
#else
|
||||
for(auto j : du1.idx[i].uses)
|
||||
{
|
||||
#endif
|
||||
printf ("%d ", j->loc_ip);
|
||||
}
|
||||
printf ("\n");
|
||||
|
||||
@ -29,10 +29,18 @@ ICODE * CIcodeRec::addIcode(ICODE *pIcode)
|
||||
|
||||
void CIcodeRec::SetInBB(int start, int end, BB *pnewBB)
|
||||
{
|
||||
#ifdef _lint
|
||||
for (auto ik=this->begin(); ik!=this->end(); ++ik)
|
||||
{
|
||||
ICODE &icode(*ik);
|
||||
#else
|
||||
for(ICODE &icode : *this)
|
||||
{
|
||||
#endif
|
||||
if((icode.loc_ip>=start) and (icode.loc_ip<=end))
|
||||
icode.inBB = pnewBB;
|
||||
// for (int i = start; i <= end; i++)
|
||||
}
|
||||
// for (int i = start; i <= end; i++)
|
||||
// at(i).inBB = pnewBB;
|
||||
}
|
||||
|
||||
|
||||
214
src/idioms.cpp
214
src/idioms.cpp
@ -24,13 +24,13 @@ bool LLInst::isJmpInst()
|
||||
{
|
||||
switch (opcode)
|
||||
{
|
||||
case iJMP: case iJMPF: case iJCXZ:
|
||||
case iLOOP: case iLOOPE:case iLOOPNE:
|
||||
case iJB: case iJBE: case iJAE: case iJA:
|
||||
case iJL: case iJLE: case iJGE: case iJG:
|
||||
case iJE: case iJNE: case iJS: case iJNS:
|
||||
case iJO: case iJNO: case iJP: case iJNP:
|
||||
return true;
|
||||
case iJMP: case iJMPF: case iJCXZ:
|
||||
case iLOOP: case iLOOPE:case iLOOPNE:
|
||||
case iJB: case iJBE: case iJAE: case iJA:
|
||||
case iJL: case iJLE: case iJGE: case iJG:
|
||||
case iJE: case iJNE: case iJS: case iJNS:
|
||||
case iJO: case iJNO: case iJP: case iJNP:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -40,7 +40,7 @@ bool LLInst::isJmpInst()
|
||||
****************************************************************************/
|
||||
void Function::findIdioms()
|
||||
{
|
||||
// int ip; /* Index to current icode */
|
||||
// int ip; /* Index to current icode */
|
||||
iICODE pEnd, pIcode; /* Pointers to end of BB and current icodes */
|
||||
int16_t delta;
|
||||
|
||||
@ -81,7 +81,7 @@ void Function::findIdioms()
|
||||
{
|
||||
switch (pIcode->ll()->getOpcode())
|
||||
{
|
||||
case iDEC: case iINC:
|
||||
case iDEC: case iINC:
|
||||
if (i18.match(pIcode))
|
||||
advance(pIcode,i18.action());
|
||||
else if (i19.match(pIcode))
|
||||
@ -96,8 +96,8 @@ void Function::findIdioms()
|
||||
{
|
||||
/* Idiom 1 */
|
||||
// todo add other push idioms.
|
||||
advance(pIcode,i01(pIcode));
|
||||
break;
|
||||
advance(pIcode,i01(pIcode));
|
||||
break;
|
||||
}
|
||||
|
||||
case iMOV:
|
||||
@ -113,93 +113,93 @@ void Function::findIdioms()
|
||||
break;
|
||||
}
|
||||
|
||||
case iCALL: case iCALLF:
|
||||
/* Check for library functions that return a long register.
|
||||
case iCALL: case iCALLF:
|
||||
/* Check for library functions that return a long register.
|
||||
* Propagate this result */
|
||||
if (pIcode->ll()->src.proc.proc != 0)
|
||||
if ((pIcode->ll()->src.proc.proc->flg & PROC_ISLIB) &&
|
||||
if (pIcode->ll()->src.proc.proc != 0)
|
||||
if ((pIcode->ll()->src.proc.proc->flg & PROC_ISLIB) &&
|
||||
(pIcode->ll()->src.proc.proc->flg & PROC_IS_FUNC))
|
||||
{
|
||||
if ((pIcode->ll()->src.proc.proc->retVal.type==TYPE_LONG_SIGN)
|
||||
|| (pIcode->ll()->src.proc.proc->retVal.type == TYPE_LONG_UNSIGN))
|
||||
localId.newLongReg(TYPE_LONG_SIGN, rDX, rAX, pIcode/*ip*/);
|
||||
}
|
||||
|
||||
/* Check for idioms */
|
||||
if (i03.match(pIcode)) /* idiom 3 */
|
||||
advance(pIcode,i03.action());
|
||||
else if (i17.match(pIcode)) /* idiom 17 */
|
||||
advance(pIcode,i17.action());
|
||||
else
|
||||
pIcode++;
|
||||
break;
|
||||
|
||||
case iRET: /* Idiom 4 */
|
||||
case iRETF:
|
||||
advance(pIcode,i04(pIcode));
|
||||
break;
|
||||
|
||||
case iADD: /* Idiom 5 */
|
||||
advance(pIcode,i05(pIcode));
|
||||
break;
|
||||
|
||||
case iSAR: /* Idiom 8 */
|
||||
advance(pIcode,i08(pIcode));
|
||||
break;
|
||||
|
||||
case iSHL:
|
||||
if (i15.match(pIcode)) /* idiom 15 */
|
||||
advance(pIcode,i15.action());
|
||||
else if (i12.match(pIcode)) /* idiom 12 */
|
||||
advance(pIcode,i12.action());
|
||||
else
|
||||
pIcode++;
|
||||
break;
|
||||
|
||||
case iSHR: /* Idiom 9 */
|
||||
advance(pIcode,i09(pIcode));
|
||||
break;
|
||||
|
||||
case iSUB: /* Idiom 6 */
|
||||
advance(pIcode,i06(pIcode));
|
||||
break;
|
||||
|
||||
case iOR: /* Idiom 10 */
|
||||
advance(pIcode,i10(pIcode));
|
||||
break;
|
||||
|
||||
case iNEG: /* Idiom 11 */
|
||||
if (i11.match(pIcode))
|
||||
advance(pIcode,i11.action());
|
||||
else if (i16.match(pIcode))
|
||||
advance(pIcode,i16.action());
|
||||
else
|
||||
pIcode++;
|
||||
break;
|
||||
|
||||
case iNOP:
|
||||
(pIcode++)->invalidate();
|
||||
break;
|
||||
|
||||
case iENTER: /* ENTER is equivalent to init PUSH bp */
|
||||
if (pIcode == Icode.begin()) //ip == 0
|
||||
{
|
||||
flg |= (PROC_HLL | PROC_IS_HLL);
|
||||
if ((pIcode->ll()->src.proc.proc->retVal.type==TYPE_LONG_SIGN)
|
||||
|| (pIcode->ll()->src.proc.proc->retVal.type == TYPE_LONG_UNSIGN))
|
||||
localId.newLongReg(TYPE_LONG_SIGN, rDX, rAX, pIcode/*ip*/);
|
||||
}
|
||||
pIcode++;
|
||||
break;
|
||||
|
||||
case iXOR: /* Idiom 7 */
|
||||
if (i21.match(pIcode))
|
||||
advance(pIcode,i21.action());
|
||||
else if (i07.match(pIcode))
|
||||
advance(pIcode,i07.action());
|
||||
else
|
||||
++pIcode;
|
||||
break;
|
||||
|
||||
default:
|
||||
/* Check for idioms */
|
||||
if (i03.match(pIcode)) /* idiom 3 */
|
||||
advance(pIcode,i03.action());
|
||||
else if (i17.match(pIcode)) /* idiom 17 */
|
||||
advance(pIcode,i17.action());
|
||||
else
|
||||
pIcode++;
|
||||
break;
|
||||
|
||||
case iRET: /* Idiom 4 */
|
||||
case iRETF:
|
||||
advance(pIcode,i04(pIcode));
|
||||
break;
|
||||
|
||||
case iADD: /* Idiom 5 */
|
||||
advance(pIcode,i05(pIcode));
|
||||
break;
|
||||
|
||||
case iSAR: /* Idiom 8 */
|
||||
advance(pIcode,i08(pIcode));
|
||||
break;
|
||||
|
||||
case iSHL:
|
||||
if (i15.match(pIcode)) /* idiom 15 */
|
||||
advance(pIcode,i15.action());
|
||||
else if (i12.match(pIcode)) /* idiom 12 */
|
||||
advance(pIcode,i12.action());
|
||||
else
|
||||
pIcode++;
|
||||
break;
|
||||
|
||||
case iSHR: /* Idiom 9 */
|
||||
advance(pIcode,i09(pIcode));
|
||||
break;
|
||||
|
||||
case iSUB: /* Idiom 6 */
|
||||
advance(pIcode,i06(pIcode));
|
||||
break;
|
||||
|
||||
case iOR: /* Idiom 10 */
|
||||
advance(pIcode,i10(pIcode));
|
||||
break;
|
||||
|
||||
case iNEG: /* Idiom 11 */
|
||||
if (i11.match(pIcode))
|
||||
advance(pIcode,i11.action());
|
||||
else if (i16.match(pIcode))
|
||||
advance(pIcode,i16.action());
|
||||
else
|
||||
pIcode++;
|
||||
break;
|
||||
|
||||
case iNOP:
|
||||
(pIcode++)->invalidate();
|
||||
break;
|
||||
|
||||
case iENTER: /* ENTER is equivalent to init PUSH bp */
|
||||
if (pIcode == Icode.begin()) //ip == 0
|
||||
{
|
||||
flg |= (PROC_HLL | PROC_IS_HLL);
|
||||
}
|
||||
pIcode++;
|
||||
break;
|
||||
|
||||
case iXOR: /* Idiom 7 */
|
||||
if (i21.match(pIcode))
|
||||
advance(pIcode,i21.action());
|
||||
else if (i07.match(pIcode))
|
||||
advance(pIcode,i07.action());
|
||||
else
|
||||
++pIcode;
|
||||
break;
|
||||
|
||||
default:
|
||||
pIcode++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -230,8 +230,14 @@ void Function::bindIcodeOff()
|
||||
pIcode = Icode.begin();
|
||||
|
||||
/* Flag all jump targets for BB construction and disassembly stage 2 */
|
||||
#ifdef _lint
|
||||
for (auto ik=Icode.begin(); ik!=Icode.end(); ++ik)
|
||||
{
|
||||
ICODE &c(*ik);
|
||||
#else
|
||||
for(ICODE &c : Icode)
|
||||
{
|
||||
{
|
||||
#endif
|
||||
LLInst *ll=c.ll();
|
||||
if (ll->testFlags(I) && ll->isJmpInst())
|
||||
{
|
||||
@ -245,27 +251,33 @@ void Function::bindIcodeOff()
|
||||
* is found (no code at dest. of jump) are simply left unlinked and
|
||||
* flagged as going nowhere. */
|
||||
//for (pIcode = Icode.begin(); pIcode!= Icode.end(); pIcode++)
|
||||
#ifdef _lint
|
||||
for (auto ik=Icode.begin(); ik!=Icode.end(); ++ik)
|
||||
{
|
||||
ICODE &icode(*ik);
|
||||
#else
|
||||
for(ICODE &icode : Icode)
|
||||
{
|
||||
{
|
||||
#endif
|
||||
LLInst *ll=icode.ll();
|
||||
if (not ll->isJmpInst())
|
||||
continue;
|
||||
if (ll->testFlags(I) )
|
||||
{
|
||||
uint32_t found;
|
||||
{
|
||||
uint32_t found;
|
||||
if (! Icode.labelSrch(ll->src.op(), found))
|
||||
ll->setFlags( NO_LABEL );
|
||||
else
|
||||
else
|
||||
ll->src.SetImmediateOp(found);
|
||||
|
||||
}
|
||||
}
|
||||
else if (ll->testFlags(SWITCH) )
|
||||
{
|
||||
{
|
||||
p = ll->caseTbl.entries;
|
||||
for (int j = 0; j < ll->caseTbl.numEntries; j++, p++)
|
||||
Icode.labelSrch(*p, *p);
|
||||
}
|
||||
Icode.labelSrch(*p, *p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Performs idioms analysis, and propagates long operands, if any */
|
||||
|
||||
@ -123,8 +123,14 @@ bool Idiom1::match(iICODE picode)
|
||||
}
|
||||
int Idiom1::action()
|
||||
{
|
||||
#ifdef _lint
|
||||
for (auto ik=m_icodes.begin(); ik!=m_icodes.end(); ++ik)
|
||||
{
|
||||
iICODE ic(*ik);
|
||||
#else
|
||||
for(iICODE ic : m_icodes)
|
||||
{
|
||||
#endif
|
||||
ic->invalidate();
|
||||
}
|
||||
m_func->flg |= PROC_HLL;
|
||||
|
||||
@ -76,8 +76,8 @@ bool Idiom13::match(iICODE pIcode)
|
||||
return false;
|
||||
m_icodes[0]=pIcode++;
|
||||
m_icodes[1]=pIcode++;
|
||||
m_loaded_reg = 0;
|
||||
uint8_t regi;
|
||||
m_loaded_reg = rUNDEF;
|
||||
eReg regi;
|
||||
|
||||
/* Check for regL */
|
||||
regi = m_icodes[0]->ll()->dst.regi;
|
||||
@ -88,7 +88,7 @@ bool Idiom13::match(iICODE pIcode)
|
||||
{
|
||||
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=(eReg)(regi - rAL + rAX);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ int Idiom8::action()
|
||||
{
|
||||
int idx;
|
||||
COND_EXPR *rhs,*lhs,*expr;
|
||||
uint8_t regH,regL;
|
||||
eReg regH,regL;
|
||||
regH=m_icodes[0]->ll()->dst.regi;
|
||||
regL=m_icodes[1]->ll()->dst.regi;
|
||||
idx = m_func->localId.newLongReg (TYPE_LONG_SIGN, regH, regL, m_icodes[0]);
|
||||
@ -119,7 +119,7 @@ int Idiom12::action()
|
||||
{
|
||||
int idx;
|
||||
COND_EXPR *rhs,*lhs,*expr;
|
||||
uint8_t regH,regL;
|
||||
eReg regH,regL;
|
||||
regL=m_icodes[0]->ll()->dst.regi;
|
||||
regH=m_icodes[1]->ll()->dst.regi;
|
||||
|
||||
@ -158,7 +158,7 @@ int Idiom9::action()
|
||||
{
|
||||
int idx;
|
||||
COND_EXPR *rhs,*lhs,*expr;
|
||||
uint8_t regH,regL;
|
||||
eReg regH,regL;
|
||||
regL=m_icodes[1]->ll()->dst.regi;
|
||||
regH=m_icodes[0]->ll()->dst.regi;
|
||||
idx = m_func->localId.newLongReg (TYPE_LONG_UNSIGN,regH,regL,m_icodes[0]);
|
||||
|
||||
@ -41,7 +41,7 @@ void LOCAL_ID::newIdent(hlType t, frameType f)
|
||||
|
||||
/* Creates a new register identifier node of TYPE_BYTE_(UN)SIGN or
|
||||
* TYPE_WORD_(UN)SIGN type. Returns the index to this new entry. */
|
||||
int LOCAL_ID::newByteWordReg(hlType t, uint8_t regi)
|
||||
int LOCAL_ID::newByteWordReg(hlType t, eReg regi)
|
||||
{
|
||||
int idx;
|
||||
|
||||
@ -143,7 +143,7 @@ int LOCAL_ID::newIntIdx(int16_t seg, int16_t off, uint8_t regi, int ix, hlType t
|
||||
/* Checks if the entry exists in the locSym, if so, returns the idx to this
|
||||
* entry; otherwise creates a new register identifier node of type
|
||||
* TYPE_LONG_(UN)SIGN and returns the index to this new entry. */
|
||||
int LOCAL_ID::newLongReg(hlType t, uint8_t regH, uint8_t regL, iICODE ix_)
|
||||
int LOCAL_ID::newLongReg(hlType t, eReg regH, eReg regL, iICODE ix_)
|
||||
{
|
||||
int idx;
|
||||
//iICODE ix_;
|
||||
@ -396,7 +396,7 @@ boolT checkLongRegEq (LONGID_TYPE longId, iICODE pIcode, int i,
|
||||
/* Given an index into the local identifier table for a long register
|
||||
* variable, determines whether regi is the high or low part, and returns
|
||||
* the other part */
|
||||
uint8_t otherLongRegi (uint8_t regi, int idx, LOCAL_ID *locTbl)
|
||||
eReg otherLongRegi (eReg regi, int idx, LOCAL_ID *locTbl)
|
||||
{
|
||||
ID *id;
|
||||
|
||||
@ -409,7 +409,7 @@ uint8_t otherLongRegi (uint8_t regi, int idx, LOCAL_ID *locTbl)
|
||||
else if (id->id.longId.l == regi)
|
||||
return (id->id.longId.h);
|
||||
}
|
||||
return 0; // Cristina: please check this!
|
||||
return rUNDEF; // Cristina: please check this!
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -103,7 +103,7 @@ void Function::newRegArg(iICODE picode, iICODE ticode)
|
||||
boolT regExist;
|
||||
condId type;
|
||||
Function * tproc;
|
||||
uint8_t regL, regH; /* Registers involved in arguments */
|
||||
eReg regL, regH; /* Registers involved in arguments */
|
||||
|
||||
/* Flag ticode as having register arguments */
|
||||
tproc = ticode->hl()->call.proc;
|
||||
|
||||
@ -200,7 +200,7 @@ static derSeq_Entry *newDerivedSeq()
|
||||
|
||||
|
||||
/* Frees the storage allocated for the queue q*/
|
||||
void freeQueue (queue &q)
|
||||
static void freeQueue (queue &q)
|
||||
{
|
||||
q.clear();
|
||||
}
|
||||
@ -236,7 +236,7 @@ derSeq_Entry::~derSeq_Entry()
|
||||
|
||||
/* Finds the next order graph of derivedGi->Gi according to its intervals
|
||||
* (derivedGi->Ii), and places it in derivedGi->next->Gi. */
|
||||
bool Function::nextOrderGraph (derSeq *derivedGi)
|
||||
bool Function::nextOrderGraph (derSeq &derivedGi)
|
||||
{
|
||||
interval *Ii; /* Interval being processed */
|
||||
BB *BBnode, /* New basic block of intervals */
|
||||
@ -249,9 +249,9 @@ bool Function::nextOrderGraph (derSeq *derivedGi)
|
||||
boolT sameGraph; /* Boolean, isomorphic graphs */
|
||||
|
||||
/* Process Gi's intervals */
|
||||
derSeq_Entry &prev_entry(derivedGi->back());
|
||||
derivedGi->push_back(derSeq_Entry());
|
||||
derSeq_Entry &new_entry(derivedGi->back());
|
||||
derSeq_Entry &prev_entry(derivedGi.back());
|
||||
derivedGi.push_back(derSeq_Entry());
|
||||
derSeq_Entry &new_entry(derivedGi.back());
|
||||
Ii = prev_entry.Ii;
|
||||
sameGraph = TRUE;
|
||||
BBnode = 0;
|
||||
@ -272,8 +272,14 @@ bool Function::nextOrderGraph (derSeq *derivedGi)
|
||||
|
||||
if (BBnode->edges.size() > 0)
|
||||
{
|
||||
#ifdef _lint
|
||||
for (auto ik=listIi.begin(); ik!=listIi.end(); ++ik)
|
||||
{
|
||||
BB *curr(*ik);
|
||||
#else
|
||||
for(BB *curr : listIi)
|
||||
{
|
||||
#endif
|
||||
for (j = 0; j < curr->edges.size(); j++)
|
||||
{
|
||||
succ = curr->edges[j].BBptr;
|
||||
@ -291,21 +297,33 @@ bool Function::nextOrderGraph (derSeq *derivedGi)
|
||||
* Determines the number of in edges to each new BB, and places it
|
||||
* in numInEdges and inEdgeCount for later interval processing. */
|
||||
curr = new_entry.Gi = bbs.front();
|
||||
#ifdef _lint
|
||||
for (auto ik=bbs.begin(); ik!=bbs.end(); ++ik)
|
||||
{
|
||||
BB *curr(*ik);
|
||||
#else
|
||||
for(BB *curr : bbs)
|
||||
{
|
||||
#endif
|
||||
#ifdef _lint
|
||||
for (auto il=curr->edges.begin(); il!=curr->edges.end(); ++il)
|
||||
{
|
||||
TYPEADR_TYPE &edge(*il);
|
||||
#else
|
||||
for(TYPEADR_TYPE &edge : curr->edges)
|
||||
{
|
||||
#endif
|
||||
BBnode = new_entry.Gi; /* BB of an interval */
|
||||
auto iter= std::find_if(bbs.begin(),bbs.end(),
|
||||
[&edge](BB *node)->bool { return edge.intPtr==node->correspInt;});
|
||||
if(iter==bbs.end())
|
||||
fatalError (INVALID_INT_BB);
|
||||
edge.BBptr = *iter;
|
||||
(*iter)->inEdges.push_back(0);
|
||||
(*iter)->inEdgeCount++;
|
||||
if(iter==bbs.end())
|
||||
fatalError (INVALID_INT_BB);
|
||||
edge.BBptr = *iter;
|
||||
(*iter)->inEdges.push_back((BB *)nullptr);
|
||||
(*iter)->inEdgeCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return (boolT)(! sameGraph);
|
||||
return (boolT)(! sameGraph);
|
||||
}
|
||||
|
||||
|
||||
@ -313,11 +331,11 @@ return (boolT)(! sameGraph);
|
||||
/* Finds the derived sequence of the graph derivedG->Gi (ie. cfg).
|
||||
* Constructs the n-th order graph and places all the intermediate graphs
|
||||
* in the derivedG list sequence. */
|
||||
uint8_t Function::findDerivedSeq (derSeq *derivedGi)
|
||||
uint8_t Function::findDerivedSeq (derSeq &derivedGi)
|
||||
{
|
||||
BB *Gi; /* Current derived sequence graph */
|
||||
|
||||
derSeq::iterator iter=derivedGi->begin();
|
||||
derSeq::iterator iter=derivedGi.begin();
|
||||
Gi = iter->Gi;
|
||||
while (! trivialGraph (Gi))
|
||||
{
|
||||
@ -335,12 +353,12 @@ uint8_t Function::findDerivedSeq (derSeq *derivedGi)
|
||||
if (! trivialGraph (Gi))
|
||||
{
|
||||
++iter;
|
||||
derivedGi->erase(iter,derivedGi->end()); /* remove Gi+1 */
|
||||
derivedGi.erase(iter,derivedGi.end()); /* remove Gi+1 */
|
||||
// freeDerivedSeq(derivedGi->next);
|
||||
// derivedGi->next = NULL;
|
||||
return FALSE;
|
||||
}
|
||||
derivedGi->back().findIntervals (this);
|
||||
derivedGi.back().findIntervals (this);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -381,7 +399,7 @@ derSeq * Function::checkReducibility()
|
||||
der_seq = new derSeq;
|
||||
der_seq->resize(1);
|
||||
der_seq->back().Gi = m_cfg.front();
|
||||
reducible = findDerivedSeq(der_seq);
|
||||
reducible = findDerivedSeq(*der_seq);
|
||||
|
||||
if (! reducible)
|
||||
{
|
||||
|
||||
@ -399,7 +399,6 @@ static int signex(uint8_t b)
|
||||
return ((b & 0x80)? (int)(0xFFFFFF00 | s): (int)s);
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* setAddress - Updates the source or destination field for the current
|
||||
* icode, based on fdst and the TO_REG flag.
|
||||
@ -433,11 +432,12 @@ static void setAddress(int i, boolT fdst, uint16_t seg, int16_t reg, uint16_t of
|
||||
pm->seg = rDS; /* any other indexed reg */
|
||||
}
|
||||
}
|
||||
pm->regi = (uint8_t)reg;
|
||||
|
||||
pm->regi = (eReg)reg;
|
||||
pm->off = (int16_t)off;
|
||||
if (reg && reg < INDEXBASE && (stateTable[i].flg & B))
|
||||
{
|
||||
pm->regi += rAL - rAX;
|
||||
pm->regi = subRegL(pm->regi);
|
||||
}
|
||||
|
||||
if (seg) /* So we can catch invalid use of segment overrides */
|
||||
|
||||
@ -68,8 +68,8 @@ private:
|
||||
unordered_map<SYMTABLE,string> z2;
|
||||
};
|
||||
|
||||
TABLEINFO_TYPE tableInfo[NUM_TABLE_TYPES]; /* Array of info about tables */
|
||||
TABLEINFO_TYPE currentTabInfo;
|
||||
static TABLEINFO_TYPE tableInfo[NUM_TABLE_TYPES]; /* Array of info about tables */
|
||||
static TABLEINFO_TYPE currentTabInfo;
|
||||
|
||||
/* Create a new symbol table. Returns "handle" */
|
||||
void TABLEINFO_TYPE::create(tableType type)
|
||||
|
||||
@ -91,8 +91,14 @@ void udm(void)
|
||||
void Function::displayCFG()
|
||||
{
|
||||
printf("\nBasic Block List - Proc %s", name.c_str());
|
||||
#ifdef _lint
|
||||
for (auto ik=m_cfg.begin(); ik!=m_cfg.end(); ++ik)
|
||||
{
|
||||
BB *pBB(*ik);
|
||||
#else
|
||||
for (BB *pBB : m_cfg)
|
||||
{
|
||||
#endif
|
||||
pBB->display();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user