removed ip dword from findIdioms, it's using iterators now, also switched to using iterators in IDX_ARRAY

This commit is contained in:
Artur K 2012-02-25 22:38:22 +01:00
parent 95ec23eceb
commit 9a6788fd2d
23 changed files with 428 additions and 433 deletions

View File

@ -57,7 +57,7 @@ private:
public:
dword procEntry; /* label number */
char name[SYMLEN]; /* Meaningful name for this proc */
std::string name; /* Meaningful name for this proc */
STATE state; /* Entry state */
Int depth; /* Depth at which we found it - for printing */
flags32 flg; /* Combination of Icode & Proc flags */
@ -84,13 +84,12 @@ public:
Function(void *ty=0) : procEntry(0),depth(0),flg(0),cbParam(0),cfg(0),dfsLast(0),numBBs(0),
hasCase(false),liveIn(0),liveOut(0),liveAnal(0)//,next(0),prev(0)
{
memset(name,0,SYMLEN);
}
public:
static Function *Create(void *ty=0,int Linkage=0,const std::string &nm="",void *module=0)
{
Function *r=new Function(ty);
strncpy(r->name,nm.c_str(),SYMLEN);
r->name = nm;
return r;
}
void compoundCond();

View File

@ -60,10 +60,10 @@ public:
static COND_EXPR *idOther(byte seg, byte regi, int16 off);
static COND_EXPR *idParam(Int off, const STKFRAME *argSymtab);
static COND_EXPR *unary(condNodeType t, COND_EXPR *sub_expr);
static COND_EXPR *idLong(LOCAL_ID *localId, opLoc sd, iICODE pIcode, hlFirst f, Int ix, operDu du, Int off);
static COND_EXPR *idLong(LOCAL_ID *localId, opLoc sd, iICODE pIcode, hlFirst f, iICODE ix, operDu du, Int off);
static COND_EXPR *idFunc(Function *pproc, STKFRAME *args);
static COND_EXPR *idID(const ID *retVal, LOCAL_ID *locsym, Int ix);
static COND_EXPR *id(const ICODE &pIcode, opLoc sd, Function *pProc, Int i, ICODE &duIcode, operDu du);
static COND_EXPR *idID(const ID *retVal, LOCAL_ID *locsym, iICODE ix_);
static COND_EXPR *id(const ICODE &pIcode, opLoc sd, Function *pProc, iICODE ix_, ICODE &duIcode, operDu du);
static COND_EXPR *boolOp(COND_EXPR *lhs, COND_EXPR *rhs, condOp op);
public:
COND_EXPR *clone();

View File

@ -4,6 +4,8 @@
****************************************************************************/
#pragma once
#include <llvm/ADT/ilist.h>
#include <bitset>
#include "types.h"
#include "ast.h"
#include "icode.h"
@ -123,6 +125,8 @@ struct PROG /* Loaded program image parameters */
extern PROG prog; /* Loaded program image parameters */
extern dword duReg[30]; /* def/use bits for registers */
//extern dword duReg[30]; /* def/use bits for registers */
extern dword maskDuReg[30]; /* masks off du bits for regs */
/* Registers used by icode instructions */

View File

@ -10,9 +10,9 @@
#include <algorithm>
#include "icode.h"
/* Type definition */
struct IDX_ARRAY : public std::vector<int>
struct IDX_ARRAY : public std::vector<iICODE>
{
bool inList(int idx)
bool inList(iICODE idx)
{
return std::find(begin(),end(),idx)!=end();
}
@ -70,6 +70,7 @@ struct ID
{
hlType type; /* Probable type */
boolT illegal; /* Boolean: not a valid field any more */
//std::vector<iICODE> idx;
IDX_ARRAY idx; /* Index into icode array (REG_FRAME only) */
frameType loc; /* Frame location */
boolT hasMacro; /* Identifier requires a macro */
@ -118,15 +119,15 @@ public:
Int newByteWordReg(hlType t, byte regi);
Int newByteWordStk(hlType t, Int off, byte regOff);
Int newIntIdx(int16 seg, int16 off, byte regi, Int ix, hlType t);
Int newLongReg(hlType t, byte regH, byte regL, Int ix);
Int newLong(opLoc sd, ICODE *pIcode, hlFirst f, Int ix, operDu du, Int off);
Int newLongReg(hlType t, byte regH, byte regL, iICODE ix_);
Int newLong(opLoc sd, ICODE *pIcode, hlFirst f, iICODE ix, operDu du, Int off);
void newIdent(hlType t, frameType f);
void flagByteWordId(Int off);
void propLongId(byte regL, byte regH, const char *name);
size_t csym() const {return id_arr.size();}
protected:
Int newLongIdx(int16 seg, int16 offH, int16 offL, byte regi, Int ix, hlType t);
Int newLongGlb(int16 seg, int16 offH, int16 offL, Int ix, hlType t);
Int newLongIdx(int16 seg, int16 offH, int16 offL, byte regi, hlType t);
Int newLongGlb(int16 seg, int16 offH, int16 offL, hlType t);
Int newLongStk(hlType t, Int offH, Int offL);
};

View File

@ -2,9 +2,10 @@
* dcc project header
* (C) Cristina Cifuentes, Mike van Emmerik
****************************************************************************/
/* STATE TABLE */
#pragma once
#include <cstring>
#include "types.h"
/* STATE TABLE */
struct STATE
{
dword IP; /* Offset into Image */
@ -16,7 +17,6 @@ struct STATE
int16 immed; /* Contents of the previous register */
} JCond;
void setState(word reg, int16 value);
public:
void checkStartup();
STATE() : IP(0)
{

View File

@ -28,13 +28,12 @@ static const char *condOpSym[] = { " <= ", " < ", " == ", " != ", " > ", " >= ",
//typedef struct _EXP_STK {
// COND_EXPR *exp;
// struct _EXP_STK *next;
//} EXP_STK;
//} EXP_STK; - for local expression stack
/* Returns the integer i in C hexadecimal format */
static char *hexStr (uint16_t i)
{
static char buf[10];
// i &= 0xFFFF;
sprintf (buf, "%s%x", (i > 9) ? "0x" : "", i);
return (buf);
}
@ -258,8 +257,9 @@ COND_EXPR *COND_EXPR::idLongIdx (Int idx)
/* Returns an identifier conditional expression node of type LONG_VAR */
COND_EXPR *COND_EXPR::idLong(LOCAL_ID *localId, opLoc sd, iICODE pIcode, hlFirst f, Int ix, operDu du, Int off)
COND_EXPR *COND_EXPR::idLong(LOCAL_ID *localId, opLoc sd, iICODE pIcode, hlFirst f, iICODE ix, operDu du, Int off)
{
printf("**************** is equal %s ***************** \n",pIcode==ix ? "yes":"no");
Int idx;
COND_EXPR *newExp = new COND_EXPR(IDENTIFIER);
@ -317,7 +317,7 @@ COND_EXPR *COND_EXPR::idOther(byte seg, byte regi, int16 off)
/* Returns an identifier conditional expression node of type TYPE_LONG or
* TYPE_WORD_SIGN */
COND_EXPR *COND_EXPR::idID (const ID *retVal, LOCAL_ID *locsym, Int ix)
COND_EXPR *COND_EXPR::idID (const ID *retVal, LOCAL_ID *locsym, iICODE ix_)
{
COND_EXPR *newExp;
Int idx;
@ -325,7 +325,7 @@ COND_EXPR *COND_EXPR::idID (const ID *retVal, LOCAL_ID *locsym, Int ix)
newExp = new COND_EXPR(IDENTIFIER);
if (retVal->type == TYPE_LONG_SIGN)
{
idx = locsym->newLongReg (TYPE_LONG_SIGN, retVal->id.longId.h,retVal->id.longId.l, ix);
idx = locsym->newLongReg (TYPE_LONG_SIGN, retVal->id.longId.h,retVal->id.longId.l, ix_);
newExp->expr.ident.idType = LONG_VAR;
newExp->expr.ident.idNode.longIdx = idx;
}
@ -344,7 +344,7 @@ COND_EXPR *COND_EXPR::idID (const ID *retVal, LOCAL_ID *locsym, Int ix)
* Arguments: i : index into the icode array, used for newLongRegId only.
* duIcode: icode instruction that needs the du set.
* du: operand is defined or used in current instruction. */
COND_EXPR *COND_EXPR::id(const ICODE &pIcode, opLoc sd, Function * pProc, Int i,ICODE &duIcode, operDu du)
COND_EXPR *COND_EXPR::id(const ICODE &pIcode, opLoc sd, Function * pProc, iICODE ix_,ICODE &duIcode, operDu du)
{
COND_EXPR *newExp;
@ -356,7 +356,7 @@ COND_EXPR *COND_EXPR::id(const ICODE &pIcode, opLoc sd, Function * pProc, Int i,
((sd == SRC) && pIcode.ic.ll.anyFlagSet(IM_SRC)) or
(sd == LHS_OP)) /* for MUL lhs */
{ /* implicit dx:ax */
idx = pProc->localId.newLongReg (TYPE_LONG_SIGN, rDX, rAX, i);
idx = pProc->localId.newLongReg (TYPE_LONG_SIGN, rDX, rAX, ix_);
newExp = COND_EXPR::idLongIdx (idx);
duIcode.setRegDU (rDX, du);
duIcode.setRegDU (rAX, du);

View File

@ -39,7 +39,7 @@ Int getNextLabel()
/* displays statistics on the subroutine */
void Function::displayStats ()
{
printf("\nStatistics - Subroutine %s\n", name);
printf("\nStatistics - Subroutine %s\n", name.c_str());
printf ("Number of Icode instructions:\n");
printf (" Low-level : %4d\n", stats.numLLIcode);
if (! (flg & PROC_ASM))
@ -240,9 +240,9 @@ void Function::codeGen (std::ostream &fs)
/* Write procedure/function header */
newBundle (&cCode);
if (flg & PROC_IS_FUNC) /* Function */
cCode.appendDecl( "\n%s %s (", hlTypes[retVal.type],name);
cCode.appendDecl( "\n%s %s (", hlTypes[retVal.type],name.c_str());
else /* Procedure */
cCode.appendDecl( "\nvoid %s (", name);
cCode.appendDecl( "\nvoid %s (", name.c_str());
/* Write arguments */
memset (buf, 0, sizeof(buf));

View File

@ -452,7 +452,7 @@ bool LibCheck(Function & pProc)
if (fileOffset == prog.offMain)
{
/* Easy - this function is called main! */
strcpy(pProc.name, "main");
pProc.name = "main";
return false;
}
@ -464,10 +464,10 @@ bool LibCheck(Function & pProc)
if (memcmp(ht[h].htPat, pat, PATLEN) == 0)
{
/* We have a match. Save the name, if not already set */
if (pProc.name[0] == '\0') /* Don't overwrite existing name */
if (pProc.name.empty() ) /* Don't overwrite existing name */
{
/* Give proc the new name */
strcpy(pProc.name, ht[h].htSym);
pProc.name = ht[h].htSym;
}
/* But is it a real library function? */
i = NIL;
@ -518,7 +518,7 @@ bool LibCheck(Function & pProc)
pattMsChkstk, sizeof(pattMsChkstk), &Idx))
{
/* Found _chkstk */
strcpy(pProc.name, "chkstk");
pProc.name = "chkstk";
pProc.flg |= PROC_ISLIB; /* We'll say its a lib function */
pProc.args.numArgs = 0; /* With no args */
}

View File

@ -350,10 +350,10 @@ static boolT successor (Int s, Int h, Function * pProc)
}
static void tagNodesInCase (BB * pBB, nodeList &l, Int head, Int tail)
/* Recursive procedure to tag nodes that belong to the case described by
* the list l, head and tail (dfsLast index to first and exit node of the
* case). */
static void tagNodesInCase (BB * pBB, nodeList &l, Int head, Int tail)
{ Int current, /* index to current node */
i;

View File

@ -81,7 +81,7 @@ Int STKFRAME::getLocVar(Int off)
/* Returns a string with the source operand of Icode */
static COND_EXPR *srcIdent (const ICODE &Icode, Function * pProc, Int i, ICODE & duIcode, operDu du)
static COND_EXPR *srcIdent (const ICODE &Icode, Function * pProc, iICODE i, ICODE & duIcode, operDu du)
{
COND_EXPR *n;
@ -99,7 +99,7 @@ static COND_EXPR *srcIdent (const ICODE &Icode, Function * pProc, Int i, ICODE &
/* Returns the destination operand */
static COND_EXPR *dstIdent (const ICODE & Icode, Function * pProc, Int i, ICODE & duIcode, operDu du)
static COND_EXPR *dstIdent (const ICODE & Icode, Function * pProc, iICODE i, ICODE & duIcode, operDu du)
{
COND_EXPR *n;
n = COND_EXPR::id (Icode, DST, pProc, i, duIcode, du);
@ -147,8 +147,8 @@ void Function::elimCondCodes ()
switch (defAt->GetLlOpcode())
{
case iCMP:
rhs = srcIdent (*defAt, this, defAt->loc_ip,*useAt, eUSE);
lhs = dstIdent (*defAt, this, defAt->loc_ip,*useAt, eUSE);
rhs = srcIdent (*defAt, this, (defAt+1).base(),*useAt, eUSE);
lhs = dstIdent (*defAt, this, (defAt+1).base(),*useAt, eUSE);
break;
case iOR:
@ -161,8 +161,8 @@ void Function::elimCondCodes ()
break;
case iTEST:
rhs = srcIdent (*defAt,this, defAt->loc_ip,*useAt, eUSE);
lhs = dstIdent (*defAt,this, defAt->loc_ip,*useAt, eUSE);
rhs = srcIdent (*defAt,this, (defAt+1).base(),*useAt, eUSE);
lhs = dstIdent (*defAt,this, (defAt+1).base(),*useAt, eUSE);
lhs = COND_EXPR::boolOp (lhs, rhs, AND);
if (defAt->isLlFlag(B))
rhs = COND_EXPR::idKte (0, 1);
@ -301,7 +301,9 @@ void Function::liveRegAnalysis (dword in_liveOut)
auto picode = pbb->rbegin2(); /* icode of function return */
if (picode->ic.hl.opcode == HLI_RET)
{
picode->ic.hl.oper.exp = COND_EXPR::idID (&retVal, &localId, pbb->back().loc_ip);
//pbb->back().loc_ip
picode->ic.hl.oper.exp = COND_EXPR::idID (&retVal, &localId,
(++pbb->rbegin2()).base());
picode->du.use = in_liveOut;
}
}
@ -856,7 +858,8 @@ void Function::findExps()
}
else /* cannot substitute function */
{
lhs = COND_EXPR::idID(retVal,&localId,picode->loc_ip);
//picode->loc_ip
lhs = COND_EXPR::idID(retVal,&localId,picode);
picode->setAsgn(lhs, exp);
}
break;
@ -955,7 +958,7 @@ void Function::findExps()
picode->ic.hl.oper.call.args);
ticode->ic.hl.oper.asgn.lhs =
COND_EXPR::idLong(&localId, DST, ticode,
HIGH_FIRST, picode->loc_ip, eDEF, 1);
HIGH_FIRST, picode, eDEF, 1);//picode->loc_ip
ticode->ic.hl.oper.asgn.rhs = exp;
picode->invalidate();
numHlIcodes--;
@ -980,7 +983,7 @@ void Function::findExps()
localId.newLongReg
(
retVal->type, retVal->id.longId.h,
retVal->id.longId.l, picode->loc_ip));
retVal->id.longId.l, picode/*picode->loc_ip*/));
if (res) /* was substituted */
{
picode->invalidate();
@ -988,7 +991,7 @@ void Function::findExps()
}
else /* cannot substitute function */
{
lhs = COND_EXPR::idID(retVal,&localId,picode->loc_ip);
lhs = COND_EXPR::idID(retVal,&localId,picode/*picode->loc_ip*/);
picode->setAsgn(lhs, exp);
}
break;
@ -1065,7 +1068,7 @@ void Function::findExps()
exp = COND_EXPR::idFunc (picode->ic.hl.oper.call.proc,
picode->ic.hl.oper.call.args);
lhs = COND_EXPR::idID (&picode->ic.hl.oper.call.proc->retVal,
&localId, picode->loc_ip);
&localId, picode/*picode->loc_ip*/);
picode->setAsgn(lhs, exp);
}
}
@ -1106,7 +1109,7 @@ void Function::dataFlow(dword liveOut)
retVal.loc = REG_FRAME;
retVal.id.longId.h = rDX;
retVal.id.longId.l = rAX;
idx = localId.newLongReg(TYPE_LONG_SIGN, rDX, rAX, 0);
idx = localId.newLongReg(TYPE_LONG_SIGN, rDX, rAX, Icode.begin()/*0*/);
localId.propLongId (rAX, rDX, "\0");
}
else if (isAx || isBx || isCx || isDx) /* word */

View File

@ -238,7 +238,7 @@ void disassem(Int pass, Function * ppProc)
/* Write procedure header */
if (pass != 3)
fprintf(fp, "\t\t%s PROC %s\n", pProc->name, (pProc->flg & PROC_FAR)? "FAR": "NEAR");
fprintf(fp, "\t\t%s PROC %s\n", pProc->name.c_str(), (pProc->flg & PROC_FAR)? "FAR": "NEAR");
/* Loop over array printing each record */
for (i = nextInst = 0; i < numIcode; i++)
@ -249,7 +249,7 @@ void disassem(Int pass, Function * ppProc)
/* Write procedure epilogue */
if (pass != 3)
{
fprintf(fp, "\n\t\t%s ENDP\n\n", pProc->name);
fprintf(fp, "\n\t\t%s ENDP\n\n", pProc->name.c_str());
fclose(fp);
}

View File

@ -3,40 +3,36 @@
* (C) Cristina Cifuentes
***************************************************************************/
#include "dcc.h"
#include <stdio.h>
#include <stdlib.h>
//#ifndef __UNIX__
#if 1
#include <map>
#include <string>
#include <stdarg.h>
#else
#include <varargs.h>
#endif
static const char *errorMessage[] = {
"Invalid option -%c\n", /* INVALID_ARG */
"Invalid instruction %02X at location %06lX\n", /* INVALID_OPCODE */
"Don't understand 80386 instruction %02X at location %06lX\n", /* INVALID_386OP */
"Segment override with no memory operand at location %06lX\n", /* FUNNY_SEGOVR */
"REP prefix without a string instruction at location %06lX\n",/* FUNNY_REP */
"Cannot open %s\n", /* CANNOT_OPEN */
"Error while reading %s\n", /* CANNOT_READ */
"malloc of %ld bytes failed\n", /* MALLOC_FAILED */
"Don't understand new EXE format\n", /* NEWEXE_FORMAT */
"Failed to find a BB for jump to %ld in proc %s\n", /* NO_BB */
"Basic Block is a synthetic jump\n", /* INVALID_SYNTHETIC_BB */
"Failed to find a BB for interval\n", /* INVALID_INT_BB */
"Instruction at location %06lX goes beyond loaded image\n", /* IP_OUT_OF_RANGE*/
"Definition not found for condition code usage at opcode %d\n",
/* DEF_NOT_FOUND */
"JX use, definition not supported at opcode #%d\n", /* JX_NOT_DEF */
"Def - use not supported. Def op = %d, use op = %d.\n", /* NOT_DEF_USE */
"Failed to construct repeat..until() condition.\n", /* REPEAT_FAIL */
"Failed to construct while() condition.\n", /* WHILE_FAIL */
#include "dcc.h"
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.
****************************************************************************/
@ -56,7 +52,7 @@ void fatalError(eErrorId errId, ...)
fprintf(stderr,"Usage: dcc [-a1a2cmpsvVi][-o asmfile] DOS_executable\n");
else {
fprintf(stderr, "dcc: ");
vfprintf(stderr, errorMessage[errId - 1], args);
vfprintf(stderr, errorMessage[errId].c_str(), args);
}
va_end(args);
exit((int)errId);
@ -78,6 +74,6 @@ void reportError(eErrorId errId, ...)
va_start(args, errId);
#endif
fprintf(stderr, "dcc: ");
vfprintf(stderr, errorMessage[errId - 1], args);
vfprintf(stderr, errorMessage[errId].c_str(), args);
va_end(args);
}

View File

@ -70,7 +70,7 @@ void FrontEnd (char *filename, CALL_GRAPH * *pcallGraph)
displayLoadInfo();
/* Do depth first flow analysis building call graph and procedure list,
* and attaching the I-code to each procedure */
* and attaching the I-code to each procedure */
parse (pcallGraph);
if (option.asm1)
@ -110,7 +110,7 @@ static void displayLoadInfo(void)
printf("File type is %s\n", (prog.fCOM)?"COM":"EXE");
if (! prog.fCOM) {
printf("Signature = %02X%02X\n", header.sigLo, header.sigHi);
printf("File size %% 512 = %04X\n", LH(&header.lastPageSize));
printf("File size %% 512 = %04X\n", LH(&header.lastPageSize));
printf("File size / 512 = %04X pages\n", LH(&header.numPages));
printf("# relocation items = %04X\n", LH(&header.numReloc));
printf("Offset to load image = %04X paras\n", LH(&header.numParaHeader));

View File

@ -148,7 +148,7 @@ CondJumps:
auto iter2=std::find_if(heldBBs.begin(),heldBBs.end(),
[ip](BB *psBB)->bool {return psBB->begin()==ip;});
if(iter2==heldBBs.end())
fatalError(NO_BB, ip, name);
fatalError(NO_BB, ip, name.c_str());
psBB = *iter2;
pBB->edges[i].BBptr = psBB;
psBB->inEdges.push_back(0);

View File

@ -136,14 +136,15 @@ boolT ICODE::removeDefRegi (byte regi, Int thisDefIdx, LOCAL_ID *locId)
void Function::highLevelGen()
{ Int i, /* idx into icode array */
numIcode; /* number of icode instructions */
ICODE * pIcode; /* ptr to current icode node */
iICODE pIcode; /* ptr to current icode node */
COND_EXPR *lhs, *rhs; /* left- and right-hand side of expression */
flags32 flg; /* icode flags */
numIcode = Icode.size();
for (i = 0; i < numIcode; i++)
for (iICODE i = Icode.begin(); i!=Icode.end() ; ++i)
{
pIcode = Icode.GetIcode(i);
assert(numIcode==Icode.size());
pIcode = i; //Icode.GetIcode(i)
if ((pIcode->ic.ll.flg & NOT_HLL) == NOT_HLL)
pIcode->invalidate();
if ((pIcode->type == LOW_LEVEL) && (pIcode->invalid == FALSE))

View File

@ -15,7 +15,7 @@
CIcodeRec::CIcodeRec()
{
//reserve(512);
reserve(1024);
}
/* Copies the icode that is pointed to by pIcode to the icode array.
@ -35,7 +35,7 @@ void CIcodeRec::SetInBB(int start, int end, BB *pnewBB)
}
/* labelSrchRepl - Searches the icodes for instruction with label = target, and
replaces *pIndex with an icode index */
replaces *pIndex with an icode index */
bool CIcodeRec::labelSrch(dword target, dword &pIndex)
{
Int i;
@ -45,10 +45,10 @@ bool CIcodeRec::labelSrch(dword target, dword &pIndex)
if (at(i).ic.ll.label == target)
{
pIndex = i;
return TRUE;
return true;
}
}
return FALSE;
return false;
}
ICODE * CIcodeRec::GetIcode(int ip)

View File

@ -267,12 +267,12 @@ static void popStkVars (iICODE pIcode, iICODE pEnd, Function * pProc)
* POP BP
* RET(F)
*****************************************************************************/
static Int idiom2(iICODE pIcode, iICODE pEnd, Int ip, Function * pProc)
static Int idiom2(iICODE pIcode, iICODE pEnd, Function * pProc)
{
iICODE nicode;
/* Match MOV SP, BP */
if (ip != 0 && ((pIcode->ic.ll.flg & I) != I) &&
if (pIcode->loc_ip != 0 && ((pIcode->ic.ll.flg & I) != I) &&
pIcode->ic.ll.dst.regi == rSP && pIcode->ic.ll.src.regi == rBP)
{
/* Get next icode, skip over holes in the icode array */
@ -1056,7 +1056,7 @@ static boolT idiom20 (iICODE picode, iICODE pend, Function * pproc)
****************************************************************************/
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 delta;
COND_EXPR *rhs, *lhs; /* Pointers to left and right hand side exps */
@ -1066,7 +1066,6 @@ void Function::findIdioms()
pIcode = Icode.begin();
pEnd = Icode.end();
ip = 0;
while (pIcode < pEnd)
{
@ -1075,25 +1074,23 @@ void Function::findIdioms()
case iDEC: case iINC:
if (idiom18 (pIcode, pEnd, this))
{
lhs = COND_EXPR::id (*(pIcode-1), SRC, this, ip, *pIcode, eUSE);
lhs = COND_EXPR::id (*(pIcode-1), SRC, this, pIcode, *pIcode, eUSE);
if (pIcode->ic.ll.opcode == iDEC)
lhs = COND_EXPR::unary (POST_DEC, lhs);
else
lhs = COND_EXPR::unary (POST_INC, lhs);
rhs = COND_EXPR::id (*(pIcode+1), SRC, this, ip, *(pIcode+2), eUSE);
exp = COND_EXPR::boolOp (lhs, rhs,
condOpJCond[(pIcode+2)->ic.ll.opcode - iJB]);
rhs = COND_EXPR::id (*(pIcode+1), SRC, this, pIcode, *(pIcode+2), eUSE);
exp = COND_EXPR::boolOp (lhs, rhs, condOpJCond[(pIcode+2)->ic.ll.opcode - iJB]);
(pIcode+2)->setJCond(exp);
(pIcode-1)->invalidate();
pIcode->invalidate();
(pIcode+1)->invalidate();
pIcode += 3;
ip += 2;
}
else if (idiom19 (pIcode, pEnd, this))
{
lhs = COND_EXPR::id (*pIcode, DST, this, ip, *(pIcode+1), eUSE);
lhs = COND_EXPR::id (*pIcode, DST, this, pIcode, *(pIcode+1), eUSE);
if (pIcode->ic.ll.opcode == iDEC)
lhs = COND_EXPR::unary (PRE_DEC, lhs);
else
@ -1104,16 +1101,15 @@ void Function::findIdioms()
(pIcode+1)->setJCond(exp);
pIcode->invalidate();
pIcode += 2;
ip++;
}
else if (idiom20 (pIcode, pEnd, this))
{
lhs = COND_EXPR::id (*(pIcode+1), SRC, this, ip, *pIcode, eUSE);
lhs = COND_EXPR::id (*(pIcode+1), SRC, this, pIcode, *pIcode, eUSE);
if (pIcode->ic.ll.opcode == iDEC)
lhs = COND_EXPR::unary (PRE_DEC, lhs);
else
lhs = COND_EXPR::unary (PRE_INC, lhs);
rhs = COND_EXPR::id (*(pIcode+2), SRC, this, ip, *(pIcode+3), eUSE);
rhs = COND_EXPR::id (*(pIcode+2), SRC, this, pIcode, *(pIcode+3), eUSE);
exp = COND_EXPR::boolOp (lhs, rhs,
condOpJCond[(pIcode+3)->ic.ll.opcode - iJB]);
(pIcode+3)->setJCond(exp);
@ -1121,7 +1117,6 @@ void Function::findIdioms()
(pIcode+1)->invalidate();
(pIcode+2)->invalidate();
pIcode += 3;
ip += 2;
}
else
pIcode++;
@ -1134,43 +1129,38 @@ void Function::findIdioms()
for ( ; idx > 0; idx--)
{
(pIcode++)->invalidate();
ip++;
}
ip--;
}
else
pIcode++;
break;
case iMOV: /* Idiom 2 */
if (idx = idiom2(pIcode, pEnd, ip, this))
if (idx = idiom2(pIcode, pEnd, this))
{
pIcode->invalidate();
(pIcode+1)->invalidate();
pIcode += 3;
ip += 2;
}
else if (idiom14 (pIcode, pEnd, &regL, &regH)) /* Idiom 14 */
{
idx = localId.newLongReg (TYPE_LONG_SIGN, regH, regL, ip);
idx = localId.newLongReg (TYPE_LONG_SIGN, regH, regL, pIcode/*ip*/);
lhs = COND_EXPR::idLongIdx (idx);
pIcode->setRegDU( regH, eDEF);
rhs = COND_EXPR::id (*pIcode, SRC, this, ip, *pIcode, NONE);
rhs = COND_EXPR::id (*pIcode, SRC, this, pIcode, *pIcode, NONE);
pIcode->setAsgn(lhs, rhs);
(pIcode+1)->invalidate();
pIcode += 2;
ip++;
}
else if (idx = idiom13 (pIcode, pEnd)) /* Idiom 13 */
{
lhs = COND_EXPR::idReg (idx, 0, &localId);
pIcode->setRegDU( idx, eDEF);
pIcode->du1.numRegsDef--; /* prev byte reg def */
rhs = COND_EXPR::id (*pIcode, SRC, this, ip, *pIcode, NONE);
rhs = COND_EXPR::id (*pIcode, SRC, this, pIcode, *pIcode, NONE);
pIcode->setAsgn(lhs, rhs);
(pIcode+1)->invalidate();
pIcode += 2;
ip++;
}
else
pIcode++;
@ -1185,7 +1175,7 @@ void Function::findIdioms()
{
if ((pIcode->ic.ll.src.proc.proc->retVal.type==TYPE_LONG_SIGN)
|| (pIcode->ic.ll.src.proc.proc->retVal.type == TYPE_LONG_UNSIGN))
localId.newLongReg(TYPE_LONG_SIGN, rDX, rAX, ip);
localId.newLongReg(TYPE_LONG_SIGN, rDX, rAX, pIcode/*ip*/);
}
/* Check for idioms */
@ -1198,7 +1188,6 @@ void Function::findIdioms()
(pIcode->ic.ll.src.proc.proc)->flg |= CALL_C;
pIcode++;
(pIcode++)->invalidate();
ip++;
}
else
{
@ -1213,10 +1202,12 @@ void Function::findIdioms()
(pIcode->ic.ll.src.proc.proc)->cbParam = (int16)idx;
pIcode->ic.ll.src.proc.cb = idx;
(pIcode->ic.ll.src.proc.proc)->flg |= CALL_C;
ip += idx/2 - 1;
pIcode++;
//ip += 1; +1 is added out of switch
pIcode++; // skip call(f)
for (idx /= 2; idx > 0; idx--)
{
(pIcode++)->invalidate();
}
}
// TODO : it's a calculated call
else
@ -1238,15 +1229,15 @@ void Function::findIdioms()
case iADD: /* Idiom 5 */
if (idiom5 (pIcode, pEnd))
{
lhs = COND_EXPR::idLong (&localId, DST, pIcode, LOW_FIRST,
ip, USE_DEF, 1);
pIcode/*ip*/, USE_DEF, 1);
rhs = COND_EXPR::idLong (&localId, SRC, pIcode, LOW_FIRST,
ip, eUSE, 1);
pIcode/*ip*/, eUSE, 1);
exp = COND_EXPR::boolOp (lhs, rhs, ADD);
pIcode->setAsgn(lhs, exp);
(pIcode+1)->invalidate();
pIcode++;
ip++;
}
pIcode++;
break;
@ -1255,7 +1246,7 @@ void Function::findIdioms()
if (idiom8 (pIcode, pEnd))
{
idx = localId.newLongReg(TYPE_LONG_SIGN,
pIcode->ic.ll.dst.regi, (pIcode+1)->ic.ll.dst.regi,ip);
pIcode->ic.ll.dst.regi, (pIcode+1)->ic.ll.dst.regi,pIcode/*ip*/);
lhs = COND_EXPR::idLongIdx (idx);
pIcode->setRegDU( (pIcode+1)->ic.ll.dst.regi, USE_DEF);
rhs = COND_EXPR::idKte (1, 2);
@ -1263,7 +1254,6 @@ void Function::findIdioms()
pIcode->setAsgn(lhs, exp);
(pIcode+1)->invalidate();
pIcode++;
ip++;
}
pIcode++;
break;
@ -1281,13 +1271,12 @@ void Function::findIdioms()
for (idx-- ; idx > 0; idx--)
{
(pIcode++)->invalidate();
ip++;
}
}
else if (idiom12 (pIcode, pEnd)) /* idiom 12 */
{
idx = localId.newLongReg (TYPE_LONG_UNSIGN,
(pIcode+1)->ic.ll.dst.regi, pIcode->ic.ll.dst.regi,ip);
(pIcode+1)->ic.ll.dst.regi, pIcode->ic.ll.dst.regi,pIcode/*ip*/);
lhs = COND_EXPR::idLongIdx (idx);
pIcode->setRegDU( (pIcode+1)->ic.ll.dst.regi, USE_DEF);
rhs = COND_EXPR::idKte (1, 2);
@ -1295,7 +1284,6 @@ void Function::findIdioms()
pIcode->setAsgn(lhs, exp);
(pIcode+1)->invalidate();
pIcode += 2;
ip++;
}
else
pIcode++;
@ -1305,7 +1293,7 @@ void Function::findIdioms()
if (idiom9 (pIcode, pEnd))
{
idx = localId.newLongReg (TYPE_LONG_UNSIGN,
pIcode->ic.ll.dst.regi, (pIcode+1)->ic.ll.dst.regi,ip);
pIcode->ic.ll.dst.regi, (pIcode+1)->ic.ll.dst.regi,pIcode/*ip*/);
lhs = COND_EXPR::idLongIdx (idx);
pIcode->setRegDU( (pIcode+1)->ic.ll.dst.regi, USE_DEF);
rhs = COND_EXPR::idKte (1, 2);
@ -1313,7 +1301,6 @@ void Function::findIdioms()
pIcode->setAsgn(lhs, exp);
(pIcode+1)->invalidate();
pIcode++;
ip++;
}
pIcode++;
break;
@ -1321,13 +1308,12 @@ void Function::findIdioms()
case iSUB: /* Idiom 6 */
if (idiom6 (pIcode, pEnd))
{
lhs = COND_EXPR::idLong (&localId, DST, pIcode, LOW_FIRST, ip, USE_DEF, 1);
rhs = COND_EXPR::idLong (&localId, SRC, pIcode, LOW_FIRST, ip, eUSE, 1);
lhs = COND_EXPR::idLong (&localId, DST, pIcode, LOW_FIRST, pIcode, USE_DEF, 1);
rhs = COND_EXPR::idLong (&localId, SRC, pIcode, LOW_FIRST, pIcode, eUSE, 1);
exp = COND_EXPR::boolOp (lhs, rhs, SUB);
pIcode->setAsgn(lhs, exp);
(pIcode+1)->invalidate();
pIcode++;
ip++;
}
pIcode++;
break;
@ -1341,13 +1327,12 @@ void Function::findIdioms()
if (idiom11 (pIcode, pEnd))
{
lhs = COND_EXPR::idLong (&localId, DST, pIcode, HIGH_FIRST,
ip, USE_DEF, 1);
pIcode/*ip*/, USE_DEF, 1);
rhs = COND_EXPR::unary (NEGATION, lhs);
pIcode->setAsgn(lhs, rhs);
(pIcode+1)->invalidate();
(pIcode+2)->invalidate();
pIcode += 3;
ip += 2;
}
else if (idiom16 (pIcode, pEnd))
{
@ -1359,7 +1344,6 @@ void Function::findIdioms()
(pIcode+1)->invalidate();
(pIcode+2)->invalidate();
pIcode += 3;
ip += 2;
}
else
pIcode++;
@ -1370,25 +1354,26 @@ void Function::findIdioms()
break;
case iENTER: /* ENTER is equivalent to init PUSH bp */
if (ip == 0)
if (pIcode == Icode.begin()) //ip == 0
{
flg |= (PROC_HLL | PROC_IS_HLL);
}
pIcode++;
break;
case iXOR: /* Idiom 7 */
if (idiom21 (pIcode, pEnd))
{
lhs = COND_EXPR::idLong (&localId, DST, pIcode,HIGH_FIRST, ip, eDEF, 1);
lhs = COND_EXPR::idLong (&localId, DST, pIcode,HIGH_FIRST, pIcode/*ip*/, eDEF, 1);
rhs = COND_EXPR::idKte ((pIcode+1)->ic.ll.src.op() , 4);
pIcode->setAsgn(lhs, rhs);
pIcode->du.use = 0; /* clear register used in iXOR */
(pIcode+1)->invalidate();
pIcode++;
ip++;
}
else if (idiom7 (pIcode))
{
lhs = COND_EXPR::id (*pIcode, DST, this, ip, *pIcode, NONE);
lhs = COND_EXPR::id (*pIcode, DST, this, pIcode, *pIcode, NONE);
rhs = COND_EXPR::idKte (0, 2);
pIcode->setAsgn(lhs, rhs);
pIcode->du.use = 0; /* clear register used in iXOR */
@ -1400,7 +1385,6 @@ void Function::findIdioms()
default:
pIcode++;
}
ip++;
}
/* Check if number of parameter bytes match their calling convention */

View File

@ -130,10 +130,10 @@ Int LOCAL_ID::newIntIdx(int16 seg, int16 off, byte 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, byte regH, byte regL, Int ix)
Int LOCAL_ID::newLongReg(hlType t, byte regH, byte regL, iICODE ix_)
{
Int idx;
//iICODE ix_;
/* Check for entry in the table */
for (idx = 0; idx < id_arr.size(); idx++)
{
@ -142,12 +142,12 @@ Int LOCAL_ID::newLongReg(hlType t, byte regH, byte regL, Int ix)
(id_arr[idx].id.longId.l == regL))
{
/* Check for occurrence in the list */
if (id_arr[idx].idx.inList(ix))
if (id_arr[idx].idx.inList(ix_))
return (idx);
else
{
/* Insert icode index in list */
id_arr[idx].idx.push_back(ix);
id_arr[idx].idx.push_back(ix_);
return (idx);
}
}
@ -155,7 +155,7 @@ Int LOCAL_ID::newLongReg(hlType t, byte regH, byte regL, Int ix)
/* Not in the table, create new identifier */
newIdent (t, REG_FRAME);
id_arr[id_arr.size()-1].idx.push_back(ix);
id_arr[id_arr.size()-1].idx.push_back(ix_);
idx = id_arr.size() - 1;
id_arr[idx].id.longId.h = regH;
id_arr[idx].id.longId.l = regL;
@ -166,7 +166,7 @@ Int LOCAL_ID::newLongReg(hlType t, byte regH, byte regL, Int ix)
/* Checks if the entry exists in the locSym, if so, returns the idx to this
* entry; otherwise creates a new global identifier node of type
* TYPE_LONG_(UN)SIGN and returns the index to this new entry. */
Int LOCAL_ID::newLongGlb(int16 seg, int16 offH, int16 offL,Int ix, hlType t)
Int LOCAL_ID::newLongGlb(int16 seg, int16 offH, int16 offL,hlType t)
{
Int idx;
@ -193,7 +193,7 @@ Int LOCAL_ID::newLongGlb(int16 seg, int16 offH, int16 offL,Int ix, hlType t)
/* Checks if the entry exists in the locSym, if so, returns the idx to this
* entry; otherwise creates a new global identifier node of type
* TYPE_LONG_(UN)SIGN and returns the index to this new entry. */
Int LOCAL_ID::newLongIdx( int16 seg, int16 offH, int16 offL,byte regi, Int ix, hlType t)
Int LOCAL_ID::newLongIdx( int16 seg, int16 offH, int16 offL,byte regi, hlType t)
{ Int idx;
/* Check for entry in the table */
@ -249,7 +249,7 @@ Int LOCAL_ID::newLongStk(hlType t, Int offH, Int offL)
/* Returns the index to an appropriate long identifier.
* Note: long constants should be checked first and stored as a long integer
* number in an expression record. */
Int LOCAL_ID::newLong(opLoc sd, ICODE *pIcode, hlFirst f, Int ix,operDu du, Int off)
Int LOCAL_ID::newLong(opLoc sd, ICODE *pIcode, hlFirst f, iICODE ix,operDu du, Int off)
{
Int idx;
LLOperand *pmH, *pmL;
@ -266,7 +266,7 @@ Int LOCAL_ID::newLong(opLoc sd, ICODE *pIcode, hlFirst f, Int ix,operDu du, Int
}
if (pmL->regi == 0) /* global variable */
idx = newLongGlb(pmH->segValue, pmH->off, pmL->off, ix,TYPE_LONG_SIGN);
idx = newLongGlb(pmH->segValue, pmH->off, pmL->off, TYPE_LONG_SIGN);
else if (pmL->regi < INDEXBASE) /* register */
{
@ -282,7 +282,8 @@ Int LOCAL_ID::newLong(opLoc sd, ICODE *pIcode, hlFirst f, Int ix,operDu du, Int
idx = newLongStk(TYPE_LONG_SIGN, pmH->off, pmL->off);
else if ((pmL->seg == rDS) && (pmL->regi == INDEXBASE + 7)) /* bx */
{ /* glb var indexed on bx */
idx = newLongIdx(pmH->segValue, pmH->off, pmL->off,rBX, ix, TYPE_LONG_SIGN);
printf("Bx indexed global, BX is an unused parameter to newLongIdx\n");
idx = newLongIdx(pmH->segValue, pmH->off, pmL->off,rBX,TYPE_LONG_SIGN);
pIcode->setRegDU( rBX, eUSE);
}
else /* idx <> bp, bx */
@ -318,15 +319,18 @@ boolT checkLongEq (LONG_STKID_TYPE longId, iICODE pIcode, Int i, Int idx,
if ((longId.offH == pmHdst->off) && (longId.offL == pmLdst->off))
{
*lhs = COND_EXPR::idLongIdx (i);
if ((pIcode->ic.ll.flg & NO_SRC) != NO_SRC)
*rhs = COND_EXPR::idLong (&pProc->localId, SRC, pIcode, HIGH_FIRST,
idx, eUSE, off);
{
*rhs = COND_EXPR::idLong (&pProc->localId, SRC, pIcode, HIGH_FIRST, pIcode, eUSE, off);
//*rhs = COND_EXPR::idLong (&pProc->localId, SRC, pIcode, HIGH_FIRST, idx, eUSE, off);
}
return true;
}
else if ((longId.offH == pmHsrc->off) && (longId.offL == pmLsrc->off))
{
*lhs = COND_EXPR::idLong (&pProc->localId, DST, pIcode, HIGH_FIRST, idx,
eDEF, off);
*lhs = COND_EXPR::idLong (&pProc->localId, DST, pIcode, HIGH_FIRST, pIcode,eDEF, off);
//*lhs = COND_EXPR::idLong (&pProc->localId, DST, pIcode, HIGH_FIRST, idx,eDEF, off);
*rhs = COND_EXPR::idLongIdx (i);
return true;
}
@ -357,12 +361,16 @@ boolT checkLongRegEq (LONGID_TYPE longId, iICODE pIcode, Int i, Int idx,
{
lhs = COND_EXPR::idLongIdx (i);
if ((pIcode->ic.ll.flg & NO_SRC) != NO_SRC)
rhs = COND_EXPR::idLong (&pProc->localId, SRC, pIcode, HIGH_FIRST, idx, eUSE, off);
{
//rhs = COND_EXPR::idLong (&pProc->localId, SRC, pIcode, HIGH_FIRST, idx, eUSE, off);
rhs = COND_EXPR::idLong (&pProc->localId, SRC, pIcode, HIGH_FIRST, pIcode, eUSE, off);
}
return true;
}
else if ((longId.h == pmHsrc->regi) && (longId.l == pmLsrc->regi))
{
lhs = COND_EXPR::idLong (&pProc->localId, DST, pIcode, HIGH_FIRST, idx, eDEF, off);
lhs = COND_EXPR::idLong (&pProc->localId, DST, pIcode, HIGH_FIRST, pIcode, eDEF, off);
//lhs = COND_EXPR::idLong (&pProc->localId, DST, pIcode, HIGH_FIRST, idx, eDEF, off);
rhs = COND_EXPR::idLongIdx (i);
return true;
}

View File

@ -3,14 +3,14 @@
* (C) Cristina Cifuentes, Mike van Emmerik, Jeff Ledermann
****************************************************************************/
#include "dcc.h"
#include <string.h>
#include <stdlib.h> /* For exit() */
#ifdef __DOSWIN__
#include <sstream>
#include <stdio.h>
#endif
#include <algorithm>
#include "dcc.h"
using namespace std;
static void FollowCtrl (Function * pProc, CALL_GRAPH * pcallGraph, STATE * pstate);
static boolT process_JMP (ICODE * pIcode, STATE * pstate,
CALL_GRAPH * pcallGraph);
@ -42,40 +42,38 @@ void parse (CALL_GRAPH * *pcallGraph)
state.IP = ((dword)prog.initCS << 4) + prog.initIP;
SynthLab = SYNTHESIZED_MIN;
// default-construct a Function object !
pProcList.push_back(Function::Create());
/* Check for special settings of initial state, based on idioms of the
startup code */
state.checkStartup();
Function &start_proc(pProcList.front());
/* Make a struct for the initial procedure */
// default-construct a Function object !
pProcList.push_back(Function::Create());
if (prog.offMain != -1)
{
/* We know where main() is. Start the flow of control from there */
pProcList.front().procEntry = prog.offMain;
start_proc.procEntry = prog.offMain;
/* In medium and large models, the segment of main may (will?) not be
the same as the initial CS segment (of the startup code) */
state.setState(rCS, prog.segMain);
strcpy(pProcList.front().name, "main");
start_proc.name = "main";
state.IP = prog.offMain;
}
else
{
/* Create initial procedure at program start address */
strcpy(pProcList.front().name, "start");
pProcList.front().procEntry = (dword)state.IP;
start_proc.name="start";
start_proc.procEntry = (dword)state.IP;
}
/* The state info is for the first procedure */
pProcList.front().state = state;
start_proc.state = state;
/* Set up call graph initial node */
*pcallGraph = new CALL_GRAPH;
(*pcallGraph)->proc = pProcList.begin();
/* This proc needs to be called to set things up for LibCheck(), which
checks a proc to see if it is a know C (etc) library */
checks a proc to see if it is a know C (etc) library */
SetupLibCheck();
/* Recursively build entire procedure list */
@ -107,14 +105,15 @@ static void updateSymType (dword symbol, hlType symType, Int size)
Int strSize (byte *sym, char delim)
{
Int i;
for (i = 0; *sym++ != delim; i++) ;
for (i = 0; *sym++ != delim; i++)
;
return (i+1);
}
Function *fakeproc=Function::Create(0,0,"fake");
/* FollowCtrl - Given an initial procedure, state information and symbol table
* builds a list of procedures reachable from the initial procedure
* using a depth first search. */
* builds a list of procedures reachable from the initial procedure
* using a depth first search. */
void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
{
ICODE _Icode, *pIcode; /* This gets copied to pProc->Icode[] later */
@ -125,7 +124,7 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
boolT done = FALSE;
dword lab;
if (strstr(name, "chkstk") != NULL)
if (name.find("chkstk") != string::npos)
{
// Danger! Dcc will likely fall over in this code.
// So we act as though we have done with this proc
@ -137,7 +136,7 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
}
if (option.VeryVerbose)
{
printf("Parsing proc %s at %lX\n", name, pstate->IP);
printf("Parsing proc %s at %lX\n", name.c_str(), pstate->IP);
}
while (! done && ! (err = scan(pstate->IP, &_Icode)))
@ -589,9 +588,11 @@ boolT Function::process_CALL (ICODE * pIcode, CALL_GRAPH * pcallGraph, STATE *ps
if (indirect)
x.flg |= PROC_ICALL;
if (x.name[0] == '\0') /* Don't overwrite existing name */
if (x.name.empty()) /* Don't overwrite existing name */
{
sprintf(x.name, "proc_%ld", ++prog.cProcs);
ostringstream os;
os<<"proc_"<< ++prog.cProcs;
x.name = os.str();
}
x.depth = x.depth + 1;
x.flg |= TERMINATES;
@ -889,7 +890,6 @@ static void setBits(int16 type, dword start, dword len)
}
}
/* DU bit definitions for each reg value - including index registers */
dword duReg[] = { 0x00,
0x11001, 0x22002, 0x44004, 0x88008, /* word regs */

View File

@ -74,7 +74,7 @@ void CALL_GRAPH::writeNodeCallGraph(Int indIdx)
{
Int i;
printf ("%s%s\n", indent(indIdx), proc->name);
printf ("%s%s\n", indent(indIdx), proc->name.c_str());
for (i = 0; i < outEdges.size(); i++)
outEdges[i]->writeNodeCallGraph (indIdx + 1);
}
@ -127,7 +127,7 @@ void Function::newRegArg(ICODE *picode, ICODE *ticode)
{
regL = localId.id_arr[lhs->expr.ident.idNode.longIdx].id.longId.l;
regH = localId.id_arr[lhs->expr.ident.idNode.longIdx].id.longId.h;
tidx = tproc->localId.newLongReg(TYPE_LONG_SIGN, regH, regL, 0);
tidx = tproc->localId.newLongReg(TYPE_LONG_SIGN, regH, regL, Icode.begin() /*0*/);
}
/* Check if register argument already on the formal argument list */

View File

@ -61,9 +61,14 @@ static boolT isLong23 (Int i, BB * pbb, Int *off, Int *arc)
/* Returns whether the conditions for a 2-2 long variable are satisfied */
static boolT isLong22 (iICODE pIcode, iICODE pEnd, Int *off)
{
if (((pIcode+2) < pEnd) && ((pIcode+2)->ic.ll.opcode == iCMP) &&
(isJCond ((pIcode+1)->ic.ll.opcode)) &&
(isJCond ((pIcode+3)->ic.ll.opcode)))
iICODE next1 = pIcode+1;
iICODE next2 = pIcode+2;
iICODE next3 = pIcode+3;
if(next3>=pEnd)
return false;
if ( (next2->ic.ll.opcode == iCMP) &&
(isJCond (next1->ic.ll.opcode)) &&
(isJCond (next3->ic.ll.opcode)))
{
*off = 2;
return true;
@ -77,7 +82,7 @@ static boolT isLong22 (iICODE pIcode, iICODE pEnd, Int *off)
* the new edges for the remaining nodes. */
static void longJCond23 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode,
Int *idx, Int arc, Int off)
{ Int j;
{
BB * pbb, * obb1, * obb2, * tbb;
if (arc == THEN)
@ -93,58 +98,50 @@ static void longJCond23 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode,
/* Modify in edges of target basic block */
auto newlast=std::remove_if(tbb->inEdges.begin(),tbb->inEdges.end(),
[obb1,obb2](BB *b) -> bool
{
return (b==obb1) || (b==obb2);
[obb1,obb2](BB *b) -> bool {
return (b==obb1) || (b==obb2); });
tbb->inEdges.erase(newlast,tbb->inEdges.end());
tbb->inEdges.push_back(pbb); /* looses 2 arcs, gains 1 arc */
/* Modify in edges of the ELSE basic block */
tbb = pbb->edges[ELSE].BBptr;
auto iter=std::find(tbb->inEdges.begin(),tbb->inEdges.end(),obb2);
assert(iter!=tbb->inEdges.end());
tbb->inEdges.erase(iter); /* looses 1 arc */
/* Update icode index */
(*idx) += 5;
}
);
tbb->inEdges.erase(newlast,tbb->inEdges.end());
tbb->inEdges.push_back(pbb); /* looses 2 arcs, gains 1 arc */
else /* ELSE arc */
{
/* Find intermediate basic blocks and target block */
pbb = pIcode->inBB;
obb1 = pbb->edges[ELSE].BBptr;
obb2 = obb1->edges[THEN].BBptr;
tbb = obb2->edges[THEN].BBptr;
/* Modify in edges of the ELSE basic block */
tbb = pbb->edges[ELSE].BBptr;
auto iter=std::find(tbb->inEdges.begin(),tbb->inEdges.end(),obb2);
assert(iter!=tbb->inEdges.end());
tbb->inEdges.erase(iter); /* looses 1 arc */
/* Update icode index */
(*idx) += 5;
}
/* Modify in edges of target basic block */
auto iter=std::find(tbb->inEdges.begin(),tbb->inEdges.end(),obb2);
assert(iter!=tbb->inEdges.end());
tbb->inEdges.erase(iter); /* looses 1 arc */
else /* ELSE arc */
{
/* Find intermediate basic blocks and target block */
pbb = pIcode->inBB;
obb1 = pbb->edges[ELSE].BBptr;
obb2 = obb1->edges[THEN].BBptr;
tbb = obb2->edges[THEN].BBptr;
/* Modify in edges of the ELSE basic block */
tbb = obb2->edges[ELSE].BBptr;
auto newlast=std::remove_if(tbb->inEdges.begin(),tbb->inEdges.end(),
[obb1,obb2](BB *b) -> bool { return (b==obb1) || (b==obb2); });
tbb->inEdges.erase(newlast,tbb->inEdges.end());
tbb->inEdges.push_back(pbb); /* looses 2 arcs, gains 1 arc */
/* Modify in edges of target basic block */
auto iter=std::find(tbb->inEdges.begin(),tbb->inEdges.end(),obb2);
assert(iter!=tbb->inEdges.end());
tbb->inEdges.erase(iter); /* looses 1 arc */
/* Modify out edge of header basic block */
pbb->edges[ELSE].BBptr = tbb;
/* Modify in edges of the ELSE basic block */
tbb = obb2->edges[ELSE].BBptr;
auto newlast=std::remove_if(tbb->inEdges.begin(),tbb->inEdges.end(),
[obb1,obb2](BB *b) -> bool
{
return (b==obb1) || (b==obb2);
}
);
tbb->inEdges.erase(newlast,tbb->inEdges.end());
tbb->inEdges.push_back(pbb); /* looses 2 arcs, gains 1 arc */
/* Update icode index */
(*idx) += 2;
}
/* Modify out edge of header basic block */
pbb->edges[ELSE].BBptr = tbb;
/* Update icode index */
(*idx) += 2;
}
/* Create new HLI_JCOND and condition */
lhs = COND_EXPR::boolOp (lhs, rhs, condOpJCond[(pIcode+off+1)->ic.ll.opcode-iJB]);
(pIcode+1)->setJCond(lhs);
(pIcode+1)->copyDU(*pIcode, eUSE, eUSE);
/* Create new HLI_JCOND and condition */
lhs = COND_EXPR::boolOp (lhs, rhs, condOpJCond[(pIcode+off+1)->ic.ll.opcode-iJB]);
(pIcode+1)->setJCond(lhs);
(pIcode+1)->copyDU(*pIcode, eUSE, eUSE);
(pIcode+1)->du.use |= (pIcode+off)->du.use;
/* Update statistics */
@ -166,12 +163,14 @@ static void longJCond22 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode, Int *idx
{
Int j;
BB * pbb, * obb1, * tbb;
iICODE next1=pIcode+1;
iICODE next2=pIcode+2;
iICODE next3=pIcode+3;
/* Form conditional expression */
lhs = COND_EXPR::boolOp (lhs, rhs, condOpJCond[(pIcode+3)->ic.ll.opcode - iJB]);
(pIcode+1)->setJCond(lhs);
(pIcode+1)->copyDU (*pIcode, eUSE, eUSE);
(pIcode+1)->du.use |= (pIcode+2)->du.use;
next1->setJCond(lhs);
next1->copyDU (*pIcode, eUSE, eUSE);
next1->du.use |= next2->du.use;
/* Adjust outEdges[0] to the new target basic block */
pbb = pIcode->inBB;
@ -201,9 +200,6 @@ static void longJCond22 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode, Int *idx
tbb->inEdges.erase(iter);
if ((pIcode+3)->ic.ll.opcode == iJE) /* replace */
tbb->inEdges.push_back(pbb);
// else
// tbb->numInEdges--; /* iJNE => looses 1 arc */
/* Update statistics */
obb1->flg |= INVALID_BB;
@ -211,8 +207,8 @@ static void longJCond22 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode, Int *idx
}
pIcode->invalidate();
(pIcode+2)->invalidate();
(pIcode+3)->invalidate();
next2->invalidate();
next3->invalidate();
(*idx) += 4;
}
@ -239,44 +235,44 @@ void Function::propLongStk (Int i, ID *pLocId)
{
switch (pIcode->ic.ll.opcode)
{
case iMOV:
if (checkLongEq (pLocId->id.longStkId, pIcode, i, idx, this,
&rhs, &lhs, 1) == TRUE)
{
pIcode->setAsgn(lhs, rhs);
(pIcode+1)->invalidate();
idx++;
}
break;
case iMOV:
if (checkLongEq (pLocId->id.longStkId, pIcode, i, idx, this,
&rhs, &lhs, 1) == TRUE)
{
pIcode->setAsgn(lhs, rhs);
(pIcode+1)->invalidate();
idx++;
}
break;
case iAND: case iOR: case iXOR:
if (checkLongEq (pLocId->id.longStkId, pIcode, i, idx, this,
&rhs, &lhs, 1) == TRUE)
case iAND: case iOR: case iXOR:
if (checkLongEq (pLocId->id.longStkId, pIcode, i, idx, this,
&rhs, &lhs, 1) == TRUE)
{
switch (pIcode->ic.ll.opcode)
{
switch (pIcode->ic.ll.opcode)
{
case iAND: rhs = COND_EXPR::boolOp (lhs, rhs, AND);
break;
case iOR: rhs = COND_EXPR::boolOp (lhs, rhs, OR);
break;
case iXOR: rhs = COND_EXPR::boolOp (lhs, rhs, XOR);
break;
}
pIcode->setAsgn(lhs, rhs);
(pIcode+1)->invalidate();
idx++;
case iAND: rhs = COND_EXPR::boolOp (lhs, rhs, AND);
break;
case iOR: rhs = COND_EXPR::boolOp (lhs, rhs, OR);
break;
case iXOR: rhs = COND_EXPR::boolOp (lhs, rhs, XOR);
break;
}
break;
pIcode->setAsgn(lhs, rhs);
(pIcode+1)->invalidate();
idx++;
}
break;
case iPUSH:
if (checkLongEq (pLocId->id.longStkId, pIcode, i, idx, this,
&rhs, &lhs, 1) == TRUE)
{
pIcode->setUnary( HLI_PUSH, lhs);
(pIcode+1)->invalidate();
idx++;
}
break;
case iPUSH:
if (checkLongEq (pLocId->id.longStkId, pIcode, i, idx, this,
&rhs, &lhs, 1) == TRUE)
{
pIcode->setUnary( HLI_PUSH, lhs);
(pIcode+1)->invalidate();
idx++;
}
break;
} /*eos*/
}
@ -314,58 +310,58 @@ int Function::checkBackwarLongDefs(int loc_ident_idx, ID *pLocId, int pLocId
continue;
switch (pIcode->ic.ll.opcode)
{
case iMOV:
pmH = &pIcode->ic.ll.dst;
pmL = &(pIcode+1)->ic.ll.dst;
if ((pLocId->id.longId.h == pmH->regi) && (pLocId->id.longId.l == pmL->regi))
{
asgn.lhs = COND_EXPR::idLongIdx (loc_ident_idx);
this->localId.id_arr[loc_ident_idx].idx.push_back(idx-1);
pIcode->setRegDU( pmL->regi, eDEF);
asgn.rhs = COND_EXPR::idLong (&this->localId, SRC, pIcode, HIGH_FIRST, idx, eUSE, 1);
pIcode->setAsgn(asgn.lhs, asgn.rhs);
(pIcode+1)->invalidate();
idx = 0; /* to exit the loop */
}
break;
case iMOV:
pmH = &pIcode->ic.ll.dst;
pmL = &(pIcode+1)->ic.ll.dst;
if ((pLocId->id.longId.h == pmH->regi) && (pLocId->id.longId.l == pmL->regi))
{
asgn.lhs = COND_EXPR::idLongIdx (loc_ident_idx);
this->localId.id_arr[loc_ident_idx].idx.push_back(pIcode);//idx-1
pIcode->setRegDU( pmL->regi, eDEF);
asgn.rhs = COND_EXPR::idLong (&this->localId, SRC, pIcode, HIGH_FIRST, pIcode/*idx*/, eUSE, 1);
pIcode->setAsgn(asgn.lhs, asgn.rhs);
(pIcode+1)->invalidate();
idx = 0; /* to exit the loop */
}
break;
case iPOP:
pmH = &(pIcode+1)->ic.ll.dst;
pmL = &pIcode->ic.ll.dst;
if ((pLocId->id.longId.h == pmH->regi) && (pLocId->id.longId.l == pmL->regi))
{
asgn.lhs = COND_EXPR::idLongIdx (loc_ident_idx);
pIcode->setRegDU( pmH->regi, eDEF);
pIcode->setUnary(HLI_POP, asgn.lhs);
(pIcode+1)->invalidate();
idx = 0; /* to exit the loop */
}
break;
case iPOP:
pmH = &(pIcode+1)->ic.ll.dst;
pmL = &pIcode->ic.ll.dst;
if ((pLocId->id.longId.h == pmH->regi) && (pLocId->id.longId.l == pmL->regi))
{
asgn.lhs = COND_EXPR::idLongIdx (loc_ident_idx);
pIcode->setRegDU( pmH->regi, eDEF);
pIcode->setUnary(HLI_POP, asgn.lhs);
(pIcode+1)->invalidate();
idx = 0; /* to exit the loop */
}
break;
// /**** others missing ***/
// /**** others missing ***/
case iAND: case iOR: case iXOR:
pmL = &pIcode->ic.ll.dst;
pmH = &(pIcode+1)->ic.ll.dst;
if ((pLocId->id.longId.h == pmH->regi) && (pLocId->id.longId.l == pmL->regi))
{
asgn.lhs = COND_EXPR::idLongIdx (loc_ident_idx);
pIcode->setRegDU( pmH->regi, USE_DEF);
asgn.rhs = COND_EXPR::idLong (&this->localId, SRC, pIcode, LOW_FIRST, idx, eUSE, 1);
switch (pIcode->ic.ll.opcode) {
case iAND: asgn.rhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, AND);
break;
case iOR:
asgn.rhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, OR);
break;
case iXOR: asgn.rhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, XOR);
break;
} /* eos */
pIcode->setAsgn(asgn.lhs, asgn.rhs);
(pIcode+1)->invalidate();
idx = 0;
}
break;
case iAND: case iOR: case iXOR:
pmL = &pIcode->ic.ll.dst;
pmH = &(pIcode+1)->ic.ll.dst;
if ((pLocId->id.longId.h == pmH->regi) && (pLocId->id.longId.l == pmL->regi))
{
asgn.lhs = COND_EXPR::idLongIdx (loc_ident_idx);
pIcode->setRegDU( pmH->regi, USE_DEF);
asgn.rhs = COND_EXPR::idLong (&this->localId, SRC, pIcode, LOW_FIRST, pIcode/*idx*/, eUSE, 1);
switch (pIcode->ic.ll.opcode) {
case iAND: asgn.rhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, AND);
break;
case iOR:
asgn.rhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, OR);
break;
case iXOR: asgn.rhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, XOR);
break;
} /* eos */
pIcode->setAsgn(asgn.lhs, asgn.rhs);
(pIcode+1)->invalidate();
idx = 0;
}
break;
} /* eos */
}
return idx;
@ -387,7 +383,7 @@ void Function::propLongReg (Int loc_ident_idx, ID *pLocId)
// WARNING: this loop modifies the iterated-over container.
for (int j = 0; j < pLocId->idx.size(); j++)
{
int pLocId_idx=pLocId->idx[j];
int pLocId_idx=std::distance(Icode.begin(),pLocId->idx[j]);
Assignment asgn;
/* Check backwards for a definition of this long register */
idx = checkBackwarLongDefs(loc_ident_idx,pLocId,pLocId_idx,asgn);
@ -396,65 +392,68 @@ void Function::propLongReg (Int loc_ident_idx, ID *pLocId)
continue;
for (idx = pLocId_idx + 1; idx < Icode.size() - 1; idx++)
{
iICODE pIcode;
iICODE pIcode(Icode.begin()),next1(Icode.begin());
LLOperand * pmH,* pmL; /* Pointers to dst LOW_LEVEL icodes */
int off,arc;
pIcode = Icode.begin()+(idx);
std::advance(pIcode,idx);
std::advance(next1,idx+1);
if ((pIcode->type == HIGH_LEVEL) || (pIcode->invalid == TRUE))
continue;
if (pIcode->ic.ll.opcode == (pIcode+1)->ic.ll.opcode)
switch (pIcode->ic.ll.opcode) {
case iMOV:
if ((pLocId->id.longId.h == pIcode->ic.ll.src.regi) &&
(pLocId->id.longId.l == (pIcode+1)->ic.ll.src.regi))
{
asgn.rhs = COND_EXPR::idLongIdx (loc_ident_idx);
pIcode->setRegDU( (pIcode+1)->ic.ll.src.regi, eUSE);
asgn.lhs = COND_EXPR::idLong (&this->localId, DST, pIcode,HIGH_FIRST, idx, eDEF, 1);
pIcode->setAsgn(asgn.lhs, asgn.rhs);
(pIcode+1)->invalidate();
idx = this->Icode.size(); /* to exit the loop */
}
break;
if (pIcode->ic.ll.opcode == next1->ic.ll.opcode)
switch (pIcode->ic.ll.opcode)
{
case iMOV:
if ((pLocId->id.longId.h == pIcode->ic.ll.src.regi) &&
(pLocId->id.longId.l == next1->ic.ll.src.regi))
{
asgn.rhs = COND_EXPR::idLongIdx (loc_ident_idx);
pIcode->setRegDU( next1->ic.ll.src.regi, eUSE);
asgn.lhs = COND_EXPR::idLong (&this->localId, DST, pIcode,HIGH_FIRST, pIcode/*idx*/, eDEF, 1);
pIcode->setAsgn(asgn.lhs, asgn.rhs);
next1->invalidate();
idx = this->Icode.size(); /* to exit the loop */
}
break;
case iPUSH:
if ((pLocId->id.longId.h == pIcode->ic.ll.src.regi) &&
(pLocId->id.longId.l == (pIcode+1)->ic.ll.src.regi))
{
asgn.rhs = COND_EXPR::idLongIdx (loc_ident_idx);
pIcode->setRegDU( (pIcode+1)->ic.ll.src.regi, eUSE);
pIcode->setUnary(HLI_PUSH, asgn.lhs);
(pIcode+1)->invalidate();
}
idx = this->Icode.size(); /* to exit the loop */
break;
case iPUSH:
if ((pLocId->id.longId.h == pIcode->ic.ll.src.regi) &&
(pLocId->id.longId.l == next1->ic.ll.src.regi))
{
asgn.rhs = COND_EXPR::idLongIdx (loc_ident_idx);
pIcode->setRegDU( next1->ic.ll.src.regi, eUSE);
pIcode->setUnary(HLI_PUSH, asgn.lhs);
next1->invalidate();
}
idx = this->Icode.size(); /* to exit the loop */
break;
/*** others missing ****/
/*** others missing ****/
case iAND: case iOR: case iXOR:
pmL = &pIcode->ic.ll.dst;
pmH = &(pIcode+1)->ic.ll.dst;
if ((pLocId->id.longId.h == pmH->regi) &&
(pLocId->id.longId.l == pmL->regi))
{
asgn.lhs = COND_EXPR::idLongIdx (loc_ident_idx);
pIcode->setRegDU( pmH->regi, USE_DEF);
asgn.rhs = COND_EXPR::idLong (&this->localId, SRC, pIcode,
LOW_FIRST, idx, eUSE, 1);
switch (pIcode->ic.ll.opcode) {
case iAND: asgn.rhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, AND);
break;
case iOR: asgn.rhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, OR);
break;
case iXOR: asgn.rhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, XOR);
break;
}
pIcode->setAsgn(asgn.lhs, asgn.rhs);
(pIcode+1)->invalidate();
idx = 0;
case iAND: case iOR: case iXOR:
pmL = &pIcode->ic.ll.dst;
pmH = &next1->ic.ll.dst;
if ((pLocId->id.longId.h == pmH->regi) &&
(pLocId->id.longId.l == pmL->regi))
{
asgn.lhs = COND_EXPR::idLongIdx (loc_ident_idx);
pIcode->setRegDU( pmH->regi, USE_DEF);
asgn.rhs = COND_EXPR::idLong (&this->localId, SRC, pIcode,
LOW_FIRST, pIcode/*idx*/, eUSE, 1);
switch (pIcode->ic.ll.opcode) {
case iAND: asgn.rhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, AND);
break;
case iOR: asgn.rhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, OR);
break;
case iXOR: asgn.rhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, XOR);
break;
}
break;
pIcode->setAsgn(asgn.lhs, asgn.rhs);
(pIcode+1)->invalidate();
idx = 0;
}
break;
} /* eos */
/* Check long conditional (i.e. 2 CMPs and 3 branches */
@ -479,8 +478,8 @@ void Function::propLongReg (Int loc_ident_idx, ID *pLocId)
* JX lab
* => HLI_JCOND (regH:regL X 0) lab
* This is better code than HLI_JCOND (HI(regH:regL) | LO(regH:regL)) */
else if ((pIcode->ic.ll.opcode == iOR) && ((pIcode+1) < pEnd) &&
(isJCond ((pIcode+1)->ic.ll.opcode)))
else if ((pIcode->ic.ll.opcode == iOR) && (next1 < pEnd) &&
(isJCond (next1->ic.ll.opcode)))
{
if ((pIcode->ic.ll.dst.regi == pLocId->id.longId.h) &&
(pIcode->ic.ll.src.regi == pLocId->id.longId.l))
@ -488,9 +487,9 @@ void Function::propLongReg (Int loc_ident_idx, ID *pLocId)
asgn.lhs = COND_EXPR::idLongIdx (loc_ident_idx);
asgn.rhs = COND_EXPR::idKte (0, 4); /* long 0 */
asgn.lhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, condOpJCond[(pIcode+1)->ic.ll.opcode - iJB]);
(pIcode+1)->setJCond(asgn.lhs);
(pIcode+1)->copyDU(*pIcode, eUSE, eUSE);
asgn.lhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, condOpJCond[next1->ic.ll.opcode - iJB]);
next1->setJCond(asgn.lhs);
next1->copyDU(*pIcode, eUSE, eUSE);
pIcode->invalidate();
}
}
@ -522,15 +521,15 @@ void Function::propLong()
{
switch (pLocId->loc)
{
case STK_FRAME:
propLongStk (i, pLocId);
break;
case REG_FRAME:
propLongReg (i, pLocId);
break;
case GLB_FRAME:
propLongGlb (i, pLocId);
break;
case STK_FRAME:
propLongStk (i, pLocId);
break;
case REG_FRAME:
propLongReg (i, pLocId);
break;
case GLB_FRAME:
propLongGlb (i, pLocId);
break;
}
}
}

View File

@ -115,56 +115,56 @@ static struct {
{ data2, axImp, 0 , iCMP , Sf | Zf | Cf , 0 }, /* 3D */
{ prefix, none2, 0 , (IC)rDS,0 , 0 }, /* 3E */
{ none1, axImp, NOT_HLL | NO_SRC , iAAS , Sf | Zf | Cf , 0 }, /* 3F */
{ regop, none2, 0 , iINC , Sf | Zf, 0 }, /* 40 */
{ regop, none2, 0 , iINC , Sf | Zf, 0 }, /* 41 */
{ regop, none2, 0 , iINC , Sf | Zf, 0 }, /* 42 */
{ regop, none2, 0 , iINC , Sf | Zf, 0 }, /* 43 */
{ regop, none2, NOT_HLL , iINC , Sf | Zf, 0 }, /* 44 */
{ regop, none2, 0 , iINC , Sf | Zf, 0 }, /* 45 */
{ regop, none2, 0 , iINC , Sf | Zf, 0 }, /* 46 */
{ regop, none2, 0 , iINC , Sf | Zf, 0 }, /* 47 */
{ regop, none2, 0 , iDEC , Sf | Zf, 0 }, /* 48 */
{ regop, none2, 0 , iDEC , Sf | Zf, 0 }, /* 49 */
{ regop, none2, 0 , iDEC , Sf | Zf, 0 }, /* 4A */
{ regop, none2, 0 , iDEC , Sf | Zf, 0 }, /* 4B */
{ regop, none2, NOT_HLL , iDEC , Sf | Zf, 0 }, /* 4C */
{ regop, none2, 0 , iDEC , Sf | Zf, 0 }, /* 4D */
{ regop, none2, 0 , iDEC , Sf | Zf, 0 }, /* 4E */
{ regop, none2, 0 , iDEC , Sf | Zf, 0 }, /* 4F */
{ regop, none2, NO_SRC , iPUSH , 0 , 0 }, /* 50 */
{ regop, none2, NO_SRC , iPUSH , 0 , 0 }, /* 51 */
{ regop, none2, NO_SRC , iPUSH , 0 , 0 }, /* 52 */
{ regop, none2, NO_SRC , iPUSH , 0 , 0 }, /* 53 */
{ regop, none2, NOT_HLL | NO_SRC , iPUSH , 0 , 0 }, /* 54 */
{ regop, none2, NO_SRC , iPUSH , 0 , 0 }, /* 55 */
{ regop, none2, NO_SRC , iPUSH , 0 , 0 }, /* 56 */
{ regop, none2, NO_SRC , iPUSH , 0 , 0 }, /* 57 */
{ regop, none2, NO_SRC , iPOP , 0 , 0 }, /* 58 */
{ regop, none2, NO_SRC , iPOP , 0 , 0 }, /* 59 */
{ regop, none2, NO_SRC , iPOP , 0 , 0 }, /* 5A */
{ regop, none2, NO_SRC , iPOP , 0 , 0 }, /* 5B */
{ regop, none2, NOT_HLL | NO_SRC , iPOP , 0 , 0 }, /* 5C */
{ regop, none2, NO_SRC , iPOP , 0 , 0 }, /* 5D */
{ regop, none2, NO_SRC , iPOP , 0 , 0 }, /* 5E */
{ regop, none2, NO_SRC , iPOP , 0 , 0 }, /* 5F */
{ none1, none2, NOT_HLL | NO_OPS , iPUSHA, 0 , 0 }, /* 60 */
{ none1, none2, NOT_HLL | NO_OPS , iPOPA , 0 , 0 }, /* 61 */
{ memOnly, modrm, TO_REG | NSP , iBOUND, 0 , 0 }, /* 62 */
{ none1, none2, OP386 , iZERO , 0 , 0 }, /* 63 */
{ none1, none2, OP386 , iZERO , 0 , 0 }, /* 64 */
{ none1, none2, OP386 , iZERO , 0 , 0 }, /* 65 */
{ none1, none2, OP386 , iZERO , 0 , 0 }, /* 66 */
{ none1, none2, OP386 , iZERO , 0 , 0 }, /* 67 */
{ data2, none2, NO_SRC , iPUSH , 0 , 0 }, /* 68 */
{ modrm, data2, TO_REG | NSP , iIMUL , Sf | Zf | Cf, 0 }, /* 69 */
{ data1, none2, S_EXT | NO_SRC , iPUSH , 0 , 0 }, /* 6A */
{ modrm, data1, TO_REG | NSP | S_EXT , iIMUL , Sf | Zf | Cf, 0 }, /* 6B */
{ strop, memImp, NOT_HLL | B|IM_OPS , iINS , 0 , Df }, /* 6C */
{ strop, memImp, NOT_HLL | IM_OPS , iINS , 0 , Df }, /* 6D */
{ strop, memImp, NOT_HLL | B|IM_OPS , iOUTS , 0 , Df }, /* 6E */
{ strop, memImp, NOT_HLL | IM_OPS , iOUTS , 0 , Df }, /* 6F */
{ dispS, none2, NOT_HLL , iJO , 0 , 0 }, /* 70 */
{ dispS, none2, NOT_HLL , iJNO , 0 , 0 }, /* 71 */
{ regop, none2, 0 , iINC , Sf | Zf , 0 }, /* 40 */
{ regop, none2, 0 , iINC , Sf | Zf , 0 }, /* 41 */
{ regop, none2, 0 , iINC , Sf | Zf , 0 }, /* 42 */
{ regop, none2, 0 , iINC , Sf | Zf , 0 }, /* 43 */
{ regop, none2, NOT_HLL , iINC , Sf | Zf , 0 }, /* 44 */
{ regop, none2, 0 , iINC , Sf | Zf , 0 }, /* 45 */
{ regop, none2, 0 , iINC , Sf | Zf , 0 }, /* 46 */
{ regop, none2, 0 , iINC , Sf | Zf , 0 }, /* 47 */
{ regop, none2, 0 , iDEC , Sf | Zf , 0 }, /* 48 */
{ regop, none2, 0 , iDEC , Sf | Zf , 0 }, /* 49 */
{ regop, none2, 0 , iDEC , Sf | Zf , 0 }, /* 4A */
{ regop, none2, 0 , iDEC , Sf | Zf , 0 }, /* 4B */
{ regop, none2, NOT_HLL , iDEC , Sf | Zf , 0 }, /* 4C */
{ regop, none2, 0 , iDEC , Sf | Zf , 0 }, /* 4D */
{ regop, none2, 0 , iDEC , Sf | Zf , 0 }, /* 4E */
{ regop, none2, 0 , iDEC , Sf | Zf , 0 }, /* 4F */
{ regop, none2, NO_SRC , iPUSH , 0 , 0 }, /* 50 */
{ regop, none2, NO_SRC , iPUSH , 0 , 0 }, /* 51 */
{ regop, none2, NO_SRC , iPUSH , 0 , 0 }, /* 52 */
{ regop, none2, NO_SRC , iPUSH , 0 , 0 }, /* 53 */
{ regop, none2, NOT_HLL | NO_SRC , iPUSH , 0 , 0 }, /* 54 */
{ regop, none2, NO_SRC , iPUSH , 0 , 0 }, /* 55 */
{ regop, none2, NO_SRC , iPUSH , 0 , 0 }, /* 56 */
{ regop, none2, NO_SRC , iPUSH , 0 , 0 }, /* 57 */
{ regop, none2, NO_SRC , iPOP , 0 , 0 }, /* 58 */
{ regop, none2, NO_SRC , iPOP , 0 , 0 }, /* 59 */
{ regop, none2, NO_SRC , iPOP , 0 , 0 }, /* 5A */
{ regop, none2, NO_SRC , iPOP , 0 , 0 }, /* 5B */
{ regop, none2, NOT_HLL | NO_SRC , iPOP , 0 , 0 }, /* 5C */
{ regop, none2, NO_SRC , iPOP , 0 , 0 }, /* 5D */
{ regop, none2, NO_SRC , iPOP , 0 , 0 }, /* 5E */
{ regop, none2, NO_SRC , iPOP , 0 , 0 }, /* 5F */
{ none1, none2, NOT_HLL | NO_OPS , iPUSHA, 0 , 0 }, /* 60 */
{ none1, none2, NOT_HLL | NO_OPS , iPOPA , 0 , 0 }, /* 61 */
{ memOnly, modrm, TO_REG | NSP , iBOUND, 0 , 0 }, /* 62 */
{ none1, none2, OP386 , iZERO , 0 , 0 }, /* 63 */
{ none1, none2, OP386 , iZERO , 0 , 0 }, /* 64 */
{ none1, none2, OP386 , iZERO , 0 , 0 }, /* 65 */
{ none1, none2, OP386 , iZERO , 0 , 0 }, /* 66 */
{ none1, none2, OP386 , iZERO , 0 , 0 }, /* 67 */
{ data2, none2, NO_SRC , iPUSH , 0 , 0 }, /* 68 */
{ modrm, data2, TO_REG | NSP , iIMUL , Sf | Zf | Cf , 0 }, /* 69 */
{ data1, none2, S_EXT | NO_SRC , iPUSH , 0 , 0 }, /* 6A */
{ modrm, data1, TO_REG | NSP | S_EXT , iIMUL , Sf | Zf | Cf , 0 }, /* 6B */
{ strop, memImp, NOT_HLL | B|IM_OPS , iINS , 0 , Df}, /* 6C */
{ strop, memImp, NOT_HLL | IM_OPS , iINS , 0 , Df}, /* 6D */
{ strop, memImp, NOT_HLL | B|IM_OPS , iOUTS , 0 , Df}, /* 6E */
{ strop, memImp, NOT_HLL | IM_OPS , iOUTS , 0 , Df}, /* 6F */
{ dispS, none2, NOT_HLL , iJO , 0 , 0 }, /* 70 */
{ dispS, none2, NOT_HLL , iJNO , 0 , 0 }, /* 71 */
{ dispS, none2, 0 , iJB , 0 , Cf }, /* 72 */
{ dispS, none2, 0 , iJAE , 0 , Cf }, /* 73 */
{ dispS, none2, 0 , iJE , 0 , Zf }, /* 74 */

View File

@ -55,7 +55,7 @@ void Function::controlFlowAnalysis()
if (option.verbose)
{
printf("\nDepth first traversal - Proc %s\n", name);
printf("\nDepth first traversal - Proc %s\n", name.c_str());
cfg.front()->displayDfs();
}
@ -90,7 +90,7 @@ void udm(void)
***************************************************************************/
void Function::displayCFG()
{
printf("\nBasic Block List - Proc %s", name);
printf("\nBasic Block List - Proc %s", name.c_str());
for (BB *pBB : cfg)
{
pBB->display();