Moved most of register definitions to use eReg enum

This commit is contained in:
Artur K
2012-03-07 21:52:46 +01:00
parent 2a99eef3a1
commit e0740f5ff7
29 changed files with 426 additions and 255 deletions

7
.gitignore vendored
View File

@@ -1,2 +1,7 @@
coverage
tests/inputs
tests/prev
tests/outputs/* tests/outputs/*
bld tests/errors
*.autosave
bld*

View File

@@ -2,6 +2,7 @@
/* Machine registers */ /* Machine registers */
enum eReg enum eReg
{ {
rUNDEF = 0,
rAX = 1, /* These are numbered relative to real 8086 */ rAX = 1, /* These are numbered relative to real 8086 */
rCX = 2, rCX = 2,
rDX = 3, rDX = 3,

View File

@@ -165,6 +165,6 @@ protected:
void findIdioms(); void findIdioms();
void propLong(); void propLong();
void genLiveKtes(); void genLiveKtes();
uint8_t findDerivedSeq (derSeq *derivedGi); uint8_t findDerivedSeq (derSeq &derivedGi);
bool nextOrderGraph(derSeq *derivedGi); bool nextOrderGraph(derSeq &derivedGi);
}; };

View File

@@ -74,7 +74,7 @@ public:
static COND_EXPR *idRegIdx(int idx, regType reg_type); static COND_EXPR *idRegIdx(int idx, regType reg_type);
static COND_EXPR *idKte(uint32_t kte, uint8_t size); static COND_EXPR *idKte(uint32_t kte, uint8_t size);
static COND_EXPR *idLoc(int off, LOCAL_ID *localId); 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 *idLongIdx(int idx);
static COND_EXPR *idOther(uint8_t seg, uint8_t regi, int16_t off); static COND_EXPR *idOther(uint8_t seg, uint8_t regi, int16_t off);
static COND_EXPR *idParam(int off, const STKFRAME *argSymtab); 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 * 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 COND_EXPR *boolOp(COND_EXPR *_lhs, COND_EXPR *_rhs, condOp _op);
static bool insertSubTreeLongReg(COND_EXPR *exp, COND_EXPR **tree, int longIdx); 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: public:
virtual COND_EXPR *clone(); virtual COND_EXPR *clone();
void release(); void release();
@@ -106,7 +106,7 @@ public:
public: public:
virtual COND_EXPR *inverse(); // return new COND_EXPR that is invarse of this 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 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); virtual COND_EXPR *insertSubTreeLongReg(COND_EXPR *_expr, int longIdx);
}; };
struct BinaryOperator : public COND_EXPR struct BinaryOperator : public COND_EXPR
@@ -124,7 +124,7 @@ struct BinaryOperator : public COND_EXPR
virtual COND_EXPR *inverse(); virtual COND_EXPR *inverse();
virtual COND_EXPR *clone(); virtual COND_EXPR *clone();
virtual bool xClear(iICODE f, iICODE t, iICODE lastBBinst, Function *pproc); 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); virtual COND_EXPR *insertSubTreeLongReg(COND_EXPR *_expr, int longIdx);
COND_EXPR *lhs() COND_EXPR *lhs()

View File

@@ -101,7 +101,7 @@ extern PROG prog; /* Loaded program image parameters */
extern std::bitset<32> duReg[30]; /* def/use bits for registers */ extern std::bitset<32> duReg[30]; /* def/use bits for registers */
//extern uint32_t 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 */ /* Registers used by icode instructions */
static constexpr const char *allRegs[21] = {"ax", "cx", "dx", "bx", "sp", "bp", static constexpr const char *allRegs[21] = {"ax", "cx", "dx", "bx", "sp", "bp",
@@ -174,4 +174,4 @@ int power2 (int);
/* Exported funcions from locident.c */ /* Exported funcions from locident.c */
boolT checkLongEq (LONG_STKID_TYPE, iICODE, int, Function *, Assignment &asgn, iICODE atOffset); boolT checkLongEq (LONG_STKID_TYPE, iICODE, int, Function *, Assignment &asgn, iICODE atOffset);
boolT checkLongRegEq (LONGID_TYPE, iICODE, int, Function *, Assignment &asgn, iICODE); boolT checkLongRegEq (LONGID_TYPE, iICODE, int, Function *, Assignment &asgn, iICODE);
uint8_t otherLongRegi (uint8_t, int, LOCAL_ID *); eReg otherLongRegi(eReg, int, LOCAL_ID *);

View File

@@ -45,10 +45,10 @@ struct COND_EXPR;
struct HlTypeSupport struct HlTypeSupport
{ {
//hlIcode opcode; /* hlIcode opcode */ //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; virtual std::string writeOut(Function *pProc, int *numLoc)=0;
protected: 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 struct CallType : public HlTypeSupport
@@ -60,7 +60,7 @@ struct CallType : public HlTypeSupport
bool newStkArg(COND_EXPR *exp, llIcode opcode, Function *pproc); bool newStkArg(COND_EXPR *exp, llIcode opcode, Function *pproc);
void placeStkArg(COND_EXPR *exp, int pos); void placeStkArg(COND_EXPR *exp, int pos);
public: public:
bool removeRegFromLong(uint8_t regi, LOCAL_ID *locId) bool removeRegFromLong(eReg regi, LOCAL_ID *locId)
{ {
printf("CallType : removeRegFromLong not supproted"); printf("CallType : removeRegFromLong not supproted");
return false; return false;
@@ -72,7 +72,7 @@ struct AssignType : public HlTypeSupport
/* for HLI_ASSIGN */ /* for HLI_ASSIGN */
COND_EXPR *lhs; COND_EXPR *lhs;
COND_EXPR *rhs; COND_EXPR *rhs;
bool removeRegFromLong(uint8_t regi, LOCAL_ID *locId) bool removeRegFromLong(eReg regi, LOCAL_ID *locId)
{ {
performLongRemoval(regi,locId,lhs); performLongRemoval(regi,locId,lhs);
return true; return true;
@@ -83,7 +83,7 @@ struct ExpType : public HlTypeSupport
{ {
/* for HLI_JCOND, HLI_RET, HLI_PUSH, HLI_POP*/ /* for HLI_JCOND, HLI_RET, HLI_PUSH, HLI_POP*/
COND_EXPR *v; COND_EXPR *v;
bool removeRegFromLong(uint8_t regi, LOCAL_ID *locId) bool removeRegFromLong(eReg regi, LOCAL_ID *locId)
{ {
performLongRemoval(regi,locId,v); performLongRemoval(regi,locId,v);
return true; return true;
@@ -156,7 +156,7 @@ struct LLOperand //: public llvm::MCOperand
uint8_t seg; /* CS, DS, ES, SS */ uint8_t seg; /* CS, DS, ES, SS */
int16_t segValue; /* Value of segment seg during analysis */ int16_t segValue; /* Value of segment seg during analysis */
uint8_t segOver; /* CS, DS, ES, SS if segment override */ 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 */ int16_t off; /* memory address offset */
uint32_t opz; /* idx of immed src op */ uint32_t opz; /* idx of immed src op */
//union {/* Source operand if (flg & I) */ //union {/* Source operand if (flg & I) */
@@ -352,7 +352,7 @@ public:
void copyDU(const ICODE &duIcode, operDu _du, operDu duDu); void copyDU(const ICODE &duIcode, operDu _du, operDu duDu);
bool valid() {return not invalid;} bool valid() {return not invalid;}
public: public:
bool removeDefRegi(uint8_t regi, int thisDefIdx, LOCAL_ID *locId); bool removeDefRegi(eReg regi, int thisDefIdx, LOCAL_ID *locId);
void checkHlCall(); void checkHlCall();
bool newStkArg(COND_EXPR *exp, llIcode opcode, Function *pproc) bool newStkArg(COND_EXPR *exp, llIcode opcode, Function *pproc)
{ {
@@ -372,3 +372,11 @@ public:
iterator labelSrch(uint32_t target); iterator labelSrch(uint32_t target);
ICODE * GetIcode(int ip); 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);
}

View File

@@ -8,11 +8,11 @@ struct Idiom14 : public Idiom
{ {
protected: protected:
iICODE m_icodes[2]; iICODE m_icodes[2];
uint8_t m_regL; eReg m_regL;
uint8_t m_regH; eReg m_regH;
public: public:
virtual ~Idiom14() {} 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;} uint8_t minimum_match_length() {return 2;}
@@ -24,7 +24,7 @@ struct Idiom13 : public Idiom
{ {
protected: protected:
iICODE m_icodes[2]; iICODE m_icodes[2];
uint8_t m_loaded_reg; eReg m_loaded_reg;
public: public:
virtual ~Idiom13() {} virtual ~Idiom13() {}
Idiom13(Function *f) : Idiom(f) Idiom13(Function *f) : Idiom(f)

View File

@@ -55,8 +55,8 @@ typedef struct
} LONG_STKID_TYPE; } LONG_STKID_TYPE;
typedef struct typedef struct
{ /* For TYPE_LONG_(UN)SIGN registers */ { /* For TYPE_LONG_(UN)SIGN registers */
uint8_t h; /* high register */ eReg h; /* high register */
uint8_t l; /* low register */ eReg l; /* low register */
} LONGID_TYPE; } LONGID_TYPE;
@@ -72,7 +72,7 @@ struct ID
char macro[10]; /* Macro for this identifier */ char macro[10]; /* Macro for this identifier */
char name[20]; /* Identifier's name */ char name[20]; /* Identifier's name */
union { /* Different types of identifiers */ 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 */ struct { /* For TYPE_BYTE(uint16_t)_(UN)SIGN on the stack */
uint8_t regOff; /* register offset (if any) */ uint8_t regOff; /* register offset (if any) */
int off; /* offset from BP */ int off; /* offset from BP */
@@ -113,10 +113,10 @@ public:
{ {
id_arr.reserve(256); 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 newByteWordStk(hlType t, int off, uint8_t regOff);
int newIntIdx(int16_t seg, int16_t off, uint8_t regi, int ix, hlType t); 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, int off);
int newLong(opLoc sd, iICODE pIcode, hlFirst f, iICODE ix, operDu du, iICODE atOffset); int newLong(opLoc sd, iICODE pIcode, hlFirst f, iICODE ix, operDu du, iICODE atOffset);
void newIdent(hlType t, frameType f); void newIdent(hlType t, frameType f);

View File

@@ -101,8 +101,14 @@ void BB::displayDfs()
printf("----\n"); printf("----\n");
/* Recursive call on successors of current node */ /* 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) for(TYPEADR_TYPE &pb : edges)
{ {
#endif
if (pb.BBptr->traversed != DFS_DISP) if (pb.BBptr->traversed != DFS_DISP)
pb.BBptr->displayDfs(); pb.BBptr->displayDfs();
} }

View File

@@ -15,12 +15,12 @@
using namespace std; using namespace std;
// Index registers **** temp solution // Index registers **** temp solution
static const char * const idxReg[8] = {"bx+si", "bx+di", "bp+si", "bp+di", 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 // Conditional operator symbols in C. Index by condOp enumeration type
static const char * const condOpSym[] = { " <= ", " < ", " == ", " != ", " > ", " >= ", static const char * const condOpSym[] = { " <= ", " < ", " == ", " != ", " > ", " >= ",
" & ", " | ", " ^ ", " ~ ", " & ", " | ", " ^ ", " ~ ",
" + ", " - ", " * ", " / ", " + ", " - ", " * ", " / ",
" >> ", " << ", " % ", " && ", " || " }; " >> ", " << ", " % ", " && ", " || " };
//#define EXP_SIZE 200 /* Size of the expression buffer */ //#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()) if (i == symtab.size())
{ {
printf ("Error, glob var not found in symtab\n"); printf ("Error, glob var not found in symtab\n");
delete newExp;
return 0; return 0;
} }
newExp->expr.ident.idNode.globIdx = i; 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 */ /* 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; 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 */ else if (pm.regi < INDEXBASE) /* register */
{ {
newExp = COND_EXPR::idReg (pm.regi, (sd == SRC) ? ll_insn.getFlag() : 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); &pProc->localId);
duIcode.setRegDU( pm.regi, du); 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 /* 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 * register (eg. dx:ax), the node gets transformed into an integer register
* node. */ * 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 */ 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) { switch (tree->type) {
case BOOLEAN_OP: 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 /* Makes a copy of the given expression. Allocates newExp storage for each
* node. Returns the copy. */ * node. Returns the copy. */
//lint -sem(COND_EXPR::clone, @p!=0)
COND_EXPR *COND_EXPR::clone() COND_EXPR *COND_EXPR::clone()
{ {
COND_EXPR* newExp=0; /* Expression node copy */ 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 /* Inserts the expression exp into the tree at the location specified by the
* register regi */ * 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) if (tree == NULL)
return false; return false;
@@ -837,10 +839,16 @@ bool COND_EXPR::insertSubTreeReg (COND_EXPR *&tree, COND_EXPR *_expr, uint8_t re
} }
return false; 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; if ((parent < rAX) || (parent > rBX))
uint8_t treeReg; 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; COND_EXPR *temp;
switch (type) { switch (type) {
@@ -852,12 +860,9 @@ COND_EXPR *COND_EXPR::insertSubTreeReg (COND_EXPR *_expr, uint8_t regi,LOCAL_ID
{ {
return _expr; 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; return FALSE;
@@ -887,10 +892,10 @@ COND_EXPR *COND_EXPR::insertSubTreeReg (COND_EXPR *_expr, uint8_t regi,LOCAL_ID
return this; return this;
} }
return nullptr; return nullptr;
} }
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; COND_EXPR *r;
r=m_lhs->insertSubTreeReg(_expr,regi,locsym); 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 *COND_EXPR::insertSubTreeLongReg(COND_EXPR *_expr, int longIdx)
{ {
COND_EXPR *temp; COND_EXPR *temp;
switch (type) switch (type)
{ {
case IDENTIFIER: case IDENTIFIER:
@@ -952,12 +957,12 @@ COND_EXPR *COND_EXPR::insertSubTreeLongReg(COND_EXPR *_expr, int longIdx)
case NEGATION: case NEGATION:
case ADDRESSOF: case ADDRESSOF:
case DEREFERENCE: case DEREFERENCE:
COND_EXPR *temp = expr.unaryExp->insertSubTreeLongReg(_expr,longIdx); temp = expr.unaryExp->insertSubTreeLongReg(_expr,longIdx);
if (nullptr!=temp) if (nullptr!=temp)
{ {
expr.unaryExp = temp; expr.unaryExp = temp;
return this; return this;
} }
return nullptr; return nullptr;
} }
return nullptr; return nullptr;
@@ -999,38 +1004,9 @@ void COND_EXPR::release()
} }
delete (this); 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 /* Makes a copy of the given expression. Allocates newExp storage for each
* node. Returns the copy. */ * node. Returns the copy. */
//lint -sem(BinaryOperator::clone, @p!=0)
COND_EXPR *BinaryOperator::clone() COND_EXPR *BinaryOperator::clone()
{ {
BinaryOperator* newExp=new BinaryOperator(m_op); /* Expression node copy */ BinaryOperator* newExp=new BinaryOperator(m_op); /* Expression node copy */
@@ -1038,3 +1014,31 @@ COND_EXPR *BinaryOperator::clone()
newExp->m_rhs = m_rhs->clone(); newExp->m_rhs = m_rhs->clone();
return newExp; 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;
}

View File

@@ -225,7 +225,7 @@ static void writeBitVector (const std::bitset<32> &regi)
* 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 ( 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 */ /* Generate new label */
pt->ll()->hllLabNum = getNextLabel(); pt->ll()->hllLabNum = getNextLabel();

View File

@@ -76,8 +76,16 @@ void Function::findImmedDom ()
currNode = m_dfsLast[currIdx]; currNode = m_dfsLast[currIdx];
if (currNode->flg & INVALID_BB) /* Do not process invalid BBs */ if (currNode->flg & INVALID_BB) /* Do not process invalid BBs */
continue; 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) for (BB * inedge : currNode->inEdges)
{ {
#endif
predIdx = inedge->dfsLastNum; predIdx = inedge->dfsLastNum;
if (predIdx < currIdx) if (predIdx < currIdx)
currNode->immedDom = commonDom (currNode->immedDom, predIdx, this); currNode->immedDom = commonDom (currNode->immedDom, predIdx, this);
@@ -255,12 +263,32 @@ static void findNodesInInt (queue &intNodes, int level, interval *Ii)
{ {
if (level == 1) 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) for(BB *en : Ii->nodes)
{
#endif
appendQueue(intNodes,en); appendQueue(intNodes,en);
}
} }
else 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) for(BB *en : Ii->nodes)
{
#endif
findNodesInInt(intNodes,level-1,en->correspInt); findNodesInInt(intNodes,level-1,en->correspInt);
}
} }
@@ -403,8 +431,14 @@ void Function::structCases()
* header field with caseHeader. */ * header field with caseHeader. */
insertList (caseNodes, i); insertList (caseNodes, i);
m_dfsLast[i]->caseHead = 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) for(TYPEADR_TYPE &pb : caseHeader->edges)
{ {
#endif
tagNodesInCase(pb.BBptr, caseNodes, i, exitNode); tagNodesInCase(pb.BBptr, caseNodes, i, exitNode);
} }
//for (j = 0; j < caseHeader->edges[j]; j++) //for (j = 0; j < caseHeader->edges[j]; j++)

View File

@@ -317,8 +317,16 @@ void Function::liveRegAnalysis (std::bitset<32> &in_liveOut)
} }
else /* Check successors */ 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) for(TYPEADR_TYPE &e : pbb->edges)
{
#endif
pbb->liveOut |= e.BBptr->liveIn; pbb->liveOut |= e.BBptr->liveIn;
}
/* propagate to invoked procedure */ /* propagate to invoked procedure */
if (pbb->nodeType == CALL_NODE) if (pbb->nodeType == CALL_NODE)
@@ -392,7 +400,8 @@ void Function::liveRegAnalysis (std::bitset<32> &in_liveOut)
void BB::genDU1() void BB::genDU1()
{ {
uint8_t regi; /* Register that was defined */ eReg regi; /* Register that was defined */
int k, defRegIdx, useIdx; int k, defRegIdx, useIdx;
iICODE picode, ticode,lastInst; iICODE picode, ticode,lastInst;
BB *tbb; /* Target basic block */ BB *tbb; /* Target basic block */
@@ -407,7 +416,7 @@ void BB::genDU1()
{ {
if (picode->type != HIGH_LEVEL) if (picode->type != HIGH_LEVEL)
continue; continue;
regi = 0; regi = rUNDEF;
defRegIdx = 0; defRegIdx = 0;
// foreach defined register // foreach defined register
bitset<32> processed=0; bitset<32> processed=0;
@@ -417,7 +426,7 @@ void BB::genDU1()
continue; continue;
//printf("Processing reg") //printf("Processing reg")
processed |= duReg[k]; processed |= duReg[k];
regi = (uint8_t)(k + 1); /* defined register */ regi = (eReg)(k + 1); /* defined register */
picode->du1.regi[defRegIdx] = regi; picode->du1.regi[defRegIdx] = regi;
/* Check remaining instructions of the BB for all uses /* Check remaining instructions of the BB for all uses
@@ -486,9 +495,9 @@ void BB::genDU1()
* from a library function (routines such as printf * from a library function (routines such as printf
* return an integer, which is normally not taken into * return an integer, which is normally not taken into
* account by the programmer). */ * account by the programmer). */
if (picode->valid() and not picode->du1.used(defRegIdx) and if (picode->valid() && ! picode->du1.used(defRegIdx) &&
(not (picode->du.lastDefRegi & duReg[regi]).any()) && ( ! (picode->du.lastDefRegi & duReg[regi]).any()) &&
(not ((picode->hl()->opcode == HLI_CALL) && ( ! ((picode->hl()->opcode == HLI_CALL) &&
(picode->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 */
@@ -521,17 +530,16 @@ void BB::genDU1()
/* Generates the du chain of each instruction in a basic block */ /* Generates the du chain of each instruction in a basic block */
void Function::genDU1 () 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 */ /* Traverse tree in dfsLast order */
assert(m_dfsLast.size()==numBBs); 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) for(BB *pbb : m_dfsLast)
{ {
#endif
if (pbb->flg & INVALID_BB) if (pbb->flg & INVALID_BB)
continue; continue;
pbb->genDU1(); pbb->genDU1();
@@ -665,7 +673,7 @@ bool BinaryOperator::xClear(iICODE f, iICODE t, iICODE lastBBinst, Function *ppr
{ {
if(0==m_rhs) if(0==m_rhs)
return false; return false;
if ( not m_rhs->xClear (f, t, lastBBinst, pproc) ) if ( ! m_rhs->xClear (f, t, lastBBinst, pproc) )
return false; return false;
if(0==m_lhs) if(0==m_lhs)
return false; return false;

View File

@@ -229,8 +229,14 @@ void disassem(int pass, Function * ppProc)
{ {
/* Bind jump offsets to labels */ /* Bind jump offsets to labels */
//for (i = 0; i < numIcode; i++) //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) for( ICODE &icode : pc)
{ {
#endif
LLInst *ll=icode.ll(); LLInst *ll=icode.ll();
ll->findJumpTargets(pc); ll->findJumpTargets(pc);
} }
@@ -245,8 +251,14 @@ void disassem(int pass, Function * ppProc)
/* Loop over array printing each record */ /* Loop over array printing each record */
nextInst = 0; nextInst = 0;
#ifdef _lint
for (auto i=pc.begin(); i!=pc.end(); ++i)
{
ICODE &icode(*i);
#else
for( ICODE &icode : pc) for( ICODE &icode : pc)
{ {
#endif
icode.ll()->dis1Line(icode.loc_ip,pass); icode.ll()->dis1Line(icode.loc_ip,pass);
} }

View File

@@ -10,28 +10,32 @@
#include <stdarg.h> #include <stdarg.h>
#include "dcc.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. fatalError: displays error message and exits the program.

View File

@@ -75,8 +75,14 @@ void FrontEnd (char *filename, CALL_GRAPH * *pcallGraph)
} }
/* Search through code looking for impure references and flag them */ /* 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) for(Function &f : pProcList)
{ {
#endif
f.markImpure(); f.markImpure();
if (option.asm1) if (option.asm1)
disassem(1, &f); disassem(1, &f);
@@ -87,9 +93,16 @@ void FrontEnd (char *filename, CALL_GRAPH * *pcallGraph)
} }
/* Converts jump target addresses to icode offsets */ /* 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) for(Function &f : pProcList)
{
#endif
f.bindIcodeOff(); f.bindIcodeOff();
}
/* Print memory bitmap */ /* Print memory bitmap */
if (option.Map) if (option.Map)
displayMemMap(); displayMemMap();

View File

@@ -157,7 +157,7 @@ CondJumps:
fatalError(NO_BB, ip, name.c_str()); fatalError(NO_BB, ip, name.c_str());
psBB = *iter2; psBB = *iter2;
pBB->edges[i].BBptr = psBB; pBB->edges[i].BBptr = psBB;
psBB->inEdges.push_back(0); psBB->inEdges.push_back((BB *)nullptr);
} }
} }
} }
@@ -165,8 +165,14 @@ CondJumps:
void Function::markImpure() void Function::markImpure()
{ {
SYM * psym; SYM * psym;
#ifdef _lint
for (auto i=Icode.begin(); i!=Icode.end(); ++i)
{
ICODE &icod(*i);
#else
for(ICODE &icod : Icode) for(ICODE &icod : Icode)
{ {
#endif
if ( not icod.ll()->testFlags(SYM_USE | SYM_DEF)) if ( not icod.ll()->testFlags(SYM_USE | SYM_DEF))
continue; continue;
psym = &symtab[icod.ll()->caseTbl.numEntries]; psym = &symtab[icod.ll()->caseTbl.numEntries];
@@ -194,8 +200,16 @@ void Function::markImpure()
****************************************************************************/ ****************************************************************************/
void Function::freeCFG() void Function::freeCFG()
{ {
#ifdef _lint
for (auto i=heldBBs.begin(); i!=heldBBs.end(); ++i)
{
BB *p(*i);
#else
for(BB *p : heldBBs) for(BB *p : heldBBs)
{
#endif
delete p; delete p;
}
} }
@@ -283,7 +297,7 @@ BB *BB::rmJMP(int marker, BB * pBB)
pBB->inEdges.pop_back(); pBB->inEdges.pop_back();
if (not pBB->inEdges.empty()) if (not pBB->inEdges.empty())
{ {
pBB->edges[0].BBptr->inEdges.push_back(0); pBB->edges[0].BBptr->inEdges.push_back((BB *)nullptr);
} }
else 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[]. */ /* index is being used as an index to inEdges[]. */
// for (i = 0; i < edges.size(); i++) // 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 = edge.BBptr;
pChild->inEdges[pChild->index++] = this; pChild->inEdges[pChild->index++] = this;

View File

@@ -13,7 +13,7 @@ using namespace std;
#define ICODE_DELTA 25 #define ICODE_DELTA 25
/* Masks off bits set by duReg[] */ /* Masks off bits set by duReg[] */
uint32_t maskDuReg[] = { 0x00, std::bitset<32> maskDuReg[] = { 0x00,
0xFEEFFE, 0xFDDFFD, 0xFBB00B, 0xF77007, /* uint16_t regs */ 0xFEEFFE, 0xFDDFFD, 0xFBB00B, 0xF77007, /* uint16_t regs */
0xFFFFEF, 0xFFFFDF, 0xFFFFBF, 0xFFFF7F, 0xFFFFEF, 0xFFFFDF, 0xFFFFBF, 0xFFFF7F,
0xFFFEFF, 0xFFFDFF, 0xFFFBFF, 0xFFF7FF, /* seg regs */ 0xFFFEFF, 0xFFFDFF, 0xFFFBFF, 0xFFF7FF, /* seg regs */
@@ -86,7 +86,7 @@ void ICODE ::invalidate()
* If all registers * If all registers
* of this instruction are unused, the instruction is invalidated (ie. removed) * 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; int numDefs;
@@ -634,8 +634,14 @@ void ICODE::writeDU(int idx)
if (du1.used(i)) if (du1.used(i))
{ {
printf ("%d: du1[%d][] = ", idx, 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 ("%d ", j->loc_ip);
} }
printf ("\n"); printf ("\n");

View File

@@ -29,10 +29,18 @@ ICODE * CIcodeRec::addIcode(ICODE *pIcode)
void CIcodeRec::SetInBB(int start, int end, BB *pnewBB) 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) for(ICODE &icode : *this)
{
#endif
if((icode.loc_ip>=start) and (icode.loc_ip<=end)) if((icode.loc_ip>=start) and (icode.loc_ip<=end))
icode.inBB = pnewBB; icode.inBB = pnewBB;
// for (int i = start; i <= end; i++) }
// for (int i = start; i <= end; i++)
// at(i).inBB = pnewBB; // at(i).inBB = pnewBB;
} }

View File

@@ -24,13 +24,13 @@ bool LLInst::isJmpInst()
{ {
switch (opcode) switch (opcode)
{ {
case iJMP: case iJMPF: case iJCXZ: case iJMP: case iJMPF: case iJCXZ:
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:
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:
case iJO: case iJNO: case iJP: case iJNP: case iJO: case iJNO: case iJP: case iJNP:
return true; return true;
} }
return false; return false;
} }
@@ -40,7 +40,7 @@ bool LLInst::isJmpInst()
****************************************************************************/ ****************************************************************************/
void Function::findIdioms() 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 */ iICODE pEnd, pIcode; /* Pointers to end of BB and current icodes */
int16_t delta; int16_t delta;
@@ -81,7 +81,7 @@ void Function::findIdioms()
{ {
switch (pIcode->ll()->getOpcode()) switch (pIcode->ll()->getOpcode())
{ {
case iDEC: case iINC: case iDEC: case iINC:
if (i18.match(pIcode)) if (i18.match(pIcode))
advance(pIcode,i18.action()); advance(pIcode,i18.action());
else if (i19.match(pIcode)) else if (i19.match(pIcode))
@@ -96,8 +96,8 @@ void Function::findIdioms()
{ {
/* Idiom 1 */ /* Idiom 1 */
// todo add other push idioms. // todo add other push idioms.
advance(pIcode,i01(pIcode)); advance(pIcode,i01(pIcode));
break; break;
} }
case iMOV: case iMOV:
@@ -113,93 +113,93 @@ void Function::findIdioms()
break; break;
} }
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->ll()->src.proc.proc != 0) if (pIcode->ll()->src.proc.proc != 0)
if ((pIcode->ll()->src.proc.proc->flg & PROC_ISLIB) && if ((pIcode->ll()->src.proc.proc->flg & PROC_ISLIB) &&
(pIcode->ll()->src.proc.proc->flg & PROC_IS_FUNC)) (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 */ /* Check for idioms */
if (i21.match(pIcode)) if (i03.match(pIcode)) /* idiom 3 */
advance(pIcode,i21.action()); advance(pIcode,i03.action());
else if (i07.match(pIcode)) else if (i17.match(pIcode)) /* idiom 17 */
advance(pIcode,i07.action()); advance(pIcode,i17.action());
else else
++pIcode;
break;
default:
pIcode++; 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(); pIcode = Icode.begin();
/* Flag all jump targets for BB construction and disassembly stage 2 */ /* 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) for(ICODE &c : Icode)
{ {
#endif
LLInst *ll=c.ll(); LLInst *ll=c.ll();
if (ll->testFlags(I) && ll->isJmpInst()) 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 * is found (no code at dest. of jump) are simply left unlinked and
* flagged as going nowhere. */ * flagged as going nowhere. */
//for (pIcode = Icode.begin(); pIcode!= Icode.end(); pIcode++) //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) for(ICODE &icode : Icode)
{ {
#endif
LLInst *ll=icode.ll(); LLInst *ll=icode.ll();
if (not ll->isJmpInst()) if (not ll->isJmpInst())
continue; continue;
if (ll->testFlags(I) ) if (ll->testFlags(I) )
{ {
uint32_t found; uint32_t found;
if (! Icode.labelSrch(ll->src.op(), found)) if (! Icode.labelSrch(ll->src.op(), found))
ll->setFlags( NO_LABEL ); ll->setFlags( NO_LABEL );
else else
ll->src.SetImmediateOp(found); ll->src.SetImmediateOp(found);
} }
else if (ll->testFlags(SWITCH) ) else if (ll->testFlags(SWITCH) )
{ {
p = ll->caseTbl.entries; p = ll->caseTbl.entries;
for (int j = 0; j < ll->caseTbl.numEntries; j++, p++) 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 */ /** Performs idioms analysis, and propagates long operands, if any */

View File

@@ -123,8 +123,14 @@ bool Idiom1::match(iICODE picode)
} }
int Idiom1::action() 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) for(iICODE ic : m_icodes)
{ {
#endif
ic->invalidate(); ic->invalidate();
} }
m_func->flg |= PROC_HLL; m_func->flg |= PROC_HLL;

View File

@@ -76,8 +76,8 @@ bool Idiom13::match(iICODE pIcode)
return false; return false;
m_icodes[0]=pIcode++; m_icodes[0]=pIcode++;
m_icodes[1]=pIcode++; m_icodes[1]=pIcode++;
m_loaded_reg = 0; m_loaded_reg = rUNDEF;
uint8_t regi; eReg regi;
/* Check for regL */ /* Check for regL */
regi = m_icodes[0]->ll()->dst.regi; 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. 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; return true;
} }
} }

View File

@@ -29,7 +29,7 @@ int Idiom8::action()
{ {
int idx; int idx;
COND_EXPR *rhs,*lhs,*expr; COND_EXPR *rhs,*lhs,*expr;
uint8_t regH,regL; eReg regH,regL;
regH=m_icodes[0]->ll()->dst.regi; regH=m_icodes[0]->ll()->dst.regi;
regL=m_icodes[1]->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]);
@@ -119,7 +119,7 @@ int Idiom12::action()
{ {
int idx; int idx;
COND_EXPR *rhs,*lhs,*expr; COND_EXPR *rhs,*lhs,*expr;
uint8_t regH,regL; eReg regH,regL;
regL=m_icodes[0]->ll()->dst.regi; regL=m_icodes[0]->ll()->dst.regi;
regH=m_icodes[1]->ll()->dst.regi; regH=m_icodes[1]->ll()->dst.regi;
@@ -158,7 +158,7 @@ int Idiom9::action()
{ {
int idx; int idx;
COND_EXPR *rhs,*lhs,*expr; COND_EXPR *rhs,*lhs,*expr;
uint8_t regH,regL; eReg regH,regL;
regL=m_icodes[1]->ll()->dst.regi; regL=m_icodes[1]->ll()->dst.regi;
regH=m_icodes[0]->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]);

View File

@@ -41,7 +41,7 @@ void LOCAL_ID::newIdent(hlType t, frameType f)
/* Creates a new register identifier node of TYPE_BYTE_(UN)SIGN or /* Creates a new register identifier node of TYPE_BYTE_(UN)SIGN or
* TYPE_WORD_(UN)SIGN type. Returns the index to this new entry. */ * 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; 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 /* 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 * entry; otherwise creates a new register identifier node of type
* TYPE_LONG_(UN)SIGN and returns the index to this new entry. */ * 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; int idx;
//iICODE ix_; //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 /* Given an index into the local identifier table for a long register
* variable, determines whether regi is the high or low part, and returns * variable, determines whether regi is the high or low part, and returns
* the other part */ * 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; ID *id;
@@ -409,7 +409,7 @@ uint8_t otherLongRegi (uint8_t regi, int idx, LOCAL_ID *locTbl)
else if (id->id.longId.l == regi) else if (id->id.longId.l == regi)
return (id->id.longId.h); return (id->id.longId.h);
} }
return 0; // Cristina: please check this! return rUNDEF; // Cristina: please check this!
} }

View File

@@ -103,7 +103,7 @@ void Function::newRegArg(iICODE picode, iICODE ticode)
boolT regExist; boolT regExist;
condId type; condId type;
Function * tproc; Function * tproc;
uint8_t regL, regH; /* Registers involved in arguments */ eReg regL, regH; /* Registers involved in arguments */
/* Flag ticode as having register arguments */ /* Flag ticode as having register arguments */
tproc = ticode->hl()->call.proc; tproc = ticode->hl()->call.proc;

View File

@@ -200,7 +200,7 @@ static derSeq_Entry *newDerivedSeq()
/* Frees the storage allocated for the queue q*/ /* Frees the storage allocated for the queue q*/
void freeQueue (queue &q) static void freeQueue (queue &q)
{ {
q.clear(); q.clear();
} }
@@ -236,7 +236,7 @@ derSeq_Entry::~derSeq_Entry()
/* Finds the next order graph of derivedGi->Gi according to its intervals /* Finds the next order graph of derivedGi->Gi according to its intervals
* (derivedGi->Ii), and places it in derivedGi->next->Gi. */ * (derivedGi->Ii), and places it in derivedGi->next->Gi. */
bool Function::nextOrderGraph (derSeq *derivedGi) bool Function::nextOrderGraph (derSeq &derivedGi)
{ {
interval *Ii; /* Interval being processed */ interval *Ii; /* Interval being processed */
BB *BBnode, /* New basic block of intervals */ BB *BBnode, /* New basic block of intervals */
@@ -249,9 +249,9 @@ bool Function::nextOrderGraph (derSeq *derivedGi)
boolT sameGraph; /* Boolean, isomorphic graphs */ boolT sameGraph; /* Boolean, isomorphic graphs */
/* Process Gi's intervals */ /* Process Gi's intervals */
derSeq_Entry &prev_entry(derivedGi->back()); derSeq_Entry &prev_entry(derivedGi.back());
derivedGi->push_back(derSeq_Entry()); derivedGi.push_back(derSeq_Entry());
derSeq_Entry &new_entry(derivedGi->back()); derSeq_Entry &new_entry(derivedGi.back());
Ii = prev_entry.Ii; Ii = prev_entry.Ii;
sameGraph = TRUE; sameGraph = TRUE;
BBnode = 0; BBnode = 0;
@@ -272,8 +272,14 @@ bool Function::nextOrderGraph (derSeq *derivedGi)
if (BBnode->edges.size() > 0) if (BBnode->edges.size() > 0)
{ {
#ifdef _lint
for (auto ik=listIi.begin(); ik!=listIi.end(); ++ik)
{
BB *curr(*ik);
#else
for(BB *curr : listIi) for(BB *curr : listIi)
{ {
#endif
for (j = 0; j < curr->edges.size(); j++) for (j = 0; j < curr->edges.size(); j++)
{ {
succ = curr->edges[j].BBptr; 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 * Determines the number of in edges to each new BB, and places it
* in numInEdges and inEdgeCount for later interval processing. */ * in numInEdges and inEdgeCount for later interval processing. */
curr = new_entry.Gi = bbs.front(); 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) 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) for(TYPEADR_TYPE &edge : curr->edges)
{ {
#endif
BBnode = new_entry.Gi; /* BB of an interval */ BBnode = new_entry.Gi; /* BB of an interval */
auto iter= std::find_if(bbs.begin(),bbs.end(), auto iter= std::find_if(bbs.begin(),bbs.end(),
[&edge](BB *node)->bool { return edge.intPtr==node->correspInt;}); [&edge](BB *node)->bool { return edge.intPtr==node->correspInt;});
if(iter==bbs.end()) if(iter==bbs.end())
fatalError (INVALID_INT_BB); fatalError (INVALID_INT_BB);
edge.BBptr = *iter; edge.BBptr = *iter;
(*iter)->inEdges.push_back(0); (*iter)->inEdges.push_back((BB *)nullptr);
(*iter)->inEdgeCount++; (*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). /* Finds the derived sequence of the graph derivedG->Gi (ie. cfg).
* Constructs the n-th order graph and places all the intermediate graphs * Constructs the n-th order graph and places all the intermediate graphs
* in the derivedG list sequence. */ * in the derivedG list sequence. */
uint8_t Function::findDerivedSeq (derSeq *derivedGi) uint8_t Function::findDerivedSeq (derSeq &derivedGi)
{ {
BB *Gi; /* Current derived sequence graph */ BB *Gi; /* Current derived sequence graph */
derSeq::iterator iter=derivedGi->begin(); derSeq::iterator iter=derivedGi.begin();
Gi = iter->Gi; Gi = iter->Gi;
while (! trivialGraph (Gi)) while (! trivialGraph (Gi))
{ {
@@ -335,12 +353,12 @@ uint8_t Function::findDerivedSeq (derSeq *derivedGi)
if (! trivialGraph (Gi)) if (! trivialGraph (Gi))
{ {
++iter; ++iter;
derivedGi->erase(iter,derivedGi->end()); /* remove Gi+1 */ derivedGi.erase(iter,derivedGi.end()); /* remove Gi+1 */
// freeDerivedSeq(derivedGi->next); // freeDerivedSeq(derivedGi->next);
// derivedGi->next = NULL; // derivedGi->next = NULL;
return FALSE; return FALSE;
} }
derivedGi->back().findIntervals (this); derivedGi.back().findIntervals (this);
return TRUE; return TRUE;
} }
@@ -381,7 +399,7 @@ derSeq * Function::checkReducibility()
der_seq = new derSeq; der_seq = new derSeq;
der_seq->resize(1); der_seq->resize(1);
der_seq->back().Gi = m_cfg.front(); der_seq->back().Gi = m_cfg.front();
reducible = findDerivedSeq(der_seq); reducible = findDerivedSeq(*der_seq);
if (! reducible) if (! reducible)
{ {

View File

@@ -399,7 +399,6 @@ static int signex(uint8_t b)
return ((b & 0x80)? (int)(0xFFFFFF00 | s): (int)s); return ((b & 0x80)? (int)(0xFFFFFF00 | s): (int)s);
} }
/**************************************************************************** /****************************************************************************
* setAddress - Updates the source or destination field for the current * setAddress - Updates the source or destination field for the current
* icode, based on fdst and the TO_REG flag. * 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->seg = rDS; /* any other indexed reg */
} }
} }
pm->regi = (uint8_t)reg;
pm->regi = (eReg)reg;
pm->off = (int16_t)off; pm->off = (int16_t)off;
if (reg && reg < INDEXBASE && (stateTable[i].flg & B)) 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 */ if (seg) /* So we can catch invalid use of segment overrides */

View File

@@ -68,8 +68,8 @@ private:
unordered_map<SYMTABLE,string> z2; unordered_map<SYMTABLE,string> z2;
}; };
TABLEINFO_TYPE tableInfo[NUM_TABLE_TYPES]; /* Array of info about tables */ static TABLEINFO_TYPE tableInfo[NUM_TABLE_TYPES]; /* Array of info about tables */
TABLEINFO_TYPE currentTabInfo; static TABLEINFO_TYPE currentTabInfo;
/* Create a new symbol table. Returns "handle" */ /* Create a new symbol table. Returns "handle" */
void TABLEINFO_TYPE::create(tableType type) void TABLEINFO_TYPE::create(tableType type)

View File

@@ -91,8 +91,14 @@ void udm(void)
void Function::displayCFG() void Function::displayCFG()
{ {
printf("\nBasic Block List - Proc %s", name.c_str()); 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) for (BB *pBB : m_cfg)
{ {
#endif
pBB->display(); pBB->display();
} }
} }