replace boolT with plain old bool in a few places

This commit is contained in:
nemerle 2014-02-28 11:26:02 +01:00
parent 5c7799b778
commit 1c5e1c2fce
37 changed files with 3154 additions and 211 deletions

View File

@ -113,11 +113,11 @@ SOURCE_GROUP(Source FILES ${dcc_SOURCES})
SOURCE_GROUP(Headers FILES ${dcc_HEADERS}) SOURCE_GROUP(Headers FILES ${dcc_HEADERS})
ADD_LIBRARY(dcc_lib STATIC ${dcc_LIB_SOURCES} ${dcc_HEADERS}) ADD_LIBRARY(dcc_lib STATIC ${dcc_LIB_SOURCES} ${dcc_HEADERS})
cotire(dcc_lib) #cotire(dcc_lib)
ADD_EXECUTABLE(dcc_original ${dcc_SOURCES} ${dcc_HEADERS}) ADD_EXECUTABLE(dcc_original ${dcc_SOURCES} ${dcc_HEADERS})
ADD_DEPENDENCIES(dcc_original dcc_lib) ADD_DEPENDENCIES(dcc_original dcc_lib)
TARGET_LINK_LIBRARIES(dcc_original dcc_lib disasm_s ${REQ_LLVM_LIBRARIES}) TARGET_LINK_LIBRARIES(dcc_original dcc_lib disasm_s ${REQ_LLVM_LIBRARIES} ncurses)
if(dcc_build_tests) if(dcc_build_tests)
ADD_SUBDIRECTORY(src) ADD_SUBDIRECTORY(src)
endif() endif()

2762
CMakeScripts/cotire.cmake Normal file

File diff suppressed because it is too large Load Diff

View File

@ -117,7 +117,7 @@ public:
void findBBExps(LOCAL_ID &locals, Function *f); void findBBExps(LOCAL_ID &locals, Function *f);
bool valid() {return 0==(flg & INVALID_BB); } bool valid() {return 0==(flg & INVALID_BB); }
bool wasTraversedAtLevel(int l) const {return traversed==l;} bool wasTraversedAtLevel(int l) const {return traversed==l;}
ICODE * writeLoopHeader(int &indLevel, Function* pProc, int *numLoc, BB *&latch, boolT &repCond); ICODE * writeLoopHeader(int &indLevel, Function* pProc, int *numLoc, BB *&latch, bool &repCond);
void addOutEdge(uint32_t ip) // TODO: fix this void addOutEdge(uint32_t ip) // TODO: fix this
{ {
edges.push_back(TYPEADR_TYPE(ip)); edges.push_back(TYPEADR_TYPE(ip));

View File

@ -177,7 +177,7 @@ enum llIcode
iPOP, iPOP,
iPOPA, iPOPA,
iPOPF, iPOPF,
iPUSH, iPUSH, // 77
iPUSHA, iPUSHA,
iPUSHF, iPUSHF,
iRCL, /* 80 */ iRCL, /* 80 */

View File

@ -13,6 +13,7 @@ struct Expr;
struct Disassembler; struct Disassembler;
struct Function; struct Function;
struct CALL_GRAPH; struct CALL_GRAPH;
struct PROG;
typedef llvm::iplist<Function> FunctionListType; typedef llvm::iplist<Function> FunctionListType;
typedef FunctionListType lFunction; typedef FunctionListType lFunction;
@ -189,6 +190,7 @@ public:
void preprocessReturnDU(LivenessSet &_liveOut); void preprocessReturnDU(LivenessSet &_liveOut);
Expr * adjustActArgType(Expr *_exp, hlType forType); Expr * adjustActArgType(Expr *_exp, hlType forType);
std::string writeCall(Function *tproc, STKFRAME &args, int *numLoc); std::string writeCall(Function *tproc, STKFRAME &args, int *numLoc);
void processDosInt(STATE *pstate, PROG &prog, bool done);
protected: protected:
void extractJumpTableRange(ICODE& pIcode, STATE *pstate, JumpTable &table); void extractJumpTableRange(ICODE& pIcode, STATE *pstate, JumpTable &table);
bool followAllTableEntries(JumpTable &table, uint32_t cs, ICODE &pIcode, CALL_GRAPH *pcallGraph, STATE *pstate); bool followAllTableEntries(JumpTable &table, uint32_t cs, ICODE &pIcode, CALL_GRAPH *pcallGraph, STATE *pstate);

View File

@ -29,6 +29,7 @@ struct STKFRAME;
struct LOCAL_ID; struct LOCAL_ID;
struct ICODE; struct ICODE;
struct LLInst; struct LLInst;
struct LLOperand;
struct ID; struct ID;
typedef std::list<ICODE>::iterator iICODE; typedef std::list<ICODE>::iterator iICODE;
typedef boost::iterator_range<iICODE> rICODE; typedef boost::iterator_range<iICODE> rICODE;
@ -291,6 +292,7 @@ struct RegisterNode : public AstIdent
regiType = reg_type; regiType = reg_type;
regiIdx = idx; regiIdx = idx;
} }
RegisterNode(const LLOperand &, LOCAL_ID *locsym);
RegisterNode(eReg regi, uint32_t icodeFlg, LOCAL_ID *locsym); RegisterNode(eReg regi, uint32_t icodeFlg, LOCAL_ID *locsym);
virtual Expr *clone() const virtual Expr *clone() const

View File

@ -22,22 +22,6 @@
#include "BasicBlock.h" #include "BasicBlock.h"
class Project; class Project;
/* CALL GRAPH NODE */ /* CALL GRAPH NODE */
struct CALL_GRAPH
{
ilFunction proc; /* Pointer to procedure in pProcList */
std::vector<CALL_GRAPH *> outEdges; /* array of out edges */
public:
void write();
CALL_GRAPH() : outEdges(0)
{
}
public:
void writeNodeCallGraph(int indIdx);
bool insertCallGraph(ilFunction caller, ilFunction callee);
bool insertCallGraph(Function *caller, ilFunction callee);
void insertArc(ilFunction newProc);
};
//extern CALL_GRAPH * callGraph; /* Pointer to the head of the call graph */
extern bundle cCode; /* Output C procedure's declaration and code */ extern bundle cCode; /* Output C procedure's declaration and code */
/**** Global variables ****/ /**** Global variables ****/
@ -121,8 +105,8 @@ bool LibCheck(Function &p); /* chklib.c */
boolT insertCallGraph (CALL_GRAPH *, ilFunction, ilFunction); boolT insertCallGraph (CALL_GRAPH *, ilFunction, ilFunction);
/* Exported functions from hlicode.c */ /* Exported functions from hlicode.c */
char *writeJcond (const HLTYPE &, Function *, int *); const char *writeJcond(const HLTYPE &, Function *, int *);
char *writeJcondInv (HLTYPE, Function *, int *); const char *writeJcondInv (HLTYPE, Function *, int *);
/* Exported funcions from locident.c */ /* Exported funcions from locident.c */

View File

@ -13,7 +13,7 @@
#include <llvm/ADT/ilist.h> #include <llvm/ADT/ilist.h>
#include <llvm/ADT/ilist_node.h> #include <llvm/ADT/ilist_node.h>
#include <llvm/MC/MCInst.h> #include <llvm/MC/MCInst.h>
#include <llvm/Instruction.h> #include <llvm/IR/Instruction.h>
#include <boost/range/iterator_range.hpp> #include <boost/range/iterator_range.hpp>
#include "libdis.h" #include "libdis.h"
#include "Enums.h" #include "Enums.h"
@ -252,16 +252,26 @@ struct LLOperand
eReg regi; /* 0 < regs < INDEXBASE <= index modes */ eReg regi; /* 0 < regs < INDEXBASE <= index modes */
int16_t off; /* memory address offset */ int16_t off; /* memory address offset */
uint32_t opz; /* idx of immed src op */ uint32_t opz; /* idx of immed src op */
bool immed;
bool is_offset; // set by jumps
bool is_compound;
size_t width;
//union {/* Source operand if (flg & I) */ //union {/* Source operand if (flg & I) */
struct { /* Call & # actual arg bytes */ struct { /* Call & # actual arg bytes */
Function *proc; /* pointer to target proc (for CALL(F))*/ Function *proc; /* pointer to target proc (for CALL(F))*/
int cb; /* # actual arg bytes */ int cb; /* # actual arg bytes */
} proc; } proc;
LLOperand() : seg(rUNDEF),segOver(rUNDEF),segValue(0),regi(rUNDEF),off(0),opz(0) LLOperand() : seg(rUNDEF),segOver(rUNDEF),segValue(0),regi(rUNDEF),off(0),
opz(0),immed(0),is_offset(false),is_compound(0),width(0)
{ {
proc.proc=0; proc.proc=0;
proc.cb=0; proc.cb=0;
} }
LLOperand(eReg r,size_t w) : LLOperand()
{
regi=r;
width=w;
}
bool operator==(const LLOperand &with) const bool operator==(const LLOperand &with) const
{ {
return (seg==with.seg) && return (seg==with.seg) &&
@ -279,12 +289,12 @@ struct LLOperand
} }
eReg getReg2() const {return regi;} eReg getReg2() const {return regi;}
bool isReg() const; bool isReg() const;
static LLOperand CreateImm2(int64_t Val) static LLOperand CreateImm2(int64_t Val,uint8_t wdth=2)
{ {
LLOperand Op; LLOperand Op;
//Op.Kind = kImmediate; Op.immed=true;
//Op.ImmVal = Val;
Op.opz = Val; Op.opz = Val;
Op.width = wdth;
return Op; return Op;
} }
static LLOperand CreateReg2(unsigned Val) static LLOperand CreateReg2(unsigned Val)
@ -298,6 +308,10 @@ struct LLOperand
return not (*this == LLOperand()); return not (*this == LLOperand());
} }
void addProcInformation(int param_count,uint32_t call_conv); void addProcInformation(int param_count,uint32_t call_conv);
bool isImmediate() const { return immed;}
void setImmediate(bool x) { immed=x;}
bool compound() const {return is_compound;} // dx:ax pair
size_t byteWidth() const { assert(width<=4); return width;}
}; };
struct LLInst : public llvm::MCInst //: public llvm::ilist_node<LLInst> struct LLInst : public llvm::MCInst //: public llvm::ilist_node<LLInst>
{ {

View File

@ -4,6 +4,10 @@
#include <cassert> #include <cassert>
#include <list> #include <list>
#include <llvm/ADT/ilist.h> #include <llvm/ADT/ilist.h>
#include <boost/icl/interval.hpp>
#include <boost/icl/interval_map.hpp>
#include <boost/icl/split_interval_map.hpp>
#include <unordered_set>
#include "symtab.h" #include "symtab.h"
#include "BinaryImage.h" #include "BinaryImage.h"
#include "Procedure.h" #include "Procedure.h"

View File

@ -33,7 +33,7 @@ struct STATE
void setMemoryByte(uint32_t addr,uint8_t val) void setMemoryByte(uint32_t addr,uint8_t val)
{ {
//TODO: make this into a full scale value tracking class ! //TODO: make this into a full scale value tracking class !
}; }
}; };

View File

@ -66,7 +66,7 @@ void BB::display()
for (size_t i = 0; i < edges.size(); i++) for (size_t i = 0; i < edges.size(); i++)
{ {
if(edges[i].BBptr==0) if(edges[i].BBptr==nullptr)
printf(" outEdge[%2zd] = Unlinked out edge to %d\n",i, edges[i].ip); printf(" outEdge[%2zd] = Unlinked out edge to %d\n",i, edges[i].ip);
else else
printf(" outEdge[%2zd] = %d\n",i, edges[i].BBptr->begin()->loc_ip); printf(" outEdge[%2zd] = %d\n",i, edges[i].BBptr->begin()->loc_ip);
@ -132,7 +132,7 @@ void BB::displayDfs()
\param indLevel indentation level - used for formatting. \param indLevel indentation level - used for formatting.
\param numLoc: last # assigned to local variables \param numLoc: last # assigned to local variables
*/ */
ICODE* BB::writeLoopHeader(int &indLevel, Function* pProc, int *numLoc, BB *&latch, boolT &repCond) ICODE* BB::writeLoopHeader(int &indLevel, Function* pProc, int *numLoc, BB *&latch, bool &repCond)
{ {
latch = pProc->m_dfsLast[this->latchNode]; latch = pProc->m_dfsLast[this->latchNode];
std::ostringstream ostr; std::ostringstream ostr;
@ -192,8 +192,8 @@ void BB::writeCode (int indLevel, Function * pProc , int *numLoc,int _latchNode,
int follow; /* ifFollow */ int follow; /* ifFollow */
BB * succ, *latch; /* Successor and latching node */ BB * succ, *latch; /* Successor and latching node */
ICODE * picode; /* Pointer to HLI_JCOND instruction */ ICODE * picode; /* Pointer to HLI_JCOND instruction */
char *l; /* Pointer to HLI_JCOND expression */ std::string l; /* Pointer to HLI_JCOND expression */
boolT emptyThen, /* THEN clause is empty */ bool emptyThen, /* THEN clause is empty */
repCond; /* Repeat condition for while() */ repCond; /* Repeat condition for while() */
/* Check if this basic block should be analysed */ /* Check if this basic block should be analysed */
@ -206,7 +206,7 @@ void BB::writeCode (int indLevel, Function * pProc , int *numLoc,int _latchNode,
/* Check for start of loop */ /* Check for start of loop */
repCond = false; repCond = false;
latch = NULL; latch = nullptr;
if (loopType) if (loopType)
{ {
picode=writeLoopHeader(indLevel, pProc, numLoc, latch, repCond); picode=writeLoopHeader(indLevel, pProc, numLoc, latch, repCond);
@ -303,13 +303,13 @@ void BB::writeCode (int indLevel, Function * pProc , int *numLoc,int _latchNode,
if (succ->dfsLastNum != follow) /* THEN part */ if (succ->dfsLastNum != follow) /* THEN part */
{ {
l = writeJcond ( *back().hl(), pProc, numLoc); l = writeJcond ( *back().hl(), pProc, numLoc);
cCode.appendCode( "\n%s%s", indentStr(indLevel-1), l); cCode.appendCode( "\n%s%s", indentStr(indLevel-1), l.c_str());
succ->writeCode (indLevel, pProc, numLoc, _latchNode,follow); succ->writeCode (indLevel, pProc, numLoc, _latchNode,follow);
} }
else /* empty THEN part => negate ELSE part */ else /* empty THEN part => negate ELSE part */
{ {
l = writeJcondInv ( *back().hl(), pProc, numLoc); l = writeJcondInv ( *back().hl(), pProc, numLoc);
cCode.appendCode( "\n%s%s", indentStr(indLevel-1), l); cCode.appendCode( "\n%s%s", indentStr(indLevel-1), l.c_str());
edges[ELSE].BBptr->writeCode (indLevel, pProc, numLoc, _latchNode, follow); edges[ELSE].BBptr->writeCode (indLevel, pProc, numLoc, _latchNode, follow);
emptyThen = true; emptyThen = true;
} }
@ -345,7 +345,7 @@ void BB::writeCode (int indLevel, Function * pProc , int *numLoc,int _latchNode,
else /* no follow => if..then..else */ else /* no follow => if..then..else */
{ {
l = writeJcond ( *back().hl(), pProc, numLoc); l = writeJcond ( *back().hl(), pProc, numLoc);
cCode.appendCode( "%s%s", indentStr(indLevel-1), l); cCode.appendCode( "%s%s", indentStr(indLevel-1), l.c_str());
edges[THEN].BBptr->writeCode (indLevel, pProc, numLoc, _latchNode, _ifFollow); edges[THEN].BBptr->writeCode (indLevel, pProc, numLoc, _latchNode, _ifFollow);
cCode.appendCode( "%s}\n%selse {\n", indentStr(indLevel-1), indentStr(indLevel - 1)); cCode.appendCode( "%s}\n%selse {\n", indentStr(indLevel-1), indentStr(indLevel - 1));
edges[ELSE].BBptr->writeCode (indLevel, pProc, numLoc, _latchNode, _ifFollow); edges[ELSE].BBptr->writeCode (indLevel, pProc, numLoc, _latchNode, _ifFollow);

119
src/RegisterNode.cpp Normal file
View File

@ -0,0 +1,119 @@
#include <stdint.h>
#include <string>
#include <sstream>
#include <iostream>
#include <cassert>
#include <boost/range.hpp>
#include <boost/range/adaptors.hpp>
//#include <boost/range/algorithm.hpp>
//#include <boost/assign.hpp>
#include "types.h"
#include "ast.h"
#include "bundle.h"
#include "machine_x86.h"
#include "project.h"
using namespace std;
using namespace boost::adaptors;
RegisterNode::RegisterNode(const LLOperand &op,LOCAL_ID *locsym)
{
ident.type(REGISTER);
hlType type_sel;
regType reg_type;
if (op.byteWidth()==1)
{
type_sel = TYPE_BYTE_SIGN;
reg_type = BYTE_REG;
}
else /* uint16_t */
{
type_sel = TYPE_WORD_SIGN;
reg_type = WORD_REG;
}
regiIdx = locsym->newByteWordReg(type_sel, op.regi);
regiType = reg_type;
}
//RegisterNode::RegisterNode(eReg regi, uint32_t icodeFlg, LOCAL_ID *locsym)
//{
// ident.type(REGISTER);
// hlType type_sel;
// regType reg_type;
// if ((icodeFlg & B) || (icodeFlg & SRC_B))
// {
// type_sel = TYPE_BYTE_SIGN;
// reg_type = BYTE_REG;
// }
// else /* uint16_t */
// {
// type_sel = TYPE_WORD_SIGN;
// reg_type = WORD_REG;
// }
// regiIdx = locsym->newByteWordReg(type_sel, regi);
// regiType = reg_type;
//}
string RegisterNode::walkCondExpr(Function *pProc, int *numLoc) const
{
std::ostringstream codeOut;
std::ostringstream o;
ID *id = &pProc->localId.id_arr[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;
cCode.appendDecl(codeOut.str());
return o.str();
}
int RegisterNode::hlTypeSize(Function *) const
{
if (regiType == BYTE_REG)
return (1);
else
return (2);
}
hlType RegisterNode::expType(Function *pproc) const
{
if (regiType == BYTE_REG)
return (TYPE_BYTE_SIGN);
else
return (TYPE_WORD_SIGN);
}
Expr *RegisterNode::insertSubTreeReg(Expr *_expr, eReg regi, const LOCAL_ID *locsym)
{
eReg treeReg = locsym->id_arr[regiIdx].id.regi;
if (treeReg == regi) /* uint16_t reg */
{
return _expr;
}
else if(Machine_X86::isSubRegisterOf(treeReg,regi)) /* uint16_t/uint8_t reg */
{
return _expr;
}
}
bool RegisterNode::xClear(rICODE range_to_check, iICODE lastBBinst, const LOCAL_ID &locId)
{
uint8_t regi = locId.id_arr[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.testRegAndSubregs(regi))
return false;
if (all_valid_and_high_level_after_start.end().base() != lastBBinst)
return true;
return false;
}

View File

@ -298,7 +298,7 @@ Expr *AstIdent::id(const LLInst &ll_insn, opLoc sd, Function * pProc, iICODE ix_
int idx; /* idx into pIcode->localId table */ int idx; /* idx into pIcode->localId table */
const LLOperand &pm((sd == SRC) ? ll_insn.src() : ll_insn.m_dst); const LLOperand &pm(*ll_insn.get(sd));
if ( ((sd == DST) && ll_insn.testFlags(IM_DST)) or if ( ((sd == DST) && ll_insn.testFlags(IM_DST)) or
((sd == SRC) && ll_insn.testFlags(IM_SRC)) or ((sd == SRC) && ll_insn.testFlags(IM_SRC)) or
@ -312,7 +312,7 @@ Expr *AstIdent::id(const LLInst &ll_insn, opLoc sd, Function * pProc, iICODE ix_
else if ((sd == DST) && ll_insn.testFlags(IM_TMP_DST)) else if ((sd == DST) && ll_insn.testFlags(IM_TMP_DST))
{ /* implicit tmp */ { /* implicit tmp */
newExp = new RegisterNode(rTMP, 0, &pProc->localId); newExp = new RegisterNode(LLOperand(rTMP,2), &pProc->localId);
duIcode.setRegDU(rTMP, (operDu)eUSE); duIcode.setRegDU(rTMP, (operDu)eUSE);
} }
@ -322,7 +322,8 @@ Expr *AstIdent::id(const LLInst &ll_insn, opLoc sd, Function * pProc, iICODE ix_
newExp = new GlobalVariable(pm.segValue, pm.off); newExp = new GlobalVariable(pm.segValue, pm.off);
else if ( pm.isReg() ) /* register */ else if ( pm.isReg() ) /* register */
{ {
newExp = new RegisterNode(pm.regi, (sd == SRC) ? ll_insn.getFlag() : ll_insn.getFlag() & NO_SRC_B, &pProc->localId); //(sd == SRC) ? ll_insn.getFlag() : ll_insn.getFlag() & NO_SRC_B
newExp = new RegisterNode(pm, &pProc->localId);
duIcode.setRegDU( pm.regi, du); duIcode.setRegDU( pm.regi, du);
} }
@ -359,10 +360,11 @@ Expr *AstIdent::id(const LLInst &ll_insn, opLoc sd, Function * pProc, iICODE ix_
case INDEX_BP: selected = rBP; break; case INDEX_BP: selected = rBP; break;
case INDEX_BX: selected = rBX; break; case INDEX_BX: selected = rBX; break;
default: default:
newExp = 0; newExp = nullptr;
assert(false); assert(false);
} }
newExp = new RegisterNode(selected, 0, &pProc->localId); //NOTICE: was selected, 0
newExp = new RegisterNode(LLOperand(selected, 0), &pProc->localId);
duIcode.setRegDU( selected, du); duIcode.setRegDU( selected, du);
newExp = UnaryOperator::Create(DEREFERENCE, newExp); newExp = UnaryOperator::Create(DEREFERENCE, newExp);
} }
@ -402,7 +404,7 @@ int hlSize[] = {2, 1, 1, 2, 2, 4, 4, 4, 2, 2, 1, 4, 4};
int Expr::hlTypeSize(Function * pproc) const int Expr::hlTypeSize(Function * pproc) const
{ {
if (this == NULL) if (this == nullptr)
return (2); /* for TYPE_UNKNOWN */ return (2); /* for TYPE_UNKNOWN */
fprintf(stderr,"hlTypeSize queried for Unkown type %d \n",m_type); fprintf(stderr,"hlTypeSize queried for Unkown type %d \n",m_type);
return 2; // CC: is this correct? return 2; // CC: is this correct?
@ -710,7 +712,7 @@ bool Expr::insertSubTreeReg (AstIdent *&tree, Expr *_expr, eReg regi,const LOCAL
bool Expr::insertSubTreeReg (Expr *&tree, Expr *_expr, eReg regi,const LOCAL_ID *locsym) bool Expr::insertSubTreeReg (Expr *&tree, Expr *_expr, eReg regi,const LOCAL_ID *locsym)
{ {
if (tree == NULL) if (tree == nullptr)
return false; return false;
Expr *temp=tree->insertSubTreeReg(_expr,regi,locsym); Expr *temp=tree->insertSubTreeReg(_expr,regi,locsym);
if(nullptr!=temp) if(nullptr!=temp)
@ -775,7 +777,7 @@ Expr *AstIdent::insertSubTreeReg(Expr *_expr, eReg regi, const LOCAL_ID *locsym)
* long register index longIdx*/ * long register index longIdx*/
bool Expr::insertSubTreeLongReg(Expr *_expr, Expr *&tree, int longIdx) bool Expr::insertSubTreeLongReg(Expr *_expr, Expr *&tree, int longIdx)
{ {
if (tree == NULL) if (tree == nullptr)
return false; return false;
Expr *temp=tree->insertSubTreeLongReg(_expr,longIdx); Expr *temp=tree->insertSubTreeLongReg(_expr,longIdx);
if(nullptr!=temp) if(nullptr!=temp)

View File

@ -10,14 +10,15 @@
#include <boost/range/adaptors.hpp> #include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp> #include <boost/range/algorithm.hpp>
#include "dcc.h"
#include "disassem.h"
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include "dcc.h"
#include "disassem.h"
#include "project.h" #include "project.h"
#include "CallGraph.h"
using namespace boost; using namespace boost;
using namespace boost::adaptors; using namespace boost::adaptors;
bundle cCode; /* Procedure declaration and code */ bundle cCode; /* Procedure declaration and code */
@ -318,9 +319,9 @@ static void backBackEnd (CALL_GRAPH * pcallGraph, std::ostream &_ios)
pcallGraph->proc->flg |= PROC_OUTPUT; pcallGraph->proc->flg |= PROC_OUTPUT;
/* Dfs if this procedure has any successors */ /* Dfs if this procedure has any successors */
for (size_t i = 0; i < pcallGraph->outEdges.size(); i++) for (auto & elem : pcallGraph->outEdges)
{ {
backBackEnd (pcallGraph->outEdges[i], _ios); backBackEnd (elem, _ios);
} }
/* Generate code for this procedure */ /* Generate code for this procedure */

View File

@ -56,7 +56,7 @@ static uint16_t *T1base, *T2base; /* Pointers to start of T1, T2 */
static uint16_t *g; /* g[] */ static uint16_t *g; /* g[] */
static HT *ht; /* The hash table */ static HT *ht; /* The hash table */
static PH_FUNC_STRUCT *pFunc; /* Points to the array of func names */ static PH_FUNC_STRUCT *pFunc; /* Points to the array of func names */
static hlType *pArg=0; /* Points to the array of param types */ static hlType *pArg=nullptr; /* Points to the array of param types */
static int numFunc; /* Number of func names actually stored */ static int numFunc; /* Number of func names actually stored */
static int numArg; /* Number of param names actually stored */ static int numArg; /* Number of param names actually stored */
#define DCCLIBS "dcclibs.dat" /* Name of the prototypes data file */ #define DCCLIBS "dcclibs.dat" /* Name of the prototypes data file */
@ -302,7 +302,7 @@ void SetupLibCheck(void)
uint16_t w, len; uint16_t w, len;
int i; int i;
if ((g_file = fopen(sSigName, "rb")) == NULL) if ((g_file = fopen(sSigName, "rb")) == nullptr)
{ {
printf("Warning: cannot open signature file %s\n", sSigName); printf("Warning: cannot open signature file %s\n", sSigName);
return; return;
@ -392,7 +392,7 @@ void SetupLibCheck(void)
/* This is now the hash table */ /* This is now the hash table */
/* First allocate space for the table */ /* First allocate space for the table */
ht = new HT[numKeys]; ht = new HT[numKeys];
if ( 0 == ht) if ( nullptr == ht)
{ {
printf("Could not allocate hash table\n"); printf("Could not allocate hash table\n");
exit(1); exit(1);
@ -446,7 +446,7 @@ bool LibCheck(Function & pProc)
if (prog.bSigs == false) if (prog.bSigs == false)
{ {
/* No signatures... can't rely on hash parameters to be initialised /* No signatures... can't rely on hash parameters to be initialised
so always return false */ so always return false */
return false; return false;
} }
@ -457,6 +457,8 @@ bool LibCheck(Function & pProc)
pProc.name = "main"; pProc.name = "main";
return false; return false;
} }
if(fileOffset + PATLEN > prog.cbImage)
return false;
memcpy(pat, &prog.image()[fileOffset], PATLEN); memcpy(pat, &prog.image()[fileOffset], PATLEN);
//memmove(pat, &prog.image()[fileOffset], PATLEN); //memmove(pat, &prog.image()[fileOffset], PATLEN);
fixWildCards(pat); /* Fix wild cards in the copy */ fixWildCards(pat); /* Fix wild cards in the copy */
@ -888,7 +890,7 @@ void readProtoFile(void)
} }
strcat(szProFName, DCCLIBS); strcat(szProFName, DCCLIBS);
if ((fProto = fopen(szProFName, "rb")) == NULL) if ((fProto = fopen(szProFName, "rb")) == nullptr)
{ {
printf("Warning: cannot open library prototype data file %s\n", szProFName); printf("Warning: cannot open library prototype data file %s\n", szProFName);
return; return;

View File

@ -276,13 +276,13 @@ void Function::structLoops(derSeq *derivedG)
/* Structure loops */ /* Structure loops */
/* for all derived sequences Gi */ /* for all derived sequences Gi */
for(derSeq::iterator iter=derivedG->begin(); iter!=derivedG->end(); ++iter) for(auto & elem : *derivedG)
{ {
level++; level++;
Ii = iter->Ii; Ii = elem.Ii;
while (Ii) /* for all intervals Ii of Gi */ while (Ii) /* for all intervals Ii of Gi */
{ {
latchNode = NULL; latchNode = nullptr;
intNodes.clear(); intNodes.clear();
/* Find interval head (original BB node in G1) and create /* Find interval head (original BB node in G1) and create

View File

@ -93,11 +93,11 @@ size_t STKFRAME::getLocVar(int off)
/* Returns a string with the source operand of Icode */ /* Returns a string with the source operand of Icode */
static Expr *srcIdent (const LLInst &ll_insn, Function * pProc, iICODE i, ICODE & duIcode, operDu du) static Expr *srcIdent (const LLInst &ll_insn, Function * pProc, iICODE i, ICODE & duIcode, operDu du)
{ {
if (ll_insn.testFlags(I)) /* immediate operand */ const LLOperand * src_op = ll_insn.get(SRC);
if (src_op->isImmediate()) /* immediate operand ll_insn.testFlags(I)*/
{ {
if (ll_insn.testFlags(B)) //if (ll_insn.testFlags(B))
return new Constant(ll_insn.src().getImm2(), 1); return new Constant(src_op->getImm2(), src_op->byteWidth());
return new Constant(ll_insn.src().getImm2(), 2);
} }
// otherwise // otherwise
return AstIdent::id (ll_insn, SRC, pProc, i, duIcode, du); return AstIdent::id (ll_insn, SRC, pProc, i, duIcode, du);
@ -148,6 +148,8 @@ void Function::elimCondCodes ()
if ((use & def) != use) if ((use & def) != use)
continue; continue;
notSup = false; notSup = false;
LLOperand *dest_ll = defAt->ll()->get(DST);
LLOperand *src_ll = defAt->ll()->get(SRC);
if ((useAtOp >= iJB) && (useAtOp <= iJNS)) if ((useAtOp >= iJB) && (useAtOp <= iJNS))
{ {
iICODE befDefAt = (++riICODE(defAt)).base(); iICODE befDefAt = (++riICODE(defAt)).base();
@ -161,29 +163,22 @@ void Function::elimCondCodes ()
case iOR: case iOR:
lhs = defAt->hl()->asgn.lhs()->clone(); lhs = defAt->hl()->asgn.lhs()->clone();
useAt->copyDU(*defAt, eUSE, eDEF); useAt->copyDU(*defAt, eUSE, eDEF);
if (defAt->ll()->testFlags(B)) //if (defAt->ll()->testFlags(B))
rhs = new Constant(0, 1); rhs = new Constant(0, dest_ll->byteWidth());
else
rhs = new Constant(0, 2);
break; break;
case iTEST: case iTEST:
rhs = srcIdent (*defAt->ll(),this, befDefAt,*useAt, eUSE); rhs = srcIdent (*defAt->ll(),this, befDefAt,*useAt, eUSE);
lhs = dstIdent (*defAt->ll(),this, befDefAt,*useAt, eUSE); lhs = dstIdent (*defAt->ll(),this, befDefAt,*useAt, eUSE);
lhs = BinaryOperator::And(lhs, rhs); lhs = BinaryOperator::And(lhs, rhs);
if (defAt->ll()->testFlags(B)) // if (defAt->ll()->testFlags(B))
rhs = new Constant(0, 1); rhs = new Constant(0, dest_ll->byteWidth());
else
rhs = new Constant(0, 2);
break; break;
case iINC: case iINC:
case iDEC: //WARNING: verbatim copy from iOR needs fixing ? case iDEC: //WARNING: verbatim copy from iOR needs fixing ?
lhs = defAt->hl()->asgn.lhs()->clone(); lhs = defAt->hl()->asgn.lhs()->clone();
useAt->copyDU(*defAt, eUSE, eDEF); useAt->copyDU(*defAt, eUSE, eDEF);
if (defAt->ll()->testFlags(B)) rhs = new Constant(0, dest_ll->byteWidth());
rhs = new Constant(0, 1);
else
rhs = new Constant(0, 2);
break; break;
default: default:
notSup = true; notSup = true;
@ -202,7 +197,8 @@ void Function::elimCondCodes ()
else if (useAtOp == iJCXZ) else if (useAtOp == iJCXZ)
{ {
lhs = new RegisterNode(rCX, 0, &localId); //NOTICE: was rCX, 0
lhs = new RegisterNode(LLOperand(rCX, 0 ), &localId);
useAt->setRegDU (rCX, eUSE); useAt->setRegDU (rCX, eUSE);
rhs = new Constant(0, 2); rhs = new Constant(0, 2);
_expr = BinaryOperator::Create(EQUAL,lhs,rhs); _expr = BinaryOperator::Create(EQUAL,lhs,rhs);
@ -514,7 +510,7 @@ void BB::genDU1()
/* Process each register definition of a HIGH_LEVEL icode instruction. /* Process each register definition of a HIGH_LEVEL icode instruction.
* Note that register variables should not be considered registers. * Note that register variables should not be considered registers.
*/ */
assert(0!=Parent); assert(nullptr!=Parent);
ICODE::TypeFilter<HIGH_LEVEL> select_high_level; ICODE::TypeFilter<HIGH_LEVEL> select_high_level;
auto all_high_levels = instructions | filtered(select_high_level); auto all_high_levels = instructions | filtered(select_high_level);
for (auto picode=all_high_levels.begin(); picode!=all_high_levels.end(); ++picode) for (auto picode=all_high_levels.begin(); picode!=all_high_levels.end(); ++picode)
@ -568,7 +564,7 @@ void LOCAL_ID::forwardSubs (Expr *lhs, Expr *rhs, iICODE picode, iICODE ticode,
} }
RegisterNode * lhs_reg=dynamic_cast<RegisterNode *>(lhs_unary); RegisterNode * lhs_reg=dynamic_cast<RegisterNode *>(lhs_unary);
assert(lhs_reg); assert(lhs_reg);
if (rhs == NULL) /* In case expression popped is NULL */ if (rhs == nullptr) /* In case expression popped is NULL */
return; return;
/* Insert on rhs of ticode, if possible */ /* Insert on rhs of ticode, if possible */
@ -607,7 +603,7 @@ static void forwardSubsLong (int longIdx, Expr *_exp, iICODE picode, iICODE tico
{ {
bool res; bool res;
if (_exp == NULL) /* In case expression popped is NULL */ if (_exp == nullptr) /* In case expression popped is NULL */
return; return;
/* Insert on rhs of ticode, if possible */ /* Insert on rhs of ticode, if possible */
@ -634,18 +630,18 @@ static void forwardSubsLong (int longIdx, Expr *_exp, iICODE picode, iICODE tico
* instruction f up to instruction t. */ * instruction f up to instruction t. */
bool UnaryOperator::xClear(rICODE range_to_check, iICODE lastBBinst, const LOCAL_ID &locs) bool UnaryOperator::xClear(rICODE range_to_check, iICODE lastBBinst, const LOCAL_ID &locs)
{ {
if(0==unaryExp) if(nullptr==unaryExp)
return false; return false;
return unaryExp->xClear ( range_to_check, lastBBinst, locs); return unaryExp->xClear ( range_to_check, lastBBinst, locs);
} }
bool BinaryOperator::xClear(rICODE range_to_check, iICODE lastBBinst, const LOCAL_ID &locs) bool BinaryOperator::xClear(rICODE range_to_check, iICODE lastBBinst, const LOCAL_ID &locs)
{ {
if(0==m_rhs) if(nullptr==m_rhs)
return false; return false;
if ( ! m_rhs->xClear (range_to_check, lastBBinst, locs) ) if ( ! m_rhs->xClear (range_to_check, lastBBinst, locs) )
return false; return false;
if(0==m_lhs) if(nullptr==m_lhs)
return false; return false;
return m_lhs->xClear (range_to_check, lastBBinst, locs); return m_lhs->xClear (range_to_check, lastBBinst, locs);
} }
@ -689,7 +685,7 @@ static int processCArg (Function * pp, Function * pProc, ICODE * picode, size_t
{ {
if (pp->args.numArgs > 0) if (pp->args.numArgs > 0)
{ {
if(_exp==NULL) if(_exp==nullptr)
fprintf(stderr,"Would try to adjustForArgType with null _exp\n"); fprintf(stderr,"Would try to adjustForArgType with null _exp\n");
else else
pp->args.adjustForArgType (numArgs, _exp->expType (pProc)); pp->args.adjustForArgType (numArgs, _exp->expType (pProc));
@ -794,7 +790,7 @@ void Function::processHliCall(Expr *_exp, iICODE picode)
{ {
if (pp->args.numArgs >0) if (pp->args.numArgs >0)
{ {
if(_exp==NULL) if(_exp==nullptr)
{ {
fprintf(stderr,"Would try to adjustForArgType with null _exp\n"); fprintf(stderr,"Would try to adjustForArgType with null _exp\n");
} }
@ -840,7 +836,7 @@ void BB::findBBExps(LOCAL_ID &locals,Function *fnc)
Expr *_exp; // expression pointer - for HLI_POP and HLI_CALL */ Expr *_exp; // expression pointer - for HLI_POP and HLI_CALL */
//Expr *lhs; // exp ptr for return value of a HLI_CALL */ //Expr *lhs; // exp ptr for return value of a HLI_CALL */
iICODE ticode; // Target icode */ iICODE ticode; // Target icode */
HLTYPE *ti_hl=0; HLTYPE *ti_hl=nullptr;
uint8_t regi; uint8_t regi;
numHlIcodes = 0; numHlIcodes = 0;
// register(s) to be forward substituted */ // register(s) to be forward substituted */
@ -1129,7 +1125,7 @@ void Function::preprocessReturnDU(LivenessSet &_liveOut)
// int idx; // int idx;
bool isAx, isBx, isCx, isDx; bool isAx, isBx, isCx, isDx;
eReg bad_regs[] = {rES,rCS,rDS,rSS}; eReg bad_regs[] = {rES,rCS,rDS,rSS};
constexpr char * names[] ={"ES","CS","DS","SS"}; constexpr const char * names[] ={"ES","CS","DS","SS"};
for(int i=0; i<4; ++i) for(int i=0; i<4; ++i)
if(_liveOut.testReg(bad_regs[i])) if(_liveOut.testReg(bad_regs[i]))
{ {

View File

@ -8,6 +8,7 @@
#include "dcc.h" #include "dcc.h"
#include "project.h" #include "project.h"
#include "CallGraph.h"
/* Global variables - extern to other modules */ /* Global variables - extern to other modules */
extern char *asm1_name, *asm2_name; /* Assembler output filenames */ extern char *asm1_name, *asm2_name; /* Assembler output filenames */
extern SYMTAB symtab; /* Global symbol table */ extern SYMTAB symtab; /* Global symbol table */
@ -34,54 +35,49 @@ static void displayTotalStats(void);
#include <llvm/CodeGen/MachineInstrBuilder.h> #include <llvm/CodeGen/MachineInstrBuilder.h>
#include <llvm/TableGen/Main.h> #include <llvm/TableGen/Main.h>
#include <llvm/TableGen/TableGenAction.h> #include <llvm/TableGen/TableGenBackend.h>
#include <llvm/TableGen/Record.h> #include <llvm/TableGen/Record.h>
/**************************************************************************** /****************************************************************************
* main * main
***************************************************************************/ ***************************************************************************/
#include <iostream> #include <iostream>
using namespace llvm; using namespace llvm;
class TVisitor : public TableGenAction { bool TVisitor(raw_ostream &OS, RecordKeeper &Records)
public: {
virtual bool operator()(raw_ostream &OS, RecordKeeper &Records) Record *rec = Records.getDef("ADD8i8");
if(rec)
{ {
Record *rec = Records.getDef("ADD8i8"); if(not rec->getTemplateArgs().empty())
if(rec) std::cout << "Has template args\n";
{ auto classes(rec->getSuperClasses());
if(not rec->getTemplateArgs().empty()) for(auto val : rec->getSuperClasses())
std::cout << "Has template args\n"; std::cout << "Super "<<val->getName()<<"\n";
auto classes(rec->getSuperClasses());
for(auto val : rec->getSuperClasses())
std::cout << "Super "<<val->getName()<<"\n";
// DagInit * in = rec->getValueAsDag(val.getName()); // DagInit * in = rec->getValueAsDag(val.getName());
// in->dump(); // in->dump();
for(const RecordVal &val : rec->getValues()) for(const RecordVal &val : rec->getValues())
{
// val.dump();
}
rec->dump();
}
// rec = Records.getDef("CCR");
// if(rec)
// rec->dump();
for(auto val : Records.getDefs())
{ {
//std::cout<< "Def "<<val.first<<"\n"; // val.dump();
} }
return false; rec->dump();
} }
}; // rec = Records.getDef("CCR");
// if(rec)
// rec->dump();
for(auto val : Records.getDefs())
{
//std::cout<< "Def "<<val.first<<"\n";
}
return false;
}
int testTblGen(int argc, char **argv) int testTblGen(int argc, char **argv)
{ {
using namespace llvm; using namespace llvm;
sys::PrintStackTraceOnErrorSignal(); sys::PrintStackTraceOnErrorSignal();
PrettyStackTraceProgram(argc,argv); PrettyStackTraceProgram(argc,argv);
cl::ParseCommandLineOptions(argc,argv); cl::ParseCommandLineOptions(argc,argv);
TVisitor tz; return llvm::TableGenMain(argv[0],TVisitor);
return llvm::TableGenMain(argv[0],tz);
InitializeNativeTarget(); InitializeNativeTarget();
Triple TheTriple; Triple TheTriple;
std::string def = sys::getDefaultTargetTriple(); std::string def = sys::getDefaultTargetTriple();

View File

@ -258,7 +258,7 @@ void Disassembler::dis1Line(LLInst &inst,int loc_ip, int pass)
oper_stream << setw(5)<<left; // align for the labels oper_stream << setw(5)<<left; // align for the labels
{ {
ostringstream lab_contents; ostringstream lab_contents;
if (readVal(lab_contents, inst.label, 0)) if (readVal(lab_contents, inst.label, nullptr))
{ {
lab_contents << ':'; /* Also removes the null */ lab_contents << ':'; /* Also removes the null */
} }
@ -343,7 +343,7 @@ void Disassembler::dis1Line(LLInst &inst,int loc_ip, int pass)
ICODE *lab=pc.GetIcode(inst.src().getImm2()); ICODE *lab=pc.GetIcode(inst.src().getImm2());
selectTable(Label); selectTable(Label);
if ((inst.src().getImm2() < (uint32_t)numIcode) && /* Ensure in range */ if ((inst.src().getImm2() < (uint32_t)numIcode) && /* Ensure in range */
readVal(operands_s, lab->ll()->label, 0)) readVal(operands_s, lab->ll()->label, nullptr))
{ {
break; /* Symbolic label. Done */ break; /* Symbolic label. Done */
} }
@ -483,7 +483,7 @@ void Disassembler::dis1Line(LLInst &inst,int loc_ip, int pass)
/* Check for user supplied comment */ /* Check for user supplied comment */
selectTable(Comment); selectTable(Comment);
ostringstream cbuf; ostringstream cbuf;
if (readVal(cbuf, inst.label, 0)) if (readVal(cbuf, inst.label, nullptr))
{ {
result_stream <<"; "<<cbuf.str(); result_stream <<"; "<<cbuf.str();
} }

View File

@ -180,8 +180,7 @@ static bool op0F(uint8_t pat[])
processor is in 16 bit address mode (real mode). processor is in 16 bit address mode (real mode).
PATLEN bytes are scanned. PATLEN bytes are scanned.
*/ */
void void fixWildCards(uint8_t pat[])
fixWildCards(uint8_t pat[])
{ {
uint8_t op, quad, intArg; uint8_t op, quad, intArg;

View File

@ -67,7 +67,7 @@ static void displayMemMap(void);
****************************************************************************/ ****************************************************************************/
bool DccFrontend::FrontEnd () bool DccFrontend::FrontEnd ()
{ {
Project::get()->callGraph = 0; Project::get()->callGraph = nullptr;
Project::get()->create(m_fname); Project::get()->create(m_fname);
/* Load program into memory */ /* Load program into memory */
@ -213,7 +213,7 @@ void DccFrontend::LoadImage(Project &proj)
uint8_t buf[4]; uint8_t buf[4];
/* Open the input file */ /* Open the input file */
if ((fp = fopen(proj.binary_path().c_str(), "rb")) == NULL) if ((fp = fopen(proj.binary_path().c_str(), "rb")) == nullptr)
{ {
fatalError(CANNOT_OPEN, proj.binary_path().c_str()); fatalError(CANNOT_OPEN, proj.binary_path().c_str());
} }

View File

@ -83,8 +83,8 @@ CondJumps:
if (ll->testFlags(SWITCH)) if (ll->testFlags(SWITCH))
{ {
pBB = BB::Create(current_range, MULTI_BRANCH, this); pBB = BB::Create(current_range, MULTI_BRANCH, this);
for (size_t i = 0; i < ll->caseTbl2.size(); i++) for (auto & elem : ll->caseTbl2)
pBB->addOutEdge(ll->caseTbl2[i]); pBB->addOutEdge(elem);
hasCase = true; hasCase = true;
} }
else if ((ll->getFlag() & (I | NO_LABEL)) == I) //TODO: WHY NO_LABEL TESTIT else if ((ll->getFlag() & (I | NO_LABEL)) == I) //TODO: WHY NO_LABEL TESTIT
@ -138,9 +138,9 @@ CondJumps:
for (; iter!=heldBBs.end(); ++iter) for (; iter!=heldBBs.end(); ++iter)
{ {
pBB = *iter; pBB = *iter;
for (size_t edeg_idx = 0; edeg_idx < pBB->edges.size(); edeg_idx++) for (auto & elem : pBB->edges)
{ {
int32_t ip = pBB->edges[edeg_idx].ip; int32_t ip = elem.ip;
if (ip >= SYNTHESIZED_MIN) if (ip >= SYNTHESIZED_MIN)
{ {
fatalError (INVALID_SYNTHETIC_BB); fatalError (INVALID_SYNTHETIC_BB);
@ -151,7 +151,7 @@ CondJumps:
if(iter2==heldBBs.end()) if(iter2==heldBBs.end())
fatalError(NO_BB, ip, name.c_str()); fatalError(NO_BB, ip, name.c_str());
psBB = *iter2; psBB = *iter2;
pBB->edges[edeg_idx].BBptr = psBB; elem.BBptr = psBB;
psBB->inEdges.push_back((BB *)nullptr); psBB->inEdges.push_back((BB *)nullptr);
} }
} }
@ -258,7 +258,7 @@ void Function::compressCFG()
/* Allocate storage for dfsLast[] array */ /* Allocate storage for dfsLast[] array */
numBBs = stats.numBBaft; numBBs = stats.numBBaft;
m_dfsLast.resize(numBBs,0); // = (BB **)allocMem(numBBs * sizeof(BB *)) m_dfsLast.resize(numBBs,nullptr); // = (BB **)allocMem(numBBs * sizeof(BB *))
/* Now do a dfs numbering traversal and fill in the inEdges[] array */ /* Now do a dfs numbering traversal and fill in the inEdges[] array */
last = numBBs - 1; last = numBBs - 1;
@ -360,10 +360,10 @@ void BB::mergeFallThrough( CIcodeRec &Icode)
traversed = DFS_MERGE; traversed = DFS_MERGE;
/* Process all out edges recursively */ /* Process all out edges recursively */
for (size_t i = 0; i < edges.size(); i++) for (auto & elem : edges)
{ {
if (edges[i].BBptr->traversed != DFS_MERGE) if (elem.BBptr->traversed != DFS_MERGE)
edges[i].BBptr->mergeFallThrough(Icode); elem.BBptr->mergeFallThrough(Icode);
} }
} }

View File

@ -97,7 +97,7 @@ bool ICODE::removeDefRegi (eReg regi, int thisDefIdx, LOCAL_ID *locId)
if(p and p->removeRegFromLong(regi,locId)) if(p and p->removeRegFromLong(regi,locId))
{ {
du1.removeDef(regi); //du1.numRegsDef--; du1.removeDef(regi); //du1.numRegsDef--;
//du.def &= maskDuReg[regi]; //du.def &= maskDuReg[regi];
du.def.clrReg(regi); du.def.clrReg(regi);
} }
return false; return false;
@ -305,9 +305,9 @@ static bool needsLhs(unsigned opc)
* refines the HIGH_LEVEL icodes. */ * refines the HIGH_LEVEL icodes. */
void Function::highLevelGen() void Function::highLevelGen()
{ {
size_t numIcode; /* number of icode instructions */ size_t numIcode; /* number of icode instructions */
iICODE pIcode; /* ptr to current icode node */ iICODE pIcode; /* ptr to current icode node */
Expr *rhs; /* left- and right-hand side of expression */ Expr *rhs; /* left- and right-hand side of expression */
uint32_t _flg; /* icode flags */ uint32_t _flg; /* icode flags */
numIcode = Icode.size(); numIcode = Icode.size();
for (iICODE i = Icode.begin(); i!=Icode.end() ; ++i) for (iICODE i = Icode.begin(); i!=Icode.end() ; ++i)
@ -316,6 +316,8 @@ void Function::highLevelGen()
assert(numIcode==Icode.size()); assert(numIcode==Icode.size());
pIcode = i; //Icode.GetIcode(i) pIcode = i; //Icode.GetIcode(i)
LLInst *ll = pIcode->ll(); LLInst *ll = pIcode->ll();
LLOperand *dst_ll = ll->get(DST);
LLOperand *src_ll = ll->get(SRC);
if ( ll->testFlags(NOT_HLL) ) if ( ll->testFlags(NOT_HLL) )
pIcode->invalidate(); pIcode->invalidate();
if ((pIcode->type != LOW_LEVEL) or not pIcode->valid() ) if ((pIcode->type != LOW_LEVEL) or not pIcode->valid() )
@ -327,8 +329,14 @@ void Function::highLevelGen()
if ( not ll->testFlags(NO_SRC) ) /* if there is src op */ if ( not ll->testFlags(NO_SRC) ) /* if there is src op */
rhs = AstIdent::id (*pIcode->ll(), SRC, this, i, *pIcode, NONE); rhs = AstIdent::id (*pIcode->ll(), SRC, this, i, *pIcode, NONE);
if(ll->m_dst.isSet() || (ll->getOpcode()==iMOD)) if(ll->m_dst.isSet() || (ll->getOpcode()==iMOD))
lhs = AstIdent::id (*pIcode->ll(), DST, this, i, *pIcode, NONE); lhs = AstIdent::id (*pIcode->ll(), DST, this, i, *pIcode, NONE);
} }
if(ll->getOpcode()==iPUSH) {
if(ll->testFlags(I)) {
lhs = new Constant(src_ll->opz,src_ll->byteWidth());
}
// lhs = AstIdent::id (*pIcode->ll(), DST, this, i, *pIcode, NONE);
}
if(needsLhs(ll->getOpcode())) if(needsLhs(ll->getOpcode()))
assert(lhs!=nullptr); assert(lhs!=nullptr);
switch (ll->getOpcode()) switch (ll->getOpcode())
@ -356,18 +364,13 @@ void Function::highLevelGen()
case iDIV: case iDIV:
case iIDIV:/* should be signed div */ case iIDIV:/* should be signed div */
{
eReg v = ( dst_ll->byteWidth()==1) ? rAL:rAX;
rhs = new BinaryOperator(DIV,lhs, rhs); rhs = new BinaryOperator(DIV,lhs, rhs);
if ( ll->testFlags(B) ) lhs = new RegisterNode(LLOperand(v, dst_ll->byteWidth()), &localId);
{ pIcode->setRegDU( v, eDEF);
lhs = new RegisterNode(rAL, 0, &localId);
pIcode->setRegDU( rAL, eDEF);
}
else
{
lhs = new RegisterNode(rAX, 0, &localId);
pIcode->setRegDU( rAX, eDEF);
}
pIcode->setAsgn(lhs, rhs); pIcode->setAsgn(lhs, rhs);
}
break; break;
case iIMUL: case iIMUL:
@ -387,17 +390,13 @@ void Function::highLevelGen()
break; break;
case iMOD: case iMOD:
{
rhs = new BinaryOperator(MOD,lhs, rhs); rhs = new BinaryOperator(MOD,lhs, rhs);
eReg lhs_reg; eReg lhs_reg = (dst_ll->byteWidth()==1) ? rAH : rDX;
lhs = new RegisterNode(LLOperand(lhs_reg, dst_ll->byteWidth()), &localId);
if ( ll->testFlags(B) )
lhs_reg = rAH;
else
lhs_reg = rDX;
lhs = new RegisterNode(lhs_reg, 0, &localId);
pIcode->setRegDU( lhs_reg, eDEF); pIcode->setRegDU( lhs_reg, eDEF);
pIcode->setAsgn(lhs, rhs); pIcode->setAsgn(lhs, rhs);
}
break; break;
case iMOV: pIcode->setAsgn(lhs, rhs); case iMOV: pIcode->setAsgn(lhs, rhs);
@ -415,7 +414,7 @@ void Function::highLevelGen()
break; break;
case iNOT: case iNOT:
rhs = new BinaryOperator(NOT,NULL, rhs); // TODO: change this to unary NOT ? rhs = new BinaryOperator(NOT,nullptr, rhs); // TODO: change this to unary NOT ?
pIcode->setAsgn(lhs, rhs); pIcode->setAsgn(lhs, rhs);
break; break;
@ -433,7 +432,7 @@ void Function::highLevelGen()
break; break;
case iRET: case iRET:
case iRETF: pIcode->setUnary(HLI_RET, NULL); case iRETF: pIcode->setUnary(HLI_RET, nullptr);
break; break;
case iSHL: case iSHL:
@ -498,7 +497,7 @@ std::string Function::writeCall (Function * tproc, STKFRAME & args, int *numLoc)
/* Displays the output of a HLI_JCOND icode. */ /* Displays the output of a HLI_JCOND icode. */
char *writeJcond (const HLTYPE &h, Function * pProc, int *numLoc) const char *writeJcond (const HLTYPE &h, Function * pProc, int *numLoc)
{ {
memset (buf, ' ', sizeof(buf)); memset (buf, ' ', sizeof(buf));
buf[0] = '\0'; buf[0] = '\0';
@ -521,7 +520,7 @@ char *writeJcond (const HLTYPE &h, Function * pProc, int *numLoc)
/* Displays the inverse output of a HLI_JCOND icode. This is used in the case /* Displays the inverse output of a HLI_JCOND icode. This is used in the case
* when the THEN clause of an if..then..else is empty. The clause is * when the THEN clause of an if..then..else is empty. The clause is
* negated and the ELSE clause is used instead. */ * negated and the ELSE clause is used instead. */
char *writeJcondInv (HLTYPE h, Function * pProc, int *numLoc) const char *writeJcondInv(HLTYPE h, Function * pProc, int *numLoc)
{ {
memset (buf, ' ', sizeof(buf)); memset (buf, ' ', sizeof(buf));
buf[0] = '\0'; buf[0] = '\0';
@ -638,12 +637,12 @@ void ICODE::writeDU()
{ {
if (not du1.used(i)) if (not du1.used(i))
continue; continue;
printf ("%d: du1[%d][] = ", my_idx, i); printf ("%d: du1[%d][] = ", my_idx, i);
for(auto j : du1.idx[i].uses) for(auto j : du1.idx[i].uses)
{ {
printf ("%d ", j->loc_ip); printf ("%d ", j->loc_ip);
} }
printf ("\n"); printf ("\n");
} }
/* For HLI_CALL, print # parameter bytes */ /* For HLI_CALL, print # parameter bytes */

View File

@ -20,6 +20,6 @@ HlTypeSupport *HLTYPE::get()
case HLI_PUSH: return &exp; case HLI_PUSH: return &exp;
case HLI_CALL: return &call; case HLI_CALL: return &call;
default: default:
return 0; return nullptr;
} }
} }

View File

@ -3,6 +3,8 @@
* (C) Cristina Cifuentes * (C) Cristina Cifuentes
****************************************************************************/ ****************************************************************************/
#include <llvm/Support/PatternMatch.h>
#include <boost/iterator/filter_iterator.hpp>
#include <cstring> #include <cstring>
#include <deque> #include <deque>
#include "idiom.h" #include "idiom.h"
@ -15,8 +17,6 @@
#include "shift_idioms.h" #include "shift_idioms.h"
#include "arith_idioms.h" #include "arith_idioms.h"
#include "dcc.h" #include "dcc.h"
#include <llvm/Support/PatternMatch.h>
#include <boost/iterator/filter_iterator.hpp>
/***************************************************************************** /*****************************************************************************
* JmpInst - Returns true if opcode is a conditional or unconditional jump * JmpInst - Returns true if opcode is a conditional or unconditional jump
****************************************************************************/ ****************************************************************************/
@ -116,7 +116,7 @@ void Function::findIdioms()
case iCALL: case iCALLF: case iCALL: case iCALLF:
/* Check for library functions that return a long register. /* Check for library functions that return a long register.
* Propagate this result */ * Propagate this result */
if (pIcode->ll()->src().proc.proc != 0) if (pIcode->ll()->src().proc.proc != nullptr)
if ((pIcode->ll()->src().proc.proc->flg & PROC_ISLIB) && if ((pIcode->ll()->src().proc.proc->flg & PROC_ISLIB) &&
(pIcode->ll()->src().proc.proc->flg & PROC_IS_FUNC)) (pIcode->ll()->src().proc.proc->flg & PROC_IS_FUNC))
{ {

View File

@ -27,6 +27,7 @@ bool Idiom14::match(iICODE pIcode)
return false; return false;
m_icodes[0]=pIcode++; m_icodes[0]=pIcode++;
m_icodes[1]=pIcode++; m_icodes[1]=pIcode++;
LLInst * matched [] = {m_icodes[0]->ll(),m_icodes[1]->ll()};
/* Check for regL */ /* Check for regL */
m_regL = m_icodes[0]->ll()->m_dst.regi; m_regL = m_icodes[0]->ll()->m_dst.regi;
if (not m_icodes[0]->ll()->testFlags(I) && ((m_regL == rAX) || (m_regL ==rBX))) if (not m_icodes[0]->ll()->testFlags(I) && ((m_regL == rAX) || (m_regL ==rBX)))
@ -105,7 +106,7 @@ int Idiom13::action()
eReg regi = m_icodes[0]->ll()->m_dst.regi; eReg regi = m_icodes[0]->ll()->m_dst.regi;
m_icodes[0]->du1.removeDef(regi); m_icodes[0]->du1.removeDef(regi);
//m_icodes[0]->du1.numRegsDef--; /* prev uint8_t reg def */ //m_icodes[0]->du1.numRegsDef--; /* prev uint8_t reg def */
lhs = new RegisterNode(m_loaded_reg, 0, &m_func->localId); lhs = new RegisterNode(LLOperand(m_loaded_reg, 0), &m_func->localId);
m_icodes[0]->setRegDU( m_loaded_reg, eDEF); m_icodes[0]->setRegDU( m_loaded_reg, eDEF);
rhs = AstIdent::id (*m_icodes[0]->ll(), SRC, m_func, m_icodes[0], *m_icodes[0], NONE); rhs = AstIdent::id (*m_icodes[0]->ll(), SRC, m_func, m_icodes[0], *m_icodes[0], NONE);
m_icodes[0]->setAsgn(lhs, rhs); m_icodes[0]->setAsgn(lhs, rhs);

View File

@ -97,7 +97,7 @@ int Idiom16::action()
{ {
AstIdent *lhs; AstIdent *lhs;
Expr *rhs; Expr *rhs;
lhs = new RegisterNode(m_icodes[0]->ll()->m_dst.regi, m_icodes[0]->ll()->getFlag(),&m_func->localId); lhs = new RegisterNode(*m_icodes[0]->ll()->get(DST),&m_func->localId);
rhs = UnaryOperator::Create(NEGATION, lhs->clone()); rhs = UnaryOperator::Create(NEGATION, lhs->clone());
m_icodes[0]->setAsgn(lhs, rhs); m_icodes[0]->setAsgn(lhs, rhs);
m_icodes[1]->invalidate(); m_icodes[1]->invalidate();

View File

@ -81,9 +81,7 @@ int Idiom15::action()
AstIdent *lhs; AstIdent *lhs;
Expr *rhs,*_exp; Expr *rhs,*_exp;
lhs = new RegisterNode(m_icodes[0]->ll()->m_dst.regi, lhs = new RegisterNode(*m_icodes[0]->ll()->get(DST), &m_func->localId);
m_icodes[0]->ll()->getFlag() & NO_SRC_B,
&m_func->localId);
rhs = new Constant(m_icodes.size(), 2); rhs = new Constant(m_icodes.size(), 2);
_exp = new BinaryOperator(SHL,lhs, rhs); _exp = new BinaryOperator(SHL,lhs, rhs);
m_icodes[0]->setAsgn(lhs, _exp); m_icodes[0]->setAsgn(lhs, _exp);
@ -159,7 +157,7 @@ int Idiom9::action()
{ {
int idx; int idx;
AstIdent *lhs; AstIdent *lhs;
Expr *rhs,*expr; Expr *expr;
eReg regH,regL; eReg regH,regL;
regL=m_icodes[1]->ll()->m_dst.regi; regL=m_icodes[1]->ll()->m_dst.regi;
regH=m_icodes[0]->ll()->m_dst.regi; regH=m_icodes[0]->ll()->m_dst.regi;

54
src/liveness_set.cpp Normal file
View File

@ -0,0 +1,54 @@
#include "BasicBlock.h"
#include "machine_x86.h"
/* DU bit definitions for each reg value - including index registers */
LivenessSet duReg[] = { {},
//AH AL . . AX, BH
{rAH,rAL,rAX},{rCH,rCL,rCX},{rDH,rDL,rDX},{rBH,rBL,rBX},
/* uint16_t regs */
{rSP},{rBP},{rSI},{rDI},
/* seg regs */
{rES},{rCS},{rSS},{rDS},
/* uint8_t regs */
{rAL},{rCL},{rDL},{rBL},
{rAH},{rCH},{rDH},{rBH},
/* tmp reg */
{rTMP},{rTMP2},
/* index regs */
{rBX,rSI},{rBX,rDI},{rBP,rSI},{rBP,rDI},
{rSI},{rDI},{rBP},{rBX}
};
LivenessSet &LivenessSet::setReg(int r)
{
this->reset();
*this |= duReg[r];
return *this;
}
LivenessSet &LivenessSet::clrReg(int r)
{
return *this -= duReg[r];
}
LivenessSet &LivenessSet::addReg(int r)
{
*this |= duReg[r];
// postProcessCompositeRegs();
return *this;
}
bool LivenessSet::testRegAndSubregs(int r) const
{
return (*this & duReg[r]).any();
}
void LivenessSet::postProcessCompositeRegs()
{
if(testReg(rAL) and testReg(rAH))
registers.insert(rAX);
if(testReg(rCL) and testReg(rCH))
registers.insert(rCX);
if(testReg(rDL) and testReg(rDH))
registers.insert(rDX);
if(testReg(rBL) and testReg(rBH))
registers.insert(rBX);
}

View File

@ -12,6 +12,7 @@
#include "dcc.h" #include "dcc.h"
#include "project.h" #include "project.h"
#include "CallGraph.h"
using namespace std; using namespace std;
//static void FollowCtrl (Function * pProc, CALL_GRAPH * pcallGraph, STATE * pstate); //static void FollowCtrl (Function * pProc, CALL_GRAPH * pcallGraph, STATE * pstate);
@ -50,7 +51,7 @@ void DccFrontend::parse(Project &proj)
/* We know where main() is. Start the flow of control from there */ /* We know where main() is. Start the flow of control from there */
start_proc.procEntry = prog.offMain; start_proc.procEntry = prog.offMain;
/* In medium and large models, the segment of main may (will?) not be /* In medium and large models, the segment of main may (will?) not be
the same as the initial CS segment (of the startup code) */ the same as the initial CS segment (of the startup code) */
state.setState(rCS, prog.segMain); state.setState(rCS, prog.segMain);
start_proc.name = "main"; start_proc.name = "main";
state.IP = prog.offMain; state.IP = prog.offMain;
@ -88,7 +89,7 @@ int strSize (const uint8_t *sym, char delim)
const uint8_t *end_ptr=std::find(sym,sym+(prog.cbImage-(till_end)),delim); const uint8_t *end_ptr=std::find(sym,sym+(prog.cbImage-(till_end)),delim);
return end_ptr-sym+1; return end_ptr-sym+1;
} }
Function *fakeproc=Function::Create(0,0,"fake"); Function *fakeproc=Function::Create(nullptr,0,"fake");
/* FollowCtrl - Given an initial procedure, state information and symbol table /* FollowCtrl - Given an initial procedure, state information and symbol table
* builds a list of procedures reachable from the initial procedure * builds a list of procedures reachable from the initial procedure
@ -597,7 +598,7 @@ boolT Function::process_CALL (ICODE & pIcode, CALL_GRAPH * pcallGraph, STATE *ps
} }
/* Address of function is given by 4 (CALLF) or 2 (CALL) bytes at /* Address of function is given by 4 (CALLF) or 2 (CALL) bytes at
* previous offset into the program image */ * previous offset into the program image */
uint32_t tgtAddr=0; uint32_t tgtAddr=0;
if (pIcode.ll()->getOpcode() == iCALLF) 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);

View File

@ -9,6 +9,7 @@
#include <cassert> #include <cassert>
#include "dcc.h" #include "dcc.h"
#include "project.h" #include "project.h"
#include "CallGraph.h"
extern Project g_proj; extern Project g_proj;
/* Static indentation buffer */ /* Static indentation buffer */
@ -123,7 +124,7 @@ void LOCAL_ID::newRegArg(iICODE picode, iICODE ticode) const
for(STKSYM &tgt_sym : *target_stackframe) for(STKSYM &tgt_sym : *target_stackframe)
{ {
RegisterNode *tgt_sym_regs = dynamic_cast<RegisterNode *>(tgt_sym.regs); RegisterNode *tgt_sym_regs = dynamic_cast<RegisterNode *>(tgt_sym.regs);
if( tgt_sym_regs == NULL ) // both REGISTER and LONG_VAR require this precondition if( tgt_sym_regs == nullptr ) // both REGISTER and LONG_VAR require this precondition
continue; continue;
if ( tgt_sym_regs->regiIdx == tidx ) if ( tgt_sym_regs->regiIdx == tidx )
{ {
@ -142,7 +143,7 @@ void LOCAL_ID::newRegArg(iICODE picode, iICODE ticode) const
/* Check if register argument already on the formal argument list */ /* Check if register argument already on the formal argument list */
for(STKSYM &tgt_sym : *target_stackframe) for(STKSYM &tgt_sym : *target_stackframe)
{ {
if( tgt_sym.regs == NULL ) // both REGISTER and LONG_VAR require this precondition if( tgt_sym.regs == nullptr ) // both REGISTER and LONG_VAR require this precondition
continue; continue;
if ( tgt_sym.regs->ident.idNode.longIdx == tidx ) if ( tgt_sym.regs->ident.idNode.longIdx == tidx )
{ {
@ -273,7 +274,7 @@ Expr *Function::adjustActArgType (Expr *_exp, hlType forType)
hlType actType; hlType actType;
int offset, offL; int offset, offL;
if (expr == NULL) if (expr == nullptr)
return _exp; return _exp;
actType = expr-> expType (this); actType = expr-> expType (this);

View File

@ -9,7 +9,7 @@ SYMTAB symtab; /* Global symbol table */
STATS stats; /* cfg statistics */ STATS stats; /* cfg statistics */
//PROG prog; /* programs fields */ //PROG prog; /* programs fields */
OPTION option; /* Command line options */ OPTION option; /* Command line options */
Project *Project::s_instance = 0; Project *Project::s_instance = nullptr;
Project::Project() : callGraph(nullptr) Project::Project() : callGraph(nullptr)
{ {
memset(&prog,0,sizeof(prog)); memset(&prog,0,sizeof(prog));
@ -94,7 +94,7 @@ const std::string &Project::symbolName(size_t idx)
Project *Project::get() Project *Project::get()
{ {
//WARNING: poor man's singleton, not thread safe //WARNING: poor man's singleton, not thread safe
if(s_instance==0) if(s_instance==nullptr)
s_instance=new Project; s_instance=new Project;
return s_instance; return s_instance;
} }

View File

@ -352,7 +352,7 @@ int Function::findBackwarLongDefs(int loc_ident_idx, const ID &pLocId, iICODE be
icode.setRegDU( pmH->regi, eDEF); icode.setRegDU( pmH->regi, eDEF);
icode.setUnary(HLI_POP, asgn.lhs); icode.setUnary(HLI_POP, asgn.lhs);
next1->invalidate(); next1->invalidate();
asgn.lhs=0; asgn.lhs=nullptr;
forced_finish=true; /* to exit the loop */ forced_finish=true; /* to exit the loop */
} }
break; break;

View File

@ -54,7 +54,7 @@ BB *interval::firstOfInt ()
{ {
auto pq = currNode; auto pq = currNode;
if (pq == nodes.end()) if (pq == nodes.end())
return 0; return nullptr;
++currNode; ++currNode;
return *pq; return *pq;
} }
@ -108,7 +108,7 @@ void derSeq_Entry::findIntervals (Function *c)
appendQueue (H, Gi); /* H = {first node of G} */ appendQueue (H, Gi); /* H = {first node of G} */
Gi->beenOnH = true; Gi->beenOnH = true;
Gi->reachingInt = BB::Create(0,"",c); /* ^ empty BB */ Gi->reachingInt = BB::Create(nullptr,"",c); /* ^ empty BB */
/* Process header nodes list H */ /* Process header nodes list H */
while (!H.empty()) while (!H.empty())
@ -124,15 +124,15 @@ void derSeq_Entry::findIntervals (Function *c)
pI->appendNodeInt (H, header); /* pI(header) = {header} */ pI->appendNodeInt (H, header); /* pI(header) = {header} */
/* Process all nodes in the current interval list */ /* Process all nodes in the current interval list */
while ((h = pI->firstOfInt()) != NULL) while ((h = pI->firstOfInt()) != nullptr)
{ {
/* Check all immediate successors of h */ /* Check all immediate successors of h */
for (size_t i = 0; i < h->edges.size(); i++) for (auto & elem : h->edges)
{ {
succ = h->edges[i].BBptr; succ = elem.BBptr;
succ->inEdgeCount--; succ->inEdgeCount--;
if (succ->reachingInt == NULL) /* first visit */ if (succ->reachingInt == nullptr) /* first visit */
{ {
succ->reachingInt = header; succ->reachingInt = header;
if (succ->inEdgeCount == 0) if (succ->inEdgeCount == 0)
@ -182,7 +182,7 @@ static void displayIntervals (interval *pI)
printf (" Interval #: %d\t#OutEdges: %d\n", pI->numInt, pI->numOutEdges); printf (" Interval #: %d\t#OutEdges: %d\n", pI->numInt, pI->numOutEdges);
for(BB *node : pI->nodes) for(BB *node : pI->nodes)
{ {
if (node->correspInt == NULL) /* real BBs */ if (node->correspInt == nullptr) /* real BBs */
printf (" Node: %d\n", node->begin()->loc_ip); printf (" Node: %d\n", node->begin()->loc_ip);
else // BBs represent intervals else // BBs represent intervals
printf (" Node (corresp int): %d\n", node->correspInt->numInt); printf (" Node (corresp int): %d\n", node->correspInt->numInt);
@ -248,7 +248,7 @@ bool Function::nextOrderGraph (derSeq &derivedGi)
derSeq_Entry &new_entry(derivedGi.back()); derSeq_Entry &new_entry(derivedGi.back());
sameGraph = true; sameGraph = true;
BBnode = 0; BBnode = nullptr;
std::vector<BB *> bbs; std::vector<BB *> bbs;
for(Ii = prev_entry.Ii; Ii != nullptr; Ii = Ii->next) for(Ii = prev_entry.Ii; Ii != nullptr; Ii = Ii->next)
{ {

View File

@ -64,7 +64,7 @@ static struct {
{ data1, axImp, B , iADD }, /* 04 */ { data1, axImp, B , iADD }, /* 04 */
{ data2, axImp, 0 , iADD }, /* 05 */ { data2, axImp, 0 , iADD }, /* 05 */
{ segop, none2, NO_SRC , iPUSH }, /* 06 */ { segop, none2, NO_SRC , iPUSH }, /* 06 */
{ segop, none2, NO_SRC , iPOP }, /* 07 */ { segop, none2, NO_SRC , iPOP }, /* 07 */
{ modrm, none2, B , iOR }, /* 08 */ { modrm, none2, B , iOR }, /* 08 */
{ modrm, none2, NSP , iOR }, /* 09 */ { modrm, none2, NSP , iOR }, /* 09 */
{ modrm, none2, TO_REG | B , iOR }, /* 0A */ { modrm, none2, TO_REG | B , iOR }, /* 0A */
@ -96,7 +96,7 @@ static struct {
{ data1, axImp, B , iAND }, /* 24 */ { data1, axImp, B , iAND }, /* 24 */
{ data2, axImp, 0 , iAND }, /* 25 */ { data2, axImp, 0 , iAND }, /* 25 */
{ prefix, none2, 0 , (IC)rES}, /* 26 */ { prefix, none2, 0 , (IC)rES}, /* 26 */
{ none1, axImp, NOT_HLL | B|NO_SRC , iDAA }, /* 27 */ { none1, axImp, NOT_HLL | B|NO_SRC , iDAA }, /* 27 */
{ modrm, none2, B , iSUB }, /* 28 */ { modrm, none2, B , iSUB }, /* 28 */
{ modrm, none2, 0 , iSUB }, /* 29 */ { modrm, none2, 0 , iSUB }, /* 29 */
{ modrm, none2, TO_REG | B , iSUB }, /* 2A */ { modrm, none2, TO_REG | B , iSUB }, /* 2A */
@ -133,7 +133,7 @@ static struct {
{ regop, none2, 0 , iDEC }, /* 49 */ { regop, none2, 0 , iDEC }, /* 49 */
{ regop, none2, 0 , iDEC }, /* 4A */ { regop, none2, 0 , iDEC }, /* 4A */
{ regop, none2, 0 , iDEC }, /* 4B */ { regop, none2, 0 , iDEC }, /* 4B */
{ regop, none2, NOT_HLL , iDEC }, /* 4C */ { regop, none2, NOT_HLL , iDEC }, /* 4C */
{ regop, none2, 0 , iDEC }, /* 4D */ { regop, none2, 0 , iDEC }, /* 4D */
{ regop, none2, 0 , iDEC }, /* 4E */ { regop, none2, 0 , iDEC }, /* 4E */
{ regop, none2, 0 , iDEC }, /* 4F */ { regop, none2, 0 , iDEC }, /* 4F */
@ -450,7 +450,7 @@ LLOperand convertExpression(const x86_ea_t &from)
{ {
eReg base_reg = convertRegister(from.base); eReg base_reg = convertRegister(from.base);
eReg index_reg = convertRegister(from.index); eReg index_reg = convertRegister(from.index);
// if(base_reg==rBX) // if(base_reg==rBX)
switch(base_reg) switch(base_reg)
{ {
case rDI: case rDI:
@ -566,8 +566,8 @@ eErrorId scan(uint32_t ip, ICODE &p)
if(p.insn.x86_get_branch_target()) if(p.insn.x86_get_branch_target())
decodeBranchTgt(p.insn); decodeBranchTgt(p.insn);
} }
// LLOperand conv = convertOperand(*p.insn.get_dest()); // LLOperand conv = convertOperand(*p.insn.get_dest());
// assert(conv==p.ll()->dst); // assert(conv==p.ll()->dst);
if (p.ll()->getOpcode()) if (p.ll()->getOpcode())
{ {
/* Save bytes of image used */ /* Save bytes of image used */
@ -626,14 +626,12 @@ static int signex(uint8_t b)
***************************************************************************/ ***************************************************************************/
static void setAddress(int i, bool fdst, uint16_t seg, int16_t reg, uint16_t off) static void setAddress(int i, bool fdst, uint16_t seg, int16_t reg, uint16_t off)
{ {
LLOperand *pm;
/* If not to register (i.e. to r/m), and talking about r/m, then this is dest */ /* If not to register (i.e. to r/m), and talking about r/m, then this is dest */
pm = (!(stateTable[i].flg & TO_REG) == fdst) ? LLOperand *pm = (!(stateTable[i].flg & TO_REG) == fdst) ? &pIcode->ll()->m_dst : &pIcode->ll()->src();
&pIcode->ll()->m_dst : &pIcode->ll()->src();
/* Set segment. A later procedure (lookupAddr in proclist.c) will /* Set segment. A later procedure (lookupAddr in proclist.c) will
* provide the value of this segment in the field segValue. */ * provide the value of this segment in the field segValue.
*/
if (seg) /* segment override */ if (seg) /* segment override */
{ {
pm->seg = pm->segOver = (eReg)seg; pm->seg = pm->segOver = (eReg)seg;
@ -733,7 +731,7 @@ static void segrm(int i)
***************************************************************************/ ***************************************************************************/
static void regop(int i) static void regop(int i)
{ {
setAddress(i, false, 0, ((int16_t)i & 7) + rAX, 0); setAddress(i, false, 0, ((int16_t)i & 0x7) + rAX, 0);
pIcode->ll()->replaceDst(pIcode->ll()->src()); pIcode->ll()->replaceDst(pIcode->ll()->src());
} }
@ -743,6 +741,9 @@ static void regop(int i)
*****************************************************************************/ *****************************************************************************/
static void segop(int i) static void segop(int i)
{ {
if(i==0x1E) {
printf("es");
}
setAddress(i, true, 0, (((int16_t)i & 0x18) >> 3) + rES, 0); setAddress(i, true, 0, (((int16_t)i & 0x18) >> 3) + rES, 0);
} }
@ -837,10 +838,13 @@ static void trans(int i)
{ {
static llIcode transTable[8] = static llIcode transTable[8] =
{ {
(llIcode)iINC, (llIcode)iDEC, (llIcode)iCALL, (llIcode)iCALLF, (llIcode)iINC, iDEC, (llIcode)iCALL, (llIcode)iCALLF,
(llIcode)iJMP, (llIcode)iJMPF,(llIcode)iPUSH, (llIcode)0 (llIcode)iJMP, (llIcode)iJMPF,(llIcode)iPUSH, (llIcode)0
}; };
LLInst *ll = pIcode->ll(); LLInst *ll = pIcode->ll();
if(transTable[REG(*pInst)]==iPUSH) {
printf("es");
}
if ((uint8_t)REG(*pInst) < 2 || !(stateTable[i].flg & B)) { /* INC & DEC */ if ((uint8_t)REG(*pInst) < 2 || !(stateTable[i].flg & B)) { /* INC & DEC */
ll->setOpcode(transTable[REG(*pInst)]); /* valid on bytes */ ll->setOpcode(transTable[REG(*pInst)]); /* valid on bytes */
rm(i); rm(i);
@ -895,7 +899,7 @@ static void arith(int i)
*****************************************************************************/ *****************************************************************************/
static void data1(int i) static void data1(int i)
{ {
pIcode->ll()->replaceSrc(LLOperand::CreateImm2((stateTable[i].flg & S_EXT)? signex(*pInst++): *pInst++)); pIcode->ll()->replaceSrc(LLOperand::CreateImm2((stateTable[i].flg & S_EXT)? signex(*pInst++): *pInst++,1));
pIcode->ll()->setFlags(I); pIcode->ll()->setFlags(I);
} }
@ -937,6 +941,7 @@ static void dispM(int i)
****************************************************************************/ ****************************************************************************/
static void dispN(int ) static void dispN(int )
{ {
//PROG &prog(Project::get()->prog); //PROG &prog(Project::get()->prog);
/*long off = (short)*/getWord(); /* Signed displacement */ /*long off = (short)*/getWord(); /* Signed displacement */
@ -961,10 +966,11 @@ static void dispS(int )
/**************************************************************************** /****************************************************************************
dispF - 4 byte disp as immed 20-bit target address dispF - 4 byte disp as immed 20-bit target address
***************************************************************************/ ***************************************************************************/
static void dispF(int ) static void dispF(int i)
{ {
/*off = */(unsigned)getWord(); uint16_t off = (unsigned)getWord();
/*seg = */(unsigned)getWord(); uint16_t seg = (unsigned)getWord();
setAddress(i, true, seg, 0, off);
// decodeBranchTgt(); // decodeBranchTgt();
} }

View File

@ -53,7 +53,7 @@ struct TABLEINFO_TYPE
{ {
TABLEINFO_TYPE() TABLEINFO_TYPE()
{ {
symTab=valTab=0; symTab=valTab=nullptr;
} }
//void deleteVal(uint32_t symOff, Function *symProc, boolT bSymToo); //void deleteVal(uint32_t symOff, Function *symProc, boolT bSymToo);
void create(tableType type); void create(tableType type);
@ -80,7 +80,7 @@ void TABLEINFO_TYPE::create(tableType type)
numEntry = 0; numEntry = 0;
tableSize = TABLESIZE; tableSize = TABLESIZE;
valTab = new SYMTABLE [TABLESIZE]; valTab = new SYMTABLE [TABLESIZE];
symTab = 0; symTab = nullptr;
break; break;
case Label: case Label:
currentTabInfo.numEntry = 0; currentTabInfo.numEntry = 0;

View File

@ -44,7 +44,7 @@ void Function::controlFlowAnalysis()
{ {
if (flg & PROC_ISLIB) if (flg & PROC_ISLIB)
return; /* Ignore library functions */ return; /* Ignore library functions */
derSeq *derivedG=0; derSeq *derivedG=nullptr;
/* Make cfg reducible and build derived sequences */ /* Make cfg reducible and build derived sequences */
derivedG=checkReducibility(); derivedG=checkReducibility();