Fixes to libdisasm, also use it a bit more
This commit is contained in:
@@ -408,7 +408,6 @@ ICODE &BB::back()
|
||||
|
||||
size_t BB::size()
|
||||
{
|
||||
|
||||
return distance(instructions.begin(),instructions.end());
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ void JumpTable::pruneEntries(uint16_t cs)
|
||||
PROG *prg(Project::get()->binary());
|
||||
for (uint32_t i = start; i < finish; i += 2)
|
||||
{
|
||||
uint32_t target = cs + LH(&prg->Image[i]);
|
||||
uint32_t target = cs + LH(&prg->image()[i]);
|
||||
if (target < finish && target >= start)
|
||||
finish = target;
|
||||
else if (target >= (uint32_t)prg->cbImage)
|
||||
@@ -23,9 +23,9 @@ void JumpTable::pruneEntries(uint16_t cs)
|
||||
ICODE _Icode; // used as scan input
|
||||
for (uint32_t i = start; i < finish; i += 2)
|
||||
{
|
||||
uint32_t target = cs + LH(&prg->Image[i]);
|
||||
uint32_t target = cs + LH(&prg->image()[i]);
|
||||
/* Be wary of 00 00 as code - it's probably data */
|
||||
if (! (prg->Image[target] || prg->Image[target+1]) || scan(target, _Icode))
|
||||
if (! (prg->image()[target] || prg->image()[target+1]) || scan(target, _Icode))
|
||||
finish = i;
|
||||
}
|
||||
|
||||
|
||||
501
src/ast.cpp
501
src/ast.cpp
@@ -9,11 +9,24 @@
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include <boost/range.hpp>
|
||||
#include <boost/range/adaptors.hpp>
|
||||
#include <boost/range/algorithm.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
|
||||
#include "types.h"
|
||||
#include "dcc.h"
|
||||
#include "ast.h"
|
||||
#include "bundle.h"
|
||||
#include "machine_x86.h"
|
||||
#include "project.h"
|
||||
using namespace std;
|
||||
using namespace boost;
|
||||
using namespace boost::adaptors;
|
||||
extern int strSize (const uint8_t *, char);
|
||||
extern char *cChar(uint8_t c);
|
||||
|
||||
|
||||
|
||||
// Conditional operator symbols in C. Index by condOp enumeration type
|
||||
static const char * const condOpSym[] = { " <= ", " < ", " == ", " != ", " > ", " >= ",
|
||||
" & ", " | ", " ^ ", " ~ ",
|
||||
@@ -97,61 +110,27 @@ void ICODE::copyDU(const ICODE &duIcode, operDu _du, operDu duDu)
|
||||
|
||||
|
||||
/* Returns an identifier conditional expression node of type GLOB_VAR */
|
||||
AstIdent *GlobalVariable::Create(int16_t segValue, int16_t off)
|
||||
GlobalVariable::GlobalVariable(int16_t segValue, int16_t off)
|
||||
{
|
||||
AstIdent *newExp;
|
||||
uint32_t adr;
|
||||
|
||||
newExp = new AstIdent();
|
||||
newExp->ident.idType = GLOB_VAR;
|
||||
valid = true;
|
||||
ident.idType = GLOB_VAR;
|
||||
adr = opAdr(segValue, off);
|
||||
auto i=Project::get()->getSymIdxByAdd(adr);
|
||||
if ( not Project::get()->validSymIdx(i) )
|
||||
{
|
||||
printf ("Error, glob var not found in symtab\n");
|
||||
delete newExp;
|
||||
return 0;
|
||||
valid = false;
|
||||
}
|
||||
newExp->ident.idNode.globIdx = i;
|
||||
return (newExp);
|
||||
globIdx = i;
|
||||
}
|
||||
|
||||
|
||||
/* Returns an identifier conditional expression node of type REGISTER */
|
||||
AstIdent *AstIdent::Reg(eReg regi, uint32_t icodeFlg, LOCAL_ID *locsym)
|
||||
string GlobalVariable::walkCondExpr(Function *, int *) const
|
||||
{
|
||||
AstIdent *newExp;
|
||||
|
||||
newExp = new AstIdent();
|
||||
newExp->ident.idType = REGISTER;
|
||||
hlType type_sel;
|
||||
regType reg_type;
|
||||
if ((icodeFlg & B) || (icodeFlg & SRC_B))
|
||||
{
|
||||
type_sel = TYPE_BYTE_SIGN;
|
||||
reg_type = BYTE_REG;
|
||||
}
|
||||
else /* uint16_t */
|
||||
{
|
||||
type_sel = TYPE_WORD_SIGN;
|
||||
reg_type = WORD_REG;
|
||||
}
|
||||
newExp->ident.idNode.regiIdx = locsym->newByteWordReg(type_sel, regi);
|
||||
newExp->ident.regiType = reg_type;
|
||||
return (newExp);
|
||||
}
|
||||
|
||||
|
||||
/* Returns an identifier conditional expression node of type REGISTER */
|
||||
AstIdent *AstIdent::RegIdx(int idx, regType reg_type)
|
||||
{
|
||||
AstIdent *newExp;
|
||||
|
||||
newExp = new AstIdent();
|
||||
newExp->ident.idType = REGISTER;
|
||||
newExp->ident.regiType = reg_type;
|
||||
newExp->ident.idNode.regiIdx = idx;
|
||||
return (newExp);
|
||||
if(valid)
|
||||
return Project::get()->symtab[globIdx].name;
|
||||
else
|
||||
return "INVALID GlobalVariable";
|
||||
}
|
||||
|
||||
/* Returns an identifier conditional expression node of type LOCAL_VAR */
|
||||
@@ -177,7 +156,7 @@ AstIdent *AstIdent::Loc(int off, LOCAL_ID *localId)
|
||||
|
||||
|
||||
/* Returns an identifier conditional expression node of type PARAM */
|
||||
AstIdent *AstIdent::idParam(int off, const STKFRAME * argSymtab)
|
||||
AstIdent *AstIdent::Param(int off, const STKFRAME * argSymtab)
|
||||
{
|
||||
AstIdent *newExp;
|
||||
|
||||
@@ -193,11 +172,10 @@ AstIdent *AstIdent::idParam(int off, const STKFRAME * argSymtab)
|
||||
|
||||
/* Returns an identifier conditional expression node of type GLOB_VAR_IDX.
|
||||
* This global variable is indexed by regi. */
|
||||
AstIdent *idCondExpIdxGlob (int16_t segValue, int16_t off, uint8_t regi, const LOCAL_ID *locSym)
|
||||
GlobalVariableIdx::GlobalVariableIdx (int16_t segValue, int16_t off, uint8_t regi, const LOCAL_ID *locSym)
|
||||
{
|
||||
size_t i;
|
||||
AstIdent *newExp = new AstIdent();
|
||||
newExp->ident.idType = GLOB_VAR_IDX;
|
||||
ident.type(GLOB_VAR_IDX);
|
||||
for (i = 0; i < locSym->csym(); i++)
|
||||
{
|
||||
const BWGLB_TYPE &lID(locSym->id_arr[i].id.bwGlb);
|
||||
@@ -206,19 +184,14 @@ AstIdent *idCondExpIdxGlob (int16_t segValue, int16_t off, uint8_t regi, const L
|
||||
}
|
||||
if (i == locSym->csym())
|
||||
printf ("Error, indexed-glob var not found in local id table\n");
|
||||
newExp->ident.idNode.idxGlbIdx = i;
|
||||
return (newExp);
|
||||
idxGlbIdx = i;
|
||||
}
|
||||
|
||||
|
||||
/* Returns an identifier conditional expression node of type CONSTANT */
|
||||
AstIdent *AstIdent::Kte(uint32_t kte, uint8_t size)
|
||||
string GlobalVariableIdx::walkCondExpr(Function *pProc, int *) const
|
||||
{
|
||||
AstIdent *newExp = new AstIdent();
|
||||
newExp->ident.idType = CONSTANT;
|
||||
newExp->ident.idNode.kte.kte = kte;
|
||||
newExp->ident.idNode.kte.size = size;
|
||||
return (newExp);
|
||||
ostringstream o;
|
||||
auto bwGlb = &pProc->localId.id_arr[idxGlbIdx].id.bwGlb;
|
||||
o << (bwGlb->seg << 4) + bwGlb->off << "["<<Machine_X86::regName(bwGlb->regi)<<"]";
|
||||
return o.str();
|
||||
}
|
||||
|
||||
|
||||
@@ -232,27 +205,34 @@ AstIdent *AstIdent::LongIdx (int idx)
|
||||
return (newExp);
|
||||
}
|
||||
|
||||
AstIdent *AstIdent::String(uint32_t idx)
|
||||
{
|
||||
AstIdent *newExp = new AstIdent;
|
||||
newExp->ident.idNode.strIdx = idx;
|
||||
newExp->ident.type(STRING);
|
||||
return newExp;
|
||||
}
|
||||
|
||||
|
||||
/* Returns an identifier conditional expression node of type LONG_VAR */
|
||||
AstIdent *AstIdent::idLong(LOCAL_ID *localId, opLoc sd, iICODE pIcode, hlFirst f, iICODE ix, operDu du, LLInst &atOffset)
|
||||
AstIdent *AstIdent::Long(LOCAL_ID *localId, opLoc sd, iICODE pIcode, hlFirst f, iICODE ix, operDu du, LLInst &atOffset)
|
||||
{
|
||||
int idx;
|
||||
AstIdent *newExp = new AstIdent();
|
||||
AstIdent *newExp;
|
||||
/* Check for long constant and save it as a constant expression */
|
||||
if ((sd == SRC) && pIcode->ll()->testFlags(I)) /* constant */
|
||||
{
|
||||
newExp->ident.idType = CONSTANT;
|
||||
int value;
|
||||
if (f == HIGH_FIRST)
|
||||
value = (pIcode->ll()->src().getImm2() << 16) + atOffset.src().getImm2();
|
||||
else/* LOW_FIRST */
|
||||
value = (atOffset.src().getImm2() << 16)+ pIcode->ll()->src().getImm2();
|
||||
newExp->ident.idNode.kte.kte = value;
|
||||
newExp->ident.idNode.kte.size = 4;
|
||||
newExp = new Constant(value,4);
|
||||
}
|
||||
/* Save it as a long expression (reg, stack or glob) */
|
||||
else
|
||||
{
|
||||
newExp = new AstIdent();
|
||||
idx = localId->newLong(sd, pIcode, f, ix, du, atOffset);
|
||||
newExp->ident.idType = LONG_VAR;
|
||||
newExp->ident.idNode.longIdx = idx;
|
||||
@@ -260,19 +240,6 @@ AstIdent *AstIdent::idLong(LOCAL_ID *localId, opLoc sd, iICODE pIcode, hlFirst f
|
||||
return (newExp);
|
||||
}
|
||||
|
||||
|
||||
/* Returns an identifier conditional expression node of type FUNCTION */
|
||||
AstIdent *AstIdent::idFunc(Function * pproc, STKFRAME * args)
|
||||
{
|
||||
AstIdent *newExp = new AstIdent();
|
||||
|
||||
newExp->ident.idType = FUNCTION;
|
||||
newExp->ident.idNode.call.proc = pproc;
|
||||
newExp->ident.idNode.call.args = args;
|
||||
return (newExp);
|
||||
}
|
||||
|
||||
|
||||
/* Returns an identifier conditional expression node of type OTHER.
|
||||
* Temporary solution, should really be encoded as an indexed type (eg.
|
||||
* arrays). */
|
||||
@@ -291,20 +258,26 @@ AstIdent *AstIdent::Other(eReg seg, eReg regi, int16_t off)
|
||||
* TYPE_WORD_SIGN */
|
||||
AstIdent *AstIdent::idID (const ID *retVal, LOCAL_ID *locsym, iICODE ix_)
|
||||
{
|
||||
AstIdent *newExp = new AstIdent();
|
||||
int idx;
|
||||
|
||||
if (retVal->type == TYPE_LONG_SIGN)
|
||||
AstIdent *newExp=nullptr;
|
||||
switch(retVal->type)
|
||||
{
|
||||
idx = locsym->newLongReg (TYPE_LONG_SIGN, retVal->id.longId.h,retVal->id.longId.l, ix_);
|
||||
newExp->ident.idType = LONG_VAR;
|
||||
newExp->ident.idNode.longIdx = idx;
|
||||
}
|
||||
else if (retVal->type == TYPE_WORD_SIGN)
|
||||
{
|
||||
newExp->ident.idType = REGISTER;
|
||||
newExp->ident.idNode.regiIdx = locsym->newByteWordReg(TYPE_WORD_SIGN, retVal->id.regi);
|
||||
newExp->ident.regiType = WORD_REG;
|
||||
case TYPE_LONG_SIGN:
|
||||
{
|
||||
newExp = new AstIdent();
|
||||
idx = locsym->newLongReg (TYPE_LONG_SIGN, retVal->id.longId.h,retVal->id.longId.l, ix_);
|
||||
newExp->ident.idType = LONG_VAR;
|
||||
newExp->ident.idNode.longIdx = idx;
|
||||
break;
|
||||
}
|
||||
case TYPE_WORD_SIGN:
|
||||
newExp = new RegisterNode(locsym->newByteWordReg(retVal->type, retVal->id.regi),WORD_REG);
|
||||
break;
|
||||
case TYPE_BYTE_SIGN:
|
||||
newExp = new RegisterNode(locsym->newByteWordReg(retVal->type, retVal->id.regi),BYTE_REG);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"AstIdent::idID unhandled type %d\n",retVal->type);
|
||||
}
|
||||
return (newExp);
|
||||
}
|
||||
@@ -315,9 +288,9 @@ AstIdent *AstIdent::idID (const ID *retVal, LOCAL_ID *locsym, iICODE ix_)
|
||||
* Arguments:
|
||||
* duIcode: icode instruction that needs the du set.
|
||||
* du: operand is defined or used in current instruction. */
|
||||
COND_EXPR *AstIdent::id(const LLInst &ll_insn, opLoc sd, Function * pProc, iICODE ix_,ICODE &duIcode, operDu du)
|
||||
Expr *AstIdent::id(const LLInst &ll_insn, opLoc sd, Function * pProc, iICODE ix_,ICODE &duIcode, operDu du)
|
||||
{
|
||||
COND_EXPR *newExp;
|
||||
Expr *newExp;
|
||||
|
||||
int idx; /* idx into pIcode->localId table */
|
||||
|
||||
@@ -335,35 +308,33 @@ COND_EXPR *AstIdent::id(const LLInst &ll_insn, opLoc sd, Function * pProc, iICOD
|
||||
|
||||
else if ((sd == DST) && ll_insn.testFlags(IM_TMP_DST))
|
||||
{ /* implicit tmp */
|
||||
newExp = AstIdent::Reg (rTMP, 0, &pProc->localId);
|
||||
newExp = new RegisterNode(rTMP, 0, &pProc->localId);
|
||||
duIcode.setRegDU(rTMP, (operDu)eUSE);
|
||||
}
|
||||
|
||||
else if ((sd == SRC) && ll_insn.testFlags(I)) /* constant */
|
||||
newExp = AstIdent::Kte (ll_insn.src().getImm2(), 2);
|
||||
newExp = new Constant(ll_insn.src().getImm2(), 2);
|
||||
else if (pm.regi == rUNDEF) /* global variable */
|
||||
newExp = GlobalVariable::Create(pm.segValue, pm.off);
|
||||
newExp = new GlobalVariable(pm.segValue, pm.off);
|
||||
else if ( pm.isReg() ) /* register */
|
||||
{
|
||||
newExp = AstIdent::Reg (pm.regi, (sd == SRC) ? ll_insn.getFlag() :
|
||||
ll_insn.getFlag() & NO_SRC_B,
|
||||
&pProc->localId);
|
||||
newExp = new RegisterNode(pm.regi, (sd == SRC) ? ll_insn.getFlag() : ll_insn.getFlag() & NO_SRC_B, &pProc->localId);
|
||||
duIcode.setRegDU( pm.regi, du);
|
||||
}
|
||||
|
||||
else if (pm.off) /* offset */
|
||||
{
|
||||
{ // TODO: this is ABI specific, should be actually based on Function calling conv
|
||||
if ((pm.seg == rSS) && (pm.regi == INDEX_BP)) /* idx on bp */
|
||||
{
|
||||
if (pm.off >= 0) /* argument */
|
||||
newExp = AstIdent::idParam (pm.off, &pProc->args);
|
||||
newExp = AstIdent::Param (pm.off, &pProc->args);
|
||||
else /* local variable */
|
||||
newExp = AstIdent::Loc (pm.off, &pProc->localId);
|
||||
}
|
||||
else if ((pm.seg == rDS) && (pm.regi == INDEX_BX)) /* bx */
|
||||
{
|
||||
if (pm.off > 0) /* global variable */
|
||||
newExp = idCondExpIdxGlob (pm.segValue, pm.off, rBX,&pProc->localId);
|
||||
newExp = new GlobalVariableIdx(pm.segValue, pm.off, rBX,&pProc->localId);
|
||||
else
|
||||
newExp = AstIdent::Other (pm.seg, pm.regi, pm.off);
|
||||
duIcode.setRegDU( rBX, eUSE);
|
||||
@@ -377,26 +348,18 @@ COND_EXPR *AstIdent::id(const LLInst &ll_insn, opLoc sd, Function * pProc, iICOD
|
||||
{
|
||||
if ((pm.seg == rDS) && (pm.regi > INDEX_BP_DI)) /* dereference */
|
||||
{
|
||||
eReg selected;
|
||||
switch (pm.regi) {
|
||||
case INDEX_SI:
|
||||
newExp = AstIdent::Reg(rSI, 0, &pProc->localId);
|
||||
duIcode.setRegDU( rSI, du);
|
||||
break;
|
||||
case INDEX_DI:
|
||||
newExp = AstIdent::Reg(rDI, 0, &pProc->localId);
|
||||
duIcode.setRegDU( rDI, du);
|
||||
break;
|
||||
case INDEX_BP:
|
||||
newExp = AstIdent::Reg(rBP, 0, &pProc->localId);
|
||||
break;
|
||||
case INDEX_BX:
|
||||
newExp = AstIdent::Reg(rBX, 0, &pProc->localId);
|
||||
duIcode.setRegDU( rBX, du);
|
||||
break;
|
||||
case INDEX_SI: selected = rSI; break;
|
||||
case INDEX_DI: selected = rDI; break;
|
||||
case INDEX_BP: selected = rBP; break;
|
||||
case INDEX_BX: selected = rBX; break;
|
||||
default:
|
||||
newExp = 0;
|
||||
assert(false);
|
||||
}
|
||||
newExp = new RegisterNode(selected, 0, &pProc->localId);
|
||||
duIcode.setRegDU( selected, du);
|
||||
newExp = UnaryOperator::Create(DEREFERENCE, newExp);
|
||||
}
|
||||
else
|
||||
@@ -433,30 +396,11 @@ condId LLInst::idType(opLoc sd) const
|
||||
/* Size of hl types */
|
||||
int hlSize[] = {2, 1, 1, 2, 2, 4, 4, 4, 2, 2, 1, 4, 4};
|
||||
|
||||
int COND_EXPR::hlTypeSize(Function * pproc) const
|
||||
int Expr::hlTypeSize(Function * pproc) const
|
||||
{
|
||||
if (this == NULL)
|
||||
return (2); /* for TYPE_UNKNOWN */
|
||||
|
||||
switch (m_type) {
|
||||
case BOOLEAN_OP:
|
||||
assert(false);
|
||||
return 0;
|
||||
// return expr->hlTypeSize(pproc);
|
||||
case NEGATION: case ADDRESSOF:
|
||||
case POST_INC: case POST_DEC:
|
||||
case PRE_INC: case PRE_DEC:
|
||||
case DEREFERENCE:
|
||||
assert(false);
|
||||
return 0;
|
||||
//return expr->hlTypeSize(pproc);
|
||||
case IDENTIFIER:
|
||||
assert(false);
|
||||
return 0;
|
||||
default:
|
||||
fprintf(stderr,"hlTypeSize queried for Unkown type %d \n",m_type);
|
||||
break;
|
||||
}
|
||||
fprintf(stderr,"hlTypeSize queried for Unkown type %d \n",m_type);
|
||||
return 2; // CC: is this correct?
|
||||
}
|
||||
|
||||
@@ -469,33 +413,35 @@ int UnaryOperator::hlTypeSize(Function *pproc) const
|
||||
{
|
||||
return (unaryExp->hlTypeSize (pproc));
|
||||
}
|
||||
int GlobalVariable::hlTypeSize(Function *pproc) const
|
||||
{
|
||||
return (Project::get()->symbolSize(globIdx));
|
||||
}
|
||||
int GlobalVariableIdx::hlTypeSize(Function *pproc) const
|
||||
{
|
||||
return (hlSize[pproc->localId.id_arr[idxGlbIdx].type]);
|
||||
}
|
||||
|
||||
int AstIdent::hlTypeSize(Function *pproc) const
|
||||
{
|
||||
switch (ident.idType)
|
||||
{
|
||||
case GLOB_VAR:
|
||||
return (Project::get()->symbolSize(ident.idNode.globIdx));
|
||||
case REGISTER:
|
||||
if (ident.regiType == BYTE_REG)
|
||||
return (1);
|
||||
else
|
||||
return (2);
|
||||
assert(false);
|
||||
return 1;
|
||||
case LOCAL_VAR:
|
||||
return (hlSize[pproc->localId.id_arr[ident.idNode.localIdx].type]);
|
||||
case PARAM:
|
||||
return (hlSize[pproc->args[ident.idNode.paramIdx].type]);
|
||||
case GLOB_VAR_IDX:
|
||||
return (hlSize[pproc->localId.id_arr[ident.idNode.idxGlbIdx].type]);
|
||||
case CONSTANT:
|
||||
return (ident.idNode.kte.size);
|
||||
case STRING:
|
||||
return (2);
|
||||
case LONG_VAR:
|
||||
return (4);
|
||||
case FUNCTION:
|
||||
return (hlSize[ident.idNode.call.proc->retVal.type]);
|
||||
case OTHER:
|
||||
return (2);
|
||||
default:
|
||||
assert(false);
|
||||
return -1;
|
||||
} /* eos */
|
||||
}
|
||||
hlType BinaryOperator::expType(Function *pproc) const
|
||||
@@ -516,70 +462,47 @@ hlType UnaryOperator::expType(Function *pproc) const
|
||||
{
|
||||
return unaryExp->expType (pproc);
|
||||
}
|
||||
hlType GlobalVariable::expType(Function *pproc) const
|
||||
{
|
||||
return Project::get()->symbolType(globIdx);
|
||||
}
|
||||
hlType GlobalVariableIdx::expType(Function *pproc) const
|
||||
{
|
||||
return (pproc->localId.id_arr[idxGlbIdx].type);
|
||||
}
|
||||
|
||||
hlType AstIdent::expType(Function *pproc) const
|
||||
{
|
||||
switch (ident.idType)
|
||||
{
|
||||
case GLOB_VAR:
|
||||
return Project::get()->symbolType(ident.idNode.globIdx);
|
||||
case UNDEF:
|
||||
case CONSTANT:
|
||||
case FUNCTION:
|
||||
case REGISTER:
|
||||
if (ident.regiType == BYTE_REG)
|
||||
return (TYPE_BYTE_SIGN);
|
||||
else
|
||||
return (TYPE_WORD_SIGN);
|
||||
case GLOB_VAR:
|
||||
case GLOB_VAR_IDX:
|
||||
assert(false);
|
||||
return TYPE_UNKNOWN;
|
||||
case LOCAL_VAR:
|
||||
return (pproc->localId.id_arr[ident.idNode.localIdx].type);
|
||||
case PARAM:
|
||||
return (pproc->args[ident.idNode.paramIdx].type);
|
||||
case GLOB_VAR_IDX:
|
||||
return (pproc->localId.id_arr[ident.idNode.idxGlbIdx].type);
|
||||
case CONSTANT:
|
||||
return (TYPE_CONST);
|
||||
case STRING:
|
||||
return (TYPE_STR);
|
||||
case LONG_VAR:
|
||||
return (pproc->localId.id_arr[ident.idNode.longIdx].type);
|
||||
case FUNCTION:
|
||||
return (ident.idNode.call.proc->retVal.type);
|
||||
default:
|
||||
return (TYPE_UNKNOWN);
|
||||
} /* eos */
|
||||
return (TYPE_UNKNOWN);
|
||||
}
|
||||
/* Returns the type of the expression */
|
||||
hlType COND_EXPR::expType(Function * pproc) const
|
||||
{
|
||||
|
||||
if (this == nullptr)
|
||||
return (TYPE_UNKNOWN);
|
||||
|
||||
switch (m_type)
|
||||
{
|
||||
case BOOLEAN_OP:
|
||||
assert(false);
|
||||
return TYPE_UNKNOWN;
|
||||
case POST_INC: case POST_DEC:
|
||||
case PRE_INC: case PRE_DEC:
|
||||
case NEGATION:
|
||||
assert(false);
|
||||
return TYPE_UNKNOWN;
|
||||
case ADDRESSOF: return (TYPE_PTR); /***????****/
|
||||
case DEREFERENCE: return (TYPE_PTR);
|
||||
case IDENTIFIER:
|
||||
assert(false);
|
||||
return TYPE_UNKNOWN;
|
||||
case UNKNOWN_OP:
|
||||
assert(false);
|
||||
return (TYPE_UNKNOWN);
|
||||
}
|
||||
return TYPE_UNKNOWN; // CC: Correct?
|
||||
}
|
||||
|
||||
|
||||
/* 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 (eReg regi, LOCAL_ID *locId, COND_EXPR *tree)
|
||||
Expr * HlTypeSupport::performLongRemoval (eReg regi, LOCAL_ID *locId, Expr *tree)
|
||||
{
|
||||
switch (tree->m_type) {
|
||||
case BOOLEAN_OP:
|
||||
@@ -588,12 +511,13 @@ void HlTypeSupport::performLongRemoval (eReg regi, LOCAL_ID *locId, COND_EXPR *t
|
||||
case NEGATION: case ADDRESSOF:
|
||||
case DEREFERENCE:
|
||||
case IDENTIFIER:
|
||||
tree->performLongRemoval(regi,locId);
|
||||
return tree->performLongRemoval(regi,locId);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"performLongRemoval attemped on %d\n",tree->m_type);
|
||||
break;
|
||||
}
|
||||
return tree;
|
||||
}
|
||||
|
||||
/* Returns the string located in image, formatted in C format. */
|
||||
@@ -603,10 +527,10 @@ static std::string getString (int offset)
|
||||
ostringstream o;
|
||||
int strLen, i;
|
||||
|
||||
strLen = strSize (&prog.Image[offset], '\0');
|
||||
strLen = strSize (&prog.image()[offset], '\0');
|
||||
o << '"';
|
||||
for (i = 0; i < strLen; i++)
|
||||
o<<cChar(prog.Image[offset+i]);
|
||||
o<<cChar(prog.image()[offset+i]);
|
||||
o << "\"\0";
|
||||
return (o.str());
|
||||
}
|
||||
@@ -614,7 +538,11 @@ string BinaryOperator::walkCondExpr(Function * pProc, int* numLoc) const
|
||||
{
|
||||
std::ostringstream outStr;
|
||||
outStr << "(";
|
||||
outStr << lhs()->walkCondExpr(pProc, numLoc);
|
||||
if(m_op!=NOT)
|
||||
{
|
||||
outStr << lhs()->walkCondExpr(pProc, numLoc);
|
||||
}
|
||||
assert(rhs());
|
||||
outStr << condOpSym[m_op];
|
||||
outStr << rhs()->walkCondExpr(pProc, numLoc);
|
||||
outStr << ")";
|
||||
@@ -631,23 +559,6 @@ string AstIdent::walkCondExpr(Function *pProc, int *numLoc) const
|
||||
std::ostringstream o;
|
||||
switch (ident.idType)
|
||||
{
|
||||
case GLOB_VAR:
|
||||
o << Project::get()->symtab[ident.idNode.globIdx].name;
|
||||
break;
|
||||
case REGISTER:
|
||||
id = &pProc->localId.id_arr[ident.idNode.regiIdx];
|
||||
if (id->name[0] == '\0') /* no name */
|
||||
{
|
||||
id->setLocalName(++(*numLoc));
|
||||
codeOut <<TypeContainer::typeName(id->type)<< " "<<id->name<<"; ";
|
||||
codeOut <<"/* "<<Machine_X86::regName(id->id.regi)<<" */\n";
|
||||
}
|
||||
if (id->hasMacro)
|
||||
o << id->macro << "("<<id->name<<")";
|
||||
else
|
||||
o << id->name;
|
||||
break;
|
||||
|
||||
case LOCAL_VAR:
|
||||
o << pProc->localId.id_arr[ident.idNode.localIdx].name;
|
||||
break;
|
||||
@@ -659,19 +570,6 @@ string AstIdent::walkCondExpr(Function *pProc, int *numLoc) const
|
||||
else
|
||||
o << psym->name;
|
||||
break;
|
||||
|
||||
case GLOB_VAR_IDX:
|
||||
bwGlb = &pProc->localId.id_arr[ident.idNode.idxGlbIdx].id.bwGlb;
|
||||
o << (bwGlb->seg << 4) + bwGlb->off << "["<<Machine_X86::regName(bwGlb->regi)<<"]";
|
||||
break;
|
||||
|
||||
case CONSTANT:
|
||||
if (ident.idNode.kte.kte < 1000)
|
||||
o << ident.idNode.kte.kte;
|
||||
else
|
||||
o << "0x"<<std::hex << ident.idNode.kte.kte;
|
||||
break;
|
||||
|
||||
case STRING:
|
||||
o << getString (ident.idNode.strIdx);
|
||||
break;
|
||||
@@ -697,11 +595,6 @@ string AstIdent::walkCondExpr(Function *pProc, int *numLoc) const
|
||||
o << "[" << (id->id.longGlb.seg<<4) + id->id.longGlb.offH <<"][bx]";
|
||||
}
|
||||
break;
|
||||
|
||||
case FUNCTION:
|
||||
o << writeCall (ident.idNode.call.proc,*ident.idNode.call.args, pProc, numLoc);
|
||||
break;
|
||||
|
||||
case OTHER:
|
||||
off = ident.idNode.other.off;
|
||||
o << Machine_X86::regName(ident.idNode.other.seg)<< "[";
|
||||
@@ -711,6 +604,12 @@ string AstIdent::walkCondExpr(Function *pProc, int *numLoc) const
|
||||
else if (off>0)
|
||||
o << "+"<< hexStr (off);
|
||||
o << "]";
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
return "";
|
||||
|
||||
|
||||
} /* eos */
|
||||
outStr << o.str();
|
||||
cCode.appendDecl(codeOut.str());
|
||||
@@ -783,35 +682,6 @@ string UnaryOperator::walkCondExpr(Function *pProc, int *numLoc) const
|
||||
|
||||
|
||||
|
||||
/* Makes a copy of the given expression. Allocates newExp storage for each
|
||||
* node. Returns the copy. */
|
||||
COND_EXPR *COND_EXPR::clone() const
|
||||
{
|
||||
COND_EXPR* newExp=nullptr; /* Expression node copy */
|
||||
|
||||
switch (m_type)
|
||||
{
|
||||
case BOOLEAN_OP:
|
||||
assert(false);
|
||||
break;
|
||||
|
||||
case NEGATION:
|
||||
case ADDRESSOF:
|
||||
case DEREFERENCE:
|
||||
case PRE_DEC: case POST_DEC:
|
||||
case PRE_INC: case POST_INC:
|
||||
assert(false);
|
||||
break;
|
||||
|
||||
case IDENTIFIER:
|
||||
assert(false);
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr,"Clone attempt on unhandled type %d\n",m_type);
|
||||
}
|
||||
return (newExp);
|
||||
}
|
||||
|
||||
|
||||
/* Changes the boolean conditional operator at the root of this expression */
|
||||
@@ -819,9 +689,9 @@ void BinaryOperator::changeBoolOp (condOp newOp)
|
||||
{
|
||||
m_op = newOp;
|
||||
}
|
||||
bool COND_EXPR::insertSubTreeReg (AstIdent *&tree, COND_EXPR *_expr, eReg regi,const LOCAL_ID *locsym)
|
||||
bool Expr::insertSubTreeReg (AstIdent *&tree, Expr *_expr, eReg regi,const LOCAL_ID *locsym)
|
||||
{
|
||||
COND_EXPR *nd = tree;
|
||||
Expr *nd = tree;
|
||||
bool res=insertSubTreeReg (nd, _expr, regi,locsym);
|
||||
if(res)
|
||||
{
|
||||
@@ -833,12 +703,12 @@ bool COND_EXPR::insertSubTreeReg (AstIdent *&tree, COND_EXPR *_expr, eReg regi,c
|
||||
}
|
||||
/* Inserts the expression exp into the tree at the location specified by the
|
||||
* register regi */
|
||||
bool COND_EXPR::insertSubTreeReg (COND_EXPR *&tree, COND_EXPR *_expr, eReg regi,const LOCAL_ID *locsym)
|
||||
bool Expr::insertSubTreeReg (Expr *&tree, Expr *_expr, eReg regi,const LOCAL_ID *locsym)
|
||||
{
|
||||
|
||||
if (tree == NULL)
|
||||
return false;
|
||||
COND_EXPR *temp=tree->insertSubTreeReg(_expr,regi,locsym);
|
||||
Expr *temp=tree->insertSubTreeReg(_expr,regi,locsym);
|
||||
if(nullptr!=temp)
|
||||
{
|
||||
tree=temp;
|
||||
@@ -847,11 +717,9 @@ bool COND_EXPR::insertSubTreeReg (COND_EXPR *&tree, COND_EXPR *_expr, eReg regi,
|
||||
return false;
|
||||
}
|
||||
|
||||
COND_EXPR *UnaryOperator::insertSubTreeReg(COND_EXPR *_expr, eReg regi, const LOCAL_ID *locsym)
|
||||
Expr *UnaryOperator::insertSubTreeReg(Expr *_expr, eReg regi, const LOCAL_ID *locsym)
|
||||
{
|
||||
|
||||
eReg treeReg;
|
||||
COND_EXPR *temp;
|
||||
Expr *temp;
|
||||
|
||||
switch (m_type) {
|
||||
case NEGATION:
|
||||
@@ -869,9 +737,9 @@ COND_EXPR *UnaryOperator::insertSubTreeReg(COND_EXPR *_expr, eReg regi, const LO
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
COND_EXPR *BinaryOperator::insertSubTreeReg(COND_EXPR *_expr, eReg regi, const LOCAL_ID *locsym)
|
||||
Expr *BinaryOperator::insertSubTreeReg(Expr *_expr, eReg regi, const LOCAL_ID *locsym)
|
||||
{
|
||||
COND_EXPR *r;
|
||||
Expr *r;
|
||||
if(this->op()!=NOT)
|
||||
{
|
||||
assert(m_lhs);
|
||||
@@ -891,30 +759,21 @@ COND_EXPR *BinaryOperator::insertSubTreeReg(COND_EXPR *_expr, eReg regi, const L
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
COND_EXPR *AstIdent::insertSubTreeReg(COND_EXPR *_expr, eReg regi, const LOCAL_ID *locsym)
|
||||
Expr *AstIdent::insertSubTreeReg(Expr *_expr, eReg regi, const LOCAL_ID *locsym)
|
||||
{
|
||||
eReg treeReg;
|
||||
if (ident.idType == REGISTER)
|
||||
{
|
||||
treeReg = locsym->id_arr[ident.idNode.regiIdx].id.regi;
|
||||
if (treeReg == regi) /* uint16_t reg */
|
||||
{
|
||||
return _expr;
|
||||
}
|
||||
else if(Machine_X86::isSubRegisterOf(treeReg,regi)) /* uint16_t/uint8_t reg */
|
||||
{
|
||||
return _expr;
|
||||
}
|
||||
assert(false);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
/* Inserts the expression exp into the tree at the location specified by the
|
||||
* long register index longIdx*/
|
||||
bool COND_EXPR::insertSubTreeLongReg(COND_EXPR *_expr, COND_EXPR *&tree, int longIdx)
|
||||
bool Expr::insertSubTreeLongReg(Expr *_expr, Expr *&tree, int longIdx)
|
||||
{
|
||||
if (tree == NULL)
|
||||
return false;
|
||||
COND_EXPR *temp=tree->insertSubTreeLongReg(_expr,longIdx);
|
||||
Expr *temp=tree->insertSubTreeLongReg(_expr,longIdx);
|
||||
if(nullptr!=temp)
|
||||
{
|
||||
tree=temp;
|
||||
@@ -922,9 +781,9 @@ bool COND_EXPR::insertSubTreeLongReg(COND_EXPR *_expr, COND_EXPR *&tree, int lon
|
||||
}
|
||||
return false;
|
||||
}
|
||||
COND_EXPR *UnaryOperator::insertSubTreeLongReg(COND_EXPR *_expr, int longIdx)
|
||||
Expr *UnaryOperator::insertSubTreeLongReg(Expr *_expr, int longIdx)
|
||||
{
|
||||
COND_EXPR *temp = unaryExp->insertSubTreeLongReg(_expr,longIdx);
|
||||
Expr *temp = unaryExp->insertSubTreeLongReg(_expr,longIdx);
|
||||
if (nullptr!=temp)
|
||||
{
|
||||
unaryExp = temp;
|
||||
@@ -932,9 +791,9 @@ COND_EXPR *UnaryOperator::insertSubTreeLongReg(COND_EXPR *_expr, int longIdx)
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
COND_EXPR *BinaryOperator::insertSubTreeLongReg(COND_EXPR *_expr, int longIdx)
|
||||
Expr *BinaryOperator::insertSubTreeLongReg(Expr *_expr, int longIdx)
|
||||
{
|
||||
COND_EXPR *r;
|
||||
Expr *r;
|
||||
if(m_op!=NOT)
|
||||
{
|
||||
r=m_lhs->insertSubTreeLongReg(_expr,longIdx);
|
||||
@@ -952,7 +811,7 @@ COND_EXPR *BinaryOperator::insertSubTreeLongReg(COND_EXPR *_expr, int longIdx)
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
COND_EXPR *AstIdent::insertSubTreeLongReg(COND_EXPR *_expr, int longIdx)
|
||||
Expr *AstIdent::insertSubTreeLongReg(Expr *_expr, int longIdx)
|
||||
{
|
||||
if (ident.idNode.longIdx == longIdx)
|
||||
{
|
||||
@@ -962,24 +821,12 @@ COND_EXPR *AstIdent::insertSubTreeLongReg(COND_EXPR *_expr, int longIdx)
|
||||
}
|
||||
|
||||
/* Recursively deallocates the abstract syntax tree rooted at *exp */
|
||||
COND_EXPR::~COND_EXPR()
|
||||
{
|
||||
switch (m_type)
|
||||
{
|
||||
case BOOLEAN_OP:
|
||||
case NEGATION:
|
||||
case ADDRESSOF:
|
||||
case DEREFERENCE:
|
||||
case IDENTIFIER:
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"release attempt on unhandled type %d\n",m_type);
|
||||
}
|
||||
}
|
||||
Expr::~Expr(){}
|
||||
|
||||
/* Makes a copy of the given expression. Allocates newExp storage for each
|
||||
* node. Returns the copy. */
|
||||
|
||||
COND_EXPR *BinaryOperator::clone() const
|
||||
Expr *BinaryOperator::clone() const
|
||||
{
|
||||
BinaryOperator* newExp=new BinaryOperator(m_op); /* Expression node copy */
|
||||
newExp->m_lhs = m_lhs->clone();
|
||||
@@ -987,7 +834,7 @@ COND_EXPR *BinaryOperator::clone() const
|
||||
return newExp;
|
||||
}
|
||||
|
||||
COND_EXPR *BinaryOperator::inverse() const
|
||||
Expr *BinaryOperator::inverse() const
|
||||
{
|
||||
static condOp invCondOp[] = {GREATER, GREATER_EQUAL, NOT_EQUAL, EQUAL,
|
||||
LESS_EQUAL, LESS, DUMMY,DUMMY,DUMMY,DUMMY,
|
||||
@@ -1017,18 +864,17 @@ COND_EXPR *BinaryOperator::inverse() const
|
||||
return res;
|
||||
|
||||
}
|
||||
void AstIdent::performLongRemoval(eReg regi, LOCAL_ID *locId)
|
||||
Expr *AstIdent::performLongRemoval(eReg regi, LOCAL_ID *locId)
|
||||
{
|
||||
eReg otherRegi; /* high or low part of long register */
|
||||
|
||||
IDENTTYPE* ident_2 = &ident;
|
||||
if (ident_2->idType == LONG_VAR)
|
||||
if (ident.idType == LONG_VAR)
|
||||
{
|
||||
otherRegi = otherLongRegi (regi, ident_2->idNode.longIdx, locId);
|
||||
ident_2->idType = REGISTER;
|
||||
ident_2->regiType = WORD_REG;
|
||||
ident_2->idNode.regiIdx = locId->newByteWordReg(TYPE_WORD_SIGN,otherRegi);
|
||||
otherRegi = otherLongRegi (regi, ident.idNode.longIdx, locId);
|
||||
delete this;
|
||||
return new RegisterNode(locId->newByteWordReg(TYPE_WORD_SIGN,otherRegi),WORD_REG);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
eReg AstIdent::otherLongRegi (eReg regi, int idx, LOCAL_ID *locTbl)
|
||||
{
|
||||
@@ -1045,3 +891,42 @@ eReg AstIdent::otherLongRegi (eReg regi, int idx, LOCAL_ID *locTbl)
|
||||
}
|
||||
return rUNDEF; // Cristina: please check this!
|
||||
}
|
||||
|
||||
|
||||
string Constant::walkCondExpr(Function *, int *) const
|
||||
{
|
||||
ostringstream o;
|
||||
if (kte.kte < 1000)
|
||||
o << kte.kte;
|
||||
else
|
||||
o << "0x"<<std::hex << kte.kte;
|
||||
return o.str();
|
||||
}
|
||||
|
||||
int Constant::hlTypeSize(Function *) const
|
||||
{
|
||||
return kte.size;
|
||||
}
|
||||
|
||||
hlType Constant::expType(Function *pproc) const
|
||||
{
|
||||
return TYPE_CONST;
|
||||
}
|
||||
|
||||
string FuncNode::walkCondExpr(Function *pProc, int *numLoc) const
|
||||
{
|
||||
return pProc->writeCall(call.proc,*call.args, numLoc);
|
||||
}
|
||||
|
||||
int FuncNode::hlTypeSize(Function *) const
|
||||
{
|
||||
return hlSize[call.proc->retVal.type];
|
||||
}
|
||||
|
||||
hlType FuncNode::expType(Function *) const
|
||||
{
|
||||
return call.proc->retVal.type;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -108,23 +108,23 @@ static void printGlobVar (std::ostream &ostr,SYM * psym)
|
||||
switch (psym->size)
|
||||
{
|
||||
case 1:
|
||||
ostr << "uint8_t\t"<<psym->name<<" = "<<prog.Image[relocOp]<<";\n";
|
||||
ostr << "uint8_t\t"<<psym->name<<" = "<<prog.image()[relocOp]<<";\n";
|
||||
break;
|
||||
case 2:
|
||||
ostr << "uint16_t\t"<<psym->name<<" = "<<LH(prog.Image+relocOp)<<";\n";
|
||||
ostr << "uint16_t\t"<<psym->name<<" = "<<LH(prog.image()+relocOp)<<";\n";
|
||||
break;
|
||||
case 4: if (psym->type == TYPE_PTR) /* pointer */
|
||||
ostr << "uint16_t *\t"<<psym->name<<" = "<<LH(prog.Image+relocOp)<<";\n";
|
||||
ostr << "uint16_t *\t"<<psym->name<<" = "<<LH(prog.image()+relocOp)<<";\n";
|
||||
else /* char */
|
||||
ostr << "char\t"<<psym->name<<"[4] = \""<<
|
||||
prog.Image[relocOp]<<prog.Image[relocOp+1]<<
|
||||
prog.Image[relocOp+2]<<prog.Image[relocOp+3]<<";\n";
|
||||
prog.image()[relocOp]<<prog.image()[relocOp+1]<<
|
||||
prog.image()[relocOp+2]<<prog.image()[relocOp+3]<<";\n";
|
||||
break;
|
||||
default:
|
||||
{
|
||||
ostringstream strContents;
|
||||
for (j=0; j < psym->size; j++)
|
||||
strContents << cChar(prog.Image[relocOp + j]);
|
||||
strContents << cChar(prog.image()[relocOp + j]);
|
||||
ostr << "char\t*"<<psym->name<<" = \""<<strContents.str()<<"\";\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ void checkHeap(char *msg); /* For debugging */
|
||||
|
||||
void fixWildCards(uint8_t pat[]); /* In fixwild.c */
|
||||
|
||||
static boolT locatePattern(uint8_t *source, int iMin, int iMax, uint8_t *pattern,
|
||||
static boolT locatePattern(const uint8_t *source, int iMin, int iMax, uint8_t *pattern,
|
||||
int iPatLen, int *index);
|
||||
|
||||
/* * * * * * * * * * * * * * * *\
|
||||
@@ -457,8 +457,8 @@ bool LibCheck(Function & pProc)
|
||||
pProc.name = "main";
|
||||
return false;
|
||||
}
|
||||
memcpy(pat, &prog.Image[fileOffset], PATLEN);
|
||||
//memmove(pat, &prog.Image[fileOffset], PATLEN);
|
||||
memcpy(pat, &prog.image()[fileOffset], PATLEN);
|
||||
//memmove(pat, &prog.image()[fileOffset], PATLEN);
|
||||
fixWildCards(pat); /* Fix wild cards in the copy */
|
||||
h = g_pattern_hasher.hash(pat); /* Hash the found proc */
|
||||
/* We always have to compare keys, because the hash function will always return a valid index */
|
||||
@@ -520,7 +520,7 @@ bool LibCheck(Function & pProc)
|
||||
pProc.flg |= PROC_RUNTIME; /* => is a runtime routine */
|
||||
}
|
||||
}
|
||||
if (locatePattern(prog.Image, pProc.procEntry,
|
||||
if (locatePattern(prog.image(), pProc.procEntry,
|
||||
pProc.procEntry+sizeof(pattMsChkstk),
|
||||
pattMsChkstk, sizeof(pattMsChkstk), &Idx))
|
||||
{
|
||||
@@ -587,11 +587,11 @@ void dispKey(int /*i*/)
|
||||
iPatLen). The pattern can contain wild bytes; if you really want to match
|
||||
for the pattern that is used up by the WILD uint8_t, tough - it will match with
|
||||
everything else as well. */
|
||||
static boolT locatePattern(uint8_t *source, int iMin, int iMax, uint8_t *pattern, int iPatLen,
|
||||
static boolT locatePattern(const uint8_t *source, int iMin, int iMax, uint8_t *pattern, int iPatLen,
|
||||
int *index)
|
||||
{
|
||||
int i, j;
|
||||
uint8_t *pSrc; /* Pointer to start of considered source */
|
||||
const uint8_t *pSrc; /* Pointer to start of considered source */
|
||||
int iLast;
|
||||
|
||||
iLast = iMax - iPatLen; /* Last source uint8_t to consider */
|
||||
@@ -645,18 +645,18 @@ void STATE::checkStartup()
|
||||
|
||||
/* Check the Turbo Pascal signatures first, since they involve only the
|
||||
first 3 bytes, and false positives may be founf with the others later */
|
||||
if (locatePattern(prog.Image, startOff, startOff+5, pattBorl4on,sizeof(pattBorl4on), &i))
|
||||
if (locatePattern(prog.image(), startOff, startOff+5, pattBorl4on,sizeof(pattBorl4on), &i))
|
||||
{
|
||||
/* The first 5 bytes are a far call. Follow that call and
|
||||
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 */
|
||||
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 = ((uint32_t)para << 4) + rel;
|
||||
if (locatePattern(prog.Image, init, init+26, pattBorl4Init,
|
||||
if (locatePattern(prog.image(), init, init+26, pattBorl4Init,
|
||||
sizeof(pattBorl4Init), &i))
|
||||
{
|
||||
|
||||
setState(rDS, LH(&prog.Image[i+1]));
|
||||
setState(rDS, LH(&prog.image()[i+1]));
|
||||
printf("Borland Pascal v4 detected\n");
|
||||
chVendor = 't'; /* Trubo */
|
||||
chModel = 'p'; /* Pascal */
|
||||
@@ -665,11 +665,11 @@ void STATE::checkStartup()
|
||||
prog.segMain = prog.initCS; /* At the 5 uint8_t jump */
|
||||
goto gotVendor; /* Already have vendor */
|
||||
}
|
||||
else if (locatePattern(prog.Image, init, init+26, pattBorl5Init,
|
||||
else if (locatePattern(prog.image(), init, init+26, pattBorl5Init,
|
||||
sizeof(pattBorl5Init), &i))
|
||||
{
|
||||
|
||||
setState( rDS, LH(&prog.Image[i+1]));
|
||||
setState( rDS, LH(&prog.image()[i+1]));
|
||||
printf("Borland Pascal v5.0 detected\n");
|
||||
chVendor = 't'; /* Trubo */
|
||||
chModel = 'p'; /* Pascal */
|
||||
@@ -678,11 +678,11 @@ void STATE::checkStartup()
|
||||
prog.segMain = prog.initCS;
|
||||
goto gotVendor; /* Already have vendor */
|
||||
}
|
||||
else if (locatePattern(prog.Image, init, init+26, pattBorl7Init,
|
||||
else if (locatePattern(prog.image(), init, init+26, pattBorl7Init,
|
||||
sizeof(pattBorl7Init), &i))
|
||||
{
|
||||
|
||||
setState( rDS, LH(&prog.Image[i+1]));
|
||||
setState( rDS, LH(&prog.image()[i+1]));
|
||||
printf("Borland Pascal v7 detected\n");
|
||||
chVendor = 't'; /* Trubo */
|
||||
chModel = 'p'; /* Pascal */
|
||||
@@ -701,43 +701,43 @@ void STATE::checkStartup()
|
||||
as near data, just more pushes at the start. */
|
||||
if(prog.cbImage>int(startOff+0x180+sizeof(pattMainLarge)))
|
||||
{
|
||||
if (locatePattern(prog.Image, startOff, startOff+0x180, pattMainLarge,sizeof(pattMainLarge), &i))
|
||||
if (locatePattern(prog.image(), startOff, startOff+0x180, pattMainLarge,sizeof(pattMainLarge), &i))
|
||||
{
|
||||
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 */
|
||||
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 = ((uint32_t)para << 4) + rel;
|
||||
prog.segMain = (uint16_t)para;
|
||||
chModel = 'l'; /* Large model */
|
||||
}
|
||||
else if (locatePattern(prog.Image, startOff, startOff+0x180, pattMainCompact,
|
||||
else if (locatePattern(prog.image(), startOff, startOff+0x180, pattMainCompact,
|
||||
sizeof(pattMainCompact), &i))
|
||||
{
|
||||
rel = LH_SIGNED(&prog.Image[i+OFFMAINCOMPACT]);/* This is the rel addr of main */
|
||||
rel = LH_SIGNED(&prog.image()[i+OFFMAINCOMPACT]);/* This is the rel addr of main */
|
||||
prog.offMain = i+OFFMAINCOMPACT+2+rel; /* Save absolute image offset */
|
||||
prog.segMain = prog.initCS;
|
||||
chModel = 'c'; /* Compact model */
|
||||
}
|
||||
else if (locatePattern(prog.Image, startOff, startOff+0x180, pattMainMedium,
|
||||
else if (locatePattern(prog.image(), startOff, startOff+0x180, pattMainMedium,
|
||||
sizeof(pattMainMedium), &i))
|
||||
{
|
||||
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 */
|
||||
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 = ((uint32_t)para << 4) + rel;
|
||||
prog.segMain = (uint16_t)para;
|
||||
chModel = 'm'; /* Medium model */
|
||||
}
|
||||
else if (locatePattern(prog.Image, startOff, startOff+0x180, pattMainSmall,
|
||||
else if (locatePattern(prog.image(), startOff, startOff+0x180, pattMainSmall,
|
||||
sizeof(pattMainSmall), &i))
|
||||
{
|
||||
rel = LH_SIGNED(&prog.Image[i+OFFMAINSMALL]); /* This is rel addr of main */
|
||||
rel = LH_SIGNED(&prog.image()[i+OFFMAINSMALL]); /* This is rel addr of main */
|
||||
prog.offMain = i+OFFMAINSMALL+2+rel; /* Save absolute image offset */
|
||||
prog.segMain = prog.initCS;
|
||||
chModel = 's'; /* Small model */
|
||||
}
|
||||
else if (memcmp(&prog.Image[startOff], pattTPasStart, sizeof(pattTPasStart)) == 0)
|
||||
else if (memcmp(&prog.image()[startOff], pattTPasStart, sizeof(pattTPasStart)) == 0)
|
||||
{
|
||||
rel = LH_SIGNED(&prog.Image[startOff+1]); /* Get the jump offset */
|
||||
rel = LH_SIGNED(&prog.image()[startOff+1]); /* Get the jump offset */
|
||||
prog.offMain = rel+startOff+3; /* Save absolute image offset */
|
||||
prog.offMain += 0x20; /* These first 32 bytes are setting up */
|
||||
prog.segMain = prog.initCS;
|
||||
@@ -764,27 +764,27 @@ void STATE::checkStartup()
|
||||
|
||||
|
||||
/* Now decide the compiler vendor and version number */
|
||||
if (memcmp(&prog.Image[startOff], pattMsC5Start, sizeof(pattMsC5Start)) == 0)
|
||||
if (memcmp(&prog.image()[startOff], pattMsC5Start, sizeof(pattMsC5Start)) == 0)
|
||||
{
|
||||
/* Yes, this is Microsoft startup code. The DS is sitting right here
|
||||
in the next 2 bytes */
|
||||
setState( rDS, LH(&prog.Image[startOff+sizeof(pattMsC5Start)]));
|
||||
setState( rDS, LH(&prog.image()[startOff+sizeof(pattMsC5Start)]));
|
||||
chVendor = 'm'; /* Microsoft compiler */
|
||||
chVersion = '5'; /* Version 5 */
|
||||
printf("MSC 5 detected\n");
|
||||
}
|
||||
|
||||
/* The C8 startup pattern is different from C5's */
|
||||
else if (memcmp(&prog.Image[startOff], pattMsC8Start, sizeof(pattMsC8Start)) == 0)
|
||||
else if (memcmp(&prog.image()[startOff], pattMsC8Start, sizeof(pattMsC8Start)) == 0)
|
||||
{
|
||||
setState( rDS, LH(&prog.Image[startOff+sizeof(pattMsC8Start)]));
|
||||
setState( rDS, LH(&prog.image()[startOff+sizeof(pattMsC8Start)]));
|
||||
printf("MSC 8 detected\n");
|
||||
chVendor = 'm'; /* Microsoft compiler */
|
||||
chVersion = '8'; /* Version 8 */
|
||||
}
|
||||
|
||||
/* The C8 .com startup pattern is different again! */
|
||||
else if (memcmp(&prog.Image[startOff], pattMsC8ComStart,
|
||||
else if (memcmp(&prog.image()[startOff], pattMsC8ComStart,
|
||||
sizeof(pattMsC8ComStart)) == 0)
|
||||
{
|
||||
printf("MSC 8 .com detected\n");
|
||||
@@ -792,27 +792,27 @@ void STATE::checkStartup()
|
||||
chVersion = '8'; /* Version 8 */
|
||||
}
|
||||
|
||||
else if (locatePattern(prog.Image, startOff, startOff+0x30, pattBorl2Start,
|
||||
else if (locatePattern(prog.image(), startOff, startOff+0x30, pattBorl2Start,
|
||||
sizeof(pattBorl2Start), &i))
|
||||
{
|
||||
/* Borland startup. DS is at the second uint8_t (offset 1) */
|
||||
setState( rDS, LH(&prog.Image[i+1]));
|
||||
setState( rDS, LH(&prog.image()[i+1]));
|
||||
printf("Borland v2 detected\n");
|
||||
chVendor = 'b'; /* Borland compiler */
|
||||
chVersion = '2'; /* Version 2 */
|
||||
}
|
||||
|
||||
else if (locatePattern(prog.Image, startOff, startOff+0x30, pattBorl3Start,
|
||||
else if (locatePattern(prog.image(), startOff, startOff+0x30, pattBorl3Start,
|
||||
sizeof(pattBorl3Start), &i))
|
||||
{
|
||||
/* Borland startup. DS is at the second uint8_t (offset 1) */
|
||||
setState( rDS, LH(&prog.Image[i+1]));
|
||||
setState( rDS, LH(&prog.image()[i+1]));
|
||||
printf("Borland v3 detected\n");
|
||||
chVendor = 'b'; /* Borland compiler */
|
||||
chVersion = '3'; /* Version 3 */
|
||||
}
|
||||
|
||||
else if (locatePattern(prog.Image, startOff, startOff+0x30, pattLogiStart,
|
||||
else if (locatePattern(prog.image(), startOff, startOff+0x30, pattLogiStart,
|
||||
sizeof(pattLogiStart), &i))
|
||||
{
|
||||
/* Logitech modula startup. DS is 0, despite appearances */
|
||||
|
||||
@@ -207,9 +207,9 @@ void Function::writeProcComments(std::ostream &ostr)
|
||||
{
|
||||
psym = &this->args[i];
|
||||
ostr << " * "<<psym->name<<" = ";
|
||||
if (psym->regs->ident.idType == REGISTER)
|
||||
if (psym->regs->ident.type() == REGISTER)
|
||||
{
|
||||
id = &this->localId.id_arr[psym->regs->ident.idNode.regiIdx];
|
||||
id = &this->localId.id_arr[((RegisterNode *)psym->regs)->regiIdx];
|
||||
ostr << Machine_X86::regName(id->id.regi);
|
||||
}
|
||||
else /* long register */
|
||||
|
||||
@@ -529,9 +529,11 @@ bool Function::Case_X_and_Y(BB* pbb, BB* thenBB, BB* elseBB)
|
||||
HLTYPE &hl1(*pbb->back().hlU());
|
||||
HLTYPE &hl2(*thenBB->back().hlU());
|
||||
BB* obb = elseBB->edges[ELSE].BBptr;
|
||||
|
||||
Expr * hl2_expr = hl2.getMyExpr();
|
||||
/* Construct compound DBL_AND expression */
|
||||
hl1.expr(BinaryOperator::Create(DBL_AND,hl1.expr(),hl2.expr()));
|
||||
assert(hl1.expr());
|
||||
assert(hl2_expr);
|
||||
hl1.expr(BinaryOperator::Create(DBL_AND,hl1.expr(),hl2_expr));
|
||||
|
||||
/* Replace in-edge to obb from e to pbb */
|
||||
replaceInEdge(obb,elseBB,pbb);
|
||||
|
||||
205
src/dataflow.cpp
205
src/dataflow.cpp
@@ -20,12 +20,12 @@ using namespace boost;
|
||||
using namespace boost::adaptors;
|
||||
struct ExpStack
|
||||
{
|
||||
typedef std::list<COND_EXPR *> EXP_STK;
|
||||
typedef std::list<Expr *> EXP_STK;
|
||||
EXP_STK expStk; /* local expression stack */
|
||||
|
||||
void init();
|
||||
void push(COND_EXPR *);
|
||||
COND_EXPR * pop();
|
||||
void push(Expr *);
|
||||
Expr * pop();
|
||||
int numElem();
|
||||
boolT empty();
|
||||
void processExpPush(int &numHlIcodes, iICODE picode)
|
||||
@@ -48,7 +48,7 @@ void ExpStack::init()
|
||||
}
|
||||
|
||||
/* Pushes the given expression onto the local stack (expStk). */
|
||||
void ExpStack::push(COND_EXPR *expr)
|
||||
void ExpStack::push(Expr *expr)
|
||||
{
|
||||
expStk.push_back(expr);
|
||||
}
|
||||
@@ -57,11 +57,11 @@ void ExpStack::push(COND_EXPR *expr)
|
||||
/* Returns the element on the top of the local expression stack (expStk),
|
||||
* and deallocates the space allocated by this node.
|
||||
* If there are no elements on the stack, returns NULL. */
|
||||
COND_EXPR *ExpStack::pop()
|
||||
Expr *ExpStack::pop()
|
||||
{
|
||||
if(expStk.empty())
|
||||
return 0;
|
||||
COND_EXPR *topExp = expStk.back();
|
||||
Expr *topExp = expStk.back();
|
||||
expStk.pop_back();
|
||||
return topExp;
|
||||
}
|
||||
@@ -91,13 +91,13 @@ size_t STKFRAME::getLocVar(int off)
|
||||
|
||||
|
||||
/* Returns a string with the source operand of Icode */
|
||||
static COND_EXPR *srcIdent (const LLInst &ll_insn, Function * pProc, iICODE i, ICODE & duIcode, operDu du)
|
||||
static Expr *srcIdent (const LLInst &ll_insn, Function * pProc, iICODE i, ICODE & duIcode, operDu du)
|
||||
{
|
||||
if (ll_insn.testFlags(I)) /* immediate operand */
|
||||
{
|
||||
if (ll_insn.testFlags(B))
|
||||
return AstIdent::Kte (ll_insn.src().getImm2(), 1);
|
||||
return AstIdent::Kte (ll_insn.src().getImm2(), 2);
|
||||
return new Constant(ll_insn.src().getImm2(), 1);
|
||||
return new Constant(ll_insn.src().getImm2(), 2);
|
||||
}
|
||||
// otherwise
|
||||
return AstIdent::id (ll_insn, SRC, pProc, i, duIcode, du);
|
||||
@@ -105,9 +105,9 @@ static COND_EXPR *srcIdent (const LLInst &ll_insn, Function * pProc, iICODE i, I
|
||||
|
||||
|
||||
/* Returns the destination operand */
|
||||
static COND_EXPR *dstIdent (const LLInst & ll_insn, Function * pProc, iICODE i, ICODE & duIcode, operDu du)
|
||||
static Expr *dstIdent (const LLInst & ll_insn, Function * pProc, iICODE i, ICODE & duIcode, operDu du)
|
||||
{
|
||||
COND_EXPR *n;
|
||||
Expr *n;
|
||||
n = AstIdent::id (ll_insn, DST, pProc, i, duIcode, du);
|
||||
/** Is it needed? (pIcode->ll()->flg) & NO_SRC_B **/
|
||||
return (n);
|
||||
@@ -120,8 +120,8 @@ void Function::elimCondCodes ()
|
||||
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 */
|
||||
Expr *rhs; /* Source operand */
|
||||
Expr *lhs; /* Destination operand */
|
||||
BinaryOperator *_expr; /* Boolean expression */
|
||||
//BB * pBB; /* Pointer to BBs in dfs last ordering */
|
||||
riICODE useAt; /* Instruction that used flag */
|
||||
@@ -159,12 +159,12 @@ void Function::elimCondCodes ()
|
||||
break;
|
||||
|
||||
case iOR:
|
||||
lhs = defAt->hl()->asgn.lhs->clone();
|
||||
lhs = defAt->hl()->asgn.lhs()->clone();
|
||||
useAt->copyDU(*defAt, eUSE, eDEF);
|
||||
if (defAt->ll()->testFlags(B))
|
||||
rhs = AstIdent::Kte (0, 1);
|
||||
rhs = new Constant(0, 1);
|
||||
else
|
||||
rhs = AstIdent::Kte (0, 2);
|
||||
rhs = new Constant(0, 2);
|
||||
break;
|
||||
|
||||
case iTEST:
|
||||
@@ -172,18 +172,18 @@ void Function::elimCondCodes ()
|
||||
lhs = dstIdent (*defAt->ll(),this, befDefAt,*useAt, eUSE);
|
||||
lhs = BinaryOperator::And(lhs, rhs);
|
||||
if (defAt->ll()->testFlags(B))
|
||||
rhs = AstIdent::Kte (0, 1);
|
||||
rhs = new Constant(0, 1);
|
||||
else
|
||||
rhs = AstIdent::Kte (0, 2);
|
||||
rhs = new Constant(0, 2);
|
||||
break;
|
||||
case iINC:
|
||||
case iDEC: //WARNING: verbatim copy from iOR needs fixing ?
|
||||
lhs = defAt->hl()->asgn.lhs->clone();
|
||||
lhs = defAt->hl()->asgn.lhs()->clone();
|
||||
useAt->copyDU(*defAt, eUSE, eDEF);
|
||||
if (defAt->ll()->testFlags(B))
|
||||
rhs = AstIdent::Kte (0, 1);
|
||||
rhs = new Constant(0, 1);
|
||||
else
|
||||
rhs = AstIdent::Kte (0, 2);
|
||||
rhs = new Constant(0, 2);
|
||||
break;
|
||||
default:
|
||||
notSup = true;
|
||||
@@ -202,9 +202,9 @@ void Function::elimCondCodes ()
|
||||
|
||||
else if (useAtOp == iJCXZ)
|
||||
{
|
||||
lhs = AstIdent::Reg (rCX, 0, &localId);
|
||||
lhs = new RegisterNode(rCX, 0, &localId);
|
||||
useAt->setRegDU (rCX, eUSE);
|
||||
rhs = AstIdent::Kte (0, 2);
|
||||
rhs = new Constant(0, 2);
|
||||
_expr = BinaryOperator::Create(EQUAL,lhs,rhs);
|
||||
useAt->setJCond(_expr);
|
||||
}
|
||||
@@ -319,7 +319,7 @@ void Function::liveRegAnalysis (LivenessSet &in_liveOut)
|
||||
auto picode = pbb->rbegin(); /* icode of function return */
|
||||
if (picode->hl()->opcode == HLI_RET)
|
||||
{
|
||||
picode->hlU()->expr(AstIdent::idID (&retVal, &localId, (++pbb->rbegin()).base()));
|
||||
picode->hlU()->expr(AstIdent::idID(&retVal, &localId, (++pbb->rbegin()).base()));
|
||||
picode->du.use = in_liveOut;
|
||||
}
|
||||
}
|
||||
@@ -392,13 +392,13 @@ void Function::liveRegAnalysis (LivenessSet &in_liveOut)
|
||||
/* Remove any references to register variables */
|
||||
if (flg & SI_REGVAR)
|
||||
{
|
||||
liveIn.set(rSI,0);
|
||||
pbb->liveIn.set(rSI,0);
|
||||
liveIn.clrReg(rSI);
|
||||
pbb->liveIn.clrReg(rSI);
|
||||
}
|
||||
if (flg & DI_REGVAR)
|
||||
{
|
||||
liveIn.set(rDI,0);
|
||||
pbb->liveIn.set(rDI,0);
|
||||
liveIn.clrReg(rDI);
|
||||
pbb->liveIn.clrReg(rDI);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -555,23 +555,23 @@ void Function::genDU1 ()
|
||||
}
|
||||
|
||||
/* Substitutes the rhs (or lhs if rhs not possible) of ticode for the rhs of picode. */
|
||||
void LOCAL_ID::forwardSubs (COND_EXPR *lhs, COND_EXPR *rhs, iICODE picode, iICODE ticode, int &numHlIcodes) const
|
||||
void LOCAL_ID::forwardSubs (Expr *lhs, Expr *rhs, iICODE picode, iICODE ticode, int &numHlIcodes) const
|
||||
{
|
||||
bool res;
|
||||
UnaryOperator *lhs_unary;
|
||||
while(lhs_unary = dynamic_cast<UnaryOperator *>(lhs))
|
||||
while( (lhs_unary = dynamic_cast<UnaryOperator *>(lhs)) )
|
||||
{
|
||||
if(dynamic_cast<AstIdent *>(lhs_unary))
|
||||
break;
|
||||
lhs = lhs_unary->unaryExp;
|
||||
}
|
||||
AstIdent * lhs_id=dynamic_cast<AstIdent *>(lhs_unary);
|
||||
assert(lhs_id);
|
||||
RegisterNode * lhs_reg=dynamic_cast<RegisterNode *>(lhs_unary);
|
||||
assert(lhs_reg);
|
||||
if (rhs == NULL) /* In case expression popped is NULL */
|
||||
return;
|
||||
|
||||
/* Insert on rhs of ticode, if possible */
|
||||
res = COND_EXPR::insertSubTreeReg (ticode->hlU()->asgn.rhs,rhs, id_arr[lhs_id->ident.idNode.regiIdx].id.regi, this);
|
||||
res = Expr::insertSubTreeReg (ticode->hlU()->asgn.rhs,rhs, id_arr[lhs_reg->regiIdx].id.regi, this);
|
||||
if (res)
|
||||
{
|
||||
picode->invalidate();
|
||||
@@ -580,7 +580,18 @@ void LOCAL_ID::forwardSubs (COND_EXPR *lhs, COND_EXPR *rhs, iICODE picode, iICOD
|
||||
else
|
||||
{
|
||||
/* Try to insert it on lhs of ticode*/
|
||||
res = COND_EXPR::insertSubTreeReg (ticode->hlU()->asgn.lhs,rhs, id_arr[lhs_id->ident.idNode.regiIdx].id.regi, this);
|
||||
RegisterNode *op = dynamic_cast<RegisterNode *>(ticode->hlU()->asgn.m_lhs);
|
||||
if(op)
|
||||
{
|
||||
eReg inserted = id_arr[lhs_reg->regiIdx].id.regi;
|
||||
eReg lhsReg = id_arr[op->regiIdx].id.regi;
|
||||
if((lhsReg==inserted)||Machine_X86::isSubRegisterOf(lhsReg,inserted))
|
||||
{
|
||||
// Do not replace ax = XYZ; given ax = H << P; with H << P =
|
||||
return;
|
||||
}
|
||||
}
|
||||
res = Expr::insertSubTreeReg (ticode->hlU()->asgn.m_lhs,rhs, id_arr[lhs_reg->regiIdx].id.regi, this);
|
||||
if (res)
|
||||
{
|
||||
picode->invalidate();
|
||||
@@ -591,7 +602,7 @@ void LOCAL_ID::forwardSubs (COND_EXPR *lhs, COND_EXPR *rhs, iICODE picode, iICOD
|
||||
|
||||
|
||||
/* 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, Expr *_exp, iICODE picode, iICODE ticode, int *numHlIcodes)
|
||||
{
|
||||
bool res;
|
||||
|
||||
@@ -599,7 +610,7 @@ static void forwardSubsLong (int longIdx, COND_EXPR *_exp, iICODE picode, iICODE
|
||||
return;
|
||||
|
||||
/* Insert on rhs of ticode, if possible */
|
||||
res = COND_EXPR::insertSubTreeLongReg (_exp, ticode->hlU()->asgn.rhs, longIdx);
|
||||
res = Expr::insertSubTreeLongReg (_exp, ticode->hlU()->asgn.rhs, longIdx);
|
||||
if (res)
|
||||
{
|
||||
picode->invalidate();
|
||||
@@ -608,7 +619,7 @@ static void forwardSubsLong (int longIdx, COND_EXPR *_exp, iICODE picode, iICODE
|
||||
else
|
||||
{
|
||||
/* Try to insert it on lhs of ticode*/
|
||||
res = COND_EXPR::insertSubTreeLongReg (_exp, ticode->hlU()->asgn.lhs, longIdx);
|
||||
res = Expr::insertSubTreeLongReg (_exp, ticode->hlU()->asgn.m_lhs, longIdx);
|
||||
if (res)
|
||||
{
|
||||
picode->invalidate();
|
||||
@@ -639,19 +650,9 @@ bool BinaryOperator::xClear(rICODE range_to_check, iICODE lastBBinst, const LOCA
|
||||
}
|
||||
bool AstIdent::xClear(rICODE range_to_check, iICODE lastBBinst, const LOCAL_ID &locId)
|
||||
{
|
||||
iICODE i;
|
||||
uint8_t regi;
|
||||
if (ident.idType == REGISTER)
|
||||
{
|
||||
regi= locId.id_arr[ident.idNode.regiIdx].id.regi;
|
||||
range_to_check.advance_begin(1);
|
||||
auto all_valid_and_high_level_after_start = range_to_check | filtered(ICODE::select_valid_high_level);
|
||||
for (ICODE &i : all_valid_and_high_level_after_start)
|
||||
if ((i.du.def & duReg[regi]).any())
|
||||
return false;
|
||||
if (all_valid_and_high_level_after_start.end().base() != lastBBinst)
|
||||
return true;
|
||||
return false;
|
||||
assert(false);
|
||||
}
|
||||
else
|
||||
return true;
|
||||
@@ -663,7 +664,7 @@ bool AstIdent::xClear(rICODE range_to_check, iICODE lastBBinst, const LOCAL_ID &
|
||||
/// @returns the type size of the stored Arg
|
||||
static int processCArg (Function * pp, Function * pProc, ICODE * picode, size_t numArgs)
|
||||
{
|
||||
COND_EXPR *_exp;
|
||||
Expr *_exp;
|
||||
bool res;
|
||||
|
||||
/* if (numArgs == 0)
|
||||
@@ -677,10 +678,10 @@ static int processCArg (Function * pp, Function * pProc, ICODE * picode, size_t
|
||||
if (pp->flg & PROC_VARARG)
|
||||
{
|
||||
if (numArgs < pp->args.size())
|
||||
adjustActArgType (_exp, pp->args[numArgs].type, pProc);
|
||||
_exp = pProc->adjustActArgType (_exp, pp->args[numArgs].type);
|
||||
}
|
||||
else
|
||||
adjustActArgType (_exp, pp->args[numArgs].type, pProc);
|
||||
_exp = pProc->adjustActArgType (_exp, pp->args[numArgs].type);
|
||||
}
|
||||
}
|
||||
else /* user function */
|
||||
@@ -714,14 +715,14 @@ void LOCAL_ID::processTargetIcode(iICODE picode, int &numHlIcodes, iICODE ticode
|
||||
boolT res;
|
||||
HLTYPE &p_hl(*picode->hlU());
|
||||
HLTYPE &t_hl(*ticode->hlU());
|
||||
AstIdent *lhs_ident = dynamic_cast<AstIdent *>(p_hl.asgn.lhs);
|
||||
|
||||
AstIdent *lhs_ident = dynamic_cast<AstIdent *>(p_hl.asgn.lhs());
|
||||
switch (t_hl.opcode)
|
||||
{
|
||||
case HLI_ASSIGN:
|
||||
assert(lhs_ident);
|
||||
if(isLong)
|
||||
{
|
||||
assert(lhs_ident);
|
||||
forwardSubsLong (lhs_ident->ident.idNode.longIdx,
|
||||
p_hl.asgn.rhs, picode,ticode,
|
||||
&numHlIcodes);
|
||||
@@ -734,18 +735,19 @@ void LOCAL_ID::processTargetIcode(iICODE picode, int &numHlIcodes, iICODE ticode
|
||||
if(isLong)
|
||||
{
|
||||
assert(lhs_ident);
|
||||
res = COND_EXPR::insertSubTreeLongReg (
|
||||
res = Expr::insertSubTreeLongReg (
|
||||
p_hl.asgn.rhs,
|
||||
t_hl.exp.v,
|
||||
lhs_ident->ident.idNode.longIdx);
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(lhs_ident);
|
||||
res = COND_EXPR::insertSubTreeReg (
|
||||
RegisterNode *lhs_reg = dynamic_cast<RegisterNode *>(p_hl.asgn.lhs());
|
||||
assert(lhs_reg);
|
||||
res = Expr::insertSubTreeReg (
|
||||
t_hl.exp.v,
|
||||
p_hl.asgn.rhs,
|
||||
id_arr[lhs_ident->ident.idNode.regiIdx].id.regi,
|
||||
id_arr[lhs_reg->regiIdx].id.regi,
|
||||
this);
|
||||
}
|
||||
if (res)
|
||||
@@ -766,7 +768,7 @@ void LOCAL_ID::processTargetIcode(iICODE picode, int &numHlIcodes, iICODE ticode
|
||||
}
|
||||
}
|
||||
|
||||
void Function::processHliCall(COND_EXPR *_exp, iICODE picode)
|
||||
void Function::processHliCall(Expr *_exp, iICODE picode)
|
||||
{
|
||||
Function * pp;
|
||||
int cb, numArgs;
|
||||
@@ -784,7 +786,7 @@ void Function::processHliCall(COND_EXPR *_exp, iICODE picode)
|
||||
if (pp->flg & PROC_ISLIB) /* library function */
|
||||
{
|
||||
if (pp->args.numArgs > 0)
|
||||
adjustActArgType(_exp, pp->args[numArgs].type, this);
|
||||
_exp = adjustActArgType(_exp, pp->args[numArgs].type);
|
||||
res = picode->newStkArg (_exp, (llIcode)picode->ll()->getOpcode(), this);
|
||||
}
|
||||
else /* user function */
|
||||
@@ -834,8 +836,8 @@ void BB::findBBExps(LOCAL_ID &locals,Function *fnc)
|
||||
bool res;
|
||||
|
||||
ID *_retVal; // function return value
|
||||
COND_EXPR *_exp, // expression pointer - for HLI_POP and HLI_CALL */
|
||||
*lhs; // exp ptr for return value of a HLI_CALL */
|
||||
Expr *_exp; // expression pointer - for HLI_POP and HLI_CALL */
|
||||
//Expr *lhs; // exp ptr for return value of a HLI_CALL */
|
||||
iICODE ticode; // Target icode */
|
||||
HLTYPE *ti_hl=0;
|
||||
uint8_t regi;
|
||||
@@ -897,11 +899,11 @@ void BB::findBBExps(LOCAL_ID &locals,Function *fnc)
|
||||
|
||||
case HLI_JCOND: case HLI_PUSH: case HLI_RET:
|
||||
{
|
||||
AstIdent *v = dynamic_cast<AstIdent *>(_icHl.expr());
|
||||
RegisterNode *v = dynamic_cast<RegisterNode *>(_icHl.expr());
|
||||
assert(v);
|
||||
res = COND_EXPR::insertSubTreeReg (ti_hl->exp.v,
|
||||
res = Expr::insertSubTreeReg (ti_hl->exp.v,
|
||||
_exp,
|
||||
locals.id_arr[v->ident.idNode.regiIdx].id.regi,
|
||||
locals.id_arr[v->regiIdx].id.regi,
|
||||
&locals);
|
||||
if (res)
|
||||
{
|
||||
@@ -930,24 +932,24 @@ void BB::findBBExps(LOCAL_ID &locals,Function *fnc)
|
||||
{
|
||||
case HLI_ASSIGN:
|
||||
assert(ti_hl->asgn.rhs);
|
||||
_exp = _icHl.call.toId();
|
||||
res = COND_EXPR::insertSubTreeReg (ti_hl->asgn.rhs,_exp, _retVal->id.regi, &locals);
|
||||
_exp = _icHl.call.toAst();
|
||||
res = Expr::insertSubTreeReg (ti_hl->asgn.rhs,_exp, _retVal->id.regi, &locals);
|
||||
if (! res)
|
||||
COND_EXPR::insertSubTreeReg (ti_hl->asgn.lhs, _exp,_retVal->id.regi, &locals);
|
||||
Expr::insertSubTreeReg (ti_hl->asgn.m_lhs, _exp,_retVal->id.regi, &locals);
|
||||
//TODO: HERE missing: 2 regs
|
||||
picode->invalidate();
|
||||
numHlIcodes--;
|
||||
break;
|
||||
|
||||
case HLI_PUSH: case HLI_RET:
|
||||
ti_hl->expr( _icHl.call.toId() );
|
||||
ti_hl->expr( _icHl.call.toAst() );
|
||||
picode->invalidate();
|
||||
numHlIcodes--;
|
||||
break;
|
||||
|
||||
case HLI_JCOND:
|
||||
_exp = _icHl.call.toId();
|
||||
res = COND_EXPR::insertSubTreeReg (ti_hl->exp.v, _exp, _retVal->id.regi, &locals);
|
||||
_exp = _icHl.call.toAst();
|
||||
res = Expr::insertSubTreeReg (ti_hl->exp.v, _exp, _retVal->id.regi, &locals);
|
||||
if (res) /* was substituted */
|
||||
{
|
||||
picode->invalidate();
|
||||
@@ -1008,9 +1010,9 @@ void BB::findBBExps(LOCAL_ID &locals,Function *fnc)
|
||||
_exp, picode.base(), ticode, &numHlIcodes);
|
||||
break;
|
||||
case HLI_JCOND: case HLI_PUSH:
|
||||
res = COND_EXPR::insertSubTreeLongReg (_exp,
|
||||
res = Expr::insertSubTreeLongReg (_exp,
|
||||
ticode->hlU()->exp.v,
|
||||
dynamic_cast<AstIdent *>(_icHl.asgn.lhs)->ident.idNode.longIdx);
|
||||
dynamic_cast<AstIdent *>(_icHl.asgn.lhs())->ident.idNode.longIdx);
|
||||
if (res)
|
||||
{
|
||||
picode->invalidate();
|
||||
@@ -1030,26 +1032,26 @@ void BB::findBBExps(LOCAL_ID &locals,Function *fnc)
|
||||
switch (ticode->hl()->opcode)
|
||||
{
|
||||
case HLI_ASSIGN:
|
||||
_exp = _icHl.call.toId();
|
||||
ticode->hlU()->asgn.lhs =
|
||||
AstIdent::idLong(&locals, DST,
|
||||
_exp = _icHl.call.toAst();
|
||||
ticode->hlU()->asgn.lhs(
|
||||
AstIdent::Long(&locals, DST,
|
||||
ticode,HIGH_FIRST, picode.base(),
|
||||
eDEF, *(++iICODE(ticode))->ll());
|
||||
eDEF, *(++iICODE(ticode))->ll()));
|
||||
ticode->hlU()->asgn.rhs = _exp;
|
||||
picode->invalidate();
|
||||
numHlIcodes--;
|
||||
break;
|
||||
|
||||
case HLI_PUSH: case HLI_RET:
|
||||
ticode->hlU()->expr( _icHl.call.toId() );
|
||||
ticode->hlU()->expr( _icHl.call.toAst() );
|
||||
picode->invalidate();
|
||||
numHlIcodes--;
|
||||
break;
|
||||
|
||||
case HLI_JCOND:
|
||||
_exp = _icHl.call.toId();
|
||||
_exp = _icHl.call.toAst();
|
||||
_retVal = &picode->hl()->call.proc->retVal;
|
||||
res = COND_EXPR::insertSubTreeLongReg (_exp,
|
||||
res = Expr::insertSubTreeLongReg (_exp,
|
||||
ticode->hlU()->exp.v,
|
||||
locals.newLongReg ( _retVal->type, _retVal->id.longId.h,
|
||||
_retVal->id.longId.l, picode.base()));
|
||||
@@ -1098,7 +1100,7 @@ void BB::findBBExps(LOCAL_ID &locals,Function *fnc)
|
||||
* assign it to the corresponding registers */
|
||||
if ( not _icHl.call.proc->isLibrary() and (not picode->du1.used(0)) and (picode->du1.numRegsDef > 0))
|
||||
{
|
||||
_exp = AstIdent::idFunc (_icHl.call.proc, _icHl.call.args);
|
||||
_exp = new FuncNode(_icHl.call.proc, _icHl.call.args);
|
||||
auto lhs = AstIdent::idID (&_icHl.call.proc->retVal, &locals, picode.base());
|
||||
picode->setAsgn(lhs, _exp);
|
||||
}
|
||||
@@ -1110,22 +1112,13 @@ void BB::findBBExps(LOCAL_ID &locals,Function *fnc)
|
||||
|
||||
void Function::findExps()
|
||||
{
|
||||
//int i, numHlIcodes;
|
||||
//STKFRAME * args; // pointer to arguments - for HLI_CALL */
|
||||
|
||||
/* Initialize expression stack */
|
||||
g_exp_stk.init();
|
||||
|
||||
/* Traverse tree in dfsLast order */
|
||||
// for (i = 0; i < numBBs; i++)
|
||||
for(BB *pbb : m_dfsLast)
|
||||
for(BB *pbb : m_dfsLast | filtered(BB::ValidFunctor()))
|
||||
{
|
||||
/* Process one BB */
|
||||
// pbb = m_dfsLast[i];
|
||||
if (not pbb->valid())
|
||||
continue;
|
||||
/* Process one valid BB */
|
||||
pbb->findBBExps( this->localId, this);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1135,6 +1128,16 @@ void Function::preprocessReturnDU(LivenessSet &_liveOut)
|
||||
{
|
||||
// int idx;
|
||||
bool isAx, isBx, isCx, isDx;
|
||||
eReg bad_regs[] = {rES,rCS,rDS,rSS};
|
||||
constexpr char * names[] ={"ES","CS","DS","SS"};
|
||||
for(int i=0; i<4; ++i)
|
||||
if(_liveOut.testReg(bad_regs[i]))
|
||||
{
|
||||
fprintf(stderr,"LivenessSet probably screwed up, %s register as an liveOut in preprocessReturnDU\n",names[i]);
|
||||
_liveOut.clrReg(bad_regs[i]);
|
||||
if(not _liveOut.any())
|
||||
return;
|
||||
}
|
||||
flg |= PROC_IS_FUNC;
|
||||
isAx = _liveOut.testReg(rAX);
|
||||
isBx = _liveOut.testReg(rBX);
|
||||
@@ -1205,7 +1208,20 @@ void Function::preprocessReturnDU(LivenessSet &_liveOut)
|
||||
else
|
||||
retVal.id.regi = rDL;
|
||||
/*idx = */localId.newByteWordReg(TYPE_BYTE_SIGN,retVal.id.regi);
|
||||
|
||||
}
|
||||
else if(isAH||isBH||isCH||isDH)
|
||||
{
|
||||
retVal.type = TYPE_BYTE_SIGN;
|
||||
retVal.loc = REG_FRAME;
|
||||
if (isAH)
|
||||
retVal.id.regi = rAH;
|
||||
else if (isBH)
|
||||
retVal.id.regi = rBH;
|
||||
else if (isCH)
|
||||
retVal.id.regi = rCH;
|
||||
else
|
||||
retVal.id.regi = rDH;
|
||||
/*idx = */localId.newByteWordReg(TYPE_BYTE_SIGN,retVal.id.regi);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1217,9 +1233,9 @@ void Function::dataFlow(LivenessSet &_liveOut)
|
||||
|
||||
/* Remove references to register variables */
|
||||
if (flg & SI_REGVAR)
|
||||
_liveOut.set(rSI,0);
|
||||
_liveOut.clrReg(rSI);
|
||||
if (flg & DI_REGVAR)
|
||||
_liveOut.set(rDI,0);
|
||||
_liveOut.clrReg(rDI);
|
||||
|
||||
/* Function - return value register(s) */
|
||||
preprocessReturnDU(_liveOut);
|
||||
@@ -1235,4 +1251,3 @@ void Function::dataFlow(LivenessSet &_liveOut)
|
||||
findExps (); /* forward substitution algorithm */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
98
src/dcc.cpp
98
src/dcc.cpp
@@ -4,9 +4,9 @@
|
||||
* (C) Cristina Cifuentes
|
||||
****************************************************************************/
|
||||
|
||||
#include <cstring>
|
||||
#include "dcc.h"
|
||||
#include "project.h"
|
||||
#include <string.h>
|
||||
|
||||
/* Global variables - extern to other modules */
|
||||
extern char *asm1_name, *asm2_name; /* Assembler output filenames */
|
||||
@@ -22,18 +22,102 @@ extern OPTION option; /* Command line options */
|
||||
static char *initargs(int argc, char *argv[]);
|
||||
static void displayTotalStats(void);
|
||||
#include <llvm/Support/raw_os_ostream.h>
|
||||
#include <llvm/Support/CommandLine.h>
|
||||
#include <llvm/Support/TargetSelect.h>
|
||||
#include <llvm/Support/TargetRegistry.h>
|
||||
#include <llvm/Support/PrettyStackTrace.h>
|
||||
#include <llvm/Support/Signals.h>
|
||||
#include <llvm/Support/Host.h>
|
||||
#include <llvm/Target/TargetMachine.h>
|
||||
#include <llvm/Target/TargetInstrInfo.h>
|
||||
#include <llvm/MC/MCAsmInfo.h>
|
||||
#include <llvm/CodeGen/MachineInstrBuilder.h>
|
||||
|
||||
#include <llvm/TableGen/Main.h>
|
||||
#include <llvm/TableGen/TableGenAction.h>
|
||||
#include <llvm/TableGen/Record.h>
|
||||
/****************************************************************************
|
||||
* main
|
||||
***************************************************************************/
|
||||
#include <iostream>
|
||||
int main(int argc, char *argv[])
|
||||
using namespace llvm;
|
||||
class TVisitor : public TableGenAction {
|
||||
public:
|
||||
virtual bool operator()(raw_ostream &OS, RecordKeeper &Records)
|
||||
{
|
||||
Record *rec = Records.getDef("ADD8i8");
|
||||
if(rec)
|
||||
{
|
||||
if(not rec->getTemplateArgs().empty())
|
||||
std::cout << "Has template args\n";
|
||||
auto classes(rec->getSuperClasses());
|
||||
for(auto val : rec->getSuperClasses())
|
||||
std::cout << "Super "<<val->getName()<<"\n";
|
||||
|
||||
// DagInit * in = rec->getValueAsDag(val.getName());
|
||||
// in->dump();
|
||||
for(const RecordVal &val : rec->getValues())
|
||||
{
|
||||
// val.dump();
|
||||
}
|
||||
rec->dump();
|
||||
|
||||
}
|
||||
// rec = Records.getDef("CCR");
|
||||
// if(rec)
|
||||
// rec->dump();
|
||||
for(auto val : Records.getDefs())
|
||||
{
|
||||
//std::cout<< "Def "<<val.first<<"\n";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
int testTblGen(int argc, char **argv)
|
||||
{
|
||||
using namespace llvm;
|
||||
sys::PrintStackTraceOnErrorSignal();
|
||||
PrettyStackTraceProgram(argc,argv);
|
||||
cl::ParseCommandLineOptions(argc,argv);
|
||||
TVisitor tz;
|
||||
|
||||
return llvm::TableGenMain(argv[0],tz);
|
||||
InitializeNativeTarget();
|
||||
Triple TheTriple;
|
||||
std::string def = sys::getDefaultTargetTriple();
|
||||
std::string MCPU="i386";
|
||||
std::string MARCH="x86";
|
||||
InitializeAllTargetInfos();
|
||||
InitializeAllTargetMCs();
|
||||
InitializeAllAsmPrinters();
|
||||
InitializeAllAsmParsers();
|
||||
InitializeAllDisassemblers();
|
||||
std::string TargetTriple("i386-pc-linux-gnu");
|
||||
TheTriple = Triple(Triple::normalize(TargetTriple));
|
||||
MCOperand op=llvm::MCOperand::CreateImm(11);
|
||||
MCAsmInfo info;
|
||||
raw_os_ostream wrap(std::cerr);
|
||||
op.print(wrap,&info);
|
||||
wrap.flush();
|
||||
std::cerr<<"\n";
|
||||
std::string lookuperr;
|
||||
TargetRegistry::printRegisteredTargetsForVersion();
|
||||
const Target *t = TargetRegistry::lookupTarget(MARCH,TheTriple,lookuperr);
|
||||
TargetOptions opts;
|
||||
std::string Features;
|
||||
opts.PrintMachineCode=1;
|
||||
TargetMachine *tm = t->createTargetMachine(TheTriple.getTriple(),MCPU,Features,opts);
|
||||
std::cerr<<tm->getInstrInfo()->getName(97)<<"\n";
|
||||
const MCInstrDesc &ds(tm->getInstrInfo()->get(97));
|
||||
const MCOperandInfo *op1=ds.OpInfo;
|
||||
uint16_t impl_def = ds.getImplicitDefs()[0];
|
||||
std::cerr<<lookuperr<<"\n";
|
||||
|
||||
exit(0);
|
||||
|
||||
}
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
// llvm::MCOperand op=llvm::MCOperand::CreateImm(11);
|
||||
// llvm::MCAsmInfo info;
|
||||
// llvm::raw_os_ostream wrap(std::cerr);
|
||||
// op.print(wrap,&info);
|
||||
// wrap.flush();
|
||||
/* Extract switches and filename */
|
||||
strcpy(option.filename, initargs(argc, argv));
|
||||
|
||||
|
||||
@@ -247,7 +247,7 @@ void Disassembler::dis1Line(LLInst &inst,int loc_ip, int pass)
|
||||
{
|
||||
for (j = 0; j < cb; j++)
|
||||
{
|
||||
hex_bytes << hex << setw(2) << setfill('0') << uint16_t(prog.Image[inst.label + j]);
|
||||
hex_bytes << hex << setw(2) << setfill('0') << uint16_t(prog.image()[inst.label + j]);
|
||||
}
|
||||
hex_bytes << ' ';
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ static void displayLoadInfo(void)
|
||||
printf("\nRelocation Table\n");
|
||||
for (i = 0; i < prog.cReloc; i++)
|
||||
{
|
||||
printf("%06X -> [%04X]\n", prog.relocTable[i],LH(prog.Image + prog.relocTable[i]));
|
||||
printf("%06X -> [%04X]\n", prog.relocTable[i],LH(prog.image() + prog.relocTable[i]));
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
@@ -303,12 +303,12 @@ void DccFrontend::LoadImage(Project &proj)
|
||||
|
||||
/* Allocate a block of memory for the program. */
|
||||
prog.cbImage = cb + sizeof(PSP);
|
||||
prog.Image = new uint8_t [prog.cbImage];
|
||||
prog.Image[0] = 0xCD; /* Fill in PSP int 20h location */
|
||||
prog.Image[1] = 0x20; /* for termination checking */
|
||||
prog.Imagez = new uint8_t [prog.cbImage];
|
||||
prog.Imagez[0] = 0xCD; /* Fill in PSP int 20h location */
|
||||
prog.Imagez[1] = 0x20; /* for termination checking */
|
||||
|
||||
/* Read in the image past where a PSP would go */
|
||||
if (cb != (int)fread(prog.Image + sizeof(PSP), 1, (size_t)cb, fp))
|
||||
if (cb != (int)fread(prog.Imagez + sizeof(PSP), 1, (size_t)cb, fp))
|
||||
{
|
||||
fatalError(CANNOT_READ, proj.binary_path().c_str());
|
||||
}
|
||||
@@ -323,7 +323,7 @@ void DccFrontend::LoadImage(Project &proj)
|
||||
{
|
||||
for (i = 0; i < prog.cReloc; i++)
|
||||
{
|
||||
uint8_t *p = &prog.Image[prog.relocTable[i]];
|
||||
uint8_t *p = &prog.Imagez[prog.relocTable[i]];
|
||||
uint16_t w = (uint16_t)LH(p) + EXE_RELOCATION;
|
||||
*p++ = (uint8_t)(w & 0x00FF);
|
||||
*p = (uint8_t)((w & 0xFF00) >> 8);
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#include "dcc.h"
|
||||
using namespace std;
|
||||
|
||||
|
||||
/* Masks off bits set by duReg[] */
|
||||
LivenessSet maskDuReg[] = { 0x00,
|
||||
/* uint16_t regs */
|
||||
@@ -38,7 +37,7 @@ static char buf[lineSize]; /* Line buffer for hl icode output */
|
||||
|
||||
|
||||
/* Places the new HLI_ASSIGN high-level operand in the high-level icode array */
|
||||
void HLTYPE::setAsgn(COND_EXPR *lhs, COND_EXPR *rhs)
|
||||
void HLTYPE::setAsgn(Expr *lhs, Expr *rhs)
|
||||
{
|
||||
assert(lhs);
|
||||
set(lhs,rhs);
|
||||
@@ -68,7 +67,7 @@ void ICODE::newCallHl()
|
||||
|
||||
/* Places the new HLI_POP/HLI_PUSH/HLI_RET high-level operand in the high-level icode
|
||||
* array */
|
||||
void ICODE::setUnary(hlIcode op, COND_EXPR *_exp)
|
||||
void ICODE::setUnary(hlIcode op, Expr *_exp)
|
||||
{
|
||||
type = HIGH_LEVEL;
|
||||
hlU()->set(op,_exp);
|
||||
@@ -76,7 +75,7 @@ void ICODE::setUnary(hlIcode op, COND_EXPR *_exp)
|
||||
|
||||
|
||||
/* Places the new HLI_JCOND high-level operand in the high-level icode array */
|
||||
void ICODE::setJCond(COND_EXPR *cexp)
|
||||
void ICODE::setJCond(Expr *cexp)
|
||||
{
|
||||
type = HIGH_LEVEL;
|
||||
hlU()->set(HLI_JCOND,cexp);
|
||||
@@ -293,8 +292,8 @@ void Function::highLevelGen()
|
||||
{
|
||||
size_t numIcode; /* number of icode instructions */
|
||||
iICODE pIcode; /* ptr to current icode node */
|
||||
COND_EXPR *lhs;
|
||||
COND_EXPR *rhs; /* left- and right-hand side of expression */
|
||||
Expr *lhs;
|
||||
Expr *rhs; /* left- and right-hand side of expression */
|
||||
uint32_t _flg; /* icode flags */
|
||||
numIcode = Icode.size();
|
||||
for (iICODE i = Icode.begin(); i!=Icode.end() ; ++i)
|
||||
@@ -333,8 +332,7 @@ void Function::highLevelGen()
|
||||
break;
|
||||
|
||||
case iDEC:
|
||||
rhs = AstIdent::Kte (1, 2);
|
||||
rhs = new BinaryOperator(SUB,lhs, rhs);
|
||||
rhs = new BinaryOperator(SUB,lhs, new Constant(1, 2));
|
||||
pIcode->setAsgn(lhs, rhs);
|
||||
break;
|
||||
|
||||
@@ -343,12 +341,12 @@ void Function::highLevelGen()
|
||||
rhs = new BinaryOperator(DIV,lhs, rhs);
|
||||
if ( ll->testFlags(B) )
|
||||
{
|
||||
lhs = AstIdent::Reg (rAL, 0, &localId);
|
||||
lhs = new RegisterNode(rAL, 0, &localId);
|
||||
pIcode->setRegDU( rAL, eDEF);
|
||||
}
|
||||
else
|
||||
{
|
||||
lhs = AstIdent::Reg (rAX, 0, &localId);
|
||||
lhs = new RegisterNode(rAX, 0, &localId);
|
||||
pIcode->setRegDU( rAX, eDEF);
|
||||
}
|
||||
pIcode->setAsgn(lhs, rhs);
|
||||
@@ -361,8 +359,7 @@ void Function::highLevelGen()
|
||||
break;
|
||||
|
||||
case iINC:
|
||||
rhs = AstIdent::Kte (1, 2);
|
||||
rhs = new BinaryOperator(ADD,lhs, rhs);
|
||||
rhs = new BinaryOperator(ADD,lhs, new Constant(1, 2));
|
||||
pIcode->setAsgn(lhs, rhs);
|
||||
break;
|
||||
|
||||
@@ -373,16 +370,15 @@ void Function::highLevelGen()
|
||||
|
||||
case iMOD:
|
||||
rhs = new BinaryOperator(MOD,lhs, rhs);
|
||||
eReg lhs_reg;
|
||||
|
||||
if ( ll->testFlags(B) )
|
||||
{
|
||||
lhs = AstIdent::Reg (rAH, 0, &localId);
|
||||
pIcode->setRegDU( rAH, eDEF);
|
||||
}
|
||||
lhs_reg = rAH;
|
||||
else
|
||||
{
|
||||
lhs = AstIdent::Reg (rDX, 0, &localId);
|
||||
pIcode->setRegDU( rDX, eDEF);
|
||||
}
|
||||
lhs_reg = rDX;
|
||||
|
||||
lhs = new RegisterNode(lhs_reg, 0, &localId);
|
||||
pIcode->setRegDU( lhs_reg, eDEF);
|
||||
pIcode->setAsgn(lhs, rhs);
|
||||
break;
|
||||
|
||||
@@ -462,7 +458,7 @@ void Function::highLevelGen()
|
||||
|
||||
/* 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 Function::writeCall (Function * tproc, STKFRAME & args, int *numLoc)
|
||||
{
|
||||
//string condExp;
|
||||
ostringstream ostr;
|
||||
@@ -470,7 +466,7 @@ std::string writeCall (Function * tproc, STKFRAME & args, Function * pproc, int
|
||||
for(const STKSYM &sym : args)
|
||||
{
|
||||
if(sym.actual)
|
||||
ostr << sym.actual->walkCondExpr (pproc, numLoc);
|
||||
ostr << sym.actual->walkCondExpr (this, numLoc);
|
||||
else
|
||||
ostr << "";
|
||||
if((&sym)!=&(args.back()))
|
||||
@@ -484,11 +480,15 @@ std::string writeCall (Function * tproc, STKFRAME & args, Function * pproc, int
|
||||
/* Displays the output of a HLI_JCOND icode. */
|
||||
char *writeJcond (const HLTYPE &h, Function * pProc, int *numLoc)
|
||||
{
|
||||
assert(h.expr());
|
||||
memset (buf, ' ', sizeof(buf));
|
||||
buf[0] = '\0';
|
||||
strcat (buf, "if ");
|
||||
COND_EXPR *inverted=h.expr()->inverse();
|
||||
if(h.opcode==HLI_INVALID)
|
||||
{
|
||||
return "if (*HLI_INVALID*) {\n";
|
||||
}
|
||||
assert(h.expr());
|
||||
Expr *inverted=h.expr()->inverse();
|
||||
//inverseCondOp (&h.exp);
|
||||
std::string e = inverted->walkCondExpr (pProc, numLoc);
|
||||
delete inverted;
|
||||
@@ -506,7 +506,12 @@ char *writeJcondInv (HLTYPE h, Function * pProc, int *numLoc)
|
||||
memset (buf, ' ', sizeof(buf));
|
||||
buf[0] = '\0';
|
||||
strcat (buf, "if ");
|
||||
std::string e = h.expr()->walkCondExpr (pProc, numLoc);
|
||||
std::string e;
|
||||
if(h.expr()==nullptr)
|
||||
e = "( *failed condition recovery* )";
|
||||
else
|
||||
e = h.expr()->walkCondExpr (pProc, numLoc);
|
||||
|
||||
strcat (buf, e.c_str());
|
||||
strcat (buf, " {\n");
|
||||
return (buf);
|
||||
@@ -515,7 +520,7 @@ char *writeJcondInv (HLTYPE h, Function * pProc, int *numLoc)
|
||||
string AssignType::writeOut(Function *pProc, int *numLoc) const
|
||||
{
|
||||
ostringstream ostr;
|
||||
ostr << lhs->walkCondExpr (pProc, numLoc);
|
||||
ostr << m_lhs->walkCondExpr (pProc, numLoc);
|
||||
ostr << " = ";
|
||||
ostr << rhs->walkCondExpr (pProc, numLoc);
|
||||
ostr << ";\n";
|
||||
@@ -524,7 +529,7 @@ string AssignType::writeOut(Function *pProc, int *numLoc) const
|
||||
string CallType::writeOut(Function *pProc, int *numLoc) const
|
||||
{
|
||||
ostringstream ostr;
|
||||
ostr << writeCall (proc, *args, pProc,numLoc);
|
||||
ostr << pProc->writeCall (proc, *args, numLoc);
|
||||
ostr << ";\n";
|
||||
return ostr.str();
|
||||
}
|
||||
@@ -535,13 +540,14 @@ string ExpType::writeOut(Function *pProc, int *numLoc) const
|
||||
return v->walkCondExpr (pProc, numLoc);
|
||||
}
|
||||
|
||||
void HLTYPE::set(COND_EXPR *l, COND_EXPR *r)
|
||||
void HLTYPE::set(Expr *l, Expr *r)
|
||||
{
|
||||
assert(l);
|
||||
assert(r);
|
||||
opcode = HLI_ASSIGN;
|
||||
assert((asgn.lhs==0) and (asgn.rhs==0)); //prevent memory leaks
|
||||
asgn.lhs=l;
|
||||
//assert((asgn.lhs==0) and (asgn.rhs==0)); //prevent memory leaks
|
||||
assert(dynamic_cast<UnaryOperator *>(l));
|
||||
asgn.m_lhs=l;
|
||||
asgn.rhs=r;
|
||||
}
|
||||
/* Returns a string with the contents of the current high-level icode.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "icode.h"
|
||||
#include "ast.h"
|
||||
|
||||
void HLTYPE::replaceExpr(COND_EXPR *e)
|
||||
void HLTYPE::replaceExpr(Expr *e)
|
||||
{
|
||||
assert(e);
|
||||
delete exp.v;
|
||||
|
||||
@@ -103,6 +103,12 @@ void HLTYPE::setCall(Function *proc)
|
||||
}
|
||||
bool AssignType::removeRegFromLong(eReg regi, LOCAL_ID *locId)
|
||||
{
|
||||
lhs->performLongRemoval(regi,locId);
|
||||
m_lhs=lhs()->performLongRemoval(regi,locId);
|
||||
return true;
|
||||
}
|
||||
void AssignType::lhs(Expr *l)
|
||||
{
|
||||
assert(dynamic_cast<UnaryOperator *>(l));
|
||||
m_lhs=l;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,9 +26,9 @@ bool Idiom5::match(iICODE pIcode)
|
||||
int Idiom5::action()
|
||||
{
|
||||
AstIdent *rhs,*lhs;
|
||||
COND_EXPR *expr;
|
||||
lhs = AstIdent::idLong (&m_func->localId, DST, m_icodes[0], LOW_FIRST, m_icodes[0], USE_DEF, *m_icodes[1]->ll());
|
||||
rhs = AstIdent::idLong (&m_func->localId, SRC, m_icodes[0], LOW_FIRST, m_icodes[0], eUSE, *m_icodes[1]->ll());
|
||||
Expr *expr;
|
||||
lhs = AstIdent::Long (&m_func->localId, DST, m_icodes[0], LOW_FIRST, m_icodes[0], USE_DEF, *m_icodes[1]->ll());
|
||||
rhs = AstIdent::Long (&m_func->localId, SRC, m_icodes[0], LOW_FIRST, m_icodes[0], eUSE, *m_icodes[1]->ll());
|
||||
expr = new BinaryOperator(ADD,lhs, rhs);
|
||||
m_icodes[0]->setAsgn(lhs, expr);
|
||||
m_icodes[1]->invalidate();
|
||||
@@ -61,9 +61,9 @@ int Idiom6::action()
|
||||
{
|
||||
|
||||
AstIdent *rhs,*lhs;
|
||||
COND_EXPR *expr;
|
||||
lhs = AstIdent::idLong (&m_func->localId, DST, m_icodes[0], LOW_FIRST, m_icodes[0], USE_DEF, *m_icodes[1]->ll());
|
||||
rhs = AstIdent::idLong (&m_func->localId, SRC, m_icodes[0], LOW_FIRST, m_icodes[0], eUSE, *m_icodes[1]->ll());
|
||||
Expr *expr;
|
||||
lhs = AstIdent::Long (&m_func->localId, DST, m_icodes[0], LOW_FIRST, m_icodes[0], USE_DEF, *m_icodes[1]->ll());
|
||||
rhs = AstIdent::Long (&m_func->localId, SRC, m_icodes[0], LOW_FIRST, m_icodes[0], eUSE, *m_icodes[1]->ll());
|
||||
expr = new BinaryOperator(SUB,lhs, rhs);
|
||||
m_icodes[0]->setAsgn(lhs, expr);
|
||||
m_icodes[1]->invalidate();
|
||||
@@ -102,7 +102,13 @@ bool Idiom18::match(iICODE picode)
|
||||
m_is_dec = m_icodes[1]->ll()->match(iDEC);
|
||||
|
||||
uint8_t regi; /* register of the MOV */
|
||||
|
||||
if(not (m_icodes[0]->ll()->match(iMOV) and m_icodes[0]->ll()->dst.isReg() ))
|
||||
return false;
|
||||
regi = m_icodes[0]->ll()->dst.regi;
|
||||
if( not ( m_icodes[2]->ll()->match(iCMP) && (m_icodes[2]->ll()->dst.regi == regi) &&
|
||||
m_icodes[3]->ll()->conditionalJump() ) )
|
||||
return false;
|
||||
// Simple matching finished, select apropriate matcher based on dst type
|
||||
/* Get variable */
|
||||
if (m_icodes[1]->ll()->dst.regi == 0) /* global variable */
|
||||
{
|
||||
@@ -111,10 +117,11 @@ bool Idiom18::match(iICODE picode)
|
||||
}
|
||||
else if ( m_icodes[1]->ll()->dst.isReg() ) /* register */
|
||||
{
|
||||
if ((m_icodes[1]->ll()->dst.regi == rSI) && (m_func->flg & SI_REGVAR))
|
||||
m_idiom_type = 1;
|
||||
else if ((m_icodes[1]->ll()->dst.regi == rDI) && (m_func->flg & DI_REGVAR))
|
||||
m_idiom_type = 1;
|
||||
m_idiom_type = 1;
|
||||
// if ((m_icodes[1]->ll()->dst.regi == rSI) && (m_func->flg & SI_REGVAR))
|
||||
// m_idiom_type = 1;
|
||||
// else if ((m_icodes[1]->ll()->dst.regi == rDI) && (m_func->flg & DI_REGVAR))
|
||||
// m_idiom_type = 1;
|
||||
}
|
||||
else if (m_icodes[1]->ll()->dst.off) /* local variable */
|
||||
m_idiom_type = 2;
|
||||
@@ -134,31 +141,23 @@ bool Idiom18::match(iICODE picode)
|
||||
break;
|
||||
case 1: /* register variable */
|
||||
/* Check previous instruction for a MOV */
|
||||
if (m_icodes[0]->ll()->match(iMOV) && (m_icodes[0]->ll()->src().regi == m_icodes[1]->ll()->dst.regi))
|
||||
if ( (m_icodes[0]->ll()->src().regi == m_icodes[1]->ll()->dst.regi))
|
||||
{
|
||||
regi = m_icodes[0]->ll()->dst.regi;
|
||||
if ( m_icodes[0]->ll()->dst.isReg() )
|
||||
{
|
||||
if ( m_icodes[2]->ll()->match(iCMP) && (m_icodes[2]->ll()->dst.regi == regi) &&
|
||||
m_icodes[3]->ll()->conditionalJump() )
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case 2: /* local */
|
||||
if (m_icodes[0]->ll()->match(iMOV) && (m_icodes[0]->ll()->src().off == m_icodes[1]->ll()->dst.off))
|
||||
if ((m_icodes[0]->ll()->src().off == m_icodes[1]->ll()->dst.off))
|
||||
{
|
||||
regi = m_icodes[0]->ll()->dst.regi;
|
||||
if ( m_icodes[0]->ll()->dst.isReg() )
|
||||
{
|
||||
if ( m_icodes[2]->ll()->match(iCMP) && (m_icodes[2]->ll()->dst.regi == regi) &&
|
||||
m_icodes[3]->ll()->conditionalJump() )
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case 3: // indexed
|
||||
printf("Unsupported idiom18 type: indexed");
|
||||
printf("Untested idiom18 type: indexed\n");
|
||||
if ((m_icodes[0]->ll()->src() == m_icodes[1]->ll()->dst))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
@@ -166,8 +165,8 @@ bool Idiom18::match(iICODE picode)
|
||||
|
||||
int Idiom18::action() // action length
|
||||
{
|
||||
COND_EXPR *rhs,*lhs;/* Pointers to left and right hand side exps */
|
||||
COND_EXPR *expr;
|
||||
Expr *rhs,*lhs;/* Pointers to left and right hand side exps */
|
||||
Expr *expr;
|
||||
lhs = AstIdent::id (*m_icodes[0]->ll(), SRC, m_func, m_icodes[1], *m_icodes[1], eUSE);
|
||||
lhs = UnaryOperator::Create(m_is_dec ? POST_DEC : POST_INC, lhs);
|
||||
rhs = AstIdent::id (*m_icodes[2]->ll(), SRC, m_func, m_icodes[1], *m_icodes[3], eUSE);
|
||||
@@ -195,38 +194,40 @@ bool Idiom19::match(iICODE picode)
|
||||
if(std::distance(picode,m_end)<2)
|
||||
return false;
|
||||
ICODE &ic(*picode);
|
||||
|
||||
int type;
|
||||
for(int i=0; i<2; ++i)
|
||||
m_icodes[i] =picode++;
|
||||
m_is_dec = m_icodes[0]->ll()->match(iDEC);
|
||||
if ( not m_icodes[1]->ll()->conditionalJump() )
|
||||
return false;
|
||||
if (m_icodes[0]->ll()->dst.regi == 0) /* global variable */
|
||||
/* not supported yet */ ;
|
||||
else if ( m_icodes[0]->ll()->dst.isReg() ) /* register */
|
||||
{
|
||||
// if (((picode->ll()->dst.regi == rSI) && (pproc->flg & SI_REGVAR)) ||
|
||||
// ((picode->ll()->dst.regi == rDI) && (pproc->flg & DI_REGVAR)))
|
||||
if (m_icodes[1]->ll()->conditionalJump())
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
else if (m_icodes[0]->ll()->dst.off) /* stack variable */
|
||||
{
|
||||
if ( m_icodes[1]->ll()->conditionalJump() )
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
else /* indexed */
|
||||
{
|
||||
fprintf(stderr,"idiom19 : Untested type [indexed]\n");
|
||||
return true;
|
||||
|
||||
/* not supported yet */
|
||||
}
|
||||
return false;
|
||||
}
|
||||
int Idiom19::action()
|
||||
{
|
||||
COND_EXPR *lhs,*rhs,*expr;
|
||||
ICODE &ic1(*m_icodes[1]);
|
||||
Expr *lhs,*expr;
|
||||
|
||||
lhs = AstIdent::id (*m_icodes[0]->ll(), DST, m_func, m_icodes[0], *m_icodes[1], eUSE);
|
||||
lhs = UnaryOperator::Create(m_is_dec ? PRE_DEC : PRE_INC, lhs);
|
||||
rhs = AstIdent::Kte (0, 2);
|
||||
expr = new BinaryOperator(condOpJCond[m_icodes[1]->ll()->getOpcode() - iJB],lhs, rhs);
|
||||
expr = new BinaryOperator(condOpJCond[m_icodes[1]->ll()->getOpcode() - iJB],lhs, new Constant(0, 2));
|
||||
m_icodes[1]->setJCond(expr);
|
||||
m_icodes[0]->invalidate();
|
||||
return 2;
|
||||
@@ -255,6 +256,9 @@ bool Idiom20::match(iICODE picode)
|
||||
return false;
|
||||
for(int i=0; i<4; ++i)
|
||||
m_icodes[i] =picode++;
|
||||
/* Check second instruction for a MOV */
|
||||
if(not (m_icodes[1]->ll()->match(iMOV) && m_icodes[1]->ll()->dst.isReg()))
|
||||
return false;
|
||||
|
||||
m_is_dec = m_icodes[0]->ll()->match(iDEC) ? PRE_DEC : PRE_INC;
|
||||
|
||||
@@ -266,53 +270,52 @@ bool Idiom20::match(iICODE picode)
|
||||
}
|
||||
else if ( ll_dest.isReg() ) /* register */
|
||||
{
|
||||
if ((ll_dest.regi == rSI) && (m_func->flg & SI_REGVAR))
|
||||
type = 1;
|
||||
else if ((ll_dest.regi == rDI) && (m_func->flg & DI_REGVAR))
|
||||
type = 1;
|
||||
type = 1;
|
||||
// if ((ll_dest.regi == rSI) && (m_func->flg & SI_REGVAR))
|
||||
// type = 1;
|
||||
// else if ((ll_dest.regi == rDI) && (m_func->flg & DI_REGVAR))
|
||||
// type = 1;
|
||||
}
|
||||
else if (ll_dest.off) /* local variable */
|
||||
type = 2;
|
||||
else /* indexed */
|
||||
{
|
||||
printf("idiom20 : Unsupported type [indexed]\n");
|
||||
printf("idiom20 : Untested type [indexed]\n");
|
||||
type = 3;
|
||||
/* not supported yet */ ;
|
||||
}
|
||||
|
||||
/* Check previous instruction for a MOV */
|
||||
if (type == 1) /* register variable */
|
||||
regi = m_icodes[1]->ll()->dst.regi;
|
||||
const LLOperand &mov_src(m_icodes[1]->ll()->src());
|
||||
if (m_icodes[2]->ll()->match(iCMP,(eReg)regi) && m_icodes[3]->ll()->conditionalJump())
|
||||
{
|
||||
if (m_icodes[1]->ll()->match(iMOV) &&
|
||||
(m_icodes[1]->ll()->src().regi == ll_dest.regi))
|
||||
switch(type)
|
||||
{
|
||||
regi = m_icodes[1]->ll()->dst.regi;
|
||||
if ( m_icodes[1]->ll()->dst.isReg() )
|
||||
{
|
||||
if (m_icodes[2]->ll()->match(iCMP,(eReg)regi) &&
|
||||
m_icodes[3]->ll()->conditionalJump())
|
||||
case 1: /* register variable */
|
||||
if ((mov_src.regi == ll_dest.regi))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (type == 2) /* local */
|
||||
{
|
||||
if ( m_icodes[0]->ll()->match(iMOV) &&
|
||||
(m_icodes[1]->ll()->src().off == ll_dest.off))
|
||||
{
|
||||
regi = m_icodes[1]->ll()->dst.regi;
|
||||
if ( m_icodes[1]->ll()->dst.isReg() )
|
||||
{
|
||||
if (m_icodes[2]->ll()->match(iCMP,(eReg)regi) &&
|
||||
m_icodes[3]->ll()->conditionalJump())
|
||||
}
|
||||
break;
|
||||
case 2: // local
|
||||
if ((mov_src.off == ll_dest.off))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
fprintf(stderr,"Test 3 ");
|
||||
if ((mov_src == ll_dest))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
int Idiom20::action()
|
||||
{
|
||||
COND_EXPR *lhs,*rhs,*expr;
|
||||
Expr *lhs,*rhs,*expr;
|
||||
lhs = AstIdent::id (*m_icodes[1]->ll(), SRC, m_func, m_icodes[0], *m_icodes[0], eUSE);
|
||||
lhs = UnaryOperator::Create(m_is_dec, lhs);
|
||||
rhs = AstIdent::id (*m_icodes[2]->ll(), SRC, m_func, m_icodes[0], *m_icodes[3], eUSE);
|
||||
|
||||
@@ -50,7 +50,7 @@ int Idiom14::action()
|
||||
{
|
||||
int idx;
|
||||
AstIdent *lhs;
|
||||
COND_EXPR *rhs;
|
||||
Expr *rhs;
|
||||
|
||||
idx = m_func->localId.newLongReg (TYPE_LONG_SIGN, m_regH, m_regL, m_icodes[0]);
|
||||
lhs = AstIdent::LongIdx (idx);
|
||||
@@ -101,8 +101,8 @@ bool Idiom13::match(iICODE pIcode)
|
||||
int Idiom13::action()
|
||||
{
|
||||
AstIdent *lhs;
|
||||
COND_EXPR *rhs;
|
||||
lhs = AstIdent::Reg (m_loaded_reg, 0, &m_func->localId);
|
||||
Expr *rhs;
|
||||
lhs = new RegisterNode(m_loaded_reg, 0, &m_func->localId);
|
||||
m_icodes[0]->setRegDU( m_loaded_reg, eDEF);
|
||||
m_icodes[0]->du1.numRegsDef--; /* prev uint8_t reg def */
|
||||
rhs = AstIdent::id (*m_icodes[0]->ll(), SRC, m_func, m_icodes[0], *m_icodes[0], NONE);
|
||||
|
||||
@@ -53,8 +53,8 @@ bool Idiom11::match (iICODE picode)
|
||||
int Idiom11::action()
|
||||
{
|
||||
AstIdent *lhs;
|
||||
COND_EXPR *rhs;
|
||||
lhs = AstIdent::idLong (&m_func->localId, DST, m_icodes[0], HIGH_FIRST,m_icodes[0], USE_DEF, *m_icodes[1]->ll());
|
||||
Expr *rhs;
|
||||
lhs = AstIdent::Long (&m_func->localId, DST, m_icodes[0], HIGH_FIRST,m_icodes[0], USE_DEF, *m_icodes[1]->ll());
|
||||
rhs = UnaryOperator::Create(NEGATION, lhs);
|
||||
m_icodes[0]->setAsgn(lhs, rhs);
|
||||
m_icodes[1]->invalidate();
|
||||
@@ -96,8 +96,8 @@ bool Idiom16::match (iICODE picode)
|
||||
int Idiom16::action()
|
||||
{
|
||||
AstIdent *lhs;
|
||||
COND_EXPR *rhs;
|
||||
lhs = AstIdent::Reg (m_icodes[0]->ll()->dst.regi, m_icodes[0]->ll()->getFlag(),&m_func->localId);
|
||||
Expr *rhs;
|
||||
lhs = new RegisterNode(m_icodes[0]->ll()->dst.regi, m_icodes[0]->ll()->getFlag(),&m_func->localId);
|
||||
rhs = UnaryOperator::Create(NEGATION, lhs->clone());
|
||||
m_icodes[0]->setAsgn(lhs, rhs);
|
||||
m_icodes[1]->invalidate();
|
||||
|
||||
@@ -29,7 +29,7 @@ int Idiom8::action()
|
||||
{
|
||||
int idx;
|
||||
AstIdent *lhs;
|
||||
COND_EXPR *rhs,*expr;
|
||||
Expr *expr;
|
||||
eReg regH,regL;
|
||||
regH=m_icodes[0]->ll()->dst.regi;
|
||||
regL=m_icodes[1]->ll()->dst.regi;
|
||||
@@ -37,8 +37,7 @@ int Idiom8::action()
|
||||
lhs = AstIdent::LongIdx (idx);
|
||||
m_icodes[0]->setRegDU( regL, USE_DEF);
|
||||
|
||||
rhs = AstIdent::Kte(1,2);
|
||||
expr = new BinaryOperator(SHR,lhs, rhs);
|
||||
expr = new BinaryOperator(SHR,lhs, new Constant(1, 2));
|
||||
m_icodes[0]->setAsgn(lhs, expr);
|
||||
m_icodes[1]->invalidate();
|
||||
return 2;
|
||||
@@ -81,11 +80,11 @@ int Idiom15::action()
|
||||
{
|
||||
AstIdent *lhs;
|
||||
|
||||
COND_EXPR *rhs,*_exp;
|
||||
lhs = AstIdent::Reg (m_icodes[0]->ll()->dst.regi,
|
||||
Expr *rhs,*_exp;
|
||||
lhs = new RegisterNode(m_icodes[0]->ll()->dst.regi,
|
||||
m_icodes[0]->ll()->getFlag() & NO_SRC_B,
|
||||
&m_func->localId);
|
||||
rhs = AstIdent::Kte (m_icodes.size(), 2);
|
||||
rhs = new Constant(m_icodes.size(), 2);
|
||||
_exp = new BinaryOperator(SHL,lhs, rhs);
|
||||
m_icodes[0]->setAsgn(lhs, _exp);
|
||||
for (size_t i=1; i<m_icodes.size()-1; ++i)
|
||||
@@ -119,7 +118,7 @@ bool Idiom12::match(iICODE pIcode)
|
||||
int Idiom12::action()
|
||||
{
|
||||
int idx;
|
||||
COND_EXPR *rhs,*expr;
|
||||
Expr *expr;
|
||||
AstIdent *lhs;
|
||||
|
||||
eReg regH,regL;
|
||||
@@ -129,8 +128,7 @@ int Idiom12::action()
|
||||
idx = m_func->localId.newLongReg (TYPE_LONG_UNSIGN, regH, regL,m_icodes[0]);
|
||||
lhs = AstIdent::LongIdx (idx);
|
||||
m_icodes[0]->setRegDU( regH, USE_DEF);
|
||||
rhs = AstIdent::Kte (1, 2);
|
||||
expr = new BinaryOperator(SHL,lhs, rhs);
|
||||
expr = new BinaryOperator(SHL,lhs, new Constant(1, 2));
|
||||
m_icodes[0]->setAsgn(lhs, expr);
|
||||
m_icodes[1]->invalidate();
|
||||
return 2;
|
||||
@@ -161,15 +159,14 @@ int Idiom9::action()
|
||||
{
|
||||
int idx;
|
||||
AstIdent *lhs;
|
||||
COND_EXPR *rhs,*expr;
|
||||
Expr *rhs,*expr;
|
||||
eReg regH,regL;
|
||||
regL=m_icodes[1]->ll()->dst.regi;
|
||||
regH=m_icodes[0]->ll()->dst.regi;
|
||||
idx = m_func->localId.newLongReg (TYPE_LONG_UNSIGN,regH,regL,m_icodes[0]);
|
||||
lhs = AstIdent::LongIdx (idx);
|
||||
m_icodes[0]->setRegDU(regL, USE_DEF);
|
||||
rhs = AstIdent::Kte (1, 2);
|
||||
expr = new BinaryOperator(SHR,lhs, rhs);
|
||||
expr = new BinaryOperator(SHR,lhs, new Constant(1, 2));
|
||||
m_icodes[0]->setAsgn(lhs, expr);
|
||||
m_icodes[1]->invalidate();
|
||||
return 2;
|
||||
|
||||
@@ -39,11 +39,11 @@ bool Idiom21::match (iICODE picode)
|
||||
}
|
||||
int Idiom21::action()
|
||||
{
|
||||
COND_EXPR *rhs;
|
||||
Expr *rhs;
|
||||
AstIdent *lhs;
|
||||
|
||||
lhs = AstIdent::idLong (&m_func->localId, DST, m_icodes[0],HIGH_FIRST, m_icodes[0], eDEF, *m_icodes[1]->ll());
|
||||
rhs = AstIdent::Kte (m_icodes[1]->ll()->src().getImm2() , 4);
|
||||
lhs = AstIdent::Long (&m_func->localId, DST, m_icodes[0],HIGH_FIRST, m_icodes[0], eDEF, *m_icodes[1]->ll());
|
||||
rhs = new Constant(m_icodes[1]->ll()->src().getImm2(), 4);
|
||||
m_icodes[0]->setAsgn(lhs, rhs);
|
||||
m_icodes[0]->du.use = 0; /* clear register used in iXOR */
|
||||
m_icodes[1]->invalidate();
|
||||
@@ -84,11 +84,9 @@ bool Idiom7::match(iICODE picode)
|
||||
}
|
||||
int Idiom7::action()
|
||||
{
|
||||
COND_EXPR *lhs;
|
||||
COND_EXPR *rhs;
|
||||
Expr *lhs;
|
||||
lhs = AstIdent::id (*m_icode->ll(), DST, m_func, m_icode, *m_icode, NONE);
|
||||
rhs = AstIdent::Kte (0, 2);
|
||||
m_icode->setAsgn(dynamic_cast<AstIdent *>(lhs), rhs);
|
||||
m_icode->setAsgn(dynamic_cast<AstIdent *>(lhs), new Constant(0, 2));
|
||||
m_icode->du.use = 0; /* clear register used in iXOR */
|
||||
m_icode->ll()->setFlags(I);
|
||||
return 1;
|
||||
|
||||
@@ -341,13 +341,13 @@ boolT checkLongEq (LONG_STKID_TYPE longId, iICODE pIcode, int i, Function * pPro
|
||||
|
||||
if ( not pIcode->ll()->testFlags(NO_SRC) )
|
||||
{
|
||||
asgn.rhs = AstIdent::idLong (&pProc->localId, SRC, pIcode, HIGH_FIRST, pIcode, eUSE, atOffset);
|
||||
asgn.rhs = AstIdent::Long (&pProc->localId, SRC, pIcode, HIGH_FIRST, pIcode, eUSE, atOffset);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if ((longId.offH == pmHsrc->off) && (longId.offL == pmLsrc->off))
|
||||
{
|
||||
asgn.lhs = AstIdent::idLong (&pProc->localId, DST, pIcode, HIGH_FIRST, pIcode,eDEF, atOffset);
|
||||
asgn.lhs = AstIdent::Long (&pProc->localId, DST, pIcode, HIGH_FIRST, pIcode,eDEF, atOffset);
|
||||
asgn.rhs = AstIdent::LongIdx (i);
|
||||
return true;
|
||||
}
|
||||
@@ -380,13 +380,13 @@ boolT checkLongRegEq (LONGID_TYPE longId, iICODE pIcode, int i,
|
||||
asgn.lhs = AstIdent::LongIdx (i);
|
||||
if ( not pIcode->ll()->testFlags(NO_SRC) )
|
||||
{
|
||||
asgn.rhs = AstIdent::idLong (&pProc->localId, SRC, pIcode, HIGH_FIRST, pIcode, eUSE, atOffset);
|
||||
asgn.rhs = AstIdent::Long (&pProc->localId, SRC, pIcode, HIGH_FIRST, pIcode, eUSE, atOffset);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if ((longId.h == pmHsrc->regi) && (longId.l == pmLsrc->regi))
|
||||
{
|
||||
asgn.lhs = AstIdent::idLong (&pProc->localId, DST, pIcode, HIGH_FIRST, pIcode, eDEF, atOffset);
|
||||
asgn.lhs = AstIdent::Long (&pProc->localId, DST, pIcode, HIGH_FIRST, pIcode, eDEF, atOffset);
|
||||
asgn.rhs = AstIdent::LongIdx (i);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -81,11 +81,11 @@ void DccFrontend::parse(Project &proj)
|
||||
|
||||
/* Returns the size of the string pointed by sym and delimited by delim.
|
||||
* Size includes delimiter. */
|
||||
int strSize (uint8_t *sym, char delim)
|
||||
int strSize (const uint8_t *sym, char delim)
|
||||
{
|
||||
PROG &prog(Project::get()->prog);
|
||||
int till_end = sym-prog.Image;
|
||||
uint8_t *end_ptr=std::find(sym,sym+(prog.cbImage-(till_end)),delim);
|
||||
int till_end = sym-prog.image();
|
||||
const 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");
|
||||
@@ -311,8 +311,8 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
|
||||
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], '$') :
|
||||
strSize (&prog.image()[operand], '$'); // + 0x100
|
||||
global_symbol_table.updateSymType (operand, TypeContainer(TYPE_STR, size));
|
||||
}
|
||||
}
|
||||
@@ -355,9 +355,9 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
|
||||
if ((psym = lookupAddr(&ll->src(), pstate, 4, eDuVal::USE))
|
||||
/* && (Icode.ll()->flg & SEG_IMMED) */ )
|
||||
{
|
||||
offset = LH(&prog.Image[psym->label]);
|
||||
offset = LH(&prog.image()[psym->label]);
|
||||
pstate->setState( (ll->getOpcode() == iLDS)? rDS: rES,
|
||||
LH(&prog.Image[psym->label + 2]));
|
||||
LH(&prog.image()[psym->label + 2]));
|
||||
pstate->setState( ll->dst.regi, (int16_t)offset);
|
||||
psym->type = TYPE_PTR;
|
||||
}
|
||||
@@ -370,7 +370,7 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
|
||||
|
||||
if (err == INVALID_386OP || err == INVALID_OPCODE)
|
||||
{
|
||||
fatalError(err, prog.Image[_Icode.ll()->label], _Icode.ll()->label);
|
||||
fatalError(err, prog.image()[_Icode.ll()->label], _Icode.ll()->label);
|
||||
this->flg |= PROC_BADINST;
|
||||
}
|
||||
else if (err == IP_OUT_OF_RANGE)
|
||||
@@ -410,7 +410,7 @@ bool Function::followAllTableEntries(JumpTable &table, uint32_t cs, ICODE& pIcod
|
||||
for (size_t i = table.start; i < table.finish; i += 2)
|
||||
{
|
||||
StCopy = *pstate;
|
||||
StCopy.IP = cs + LH(&prog.Image[i]);
|
||||
StCopy.IP = cs + LH(&prog.image()[i]);
|
||||
iICODE last_current_insn = (++Icode.rbegin()).base();
|
||||
|
||||
FollowCtrl (pcallGraph, &StCopy);
|
||||
@@ -434,7 +434,7 @@ bool Function::process_JMP (ICODE & pIcode, STATE *pstate, CALL_GRAPH * pcallGra
|
||||
if (pIcode.ll()->testFlags(I))
|
||||
{
|
||||
if (pIcode.ll()->getOpcode() == iJMPF)
|
||||
pstate->setState( rCS, LH(prog.Image + pIcode.ll()->label + 3));
|
||||
pstate->setState( rCS, LH(prog.image() + pIcode.ll()->label + 3));
|
||||
pstate->IP = pIcode.ll()->src().getImm2();
|
||||
int64_t i = pIcode.ll()->src().getImm2();
|
||||
if (i < 0)
|
||||
@@ -483,7 +483,7 @@ bool Function::process_JMP (ICODE & pIcode, STATE *pstate, CALL_GRAPH * pcallGra
|
||||
cs = (uint32_t)(uint16_t)pstate->r[rCS] << 4;
|
||||
for (i = offTable; i < endTable; i += 2)
|
||||
{
|
||||
target = cs + LH(&prog.Image[i]);
|
||||
target = cs + LH(&prog.image()[i]);
|
||||
if (target < endTable && target >= offTable)
|
||||
endTable = target;
|
||||
else if (target >= (uint32_t)prog.cbImage)
|
||||
@@ -492,9 +492,9 @@ bool Function::process_JMP (ICODE & pIcode, STATE *pstate, CALL_GRAPH * pcallGra
|
||||
|
||||
for (i = offTable; i < endTable; i += 2)
|
||||
{
|
||||
target = cs + LH(&prog.Image[i]);
|
||||
target = cs + LH(&prog.image()[i]);
|
||||
/* Be wary of 00 00 as code - it's probably data */
|
||||
if (! (prog.Image[target] || prog.Image[target+1]) ||
|
||||
if (! (prog.image()[target] || prog.image()[target+1]) ||
|
||||
scan(target, _Icode))
|
||||
endTable = i;
|
||||
}
|
||||
@@ -516,7 +516,7 @@ bool Function::process_JMP (ICODE & pIcode, STATE *pstate, CALL_GRAPH * pcallGra
|
||||
for (i = offTable, k = 0; i < endTable; i += 2)
|
||||
{
|
||||
StCopy = *pstate;
|
||||
StCopy.IP = cs + LH(&prog.Image[i]);
|
||||
StCopy.IP = cs + LH(&prog.image()[i]);
|
||||
iICODE last_current_insn = (++Icode.rbegin()).base();
|
||||
//ip = Icode.size();
|
||||
|
||||
@@ -604,9 +604,9 @@ boolT Function::process_CALL (ICODE & pIcode, CALL_GRAPH * pcallGraph, STATE *ps
|
||||
* previous offset into the program image */
|
||||
uint32_t tgtAddr=0;
|
||||
if (pIcode.ll()->getOpcode() == iCALLF)
|
||||
tgtAddr= LH(&prog.Image[off]) + ((uint32_t)(LH(&prog.Image[off+2])) << 4);
|
||||
tgtAddr= LH(&prog.image()[off]) + ((uint32_t)(LH(&prog.image()[off+2])) << 4);
|
||||
else
|
||||
tgtAddr= LH(&prog.Image[off]) + ((uint32_t)(uint16_t)state.r[rCS] << 4);
|
||||
tgtAddr= LH(&prog.image()[off]) + ((uint32_t)(uint16_t)state.r[rCS] << 4);
|
||||
pIcode.ll()->replaceSrc(LLOperand::CreateImm2( tgtAddr ) );
|
||||
pIcode.ll()->setFlags(I);
|
||||
indirect = true;
|
||||
@@ -651,7 +651,7 @@ boolT Function::process_CALL (ICODE & pIcode, CALL_GRAPH * pcallGraph, STATE *ps
|
||||
localState = *pstate;
|
||||
pstate->IP = pIcode.ll()->src().getImm2();
|
||||
if (pIcode.ll()->getOpcode() == iCALLF)
|
||||
pstate->setState( rCS, LH(prog.Image + pIcode.ll()->label + 3));
|
||||
pstate->setState( rCS, LH(prog.image() + pIcode.ll()->label + 3));
|
||||
x.state = *pstate;
|
||||
|
||||
/* Insert new procedure in call graph */
|
||||
@@ -694,7 +694,7 @@ static void process_MOV(LLInst & ll, STATE * pstate)
|
||||
{
|
||||
psym = lookupAddr(&ll.src(), pstate, 2, eDuVal::USE);
|
||||
if (psym && ((psym->flg & SEG_IMMED) || psym->duVal.val))
|
||||
pstate->setState( dstReg, LH(&prog.Image[psym->label]));
|
||||
pstate->setState( dstReg, LH(&prog.image()[psym->label]));
|
||||
}
|
||||
else if (srcReg < INDEX_BX_SI && pstate->f[srcReg]) /* reg */
|
||||
{
|
||||
@@ -714,9 +714,13 @@ static void process_MOV(LLInst & ll, STATE * pstate)
|
||||
{
|
||||
if (ll.testFlags(I)) /* immediate */
|
||||
{
|
||||
prog.Image[psym->label] = (uint8_t)ll.src().getImm2();
|
||||
//prog.image()[psym->label] = (uint8_t)ll.src().getImm2();
|
||||
pstate->setMemoryByte(psym->label,(uint8_t)ll.src().getImm2());
|
||||
if(psym->size>1)
|
||||
prog.Image[psym->label+1] = (uint8_t)(ll.src().getImm2()>>8);
|
||||
{
|
||||
pstate->setMemoryByte(psym->label+1,uint8_t(ll.src().getImm2()>>8));
|
||||
//prog.image()[psym->label+1] = (uint8_t)(ll.src().getImm2()>>8);
|
||||
}
|
||||
psym->duVal.val = 1;
|
||||
}
|
||||
else if (srcReg == 0) /* direct mem offset */
|
||||
@@ -724,18 +728,26 @@ static void process_MOV(LLInst & ll, STATE * pstate)
|
||||
psym2 = lookupAddr (&ll.src(), pstate, 2, eDuVal::USE);
|
||||
if (psym2 && ((psym->flg & SEG_IMMED) || (psym->duVal.val)))
|
||||
{
|
||||
prog.Image[psym->label] = (uint8_t)prog.Image[psym2->label];
|
||||
//prog.image()[psym->label] = (uint8_t)prog.image()[psym2->label];
|
||||
pstate->setMemoryByte(psym->label,(uint8_t)prog.image()[psym2->label]);
|
||||
if(psym->size>1)
|
||||
prog.Image[psym->label+1] = prog.Image[psym2->label+1];//(uint8_t)(prog.Image[psym2->label+1] >> 8);
|
||||
{
|
||||
pstate->setMemoryByte(psym->label+1,(uint8_t)prog.image()[psym2->label+1]);
|
||||
//prog.image()[psym->label+1] = prog.image()[psym2->label+1];//(uint8_t)(prog.image()[psym2->label+1] >> 8);
|
||||
}
|
||||
psym->duVal.setFlags(eDuVal::DEF);
|
||||
psym2->duVal.setFlags(eDuVal::USE);
|
||||
}
|
||||
}
|
||||
else if (srcReg < INDEX_BX_SI && pstate->f[srcReg]) /* reg */
|
||||
{
|
||||
prog.Image[psym->label] = (uint8_t)pstate->r[srcReg];
|
||||
//prog.image()[psym->label] = (uint8_t)pstate->r[srcReg];
|
||||
pstate->setMemoryByte(psym->label,(uint8_t)pstate->r[srcReg]);
|
||||
if(psym->size>1)
|
||||
prog.Image[psym->label+1] = (uint8_t)(pstate->r[srcReg] >> 8);
|
||||
{
|
||||
pstate->setMemoryByte(psym->label,(uint8_t)pstate->r[srcReg]>>8);
|
||||
//prog.image()[psym->label+1] = (uint8_t)(pstate->r[srcReg] >> 8);
|
||||
}
|
||||
psym->duVal.setFlags(eDuVal::DEF);
|
||||
}
|
||||
}
|
||||
|
||||
107
src/procs.cpp
107
src/procs.cpp
@@ -94,7 +94,7 @@ void LOCAL_ID::newRegArg(iICODE picode, iICODE ticode) const
|
||||
STKFRAME * call_args_stackframe, *target_stackframe;
|
||||
const ID *id;
|
||||
int tidx;
|
||||
boolT regExist;
|
||||
bool regExist=false;
|
||||
condId type;
|
||||
Function * tproc;
|
||||
eReg regL, regH; /* Registers involved in arguments */
|
||||
@@ -106,16 +106,29 @@ void LOCAL_ID::newRegArg(iICODE picode, iICODE ticode) const
|
||||
/* Get registers and index into target procedure's local list */
|
||||
call_args_stackframe = ticode->hl()->call.args;
|
||||
target_stackframe = &tproc->args;
|
||||
lhs = dynamic_cast<AstIdent *>(picode->hl()->asgn.lhs);
|
||||
lhs = dynamic_cast<AstIdent *>(picode->hl()->asgn.lhs());
|
||||
RegisterNode *lhs_reg = dynamic_cast<RegisterNode *>(lhs);
|
||||
assert(lhs);
|
||||
type = lhs->ident.idType;
|
||||
if (type == REGISTER)
|
||||
type = lhs->ident.type();
|
||||
if (lhs_reg)
|
||||
{
|
||||
regL = id_arr[lhs->ident.idNode.regiIdx].id.regi;
|
||||
regL = id_arr[lhs_reg->regiIdx].id.regi;
|
||||
if (regL < rAL)
|
||||
tidx = tproc->localId.newByteWordReg(TYPE_WORD_SIGN, regL);
|
||||
else
|
||||
tidx = tproc->localId.newByteWordReg(TYPE_BYTE_SIGN, regL);
|
||||
/* Check if register argument already on the formal argument list */
|
||||
for(STKSYM &tgt_sym : *target_stackframe)
|
||||
{
|
||||
RegisterNode *tgt_sym_regs = dynamic_cast<RegisterNode *>(tgt_sym.regs);
|
||||
if( tgt_sym_regs == NULL ) // both REGISTER and LONG_VAR require this precondition
|
||||
continue;
|
||||
if ( tgt_sym_regs->regiIdx == tidx )
|
||||
{
|
||||
regExist = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (type == LONG_VAR)
|
||||
{
|
||||
@@ -123,32 +136,20 @@ void LOCAL_ID::newRegArg(iICODE picode, iICODE ticode) const
|
||||
regL = id_arr[longIdx].id.longId.l;
|
||||
regH = id_arr[longIdx].id.longId.h;
|
||||
tidx = tproc->localId.newLongReg(TYPE_LONG_SIGN, regH, regL, tproc->Icode.begin() /*0*/);
|
||||
}
|
||||
|
||||
/* Check if register argument already on the formal argument list */
|
||||
regExist = false;
|
||||
for(STKSYM &tgt_sym : *target_stackframe)
|
||||
{
|
||||
if( tgt_sym.regs == NULL ) // both REGISTER and LONG_VAR require this precondition
|
||||
continue;
|
||||
if (type == REGISTER)
|
||||
{
|
||||
if ( tgt_sym.regs->ident.idNode.regiIdx == tidx )
|
||||
{
|
||||
regExist = true;
|
||||
}
|
||||
}
|
||||
else if (type == LONG_VAR)
|
||||
/* Check if register argument already on the formal argument list */
|
||||
for(STKSYM &tgt_sym : *target_stackframe)
|
||||
{
|
||||
if( tgt_sym.regs == NULL ) // both REGISTER and LONG_VAR require this precondition
|
||||
continue;
|
||||
if ( tgt_sym.regs->ident.idNode.longIdx == tidx )
|
||||
{
|
||||
regExist = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(regExist == true)
|
||||
break;
|
||||
}
|
||||
|
||||
else
|
||||
;//regExist = false;
|
||||
/* Do ts (formal arguments) */
|
||||
if (regExist == false)
|
||||
{
|
||||
@@ -161,12 +162,12 @@ void LOCAL_ID::newRegArg(iICODE picode, iICODE ticode) const
|
||||
if (regL < rAL)
|
||||
{
|
||||
newsym.type = TYPE_WORD_SIGN;
|
||||
newsym.regs = AstIdent::RegIdx(tidx, WORD_REG);
|
||||
newsym.regs = new RegisterNode(tidx, WORD_REG);
|
||||
}
|
||||
else
|
||||
{
|
||||
newsym.type = TYPE_BYTE_SIGN;
|
||||
newsym.regs = AstIdent::RegIdx(tidx, BYTE_REG);
|
||||
newsym.regs = new RegisterNode(tidx, BYTE_REG);
|
||||
}
|
||||
tproc->localId.id_arr[tidx].name = newsym.name;
|
||||
}
|
||||
@@ -189,7 +190,7 @@ void LOCAL_ID::newRegArg(iICODE picode, iICODE ticode) const
|
||||
/* Mask off high and low register(s) in picode */
|
||||
switch (type) {
|
||||
case REGISTER:
|
||||
id = &id_arr[lhs->ident.idNode.regiIdx];
|
||||
id = &id_arr[lhs_reg->regiIdx];
|
||||
picode->du.def &= maskDuReg[id->id.regi];
|
||||
if (id->id.regi < rAL)
|
||||
newsym.type = TYPE_WORD_SIGN;
|
||||
@@ -215,9 +216,9 @@ void LOCAL_ID::newRegArg(iICODE picode, iICODE ticode) const
|
||||
* @return true if it was a near call that made use of a segment register.
|
||||
* false elsewhere
|
||||
*/
|
||||
bool CallType::newStkArg(COND_EXPR *exp, llIcode opcode, Function * pproc)
|
||||
bool CallType::newStkArg(Expr *exp, llIcode opcode, Function * pproc)
|
||||
{
|
||||
AstIdent *expr = dynamic_cast<AstIdent *>(exp);
|
||||
RegisterNode *expr = dynamic_cast<RegisterNode *>(exp);
|
||||
|
||||
uint8_t regi;
|
||||
/* Check for far procedure call, in which case, references to segment
|
||||
@@ -225,16 +226,13 @@ bool CallType::newStkArg(COND_EXPR *exp, llIcode opcode, Function * pproc)
|
||||
* long references to another segment) */
|
||||
if (expr)
|
||||
{
|
||||
if (expr->ident.idType == REGISTER)
|
||||
regi = pproc->localId.id_arr[expr->regiIdx].id.regi;
|
||||
if ((regi >= rES) && (regi <= rDS))
|
||||
{
|
||||
regi = pproc->localId.id_arr[expr->ident.idNode.regiIdx].id.regi;
|
||||
if ((regi >= rES) && (regi <= rDS))
|
||||
{
|
||||
if (opcode == iCALLF)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
if (opcode == iCALLF)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,22 +247,22 @@ 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 (Expr *exp, int pos)
|
||||
{
|
||||
(*args)[pos].actual = exp;
|
||||
(*args)[pos].setArgName(pos);
|
||||
}
|
||||
|
||||
COND_EXPR *CallType::toId()
|
||||
Expr *CallType::toAst()
|
||||
{
|
||||
return AstIdent::idFunc( proc, args);
|
||||
return new FuncNode( proc, args);
|
||||
}
|
||||
|
||||
|
||||
/* Checks to determine whether the expression (actual argument) has the
|
||||
* same type as the given type (from the procedure's formal list). If not,
|
||||
* the actual argument gets modified */
|
||||
void adjustActArgType (COND_EXPR *_exp, hlType forType, Function * pproc)
|
||||
Expr *Function::adjustActArgType (Expr *_exp, hlType forType)
|
||||
{
|
||||
AstIdent *expr = dynamic_cast<AstIdent *>(_exp);
|
||||
PROG &prog(Project::get()->prog);
|
||||
@@ -272,11 +270,11 @@ void adjustActArgType (COND_EXPR *_exp, hlType forType, Function * pproc)
|
||||
int offset, offL;
|
||||
|
||||
if (expr == NULL)
|
||||
return;
|
||||
return _exp;
|
||||
|
||||
actType = expr-> expType (pproc);
|
||||
actType = expr-> expType (this);
|
||||
if (actType == forType)
|
||||
return;
|
||||
return _exp;
|
||||
switch (forType)
|
||||
{
|
||||
case TYPE_UNKNOWN: case TYPE_BYTE_SIGN:
|
||||
@@ -292,16 +290,20 @@ void adjustActArgType (COND_EXPR *_exp, hlType forType, Function * pproc)
|
||||
case TYPE_STR:
|
||||
switch (actType) {
|
||||
case TYPE_CONST:
|
||||
/* It's an offset into image where a string is
|
||||
* found. Point to the string. */
|
||||
offL = expr->ident.idNode.kte.kte;
|
||||
/* It's an offset into image where a string is found. Point to the string. */
|
||||
{
|
||||
Constant *c=dynamic_cast<Constant *>(expr);
|
||||
assert(c);
|
||||
offL = c->kte.kte;
|
||||
if (prog.fCOM)
|
||||
offset = (pproc->state.r[rDS]<<4) + offL + 0x100;
|
||||
offset = (state.r[rDS]<<4) + offL + 0x100;
|
||||
else
|
||||
offset = (pproc->state.r[rDS]<<4) + offL;
|
||||
offset = (state.r[rDS]<<4) + offL;
|
||||
expr->ident.idNode.strIdx = offset;
|
||||
expr->ident.idType = STRING;
|
||||
break;
|
||||
expr->ident.type(STRING);
|
||||
delete c;
|
||||
return AstIdent::String(offset);
|
||||
}
|
||||
|
||||
case TYPE_PTR:
|
||||
/* It's a pointer to a char rather than a pointer to
|
||||
@@ -319,6 +321,7 @@ void adjustActArgType (COND_EXPR *_exp, hlType forType, Function * pproc)
|
||||
default:
|
||||
fprintf(stderr,"adjustForArgType unhandled forType %d \n",forType);
|
||||
}
|
||||
return _exp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -336,7 +336,7 @@ int Function::findBackwarLongDefs(int loc_ident_idx, const ID &pLocId, iICODE be
|
||||
localId.id_arr[loc_ident_idx].idx.push_back(pIcode);//idx-1//insert
|
||||
icode.setRegDU( pmL->regi, eDEF);
|
||||
asgn.lhs = AstIdent::LongIdx (loc_ident_idx);
|
||||
asgn.rhs = AstIdent::idLong (&this->localId, SRC, pIcode, HIGH_FIRST, pIcode, eUSE, *next1->ll());
|
||||
asgn.rhs = AstIdent::Long (&this->localId, SRC, pIcode, HIGH_FIRST, pIcode, eUSE, *next1->ll());
|
||||
icode.setAsgn(asgn.lhs, asgn.rhs);
|
||||
next1->invalidate();
|
||||
forced_finish=true; /* to exit the loop */
|
||||
@@ -365,7 +365,7 @@ int Function::findBackwarLongDefs(int loc_ident_idx, const ID &pLocId, iICODE be
|
||||
if ((pLocId.id.longId.h == pmH->regi) && (pLocId.id.longId.l == pmL->regi))
|
||||
{
|
||||
asgn.lhs = AstIdent::LongIdx (loc_ident_idx);
|
||||
asgn.rhs = AstIdent::idLong (&this->localId, SRC, pIcode, LOW_FIRST, pIcode, eUSE, *next1->ll());
|
||||
asgn.rhs = AstIdent::Long (&this->localId, SRC, pIcode, LOW_FIRST, pIcode, eUSE, *next1->ll());
|
||||
icode.setRegDU( pmH->regi, USE_DEF);
|
||||
condOp toCreate=DUMMY;
|
||||
switch (icode.ll()->getOpcode())
|
||||
@@ -411,13 +411,13 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be
|
||||
const LLOperand &src_op1(pIcode->ll()->src());
|
||||
const LLOperand &src_op2(next1->ll()->src());
|
||||
eReg srcReg1=src_op1.getReg2();
|
||||
eReg srcReg2=src_op2.getReg2();
|
||||
if ((ref_long.h == srcReg1) && (ref_long.l == srcReg2))
|
||||
eReg nextReg2=src_op2.getReg2();
|
||||
if ((ref_long.h == srcReg1) && (ref_long.l == nextReg2))
|
||||
{
|
||||
pIcode->setRegDU( next1->ll()->src().getReg2(), eUSE);
|
||||
pIcode->setRegDU( nextReg2, eUSE);
|
||||
|
||||
asgn.rhs = AstIdent::LongIdx (loc_ident_idx);
|
||||
asgn.lhs = AstIdent::idLong (&this->localId, DST, pIcode,HIGH_FIRST, pIcode, eDEF, *next1->ll());
|
||||
asgn.lhs = AstIdent::Long (&this->localId, DST, pIcode,HIGH_FIRST, pIcode, eDEF, *next1->ll());
|
||||
|
||||
pIcode->setAsgn(dynamic_cast<AstIdent *>(asgn.lhs), asgn.rhs);
|
||||
next1->invalidate();
|
||||
@@ -453,7 +453,7 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be
|
||||
{
|
||||
asgn.lhs = AstIdent::LongIdx (loc_ident_idx);
|
||||
pIcode->setRegDU( pmH->regi, USE_DEF);
|
||||
asgn.rhs = AstIdent::idLong (&this->localId, SRC, pIcode,
|
||||
asgn.rhs = AstIdent::Long (&this->localId, SRC, pIcode,
|
||||
LOW_FIRST, pIcode, eUSE, *next1->ll());
|
||||
condOp toCreate=DUMMY;
|
||||
switch (pIcode->ll()->getOpcode()) {
|
||||
@@ -505,7 +505,7 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be
|
||||
if (pLocId.id.longId.srcDstRegMatch(pIcode,pIcode))
|
||||
{
|
||||
asgn.lhs = AstIdent::LongIdx (loc_ident_idx);
|
||||
asgn.rhs = AstIdent::Kte (0, 4); /* long 0 */
|
||||
asgn.rhs = new Constant(0, 4); /* long 0 */
|
||||
asgn.lhs = new BinaryOperator(condOpJCond[next1->ll()->getOpcode() - iJB],asgn.lhs, asgn.rhs);
|
||||
next1->setJCond(asgn.lhs);
|
||||
next1->copyDU(*pIcode, eUSE, eUSE);
|
||||
|
||||
113
src/scanner.cpp
113
src/scanner.cpp
@@ -314,14 +314,29 @@ static struct {
|
||||
} ;
|
||||
|
||||
static uint16_t SegPrefix, RepPrefix;
|
||||
static uint8_t *pInst; /* Ptr. to current uint8_t of instruction */
|
||||
static const uint8_t *pInst; /* Ptr. to current uint8_t of instruction */
|
||||
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.
|
||||
****************************************************************************/
|
||||
static void decodeBranchTgt(x86_insn_t &insn)
|
||||
{
|
||||
x86_op_t *tgt_op = insn.x86_get_branch_target();
|
||||
if(tgt_op->type==op_expression)
|
||||
return; // unhandled for now
|
||||
if(tgt_op->type==op_register)
|
||||
return; // unhandled for now
|
||||
int32_t addr = tgt_op->getAddress();
|
||||
if(tgt_op->is_relative())
|
||||
{
|
||||
addr += insn.addr+insn.size;
|
||||
}
|
||||
pIcode->ll()->replaceSrc((uint32_t)addr);
|
||||
pIcode->ll()->setFlags(I);
|
||||
// PROG &prog(Project::get()->prog);
|
||||
// long off = (short)getWord(); /* Signed displacement */
|
||||
// assert(addr==(uint32_t)(off + (unsigned)(pInst - prog.image())));
|
||||
|
||||
}
|
||||
|
||||
static void convertUsedFlags(x86_insn_t &from,ICODE &to)
|
||||
{
|
||||
@@ -345,6 +360,13 @@ static void convertUsedFlags(x86_insn_t &from,ICODE &to)
|
||||
if(from.containsFlag(insn_eflag_direction,from.flags_tested))
|
||||
to.ll()->flagDU.u |= Df;
|
||||
}
|
||||
static void convertPrefix(x86_insn_prefix prefix,ICODE &to)
|
||||
{
|
||||
if(prefix ==insn_no_prefix)
|
||||
return;
|
||||
// insn_lock - no need to handle
|
||||
RepPrefix = (uint16_t)prefix & ~insn_lock;
|
||||
}
|
||||
/****************************************************************************
|
||||
Checks for int 34 to int 3B - if so, converts to ESC nn instruction
|
||||
****************************************************************************/
|
||||
@@ -362,7 +384,7 @@ static void fixFloatEmulation(x86_insn_t &insn)
|
||||
/* This is a Borland/Microsoft floating point emulation instruction. Treat as if it is an ESC opcode */
|
||||
|
||||
int actual_valid_bytes=std::min(16U,prog.cbImage-insn.offset);
|
||||
memcpy(buf,prog.Image+insn.offset,actual_valid_bytes);
|
||||
memcpy(buf,prog.image()+insn.offset,actual_valid_bytes);
|
||||
X86_Disasm ds(opt_16_bit);
|
||||
x86_insn_t patched_insn;
|
||||
//patch actual instruction into buffer;
|
||||
@@ -378,7 +400,7 @@ int disassembleOneLibDisasm(uint32_t ip,x86_insn_t &l)
|
||||
{
|
||||
PROG &prog(Project::get()->prog);
|
||||
X86_Disasm ds(opt_16_bit);
|
||||
int cnt=ds.x86_disasm(prog.Image,prog.cbImage,0,ip,&l);
|
||||
int cnt=ds.x86_disasm(prog.image(),prog.cbImage,0,ip,&l);
|
||||
if(cnt && l.is_valid())
|
||||
{
|
||||
fixFloatEmulation(l); //can change 'l'
|
||||
@@ -416,6 +438,11 @@ LLOperand convertOperand(const x86_op_t &from)
|
||||
}
|
||||
return LLOperand::CreateImm2(0);
|
||||
}
|
||||
/*****************************************************************************
|
||||
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(uint32_t ip, ICODE &p)
|
||||
{
|
||||
PROG &prog(Project::get()->prog);
|
||||
@@ -431,10 +458,12 @@ eErrorId scan(uint32_t ip, ICODE &p)
|
||||
if(cnt)
|
||||
{
|
||||
convertUsedFlags(p.insn,p);
|
||||
convertPrefix(p.insn.prefix,p);
|
||||
|
||||
}
|
||||
|
||||
SegPrefix = RepPrefix = 0;
|
||||
pInst = prog.Image + ip;
|
||||
pInst = prog.image() + ip;
|
||||
pIcode = &p;
|
||||
|
||||
do
|
||||
@@ -446,12 +475,20 @@ eErrorId scan(uint32_t ip, ICODE &p)
|
||||
(*stateTable[op].state2)(op); /* Third state */
|
||||
|
||||
} while (stateTable[op].state1 == prefix); /* Loop if prefix */
|
||||
if(p.insn.group == x86_insn_t::insn_controlflow)
|
||||
{
|
||||
if(p.insn.x86_get_branch_target())
|
||||
decodeBranchTgt(p.insn);
|
||||
}
|
||||
// LLOperand conv = convertOperand(*p.insn.get_dest());
|
||||
// assert(conv==p.ll()->dst);
|
||||
if (p.ll()->getOpcode())
|
||||
{
|
||||
/* Save bytes of image used */
|
||||
p.ll()->numBytes = (uint8_t)((pInst - prog.Image) - ip);
|
||||
p.ll()->numBytes = (uint8_t)((pInst - prog.image()) - ip);
|
||||
if(p.insn.is_valid())
|
||||
assert(p.ll()->numBytes == p.insn.size);
|
||||
p.ll()->numBytes = p.insn.size;
|
||||
return ((SegPrefix)? FUNNY_SEGOVR: /* Seg. Override invalid */
|
||||
(RepPrefix ? FUNNY_REP: NO_ERR));/* REP prefix invalid */
|
||||
}
|
||||
@@ -462,11 +499,11 @@ eErrorId scan(uint32_t ip, ICODE &p)
|
||||
/***************************************************************************
|
||||
relocItem - returns true if uint16_t pointed at is in relocation table
|
||||
**************************************************************************/
|
||||
static bool relocItem(uint8_t *p)
|
||||
static bool relocItem(const uint8_t *p)
|
||||
{
|
||||
PROG &prog(Project::get()->prog);
|
||||
int i;
|
||||
uint32_t off = p - prog.Image;
|
||||
uint32_t off = p - prog.image();
|
||||
|
||||
for (i = 0; i < prog.cReloc; i++)
|
||||
if (prog.relocTable[i] == off)
|
||||
@@ -501,13 +538,13 @@ static int signex(uint8_t 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, uint16_t seg, int16_t reg, uint16_t off)
|
||||
static void setAddress(int i, bool fdst, uint16_t seg, int16_t reg, uint16_t off)
|
||||
{
|
||||
LLOperand *pm;
|
||||
|
||||
/* If not to register (i.e. to r/m), and talking about r/m, then this is dest */
|
||||
pm = (!(stateTable[i].flg & TO_REG) == fdst) ?
|
||||
&pIcode->ll()->dst : &pIcode->ll()->src();
|
||||
&pIcode->ll()->dst : &pIcode->ll()->src();
|
||||
|
||||
/* Set segment. A later procedure (lookupAddr in proclist.c) will
|
||||
* provide the value of this segment in the field segValue. */
|
||||
@@ -572,7 +609,7 @@ static void rm(int i)
|
||||
setAddress(i, true, 0, rm + rAX, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
//pIcode->insn.get_dest()->
|
||||
if ((stateTable[i].flg & NSP) && (pIcode->ll()->src().getReg2()==rSP ||
|
||||
pIcode->ll()->dst.getReg2()==rSP))
|
||||
pIcode->ll()->setFlags(NOT_HLL);
|
||||
@@ -739,7 +776,7 @@ static void arith(int i)
|
||||
uint8_t opcode;
|
||||
static llIcode arithTable[8] =
|
||||
{
|
||||
iTEST , (llIcode)0, iNOT, iNEG,
|
||||
iTEST, (llIcode)0, iNOT, iNEG,
|
||||
iMUL , iIMUL, iDIV, iIDIV
|
||||
};
|
||||
opcode = arithTable[REG(*pInst)];
|
||||
@@ -810,47 +847,40 @@ static void dispM(int i)
|
||||
{
|
||||
setAddress(i, false, SegPrefix, 0, getWord());
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
dispN - 2 uint8_t disp as immed relative to ip
|
||||
****************************************************************************/
|
||||
static void dispN(int )
|
||||
{
|
||||
PROG &prog(Project::get()->prog);
|
||||
long off = (short)getWord(); /* Signed displacement */
|
||||
//PROG &prog(Project::get()->prog);
|
||||
/*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->ll()->replaceSrc((uint32_t)(off + (unsigned)(pInst - prog.Image)));
|
||||
pIcode->ll()->setFlags(I);
|
||||
// decodeBranchTgt();
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
dispS - 1 uint8_t disp as immed relative to ip
|
||||
dispS - 1 byte disp as immed relative to ip
|
||||
***************************************************************************/
|
||||
static void dispS(int )
|
||||
{
|
||||
PROG &prog(Project::get()->prog);
|
||||
long off = signex(*pInst++); /* Signed displacement */
|
||||
/*long off =*/ signex(*pInst++); /* Signed displacement */
|
||||
|
||||
pIcode->ll()->replaceSrc((uint32_t)(off + (unsigned)(pInst - prog.Image)));
|
||||
pIcode->ll()->setFlags(I);
|
||||
// decodeBranchTgt();
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
dispF - 4 uint8_t disp as immed 20-bit target address
|
||||
dispF - 4 byte disp as immed 20-bit target address
|
||||
***************************************************************************/
|
||||
static void dispF(int )
|
||||
{
|
||||
uint32_t off = (unsigned)getWord();
|
||||
uint32_t seg = (unsigned)getWord();
|
||||
|
||||
pIcode->ll()->replaceSrc(off + ((uint32_t)(unsigned)seg << 4));
|
||||
pIcode->ll()->setFlags(I);
|
||||
/*off = */(unsigned)getWord();
|
||||
/*seg = */(unsigned)getWord();
|
||||
// decodeBranchTgt();
|
||||
}
|
||||
|
||||
|
||||
@@ -880,12 +910,19 @@ static void strop(int )
|
||||
{
|
||||
if (RepPrefix)
|
||||
{
|
||||
// pIcode->ll()->getOpcode() += ((pIcode->ll()->getOpcode() == iCMPS ||
|
||||
// pIcode->ll()->getOpcode() == iSCAS)
|
||||
// && RepPrefix == iREPE)? 2: 1;
|
||||
if ((pIcode->ll()->match(iCMPS) || pIcode->ll()->match(iSCAS) ) && RepPrefix == iREPE)
|
||||
BumpOpcode(*pIcode->ll()); // += 2
|
||||
BumpOpcode(*pIcode->ll()); // else += 1
|
||||
if ( pIcode->ll()->match(iCMPS) || pIcode->ll()->match(iSCAS) )
|
||||
{
|
||||
if(pIcode->insn.prefix & insn_rep_zero)
|
||||
{
|
||||
BumpOpcode(*pIcode->ll()); // iCMPS -> iREPE_CMPS
|
||||
BumpOpcode(*pIcode->ll());
|
||||
}
|
||||
else if(pIcode->insn.prefix & insn_rep_notzero)
|
||||
BumpOpcode(*pIcode->ll()); // iX -> iREPNE_X
|
||||
}
|
||||
else
|
||||
if(pIcode->insn.prefix & insn_rep_zero)
|
||||
BumpOpcode(*pIcode->ll()); // iX -> iREPE_X
|
||||
if (pIcode->ll()->match(iREP_LODS) )
|
||||
pIcode->ll()->setFlags(NOT_HLL);
|
||||
RepPrefix = 0;
|
||||
|
||||
Reference in New Issue
Block a user