From 3bcbb7a2cffd98d541cebe067ac0e18ac51c40c0 Mon Sep 17 00:00:00 2001 From: Artur K Date: Sat, 10 Mar 2012 22:46:15 +0100 Subject: [PATCH] Removed lints --- include/BasicBlock.h | 1 + include/bundle.h | 1 + include/dcc.h | 8 +- include/disassem.h | 5 ++ include/error.h | 2 +- include/icode.h | 65 +++++++++++----- include/machine_x86.h | 17 +++++ include/state.h | 2 +- src/BasicBlock.cpp | 33 +------- src/ast.cpp | 21 +++-- src/backend.cpp | 72 +++++++---------- src/bundle.cpp | 8 +- src/chklib.cpp | 14 +++- src/control.cpp | 51 ++----------- src/dataflow.cpp | 68 ++++++++--------- src/dcc.cpp | 8 +- src/disassem.cpp | 136 ++++++++++++--------------------- src/error.cpp | 6 +- src/frontend.cpp | 13 +--- src/graph.cpp | 32 +------- src/hlicode.cpp | 45 +++-------- src/icode.cpp | 15 ++-- src/idioms.cpp | 20 +---- src/idioms/arith_idioms.cpp | 29 +++---- src/idioms/epilogue_idioms.cpp | 2 +- src/idioms/idiom1.cpp | 6 -- src/idioms/shift_idioms.cpp | 2 - src/machine_x86.cpp | 32 +++++++- src/parser.cpp | 7 +- src/perfhlib.cpp | 1 + src/procs.cpp | 3 +- src/proplong.cpp | 12 +-- src/reducible.cpp | 28 +------ src/scanner.cpp | 2 +- src/udm.cpp | 6 -- 35 files changed, 301 insertions(+), 472 deletions(-) diff --git a/include/BasicBlock.h b/include/BasicBlock.h index eb08d58..c8dfb7d 100644 --- a/include/BasicBlock.h +++ b/include/BasicBlock.h @@ -40,6 +40,7 @@ private: //friend class SymbolTableListTraits; iICODE range_start; iICODE range_end; + public: iICODE begin(); iICODE end() const; diff --git a/include/bundle.h b/include/bundle.h index 1e74fae..0657fe2 100644 --- a/include/bundle.h +++ b/include/bundle.h @@ -15,6 +15,7 @@ struct bundle public: void appendCode(const char *format, ...); void appendDecl(const char *format, ...); + void appendDecl(const std::string &); strTable decl; /* Declarations */ strTable code; /* C code */ }; diff --git a/include/dcc.h b/include/dcc.h index c638c99..ffaf4ee 100644 --- a/include/dcc.h +++ b/include/dcc.h @@ -104,10 +104,6 @@ extern std::bitset<32> duReg[30]; /* def/use bits for registers */ extern std::bitset<32> maskDuReg[30]; /* masks off du bits for regs */ /* Registers used by icode instructions */ -static constexpr const char *allRegs[21] = {"ax", "cx", "dx", "bx", "sp", "bp", - "si", "di", "es", "cs", "ss", "ds", - "al", "cl", "dl", "bl", "ah", "ch", "dh", "bh", - "tmp"}; /* Memory map states */ #define BM_UNKNOWN 0 /* Unscanned memory */ @@ -169,7 +165,7 @@ hlType expType (const COND_EXPR *, Function *); std::string writeCall (Function *, STKFRAME *, Function *, int *); char *writeJcond (const HLTYPE &, Function *, int *); char *writeJcondInv (HLTYPE, Function *, int *); -int power2 (int); + /* Exported funcions from locident.c */ boolT checkLongEq (LONG_STKID_TYPE, iICODE, int, Function *, Assignment &asgn, iICODE atOffset); @@ -177,6 +173,6 @@ boolT checkLongRegEq (LONGID_TYPE, iICODE, int, Function *, Assignment &asgn, iI eReg otherLongRegi(eReg, int, LOCAL_ID *); -extern eReg subRegH(eReg reg); +extern eReg subRegH(eReg reg); //TODO: move these into machine_x86 extern eReg subRegL(eReg reg); extern const char *indentStr(int level); diff --git a/include/disassem.h b/include/disassem.h index 3789bf6..85949da 100644 --- a/include/disassem.h +++ b/include/disassem.h @@ -2,6 +2,11 @@ * dcc project disassembler header * (C) Mike van Emmerik ****************************************************************************/ +#pragma once +#include +#include +#include "bundle.h" +struct LLInst; /* Definitions for extended keys (first key is zero) */ diff --git a/include/error.h b/include/error.h index bc3eebd..9ffeb98 100644 --- a/include/error.h +++ b/include/error.h @@ -30,7 +30,7 @@ enum eErrorId WHILE_FAIL }; -//lint -function(exit,fatalError) + void fatalError(eErrorId errId, ...); void reportError(eErrorId errId, ...); diff --git a/include/icode.h b/include/icode.h index f9e3dab..c2dc8d9 100644 --- a/include/icode.h +++ b/include/icode.h @@ -3,11 +3,13 @@ * (C) Cristina Cifuentes ****************************************************************************/ #pragma once +#include #include #include #include #include #include +#include #include #include #include "Enums.h" @@ -20,9 +22,12 @@ struct Function; struct STKFRAME; struct CIcodeRec; struct ICODE; +struct bundle; typedef std::list::iterator iICODE; typedef std::list::reverse_iterator riICODE; +/* uint8_t and uint16_t registers */ + /* Def/use of flags - low 4 bits represent flags */ struct DU { @@ -65,19 +70,19 @@ struct AssignType : public HlTypeSupport /* for HLI_ASSIGN */ COND_EXPR *lhs; COND_EXPR *rhs; + AssignType() : lhs(0),rhs(0) {} bool removeRegFromLong(eReg regi, LOCAL_ID *locId) { performLongRemoval(regi,locId,lhs); return true; } std::string writeOut(Function *pProc, int *numLoc); - AssignType() : lhs(0),rhs(0) - {} }; struct ExpType : public HlTypeSupport { /* for HLI_JCOND, HLI_RET, HLI_PUSH, HLI_POP*/ COND_EXPR *v; + ExpType() : v(0) {} bool removeRegFromLong(eReg regi, LOCAL_ID *locId) { performLongRemoval(regi,locId,v); @@ -148,7 +153,7 @@ public: void setAsgn(COND_EXPR *lhs, COND_EXPR *rhs); } ; /* LOW_LEVEL icode operand record */ -struct LLOperand //: public llvm::MCOperand +struct LLOperand : public llvm::MCOperand { eReg seg; /* CS, DS, ES, SS */ int16_t segValue; /* Value of segment seg during analysis */ @@ -161,15 +166,22 @@ struct LLOperand //: public llvm::MCOperand Function *proc; /* pointer to target proc (for CALL(F))*/ int cb; /* # actual arg bytes */ } proc; + LLOperand() : seg(rUNDEF),segValue(0),segOver(rUNDEF),regi(rUNDEF),off(0),opz(0) + { + proc.proc=0; + proc.cb=0; + } uint32_t op() const {return opz;} void SetImmediateOp(uint32_t dw) {opz=dw;} + bool isReg() const; + }; -struct LLInst : public llvm::ilist_node +struct LLInst : public llvm::MCInst //: public llvm::ilist_node { protected: uint32_t flg; /* icode flags */ - llIcode opcode; /* llIcode instruction */ +// llIcode opcode; /* llIcode instruction */ public: int codeIdx; /* Index into cCode.code */ uint8_t numBytes; /* Number of bytes this instr */ @@ -185,13 +197,13 @@ public: int hllLabNum; /* label # for hll codegen */ bool conditionalJump() { - return (opcode >= iJB) && (opcode < iJCXZ); + return (getOpcode() >= iJB) && (getOpcode() < iJCXZ); } bool testFlags(uint32_t x) const { return (flg & x)!=0;} void setFlags(uint32_t flag) {flg |= flag;} void clrFlags(uint32_t flag) { - if(opcode==iMOD) + if(getOpcode()==iMOD) { assert(false); } @@ -199,7 +211,7 @@ public: } uint32_t getFlag() const {return flg;} - llIcode getOpcode() const { return opcode; } + //llIcode getOpcode() const { return opcode; } uint32_t GetLlLabel() const { return label;} @@ -208,19 +220,19 @@ public: bool match(llIcode op) { - return (opcode==op); + return (getOpcode()==op); } bool match(llIcode op,eReg dest) { - return (opcode==op)&&dst.regi==dest; + return (getOpcode()==op)&&dst.regi==dest; } bool match(llIcode op,eReg dest,uint32_t flgs) { - return (opcode==op) and (dst.regi==dest) and testFlags(flgs); + return (getOpcode()==op) and (dst.regi==dest) and testFlags(flgs); } bool match(llIcode op,eReg dest,eReg src_reg) { - return (opcode==op)&&(dst.regi==dest)&&(src.regi==src_reg); + return (getOpcode()==op)&&(dst.regi==dest)&&(src.regi==src_reg); } bool match(eReg dest,eReg src_reg) { @@ -232,17 +244,13 @@ public: } bool match(llIcode op,uint32_t flgs) { - return (opcode==op) and testFlags(flgs); + return (getOpcode()==op) and testFlags(flgs); } void set(llIcode op,uint32_t flags) { - opcode = op; + setOpcode(op); flg =flags; } - void setOpcode(llIcode op) - { - opcode = op; - } void emitGotoLabel(int indLevel); void findJumpTargets(CIcodeRec &_pc); void writeIntComment(std::ostringstream &s); @@ -253,6 +261,11 @@ public: bool isJmpInst(); HLTYPE toHighLevel(COND_EXPR *lhs, COND_EXPR *rhs, Function *func); HLTYPE createCall(); + LLInst(ICODE *container) : m_link(container),flg(0) + { + + } + ICODE *m_link; }; /* Icode definition: LOW_LEVEL and HIGH_LEVEL */ @@ -261,6 +274,7 @@ struct ICODE protected: LLInst m_ll; HLTYPE m_hl; + bool invalid; /* Has no HIGH_LEVEL equivalent */ public: /* Def/Use of registers and stack variables */ struct DU_ICODE @@ -317,18 +331,20 @@ public: Use &u(idx[regIdx]); u.removeUser(ic); } + DU1() : numRegsDef(0) {} }; icodeType type; /* Icode type */ - bool invalid; /* Has no HIGH_LEVEL equivalent */ BB *inBB; /* BB to which this icode belongs */ DU_ICODE du; /* Def/use regs/vars */ DU1 du1; /* du chain 1 */ + int loc_ip; // used by CICodeRec to number ICODEs + LLInst * ll() { return &m_ll;} const LLInst * ll() const { return &m_ll;} + HLTYPE * hl() { return &m_hl;} const HLTYPE * hl() const { return &m_hl;} void hl(const HLTYPE &v) { m_hl=v;} - int loc_ip; // used by CICodeRec to number ICODEs void setRegDU(eReg regi, operDu du_in); void invalidate(); @@ -355,8 +371,15 @@ public: { return hl()->call.newStkArg(exp,opcode,pproc); } + ICODE() : m_ll(this),type(NOT_SCANNED),inBB(0),loc_ip(0),invalid(false) + { + } +}; +struct MappingLLtoML +{ + std::list > m_low_level; + std::list > m_middle_level; }; - // This is the icode array object. class CIcodeRec : public std::list { diff --git a/include/machine_x86.h b/include/machine_x86.h index a08913e..9efaaa7 100644 --- a/include/machine_x86.h +++ b/include/machine_x86.h @@ -1,5 +1,8 @@ #pragma once +#include #include +#include +#include /* Machine registers */ enum eReg { @@ -45,4 +48,18 @@ class Machine_X86 public: Machine_X86(); static const std::string ®Name(eReg r); + static const std::string &opcodeName(unsigned r); + static bool physicalReg(eReg r); + /* Writes the registers that are set in the bitvector */ + //TODO: move this into Machine_X86 ? + static void writeBitVector (std::ostream &ostr,const std::bitset<32> ®i) + { + int j; + for (j = rAX; j < INDEX_BX_SI; j++) + { + if (regi.test(j-1)) + ostr << regName(eReg(j)); + } + } + }; diff --git a/include/state.h b/include/state.h index 10ae94e..6377374 100644 --- a/include/state.h +++ b/include/state.h @@ -25,7 +25,7 @@ struct STATE JCond.regi=0; JCond.immed=0; - memset(r,0,sizeof(int16_t)*INDEX_BX_SI); + memset(r,0,sizeof(int16_t)*INDEX_BX_SI); //TODO: move this to machine_x86 memset(f,0,sizeof(uint8_t)*INDEX_BX_SI); } }; diff --git a/src/BasicBlock.cpp b/src/BasicBlock.cpp index 4992259..779820b 100644 --- a/src/BasicBlock.cpp +++ b/src/BasicBlock.cpp @@ -15,7 +15,6 @@ BB *BB::Create(void *ctx, const string &s, Function *parent, BB *insertBefore) BB *BB::Create(int start, int ip, uint8_t _nodeType, int numOutEdges, Function *parent) { - //parent->m_cfg; BB* pnewBB; pnewBB = new BB; @@ -36,7 +35,6 @@ BB *BB::Create(int start, int ip, uint8_t _nodeType, int numOutEdges, Function * pnewBB->range_end = parent->Icode.end(); } - // pnewBB->range_start = parent->Icode.begin(); if (numOutEdges) pnewBB->edges.resize(numOutEdges); @@ -101,28 +99,15 @@ void BB::displayDfs() else { int edge_idx=0; -#ifdef _lint - for(auto iter=inEdges.begin(); iter!=inEdges.end(); ++iter) - { - BB *node(*iter); -#else for(BB *node : inEdges) { -#endif printf (" inEdge[%ld] = %ld\n", edge_idx, node->begin()->loc_ip); edge_idx++; } } - /* Display out edges information */ -#ifdef _lint - for(auto iter=edges.begin(); iter!=edges.end(); ++iter) - { - TYPEADR_TYPE &edg(*iter); -#else for(TYPEADR_TYPE &edg : edges) { -#endif if (nodeType == INTERVAL_NODE) printf(" outEdge[%ld] = %ld\n", i, edg.BBptr->correspInt->numInt); else @@ -131,14 +116,8 @@ void BB::displayDfs() printf("----\n"); /* Recursive call on successors of current node */ -#ifdef _lint - for (auto ik=edges.begin(); ik!=edges.end(); ++ik) - { - TYPEADR_TYPE &pb(*ik); -#else for(TYPEADR_TYPE &pb : edges) { -#endif if (pb.BBptr->traversed != DFS_DISP) pb.BBptr->displayDfs(); } @@ -374,15 +353,9 @@ void BB::writeBB(int lev, Function * pProc, int *numLoc) //for (i = start, last = i + length; i < last; i++) /* Generate code for each hlicode that is not a HLI_JCOND */ - //for(); -#ifdef _lint - for(iICODE hli=begin(); hli!=end(); ++hli) - { - ICODE &pHli(*hli); -#else + for(ICODE &pHli : *this) { -#endif if ((pHli.type == HIGH_LEVEL) && ( pHli.valid() )) //TODO: use filtering range here. { std::string line = pHli.hl()->write1HlIcode(pProc, numLoc); @@ -396,10 +369,6 @@ void BB::writeBB(int lev, Function * pProc, int *numLoc) } } } -//int BB::beginIdx() -//{ -// return start; -//} iICODE BB::begin() { diff --git a/src/ast.cpp b/src/ast.cpp index 404a9f5..072c7c1 100644 --- a/src/ast.cpp +++ b/src/ast.cpp @@ -5,7 +5,6 @@ * (C) Cristina Cifuentes */ #include -//#include // For free() #include #include #include @@ -20,7 +19,6 @@ static const char * const condOpSym[] = { " <= ", " < ", " == ", " != ", " > ", " + ", " - ", " * ", " / ", " >> ", " << ", " % ", " && ", " || " }; -//#define EXP_SIZE 200 /* Size of the expression buffer */ /* Local expression stack */ //typedef struct _EXP_STK { @@ -64,7 +62,6 @@ void ICODE::setRegDU (eReg regi, operDu du_in) /* Copies the def, use, or def and use fields of duIcode into pIcode */ void ICODE::copyDU(const ICODE &duIcode, operDu _du, operDu duDu) { - // printf("%s %d,%d from %d to %d\n",__FUNCTION__,int(du),int(duDu),duIcode->ll()->getOpcode(),pIcode->ll()->getOpcode()); switch (_du) { case eDEF: @@ -363,9 +360,9 @@ COND_EXPR *COND_EXPR::id(const LLInst &ll_insn, opLoc sd, Function * pProc, iICO else if ((sd == SRC) && ll_insn.testFlags(I)) /* constant */ newExp = COND_EXPR::idKte (ll_insn.src.op(), 2); - else if (pm.regi == 0) /* global variable */ + else if (pm.regi == rUNDEF) /* global variable */ newExp = GlobalVariable::Create(pm.segValue, pm.off); - else if (pm.regi < INDEX_BX_SI) /* register */ + else if ( pm.isReg() ) /* register */ { newExp = COND_EXPR::idReg (pm.regi, (sd == SRC) ? ll_insn.getFlag() : ll_insn.getFlag() & NO_SRC_B, @@ -438,10 +435,11 @@ condId ICODE::idType(opLoc sd) return (CONSTANT); else if (pm.regi == 0) return (GLOB_VAR); - else if (pm.regi < INDEX_BX_SI) + else if ( pm.isReg() ) return (REGISTER); - else if ((pm.seg == rSS) && (pm.regi == INDEX_BX_SI)) + else if ((pm.seg == rSS) && (pm.regi == INDEX_BP)) { + //TODO: which pm.seg/pm.regi pairs should produce PARAM/LOCAL_VAR ? if (pm.off >= 0) return (PARAM); else @@ -793,7 +791,6 @@ string walkCondExpr (const COND_EXPR* expr, Function * pProc, int* numLoc) /* Makes a copy of the given expression. Allocates newExp storage for each * node. Returns the copy. */ -//lint -sem(COND_EXPR::clone, @p!=0) COND_EXPR *COND_EXPR::clone() const { COND_EXPR* newExp=0; /* Expression node copy */ @@ -830,6 +827,7 @@ void COND_EXPR::changeBoolOp (condOp newOp) * register regi */ bool COND_EXPR::insertSubTreeReg (COND_EXPR *&tree, COND_EXPR *_expr, eReg regi,LOCAL_ID *locsym) { + if (tree == NULL) return false; COND_EXPR *temp=tree->insertSubTreeReg(_expr,regi,locsym); @@ -848,7 +846,7 @@ bool isSubRegisterOf(eReg reg,eReg parent) } COND_EXPR *COND_EXPR::insertSubTreeReg (COND_EXPR *_expr, eReg regi,LOCAL_ID *locsym) { - //HlTypeSupport *set_val; + eReg treeReg; COND_EXPR *temp; @@ -894,6 +892,7 @@ COND_EXPR *COND_EXPR::insertSubTreeReg (COND_EXPR *_expr, eReg regi,LOCAL_ID *lo } return nullptr; } + return nullptr; } COND_EXPR *BinaryOperator::insertSubTreeReg(COND_EXPR *_expr, eReg regi, LOCAL_ID *locsym) @@ -984,7 +983,6 @@ COND_EXPR *BinaryOperator::insertSubTreeLongReg(COND_EXPR *_expr, int longIdx) return this; } return nullptr; - } @@ -1007,7 +1005,7 @@ void COND_EXPR::release() } /* Makes a copy of the given expression. Allocates newExp storage for each * node. Returns the copy. */ -//lint -sem(BinaryOperator::clone, @p!=0) + COND_EXPR *BinaryOperator::clone() { BinaryOperator* newExp=new BinaryOperator(m_op); /* Expression node copy */ @@ -1042,4 +1040,5 @@ COND_EXPR *BinaryOperator::inverse() } /* eos */ assert(false); return res; + } diff --git a/src/backend.cpp b/src/backend.cpp index 6292bed..792d2a3 100644 --- a/src/backend.cpp +++ b/src/backend.cpp @@ -8,7 +8,9 @@ #include #include "dcc.h" +#include "disassem.h" #include +#include #include #include #include @@ -136,15 +138,8 @@ static void writeGlobSymTable() if (not symtab.empty()) { cCode.appendDecl( "/* Global variables */\n"); -#ifdef _lint - for (auto iter=symtab.begin(); iter!=symtab.end(); ++iter) - { - SYM &sym(*iter); -#else for (SYM &sym : symtab) { -#endif -// pSym = &symtab[idx]; if (sym.duVal.isUSE_VAL()) /* first used */ printGlobVar (&sym); else { /* first defined */ @@ -184,19 +179,6 @@ static void writeHeader (std::ostream &_ios, char *fileName) freeBundle (&cCode); } - -/* Writes the registers that are set in the bitvector */ -static void writeBitVector (const std::bitset<32> ®i) -{ - int j; - - for (j = rAX; j < INDEX_BX_SI; j++) - { - if (regi.test(j)) - printf ("%s ", allRegs[j-1]); - } -} - // Note: Not currently called! /* Checks the given icode to determine whether it has a label associated * to it. If so, a goto is emitted to this label; otherwise, a new label @@ -205,7 +187,7 @@ static void writeBitVector (const std::bitset<32> ®i) * the code; that is, the target code has not been traversed yet. */ static void emitFwdGotoLabel (ICODE * pt, int indLevel) { - if ( ! pt->ll()->testFlags(HLL_LABEL) ) /* node hasn't got a lab */ + if ( not pt->ll()->testFlags(HLL_LABEL)) /* node hasn't got a lab */ { /* Generate new label */ pt->ll()->hllLabNum = getNextLabel(); @@ -220,8 +202,10 @@ static void emitFwdGotoLabel (ICODE * pt, int indLevel) void Function::codeGen (std::ostream &fs) { int numLoc; - char buf[200], /* Procedure's definition */ - arg[30]; /* One argument */ + ostringstream buf; + //STKFRAME * args; /* Procedure arguments */ + //char buf[200], /* Procedure's definition */ + // arg[30]; /* One argument */ BB *pBB; /* Pointer to basic block */ /* Write procedure/function header */ @@ -232,19 +216,17 @@ void Function::codeGen (std::ostream &fs) cCode.appendDecl( "\nvoid %s (", name.c_str()); /* Write arguments */ - memset (buf, 0, sizeof(buf)); for (size_t i = 0; i < args.sym.size(); i++) { if (args.sym[i].invalid == FALSE) { - sprintf (arg,"%s %s",hlTypes[args.sym[i].type], args.sym[i].name); - strcat (buf, arg); + buf<writeCode (1, this, &numLoc, MAX, UN_INIT); + } cCode.appendCode( "}\n\n"); writeBundle (fs, cCode); @@ -302,17 +280,18 @@ void Function::codeGen (std::ostream &fs) { pBB = m_dfsLast[i]; if (pBB->flg & INVALID_BB) continue; /* skip invalid BBs */ - printf ("BB %d\n", i); - printf (" Start = %d, end = %d\n", pBB->begin()->loc_ip, pBB->begin()->loc_ip+pBB->size()); - printf (" LiveUse = "); - writeBitVector (pBB->liveUse); - printf ("\n Def = "); - writeBitVector (pBB->def); - printf ("\n LiveOut = "); - writeBitVector (pBB->liveOut); - printf ("\n LiveIn = "); - writeBitVector (pBB->liveIn); - printf ("\n\n"); + cout << "BB "<decl); freeStrTab (procCode->code); @@ -90,4 +90,10 @@ void bundle::appendDecl(const char *format,...) va_end (args); } +void bundle::appendDecl(const std::string &v) +{ + decl.push_back(v); +} + + diff --git a/src/chklib.cpp b/src/chklib.cpp index 2c87d62..b7cbd45 100644 --- a/src/chklib.cpp +++ b/src/chklib.cpp @@ -62,8 +62,8 @@ static int numArg; /* Number of param names actually stored /* prototypes */ void grab(int n, FILE *_file); -uint16_t readFileShort(FILE *g_file); -void readFileSection(uint16_t* p, int len, FILE *g_file); +uint16_t readFileShort(FILE *_file); +void readFileSection(uint16_t* p, int len, FILE *_file); void cleanup(void); void checkStartup(STATE *state); void readProtoFile(void); @@ -908,11 +908,17 @@ readProtoFile(void) for (i=0; i < numFunc; i++) { - fread(&pFunc[i], 1, SYMLEN, fProto); + size_t read_size=fread(&pFunc[i], 1, SYMLEN, fProto); + assert(read_size==SYMLEN); + if(read_size!=SYMLEN) + break; pFunc[i].typ = (hlType)readFileShort(fProto); pFunc[i].numArg = readFileShort(fProto); pFunc[i].firstArg = readFileShort(fProto); - fread(&pFunc[i].bVararg, 1, 1, fProto); + if(feof(fProto)) + break; + int c = fgetc(fProto); + pFunc[i].bVararg = (c!=0); //fread(&pFunc[i].bVararg, 1, 1, fProto); } grab(2, fProto); diff --git a/src/control.cpp b/src/control.cpp index f1bef6b..102c994 100644 --- a/src/control.cpp +++ b/src/control.cpp @@ -65,24 +65,14 @@ static int commonDom (int currImmDom, int predImmDom, Function * pProc) void Function::findImmedDom () { BB * currNode; - int currIdx, predIdx; - - for (currIdx = 0; currIdx < numBBs; currIdx++) + for (size_t currIdx = 0; currIdx < numBBs; currIdx++) { currNode = m_dfsLast[currIdx]; if (currNode->flg & INVALID_BB) /* Do not process invalid BBs */ continue; -#ifdef _lint - BB * inedge=0; - for (auto i=currNode->inEdges.begin(); i!=currNode->inEdges.end(); ++i) - { - inedge=*i; - -#else for (BB * inedge : currNode->inEdges) { -#endif - predIdx = inedge->dfsLastNum; + size_t predIdx = inedge->dfsLastNum; if (predIdx < currIdx) currNode->immedDom = commonDom (currNode->immedDom, predIdx, this); } @@ -259,30 +249,15 @@ static void findNodesInInt (queue &intNodes, int level, interval *Ii) { if (level == 1) { -#ifdef _lint - BB * en=0; - for (auto i=Ii->nodes.begin(); i!=Ii->nodes.end(); ++i) - { - en=*i; -#else for(BB *en : Ii->nodes) { -#endif appendQueue(intNodes,en); } } else { -#ifdef _lint - BB * en=0; - for (auto i=Ii->nodes.begin(); i!=Ii->nodes.end(); ++i) - { - en=*i; - -#else for(BB *en : Ii->nodes) { -#endif findNodesInInt(intNodes,level-1,en->correspInt); } } @@ -296,8 +271,7 @@ void Function::structLoops(derSeq *derivedG) BB * intHead, /* interval header node */ * pred, /* predecessor node */ * latchNode;/* latching node (in case of loops) */ - int - level = 0; /* derived sequence level */ + size_t level = 0; /* derived sequence level */ interval *initInt; /* initial interval */ queue intNodes; /* list of interval nodes */ @@ -362,16 +336,15 @@ void Function::structLoops(derSeq *derivedG) /* Returns whether the BB indexed by s is a successor of the BB indexed by * h. Note that h is a case node. */ -static boolT successor (int s, int h, Function * pProc) +static bool successor (int s, int h, Function * pProc) { - int i; BB * header; header = pProc->m_dfsLast[h]; - for (i = 0; i < header->edges.size(); i++) - if (header->edges[i].BBptr->dfsLastNum == s) - return true; - return false; + auto iter = std::find_if(header->edges.begin(), + header->edges.end(), + [s](const TYPEADR_TYPE &te)->bool{ return te.BBptr->dfsLastNum == s;}); + return iter!=header->edges.end(); } @@ -428,14 +401,8 @@ void Function::structCases() * header field with caseHeader. */ insertList (caseNodes, i); m_dfsLast[i]->caseHead = i; -#ifdef _lint - for (auto ki=caseHeader->edges.begin(); ki!=caseHeader->edges.end(); ++ki) - { - TYPEADR_TYPE &pb(*ki); -#else for(TYPEADR_TYPE &pb : caseHeader->edges) { -#endif tagNodesInCase(pb.BBptr, caseNodes, i, exitNode); } //for (j = 0; j < caseHeader->edges[j]; j++) @@ -525,8 +492,6 @@ void Function::compoundCond() int i; //j, k, numOutEdges BB * pbb, * t, * e, * obb;//,* pred; ICODE * picode, * ticode; - //COND_EXPR *exp; - //TYPEADR_TYPE *edges; boolT change; change = TRUE; diff --git a/src/dataflow.cpp b/src/dataflow.cpp index ddb5270..411d9f4 100644 --- a/src/dataflow.cpp +++ b/src/dataflow.cpp @@ -6,14 +6,14 @@ ****************************************************************************/ #include "dcc.h" -//#include -//#include -//#include +#include +#include +#include #include #include #include #include -//using namespace boost; +using namespace boost; struct ExpStack { typedef std::list EXP_STK; @@ -120,7 +120,7 @@ void Function::elimCondCodes () BB * pBB; /* Pointer to BBs in dfs last ordering */ riICODE useAt; /* Instruction that used flag */ riICODE defAt; /* Instruction that defined flag */ - lhs=rhs=_expr=0; + //lhs=rhs=_expr=0; for (i = 0; i < numBBs; i++) { pBB = m_dfsLast[i]; @@ -129,10 +129,9 @@ void Function::elimCondCodes () // auto v(pBB | boost::adaptors::reversed); // for (const ICODE &useAt : v) // {} - assert(distance(pBB->rbegin(),pBB->rend())==pBB->size()); for (useAt = pBB->rbegin(); useAt != pBB->rend(); useAt++) { - llIcode useAtOp = useAt->ll()->getOpcode(); + llIcode useAtOp = llIcode(useAt->ll()->getOpcode()); use = useAt->ll()->flagDU.u; if ((useAt->type != LOW_LEVEL) || ( ! useAt->valid() ) || ( 0 == use )) continue; @@ -252,14 +251,8 @@ void Function::genLiveKtes () pbb = m_dfsLast[i]; if (pbb->flg & INVALID_BB) continue; // skip invalid BBs -#ifdef _lint - for (auto j = pbb->begin(); j != pbb->end(); j++) - { - ICODE &insn(*j); -#else for(ICODE &insn : *pbb) { -#endif if ((insn.type == HIGH_LEVEL) && ( insn.valid() )) { liveUse |= (insn.du.use & ~def); @@ -326,14 +319,8 @@ void Function::liveRegAnalysis (std::bitset<32> &in_liveOut) } else /* Check successors */ { -#ifdef _lint - for (auto i=pbb->edges.begin(); i!=pbb->edges.end(); ++i) - { - TYPEADR_TYPE &e(*i); -#else for(TYPEADR_TYPE &e : pbb->edges) { -#endif pbb->liveOut |= e.BBptr->liveIn; } @@ -411,7 +398,6 @@ void Function::liveRegAnalysis (std::bitset<32> &in_liveOut) void BB::genDU1() { eReg regi; /* Register that was defined */ - int k, defRegIdx, useIdx; iICODE picode, ticode,lastInst; BB *tbb; /* Target basic block */ @@ -505,9 +491,9 @@ void BB::genDU1() * from a library function (routines such as printf * return an integer, which is normally not taken into * account by the programmer). */ - if (picode->valid() && ! picode->du1.used(defRegIdx) && - ( ! (picode->du.lastDefRegi & duReg[regi]).any()) && - ( ! ((picode->hl()->opcode == HLI_CALL) && + if (picode->valid() and not picode->du1.used(defRegIdx) and + (not (picode->du.lastDefRegi & duReg[regi]).any()) && + (not ((picode->hl()->opcode == HLI_CALL) && (picode->hl()->call.proc->flg & PROC_ISLIB)))) { if (! (this->liveOut & duReg[regi]).any()) /* not liveOut */ @@ -542,14 +528,8 @@ void Function::genDU1 () { /* Traverse tree in dfsLast order */ assert(m_dfsLast.size()==numBBs); -#ifdef _lint - for (auto i=m_dfsLast.begin(); i!=m_dfsLast.end(); ++i) - { - BB *pbb(*i); -#else for(BB *pbb : m_dfsLast) { -#endif if (pbb->flg & INVALID_BB) continue; pbb->genDU1(); @@ -636,7 +616,7 @@ bool COND_EXPR::xClear (iICODE f, iICODE t, iICODE lastBBinst, Function * pproc) { regi= pproc->localId.id_arr[expr.ident.idNode.regiIdx].id.regi; for (i = ++iICODE(f); (i != lastBBinst) && (i!=t); i++) - if ((i->type == HIGH_LEVEL) && ( not i->invalid )) + if ((i->type == HIGH_LEVEL) && ( i->valid() )) { if ((i->du.def & duReg[regi]).any()) return false; @@ -711,13 +691,13 @@ static int processCArg (Function * pp, Function * pProc, ICODE * picode, int num } else adjustActArgType (_exp, pp->args.sym[numArgs].type, pProc); - res = picode->newStkArg (_exp, picode->ll()->getOpcode(), pProc); + res = picode->newStkArg (_exp, (llIcode)picode->ll()->getOpcode(), pProc); } else /* user function */ { if (pp->args.numArgs > 0) pp->args.adjustForArgType (numArgs, expType (_exp, pProc)); - res = picode->newStkArg (_exp, picode->ll()->getOpcode(), pProc); + res = picode->newStkArg (_exp, (llIcode)picode->ll()->getOpcode(), pProc); } /* Do not update the size of k if the expression was a segment register @@ -796,13 +776,13 @@ void Function::processHliCall1(COND_EXPR *_exp, iICODE picode) { if (pp->args.numArgs > 0) adjustActArgType(_exp, pp->args.sym[numArgs].type, this); - res = picode->newStkArg (_exp, picode->ll()->getOpcode(), this); + res = picode->newStkArg (_exp, (llIcode)picode->ll()->getOpcode(), this); } else /* user function */ { if (pp->args.numArgs >0) pp->args.adjustForArgType (numArgs,expType (_exp, this)); - res = picode->newStkArg (_exp,picode->ll()->getOpcode(), this); + res = picode->newStkArg (_exp,(llIcode)picode->ll()->getOpcode(), this); } if (res == FALSE) k += hlTypeSize (_exp, this); @@ -849,6 +829,7 @@ void Function::findExps() /* Initialize expression stack */ g_exp_stk.init(); + _exp = 0; /* Traverse tree in dfsLast order */ for (i = 0; i < numBBs; i++) @@ -1125,9 +1106,11 @@ void Function::dataFlow(std::bitset<32> &_liveOut) isCx = _liveOut.test(rCX - rAX); isDx = _liveOut.test(rDX - rAX); bool isAL = !isAx && _liveOut.test(rAL - rAX); - bool isBL = !isBx && _liveOut.test(rBL - rAX); - bool isCL = !isCx && _liveOut.test(rCL - rAX); bool isAH = !isAx && _liveOut.test(rAH - rAX); + bool isBL = !isBx && _liveOut.test(rBL - rAX); + bool isBH = !isBx && _liveOut.test(rBH - rAX); + bool isCL = !isCx && _liveOut.test(rCL - rAX); + bool isCH = !isCx && _liveOut.test(rCH - rAX); bool isDL = !isDx && _liveOut.test(rDL - rAX); bool isDH = !isDx && _liveOut.test(rDH - rAX); if(isAL && isAH) @@ -1142,6 +1125,19 @@ void Function::dataFlow(std::bitset<32> &_liveOut) printf("**************************************************************************** dataFlow Join discovered Dx\n"); isDH=isDL=false; } + if(isBL && isBH) + { + isBx = true; + printf("**************************************************************************** dataFlow Join discovered Dx\n"); + isBH=isBL=false; + } + if(isCL && isCH) + { + isCx = true; + printf("**************************************************************************** dataFlow Join discovered Dx\n"); + isCH=isCL=false; + } + if (isAx && isDx) /* long or pointer */ { retVal.type = TYPE_LONG_SIGN; diff --git a/src/dcc.cpp b/src/dcc.cpp index 00cc9b3..b55ce5a 100644 --- a/src/dcc.cpp +++ b/src/dcc.cpp @@ -8,7 +8,6 @@ #include /* Global variables - extern to other modules */ -//char *progname; /* argv[0] - for error msgs */ char *asm1_name, *asm2_name; /* Assembler output filenames */ SYMTAB symtab; /* Global symbol table */ STATS stats; /* cfg statistics */ @@ -73,7 +72,6 @@ int main(int argc, char *argv[]) static char *initargs(int argc, char *argv[]) { char *pc; - //progname = *argv; /* Save invocation name for error messages */ while (--argc > 0 && (*++argv)[0] == '-') { @@ -102,7 +100,6 @@ static char *initargs(int argc, char *argv[]) break; case 'V': /* Very verbose => verbose */ option.VeryVerbose = true; - //lint -fallthrough case 'v': option.verbose = true; /* Make everything verbose */ break; @@ -115,10 +112,9 @@ static char *initargs(int argc, char *argv[]) asm1_name = asm2_name = *++argv; goto NextArg; } - //lint -fallthrough default: - fatalError(INVALID_ARG, *pc); // does not return - + fatalError(INVALID_ARG, *pc); + return *argv; } NextArg:; } diff --git a/src/disassem.cpp b/src/disassem.cpp index 3d07b6c..aefb9d4 100644 --- a/src/disassem.cpp +++ b/src/disassem.cpp @@ -33,24 +33,6 @@ using namespace std; #define DELTA_ICODE 16 /* Number of icodes to realloc by each time */ -static const char *szOps[] = -{ - "CBW", "AAA", "AAD", "AAM", "AAS", "ADC", "ADD", "AND", - "BOUND","CALL", "CALL", "CLC", "CLD", "CLI", "CMC", "CMP", - "CMPS", "REPNE CMPS","REPE CMPS","DAA", "DAS", "DEC", "DIV", "ENTER", - "ESC", "HLT", "IDIV", "IMUL", "IN", "INC", "INS", "REP INS", - "INT", "IRET", "JB", "JBE", "JAE", "JA", "JE", "JNE", - "JL", "JGE", "JLE", "JG", "JS", "JNS", "JO", "JNO", - "JP", "JNP", "JCXZ", "JMP", "JMP", "LAHF", "LDS", "LEA", - "LEAVE","LES", "LOCK", "LODS", "REP LODS", "LOOP", "LOOPE","LOOPNE", - "MOV", "MOVS", "REP MOVS", "MUL", "NEG", "NOT", "OR", "OUT", - "OUTS", "REP OUTS", "POP", "POPA", "POPF", "PUSH", "PUSHA","PUSHF", - "RCL", "RCR", "ROL", "ROR", "RET", "RETF", "SAHF", "SAR", - "SHL", "SHR", "SBB", "SCAS", "REPNE SCAS","REPE SCAS", "CWD", "STC", - "STD", "STI", "STOS", "REP STOS", "SUB", "TEST", "WAIT", "XCHG", - "XLAT", "XOR", "INTO", "NOP", "REPNE", "REPE", "MOD" -}; - /* The following opcodes are for mod != 3 */ static const char *szFlops1[] = { @@ -120,10 +102,10 @@ static const char *szFlops3C[] = }; -static const char *szIndex[8] = {"bx+si", "bx+di", "bp+si", "bp+di", "si", "di","bp","bx" }; -static const char *szBreg[8] = { "al", "cl", "dl", "bl", "ah", "ch", "dh", "bh" }; -static const char *szWreg[12] = { "ax", "cx", "dx", "bx", "sp", "bp", "si", "di", - "es", "cs", "ss", "ds" }; +//static const char *szIndex[8] = {"bx+si", "bx+di", "bp+si", "bp+di", "si", "di","bp","bx" }; +//static const char *szBreg[8] = { "al", "cl", "dl", "bl", "ah", "ch", "dh", "bh" }; +//static const char *szWreg[12] = { "ax", "cx", "dx", "bx", "sp", "bp", "si", "di", +// "es", "cs", "ss", "ds" }; static const char *szPtr[2] = { "word ptr ", "byte ptr " }; @@ -139,7 +121,6 @@ boolT callArg(uint16_t off, char *temp); /* Check for procedure name */ static FILE *fp; static CIcodeRec pc; - static int cb, j, numIcode, allocIcode; static map pl; static uint32_t nextInst; @@ -229,14 +210,8 @@ void disassem(int pass, Function * ppProc) { /* Bind jump offsets to labels */ //for (i = 0; i < numIcode; i++) -#ifdef _lint - for (auto i=pc.begin(); i!=pc.end(); ++i) - { - ICODE &icode(*i); -#else for( ICODE &icode : pc) { -#endif LLInst *ll=icode.ll(); ll->findJumpTargets(pc); } @@ -251,14 +226,8 @@ void disassem(int pass, Function * ppProc) /* Loop over array printing each record */ nextInst = 0; -#ifdef _lint - for (auto i=pc.begin(); i!=pc.end(); ++i) - { - ICODE &icode(*i); -#else for( ICODE &icode : pc) { -#endif icode.ll()->dis1Line(icode.loc_ip,pass); } @@ -272,7 +241,6 @@ void disassem(int pass, Function * ppProc) pc.clear(); destroySymTables(); } - /**************************************************************************** * dis1Line() - disassemble one line to stream fp * * * i is index into Icode for this proc * @@ -292,16 +260,16 @@ void LLInst::dis1Line(int loc_ip, int pass) * Do not try to display NO_CODE entries or synthetic instructions, * other than JMPs, that have been introduced for def/use analysis. */ if ((option.asm1) && - ( testFlags(NO_CODE) || - (testFlags(SYNTHETIC) && (opcode != iJMP)))) + ( this->testFlags(NO_CODE) || + (this->testFlags(SYNTHETIC) && (this->getOpcode() != iJMP)))) { return; } - else if (testFlags(NO_CODE)) + else if (this->testFlags(NO_CODE)) { return; } - if (testFlags(TARGET | CASE)) + if (this->testFlags(TARGET | CASE)) { if (pass == 3) cCode.appendCode("\n"); /* Print to c code buffer */ @@ -310,19 +278,19 @@ void LLInst::dis1Line(int loc_ip, int pass) } /* Find next instruction label and print hex bytes */ - if (testFlags(SYNTHETIC)) - nextInst = label; + if (this->testFlags(SYNTHETIC)) + nextInst = this->label; else { - cb = (uint32_t) numBytes; - nextInst = label + cb; + cb = (uint32_t) this->numBytes; + nextInst = this->label + cb; /* Output hexa code in program image */ if (pass != 3) { for (j = 0; j < cb; j++) { - hex_bytes << hex << setw(2) << setfill('0') << uint16_t(prog.Image[label + j]); + hex_bytes << hex << setw(2) << setfill('0') << uint16_t(prog.Image[this->label + j]); } hex_bytes << ' '; } @@ -333,11 +301,11 @@ void LLInst::dis1Line(int loc_ip, int pass) oper_stream << setw(5)<label, 0)) { lab_contents << ':'; /* Also removes the null */ } - else if (testFlags(TARGET)) /* Symbols override Lnn labels */ + else if (this->testFlags(TARGET)) /* Symbols override Lnn labels */ { /* Print label */ if (pl.count(loc_ip)==0) @@ -348,13 +316,13 @@ void LLInst::dis1Line(int loc_ip, int pass) } oper_stream<< lab_contents.str(); } - if (opcode == iSIGNEX && testFlags(B)) + if ((this->getOpcode()==iSIGNEX )&& this->testFlags(B)) { - opcode = iCBW; + setOpcode(iCBW); } - opcode_with_mods<getOpcode()); - switch (opcode) + switch ( this->getOpcode() ) { case iADD: case iADC: case iSUB: case iSBB: case iAND: case iOR: case iXOR: case iTEST: case iCMP: case iMOV: case iLEA: case iXCHG: @@ -383,7 +351,6 @@ void LLInst::dis1Line(int loc_ip, int pass) if (testFlags(I)) { operands_s<ll()->immed.op)); } else { @@ -437,13 +404,13 @@ void LLInst::dis1Line(int loc_ip, int pass) { pl[j] = ++g_lab; } - if (opcode == iJMPF) + if (getOpcode() == iJMPF) { operands_s<<" far ptr "; } operands_s<<"L"<name; } - else if (opcode == iCALLF) + else if (getOpcode() == iCALLF) { operands_s<<"dword ptr "; strSrc(operands_s,true); @@ -493,21 +460,21 @@ void LLInst::dis1Line(int loc_ip, int pass) case iOUTS: case iREP_OUTS: if (src.segOver) { - bool is_dx_src=(opcode == iOUTS || opcode == iREP_OUTS); + bool is_dx_src=(getOpcode() == iOUTS || getOpcode() == iREP_OUTS); if(is_dx_src) operands_s<<"dx, "<= INDEX_BX_SI)) + if ((flg & I) and not pm.isReg()) os << szPtr[flg & B]; formatRM(os, flg, pm); return os; @@ -689,7 +652,6 @@ static ostringstream & strDst(ostringstream &os,uint32_t flg, LLOperand &pm) ****************************************************************************/ ostringstream &LLInst::strSrc(ostringstream &os,bool skip_comma) { - if(false==skip_comma) os<<", "; if (testFlags(I)) @@ -734,7 +696,7 @@ void LLInst::flops(std::ostringstream &out) /* Note that op is set to the escape number, e.g. esc 0x38 is FILD */ - if ((dst.regi == 0) || (dst.regi >= INDEX_BX_SI)) + if ( not dst.isReg() ) { /* The mod/rm mod bits are not set to 11 (i.e. register). This is the normal floating point opcode */ out< #include "dcc.h" -#ifdef _lint - static std::map errorMessage; -#else + static std::map errorMessage = { {INVALID_ARG ,"Invalid option -%c\n"}, @@ -34,8 +32,6 @@ {REPEAT_FAIL ,"Failed to construct repeat..until() condition.\n"}, {WHILE_FAIL ,"Failed to construct while() condition.\n"}, }; -#endif - /**************************************************************************** fatalError: displays error message and exits the program. diff --git a/src/frontend.cpp b/src/frontend.cpp index b308ffe..b5a641e 100644 --- a/src/frontend.cpp +++ b/src/frontend.cpp @@ -5,6 +5,7 @@ ****************************************************************************/ #include "dcc.h" +#include "disassem.h" #include #include #include @@ -75,14 +76,8 @@ void FrontEnd (char *filename, CALL_GRAPH * *pcallGraph) } /* Search through code looking for impure references and flag them */ -#ifdef _lint - for (auto i=pProcList.begin(); i!=pProcList.end(); ++i) - { - Function &f(*i); -#else for(Function &f : pProcList) { -#endif f.markImpure(); if (option.asm1) disassem(1, &f); @@ -93,14 +88,8 @@ void FrontEnd (char *filename, CALL_GRAPH * *pcallGraph) } /* Converts jump target addresses to icode offsets */ -#ifdef _lint - for (auto i=pProcList.begin(); i!=pProcList.end(); ++i) - { - Function &f(*i); -#else for(Function &f : pProcList) { -#endif f.bindIcodeOff(); } /* Print memory bitmap */ diff --git a/src/graph.cpp b/src/graph.cpp index 54c8b65..f812efd 100644 --- a/src/graph.cpp +++ b/src/graph.cpp @@ -161,14 +161,8 @@ CondJumps: void Function::markImpure() { SYM * psym; -#ifdef _lint - for (auto i=Icode.begin(); i!=Icode.end(); ++i) - { - ICODE &icod(*i); -#else for(ICODE &icod : Icode) { -#endif if ( not icod.ll()->testFlags(SYM_USE | SYM_DEF)) continue; psym = &symtab[icod.ll()->caseTbl.numEntries]; @@ -196,14 +190,8 @@ void Function::markImpure() ****************************************************************************/ void Function::freeCFG() { -#ifdef _lint - for (auto i=heldBBs.begin(); i!=heldBBs.end(); ++i) - { - BB *p(*i); -#else for(BB *p : heldBBs) { -#endif delete p; } } @@ -219,25 +207,12 @@ void Function::compressCFG() /* First pass over BB list removes redundant jumps of the form * (Un)Conditional -> Unconditional jump */ -#ifdef _lint - - for (auto iter=m_cfg.begin(); iter!=m_cfg.end(); ++iter) - { - BB *pBB(*iter); -#else for (BB *pBB : m_cfg) { -#endif if(pBB->inEdges.empty() || (pBB->nodeType != ONE_BRANCH && pBB->nodeType != TWO_BRANCH)) continue; -#ifdef _lint - for (auto iter2=pBB->edges.begin(); iter2!=pBB->edges.end(); ++iter2) - { - TYPEADR_TYPE &edgeRef(*iter2); -#else for (TYPEADR_TYPE &edgeRef : pBB->edges) { -#endif ip = pBB->rbegin()->loc_ip; pNxt = edgeRef.BBptr->rmJMP(ip, edgeRef.BBptr); @@ -246,6 +221,7 @@ void Function::compressCFG() edgeRef.BBptr = pNxt; assert(pBB->back().loc_ip==ip); pBB->back().ll()->SetImmediateOp((uint32_t)pNxt->begin()->loc_ip); + //Icode[ip].SetImmediateOp((uint32_t)pNxt->begin()); } } } @@ -403,14 +379,8 @@ void BB::dfsNumbering(std::vector &dfsLast, int *first, int *last) /* index is being used as an index to inEdges[]. */ // for (i = 0; i < edges.size(); i++) -#ifdef _lint - for (auto i=edges.begin(); i!=edges.end(); ++i) - { - auto edge(*i); -#else for(auto edge : edges) { -#endif pChild = edge.BBptr; pChild->inEdges[pChild->index++] = this; diff --git a/src/hlicode.cpp b/src/hlicode.cpp index 8471f01..b7299b6 100644 --- a/src/hlicode.cpp +++ b/src/hlicode.cpp @@ -78,7 +78,7 @@ void ICODE::setJCond(COND_EXPR *cexp) * it has been replaced by a high-level icode. */ void ICODE ::invalidate() { - invalid = TRUE; + invalid = true; } @@ -287,7 +287,6 @@ void Function::highLevelGen() COND_EXPR *lhs, *rhs; /* left- and right-hand side of expression */ uint32_t _flg; /* icode flags */ numIcode = Icode.size(); - lhs=rhs=0; for (iICODE i = Icode.begin(); i!=Icode.end() ; ++i) { assert(numIcode==Icode.size()); @@ -469,6 +468,7 @@ COND_EXPR *COND_EXPR::inverse () const return COND_EXPR::unary (NEGATION, this->clone()); case DBL_AND: case DBL_OR: + // Binary::Create(invertop,lhs->inverse(),rhs->inverse()); res = this->clone(); res->boolExpr.op = invCondOp[op()]; res->boolExpr.lhs=lhs()->inverse (); @@ -591,13 +591,9 @@ string HLTYPE::write1HlIcode (Function * pProc, int *numLoc) } -int power2 (int i) -/* Returns the value of 2 to the power of i */ -{ - if (i == 0) - return (1); - return (2 << (i-1)); -} +//TODO: replace all "< (INDEX_BX_SI-1)" with machine_x86::lastReg + +//TODO: replace all >= INDEX_BX_SI with machine_x86::isRegExpression /* Writes the registers/stack variables that are used and defined by this @@ -607,48 +603,29 @@ void ICODE::writeDU() int my_idx = loc_ip; { ostringstream ostr; - for (int i = 0; i < (INDEX_BX_SI-1); i++) - if (du.def[i]) - ostr << allRegs[i] << " "; + Machine_X86::writeBitVector(ostr,du.def); if (!ostr.str().empty()) printf ("Def (reg) = %s\n", ostr.str().c_str()); } { ostringstream ostr; - for (int i = 0; i < (INDEX_BX_SI-1); i++) - if (du.def[i]) - ostr << allRegs[i] << " "; - if (!ostr.str().empty()) - printf ("Def (reg) = %s\n", ostr.str().c_str()); - for (int i = 0; i < INDEX_BX_SI; i++) - { - if (du.use[i]) - ostr << allRegs[i] << " "; - } + Machine_X86::writeBitVector(ostr,du.use); if (!ostr.str().empty()) printf ("Use (reg) = %s\n", ostr.str().c_str()); - } /* Print du1 chain */ printf ("# regs defined = %d\n", du1.numRegsDef); for (int i = 0; i < MAX_REGS_DEF; i++) { - if (du1.used(i)) - { + if (not du1.used(i)) + continue; printf ("%d: du1[%d][] = ", my_idx, i); -#ifdef _lint - for (auto ik=du1.idx[i].uses.begin(); ik!=du1.idx[i].uses.end(); ++ik) - { - auto j(*ik); -#else for(auto j : du1.idx[i].uses) { -#endif printf ("%d ", j->loc_ip); } printf ("\n"); - } } /* For HLI_CALL, print # parameter bytes */ @@ -656,7 +633,3 @@ void ICODE::writeDU() printf ("# param bytes = %d\n", hl()->call.args->cb); printf ("\n"); } - - - - diff --git a/src/icode.cpp b/src/icode.cpp index 97032d4..ef67e0f 100644 --- a/src/icode.cpp +++ b/src/icode.cpp @@ -29,14 +29,8 @@ ICODE * CIcodeRec::addIcode(ICODE *pIcode) void CIcodeRec::SetInBB(int start, int _end, BB *pnewBB) { -#ifdef _lint - for (auto ik=this->begin(); ik!=this->end(); ++ik) - { - ICODE &icode(*ik); -#else for(ICODE &icode : *this) { -#endif if((icode.loc_ip>=start) and (icode.loc_ip<=_end)) icode.inBB = pnewBB; } @@ -46,7 +40,6 @@ void CIcodeRec::SetInBB(int start, int _end, BB *pnewBB) replaces *pIndex with an icode index */ bool CIcodeRec::labelSrch(uint32_t target, uint32_t &pIndex) { - iICODE location=labelSrch(target); if(end()==location) return false; @@ -55,7 +48,6 @@ bool CIcodeRec::labelSrch(uint32_t target, uint32_t &pIndex) } CIcodeRec::iterator CIcodeRec::labelSrch(uint32_t target) { - return find_if(begin(),end(),[target](ICODE &l) -> bool {return l.ll()->label==target;}); } ICODE * CIcodeRec::GetIcode(int ip) @@ -66,7 +58,6 @@ ICODE * CIcodeRec::GetIcode(int ip) return &(*res); } - extern int getNextLabel(); extern bundle cCode; /* Checks the given icode to determine whether it has a label associated @@ -90,3 +81,9 @@ void LLInst::emitGotoLabel (int indLevel) stats.numHLIcode++; } + + +bool LLOperand::isReg() const +{ + return (regi>=rAX) && (regi<=rTMP); +} diff --git a/src/idioms.cpp b/src/idioms.cpp index b460331..86c5432 100644 --- a/src/idioms.cpp +++ b/src/idioms.cpp @@ -16,13 +16,13 @@ #include "arith_idioms.h" #include "dcc.h" #include -//#include +#include /***************************************************************************** * JmpInst - Returns TRUE if opcode is a conditional or unconditional jump ****************************************************************************/ bool LLInst::isJmpInst() { - switch (opcode) + switch (getOpcode()) { case iJMP: case iJMPF: case iJCXZ: case iLOOP: case iLOOPE:case iLOOPNE: @@ -74,9 +74,9 @@ void Function::findIdioms() Idiom20 i20(this); struct is_valid { - bool operator()(ICODE &z) { return not z.invalid;} + bool operator()(ICODE &z) { return z.valid();} }; - //typedef boost::filter_iterator ifICODE; + typedef boost::filter_iterator ifICODE; while (pIcode != pEnd) { switch (pIcode->ll()->getOpcode()) @@ -230,14 +230,8 @@ void Function::bindIcodeOff() pIcode = Icode.begin(); /* Flag all jump targets for BB construction and disassembly stage 2 */ -#ifdef _lint - for (auto ik=Icode.begin(); ik!=Icode.end(); ++ik) - { - ICODE &c(*ik); -#else for(ICODE &c : Icode) { -#endif LLInst *ll=c.ll(); if (ll->testFlags(I) && ll->isJmpInst()) { @@ -251,14 +245,8 @@ void Function::bindIcodeOff() * is found (no code at dest. of jump) are simply left unlinked and * flagged as going nowhere. */ //for (pIcode = Icode.begin(); pIcode!= Icode.end(); pIcode++) -#ifdef _lint - for (auto ik=Icode.begin(); ik!=Icode.end(); ++ik) - { - ICODE &icode(*ik); -#else for(ICODE &icode : Icode) { -#endif LLInst *ll=icode.ll(); if (not ll->isJmpInst()) continue; diff --git a/src/idioms/arith_idioms.cpp b/src/idioms/arith_idioms.cpp index 19e26c1..bd9b4cc 100644 --- a/src/idioms/arith_idioms.cpp +++ b/src/idioms/arith_idioms.cpp @@ -105,7 +105,7 @@ bool Idiom18::match(iICODE picode) /* not supported yet */ type = 0; } - else if (m_icodes[1]->ll()->dst.regi < INDEX_BX_SI) /* register */ + else if ( m_icodes[1]->ll()->dst.isReg() ) /* register */ { if ((m_icodes[1]->ll()->dst.regi == rSI) && (m_func->flg & SI_REGVAR)) type = 1; @@ -131,7 +131,7 @@ bool Idiom18::match(iICODE picode) if (m_icodes[0]->ll()->match(iMOV) && (m_icodes[0]->ll()->src.regi == m_icodes[1]->ll()->dst.regi)) { regi = m_icodes[0]->ll()->dst.regi; - if ((regi > 0) && (regi < INDEX_BX_SI)) + if ( m_icodes[0]->ll()->dst.isReg() ) { if ( m_icodes[2]->ll()->match(iCMP) && (m_icodes[2]->ll()->dst.regi == regi) && m_icodes[3]->ll()->conditionalJump() ) @@ -143,7 +143,7 @@ bool Idiom18::match(iICODE picode) if (m_icodes[0]->ll()->match(iMOV) && (m_icodes[0]->ll()->src.off == m_icodes[1]->ll()->dst.off)) { regi = m_icodes[0]->ll()->dst.regi; - if ((regi > 0) && (regi < INDEX_BX_SI)) + if ( m_icodes[0]->ll()->dst.isReg() ) { if ( m_icodes[2]->ll()->match(iCMP) && (m_icodes[2]->ll()->dst.regi == regi) && m_icodes[3]->ll()->conditionalJump() ) @@ -194,7 +194,7 @@ bool Idiom19::match(iICODE picode) m_is_dec = m_icodes[0]->ll()->match(iDEC); if (m_icodes[0]->ll()->dst.regi == 0) /* global variable */ /* not supported yet */ ; - else if (m_icodes[0]->ll()->dst.regi < INDEX_BX_SI) /* register */ + else if ( m_icodes[0]->ll()->dst.isReg() ) /* register */ { // if (((picode->ll()->dst.regi == rSI) && (pproc->flg & SI_REGVAR)) || // ((picode->ll()->dst.regi == rDI) && (pproc->flg & DI_REGVAR))) @@ -248,23 +248,24 @@ bool Idiom20::match(iICODE picode) m_is_dec = m_icodes[0]->ll()->match(iDEC); + LLOperand &ll_dest(m_icodes[0]->ll()->dst); /* Get variable */ - if (m_icodes[0]->ll()->dst.regi == 0) /* global variable */ + if (ll_dest.regi == 0) /* global variable */ { /* not supported yet */ ; } - else if (m_icodes[0]->ll()->dst.regi < INDEX_BX_SI) /* register */ + else if ( ll_dest.isReg() ) /* register */ { - if ((m_icodes[0]->ll()->dst.regi == rSI) && (m_func->flg & SI_REGVAR)) + if ((ll_dest.regi == rSI) && (m_func->flg & SI_REGVAR)) type = 1; - else if ((m_icodes[0]->ll()->dst.regi == rDI) && (m_func->flg & DI_REGVAR)) + else if ((ll_dest.regi == rDI) && (m_func->flg & DI_REGVAR)) type = 1; } - else if (m_icodes[0]->ll()->dst.off) /* local variable */ + else if (ll_dest.off) /* local variable */ type = 2; else /* indexed */ { - printf("idiom20 : Unsupported type\n"); + printf("idiom20 : Unsupported type [indexed]\n"); /* not supported yet */ ; } @@ -272,10 +273,10 @@ bool Idiom20::match(iICODE picode) if (type == 1) /* register variable */ { if (m_icodes[1]->ll()->match(iMOV) && - (m_icodes[1]->ll()->src.regi == m_icodes[0]->ll()->dst.regi)) + (m_icodes[1]->ll()->src.regi == ll_dest.regi)) { regi = m_icodes[1]->ll()->dst.regi; - if ((regi > 0) && (regi < INDEX_BX_SI)) + if ( m_icodes[1]->ll()->dst.isReg() ) { if (m_icodes[2]->ll()->match(iCMP,(eReg)regi) && m_icodes[3]->ll()->conditionalJump()) @@ -286,10 +287,10 @@ bool Idiom20::match(iICODE picode) else if (type == 2) /* local */ { if ( m_icodes[0]->ll()->match(iMOV) && - (m_icodes[1]->ll()->src.off == m_icodes[0]->ll()->dst.off)) + (m_icodes[1]->ll()->src.off == ll_dest.off)) { regi = m_icodes[1]->ll()->dst.regi; - if ((regi > 0) && (regi < INDEX_BX_SI)) + if ( m_icodes[1]->ll()->dst.isReg() ) { if (m_icodes[2]->ll()->match(iCMP,(eReg)regi) && m_icodes[3]->ll()->conditionalJump()) diff --git a/src/idioms/epilogue_idioms.cpp b/src/idioms/epilogue_idioms.cpp index 3fd9301..850d9f0 100644 --- a/src/idioms/epilogue_idioms.cpp +++ b/src/idioms/epilogue_idioms.cpp @@ -140,7 +140,7 @@ int Idiom4::action() { if( ! m_icodes.empty()) // if not an empty RET[F] N { - for(size_t idx=0; idxinvalidate(); } if(m_param_count) diff --git a/src/idioms/idiom1.cpp b/src/idioms/idiom1.cpp index 04209b0..9c3fd20 100644 --- a/src/idioms/idiom1.cpp +++ b/src/idioms/idiom1.cpp @@ -123,14 +123,8 @@ bool Idiom1::match(iICODE picode) } int Idiom1::action() { -#ifdef _lint - for (auto ik=m_icodes.begin(); ik!=m_icodes.end(); ++ik) - { - iICODE ic(*ik); -#else for(iICODE ic : m_icodes) { -#endif ic->invalidate(); } m_func->flg |= PROC_HLL; diff --git a/src/idioms/shift_idioms.cpp b/src/idioms/shift_idioms.cpp index afa4118..649c216 100644 --- a/src/idioms/shift_idioms.cpp +++ b/src/idioms/shift_idioms.cpp @@ -57,7 +57,6 @@ int Idiom8::action() ****************************************************************************/ bool Idiom15::match(iICODE pIcode) { - uint8_t regi; if(distance(pIcode,m_end)<2) @@ -72,7 +71,6 @@ bool Idiom15::match(iICODE pIcode) pIcode->ll()->match(iSHL,(eReg)regi,I) and (pIcode->ll()->src.op() == 1) ) { - m_icodes.push_back(pIcode++); } return m_icodes.size()>1; diff --git a/src/machine_x86.cpp b/src/machine_x86.cpp index ac452e3..d0a1062 100644 --- a/src/machine_x86.cpp +++ b/src/machine_x86.cpp @@ -1,4 +1,4 @@ - +#include #include "machine_x86.h" // Index registers **** temp solution static const std::string regNames[] = { @@ -22,5 +22,35 @@ Machine_X86::Machine_X86() const std::string &Machine_X86::regName(eReg r) { + assert(r<(sizeof(regNames)/sizeof(std::string))); return regNames[r]; } + +static const std::string szOps[] = +{ + "CBW", "AAA", "AAD", "AAM", "AAS", "ADC", "ADD", "AND", + "BOUND","CALL", "CALL", "CLC", "CLD", "CLI", "CMC", "CMP", + "CMPS", "REPNE CMPS","REPE CMPS","DAA", "DAS", "DEC", "DIV", "ENTER", + "ESC", "HLT", "IDIV", "IMUL", "IN", "INC", "INS", "REP INS", + "INT", "IRET", "JB", "JBE", "JAE", "JA", "JE", "JNE", + "JL", "JGE", "JLE", "JG", "JS", "JNS", "JO", "JNO", + "JP", "JNP", "JCXZ", "JMP", "JMP", "LAHF", "LDS", "LEA", + "LEAVE","LES", "LOCK", "LODS", "REP LODS", "LOOP", "LOOPE","LOOPNE", + "MOV", "MOVS", "REP MOVS", "MUL", "NEG", "NOT", "OR", "OUT", + "OUTS", "REP OUTS", "POP", "POPA", "POPF", "PUSH", "PUSHA","PUSHF", + "RCL", "RCR", "ROL", "ROR", "RET", "RETF", "SAHF", "SAR", + "SHL", "SHR", "SBB", "SCAS", "REPNE SCAS","REPE SCAS", "CWD", "STC", + "STD", "STI", "STOS", "REP STOS", "SUB", "TEST", "WAIT", "XCHG", + "XLAT", "XOR", "INTO", "NOP", "REPNE", "REPE", "MOD" +}; + +const std::string &Machine_X86::opcodeName(unsigned r) +{ + assert(r<(sizeof(szOps)/sizeof(std::string))); + return szOps[r]; +} + +bool Machine_X86::physicalReg(eReg r) +{ + return (r>=rAX) && (rregi == 0) { /* Global var */ + if (pm->regi == 0) + { + /* Global var */ if (pm->segValue) { /* there is a value in the seg field */ operand = opAdr (pm->segValue, pm->off); psym = updateGlobSym (operand, size, duFlag); @@ -1043,7 +1045,6 @@ void Function::process_operands(ICODE & pIcode, STATE * pstate) if (! Imm) { use(SRC, pIcode, this, pstate, cb, ix); } - //lint -fallthrough case iINC: case iDEC: case iNEG: case iNOT: case iAAA: case iAAD: case iAAM: case iAAS: case iDAA: case iDAS: diff --git a/src/perfhlib.cpp b/src/perfhlib.cpp index 3788742..931f676 100644 --- a/src/perfhlib.cpp +++ b/src/perfhlib.cpp @@ -47,6 +47,7 @@ PatternHasher::init(int _NumEntry, int _EntryLen, int _SetSize, char _SetMin, g = new short [NumVert + 1]; // visited = new bool [NumVert + 1]; return; + } void PatternHasher::cleanup(void) diff --git a/src/procs.cpp b/src/procs.cpp index 7632f04..26110fa 100644 --- a/src/procs.cpp +++ b/src/procs.cpp @@ -23,7 +23,6 @@ const char *indentStr(int indLevel) // Indentation according to the depth of the /* Inserts an outEdge at the current callGraph pointer if the newProc does * not exist. */ -//lint -sem(vector::push,custodial(1)) void CALL_GRAPH::insertArc (ilFunction newProc) { CALL_GRAPH *pcg; @@ -109,7 +108,7 @@ void Function::newRegArg(iICODE picode, iICODE ticode) /* Flag ticode as having register arguments */ tproc = ticode->hl()->call.proc; tproc->flg |= REG_ARGS; - tidx = 0; + /* Get registers and index into target procedure's local list */ ps = ticode->hl()->call.args; ts = &tproc->args; diff --git a/src/proplong.cpp b/src/proplong.cpp index c5848a7..af6f5ef 100644 --- a/src/proplong.cpp +++ b/src/proplong.cpp @@ -67,8 +67,8 @@ static boolT isLong22 (iICODE pIcode, iICODE pEnd, iICODE &off) // preincrement because pIcode is not checked here iICODE icodes[] = { ++pIcode,++pIcode,++pIcode }; if ( icodes[1]->ll()->match(iCMP) && - (isJCond (icodes[0]->ll()->getOpcode())) && - (isJCond (icodes[2]->ll()->getOpcode()))) + (isJCond ((llIcode)icodes[0]->ll()->getOpcode())) && + (isJCond ((llIcode)icodes[2]->ll()->getOpcode()))) { off = initial_icode; advance(off,2); @@ -244,7 +244,7 @@ void Function::propLongStk (int i, const ID &pLocId) next1 = ++iICODE(pIcode); if(next1==pEnd) break; - if ((pIcode->type == HIGH_LEVEL) || (pIcode->invalid == TRUE)) + if ((pIcode->type == HIGH_LEVEL) || ( not pIcode->valid() )) continue; if (pIcode->ll()->getOpcode() == next1->ll()->getOpcode()) { @@ -312,7 +312,7 @@ int Function::findBackwarLongDefs(int loc_ident_idx, const ID &pLocId, iICODE be ICODE &icode(*pIcode); - if ((icode.type == HIGH_LEVEL) || (icode.invalid == TRUE)) + if ((icode.type == HIGH_LEVEL) || ( not icode.valid() )) continue; if (icode.ll()->getOpcode() != next1->ll()->getOpcode()) continue; @@ -391,7 +391,7 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be LLOperand * pmH,* pmL; /* Pointers to dst LOW_LEVEL icodes */ int arc; - if ((pIcode->type == HIGH_LEVEL) || (pIcode->invalid == TRUE)) + if ((pIcode->type == HIGH_LEVEL) || ( not pIcode->valid() )) continue; if (pIcode->ll()->getOpcode() == next1->ll()->getOpcode()) @@ -478,7 +478,7 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be * JX lab * => HLI_JCOND (regH:regL X 0) lab * This is better code than HLI_JCOND (HI(regH:regL) | LO(regH:regL)) */ - else if (pIcode->ll()->match(iOR) && (next1 != pEnd) && (isJCond (next1->ll()->getOpcode()))) + else if (pIcode->ll()->match(iOR) && (next1 != pEnd) && (isJCond ((llIcode)next1->ll()->getOpcode()))) { if ((pIcode->ll()->dst.regi == pLocId.id.longId.h) && (pIcode->ll()->src.regi == pLocId.id.longId.l)) { diff --git a/src/reducible.cpp b/src/reducible.cpp index 68e607e..d718beb 100644 --- a/src/reducible.cpp +++ b/src/reducible.cpp @@ -35,7 +35,6 @@ static BB *firstOfQueue (queue &Q) /* Appends pointer to node at the end of the queue Q if node is not present * in this queue. Returns the queue node just appended. */ -//lint -sem(appendQueue,custodial(1)) queue::iterator appendQueue (queue &Q, BB *node) { auto iter=std::find(Q.begin(),Q.end(),node); @@ -100,7 +99,7 @@ static void appendNodeInt (queue &pqH, BB *node, interval *pI) void derSeq_Entry::findIntervals (Function *c) { interval *pI, /* Interval being processed */ - *J=0; /* ^ last interval in derivedGi->Ii */ + *J; /* ^ last interval in derivedGi->Ii */ BB *h, /* Node being processed */ *header, /* Current interval's header node */ *succ; /* Successor basic block */ @@ -174,17 +173,12 @@ void derSeq_Entry::findIntervals (Function *c) /* Displays the intervals of the graph Gi. */ static void displayIntervals (interval *pI) { + while (pI) { printf (" Interval #: %ld\t#OutEdges: %ld\n", pI->numInt, pI->numOutEdges); -#ifdef _lint - for(auto iter=pI->nodes.begin(); iter!=pI->nodes.end(); ++iter) - { - BB *node(*iter); -#else for(BB *node : pI->nodes) { -#endif if (node->correspInt == NULL) /* real BBs */ printf (" Node: %ld\n", node->begin()->loc_ip); else // BBs represent intervals @@ -275,14 +269,8 @@ bool Function::nextOrderGraph (derSeq &derivedGi) if (BBnode->edges.size() > 0) { -#ifdef _lint - for (auto ik=listIi.begin(); ik!=listIi.end(); ++ik) - { - BB *curr(*ik); -#else for(BB *curr : listIi) { -#endif for (j = 0; j < curr->edges.size(); j++) { succ = curr->edges[j].BBptr; @@ -300,22 +288,10 @@ bool Function::nextOrderGraph (derSeq &derivedGi) * Determines the number of in edges to each new BB, and places it * in numInEdges and inEdgeCount for later interval processing. */ curr = new_entry.Gi = bbs.front(); -#ifdef _lint - for (auto ik=bbs.begin(); ik!=bbs.end(); ++ik) - { - BB *curr(*ik); -#else for(BB *curr : bbs) { -#endif -#ifdef _lint - for (auto il=curr->edges.begin(); il!=curr->edges.end(); ++il) - { - TYPEADR_TYPE &edge(*il); -#else for(TYPEADR_TYPE &edge : curr->edges) { -#endif BBnode = new_entry.Gi; /* BB of an interval */ auto iter= std::find_if(bbs.begin(),bbs.end(), [&edge](BB *node)->bool { return edge.intPtr==node->correspInt;}); diff --git a/src/scanner.cpp b/src/scanner.cpp index dedb6f5..ca178de 100644 --- a/src/scanner.cpp +++ b/src/scanner.cpp @@ -785,7 +785,7 @@ static void prefix(int ) inline void BumpOpcode(LLInst &ll) { - llIcode ic = ll.getOpcode(); + llIcode ic((llIcode)ll.getOpcode()); ic = (llIcode)(((int)ic)+1); // Bump this icode via the int type ll.setOpcode(ic); } diff --git a/src/udm.cpp b/src/udm.cpp index 1bfeb57..9334b2d 100644 --- a/src/udm.cpp +++ b/src/udm.cpp @@ -91,14 +91,8 @@ void udm(void) void Function::displayCFG() { printf("\nBasic Block List - Proc %s", name.c_str()); -#ifdef _lint - for (auto ik=m_cfg.begin(); ik!=m_cfg.end(); ++ik) - { - BB *pBB(*ik); -#else for (BB *pBB : m_cfg) { -#endif pBB->display(); } }