lots of small things
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
#include "Procedure.h"
|
||||
#include "dcc.h"
|
||||
using namespace std;
|
||||
extern char *indent (Int indLevel);
|
||||
extern char *indent (int indLevel);
|
||||
BB *BB::Create(void *ctx, const string &s, Function *parent, BB *insertBefore)
|
||||
{
|
||||
BB *pnewBB = new BB;
|
||||
@@ -13,7 +13,7 @@ BB *BB::Create(void *ctx, const string &s, Function *parent, BB *insertBefore)
|
||||
return pnewBB;
|
||||
}
|
||||
|
||||
BB *BB::Create(Int start, Int ip, byte nodeType, Int numOutEdges, Function *parent)
|
||||
BB *BB::Create(int start, int ip, uint8_t nodeType, int numOutEdges, Function *parent)
|
||||
{
|
||||
parent->m_cfg;
|
||||
BB* pnewBB;
|
||||
@@ -65,7 +65,7 @@ void BB::display()
|
||||
****************************************************************************/
|
||||
void BB::displayDfs()
|
||||
{
|
||||
Int i;
|
||||
int i;
|
||||
assert(this);
|
||||
traversed = DFS_DISP;
|
||||
|
||||
@@ -114,9 +114,9 @@ void BB::displayDfs()
|
||||
* current procedure.
|
||||
* indLevel: indentation level - used for formatting.
|
||||
* numLoc: last # assigned to local variables */
|
||||
void BB::writeCode (Int indLevel, Function * pProc , Int *numLoc,Int latchNode, Int _ifFollow)
|
||||
void BB::writeCode (int indLevel, Function * pProc , int *numLoc,int latchNode, int _ifFollow)
|
||||
{
|
||||
Int follow, /* ifFollow */
|
||||
int follow, /* ifFollow */
|
||||
_loopType, /* Type of loop, if any */
|
||||
_nodeType; /* Type of node */
|
||||
BB * succ, *latch; /* Successor and latching node */
|
||||
@@ -330,7 +330,7 @@ void BB::writeCode (Int indLevel, Function * pProc , Int *numLoc,Int latchNode,
|
||||
* Args: pBB: pointer to the current basic block.
|
||||
* Icode: pointer to the array of icodes for current procedure.
|
||||
* lev: indentation level - used for formatting. */
|
||||
void BB::writeBB(Int lev, Function * pProc, Int *numLoc)
|
||||
void BB::writeBB(int lev, Function * pProc, int *numLoc)
|
||||
{
|
||||
/* Save the index into the code table in case there is a later goto
|
||||
* into this instruction (first instruction of the BB) */
|
||||
|
||||
60
src/ast.cpp
60
src/ast.cpp
@@ -40,7 +40,7 @@ static char *hexStr (uint16_t i)
|
||||
|
||||
|
||||
/* Sets the du record for registers according to the du flag */
|
||||
void ICODE::setRegDU (byte regi, operDu du_in)
|
||||
void ICODE::setRegDU (uint8_t regi, operDu du_in)
|
||||
{
|
||||
// printf("%s %d %x\n",__FUNCTION__,regi,int(du_in));
|
||||
switch (du_in)
|
||||
@@ -120,10 +120,10 @@ COND_EXPR *COND_EXPR::unary(condNodeType t, COND_EXPR *sub_expr)
|
||||
|
||||
|
||||
/* Returns an identifier conditional expression node of type GLOB_VAR */
|
||||
COND_EXPR *COND_EXPR::idGlob (int16 segValue, int16 off)
|
||||
COND_EXPR *COND_EXPR::idGlob (int16_t segValue, int16_t off)
|
||||
{
|
||||
COND_EXPR *newExp;
|
||||
dword adr;
|
||||
uint32_t adr;
|
||||
size_t i;
|
||||
|
||||
newExp = new COND_EXPR(IDENTIFIER);
|
||||
@@ -140,7 +140,7 @@ COND_EXPR *COND_EXPR::idGlob (int16 segValue, int16 off)
|
||||
|
||||
|
||||
/* Returns an identifier conditional expression node of type REGISTER */
|
||||
COND_EXPR *COND_EXPR::idReg(byte regi, flags32 icodeFlg, LOCAL_ID *locsym)
|
||||
COND_EXPR *COND_EXPR::idReg(uint8_t regi, uint32_t icodeFlg, LOCAL_ID *locsym)
|
||||
{
|
||||
COND_EXPR *newExp;
|
||||
|
||||
@@ -151,7 +151,7 @@ COND_EXPR *COND_EXPR::idReg(byte regi, flags32 icodeFlg, LOCAL_ID *locsym)
|
||||
newExp->expr.ident.idNode.regiIdx = locsym->newByteWordReg(TYPE_BYTE_SIGN, regi);
|
||||
newExp->expr.ident.regiType = BYTE_REG;
|
||||
}
|
||||
else /* word */
|
||||
else /* uint16_t */
|
||||
{
|
||||
newExp->expr.ident.idNode.regiIdx = locsym->newByteWordReg( TYPE_WORD_SIGN, regi);
|
||||
newExp->expr.ident.regiType = WORD_REG;
|
||||
@@ -161,7 +161,7 @@ COND_EXPR *COND_EXPR::idReg(byte regi, flags32 icodeFlg, LOCAL_ID *locsym)
|
||||
|
||||
|
||||
/* Returns an identifier conditional expression node of type REGISTER */
|
||||
COND_EXPR *COND_EXPR::idRegIdx(Int idx, regType reg_type)
|
||||
COND_EXPR *COND_EXPR::idRegIdx(int idx, regType reg_type)
|
||||
{
|
||||
COND_EXPR *newExp;
|
||||
|
||||
@@ -173,7 +173,7 @@ COND_EXPR *COND_EXPR::idRegIdx(Int idx, regType reg_type)
|
||||
}
|
||||
|
||||
/* Returns an identifier conditional expression node of type LOCAL_VAR */
|
||||
COND_EXPR *COND_EXPR::idLoc(Int off, LOCAL_ID *localId)
|
||||
COND_EXPR *COND_EXPR::idLoc(int off, LOCAL_ID *localId)
|
||||
{
|
||||
COND_EXPR *newExp;
|
||||
size_t i;
|
||||
@@ -193,7 +193,7 @@ COND_EXPR *COND_EXPR::idLoc(Int off, LOCAL_ID *localId)
|
||||
|
||||
|
||||
/* Returns an identifier conditional expression node of type PARAM */
|
||||
COND_EXPR *COND_EXPR::idParam(Int off, const STKFRAME * argSymtab)
|
||||
COND_EXPR *COND_EXPR::idParam(int off, const STKFRAME * argSymtab)
|
||||
{
|
||||
COND_EXPR *newExp;
|
||||
size_t i;
|
||||
@@ -211,7 +211,7 @@ COND_EXPR *COND_EXPR::idParam(Int off, const STKFRAME * argSymtab)
|
||||
|
||||
/* Returns an identifier conditional expression node of type GLOB_VAR_IDX.
|
||||
* This global variable is indexed by regi. */
|
||||
COND_EXPR *idCondExpIdxGlob (int16 segValue, int16 off, byte regi, const LOCAL_ID *locSym)
|
||||
COND_EXPR *idCondExpIdxGlob (int16_t segValue, int16_t off, uint8_t regi, const LOCAL_ID *locSym)
|
||||
{
|
||||
COND_EXPR *newExp;
|
||||
size_t i;
|
||||
@@ -231,7 +231,7 @@ COND_EXPR *idCondExpIdxGlob (int16 segValue, int16 off, byte regi, const LOCAL_I
|
||||
|
||||
|
||||
/* Returns an identifier conditional expression node of type CONSTANT */
|
||||
COND_EXPR *COND_EXPR::idKte(dword kte, byte size)
|
||||
COND_EXPR *COND_EXPR::idKte(uint32_t kte, uint8_t size)
|
||||
{
|
||||
COND_EXPR *newExp = new COND_EXPR(IDENTIFIER);
|
||||
newExp->expr.ident.idType = CONSTANT;
|
||||
@@ -243,7 +243,7 @@ COND_EXPR *COND_EXPR::idKte(dword kte, byte size)
|
||||
|
||||
/* Returns an identifier conditional expression node of type LONG_VAR,
|
||||
* that points to the given index idx. */
|
||||
COND_EXPR *COND_EXPR::idLongIdx (Int idx)
|
||||
COND_EXPR *COND_EXPR::idLongIdx (int idx)
|
||||
{
|
||||
COND_EXPR *newExp = new COND_EXPR(IDENTIFIER);
|
||||
newExp->expr.ident.idType = LONG_VAR;
|
||||
@@ -253,9 +253,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, iICODE 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)
|
||||
{
|
||||
Int idx;
|
||||
int idx;
|
||||
COND_EXPR *newExp = new COND_EXPR(IDENTIFIER);
|
||||
/* Check for long constant and save it as a constant expression */
|
||||
if ((sd == SRC) && ((pIcode->ic.ll.flg & I) == I)) /* constant */
|
||||
@@ -298,7 +298,7 @@ COND_EXPR *COND_EXPR::idFunc(Function * pproc, STKFRAME * args)
|
||||
/* Returns an identifier conditional expression node of type OTHER.
|
||||
* Temporary solution, should really be encoded as an indexed type (eg.
|
||||
* arrays). */
|
||||
COND_EXPR *COND_EXPR::idOther(byte seg, byte regi, int16 off)
|
||||
COND_EXPR *COND_EXPR::idOther(uint8_t seg, uint8_t regi, int16_t off)
|
||||
{
|
||||
COND_EXPR *newExp;
|
||||
|
||||
@@ -316,7 +316,7 @@ COND_EXPR *COND_EXPR::idOther(byte seg, byte regi, int16 off)
|
||||
COND_EXPR *COND_EXPR::idID (const ID *retVal, LOCAL_ID *locsym, iICODE ix_)
|
||||
{
|
||||
COND_EXPR *newExp;
|
||||
Int idx;
|
||||
int idx;
|
||||
|
||||
newExp = new COND_EXPR(IDENTIFIER);
|
||||
if (retVal->type == TYPE_LONG_SIGN)
|
||||
@@ -344,7 +344,7 @@ COND_EXPR *COND_EXPR::id(const ICODE &pIcode, opLoc sd, Function * pProc, iICODE
|
||||
{
|
||||
COND_EXPR *newExp;
|
||||
|
||||
Int idx; /* idx into pIcode->localId table */
|
||||
int idx; /* idx into pIcode->localId table */
|
||||
|
||||
const LLOperand &pm((sd == SRC) ? pIcode.ic.ll.src : pIcode.ic.ll.dst);
|
||||
|
||||
@@ -451,13 +451,13 @@ condId ICODE::idType(opLoc sd)
|
||||
|
||||
|
||||
/* Size of hl types */
|
||||
Int hlSize[] = {2, 1, 1, 2, 2, 4, 4, 4, 2, 2, 1, 4, 4};
|
||||
int hlSize[] = {2, 1, 1, 2, 2, 4, 4, 4, 2, 2, 1, 4, 4};
|
||||
|
||||
|
||||
/* Returns the type of the expression */
|
||||
Int hlTypeSize (const COND_EXPR *expr, Function * pproc)
|
||||
int hlTypeSize (const COND_EXPR *expr, Function * pproc)
|
||||
{
|
||||
Int first, second;
|
||||
int first, second;
|
||||
|
||||
if (expr == NULL)
|
||||
return (2); /* for TYPE_UNKNOWN */
|
||||
@@ -578,10 +578,10 @@ hlType expType (const COND_EXPR *expr, Function * pproc)
|
||||
/* Removes the register from the tree. If the register was part of a long
|
||||
* register (eg. dx:ax), the node gets transformed into an integer register
|
||||
* node. */
|
||||
void HlTypeSupport::performLongRemoval (byte regi, LOCAL_ID *locId, COND_EXPR *tree)
|
||||
void HlTypeSupport::performLongRemoval (uint8_t regi, LOCAL_ID *locId, COND_EXPR *tree)
|
||||
{
|
||||
IDENTTYPE* ident; /* ptr to an identifier */
|
||||
byte otherRegi; /* high or low part of long register */
|
||||
uint8_t otherRegi; /* high or low part of long register */
|
||||
|
||||
switch (tree->type) {
|
||||
case BOOLEAN_OP:
|
||||
@@ -606,10 +606,10 @@ void HlTypeSupport::performLongRemoval (byte regi, LOCAL_ID *locId, COND_EXPR *t
|
||||
|
||||
|
||||
/* Returns the string located in image, formatted in C format. */
|
||||
static std::string getString (Int offset)
|
||||
static std::string getString (int offset)
|
||||
{
|
||||
ostringstream o;
|
||||
Int strLen, i;
|
||||
int strLen, i;
|
||||
|
||||
strLen = strSize (&prog.Image[offset], '\0');
|
||||
o << '"';
|
||||
@@ -621,9 +621,9 @@ static std::string getString (Int offset)
|
||||
|
||||
|
||||
/* Walks the conditional expression tree and returns the result on a string */
|
||||
string walkCondExpr (const COND_EXPR* expr, Function * pProc, Int* numLoc)
|
||||
string walkCondExpr (const COND_EXPR* expr, Function * pProc, int* numLoc)
|
||||
{
|
||||
int16 off; /* temporal - for OTHER */
|
||||
int16_t off; /* temporal - for OTHER */
|
||||
ID* id; /* Pointer to local identifier table */
|
||||
//char* o; /* Operand string pointer */
|
||||
bool needBracket; /* Determine whether parenthesis is needed */
|
||||
@@ -828,9 +828,9 @@ void COND_EXPR::changeBoolOp (condOp newOp)
|
||||
|
||||
/* Inserts the expression exp into the tree at the location specified by the
|
||||
* register regi */
|
||||
bool insertSubTreeReg (COND_EXPR *expr, COND_EXPR **tree, byte regi,LOCAL_ID *locsym)
|
||||
bool insertSubTreeReg (COND_EXPR *expr, COND_EXPR **tree, uint8_t regi,LOCAL_ID *locsym)
|
||||
{
|
||||
byte treeReg;
|
||||
uint8_t treeReg;
|
||||
|
||||
if (*tree == NULL)
|
||||
return FALSE;
|
||||
@@ -840,12 +840,12 @@ bool insertSubTreeReg (COND_EXPR *expr, COND_EXPR **tree, byte regi,LOCAL_ID *lo
|
||||
if ((*tree)->expr.ident.idType == REGISTER)
|
||||
{
|
||||
treeReg = locsym->id_arr[(*tree)->expr.ident.idNode.regiIdx].id.regi;
|
||||
if (treeReg == regi) /* word reg */
|
||||
if (treeReg == regi) /* uint16_t reg */
|
||||
{
|
||||
*tree = expr;
|
||||
return TRUE;
|
||||
}
|
||||
else if ((regi >= rAX) && (regi <= rBX)) /* word/byte reg */
|
||||
else if ((regi >= rAX) && (regi <= rBX)) /* uint16_t/uint8_t reg */
|
||||
{
|
||||
if ((treeReg == (regi + rAL-1)) || (treeReg == (regi + rAH-1)))
|
||||
{
|
||||
@@ -876,7 +876,7 @@ bool insertSubTreeReg (COND_EXPR *expr, COND_EXPR **tree, byte regi,LOCAL_ID *lo
|
||||
|
||||
/* Inserts the expression exp into the tree at the location specified by the
|
||||
* long register index longIdx*/
|
||||
bool insertSubTreeLongReg(COND_EXPR *exp, COND_EXPR **tree, Int longIdx)
|
||||
bool insertSubTreeLongReg(COND_EXPR *exp, COND_EXPR **tree, int longIdx)
|
||||
{
|
||||
switch ((*tree)->type)
|
||||
{
|
||||
|
||||
@@ -22,16 +22,16 @@ static char indentBuf[indSize] =
|
||||
|
||||
|
||||
/* Indentation according to the depth of the statement */
|
||||
char *indent (Int indLevel)
|
||||
char *indent (int indLevel)
|
||||
{
|
||||
return (&indentBuf[indSize-(indLevel*4)-1]);
|
||||
}
|
||||
|
||||
|
||||
/* Returns a unique index to the next label */
|
||||
Int getNextLabel()
|
||||
int getNextLabel()
|
||||
{
|
||||
static Int labelIdx = 1; /* index of the next label */
|
||||
static int labelIdx = 1; /* index of the next label */
|
||||
return (labelIdx++);
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ static void fixupLabels (PPROC pProc)
|
||||
* a unique label number for it. This label is placed in the associated
|
||||
* icode for the node (pProc->Icode). The procedure is done in sequential
|
||||
* order of dsfLast numbering. */
|
||||
{ Int i; /* index into the dfsLast array */
|
||||
{ int i; /* index into the dfsLast array */
|
||||
PBB *dfsLast; /* pointer to the dfsLast array */
|
||||
|
||||
dfsLast = pProc->dfsLast;
|
||||
@@ -73,7 +73,7 @@ static void fixupLabels (PPROC pProc)
|
||||
|
||||
/* Returns the corresponding C string for the given character c. Character
|
||||
* constants such as carriage return and line feed, require 2 C characters. */
|
||||
char *cChar (byte c)
|
||||
char *cChar (uint8_t c)
|
||||
{
|
||||
static char res[3];
|
||||
|
||||
@@ -106,19 +106,19 @@ char *cChar (byte c)
|
||||
* exe file: prog.Image[operand+0x100] */
|
||||
static void printGlobVar (SYM * psym)
|
||||
{
|
||||
Int j;
|
||||
dword relocOp = prog.fCOM ? psym->label : psym->label + 0x100;
|
||||
int j;
|
||||
uint32_t relocOp = prog.fCOM ? psym->label : psym->label + 0x100;
|
||||
char *strContents; /* initial contents of variable */
|
||||
|
||||
switch (psym->size) {
|
||||
case 1: cCode.appendDecl( "byte\t%s = %ld;\n",
|
||||
case 1: cCode.appendDecl( "uint8_t\t%s = %ld;\n",
|
||||
psym->name, prog.Image[relocOp]);
|
||||
break;
|
||||
case 2: cCode.appendDecl( "word\t%s = %ld;\n",
|
||||
case 2: cCode.appendDecl( "uint16_t\t%s = %ld;\n",
|
||||
psym->name, LH(prog.Image+relocOp));
|
||||
break;
|
||||
case 4: if (psym->type == TYPE_PTR) /* pointer */
|
||||
cCode.appendDecl( "word\t*%s = %ld;\n",
|
||||
cCode.appendDecl( "uint16_t\t*%s = %ld;\n",
|
||||
psym->name, LH(prog.Image+relocOp));
|
||||
else /* char */
|
||||
cCode.appendDecl(
|
||||
@@ -144,7 +144,7 @@ static void printGlobVar (SYM * psym)
|
||||
* initialization. */
|
||||
static void writeGlobSymTable()
|
||||
{
|
||||
Int idx;
|
||||
int idx;
|
||||
char type[10];
|
||||
SYM * pSym;
|
||||
|
||||
@@ -158,7 +158,7 @@ static void writeGlobSymTable()
|
||||
printGlobVar (&symtab[idx]);
|
||||
else { /* first defined */
|
||||
switch (pSym->size) {
|
||||
case 1: strcpy (type, "byte\t"); break;
|
||||
case 1: strcpy (type, "uint8_t\t"); break;
|
||||
case 2: strcpy (type, "int\t"); break;
|
||||
case 4: if (pSym->type == TYPE_PTR)
|
||||
strcpy (type, "int\t*");
|
||||
@@ -195,9 +195,9 @@ static void writeHeader (std::ostream &ios, char *fileName)
|
||||
|
||||
|
||||
/* Writes the registers that are set in the bitvector */
|
||||
static void writeBitVector (dword regi)
|
||||
static void writeBitVector (uint32_t regi)
|
||||
{
|
||||
Int j;
|
||||
int j;
|
||||
|
||||
for (j = 0; j < INDEXBASE; j++)
|
||||
{
|
||||
@@ -206,7 +206,7 @@ static void writeBitVector (dword regi)
|
||||
}
|
||||
}
|
||||
static void writeBitVector (const std::bitset<32> ®i)
|
||||
{ Int j;
|
||||
{ int j;
|
||||
|
||||
for (j = 0; j < INDEXBASE; j++)
|
||||
{
|
||||
@@ -223,7 +223,7 @@ static void writeBitVector (const std::bitset<32> ®i)
|
||||
* is created and a goto is also emitted.
|
||||
* Note: this procedure is to be used when the label is to be forward on
|
||||
* the code; that is, the target code has not been traversed yet. */
|
||||
static void emitFwdGotoLabel (ICODE * pt, Int indLevel)
|
||||
static void emitFwdGotoLabel (ICODE * pt, int indLevel)
|
||||
{
|
||||
if (! (pt->ic.ll.flg & HLL_LABEL)) /* node hasn't got a lab */
|
||||
{
|
||||
@@ -240,7 +240,7 @@ static void emitFwdGotoLabel (ICODE * pt, Int indLevel)
|
||||
* and invokes the procedure that writes the code of the given record *hli */
|
||||
void Function::codeGen (std::ostream &fs)
|
||||
{
|
||||
Int i, numLoc;
|
||||
int i, numLoc;
|
||||
//STKFRAME * args; /* Procedure arguments */
|
||||
char buf[200], /* Procedure's definition */
|
||||
arg[30]; /* One argument */
|
||||
@@ -339,7 +339,7 @@ void Function::codeGen (std::ostream &fs)
|
||||
* of the call graph. */
|
||||
static void backBackEnd (char *filename, CALL_GRAPH * pcallGraph, std::ostream &ios)
|
||||
{
|
||||
Int i;
|
||||
int i;
|
||||
|
||||
// IFace.Yield(); /* This is a good place to yield to other apps */
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ void newBundle (bundle *)
|
||||
|
||||
|
||||
/* Returns the next available index into the table */
|
||||
Int nextBundleIdx (strTable *strTab)
|
||||
int nextBundleIdx (strTable *strTab)
|
||||
{
|
||||
return (strTab->size());
|
||||
}
|
||||
@@ -29,7 +29,7 @@ Int nextBundleIdx (strTable *strTab)
|
||||
|
||||
/* Adds the given label to the start of the line strTab[idx]. The first
|
||||
* tab is removed and replaced by this label */
|
||||
void addLabelBundle (strTable &strTab, Int idx, Int label)
|
||||
void addLabelBundle (strTable &strTab, int idx, int label)
|
||||
{
|
||||
char s[lineSize];
|
||||
sprintf (s, "l%ld: %s", label, strTab[idx].c_str()+4);
|
||||
@@ -40,7 +40,7 @@ void addLabelBundle (strTable &strTab, Int idx, Int label)
|
||||
/* Writes the contents of the string table on the file fp. */
|
||||
static void writeStrTab (std::ostream &ios, strTable &strTab)
|
||||
{
|
||||
Int i;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < strTab.size(); i++)
|
||||
ios << strTab[i];
|
||||
|
||||
108
src/chklib.cpp
108
src/chklib.cpp
@@ -22,7 +22,7 @@
|
||||
typedef struct HT_tag
|
||||
{
|
||||
char htSym[SYMLEN];
|
||||
byte htPat[PATLEN];
|
||||
uint8_t htPat[PATLEN];
|
||||
} HT;
|
||||
|
||||
/* Structure of the prototypes table. Same as the struct in parsehdr.h,
|
||||
@@ -51,8 +51,8 @@ unsigned SymLen; /* Max size of the symbols, including null */
|
||||
FILE *f; /* File being read */
|
||||
static char sSigName[100]; /* Full path name of .sig file */
|
||||
|
||||
static word *T1base, *T2base; /* Pointers to start of T1, T2 */
|
||||
static word *g; /* g[] */
|
||||
static uint16_t *T1base, *T2base; /* Pointers to start of T1, T2 */
|
||||
static uint16_t *g; /* g[] */
|
||||
static HT *ht; /* The hash table */
|
||||
static PH_FUNC_STRUCT *pFunc; /* Points to the array of func names */
|
||||
static hlType *pArg=0; /* Points to the array of param types */
|
||||
@@ -62,8 +62,8 @@ static int numArg; /* Number of param names actually stored
|
||||
|
||||
/* prototypes */
|
||||
void grab(int n, FILE *f);
|
||||
word readFileShort(FILE *f);
|
||||
void readFileSection(word* p, int len, FILE *f);
|
||||
uint16_t readFileShort(FILE *f);
|
||||
void readFileSection(uint16_t* p, int len, FILE *f);
|
||||
void cleanup(void);
|
||||
void checkStartup(STATE *state);
|
||||
void readProtoFile(void);
|
||||
@@ -71,17 +71,17 @@ void fixNewline(char *s);
|
||||
int searchPList(char *name);
|
||||
void checkHeap(char *msg); /* For debugging */
|
||||
|
||||
void fixWildCards(byte pat[]); /* In fixwild.c */
|
||||
void fixWildCards(uint8_t pat[]); /* In fixwild.c */
|
||||
|
||||
static boolT locatePattern(byte *source, Int iMin, Int iMax, byte *pattern,
|
||||
Int iPatLen, Int *index);
|
||||
static boolT locatePattern(uint8_t *source, int iMin, int iMax, uint8_t *pattern,
|
||||
int iPatLen, int *index);
|
||||
|
||||
/* * * * * * * * * * * * * * * *\
|
||||
* *
|
||||
* S t a r t P a t t e r n s ( V e n d o r i d ) *
|
||||
* *
|
||||
\* * * * * * * * * * * * * * * */
|
||||
static byte pattMsC5Start[] =
|
||||
static uint8_t pattMsC5Start[] =
|
||||
{
|
||||
0xB4, 0x30, /* Mov ah, 30 */
|
||||
0xCD, 0x21, /* int 21 (dos version number) */
|
||||
@@ -90,7 +90,7 @@ static byte pattMsC5Start[] =
|
||||
0xCD, 0x20, /* int 20 (exit) */
|
||||
0xBF /* Mov di, DSEG */
|
||||
};
|
||||
static byte pattMsC8Start[] =
|
||||
static uint8_t pattMsC8Start[] =
|
||||
{
|
||||
0xB4, 0x30, /* Mov ah, 30 */
|
||||
0xCD, 0x21, /* int 21 */
|
||||
@@ -101,7 +101,7 @@ static byte pattMsC8Start[] =
|
||||
0xCB, /* retf */
|
||||
0xBF /* mov di, DSEG */
|
||||
};
|
||||
static byte pattMsC8ComStart[] =
|
||||
static uint8_t pattMsC8ComStart[] =
|
||||
{
|
||||
0xB4, 0x30, /* Mov ah, 30 */
|
||||
0xCD, 0x21, /* int 21 (dos version number) */
|
||||
@@ -110,7 +110,7 @@ static byte pattMsC8ComStart[] =
|
||||
0xC3, /* ret */
|
||||
0x8C, 0xDF /* Mov di, ds */
|
||||
};
|
||||
static byte pattBorl2Start[] =
|
||||
static uint8_t pattBorl2Start[] =
|
||||
{
|
||||
0xBA, WILD, WILD, /* Mov dx, dseg */
|
||||
0x2E, 0x89, 0x16, /* mov cs:[], dx */
|
||||
@@ -126,7 +126,7 @@ static byte pattBorl2Start[] =
|
||||
0x89, 0x2E, WILD, WILD, /* mov [xx], bp */
|
||||
0xC7 /* mov [xx], -1 */
|
||||
};
|
||||
static byte pattBorl3Start[] =
|
||||
static uint8_t pattBorl3Start[] =
|
||||
{
|
||||
0xBA, WILD, WILD, /* Mov dx, dseg */
|
||||
0x2E, 0x89, 0x16, /* mov cs:[], dx */
|
||||
@@ -143,12 +143,12 @@ static byte pattBorl3Start[] =
|
||||
0xE8 /* call ... */
|
||||
};
|
||||
|
||||
static byte pattBorl4on[] =
|
||||
static uint8_t pattBorl4on[] =
|
||||
{
|
||||
0x9A, 0, 0, WILD, WILD /* Call init (offset always 0) */
|
||||
};
|
||||
|
||||
static byte pattBorl4Init[] =
|
||||
static uint8_t pattBorl4Init[] =
|
||||
{
|
||||
0xBA, WILD, WILD, /* Mov dx, dseg */
|
||||
0x8E, 0xDA, /* mov ds, dx */
|
||||
@@ -160,7 +160,7 @@ static byte pattBorl4Init[] =
|
||||
0x8C, 0xD2 /* mov dx, ss */
|
||||
};
|
||||
|
||||
static byte pattBorl5Init[] =
|
||||
static uint8_t pattBorl5Init[] =
|
||||
{
|
||||
0xBA, WILD, WILD, /* Mov dx, dseg */
|
||||
0x8E, 0xDA, /* mov ds, dx */
|
||||
@@ -173,7 +173,7 @@ static byte pattBorl5Init[] =
|
||||
0x8C, 0xD2 /* mov dx, ss */
|
||||
};
|
||||
|
||||
static byte pattBorl7Init[] =
|
||||
static uint8_t pattBorl7Init[] =
|
||||
{
|
||||
0xBA, WILD, WILD, /* Mov dx, dseg */
|
||||
0x8E, 0xDA, /* mov ds, dx */
|
||||
@@ -188,7 +188,7 @@ static byte pattBorl7Init[] =
|
||||
};
|
||||
|
||||
|
||||
static byte pattLogiStart[] =
|
||||
static uint8_t pattLogiStart[] =
|
||||
{
|
||||
0xEB, 0x04, /* jmp short $+6 */
|
||||
WILD, WILD, /* Don't know what this is */
|
||||
@@ -197,7 +197,7 @@ static byte pattLogiStart[] =
|
||||
0x8E, 0xD8 /* mov ds, ax */
|
||||
};
|
||||
|
||||
static byte pattTPasStart[] =
|
||||
static uint8_t pattTPasStart[] =
|
||||
{
|
||||
0xE9, 0x79, 0x2C /* Jmp 2D7C - Turbo pascal 3.0 */
|
||||
};
|
||||
@@ -212,7 +212,7 @@ static byte pattTPasStart[] =
|
||||
|
||||
|
||||
/* This pattern works for MS and Borland, small and tiny model */
|
||||
static byte pattMainSmall[] =
|
||||
static uint8_t pattMainSmall[] =
|
||||
{
|
||||
0xFF, 0x36, WILD, WILD, /* Push environment pointer */
|
||||
0xFF, 0x36, WILD, WILD, /* Push argv */
|
||||
@@ -225,7 +225,7 @@ static byte pattMainSmall[] =
|
||||
#define OFFMAINSMALL 13
|
||||
|
||||
/* This pattern works for MS and Borland, medium model */
|
||||
static byte pattMainMedium[] =
|
||||
static uint8_t pattMainMedium[] =
|
||||
{
|
||||
0xFF, 0x36, WILD, WILD, /* Push environment pointer */
|
||||
0xFF, 0x36, WILD, WILD, /* Push argv */
|
||||
@@ -239,7 +239,7 @@ static byte pattMainMedium[] =
|
||||
#define OFFMAINMEDIUM 13
|
||||
|
||||
/* This pattern works for MS and Borland, compact model */
|
||||
static byte pattMainCompact[] =
|
||||
static uint8_t pattMainCompact[] =
|
||||
{
|
||||
0xFF, 0x36, WILD, WILD, /* Push environment pointer lo */
|
||||
0xFF, 0x36, WILD, WILD, /* Push environment pointer hi */
|
||||
@@ -254,7 +254,7 @@ static byte pattMainCompact[] =
|
||||
#define OFFMAINCOMPACT 21
|
||||
|
||||
/* This pattern works for MS and Borland, large model */
|
||||
static byte pattMainLarge[] =
|
||||
static uint8_t pattMainLarge[] =
|
||||
{
|
||||
0xFF, 0x36, WILD, WILD, /* Push environment pointer lo */
|
||||
0xFF, 0x36, WILD, WILD, /* Push environment pointer hi */
|
||||
@@ -277,7 +277,7 @@ static byte pattMainLarge[] =
|
||||
\* * * * * * * * * * * * * * * */
|
||||
|
||||
/* This pattern is for the stack check code in Microsoft compilers */
|
||||
static byte pattMsChkstk[] =
|
||||
static uint8_t pattMsChkstk[] =
|
||||
{
|
||||
0x59, /* pop cx */
|
||||
0x8B, 0xDC, /* mov bx, sp */
|
||||
@@ -297,7 +297,7 @@ static byte pattMsChkstk[] =
|
||||
/* This procedure is called to initialise the library check code */
|
||||
void SetupLibCheck(void)
|
||||
{
|
||||
word w, len;
|
||||
uint16_t w, len;
|
||||
int i;
|
||||
|
||||
if ((f = fopen(sSigName, "rb")) == NULL)
|
||||
@@ -348,7 +348,7 @@ void SetupLibCheck(void)
|
||||
printf("Expected 'T1'\n");
|
||||
exit(3);
|
||||
}
|
||||
len = (word) (PatLen * 256 * sizeof(word));
|
||||
len = (uint16_t) (PatLen * 256 * sizeof(uint16_t));
|
||||
w = readFileShort(f);
|
||||
if (w != len)
|
||||
{
|
||||
@@ -378,7 +378,7 @@ void SetupLibCheck(void)
|
||||
printf("Expected 'gg'\n");
|
||||
exit(3);
|
||||
}
|
||||
len = (word)(numVert * sizeof(word));
|
||||
len = (uint16_t)(numVert * sizeof(uint16_t));
|
||||
w = readFileShort(f);
|
||||
if (w != len)
|
||||
{
|
||||
@@ -403,7 +403,7 @@ void SetupLibCheck(void)
|
||||
exit(3);
|
||||
}
|
||||
w = readFileShort(f);
|
||||
if (w != numKeys * (SymLen + PatLen + sizeof(word)))
|
||||
if (w != numKeys * (SymLen + PatLen + sizeof(uint16_t)))
|
||||
{
|
||||
printf("Problem with size of hash table: file %d, calc %d\n", w, len);
|
||||
exit(6);
|
||||
@@ -438,8 +438,8 @@ bool LibCheck(Function & pProc)
|
||||
{
|
||||
long fileOffset;
|
||||
int h, i, j, arg;
|
||||
Int Idx;
|
||||
byte pat[PATLEN];
|
||||
int Idx;
|
||||
uint8_t pat[PATLEN];
|
||||
|
||||
if (prog.bSigs == FALSE)
|
||||
{
|
||||
@@ -537,10 +537,10 @@ void grab(int n, FILE *f)
|
||||
}
|
||||
}
|
||||
|
||||
word
|
||||
uint16_t
|
||||
readFileShort(FILE *f)
|
||||
{
|
||||
byte b1, b2;
|
||||
uint8_t b1, b2;
|
||||
|
||||
if (fread(&b1, 1, 1, f) != 1)
|
||||
{
|
||||
@@ -552,12 +552,12 @@ readFileShort(FILE *f)
|
||||
printf("Could not read short\n");
|
||||
exit(11);
|
||||
}
|
||||
return (word)(b2 << 8) + (word)b1;
|
||||
return (uint16_t)(b2 << 8) + (uint16_t)b1;
|
||||
}
|
||||
|
||||
// Read a section of the file, considering endian issues
|
||||
void
|
||||
readFileSection(word* p, int len, FILE* f)
|
||||
readFileSection(uint16_t* p, int len, FILE* f)
|
||||
{
|
||||
for (int i=0; i < len; i += 2)
|
||||
{
|
||||
@@ -566,7 +566,7 @@ readFileSection(word* p, int len, FILE* f)
|
||||
}
|
||||
|
||||
/* The following two functions are dummies, since we don't call map() */
|
||||
void getKey(int i, byte **keys)
|
||||
void getKey(int i, uint8_t **keys)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -578,16 +578,16 @@ void dispKey(int i)
|
||||
|
||||
/* Search the source array between limits iMin and iMax for the pattern (length
|
||||
iPatLen). The pattern can contain wild bytes; if you really want to match
|
||||
for the pattern that is used up by the WILD byte, tough - it will match with
|
||||
for the pattern that is used up by the WILD uint8_t, tough - it will match with
|
||||
everything else as well. */
|
||||
static boolT locatePattern(byte *source, Int iMin, Int iMax, byte *pattern, Int iPatLen,
|
||||
Int *index)
|
||||
static boolT locatePattern(uint8_t *source, int iMin, int iMax, uint8_t *pattern, int iPatLen,
|
||||
int *index)
|
||||
{
|
||||
Int i, j;
|
||||
byte *pSrc; /* Pointer to start of considered source */
|
||||
Int iLast;
|
||||
int i, j;
|
||||
uint8_t *pSrc; /* Pointer to start of considered source */
|
||||
int iLast;
|
||||
|
||||
iLast = iMax - iPatLen; /* Last source byte to consider */
|
||||
iLast = iMax - iPatLen; /* Last source uint8_t to consider */
|
||||
|
||||
for (i=iMin; i <= iLast; i++)
|
||||
{
|
||||
@@ -595,7 +595,7 @@ static boolT locatePattern(byte *source, Int iMin, Int iMax, byte *pattern, Int
|
||||
/* i is the index of the start of the moving pattern */
|
||||
for (j=0; j < iPatLen; j++)
|
||||
{
|
||||
/* j is the index of the byte being considered in the pattern. */
|
||||
/* j is the index of the uint8_t being considered in the pattern. */
|
||||
if ((*pSrc != pattern[j]) && (pattern[j] != WILD))
|
||||
{
|
||||
/* A definite mismatch */
|
||||
@@ -625,15 +625,15 @@ void STATE::checkStartup()
|
||||
Also sets prog.offMain and prog.segMain if possible */
|
||||
|
||||
|
||||
Int startOff; /* Offset into the Image of the initial CS:IP */
|
||||
Int i, rel, para, init;
|
||||
int startOff; /* Offset into the Image of the initial CS:IP */
|
||||
int i, rel, para, init;
|
||||
char chModel = 'x';
|
||||
char chVendor = 'x';
|
||||
char chVersion = 'x';
|
||||
char *pPath;
|
||||
char temp[4];
|
||||
|
||||
startOff = ((dword)prog.initCS << 4) + prog.initIP;
|
||||
startOff = ((uint32_t)prog.initCS << 4) + prog.initIP;
|
||||
|
||||
/* Check the Turbo Pascal signatures first, since they involve only the
|
||||
first 3 bytes, and false positives may be founf with the others later */
|
||||
@@ -643,7 +643,7 @@ void STATE::checkStartup()
|
||||
determine the version from that */
|
||||
rel = LH(&prog.Image[startOff+1]); /* This is abs off of init */
|
||||
para= LH(&prog.Image[startOff+3]);/* This is abs seg of init */
|
||||
init = ((dword)para << 4) + rel;
|
||||
init = ((uint32_t)para << 4) + rel;
|
||||
if (locatePattern(prog.Image, init, init+26, pattBorl4Init,
|
||||
sizeof(pattBorl4Init), &i))
|
||||
{
|
||||
@@ -654,7 +654,7 @@ void STATE::checkStartup()
|
||||
chModel = 'p'; /* Pascal */
|
||||
chVersion = '4'; /* Version 4 */
|
||||
prog.offMain = startOff; /* Code starts immediately */
|
||||
prog.segMain = prog.initCS; /* At the 5 byte jump */
|
||||
prog.segMain = prog.initCS; /* At the 5 uint8_t jump */
|
||||
goto gotVendor; /* Already have vendor */
|
||||
}
|
||||
else if (locatePattern(prog.Image, init, init+26, pattBorl5Init,
|
||||
@@ -698,8 +698,8 @@ void STATE::checkStartup()
|
||||
rel = LH(&prog.Image[i+OFFMAINLARGE]); /* This is abs off of main */
|
||||
para= LH(&prog.Image[i+OFFMAINLARGE+2]);/* This is abs seg of main */
|
||||
/* Save absolute image offset */
|
||||
prog.offMain = ((dword)para << 4) + rel;
|
||||
prog.segMain = (word)para;
|
||||
prog.offMain = ((uint32_t)para << 4) + rel;
|
||||
prog.segMain = (uint16_t)para;
|
||||
chModel = 'l'; /* Large model */
|
||||
}
|
||||
else if (locatePattern(prog.Image, startOff, startOff+0x180, pattMainCompact,
|
||||
@@ -715,8 +715,8 @@ void STATE::checkStartup()
|
||||
{
|
||||
rel = LH(&prog.Image[i+OFFMAINMEDIUM]); /* This is abs off of main */
|
||||
para= LH(&prog.Image[i+OFFMAINMEDIUM+2]);/* This is abs seg of main */
|
||||
prog.offMain = ((dword)para << 4) + rel;
|
||||
prog.segMain = (word)para;
|
||||
prog.offMain = ((uint32_t)para << 4) + rel;
|
||||
prog.segMain = (uint16_t)para;
|
||||
chModel = 'm'; /* Medium model */
|
||||
}
|
||||
else if (locatePattern(prog.Image, startOff, startOff+0x180, pattMainSmall,
|
||||
@@ -787,7 +787,7 @@ void STATE::checkStartup()
|
||||
else if (locatePattern(prog.Image, startOff, startOff+0x30, pattBorl2Start,
|
||||
sizeof(pattBorl2Start), &i))
|
||||
{
|
||||
/* Borland startup. DS is at the second byte (offset 1) */
|
||||
/* Borland startup. DS is at the second uint8_t (offset 1) */
|
||||
setState( rDS, LH(&prog.Image[i+1]));
|
||||
printf("Borland v2 detected\n");
|
||||
chVendor = 'b'; /* Borland compiler */
|
||||
@@ -797,7 +797,7 @@ void STATE::checkStartup()
|
||||
else if (locatePattern(prog.Image, startOff, startOff+0x30, pattBorl3Start,
|
||||
sizeof(pattBorl3Start), &i))
|
||||
{
|
||||
/* Borland startup. DS is at the second byte (offset 1) */
|
||||
/* Borland startup. DS is at the second uint8_t (offset 1) */
|
||||
setState( rDS, LH(&prog.Image[i+1]));
|
||||
printf("Borland v3 detected\n");
|
||||
chVendor = 'b'; /* Borland compiler */
|
||||
|
||||
@@ -113,7 +113,7 @@ static const char *int21h[] =
|
||||
"Reserved",
|
||||
"Reserved",
|
||||
"Get PSP address",
|
||||
"Get DBCS lead byte table",
|
||||
"Get DBCS lead uint8_t table",
|
||||
"Reserved",
|
||||
"Get extended country information",
|
||||
"Get or set code page",
|
||||
|
||||
@@ -15,10 +15,10 @@
|
||||
#endif
|
||||
|
||||
//typedef struct list {
|
||||
// Int nodeIdx;
|
||||
// int nodeIdx;
|
||||
// struct list *next;
|
||||
//} nodeList;
|
||||
typedef std::list<Int> nodeList; /* dfsLast index to the node */
|
||||
typedef std::list<int> nodeList; /* dfsLast index to the node */
|
||||
|
||||
#define ancestor(a,b) ((a->dfsLastNum < b->dfsLastNum) && (a->dfsFirstNum < b->dfsFirstNum))
|
||||
/* there is a path on the DFST from a to b if the a was first visited in a
|
||||
@@ -43,7 +43,7 @@ static boolT isBackEdge (BB * p,BB * s)
|
||||
|
||||
/* Finds the common dominator of the current immediate dominator
|
||||
* currImmDom and its predecessor's immediate dominator predImmDom */
|
||||
static Int commonDom (Int currImmDom, Int predImmDom, Function * pProc)
|
||||
static int commonDom (int currImmDom, int predImmDom, Function * pProc)
|
||||
{
|
||||
if (currImmDom == NO_DOM)
|
||||
return (predImmDom);
|
||||
@@ -69,7 +69,7 @@ static Int commonDom (Int currImmDom, Int predImmDom, Function * pProc)
|
||||
void Function::findImmedDom ()
|
||||
{
|
||||
BB * currNode;
|
||||
Int currIdx, j, predIdx;
|
||||
int currIdx, j, predIdx;
|
||||
|
||||
for (currIdx = 0; currIdx < numBBs; currIdx++)
|
||||
{
|
||||
@@ -87,7 +87,7 @@ void Function::findImmedDom ()
|
||||
|
||||
|
||||
/* Inserts the node n to the list l. */
|
||||
static void insertList (nodeList &l, Int n)
|
||||
static void insertList (nodeList &l, int n)
|
||||
{
|
||||
l.push_back(n);
|
||||
}
|
||||
@@ -95,7 +95,7 @@ static void insertList (nodeList &l, Int n)
|
||||
|
||||
/* Returns whether or not the node n (dfsLast numbering of a basic block)
|
||||
* is on the list l. */
|
||||
static boolT inList (nodeList &l, Int n)
|
||||
static boolT inList (nodeList &l, int n)
|
||||
{
|
||||
return std::find(l.begin(),l.end(),n)!=l.end();
|
||||
}
|
||||
@@ -119,7 +119,7 @@ static boolT inInt(BB * n, queue &q)
|
||||
* The follow node is the closest node to the loop. */
|
||||
static void findEndlessFollow (Function * pProc, nodeList &loopNodes, BB * head)
|
||||
{
|
||||
Int j, succ;
|
||||
int j, succ;
|
||||
|
||||
head->loopFollow = MAX;
|
||||
nodeList::iterator p = loopNodes.begin();
|
||||
@@ -140,9 +140,9 @@ static void findEndlessFollow (Function * pProc, nodeList &loopNodes, BB * head)
|
||||
* determines the type of loop. */
|
||||
static void findNodesInLoop(BB * latchNode,BB * head,Function * pProc,queue &intNodes)
|
||||
{
|
||||
Int i, headDfsNum, intNodeType;
|
||||
int i, headDfsNum, intNodeType;
|
||||
nodeList loopNodes;
|
||||
Int immedDom, /* dfsLast index to immediate dominator */
|
||||
int immedDom, /* dfsLast index to immediate dominator */
|
||||
thenDfs, elseDfs; /* dsfLast index for THEN and ELSE nodes */
|
||||
BB * pbb;
|
||||
|
||||
@@ -248,10 +248,10 @@ static void findNodesInLoop(BB * latchNode,BB * head,Function * pProc,queue &int
|
||||
freeList(loopNodes);
|
||||
}
|
||||
|
||||
//static void findNodesInInt (queue **intNodes, Int level, interval *Ii)
|
||||
//static void findNodesInInt (queue **intNodes, int level, interval *Ii)
|
||||
/* Recursive procedure to find nodes that belong to the interval (ie. nodes
|
||||
* from G1). */
|
||||
static void findNodesInInt (queue &intNodes, Int level, interval *Ii)
|
||||
static void findNodesInInt (queue &intNodes, int level, interval *Ii)
|
||||
{
|
||||
if (level == 1)
|
||||
{
|
||||
@@ -271,7 +271,7 @@ void Function::structLoops(derSeq *derivedG)
|
||||
BB * intHead, /* interval header node */
|
||||
* pred, /* predecessor node */
|
||||
* latchNode;/* latching node (in case of loops) */
|
||||
Int i, /* counter */
|
||||
int i, /* counter */
|
||||
level = 0; /* derived sequence level */
|
||||
interval *initInt; /* initial interval */
|
||||
queue intNodes; /* list of interval nodes */
|
||||
@@ -337,9 +337,9 @@ void Function::structLoops(derSeq *derivedG)
|
||||
|
||||
/* Returns whether the BB indexed by s is a successor of the BB indexed by
|
||||
* h. Note that h is a case node. */
|
||||
static boolT successor (Int s, Int h, Function * pProc)
|
||||
static boolT successor (int s, int h, Function * pProc)
|
||||
{
|
||||
Int i;
|
||||
int i;
|
||||
BB * header;
|
||||
|
||||
header = pProc->m_dfsLast[h];
|
||||
@@ -353,8 +353,8 @@ static boolT successor (Int s, Int h, Function * pProc)
|
||||
/* 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 */
|
||||
static void tagNodesInCase (BB * pBB, nodeList &l, int head, int tail)
|
||||
{ int current, /* index to current node */
|
||||
i;
|
||||
|
||||
pBB->traversed = DFS_CASE;
|
||||
@@ -374,9 +374,9 @@ static void tagNodesInCase (BB * pBB, nodeList &l, Int head, Int tail)
|
||||
* has a case node. */
|
||||
void Function::structCases()
|
||||
{
|
||||
Int i, j;
|
||||
int i, j;
|
||||
BB * caseHeader; /* case header node */
|
||||
Int exitNode = NO_NODE; /* case exit node */
|
||||
int exitNode = NO_NODE; /* case exit node */
|
||||
nodeList caseNodes; /* temporary: list of nodes in case */
|
||||
|
||||
/* Linear scan of the nodes in reverse dfsLast order, searching for
|
||||
@@ -417,7 +417,7 @@ void Function::structCases()
|
||||
|
||||
/* Flags all nodes in the list l as having follow node f, and deletes all
|
||||
* nodes from the list. */
|
||||
static void flagNodes (nodeList &l, Int f, Function * pProc)
|
||||
static void flagNodes (nodeList &l, int f, Function * pProc)
|
||||
{
|
||||
nodeList::iterator p;
|
||||
|
||||
@@ -433,7 +433,7 @@ static void flagNodes (nodeList &l, Int f, Function * pProc)
|
||||
/* Structures if statements */
|
||||
void Function::structIfs ()
|
||||
{
|
||||
Int curr, /* Index for linear scan of nodes */
|
||||
int curr, /* Index for linear scan of nodes */
|
||||
desc, /* Index for descendant */
|
||||
followInEdges, /* Largest # in-edges so far */
|
||||
follow; /* Possible follow node */
|
||||
@@ -491,7 +491,7 @@ void Function::structIfs ()
|
||||
* into one block with the appropriate condition */
|
||||
void Function::compoundCond()
|
||||
{
|
||||
Int i, j, k, numOutEdges;
|
||||
int i, j, k, numOutEdges;
|
||||
BB * pbb, * t, * e, * obb,* pred;
|
||||
ICODE * picode, * ticode;
|
||||
COND_EXPR *exp;
|
||||
|
||||
182
src/dataflow.cpp
182
src/dataflow.cpp
@@ -18,7 +18,7 @@ struct ExpStack
|
||||
void init();
|
||||
void push(COND_EXPR *);
|
||||
COND_EXPR * pop();
|
||||
Int numElem();
|
||||
int numElem();
|
||||
boolT empty();
|
||||
};
|
||||
/***************************************************************************
|
||||
@@ -53,7 +53,7 @@ COND_EXPR *ExpStack::pop()
|
||||
}
|
||||
|
||||
/* Returns the number of elements available in the expression stack */
|
||||
Int ExpStack::numElem()
|
||||
int ExpStack::numElem()
|
||||
{
|
||||
return expStk.size();
|
||||
}
|
||||
@@ -69,9 +69,9 @@ ExpStack g_exp_stk;
|
||||
|
||||
/* Returns the index of the local variable or parameter at offset off, if it
|
||||
* is in the stack frame provided. */
|
||||
Int STKFRAME::getLocVar(Int off)
|
||||
int STKFRAME::getLocVar(int off)
|
||||
{
|
||||
Int i;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < sym.size(); i++)
|
||||
if (sym[i].off == off)
|
||||
@@ -102,16 +102,13 @@ static COND_EXPR *dstIdent (const ICODE & Icode, Function * pProc, iICODE i, ICO
|
||||
/** Is it needed? (pIcode->ic.ll.flg) & NO_SRC_B **/
|
||||
return (n);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Eliminates all condition codes and generates new hlIcode instructions */
|
||||
void Function::elimCondCodes ()
|
||||
{
|
||||
Int i;
|
||||
int i;
|
||||
|
||||
byte use; /* Used flags bit vector */
|
||||
byte def; /* Defined flags bit vector */
|
||||
uint8_t use; /* Used flags bit vector */
|
||||
uint8_t def; /* Defined flags bit vector */
|
||||
boolT notSup; /* Use/def combination not supported */
|
||||
COND_EXPR *rhs; /* Source operand */
|
||||
COND_EXPR *lhs; /* Destination operand */
|
||||
@@ -127,9 +124,7 @@ void Function::elimCondCodes ()
|
||||
|
||||
for (useAt = pBB->rbegin2(); useAt != pBB->rend2(); useAt++)
|
||||
{
|
||||
if ((useAt->type == LOW_LEVEL) &&
|
||||
(useAt->invalid == FALSE) &&
|
||||
(use = useAt->ic.ll.flagDU.u))
|
||||
if ((useAt->type == LOW_LEVEL) && (useAt->valid()) && (use = useAt->ic.ll.flagDU.u))
|
||||
{
|
||||
/* Find definition within the same basic block */
|
||||
defAt=useAt;
|
||||
@@ -139,66 +134,83 @@ void Function::elimCondCodes ()
|
||||
def = defAt->ic.ll.flagDU.d;
|
||||
if ((use & def) != use)
|
||||
continue;
|
||||
notSup = FALSE;
|
||||
if ((useAt->GetLlOpcode() >= iJB) && (useAt->GetLlOpcode() <= iJNS))
|
||||
{
|
||||
notSup = FALSE;
|
||||
if ((useAt->GetLlOpcode() >= iJB) && (useAt->GetLlOpcode() <= iJNS))
|
||||
{
|
||||
iICODE befDefAt = (++riICODE(defAt)).base();
|
||||
switch (defAt->GetLlOpcode())
|
||||
{
|
||||
case iCMP:
|
||||
switch (defAt->GetLlOpcode())
|
||||
{
|
||||
case iCMP:
|
||||
rhs = srcIdent (*defAt, this, befDefAt,*useAt, eUSE);
|
||||
lhs = dstIdent (*defAt, this, befDefAt,*useAt, eUSE);
|
||||
break;
|
||||
break;
|
||||
|
||||
case iOR:
|
||||
lhs = defAt->ic.hl.asgn.lhs->clone();
|
||||
useAt->copyDU(*defAt, eUSE, eDEF);
|
||||
if (defAt->isLlFlag(B))
|
||||
rhs = COND_EXPR::idKte (0, 1);
|
||||
else
|
||||
rhs = COND_EXPR::idKte (0, 2);
|
||||
break;
|
||||
case iOR:
|
||||
lhs = defAt->ic.hl.asgn.lhs->clone();
|
||||
useAt->copyDU(*defAt, eUSE, eDEF);
|
||||
if (defAt->isLlFlag(B))
|
||||
rhs = COND_EXPR::idKte (0, 1);
|
||||
else
|
||||
rhs = COND_EXPR::idKte (0, 2);
|
||||
break;
|
||||
|
||||
case iTEST:
|
||||
case iTEST:
|
||||
rhs = srcIdent (*defAt,this, befDefAt,*useAt, eUSE);
|
||||
lhs = dstIdent (*defAt,this, befDefAt,*useAt, eUSE);
|
||||
lhs = COND_EXPR::boolOp (lhs, rhs, AND);
|
||||
if (defAt->isLlFlag(B))
|
||||
rhs = COND_EXPR::idKte (0, 1);
|
||||
else
|
||||
rhs = COND_EXPR::idKte (0, 2);
|
||||
break;
|
||||
lhs = COND_EXPR::boolOp (lhs, rhs, AND);
|
||||
if (defAt->isLlFlag(B))
|
||||
rhs = COND_EXPR::idKte (0, 1);
|
||||
else
|
||||
rhs = COND_EXPR::idKte (0, 2);
|
||||
break;
|
||||
|
||||
default:
|
||||
notSup = TRUE;
|
||||
std::cout << hex<<defAt->loc_ip;
|
||||
reportError (JX_NOT_DEF, defAt->GetLlOpcode());
|
||||
flg |= PROC_ASM; /* generate asm */
|
||||
}
|
||||
if (! notSup)
|
||||
{
|
||||
exp = COND_EXPR::boolOp (lhs, rhs,condOpJCond[useAt->GetLlOpcode()-iJB]);
|
||||
useAt->setJCond(exp);
|
||||
}
|
||||
}
|
||||
|
||||
else if (useAt->GetLlOpcode() == iJCXZ)
|
||||
{
|
||||
lhs = COND_EXPR::idReg (rCX, 0, &localId);
|
||||
useAt->setRegDU (rCX, eUSE);
|
||||
rhs = COND_EXPR::idKte (0, 2);
|
||||
exp = COND_EXPR::boolOp (lhs, rhs, EQUAL);
|
||||
useAt->setJCond(exp);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
reportError (NOT_DEF_USE,defAt->GetLlOpcode(),useAt->GetLlOpcode());
|
||||
default:
|
||||
notSup = TRUE;
|
||||
std::cout << hex<<defAt->loc_ip;
|
||||
reportError (JX_NOT_DEF, defAt->GetLlOpcode());
|
||||
flg |= PROC_ASM; /* generate asm */
|
||||
}
|
||||
break;
|
||||
if (! notSup)
|
||||
{
|
||||
exp = COND_EXPR::boolOp (lhs, rhs,condOpJCond[useAt->GetLlOpcode()-iJB]);
|
||||
useAt->setJCond(exp);
|
||||
}
|
||||
}
|
||||
|
||||
else if (useAt->GetLlOpcode() == iJCXZ)
|
||||
{
|
||||
lhs = COND_EXPR::idReg (rCX, 0, &localId);
|
||||
useAt->setRegDU (rCX, eUSE);
|
||||
rhs = COND_EXPR::idKte (0, 2);
|
||||
exp = COND_EXPR::boolOp (lhs, rhs, EQUAL);
|
||||
useAt->setJCond(exp);
|
||||
}
|
||||
// else if (useAt->GetLlOpcode() == iRCL)
|
||||
// {
|
||||
// ICODE &a(*defAt);
|
||||
// ICODE &b(*useAt);
|
||||
// if(a.GetLlOpcode() == iRCL)
|
||||
// {
|
||||
// if ((b.ic.ll.flg & NO_SRC) != NO_SRC) /* if there is src op */
|
||||
// rhs = COND_EXPR::id (*useAt, SRC, this, Icode.end(), *useAt, NONE);
|
||||
// lhs = COND_EXPR::id (*useAt, DST, this, Icode.end(), *useAt, USE_DEF);
|
||||
|
||||
// rhs = COND_EXPR::boolOp (lhs, rhs, SHL);
|
||||
// useAt->setAsgn(lhs->clone(), rhs);
|
||||
// printf("RCL\n");
|
||||
// }
|
||||
|
||||
// }
|
||||
else
|
||||
{
|
||||
ICODE &a(*defAt);
|
||||
ICODE &b(*useAt);
|
||||
reportError (NOT_DEF_USE,a.GetLlOpcode(),b.GetLlOpcode());
|
||||
flg |= PROC_ASM; /* generate asm */
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/* Check for extended basic block */
|
||||
if ((pBB->size() == 1) &&(useAt->GetLlOpcode() >= iJB) && (useAt->GetLlOpcode() <= iJNS))
|
||||
{
|
||||
@@ -231,7 +243,7 @@ void Function::elimCondCodes ()
|
||||
* is not really meant to be a register that is used before defined). */
|
||||
void Function::genLiveKtes ()
|
||||
{
|
||||
Int i;
|
||||
int i;
|
||||
BB * pbb;
|
||||
bitset<32> liveUse, def;
|
||||
|
||||
@@ -261,11 +273,11 @@ void Function::genLiveKtes ()
|
||||
* Propagates register usage information to the procedure call. */
|
||||
void Function::liveRegAnalysis (std::bitset<32> &in_liveOut)
|
||||
{
|
||||
Int i, j;
|
||||
int i, j;
|
||||
BB * pbb=0; /* pointer to current basic block */
|
||||
Function * pcallee; /* invoked subroutine */
|
||||
//ICODE *ticode /* icode that invokes a subroutine */
|
||||
;
|
||||
;
|
||||
std::bitset<32> prevLiveOut, /* previous live out */
|
||||
prevLiveIn; /* previous live in */
|
||||
boolT change; /* is there change in the live sets?*/
|
||||
@@ -329,7 +341,7 @@ void Function::liveRegAnalysis (std::bitset<32> &in_liveOut)
|
||||
{
|
||||
if ( (pcallee->flg & PROC_IS_FUNC) && /* returns a value */
|
||||
(pcallee->liveOut & pbb->edges[0].BBptr->liveIn).any()
|
||||
)
|
||||
)
|
||||
pbb->liveOut = pcallee->liveOut;
|
||||
else
|
||||
pbb->liveOut = 0;
|
||||
@@ -384,8 +396,8 @@ void Function::liveRegAnalysis (std::bitset<32> &in_liveOut)
|
||||
|
||||
void BB::genDU1()
|
||||
{
|
||||
byte regi; /* Register that was defined */
|
||||
Int k, defRegIdx, useIdx;
|
||||
uint8_t regi; /* Register that was defined */
|
||||
int k, defRegIdx, useIdx;
|
||||
iICODE picode, ticode,lastInst;
|
||||
BB *tbb; /* Target basic block */
|
||||
bool res;
|
||||
@@ -406,7 +418,7 @@ void BB::genDU1()
|
||||
{
|
||||
if (not picode->du.def.test(k))
|
||||
continue;
|
||||
regi = (byte)(k + 1); /* defined register */
|
||||
regi = (uint8_t)(k + 1); /* defined register */
|
||||
picode->du1.regi[defRegIdx] = regi;
|
||||
|
||||
/* Check remaining instructions of the BB for all uses
|
||||
@@ -477,9 +489,9 @@ void BB::genDU1()
|
||||
* return an integer, which is normally not taken into
|
||||
* account by the programmer). */
|
||||
if (picode->valid() and not picode->du1.used(defRegIdx) and
|
||||
(not (picode->du.lastDefRegi & duReg[regi]).any()) &&
|
||||
(not ((picode->ic.hl.opcode == HLI_CALL) &&
|
||||
(picode->ic.hl.call.proc->flg & PROC_ISLIB))))
|
||||
(not (picode->du.lastDefRegi & duReg[regi]).any()) &&
|
||||
(not ((picode->ic.hl.opcode == HLI_CALL) &&
|
||||
(picode->ic.hl.call.proc->flg & PROC_ISLIB))))
|
||||
{
|
||||
if (! (this->liveOut & duReg[regi]).any()) /* not liveOut */
|
||||
{
|
||||
@@ -511,8 +523,8 @@ void BB::genDU1()
|
||||
/* Generates the du chain of each instruction in a basic block */
|
||||
void Function::genDU1 ()
|
||||
{
|
||||
byte regi; /* Register that was defined */
|
||||
Int i, k, defRegIdx, useIdx;
|
||||
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;
|
||||
@@ -533,7 +545,7 @@ void Function::genDU1 ()
|
||||
/* Substitutes the rhs (or lhs if rhs not possible) of ticode for the rhs
|
||||
* of picode. */
|
||||
static void forwardSubs (COND_EXPR *lhs, COND_EXPR *rhs, iICODE picode,
|
||||
iICODE ticode, LOCAL_ID *locsym, Int &numHlIcodes)
|
||||
iICODE ticode, LOCAL_ID *locsym, int &numHlIcodes)
|
||||
{
|
||||
boolT res;
|
||||
|
||||
@@ -566,8 +578,8 @@ static void forwardSubs (COND_EXPR *lhs, COND_EXPR *rhs, iICODE picode,
|
||||
|
||||
/* Substitutes the rhs (or lhs if rhs not possible) of ticode for the
|
||||
* expression exp given */
|
||||
static void forwardSubsLong (Int longIdx, COND_EXPR *exp, iICODE picode,
|
||||
iICODE ticode, Int *numHlIcodes)
|
||||
static void forwardSubsLong (int longIdx, COND_EXPR *exp, iICODE picode,
|
||||
iICODE ticode, int *numHlIcodes)
|
||||
{
|
||||
bool res;
|
||||
|
||||
@@ -600,7 +612,7 @@ static boolT xClear (COND_EXPR *rhs, iICODE f, iICODE t, iICODE lastBBinst, Func
|
||||
{
|
||||
iICODE i;
|
||||
boolT res;
|
||||
byte regi;
|
||||
uint8_t regi;
|
||||
|
||||
if (rhs == NULL)
|
||||
return false;
|
||||
@@ -646,7 +658,7 @@ static boolT xClear (COND_EXPR *rhs, iICODE f, iICODE t, iICODE lastBBinst, Func
|
||||
/* Checks the type of the formal argument as against to the actual argument,
|
||||
* whenever possible, and then places the actual argument on the procedure's
|
||||
* argument list. */
|
||||
static void processCArg (Function * pp, Function * pProc, ICODE * picode, Int numArgs, Int *k)
|
||||
static void processCArg (Function * pp, Function * pProc, ICODE * picode, int numArgs, int *k)
|
||||
{
|
||||
COND_EXPR *exp;
|
||||
boolT res;
|
||||
@@ -685,7 +697,7 @@ static void processCArg (Function * pp, Function * pProc, ICODE * picode, Int nu
|
||||
* For HLI_CALL hlIcodes, places the arguments in the argument list. */
|
||||
void Function::findExps()
|
||||
{
|
||||
Int i, k, numHlIcodes;
|
||||
int i, k, numHlIcodes;
|
||||
iICODE lastInst,
|
||||
picode, // Current icode */
|
||||
ticode; // Target icode */
|
||||
@@ -694,7 +706,7 @@ void Function::findExps()
|
||||
COND_EXPR *exp, // expression pointer - for HLI_POP and HLI_CALL */
|
||||
*lhs; // exp ptr for return value of a HLI_CALL */
|
||||
//STKFRAME * args; // pointer to arguments - for HLI_CALL */
|
||||
byte regi; // register(s) to be forward substituted */
|
||||
uint8_t regi; // register(s) to be forward substituted */
|
||||
ID *retVal; // function return value
|
||||
|
||||
/* Initialize expression stack */
|
||||
@@ -714,7 +726,7 @@ void Function::findExps()
|
||||
if ((picode->type == HIGH_LEVEL) && (picode->invalid == FALSE))
|
||||
{
|
||||
numHlIcodes++;
|
||||
if (picode->du1.numRegsDef == 1) /* byte/word regs */
|
||||
if (picode->du1.numRegsDef == 1) /* uint8_t/uint16_t regs */
|
||||
{
|
||||
/* Check for only one use of this register. If this is
|
||||
* the last definition of the register in this BB, check
|
||||
@@ -959,7 +971,7 @@ void Function::findExps()
|
||||
res = insertSubTreeLongReg (exp,
|
||||
&ticode->ic.hl.exp.v,
|
||||
localId.newLongReg ( retVal->type, retVal->id.longId.h,
|
||||
retVal->id.longId.l, picode));
|
||||
retVal->id.longId.l, picode));
|
||||
if (res) /* was substituted */
|
||||
{
|
||||
picode->invalidate();
|
||||
@@ -992,7 +1004,7 @@ void Function::findExps()
|
||||
if ((picode->ic.hl.opcode == HLI_CALL) &&
|
||||
! (picode->ic.hl.call.proc->flg & REG_ARGS))
|
||||
{ Function * pp;
|
||||
Int cb, numArgs;
|
||||
int cb, numArgs;
|
||||
boolT res;
|
||||
|
||||
pp = picode->ic.hl.call.proc;
|
||||
@@ -1060,7 +1072,7 @@ void Function::findExps()
|
||||
void Function::dataFlow(std::bitset<32> &liveOut)
|
||||
{
|
||||
boolT isAx, isBx, isCx, isDx;
|
||||
Int idx;
|
||||
int idx;
|
||||
|
||||
/* Remove references to register variables */
|
||||
if (flg & SI_REGVAR)
|
||||
@@ -1086,7 +1098,7 @@ void Function::dataFlow(std::bitset<32> &liveOut)
|
||||
idx = localId.newLongReg(TYPE_LONG_SIGN, rDX, rAX, Icode.begin()/*0*/);
|
||||
localId.propLongId (rAX, rDX, "\0");
|
||||
}
|
||||
else if (isAx || isBx || isCx || isDx) /* word */
|
||||
else if (isAx || isBx || isCx || isDx) /* uint16_t */
|
||||
{
|
||||
retVal.type = TYPE_WORD_SIGN;
|
||||
retVal.loc = REG_FRAME;
|
||||
|
||||
@@ -127,36 +127,36 @@ static const char *szWreg[12] = { "ax", "cx", "dx", "bx", "sp", "bp", "si", "di"
|
||||
static const char *szPtr[2] = { "word ptr ", "byte ptr " };
|
||||
|
||||
|
||||
static void dis1Line (ICODE &icode, Int pass);
|
||||
void dis1LineOp(Int i, boolT fWin, char attr, word *len, Function * pProc);
|
||||
static void formatRM(ostringstream &p, flags32 flg, const LLOperand &pm);
|
||||
static ostringstream &strDst(ostringstream &os, flags32 flg, LLOperand &pm);
|
||||
static void dis1Line (ICODE &icode, int pass);
|
||||
void dis1LineOp(int i, boolT fWin, char attr, uint16_t *len, Function * pProc);
|
||||
static void formatRM(ostringstream &p, uint32_t flg, const LLOperand &pm);
|
||||
static ostringstream &strDst(ostringstream &os, uint32_t flg, LLOperand &pm);
|
||||
static ostringstream &strSrc(ostringstream &os,const LLInst &pc,bool skip_comma=false);
|
||||
|
||||
static char *strHex(dword d);
|
||||
static Int checkScanned(dword pcCur);
|
||||
static char *strHex(uint32_t d);
|
||||
static int checkScanned(uint32_t pcCur);
|
||||
static void setProc(Function * proc);
|
||||
static void dispData(word dataSeg);
|
||||
static void dispData(uint16_t dataSeg);
|
||||
void flops(LLInst &pIcode, std::ostringstream &out);
|
||||
boolT callArg(word off, char *temp); /* Check for procedure name */
|
||||
boolT callArg(uint16_t off, char *temp); /* Check for procedure name */
|
||||
|
||||
static FILE *fp;
|
||||
static CIcodeRec pc;
|
||||
static std::ostringstream buf;
|
||||
static Int cb, j, numIcode, allocIcode, eop;
|
||||
static int cb, j, numIcode, allocIcode, eop;
|
||||
static map<int,int> pl;
|
||||
static dword nextInst;
|
||||
static uint32_t nextInst;
|
||||
static boolT fImpure;
|
||||
static Int lab, prevPass;
|
||||
static int lab, prevPass;
|
||||
static Function * pProc; /* Points to current proc struct */
|
||||
|
||||
struct POSSTACK_ENTRY
|
||||
{
|
||||
Int ic; /* An icode offset */
|
||||
int ic; /* An icode offset */
|
||||
Function * pProc; /* A pointer to a PROCEDURE structure */
|
||||
} ;
|
||||
vector<POSSTACK_ENTRY> posStack; /* position stack */
|
||||
byte iPS; /* Index into the stack */
|
||||
uint8_t iPS; /* Index into the stack */
|
||||
|
||||
//static char cbuf[256]; /* Has to be 256 for wgetstr() to work */
|
||||
|
||||
@@ -174,9 +174,9 @@ byte iPS; /* Index into the stack */
|
||||
* pass == 2 generates output on file .a2
|
||||
* pass == 3 generates output on file .b
|
||||
****************************************************************************/
|
||||
void disassem(Int pass, Function * ppProc)
|
||||
void disassem(int pass, Function * ppProc)
|
||||
{
|
||||
Int i;
|
||||
int i;
|
||||
|
||||
pProc = ppProc; /* Save the passes pProc */
|
||||
if (pass != prevPass)
|
||||
@@ -263,7 +263,7 @@ void disassem(Int pass, Function * ppProc)
|
||||
* i is index into Icode for this proc *
|
||||
* It is assumed that icode i is already scanned *
|
||||
****************************************************************************/
|
||||
static void dis1Line(ICODE &icode_iter, Int pass)
|
||||
static void dis1Line(ICODE &icode_iter, int pass)
|
||||
{
|
||||
ostringstream oper_stream;
|
||||
ostringstream hex_bytes;
|
||||
@@ -298,7 +298,7 @@ static void dis1Line(ICODE &icode_iter, Int pass)
|
||||
nextInst = _IcLL.label;
|
||||
else
|
||||
{
|
||||
cb = (dword) _IcLL.numBytes;
|
||||
cb = (uint32_t) _IcLL.numBytes;
|
||||
nextInst = _IcLL.label + cb;
|
||||
|
||||
/* Output hexa code in program image */
|
||||
@@ -402,7 +402,7 @@ static void dis1Line(ICODE &icode_iter, Int pass)
|
||||
{
|
||||
ICODE *lab=pc.GetIcode(_IcLL.src.op());
|
||||
selectTable(Label);
|
||||
if ((_IcLL.src.op() < (dword)numIcode) && /* Ensure in range */
|
||||
if ((_IcLL.src.op() < (uint32_t)numIcode) && /* Ensure in range */
|
||||
readVal(oper_stream, lab->ic.ll.label, 0))
|
||||
{
|
||||
break; /* Symbolic label. Done */
|
||||
@@ -528,7 +528,7 @@ static void dis1Line(ICODE &icode_iter, Int pass)
|
||||
}
|
||||
else
|
||||
{
|
||||
for (j = _IcLL.label, fImpure = 0; j > 0 && j < (Int)nextInst; j++)
|
||||
for (j = _IcLL.label, fImpure = 0; j > 0 && j < (int)nextInst; j++)
|
||||
{
|
||||
fImpure |= BITMAP(j, BM_DATA);
|
||||
}
|
||||
@@ -604,7 +604,7 @@ static void dis1Line(ICODE &icode_iter, Int pass)
|
||||
/****************************************************************************
|
||||
* formatRM
|
||||
***************************************************************************/
|
||||
static void formatRM(std::ostringstream &p, flags32 flg, const LLOperand &pm)
|
||||
static void formatRM(std::ostringstream &p, uint32_t flg, const LLOperand &pm)
|
||||
{
|
||||
char seg[4];
|
||||
|
||||
@@ -616,7 +616,7 @@ static void formatRM(std::ostringstream &p, flags32 flg, const LLOperand &pm)
|
||||
|
||||
if (pm.regi == 0)
|
||||
{
|
||||
p<<seg<<"["<<strHex((dword)pm.off)<<"]";
|
||||
p<<seg<<"["<<strHex((uint32_t)pm.off)<<"]";
|
||||
}
|
||||
|
||||
else if (pm.regi == (INDEXBASE - 1))
|
||||
@@ -636,11 +636,11 @@ static void formatRM(std::ostringstream &p, flags32 flg, const LLOperand &pm)
|
||||
{
|
||||
if (pm.off < 0)
|
||||
{
|
||||
p <<seg<<"["<<szIndex[pm.regi - INDEXBASE]<<"-"<<strHex((dword)(- pm.off))<<"]";
|
||||
p <<seg<<"["<<szIndex[pm.regi - INDEXBASE]<<"-"<<strHex((uint32_t)(- pm.off))<<"]";
|
||||
}
|
||||
else
|
||||
{
|
||||
p <<seg<<"["<<szIndex[pm.regi - INDEXBASE]<<"+"<<strHex((dword)(pm.off))<<"]";
|
||||
p <<seg<<"["<<szIndex[pm.regi - INDEXBASE]<<"+"<<strHex((uint32_t)(pm.off))<<"]";
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -651,7 +651,7 @@ static void formatRM(std::ostringstream &p, flags32 flg, const LLOperand &pm)
|
||||
/*****************************************************************************
|
||||
* strDst
|
||||
****************************************************************************/
|
||||
static ostringstream & strDst(ostringstream &os,flags32 flg, LLOperand &pm)
|
||||
static ostringstream & strDst(ostringstream &os,uint32_t flg, LLOperand &pm)
|
||||
{
|
||||
/* Immediates to memory require size descriptor */
|
||||
//os << setw(WID_PTR);
|
||||
@@ -685,7 +685,7 @@ static ostringstream &strSrc(ostringstream &os,const LLInst &l_ins,bool skip_com
|
||||
/****************************************************************************
|
||||
* strHex *
|
||||
****************************************************************************/
|
||||
static char *strHex(dword d)
|
||||
static char *strHex(uint32_t d)
|
||||
{
|
||||
static char buf[10];
|
||||
|
||||
@@ -697,7 +697,7 @@ static char *strHex(dword d)
|
||||
/****************************************************************************
|
||||
* interactDis - interactive disassembler *
|
||||
****************************************************************************/
|
||||
void interactDis(Function * initProc, Int initIC)
|
||||
void interactDis(Function * initProc, int initIC)
|
||||
{
|
||||
printf("Sorry - interactive disasassembler option not available for Unix\n");
|
||||
return;
|
||||
@@ -707,7 +707,7 @@ void interactDis(Function * initProc, Int initIC)
|
||||
void flops(LLInst &pIcode,std::ostringstream &out)
|
||||
{
|
||||
char bf[30];
|
||||
byte op = (byte)pIcode.src.op();
|
||||
uint8_t op = (uint8_t)pIcode.src.op();
|
||||
|
||||
/* Note that op is set to the escape number, e.g.
|
||||
esc 0x38 is FILD */
|
||||
@@ -743,7 +743,7 @@ void flops(LLInst &pIcode,std::ostringstream &out)
|
||||
break;
|
||||
|
||||
default:
|
||||
strcpy(bf, "word ptr ");
|
||||
strcpy(bf, "uint16_t ptr ");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,10 +40,10 @@ void fatalError(eErrorId errId, ...)
|
||||
{ va_list args;
|
||||
//#ifdef __UNIX__ /* ultrix */
|
||||
#if 0
|
||||
Int errId;
|
||||
int errId;
|
||||
|
||||
va_start(args);
|
||||
errId = va_arg(args, Int);
|
||||
errId = va_arg(args, int);
|
||||
#else
|
||||
va_start(args, errId);
|
||||
#endif
|
||||
@@ -66,10 +66,10 @@ void reportError(eErrorId errId, ...)
|
||||
{ va_list args;
|
||||
//#ifdef __UNIX__ /* ultrix */
|
||||
#if 0
|
||||
Int errId;
|
||||
int errId;
|
||||
|
||||
va_start(args);
|
||||
errId = va_arg(args, Int);
|
||||
errId = va_arg(args, int);
|
||||
#else /* msdos or windows*/
|
||||
va_start(args, errId);
|
||||
#endif
|
||||
|
||||
@@ -20,25 +20,25 @@
|
||||
#define bool unsigned char
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
#define byte unsigned char
|
||||
#define uint8_t unsigned char
|
||||
#endif
|
||||
|
||||
static int pc; /* Indexes into pat[] */
|
||||
|
||||
/* prototypes */
|
||||
static bool ModRM(byte pat[]); /* Handle the mod/rm byte */
|
||||
static bool TwoWild(byte pat[]); /* Make the next 2 bytes wild */
|
||||
static bool FourWild(byte pat[]); /* Make the next 4 bytes wild */
|
||||
void fixWildCards(byte pat[]); /* Main routine */
|
||||
static bool ModRM(uint8_t pat[]); /* Handle the mod/rm uint8_t */
|
||||
static bool TwoWild(uint8_t pat[]); /* Make the next 2 bytes wild */
|
||||
static bool FourWild(uint8_t pat[]); /* Make the next 4 bytes wild */
|
||||
void fixWildCards(uint8_t pat[]); /* Main routine */
|
||||
|
||||
|
||||
/* Handle the mod/rm case. Returns true if pattern exhausted */
|
||||
static bool ModRM(byte pat[])
|
||||
static bool ModRM(uint8_t pat[])
|
||||
{
|
||||
byte op;
|
||||
uint8_t op;
|
||||
|
||||
/* A standard mod/rm byte follows opcode */
|
||||
op = pat[pc++]; /* The mod/rm byte */
|
||||
/* A standard mod/rm uint8_t follows opcode */
|
||||
op = pat[pc++]; /* The mod/rm uint8_t */
|
||||
if (pc >= PATLEN) return TRUE; /* Skip Mod/RM */
|
||||
switch (op & 0xC0)
|
||||
{
|
||||
@@ -71,7 +71,7 @@ static bool ModRM(byte pat[])
|
||||
|
||||
/* Change the next two bytes to wild cards */
|
||||
static bool
|
||||
TwoWild(byte pat[])
|
||||
TwoWild(uint8_t pat[])
|
||||
{
|
||||
pat[pc++] = WILD;
|
||||
if (pc >= PATLEN) return TRUE; /* Pattern exhausted */
|
||||
@@ -82,7 +82,7 @@ TwoWild(byte pat[])
|
||||
|
||||
/* Change the next four bytes to wild cards */
|
||||
static bool
|
||||
FourWild(byte pat[])
|
||||
FourWild(uint8_t pat[])
|
||||
{
|
||||
TwoWild(pat);
|
||||
return TwoWild(pat);
|
||||
@@ -91,16 +91,16 @@ FourWild(byte pat[])
|
||||
/* Chop from the current point by wiping with zeroes. Can't rely on anything
|
||||
after this point */
|
||||
static void
|
||||
chop(byte pat[])
|
||||
chop(uint8_t pat[])
|
||||
{
|
||||
if (pc >= PATLEN) return; /* Could go negative otherwise */
|
||||
memset(&pat[pc], 0, PATLEN - pc);
|
||||
}
|
||||
|
||||
static bool op0F(byte pat[])
|
||||
static bool op0F(uint8_t pat[])
|
||||
{
|
||||
/* The two byte opcodes */
|
||||
byte op = pat[pc++];
|
||||
/* The two uint8_t opcodes */
|
||||
uint8_t op = pat[pc++];
|
||||
switch (op & 0xF0)
|
||||
{
|
||||
case 0x00: /* 00 - 0F */
|
||||
@@ -115,10 +115,10 @@ static bool op0F(byte pat[])
|
||||
return ModRM(pat);
|
||||
|
||||
case 0x80:
|
||||
pc += 2; /* Word displacement cond jumps */
|
||||
pc += 2; /* uint16_t displacement cond jumps */
|
||||
return FALSE;
|
||||
|
||||
case 0x90: /* Byte set on condition */
|
||||
case 0x90: /* uint8_t set on condition */
|
||||
return ModRM(pat);
|
||||
|
||||
case 0xA0:
|
||||
@@ -168,7 +168,7 @@ static bool op0F(byte pat[])
|
||||
return FALSE;
|
||||
|
||||
default:
|
||||
return FALSE; /* Treat as double byte opcodes */
|
||||
return FALSE; /* Treat as double uint8_t opcodes */
|
||||
|
||||
}
|
||||
|
||||
@@ -183,10 +183,10 @@ static bool op0F(byte pat[])
|
||||
PATLEN bytes are scanned.
|
||||
*/
|
||||
void
|
||||
fixWildCards(byte pat[])
|
||||
fixWildCards(uint8_t pat[])
|
||||
{
|
||||
|
||||
byte op, quad, intArg;
|
||||
uint8_t op, quad, intArg;
|
||||
|
||||
|
||||
pc=0;
|
||||
@@ -195,17 +195,17 @@ fixWildCards(byte pat[])
|
||||
op = pat[pc++];
|
||||
if (pc >= PATLEN) return;
|
||||
|
||||
quad = (byte) (op & 0xC0); /* Quadrant of the opcode map */
|
||||
quad = (uint8_t) (op & 0xC0); /* Quadrant of the opcode map */
|
||||
if (quad == 0)
|
||||
{
|
||||
/* Arithmetic group 00-3F */
|
||||
|
||||
if ((op & 0xE7) == 0x26) /* First check for the odds */
|
||||
{
|
||||
/* Segment prefix: treat as 1 byte opcode */
|
||||
/* Segment prefix: treat as 1 uint8_t opcode */
|
||||
continue;
|
||||
}
|
||||
if (op == 0x0F) /* 386 2 byte opcodes */
|
||||
if (op == 0x0F) /* 386 2 uint8_t opcodes */
|
||||
{
|
||||
if (op0F(pat)) return;
|
||||
continue;
|
||||
@@ -216,20 +216,20 @@ fixWildCards(byte pat[])
|
||||
/* All these are constant. Work out the instr length */
|
||||
if (op & 2)
|
||||
{
|
||||
/* Push, pop, other 1 byte opcodes */
|
||||
/* Push, pop, other 1 uint8_t opcodes */
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (op & 1)
|
||||
{
|
||||
/* Word immediate operands */
|
||||
/* uint16_t immediate operands */
|
||||
pc += 2;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Byte immediate operands */
|
||||
/* uint8_t immediate operands */
|
||||
pc++;
|
||||
continue;
|
||||
}
|
||||
@@ -255,7 +255,7 @@ fixWildCards(byte pat[])
|
||||
/* 0x60 - 0x70 */
|
||||
if (op & 0x10)
|
||||
{
|
||||
/* 70-7F 2 byte jump opcodes */
|
||||
/* 70-7F 2 uint8_t jump opcodes */
|
||||
pc++;
|
||||
continue;
|
||||
}
|
||||
@@ -282,11 +282,11 @@ fixWildCards(byte pat[])
|
||||
if (TwoWild(pat)) return;
|
||||
continue;
|
||||
|
||||
case 0x68: /* Push byte */
|
||||
case 0x6A: /* Push byte */
|
||||
case 0x68: /* Push uint8_t */
|
||||
case 0x6A: /* Push uint8_t */
|
||||
case 0x6D: /* insb port */
|
||||
case 0x6F: /* outsb port */
|
||||
/* 2 byte instr, no wilds */
|
||||
/* 2 uint8_t instr, no wilds */
|
||||
pc++;
|
||||
continue;
|
||||
|
||||
@@ -300,14 +300,14 @@ fixWildCards(byte pat[])
|
||||
switch (op & 0xF0)
|
||||
{
|
||||
case 0x80: /* 80 - 8F */
|
||||
/* All have a mod/rm byte */
|
||||
/* All have a mod/rm uint8_t */
|
||||
if (ModRM(pat)) return;
|
||||
/* These also have immediate values */
|
||||
switch (op)
|
||||
{
|
||||
case 0x80:
|
||||
case 0x83:
|
||||
/* One byte immediate */
|
||||
/* One uint8_t immediate */
|
||||
pc++;
|
||||
continue;
|
||||
|
||||
@@ -326,7 +326,7 @@ fixWildCards(byte pat[])
|
||||
if (FourWild(pat)) return;
|
||||
continue;
|
||||
}
|
||||
/* All others are 1 byte opcodes */
|
||||
/* All others are 1 uint8_t opcodes */
|
||||
continue;
|
||||
case 0xA0: /* A0 - AF */
|
||||
if ((op & 0x0C) == 0)
|
||||
@@ -337,7 +337,7 @@ fixWildCards(byte pat[])
|
||||
}
|
||||
else if ((op & 0xFE) == 0xA8)
|
||||
{
|
||||
/* test al,#byte or test ax,#word */
|
||||
/* test al,#uint8_t or test ax,#uint16_t */
|
||||
if (op & 1) pc += 2;
|
||||
else pc += 1;
|
||||
continue;
|
||||
@@ -366,10 +366,10 @@ fixWildCards(byte pat[])
|
||||
/* In the last quadrant of the op code table */
|
||||
switch (op)
|
||||
{
|
||||
case 0xC0: /* 386: Rotate group 2 ModRM, byte, #byte */
|
||||
case 0xC1: /* 386: Rotate group 2 ModRM, word, #byte */
|
||||
case 0xC0: /* 386: Rotate group 2 ModRM, uint8_t, #uint8_t */
|
||||
case 0xC1: /* 386: Rotate group 2 ModRM, uint16_t, #uint8_t */
|
||||
if (ModRM(pat)) return;
|
||||
/* Byte immediate value follows ModRM */
|
||||
/* uint8_t immediate value follows ModRM */
|
||||
pc++;
|
||||
continue;
|
||||
|
||||
@@ -390,27 +390,27 @@ fixWildCards(byte pat[])
|
||||
|
||||
case 0xC6: /* Mov ModRM, #nn */
|
||||
if (ModRM(pat)) return;
|
||||
/* Byte immediate value follows ModRM */
|
||||
/* uint8_t immediate value follows ModRM */
|
||||
pc++;
|
||||
continue;
|
||||
case 0xC7: /* Mov ModRM, #nnnn */
|
||||
if (ModRM(pat)) return;
|
||||
/* Word immediate value follows ModRM */
|
||||
/* uint16_t immediate value follows ModRM */
|
||||
/* Immediate 16 bit values might be constant, but also
|
||||
might be relocatable. For now, make them wild */
|
||||
if (TwoWild(pat)) return;
|
||||
continue;
|
||||
|
||||
case 0xC8: /* Enter Iw, Ib */
|
||||
pc += 3; /* Constant word, byte */
|
||||
pc += 3; /* Constant uint16_t, uint8_t */
|
||||
continue;
|
||||
case 0xC9: /* Leave */
|
||||
continue;
|
||||
|
||||
case 0xCC: /* Int 3 */
|
||||
case 0xCC: /* int 3 */
|
||||
continue;
|
||||
|
||||
case 0xCD: /* Int nn */
|
||||
case 0xCD: /* int nn */
|
||||
intArg = pat[pc++];
|
||||
if ((intArg >= 0x34) && (intArg <= 0x3B))
|
||||
{
|
||||
@@ -425,10 +425,10 @@ fixWildCards(byte pat[])
|
||||
case 0xCF: /* Iret */
|
||||
continue;
|
||||
|
||||
case 0xD0: /* Group 2 rotate, byte, 1 bit */
|
||||
case 0xD1: /* Group 2 rotate, word, 1 bit */
|
||||
case 0xD2: /* Group 2 rotate, byte, CL bits */
|
||||
case 0xD3: /* Group 2 rotate, word, CL bits */
|
||||
case 0xD0: /* Group 2 rotate, uint8_t, 1 bit */
|
||||
case 0xD1: /* Group 2 rotate, uint16_t, 1 bit */
|
||||
case 0xD2: /* Group 2 rotate, uint8_t, CL bits */
|
||||
case 0xD3: /* Group 2 rotate, uint16_t, CL bits */
|
||||
if (ModRM(pat)) return;
|
||||
continue;
|
||||
|
||||
@@ -500,8 +500,8 @@ fixWildCards(byte pat[])
|
||||
case 0xFD: /* Std */
|
||||
continue;
|
||||
|
||||
case 0xF6: /* Group 3 byte test/not/mul/div */
|
||||
case 0xF7: /* Group 3 word test/not/mul/div */
|
||||
case 0xF6: /* Group 3 uint8_t test/not/mul/div */
|
||||
case 0xF7: /* Group 3 uint16_t test/not/mul/div */
|
||||
case 0xFE: /* Inc/Dec group 4 */
|
||||
if (ModRM(pat)) return;
|
||||
continue;
|
||||
@@ -511,7 +511,7 @@ fixWildCards(byte pat[])
|
||||
if (ModRM(pat)) return;
|
||||
continue;
|
||||
|
||||
default: /* Rest are single byte opcodes */
|
||||
default: /* Rest are single uint8_t opcodes */
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
128
src/frontend.cpp
128
src/frontend.cpp
@@ -11,40 +11,40 @@
|
||||
#include <malloc.h> /* For malloc, free, realloc */
|
||||
|
||||
typedef struct { /* PSP structure */
|
||||
word int20h; /* interrupt 20h */
|
||||
word eof; /* segment, end of allocation block */
|
||||
byte res1; /* reserved */
|
||||
byte dosDisp[5]; /* far call to DOS function dispatcher */
|
||||
byte int22h[4]; /* vector for terminate routine */
|
||||
byte int23h[4]; /* vector for ctrl+break routine */
|
||||
byte int24h[4]; /* vector for error routine */
|
||||
byte res2[22]; /* reserved */
|
||||
word segEnv; /* segment address of environment block */
|
||||
byte res3[34]; /* reserved */
|
||||
byte int21h[6]; /* opcode for int21h and far return */
|
||||
byte res4[6]; /* reserved */
|
||||
byte fcb1[16]; /* default file control block 1 */
|
||||
byte fcb2[16]; /* default file control block 2 */
|
||||
byte res5[4]; /* reserved */
|
||||
byte cmdTail[0x80]; /* command tail and disk transfer area */
|
||||
uint16_t int20h; /* interrupt 20h */
|
||||
uint16_t eof; /* segment, end of allocation block */
|
||||
uint8_t res1; /* reserved */
|
||||
uint8_t dosDisp[5]; /* far call to DOS function dispatcher */
|
||||
uint8_t int22h[4]; /* vector for terminate routine */
|
||||
uint8_t int23h[4]; /* vector for ctrl+break routine */
|
||||
uint8_t int24h[4]; /* vector for error routine */
|
||||
uint8_t res2[22]; /* reserved */
|
||||
uint16_t segEnv; /* segment address of environment block */
|
||||
uint8_t res3[34]; /* reserved */
|
||||
uint8_t int21h[6]; /* opcode for int21h and far return */
|
||||
uint8_t res4[6]; /* reserved */
|
||||
uint8_t fcb1[16]; /* default file control block 1 */
|
||||
uint8_t fcb2[16]; /* default file control block 2 */
|
||||
uint8_t res5[4]; /* reserved */
|
||||
uint8_t cmdTail[0x80]; /* command tail and disk transfer area */
|
||||
} PSP;
|
||||
|
||||
static struct { /* EXE file header */
|
||||
byte sigLo; /* .EXE signature: 0x4D 0x5A */
|
||||
byte sigHi;
|
||||
word lastPageSize; /* Size of the last page */
|
||||
word numPages; /* Number of pages in the file */
|
||||
word numReloc; /* Number of relocation items */
|
||||
word numParaHeader; /* # of paragraphs in the header */
|
||||
word minAlloc; /* Minimum number of paragraphs */
|
||||
word maxAlloc; /* Maximum number of paragraphs */
|
||||
word initSS; /* Segment displacement of stack */
|
||||
word initSP; /* Contents of SP at entry */
|
||||
word checkSum; /* Complemented checksum */
|
||||
word initIP; /* Contents of IP at entry */
|
||||
word initCS; /* Segment displacement of code */
|
||||
word relocTabOffset; /* Relocation table offset */
|
||||
word overlayNum; /* Overlay number */
|
||||
uint8_t sigLo; /* .EXE signature: 0x4D 0x5A */
|
||||
uint8_t sigHi;
|
||||
uint16_t lastPageSize; /* Size of the last page */
|
||||
uint16_t numPages; /* Number of pages in the file */
|
||||
uint16_t numReloc; /* Number of relocation items */
|
||||
uint16_t numParaHeader; /* # of paragraphs in the header */
|
||||
uint16_t minAlloc; /* Minimum number of paragraphs */
|
||||
uint16_t maxAlloc; /* Maximum number of paragraphs */
|
||||
uint16_t initSS; /* Segment displacement of stack */
|
||||
uint16_t initSP; /* Contents of SP at entry */
|
||||
uint16_t checkSum; /* Complemented checksum */
|
||||
uint16_t initIP; /* Contents of IP at entry */
|
||||
uint16_t initCS; /* Segment displacement of code */
|
||||
uint16_t relocTabOffset; /* Relocation table offset */
|
||||
uint16_t overlayNum; /* Overlay number */
|
||||
} header;
|
||||
|
||||
#define EXE_RELOCATION 0x10 /* EXE images rellocated to above PSP */
|
||||
@@ -101,7 +101,7 @@ void FrontEnd (char *filename, CALL_GRAPH * *pcallGraph)
|
||||
***************************************************************************/
|
||||
static void displayLoadInfo(void)
|
||||
{
|
||||
Int i;
|
||||
int i;
|
||||
|
||||
printf("File type is %s\n", (prog.fCOM)?"COM":"EXE");
|
||||
if (! prog.fCOM) {
|
||||
@@ -132,10 +132,10 @@ static void displayLoadInfo(void)
|
||||
/*****************************************************************************
|
||||
* fill - Fills line for displayMemMap()
|
||||
****************************************************************************/
|
||||
static void fill(Int ip, char *bf)
|
||||
static void fill(int ip, char *bf)
|
||||
{
|
||||
static byte type[4] = {'.', 'd', 'c', 'x'};
|
||||
byte i;
|
||||
static uint8_t type[4] = {'.', 'd', 'c', 'x'};
|
||||
uint8_t i;
|
||||
|
||||
for (i = 0; i < 16; i++, ip++)
|
||||
{
|
||||
@@ -153,8 +153,8 @@ static void fill(Int ip, char *bf)
|
||||
static void displayMemMap(void)
|
||||
{
|
||||
char c, b1[33], b2[33], b3[33];
|
||||
byte i;
|
||||
Int ip = 0;
|
||||
uint8_t i;
|
||||
int ip = 0;
|
||||
|
||||
printf("\nMemory Map\n");
|
||||
while (ip < prog.cbImage)
|
||||
@@ -189,8 +189,8 @@ static void displayMemMap(void)
|
||||
static void LoadImage(char *filename)
|
||||
{
|
||||
FILE *fp;
|
||||
Int i, cb;
|
||||
byte buf[4];
|
||||
int i, cb;
|
||||
uint8_t buf[4];
|
||||
|
||||
/* Open the input file */
|
||||
if ((fp = fopen(filename, "rb")) == NULL)
|
||||
@@ -219,11 +219,11 @@ static void LoadImage(char *filename)
|
||||
}
|
||||
|
||||
/* Calculate the load module size.
|
||||
* This is the number of pages in the file
|
||||
* less the length of the header and reloc table
|
||||
* less the number of bytes unused on last page
|
||||
*/
|
||||
cb = (dword)LH(&header.numPages) * 512 - (dword)LH(&header.numParaHeader) * 16;
|
||||
* This is the number of pages in the file
|
||||
* less the length of the header and reloc table
|
||||
* less the number of bytes unused on last page
|
||||
*/
|
||||
cb = (uint32_t)LH(&header.numPages) * 512 - (uint32_t)LH(&header.numParaHeader) * 16;
|
||||
if (header.lastPageSize)
|
||||
{
|
||||
cb -= 512 - LH(&header.lastPageSize);
|
||||
@@ -237,16 +237,16 @@ static void LoadImage(char *filename)
|
||||
* to have to load DS from a constant so it'll be pretty
|
||||
* obvious.
|
||||
*/
|
||||
prog.initCS = (int16)LH(&header.initCS) + EXE_RELOCATION;
|
||||
prog.initIP = (int16)LH(&header.initIP);
|
||||
prog.initSS = (int16)LH(&header.initSS) + EXE_RELOCATION;
|
||||
prog.initSP = (int16)LH(&header.initSP);
|
||||
prog.cReloc = (int16)LH(&header.numReloc);
|
||||
prog.initCS = (int16_t)LH(&header.initCS) + EXE_RELOCATION;
|
||||
prog.initIP = (int16_t)LH(&header.initIP);
|
||||
prog.initSS = (int16_t)LH(&header.initSS) + EXE_RELOCATION;
|
||||
prog.initSP = (int16_t)LH(&header.initSP);
|
||||
prog.cReloc = (int16_t)LH(&header.numReloc);
|
||||
|
||||
/* Allocate the relocation table */
|
||||
if (prog.cReloc)
|
||||
{
|
||||
prog.relocTable = new dword [prog.cReloc];
|
||||
prog.relocTable = new uint32_t [prog.cReloc];
|
||||
fseek(fp, LH(&header.relocTabOffset), SEEK_SET);
|
||||
|
||||
/* Read in seg:offset pairs and convert to Image ptrs */
|
||||
@@ -254,11 +254,11 @@ static void LoadImage(char *filename)
|
||||
{
|
||||
fread(buf, 1, 4, fp);
|
||||
prog.relocTable[i] = LH(buf) +
|
||||
(((Int)LH(buf+2) + EXE_RELOCATION)<<4);
|
||||
(((int)LH(buf+2) + EXE_RELOCATION)<<4);
|
||||
}
|
||||
}
|
||||
/* Seek to start of image */
|
||||
fseek(fp, (Int)LH(&header.numParaHeader) * 16, SEEK_SET);
|
||||
fseek(fp, (int)LH(&header.numParaHeader) * 16, SEEK_SET);
|
||||
}
|
||||
else
|
||||
{ /* COM file
|
||||
@@ -282,8 +282,8 @@ static void LoadImage(char *filename)
|
||||
|
||||
/* Allocate a block of memory for the program. */
|
||||
prog.cbImage = cb + sizeof(PSP);
|
||||
prog.Image = new byte [prog.cbImage];
|
||||
prog.Image[0] = 0xCD; /* Fill in PSP Int 20h location */
|
||||
prog.Image = new uint8_t [prog.cbImage];
|
||||
prog.Image[0] = 0xCD; /* Fill in PSP int 20h location */
|
||||
prog.Image[1] = 0x20; /* for termination checking */
|
||||
|
||||
/* Read in the image past where a PSP would go */
|
||||
@@ -294,14 +294,14 @@ static void LoadImage(char *filename)
|
||||
fatalError(CANNOT_READ, filename);
|
||||
}
|
||||
#endif
|
||||
if (cb != (Int)fread(prog.Image + sizeof(PSP), 1, (size_t)cb, fp))
|
||||
if (cb != (int)fread(prog.Image + sizeof(PSP), 1, (size_t)cb, fp))
|
||||
{
|
||||
fatalError(CANNOT_READ, filename);
|
||||
}
|
||||
|
||||
/* Set up memory map */
|
||||
cb = (prog.cbImage + 3) / 4;
|
||||
prog.map = (byte *)malloc(cb);
|
||||
prog.map = (uint8_t *)malloc(cb);
|
||||
memset(prog.map, BM_UNKNOWN, (size_t)cb);
|
||||
|
||||
/* Relocate segment constants */
|
||||
@@ -309,10 +309,10 @@ static void LoadImage(char *filename)
|
||||
{
|
||||
for (i = 0; i < prog.cReloc; i++)
|
||||
{
|
||||
byte *p = &prog.Image[prog.relocTable[i]];
|
||||
word w = (word)LH(p) + EXE_RELOCATION;
|
||||
*p++ = (byte)(w & 0x00FF);
|
||||
*p = (byte)((w & 0xFF00) >> 8);
|
||||
uint8_t *p = &prog.Image[prog.relocTable[i]];
|
||||
uint16_t w = (uint16_t)LH(p) + EXE_RELOCATION;
|
||||
*p++ = (uint8_t)(w & 0x00FF);
|
||||
*p = (uint8_t)((w & 0xFF00) >> 8);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -323,14 +323,14 @@ static void LoadImage(char *filename)
|
||||
/*****************************************************************************
|
||||
* allocMem - malloc with failure test
|
||||
****************************************************************************/
|
||||
void *allocMem(Int cb)
|
||||
void *allocMem(int cb)
|
||||
{
|
||||
byte *p;
|
||||
uint8_t *p;
|
||||
|
||||
//printf("Attempt to allocMem %5ld bytes\n", cb);
|
||||
|
||||
if (! (p = (byte*)malloc((size_t)cb)))
|
||||
/* if (! (p = (byte*)calloc((size_t)cb, 1))) */
|
||||
if (! (p = (uint8_t*)malloc((size_t)cb)))
|
||||
/* if (! (p = (uint8_t*)calloc((size_t)cb, 1))) */
|
||||
{
|
||||
fatalError(MALLOC_FAILED, cb);
|
||||
}
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
#endif
|
||||
#include "graph.h"
|
||||
|
||||
//static BB * rmJMP(Function * pProc, Int marker, BB * pBB);
|
||||
//static BB * rmJMP(Function * pProc, int marker, BB * pBB);
|
||||
static void mergeFallThrough(Function * pProc, BB * pBB);
|
||||
static void dfsNumbering(BB * pBB, std::vector<BB*> &dfsLast, Int *first, Int *last);
|
||||
static void dfsNumbering(BB * pBB, std::vector<BB*> &dfsLast, int *first, int *last);
|
||||
|
||||
/*****************************************************************************
|
||||
* createCFG - Create the basic control flow graph
|
||||
@@ -32,8 +32,8 @@ void Function::createCFG()
|
||||
* 5) Repeated string instructions
|
||||
* 6) End of procedure
|
||||
*/
|
||||
Int i;
|
||||
Int ip, start;
|
||||
int i;
|
||||
int ip, start;
|
||||
BB * psBB;
|
||||
BB * pBB;
|
||||
iICODE pIcode = Icode.begin();
|
||||
@@ -63,7 +63,7 @@ void Function::createCFG()
|
||||
pBB = BB::Create(start, ip, TWO_BRANCH, 2, this);
|
||||
CondJumps:
|
||||
start = ip + 1;
|
||||
pBB->edges[0].ip = (dword)start;
|
||||
pBB->edges[0].ip = (uint32_t)start;
|
||||
/* This is for jumps off into nowhere */
|
||||
if (pIcode->ic.ll.flg & NO_LABEL)
|
||||
{
|
||||
@@ -105,7 +105,7 @@ CondJumps:
|
||||
pBB = BB::Create(start, ip, CALL_NODE, i, this);
|
||||
start = ip + 1;
|
||||
if (i)
|
||||
pBB->edges[0].ip = (dword)start;
|
||||
pBB->edges[0].ip = (uint32_t)start;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -130,14 +130,14 @@ CondJumps:
|
||||
{
|
||||
pBB = BB::Create(start, ip, FALL_NODE, 1, this);
|
||||
start = ip + 1;
|
||||
pBB->edges[0].ip = (dword)start;
|
||||
pBB->edges[0].ip = (uint32_t)start;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
std::vector<BB *>::iterator iter=heldBBs.begin();
|
||||
auto iter=heldBBs.begin();
|
||||
/* Convert list of BBs into a graph */
|
||||
for (; iter!=heldBBs.end(); ++iter)
|
||||
{
|
||||
@@ -169,7 +169,7 @@ void Function::markImpure()
|
||||
if ( not icod.isLlFlag(SYM_USE | SYM_DEF))
|
||||
continue;
|
||||
psym = &symtab[icod.ic.ll.caseTbl.numEntries];
|
||||
for (int c = (Int)psym->label; c < (Int)psym->label+psym->size; c++)
|
||||
for (int c = (int)psym->label; c < (int)psym->label+psym->size; c++)
|
||||
{
|
||||
if (BITMAP(c, BM_CODE))
|
||||
{
|
||||
@@ -204,7 +204,7 @@ void Function::freeCFG()
|
||||
void Function::compressCFG()
|
||||
{
|
||||
BB * pBB, *pNxt;
|
||||
Int ip, first=0, last, i;
|
||||
int ip, first=0, last, i;
|
||||
|
||||
/* First pass over BB list removes redundant jumps of the form
|
||||
* (Un)Conditional -> Unconditional jump */
|
||||
@@ -223,8 +223,8 @@ void Function::compressCFG()
|
||||
{
|
||||
pBB->edges[i].BBptr = pNxt;
|
||||
assert(pBB->back().loc_ip==ip);
|
||||
pBB->back().SetImmediateOp((dword)pNxt->begin());
|
||||
//Icode[ip].SetImmediateOp((dword)pNxt->begin());
|
||||
pBB->back().SetImmediateOp((uint32_t)pNxt->begin());
|
||||
//Icode[ip].SetImmediateOp((uint32_t)pNxt->begin());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -270,7 +270,7 @@ void Function::compressCFG()
|
||||
/****************************************************************************
|
||||
* rmJMP - If BB addressed is just a JMP it is replaced with its target
|
||||
***************************************************************************/
|
||||
BB *BB::rmJMP(Int marker, BB * pBB)
|
||||
BB *BB::rmJMP(int marker, BB * pBB)
|
||||
{
|
||||
marker += DFS_JMP;
|
||||
|
||||
@@ -323,7 +323,7 @@ BB *BB::rmJMP(Int marker, BB * pBB)
|
||||
void BB::mergeFallThrough( CIcodeRec &Icode)
|
||||
{
|
||||
BB * pChild;
|
||||
Int i;
|
||||
int i;
|
||||
|
||||
if (!this)
|
||||
{
|
||||
@@ -374,7 +374,7 @@ void BB::mergeFallThrough( CIcodeRec &Icode)
|
||||
* dfsNumbering - Numbers nodes during first and last visits and determine
|
||||
* in-edges
|
||||
****************************************************************************/
|
||||
void BB::dfsNumbering(std::vector<BB *> &dfsLast, Int *first, Int *last)
|
||||
void BB::dfsNumbering(std::vector<BB *> &dfsLast, int *first, int *last)
|
||||
{
|
||||
BB * pChild;
|
||||
traversed = DFS_NUM;
|
||||
|
||||
@@ -13,11 +13,11 @@ using namespace std;
|
||||
#define ICODE_DELTA 25
|
||||
|
||||
/* Masks off bits set by duReg[] */
|
||||
dword maskDuReg[] = { 0x00,
|
||||
0xFEEFFE, 0xFDDFFD, 0xFBB00B, 0xF77007, /* word regs */
|
||||
uint32_t maskDuReg[] = { 0x00,
|
||||
0xFEEFFE, 0xFDDFFD, 0xFBB00B, 0xF77007, /* uint16_t regs */
|
||||
0xFFFFEF, 0xFFFFDF, 0xFFFFBF, 0xFFFF7F,
|
||||
0xFFFEFF, 0xFFFDFF, 0xFFFBFF, 0xFFF7FF, /* seg regs */
|
||||
0xFFEFFF, 0xFFDFFF, 0xFFBFFF, 0xFF7FFF, /* byte regs */
|
||||
0xFFEFFF, 0xFFDFFF, 0xFFBFFF, 0xFF7FFF, /* uint8_t regs */
|
||||
0xFEFFFF, 0xFDFFFF, 0xFBFFFF, 0xF7FFFF,
|
||||
0xEFFFFF, /* tmp reg */
|
||||
0xFFFFB7, 0xFFFF77, 0xFFFF9F, 0xFFFF5F, /* index regs */
|
||||
@@ -87,9 +87,9 @@ void ICODE ::invalidate()
|
||||
* If all registers
|
||||
* of this instruction are unused, the instruction is invalidated (ie. removed)
|
||||
*/
|
||||
bool ICODE::removeDefRegi (byte regi, Int thisDefIdx, LOCAL_ID *locId)
|
||||
bool ICODE::removeDefRegi (uint8_t regi, int thisDefIdx, LOCAL_ID *locId)
|
||||
{
|
||||
Int numDefs;
|
||||
int numDefs;
|
||||
|
||||
numDefs = du1.numRegsDef;
|
||||
// if (numDefs == thisDefIdx)
|
||||
@@ -130,11 +130,11 @@ bool ICODE::removeDefRegi (byte regi, Int thisDefIdx, LOCAL_ID *locId)
|
||||
* Note: this process should be done before data flow analysis, which
|
||||
* refines the HIGH_LEVEL icodes. */
|
||||
void Function::highLevelGen()
|
||||
{ Int i, /* idx into icode array */
|
||||
{ int i, /* idx into icode array */
|
||||
numIcode; /* number of icode instructions */
|
||||
iICODE pIcode; /* ptr to current icode node */
|
||||
COND_EXPR *lhs, *rhs; /* left- and right-hand side of expression */
|
||||
flags32 flg; /* icode flags */
|
||||
uint32_t flg; /* icode flags */
|
||||
|
||||
numIcode = Icode.size();
|
||||
for (iICODE i = Icode.begin(); i!=Icode.end() ; ++i)
|
||||
@@ -257,7 +257,8 @@ void Function::highLevelGen()
|
||||
case iRETF: pIcode->setUnary(HLI_RET, NULL);
|
||||
break;
|
||||
|
||||
case iSHL: rhs = COND_EXPR::boolOp (lhs, rhs, SHL);
|
||||
case iSHL:
|
||||
rhs = COND_EXPR::boolOp (lhs, rhs, SHL);
|
||||
pIcode->setAsgn(lhs, rhs);
|
||||
break;
|
||||
|
||||
@@ -332,9 +333,9 @@ COND_EXPR *COND_EXPR::inverse ()
|
||||
|
||||
/* Returns the string that represents the procedure call of tproc (ie. with
|
||||
* actual parameters) */
|
||||
std::string writeCall (Function * tproc, STKFRAME * args, Function * pproc, Int *numLoc)
|
||||
std::string writeCall (Function * tproc, STKFRAME * args, Function * pproc, int *numLoc)
|
||||
{
|
||||
Int i; /* counter of # arguments */
|
||||
int i; /* counter of # arguments */
|
||||
string condExp;
|
||||
ostringstream s;
|
||||
s<<tproc->name<<" (";
|
||||
@@ -350,7 +351,7 @@ std::string writeCall (Function * tproc, STKFRAME * args, Function * pproc, Int
|
||||
|
||||
|
||||
/* Displays the output of a HLI_JCOND icode. */
|
||||
char *writeJcond (HLTYPE h, Function * pProc, Int *numLoc)
|
||||
char *writeJcond (HLTYPE h, Function * pProc, int *numLoc)
|
||||
{
|
||||
memset (buf, ' ', sizeof(buf));
|
||||
buf[0] = '\0';
|
||||
@@ -368,7 +369,7 @@ char *writeJcond (HLTYPE h, Function * pProc, Int *numLoc)
|
||||
/* Displays the inverse output of a HLI_JCOND icode. This is used in the case
|
||||
* when the THEN clause of an if..then..else is empty. The clause is
|
||||
* negated and the ELSE clause is used instead. */
|
||||
char *writeJcondInv (HLTYPE h, Function * pProc, Int *numLoc)
|
||||
char *writeJcondInv (HLTYPE h, Function * pProc, int *numLoc)
|
||||
{
|
||||
memset (buf, ' ', sizeof(buf));
|
||||
buf[0] = '\0';
|
||||
@@ -379,7 +380,7 @@ char *writeJcondInv (HLTYPE h, Function * pProc, Int *numLoc)
|
||||
return (buf);
|
||||
}
|
||||
|
||||
string AssignType::writeOut(Function *pProc, Int *numLoc)
|
||||
string AssignType::writeOut(Function *pProc, int *numLoc)
|
||||
{
|
||||
ostringstream ostr;
|
||||
ostr << walkCondExpr (lhs, pProc, numLoc);
|
||||
@@ -388,14 +389,14 @@ string AssignType::writeOut(Function *pProc, Int *numLoc)
|
||||
ostr << ";\n";
|
||||
return ostr.str();
|
||||
}
|
||||
string CallType::writeOut(Function *pProc, Int *numLoc)
|
||||
string CallType::writeOut(Function *pProc, int *numLoc)
|
||||
{
|
||||
ostringstream ostr;
|
||||
ostr << writeCall (proc, args, pProc,numLoc);
|
||||
ostr << ";\n";
|
||||
return ostr.str();
|
||||
}
|
||||
string ExpType::writeOut(Function *pProc, Int *numLoc)
|
||||
string ExpType::writeOut(Function *pProc, int *numLoc)
|
||||
{
|
||||
return walkCondExpr (v, pProc, numLoc);
|
||||
}
|
||||
@@ -404,7 +405,7 @@ string ExpType::writeOut(Function *pProc, Int *numLoc)
|
||||
* Note: this routine does not output the contens of HLI_JCOND icodes. This is
|
||||
* done in a separate routine to be able to support the removal of
|
||||
* empty THEN clauses on an if..then..else. */
|
||||
string HLTYPE::write1HlIcode (Function * pProc, Int *numLoc)
|
||||
string HLTYPE::write1HlIcode (Function * pProc, int *numLoc)
|
||||
{
|
||||
string e;
|
||||
ostringstream ostr;
|
||||
@@ -435,7 +436,7 @@ string HLTYPE::write1HlIcode (Function * pProc, Int *numLoc)
|
||||
}
|
||||
|
||||
|
||||
Int power2 (Int i)
|
||||
int power2 (int i)
|
||||
/* Returns the value of 2 to the power of i */
|
||||
{
|
||||
if (i == 0)
|
||||
@@ -446,10 +447,10 @@ Int power2 (Int i)
|
||||
|
||||
/* Writes the registers/stack variables that are used and defined by this
|
||||
* instruction. */
|
||||
void ICODE::writeDU(Int idx)
|
||||
void ICODE::writeDU(int idx)
|
||||
{
|
||||
static char buf[100];
|
||||
Int i, j;
|
||||
int i, j;
|
||||
|
||||
memset (buf, ' ', sizeof(buf));
|
||||
buf[0] = '\0';
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <memory.h>
|
||||
|
||||
#include "dcc.h"
|
||||
#include "types.h" // Common types like byte, etc
|
||||
#include "types.h" // Common types like uint8_t, etc
|
||||
#include "ast.h" // Some icode types depend on these
|
||||
#include "icode.h"
|
||||
|
||||
@@ -38,18 +38,18 @@ 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 */
|
||||
bool CIcodeRec::labelSrch(dword target, dword &pIndex)
|
||||
bool CIcodeRec::labelSrch(uint32_t target, uint32_t &pIndex)
|
||||
{
|
||||
Int i;
|
||||
int i;
|
||||
iICODE location=labelSrch(target);
|
||||
if(end()==location)
|
||||
return false;
|
||||
pIndex=location->loc_ip;
|
||||
return true;
|
||||
}
|
||||
CIcodeRec::iterator CIcodeRec::labelSrch(dword target)
|
||||
CIcodeRec::iterator CIcodeRec::labelSrch(uint32_t target)
|
||||
{
|
||||
Int i;
|
||||
int i;
|
||||
return find_if(begin(),end(),[target](ICODE &l) -> bool {return l.ic.ll.label==target;});
|
||||
}
|
||||
ICODE * CIcodeRec::GetIcode(int ip)
|
||||
@@ -61,14 +61,14 @@ ICODE * CIcodeRec::GetIcode(int ip)
|
||||
}
|
||||
|
||||
extern char *indent(int level);
|
||||
extern Int getNextLabel();
|
||||
extern int getNextLabel();
|
||||
extern bundle cCode;
|
||||
/* Checks the given icode to determine whether it has a label associated
|
||||
* to it. If so, a goto is emitted to this label; otherwise, a new label
|
||||
* is created and a goto is also emitted.
|
||||
* Note: this procedure is to be used when the label is to be backpatched
|
||||
* onto code in cCode.code */
|
||||
void ICODE::emitGotoLabel (Int indLevel)
|
||||
void ICODE::emitGotoLabel (int indLevel)
|
||||
{
|
||||
if (! (ic.ll.flg & HLL_LABEL)) /* node hasn't got a lab */
|
||||
{
|
||||
|
||||
@@ -38,9 +38,9 @@ bool JmpInst(llIcode opcode)
|
||||
****************************************************************************/
|
||||
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;
|
||||
int16_t delta;
|
||||
|
||||
pIcode = Icode.begin();
|
||||
pEnd = Icode.end();
|
||||
@@ -219,9 +219,9 @@ void Function::findIdioms()
|
||||
* binds jump target addresses to icode offsets. */
|
||||
void Function::bindIcodeOff()
|
||||
{
|
||||
Int i; /* idx into icode array */
|
||||
int i; /* idx into icode array */
|
||||
iICODE pIcode; /* ptr icode array */
|
||||
dword *p; /* for case table */
|
||||
uint32_t *p; /* for case table */
|
||||
|
||||
if (Icode.empty()) /* No Icode */
|
||||
return;
|
||||
@@ -255,7 +255,7 @@ void Function::bindIcodeOff()
|
||||
continue;
|
||||
if (icode.ic.ll.flg & I)
|
||||
{
|
||||
dword found;
|
||||
uint32_t found;
|
||||
if (! Icode.labelSrch(icode.ic.ll.src.op(), found))
|
||||
icode.ic.ll.flg |= NO_LABEL;
|
||||
else
|
||||
|
||||
@@ -95,7 +95,7 @@ bool Idiom18::match(iICODE picode)
|
||||
|
||||
m_is_dec = m_icodes[1]->ic.ll.match(iDEC);
|
||||
int type = -1; /* type of variable: 1 = reg-var, 2 = local */
|
||||
byte regi; /* register of the MOV */
|
||||
uint8_t regi; /* register of the MOV */
|
||||
|
||||
/* Get variable */
|
||||
if (m_icodes[1]->ic.ll.dst.regi == 0) /* global variable */
|
||||
@@ -238,7 +238,7 @@ int Idiom19::action()
|
||||
bool Idiom20::match(iICODE picode)
|
||||
{
|
||||
uint8_t type = 0; /* type of variable: 1 = reg-var, 2 = local */
|
||||
byte regi; /* register of the MOV */
|
||||
uint8_t regi; /* register of the MOV */
|
||||
if(std::distance(picode,m_end)<4)
|
||||
return false;
|
||||
for(int i=0; i<4; ++i)
|
||||
|
||||
@@ -38,7 +38,7 @@ int Idiom3::action()
|
||||
{
|
||||
if (m_icodes[0]->ic.ll.flg & I)
|
||||
{
|
||||
m_icodes[0]->ic.ll.src.proc.proc->cbParam = (int16)m_param_count;
|
||||
m_icodes[0]->ic.ll.src.proc.proc->cbParam = (int16_t)m_param_count;
|
||||
m_icodes[0]->ic.ll.src.proc.cb = m_param_count;
|
||||
m_icodes[0]->ic.ll.src.proc.proc->flg |= CALL_C;
|
||||
}
|
||||
@@ -73,7 +73,7 @@ bool Idiom17::match(iICODE picode)
|
||||
/* Match ADD SP, immed */
|
||||
for(int i=0; i<2; ++i)
|
||||
m_icodes.push_back(picode++);
|
||||
byte regi;
|
||||
uint8_t regi;
|
||||
|
||||
/* Match POP reg */
|
||||
if (m_icodes[1]->ic.ll.match(iPOP))
|
||||
@@ -98,7 +98,7 @@ int Idiom17::action()
|
||||
{
|
||||
if (m_icodes[0]->isLlFlag(I))
|
||||
{
|
||||
m_icodes[0]->ic.ll.src.proc.proc->cbParam = (int16)m_param_count;
|
||||
m_icodes[0]->ic.ll.src.proc.proc->cbParam = (int16_t)m_param_count;
|
||||
m_icodes[0]->ic.ll.src.proc.cb = m_param_count;
|
||||
m_icodes[0]->ic.ll.src.proc.proc->flg |= CALL_C;
|
||||
for(int idx=1; idx<m_icodes.size(); ++idx)
|
||||
|
||||
@@ -131,7 +131,7 @@ bool Idiom4::match(iICODE pIcode)
|
||||
/* Check for RET(F) immed */
|
||||
if (pIcode->ic.ll.flg & I)
|
||||
{
|
||||
m_param_count = (int16)pIcode->ic.ll.src.op();
|
||||
m_param_count = (int16_t)pIcode->ic.ll.src.op();
|
||||
}
|
||||
}
|
||||
int Idiom4::action()
|
||||
@@ -140,7 +140,7 @@ int Idiom4::action()
|
||||
m_icodes[idx]->invalidate();
|
||||
if(m_param_count)
|
||||
{
|
||||
m_func->cbParam = (int16)m_param_count;
|
||||
m_func->cbParam = (int16_t)m_param_count;
|
||||
m_func->flg |= CALL_PASCAL;
|
||||
}
|
||||
return 1;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* [PUSH SI]
|
||||
* In which case, the stack variable flags are set
|
||||
****************************************************************************/
|
||||
Int Idiom1::checkStkVars (iICODE pIcode)
|
||||
int Idiom1::checkStkVars (iICODE pIcode)
|
||||
{
|
||||
/* Look for PUSH SI */
|
||||
int si_matched=0;
|
||||
@@ -51,12 +51,12 @@ Int Idiom1::checkStkVars (iICODE pIcode)
|
||||
bool Idiom1::match(iICODE picode)
|
||||
{
|
||||
uint8_t type = 0; /* type of variable: 1 = reg-var, 2 = local */
|
||||
byte regi; /* register of the MOV */
|
||||
uint8_t regi; /* register of the MOV */
|
||||
if(m_func->flg & PROC_HLL)
|
||||
return false;
|
||||
if(picode==m_end)
|
||||
return false;
|
||||
Int n;
|
||||
int n;
|
||||
m_icodes.clear();
|
||||
m_min_off = 0;
|
||||
/* PUSH BP as first instruction of procedure */
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
using namespace std;
|
||||
|
||||
/*****************************************************************************
|
||||
* idiom 14 - Long word assign
|
||||
* idiom 14 - Long uint16_t assign
|
||||
* MOV regL, mem/reg
|
||||
* XOR regH, regH
|
||||
* Eg: MOV ax, di
|
||||
@@ -61,14 +61,14 @@ int Idiom14::action()
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* idiom 13 - Word assign
|
||||
* idiom 13 - uint16_t assign
|
||||
* MOV regL, mem
|
||||
* MOV regH, 0
|
||||
* Eg: MOV al, [bp-2]
|
||||
* MOV ah, 0
|
||||
* => MOV ax, [bp-2]
|
||||
* Found in Borland Turbo C, used for multiplication and division of
|
||||
* byte operands (ie. they need to be extended to words).
|
||||
* uint8_t operands (ie. they need to be extended to words).
|
||||
****************************************************************************/
|
||||
bool Idiom13::match(iICODE pIcode)
|
||||
{
|
||||
@@ -77,7 +77,7 @@ bool Idiom13::match(iICODE pIcode)
|
||||
m_icodes[0]=pIcode++;
|
||||
m_icodes[1]=pIcode++;
|
||||
m_loaded_reg = 0;
|
||||
byte regi;
|
||||
uint8_t regi;
|
||||
|
||||
/* Check for regL */
|
||||
regi = m_icodes[0]->ic.ll.dst.regi;
|
||||
@@ -101,7 +101,7 @@ int Idiom13::action()
|
||||
COND_EXPR *lhs,*rhs;
|
||||
lhs = COND_EXPR::idReg (m_loaded_reg, 0, &m_func->localId);
|
||||
m_icodes[0]->setRegDU( m_loaded_reg, eDEF);
|
||||
m_icodes[0]->du1.numRegsDef--; /* prev byte reg def */
|
||||
m_icodes[0]->du1.numRegsDef--; /* prev uint8_t reg def */
|
||||
rhs = COND_EXPR::id (*m_icodes[0], SRC, m_func, m_icodes[0], *m_icodes[0], NONE);
|
||||
m_icodes[0]->setAsgn(lhs, rhs);
|
||||
m_icodes[1]->invalidate();
|
||||
|
||||
@@ -79,7 +79,7 @@ bool Idiom16::match (iICODE picode)
|
||||
for(int i=0; i<3; ++i)
|
||||
m_icodes[i]=picode++;
|
||||
|
||||
byte regi = m_icodes[0]->ic.ll.dst.regi;
|
||||
uint8_t regi = m_icodes[0]->ic.ll.dst.regi;
|
||||
if ((regi >= rAX) && (regi < INDEXBASE))
|
||||
{
|
||||
if (m_icodes[1]->ic.ll.match(iSBB) && m_icodes[2]->ic.ll.match(iINC))
|
||||
|
||||
@@ -30,7 +30,7 @@ int Idiom8::action()
|
||||
{
|
||||
int idx;
|
||||
COND_EXPR *rhs,*lhs,*expr;
|
||||
byte regH,regL;
|
||||
uint8_t regH,regL;
|
||||
regH=m_icodes[0]->ic.ll.dst.regi;
|
||||
regL=m_icodes[1]->ic.ll.dst.regi;
|
||||
idx = m_func->localId.newLongReg (TYPE_LONG_SIGN, regH, regL, m_icodes[0]);
|
||||
@@ -58,8 +58,8 @@ int Idiom8::action()
|
||||
****************************************************************************/
|
||||
bool Idiom15::match(iICODE pIcode)
|
||||
{
|
||||
Int n = 1;
|
||||
byte regi;
|
||||
int n = 1;
|
||||
uint8_t regi;
|
||||
|
||||
if(distance(pIcode,m_end)<2)
|
||||
return false;
|
||||
@@ -122,7 +122,7 @@ int Idiom12::action()
|
||||
{
|
||||
int idx;
|
||||
COND_EXPR *rhs,*lhs,*expr;
|
||||
byte regH,regL;
|
||||
uint8_t regH,regL;
|
||||
regL=m_icodes[0]->ic.ll.dst.regi;
|
||||
regH=m_icodes[1]->ic.ll.dst.regi;
|
||||
|
||||
@@ -162,7 +162,7 @@ int Idiom9::action()
|
||||
{
|
||||
int idx;
|
||||
COND_EXPR *rhs,*lhs,*expr;
|
||||
byte regH,regL;
|
||||
uint8_t regH,regL;
|
||||
regL=m_icodes[1]->ic.ll.dst.regi;
|
||||
regH=m_icodes[0]->ic.ll.dst.regi;
|
||||
idx = m_func->localId.newLongReg (TYPE_LONG_UNSIGN,regH,regL,m_icodes[0]);
|
||||
|
||||
@@ -5,8 +5,23 @@
|
||||
* (C) Cristina Cifuentes
|
||||
*/
|
||||
|
||||
#include <cstring>
|
||||
#include "locident.h"
|
||||
#include "dcc.h"
|
||||
#include <string.h>
|
||||
|
||||
ID::ID() : type(TYPE_UNKNOWN),illegal(false),loc(STK_FRAME),hasMacro(false)
|
||||
{
|
||||
name[0]=0;
|
||||
macro[0]=0;
|
||||
memset(&id,0,sizeof(id));
|
||||
}
|
||||
ID::ID(hlType t, frameType f) : type(t),illegal(false),hasMacro(false)
|
||||
{
|
||||
name[0]=0;
|
||||
macro[0]=0;
|
||||
memset(&id,0,sizeof(id));
|
||||
loc=f;
|
||||
}
|
||||
|
||||
|
||||
#define LOCAL_ID_DELTA 25
|
||||
@@ -26,9 +41,9 @@ void LOCAL_ID::newIdent(hlType t, frameType f)
|
||||
|
||||
/* Creates a new register identifier node of TYPE_BYTE_(UN)SIGN or
|
||||
* TYPE_WORD_(UN)SIGN type. Returns the index to this new entry. */
|
||||
Int LOCAL_ID::newByteWordReg(hlType t, byte regi)
|
||||
int LOCAL_ID::newByteWordReg(hlType t, uint8_t regi)
|
||||
{
|
||||
Int idx;
|
||||
int idx;
|
||||
|
||||
/* Check for entry in the table */
|
||||
auto found=std::find_if(id_arr.begin(),id_arr.end(),[t,regi](ID &el)->bool {
|
||||
@@ -50,9 +65,9 @@ Int LOCAL_ID::newByteWordReg(hlType t, byte regi)
|
||||
* the array 1 position. The problem is that indexes into this
|
||||
* array have already been saved in several positions; therefore,
|
||||
* flagging this entry as illegal is all that can be done. */
|
||||
void LOCAL_ID::flagByteWordId (Int off)
|
||||
void LOCAL_ID::flagByteWordId (int off)
|
||||
{
|
||||
Int idx;
|
||||
int idx;
|
||||
auto found=std::find_if(id_arr.begin(),id_arr.end(),[off](ID &en)->bool {
|
||||
//if (((en.type == TYPE_WORD_SIGN) || (en.type == TYPE_BYTE_SIGN)) &&
|
||||
if ((en.isSigned()) &&
|
||||
@@ -70,9 +85,9 @@ void LOCAL_ID::flagByteWordId (Int off)
|
||||
|
||||
/* Creates a new stack identifier node of TYPE_BYTE_(UN)SIGN or
|
||||
* TYPE_WORD_(UN)SIGN type. Returns the index to this new entry. */
|
||||
Int LOCAL_ID::newByteWordStk(hlType t, Int off, byte regOff)
|
||||
int LOCAL_ID::newByteWordStk(hlType t, int off, uint8_t regOff)
|
||||
{
|
||||
Int idx;
|
||||
int idx;
|
||||
|
||||
/* Check for entry in the table */
|
||||
auto found=std::find_if(id_arr.begin(),id_arr.end(),[off,regOff](ID &el)->bool {
|
||||
@@ -101,9 +116,9 @@ Int LOCAL_ID::newByteWordStk(hlType t, Int off, byte regOff)
|
||||
* regi: indexed register into global variable
|
||||
* ix: index into icode array
|
||||
* t: HIGH_LEVEL type */
|
||||
Int LOCAL_ID::newIntIdx(int16 seg, int16 off, byte regi,Int ix, hlType t)
|
||||
int LOCAL_ID::newIntIdx(int16_t seg, int16_t off, uint8_t regi, int ix, hlType t)
|
||||
{
|
||||
Int idx;
|
||||
int idx;
|
||||
|
||||
/* Check for entry in the table */
|
||||
for (idx = 0; idx < id_arr.size(); idx++)
|
||||
@@ -128,9 +143,9 @@ 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, iICODE ix_)
|
||||
int LOCAL_ID::newLongReg(hlType t, uint8_t regH, uint8_t regL, iICODE ix_)
|
||||
{
|
||||
Int idx;
|
||||
int idx;
|
||||
//iICODE ix_;
|
||||
/* Check for entry in the table */
|
||||
for (idx = 0; idx < id_arr.size(); idx++)
|
||||
@@ -166,9 +181,9 @@ Int LOCAL_ID::newLongReg(hlType t, byte regH, byte regL, iICODE 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,hlType t)
|
||||
int LOCAL_ID::newLongGlb(int16_t seg, int16_t offH, int16_t offL,hlType t)
|
||||
{
|
||||
Int idx;
|
||||
int idx;
|
||||
|
||||
/* Check for entry in the table */
|
||||
for (idx = 0; idx < id_arr.size(); idx++)
|
||||
@@ -193,8 +208,8 @@ Int LOCAL_ID::newLongGlb(int16 seg, int16 offH, int16 offL,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, hlType t)
|
||||
{ Int idx;
|
||||
int LOCAL_ID::newLongIdx( int16_t seg, int16_t offH, int16_t offL,uint8_t regi, hlType t)
|
||||
{ int idx;
|
||||
|
||||
/* Check for entry in the table */
|
||||
for (idx = 0; idx < id_arr.size(); idx++)
|
||||
@@ -220,9 +235,9 @@ Int LOCAL_ID::newLongIdx( int16 seg, int16 offH, int16 offL,byte regi, hlType t)
|
||||
|
||||
/* Creates a new stack identifier node of type TYPE_LONG_(UN)SIGN.
|
||||
* Returns the index to this entry. */
|
||||
Int LOCAL_ID::newLongStk(hlType t, Int offH, Int offL)
|
||||
int LOCAL_ID::newLongStk(hlType t, int offH, int offL)
|
||||
{
|
||||
Int idx;
|
||||
int idx;
|
||||
|
||||
/* Check for entry in the table */
|
||||
for (idx = 0; idx < id_arr.size(); idx++)
|
||||
@@ -249,9 +264,9 @@ 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, iICODE pIcode, hlFirst f, iICODE ix,operDu du, Int off)
|
||||
int LOCAL_ID::newLong(opLoc sd, iICODE pIcode, hlFirst f, iICODE ix,operDu du, int off)
|
||||
{
|
||||
Int idx;
|
||||
int idx;
|
||||
LLOperand *pmH, *pmL;
|
||||
iICODE atOffset(pIcode);
|
||||
advance(atOffset,off);
|
||||
@@ -308,8 +323,8 @@ Int LOCAL_ID::newLong(opLoc sd, iICODE pIcode, hlFirst f, iICODE ix,operDu du, I
|
||||
* idx : idx into icode array
|
||||
* pProc : ptr to current procedure record
|
||||
* rhs, lhs : return expressions if successful. */
|
||||
boolT checkLongEq (LONG_STKID_TYPE longId, iICODE pIcode, Int i,
|
||||
Function * pProc, Assignment &asgn, Int off)
|
||||
boolT checkLongEq (LONG_STKID_TYPE longId, iICODE pIcode, int i,
|
||||
Function * pProc, Assignment &asgn, int off)
|
||||
{
|
||||
LLOperand *pmHdst, *pmLdst, *pmHsrc, *pmLsrc; /* pointers to LOW_LEVEL icodes */
|
||||
iICODE atOffset(pIcode);
|
||||
@@ -349,8 +364,8 @@ boolT checkLongEq (LONG_STKID_TYPE longId, iICODE pIcode, Int i,
|
||||
* idx : idx into icode array
|
||||
* pProc : ptr to current procedure record
|
||||
* rhs, lhs : return expressions if successful. */
|
||||
boolT checkLongRegEq (LONGID_TYPE longId, iICODE pIcode, Int i,
|
||||
Function * pProc, COND_EXPR *&rhs, COND_EXPR *&lhs, Int off)
|
||||
boolT checkLongRegEq (LONGID_TYPE longId, iICODE pIcode, int i,
|
||||
Function * pProc, COND_EXPR *&rhs, COND_EXPR *&lhs, int off)
|
||||
{
|
||||
LLOperand *pmHdst, *pmLdst, *pmHsrc, *pmLsrc; /* pointers to LOW_LEVEL icodes */
|
||||
iICODE atOffset(pIcode);
|
||||
@@ -384,7 +399,7 @@ boolT checkLongRegEq (LONGID_TYPE longId, iICODE pIcode, Int i,
|
||||
/* Given an index into the local identifier table for a long register
|
||||
* variable, determines whether regi is the high or low part, and returns
|
||||
* the other part */
|
||||
byte otherLongRegi (byte regi, Int idx, LOCAL_ID *locTbl)
|
||||
uint8_t otherLongRegi (uint8_t regi, int idx, LOCAL_ID *locTbl)
|
||||
{
|
||||
ID *id;
|
||||
|
||||
@@ -405,9 +420,9 @@ byte otherLongRegi (byte regi, Int idx, LOCAL_ID *locTbl)
|
||||
* the local identifier table. If so, macros for these registers are
|
||||
* placed in the local identifier table, as these registers belong to a
|
||||
* long register identifier. */
|
||||
void LOCAL_ID::propLongId (byte regL, byte regH, const char *name)
|
||||
void LOCAL_ID::propLongId (uint8_t regL, uint8_t regH, const char *name)
|
||||
{
|
||||
Int i;
|
||||
int i;
|
||||
ID *_id;
|
||||
|
||||
for (i = 0; i < id_arr.size(); i++)
|
||||
|
||||
207
src/parser.cpp
207
src/parser.cpp
@@ -11,14 +11,14 @@
|
||||
|
||||
#include "dcc.h"
|
||||
using namespace std;
|
||||
static void FollowCtrl (Function * pProc, CALL_GRAPH * pcallGraph, STATE * pstate);
|
||||
//static void FollowCtrl (Function * pProc, CALL_GRAPH * pcallGraph, STATE * pstate);
|
||||
static boolT process_JMP (ICODE * pIcode, STATE * pstate, CALL_GRAPH * pcallGraph);
|
||||
static void setBits(int16 type, dword start, dword len);
|
||||
static SYM * updateGlobSym(dword operand, Int size, word duFlag);
|
||||
static void setBits(int16_t type, uint32_t start, uint32_t len);
|
||||
static SYM * updateGlobSym(uint32_t operand, int size, uint16_t duFlag);
|
||||
static void process_MOV(ICODE & pIcode, STATE * pstate);
|
||||
static SYM * lookupAddr (LLOperand *pm, STATE * pstate, Int size, word duFlag);
|
||||
void interactDis(Function * initProc, Int ic);
|
||||
static dword SynthLab;
|
||||
static SYM * lookupAddr (LLOperand *pm, STATE * pstate, int size, uint16_t duFlag);
|
||||
void interactDis(Function * initProc, int ic);
|
||||
static uint32_t SynthLab;
|
||||
|
||||
|
||||
/* Parses the program, builds the call graph, and returns the list of
|
||||
@@ -34,7 +34,7 @@ void parse (CALL_GRAPH * *pcallGraph)
|
||||
state.setState(rCS, prog.initCS);
|
||||
state.setState(rSS, prog.initSS);
|
||||
state.setState(rSP, prog.initSP);
|
||||
state.IP = ((dword)prog.initCS << 4) + prog.initIP;
|
||||
state.IP = ((uint32_t)prog.initCS << 4) + prog.initIP;
|
||||
SynthLab = SYNTHESIZED_MIN;
|
||||
|
||||
// default-construct a Function object !
|
||||
@@ -58,7 +58,7 @@ void parse (CALL_GRAPH * *pcallGraph)
|
||||
{
|
||||
/* Create initial procedure at program start address */
|
||||
start_proc.name="start";
|
||||
start_proc.procEntry = (dword)state.IP;
|
||||
start_proc.procEntry = (uint32_t)state.IP;
|
||||
}
|
||||
/* The state info is for the first procedure */
|
||||
start_proc.state = state;
|
||||
@@ -81,8 +81,8 @@ void parse (CALL_GRAPH * *pcallGraph)
|
||||
|
||||
/* Updates the type of the symbol in the symbol table. The size is updated
|
||||
* if necessary (0 means no update necessary). */
|
||||
static void updateSymType (dword symbol, hlType symType, Int size)
|
||||
{ Int i;
|
||||
static void updateSymType (uint32_t symbol, hlType symType, int size)
|
||||
{ int i;
|
||||
|
||||
for (i = 0; i < symtab.size(); i++)
|
||||
if (symtab[i].label == symbol)
|
||||
@@ -97,12 +97,11 @@ static void updateSymType (dword symbol, hlType symType, Int size)
|
||||
|
||||
/* Returns the size of the string pointed by sym and delimited by delim.
|
||||
* Size includes delimiter. */
|
||||
Int strSize (byte *sym, char delim)
|
||||
int strSize (uint8_t *sym, char delim)
|
||||
{
|
||||
Int i;
|
||||
for (i = 0; *sym++ != delim; i++)
|
||||
;
|
||||
return (i+1);
|
||||
int till_end = sym-prog.Image;
|
||||
uint8_t *end_ptr=std::find(sym,sym+(prog.cbImage-(till_end)),delim);
|
||||
return end_ptr-sym+1;
|
||||
}
|
||||
Function *fakeproc=Function::Create(0,0,"fake");
|
||||
|
||||
@@ -114,7 +113,7 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
|
||||
ICODE _Icode, *pIcode; /* This gets copied to pProc->Icode[] later */
|
||||
ICODE eIcode; /* extra icodes for iDIV, iIDIV, iXCHG */
|
||||
SYM * psym;
|
||||
dword offset;
|
||||
uint32_t offset;
|
||||
eErrorId err;
|
||||
boolT done = FALSE;
|
||||
|
||||
@@ -135,8 +134,8 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
|
||||
|
||||
while (! done && ! (err = scan(pstate->IP, _Icode)))
|
||||
{
|
||||
pstate->IP += (dword)_Icode.ic.ll.numBytes;
|
||||
setBits(BM_CODE, _Icode.ic.ll.label, (dword)_Icode.ic.ll.numBytes);
|
||||
pstate->IP += (uint32_t)_Icode.ic.ll.numBytes;
|
||||
setBits(BM_CODE, _Icode.ic.ll.label, (uint32_t)_Icode.ic.ll.numBytes);
|
||||
|
||||
process_operands(_Icode,pstate);
|
||||
|
||||
@@ -249,7 +248,7 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
|
||||
*/
|
||||
if (ip > 0 && prev.ic.ll.opcode == iCMP && (prev.ic.ll.flg & I))
|
||||
{
|
||||
pstate->JCond.immed = (int16)prev.ic.ll.src.op();
|
||||
pstate->JCond.immed = (int16_t)prev.ic.ll.src.op();
|
||||
if (_Icode.ic.ll.opcode == iJA || _Icode.ic.ll.opcode == iJBE)
|
||||
pstate->JCond.immed++;
|
||||
if (_Icode.ic.ll.opcode == iJAE || _Icode.ic.ll.opcode == iJA)
|
||||
@@ -297,12 +296,12 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
|
||||
case iINT:
|
||||
if (_Icode.ic.ll.src.op() == 0x21 && pstate->f[rAH])
|
||||
{
|
||||
Int funcNum = pstate->r[rAH];
|
||||
Int operand;
|
||||
Int size;
|
||||
int funcNum = pstate->r[rAH];
|
||||
int operand;
|
||||
int size;
|
||||
|
||||
/* Save function number */
|
||||
Icode.back().ic.ll.dst.off = (int16)funcNum;
|
||||
Icode.back().ic.ll.dst.off = (int16_t)funcNum;
|
||||
//Icode.GetIcode(Icode.GetNumIcodes() - 1)->
|
||||
|
||||
/* Program termination: int21h, fn 00h, 31h, 4Ch */
|
||||
@@ -313,11 +312,11 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
|
||||
if (pstate->f[rDX]) /* offset goes into DX */
|
||||
if (funcNum == 0x09)
|
||||
{
|
||||
operand = ((dword)(word)pstate->r[rDS]<<4) +
|
||||
(dword)(word)pstate->r[rDX];
|
||||
operand = ((uint32_t)(uint16_t)pstate->r[rDS]<<4) +
|
||||
(uint32_t)(uint16_t)pstate->r[rDX];
|
||||
size = prog.fCOM ?
|
||||
strSize (&prog.Image[operand], '$') :
|
||||
strSize (&prog.Image[operand + 0x100], '$');
|
||||
strSize (&prog.Image[operand], '$'); // + 0x100
|
||||
updateSymType (operand, TYPE_STR, size);
|
||||
}
|
||||
}
|
||||
@@ -360,7 +359,7 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
|
||||
offset = LH(&prog.Image[psym->label]);
|
||||
pstate->setState( (_Icode.ic.ll.opcode == iLDS)? rDS: rES,
|
||||
LH(&prog.Image[psym->label + 2]));
|
||||
pstate->setState( _Icode.ic.ll.dst.regi, (int16)offset);
|
||||
pstate->setState( _Icode.ic.ll.dst.regi, (int16_t)offset);
|
||||
psym->type = TYPE_PTR;
|
||||
}
|
||||
break;
|
||||
@@ -386,11 +385,11 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
|
||||
/* process_JMP - Handles JMPs, returns TRUE if we should end recursion */
|
||||
boolT Function::process_JMP (ICODE & pIcode, STATE *pstate, CALL_GRAPH * pcallGraph)
|
||||
{
|
||||
static byte i2r[4] = {rSI, rDI, rBP, rBX};
|
||||
static uint8_t i2r[4] = {rSI, rDI, rBP, rBX};
|
||||
ICODE _Icode;
|
||||
dword cs, offTable, endTable;
|
||||
dword i, k, seg, target;
|
||||
dword tmp;
|
||||
uint32_t cs, offTable, endTable;
|
||||
uint32_t i, k, seg, target;
|
||||
uint32_t tmp;
|
||||
|
||||
if (pIcode.ic.ll.flg & I)
|
||||
{
|
||||
@@ -407,10 +406,10 @@ boolT Function::process_JMP (ICODE & pIcode, STATE *pstate, CALL_GRAPH * pcallGr
|
||||
}
|
||||
|
||||
/* We've got an indirect JMP - look for switch() stmt. idiom of the form
|
||||
* JMP word ptr word_offset[rBX | rSI | rDI] */
|
||||
* JMP uint16_t ptr word_offset[rBX | rSI | rDI] */
|
||||
seg = (pIcode.ic.ll.src.seg)? pIcode.ic.ll.src.seg: rDS;
|
||||
|
||||
/* Ensure we have a word offset & valid seg */
|
||||
/* Ensure we have a uint16_t offset & valid seg */
|
||||
if (pIcode.ic.ll.opcode == iJMP && (pIcode.ic.ll.flg & WORD_OFF) &&
|
||||
pstate->f[seg] &&
|
||||
(pIcode.ic.ll.src.regi == INDEXBASE + 4 ||
|
||||
@@ -418,7 +417,7 @@ boolT Function::process_JMP (ICODE & pIcode, STATE *pstate, CALL_GRAPH * pcallGr
|
||||
pIcode.ic.ll.src.regi == INDEXBASE + 7))
|
||||
{
|
||||
|
||||
offTable = ((dword)(word)pstate->r[seg] << 4) + pIcode.ic.ll.src.off;
|
||||
offTable = ((uint32_t)(uint16_t)pstate->r[seg] << 4) + pIcode.ic.ll.src.off;
|
||||
|
||||
/* Firstly look for a leading range check of the form:-
|
||||
* CMP {BX | SI | DI}, immed
|
||||
@@ -429,9 +428,9 @@ boolT Function::process_JMP (ICODE & pIcode, STATE *pstate, CALL_GRAPH * pcallGr
|
||||
if (pstate->JCond.regi == i2r[pIcode.ic.ll.src.regi-(INDEXBASE+4)])
|
||||
endTable = offTable + pstate->JCond.immed;
|
||||
else
|
||||
endTable = (dword)prog.cbImage;
|
||||
endTable = (uint32_t)prog.cbImage;
|
||||
|
||||
/* Search for first byte flagged after start of table */
|
||||
/* Search for first uint8_t flagged after start of table */
|
||||
for (i = offTable; i <= endTable; i++)
|
||||
if (BITMAP(i, BM_CODE | BM_DATA))
|
||||
break;
|
||||
@@ -440,13 +439,13 @@ boolT Function::process_JMP (ICODE & pIcode, STATE *pstate, CALL_GRAPH * pcallGr
|
||||
/* Now do some heuristic pruning. Look for ptrs. into the table
|
||||
* and for addresses that don't appear to point to valid code.
|
||||
*/
|
||||
cs = (dword)(word)pstate->r[rCS] << 4;
|
||||
cs = (uint32_t)(uint16_t)pstate->r[rCS] << 4;
|
||||
for (i = offTable; i < endTable; i += 2)
|
||||
{
|
||||
target = cs + LH(&prog.Image[i]);
|
||||
if (target < endTable && target >= offTable)
|
||||
endTable = target;
|
||||
else if (target >= (dword)prog.cbImage)
|
||||
else if (target >= (uint32_t)prog.cbImage)
|
||||
endTable = i;
|
||||
}
|
||||
|
||||
@@ -464,14 +463,14 @@ boolT Function::process_JMP (ICODE & pIcode, STATE *pstate, CALL_GRAPH * pcallGr
|
||||
if (offTable < endTable)
|
||||
{
|
||||
STATE StCopy;
|
||||
Int ip;
|
||||
dword *psw;
|
||||
int ip;
|
||||
uint32_t *psw;
|
||||
|
||||
setBits(BM_DATA, offTable, endTable - offTable);
|
||||
|
||||
pIcode.ic.ll.flg |= SWITCH;
|
||||
pIcode.ic.ll.caseTbl.numEntries = (endTable - offTable) / 2;
|
||||
psw = (dword*)allocMem(pIcode.ic.ll.caseTbl.numEntries*sizeof(dword));
|
||||
psw = (uint32_t*)allocMem(pIcode.ic.ll.caseTbl.numEntries*sizeof(uint32_t));
|
||||
pIcode.ic.ll.caseTbl.entries = psw;
|
||||
|
||||
for (i = offTable, k = 0; i < endTable; i += 2)
|
||||
@@ -514,7 +513,7 @@ boolT Function::process_CALL (ICODE & pIcode, CALL_GRAPH * pcallGraph, STATE *ps
|
||||
{
|
||||
ICODE &last_insn(Icode.back());
|
||||
STATE localState; /* Local copy of the machine state */
|
||||
dword off;
|
||||
uint32_t off;
|
||||
boolT indirect;
|
||||
|
||||
/* For Indirect Calls, find the function address */
|
||||
@@ -540,16 +539,16 @@ boolT Function::process_CALL (ICODE & pIcode, CALL_GRAPH * pcallGraph, STATE *ps
|
||||
usually wrong! Consider also CALL [BP+0E] in which the
|
||||
segment for the pointer is in SS! - Mike */
|
||||
|
||||
off = (dword)(word)pIcode.ic.ll.dst.off +
|
||||
((dword)(word)pIcode.ic.ll.dst.segValue << 4);
|
||||
off = (uint32_t)(uint16_t)pIcode.ic.ll.dst.off +
|
||||
((uint32_t)(uint16_t)pIcode.ic.ll.dst.segValue << 4);
|
||||
|
||||
/* Address of function is given by 4 (CALLF) or 2 (CALL) bytes at
|
||||
* previous offset into the program image */
|
||||
dword tgtAddr=0;
|
||||
uint32_t tgtAddr=0;
|
||||
if (pIcode.ic.ll.opcode == iCALLF)
|
||||
tgtAddr= LH(&prog.Image[off]) + (dword)(LH(&prog.Image[off+2])) << 4;
|
||||
tgtAddr= LH(&prog.Image[off]) + (uint32_t)(LH(&prog.Image[off+2])) << 4;
|
||||
else
|
||||
tgtAddr= LH(&prog.Image[off]) + (dword)(word)state.r[rCS] << 4;
|
||||
tgtAddr= LH(&prog.Image[off]) + (uint32_t)(uint16_t)state.r[rCS] << 4;
|
||||
pIcode.ic.ll.src.SetImmediateOp( tgtAddr );
|
||||
pIcode.ic.ll.flg |= I;
|
||||
indirect = TRUE;
|
||||
@@ -629,13 +628,13 @@ boolT Function::process_CALL (ICODE & pIcode, CALL_GRAPH * pcallGraph, STATE *ps
|
||||
static void process_MOV(ICODE & pIcode, STATE * pstate)
|
||||
{
|
||||
SYM * psym, *psym2; /* Pointer to symbol in global symbol table */
|
||||
byte dstReg = pIcode.ic.ll.dst.regi;
|
||||
byte srcReg = pIcode.ic.ll.src.regi;
|
||||
uint8_t dstReg = pIcode.ic.ll.dst.regi;
|
||||
uint8_t srcReg = pIcode.ic.ll.src.regi;
|
||||
|
||||
if (dstReg > 0 && dstReg < INDEXBASE)
|
||||
{
|
||||
if (pIcode.ic.ll.flg & I)
|
||||
pstate->setState( dstReg, (int16)pIcode.ic.ll.src.op());
|
||||
pstate->setState( dstReg, (int16_t)pIcode.ic.ll.src.op());
|
||||
else if (srcReg == 0) /* direct memory offset */
|
||||
{
|
||||
psym = lookupAddr(&pIcode.ic.ll.src, pstate, 2, eDuVal::USE);
|
||||
@@ -652,28 +651,36 @@ static void process_MOV(ICODE & pIcode, STATE * pstate)
|
||||
}
|
||||
}
|
||||
else if (dstReg == 0) { /* direct memory offset */
|
||||
psym = lookupAddr (&pIcode.ic.ll.dst, pstate, 2, eDEF);
|
||||
int size=2;
|
||||
if((pIcode.ic.ll.src.regi>=rAL)&&(pIcode.ic.ll.src.regi<=rBH))
|
||||
size=1;
|
||||
psym = lookupAddr (&pIcode.ic.ll.dst, pstate, size, eDEF);
|
||||
if (psym && ! (psym->duVal.val)) /* no initial value yet */
|
||||
if (pIcode.ic.ll.flg & I) { /* immediate */
|
||||
prog.Image[psym->label] = (byte)pIcode.ic.ll.src.op();
|
||||
prog.Image[psym->label+1] = (byte)(pIcode.ic.ll.src.op()>>8);
|
||||
if (pIcode.ic.ll.flg & I) /* immediate */
|
||||
{
|
||||
prog.Image[psym->label] = (uint8_t)pIcode.ic.ll.src.op();
|
||||
if(psym->size>1)
|
||||
prog.Image[psym->label+1] = (uint8_t)(pIcode.ic.ll.src.op()>>8);
|
||||
psym->duVal.val = 1;
|
||||
}
|
||||
else if (srcReg == 0) { /* direct mem offset */
|
||||
else if (srcReg == 0) /* direct mem offset */
|
||||
{
|
||||
psym2 = lookupAddr (&pIcode.ic.ll.src, pstate, 2, eDuVal::USE);
|
||||
if (psym2 && ((psym->flg & SEG_IMMED) || (psym->duVal.val)))
|
||||
{
|
||||
prog.Image[psym->label] = (byte)prog.Image[psym2->label];
|
||||
prog.Image[psym->label+1] =
|
||||
(byte)(prog.Image[psym2->label+1] >> 8);
|
||||
psym->duVal.val=1;
|
||||
prog.Image[psym->label] = (uint8_t)prog.Image[psym2->label];
|
||||
if(psym->size>1)
|
||||
prog.Image[psym->label+1] = (uint8_t)(prog.Image[psym2->label+1] >> 8);
|
||||
psym->duVal.setFlags(eDuVal::DEF);
|
||||
psym2->duVal.setFlags(eDuVal::USE);
|
||||
}
|
||||
}
|
||||
else if (srcReg < INDEXBASE && pstate->f[srcReg]) /* reg */
|
||||
{
|
||||
prog.Image[psym->label] = (byte)pstate->r[srcReg];
|
||||
prog.Image[psym->label+1] = (byte)(pstate->r[srcReg] >> 8);
|
||||
psym->duVal.val;
|
||||
prog.Image[psym->label] = (uint8_t)pstate->r[srcReg];
|
||||
if(psym->size>1)
|
||||
prog.Image[psym->label+1] = (uint8_t)(pstate->r[srcReg] >> 8);
|
||||
psym->duVal.setFlags(eDuVal::DEF);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -687,9 +694,9 @@ static hlType cbType[] = {TYPE_UNKNOWN, TYPE_BYTE_UNSIGN, TYPE_WORD_SIGN,
|
||||
* is not there yet. If it is part of the symtab, the size of the variable
|
||||
* is checked and updated if the old size was less than the new size (ie.
|
||||
* the maximum size is always saved). */
|
||||
static SYM * updateGlobSym (dword operand, Int size, word duFlag)
|
||||
static SYM * updateGlobSym (uint32_t operand, int size, uint16_t duFlag)
|
||||
{
|
||||
Int i;
|
||||
int i;
|
||||
|
||||
/* Check for symbol in symbol table */
|
||||
for (i = 0; i < symtab.size(); i++)
|
||||
@@ -697,8 +704,8 @@ static SYM * updateGlobSym (dword operand, Int size, word duFlag)
|
||||
{
|
||||
if (symtab[i].size < size)
|
||||
symtab[i].size = size;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/* New symbol, not in symbol table */
|
||||
if (i == symtab.size())
|
||||
@@ -725,9 +732,9 @@ static SYM * updateGlobSym (dword operand, Int size, word duFlag)
|
||||
|
||||
/* Updates the offset entry to the stack frame table (arguments),
|
||||
* and returns a pointer to such entry. */
|
||||
static void updateFrameOff (STKFRAME * ps, int16 off, Int size, word duFlag)
|
||||
static void updateFrameOff (STKFRAME * ps, int16_t off, int size, uint16_t duFlag)
|
||||
{
|
||||
Int i;
|
||||
int i;
|
||||
|
||||
/* Check for symbol in stack frame table */
|
||||
for (i = 0; i < ps->sym.size(); i++)
|
||||
@@ -764,8 +771,8 @@ static void updateFrameOff (STKFRAME * ps, int16 off, Int size, word duFlag)
|
||||
}
|
||||
|
||||
/* Save maximum argument offset */
|
||||
if ((dword)ps->maxOff < (off + (dword)size))
|
||||
ps->maxOff = off + (int16)size;
|
||||
if ((uint32_t)ps->maxOff < (off + (uint32_t)size))
|
||||
ps->maxOff = off + (int16_t)size;
|
||||
}
|
||||
|
||||
|
||||
@@ -773,11 +780,11 @@ static void updateFrameOff (STKFRAME * ps, int16 off, Int size, word duFlag)
|
||||
* if necessary.
|
||||
* Returns a pointer to the symbol in the
|
||||
* symbol table, or Null if it's not a direct memory offset. */
|
||||
static SYM * lookupAddr (LLOperand *pm, STATE *pstate, Int size, word duFlag)
|
||||
static SYM * lookupAddr (LLOperand *pm, STATE *pstate, int size, uint16_t duFlag)
|
||||
{
|
||||
Int i;
|
||||
int i;
|
||||
SYM * psym;
|
||||
dword operand;
|
||||
uint32_t operand;
|
||||
|
||||
if (pm->regi == 0) { /* Global var */
|
||||
if (pm->segValue) { /* there is a value in the seg field */
|
||||
@@ -785,7 +792,7 @@ static SYM * lookupAddr (LLOperand *pm, STATE *pstate, Int size, word duFlag)
|
||||
psym = updateGlobSym (operand, size, duFlag);
|
||||
|
||||
/* Check for out of bounds */
|
||||
if (psym->label >= (dword)prog.cbImage)
|
||||
if (psym->label >= (uint32_t)prog.cbImage)
|
||||
return (NULL);
|
||||
return (psym);
|
||||
}
|
||||
@@ -799,7 +806,7 @@ static SYM * lookupAddr (LLOperand *pm, STATE *pstate, Int size, word duFlag)
|
||||
if (symtab.size() > i)
|
||||
{
|
||||
if (size == 4)
|
||||
operand += 2; /* High word */
|
||||
operand += 2; /* High uint16_t */
|
||||
for (i = 0; i < prog.cReloc; i++)
|
||||
if (prog.relocTable[i] == operand) {
|
||||
psym->flg = SEG_IMMED;
|
||||
@@ -808,7 +815,7 @@ static SYM * lookupAddr (LLOperand *pm, STATE *pstate, Int size, word duFlag)
|
||||
}
|
||||
|
||||
/* Check for out of bounds */
|
||||
if (psym->label >= (dword)prog.cbImage)
|
||||
if (psym->label >= (uint32_t)prog.cbImage)
|
||||
return (NULL);
|
||||
return (psym);
|
||||
}
|
||||
@@ -818,7 +825,7 @@ static SYM * lookupAddr (LLOperand *pm, STATE *pstate, Int size, word duFlag)
|
||||
|
||||
|
||||
/* setState - Assigns a value to a reg. */
|
||||
void STATE::setState(word reg, int16 value)
|
||||
void STATE::setState(uint16_t reg, int16_t value)
|
||||
{
|
||||
value &= 0xFFFF;
|
||||
r[reg] = value;
|
||||
@@ -854,15 +861,15 @@ void STATE::setState(word reg, int16 value)
|
||||
|
||||
|
||||
|
||||
static void setBits(int16 type, dword start, dword len)
|
||||
static void setBits(int16_t type, uint32_t start, uint32_t len)
|
||||
/* setBits - Sets memory bitmap bits for BM_CODE or BM_DATA (additively) */
|
||||
{
|
||||
dword i;
|
||||
uint32_t i;
|
||||
|
||||
if (start < (dword)prog.cbImage)
|
||||
if (start < (uint32_t)prog.cbImage)
|
||||
{
|
||||
if (start + len > (dword)prog.cbImage)
|
||||
len = (dword)(prog.cbImage - start);
|
||||
if (start + len > (uint32_t)prog.cbImage)
|
||||
len = (uint32_t)(prog.cbImage - start);
|
||||
|
||||
for (i = start + len - 1; i >= start; i--)
|
||||
{
|
||||
@@ -875,10 +882,10 @@ static void setBits(int16 type, dword start, dword len)
|
||||
/* DU bit definitions for each reg value - including index registers */
|
||||
std::bitset<32> duReg[] = { 0x00,
|
||||
//AH AL . . AX, BH
|
||||
0x11001, 0x22002, 0x44004, 0x88008, /* word regs */
|
||||
0x11001, 0x22002, 0x44004, 0x88008, /* uint16_t regs */
|
||||
0x10, 0x20, 0x40, 0x80,
|
||||
0x100, 0x200, 0x400, 0x800, /* seg regs */
|
||||
0x1000, 0x2000, 0x4000, 0x8000, /* byte regs */
|
||||
0x1000, 0x2000, 0x4000, 0x8000, /* uint8_t regs */
|
||||
0x10000, 0x20000, 0x40000, 0x80000,
|
||||
0x100000, /* tmp reg */
|
||||
0x48, 0x88, 0x60, 0xA0, /* index regs */
|
||||
@@ -893,7 +900,7 @@ std::bitset<32> duReg[] = { 0x00,
|
||||
* pstate: ptr to current procedure state
|
||||
* size : size of the operand
|
||||
* ix : current index into icode array */
|
||||
static void use (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, Int size, Int ix)
|
||||
static void use (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int size, int ix)
|
||||
{
|
||||
LLOperand * pm = (d == SRC)? &pIcode.ic.ll.src: &pIcode.ic.ll.dst;
|
||||
SYM * psym;
|
||||
@@ -910,7 +917,7 @@ static void use (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, Int
|
||||
|
||||
else if (pm->regi == INDEXBASE + 2 || pm->regi == INDEXBASE + 3)
|
||||
pProc->localId.newByteWordStk (TYPE_WORD_SIGN, pm->off,
|
||||
(byte)((pm->regi == INDEXBASE + 2) ? rSI : rDI));
|
||||
(uint8_t)((pm->regi == INDEXBASE + 2) ? rSI : rDI));
|
||||
|
||||
else if ((pm->regi >= INDEXBASE + 4) && (pm->regi <= INDEXBASE + 7))
|
||||
{
|
||||
@@ -924,7 +931,7 @@ static void use (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, Int
|
||||
|
||||
else if (psym = lookupAddr(pm, pstate, size, eDuVal::USE))
|
||||
{
|
||||
setBits (BM_DATA, psym->label, (dword)size);
|
||||
setBits (BM_DATA, psym->label, (uint32_t)size);
|
||||
pIcode.ic.ll.flg |= SYM_USE;
|
||||
pIcode.ic.ll.caseTbl.numEntries = psym - &symtab[0];
|
||||
}
|
||||
@@ -939,8 +946,8 @@ static void use (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, Int
|
||||
/* Checks which registers were defined (ie. got a new value) and updates the
|
||||
* du.d flag.
|
||||
* Places local variables in the local symbol table. */
|
||||
static void def (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, Int size,
|
||||
Int ix)
|
||||
static void def (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int size,
|
||||
int ix)
|
||||
{
|
||||
LLOperand *pm = (d == SRC)? &pIcode.ic.ll.src: &pIcode.ic.ll.dst;
|
||||
SYM * psym;
|
||||
@@ -958,7 +965,7 @@ static void def (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, Int
|
||||
else if (pm->regi == INDEXBASE + 2 || pm->regi == INDEXBASE + 3)
|
||||
{
|
||||
pProc->localId.newByteWordStk(TYPE_WORD_SIGN, pm->off,
|
||||
(byte)((pm->regi == INDEXBASE + 2) ? rSI : rDI));
|
||||
(uint8_t)((pm->regi == INDEXBASE + 2) ? rSI : rDI));
|
||||
}
|
||||
|
||||
else if ((pm->regi >= INDEXBASE + 4) && (pm->regi <= INDEXBASE + 7))
|
||||
@@ -973,7 +980,7 @@ static void def (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, Int
|
||||
|
||||
else if (psym = lookupAddr(pm, pstate, size, eDEF))
|
||||
{
|
||||
setBits(BM_DATA, psym->label, (dword)size);
|
||||
setBits(BM_DATA, psym->label, (uint32_t)size);
|
||||
pIcode.ic.ll.flg |= SYM_DEF;
|
||||
pIcode.ic.ll.caseTbl.numEntries = psym - &symtab[0];
|
||||
}
|
||||
@@ -991,8 +998,8 @@ static void def (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, Int
|
||||
/* use_def - operand is both use and def'd.
|
||||
* Note: the destination will always be a register, stack variable, or global
|
||||
* variable. */
|
||||
static void use_def(opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, Int cb,
|
||||
Int ix)
|
||||
static void use_def(opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int cb,
|
||||
int ix)
|
||||
{
|
||||
LLOperand * pm = (d == SRC)? &pIcode.ic.ll.src: &pIcode.ic.ll.dst;
|
||||
|
||||
@@ -1010,11 +1017,11 @@ static void use_def(opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, I
|
||||
* bitmap */
|
||||
void Function::process_operands(ICODE & pIcode, STATE * pstate)
|
||||
{
|
||||
Int ix=Icode.size();
|
||||
Int i;
|
||||
Int sseg = (pIcode.ic.ll.src.seg)? pIcode.ic.ll.src.seg: rDS;
|
||||
Int cb = (pIcode.ic.ll.flg & B) ? 1: 2;
|
||||
flags32 Imm = (pIcode.ic.ll.flg & I);
|
||||
int ix=Icode.size();
|
||||
int i;
|
||||
int sseg = (pIcode.ic.ll.src.seg)? pIcode.ic.ll.src.seg: rDS;
|
||||
int cb = (pIcode.ic.ll.flg & B) ? 1: 2;
|
||||
uint32_t Imm = (pIcode.ic.ll.flg & I);
|
||||
|
||||
switch (pIcode.ic.ll.opcode) {
|
||||
case iAND: case iOR: case iXOR:
|
||||
@@ -1072,13 +1079,13 @@ void Function::process_operands(ICODE & pIcode, STATE * pstate)
|
||||
|
||||
case iSIGNEX:
|
||||
cb = (pIcode.ic.ll.flg & SRC_B) ? 1 : 2;
|
||||
if (cb == 1) /* byte */
|
||||
if (cb == 1) /* uint8_t */
|
||||
{
|
||||
pIcode.du.def |= duReg[rAX];
|
||||
pIcode.du1.numRegsDef++;
|
||||
pIcode.du.use |= duReg[rAL];
|
||||
}
|
||||
else /* word */
|
||||
else /* uint16_t */
|
||||
{
|
||||
pIcode.du.def |= (duReg[rDX] | duReg[rAX]);
|
||||
pIcode.du1.numRegsDef += 2;
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
/* Private data structures */
|
||||
|
||||
static word *T1, *T2; /* Pointers to T1[i], T2[i] */
|
||||
static uint16_t *T1, *T2; /* Pointers to T1[i], T2[i] */
|
||||
static short *g; /* g[] */
|
||||
|
||||
static int numEdges; /* An edge counter */
|
||||
@@ -39,8 +39,8 @@ PatternHasher::init(int _NumEntry, int _EntryLen, int _SetSize, char _SetMin,
|
||||
NumVert = _NumVert;
|
||||
|
||||
/* Allocate the variable sized tables etc */
|
||||
T1base = new word [EntryLen * SetSize];
|
||||
T2base = new word [EntryLen * SetSize];
|
||||
T1base = new uint16_t [EntryLen * SetSize];
|
||||
T2base = new uint16_t [EntryLen * SetSize];
|
||||
graphNode = new int [NumEntry*2 + 1];
|
||||
graphNext = new int [NumEntry*2 + 1];
|
||||
graphFirst = new int [NumVert + 1];
|
||||
@@ -66,9 +66,9 @@ void PatternHasher::cleanup(void)
|
||||
// delete [] visited;
|
||||
}
|
||||
|
||||
int PatternHasher::hash(byte *string)
|
||||
int PatternHasher::hash(uint8_t *string)
|
||||
{
|
||||
word u, v;
|
||||
uint16_t u, v;
|
||||
int j;
|
||||
|
||||
u = 0;
|
||||
@@ -90,18 +90,18 @@ int PatternHasher::hash(byte *string)
|
||||
return (g[u] + g[v]) % NumEntry;
|
||||
}
|
||||
|
||||
word * PatternHasher::readT1(void)
|
||||
uint16_t * PatternHasher::readT1(void)
|
||||
{
|
||||
return T1base;
|
||||
}
|
||||
|
||||
word *PatternHasher::readT2(void)
|
||||
uint16_t *PatternHasher::readT2(void)
|
||||
{
|
||||
return T2base;
|
||||
}
|
||||
|
||||
word * PatternHasher::readG(void)
|
||||
uint16_t * PatternHasher::readG(void)
|
||||
{
|
||||
return (word *)g;
|
||||
return (uint16_t *)g;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
static char indentBuf[indSize] =
|
||||
" ";
|
||||
|
||||
static char *indent (Int indLevel) // Indentation according to the depth of the statement
|
||||
static char *indent (int indLevel) // Indentation according to the depth of the statement
|
||||
{
|
||||
return (&indentBuf[indSize-(indLevel*3)-1]);
|
||||
}
|
||||
@@ -26,7 +26,7 @@ static char *indent (Int indLevel) // Indentation according to the depth of the
|
||||
void CALL_GRAPH::insertArc (ilFunction newProc)
|
||||
{
|
||||
CALL_GRAPH *pcg;
|
||||
Int i;
|
||||
int i;
|
||||
|
||||
/* Check if procedure already exists */
|
||||
auto res=std::find_if(outEdges.begin(),outEdges.end(),[newProc](CALL_GRAPH *e) {return e->proc==newProc;});
|
||||
@@ -42,7 +42,7 @@ void CALL_GRAPH::insertArc (ilFunction newProc)
|
||||
/* Inserts a (caller, callee) arc in the call graph tree. */
|
||||
boolT CALL_GRAPH::insertCallGraph(ilFunction caller, ilFunction callee)
|
||||
{
|
||||
Int i;
|
||||
int i;
|
||||
|
||||
if (proc == caller)
|
||||
{
|
||||
@@ -69,9 +69,9 @@ boolT CALL_GRAPH::insertCallGraph(Function *caller, ilFunction callee)
|
||||
|
||||
/* Displays the current node of the call graph, and invokes recursively on
|
||||
* the nodes the procedure invokes. */
|
||||
void CALL_GRAPH::writeNodeCallGraph(Int indIdx)
|
||||
void CALL_GRAPH::writeNodeCallGraph(int indIdx)
|
||||
{
|
||||
Int i;
|
||||
int i;
|
||||
|
||||
printf ("%s%s\n", indent(indIdx), proc->name.c_str());
|
||||
for (i = 0; i < outEdges.size(); i++)
|
||||
@@ -99,7 +99,7 @@ void Function::newRegArg(iICODE picode, iICODE ticode)
|
||||
COND_EXPR *lhs;
|
||||
STKFRAME * ps, *ts;
|
||||
ID *id;
|
||||
Int i, tidx;
|
||||
int i, tidx;
|
||||
boolT regExist;
|
||||
condId type;
|
||||
Function * tproc;
|
||||
@@ -218,7 +218,7 @@ void Function::newRegArg(iICODE picode, iICODE ticode)
|
||||
*/
|
||||
bool CallType::newStkArg(COND_EXPR *exp, llIcode opcode, Function * pproc)
|
||||
{
|
||||
byte regi;
|
||||
uint8_t regi;
|
||||
/* Check for far procedure call, in which case, references to segment
|
||||
* registers are not be considered another parameter (i.e. they are
|
||||
* long references to another segment) */
|
||||
@@ -246,7 +246,7 @@ bool CallType::newStkArg(COND_EXPR *exp, llIcode opcode, Function * pproc)
|
||||
|
||||
/* Places the actual argument exp in the position given by pos in the
|
||||
* argument list of picode. */
|
||||
void CallType::placeStkArg (COND_EXPR *exp, Int pos)
|
||||
void CallType::placeStkArg (COND_EXPR *exp, int pos)
|
||||
{
|
||||
args->sym[pos].actual = exp;
|
||||
sprintf (args->sym[pos].name, "arg%ld", pos);
|
||||
@@ -259,7 +259,7 @@ void CallType::placeStkArg (COND_EXPR *exp, Int pos)
|
||||
void adjustActArgType (COND_EXPR *exp, hlType forType, Function * pproc)
|
||||
{
|
||||
hlType actType;
|
||||
Int offset, offL;
|
||||
int offset, offL;
|
||||
|
||||
if (exp == NULL)
|
||||
return;
|
||||
@@ -311,11 +311,11 @@ void adjustActArgType (COND_EXPR *exp, hlType forType, Function * pproc)
|
||||
/* Determines whether the formal argument has the same type as the given
|
||||
* type (type of the actual argument). If not, the formal argument is
|
||||
* changed its type */
|
||||
void STKFRAME::adjustForArgType(Int numArg_, hlType actType_)
|
||||
void STKFRAME::adjustForArgType(int numArg_, hlType actType_)
|
||||
{
|
||||
hlType forType;
|
||||
STKSYM * psym, * nsym;
|
||||
Int off, i;
|
||||
int off, i;
|
||||
|
||||
/* Find stack offset for this argument */
|
||||
off = m_minOff;
|
||||
|
||||
@@ -22,7 +22,7 @@ static boolT isJCond (llIcode opcode)
|
||||
|
||||
|
||||
/* Returns whether the conditions for a 2-3 long variable are satisfied */
|
||||
static boolT isLong23 (iICODE iter, BB * pbb, Int *off, Int *arc)
|
||||
static boolT isLong23 (iICODE iter, BB * pbb, int *off, int *arc)
|
||||
{
|
||||
BB * t, * e, * obb2;
|
||||
|
||||
@@ -59,7 +59,7 @@ static boolT isLong23 (iICODE iter, 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)
|
||||
static boolT isLong22 (iICODE pIcode, iICODE pEnd, int *off)
|
||||
{
|
||||
if(distance(pIcode,pEnd)<4)
|
||||
return false;
|
||||
@@ -82,7 +82,7 @@ static boolT isLong22 (iICODE pIcode, iICODE pEnd, Int *off)
|
||||
* @return number of ICODEs to skip
|
||||
|
||||
*/
|
||||
static int longJCond23 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode, Int arc, Int off)
|
||||
static int longJCond23 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode, int arc, int off)
|
||||
{
|
||||
BB * pbb, * obb1, * obb2, * tbb;
|
||||
int skipped_insn=0;
|
||||
@@ -169,7 +169,7 @@ static int longJCond23 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode, Int arc,
|
||||
*/
|
||||
static int longJCond22 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode,iICODE pEnd)
|
||||
{
|
||||
Int j;
|
||||
int j;
|
||||
BB * pbb, * obb1, * tbb;
|
||||
if(distance(pIcode,pEnd)<4)
|
||||
return false;
|
||||
@@ -227,9 +227,9 @@ static int longJCond22 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode,iICODE pEn
|
||||
* Arguments: i : index into the local identifier table
|
||||
* pLocId: ptr to the long local identifier
|
||||
* pProc : ptr to current procedure's record. */
|
||||
void Function::propLongStk (Int i, const ID &pLocId)
|
||||
void Function::propLongStk (int i, const ID &pLocId)
|
||||
{
|
||||
Int off, arc;
|
||||
int off, arc;
|
||||
Assignment asgn;
|
||||
//COND_EXPR *lhs, *rhs; /* Pointers to left and right hand expression */
|
||||
iICODE next1, pEnd;
|
||||
@@ -502,7 +502,7 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be
|
||||
* @arg pLocId ptr to the long local identifier
|
||||
*
|
||||
*/
|
||||
void Function::propLongReg (Int loc_ident_idx, const ID &pLocId)
|
||||
void Function::propLongReg (int loc_ident_idx, const ID &pLocId)
|
||||
{
|
||||
/* Process all definitions/uses of long registers at an icode position */
|
||||
// WARNING: this loop modifies the iterated-over container.
|
||||
@@ -526,7 +526,7 @@ void Function::propLongReg (Int loc_ident_idx, const ID &pLocId)
|
||||
|
||||
/* Propagates the long global address across all LOW_LEVEL icodes.
|
||||
* Transforms some LOW_LEVEL icodes into HIGH_LEVEL */
|
||||
void Function::propLongGlb (Int i, const ID &pLocId)
|
||||
void Function::propLongGlb (int i, const ID &pLocId)
|
||||
{
|
||||
printf("WARN: Function::propLongGlb not implemented");
|
||||
}
|
||||
@@ -536,7 +536,7 @@ void Function::propLongGlb (Int i, const ID &pLocId)
|
||||
* into HIGH_LEVEL icodes. */
|
||||
void Function::propLong()
|
||||
{
|
||||
Int i;
|
||||
int i;
|
||||
/* Pointer to current local identifier */
|
||||
|
||||
for (i = 0; i < localId.csym(); i++)
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <malloc.h> /* For free() */
|
||||
#include <string.h>
|
||||
|
||||
static Int numInt; /* Number of intervals */
|
||||
static int numInt; /* Number of intervals */
|
||||
|
||||
|
||||
#define nonEmpty(q) (q != NULL)
|
||||
@@ -84,7 +84,7 @@ static void appendNodeInt (queue &pqH, BB *node, interval *pI)
|
||||
auto found_iter=std::find(pqH.begin(),pqH.end(),node);
|
||||
if(found_iter!=pqH.end())
|
||||
{
|
||||
pI->numOutEdges -= (byte)(*found_iter)->inEdges.size() - 1;
|
||||
pI->numOutEdges -= (uint8_t)(*found_iter)->inEdges.size() - 1;
|
||||
pqH.erase(found_iter);
|
||||
}
|
||||
}
|
||||
@@ -103,7 +103,7 @@ void derSeq_Entry::findIntervals (Function *c)
|
||||
BB *h, /* Node being processed */
|
||||
*header, /* Current interval's header node */
|
||||
*succ; /* Successor basic block */
|
||||
Int i; /* Counter */
|
||||
int i; /* Counter */
|
||||
queue H; /* Queue of possible header nodes */
|
||||
boolT first = TRUE; /* First pass through the loop */
|
||||
|
||||
@@ -116,7 +116,7 @@ void derSeq_Entry::findIntervals (Function *c)
|
||||
{
|
||||
header = firstOfQueue (H);
|
||||
pI = new interval;
|
||||
pI->numInt = (byte)numInt++;
|
||||
pI->numInt = (uint8_t)numInt++;
|
||||
if (first) /* ^ to first interval */
|
||||
Ii = J = pI;
|
||||
appendNodeInt (H, header, pI); /* pI(header) = {header} */
|
||||
@@ -244,7 +244,7 @@ bool Function::nextOrderGraph (derSeq *derivedGi)
|
||||
*succ /* Successor node */
|
||||
;
|
||||
//queue *listIi; /* List of intervals */
|
||||
Int i, /* Index to outEdges array */
|
||||
int i, /* Index to outEdges array */
|
||||
j; /* Index to successors */
|
||||
boolT sameGraph; /* Boolean, isomorphic graphs */
|
||||
|
||||
@@ -313,7 +313,7 @@ return (boolT)(! sameGraph);
|
||||
/* Finds the derived sequence of the graph derivedG->Gi (ie. cfg).
|
||||
* Constructs the n-th order graph and places all the intermediate graphs
|
||||
* in the derivedG list sequence. */
|
||||
byte Function::findDerivedSeq (derSeq *derivedGi)
|
||||
uint8_t Function::findDerivedSeq (derSeq *derivedGi)
|
||||
{
|
||||
BB *Gi; /* Current derived sequence graph */
|
||||
|
||||
@@ -346,7 +346,7 @@ byte Function::findDerivedSeq (derSeq *derivedGi)
|
||||
|
||||
/* Converts the irreducible graph G into an equivalent reducible one, by
|
||||
* means of node splitting. */
|
||||
static void nodeSplitting (std::vector<BB *> &G)
|
||||
static void nodeSplitting (std::list<BB *> &G)
|
||||
{
|
||||
fprintf(stderr,"Attempt to perform node splitting: NOT IMPLEMENTED\n");
|
||||
}
|
||||
@@ -354,7 +354,7 @@ static void nodeSplitting (std::vector<BB *> &G)
|
||||
/* Displays the derived sequence and intervals of the graph G */
|
||||
void derSeq::display()
|
||||
{
|
||||
Int n = 1; /* Derived sequence number */
|
||||
int n = 1; /* Derived sequence number */
|
||||
printf ("\nDerived Sequence Intervals\n");
|
||||
derSeq::iterator iter=this->begin();
|
||||
while (iter!=this->end())
|
||||
@@ -374,7 +374,7 @@ void derSeq::display()
|
||||
derSeq * Function::checkReducibility()
|
||||
{
|
||||
derSeq * der_seq;
|
||||
byte reducible; /* Reducible graph flag */
|
||||
uint8_t reducible; /* Reducible graph flag */
|
||||
|
||||
numInt = 1; /* reinitialize no. of intervals*/
|
||||
stats.nOrder = 1; /* nOrder(cfg) = 1 */
|
||||
|
||||
238
src/scanner.cpp
238
src/scanner.cpp
@@ -10,46 +10,46 @@
|
||||
#include "dcc.h"
|
||||
#include "scanner.h"
|
||||
|
||||
static void rm(Int i);
|
||||
static void modrm(Int i);
|
||||
static void segrm(Int i);
|
||||
static void data1(Int i);
|
||||
static void data2(Int i);
|
||||
static void regop(Int i);
|
||||
static void segop(Int i);
|
||||
static void strop(Int i);
|
||||
static void escop(Int i);
|
||||
static void axImp(Int i);
|
||||
static void alImp(Int i);
|
||||
static void axSrcIm(Int i);
|
||||
static void memImp(Int i);
|
||||
static void memReg0(Int i);
|
||||
static void memOnly(Int i);
|
||||
static void dispM(Int i);
|
||||
static void dispS(Int i);
|
||||
static void dispN(Int i);
|
||||
static void dispF(Int i);
|
||||
static void prefix(Int i);
|
||||
static void immed(Int i);
|
||||
static void shift(Int i);
|
||||
static void arith(Int i);
|
||||
static void trans(Int i);
|
||||
static void const1(Int i);
|
||||
static void const3(Int i);
|
||||
static void none1(Int i);
|
||||
static void none2(Int i);
|
||||
static void checkInt(Int i);
|
||||
static void rm(int i);
|
||||
static void modrm(int i);
|
||||
static void segrm(int i);
|
||||
static void data1(int i);
|
||||
static void data2(int i);
|
||||
static void regop(int i);
|
||||
static void segop(int i);
|
||||
static void strop(int i);
|
||||
static void escop(int i);
|
||||
static void axImp(int i);
|
||||
static void alImp(int i);
|
||||
static void axSrcIm(int i);
|
||||
static void memImp(int i);
|
||||
static void memReg0(int i);
|
||||
static void memOnly(int i);
|
||||
static void dispM(int i);
|
||||
static void dispS(int i);
|
||||
static void dispN(int i);
|
||||
static void dispF(int i);
|
||||
static void prefix(int i);
|
||||
static void immed(int i);
|
||||
static void shift(int i);
|
||||
static void arith(int i);
|
||||
static void trans(int i);
|
||||
static void const1(int i);
|
||||
static void const3(int i);
|
||||
static void none1(int i);
|
||||
static void none2(int i);
|
||||
static void checkInt(int i);
|
||||
|
||||
#define iZERO (llIcode)0 // For neatness
|
||||
#define IC llIcode
|
||||
|
||||
static struct {
|
||||
void (*state1)(Int);
|
||||
void (*state2)(Int);
|
||||
flags32 flg;
|
||||
void (*state1)(int);
|
||||
void (*state2)(int);
|
||||
uint32_t flg;
|
||||
llIcode opcode;
|
||||
byte df;
|
||||
byte uf;
|
||||
uint8_t df;
|
||||
uint8_t uf;
|
||||
} stateTable[] = {
|
||||
{ modrm, none2, B , iADD , Sf | Zf | Cf , 0 }, /* 00 */
|
||||
{ modrm, none2, 0 , iADD , Sf | Zf | Cf , 0 }, /* 01 */
|
||||
@@ -309,8 +309,8 @@ static struct {
|
||||
{ trans, none1, NSP , iZERO , 0 , 0 } /* FF */
|
||||
} ;
|
||||
|
||||
static word SegPrefix, RepPrefix;
|
||||
static byte *pInst; /* Ptr. to current byte of instruction */
|
||||
static uint16_t SegPrefix, RepPrefix;
|
||||
static uint8_t *pInst; /* Ptr. to current uint8_t of instruction */
|
||||
static ICODE * pIcode; /* Ptr to Icode record filled in by scan() */
|
||||
|
||||
|
||||
@@ -318,13 +318,13 @@ static ICODE * pIcode; /* Ptr to Icode record filled in by scan() */
|
||||
Scans one machine instruction at offset ip in prog.Image and returns error.
|
||||
At the same time, fill in low-level icode details for the scanned inst.
|
||||
****************************************************************************/
|
||||
eErrorId scan(dword ip, ICODE &p)
|
||||
eErrorId scan(uint32_t ip, ICODE &p)
|
||||
{
|
||||
Int op;
|
||||
int op;
|
||||
p = ICODE();
|
||||
p.type = LOW_LEVEL;
|
||||
p.ic.ll.label = ip; /* ip is absolute offset into image*/
|
||||
if (ip >= (dword)prog.cbImage)
|
||||
if (ip >= (uint32_t)prog.cbImage)
|
||||
{
|
||||
return (IP_OUT_OF_RANGE);
|
||||
}
|
||||
@@ -349,7 +349,7 @@ eErrorId scan(dword ip, ICODE &p)
|
||||
if (p.ic.ll.opcode)
|
||||
{
|
||||
/* Save bytes of image used */
|
||||
p.ic.ll.numBytes = (byte)((pInst - prog.Image) - ip);
|
||||
p.ic.ll.numBytes = (uint8_t)((pInst - prog.Image) - ip);
|
||||
return ((SegPrefix)? FUNNY_SEGOVR: /* Seg. Override invalid */
|
||||
(RepPrefix ? FUNNY_REP: NO_ERR));/* REP prefix invalid */
|
||||
}
|
||||
@@ -359,12 +359,12 @@ eErrorId scan(dword ip, ICODE &p)
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
relocItem - returns TRUE if word pointed at is in relocation table
|
||||
relocItem - returns TRUE if uint16_t pointed at is in relocation table
|
||||
**************************************************************************/
|
||||
static boolT relocItem(byte *p)
|
||||
static boolT relocItem(uint8_t *p)
|
||||
{
|
||||
Int i;
|
||||
dword off = p - prog.Image;
|
||||
int i;
|
||||
uint32_t off = p - prog.Image;
|
||||
|
||||
for (i = 0; i < prog.cReloc; i++)
|
||||
if (prog.relocTable[i] == off)
|
||||
@@ -374,23 +374,23 @@ static boolT relocItem(byte *p)
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
getWord - returns next word from image
|
||||
getWord - returns next uint16_t from image
|
||||
**************************************************************************/
|
||||
static word getWord(void)
|
||||
static uint16_t getWord(void)
|
||||
{
|
||||
word w = LH(pInst);
|
||||
uint16_t w = LH(pInst);
|
||||
pInst += 2;
|
||||
return w;
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
signex - returns byte sign extended to Int
|
||||
signex - returns uint8_t sign extended to int
|
||||
***************************************************************************/
|
||||
static Int signex(byte b)
|
||||
static int signex(uint8_t b)
|
||||
{
|
||||
long s = b;
|
||||
return ((b & 0x80)? (Int)(0xFFFFFF00 | s): (Int)s);
|
||||
return ((b & 0x80)? (int)(0xFFFFFF00 | s): (int)s);
|
||||
}
|
||||
|
||||
|
||||
@@ -400,7 +400,7 @@ static Int signex(byte b)
|
||||
* Note: fdst == TRUE is for the r/m part of the field (dest, unless TO_REG)
|
||||
* fdst == FALSE is for reg part of the field
|
||||
***************************************************************************/
|
||||
static void setAddress(Int i, boolT fdst, word seg, int16 reg, word off)
|
||||
static void setAddress(int i, boolT fdst, uint16_t seg, int16_t reg, uint16_t off)
|
||||
{
|
||||
LLOperand *pm;
|
||||
|
||||
@@ -413,7 +413,7 @@ static void setAddress(Int i, boolT fdst, word seg, int16 reg, word off)
|
||||
* provide the value of this segment in the field segValue. */
|
||||
if (seg) /* segment override */
|
||||
{
|
||||
pm->seg = pm->segOver = (byte)seg;
|
||||
pm->seg = pm->segOver = (uint8_t)seg;
|
||||
}
|
||||
else
|
||||
{ /* no override, check indexed register */
|
||||
@@ -427,8 +427,8 @@ static void setAddress(Int i, boolT fdst, word seg, int16 reg, word off)
|
||||
pm->seg = rDS; /* any other indexed reg */
|
||||
}
|
||||
}
|
||||
pm->regi = (byte)reg;
|
||||
pm->off = (int16)off;
|
||||
pm->regi = (uint8_t)reg;
|
||||
pm->off = (int16_t)off;
|
||||
if (reg && reg < INDEXBASE && (stateTable[i].flg & B))
|
||||
{
|
||||
pm->regi += rAL - rAX;
|
||||
@@ -442,12 +442,12 @@ static void setAddress(Int i, boolT fdst, word seg, int16 reg, word off)
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
rm - Decodes r/m part of modrm byte for dst (unless TO_REG) part of icode
|
||||
rm - Decodes r/m part of modrm uint8_t for dst (unless TO_REG) part of icode
|
||||
***************************************************************************/
|
||||
static void rm(Int i)
|
||||
static void rm(int i)
|
||||
{
|
||||
byte mod = *pInst >> 6;
|
||||
byte rm = *pInst++ & 7;
|
||||
uint8_t mod = *pInst >> 6;
|
||||
uint8_t rm = *pInst++ & 7;
|
||||
|
||||
switch (mod) {
|
||||
case 0: /* No disp unless rm == 6 */
|
||||
@@ -458,11 +458,11 @@ static void rm(Int i)
|
||||
else setAddress(i, TRUE, SegPrefix, rm + INDEXBASE, 0);
|
||||
break;
|
||||
|
||||
case 1: /* 1 byte disp */
|
||||
setAddress(i, TRUE, SegPrefix, rm+INDEXBASE, (word)signex(*pInst++));
|
||||
case 1: /* 1 uint8_t disp */
|
||||
setAddress(i, TRUE, SegPrefix, rm+INDEXBASE, (uint16_t)signex(*pInst++));
|
||||
break;
|
||||
|
||||
case 2: /* 2 byte disp */
|
||||
case 2: /* 2 uint8_t disp */
|
||||
setAddress(i, TRUE, SegPrefix, rm + INDEXBASE, getWord());
|
||||
pIcode->ic.ll.flg |= WORD_OFF;
|
||||
break;
|
||||
@@ -479,9 +479,9 @@ static void rm(Int i)
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
modrm - Sets up src and dst from modrm byte
|
||||
modrm - Sets up src and dst from modrm uint8_t
|
||||
***************************************************************************/
|
||||
static void modrm(Int i)
|
||||
static void modrm(int i)
|
||||
{
|
||||
setAddress(i, FALSE, 0, REG(*pInst) + rAX, 0);
|
||||
rm(i);
|
||||
@@ -491,14 +491,14 @@ static void modrm(Int i)
|
||||
/****************************************************************************
|
||||
segrm - seg encoded as reg of modrm
|
||||
****************************************************************************/
|
||||
static void segrm(Int i)
|
||||
static void segrm(int i)
|
||||
{
|
||||
Int reg = REG(*pInst) + rES;
|
||||
int reg = REG(*pInst) + rES;
|
||||
|
||||
if (reg > rDS || (reg == rCS && (stateTable[i].flg & TO_REG)))
|
||||
pIcode->ic.ll.opcode = (llIcode)0;
|
||||
else {
|
||||
setAddress(i, FALSE, 0, (int16)reg, 0);
|
||||
setAddress(i, FALSE, 0, (int16_t)reg, 0);
|
||||
rm(i);
|
||||
}
|
||||
}
|
||||
@@ -507,9 +507,9 @@ static void segrm(Int i)
|
||||
/****************************************************************************
|
||||
regop - src/dst reg encoded as low 3 bits of opcode
|
||||
***************************************************************************/
|
||||
static void regop(Int i)
|
||||
static void regop(int i)
|
||||
{
|
||||
setAddress(i, FALSE, 0, ((int16)i & 7) + rAX, 0);
|
||||
setAddress(i, FALSE, 0, ((int16_t)i & 7) + rAX, 0);
|
||||
pIcode->ic.ll.dst.regi = pIcode->ic.ll.src.regi;
|
||||
}
|
||||
|
||||
@@ -517,28 +517,28 @@ static void regop(Int i)
|
||||
/*****************************************************************************
|
||||
segop - seg encoded in middle of opcode
|
||||
*****************************************************************************/
|
||||
static void segop(Int i)
|
||||
static void segop(int i)
|
||||
{
|
||||
setAddress(i, TRUE, 0, (((int16)i & 0x18) >> 3) + rES, 0);
|
||||
setAddress(i, TRUE, 0, (((int16_t)i & 0x18) >> 3) + rES, 0);
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
axImp - Plugs an implied AX dst
|
||||
***************************************************************************/
|
||||
static void axImp(Int i)
|
||||
static void axImp(int i)
|
||||
{
|
||||
setAddress(i, TRUE, 0, rAX, 0);
|
||||
}
|
||||
|
||||
/* Implied AX source */
|
||||
static void axSrcIm (Int )
|
||||
static void axSrcIm (int )
|
||||
{
|
||||
pIcode->ic.ll.src.regi = rAX;
|
||||
}
|
||||
|
||||
/* Implied AL source */
|
||||
static void alImp (Int )
|
||||
static void alImp (int )
|
||||
{
|
||||
pIcode->ic.ll.src.regi = rAL;
|
||||
}
|
||||
@@ -547,7 +547,7 @@ static void alImp (Int )
|
||||
/*****************************************************************************
|
||||
memImp - Plugs implied src memory operand with any segment override
|
||||
****************************************************************************/
|
||||
static void memImp(Int i)
|
||||
static void memImp(int i)
|
||||
{
|
||||
setAddress(i, FALSE, SegPrefix, 0, 0);
|
||||
}
|
||||
@@ -556,7 +556,7 @@ static void memImp(Int i)
|
||||
/****************************************************************************
|
||||
memOnly - Instruction is not valid if modrm refers to register (i.e. mod == 3)
|
||||
***************************************************************************/
|
||||
static void memOnly(Int )
|
||||
static void memOnly(int )
|
||||
{
|
||||
if ((*pInst & 0xC0) == 0xC0)
|
||||
pIcode->ic.ll.opcode = (llIcode)0;
|
||||
@@ -566,7 +566,7 @@ static void memOnly(Int )
|
||||
/****************************************************************************
|
||||
memReg0 - modrm for 'memOnly' and Reg field must also be 0
|
||||
****************************************************************************/
|
||||
static void memReg0(Int i)
|
||||
static void memReg0(int i)
|
||||
{
|
||||
if (REG(*pInst) || (*pInst & 0xC0) == 0xC0)
|
||||
pIcode->ic.ll.opcode = (llIcode)0;
|
||||
@@ -576,12 +576,12 @@ static void memReg0(Int i)
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
immed - Sets up dst and opcode from modrm byte
|
||||
immed - Sets up dst and opcode from modrm uint8_t
|
||||
**************************************************************************/
|
||||
static void immed(Int i)
|
||||
static void immed(int i)
|
||||
{
|
||||
static llIcode immedTable[8] = {iADD, iOR, iADC, iSBB, iAND, iSUB, iXOR, iCMP};
|
||||
static byte uf[8] = { 0, 0, Cf, Cf, 0, 0, 0, 0 };
|
||||
static uint8_t uf[8] = { 0, 0, Cf, Cf, 0, 0, 0, 0 };
|
||||
|
||||
pIcode->ic.ll.opcode = immedTable[REG(*pInst)];
|
||||
pIcode->ic.ll.flagDU.u = uf[REG(*pInst)];
|
||||
@@ -594,16 +594,16 @@ static void immed(Int i)
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
shift - Sets up dst and opcode from modrm byte
|
||||
shift - Sets up dst and opcode from modrm uint8_t
|
||||
***************************************************************************/
|
||||
static void shift(Int i)
|
||||
static void shift(int i)
|
||||
{
|
||||
static llIcode shiftTable[8] =
|
||||
{
|
||||
(llIcode)iROL, (llIcode)iROR, (llIcode)iRCL, (llIcode)iRCR,
|
||||
(llIcode)iSHL, (llIcode)iSHR, (llIcode)0, (llIcode)iSAR};
|
||||
static byte uf[8] = {0, 0, Cf, Cf, 0, 0, 0, 0 };
|
||||
static byte df[8] = {Cf, Cf, Cf, Cf, Sf | Zf | Cf,
|
||||
static uint8_t uf[8] = {0, 0, Cf, Cf, 0, 0, 0, 0 };
|
||||
static uint8_t df[8] = {Cf, Cf, Cf, Cf, Sf | Zf | Cf,
|
||||
Sf | Zf | Cf, 0, Sf | Zf | Cf};
|
||||
|
||||
pIcode->ic.ll.opcode = shiftTable[REG(*pInst)];
|
||||
@@ -615,18 +615,18 @@ static void shift(Int i)
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
trans - Sets up dst and opcode from modrm byte
|
||||
trans - Sets up dst and opcode from modrm uint8_t
|
||||
***************************************************************************/
|
||||
static void trans(Int i)
|
||||
static void trans(int i)
|
||||
{
|
||||
static llIcode transTable[8] =
|
||||
{
|
||||
(llIcode)iINC, (llIcode)iDEC, (llIcode)iCALL, (llIcode)iCALLF,
|
||||
(llIcode)iJMP, (llIcode)iJMPF,(llIcode)iPUSH, (llIcode)0
|
||||
};
|
||||
static byte df[8] = {Sf | Zf, Sf | Zf, 0, 0, 0, 0, 0, 0};
|
||||
static uint8_t df[8] = {Sf | Zf, Sf | Zf, 0, 0, 0, 0, 0, 0};
|
||||
|
||||
if ((byte)REG(*pInst) < 2 || !(stateTable[i].flg & B)) { /* INC & DEC */
|
||||
if ((uint8_t)REG(*pInst) < 2 || !(stateTable[i].flg & B)) { /* INC & DEC */
|
||||
pIcode->ic.ll.opcode = transTable[REG(*pInst)]; /* valid on bytes */
|
||||
pIcode->ic.ll.flagDU.d = df[REG(*pInst)];
|
||||
rm(i);
|
||||
@@ -640,16 +640,16 @@ static void trans(Int i)
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
arith - Sets up dst and opcode from modrm byte
|
||||
arith - Sets up dst and opcode from modrm uint8_t
|
||||
****************************************************************************/
|
||||
static void arith(Int i)
|
||||
{ byte opcode;
|
||||
static void arith(int i)
|
||||
{ uint8_t opcode;
|
||||
static llIcode arithTable[8] =
|
||||
{
|
||||
(llIcode)iTEST, (llIcode)0, (llIcode)iNOT, (llIcode)iNEG,
|
||||
(llIcode)iMUL, (llIcode)iIMUL, (llIcode)iDIV, (llIcode)iIDIV
|
||||
};
|
||||
static byte df[8] = {Sf | Zf | Cf, 0, 0, Sf | Zf | Cf,
|
||||
static uint8_t df[8] = {Sf | Zf | Cf, 0, 0, Sf | Zf | Cf,
|
||||
Sf | Zf | Cf, Sf | Zf | Cf, Sf | Zf | Cf,
|
||||
Sf | Zf | Cf};
|
||||
|
||||
@@ -680,9 +680,9 @@ static void arith(Int i)
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
data1 - Sets up immed from 1 byte data
|
||||
data1 - Sets up immed from 1 uint8_t data
|
||||
*****************************************************************************/
|
||||
static void data1(Int i)
|
||||
static void data1(int i)
|
||||
{
|
||||
pIcode->ic.ll.src.SetImmediateOp( (stateTable[i].flg & S_EXT)? signex(*pInst++): *pInst++ );
|
||||
pIcode->ic.ll.flg |= I;
|
||||
@@ -690,9 +690,9 @@ static void data1(Int i)
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
data2 - Sets up immed from 2 byte data
|
||||
data2 - Sets up immed from 2 uint8_t data
|
||||
****************************************************************************/
|
||||
static void data2(Int )
|
||||
static void data2(int )
|
||||
{
|
||||
if (relocItem(pInst))
|
||||
pIcode->ic.ll.flg |= SEG_IMMED;
|
||||
@@ -714,60 +714,60 @@ static void data2(Int )
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
dispM - 2 byte offset without modrm (== mod 0, rm 6) (Note:TO_REG bits are
|
||||
dispM - 2 uint8_t offset without modrm (== mod 0, rm 6) (Note:TO_REG bits are
|
||||
reversed)
|
||||
****************************************************************************/
|
||||
static void dispM(Int i)
|
||||
static void dispM(int i)
|
||||
{
|
||||
setAddress(i, FALSE, SegPrefix, 0, getWord());
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
dispN - 2 byte disp as immed relative to ip
|
||||
dispN - 2 uint8_t disp as immed relative to ip
|
||||
****************************************************************************/
|
||||
static void dispN(Int )
|
||||
static void dispN(int )
|
||||
{
|
||||
long off = (short)getWord(); /* Signed displacement */
|
||||
|
||||
/* Note: the result of the subtraction could be between 32k and 64k, and
|
||||
still be positive; it is an offset from prog.Image. So this must be
|
||||
treated as unsigned */
|
||||
pIcode->ic.ll.src.SetImmediateOp((dword)(off + (unsigned)(pInst - prog.Image)));
|
||||
pIcode->ic.ll.src.SetImmediateOp((uint32_t)(off + (unsigned)(pInst - prog.Image)));
|
||||
pIcode->ic.ll.flg |= I;
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
dispS - 1 byte disp as immed relative to ip
|
||||
dispS - 1 uint8_t disp as immed relative to ip
|
||||
***************************************************************************/
|
||||
static void dispS(Int )
|
||||
static void dispS(int )
|
||||
{
|
||||
long off = signex(*pInst++); /* Signed displacement */
|
||||
|
||||
pIcode->ic.ll.src.SetImmediateOp((dword)(off + (unsigned)(pInst - prog.Image)));
|
||||
pIcode->ic.ll.src.SetImmediateOp((uint32_t)(off + (unsigned)(pInst - prog.Image)));
|
||||
pIcode->ic.ll.flg |= I;
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
dispF - 4 byte disp as immed 20-bit target address
|
||||
dispF - 4 uint8_t disp as immed 20-bit target address
|
||||
***************************************************************************/
|
||||
static void dispF(Int )
|
||||
static void dispF(int )
|
||||
{
|
||||
dword off = (unsigned)getWord();
|
||||
dword seg = (unsigned)getWord();
|
||||
uint32_t off = (unsigned)getWord();
|
||||
uint32_t seg = (unsigned)getWord();
|
||||
|
||||
pIcode->ic.ll.src.SetImmediateOp(off + ((dword)(unsigned)seg << 4));
|
||||
pIcode->ic.ll.src.SetImmediateOp(off + ((uint32_t)(unsigned)seg << 4));
|
||||
pIcode->ic.ll.flg |= I;
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
prefix - picks up prefix byte for following instruction (LOCK is ignored
|
||||
prefix - picks up prefix uint8_t for following instruction (LOCK is ignored
|
||||
on purpose)
|
||||
****************************************************************************/
|
||||
static void prefix(Int )
|
||||
static void prefix(int )
|
||||
{
|
||||
if (pIcode->ic.ll.opcode == iREPE || pIcode->ic.ll.opcode == iREPNE)
|
||||
RepPrefix = pIcode->ic.ll.opcode;
|
||||
@@ -783,7 +783,7 @@ inline void BumpOpcode(llIcode& ic)
|
||||
/*****************************************************************************
|
||||
strop - checks RepPrefix and converts string instructions accordingly
|
||||
*****************************************************************************/
|
||||
static void strop(Int )
|
||||
static void strop(int )
|
||||
{
|
||||
if (RepPrefix)
|
||||
{
|
||||
@@ -804,9 +804,9 @@ static void strop(Int )
|
||||
/***************************************************************************
|
||||
escop - esc operands
|
||||
***************************************************************************/
|
||||
static void escop(Int i)
|
||||
static void escop(int i)
|
||||
{
|
||||
pIcode->ic.ll.src.SetImmediateOp(REG(*pInst) + (dword)((i & 7) << 3));
|
||||
pIcode->ic.ll.src.SetImmediateOp(REG(*pInst) + (uint32_t)((i & 7) << 3));
|
||||
pIcode->ic.ll.flg |= I;
|
||||
rm(i);
|
||||
}
|
||||
@@ -815,7 +815,7 @@ static void escop(Int i)
|
||||
/****************************************************************************
|
||||
const1
|
||||
****************************************************************************/
|
||||
static void const1(Int )
|
||||
static void const1(int )
|
||||
{
|
||||
pIcode->ic.ll.src.SetImmediateOp(1);
|
||||
pIcode->ic.ll.flg |= I;
|
||||
@@ -825,7 +825,7 @@ static void const1(Int )
|
||||
/*****************************************************************************
|
||||
const3
|
||||
****************************************************************************/
|
||||
static void const3(Int )
|
||||
static void const3(int )
|
||||
{
|
||||
pIcode->ic.ll.src.SetImmediateOp(3);
|
||||
pIcode->ic.ll.flg |= I;
|
||||
@@ -835,7 +835,7 @@ static void const3(Int )
|
||||
/****************************************************************************
|
||||
none1
|
||||
****************************************************************************/
|
||||
static void none1(Int )
|
||||
static void none1(int )
|
||||
{
|
||||
}
|
||||
|
||||
@@ -843,7 +843,7 @@ static void none1(Int )
|
||||
/****************************************************************************
|
||||
none2 - Sets the NO_OPS flag if the operand is immediate
|
||||
****************************************************************************/
|
||||
static void none2(Int )
|
||||
static void none2(int )
|
||||
{
|
||||
if (pIcode->ic.ll.flg & I)
|
||||
pIcode->ic.ll.flg |= NO_OPS;
|
||||
@@ -852,9 +852,9 @@ static void none2(Int )
|
||||
/****************************************************************************
|
||||
Checks for int 34 to int 3B - if so, converts to ESC nn instruction
|
||||
****************************************************************************/
|
||||
static void checkInt(Int )
|
||||
static void checkInt(int )
|
||||
{
|
||||
word wOp = (word) pIcode->ic.ll.src.op();
|
||||
uint16_t wOp = (uint16_t) pIcode->ic.ll.src.op();
|
||||
if ((wOp >= 0x34) && (wOp <= 0x3B))
|
||||
{
|
||||
/* This is a Borland/Microsoft floating point emulation instruction.
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
\* * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/* This file implements a symbol table with a symbolic name, a symbol value
|
||||
(word), and a procedure number. Two tables are maintained, to be able to
|
||||
(uint16_t), and a procedure number. Two tables are maintained, to be able to
|
||||
look up by name or by value. Pointers are used for the duplicated symbolic
|
||||
name to save space. Both tables have the same structure.
|
||||
The hash tables automatically expand when they get 90% full; they are
|
||||
@@ -30,7 +30,7 @@
|
||||
#define TABLESIZE 16 /* Number of entries added each expansion */
|
||||
/* Probably has to be a power of 2 */
|
||||
#define STRTABSIZE 256 /* Size string table is inc'd by */
|
||||
#define NIL ((word)-1)
|
||||
#define NIL ((uint16_t)-1)
|
||||
using namespace std;
|
||||
static char *pStrTab; /* Pointer to the current string table */
|
||||
static int strTabNext; /* Next free index into pStrTab */
|
||||
@@ -41,8 +41,8 @@ struct hash<SYMTABLE> : public unary_function<const SYMTABLE &,size_t>
|
||||
{
|
||||
size_t operator()(const SYMTABLE & key) const
|
||||
{
|
||||
word h = 0;
|
||||
h = (word)(key.symOff ^ (key.symOff >> 8));
|
||||
uint16_t h = 0;
|
||||
h = (uint16_t)(key.symOff ^ (key.symOff >> 8));
|
||||
return h;
|
||||
}
|
||||
|
||||
@@ -55,15 +55,15 @@ struct TABLEINFO_TYPE
|
||||
{
|
||||
symTab=valTab=0;
|
||||
}
|
||||
void deleteVal(dword symOff, Function *symProc, boolT bSymToo);
|
||||
void deleteVal(uint32_t symOff, Function *symProc, boolT bSymToo);
|
||||
void create(tableType type);
|
||||
void destroy();
|
||||
private:
|
||||
|
||||
SYMTABLE *symTab; /* Pointer to the symbol hashed table */
|
||||
SYMTABLE *valTab; /* Pointer to the value hashed table */
|
||||
word numEntry; /* Number of entries in this table */
|
||||
word tableSize;/* Size of the table (entries) */
|
||||
uint16_t numEntry; /* Number of entries in this table */
|
||||
uint16_t tableSize;/* Size of the table (entries) */
|
||||
unordered_map<string,SYMTABLE> z;
|
||||
unordered_map<SYMTABLE,string> z2;
|
||||
};
|
||||
@@ -133,7 +133,7 @@ void destroySymTables(void)
|
||||
}
|
||||
|
||||
/* Using the value, read the symbolic name */
|
||||
boolT readVal(std::ostringstream &symName, dword symOff, Function * symProc)
|
||||
boolT readVal(std::ostringstream &symName, uint32_t symOff, Function * symProc)
|
||||
{
|
||||
return false; // no symbolic names for now
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user