removed most of clang warnings / errors
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
using namespace std;
|
||||
using namespace boost;
|
||||
|
||||
BB *BB::Create(void *ctx, const string &s, Function *parent, BB *insertBefore)
|
||||
BB *BB::Create(void */*ctx*/, const string &/*s*/, Function *parent, BB */*insertBefore*/)
|
||||
{
|
||||
BB *pnewBB = new BB;
|
||||
pnewBB->Parent = parent;
|
||||
@@ -81,14 +81,14 @@ static const char *const s_loopType[] = {"noLoop", "while", "repeat", "loop", "f
|
||||
void BB::display()
|
||||
{
|
||||
printf("\nnode type = %s, ", s_nodeType[nodeType]);
|
||||
printf("start = %ld, length = %ld, #out edges = %ld\n", begin()->loc_ip, size(), edges.size());
|
||||
printf("start = %d, length = %zd, #out edges = %zd\n", begin()->loc_ip, size(), edges.size());
|
||||
|
||||
for (size_t i = 0; i < edges.size(); i++)
|
||||
{
|
||||
if(edges[i].BBptr==0)
|
||||
printf(" outEdge[%2d] = Unlinked out edge to %d\n",i, edges[i].ip);
|
||||
printf(" outEdge[%2zd] = Unlinked out edge to %d\n",i, edges[i].ip);
|
||||
else
|
||||
printf(" outEdge[%2d] = %d\n",i, edges[i].BBptr->begin()->loc_ip);
|
||||
printf(" outEdge[%2zd] = %d\n",i, edges[i].BBptr->begin()->loc_ip);
|
||||
}
|
||||
}
|
||||
/*****************************************************************************
|
||||
@@ -101,29 +101,29 @@ void BB::displayDfs()
|
||||
traversed = DFS_DISP;
|
||||
|
||||
printf("node type = %s, ", s_nodeType[nodeType]);
|
||||
printf("start = %ld, length = %ld, #in-edges = %ld, #out-edges = %ld\n",
|
||||
printf("start = %d, length = %zd, #in-edges = %zd, #out-edges = %zd\n",
|
||||
begin()->loc_ip, size(), inEdges.size(), edges.size());
|
||||
printf("dfsFirst = %ld, dfsLast = %ld, immed dom = %ld\n",
|
||||
printf("dfsFirst = %d, dfsLast = %d, immed dom = %d\n",
|
||||
dfsFirstNum, dfsLastNum,
|
||||
immedDom == MAX ? -1 : immedDom);
|
||||
printf("loopType = %s, loopHead = %ld, latchNode = %ld, follow = %ld\n",
|
||||
printf("loopType = %s, loopHead = %d, latchNode = %d, follow = %d\n",
|
||||
s_loopType[loopType],
|
||||
loopHead == MAX ? -1 : loopHead,
|
||||
latchNode == MAX ? -1 : latchNode,
|
||||
loopFollow == MAX ? -1 : loopFollow);
|
||||
printf ("ifFollow = %ld, caseHead = %ld, caseTail = %ld\n",
|
||||
printf ("ifFollow = %d, caseHead = %d, caseTail = %d\n",
|
||||
ifFollow == MAX ? -1 : ifFollow,
|
||||
caseHead == MAX ? -1 : caseHead,
|
||||
caseTail == MAX ? -1 : caseTail);
|
||||
|
||||
if (nodeType == INTERVAL_NODE)
|
||||
printf("corresponding interval = %ld\n", correspInt->numInt);
|
||||
printf("corresponding interval = %d\n", correspInt->numInt);
|
||||
else
|
||||
{
|
||||
int edge_idx=0;
|
||||
for(BB *node : inEdges)
|
||||
{
|
||||
printf (" inEdge[%ld] = %ld\n", edge_idx, node->begin()->loc_ip);
|
||||
printf (" inEdge[%d] = %d\n", edge_idx, node->begin()->loc_ip);
|
||||
edge_idx++;
|
||||
}
|
||||
}
|
||||
@@ -132,9 +132,9 @@ void BB::displayDfs()
|
||||
for(TYPEADR_TYPE &edg : edges)
|
||||
{
|
||||
if (nodeType == INTERVAL_NODE)
|
||||
printf(" outEdge[%ld] = %ld\n", i, edg.BBptr->correspInt->numInt);
|
||||
printf(" outEdge[%d] = %d\n", i, edg.BBptr->correspInt->numInt);
|
||||
else
|
||||
printf(" outEdge[%d] = %ld\n", i, edg.BBptr->begin()->loc_ip);
|
||||
printf(" outEdge[%d] = %d\n", i, edg.BBptr->begin()->loc_ip);
|
||||
++i;
|
||||
}
|
||||
printf("----\n");
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
SET(dcc_test_SOURCES tests/comwrite.cpp)
|
||||
SET(dcc_test_SOURCES
|
||||
tests/comwrite.cpp
|
||||
tests/project.cpp
|
||||
tests/loader.cpp
|
||||
|
||||
)
|
||||
include_directories(${GMOCK_INCLUDE_DIRS} ${GMOCK_ROOT}/gtest/include)
|
||||
enable_testing()
|
||||
add_executable(tester ${dcc_test_SOURCES})
|
||||
target_link_libraries(tester
|
||||
ADD_DEPENDENCIES(tester dcc_lib)
|
||||
|
||||
target_link_libraries(tester dcc_lib disasm_s
|
||||
${GMOCK_BOTH_LIBRARIES} ${REQ_LLVM_LIBRARIES})
|
||||
add_test(dcc-tests tester)
|
||||
|
||||
361
src/ast.cpp
361
src/ast.cpp
@@ -13,7 +13,6 @@
|
||||
#include "dcc.h"
|
||||
#include "machine_x86.h"
|
||||
#include "project.h"
|
||||
extern Project g_proj;
|
||||
using namespace std;
|
||||
// Conditional operator symbols in C. Index by condOp enumeration type
|
||||
static const char * const condOpSym[] = { " <= ", " < ", " == ", " != ", " > ", " >= ",
|
||||
@@ -122,8 +121,8 @@ COND_EXPR *GlobalVariable::Create(int16_t segValue, int16_t off)
|
||||
newExp = new COND_EXPR(IDENTIFIER);
|
||||
newExp->expr.ident.idType = GLOB_VAR;
|
||||
adr = opAdr(segValue, off);
|
||||
auto i=g_proj.getSymIdxByAdd(adr);
|
||||
if ( not g_proj.validSymIdx(i) )
|
||||
auto i=Project::get()->getSymIdxByAdd(adr);
|
||||
if ( not Project::get()->validSymIdx(i) )
|
||||
{
|
||||
printf ("Error, glob var not found in symtab\n");
|
||||
delete newExp;
|
||||
@@ -477,7 +476,7 @@ int hlTypeSize (const COND_EXPR *expr, Function * pproc)
|
||||
switch (expr->expr.ident.idType)
|
||||
{
|
||||
case GLOB_VAR:
|
||||
return (g_proj.symbolSize(expr->expr.ident.idNode.globIdx));
|
||||
return (Project::get()->symbolSize(expr->expr.ident.idNode.globIdx));
|
||||
case REGISTER:
|
||||
if (expr->expr.ident.regiType == BYTE_REG)
|
||||
return (1);
|
||||
@@ -501,6 +500,9 @@ int hlTypeSize (const COND_EXPR *expr, Function * pproc)
|
||||
return (2);
|
||||
} /* eos */
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"hlTypeSize queried for Unkown type %d \n",expr->m_type);
|
||||
break;
|
||||
}
|
||||
return 2; // CC: is this correct?
|
||||
}
|
||||
@@ -540,7 +542,7 @@ hlType COND_EXPR::expType(Function * pproc) const
|
||||
switch (expr.ident.idType)
|
||||
{
|
||||
case GLOB_VAR:
|
||||
return g_proj.symbolType(expr.ident.idNode.globIdx);
|
||||
return Project::get()->symbolType(expr.ident.idNode.globIdx);
|
||||
case REGISTER:
|
||||
if (expr.ident.regiType == BYTE_REG)
|
||||
return (TYPE_BYTE_SIGN);
|
||||
@@ -580,23 +582,26 @@ void HlTypeSupport::performLongRemoval (eReg regi, LOCAL_ID *locId, COND_EXPR *t
|
||||
eReg otherRegi; /* high or low part of long register */
|
||||
|
||||
switch (tree->m_type) {
|
||||
case BOOLEAN_OP:
|
||||
break;
|
||||
case POST_INC: case POST_DEC:
|
||||
case PRE_INC: case PRE_DEC:
|
||||
case NEGATION: case ADDRESSOF:
|
||||
case DEREFERENCE:
|
||||
break;
|
||||
case IDENTIFIER:
|
||||
ident = &tree->expr.ident;
|
||||
if (ident->idType == LONG_VAR)
|
||||
{
|
||||
otherRegi = otherLongRegi (regi, ident->idNode.longIdx, locId);
|
||||
ident->idType = REGISTER;
|
||||
ident->regiType = WORD_REG;
|
||||
ident->idNode.regiIdx = locId->newByteWordReg(TYPE_WORD_SIGN,otherRegi);
|
||||
}
|
||||
break;
|
||||
case BOOLEAN_OP:
|
||||
break;
|
||||
case POST_INC: case POST_DEC:
|
||||
case PRE_INC: case PRE_DEC:
|
||||
case NEGATION: case ADDRESSOF:
|
||||
case DEREFERENCE:
|
||||
break;
|
||||
case IDENTIFIER:
|
||||
ident = &tree->expr.ident;
|
||||
if (ident->idType == LONG_VAR)
|
||||
{
|
||||
otherRegi = otherLongRegi (regi, ident->idNode.longIdx, locId);
|
||||
ident->idType = REGISTER;
|
||||
ident->regiType = WORD_REG;
|
||||
ident->idNode.regiIdx = locId->newByteWordReg(TYPE_WORD_SIGN,otherRegi);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"performLongRemoval attemped on %d\n",tree->m_type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -634,154 +639,159 @@ string walkCondExpr (const COND_EXPR* expr, Function * pProc, int* numLoc)
|
||||
needBracket = true;
|
||||
switch (expr->m_type)
|
||||
{
|
||||
case BOOLEAN_OP:
|
||||
outStr << "(";
|
||||
outStr << walkCondExpr(expr->lhs(), pProc, numLoc);
|
||||
outStr << condOpSym[expr->op()];
|
||||
outStr << walkCondExpr(expr->rhs(), pProc, numLoc);
|
||||
outStr << ")";
|
||||
break;
|
||||
|
||||
case NEGATION:
|
||||
if (expr->expr.unaryExp->m_type == IDENTIFIER)
|
||||
{
|
||||
needBracket = false;
|
||||
outStr << "!";
|
||||
}
|
||||
else
|
||||
outStr << "! (";
|
||||
outStr << walkCondExpr (expr->expr.unaryExp, pProc, numLoc);
|
||||
if (needBracket == true)
|
||||
outStr << ")";
|
||||
break;
|
||||
|
||||
case ADDRESSOF:
|
||||
if (expr->expr.unaryExp->m_type == IDENTIFIER)
|
||||
{
|
||||
needBracket = false;
|
||||
outStr << "&";
|
||||
}
|
||||
else
|
||||
outStr << "&(";
|
||||
outStr << walkCondExpr (expr->expr.unaryExp, pProc, numLoc);
|
||||
if (needBracket == true)
|
||||
outStr << ")";
|
||||
break;
|
||||
|
||||
case DEREFERENCE:
|
||||
outStr << "*";
|
||||
if (expr->expr.unaryExp->m_type == IDENTIFIER)
|
||||
needBracket = false;
|
||||
else
|
||||
case BOOLEAN_OP:
|
||||
outStr << "(";
|
||||
outStr << walkCondExpr (expr->expr.unaryExp, pProc, numLoc);
|
||||
if (needBracket == true)
|
||||
outStr << walkCondExpr(expr->lhs(), pProc, numLoc);
|
||||
outStr << condOpSym[expr->op()];
|
||||
outStr << walkCondExpr(expr->rhs(), pProc, numLoc);
|
||||
outStr << ")";
|
||||
break;
|
||||
break;
|
||||
|
||||
case POST_INC:
|
||||
outStr << walkCondExpr (expr->expr.unaryExp, pProc, numLoc) << "++";
|
||||
break;
|
||||
case NEGATION:
|
||||
if (expr->expr.unaryExp->m_type == IDENTIFIER)
|
||||
{
|
||||
needBracket = false;
|
||||
outStr << "!";
|
||||
}
|
||||
else
|
||||
outStr << "! (";
|
||||
outStr << walkCondExpr (expr->expr.unaryExp, pProc, numLoc);
|
||||
if (needBracket == true)
|
||||
outStr << ")";
|
||||
break;
|
||||
|
||||
case POST_DEC:
|
||||
outStr << walkCondExpr (expr->expr.unaryExp, pProc, numLoc) << "--";
|
||||
break;
|
||||
case ADDRESSOF:
|
||||
if (expr->expr.unaryExp->m_type == IDENTIFIER)
|
||||
{
|
||||
needBracket = false;
|
||||
outStr << "&";
|
||||
}
|
||||
else
|
||||
outStr << "&(";
|
||||
outStr << walkCondExpr (expr->expr.unaryExp, pProc, numLoc);
|
||||
if (needBracket == true)
|
||||
outStr << ")";
|
||||
break;
|
||||
|
||||
case PRE_INC:
|
||||
outStr << "++"<< walkCondExpr (expr->expr.unaryExp, pProc, numLoc);
|
||||
break;
|
||||
case DEREFERENCE:
|
||||
outStr << "*";
|
||||
if (expr->expr.unaryExp->m_type == IDENTIFIER)
|
||||
needBracket = false;
|
||||
else
|
||||
outStr << "(";
|
||||
outStr << walkCondExpr (expr->expr.unaryExp, pProc, numLoc);
|
||||
if (needBracket == true)
|
||||
outStr << ")";
|
||||
break;
|
||||
|
||||
case PRE_DEC:
|
||||
outStr << "--"<< walkCondExpr (expr->expr.unaryExp, pProc, numLoc);
|
||||
break;
|
||||
case POST_INC:
|
||||
outStr << walkCondExpr (expr->expr.unaryExp, pProc, numLoc) << "++";
|
||||
break;
|
||||
|
||||
case IDENTIFIER:
|
||||
std::ostringstream o;
|
||||
switch (expr->expr.ident.idType)
|
||||
case POST_DEC:
|
||||
outStr << walkCondExpr (expr->expr.unaryExp, pProc, numLoc) << "--";
|
||||
break;
|
||||
|
||||
case PRE_INC:
|
||||
outStr << "++"<< walkCondExpr (expr->expr.unaryExp, pProc, numLoc);
|
||||
break;
|
||||
|
||||
case PRE_DEC:
|
||||
outStr << "--"<< walkCondExpr (expr->expr.unaryExp, pProc, numLoc);
|
||||
break;
|
||||
|
||||
case IDENTIFIER:
|
||||
{
|
||||
case GLOB_VAR:
|
||||
o << g_proj.symtab[expr->expr.ident.idNode.globIdx].name;
|
||||
break;
|
||||
case REGISTER:
|
||||
id = &pProc->localId.id_arr[expr->expr.ident.idNode.regiIdx];
|
||||
if (id->name[0] == '\0') /* no name */
|
||||
std::ostringstream o;
|
||||
switch (expr->expr.ident.idType)
|
||||
{
|
||||
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 GLOB_VAR:
|
||||
o << Project::get()->symtab[expr->expr.ident.idNode.globIdx].name;
|
||||
break;
|
||||
case REGISTER:
|
||||
id = &pProc->localId.id_arr[expr->expr.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[expr->expr.ident.idNode.localIdx].name;
|
||||
break;
|
||||
case LOCAL_VAR:
|
||||
o << pProc->localId.id_arr[expr->expr.ident.idNode.localIdx].name;
|
||||
break;
|
||||
|
||||
case PARAM:
|
||||
psym = &pProc->args[expr->expr.ident.idNode.paramIdx];
|
||||
if (psym->hasMacro)
|
||||
o << psym->macro<<"("<<psym->name<< ")";
|
||||
else
|
||||
o << psym->name;
|
||||
break;
|
||||
case PARAM:
|
||||
psym = &pProc->args[expr->expr.ident.idNode.paramIdx];
|
||||
if (psym->hasMacro)
|
||||
o << psym->macro<<"("<<psym->name<< ")";
|
||||
else
|
||||
o << psym->name;
|
||||
break;
|
||||
|
||||
case GLOB_VAR_IDX:
|
||||
bwGlb = &pProc->localId.id_arr[expr->expr.ident.idNode.idxGlbIdx].id.bwGlb;
|
||||
o << (bwGlb->seg << 4) + bwGlb->off << "["<<Machine_X86::regName(bwGlb->regi)<<"]";
|
||||
break;
|
||||
case GLOB_VAR_IDX:
|
||||
bwGlb = &pProc->localId.id_arr[expr->expr.ident.idNode.idxGlbIdx].id.bwGlb;
|
||||
o << (bwGlb->seg << 4) + bwGlb->off << "["<<Machine_X86::regName(bwGlb->regi)<<"]";
|
||||
break;
|
||||
|
||||
case CONSTANT:
|
||||
if (expr->expr.ident.idNode.kte.kte < 1000)
|
||||
o << expr->expr.ident.idNode.kte.kte;
|
||||
else
|
||||
o << "0x"<<std::hex << expr->expr.ident.idNode.kte.kte;
|
||||
break;
|
||||
case CONSTANT:
|
||||
if (expr->expr.ident.idNode.kte.kte < 1000)
|
||||
o << expr->expr.ident.idNode.kte.kte;
|
||||
else
|
||||
o << "0x"<<std::hex << expr->expr.ident.idNode.kte.kte;
|
||||
break;
|
||||
|
||||
case STRING:
|
||||
o << getString (expr->expr.ident.idNode.strIdx);
|
||||
break;
|
||||
case STRING:
|
||||
o << getString (expr->expr.ident.idNode.strIdx);
|
||||
break;
|
||||
|
||||
case LONG_VAR:
|
||||
id = &pProc->localId.id_arr[expr->expr.ident.idNode.longIdx];
|
||||
if (id->name[0] != '\0') /* STK_FRAME & REG w/name*/
|
||||
o << id->name;
|
||||
else if (id->loc == REG_FRAME)
|
||||
{
|
||||
id->setLocalName(++(*numLoc));
|
||||
codeOut <<TypeContainer::typeName(id->type)<< " "<<id->name<<"; ";
|
||||
codeOut <<"/* "<<Machine_X86::regName(id->id.longId.h) << ":" <<
|
||||
Machine_X86::regName(id->id.longId.l) << " */\n";
|
||||
o << id->name;
|
||||
pProc->localId.propLongId (id->id.longId.l,id->id.longId.h, id->name.c_str());
|
||||
}
|
||||
else /* GLB_FRAME */
|
||||
{
|
||||
if (id->id.longGlb.regi == 0) /* not indexed */
|
||||
o << "[" << (id->id.longGlb.seg<<4) + id->id.longGlb.offH <<"]";
|
||||
else if (id->id.longGlb.regi == rBX)
|
||||
o << "[" << (id->id.longGlb.seg<<4) + id->id.longGlb.offH <<"][bx]";
|
||||
}
|
||||
break;
|
||||
case LONG_VAR:
|
||||
id = &pProc->localId.id_arr[expr->expr.ident.idNode.longIdx];
|
||||
if (id->name[0] != '\0') /* STK_FRAME & REG w/name*/
|
||||
o << id->name;
|
||||
else if (id->loc == REG_FRAME)
|
||||
{
|
||||
id->setLocalName(++(*numLoc));
|
||||
codeOut <<TypeContainer::typeName(id->type)<< " "<<id->name<<"; ";
|
||||
codeOut <<"/* "<<Machine_X86::regName(id->id.longId.h) << ":" <<
|
||||
Machine_X86::regName(id->id.longId.l) << " */\n";
|
||||
o << id->name;
|
||||
pProc->localId.propLongId (id->id.longId.l,id->id.longId.h, id->name.c_str());
|
||||
}
|
||||
else /* GLB_FRAME */
|
||||
{
|
||||
if (id->id.longGlb.regi == 0) /* not indexed */
|
||||
o << "[" << (id->id.longGlb.seg<<4) + id->id.longGlb.offH <<"]";
|
||||
else if (id->id.longGlb.regi == rBX)
|
||||
o << "[" << (id->id.longGlb.seg<<4) + id->id.longGlb.offH <<"][bx]";
|
||||
}
|
||||
break;
|
||||
|
||||
case FUNCTION:
|
||||
o << writeCall (expr->expr.ident.idNode.call.proc,*expr->expr.ident.idNode.call.args, pProc, numLoc);
|
||||
break;
|
||||
case FUNCTION:
|
||||
o << writeCall (expr->expr.ident.idNode.call.proc,*expr->expr.ident.idNode.call.args, pProc, numLoc);
|
||||
break;
|
||||
|
||||
case OTHER:
|
||||
off = expr->expr.ident.idNode.other.off;
|
||||
o << Machine_X86::regName(expr->expr.ident.idNode.other.seg)<< "[";
|
||||
o << Machine_X86::regName(expr->expr.ident.idNode.other.regi);
|
||||
if (off < 0)
|
||||
o << "-"<< hexStr (-off);
|
||||
else if (off>0)
|
||||
o << "+"<< hexStr (off);
|
||||
o << "]";
|
||||
} /* eos */
|
||||
outStr << o.str();
|
||||
break;
|
||||
case OTHER:
|
||||
off = expr->expr.ident.idNode.other.off;
|
||||
o << Machine_X86::regName(expr->expr.ident.idNode.other.seg)<< "[";
|
||||
o << Machine_X86::regName(expr->expr.ident.idNode.other.regi);
|
||||
if (off < 0)
|
||||
o << "-"<< hexStr (-off);
|
||||
else if (off>0)
|
||||
o << "+"<< hexStr (off);
|
||||
o << "]";
|
||||
} /* eos */
|
||||
outStr << o.str();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
fprintf(stderr,"walkCondExpr attemped on %d\n",expr->m_type);
|
||||
break;
|
||||
}
|
||||
cCode.appendDecl(codeOut.str());
|
||||
return outStr.str();
|
||||
@@ -796,21 +806,23 @@ COND_EXPR *COND_EXPR::clone() const
|
||||
|
||||
switch (m_type)
|
||||
{
|
||||
case BOOLEAN_OP:
|
||||
newExp = new COND_EXPR(*this);
|
||||
newExp->boolExpr.lhs = lhs()->clone();
|
||||
newExp->boolExpr.rhs = rhs()->clone();
|
||||
break;
|
||||
case BOOLEAN_OP:
|
||||
newExp = new COND_EXPR(*this);
|
||||
newExp->boolExpr.lhs = lhs()->clone();
|
||||
newExp->boolExpr.rhs = rhs()->clone();
|
||||
break;
|
||||
|
||||
case NEGATION:
|
||||
case ADDRESSOF:
|
||||
case DEREFERENCE:
|
||||
newExp = new COND_EXPR(*this);
|
||||
newExp->expr.unaryExp = expr.unaryExp->clone();
|
||||
break;
|
||||
case NEGATION:
|
||||
case ADDRESSOF:
|
||||
case DEREFERENCE:
|
||||
newExp = new COND_EXPR(*this);
|
||||
newExp->expr.unaryExp = expr.unaryExp->clone();
|
||||
break;
|
||||
|
||||
case IDENTIFIER:
|
||||
return new COND_EXPR(*this);
|
||||
case IDENTIFIER:
|
||||
return new COND_EXPR(*this);
|
||||
default:
|
||||
fprintf(stderr,"Clone attempt on unhandled type %d\n",m_type);
|
||||
}
|
||||
return (newExp);
|
||||
}
|
||||
@@ -857,7 +869,7 @@ COND_EXPR *COND_EXPR::insertSubTreeReg (COND_EXPR *_expr, eReg regi,const LOCAL_
|
||||
return _expr;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return nullptr;
|
||||
|
||||
case BOOLEAN_OP:
|
||||
temp = lhs()->insertSubTreeReg( _expr, regi, locsym);
|
||||
@@ -884,11 +896,14 @@ COND_EXPR *COND_EXPR::insertSubTreeReg (COND_EXPR *_expr, eReg regi,const LOCAL_
|
||||
return this;
|
||||
}
|
||||
return nullptr;
|
||||
default:
|
||||
fprintf(stderr,"insertSubTreeReg attempt on unhandled type %d\n",m_type);
|
||||
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
COND_EXPR *BinaryOperator::insertSubTreeReg(COND_EXPR *_expr, eReg regi, LOCAL_ID *locsym)
|
||||
COND_EXPR *BinaryOperator::insertSubTreeReg(COND_EXPR *_expr, eReg regi, const LOCAL_ID *locsym)
|
||||
{
|
||||
COND_EXPR *r;
|
||||
r=m_lhs->insertSubTreeReg(_expr,regi,locsym);
|
||||
@@ -957,6 +972,8 @@ COND_EXPR *COND_EXPR::insertSubTreeLongReg(COND_EXPR *_expr, int longIdx)
|
||||
return this;
|
||||
}
|
||||
return nullptr;
|
||||
default:
|
||||
fprintf(stderr,"insertSubTreeLongReg attempt on unhandled type %d\n",m_type);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@@ -993,13 +1010,15 @@ void COND_EXPR::release()
|
||||
case DEREFERENCE:
|
||||
expr.unaryExp->release();
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"release attempt on unhandled type %d\n",m_type);
|
||||
}
|
||||
delete (this);
|
||||
}
|
||||
/* Makes a copy of the given expression. Allocates newExp storage for each
|
||||
* node. Returns the copy. */
|
||||
|
||||
COND_EXPR *BinaryOperator::clone()
|
||||
COND_EXPR *BinaryOperator::clone() const
|
||||
{
|
||||
BinaryOperator* newExp=new BinaryOperator(m_op); /* Expression node copy */
|
||||
newExp->m_lhs = m_lhs->clone();
|
||||
@@ -1007,7 +1026,7 @@ COND_EXPR *BinaryOperator::clone()
|
||||
return newExp;
|
||||
}
|
||||
|
||||
COND_EXPR *BinaryOperator::inverse()
|
||||
COND_EXPR *BinaryOperator::inverse() const
|
||||
{
|
||||
static condOp invCondOp[] = {GREATER, GREATER_EQUAL, NOT_EQUAL, EQUAL,
|
||||
LESS_EQUAL, LESS, DUMMY,DUMMY,DUMMY,DUMMY,
|
||||
@@ -1030,6 +1049,8 @@ COND_EXPR *BinaryOperator::inverse()
|
||||
res->m_lhs=m_lhs->inverse ();
|
||||
res->m_rhs=m_rhs->inverse ();
|
||||
return res;
|
||||
default:
|
||||
fprintf(stderr,"BinaryOperator::inverse attempt on unhandled op %d\n",m_op);
|
||||
} /* eos */
|
||||
assert(false);
|
||||
return res;
|
||||
|
||||
@@ -178,11 +178,12 @@ static void writeHeader (std::ostream &_ios, char *fileName)
|
||||
}
|
||||
|
||||
// Note: Not currently called!
|
||||
/* Checks the given icode to determine whether it has a label associated
|
||||
/** Checks the given icode to determine whether it has a label associated
|
||||
* to it. If so, a goto is emitted to this label; otherwise, a new label
|
||||
* is created and a goto is also emitted.
|
||||
* Note: this procedure is to be used when the label is to be forward on
|
||||
* the code; that is, the target code has not been traversed yet. */
|
||||
#if 0
|
||||
static void emitFwdGotoLabel (ICODE * pt, int indLevel)
|
||||
{
|
||||
if ( not pt->ll()->testFlags(HLL_LABEL)) /* node hasn't got a lab */
|
||||
@@ -193,7 +194,7 @@ static void emitFwdGotoLabel (ICODE * pt, int indLevel)
|
||||
}
|
||||
cCode.appendCode( "%sgoto l%ld;\n", indentStr(indLevel), pt->ll()->hllLabNum);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* Writes the procedure's declaration (including arguments), local variables,
|
||||
* and invokes the procedure that writes the code of the given record *hli */
|
||||
|
||||
@@ -26,7 +26,7 @@ void strTable::addLabelBundle (int idx, int label)
|
||||
if(at(idx).size()<4)
|
||||
at(idx)=s;
|
||||
else
|
||||
at(idx) = string(s)+at(idx).substr(4);
|
||||
at(idx) = string(s)+at(idx).substr(4);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -219,8 +219,8 @@ static uint8_t pattMainSmall[] =
|
||||
0xFF, 0x36, WILD, WILD, /* Push argv */
|
||||
0xFF, 0x36, WILD, WILD, /* Push argc */
|
||||
0xE8, WILD, WILD /* call _main */
|
||||
/* 0x50, /* push ax... not in Borland V3 */
|
||||
/* 0xE8 /* call _exit */
|
||||
// 0x50, /* push ax... not in Borland V3 */
|
||||
// 0xE8 /* call _exit */
|
||||
};
|
||||
/* Num bytes from start pattern to the relative offset of main() */
|
||||
#define OFFMAINSMALL 13
|
||||
@@ -232,9 +232,9 @@ static uint8_t pattMainMedium[] =
|
||||
0xFF, 0x36, WILD, WILD, /* Push argv */
|
||||
0xFF, 0x36, WILD, WILD, /* Push argc */
|
||||
0x9A, WILD, WILD, WILD, WILD /* call far _main */
|
||||
/* 0x50 /* push ax */
|
||||
/* 0x0E, /* push cs NB not tested Borland */
|
||||
/* 0xE8 /* call _exit */
|
||||
// 0x50 /* push ax */
|
||||
// 0x0E, /* push cs NB not tested Borland */
|
||||
// 0xE8 /* call _exit */
|
||||
};
|
||||
/* Num bytes from start pattern to the relative offset of main() */
|
||||
#define OFFMAINMEDIUM 13
|
||||
@@ -248,8 +248,8 @@ static uint8_t pattMainCompact[] =
|
||||
0xFF, 0x36, WILD, WILD, /* Push argv hi */
|
||||
0xFF, 0x36, WILD, WILD, /* Push argc */
|
||||
0xE8, WILD, WILD, /* call _main */
|
||||
/* 0x50, /* push ax */
|
||||
/* 0xE8 /* call _exit */
|
||||
// 0x50, /* push ax */
|
||||
// 0xE8 /* call _exit */
|
||||
};
|
||||
/* Num bytes from start pattern to the relative offset of main() */
|
||||
#define OFFMAINCOMPACT 21
|
||||
@@ -263,9 +263,9 @@ static uint8_t pattMainLarge[] =
|
||||
0xFF, 0x36, WILD, WILD, /* Push argv hi */
|
||||
0xFF, 0x36, WILD, WILD, /* Push argc */
|
||||
0x9A, WILD, WILD, WILD, WILD /* call far _main */
|
||||
/* 0x50 /* push ax */
|
||||
/* 0x0E, /* push cs */
|
||||
/* 0xE8 /* call _exit */
|
||||
// 0x50 /* push ax */
|
||||
// 0x0E, /* push cs */
|
||||
// 0xE8 /* call _exit */
|
||||
};
|
||||
/* Num bytes from start pattern to the relative offset of main() */
|
||||
#define OFFMAINLARGE 21
|
||||
@@ -502,6 +502,8 @@ bool LibCheck(Function & pProc)
|
||||
case TYPE_BYTE_SIGN: case TYPE_BYTE_UNSIGN:
|
||||
pProc.liveOut = duReg[rAL];
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"Unknown retval type %d in LibCheck\n",pProc.retVal.type);
|
||||
/*** other types are not considered yet ***/
|
||||
}
|
||||
}
|
||||
@@ -569,12 +571,12 @@ readFileSection(uint16_t* p, int len, FILE* f)
|
||||
}
|
||||
|
||||
/* The following two functions are dummies, since we don't call map() */
|
||||
void getKey(int i, uint8_t **keys)
|
||||
void getKey(int /*i*/, uint8_t **/*keys*/)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void dispKey(int i)
|
||||
void dispKey(int /*i*/)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -695,7 +697,7 @@ void STATE::checkStartup()
|
||||
but decides the model required. Note: must do the far data models
|
||||
(large and compact) before the others, since they are the same pattern
|
||||
as near data, just more pushes at the start. */
|
||||
if(prog.cbImage>startOff+0x180+sizeof(pattMainLarge))
|
||||
if(prog.cbImage>int(startOff+0x180+sizeof(pattMainLarge)))
|
||||
{
|
||||
if (locatePattern(prog.Image, startOff, startOff+0x180, pattMainLarge,sizeof(pattMainLarge), &i))
|
||||
{
|
||||
|
||||
@@ -244,6 +244,9 @@ void Function::writeProcComments(std::ostream &ostr)
|
||||
case TYPE_LONG_SIGN: case TYPE_LONG_UNSIGN:
|
||||
ostr << " * Return value in registers dx:ax.\n";
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"Unknown retval type %d",this->retVal.type);
|
||||
break;
|
||||
} /* eos */
|
||||
}
|
||||
|
||||
|
||||
@@ -300,13 +300,12 @@ void Function::structLoops(derSeq *derivedG)
|
||||
{
|
||||
pred = intHead->inEdges[i];
|
||||
if (inInt(pred, intNodes) && isBackEdge(pred, intHead))
|
||||
{
|
||||
if (! latchNode)
|
||||
latchNode = pred;
|
||||
else
|
||||
{
|
||||
if (pred->dfsLastNum > latchNode->dfsLastNum)
|
||||
latchNode = pred;
|
||||
}
|
||||
else if (pred->dfsLastNum > latchNode->dfsLastNum)
|
||||
latchNode = pred;
|
||||
}
|
||||
}
|
||||
|
||||
/* Find nodes in the loop and the type of loop */
|
||||
@@ -352,8 +351,7 @@ static bool successor (int s, int h, Function * pProc)
|
||||
* case). */
|
||||
static void tagNodesInCase (BB * pBB, nodeList &l, int head, int tail)
|
||||
{
|
||||
int current, /* index to current node */
|
||||
i;
|
||||
int current; /* index to current node */
|
||||
|
||||
pBB->traversed = DFS_CASE;
|
||||
current = pBB->dfsLastNum;
|
||||
@@ -374,44 +372,46 @@ static void tagNodesInCase (BB * pBB, nodeList &l, int head, int tail)
|
||||
* has a case node. */
|
||||
void Function::structCases()
|
||||
{
|
||||
int i, j;
|
||||
BB * caseHeader; /* case header node */
|
||||
int exitNode = NO_NODE; /* case exit node */
|
||||
nodeList caseNodes; /* temporary: list of nodes in case */
|
||||
|
||||
/* Linear scan of the nodes in reverse dfsLast order, searching for
|
||||
* case nodes */
|
||||
for (i = numBBs - 1; i >= 0; i--)
|
||||
if (m_dfsLast[i]->nodeType == MULTI_BRANCH)
|
||||
{
|
||||
caseHeader = m_dfsLast[i];
|
||||
for (int i = numBBs - 1; i >= 0; i--)
|
||||
{
|
||||
if ((m_dfsLast[i]->nodeType != MULTI_BRANCH))
|
||||
continue;
|
||||
BB * caseHeader = m_dfsLast[i];; /* case header node */
|
||||
|
||||
/* Find descendant node which has as immediate predecessor
|
||||
/* Find descendant node which has as immediate predecessor
|
||||
* the current header node, and is not a successor. */
|
||||
for (j = i + 2; j < numBBs; j++)
|
||||
for (size_t j = i + 2; j < numBBs; j++)
|
||||
{
|
||||
if ((!successor(j, i, this)) && (m_dfsLast[j]->immedDom == i))
|
||||
{
|
||||
if ((!successor(j, i, this)) &&
|
||||
(m_dfsLast[j]->immedDom == i))
|
||||
if (exitNode == NO_NODE)
|
||||
exitNode = j;
|
||||
else if (m_dfsLast[exitNode]->inEdges.size() < m_dfsLast[j]->inEdges.size())
|
||||
exitNode = j;
|
||||
if (exitNode == NO_NODE)
|
||||
{
|
||||
exitNode = j;
|
||||
}
|
||||
else if (m_dfsLast[exitNode]->inEdges.size() < m_dfsLast[j]->inEdges.size())
|
||||
exitNode = j;
|
||||
}
|
||||
m_dfsLast[i]->caseTail = exitNode;
|
||||
|
||||
/* Tag nodes that belong to the case by recording the
|
||||
* header field with caseHeader. */
|
||||
insertList (caseNodes, i);
|
||||
m_dfsLast[i]->caseHead = i;
|
||||
for(TYPEADR_TYPE &pb : caseHeader->edges)
|
||||
{
|
||||
tagNodesInCase(pb.BBptr, caseNodes, i, exitNode);
|
||||
}
|
||||
//for (j = 0; j < caseHeader->edges[j]; j++)
|
||||
// tagNodesInCase (caseHeader->edges[j].BBptr, caseNodes, i, exitNode);
|
||||
if (exitNode != NO_NODE)
|
||||
m_dfsLast[exitNode]->caseHead = i;
|
||||
}
|
||||
m_dfsLast[i]->caseTail = exitNode;
|
||||
|
||||
/* Tag nodes that belong to the case by recording the
|
||||
* header field with caseHeader. */
|
||||
insertList (caseNodes, i);
|
||||
m_dfsLast[i]->caseHead = i;
|
||||
for(TYPEADR_TYPE &pb : caseHeader->edges)
|
||||
{
|
||||
tagNodesInCase(pb.BBptr, caseNodes, i, exitNode);
|
||||
}
|
||||
//for (j = 0; j < caseHeader->edges[j]; j++)
|
||||
// tagNodesInCase (caseHeader->edges[j].BBptr, caseNodes, i, exitNode);
|
||||
if (exitNode != NO_NODE)
|
||||
m_dfsLast[exitNode]->caseHead = i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -432,7 +432,7 @@ static void flagNodes (nodeList &l, int f, Function * pProc)
|
||||
void Function::structIfs ()
|
||||
{
|
||||
int curr, /* Index for linear scan of nodes */
|
||||
desc, /* Index for descendant */
|
||||
/*desc,*/ /* Index for descendant */
|
||||
followInEdges, /* Largest # in-edges so far */
|
||||
follow; /* Possible follow node */
|
||||
nodeList domDesc, /* List of nodes dominated by curr */
|
||||
@@ -454,7 +454,7 @@ void Function::structIfs ()
|
||||
follow = 0;
|
||||
|
||||
/* Find all nodes that have this node as immediate dominator */
|
||||
for (desc = curr+1; desc < numBBs; desc++)
|
||||
for (size_t desc = curr+1; desc < numBBs; desc++)
|
||||
{
|
||||
if (m_dfsLast[desc]->immedDom == curr)
|
||||
{
|
||||
@@ -603,7 +603,7 @@ void Function::compoundCond()
|
||||
|
||||
/* Traverse nodes in postorder, this way, the header node of a
|
||||
* compound condition is analysed first */
|
||||
for (int i = 0; i < this->numBBs; i++)
|
||||
for (size_t i = 0; i < this->numBBs; i++)
|
||||
{
|
||||
pbb = this->m_dfsLast[i];
|
||||
if (pbb->flg & INVALID_BB)
|
||||
|
||||
118
src/dataflow.cpp
118
src/dataflow.cpp
@@ -114,7 +114,7 @@ static COND_EXPR *dstIdent (const LLInst & ll_insn, Function * pProc, iICODE i,
|
||||
/* Eliminates all condition codes and generates new hlIcode instructions */
|
||||
void Function::elimCondCodes ()
|
||||
{
|
||||
int i;
|
||||
// int i;
|
||||
|
||||
uint8_t use; /* Used flags bit vector */
|
||||
uint8_t def; /* Defined flags bit vector */
|
||||
@@ -122,15 +122,19 @@ void Function::elimCondCodes ()
|
||||
COND_EXPR *rhs; /* Source operand */
|
||||
COND_EXPR *lhs; /* Destination operand */
|
||||
COND_EXPR *_expr; /* Boolean expression */
|
||||
BB * pBB; /* Pointer to BBs in dfs last ordering */
|
||||
//BB * pBB; /* Pointer to BBs in dfs last ordering */
|
||||
riICODE useAt; /* Instruction that used flag */
|
||||
riICODE defAt; /* Instruction that defined flag */
|
||||
//lhs=rhs=_expr=0;
|
||||
for (i = 0; i < numBBs; i++)
|
||||
auto valid_reversed_bbs = (m_dfsLast | reversed | filtered(BB::ValidFunctor()) );
|
||||
for( BB * pBB : valid_reversed_bbs)
|
||||
{
|
||||
pBB = m_dfsLast[i];
|
||||
if (pBB->flg & INVALID_BB)
|
||||
continue; /* Do not process invalid BBs */
|
||||
|
||||
// for (size_t i = 0; i < numBBs; i++)
|
||||
// {
|
||||
// pBB = m_dfsLast[i];
|
||||
// if (pBB->flg & INVALID_BB)
|
||||
// continue; /* Do not process invalid BBs */
|
||||
// auto v(pBB | boost::adaptors::reversed);
|
||||
// for (const ICODE &useAt : v)
|
||||
// {}
|
||||
@@ -245,11 +249,10 @@ void Function::elimCondCodes ()
|
||||
* is not really meant to be a register that is used before defined). */
|
||||
void Function::genLiveKtes ()
|
||||
{
|
||||
int i;
|
||||
BB * pbb;
|
||||
bitset<32> liveUse, def;
|
||||
|
||||
for (i = 0; i < numBBs; i++)
|
||||
for (size_t i = 0; i < numBBs; i++)
|
||||
{
|
||||
liveUse.reset();
|
||||
def.reset();
|
||||
@@ -617,42 +620,45 @@ bool COND_EXPR::xClear (rICODE range_to_check, iICODE lastBBinst, const LOCAL_ID
|
||||
|
||||
switch (m_type)
|
||||
{
|
||||
case IDENTIFIER:
|
||||
if (expr.ident.idType == REGISTER)
|
||||
{
|
||||
regi= locId.id_arr[expr.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)
|
||||
case IDENTIFIER:
|
||||
if (expr.ident.idType == REGISTER)
|
||||
{
|
||||
regi= locId.id_arr[expr.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;
|
||||
}
|
||||
else
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
return true;
|
||||
/* else if (rhs->expr.ident.idType == LONG_VAR)
|
||||
/* else if (rhs->expr.ident.idType == LONG_VAR)
|
||||
{
|
||||
missing all other identifiers ****
|
||||
} */
|
||||
|
||||
case BOOLEAN_OP:
|
||||
if(0==rhs())
|
||||
return false;
|
||||
res = rhs()->xClear ( range_to_check, lastBBinst, locId);
|
||||
if (res == false)
|
||||
return false;
|
||||
if(0==lhs())
|
||||
return false;
|
||||
return lhs()->xClear ( range_to_check, lastBBinst, locId);
|
||||
case BOOLEAN_OP:
|
||||
if(0==rhs())
|
||||
return false;
|
||||
res = rhs()->xClear ( range_to_check, lastBBinst, locId);
|
||||
if (res == false)
|
||||
return false;
|
||||
if(0==lhs())
|
||||
return false;
|
||||
return lhs()->xClear ( range_to_check, lastBBinst, locId);
|
||||
|
||||
case NEGATION:
|
||||
case ADDRESSOF:
|
||||
case DEREFERENCE:
|
||||
if(0==expr.unaryExp)
|
||||
return false;
|
||||
return expr.unaryExp->xClear ( range_to_check, lastBBinst, locId);
|
||||
default:
|
||||
fprintf(stderr,"COND_EXPR::xClear unhandled type %d\n",m_type);
|
||||
|
||||
case NEGATION:
|
||||
case ADDRESSOF:
|
||||
case DEREFERENCE:
|
||||
if(0==expr.unaryExp)
|
||||
return false;
|
||||
return expr.unaryExp->xClear ( range_to_check, lastBBinst, locId);
|
||||
} /* eos */
|
||||
return false;
|
||||
}
|
||||
@@ -677,7 +683,7 @@ bool BinaryOperator::xClear(rICODE range_to_check, iICODE lastBBinst, const LOCA
|
||||
* whenever possible, and then places the actual argument on the procedure's
|
||||
* argument list. */
|
||||
/// @returns the type size of the stored Arg
|
||||
static int processCArg (Function * pp, Function * pProc, ICODE * picode, int numArgs)
|
||||
static int processCArg (Function * pp, Function * pProc, ICODE * picode, size_t numArgs)
|
||||
{
|
||||
COND_EXPR *_exp;
|
||||
bool res;
|
||||
@@ -689,6 +695,7 @@ static int processCArg (Function * pp, Function * pProc, ICODE * picode, int num
|
||||
if (pp->flg & PROC_ISLIB) /* library function */
|
||||
{
|
||||
if (pp->args.numArgs > 0)
|
||||
{
|
||||
if (pp->flg & PROC_VARARG)
|
||||
{
|
||||
if (numArgs < pp->args.size())
|
||||
@@ -696,6 +703,7 @@ static int processCArg (Function * pp, Function * pProc, ICODE * picode, int num
|
||||
}
|
||||
else
|
||||
adjustActArgType (_exp, pp->args[numArgs].type, pProc);
|
||||
}
|
||||
}
|
||||
else /* user function */
|
||||
{
|
||||
@@ -765,6 +773,9 @@ void LOCAL_ID::processTargetIcode(iICODE picode, int &numHlIcodes, iICODE ticode
|
||||
picode->invalidate();
|
||||
numHlIcodes--;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"unhandled LOCAL_ID::processTargetIcode opcode %d\n",t_hl.opcode);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -831,7 +842,7 @@ void Function::processHliCall(COND_EXPR *_exp, iICODE picode)
|
||||
}
|
||||
|
||||
|
||||
int BB::findBBExps(LOCAL_ID &locals,Function *fnc)
|
||||
void BB::findBBExps(LOCAL_ID &locals,Function *fnc)
|
||||
{
|
||||
bool res;
|
||||
|
||||
@@ -907,12 +918,15 @@ int BB::findBBExps(LOCAL_ID &locals,Function *fnc)
|
||||
}
|
||||
break;
|
||||
|
||||
/****case HLI_CALL: /* register arguments
|
||||
/****case HLI_CALL: // register arguments
|
||||
newRegArg (pProc, picode, ticode);
|
||||
picode->invalidate();
|
||||
numHlIcodes--;
|
||||
break; */
|
||||
} /* eos */
|
||||
default:
|
||||
fprintf(stderr,"unhandled BB::findBBExps target opcode %d\n",ticode->hl()->opcode);
|
||||
|
||||
} // eos
|
||||
break;
|
||||
|
||||
case HLI_CALL:
|
||||
@@ -953,8 +967,12 @@ int BB::findBBExps(LOCAL_ID &locals,Function *fnc)
|
||||
picode->setAsgn(lhs, _exp);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"unhandled BB::findBBExps HLI_CALL target opcode %d\n",ti_hl->opcode);
|
||||
} /* eos */
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"BB::findBBExps Unhandled HLI %d\n",_icHl.opcode);
|
||||
} /* eos */
|
||||
}
|
||||
}
|
||||
@@ -1009,6 +1027,8 @@ int BB::findBBExps(LOCAL_ID &locals,Function *fnc)
|
||||
break;
|
||||
case HLI_CALL: /*** missing ***/
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"BB::findBBExps Unhandled target op %d\n",ticode->hl()->opcode);
|
||||
} /* eos */
|
||||
}
|
||||
break;
|
||||
@@ -1052,7 +1072,13 @@ int BB::findBBExps(LOCAL_ID &locals,Function *fnc)
|
||||
picode->setAsgn(lhs, _exp);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"BB::findBBExps Unhandled target op %d\n",ticode->hl()->opcode);
|
||||
} /* eos */
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"BB::findBBExps Unhandled HLI %d\n",_icHl.opcode);
|
||||
|
||||
} /* eos */
|
||||
}
|
||||
}
|
||||
@@ -1115,7 +1141,7 @@ void Function::preprocessReturnDU(std::bitset<32> &_liveOut)
|
||||
{
|
||||
if (_liveOut.any())
|
||||
{
|
||||
int idx;
|
||||
// int idx;
|
||||
bool isAx, isBx, isCx, isDx;
|
||||
flg |= PROC_IS_FUNC;
|
||||
isAx = _liveOut.test(rAX - rAX);
|
||||
@@ -1157,7 +1183,7 @@ void Function::preprocessReturnDU(std::bitset<32> &_liveOut)
|
||||
retVal.loc = REG_FRAME;
|
||||
retVal.id.longId.h = rDX;
|
||||
retVal.id.longId.l = rAX;
|
||||
idx = localId.newLongReg(TYPE_LONG_SIGN, rDX, rAX, Icode.begin()/*0*/);
|
||||
/*idx = */localId.newLongReg(TYPE_LONG_SIGN, rDX, rAX, Icode.begin()/*0*/);
|
||||
localId.propLongId (rAX, rDX, "\0");
|
||||
}
|
||||
else if (isAx || isBx || isCx || isDx) /* uint16_t */
|
||||
@@ -1172,7 +1198,7 @@ void Function::preprocessReturnDU(std::bitset<32> &_liveOut)
|
||||
retVal.id.regi = rCX;
|
||||
else
|
||||
retVal.id.regi = rDX;
|
||||
idx = localId.newByteWordReg(TYPE_WORD_SIGN,retVal.id.regi);
|
||||
/*idx = */localId.newByteWordReg(TYPE_WORD_SIGN,retVal.id.regi);
|
||||
}
|
||||
else if(isAL||isBL||isCL||isDL)
|
||||
{
|
||||
@@ -1186,7 +1212,7 @@ void Function::preprocessReturnDU(std::bitset<32> &_liveOut)
|
||||
retVal.id.regi = rCL;
|
||||
else
|
||||
retVal.id.regi = rDL;
|
||||
idx = localId.newByteWordReg(TYPE_BYTE_SIGN,retVal.id.regi);
|
||||
/*idx = */localId.newByteWordReg(TYPE_BYTE_SIGN,retVal.id.regi);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
17
src/dcc.cpp
17
src/dcc.cpp
@@ -9,11 +9,11 @@
|
||||
#include <string.h>
|
||||
|
||||
/* Global variables - extern to other modules */
|
||||
char *asm1_name, *asm2_name; /* Assembler output filenames */
|
||||
SYMTAB symtab; /* Global symbol table */
|
||||
STATS stats; /* cfg statistics */
|
||||
extern char *asm1_name, *asm2_name; /* Assembler output filenames */
|
||||
extern SYMTAB symtab; /* Global symbol table */
|
||||
extern STATS stats; /* cfg statistics */
|
||||
//PROG prog; /* programs fields */
|
||||
OPTION option; /* Command line options */
|
||||
extern OPTION option; /* Command line options */
|
||||
//Function * pProcList; /* List of procedures, topologically sort */
|
||||
//Function * pLastProc; /* Pointer to last node in procedure list */
|
||||
//FunctionListType pProcList;
|
||||
@@ -27,7 +27,6 @@ static void displayTotalStats(void);
|
||||
* main
|
||||
***************************************************************************/
|
||||
#include <iostream>
|
||||
extern Project g_proj;
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// llvm::MCOperand op=llvm::MCOperand::CreateImm(11);
|
||||
@@ -56,9 +55,9 @@ int main(int argc, char *argv[])
|
||||
* analysis, data flow etc. and outputs it to output file ready for
|
||||
* re-compilation.
|
||||
*/
|
||||
BackEnd(option.filename, g_proj.callGraph);
|
||||
BackEnd(option.filename, Project::get()->callGraph);
|
||||
|
||||
g_proj.callGraph->write();
|
||||
Project::get()->callGraph->write();
|
||||
|
||||
if (option.Stats)
|
||||
displayTotalStats();
|
||||
@@ -153,8 +152,8 @@ displayTotalStats ()
|
||||
/* Displays final statistics for the complete program */
|
||||
{
|
||||
printf ("\nFinal Program Statistics\n");
|
||||
printf (" Total number of low-level Icodes : %ld\n", stats.totalLL);
|
||||
printf (" Total number of high-level Icodes: %ld\n", stats.totalHL);
|
||||
printf (" Total number of low-level Icodes : %d\n", stats.totalLL);
|
||||
printf (" Total number of high-level Icodes: %d\n", stats.totalHL);
|
||||
printf (" Total reduction of instructions : %2.2f%%\n", 100.0 -
|
||||
(stats.totalHL * 100.0) / stats.totalLL);
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ struct POSSTACK_ENTRY
|
||||
Function * pProc; /* A pointer to a PROCEDURE structure */
|
||||
} ;
|
||||
static vector<POSSTACK_ENTRY> posStack; /* position stack */
|
||||
static uint8_t iPS; /* Index into the stack */
|
||||
//static uint8_t iPS; /* Index into the stack */
|
||||
|
||||
|
||||
// These are "curses equivalent" functions. (Used to use curses for all this,
|
||||
@@ -552,7 +552,7 @@ void Disassembler::dis1Line(LLInst &inst,int loc_ip, int pass)
|
||||
/****************************************************************************
|
||||
* formatRM
|
||||
***************************************************************************/
|
||||
static void formatRM(std::ostringstream &p, uint32_t flg, const LLOperand &pm)
|
||||
static void formatRM(std::ostringstream &p, uint32_t /*flg*/, const LLOperand &pm)
|
||||
{
|
||||
//char seg[4];
|
||||
|
||||
@@ -627,14 +627,14 @@ static char *strHex(uint32_t d)
|
||||
static char buf[10];
|
||||
|
||||
d &= 0xFFFF;
|
||||
sprintf(buf, "0%lX%s", d, (d > 9)? "h": "");
|
||||
sprintf(buf, "0%X%s", d, (d > 9)? "h": "");
|
||||
return (buf + (buf[1] <= '9'));
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* interactDis - interactive disassembler *
|
||||
****************************************************************************/
|
||||
void interactDis(Function * initProc, int initIC)
|
||||
void interactDis(Function * /*initProc*/, int /*initIC*/)
|
||||
{
|
||||
printf("Sorry - interactive disasassembler option not available for Unix\n");
|
||||
return;
|
||||
@@ -643,7 +643,7 @@ void interactDis(Function * initProc, int initIC)
|
||||
/* Handle the floating point opcodes (icode iESC) */
|
||||
void LLInst::flops(std::ostringstream &out)
|
||||
{
|
||||
char bf[30];
|
||||
//char bf[30];
|
||||
uint8_t op = (uint8_t)src().getImm2();
|
||||
|
||||
/* Note that op is set to the escape number, e.g.
|
||||
|
||||
@@ -3,14 +3,20 @@
|
||||
* Loads a program into simulated main memory and builds the procedure list.
|
||||
* (C) Cristina Cifuentes
|
||||
****************************************************************************/
|
||||
|
||||
#define __STDC_FORMAT_MACROS
|
||||
#include "dcc.h"
|
||||
#include "disassem.h"
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <malloc.h> /* For malloc, free, realloc */
|
||||
#include "project.h"
|
||||
class Loader
|
||||
{
|
||||
bool loadIntoProject(IProject *);
|
||||
};
|
||||
|
||||
typedef struct { /* PSP structure */
|
||||
uint16_t int20h; /* interrupt 20h */
|
||||
uint16_t eof; /* segment, end of allocation block */
|
||||
@@ -50,7 +56,7 @@ static struct { /* EXE file header */
|
||||
|
||||
#define EXE_RELOCATION 0x10 /* EXE images rellocated to above PSP */
|
||||
|
||||
static void LoadImage(char *filename);
|
||||
//static void LoadImage(char *filename);
|
||||
static void displayLoadInfo(void);
|
||||
static void displayMemMap(void);
|
||||
|
||||
@@ -58,22 +64,20 @@ static void displayMemMap(void);
|
||||
* FrontEnd - invokes the loader, parser, disassembler (if asm1), icode
|
||||
* rewritter, and displays any useful information.
|
||||
****************************************************************************/
|
||||
extern Project g_proj;
|
||||
bool DccFrontend::FrontEnd ()
|
||||
{
|
||||
|
||||
g_proj.callGraph = 0;
|
||||
g_proj.m_fname = m_fname;
|
||||
Project::get()->callGraph = 0;
|
||||
Project::get()->create(m_fname);
|
||||
|
||||
/* Load program into memory */
|
||||
LoadImage(g_proj);
|
||||
LoadImage(*Project::get());
|
||||
|
||||
if (option.verbose)
|
||||
displayLoadInfo();
|
||||
|
||||
/* Do depth first flow analysis building call graph and procedure list,
|
||||
* and attaching the I-code to each procedure */
|
||||
parse (g_proj);
|
||||
parse (*Project::get());
|
||||
|
||||
if (option.asm1)
|
||||
{
|
||||
@@ -82,7 +86,7 @@ bool DccFrontend::FrontEnd ()
|
||||
|
||||
/* Search through code looking for impure references and flag them */
|
||||
Disassembler ds(1);
|
||||
for(Function &f : g_proj.pProcList)
|
||||
for(Function &f : Project::get()->pProcList)
|
||||
{
|
||||
f.markImpure();
|
||||
if (option.asm1)
|
||||
@@ -92,11 +96,11 @@ bool DccFrontend::FrontEnd ()
|
||||
}
|
||||
if (option.Interact)
|
||||
{
|
||||
interactDis(&g_proj.pProcList.front(), 0); /* Interactive disassembler */
|
||||
interactDis(&Project::get()->pProcList.front(), 0); /* Interactive disassembler */
|
||||
}
|
||||
|
||||
/* Converts jump target addresses to icode offsets */
|
||||
for(Function &f : g_proj.pProcList)
|
||||
for(Function &f : Project::get()->pProcList)
|
||||
{
|
||||
f.bindIcodeOff();
|
||||
}
|
||||
@@ -125,7 +129,7 @@ static void displayLoadInfo(void)
|
||||
printf("Minimum allocation = %04X paras\n", LH(&header.minAlloc));
|
||||
printf("Maximum allocation = %04X paras\n", LH(&header.maxAlloc));
|
||||
}
|
||||
printf("Load image size = %04X\n", prog.cbImage - sizeof(PSP));
|
||||
printf("Load image size = %04" PRIiPTR "\n", prog.cbImage - sizeof(PSP));
|
||||
printf("Initial SS:SP = %04X:%04X\n", prog.initSS, prog.initSP);
|
||||
printf("Initial CS:IP = %04X:%04X\n", prog.initCS, prog.initIP);
|
||||
|
||||
@@ -208,15 +212,15 @@ void DccFrontend::LoadImage(Project &proj)
|
||||
uint8_t buf[4];
|
||||
|
||||
/* Open the input file */
|
||||
if ((fp = fopen(proj.m_fname.c_str(), "rb")) == NULL)
|
||||
if ((fp = fopen(proj.binary_path().c_str(), "rb")) == NULL)
|
||||
{
|
||||
fatalError(CANNOT_OPEN, proj.m_fname.c_str());
|
||||
fatalError(CANNOT_OPEN, proj.binary_path().c_str());
|
||||
}
|
||||
|
||||
/* Read in first 2 bytes to check EXE signature */
|
||||
if (fread(&header, 1, 2, fp) != 2)
|
||||
{
|
||||
fatalError(CANNOT_READ, proj.m_fname.c_str());
|
||||
fatalError(CANNOT_READ, proj.binary_path().c_str());
|
||||
}
|
||||
|
||||
if (! (prog.fCOM = (boolT)(header.sigLo != 0x4D || header.sigHi != 0x5A))) {
|
||||
@@ -224,7 +228,7 @@ void DccFrontend::LoadImage(Project &proj)
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
if (fread(&header, sizeof(header), 1, fp) != 1)
|
||||
{
|
||||
fatalError(CANNOT_READ, proj.m_fname.c_str());
|
||||
fatalError(CANNOT_READ, proj.binary_path().c_str());
|
||||
}
|
||||
|
||||
/* This is a typical DOS kludge! */
|
||||
@@ -305,7 +309,7 @@ void DccFrontend::LoadImage(Project &proj)
|
||||
/* Read in the image past where a PSP would go */
|
||||
if (cb != (int)fread(prog.Image + sizeof(PSP), 1, (size_t)cb, fp))
|
||||
{
|
||||
fatalError(CANNOT_READ, proj.m_fname.c_str());
|
||||
fatalError(CANNOT_READ, proj.binary_path().c_str());
|
||||
}
|
||||
|
||||
/* Set up memory map */
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
#include "project.h"
|
||||
extern Project g_proj;
|
||||
//static BB * rmJMP(Function * pProc, int marker, BB * pBB);
|
||||
static void mergeFallThrough(Function * pProc, BB * pBB);
|
||||
static void dfsNumbering(BB * pBB, std::vector<BB*> &dfsLast, int *first, int *last);
|
||||
//static void mergeFallThrough(Function * pProc, BB * pBB);
|
||||
//static void dfsNumbering(BB * pBB, std::vector<BB*> &dfsLast, int *first, int *last);
|
||||
|
||||
/*****************************************************************************
|
||||
* createCFG - Create the basic control flow graph
|
||||
@@ -30,7 +30,6 @@ void Function::createCFG()
|
||||
* 6) End of procedure
|
||||
*/
|
||||
int i;
|
||||
int ip;
|
||||
BB * psBB;
|
||||
BB * pBB;
|
||||
iICODE pIcode = Icode.begin();
|
||||
@@ -85,7 +84,7 @@ CondJumps:
|
||||
{
|
||||
//pBB = BB::Create(start, ip, MULTI_BRANCH, ll->caseTbl.numEntries, this);
|
||||
pBB = BB::Create(iStart, pIcode, MULTI_BRANCH, ll->caseTbl2.size(), this);
|
||||
for (i = 0; i < ll->caseTbl2.size(); i++)
|
||||
for (size_t i = 0; i < ll->caseTbl2.size(); i++)
|
||||
pBB->edges[i].ip = ll->caseTbl2[i];
|
||||
hasCase = true;
|
||||
}
|
||||
@@ -153,7 +152,7 @@ CondJumps:
|
||||
pBB = *iter;
|
||||
for (size_t edeg_idx = 0; edeg_idx < pBB->edges.size(); edeg_idx++)
|
||||
{
|
||||
uint32_t ip = pBB->edges[edeg_idx].ip;
|
||||
int32_t ip = pBB->edges[edeg_idx].ip;
|
||||
if (ip >= SYNTHESIZED_MIN)
|
||||
{
|
||||
fatalError (INVALID_SYNTHETIC_BB);
|
||||
@@ -179,8 +178,8 @@ void Function::markImpure()
|
||||
continue;
|
||||
//assert that case tbl has less entries then symbol table ????
|
||||
//WARNING: Case entries are held in symbol table !
|
||||
assert(g_proj.validSymIdx(icod.ll()->caseEntry));
|
||||
const SYM &psym(g_proj.getSymByIdx(icod.ll()->caseEntry));
|
||||
assert(Project::get()->validSymIdx(icod.ll()->caseEntry));
|
||||
const SYM &psym(Project::get()->getSymByIdx(icod.ll()->caseEntry));
|
||||
for (int c = (int)psym.label; c < (int)psym.label+psym.size; c++)
|
||||
{
|
||||
if (BITMAP(c, BM_CODE))
|
||||
@@ -335,8 +334,6 @@ BB *BB::rmJMP(int marker, BB * pBB)
|
||||
void BB::mergeFallThrough( CIcodeRec &Icode)
|
||||
{
|
||||
BB * pChild;
|
||||
int i;
|
||||
|
||||
if (!this)
|
||||
{
|
||||
printf("mergeFallThrough on empty BB!\n");
|
||||
@@ -375,9 +372,11 @@ void BB::mergeFallThrough( CIcodeRec &Icode)
|
||||
traversed = DFS_MERGE;
|
||||
|
||||
/* Process all out edges recursively */
|
||||
for (i = 0; i < edges.size(); i++)
|
||||
if (edges[i].BBptr->traversed != DFS_MERGE)
|
||||
edges[i].BBptr->mergeFallThrough(Icode);
|
||||
for (size_t i = 0; i < edges.size(); i++)
|
||||
{
|
||||
if (edges[i].BBptr->traversed != DFS_MERGE)
|
||||
edges[i].BBptr->mergeFallThrough(Icode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -399,7 +398,7 @@ void BB::dfsNumbering(std::vector<BB *> &dfsLast, int *first, int *last)
|
||||
pChild->inEdges[pChild->index++] = this;
|
||||
|
||||
/* Is this the last visit? */
|
||||
if (pChild->index == pChild->inEdges.size())
|
||||
if (pChild->index == int(pChild->inEdges.size()))
|
||||
pChild->index = UN_INIT;
|
||||
|
||||
if (pChild->traversed != DFS_NUM)
|
||||
|
||||
@@ -282,7 +282,7 @@ HLTYPE LLInst::toHighLevel(COND_EXPR *lhs,COND_EXPR *rhs,Function *func)
|
||||
* refines the HIGH_LEVEL icodes. */
|
||||
void Function::highLevelGen()
|
||||
{
|
||||
int numIcode; /* number of icode instructions */
|
||||
size_t numIcode; /* number of icode instructions */
|
||||
iICODE pIcode; /* ptr to current icode node */
|
||||
COND_EXPR *lhs, *rhs; /* left- and right-hand side of expression */
|
||||
uint32_t _flg; /* icode flags */
|
||||
@@ -473,6 +473,8 @@ COND_EXPR *COND_EXPR::inverse () const
|
||||
res->boolExpr.lhs=lhs()->inverse ();
|
||||
res->boolExpr.rhs=rhs()->inverse ();
|
||||
return res;
|
||||
default:
|
||||
fprintf(stderr,"COND_EXPR::inverse unhandled op %d",op());
|
||||
} /* eos */
|
||||
|
||||
}
|
||||
@@ -488,8 +490,7 @@ COND_EXPR *COND_EXPR::inverse () const
|
||||
* actual parameters) */
|
||||
std::string writeCall (Function * tproc, STKFRAME & args, Function * pproc, int *numLoc)
|
||||
{
|
||||
int i; /* counter of # arguments */
|
||||
string condExp;
|
||||
//string condExp;
|
||||
ostringstream ostr;
|
||||
ostr<<tproc->name<<" (";
|
||||
for(const STKSYM &sym : args)
|
||||
@@ -585,6 +586,10 @@ string HLTYPE::write1HlIcode (Function * pProc, int *numLoc)
|
||||
ostr << p->writeOut(pProc,numLoc);
|
||||
ostr << "\n";
|
||||
break;
|
||||
case HLI_JCOND: //Handled elsewhere
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr," HLTYPE::write1HlIcode - Unhandled opcode %d\n",opcode);
|
||||
}
|
||||
return ostr.str();
|
||||
}
|
||||
|
||||
26
src/hltype.cpp
Normal file
26
src/hltype.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include "icode.h"
|
||||
#include "ast.h"
|
||||
|
||||
void HLTYPE::replaceExpr(COND_EXPR *e)
|
||||
{
|
||||
assert(e);
|
||||
delete exp.v;
|
||||
exp.v=e;
|
||||
}
|
||||
|
||||
|
||||
|
||||
HlTypeSupport *HLTYPE::get()
|
||||
{
|
||||
switch(opcode)
|
||||
{
|
||||
case HLI_ASSIGN: return &asgn;
|
||||
case HLI_RET:
|
||||
case HLI_POP:
|
||||
case HLI_JCOND:
|
||||
case HLI_PUSH: return &exp;
|
||||
case HLI_CALL: return &call;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -57,9 +57,9 @@ CIcodeRec::iterator CIcodeRec::labelSrch(uint32_t target)
|
||||
{
|
||||
return find_if(begin(),end(),[target](ICODE &l) -> bool {return l.ll()->label==target;});
|
||||
}
|
||||
ICODE * CIcodeRec::GetIcode(int ip)
|
||||
ICODE * CIcodeRec::GetIcode(size_t ip)
|
||||
{
|
||||
assert(ip>=0 && ip<size());
|
||||
assert(ip<size());
|
||||
iICODE res=begin();
|
||||
advance(res,ip);
|
||||
return &(*res);
|
||||
|
||||
@@ -207,7 +207,9 @@ bool Idiom19::match(iICODE picode)
|
||||
return true;
|
||||
}
|
||||
else /* indexed */
|
||||
/* not supported yet */ ;
|
||||
{
|
||||
/* not supported yet */
|
||||
}
|
||||
return false;
|
||||
}
|
||||
int Idiom19::action()
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "dcc.h"
|
||||
|
||||
/*****************************************************************************
|
||||
/* checkStkVars - Checks for PUSH SI
|
||||
* checkStkVars - Checks for PUSH SI
|
||||
* [PUSH DI]
|
||||
* or PUSH DI
|
||||
* [PUSH SI]
|
||||
@@ -115,7 +115,7 @@ bool Idiom1::match(iICODE picode)
|
||||
else // push di [push si] / push si [push di]
|
||||
{
|
||||
size_t n = checkStkVars (picode);
|
||||
for(int i=0; i<n; ++i)
|
||||
for(size_t i=0; i<n; ++i)
|
||||
m_icodes.push_back(picode++);
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ using namespace std;
|
||||
****************************************************************************/
|
||||
bool Idiom11::match (iICODE picode)
|
||||
{
|
||||
const char *matchstring="(oNEG rH) (oNEG rL) (SBB \rH i0)";
|
||||
//const char *matchstring="(oNEG rH) (oNEG rL) (SBB \rH i0)";
|
||||
condId type; /* type of argument */
|
||||
if(distance(picode,m_end)<3)
|
||||
return false;
|
||||
@@ -31,20 +31,22 @@ bool Idiom11::match (iICODE picode)
|
||||
return false;
|
||||
switch (type)
|
||||
{
|
||||
case GLOB_VAR:
|
||||
if ((m_icodes[2]->ll()->dst.segValue == m_icodes[0]->ll()->dst.segValue) &&
|
||||
(m_icodes[2]->ll()->dst.off == m_icodes[0]->ll()->dst.off))
|
||||
return true;
|
||||
break;
|
||||
case REGISTER:
|
||||
if (m_icodes[2]->ll()->dst.regi == m_icodes[0]->ll()->dst.regi)
|
||||
return true;
|
||||
break;
|
||||
case PARAM:
|
||||
case LOCAL_VAR:
|
||||
if (m_icodes[2]->ll()->dst.off == m_icodes[0]->ll()->dst.off)
|
||||
return true;
|
||||
break;
|
||||
case GLOB_VAR:
|
||||
if ((m_icodes[2]->ll()->dst.segValue == m_icodes[0]->ll()->dst.segValue) &&
|
||||
(m_icodes[2]->ll()->dst.off == m_icodes[0]->ll()->dst.off))
|
||||
return true;
|
||||
break;
|
||||
case REGISTER:
|
||||
if (m_icodes[2]->ll()->dst.regi == m_icodes[0]->ll()->dst.regi)
|
||||
return true;
|
||||
break;
|
||||
case PARAM:
|
||||
case LOCAL_VAR:
|
||||
if (m_icodes[2]->ll()->dst.off == m_icodes[0]->ll()->dst.off)
|
||||
return true;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"Idiom11::match unhandled type %d\n",type);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -73,7 +75,7 @@ int Idiom11::action()
|
||||
****************************************************************************/
|
||||
bool Idiom16::match (iICODE picode)
|
||||
{
|
||||
const char *matchstring="(oNEG rR) (oSBB rR rR) (oINC rR)";
|
||||
//const char *matchstring="(oNEG rR) (oSBB rR rR) (oINC rR)";
|
||||
if(distance(picode,m_end)<3)
|
||||
return false;
|
||||
for(int i=0; i<3; ++i)
|
||||
|
||||
@@ -12,7 +12,7 @@ bool LONGID_TYPE::srcDstRegMatch(iICODE a, iICODE b) const
|
||||
{
|
||||
return (a->ll()->src().getReg2()==l) and (b->ll()->dst.getReg2()==h);
|
||||
}
|
||||
|
||||
|
||||
|
||||
ID::ID() : type(TYPE_UNKNOWN),illegal(false),loc(STK_FRAME),hasMacro(false)
|
||||
{
|
||||
@@ -72,7 +72,6 @@ int LOCAL_ID::newByteWordReg(hlType t, eReg regi)
|
||||
* flagging this entry as illegal is all that can be done. */
|
||||
void LOCAL_ID::flagByteWordId (int off)
|
||||
{
|
||||
int idx;
|
||||
auto found=std::find_if(id_arr.begin(),id_arr.end(),[off](ID &en)->bool {
|
||||
//if (((en.type == TYPE_WORD_SIGN) || (en.type == TYPE_BYTE_SIGN)) &&
|
||||
if ((en.typeBitsize()<=16) &&
|
||||
@@ -121,12 +120,10 @@ int LOCAL_ID::newByteWordStk(hlType t, int off, uint8_t regOff)
|
||||
* regi: indexed register into global variable
|
||||
* ix: index into icode array
|
||||
* t: HIGH_LEVEL type */
|
||||
int LOCAL_ID::newIntIdx(int16_t seg, int16_t off, eReg regi, int ix, hlType t)
|
||||
int LOCAL_ID::newIntIdx(int16_t seg, int16_t off, eReg regi, hlType t)
|
||||
{
|
||||
int idx;
|
||||
|
||||
/* Check for entry in the table */
|
||||
for (idx = 0; idx < id_arr.size(); idx++)
|
||||
for (size_t idx = 0; idx < id_arr.size(); idx++)
|
||||
{
|
||||
if (/*(locSym->id[idx].type == t) && Not checking type */
|
||||
(id_arr[idx].id.bwGlb.seg == seg) &&
|
||||
@@ -137,11 +134,10 @@ int LOCAL_ID::newIntIdx(int16_t seg, int16_t off, eReg regi, int ix, hlType t)
|
||||
|
||||
/* Not in the table, create new identifier */
|
||||
newIdent (t, GLB_FRAME);
|
||||
idx = id_arr.size() - 1;
|
||||
id_arr[idx].id.bwGlb.seg = seg;
|
||||
id_arr[idx].id.bwGlb.off = off;
|
||||
id_arr[idx].id.bwGlb.regi = regi;
|
||||
return (idx);
|
||||
id_arr.back().id.bwGlb.seg = seg;
|
||||
id_arr.back().id.bwGlb.off = off;
|
||||
id_arr.back().id.bwGlb.regi = regi;
|
||||
return id_arr.size() - 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -279,7 +275,7 @@ int LOCAL_ID::newLong(opLoc sd, iICODE pIcode, hlFirst f, iICODE ix,operDu du, L
|
||||
{
|
||||
size_t idx;
|
||||
const LLOperand *pmH, *pmL;
|
||||
LLInst &p_ll(*pIcode->ll());
|
||||
LLInst &p_ll(*pIcode->ll());
|
||||
if (f == LOW_FIRST)
|
||||
{
|
||||
pmL = p_ll.get(sd);
|
||||
|
||||
147
src/parser.cpp
147
src/parser.cpp
@@ -2,7 +2,8 @@
|
||||
* dcc project procedure list builder
|
||||
* (C) Cristina Cifuentes, Mike van Emmerik, Jeff Ledermann
|
||||
****************************************************************************/
|
||||
|
||||
#define __STDC_FORMAT_MACROS
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h> /* For exit() */
|
||||
#include <sstream>
|
||||
@@ -12,9 +13,8 @@
|
||||
#include "dcc.h"
|
||||
#include "project.h"
|
||||
using namespace std;
|
||||
extern Project g_proj;
|
||||
|
||||
//static void FollowCtrl (Function * pProc, CALL_GRAPH * pcallGraph, STATE * pstate);
|
||||
static boolT process_JMP (ICODE * pIcode, STATE * pstate, CALL_GRAPH * pcallGraph);
|
||||
static void setBits(int16_t type, uint32_t start, uint32_t len);
|
||||
static void process_MOV(LLInst &ll, STATE * pstate);
|
||||
static SYM * lookupAddr (LLOperand *pm, STATE * pstate, int size, uint16_t duFlag);
|
||||
@@ -38,7 +38,7 @@ void DccFrontend::parse(Project &proj)
|
||||
SynthLab = SYNTHESIZED_MIN;
|
||||
|
||||
// default-construct a Function object !
|
||||
auto func = proj.createFunction();
|
||||
/*auto func = */proj.createFunction();
|
||||
|
||||
/* Check for special settings of initial state, based on idioms of the
|
||||
startup code */
|
||||
@@ -102,7 +102,7 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
|
||||
uint32_t offset;
|
||||
eErrorId err;
|
||||
bool done = false;
|
||||
SYMTAB &global_symbol_table(g_proj.symtab);
|
||||
SYMTAB &global_symbol_table(Project::get()->symtab);
|
||||
if (name.find("chkstk") != string::npos)
|
||||
{
|
||||
// Danger! Dcc will likely fall over in this code.
|
||||
@@ -115,7 +115,7 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
|
||||
}
|
||||
if (option.VeryVerbose)
|
||||
{
|
||||
printf("Parsing proc %s at %lX\n", name.c_str(), pstate->IP);
|
||||
printf("Parsing proc %s at %X\n", name.c_str(), pstate->IP);
|
||||
}
|
||||
|
||||
while (! done && ! (err = scan(pstate->IP, _Icode)))
|
||||
@@ -337,10 +337,12 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
|
||||
|
||||
case iSHL:
|
||||
if (pstate->JCond.regi == ll->dst.regi)
|
||||
{
|
||||
if ((ll->testFlags(I)) && ll->src().getImm2() == 1)
|
||||
pstate->JCond.immed *= 2;
|
||||
else
|
||||
pstate->JCond.regi = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case iLEA:
|
||||
@@ -404,7 +406,7 @@ bool Function::followAllTableEntries(JumpTable &table, uint32_t cs, ICODE& pIcod
|
||||
pIcode.ll()->caseTbl2.resize( table.size() );
|
||||
assert(pIcode.ll()->caseTbl2.size()<512);
|
||||
uint32_t k=0;
|
||||
for (int i = table.start; i < table.finish; i += 2)
|
||||
for (size_t i = table.start; i < table.finish; i += 2)
|
||||
{
|
||||
StCopy = *pstate;
|
||||
StCopy.IP = cs + LH(&prog.Image[i]);
|
||||
@@ -417,6 +419,7 @@ bool Function::followAllTableEntries(JumpTable &table, uint32_t cs, ICODE& pIcod
|
||||
last_current_insn->ll()->setFlags(CASE);
|
||||
pIcode.ll()->caseTbl2.push_back( last_current_insn->ll()->GetLlLabel() );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Function::process_JMP (ICODE & pIcode, STATE *pstate, CALL_GRAPH * pcallGraph)
|
||||
@@ -426,14 +429,14 @@ bool Function::process_JMP (ICODE & pIcode, STATE *pstate, CALL_GRAPH * pcallGra
|
||||
ICODE _Icode;
|
||||
uint32_t cs, offTable, endTable;
|
||||
uint32_t i, k, seg, target;
|
||||
uint32_t tmp;
|
||||
|
||||
if (pIcode.ll()->testFlags(I))
|
||||
{
|
||||
if (pIcode.ll()->getOpcode() == iJMPF)
|
||||
pstate->setState( rCS, LH(prog.Image + pIcode.ll()->label + 3));
|
||||
uint32_t i = pstate->IP = pIcode.ll()->src().getImm2();
|
||||
if ((long)i < 0)
|
||||
pstate->IP = pIcode.ll()->src().getImm2();
|
||||
int64_t i = pIcode.ll()->src().getImm2();
|
||||
if (i < 0)
|
||||
{
|
||||
exit(1);
|
||||
}
|
||||
@@ -501,8 +504,8 @@ bool Function::process_JMP (ICODE & pIcode, STATE *pstate, CALL_GRAPH * pcallGra
|
||||
{
|
||||
assert(((endTable - offTable) / 2)<512);
|
||||
STATE StCopy;
|
||||
int ip;
|
||||
uint32_t *psw;
|
||||
//int ip;
|
||||
//uint32_t *psw;
|
||||
|
||||
setBits(BM_DATA, offTable, endTable - offTable);
|
||||
|
||||
@@ -514,7 +517,7 @@ bool Function::process_JMP (ICODE & pIcode, STATE *pstate, CALL_GRAPH * pcallGra
|
||||
StCopy = *pstate;
|
||||
StCopy.IP = cs + LH(&prog.Image[i]);
|
||||
iICODE last_current_insn = (++Icode.rbegin()).base();
|
||||
ip = Icode.size();
|
||||
//ip = Icode.size();
|
||||
|
||||
FollowCtrl (pcallGraph, &StCopy);
|
||||
++last_current_insn;
|
||||
@@ -600,9 +603,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;
|
||||
@@ -612,12 +615,12 @@ boolT Function::process_CALL (ICODE & pIcode, CALL_GRAPH * pcallGraph, STATE *ps
|
||||
if (pIcode.ll()->testFlags(I))
|
||||
{
|
||||
/* Search procedure list for one with appropriate entry point */
|
||||
ilFunction iter = g_proj.findByEntry(pIcode.ll()->src().getImm2());
|
||||
ilFunction iter = Project::get()->findByEntry(pIcode.ll()->src().getImm2());
|
||||
|
||||
/* Create a new procedure node and save copy of the state */
|
||||
if ( not g_proj.valid(iter) )
|
||||
if ( not Project::get()->valid(iter) )
|
||||
{
|
||||
iter = g_proj.createFunction();
|
||||
iter = Project::get()->createFunction();
|
||||
Function &x(*iter);
|
||||
x.procEntry = pIcode.ll()->src().getImm2();
|
||||
LibCheck(x);
|
||||
@@ -665,7 +668,7 @@ boolT Function::process_CALL (ICODE & pIcode, CALL_GRAPH * pcallGraph, STATE *ps
|
||||
|
||||
}
|
||||
else
|
||||
g_proj.callGraph->insertCallGraph (this, iter);
|
||||
Project::get()->callGraph->insertCallGraph (this, iter);
|
||||
|
||||
last_insn.ll()->src().proc.proc = &(*iter); // ^ target proc
|
||||
|
||||
@@ -707,6 +710,7 @@ static void process_MOV(LLInst & ll, STATE * pstate)
|
||||
size=1;
|
||||
psym = lookupAddr (&ll.dst, pstate, size, eDEF);
|
||||
if (psym && ! (psym->duVal.val)) /* no initial value yet */
|
||||
{
|
||||
if (ll.testFlags(I)) /* immediate */
|
||||
{
|
||||
prog.Image[psym->label] = (uint8_t)ll.src().getImm2();
|
||||
@@ -733,6 +737,7 @@ static void process_MOV(LLInst & ll, STATE * pstate)
|
||||
prog.Image[psym->label+1] = (uint8_t)(pstate->r[srcReg] >> 8);
|
||||
psym->duVal.setFlags(eDuVal::DEF);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -742,8 +747,6 @@ static void process_MOV(LLInst & ll, STATE * pstate)
|
||||
* and returns a pointer to such entry. */
|
||||
void STKFRAME::updateFrameOff ( int16_t off, int _size, uint16_t duFlag)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Check for symbol in stack frame table */
|
||||
auto iter=findByLabel(off);
|
||||
if(iter!=end())
|
||||
@@ -751,14 +754,14 @@ void STKFRAME::updateFrameOff ( int16_t off, int _size, uint16_t duFlag)
|
||||
if (iter->size < _size)
|
||||
{
|
||||
iter->size = _size;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
char nm[16];
|
||||
STKSYM new_sym;
|
||||
|
||||
sprintf (nm, "arg%ld", size());
|
||||
sprintf (nm, "arg%" PRIu64, uint64_t(size()));
|
||||
new_sym.name = nm;
|
||||
new_sym.label= off;
|
||||
new_sym.size = _size;
|
||||
@@ -800,13 +803,13 @@ static SYM * lookupAddr (LLOperand *pm, STATE *pstate, int size, uint16_t duFlag
|
||||
if (pm->segValue) /* there is a value in the seg field */
|
||||
{
|
||||
operand = opAdr (pm->segValue, pm->off);
|
||||
psym = g_proj.symtab.updateGlobSym (operand, size, duFlag,created_new);
|
||||
psym = Project::get()->symtab.updateGlobSym (operand, size, duFlag,created_new);
|
||||
}
|
||||
else if (pstate->f[pm->seg]) /* new value */
|
||||
{
|
||||
pm->segValue = pstate->r[pm->seg];
|
||||
operand = opAdr(pm->segValue, pm->off);
|
||||
psym = g_proj.symtab.updateGlobSym (operand, size, duFlag,created_new);
|
||||
psym = Project::get()->symtab.updateGlobSym (operand, size, duFlag,created_new);
|
||||
|
||||
/* Flag new memory locations that are segment values */
|
||||
if (created_new)
|
||||
@@ -821,7 +824,7 @@ static SYM * lookupAddr (LLOperand *pm, STATE *pstate, int size, uint16_t duFlag
|
||||
}
|
||||
}
|
||||
/* Check for out of bounds */
|
||||
if (psym && (psym->label>=0) and (psym->label < (uint32_t)prog.cbImage))
|
||||
if (psym and (psym->label < (uint32_t)prog.cbImage))
|
||||
return psym;
|
||||
return nullptr;
|
||||
}
|
||||
@@ -903,7 +906,7 @@ std::bitset<32> duReg[] = { 0x00,
|
||||
* pstate: ptr to current procedure state
|
||||
* size : size of the operand
|
||||
* ix : current index into icode array */
|
||||
static void use (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int size, int ix)
|
||||
static void use (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int size)
|
||||
{
|
||||
const LLOperand * pm = pIcode.ll()->get(d) ;
|
||||
SYM * psym;
|
||||
@@ -927,17 +930,21 @@ static void use (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int
|
||||
if ((pm->seg == rDS) && (pm->regi == INDEX_BX)) /* bx */
|
||||
{
|
||||
if (pm->off > 0) /* global indexed variable */
|
||||
pProc->localId.newIntIdx(pm->segValue, pm->off, rBX,ix, TYPE_WORD_SIGN);
|
||||
pProc->localId.newIntIdx(pm->segValue, pm->off, rBX,TYPE_WORD_SIGN);
|
||||
}
|
||||
pIcode.du.use |= duReg[pm->regi];
|
||||
}
|
||||
|
||||
else if (psym = lookupAddr(const_cast<LLOperand *>(pm), pstate, size, eDuVal::USE))
|
||||
else
|
||||
{
|
||||
setBits (BM_DATA, psym->label, (uint32_t)size);
|
||||
pIcode.ll()->setFlags(SYM_USE);
|
||||
pIcode.ll()->caseEntry = distance(&g_proj.symtab[0],psym); //WARNING: was setting case count
|
||||
psym = lookupAddr(const_cast<LLOperand *>(pm), pstate, size, eDuVal::USE);
|
||||
if( nullptr != psym )
|
||||
{
|
||||
setBits (BM_DATA, psym->label, (uint32_t)size);
|
||||
pIcode.ll()->setFlags(SYM_USE);
|
||||
pIcode.ll()->caseEntry = distance(&Project::get()->symtab[0],psym); //WARNING: was setting case count
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -950,13 +957,21 @@ static void use (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int
|
||||
/* Checks which registers were defined (ie. got a new value) and updates the
|
||||
* du.d flag.
|
||||
* Places local variables in the local symbol table. */
|
||||
static void def (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int size,
|
||||
int ix)
|
||||
static void def (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int size)
|
||||
{
|
||||
LLOperand *pm = pIcode.ll()->get(d);
|
||||
SYM * psym;
|
||||
|
||||
if (pm->regi == 0 || pm->regi >= INDEX_BX_SI)
|
||||
if (pm->regi==0)
|
||||
{
|
||||
SYM * psym;
|
||||
psym = lookupAddr(pm, pstate, size, eDEF);
|
||||
if (nullptr!=psym)
|
||||
{
|
||||
setBits(BM_DATA, psym->label, (uint32_t)size);
|
||||
pIcode.ll()->setFlags(SYM_DEF);
|
||||
pIcode.ll()->caseEntry = distance(&Project::get()->symtab[0],psym); // WARNING: was setting Case count
|
||||
}
|
||||
}
|
||||
else if (pm->regi >= INDEX_BX_SI)
|
||||
{
|
||||
if (pm->regi == INDEX_BP) /* indexed on bp */
|
||||
{
|
||||
@@ -977,19 +992,11 @@ static void def (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int
|
||||
if ((pm->seg == rDS) && (pm->regi == INDEX_BX)) /* bx */
|
||||
{
|
||||
if (pm->off > 0) /* global var */
|
||||
pProc->localId.newIntIdx(pm->segValue, pm->off, rBX,ix, TYPE_WORD_SIGN);
|
||||
pProc->localId.newIntIdx(pm->segValue, pm->off, rBX,TYPE_WORD_SIGN);
|
||||
}
|
||||
pIcode.du.use |= duReg[pm->regi];
|
||||
}
|
||||
|
||||
else if (psym = lookupAddr(pm, pstate, size, eDEF))
|
||||
{
|
||||
setBits(BM_DATA, psym->label, (uint32_t)size);
|
||||
pIcode.ll()->setFlags(SYM_DEF);
|
||||
pIcode.ll()->caseEntry = distance(&g_proj.symtab[0],psym); // WARNING: was setting Case count
|
||||
}
|
||||
}
|
||||
|
||||
/* Definition of register */
|
||||
else if ((d == DST) || ((d == SRC) && (not pIcode.ll()->testFlags(I))))
|
||||
{
|
||||
@@ -1002,12 +1009,11 @@ static void def (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int
|
||||
/* use_def - operand is both use and def'd.
|
||||
* Note: the destination will always be a register, stack variable, or global
|
||||
* variable. */
|
||||
static void use_def(opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int cb,
|
||||
int ix)
|
||||
static void use_def(opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int cb)
|
||||
{
|
||||
const LLOperand * pm = pIcode.ll()->get(d);
|
||||
|
||||
use (d, pIcode, pProc, pstate, cb, ix);
|
||||
use (d, pIcode, pProc, pstate, cb);
|
||||
|
||||
if (pm->regi < INDEX_BX_SI) /* register */
|
||||
{
|
||||
@@ -1022,7 +1028,6 @@ static void use_def(opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, i
|
||||
extern LLOperand convertOperand(const x86_op_t &from);
|
||||
void Function::process_operands(ICODE & pIcode, STATE * pstate)
|
||||
{
|
||||
int ix=Icode.size();
|
||||
LLInst &ll_ins(*pIcode.ll());
|
||||
|
||||
int sseg = (ll_ins.src().seg)? ll_ins.src().seg: rDS;
|
||||
@@ -1036,39 +1041,39 @@ void Function::process_operands(ICODE & pIcode, STATE * pstate)
|
||||
case iRCL: case iRCR: case iROL: case iROR:
|
||||
case iADD: case iADC: case iSUB: case iSBB:
|
||||
if (! Imm) {
|
||||
use(SRC, pIcode, this, pstate, cb, ix);
|
||||
use(SRC, pIcode, this, pstate, cb);
|
||||
}
|
||||
case iINC: case iDEC: case iNEG: case iNOT:
|
||||
case iAAA: case iAAD: case iAAM: case iAAS:
|
||||
case iDAA: case iDAS:
|
||||
use_def(DST, pIcode, this, pstate, cb, ix);
|
||||
use_def(DST, pIcode, this, pstate, cb);
|
||||
break;
|
||||
|
||||
case iXCHG:
|
||||
/* This instruction is replaced by 3 instructions, only need
|
||||
* to define the src operand and use the destination operand
|
||||
* in the mean time. */
|
||||
use(SRC, pIcode, this, pstate, cb, ix);
|
||||
def(DST, pIcode, this, pstate, cb, ix);
|
||||
use(SRC, pIcode, this, pstate, cb);
|
||||
def(DST, pIcode, this, pstate, cb);
|
||||
break;
|
||||
|
||||
case iTEST: case iCMP:
|
||||
if (! Imm)
|
||||
use(SRC, pIcode, this, pstate, cb, ix);
|
||||
use(DST, pIcode, this, pstate, cb, ix);
|
||||
use(SRC, pIcode, this, pstate, cb);
|
||||
use(DST, pIcode, this, pstate, cb);
|
||||
break;
|
||||
|
||||
case iDIV: case iIDIV:
|
||||
use(SRC, pIcode, this, pstate, cb, ix);
|
||||
use(SRC, pIcode, this, pstate, cb);
|
||||
if (cb == 1)
|
||||
pIcode.du.use |= duReg[rTMP];
|
||||
break;
|
||||
|
||||
case iMUL: case iIMUL:
|
||||
use(SRC, pIcode, this, pstate, cb, ix);
|
||||
use(SRC, pIcode, this, pstate, cb);
|
||||
if (! Imm)
|
||||
{
|
||||
use (DST, pIcode, this, pstate, cb, ix);
|
||||
use (DST, pIcode, this, pstate, cb);
|
||||
if (cb == 1)
|
||||
{
|
||||
pIcode.du.def |= duReg[rAX];
|
||||
@@ -1081,7 +1086,7 @@ void Function::process_operands(ICODE & pIcode, STATE * pstate)
|
||||
}
|
||||
}
|
||||
else
|
||||
def (DST, pIcode, this, pstate, cb, ix);
|
||||
def (DST, pIcode, this, pstate, cb);
|
||||
break;
|
||||
|
||||
case iSIGNEX:
|
||||
@@ -1105,14 +1110,14 @@ void Function::process_operands(ICODE & pIcode, STATE * pstate)
|
||||
case iCALL: case iPUSH: case iPOP:
|
||||
if (! Imm) {
|
||||
if (pIcode.ll()->getOpcode() == iPOP)
|
||||
def(DST, pIcode, this, pstate, cb, ix);
|
||||
def(DST, pIcode, this, pstate, cb);
|
||||
else
|
||||
use(DST, pIcode, this, pstate, cb, ix);
|
||||
use(DST, pIcode, this, pstate, cb);
|
||||
}
|
||||
break;
|
||||
|
||||
case iESC: /* operands may be larger */
|
||||
use(DST, pIcode, this, pstate, cb, ix);
|
||||
use(DST, pIcode, this, pstate, cb);
|
||||
break;
|
||||
|
||||
case iLDS: case iLES:
|
||||
@@ -1120,25 +1125,25 @@ void Function::process_operands(ICODE & pIcode, STATE * pstate)
|
||||
pIcode.du1.numRegsDef++;
|
||||
cb = 4;
|
||||
case iMOV:
|
||||
use(SRC, pIcode, this, pstate, cb, ix);
|
||||
def(DST, pIcode, this, pstate, cb, ix);
|
||||
use(SRC, pIcode, this, pstate, cb);
|
||||
def(DST, pIcode, this, pstate, cb);
|
||||
break;
|
||||
|
||||
case iLEA:
|
||||
use(SRC, pIcode, this, pstate, 2, ix);
|
||||
def(DST, pIcode, this, pstate, 2, ix);
|
||||
use(SRC, pIcode, this, pstate, 2);
|
||||
def(DST, pIcode, this, pstate, 2);
|
||||
break;
|
||||
|
||||
case iBOUND:
|
||||
use(SRC, pIcode, this, pstate, 4, ix);
|
||||
use(DST, pIcode, this, pstate, cb, ix);
|
||||
use(SRC, pIcode, this, pstate, 4);
|
||||
use(DST, pIcode, this, pstate, cb);
|
||||
break;
|
||||
|
||||
case iJMPF:
|
||||
cb = 4;
|
||||
case iJMP:
|
||||
if (! Imm)
|
||||
use(SRC, pIcode, this, pstate, cb, ix);
|
||||
use(SRC, pIcode, this, pstate, cb);
|
||||
break;
|
||||
|
||||
case iLOOP: case iLOOPE: case iLOOPNE:
|
||||
@@ -1194,7 +1199,7 @@ void Function::process_operands(ICODE & pIcode, STATE * pstate)
|
||||
break;
|
||||
|
||||
case iIN: case iOUT:
|
||||
def(DST, pIcode, this, pstate, cb, ix);
|
||||
def(DST, pIcode, this, pstate, cb);
|
||||
if (! Imm)
|
||||
{
|
||||
pIcode.du.use |= duReg[rDX];
|
||||
|
||||
@@ -14,14 +14,14 @@
|
||||
static uint16_t *T1, *T2; /* Pointers to T1[i], T2[i] */
|
||||
static short *g; /* g[] */
|
||||
|
||||
static int numEdges; /* An edge counter */
|
||||
//static int numEdges; /* An edge counter */
|
||||
//static bool *visited; /* Array of bools: whether visited */
|
||||
|
||||
/* Private prototypes */
|
||||
static void initGraph(void);
|
||||
static void addToGraph(int e, int v1, int v2);
|
||||
static bool isCycle(void);
|
||||
static void duplicateKeys(int v1, int v2);
|
||||
//static void initGraph(void);
|
||||
//static void addToGraph(int e, int v1, int v2);
|
||||
//static bool isCycle(void);
|
||||
//static void duplicateKeys(int v1, int v2);
|
||||
PatternHasher g_pattern_hasher;
|
||||
|
||||
void
|
||||
|
||||
@@ -43,8 +43,6 @@ void CALL_GRAPH::insertArc (ilFunction newProc)
|
||||
/* Inserts a (caller, callee) arc in the call graph tree. */
|
||||
bool CALL_GRAPH::insertCallGraph(ilFunction caller, ilFunction callee)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (proc == caller)
|
||||
{
|
||||
insertArc (callee);
|
||||
@@ -52,8 +50,8 @@ bool CALL_GRAPH::insertCallGraph(ilFunction caller, ilFunction callee)
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < outEdges.size(); i++)
|
||||
if (outEdges[i]->insertCallGraph (caller, callee))
|
||||
for (CALL_GRAPH *edg : outEdges)
|
||||
if (edg->insertCallGraph (caller, callee))
|
||||
return true;
|
||||
return (false);
|
||||
}
|
||||
@@ -61,7 +59,7 @@ bool CALL_GRAPH::insertCallGraph(ilFunction caller, ilFunction callee)
|
||||
|
||||
bool CALL_GRAPH::insertCallGraph(Function *caller, ilFunction callee)
|
||||
{
|
||||
return insertCallGraph(g_proj.funcIter(caller),callee);
|
||||
return insertCallGraph(Project::get()->funcIter(caller),callee);
|
||||
}
|
||||
|
||||
|
||||
@@ -69,11 +67,9 @@ bool CALL_GRAPH::insertCallGraph(Function *caller, ilFunction callee)
|
||||
* the nodes the procedure invokes. */
|
||||
void CALL_GRAPH::writeNodeCallGraph(int indIdx)
|
||||
{
|
||||
int i;
|
||||
|
||||
printf ("%s%s\n", indentStr(indIdx), proc->name.c_str());
|
||||
for (i = 0; i < outEdges.size(); i++)
|
||||
outEdges[i]->writeNodeCallGraph (indIdx + 1);
|
||||
for (CALL_GRAPH *cg : outEdges)
|
||||
cg->writeNodeCallGraph (indIdx + 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -205,6 +201,8 @@ void LOCAL_ID::newRegArg(iICODE picode, iICODE ticode) const
|
||||
picode->du.def &= maskDuReg[id->id.longId.l];
|
||||
newsym.type = TYPE_LONG_SIGN;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"LOCAL_ID::newRegArg unhandled type %d in masking low\n",type);
|
||||
}
|
||||
call_args_stackframe->push_back(newsym);
|
||||
call_args_stackframe->numArgs++;
|
||||
@@ -228,10 +226,12 @@ bool CallType::newStkArg(COND_EXPR *exp, llIcode opcode, Function * pproc)
|
||||
{
|
||||
regi = pproc->localId.id_arr[exp->expr.ident.idNode.regiIdx].id.regi;
|
||||
if ((regi >= rES) && (regi <= rDS))
|
||||
{
|
||||
if (opcode == iCALLF)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -308,8 +308,12 @@ void adjustActArgType (COND_EXPR *exp, hlType forType, Function * pproc)
|
||||
case TYPE_WORD_SIGN:
|
||||
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"adjustForArgType unhandled actType_ %d \n",actType);
|
||||
} /* eos */
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"adjustForArgType unhandled forType %d \n",forType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -317,11 +321,11 @@ void adjustActArgType (COND_EXPR *exp, hlType forType, Function * pproc)
|
||||
/* Determines whether the formal argument has the same type as the given
|
||||
* type (type of the actual argument). If not, the formal argument is
|
||||
* changed its type */
|
||||
void STKFRAME::adjustForArgType(int numArg_, hlType actType_)
|
||||
void STKFRAME::adjustForArgType(size_t numArg_, hlType actType_)
|
||||
{
|
||||
hlType forType;
|
||||
STKSYM * psym, * nsym;
|
||||
int off, i;
|
||||
int off;
|
||||
/* If formal argument does not exist, do not create new ones, just
|
||||
* ignore actual argument
|
||||
*/
|
||||
@@ -330,7 +334,7 @@ void STKFRAME::adjustForArgType(int numArg_, hlType actType_)
|
||||
|
||||
/* Find stack offset for this argument */
|
||||
off = m_minOff;
|
||||
i=0;
|
||||
size_t i=0;
|
||||
for(STKSYM &s : *this) // walk formal arguments upto numArg_
|
||||
{
|
||||
if(i>=numArg_)
|
||||
@@ -343,7 +347,7 @@ void STKFRAME::adjustForArgType(int numArg_, hlType actType_)
|
||||
//psym = &at(numArg_);
|
||||
//i = numArg_;
|
||||
//auto iter=std::find_if(sym.begin(),sym.end(),[off](STKSYM &s)->bool {s.off==off;});
|
||||
auto iter=std::find_if(begin()+numArg_,end(),[off](STKSYM &s)->bool {s.label==off;});
|
||||
auto iter=std::find_if(begin()+numArg_,end(),[off](STKSYM &s)->bool {return s.label==off;});
|
||||
if(iter==end()) // symbol not found
|
||||
return;
|
||||
psym = &(*iter);
|
||||
@@ -380,6 +384,8 @@ void STKFRAME::adjustForArgType(int numArg_, hlType actType_)
|
||||
case TYPE_CONST:
|
||||
case TYPE_STR:
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"STKFRAME::adjustForArgType unhandled actType_ %d \n",actType_);
|
||||
} /* eos */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,38 @@
|
||||
#include <utility>
|
||||
#include "dcc.h"
|
||||
#include "project.h"
|
||||
#include "Procedure.h"
|
||||
Project g_proj;
|
||||
using namespace std;
|
||||
//Project g_proj;
|
||||
char *asm1_name, *asm2_name; /* Assembler output filenames */
|
||||
SYMTAB symtab; /* Global symbol table */
|
||||
STATS stats; /* cfg statistics */
|
||||
//PROG prog; /* programs fields */
|
||||
OPTION option; /* Command line options */
|
||||
Project *Project::s_instance = 0;
|
||||
Project::Project() : callGraph(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
void Project::initialize()
|
||||
{
|
||||
delete callGraph;
|
||||
callGraph = nullptr;
|
||||
}
|
||||
void Project::create(const string &a)
|
||||
{
|
||||
m_fname=a;
|
||||
string::size_type ext_loc=a.find_last_of('.');
|
||||
string::size_type slash_loc=a.find_last_of('/',ext_loc);
|
||||
if(slash_loc==string::npos)
|
||||
slash_loc=0;
|
||||
else
|
||||
slash_loc++;
|
||||
if(ext_loc!=string::npos)
|
||||
m_project_name = a.substr(slash_loc,(ext_loc-slash_loc));
|
||||
else
|
||||
m_project_name = a.substr(slash_loc);
|
||||
}
|
||||
bool Project::valid(ilFunction iter)
|
||||
{
|
||||
return iter!=pProcList.end();
|
||||
@@ -63,7 +94,10 @@ const std::string &Project::symbolName(size_t idx)
|
||||
}
|
||||
Project *Project::get()
|
||||
{
|
||||
return &g_proj;
|
||||
//WARNING: poor man's singleton, not thread safe
|
||||
if(s_instance==0)
|
||||
s_instance=new Project;
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
|
||||
@@ -71,3 +105,4 @@ SourceMachine *Project::machine()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -236,7 +236,7 @@ void Function::propLongStk (int i, const ID &pLocId)
|
||||
iICODE l23;
|
||||
/* Check all icodes for offHi:offLo */
|
||||
pEnd = Icode.end();
|
||||
int stat_size=Icode.size();
|
||||
size_t stat_size=Icode.size();
|
||||
// for (idx = 0; idx < (Icode.size() - 1); idx++)
|
||||
for(auto pIcode = Icode.begin(); ;++pIcode)
|
||||
{
|
||||
@@ -459,7 +459,7 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be
|
||||
{
|
||||
if (checkLongRegEq (pLocId.id.longId, pIcode, loc_ident_idx, this, asgn, *long_loc->ll()))
|
||||
{
|
||||
// reduce the advance by 1 here (loop increases) ?
|
||||
// reduce the advance by 1 here (loop increases) ?
|
||||
advance(pIcode,longJCond23 (asgn, pIcode, arc, long_loc));
|
||||
}
|
||||
}
|
||||
@@ -476,9 +476,9 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be
|
||||
}
|
||||
|
||||
/* Check for OR regH, regL
|
||||
* JX lab
|
||||
* => HLI_JCOND (regH:regL X 0) lab
|
||||
* This is better code than HLI_JCOND (HI(regH:regL) | LO(regH:regL)) */
|
||||
* JX lab
|
||||
* => HLI_JCOND (regH:regL X 0) lab
|
||||
* This is better code than HLI_JCOND (HI(regH:regL) | LO(regH:regL)) */
|
||||
else if (pIcode->ll()->match(iOR) && (next1 != pEnd) && (isJCond ((llIcode)next1->ll()->getOpcode())))
|
||||
{
|
||||
if (pLocId.id.longId.srcDstRegMatch(pIcode,pIcode))
|
||||
@@ -492,6 +492,7 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be
|
||||
}
|
||||
}
|
||||
} /* end for */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Finds the definition of the long register pointed to by pLocId, and
|
||||
@@ -504,8 +505,8 @@ void Function::propLongReg (int loc_ident_idx, const ID &pLocId)
|
||||
{
|
||||
/* Process all definitions/uses of long registers at an icode position */
|
||||
// WARNING: this loop modifies the iterated-over container.
|
||||
size_t initial_size=pLocId.idx.size();
|
||||
for (int j = 0; j < pLocId.idx.size(); j++)
|
||||
//size_t initial_size=pLocId.idx.size();
|
||||
for (size_t j = 0; j < pLocId.idx.size(); j++)
|
||||
{
|
||||
auto idx_iter=pLocId.idx.begin();
|
||||
std::advance(idx_iter,j);
|
||||
@@ -524,7 +525,7 @@ void Function::propLongReg (int loc_ident_idx, const ID &pLocId)
|
||||
|
||||
/* Propagates the long global address across all LOW_LEVEL icodes.
|
||||
* Transforms some LOW_LEVEL icodes into HIGH_LEVEL */
|
||||
void Function::propLongGlb (int i, const ID &pLocId)
|
||||
void Function::propLongGlb (int /*i*/, const ID &/*pLocId*/)
|
||||
{
|
||||
printf("WARN: Function::propLongGlb not implemented");
|
||||
}
|
||||
@@ -534,10 +535,9 @@ void Function::propLongGlb (int i, const ID &pLocId)
|
||||
* into HIGH_LEVEL icodes. */
|
||||
void Function::propLong()
|
||||
{
|
||||
int i;
|
||||
/* Pointer to current local identifier */
|
||||
|
||||
for (i = 0; i < localId.csym(); i++)
|
||||
//TODO: change into range based for
|
||||
for (size_t i = 0; i < localId.csym(); i++)
|
||||
{
|
||||
const ID &pLocId(localId.id_arr[i]);
|
||||
if ((pLocId.type==TYPE_LONG_SIGN) || (pLocId.type==TYPE_LONG_UNSIGN))
|
||||
|
||||
@@ -103,7 +103,7 @@ void derSeq_Entry::findIntervals (Function *c)
|
||||
BB *h, /* Node being processed */
|
||||
*header, /* Current interval's header node */
|
||||
*succ; /* Successor basic block */
|
||||
int i; /* Counter */
|
||||
//int i; /* Counter */
|
||||
queue H; /* Queue of possible header nodes */
|
||||
boolT first = true; /* First pass through the loop */
|
||||
|
||||
@@ -125,7 +125,7 @@ void derSeq_Entry::findIntervals (Function *c)
|
||||
while ((h = pI->firstOfInt()) != NULL)
|
||||
{
|
||||
/* Check all immediate successors of h */
|
||||
for (i = 0; i < h->edges.size(); i++)
|
||||
for (size_t i = 0; i < h->edges.size(); i++)
|
||||
{
|
||||
succ = h->edges[i].BBptr;
|
||||
succ->inEdgeCount--;
|
||||
@@ -176,11 +176,11 @@ static void displayIntervals (interval *pI)
|
||||
|
||||
while (pI)
|
||||
{
|
||||
printf (" Interval #: %ld\t#OutEdges: %ld\n", pI->numInt, pI->numOutEdges);
|
||||
printf (" Interval #: %d\t#OutEdges: %d\n", pI->numInt, pI->numOutEdges);
|
||||
for(BB *node : pI->nodes)
|
||||
{
|
||||
if (node->correspInt == NULL) /* real BBs */
|
||||
printf (" Node: %ld\n", node->begin()->loc_ip);
|
||||
printf (" Node: %d\n", node->begin()->loc_ip);
|
||||
else // BBs represent intervals
|
||||
printf (" Node (corresp int): %d\n", node->correspInt->numInt);
|
||||
}
|
||||
@@ -190,17 +190,17 @@ static void displayIntervals (interval *pI)
|
||||
|
||||
|
||||
/* Allocates space for a new derSeq node. */
|
||||
static derSeq_Entry *newDerivedSeq()
|
||||
{
|
||||
return new derSeq_Entry;
|
||||
}
|
||||
//static derSeq_Entry *newDerivedSeq()
|
||||
//{
|
||||
// return new derSeq_Entry;
|
||||
//}
|
||||
|
||||
|
||||
/* Frees the storage allocated for the queue q*/
|
||||
static void freeQueue (queue &q)
|
||||
{
|
||||
q.clear();
|
||||
}
|
||||
//static void freeQueue (queue &q)
|
||||
//{
|
||||
// q.clear();
|
||||
//}
|
||||
|
||||
|
||||
/* Frees the storage allocated for the interval pI */
|
||||
@@ -237,12 +237,12 @@ bool Function::nextOrderGraph (derSeq &derivedGi)
|
||||
{
|
||||
interval *Ii; /* Interval being processed */
|
||||
BB *BBnode, /* New basic block of intervals */
|
||||
*curr, /* BB being checked for out edges */
|
||||
//*curr, /* BB being checked for out edges */
|
||||
*succ /* Successor node */
|
||||
;
|
||||
//queue *listIi; /* List of intervals */
|
||||
int i, /* Index to outEdges array */
|
||||
j; /* Index to successors */
|
||||
int i; /* Index to outEdges array */
|
||||
/*j;*/ /* Index to successors */
|
||||
boolT sameGraph; /* Boolean, isomorphic graphs */
|
||||
|
||||
/* Process Gi's intervals */
|
||||
@@ -271,7 +271,7 @@ bool Function::nextOrderGraph (derSeq &derivedGi)
|
||||
{
|
||||
for(BB *curr : listIi)
|
||||
{
|
||||
for (j = 0; j < curr->edges.size(); j++)
|
||||
for (size_t j = 0; j < curr->edges.size(); j++)
|
||||
{
|
||||
succ = curr->edges[j].BBptr;
|
||||
if (succ->inInterval != curr->inInterval)
|
||||
@@ -287,7 +287,8 @@ bool Function::nextOrderGraph (derSeq &derivedGi)
|
||||
/* Convert list of pointers to intervals into a real graph.
|
||||
* Determines the number of in edges to each new BB, and places it
|
||||
* in numInEdges and inEdgeCount for later interval processing. */
|
||||
curr = new_entry.Gi = bbs.front();
|
||||
//curr = new_entry.Gi = bbs.front();
|
||||
new_entry.Gi = bbs.front();
|
||||
for(BB *curr : bbs)
|
||||
{
|
||||
for(TYPEADR_TYPE &edge : curr->edges)
|
||||
@@ -315,6 +316,7 @@ uint8_t Function::findDerivedSeq (derSeq &derivedGi)
|
||||
BB *Gi; /* Current derived sequence graph */
|
||||
|
||||
derSeq::iterator iter=derivedGi.begin();
|
||||
assert(iter!=derivedGi.end());
|
||||
Gi = iter->Gi;
|
||||
while (! trivialGraph (Gi))
|
||||
{
|
||||
@@ -343,7 +345,7 @@ uint8_t Function::findDerivedSeq (derSeq &derivedGi)
|
||||
|
||||
/* Converts the irreducible graph G into an equivalent reducible one, by
|
||||
* means of node splitting. */
|
||||
static void nodeSplitting (std::list<BB *> &G)
|
||||
static void nodeSplitting (std::list<BB *> &/*G*/)
|
||||
{
|
||||
fprintf(stderr,"Attempt to perform node splitting: NOT IMPLEMENTED\n");
|
||||
}
|
||||
@@ -356,7 +358,7 @@ void derSeq::display()
|
||||
derSeq::iterator iter=this->begin();
|
||||
while (iter!=this->end())
|
||||
{
|
||||
printf ("\nIntervals for G%lX\n", n++);
|
||||
printf ("\nIntervals for G%X\n", n++);
|
||||
displayIntervals (iter->Ii);
|
||||
++iter;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#define S_EXT 0x000200 /* sign extend */
|
||||
#define OP386 0x000400 /* 386 op-code */
|
||||
#define NSP 0x000800 /* NOT_HLL if SP is src or dst */
|
||||
#define ICODEMASK 0xFF00FF /* Masks off parser flags */
|
||||
// defined in Enums.h #define ICODEMASK 0xFF00FF /* Masks off parser flags */
|
||||
|
||||
static void rm(int i);
|
||||
static void modrm(int i);
|
||||
@@ -408,7 +408,12 @@ LLOperand convertOperand(const x86_op_t &from)
|
||||
break;
|
||||
case op_register:
|
||||
return LLOperand::CreateReg2(convertRegister(from.data.reg));
|
||||
case op_immediate:
|
||||
return LLOperand::CreateImm2(from.data.sdword);
|
||||
default:
|
||||
fprintf(stderr,"convertOperand does not know how to convert %d\n",from.type);
|
||||
}
|
||||
return LLOperand::CreateImm2(0);
|
||||
}
|
||||
eErrorId scan(uint32_t ip, ICODE &p)
|
||||
{
|
||||
|
||||
@@ -133,7 +133,7 @@ void destroySymTables(void)
|
||||
}
|
||||
|
||||
/* Using the value, read the symbolic name */
|
||||
boolT readVal(std::ostringstream &symName, uint32_t symOff, Function * symProc)
|
||||
boolT readVal(std::ostringstream &/*symName*/, uint32_t /*symOff*/, Function * /*symProc*/)
|
||||
{
|
||||
return false; // no symbolic names for now
|
||||
}
|
||||
@@ -142,7 +142,6 @@ boolT readVal(std::ostringstream &symName, uint32_t symOff, Function * symProc)
|
||||
* if necessary (0 means no update necessary). */
|
||||
void SYMTAB::updateSymType (uint32_t symbol,const TypeContainer &tc)
|
||||
{
|
||||
int i;
|
||||
auto iter=findByLabel(symbol);
|
||||
if(iter==end())
|
||||
return;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "dcc.h"
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include "dcc.h"
|
||||
|
||||
TEST(CowriteTest, HandlesZeroInput) {
|
||||
EXPECT_EQ(1, 1);
|
||||
|
||||
14
src/tests/loader.cpp
Normal file
14
src/tests/loader.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include "project.h"
|
||||
#include "loader.h"
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(Loader, NewProjectIsInitalized) {
|
||||
Project p;
|
||||
EXPECT_EQ(nullptr,p.callGraph);
|
||||
ASSERT_TRUE(p.pProcList.empty());
|
||||
ASSERT_TRUE(p.binary_path().empty());
|
||||
ASSERT_TRUE(p.project_name().empty());
|
||||
ASSERT_TRUE(p.symtab.empty());
|
||||
}
|
||||
|
||||
27
src/tests/project.cpp
Normal file
27
src/tests/project.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "project.h"
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(Project, NewProjectIsInitalized) {
|
||||
Project p;
|
||||
EXPECT_EQ(nullptr,p.callGraph);
|
||||
ASSERT_TRUE(p.pProcList.empty());
|
||||
ASSERT_TRUE(p.binary_path().empty());
|
||||
ASSERT_TRUE(p.project_name().empty());
|
||||
ASSERT_TRUE(p.symtab.empty());
|
||||
}
|
||||
|
||||
TEST(Project, CreatedProjectHasValidNames) {
|
||||
Project p;
|
||||
std::vector<std::string> strs = {"./Project1.EXE","/home/Project2.EXE","/home/Pro ject3"};
|
||||
std::vector<std::string> expected = {"Project1","Project2","Pro ject3"};
|
||||
for(size_t i=0; i<strs.size(); i++)
|
||||
{
|
||||
p.create(strs[i]);
|
||||
EXPECT_EQ(nullptr,p.callGraph);
|
||||
ASSERT_TRUE(p.pProcList.empty());
|
||||
EXPECT_EQ(expected[i],p.project_name());
|
||||
EXPECT_EQ(strs[i],p.binary_path());
|
||||
ASSERT_TRUE(p.symtab.empty());
|
||||
}
|
||||
}
|
||||
10
src/udm.cpp
10
src/udm.cpp
@@ -12,8 +12,8 @@
|
||||
#include "project.h"
|
||||
|
||||
extern Project g_proj;
|
||||
static void displayCFG(Function * pProc);
|
||||
static void displayDfs(BB * pBB);
|
||||
//static void displayCFG(Function * pProc);
|
||||
//static void displayDfs(BB * pBB);
|
||||
|
||||
/****************************************************************************
|
||||
* udm
|
||||
@@ -73,7 +73,7 @@ void udm(void)
|
||||
/* Build the control flow graph, find idioms, and convert low-level
|
||||
* icodes to high-level ones */
|
||||
Disassembler ds(2);
|
||||
for (auto iter = g_proj.pProcList.rbegin(); iter!=g_proj.pProcList.rend(); ++iter)
|
||||
for (auto iter = Project::get()->pProcList.rbegin(); iter!=Project::get()->pProcList.rend(); ++iter)
|
||||
{
|
||||
iter->buildCFG(ds);
|
||||
}
|
||||
@@ -83,10 +83,10 @@ void udm(void)
|
||||
* and intermediate instructions. Find expressions by forward
|
||||
* substitution algorithm */
|
||||
std::bitset<32> live_regs;
|
||||
g_proj.pProcList.front().dataFlow (live_regs);
|
||||
Project::get()->pProcList.front().dataFlow (live_regs);
|
||||
|
||||
/* Control flow analysis - structuring algorithm */
|
||||
for (auto iter = g_proj.pProcList.rbegin(); iter!=g_proj.pProcList.rend(); ++iter)
|
||||
for (auto iter = Project::get()->pProcList.rbegin(); iter!=Project::get()->pProcList.rend(); ++iter)
|
||||
{
|
||||
iter->controlFlowAnalysis();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user