Browse Source

Removed lints

Artur K 12 years ago
parent
commit
3bcbb7a2cf

+ 1 - 0
include/BasicBlock.h

@@ -40,6 +40,7 @@ private:
     //friend class SymbolTableListTraits<BB, Function>;
     iICODE  range_start;
     iICODE  range_end;
+
 public:
     iICODE begin();
     iICODE end() const;

+ 1 - 0
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       */
 };

+ 2 - 6
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);

+ 5 - 0
include/disassem.h

@@ -2,6 +2,11 @@
  *  dcc project disassembler header
  * (C) Mike van Emmerik
  ****************************************************************************/
+#pragma once
+#include <sstream>
+#include <vector>
+#include "bundle.h"
+struct LLInst;
 
 /* Definitions for extended keys (first key is zero) */
 

+ 1 - 1
include/error.h

@@ -30,7 +30,7 @@ enum eErrorId
     WHILE_FAIL
 };
 
-//lint -function(exit,fatalError)
+
 void fatalError(eErrorId errId, ...);
 void reportError(eErrorId errId, ...);
 

+ 44 - 21
include/icode.h

@@ -3,11 +3,13 @@
  * (C) Cristina Cifuentes
  ****************************************************************************/
 #pragma once
+#include <memory>
 #include <vector>
 #include <list>
 #include <bitset>
 #include <llvm/ADT/ilist.h>
 #include <llvm/ADT/ilist_node.h>
+#include <llvm/CodeGen/MachineInstr.h>
 #include <llvm/MC/MCInst.h>
 #include <llvm/MC/MCAsmInfo.h>
 #include "Enums.h"
@@ -20,9 +22,12 @@ struct Function;
 struct STKFRAME;
 struct CIcodeRec;
 struct ICODE;
+struct bundle;
 typedef std::list<ICODE>::iterator iICODE;
 typedef std::list<ICODE>::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<LLInst>
+struct LLInst : public llvm::MCInst //: public llvm::ilist_node<LLInst>
 {
 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<std::shared_ptr<LLInst> > m_low_level;
+    std::list<std::shared_ptr<HLTYPE> > m_middle_level;
 };
-
 // This is the icode array object.
 class CIcodeRec : public std::list<ICODE>
 {

+ 17 - 0
include/machine_x86.h

@@ -1,5 +1,8 @@
 #pragma once
+#include <stdint.h>
 #include <string>
+#include <sstream>
+#include <bitset>
 /* Machine registers */
 enum eReg
 {
@@ -45,4 +48,18 @@ class Machine_X86
 public:
     Machine_X86();
     static const std::string &regName(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> &regi)
+    {
+        int j;
+        for (j = rAX; j < INDEX_BX_SI; j++)
+        {
+            if (regi.test(j-1))
+                ostr << regName(eReg(j));
+        }
+    }
+
 };

+ 1 - 1
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);
     }
 };

+ 1 - 32
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()
 {

+ 10 - 11
src/ast.cpp

@@ -5,7 +5,6 @@
  * (C) Cristina Cifuentes
  */
 #include <stdint.h>
-//#include <malloc.h>		// For free()
 #include <string>
 #include <sstream>
 #include <iostream>
@@ -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;
+
 }

+ 26 - 46
src/backend.cpp

@@ -8,7 +8,9 @@
 #include <string>
 
 #include "dcc.h"
+#include "disassem.h"
 #include <fstream>
+#include <iostream>
 #include <sstream>
 #include <string.h>
 #include <stdio.h>
@@ -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> &regi)
-{
-    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> &regi)
  *		 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<<hlTypes[args.sym[i].type]<<" "<<args.sym[i].name;
             if (i < (args.sym.size() - 1))
-                strcat (buf, ", ");
+                buf<<", ";
         }
     }
-    strcat (buf, ")\n");
-    cCode.appendDecl( "%s", buf);
+    buf<<")\n";
+    cCode.appendDecl( buf.str() );
 
     /* Write comments */
     writeProcComments();
@@ -253,14 +235,8 @@ void Function::codeGen (std::ostream &fs)
     if (! (flg & PROC_ASM))
     {
         numLoc = 0;
-#ifdef _lint
-        for (size_t i = 0; i < localId.csym(); i++)
-        {
-            ID &refId(localId.id_arr[i]);
-#else
         for (ID &refId : localId )
         {
-#endif
             /* Output only non-invalidated entries */
             if (refId.illegal == FALSE)
             {
@@ -290,7 +266,9 @@ void Function::codeGen (std::ostream &fs)
     if (flg & PROC_ASM)		/* generate assembler */
         disassem (3, this);
     else							/* generate C */
+    {
         m_cfg.front()->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 "<<i<<"\n";
+            cout << "  Start = "<<pBB->begin()->loc_ip;
+            cout << ", end = "<<pBB->begin()->loc_ip+pBB->size()<<"\n";
+            cout << "  LiveUse = ";
+            Machine_X86::writeBitVector(cout,pBB->liveUse);
+            cout << "\n  Def = ";
+            Machine_X86::writeBitVector(cout,pBB->def);
+            cout << "\n  LiveOut = ";
+            Machine_X86::writeBitVector(cout,pBB->liveOut);
+            cout << "\n  LiveIn = ";
+            Machine_X86::writeBitVector(cout,pBB->liveIn);
+            cout <<"\n\n";
         }
 }
 
@@ -321,6 +300,7 @@ void Function::codeGen (std::ostream &fs)
  * of the call graph.	*/
 static void backBackEnd (char *filename, CALL_GRAPH * pcallGraph, std::ostream &_ios)
 {
+
     //	IFace.Yield();			/* This is a good place to yield to other apps */
 
     /* Check if this procedure has been processed already */

+ 7 - 1
src/bundle.cpp

@@ -63,8 +63,8 @@ static void freeStrTab (strTable &strTab)
 }
 
 
-void freeBundle (bundle *procCode)
 /* Deallocates the space taken by the bundle procCode */
+void freeBundle (bundle *procCode)
 {
     freeStrTab (procCode->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);
+}
+
+
 

+ 10 - 4
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);

+ 8 - 43
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;

+ 31 - 35
src/dataflow.cpp

@@ -6,14 +6,14 @@
  ****************************************************************************/
 
 #include "dcc.h"
-//#include <boost/range.hpp>
-//#include <boost/range/adaptors.hpp>
-//#include <boost/range/algorithm.hpp>
+#include <boost/range.hpp>
+#include <boost/range/adaptors.hpp>
+#include <boost/range/algorithm.hpp>
 #include <string.h>
 #include <iostream>
 #include <iomanip>
 #include <stdio.h>
-//using namespace boost;
+using namespace boost;
 struct ExpStack
 {
     typedef std::list<COND_EXPR *> 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 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 isAH = !isAx && _liveOut.test(rAH - 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;

+ 2 - 6
src/dcc.cpp

@@ -8,7 +8,6 @@
 #include <string.h>
 
 /* 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:;
     }

+ 49 - 87
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<int,int> 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)<<left; // align for the labels
     {
         ostringstream lab_contents;
-        if (readVal(lab_contents, label, 0))
+        if (readVal(lab_contents, this->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<<szOps[opcode];
+    opcode_with_mods<<Machine_X86::opcodeName(this->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<<strHex(src.op());
-//                strcpy(p + WID_PTR, strHex(pIcode->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"<<pl[j];
             }
-            else if (opcode == iJMPF)
+            else if (getOpcode() == iJMPF)
             {
                 operands_s<<"dword ptr";
                 strSrc(operands_s,true);
@@ -457,13 +424,13 @@ void LLInst::dis1Line(int loc_ip, int pass)
         case iCALL: case iCALLF:
             if (testFlags(I))
             {
-                if((opcode == iCALL))
+                if((getOpcode() == iCALL))
                     operands_s<< "near";
                 else
                     operands_s<< " far";
                 operands_s<<" ptr "<<(src.proc.proc)->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, "<<szPtr[getFlag() & B];
                 else
                     operands_s<<szPtr[getFlag() & B];
-                if (opcode == iLODS ||
-                    opcode == iREP_LODS ||
-                    opcode == iOUTS ||
-                    opcode == iREP_OUTS)
+                if (getOpcode() == iLODS ||
+                    getOpcode() == iREP_LODS ||
+                    getOpcode() == iOUTS ||
+                    getOpcode() == iREP_OUTS)
                 {
-                    operands_s<<szWreg[src.segOver-rAX];
+                    operands_s<<Machine_X86::regName(src.segOver); // szWreg[src.segOver-rAX]
                 }
                 else
                 {
-                    operands_s<<"es:[di], "<<szWreg[src.segOver - rAX];
+                    operands_s<<"es:[di], "<<Machine_X86::regName(src.segOver);
                 }
                 operands_s<<":[si]";
             }
@@ -521,7 +488,7 @@ void LLInst::dis1Line(int loc_ip, int pass)
             if (src.segOver)
             {
                 operands_s<<" "<<szPtr[1];
-                operands_s<<szWreg[src.segOver-rAX]<<":[bx]";
+                operands_s<<Machine_X86::regName(src.segOver)<<":[bx]";
             }
             break;
 
@@ -593,7 +560,7 @@ void LLInst::dis1Line(int loc_ip, int pass)
     }
 
     /* Comment on iINT icodes */
-    if (opcode == iINT)
+    if (getOpcode() == iINT)
         writeIntComment(result_stream);
 
     /* Display output line */
@@ -628,45 +595,41 @@ void LLInst::dis1Line(int loc_ip, int pass)
  ***************************************************************************/
 static void formatRM(std::ostringstream &p, uint32_t flg, const LLOperand &pm)
 {
-    char    seg[4];
+    //char    seg[4];
 
     if (pm.segOver)
     {
-        strcat(strcpy(seg, szWreg[pm.segOver - rAX]), ":");
-    }
-    else    *seg = '\0';
-
-    if (pm.regi == 0)
-    {
-        p<<seg<<"["<<strHex((uint32_t)pm.off)<<"]";
+        p <<Machine_X86::regName(pm.segOver)<<':';
+        //strcat(strcpy(seg, szWreg[pm.segOver - rAX]), ":");
     }
+    //else    *seg = '\0';
 
-    else if (pm.regi == (INDEX_BX_SI - 1))
+    if (pm.regi == rUNDEF)
     {
-        p<<"tmp";
+        p<<"["<<strHex((uint32_t)pm.off)<<"]";
     }
-
-    else if (pm.regi < INDEX_BX_SI)
+    else if (pm.isReg())
     {
-        if(flg & B)
-            p << szBreg[pm.regi - rAL];
-        else
-            p << szWreg[pm.regi - rAX];
+        p<<Machine_X86::regName(pm.regi);
+//        if(flg & B)
+//            p << szBreg[pm.regi - rAL];
+//        else
+//            p << szWreg[pm.regi - rAX];
     }
 
     else if (pm.off)
     {
         if (pm.off < 0)
         {
-            p <<seg<<"["<<szIndex[pm.regi - INDEX_BX_SI]<<"-"<<strHex((uint32_t)(- pm.off))<<"]";
+            p <<"["<<Machine_X86::regName(pm.regi)<<"-"<<strHex((uint32_t)(- pm.off))<<"]";
         }
         else
         {
-            p <<seg<<"["<<szIndex[pm.regi - INDEX_BX_SI]<<"+"<<strHex((uint32_t)(pm.off))<<"]";
+            p <<"["<<Machine_X86::regName(pm.regi)<<"+"<<strHex((uint32_t)(pm.off))<<"]";
         }
     }
     else
-        p <<seg<<"["<<szIndex[pm.regi - INDEX_BX_SI]<<"]";
+        p <<"["<<Machine_X86::regName(pm.regi)<<"]";
 }
 
 
@@ -677,7 +640,7 @@ static ostringstream & strDst(ostringstream &os,uint32_t flg, LLOperand &pm)
 {
     /* Immediates to memory require size descriptor */
     //os << setw(WID_PTR);
-    if ((flg & I) && (pm.regi == 0 || pm.regi >= 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<<szFlops1[op]<<' ';

+ 1 - 5
src/error.cpp

@@ -10,9 +10,7 @@
 #include <stdarg.h>
 
 #include "dcc.h"
-#ifdef _lint
-    static std::map<eErrorId,std::string> errorMessage;
-#else
+
     static std::map<eErrorId,std::string> 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.

+ 1 - 12
src/frontend.cpp

@@ -5,6 +5,7 @@
 ****************************************************************************/
 
 #include "dcc.h"
+#include "disassem.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -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 */

+ 1 - 31
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<BB *> &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;
 

+ 9 - 36
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");
 }
-
-
-
-

+ 6 - 9
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);
+}

+ 4 - 16
src/idioms.cpp

@@ -16,13 +16,13 @@
 #include "arith_idioms.h"
 #include "dcc.h"
 #include <llvm/Support/PatternMatch.h>
-//#include <boost/iterator/filter_iterator.hpp>
+#include <boost/iterator/filter_iterator.hpp>
 /*****************************************************************************
  * 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<is_valid,iICODE> ifICODE;
+    typedef boost::filter_iterator<is_valid,iICODE> 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;

+ 15 - 14
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())

+ 1 - 1
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; idx<m_icodes.size()-1; ++idx) // invalidate all but the RET
+    for(size_t idx=0; idx<m_icodes.size()-1; ++idx) // don't invalidate last entry
             m_icodes[idx]->invalidate();
     }
     if(m_param_count)

+ 0 - 6
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;

+ 0 - 2
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;

+ 31 - 1
src/machine_x86.cpp

@@ -1,4 +1,4 @@
-
+#include <cassert>
 #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) && (r<rTMP);
+}

+ 4 - 3
src/parser.cpp

@@ -19,7 +19,7 @@ static void     process_MOV(LLInst &ll, STATE * pstate);
 static SYM *     lookupAddr (LLOperand *pm, STATE * pstate, int size, uint16_t duFlag);
 void    interactDis(Function * initProc, int ic);
 static uint32_t    SynthLab;
-
+//TODO: Move these to Machine_X86
 /*constexpr */eReg subRegH(eReg reg)
 {
     return eReg((int)reg + (int)rAH-(int)rAX);
@@ -798,7 +798,9 @@ static SYM * lookupAddr (LLOperand *pm, STATE *pstate, int size, uint16_t duFlag
     SYM *    psym;
     uint32_t   operand;
 
-    if (pm->regi == 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:

+ 1 - 0
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)

+ 1 - 2
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<CALL_GRAPH *>::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;

+ 6 - 6
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))
             {

+ 2 - 26
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;});

+ 1 - 1
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);
 }

+ 0 - 6
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();
     }
 }