replace boolT with plain old bool in a few places
This commit is contained in:
parent
5c7799b778
commit
1c5e1c2fce
@ -113,11 +113,11 @@ SOURCE_GROUP(Source FILES ${dcc_SOURCES})
|
||||
SOURCE_GROUP(Headers FILES ${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_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)
|
||||
ADD_SUBDIRECTORY(src)
|
||||
endif()
|
||||
|
||||
2762
CMakeScripts/cotire.cmake
Normal file
2762
CMakeScripts/cotire.cmake
Normal file
File diff suppressed because it is too large
Load Diff
@ -117,7 +117,7 @@ public:
|
||||
void findBBExps(LOCAL_ID &locals, Function *f);
|
||||
bool valid() {return 0==(flg & INVALID_BB); }
|
||||
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
|
||||
{
|
||||
edges.push_back(TYPEADR_TYPE(ip));
|
||||
|
||||
@ -177,7 +177,7 @@ enum llIcode
|
||||
iPOP,
|
||||
iPOPA,
|
||||
iPOPF,
|
||||
iPUSH,
|
||||
iPUSH, // 77
|
||||
iPUSHA,
|
||||
iPUSHF,
|
||||
iRCL, /* 80 */
|
||||
|
||||
@ -13,6 +13,7 @@ struct Expr;
|
||||
struct Disassembler;
|
||||
struct Function;
|
||||
struct CALL_GRAPH;
|
||||
struct PROG;
|
||||
|
||||
typedef llvm::iplist<Function> FunctionListType;
|
||||
typedef FunctionListType lFunction;
|
||||
@ -189,6 +190,7 @@ public:
|
||||
void preprocessReturnDU(LivenessSet &_liveOut);
|
||||
Expr * adjustActArgType(Expr *_exp, hlType forType);
|
||||
std::string writeCall(Function *tproc, STKFRAME &args, int *numLoc);
|
||||
void processDosInt(STATE *pstate, PROG &prog, bool done);
|
||||
protected:
|
||||
void extractJumpTableRange(ICODE& pIcode, STATE *pstate, JumpTable &table);
|
||||
bool followAllTableEntries(JumpTable &table, uint32_t cs, ICODE &pIcode, CALL_GRAPH *pcallGraph, STATE *pstate);
|
||||
|
||||
@ -29,6 +29,7 @@ struct STKFRAME;
|
||||
struct LOCAL_ID;
|
||||
struct ICODE;
|
||||
struct LLInst;
|
||||
struct LLOperand;
|
||||
struct ID;
|
||||
typedef std::list<ICODE>::iterator iICODE;
|
||||
typedef boost::iterator_range<iICODE> rICODE;
|
||||
@ -291,6 +292,7 @@ struct RegisterNode : public AstIdent
|
||||
regiType = reg_type;
|
||||
regiIdx = idx;
|
||||
}
|
||||
RegisterNode(const LLOperand &, LOCAL_ID *locsym);
|
||||
|
||||
RegisterNode(eReg regi, uint32_t icodeFlg, LOCAL_ID *locsym);
|
||||
virtual Expr *clone() const
|
||||
|
||||
@ -22,22 +22,6 @@
|
||||
#include "BasicBlock.h"
|
||||
class Project;
|
||||
/* 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 */
|
||||
|
||||
/**** Global variables ****/
|
||||
@ -121,8 +105,8 @@ bool LibCheck(Function &p); /* chklib.c */
|
||||
boolT insertCallGraph (CALL_GRAPH *, ilFunction, ilFunction);
|
||||
|
||||
/* Exported functions from hlicode.c */
|
||||
char *writeJcond (const HLTYPE &, Function *, int *);
|
||||
char *writeJcondInv (HLTYPE, Function *, int *);
|
||||
const char *writeJcond(const HLTYPE &, Function *, int *);
|
||||
const char *writeJcondInv (HLTYPE, Function *, int *);
|
||||
|
||||
|
||||
/* Exported funcions from locident.c */
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
#include <llvm/ADT/ilist.h>
|
||||
#include <llvm/ADT/ilist_node.h>
|
||||
#include <llvm/MC/MCInst.h>
|
||||
#include <llvm/Instruction.h>
|
||||
#include <llvm/IR/Instruction.h>
|
||||
#include <boost/range/iterator_range.hpp>
|
||||
#include "libdis.h"
|
||||
#include "Enums.h"
|
||||
@ -252,16 +252,26 @@ struct LLOperand
|
||||
eReg regi; /* 0 < regs < INDEXBASE <= index modes */
|
||||
int16_t off; /* memory address offset */
|
||||
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) */
|
||||
struct { /* Call & # actual arg bytes */
|
||||
Function *proc; /* pointer to target proc (for CALL(F))*/
|
||||
int cb; /* # actual arg bytes */
|
||||
} 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.cb=0;
|
||||
}
|
||||
LLOperand(eReg r,size_t w) : LLOperand()
|
||||
{
|
||||
regi=r;
|
||||
width=w;
|
||||
}
|
||||
bool operator==(const LLOperand &with) const
|
||||
{
|
||||
return (seg==with.seg) &&
|
||||
@ -279,12 +289,12 @@ struct LLOperand
|
||||
}
|
||||
eReg getReg2() const {return regi;}
|
||||
bool isReg() const;
|
||||
static LLOperand CreateImm2(int64_t Val)
|
||||
static LLOperand CreateImm2(int64_t Val,uint8_t wdth=2)
|
||||
{
|
||||
LLOperand Op;
|
||||
//Op.Kind = kImmediate;
|
||||
//Op.ImmVal = Val;
|
||||
Op.immed=true;
|
||||
Op.opz = Val;
|
||||
Op.width = wdth;
|
||||
return Op;
|
||||
}
|
||||
static LLOperand CreateReg2(unsigned Val)
|
||||
@ -298,6 +308,10 @@ struct LLOperand
|
||||
return not (*this == LLOperand());
|
||||
}
|
||||
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>
|
||||
{
|
||||
|
||||
@ -4,6 +4,10 @@
|
||||
#include <cassert>
|
||||
#include <list>
|
||||
#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 "BinaryImage.h"
|
||||
#include "Procedure.h"
|
||||
|
||||
@ -33,7 +33,7 @@ struct STATE
|
||||
void setMemoryByte(uint32_t addr,uint8_t val)
|
||||
{
|
||||
//TODO: make this into a full scale value tracking class !
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -66,7 +66,7 @@ void BB::display()
|
||||
|
||||
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);
|
||||
else
|
||||
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 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];
|
||||
std::ostringstream ostr;
|
||||
@ -192,8 +192,8 @@ void BB::writeCode (int indLevel, Function * pProc , int *numLoc,int _latchNode,
|
||||
int follow; /* ifFollow */
|
||||
BB * succ, *latch; /* Successor and latching node */
|
||||
ICODE * picode; /* Pointer to HLI_JCOND instruction */
|
||||
char *l; /* Pointer to HLI_JCOND expression */
|
||||
boolT emptyThen, /* THEN clause is empty */
|
||||
std::string l; /* Pointer to HLI_JCOND expression */
|
||||
bool emptyThen, /* THEN clause is empty */
|
||||
repCond; /* Repeat condition for while() */
|
||||
|
||||
/* 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 */
|
||||
repCond = false;
|
||||
latch = NULL;
|
||||
latch = nullptr;
|
||||
if (loopType)
|
||||
{
|
||||
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 */
|
||||
{
|
||||
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);
|
||||
}
|
||||
else /* empty THEN part => negate ELSE part */
|
||||
{
|
||||
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);
|
||||
emptyThen = true;
|
||||
}
|
||||
@ -345,7 +345,7 @@ void BB::writeCode (int indLevel, Function * pProc , int *numLoc,int _latchNode,
|
||||
else /* no follow => if..then..else */
|
||||
{
|
||||
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);
|
||||
cCode.appendCode( "%s}\n%selse {\n", indentStr(indLevel-1), indentStr(indLevel - 1));
|
||||
edges[ELSE].BBptr->writeCode (indLevel, pProc, numLoc, _latchNode, _ifFollow);
|
||||
|
||||
119
src/RegisterNode.cpp
Normal file
119
src/RegisterNode.cpp
Normal 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;
|
||||
}
|
||||
18
src/ast.cpp
18
src/ast.cpp
@ -298,7 +298,7 @@ Expr *AstIdent::id(const LLInst &ll_insn, opLoc sd, Function * pProc, iICODE ix_
|
||||
|
||||
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
|
||||
((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))
|
||||
{ /* implicit tmp */
|
||||
newExp = new RegisterNode(rTMP, 0, &pProc->localId);
|
||||
newExp = new RegisterNode(LLOperand(rTMP,2), &pProc->localId);
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
@ -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_BX: selected = rBX; break;
|
||||
default:
|
||||
newExp = 0;
|
||||
newExp = nullptr;
|
||||
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);
|
||||
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
|
||||
{
|
||||
if (this == NULL)
|
||||
if (this == nullptr)
|
||||
return (2); /* for TYPE_UNKNOWN */
|
||||
fprintf(stderr,"hlTypeSize queried for Unkown type %d \n",m_type);
|
||||
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)
|
||||
{
|
||||
|
||||
if (tree == NULL)
|
||||
if (tree == nullptr)
|
||||
return false;
|
||||
Expr *temp=tree->insertSubTreeReg(_expr,regi,locsym);
|
||||
if(nullptr!=temp)
|
||||
@ -775,7 +777,7 @@ Expr *AstIdent::insertSubTreeReg(Expr *_expr, eReg regi, const LOCAL_ID *locsym)
|
||||
* long register index longIdx*/
|
||||
bool Expr::insertSubTreeLongReg(Expr *_expr, Expr *&tree, int longIdx)
|
||||
{
|
||||
if (tree == NULL)
|
||||
if (tree == nullptr)
|
||||
return false;
|
||||
Expr *temp=tree->insertSubTreeLongReg(_expr,longIdx);
|
||||
if(nullptr!=temp)
|
||||
|
||||
@ -10,14 +10,15 @@
|
||||
#include <boost/range/adaptors.hpp>
|
||||
#include <boost/range/algorithm.hpp>
|
||||
|
||||
#include "dcc.h"
|
||||
#include "disassem.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "dcc.h"
|
||||
#include "disassem.h"
|
||||
#include "project.h"
|
||||
#include "CallGraph.h"
|
||||
using namespace boost;
|
||||
using namespace boost::adaptors;
|
||||
bundle cCode; /* Procedure declaration and code */
|
||||
@ -318,9 +319,9 @@ static void backBackEnd (CALL_GRAPH * pcallGraph, std::ostream &_ios)
|
||||
pcallGraph->proc->flg |= PROC_OUTPUT;
|
||||
|
||||
/* 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 */
|
||||
|
||||
@ -56,7 +56,7 @@ static uint16_t *T1base, *T2base; /* Pointers to start of T1, T2 */
|
||||
static uint16_t *g; /* g[] */
|
||||
static HT *ht; /* The hash table */
|
||||
static PH_FUNC_STRUCT *pFunc; /* Points to the array of func names */
|
||||
static hlType *pArg=0; /* Points to the array of param types */
|
||||
static hlType *pArg=nullptr; /* Points to the array of param types */
|
||||
static int numFunc; /* Number of func names actually stored */
|
||||
static int numArg; /* Number of param names actually stored */
|
||||
#define DCCLIBS "dcclibs.dat" /* Name of the prototypes data file */
|
||||
@ -302,7 +302,7 @@ void SetupLibCheck(void)
|
||||
uint16_t w, len;
|
||||
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);
|
||||
return;
|
||||
@ -392,7 +392,7 @@ void SetupLibCheck(void)
|
||||
/* This is now the hash table */
|
||||
/* First allocate space for the table */
|
||||
ht = new HT[numKeys];
|
||||
if ( 0 == ht)
|
||||
if ( nullptr == ht)
|
||||
{
|
||||
printf("Could not allocate hash table\n");
|
||||
exit(1);
|
||||
@ -457,6 +457,8 @@ bool LibCheck(Function & pProc)
|
||||
pProc.name = "main";
|
||||
return false;
|
||||
}
|
||||
if(fileOffset + PATLEN > prog.cbImage)
|
||||
return false;
|
||||
memcpy(pat, &prog.image()[fileOffset], PATLEN);
|
||||
//memmove(pat, &prog.image()[fileOffset], PATLEN);
|
||||
fixWildCards(pat); /* Fix wild cards in the copy */
|
||||
@ -888,7 +890,7 @@ void readProtoFile(void)
|
||||
}
|
||||
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);
|
||||
return;
|
||||
|
||||
@ -276,13 +276,13 @@ void Function::structLoops(derSeq *derivedG)
|
||||
|
||||
/* Structure loops */
|
||||
/* for all derived sequences Gi */
|
||||
for(derSeq::iterator iter=derivedG->begin(); iter!=derivedG->end(); ++iter)
|
||||
for(auto & elem : *derivedG)
|
||||
{
|
||||
level++;
|
||||
Ii = iter->Ii;
|
||||
Ii = elem.Ii;
|
||||
while (Ii) /* for all intervals Ii of Gi */
|
||||
{
|
||||
latchNode = NULL;
|
||||
latchNode = nullptr;
|
||||
intNodes.clear();
|
||||
|
||||
/* Find interval head (original BB node in G1) and create
|
||||
|
||||
@ -93,11 +93,11 @@ size_t STKFRAME::getLocVar(int off)
|
||||
/* Returns a string with the source operand of Icode */
|
||||
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))
|
||||
return new Constant(ll_insn.src().getImm2(), 1);
|
||||
return new Constant(ll_insn.src().getImm2(), 2);
|
||||
//if (ll_insn.testFlags(B))
|
||||
return new Constant(src_op->getImm2(), src_op->byteWidth());
|
||||
}
|
||||
// otherwise
|
||||
return AstIdent::id (ll_insn, SRC, pProc, i, duIcode, du);
|
||||
@ -148,6 +148,8 @@ void Function::elimCondCodes ()
|
||||
if ((use & def) != use)
|
||||
continue;
|
||||
notSup = false;
|
||||
LLOperand *dest_ll = defAt->ll()->get(DST);
|
||||
LLOperand *src_ll = defAt->ll()->get(SRC);
|
||||
if ((useAtOp >= iJB) && (useAtOp <= iJNS))
|
||||
{
|
||||
iICODE befDefAt = (++riICODE(defAt)).base();
|
||||
@ -161,29 +163,22 @@ void Function::elimCondCodes ()
|
||||
case iOR:
|
||||
lhs = defAt->hl()->asgn.lhs()->clone();
|
||||
useAt->copyDU(*defAt, eUSE, eDEF);
|
||||
if (defAt->ll()->testFlags(B))
|
||||
rhs = new Constant(0, 1);
|
||||
else
|
||||
rhs = new Constant(0, 2);
|
||||
//if (defAt->ll()->testFlags(B))
|
||||
rhs = new Constant(0, dest_ll->byteWidth());
|
||||
break;
|
||||
|
||||
case iTEST:
|
||||
rhs = srcIdent (*defAt->ll(),this, befDefAt,*useAt, eUSE);
|
||||
lhs = dstIdent (*defAt->ll(),this, befDefAt,*useAt, eUSE);
|
||||
lhs = BinaryOperator::And(lhs, rhs);
|
||||
if (defAt->ll()->testFlags(B))
|
||||
rhs = new Constant(0, 1);
|
||||
else
|
||||
rhs = new Constant(0, 2);
|
||||
// if (defAt->ll()->testFlags(B))
|
||||
rhs = new Constant(0, dest_ll->byteWidth());
|
||||
break;
|
||||
case iINC:
|
||||
case iDEC: //WARNING: verbatim copy from iOR needs fixing ?
|
||||
lhs = defAt->hl()->asgn.lhs()->clone();
|
||||
useAt->copyDU(*defAt, eUSE, eDEF);
|
||||
if (defAt->ll()->testFlags(B))
|
||||
rhs = new Constant(0, 1);
|
||||
else
|
||||
rhs = new Constant(0, 2);
|
||||
rhs = new Constant(0, dest_ll->byteWidth());
|
||||
break;
|
||||
default:
|
||||
notSup = true;
|
||||
@ -202,7 +197,8 @@ void Function::elimCondCodes ()
|
||||
|
||||
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);
|
||||
rhs = new Constant(0, 2);
|
||||
_expr = BinaryOperator::Create(EQUAL,lhs,rhs);
|
||||
@ -514,7 +510,7 @@ void BB::genDU1()
|
||||
/* Process each register definition of a HIGH_LEVEL icode instruction.
|
||||
* Note that register variables should not be considered registers.
|
||||
*/
|
||||
assert(0!=Parent);
|
||||
assert(nullptr!=Parent);
|
||||
ICODE::TypeFilter<HIGH_LEVEL> 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)
|
||||
@ -568,7 +564,7 @@ void LOCAL_ID::forwardSubs (Expr *lhs, Expr *rhs, iICODE picode, iICODE ticode,
|
||||
}
|
||||
RegisterNode * lhs_reg=dynamic_cast<RegisterNode *>(lhs_unary);
|
||||
assert(lhs_reg);
|
||||
if (rhs == NULL) /* In case expression popped is NULL */
|
||||
if (rhs == nullptr) /* In case expression popped is NULL */
|
||||
return;
|
||||
|
||||
/* Insert on rhs of ticode, if possible */
|
||||
@ -607,7 +603,7 @@ static void forwardSubsLong (int longIdx, Expr *_exp, iICODE picode, iICODE tico
|
||||
{
|
||||
bool res;
|
||||
|
||||
if (_exp == NULL) /* In case expression popped is NULL */
|
||||
if (_exp == nullptr) /* In case expression popped is NULL */
|
||||
return;
|
||||
|
||||
/* 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. */
|
||||
bool UnaryOperator::xClear(rICODE range_to_check, iICODE lastBBinst, const LOCAL_ID &locs)
|
||||
{
|
||||
if(0==unaryExp)
|
||||
if(nullptr==unaryExp)
|
||||
return false;
|
||||
return unaryExp->xClear ( range_to_check, lastBBinst, locs);
|
||||
}
|
||||
|
||||
bool BinaryOperator::xClear(rICODE range_to_check, iICODE lastBBinst, const LOCAL_ID &locs)
|
||||
{
|
||||
if(0==m_rhs)
|
||||
if(nullptr==m_rhs)
|
||||
return false;
|
||||
if ( ! m_rhs->xClear (range_to_check, lastBBinst, locs) )
|
||||
return false;
|
||||
if(0==m_lhs)
|
||||
if(nullptr==m_lhs)
|
||||
return false;
|
||||
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(_exp==NULL)
|
||||
if(_exp==nullptr)
|
||||
fprintf(stderr,"Would try to adjustForArgType with null _exp\n");
|
||||
else
|
||||
pp->args.adjustForArgType (numArgs, _exp->expType (pProc));
|
||||
@ -794,7 +790,7 @@ void Function::processHliCall(Expr *_exp, iICODE picode)
|
||||
{
|
||||
if (pp->args.numArgs >0)
|
||||
{
|
||||
if(_exp==NULL)
|
||||
if(_exp==nullptr)
|
||||
{
|
||||
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 *lhs; // exp ptr for return value of a HLI_CALL */
|
||||
iICODE ticode; // Target icode */
|
||||
HLTYPE *ti_hl=0;
|
||||
HLTYPE *ti_hl=nullptr;
|
||||
uint8_t regi;
|
||||
numHlIcodes = 0;
|
||||
// register(s) to be forward substituted */
|
||||
@ -1129,7 +1125,7 @@ void Function::preprocessReturnDU(LivenessSet &_liveOut)
|
||||
// int idx;
|
||||
bool isAx, isBx, isCx, isDx;
|
||||
eReg bad_regs[] = {rES,rCS,rDS,rSS};
|
||||
constexpr char * names[] ={"ES","CS","DS","SS"};
|
||||
constexpr const char * names[] ={"ES","CS","DS","SS"};
|
||||
for(int i=0; i<4; ++i)
|
||||
if(_liveOut.testReg(bad_regs[i]))
|
||||
{
|
||||
|
||||
12
src/dcc.cpp
12
src/dcc.cpp
@ -8,6 +8,7 @@
|
||||
#include "dcc.h"
|
||||
#include "project.h"
|
||||
|
||||
#include "CallGraph.h"
|
||||
/* Global variables - extern to other modules */
|
||||
extern char *asm1_name, *asm2_name; /* Assembler output filenames */
|
||||
extern SYMTAB symtab; /* Global symbol table */
|
||||
@ -34,16 +35,14 @@ static void displayTotalStats(void);
|
||||
#include <llvm/CodeGen/MachineInstrBuilder.h>
|
||||
|
||||
#include <llvm/TableGen/Main.h>
|
||||
#include <llvm/TableGen/TableGenAction.h>
|
||||
#include <llvm/TableGen/TableGenBackend.h>
|
||||
#include <llvm/TableGen/Record.h>
|
||||
/****************************************************************************
|
||||
* main
|
||||
***************************************************************************/
|
||||
#include <iostream>
|
||||
using namespace llvm;
|
||||
class TVisitor : public TableGenAction {
|
||||
public:
|
||||
virtual bool operator()(raw_ostream &OS, RecordKeeper &Records)
|
||||
bool TVisitor(raw_ostream &OS, RecordKeeper &Records)
|
||||
{
|
||||
Record *rec = Records.getDef("ADD8i8");
|
||||
if(rec)
|
||||
@ -72,16 +71,13 @@ public:
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
int testTblGen(int argc, char **argv)
|
||||
{
|
||||
using namespace llvm;
|
||||
sys::PrintStackTraceOnErrorSignal();
|
||||
PrettyStackTraceProgram(argc,argv);
|
||||
cl::ParseCommandLineOptions(argc,argv);
|
||||
TVisitor tz;
|
||||
|
||||
return llvm::TableGenMain(argv[0],tz);
|
||||
return llvm::TableGenMain(argv[0],TVisitor);
|
||||
InitializeNativeTarget();
|
||||
Triple TheTriple;
|
||||
std::string def = sys::getDefaultTargetTriple();
|
||||
|
||||
@ -258,7 +258,7 @@ void Disassembler::dis1Line(LLInst &inst,int loc_ip, int pass)
|
||||
oper_stream << setw(5)<<left; // align for the labels
|
||||
{
|
||||
ostringstream lab_contents;
|
||||
if (readVal(lab_contents, inst.label, 0))
|
||||
if (readVal(lab_contents, inst.label, nullptr))
|
||||
{
|
||||
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());
|
||||
selectTable(Label);
|
||||
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 */
|
||||
}
|
||||
@ -483,7 +483,7 @@ void Disassembler::dis1Line(LLInst &inst,int loc_ip, int pass)
|
||||
/* Check for user supplied comment */
|
||||
selectTable(Comment);
|
||||
ostringstream cbuf;
|
||||
if (readVal(cbuf, inst.label, 0))
|
||||
if (readVal(cbuf, inst.label, nullptr))
|
||||
{
|
||||
result_stream <<"; "<<cbuf.str();
|
||||
}
|
||||
|
||||
@ -180,8 +180,7 @@ static bool op0F(uint8_t pat[])
|
||||
processor is in 16 bit address mode (real mode).
|
||||
PATLEN bytes are scanned.
|
||||
*/
|
||||
void
|
||||
fixWildCards(uint8_t pat[])
|
||||
void fixWildCards(uint8_t pat[])
|
||||
{
|
||||
|
||||
uint8_t op, quad, intArg;
|
||||
|
||||
@ -67,7 +67,7 @@ static void displayMemMap(void);
|
||||
****************************************************************************/
|
||||
bool DccFrontend::FrontEnd ()
|
||||
{
|
||||
Project::get()->callGraph = 0;
|
||||
Project::get()->callGraph = nullptr;
|
||||
Project::get()->create(m_fname);
|
||||
|
||||
/* Load program into memory */
|
||||
@ -213,7 +213,7 @@ void DccFrontend::LoadImage(Project &proj)
|
||||
uint8_t buf[4];
|
||||
|
||||
/* 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());
|
||||
}
|
||||
|
||||
@ -83,8 +83,8 @@ CondJumps:
|
||||
if (ll->testFlags(SWITCH))
|
||||
{
|
||||
pBB = BB::Create(current_range, MULTI_BRANCH, this);
|
||||
for (size_t i = 0; i < ll->caseTbl2.size(); i++)
|
||||
pBB->addOutEdge(ll->caseTbl2[i]);
|
||||
for (auto & elem : ll->caseTbl2)
|
||||
pBB->addOutEdge(elem);
|
||||
hasCase = true;
|
||||
}
|
||||
else if ((ll->getFlag() & (I | NO_LABEL)) == I) //TODO: WHY NO_LABEL TESTIT
|
||||
@ -138,9 +138,9 @@ CondJumps:
|
||||
for (; iter!=heldBBs.end(); ++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)
|
||||
{
|
||||
fatalError (INVALID_SYNTHETIC_BB);
|
||||
@ -151,7 +151,7 @@ CondJumps:
|
||||
if(iter2==heldBBs.end())
|
||||
fatalError(NO_BB, ip, name.c_str());
|
||||
psBB = *iter2;
|
||||
pBB->edges[edeg_idx].BBptr = psBB;
|
||||
elem.BBptr = psBB;
|
||||
psBB->inEdges.push_back((BB *)nullptr);
|
||||
}
|
||||
}
|
||||
@ -258,7 +258,7 @@ void Function::compressCFG()
|
||||
|
||||
/* Allocate storage for dfsLast[] array */
|
||||
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 */
|
||||
last = numBBs - 1;
|
||||
@ -360,10 +360,10 @@ void BB::mergeFallThrough( CIcodeRec &Icode)
|
||||
traversed = DFS_MERGE;
|
||||
|
||||
/* 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)
|
||||
edges[i].BBptr->mergeFallThrough(Icode);
|
||||
if (elem.BBptr->traversed != DFS_MERGE)
|
||||
elem.BBptr->mergeFallThrough(Icode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -316,6 +316,8 @@ void Function::highLevelGen()
|
||||
assert(numIcode==Icode.size());
|
||||
pIcode = i; //Icode.GetIcode(i)
|
||||
LLInst *ll = pIcode->ll();
|
||||
LLOperand *dst_ll = ll->get(DST);
|
||||
LLOperand *src_ll = ll->get(SRC);
|
||||
if ( ll->testFlags(NOT_HLL) )
|
||||
pIcode->invalidate();
|
||||
if ((pIcode->type != LOW_LEVEL) or not pIcode->valid() )
|
||||
@ -329,6 +331,12 @@ void Function::highLevelGen()
|
||||
if(ll->m_dst.isSet() || (ll->getOpcode()==iMOD))
|
||||
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()))
|
||||
assert(lhs!=nullptr);
|
||||
switch (ll->getOpcode())
|
||||
@ -356,18 +364,13 @@ void Function::highLevelGen()
|
||||
|
||||
case iDIV:
|
||||
case iIDIV:/* should be signed div */
|
||||
{
|
||||
eReg v = ( dst_ll->byteWidth()==1) ? rAL:rAX;
|
||||
rhs = new BinaryOperator(DIV,lhs, rhs);
|
||||
if ( ll->testFlags(B) )
|
||||
{
|
||||
lhs = new RegisterNode(rAL, 0, &localId);
|
||||
pIcode->setRegDU( rAL, eDEF);
|
||||
}
|
||||
else
|
||||
{
|
||||
lhs = new RegisterNode(rAX, 0, &localId);
|
||||
pIcode->setRegDU( rAX, eDEF);
|
||||
}
|
||||
lhs = new RegisterNode(LLOperand(v, dst_ll->byteWidth()), &localId);
|
||||
pIcode->setRegDU( v, eDEF);
|
||||
pIcode->setAsgn(lhs, rhs);
|
||||
}
|
||||
break;
|
||||
|
||||
case iIMUL:
|
||||
@ -387,17 +390,13 @@ void Function::highLevelGen()
|
||||
break;
|
||||
|
||||
case iMOD:
|
||||
{
|
||||
rhs = new BinaryOperator(MOD,lhs, rhs);
|
||||
eReg lhs_reg;
|
||||
|
||||
if ( ll->testFlags(B) )
|
||||
lhs_reg = rAH;
|
||||
else
|
||||
lhs_reg = rDX;
|
||||
|
||||
lhs = new RegisterNode(lhs_reg, 0, &localId);
|
||||
eReg lhs_reg = (dst_ll->byteWidth()==1) ? rAH : rDX;
|
||||
lhs = new RegisterNode(LLOperand(lhs_reg, dst_ll->byteWidth()), &localId);
|
||||
pIcode->setRegDU( lhs_reg, eDEF);
|
||||
pIcode->setAsgn(lhs, rhs);
|
||||
}
|
||||
break;
|
||||
|
||||
case iMOV: pIcode->setAsgn(lhs, rhs);
|
||||
@ -415,7 +414,7 @@ void Function::highLevelGen()
|
||||
break;
|
||||
|
||||
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);
|
||||
break;
|
||||
|
||||
@ -433,7 +432,7 @@ void Function::highLevelGen()
|
||||
break;
|
||||
|
||||
case iRET:
|
||||
case iRETF: pIcode->setUnary(HLI_RET, NULL);
|
||||
case iRETF: pIcode->setUnary(HLI_RET, nullptr);
|
||||
break;
|
||||
|
||||
case iSHL:
|
||||
@ -498,7 +497,7 @@ std::string Function::writeCall (Function * tproc, STKFRAME & args, int *numLoc)
|
||||
|
||||
|
||||
/* 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));
|
||||
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
|
||||
* when the THEN clause of an if..then..else is empty. The clause is
|
||||
* negated and the ELSE clause is used instead. */
|
||||
char *writeJcondInv (HLTYPE h, Function * pProc, int *numLoc)
|
||||
const char *writeJcondInv(HLTYPE h, Function * pProc, int *numLoc)
|
||||
{
|
||||
memset (buf, ' ', sizeof(buf));
|
||||
buf[0] = '\0';
|
||||
|
||||
@ -20,6 +20,6 @@ HlTypeSupport *HLTYPE::get()
|
||||
case HLI_PUSH: return &exp;
|
||||
case HLI_CALL: return &call;
|
||||
default:
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,6 +3,8 @@
|
||||
* (C) Cristina Cifuentes
|
||||
****************************************************************************/
|
||||
|
||||
#include <llvm/Support/PatternMatch.h>
|
||||
#include <boost/iterator/filter_iterator.hpp>
|
||||
#include <cstring>
|
||||
#include <deque>
|
||||
#include "idiom.h"
|
||||
@ -15,8 +17,6 @@
|
||||
#include "shift_idioms.h"
|
||||
#include "arith_idioms.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
|
||||
****************************************************************************/
|
||||
@ -116,7 +116,7 @@ void Function::findIdioms()
|
||||
case iCALL: case iCALLF:
|
||||
/* Check for library functions that return a long register.
|
||||
* 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) &&
|
||||
(pIcode->ll()->src().proc.proc->flg & PROC_IS_FUNC))
|
||||
{
|
||||
|
||||
@ -27,6 +27,7 @@ bool Idiom14::match(iICODE pIcode)
|
||||
return false;
|
||||
m_icodes[0]=pIcode++;
|
||||
m_icodes[1]=pIcode++;
|
||||
LLInst * matched [] = {m_icodes[0]->ll(),m_icodes[1]->ll()};
|
||||
/* Check for regL */
|
||||
m_regL = m_icodes[0]->ll()->m_dst.regi;
|
||||
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;
|
||||
m_icodes[0]->du1.removeDef(regi);
|
||||
//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);
|
||||
rhs = AstIdent::id (*m_icodes[0]->ll(), SRC, m_func, m_icodes[0], *m_icodes[0], NONE);
|
||||
m_icodes[0]->setAsgn(lhs, rhs);
|
||||
|
||||
@ -97,7 +97,7 @@ int Idiom16::action()
|
||||
{
|
||||
AstIdent *lhs;
|
||||
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());
|
||||
m_icodes[0]->setAsgn(lhs, rhs);
|
||||
m_icodes[1]->invalidate();
|
||||
|
||||
@ -81,9 +81,7 @@ int Idiom15::action()
|
||||
AstIdent *lhs;
|
||||
|
||||
Expr *rhs,*_exp;
|
||||
lhs = new RegisterNode(m_icodes[0]->ll()->m_dst.regi,
|
||||
m_icodes[0]->ll()->getFlag() & NO_SRC_B,
|
||||
&m_func->localId);
|
||||
lhs = new RegisterNode(*m_icodes[0]->ll()->get(DST), &m_func->localId);
|
||||
rhs = new Constant(m_icodes.size(), 2);
|
||||
_exp = new BinaryOperator(SHL,lhs, rhs);
|
||||
m_icodes[0]->setAsgn(lhs, _exp);
|
||||
@ -159,7 +157,7 @@ int Idiom9::action()
|
||||
{
|
||||
int idx;
|
||||
AstIdent *lhs;
|
||||
Expr *rhs,*expr;
|
||||
Expr *expr;
|
||||
eReg regH,regL;
|
||||
regL=m_icodes[1]->ll()->m_dst.regi;
|
||||
regH=m_icodes[0]->ll()->m_dst.regi;
|
||||
|
||||
54
src/liveness_set.cpp
Normal file
54
src/liveness_set.cpp
Normal 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);
|
||||
}
|
||||
@ -12,6 +12,7 @@
|
||||
|
||||
#include "dcc.h"
|
||||
#include "project.h"
|
||||
#include "CallGraph.h"
|
||||
using namespace std;
|
||||
|
||||
//static void FollowCtrl (Function * pProc, CALL_GRAPH * pcallGraph, STATE * pstate);
|
||||
@ -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);
|
||||
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
|
||||
* builds a list of procedures reachable from the initial procedure
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
#include <cassert>
|
||||
#include "dcc.h"
|
||||
#include "project.h"
|
||||
#include "CallGraph.h"
|
||||
|
||||
extern Project g_proj;
|
||||
/* Static indentation buffer */
|
||||
@ -123,7 +124,7 @@ void LOCAL_ID::newRegArg(iICODE picode, iICODE ticode) const
|
||||
for(STKSYM &tgt_sym : *target_stackframe)
|
||||
{
|
||||
RegisterNode *tgt_sym_regs = dynamic_cast<RegisterNode *>(tgt_sym.regs);
|
||||
if( tgt_sym_regs == NULL ) // both REGISTER and LONG_VAR require this precondition
|
||||
if( tgt_sym_regs == nullptr ) // both REGISTER and LONG_VAR require this precondition
|
||||
continue;
|
||||
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 */
|
||||
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;
|
||||
if ( tgt_sym.regs->ident.idNode.longIdx == tidx )
|
||||
{
|
||||
@ -273,7 +274,7 @@ Expr *Function::adjustActArgType (Expr *_exp, hlType forType)
|
||||
hlType actType;
|
||||
int offset, offL;
|
||||
|
||||
if (expr == NULL)
|
||||
if (expr == nullptr)
|
||||
return _exp;
|
||||
|
||||
actType = expr-> expType (this);
|
||||
|
||||
@ -9,7 +9,7 @@ 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::s_instance = nullptr;
|
||||
Project::Project() : callGraph(nullptr)
|
||||
{
|
||||
memset(&prog,0,sizeof(prog));
|
||||
@ -94,7 +94,7 @@ const std::string &Project::symbolName(size_t idx)
|
||||
Project *Project::get()
|
||||
{
|
||||
//WARNING: poor man's singleton, not thread safe
|
||||
if(s_instance==0)
|
||||
if(s_instance==nullptr)
|
||||
s_instance=new Project;
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
@ -352,7 +352,7 @@ int Function::findBackwarLongDefs(int loc_ident_idx, const ID &pLocId, iICODE be
|
||||
icode.setRegDU( pmH->regi, eDEF);
|
||||
icode.setUnary(HLI_POP, asgn.lhs);
|
||||
next1->invalidate();
|
||||
asgn.lhs=0;
|
||||
asgn.lhs=nullptr;
|
||||
forced_finish=true; /* to exit the loop */
|
||||
}
|
||||
break;
|
||||
|
||||
@ -54,7 +54,7 @@ BB *interval::firstOfInt ()
|
||||
{
|
||||
auto pq = currNode;
|
||||
if (pq == nodes.end())
|
||||
return 0;
|
||||
return nullptr;
|
||||
++currNode;
|
||||
return *pq;
|
||||
}
|
||||
@ -108,7 +108,7 @@ void derSeq_Entry::findIntervals (Function *c)
|
||||
|
||||
appendQueue (H, Gi); /* H = {first node of G} */
|
||||
Gi->beenOnH = true;
|
||||
Gi->reachingInt = BB::Create(0,"",c); /* ^ empty BB */
|
||||
Gi->reachingInt = BB::Create(nullptr,"",c); /* ^ empty BB */
|
||||
|
||||
/* Process header nodes list H */
|
||||
while (!H.empty())
|
||||
@ -124,15 +124,15 @@ void derSeq_Entry::findIntervals (Function *c)
|
||||
pI->appendNodeInt (H, header); /* pI(header) = {header} */
|
||||
|
||||
/* Process all nodes in the current interval list */
|
||||
while ((h = pI->firstOfInt()) != NULL)
|
||||
while ((h = pI->firstOfInt()) != nullptr)
|
||||
{
|
||||
/* 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--;
|
||||
|
||||
if (succ->reachingInt == NULL) /* first visit */
|
||||
if (succ->reachingInt == nullptr) /* first visit */
|
||||
{
|
||||
succ->reachingInt = header;
|
||||
if (succ->inEdgeCount == 0)
|
||||
@ -182,7 +182,7 @@ static void displayIntervals (interval *pI)
|
||||
printf (" Interval #: %d\t#OutEdges: %d\n", pI->numInt, pI->numOutEdges);
|
||||
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);
|
||||
else // BBs represent intervals
|
||||
printf (" Node (corresp int): %d\n", node->correspInt->numInt);
|
||||
@ -248,7 +248,7 @@ bool Function::nextOrderGraph (derSeq &derivedGi)
|
||||
derSeq_Entry &new_entry(derivedGi.back());
|
||||
|
||||
sameGraph = true;
|
||||
BBnode = 0;
|
||||
BBnode = nullptr;
|
||||
std::vector<BB *> bbs;
|
||||
for(Ii = prev_entry.Ii; Ii != nullptr; Ii = Ii->next)
|
||||
{
|
||||
|
||||
@ -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)
|
||||
{
|
||||
LLOperand *pm;
|
||||
|
||||
/* If not to register (i.e. to r/m), and talking about r/m, then this is dest */
|
||||
pm = (!(stateTable[i].flg & TO_REG) == fdst) ?
|
||||
&pIcode->ll()->m_dst : &pIcode->ll()->src();
|
||||
LLOperand *pm = (!(stateTable[i].flg & TO_REG) == fdst) ? &pIcode->ll()->m_dst : &pIcode->ll()->src();
|
||||
|
||||
/* 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 */
|
||||
{
|
||||
pm->seg = pm->segOver = (eReg)seg;
|
||||
@ -733,7 +731,7 @@ static void segrm(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());
|
||||
|
||||
}
|
||||
@ -743,6 +741,9 @@ static void regop(int i)
|
||||
*****************************************************************************/
|
||||
static void segop(int i)
|
||||
{
|
||||
if(i==0x1E) {
|
||||
printf("es");
|
||||
}
|
||||
setAddress(i, true, 0, (((int16_t)i & 0x18) >> 3) + rES, 0);
|
||||
}
|
||||
|
||||
@ -837,10 +838,13 @@ static void trans(int i)
|
||||
{
|
||||
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
|
||||
};
|
||||
LLInst *ll = pIcode->ll();
|
||||
if(transTable[REG(*pInst)]==iPUSH) {
|
||||
printf("es");
|
||||
}
|
||||
if ((uint8_t)REG(*pInst) < 2 || !(stateTable[i].flg & B)) { /* INC & DEC */
|
||||
ll->setOpcode(transTable[REG(*pInst)]); /* valid on bytes */
|
||||
rm(i);
|
||||
@ -895,7 +899,7 @@ static void arith(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);
|
||||
}
|
||||
|
||||
@ -937,6 +941,7 @@ static void dispM(int i)
|
||||
****************************************************************************/
|
||||
static void dispN(int )
|
||||
{
|
||||
|
||||
//PROG &prog(Project::get()->prog);
|
||||
/*long off = (short)*/getWord(); /* Signed displacement */
|
||||
|
||||
@ -961,10 +966,11 @@ static void dispS(int )
|
||||
/****************************************************************************
|
||||
dispF - 4 byte disp as immed 20-bit target address
|
||||
***************************************************************************/
|
||||
static void dispF(int )
|
||||
static void dispF(int i)
|
||||
{
|
||||
/*off = */(unsigned)getWord();
|
||||
/*seg = */(unsigned)getWord();
|
||||
uint16_t off = (unsigned)getWord();
|
||||
uint16_t seg = (unsigned)getWord();
|
||||
setAddress(i, true, seg, 0, off);
|
||||
// decodeBranchTgt();
|
||||
}
|
||||
|
||||
|
||||
@ -53,7 +53,7 @@ struct TABLEINFO_TYPE
|
||||
{
|
||||
TABLEINFO_TYPE()
|
||||
{
|
||||
symTab=valTab=0;
|
||||
symTab=valTab=nullptr;
|
||||
}
|
||||
//void deleteVal(uint32_t symOff, Function *symProc, boolT bSymToo);
|
||||
void create(tableType type);
|
||||
@ -80,7 +80,7 @@ void TABLEINFO_TYPE::create(tableType type)
|
||||
numEntry = 0;
|
||||
tableSize = TABLESIZE;
|
||||
valTab = new SYMTABLE [TABLESIZE];
|
||||
symTab = 0;
|
||||
symTab = nullptr;
|
||||
break;
|
||||
case Label:
|
||||
currentTabInfo.numEntry = 0;
|
||||
|
||||
@ -44,7 +44,7 @@ void Function::controlFlowAnalysis()
|
||||
{
|
||||
if (flg & PROC_ISLIB)
|
||||
return; /* Ignore library functions */
|
||||
derSeq *derivedG=0;
|
||||
derSeq *derivedG=nullptr;
|
||||
|
||||
/* Make cfg reducible and build derived sequences */
|
||||
derivedG=checkReducibility();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user