Browse Source

more fixes

Artur K 12 years ago
parent
commit
eb6c1ac939

+ 2 - 0
CMakeLists.txt

@@ -35,6 +35,7 @@ set(dcc_SOURCES
     src/frontend.cpp
     src/graph.cpp
     src/hlicode.cpp
+    src/machine_x86.cpp
     src/icode.cpp
     src/idioms.cpp
     src/idioms/idiom1.cpp
@@ -65,6 +66,7 @@ set(dcc_HEADERS
     include/error.h
     include/graph.h
     include/hlicode.h
+    include/machine_x86.h
     include/icode.h
     include/idioms/idiom.h
     include/idioms/idiom1.h

+ 1 - 1
include/BasicBlock.h

@@ -42,7 +42,7 @@ private:
     iICODE  range_end;
 public:
     iICODE begin();
-    iICODE end();
+    iICODE end() const;
     riICODE rbegin();
     riICODE rend();
     ICODE &front();

+ 3 - 33
include/Enums.h

@@ -1,34 +1,4 @@
 #pragma once
-/* Machine registers */
-enum eReg
-{
-    rUNDEF =     0,
-    rAX =        1,  /* These are numbered relative to real 8086 */
-    rCX =        2,
-    rDX =        3,
-    rBX =        4,
-    rSP =        5,
-    rBP =        6,
-    rSI =        7,
-    rDI =        8,
-
-    rES =        9,
-    rCS =       10,
-    rSS =       11,
-    rDS =       12,
-
-    rAL =       13,
-    rCL =       14,
-    rDL =       15,
-    rBL =       16,
-    rAH =       17,
-    rCH =       18,
-    rDH =       19,
-    rBH =       20,
-
-    rTMP=       21,		/* temp register for DIV/IDIV/MOD	*/
-    INDEXBASE = 22          /* Indexed modes go from INDEXBASE to INDEXBASE+7  */
-};
 
 /* Register types */
 enum regType
@@ -285,11 +255,11 @@ enum hlType
     TYPE_WORD_UNSIGN,	/* unsigned word (16 bits)	*/
     TYPE_LONG_SIGN,		/* signed long (32 bits)	*/
     TYPE_LONG_UNSIGN,	/* unsigned long (32 bits)	*/
-    TYPE_RECORD,		/* record structure			*/
+    TYPE_RECORD,        /* record structure			*/
     TYPE_PTR,        	/* pointer (32 bit ptr) 	*/
     TYPE_STR,        	/* string               	*/
-    TYPE_CONST,			/* constant (any type)		*/
-    TYPE_FLOAT,			/* floating point			*/
+    TYPE_CONST,         /* constant (any type)		*/
+    TYPE_FLOAT,         /* floating point			*/
     TYPE_DOUBLE		/* double precision float	*/
 };
 

+ 3 - 2
include/IdentType.h

@@ -1,6 +1,7 @@
 #pragma once
 #include "ast.h"
 #include "types.h"
+#include "machine_x86.h"
 struct IDENTTYPE
 {
     condId           idType;
@@ -23,8 +24,8 @@ struct IDENTTYPE
             STKFRAME *args;
         }			 call;
         struct {                /* for OTHER; tmp struct            */
-            uint8_t     seg;       /*   segment                        */
-            uint8_t     regi;      /*   index mode                     */
+            eReg     seg;       /*   segment                        */
+            eReg     regi;      /*   index mode                     */
             int16_t    off;       /*   offset                         */
         }            other;
     }                idNode;

+ 2 - 2
include/Procedure.h

@@ -102,8 +102,8 @@ public:
     std::list<BB*> heldBBs;
     //BB *         *dfsLast;  /* Array of pointers to BBs in dfsLast
 //                           * (reverse postorder) order            	 */
-    int          numBBs;    /* Number of BBs in the graph cfg       	 */
-    boolT        hasCase;   /* Procedure has a case node            	 */
+    size_t        numBBs;    /* Number of BBs in the graph cfg       	 */
+    bool         hasCase;   /* Procedure has a case node            	 */
 
     /* For interprocedural live analysis */
     std::bitset<32>     liveIn;	/* Registers used before defined                 */

+ 1 - 1
include/StackFrame.h

@@ -37,5 +37,5 @@ struct STKFRAME
     {
 
     }
-    int getLocVar(int off);
+    size_t getLocVar(int off);
 };

+ 1 - 1
include/ast.h

@@ -76,7 +76,7 @@ public:
     static COND_EXPR *idLoc(int off, LOCAL_ID *localId);
     static COND_EXPR *idReg(eReg regi, uint32_t icodeFlg, LOCAL_ID *locsym);
     static COND_EXPR *idLongIdx(int idx);
-    static COND_EXPR *idOther(uint8_t seg, uint8_t regi, int16_t off);
+    static COND_EXPR *idOther(eReg seg, eReg regi, int16_t off);
     static COND_EXPR *idParam(int off, const STKFRAME *argSymtab);
     static COND_EXPR *unary(condNodeType t, COND_EXPR *sub_expr);
     static COND_EXPR *idLong(LOCAL_ID *localId, opLoc sd, iICODE pIcode, hlFirst f, iICODE ix, operDu du, iICODE atOffset);

+ 2 - 1
include/dcc.h

@@ -83,7 +83,7 @@ struct PROG /* Loaded program image parameters  */
     int16_t     initCS;
     int16_t     initIP;     /* These are initial load values    */
     int16_t     initSS;     /* Probably not of great interest   */
-    int16_t     initSP;
+    uint16_t    initSP;
     bool        fCOM;       /* Flag set if COM program (else EXE)*/
     int         cReloc;     /* No. of relocation table entries  */
     uint32_t *  relocTable; /* Ptr. to relocation table         */
@@ -179,3 +179,4 @@ eReg otherLongRegi(eReg, int, LOCAL_ID *);
 
 extern eReg subRegH(eReg reg);
 extern eReg subRegL(eReg reg);
+extern const char *indentStr(int level);

+ 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, ...);
 

+ 2 - 9
include/icode.h

@@ -23,13 +23,6 @@ struct ICODE;
 typedef std::list<ICODE>::iterator iICODE;
 typedef std::list<ICODE>::reverse_iterator riICODE;
 
-/* uint8_t and uint16_t registers */
-static const char *const byteReg[9]  = {"al", "cl", "dl", "bl",
-                                        "ah", "ch", "dh", "bh", "tmp" };
-static const char *const wordReg[21] = {"ax", "cx", "dx", "bx", "sp", "bp",
-                                        "si", "di", "es", "cs", "ss", "ds",
-                                        "", "", "", "", "", "", "", "", "tmp"};
-
 /* Def/use of flags - low 4 bits represent flags */
 struct DU
 {
@@ -251,7 +244,7 @@ public:
         opcode = op;
     }
     void emitGotoLabel(int indLevel);
-    void findJumpTargets(CIcodeRec &pc);
+    void findJumpTargets(CIcodeRec &_pc);
     void writeIntComment(std::ostringstream &s);
     void dis1Line(int loc_ip, int pass);
     std::ostringstream &strSrc(std::ostringstream &os,bool skip_comma=false);
@@ -349,7 +342,7 @@ public:
         type=HIGH_LEVEL;
         hl()->setAsgn(lhs,rhs);
     }
-    void setUnary(hlIcode op, COND_EXPR *exp);
+    void setUnary(hlIcode op, COND_EXPR *_exp);
     void setJCond(COND_EXPR *cexp);
 
     void emitGotoLabel(int indLevel);

+ 8 - 2
include/locident.h

@@ -13,6 +13,7 @@
 #include <algorithm>
 
 #include "Enums.h"
+#include "machine_x86.h"
 
 /* Type definition */
 // this array has to stay in-order of addition i.e. not std::set<iICODE,std::less<iICODE> >
@@ -44,7 +45,7 @@ typedef struct
 {
     int16_t	seg;			/*   segment value							 */
     int16_t	off;			/*   offset									 */
-    uint8_t 	regi;			/*   optional indexed register				 */
+    eReg 	regi;			/*   optional indexed register				 */
 } BWGLB_TYPE;
 
 
@@ -100,6 +101,8 @@ struct ID
         {
             case TYPE_WORD_SIGN: case TYPE_WORD_UNSIGN:
             return 16;
+            case TYPE_BYTE_SIGN: case TYPE_BYTE_UNSIGN:
+            return 8;
         }
         return ~0;
     }
@@ -113,9 +116,12 @@ public:
     {
         id_arr.reserve(256);
     }
+    // interface to allow range based iteration
+    std::vector<ID>::iterator begin() {return id_arr.begin();}
+    std::vector<ID>::iterator end() {return id_arr.end();}
     int newByteWordReg(hlType t, eReg regi);
     int newByteWordStk(hlType t, int off, uint8_t regOff);
-    int newIntIdx(int16_t seg, int16_t off, uint8_t regi, int ix, hlType t);
+    int newIntIdx(int16_t seg, int16_t off, eReg regi, int ix, hlType t);
     int newLongReg(hlType t, eReg regH, eReg regL, iICODE ix_);
     int newLong(opLoc sd, iICODE pIcode, hlFirst f, iICODE ix, operDu du, int off);
     int newLong(opLoc sd, iICODE pIcode, hlFirst f, iICODE ix, operDu du, iICODE atOffset);

+ 48 - 0
include/machine_x86.h

@@ -0,0 +1,48 @@
+#pragma once
+#include <string>
+/* Machine registers */
+enum eReg
+{
+    rUNDEF =     0,
+    rAX =        1,  /* These are numbered relative to real 8086 */
+    rCX =        2,
+    rDX =        3,
+    rBX =        4,
+    rSP =        5,
+    rBP =        6,
+    rSI =        7,
+    rDI =        8,
+
+    rES =        9,
+    rCS =       10,
+    rSS =       11,
+    rDS =       12,
+
+    rAL =       13,
+    rCL =       14,
+    rDL =       15,
+    rBL =       16,
+    rAH =       17,
+    rCH =       18,
+    rDH =       19,
+    rBH =       20,
+
+    rTMP=       21, /* temp register for DIV/IDIV/MOD	*/
+    /* Indexed modes go from INDEXBASE to INDEXBASE+7  */
+    INDEX_BX_SI = 22, // "bx+si"
+    INDEX_BX_DI, // "bx+di"
+    INDEX_BP_SI, // "bp+si"
+    INDEX_BP_DI, // "bp+di"
+    INDEX_SI, // "si"
+    INDEX_DI, // "di"
+    INDEX_BP, // "bp"
+    INDEX_BX, // "bx"
+    LAST_REG
+};
+
+class Machine_X86
+{
+public:
+    Machine_X86();
+    static const std::string &regName(eReg r);
+};

+ 1 - 3
include/perfhlib.h

@@ -1,11 +1,9 @@
+#pragma once
 /* Perfect hashing function library. Contains functions to generate perfect
     hashing functions
  * (C) Mike van Emmerik
  */
 
-
-#define TRUE 1
-#define FALSE 0
 //#define bool unsigned char
 #define uint8_t unsigned char
 #define uint16_t unsigned short

+ 6 - 5
include/state.h

@@ -5,13 +5,14 @@
 #pragma once
 #include <stdint.h>
 #include <cstring>
-#include "Enums.h"
+#include "machine_x86.h"
+
 /* STATE TABLE */
 struct STATE
 {
     uint32_t       IP;             /* Offset into Image                    */
-    int16_t       r[INDEXBASE];   /* Value of segs and AX                 */
-    uint8_t        f[INDEXBASE];   /* True if r[.] has a value             */
+    int16_t       r[INDEX_BX_SI];   /* Value of segs and AX                 */
+    uint8_t        f[INDEX_BX_SI];   /* True if r[.] has a value             */
     struct
     {                           /* For case stmt indexed reg            */
         uint8_t    regi;           /*   Last conditional jump              */
@@ -24,8 +25,8 @@ struct STATE
         JCond.regi=0;
         JCond.immed=0;
 
-        memset(r,0,sizeof(int16_t)*INDEXBASE);
-        memset(f,0,sizeof(uint8_t)*INDEXBASE);
+        memset(r,0,sizeof(int16_t)*INDEX_BX_SI);
+        memset(f,0,sizeof(uint8_t)*INDEX_BX_SI);
     }
 };
 

+ 38 - 36
src/BasicBlock.cpp

@@ -5,7 +5,7 @@
 #include "Procedure.h"
 #include "dcc.h"
 using namespace std;
-extern char *indent (int indLevel);
+
 BB *BB::Create(void *ctx, const string &s, Function *parent, BB *insertBefore)
 {
     BB *pnewBB = new BB;
@@ -13,13 +13,13 @@ BB *BB::Create(void *ctx, const string &s, Function *parent, BB *insertBefore)
     return pnewBB;
 }
 
-BB *BB::Create(int start, int ip, uint8_t nodeType, int numOutEdges, Function *parent)
+BB *BB::Create(int start, int ip, uint8_t _nodeType, int numOutEdges, Function *parent)
 {
-    parent->m_cfg;
+    //parent->m_cfg;
     BB* pnewBB;
 
     pnewBB = new BB;
-    pnewBB->nodeType = nodeType;	/* Initialise */
+    pnewBB->nodeType = _nodeType;	/* Initialise */
     pnewBB->immedDom = NO_DOM;
     pnewBB->loopHead = pnewBB->caseHead = pnewBB->caseTail =
             pnewBB->latchNode= pnewBB->loopFollow = NO_NODE;
@@ -68,7 +68,7 @@ void BB::display()
     printf("\nnode type = %s, ", s_nodeType[nodeType]);
     printf("start = %ld, length = %ld, #out edges = %ld\n", begin()->loc_ip, size(), edges.size());
 
-    for (int i = 0; i < edges.size(); i++)
+    for (size_t i = 0; i < edges.size(); i++)
         printf(" outEdge[%2d] = %ld\n",i, edges[i].BBptr->begin()->loc_ip);
 }
 /*****************************************************************************
@@ -100,6 +100,7 @@ void BB::displayDfs()
         printf("corresponding interval = %ld\n", correspInt->numInt);
     else
     {
+        int edge_idx=0;
 #ifdef _lint
         for(auto iter=inEdges.begin(); iter!=inEdges.end(); ++iter)
         {
@@ -108,7 +109,8 @@ void BB::displayDfs()
         for(BB *node : inEdges)
         {
 #endif
-            printf ("  inEdge[%ld] = %ld\n", i, node->begin()->loc_ip);
+            printf ("  inEdge[%ld] = %ld\n", edge_idx, node->begin()->loc_ip);
+            edge_idx++;
         }
     }
 
@@ -148,14 +150,14 @@ void BB::displayDfs()
  *						current procedure.
  *				indLevel: indentation level - used for formatting.
  *				numLoc: last # assigned to local variables 				*/
-void BB::writeCode (int indLevel, Function * pProc , int *numLoc,int latchNode, int _ifFollow)
+void BB::writeCode (int indLevel, Function * pProc , int *numLoc,int _latchNode, int _ifFollow)
 {
-    int follow,						/* ifFollow						*/
-            _loopType, 					/* Type of loop, if any 		*/
-            _nodeType;						/* Type of node 				*/
+    int follow,						/* ifFollow                 	*/
+        _loopType, 					/* Type of loop, if any         */
+        _nodeType;                                      /* Type of node                 */
     BB * succ, *latch;					/* Successor and latching node 	*/
     ICODE * picode;					/* Pointer to HLI_JCOND instruction	*/
-    char *l;							/* Pointer to HLI_JCOND expression	*/
+    char *l;                                            /* Pointer to HLI_JCOND expression	*/
     boolT emptyThen,					/* THEN clause is empty			*/
             repCond;					/* Repeat condition for while() */
 
@@ -202,19 +204,19 @@ void BB::writeCode (int indLevel, Function * pProc , int *numLoc,int latchNode,
                 }
                 {
                     string e=walkCondExpr (picode->hl()->expr(), pProc, numLoc);
-                    cCode.appendCode( "\n%swhile (%s) {\n", indent(indLevel),e.c_str());
+                    cCode.appendCode( "\n%swhile (%s) {\n", indentStr(indLevel),e.c_str());
                 }
                 picode->invalidate();
                 break;
 
             case REPEAT_TYPE:
-                cCode.appendCode( "\n%sdo {\n", indent(indLevel));
+                cCode.appendCode( "\n%sdo {\n", indentStr(indLevel));
                 picode = &latch->back();
                 picode->invalidate();
                 break;
 
             case ENDLESS_TYPE:
-                cCode.appendCode( "\n%sfor (;;) {\n", indent(indLevel));
+                cCode.appendCode( "\n%sfor (;;) {\n", indentStr(indLevel));
         }
         stats.numHLIcode += 1;
         indLevel++;
@@ -227,7 +229,7 @@ void BB::writeCode (int indLevel, Function * pProc , int *numLoc,int latchNode,
     /* Check for end of path */
     _nodeType = nodeType;
     if (_nodeType == RETURN_NODE || _nodeType == TERMINATE_NODE ||
-        _nodeType == NOWHERE_NODE || (dfsLastNum == latchNode))
+        _nodeType == NOWHERE_NODE || (dfsLastNum == _latchNode))
         return;
 
     /* Check type of loop/node and process code */
@@ -258,17 +260,17 @@ void BB::writeCode (int indLevel, Function * pProc , int *numLoc,int latchNode,
                          * in while condition, then, emit the loop trailer */
             if (repCond)
                 writeBB (indLevel+1, pProc, numLoc);
-            cCode.appendCode( "%s}	/* end of while */\n",indent(indLevel));
+            cCode.appendCode( "%s}	/* end of while */\n",indentStr(indLevel));
         }
         else if (_loopType == ENDLESS_TYPE)
-            cCode.appendCode( "%s}	/* end of loop */\n",indent(indLevel));
+            cCode.appendCode( "%s}	/* end of loop */\n",indentStr(indLevel));
         else if (_loopType == REPEAT_TYPE)
         {
             if (picode->hl()->opcode != HLI_JCOND)
                 reportError (REPEAT_FAIL);
             {
                 string e=walkCondExpr (picode->hl()->expr(), pProc, numLoc);
-                cCode.appendCode( "%s} while (%s);\n", indent(indLevel),e.c_str());
+                cCode.appendCode( "%s} while (%s);\n", indentStr(indLevel),e.c_str());
             }
         }
 
@@ -277,7 +279,7 @@ void BB::writeCode (int indLevel, Function * pProc , int *numLoc,int latchNode,
         {
             succ = pProc->m_dfsLast[loopFollow];
             if (succ->traversed != DFS_ALPHA)
-                succ->writeCode (indLevel, pProc, numLoc, latchNode, _ifFollow);
+                succ->writeCode (indLevel, pProc, numLoc, _latchNode, _ifFollow);
             else		/* has been traversed so we need a goto */
                 succ->front().ll()->emitGotoLabel (indLevel);
         }
@@ -301,14 +303,14 @@ void BB::writeCode (int indLevel, Function * pProc , int *numLoc,int latchNode,
                     if (succ->dfsLastNum != follow)	/* THEN part */
                     {
                         l = writeJcond ( *back().hl(), pProc, numLoc);
-                        cCode.appendCode( "\n%s%s", indent(indLevel-1), l);
-                        succ->writeCode (indLevel, pProc, numLoc, latchNode,follow);
+                        cCode.appendCode( "\n%s%s", indentStr(indLevel-1), l);
+                        succ->writeCode (indLevel, pProc, numLoc, _latchNode,follow);
                     }
                     else		/* empty THEN part => negate ELSE part */
                     {
                         l = writeJcondInv ( *back().hl(), pProc, numLoc);
-                        cCode.appendCode( "\n%s%s", indent(indLevel-1), l);
-                        edges[ELSE].BBptr->writeCode (indLevel, pProc, numLoc, latchNode, follow);
+                        cCode.appendCode( "\n%s%s", indentStr(indLevel-1), l);
+                        edges[ELSE].BBptr->writeCode (indLevel, pProc, numLoc, _latchNode, follow);
                         emptyThen = true;
                     }
                 }
@@ -322,32 +324,32 @@ void BB::writeCode (int indLevel, Function * pProc , int *numLoc,int latchNode,
                     if (succ->dfsLastNum != follow)		/* ELSE part */
                     {
                         cCode.appendCode( "%s}\n%selse {\n",
-                                          indent(indLevel-1), indent(indLevel - 1));
-                        succ->writeCode (indLevel, pProc, numLoc, latchNode, follow);
+                                          indentStr(indLevel-1), indentStr(indLevel - 1));
+                        succ->writeCode (indLevel, pProc, numLoc, _latchNode, follow);
                     }
                     /* else (empty ELSE part) */
                 }
                 else if (! emptyThen) 	/* already visited => emit label */
                 {
                     cCode.appendCode( "%s}\n%selse {\n",
-                                      indent(indLevel-1), indent(indLevel - 1));
+                                      indentStr(indLevel-1), indentStr(indLevel - 1));
                     succ->front().ll()->emitGotoLabel (indLevel);
                 }
-                cCode.appendCode( "%s}\n", indent(--indLevel));
+                cCode.appendCode( "%s}\n", indentStr(--indLevel));
 
                 /* Continue with the follow */
                 succ = pProc->m_dfsLast[follow];
                 if (succ->traversed != DFS_ALPHA)
-                    succ->writeCode (indLevel, pProc, numLoc, latchNode,_ifFollow);
+                    succ->writeCode (indLevel, pProc, numLoc, _latchNode,_ifFollow);
             }
             else		/* no follow => if..then..else */
             {
                 l = writeJcond ( *back().hl(), pProc, numLoc);
-                cCode.appendCode( "%s%s", indent(indLevel-1), l);
-                edges[THEN].BBptr->writeCode (indLevel, pProc, numLoc, latchNode, _ifFollow);
-                cCode.appendCode( "%s}\n%selse {\n", indent(indLevel-1), indent(indLevel - 1));
-                edges[ELSE].BBptr->writeCode (indLevel, pProc, numLoc, latchNode, _ifFollow);
-                cCode.appendCode( "%s}\n", indent(--indLevel));
+                cCode.appendCode( "%s%s", indentStr(indLevel-1), l);
+                edges[THEN].BBptr->writeCode (indLevel, pProc, numLoc, _latchNode, _ifFollow);
+                cCode.appendCode( "%s}\n%selse {\n", indentStr(indLevel-1), indentStr(indLevel - 1));
+                edges[ELSE].BBptr->writeCode (indLevel, pProc, numLoc, _latchNode, _ifFollow);
+                cCode.appendCode( "%s}\n", indentStr(--indLevel));
             }
         }
 
@@ -355,7 +357,7 @@ void BB::writeCode (int indLevel, Function * pProc , int *numLoc,int latchNode,
         {
             succ = edges[0].BBptr;		/* fall-through edge */
             if (succ->traversed != DFS_ALPHA)
-                succ->writeCode (indLevel, pProc,numLoc, latchNode,_ifFollow);
+                succ->writeCode (indLevel, pProc,numLoc, _latchNode,_ifFollow);
         }
     }
 }
@@ -386,7 +388,7 @@ void BB::writeBB(int lev, Function * pProc, int *numLoc)
             std::string line = pHli.hl()->write1HlIcode(pProc, numLoc);
             if (!line.empty())
             {
-                cCode.appendCode( "%s%s", indent(lev), line.c_str());
+                cCode.appendCode( "%s%s", indentStr(lev), line.c_str());
                 stats.numHLIcode++;
             }
             if (option.verbose)
@@ -404,7 +406,7 @@ iICODE BB::begin()
     return range_start;
 }
 
-iICODE BB::end()
+iICODE BB::end() const
 {
     return range_end;
 }

+ 19 - 22
src/ast.cpp

@@ -12,10 +12,8 @@
 #include <cassert>
 #include "types.h"
 #include "dcc.h"
+#include "machine_x86.h"
 using namespace std;
-// Index registers **** temp solution
-static const char * const idxReg[8] = {"bx+si", "bx+di", "bp+si", "bp+di",
-                                       "si", "di", "bp", "bx" };
 // Conditional operator symbols in C.  Index by condOp enumeration type
 static const char * const condOpSym[] = { " <= ", " < ", " == ", " != ", " > ", " >= ",
                                           " & ", " | ", " ^ ", " ~ ",
@@ -297,7 +295,7 @@ COND_EXPR *COND_EXPR::idFunc(Function * pproc, STKFRAME * args)
 /* Returns an identifier conditional expression node of type OTHER.
  * Temporary solution, should really be encoded as an indexed type (eg.
  * arrays). */
-COND_EXPR *COND_EXPR::idOther(uint8_t seg, uint8_t regi, int16_t off)
+COND_EXPR *COND_EXPR::idOther(eReg seg, eReg regi, int16_t off)
 {
     COND_EXPR *newExp;
 
@@ -367,7 +365,7 @@ COND_EXPR *COND_EXPR::id(const LLInst &ll_insn, opLoc sd, Function * pProc, iICO
         newExp = COND_EXPR::idKte (ll_insn.src.op(), 2);
     else if (pm.regi == 0)                             /* global variable */
         newExp = GlobalVariable::Create(pm.segValue, pm.off);
-    else if (pm.regi < INDEXBASE)                      /* register */
+    else if (pm.regi < INDEX_BX_SI)                      /* register */
     {
         newExp = COND_EXPR::idReg (pm.regi, (sd == SRC) ? ll_insn.getFlag() :
                                                           ll_insn.getFlag() & NO_SRC_B,
@@ -377,14 +375,14 @@ COND_EXPR *COND_EXPR::id(const LLInst &ll_insn, opLoc sd, Function * pProc, iICO
 
     else if (pm.off)                                   /* offset */
     {
-        if ((pm.seg == rSS) && (pm.regi == INDEXBASE + 6)) /* idx on bp */
+        if ((pm.seg == rSS) && (pm.regi == INDEX_BP)) /* idx on bp */
         {
             if (pm.off >= 0)                           /* argument */
                 newExp = COND_EXPR::idParam (pm.off, &pProc->args);
             else                                        /* local variable */
                 newExp = COND_EXPR::idLoc (pm.off, &pProc->localId);
         }
-        else if ((pm.seg == rDS) && (pm.regi == INDEXBASE + 7)) /* bx */
+        else if ((pm.seg == rDS) && (pm.regi == INDEX_BX)) /* bx */
         {
             if (pm.off > 0)        /* global variable */
                 newExp = idCondExpIdxGlob (pm.segValue, pm.off, rBX,&pProc->localId);
@@ -399,21 +397,21 @@ COND_EXPR *COND_EXPR::id(const LLInst &ll_insn, opLoc sd, Function * pProc, iICO
 
     else  /* (pm->regi >= INDEXBASE && pm->off = 0) => indexed && no off */
     {
-        if ((pm.seg == rDS) && (pm.regi > INDEXBASE + 3)) /* dereference */
+        if ((pm.seg == rDS) && (pm.regi > INDEX_BP_DI)) /* dereference */
         {
             switch (pm.regi) {
-            case INDEXBASE + 4:
+            case INDEX_SI:
                 newExp = COND_EXPR::idReg(rSI, 0, &pProc->localId);
                 duIcode.setRegDU( rSI, du);
                 break;
-            case INDEXBASE + 5:
+            case INDEX_DI:
                 newExp = COND_EXPR::idReg(rDI, 0, &pProc->localId);
                 duIcode.setRegDU( rDI, du);
                 break;
-            case INDEXBASE + 6:
+            case INDEX_BP:
                 newExp = COND_EXPR::idReg(rBP, 0, &pProc->localId);
                 break;
-            case INDEXBASE + 7:
+            case INDEX_BX:
                 newExp = COND_EXPR::idReg(rBX, 0, &pProc->localId);
                 duIcode.setRegDU( rBX, du);
                 break;
@@ -440,9 +438,9 @@ condId ICODE::idType(opLoc sd)
         return (CONSTANT);
     else if (pm.regi == 0)
         return (GLOB_VAR);
-    else if (pm.regi < INDEXBASE)
+    else if (pm.regi < INDEX_BX_SI)
         return (REGISTER);
-    else if ((pm.seg == rSS) && (pm.regi == INDEXBASE))
+    else if ((pm.seg == rSS) && (pm.regi == INDEX_BX_SI))
     {
         if (pm.off >= 0)
             return (PARAM);
@@ -713,10 +711,7 @@ string walkCondExpr (const COND_EXPR* expr, Function * pProc, int* numLoc)
             if (id->name[0] == '\0')	/* no name */
             {
                 sprintf (id->name, "loc%ld", ++(*numLoc));
-                if (id->id.regi < rAL)
-                    cCode.appendDecl("%s %s; /* %s */\n",hlTypes[id->type], id->name,wordReg[id->id.regi - rAX]);
-                else
-                    cCode.appendDecl("%s %s; /* %s */\n",hlTypes[id->type], id->name,byteReg[id->id.regi - rAL]);
+                cCode.appendDecl("%s %s; /* %s */\n",hlTypes[id->type], id->name,Machine_X86::regName(id->id.regi).c_str());
             }
             if (id->hasMacro)
                 o << id->macro << "("<<id->name<<")";
@@ -738,7 +733,7 @@ string walkCondExpr (const COND_EXPR* expr, Function * pProc, int* numLoc)
 
         case GLOB_VAR_IDX:
             bwGlb = &pProc->localId.id_arr[expr->expr.ident.idNode.idxGlbIdx].id.bwGlb;
-            o << (bwGlb->seg << 4) + bwGlb->off <<  "["<<wordReg[bwGlb->regi - rAX]<<"]";
+            o << (bwGlb->seg << 4) + bwGlb->off <<  "["<<Machine_X86::regName(bwGlb->regi)<<"]";
             break;
 
         case CONSTANT:
@@ -759,7 +754,9 @@ string walkCondExpr (const COND_EXPR* expr, Function * pProc, int* numLoc)
             else if (id->loc == REG_FRAME)
             {
                 sprintf (id->name, "loc%ld", ++(*numLoc));
-                cCode.appendDecl("%s %s; /* %s:%s */\n",hlTypes[id->type], id->name,wordReg[id->id.longId.h - rAX],wordReg[id->id.longId.l - rAX]);
+                cCode.appendDecl("%s %s; /* %s:%s */\n",hlTypes[id->type], id->name,
+                                 Machine_X86::regName(id->id.longId.h).c_str(),
+                                 Machine_X86::regName(id->id.longId.l).c_str());
                 o << id->name;
                 pProc->localId.propLongId (id->id.longId.l,id->id.longId.h, id->name);
             }
@@ -778,8 +775,8 @@ string walkCondExpr (const COND_EXPR* expr, Function * pProc, int* numLoc)
 
         case OTHER:
             off = expr->expr.ident.idNode.other.off;
-            o << wordReg[expr->expr.ident.idNode.other.seg - rAX]<< "[";
-            o << idxReg[expr->expr.ident.idNode.other.regi - INDEXBASE];
+            o << Machine_X86::regName(expr->expr.ident.idNode.other.seg)<< "[";
+            o << Machine_X86::regName(expr->expr.ident.idNode.other.regi);
             if (off < 0)
                 o << "-"<< hexStr (-off);
             else if (off>0)

+ 39 - 47
src/backend.cpp

@@ -15,19 +15,6 @@
 
 bundle cCode;			/* Procedure declaration and code */
 using namespace std;
-/* Indentation buffer */
-#define indSize	81		/* size of the indentation buffer.  Each indentation
-    * is of 4 spaces => max. 20 indentation levels */
-static char indentBuf[indSize] =
-        "                                                                                ";
-
-
-/* Indentation according to the depth of the statement */
-char *indent (int indLevel)
-{
-    return (&indentBuf[indSize-(indLevel*4)-1]);
-}
-
 
 /* Returns a unique index to the next label */
 int getNextLabel()
@@ -144,23 +131,27 @@ static void printGlobVar (SYM * psym)
  * initialization. */
 static void writeGlobSymTable()
 {
-    int idx;
     char type[10];
-    SYM * pSym;
 
     if (not symtab.empty())
     {
         cCode.appendDecl( "/* Global variables */\n");
-        for (idx = 0; idx < symtab.size(); idx++)
+#ifdef _lint
+        for (auto iter=symtab.begin(); iter!=symtab.end(); ++iter)
         {
-            pSym = &symtab[idx];
-            if (symtab[idx].duVal.isUSE_VAL())	/* first used */
-                printGlobVar (&symtab[idx]);
+            SYM &sym(*iter);
+#else
+        for (SYM &sym : symtab)
+        {
+#endif
+//            pSym = &symtab[idx];
+            if (sym.duVal.isUSE_VAL())	/* first used */
+                printGlobVar (&sym);
             else {					/* first defined */
-                switch (pSym->size) {
+                switch (sym.size) {
                     case 1:  strcpy (type, "uint8_t\t"); break;
                     case 2:  strcpy (type, "int\t"); break;
-                    case 4:  if (pSym->type == TYPE_PTR)
+                    case 4:  if (sym.type == TYPE_PTR)
                             strcpy (type, "int\t*");
                         else
                             strcpy (type, "char\t*");
@@ -168,7 +159,7 @@ static void writeGlobSymTable()
                     default: strcpy (type, "char\t*");
                 }
                 cCode.appendDecl( "%s%s;\t/* size = %ld */\n",
-                                  type, pSym->name, pSym->size);
+                                  type, sym.name, sym.size);
             }
         }
         cCode.appendDecl( "\n");
@@ -199,7 +190,7 @@ static void writeBitVector (const std::bitset<32> &regi)
 {
     int j;
 
-    for (j = rAX; j < INDEXBASE; j++)
+    for (j = rAX; j < INDEX_BX_SI; j++)
     {
         if (regi.test(j))
             printf ("%s ", allRegs[j-1]);
@@ -220,7 +211,7 @@ static void emitFwdGotoLabel (ICODE * pt, int indLevel)
         pt->ll()->hllLabNum = getNextLabel();
         pt->ll()->setFlags(HLL_LABEL);
     }
-    cCode.appendCode( "%sgoto l%ld;\n", indent(indLevel), pt->ll()->hllLabNum);
+    cCode.appendCode( "%sgoto l%ld;\n", indentStr(indLevel), pt->ll()->hllLabNum);
 }
 
 
@@ -228,11 +219,9 @@ static void emitFwdGotoLabel (ICODE * pt, int indLevel)
  * and invokes the procedure that writes the code of the given record *hli */
 void Function::codeGen (std::ostream &fs)
 {
-    int i, numLoc;
-    //STKFRAME * args;       /* Procedure arguments              */
+    int numLoc;
     char buf[200],        /* Procedure's definition           */
-            arg[30];         /* One argument                     */
-    ID *locid;            /* Pointer to one local identifier  */
+         arg[30];         /* One argument                     */
     BB *pBB;              /* Pointer to basic block           */
 
     /* Write procedure/function header */
@@ -244,7 +233,7 @@ void Function::codeGen (std::ostream &fs)
 
     /* Write arguments */
     memset (buf, 0, sizeof(buf));
-    for (i = 0; i < args.sym.size(); i++)
+    for (size_t i = 0; i < args.sym.size(); i++)
     {
         if (args.sym[i].invalid == FALSE)
         {
@@ -264,30 +253,35 @@ void Function::codeGen (std::ostream &fs)
     if (! (flg & PROC_ASM))
     {
         numLoc = 0;
-        for (i = 0; i < localId.csym(); i++)
+#ifdef _lint
+        for (size_t i = 0; i < localId.csym(); i++)
+        {
+            ID &refId(localId.id_arr[i]);
+#else
+        for (ID &refId : localId )
         {
-            locid = &localId.id_arr[i];
+#endif
             /* Output only non-invalidated entries */
-            if (locid->illegal == FALSE)
+            if (refId.illegal == FALSE)
             {
-                if (locid->loc == REG_FRAME)
+                if (refId.loc == REG_FRAME)
                 {
                     /* Register variables are assigned to a local variable */
-                    if (((flg & SI_REGVAR) && (locid->id.regi == rSI)) ||
-                        ((flg & DI_REGVAR) && (locid->id.regi == rDI)))
+                    if (((flg & SI_REGVAR) && (refId.id.regi == rSI)) ||
+                        ((flg & DI_REGVAR) && (refId.id.regi == rDI)))
                     {
-                        sprintf (locid->name, "loc%ld", ++numLoc);
-                        cCode.appendDecl( "int %s;\n", locid->name);
+                        sprintf (refId.name, "loc%ld", ++numLoc);
+                        cCode.appendDecl( "int %s;\n", refId.name);
                     }
                     /* Other registers are named when they are first used in
                      * the output C code, and appended to the proc decl. */
                 }
 
-                else if (locid->loc == STK_FRAME)
+                else if (refId.loc == STK_FRAME)
                 {
                     /* Name local variables and output appropriate type */
-                    sprintf (locid->name, "loc%ld", ++numLoc);
-                    cCode.appendDecl( "%s %s;\n",hlTypes[locid->type], locid->name);
+                    sprintf (refId.name, "loc%ld", ++numLoc);
+                    cCode.appendDecl( "%s %s;\n",hlTypes[refId.type], refId.name);
                 }
             }
         }
@@ -304,7 +298,7 @@ void Function::codeGen (std::ostream &fs)
 
     /* Write Live register analysis information */
     if (option.verbose)
-        for (i = 0; i < numBBs; i++)
+        for (size_t i = 0; i < numBBs; i++)
         {
             pBB = m_dfsLast[i];
             if (pBB->flg & INVALID_BB)	continue;	/* skip invalid BBs */
@@ -325,10 +319,8 @@ void Function::codeGen (std::ostream &fs)
 
 /* Recursive procedure. Displays the procedure's code in depth-first order
  * of the call graph.	*/
-static void backBackEnd (char *filename, CALL_GRAPH * pcallGraph, std::ostream &ios)
+static void backBackEnd (char *filename, CALL_GRAPH * pcallGraph, std::ostream &_ios)
 {
-    int i;
-
     //	IFace.Yield();			/* This is a good place to yield to other apps */
 
     /* Check if this procedure has been processed already */
@@ -338,15 +330,15 @@ static void backBackEnd (char *filename, CALL_GRAPH * pcallGraph, std::ostream &
     pcallGraph->proc->flg |= PROC_OUTPUT;
 
     /* Dfs if this procedure has any successors */
-    for (i = 0; i < pcallGraph->outEdges.size(); i++)
+    for (size_t i = 0; i < pcallGraph->outEdges.size(); i++)
     {
-        backBackEnd (filename, pcallGraph->outEdges[i], ios);
+        backBackEnd (filename, pcallGraph->outEdges[i], _ios);
     }
 
     /* Generate code for this procedure */
     stats.numLLIcode = pcallGraph->proc->Icode.size();
     stats.numHLIcode = 0;
-    pcallGraph->proc->codeGen (ios);
+    pcallGraph->proc->codeGen (_ios);
 
     /* Generate statistics */
     if (option.Stats)

+ 1 - 3
src/bundle.cpp

@@ -40,9 +40,7 @@ void addLabelBundle (strTable &strTab, int idx, int label)
 /* Writes the contents of the string table on the file fp.  */
 static void writeStrTab (std::ostream &ios, strTable &strTab)
 {
-    int i;
-
-    for (i = 0; i < strTab.size(); i++)
+    for (size_t i = 0; i < strTab.size(); i++)
         ios << strTab[i];
 }
 

+ 1 - 1
src/chklib.cpp

@@ -43,7 +43,7 @@ struct ph_func_tag
 #define NUM_PLIST   64              	/* Number of entries to increase allocation by */
 
 /* statics */
-char buf[100];          				/* A general purpose buffer */
+static char buf[100];          				/* A general purpose buffer */
 int numKeys;            				/* Number of hash table entries (keys) */
 int numVert;            				/* Number of vertices in the graph (also size of g[]) */
 unsigned PatLen;        				/* Size of the keys (pattern length) */

+ 5 - 8
src/comwrite.cpp

@@ -7,6 +7,7 @@
  ****************************************************************************/
 
 #include "dcc.h"
+#include "machine_x86.h"
 #include <string.h>
 #include <sstream>
 using namespace std;
@@ -200,19 +201,15 @@ void Function::writeProcComments()
             if (psym->regs->expr.ident.idType == REGISTER)
             {
                 id = &this->localId.id_arr[psym->regs->expr.ident.idNode.regiIdx];
-                if (psym->regs->expr.ident.regiType == WORD_REG)
-                    cCode.appendDecl(" *     %s = %s.\n", psym->name,
-                                     wordReg[id->id.regi - rAX]);
-                else		/* BYTE_REG */
-                    cCode.appendDecl(" *     %s = %s.\n", psym->name,
-                                     byteReg[id->id.regi - rAL]);
+                cCode.appendDecl(" *     %s = %s.\n", psym->name,
+                                 Machine_X86::regName(id->id.regi).c_str());
             }
             else		/* long register */
             {
                 id = &this->localId.id_arr[psym->regs->expr.ident.idNode.longIdx];
                 cCode.appendDecl(" *     %s = %s:%s.\n", psym->name,
-                                 wordReg[id->id.longId.h - rAX],
-                                 wordReg[id->id.longId.l - rAX]);
+                                 Machine_X86::regName(id->id.longId.h).c_str(),
+                                 Machine_X86::regName(id->id.longId.l).c_str());
             }
 
         }

+ 7 - 6
src/control.cpp

@@ -123,13 +123,13 @@ static boolT inInt(BB * n, queue &q)
  * The follow node is the closest node to the loop. */
 static void findEndlessFollow (Function * pProc, nodeList &loopNodes, BB * head)
 {
-    int j, succ;
+    int succ;
 
     head->loopFollow = MAX;
     nodeList::iterator p = loopNodes.begin();
     for( ;p != loopNodes.end();++p)
     {
-        for (j = 0; j < pProc->m_dfsLast[*p]->edges.size(); j++)
+        for (size_t j = 0; j < pProc->m_dfsLast[*p]->edges.size(); j++)
         {
             succ = pProc->m_dfsLast[*p]->edges[j].BBptr->dfsLastNum;
             if ((! inList(loopNodes, succ)) && (succ < head->loopFollow))
@@ -264,7 +264,6 @@ static void findNodesInInt (queue &intNodes, int level, interval *Ii)
         for (auto i=Ii->nodes.begin(); i!=Ii->nodes.end(); ++i)
         {
             en=*i;
-
 #else
         for(BB *en : Ii->nodes)
         {
@@ -273,6 +272,7 @@ static void findNodesInInt (queue &intNodes, int level, interval *Ii)
         }
     }
     else
+    {
 #ifdef _lint
         BB * en=0;
         for (auto i=Ii->nodes.begin(); i!=Ii->nodes.end(); ++i)
@@ -285,6 +285,7 @@ static void findNodesInInt (queue &intNodes, int level, interval *Ii)
 #endif
             findNodesInInt(intNodes,level-1,en->correspInt);
         }
+    }
 }
 
 
@@ -295,7 +296,7 @@ void Function::structLoops(derSeq *derivedG)
     BB * intHead,      	/* interval header node         	*/
             * pred,     /* predecessor node         		*/
             * latchNode;/* latching node (in case of loops) */
-    int i,              /* counter              			*/
+    int
             level = 0;  /* derived sequence level       	*/
     interval *initInt;  /* initial interval         		*/
     queue intNodes;  	/* list of interval nodes       	*/
@@ -314,7 +315,7 @@ void Function::structLoops(derSeq *derivedG)
             /* Find interval head (original BB node in G1) and create
            * list of nodes of interval Ii.              */
             initInt = Ii;
-            for (i = 1; i < level; i++)
+            for (size_t i = 1; i < level; i++)
                 initInt = (*initInt->nodes.begin())->correspInt;
             intHead = *initInt->nodes.begin();
 
@@ -322,7 +323,7 @@ void Function::structLoops(derSeq *derivedG)
             findNodesInInt (intNodes, level, Ii);
 
             /* Find greatest enclosing back edge (if any) */
-            for (i = 0; i < intHead->inEdges.size(); i++)
+            for (size_t i = 0; i < intHead->inEdges.size(); i++)
             {
                 pred = intHead->inEdges[i];
                 if (inInt(pred, intNodes) && isBackEdge(pred, intHead))

+ 258 - 208
src/dataflow.cpp

@@ -73,9 +73,9 @@ ExpStack g_exp_stk;
 
 /* Returns the index of the local variable or parameter at offset off, if it
  * is in the stack frame provided.  */
-int STKFRAME::getLocVar(int off)
+size_t STKFRAME::getLocVar(int off)
 {
-    int     i;
+    size_t i;
 
     for (i = 0; i < sym.size(); i++)
         if (sym[i].off == off)
@@ -120,6 +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;
     for (i = 0; i < numBBs; i++)
     {
         pBB = m_dfsLast[i];
@@ -251,12 +252,18 @@ 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++)
         {
-            if ((j->type == HIGH_LEVEL) && (j->invalid == FALSE))
+            ICODE &insn(*j);
+#else
+        for(ICODE &insn : *pbb)
+        {
+#endif
+            if ((insn.type == HIGH_LEVEL) && ( insn.valid() ))
             {
-                liveUse |= (j->du.use & ~def);
-                def |= j->du.def;
+                liveUse |= (insn.du.use & ~def);
+                def |= insn.du.def;
             }
         }
         pbb->liveUse = liveUse;
@@ -423,7 +430,7 @@ void BB::genDU1()
         defRegIdx = 0;
         // foreach defined register
         bitset<32> processed=0;
-        for (k = 0; k < INDEXBASE; k++)
+        for (k = 0; k < INDEX_BX_SI; k++)
         {
             if (not picode->du.def.test(k))
                 continue;
@@ -514,9 +521,9 @@ void BB::genDU1()
 
                     /* Backpatch any uses of this instruction, within
                      * the same BB, if the instruction was invalidated */
-                    for (auto ticode = riICODE(picode); ticode != this->rend(); ticode++)
+                    for (auto back_patch_at = riICODE(picode); back_patch_at != rend(); back_patch_at++)
                     {
-                        ticode->du1.remove(0,picode);
+                        back_patch_at->du1.remove(0,picode);
                     }
                 }
                 else		/* liveOut */
@@ -587,16 +594,15 @@ static void forwardSubs (COND_EXPR *lhs, COND_EXPR *rhs, iICODE picode,
 
 /* Substitutes the rhs (or lhs if rhs not possible) of ticode for the
  * expression exp given */
-static void forwardSubsLong (int longIdx, COND_EXPR *exp, iICODE picode,
-                             iICODE ticode, int *numHlIcodes)
+static void forwardSubsLong (int longIdx, COND_EXPR *_exp, iICODE picode, iICODE ticode, int *numHlIcodes)
 {
     bool res;
 
-    if (exp == NULL)        /* In case expression popped is NULL */
+    if (_exp == NULL)        /* In case expression popped is NULL */
         return;
 
     /* Insert on rhs of ticode, if possible */
-    res = COND_EXPR::insertSubTreeLongReg (exp, &ticode->hl()->asgn.rhs, longIdx);
+    res = COND_EXPR::insertSubTreeLongReg (_exp, &ticode->hl()->asgn.rhs, longIdx);
     if (res)
     {
         picode->invalidate();
@@ -605,7 +611,7 @@ static void forwardSubsLong (int longIdx, COND_EXPR *exp, iICODE picode,
     else
     {
         /* Try to insert it on lhs of ticode*/
-        res = COND_EXPR::insertSubTreeLongReg (exp, &ticode->hl()->asgn.lhs, longIdx);
+        res = COND_EXPR::insertSubTreeLongReg (_exp, &ticode->hl()->asgn.lhs, longIdx);
         if (res)
         {
             picode->invalidate();
@@ -685,38 +691,40 @@ bool BinaryOperator::xClear(iICODE f, iICODE t, iICODE lastBBinst, Function *ppr
 /* Checks the type of the formal argument as against to the actual argument,
  * whenever possible, and then places the actual argument on the procedure's
  * argument list.	*/
-static void processCArg (Function * pp, Function * pProc, ICODE * picode, int numArgs, int *k)
+/// @returns the type size of the stored Arg
+static int processCArg (Function * pp, Function * pProc, ICODE * picode, int numArgs)
 {
-    COND_EXPR *exp;
-    boolT res;
+    COND_EXPR *_exp;
+    bool res;
 
     /* if (numArgs == 0)
                 return; */
 
-    exp = g_exp_stk.pop();
+    _exp = g_exp_stk.pop();
     if (pp->flg & PROC_ISLIB) /* library function */
     {
         if (pp->args.numArgs > 0)
             if (pp->flg & PROC_VARARG)
             {
                 if (numArgs < pp->args.sym.size())
-                    adjustActArgType (exp, pp->args.sym[numArgs].type, pProc);
+                    adjustActArgType (_exp, pp->args.sym[numArgs].type, pProc);
             }
             else
-                adjustActArgType (exp, pp->args.sym[numArgs].type, pProc);
-        res = picode->newStkArg (exp, picode->ll()->getOpcode(), pProc);
+                adjustActArgType (_exp, pp->args.sym[numArgs].type, pProc);
+        res = picode->newStkArg (_exp, 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);
+            pp->args.adjustForArgType (numArgs, expType (_exp, pProc));
+        res = picode->newStkArg (_exp, picode->ll()->getOpcode(), pProc);
     }
 
     /* Do not update the size of k if the expression was a segment register
          * in a near call */
-    if (res == FALSE)
-        *k += hlTypeSize (exp, pProc);
+    if (res == false)
+        return hlTypeSize (_exp, pProc);
+    return 0; // be default we do not know the size of the argument
 }
 
 /** Eliminates extraneous intermediate icode instructions when finding
@@ -769,7 +777,7 @@ void Function::processTargetIcode(iICODE picode, int &numHlIcodes, iICODE ticode
     }
 }
 
-void Function::processHliCall1(COND_EXPR *exp, iICODE picode)
+void Function::processHliCall1(COND_EXPR *_exp, iICODE picode)
 {
     Function * pp;
     int cb, numArgs;
@@ -779,58 +787,69 @@ void Function::processHliCall1(COND_EXPR *exp, iICODE picode)
     if (pp->flg & CALL_PASCAL)
     {
         cb = pp->cbParam;	/* fixed # arguments */
-        for (k = 0, numArgs = 0; k < cb; numArgs++)
+        k = 0;
+        numArgs = 0;
+        while(k<cb)
         {
-            exp = g_exp_stk.pop();
+            _exp = g_exp_stk.pop();
             if (pp->flg & PROC_ISLIB)	/* library function */
             {
                 if (pp->args.numArgs > 0)
-                    adjustActArgType(exp, pp->args.sym[numArgs].type, this);
-                res = picode->newStkArg (exp, picode->ll()->getOpcode(), this);
+                    adjustActArgType(_exp, pp->args.sym[numArgs].type, this);
+                res = picode->newStkArg (_exp, 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);
+                    pp->args.adjustForArgType (numArgs,expType (_exp, this));
+                res = picode->newStkArg (_exp,picode->ll()->getOpcode(), this);
             }
             if (res == FALSE)
-                k += hlTypeSize (exp, this);
+                k += hlTypeSize (_exp, this);
+            numArgs++;
         }
     }
     else		/* CALL_C */
     {
         cb = picode->hl()->call.args->cb;
         numArgs = 0;
+        k = 0;
         if (cb)
-            for (k = 0; k < cb; numArgs++)
-                processCArg (pp, this, &(*picode), numArgs, &k);
+        {
+            while ( k < cb )
+            {
+                k+=processCArg (pp, this, &(*picode), numArgs);
+                numArgs++;
+            }
+        }
         else if ((cb == 0) && picode->ll()->testFlags(REST_STK))
+        {
             while (! g_exp_stk.empty())
             {
-                processCArg (pp, this, &(*picode), numArgs, &k);
+                k+=processCArg (pp, this, &(*picode), numArgs);
                 numArgs++;
             }
+        }
     }
 }
 
 void Function::findExps()
 {
     int i, numHlIcodes;
-    iICODE lastInst,
+    iICODE
             picode,     // Current icode                            */
             ticode;     // Target icode                             */
     BB * pbb;           // Current and next basic block             */
     boolT res;
-    COND_EXPR *exp,     // expression pointer - for HLI_POP and HLI_CALL    */
+    COND_EXPR *_exp,     // expression pointer - for HLI_POP and HLI_CALL    */
             *lhs;	// exp ptr for return value of a HLI_CALL		*/
     //STKFRAME * args;  // pointer to arguments - for HLI_CALL          */
     uint8_t regi;		// register(s) to be forward substituted	*/
-    ID *retVal;         // function return value
+    ID *_retVal;         // function return value
 
     /* Initialize expression stack */
     g_exp_stk.init();
-
+    _exp = 0;
     /* Traverse tree in dfsLast order */
     for (i = 0; i < numBBs; i++)
     {
@@ -838,30 +857,29 @@ void Function::findExps()
         pbb = m_dfsLast[i];
         if (pbb->flg & INVALID_BB)
             continue;
-        lastInst = pbb->end();
         numHlIcodes = 0;
-        for (picode = pbb->begin(); picode != lastInst; picode++)
+        for (picode = pbb->begin(); picode != pbb->end(); picode++)
         {
-            if ((picode->type == HIGH_LEVEL) && (picode->invalid == FALSE))
+            if ((picode->type != HIGH_LEVEL) || ( ! picode->valid() ))
+                continue;
+            numHlIcodes++;
+            if (picode->du1.numRegsDef == 1)    /* uint8_t/uint16_t regs */
             {
-                numHlIcodes++;
-                if (picode->du1.numRegsDef == 1)    /* uint8_t/uint16_t regs */
+                /* Check for only one use of this register.  If this is
+                 * the last definition of the register in this BB, check
+                 * that it is not liveOut from this basic block */
+                if (picode->du1.numUses(0)==1)
                 {
-                    /* Check for only one use of this register.  If this is
-                     * the last definition of the register in this BB, check
-                     * that it is not liveOut from this basic block */
-                    if (picode->du1.numUses(0)==1)
-                    {
-                        /* Check that this register is not liveOut, if it
-                         * is the last definition of the register */
-                        regi = picode->du1.regi[0];
+                    /* Check that this register is not liveOut, if it
+                     * is the last definition of the register */
+                    regi = picode->du1.regi[0];
 
-                        /* Check if we can forward substitute this register */
-                        switch (picode->hl()->opcode)
-                        {
+                    /* Check if we can forward substitute this register */
+                    switch (picode->hl()->opcode)
+                    {
                         case HLI_ASSIGN:
                             /* Replace rhs of current icode into target
-                             * icode expression */
+                         * icode expression */
                             ticode = picode->du1.idx[0].uses.front();
                             if ((picode->du.lastDefRegi & duReg[regi]).any() &&
                                     ((ticode->hl()->opcode != HLI_CALL) &&
@@ -869,7 +887,7 @@ void Function::findExps()
                                 continue;
 
                             if (picode->hl()->asgn.rhs->xClear (picode,
-                                        picode->du1.idx[0].uses[0],  lastInst, this))
+                                                                picode->du1.idx[0].uses[0],  pbb->end(), this))
                             {
                                 processTargetIcode(picode, numHlIcodes, ticode,false);
                             }
@@ -882,86 +900,86 @@ void Function::findExps()
                                      (ticode->hl()->opcode != HLI_RET)))
                                 continue;
 
-                            exp = g_exp_stk.pop();  /* pop last exp pushed */
+                            _exp = g_exp_stk.pop();  /* pop last exp pushed */
                             switch (ticode->hl()->opcode) {
-                            case HLI_ASSIGN:
-                                forwardSubs (picode->hl()->expr(), exp,
-                                             picode, ticode, &localId,
-                                             numHlIcodes);
-                                break;
-
-                            case HLI_JCOND: case HLI_PUSH: case HLI_RET:
-                                res = COND_EXPR::insertSubTreeReg (ticode->hl()->exp.v,
-                                                        exp,
-                                                        localId.id_arr[picode->hl()->expr()->expr.ident.idNode.regiIdx].id.regi,
-                                                        &localId);
-                                if (res)
-                                {
-                                    picode->invalidate();
-                                    numHlIcodes--;
-                                }
-                                break;
-
-                                /****case HLI_CALL:    /* register arguments
-                                newRegArg (pProc, picode, ticode);
-                                picode->invalidate();
-                                numHlIcodes--;
-                                break;	*/
+                                case HLI_ASSIGN:
+                                    forwardSubs (picode->hl()->expr(), _exp,
+                                                 picode, ticode, &localId,
+                                                 numHlIcodes);
+                                    break;
+
+                                case HLI_JCOND: case HLI_PUSH: case HLI_RET:
+                                    res = COND_EXPR::insertSubTreeReg (ticode->hl()->exp.v,
+                                                                       _exp,
+                                                                       localId.id_arr[picode->hl()->expr()->expr.ident.idNode.regiIdx].id.regi,
+                                                                       &localId);
+                                    if (res)
+                                    {
+                                        picode->invalidate();
+                                        numHlIcodes--;
+                                    }
+                                    break;
+
+                                    /****case HLI_CALL:    /* register arguments
+                            newRegArg (pProc, picode, ticode);
+                            picode->invalidate();
+                            numHlIcodes--;
+                            break;	*/
                             } /* eos */
                             break;
 
                         case HLI_CALL:
                             ticode = picode->du1.idx[0].uses.front();
                             HLTYPE *ti_hl(ticode->hl());
-                            retVal = &picode->hl()->call.proc->retVal;
+                            _retVal = &picode->hl()->call.proc->retVal;
                             switch (ti_hl->opcode) {
-                            case HLI_ASSIGN:
-                                assert(ti_hl->asgn.rhs);
-                                exp = COND_EXPR::idFunc ( picode->hl()->call.proc, picode->hl()->call.args);
-                                res = COND_EXPR::insertSubTreeReg (ti_hl->asgn.rhs,exp, retVal->id.regi, &localId);
-                                if (! res)
-                                    COND_EXPR::insertSubTreeReg (ti_hl->asgn.lhs, exp,retVal->id.regi, &localId);
-                                //TODO: HERE missing: 2 regs
-                                picode->invalidate();
-                                numHlIcodes--;
-                                break;
-
-                            case HLI_PUSH: case HLI_RET:
-                                ti_hl->expr( COND_EXPR::idFunc ( picode->hl()->call.proc, picode->hl()->call.args) );
-                                picode->invalidate();
-                                numHlIcodes--;
-                                break;
-
-                            case HLI_JCOND:
-                                exp = COND_EXPR::idFunc ( picode->hl()->call.proc, picode->hl()->call.args);
-                                res = COND_EXPR::insertSubTreeReg (ti_hl->exp.v, exp, retVal->id.regi, &localId);
-                                if (res)	/* was substituted */
-                                {
+                                case HLI_ASSIGN:
+                                    assert(ti_hl->asgn.rhs);
+                                    _exp = COND_EXPR::idFunc ( picode->hl()->call.proc, picode->hl()->call.args);
+                                    res = COND_EXPR::insertSubTreeReg (ti_hl->asgn.rhs,_exp, _retVal->id.regi, &localId);
+                                    if (! res)
+                                        COND_EXPR::insertSubTreeReg (ti_hl->asgn.lhs, _exp,_retVal->id.regi, &localId);
+                                    //TODO: HERE missing: 2 regs
+                                    picode->invalidate();
+                                    numHlIcodes--;
+                                    break;
+
+                                case HLI_PUSH: case HLI_RET:
+                                    ti_hl->expr( COND_EXPR::idFunc ( picode->hl()->call.proc, picode->hl()->call.args) );
                                     picode->invalidate();
                                     numHlIcodes--;
-                                }
-                                else	/* cannot substitute function */
-                                {
-                                    //picode->loc_ip
-                                    lhs = COND_EXPR::idID(retVal,&localId,picode);
-                                    picode->setAsgn(lhs, exp);
-                                }
-                                break;
+                                    break;
+
+                                case HLI_JCOND:
+                                    _exp = COND_EXPR::idFunc ( picode->hl()->call.proc, picode->hl()->call.args);
+                                    res = COND_EXPR::insertSubTreeReg (ti_hl->exp.v, _exp, _retVal->id.regi, &localId);
+                                    if (res)	/* was substituted */
+                                    {
+                                        picode->invalidate();
+                                        numHlIcodes--;
+                                    }
+                                    else	/* cannot substitute function */
+                                    {
+                                        //picode->loc_ip
+                                        lhs = COND_EXPR::idID(_retVal,&localId,picode);
+                                        picode->setAsgn(lhs, _exp);
+                                    }
+                                    break;
                             } /* eos */
                             break;
-                        } /* eos */
-                    }
+                    } /* eos */
                 }
+            }
 
-                else if (picode->du1.numRegsDef == 2)   /* long regs */
+            else if (picode->du1.numRegsDef == 2)   /* long regs */
+            {
+                /* Check for only one use of these registers */
+                if ((picode->du1.numUses(0) == 1) and (picode->du1.numUses(1) == 1))
                 {
-                    /* Check for only one use of these registers */
-                    if ((picode->du1.numUses(0) == 1) and (picode->du1.numUses(1) == 1))
-                    {
-                        switch (picode->hl()->opcode) {
+                    switch (picode->hl()->opcode) {
                         case HLI_ASSIGN:
                             /* Replace rhs of current icode into target
-                             * icode expression */
+                         * icode expression */
                             if (picode->du1.idx[0].uses[0] == picode->du1.idx[1].uses[0])
                             {
                                 ticode = picode->du1.idx[0].uses.front();
@@ -982,24 +1000,24 @@ void Function::findExps()
                                          (ticode->hl()->opcode != HLI_RET)))
                                     continue;
 
-                                exp = g_exp_stk.pop(); /* pop last exp pushed */
+                                _exp = g_exp_stk.pop(); /* pop last exp pushed */
                                 switch (ticode->hl()->opcode) {
-                                case HLI_ASSIGN:
-                                    forwardSubsLong (picode->hl()->expr()->expr.ident.idNode.longIdx,
-                                                     exp, picode, ticode, &numHlIcodes);
-                                    break;
-                                case HLI_JCOND: case HLI_PUSH:
-                                    res = COND_EXPR::insertSubTreeLongReg (exp,
-                                                                &ticode->hl()->exp.v,
-                                                                picode->hl()->asgn.lhs->expr.ident.idNode.longIdx);
-                                    if (res)
-                                    {
-                                        picode->invalidate();
-                                        numHlIcodes--;
-                                    }
-                                    break;
-                                case HLI_CALL:	/*** missing ***/
-                                    break;
+                                    case HLI_ASSIGN:
+                                        forwardSubsLong (picode->hl()->expr()->expr.ident.idNode.longIdx,
+                                                         _exp, picode, ticode, &numHlIcodes);
+                                        break;
+                                    case HLI_JCOND: case HLI_PUSH:
+                                        res = COND_EXPR::insertSubTreeLongReg (_exp,
+                                                                               &ticode->hl()->exp.v,
+                                                                               picode->hl()->asgn.lhs->expr.ident.idNode.longIdx);
+                                        if (res)
+                                        {
+                                            picode->invalidate();
+                                            numHlIcodes--;
+                                        }
+                                        break;
+                                    case HLI_CALL:	/*** missing ***/
+                                        break;
                                 } /* eos */
                             }
                             break;
@@ -1008,74 +1026,73 @@ void Function::findExps()
                             ticode = picode->du1.idx[0].uses.front();
                             switch (ticode->hl()->opcode)
                             {
-                            case HLI_ASSIGN:
-                                exp = COND_EXPR::idFunc ( picode->hl()->call.proc, picode->hl()->call.args);
-                                ticode->hl()->asgn.lhs =
-                                        COND_EXPR::idLong(&localId, DST, ticode,HIGH_FIRST, picode, eDEF, ++iICODE(ticode));
-                                ticode->hl()->asgn.rhs = exp;
-                                picode->invalidate();
-                                numHlIcodes--;
-                                break;
-
-                            case HLI_PUSH:  case HLI_RET:
-                                ticode->hl()->expr( COND_EXPR::idFunc ( picode->hl()->call.proc, picode->hl()->call.args) );
-                                picode->invalidate();
-                                numHlIcodes--;
-                                break;
-
-                            case HLI_JCOND:
-                                exp = COND_EXPR::idFunc ( picode->hl()->call.proc, picode->hl()->call.args);
-                                retVal = &picode->hl()->call.proc->retVal;
-                                res = COND_EXPR::insertSubTreeLongReg (exp,
-                                                            &ticode->hl()->exp.v,
-                                                            localId.newLongReg ( retVal->type, retVal->id.longId.h,
-                                                                                 retVal->id.longId.l, picode));
-                                if (res)	/* was substituted */
-                                {
+                                case HLI_ASSIGN:
+                                    _exp = COND_EXPR::idFunc ( picode->hl()->call.proc, picode->hl()->call.args);
+                                    ticode->hl()->asgn.lhs =
+                                            COND_EXPR::idLong(&localId, DST, ticode,HIGH_FIRST, picode, eDEF, ++iICODE(ticode));
+                                    ticode->hl()->asgn.rhs = _exp;
+                                    picode->invalidate();
+                                    numHlIcodes--;
+                                    break;
+
+                                case HLI_PUSH:  case HLI_RET:
+                                    ticode->hl()->expr( COND_EXPR::idFunc ( picode->hl()->call.proc, picode->hl()->call.args) );
                                     picode->invalidate();
                                     numHlIcodes--;
-                                }
-                                else	/* cannot substitute function */
-                                {
-                                    lhs = COND_EXPR::idID(retVal,&localId,picode/*picode->loc_ip*/);
-                                    picode->setAsgn(lhs, exp);
-                                }
-                                break;
+                                    break;
+
+                                case HLI_JCOND:
+                                    _exp = COND_EXPR::idFunc ( picode->hl()->call.proc, picode->hl()->call.args);
+                                    _retVal = &picode->hl()->call.proc->retVal;
+                                    res = COND_EXPR::insertSubTreeLongReg (_exp,
+                                                                           &ticode->hl()->exp.v,
+                                                                           localId.newLongReg ( _retVal->type, _retVal->id.longId.h,
+                                                                                                _retVal->id.longId.l, picode));
+                                    if (res)	/* was substituted */
+                                    {
+                                        picode->invalidate();
+                                        numHlIcodes--;
+                                    }
+                                    else	/* cannot substitute function */
+                                    {
+                                        lhs = COND_EXPR::idID(_retVal,&localId,picode/*picode->loc_ip*/);
+                                        picode->setAsgn(lhs, _exp);
+                                    }
+                                    break;
                             } /* eos */
-                        } /* eos */
-                    }
+                    } /* eos */
                 }
+            }
 
-                /* HLI_PUSH doesn't define any registers, only uses registers.
-                 * Push the associated expression to the register on the local
-                 * expression stack */
-                else if (picode->hl()->opcode == HLI_PUSH)
-                {
-                    g_exp_stk.push(picode->hl()->expr());
-                    picode->invalidate();
-                    numHlIcodes--;
-                }
+            /* HLI_PUSH doesn't define any registers, only uses registers.
+             * Push the associated expression to the register on the local
+             * expression stack */
+            else if (picode->hl()->opcode == HLI_PUSH)
+            {
+                g_exp_stk.push(picode->hl()->expr());
+                picode->invalidate();
+                numHlIcodes--;
+            }
 
-                /* For HLI_CALL instructions that use arguments from the stack,
-                 * pop them from the expression stack and place them on the
-                 * procedure's argument list */
+            /* For HLI_CALL instructions that use arguments from the stack,
+             * pop them from the expression stack and place them on the
+             * procedure's argument list */
 
-                if ((picode->hl()->opcode == HLI_CALL) &&  ! (picode->hl()->call.proc->flg & REG_ARGS))
-                {
-                    processHliCall1(exp, picode);
-                }
+            if ((picode->hl()->opcode == HLI_CALL) &&  ! (picode->hl()->call.proc->flg & REG_ARGS))
+            {
+                processHliCall1(_exp, picode);
+            }
 
-                /* If we could not substitute the result of a function,
-                 * assign it to the corresponding registers */
-                if ((picode->hl()->opcode == HLI_CALL) &&
-                        ((picode->hl()->call.proc->flg & PROC_ISLIB) !=
-                         PROC_ISLIB) && (not picode->du1.used(0)) &&
-                        (picode->du1.numRegsDef > 0))
-                {
-                    exp = COND_EXPR::idFunc (picode->hl()->call.proc, picode->hl()->call.args);
-                    lhs = COND_EXPR::idID (&picode->hl()->call.proc->retVal, &localId, picode);
-                    picode->setAsgn(lhs, exp);
-                }
+            /* If we could not substitute the result of a function,
+             * assign it to the corresponding registers */
+            if ((picode->hl()->opcode == HLI_CALL) &&
+                    ((picode->hl()->call.proc->flg & PROC_ISLIB) !=
+                     PROC_ISLIB) && (not picode->du1.used(0)) &&
+                    (picode->du1.numRegsDef > 0))
+            {
+                _exp = COND_EXPR::idFunc (picode->hl()->call.proc, picode->hl()->call.args);
+                lhs = COND_EXPR::idID (&picode->hl()->call.proc->retVal, &localId, picode);
+                picode->setAsgn(lhs, _exp);
             }
         }
 
@@ -1088,26 +1105,43 @@ void Function::findExps()
 /** Invokes procedures related with data flow analysis.  Works on a procedure
  * at a time basis.
  * Note: indirect recursion in liveRegAnalysis is possible. */
-void Function::dataFlow(std::bitset<32> &liveOut)
+void Function::dataFlow(std::bitset<32> &_liveOut)
 {
-    boolT isAx, isBx, isCx, isDx;
+    bool isAx, isBx, isCx, isDx;
     int idx;
 
     /* Remove references to register variables */
     if (flg & SI_REGVAR)
-        liveOut &= maskDuReg[rSI];
+        _liveOut &= maskDuReg[rSI];
     if (flg & DI_REGVAR)
-        liveOut &= maskDuReg[rDI];
+        _liveOut &= maskDuReg[rDI];
 
     /* Function - return value register(s) */
-    if (liveOut != 0)
+    if (_liveOut.any())
     {
         flg |= PROC_IS_FUNC;
-        isAx = liveOut.test(rAX - rAX);
-        isBx = liveOut.test(rBX - rAX);
-        isCx = liveOut.test(rCX - rAX);
-        isDx = liveOut.test(rDX - rAX);
-
+        isAx = _liveOut.test(rAX - rAX);
+        isBx = _liveOut.test(rBX - rAX);
+        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 isDL = !isDx && _liveOut.test(rDL - rAX);
+        bool isDH = !isDx && _liveOut.test(rDH - rAX);
+        if(isAL && isAH)
+        {
+            isAx = true;
+            printf("**************************************************************************** dataFlow Join discovered Ax\n");
+            isAH=isAL=false;
+        }
+        if(isDL && isDH)
+        {
+            isDx = true;
+            printf("**************************************************************************** dataFlow Join discovered Dx\n");
+            isDH=isDL=false;
+        }
         if (isAx && isDx)       /* long or pointer */
         {
             retVal.type = TYPE_LONG_SIGN;
@@ -1131,13 +1165,29 @@ void Function::dataFlow(std::bitset<32> &liveOut)
                 retVal.id.regi = rDX;
             idx = localId.newByteWordReg(TYPE_WORD_SIGN,retVal.id.regi);
         }
+        else if(isAL||isBL||isCL||isDL)
+        {
+            printf("**************************************************************************** AL/DL return \n");
+            retVal.type = TYPE_BYTE_SIGN;
+            retVal.loc = REG_FRAME;
+            if (isAL)
+                retVal.id.regi = rAL;
+            else if (isBL)
+                retVal.id.regi = rBL;
+            else if (isCL)
+                retVal.id.regi = rCL;
+            else
+                retVal.id.regi = rDL;
+            idx = localId.newByteWordReg(TYPE_BYTE_SIGN,retVal.id.regi);
+
+        }
     }
 
     /* Data flow analysis */
     liveAnal = true;
     elimCondCodes();
     genLiveKtes();
-    liveRegAnalysis (liveOut);   /* calls dataFlow() recursively */
+    liveRegAnalysis (_liveOut);   /* calls dataFlow() recursively */
     if (! (flg & PROC_ASM))		/* can generate C for pProc		*/
     {
         genDU1 ();			/* generate def/use level 1 chain */

+ 5 - 5
src/dcc.cpp

@@ -8,7 +8,7 @@
 #include <string.h>
 
 /* Global variables - extern to other modules */
-char    *progname;          /* argv[0] - for error msgs 			  */
+//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 +73,7 @@ int main(int argc, char *argv[])
 static char *initargs(int argc, char *argv[])
 {
     char *pc;
-    progname = *argv;   /* Save invocation name for error messages */
+    //progname = *argv;   /* Save invocation name for error messages */
 
     while (--argc > 0 && (*++argv)[0] == '-')
     {
@@ -117,8 +117,8 @@ static char *initargs(int argc, char *argv[])
                     }
                 //lint -fallthrough
                 default:
-                    fatalError(INVALID_ARG, *pc);
-                    return *argv;
+                    fatalError(INVALID_ARG, *pc); // does not return
+
             }
 NextArg:;
     }
@@ -146,7 +146,7 @@ NextArg:;
     }
 
     fatalError(USAGE);
-    return *argv;
+    return *argv; // does not reach this.
 }
 
 static void

+ 18 - 18
src/disassem.cpp

@@ -139,12 +139,12 @@ boolT callArg(uint16_t off, char *temp);  /* Check for procedure name */
 
 static  FILE   *fp;
 static  CIcodeRec pc;
-static std::ostringstream buf;
-static  int     cb, j, numIcode, allocIcode, eop;
+
+static  int     cb, j, numIcode, allocIcode;
 static  map<int,int> pl;
 static  uint32_t   nextInst;
 static  boolT    fImpure;
-static  int     lab, prevPass;
+static  int     g_lab, prevPass;
 static  Function *   pProc;          /* Points to current proc struct */
 
 struct POSSTACK_ENTRY
@@ -165,13 +165,13 @@ uint8_t              iPS;          /* Index into the stack */
 #define dis_show()					// Nothing to do unless using Curses
 
 
-void LLInst::findJumpTargets(CIcodeRec &pc)
+void LLInst::findJumpTargets(CIcodeRec &_pc)
 {
     if (testFlags(I) && ! testFlags(JMP_ICODE) && isJmpInst())
     {
         /* Replace the immediate operand with an icode index */
-        iICODE labTgt=pc.labelSrch(src.op());
-        if (labTgt!=pc.end())
+        iICODE labTgt=_pc.labelSrch(src.op());
+        if (labTgt!=_pc.end())
         {
             src.SetImmediateOp(labTgt->loc_ip);
             /* This icode is the target of a jump */
@@ -194,13 +194,13 @@ void LLInst::findJumpTargets(CIcodeRec &pc)
  ****************************************************************************/
 void disassem(int pass, Function * ppProc)
 {
-    int         i;
+
 
     pProc = ppProc;             /* Save the passes pProc */
     if (pass != prevPass)
     {
         prevPass = pass;
-        lab = 0; 	/* Restart label numbers */
+        g_lab = 0; 	/* Restart label numbers */
     }
     createSymTables();
     allocIcode = numIcode = pProc->Icode.size();
@@ -342,7 +342,7 @@ void LLInst::dis1Line(int loc_ip, int pass)
             /* Print label */
             if (pl.count(loc_ip)==0)
             {
-                pl[loc_ip] = ++lab;
+                pl[loc_ip] = ++g_lab;
             }
             lab_contents<< "L"<<pl[loc_ip]<<':';
         }
@@ -435,7 +435,7 @@ void LLInst::dis1Line(int loc_ip, int pass)
                 j = src.op();
                 if (pl.count(j)==0)       /* Forward jump */
                 {
-                    pl[j] = ++lab;
+                    pl[j] = ++g_lab;
                 }
                 if (opcode == iJMPF)
                 {
@@ -641,12 +641,12 @@ static void formatRM(std::ostringstream &p, uint32_t flg, const LLOperand &pm)
         p<<seg<<"["<<strHex((uint32_t)pm.off)<<"]";
     }
 
-    else if (pm.regi == (INDEXBASE - 1))
+    else if (pm.regi == (INDEX_BX_SI - 1))
     {
         p<<"tmp";
     }
 
-    else if (pm.regi < INDEXBASE)
+    else if (pm.regi < INDEX_BX_SI)
     {
         if(flg & B)
             p << szBreg[pm.regi - rAL];
@@ -658,15 +658,15 @@ static void formatRM(std::ostringstream &p, uint32_t flg, const LLOperand &pm)
     {
         if (pm.off < 0)
         {
-            p <<seg<<"["<<szIndex[pm.regi - INDEXBASE]<<"-"<<strHex((uint32_t)(- pm.off))<<"]";
+            p <<seg<<"["<<szIndex[pm.regi - INDEX_BX_SI]<<"-"<<strHex((uint32_t)(- pm.off))<<"]";
         }
         else
         {
-            p <<seg<<"["<<szIndex[pm.regi - INDEXBASE]<<"+"<<strHex((uint32_t)(pm.off))<<"]";
+            p <<seg<<"["<<szIndex[pm.regi - INDEX_BX_SI]<<"+"<<strHex((uint32_t)(pm.off))<<"]";
         }
     }
     else
-        p <<seg<<"["<<szIndex[pm.regi - INDEXBASE]<<"]";
+        p <<seg<<"["<<szIndex[pm.regi - INDEX_BX_SI]<<"]";
 }
 
 
@@ -677,7 +677,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 >= INDEXBASE))
+    if ((flg & I) && (pm.regi == 0 || pm.regi >= INDEX_BX_SI))
         os << szPtr[flg & B];
     formatRM(os, flg, pm);
     return os;
@@ -689,7 +689,7 @@ static ostringstream & strDst(ostringstream &os,uint32_t flg, LLOperand &pm)
  ****************************************************************************/
 ostringstream &LLInst::strSrc(ostringstream &os,bool skip_comma)
 {
-    static char buf[30] = {", "};
+
     if(false==skip_comma)
         os<<", ";
     if (testFlags(I))
@@ -734,7 +734,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 >= INDEXBASE))
+    if ((dst.regi == 0) || (dst.regi >= INDEX_BX_SI))
     {
         /* The mod/rm mod bits are not set to 11 (i.e. register). This is the normal floating point opcode */
         out<<szFlops1[op]<<' ';

+ 19 - 23
src/graph.cpp

@@ -5,11 +5,7 @@
 
 #include "dcc.h"
 #include <string.h>
-#if __BORLAND__
-#include <alloc.h>
-#else
 #include <malloc.h>		/* For free() */
-#endif
 #include "graph.h"
 
 //static BB *  rmJMP(Function * pProc, int marker, BB * pBB);
@@ -134,7 +130,7 @@ CondJumps:
                             pBB->edges[0].ip = (uint32_t)start;
                         }
                     }
-                break;
+                    break;
             }
         }
     }
@@ -143,20 +139,20 @@ CondJumps:
     for (; iter!=heldBBs.end(); ++iter)
     {
         pBB = *iter;
-        for (i = 0; i < pBB->edges.size(); i++)
+        for (size_t edeg_idx = 0; edeg_idx < pBB->edges.size(); edeg_idx++)
         {
-            ip = pBB->edges[i].ip;
+            ip = pBB->edges[edeg_idx].ip;
             if (ip >= SYNTHESIZED_MIN)
             {
                 fatalError (INVALID_SYNTHETIC_BB);
-                return ;
+                return;
             }
             auto iter2=std::find_if(heldBBs.begin(),heldBBs.end(),
-                         [ip](BB *psBB)->bool {return psBB->begin()->loc_ip==ip;});
+                                    [ip](BB *psBB)->bool {return psBB->begin()->loc_ip==ip;});
             if(iter2==heldBBs.end())
                 fatalError(NO_BB, ip, name.c_str());
             psBB = *iter2;
-            pBB->edges[i].BBptr = psBB;
+            pBB->edges[edeg_idx].BBptr = psBB;
             psBB->inEdges.push_back((BB *)nullptr);
         }
     }
@@ -218,14 +214,14 @@ void Function::freeCFG()
  ****************************************************************************/
 void Function::compressCFG()
 {
-    BB * pBB, *pNxt;
-    int	ip, first=0, last, i;
+    BB *pNxt;
+    int	ip, first=0, last;
 
     /* First pass over BB list removes redundant jumps of the form
          * (Un)Conditional -> Unconditional jump  */
 #ifdef _lint
-    auto iter=m_cfg.begin();
-    for (;iter!=m_cfg.end(); ++iter)
+
+    for (auto iter=m_cfg.begin(); iter!=m_cfg.end(); ++iter)
     {
         BB *pBB(*iter);
 #else
@@ -235,9 +231,9 @@ void Function::compressCFG()
         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)
+        for (auto iter2=pBB->edges.begin(); iter2!=pBB->edges.end(); ++iter2)
         {
-            TYPEADR_TYPE &edgeRef(*iter);
+            TYPEADR_TYPE &edgeRef(*iter2);
 #else
         for (TYPEADR_TYPE &edgeRef : pBB->edges)
         {
@@ -265,7 +261,7 @@ void Function::compressCFG()
 
     for(auto iter=m_cfg.begin(); iter!=m_cfg.end(); ++iter)
     {
-        pBB = *iter;
+        BB * pBB = *iter;
         if (pBB->inEdges.empty())
         {
             if (iter == m_cfg.begin())	/* Init it misses out on */
@@ -330,8 +326,8 @@ BB *BB::rmJMP(int marker, BB * pBB)
                 {
                     pBB->front().ll()->setFlags(NO_CODE);
                     pBB->front().invalidate();
-//                    pProc->Icode.setFlags(pBB->start, NO_CODE);
-//                    pProc->Icode.SetLlInvalid(pBB->start, TRUE);
+                    //                    pProc->Icode.setFlags(pBB->start, NO_CODE);
+                    //                    pProc->Icode.SetLlInvalid(pBB->start, TRUE);
                 }
             } while (pBB->nodeType != NOWHERE_NODE);
 
@@ -364,7 +360,7 @@ void BB::mergeFallThrough( CIcodeRec &Icode)
             if(back().loc_ip>pChild->front().loc_ip) // back edege
                 break;
             auto iter=std::find_if(this->end(),pChild->begin(),[](ICODE &c)
-                {return not c.ll()->testFlags(NO_CODE);});
+            {return not c.ll()->testFlags(NO_CODE);});
 
             if (iter != pChild->begin())
                 break;
@@ -390,8 +386,8 @@ void BB::mergeFallThrough( CIcodeRec &Icode)
 
     /* Process all out edges recursively */
     for (i = 0; i < edges.size(); i++)
-        if (edges[i].BBptr->traversed != DFS_MERGE)
-            edges[i].BBptr->mergeFallThrough(Icode);
+    if (edges[i].BBptr->traversed != DFS_MERGE)
+    edges[i].BBptr->mergeFallThrough(Icode);
 }
 
 
@@ -406,7 +402,7 @@ void BB::dfsNumbering(std::vector<BB *> &dfsLast, int *first, int *last)
     dfsFirstNum = (*first)++;
 
     /* index is being used as an index to inEdges[]. */
-//    for (i = 0; i < edges.size(); i++)
+    //    for (i = 0; i < edges.size(); i++)
 #ifdef _lint
     for (auto i=edges.begin(); i!=edges.end(); ++i)
     {

+ 10 - 9
src/hlicode.cpp

@@ -59,10 +59,10 @@ void ICODE::newCallHl()
 
 /* Places the new HLI_POP/HLI_PUSH/HLI_RET high-level operand in the high-level icode
  * array */
-void ICODE::setUnary(hlIcode op, COND_EXPR *exp)
+void ICODE::setUnary(hlIcode op, COND_EXPR *_exp)
 {
     type = HIGH_LEVEL;
-    hl()->set(op,exp);
+    hl()->set(op,_exp);
 }
 
 
@@ -285,8 +285,9 @@ void Function::highLevelGen()
     int numIcode;         /* number of icode instructions */
     iICODE pIcode;        /* ptr to current icode node */
     COND_EXPR *lhs, *rhs; /* left- and right-hand side of expression */
-    uint32_t flg;          /* icode flags */
+    uint32_t _flg;          /* icode flags */
     numIcode = Icode.size();
+    lhs=rhs=0;
     for (iICODE i = Icode.begin(); i!=Icode.end() ; ++i)
     {
         assert(numIcode==Icode.size());
@@ -296,9 +297,9 @@ void Function::highLevelGen()
             pIcode->invalidate();
         if ((pIcode->type != LOW_LEVEL) or not pIcode->valid() )
             continue;
-        flg = ll->getFlag();
-        if ((flg & IM_OPS) != IM_OPS)   /* not processing IM_OPS yet */
-            if ((flg & NO_OPS) != NO_OPS)       /* if there are opers */
+        _flg = ll->getFlag();
+        if ((_flg & IM_OPS) != IM_OPS)   /* not processing IM_OPS yet */
+            if ((_flg & NO_OPS) != NO_OPS)       /* if there are opers */
             {
                 if ( not ll->testFlags(NO_SRC) )   /* if there is src op */
                     rhs = COND_EXPR::id (*pIcode->ll(), SRC, this, i, *pIcode, NONE);
@@ -606,7 +607,7 @@ void ICODE::writeDU()
     int my_idx = loc_ip;
     {
         ostringstream ostr;
-        for (int i = 0; i < (INDEXBASE-1); i++)
+        for (int i = 0; i < (INDEX_BX_SI-1); i++)
             if (du.def[i])
                 ostr << allRegs[i] << " ";
         if (!ostr.str().empty())
@@ -614,12 +615,12 @@ void ICODE::writeDU()
     }
     {
         ostringstream ostr;
-        for (int i = 0; i < (INDEXBASE-1); i++)
+        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 < INDEXBASE; i++)
+        for (int i = 0; i < INDEX_BX_SI; i++)
         {
             if (du.use[i])
                 ostr << allRegs[i] << " ";

+ 6 - 8
src/icode.cpp

@@ -27,7 +27,7 @@ ICODE * CIcodeRec::addIcode(ICODE *pIcode)
     return &back();
 }
 
-void CIcodeRec::SetInBB(int start, int end, BB *pnewBB)
+void CIcodeRec::SetInBB(int start, int _end, BB *pnewBB)
 {
 #ifdef _lint
     for (auto ik=this->begin(); ik!=this->end(); ++ik)
@@ -37,18 +37,16 @@ void CIcodeRec::SetInBB(int start, int end, BB *pnewBB)
     for(ICODE &icode : *this)
     {
 #endif
-        if((icode.loc_ip>=start) and (icode.loc_ip<=end))
+        if((icode.loc_ip>=start) and (icode.loc_ip<=_end))
             icode.inBB = pnewBB;
     }
-    //    for (int i = start; i <= end; i++)
-//        at(i).inBB = pnewBB;
 }
 
 /* labelSrchRepl - Searches the icodes for instruction with label = target, and
    replaces *pIndex with an icode index */
 bool CIcodeRec::labelSrch(uint32_t target, uint32_t &pIndex)
 {
-    int  i;
+
     iICODE location=labelSrch(target);
     if(end()==location)
             return false;
@@ -57,7 +55,7 @@ bool CIcodeRec::labelSrch(uint32_t target, uint32_t &pIndex)
 }
 CIcodeRec::iterator CIcodeRec::labelSrch(uint32_t target)
 {
-    int  i;
+
     return find_if(begin(),end(),[target](ICODE &l) -> bool {return l.ll()->label==target;});
 }
 ICODE * CIcodeRec::GetIcode(int ip)
@@ -68,7 +66,7 @@ ICODE * CIcodeRec::GetIcode(int ip)
     return &(*res);
 }
 
-extern char *indent(int level);
+
 extern int getNextLabel();
 extern bundle cCode;
 /* Checks the given icode to determine whether it has a label associated
@@ -88,7 +86,7 @@ void LLInst::emitGotoLabel (int indLevel)
                  * the code */
         addLabelBundle (cCode.code, codeIdx, hllLabNum);
     }
-    cCode.appendCode( "%sgoto L%ld;\n", indent(indLevel), hllLabNum);
+    cCode.appendCode( "%sgoto L%ld;\n", indentStr(indLevel), hllLabNum);
     stats.numHLIcode++;
 }
 

+ 1 - 1
src/idioms.cpp

@@ -221,7 +221,7 @@ void Function::findIdioms()
  * binds jump target addresses to icode offsets.    */
 void Function::bindIcodeOff()
 {
-    int i;                 /* idx into icode array */
+
     iICODE pIcode;            /* ptr icode array      */
     uint32_t *p;                 /* for case table       */
 

+ 7 - 7
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 < INDEXBASE)	/* register */
+    else if (m_icodes[1]->ll()->dst.regi < INDEX_BX_SI)	/* 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 < INDEXBASE))
+            if ((regi > 0) && (regi < INDEX_BX_SI))
             {
                 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 < INDEXBASE))
+            if ((regi > 0) && (regi < INDEX_BX_SI))
             {
                 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 < INDEXBASE) /* register */
+    else if (m_icodes[0]->ll()->dst.regi < INDEX_BX_SI) /* register */
     {
         //        if (((picode->ll()->dst.regi == rSI) && (pproc->flg & SI_REGVAR)) ||
         //            ((picode->ll()->dst.regi == rDI) && (pproc->flg & DI_REGVAR)))
@@ -253,7 +253,7 @@ bool Idiom20::match(iICODE picode)
     {
         /* not supported yet */ ;
     }
-    else if (m_icodes[0]->ll()->dst.regi < INDEXBASE)	/* register */
+    else if (m_icodes[0]->ll()->dst.regi < INDEX_BX_SI)	/* register */
     {
         if ((m_icodes[0]->ll()->dst.regi == rSI) && (m_func->flg & SI_REGVAR))
             type = 1;
@@ -275,7 +275,7 @@ bool Idiom20::match(iICODE picode)
                 (m_icodes[1]->ll()->src.regi == m_icodes[0]->ll()->dst.regi))
         {
             regi = m_icodes[1]->ll()->dst.regi;
-            if ((regi > 0) && (regi < INDEXBASE))
+            if ((regi > 0) && (regi < INDEX_BX_SI))
             {
                 if (m_icodes[2]->ll()->match(iCMP,(eReg)regi) &&
                         m_icodes[3]->ll()->conditionalJump())
@@ -289,7 +289,7 @@ bool Idiom20::match(iICODE picode)
              (m_icodes[1]->ll()->src.off == m_icodes[0]->ll()->dst.off))
         {
             regi = m_icodes[1]->ll()->dst.regi;
-            if ((regi > 0) && (regi < INDEXBASE))
+            if ((regi > 0) && (regi < INDEX_BX_SI))
             {
                 if (m_icodes[2]->ll()->match(iCMP,(eReg)regi) &&
                         m_icodes[3]->ll()->conditionalJump())

+ 1 - 1
src/idioms/call_idioms.cpp

@@ -101,7 +101,7 @@ int Idiom17::action()
         m_icodes[0]->ll()->src.proc.proc->cbParam = (int16_t)m_param_count;
         m_icodes[0]->ll()->src.proc.cb = m_param_count;
         m_icodes[0]->ll()->src.proc.proc->flg |= CALL_C;
-        for(int idx=1; idx<m_icodes.size(); ++idx)
+        for(size_t idx=1; idx<m_icodes.size(); ++idx)
         {
             m_icodes[idx]->invalidate();
         }

+ 4 - 4
src/idioms/idiom1.cpp

@@ -50,13 +50,13 @@ int Idiom1::checkStkVars (iICODE pIcode)
  ****************************************************************************/
 bool Idiom1::match(iICODE picode)
 {
-    uint8_t type = 0;	/* type of variable: 1 = reg-var, 2 = local */
-    uint8_t regi;		/* register of the MOV */
+    //uint8_t type = 0;	/* type of variable: 1 = reg-var, 2 = local */
+    //uint8_t regi;		/* register of the MOV */
     if(m_func->flg & PROC_HLL)
         return false;
     if(picode==m_end)
         return false;
-    int n;
+    //int n;
     m_icodes.clear();
     m_min_off = 0;
     /* PUSH BP as first instruction of procedure */
@@ -114,7 +114,7 @@ bool Idiom1::match(iICODE picode)
     }
     else // push di [push si] / push si [push di]
     {
-        n = checkStkVars (picode);
+        size_t n = checkStkVars (picode);
         for(int i=0; i<n; ++i)
             m_icodes.push_back(picode++);
 

+ 1 - 1
src/idioms/neg_idioms.cpp

@@ -80,7 +80,7 @@ bool Idiom16::match (iICODE picode)
         m_icodes[i]=picode++;
 
     uint8_t regi = m_icodes[0]->ll()->dst.regi;
-    if ((regi >= rAX) && (regi < INDEXBASE))
+    if ((regi >= rAX) && (regi < INDEX_BX_SI))
     {
         if (m_icodes[1]->ll()->match(iSBB) && m_icodes[2]->ll()->match(iINC))
             if ((m_icodes[1]->ll()->dst.regi == (m_icodes[1]->ll()->src.regi)) &&

+ 5 - 5
src/idioms/shift_idioms.cpp

@@ -57,7 +57,7 @@ int Idiom8::action()
  ****************************************************************************/
 bool Idiom15::match(iICODE pIcode)
 {
-    int n = 1;
+
     uint8_t regi;
 
     if(distance(pIcode,m_end)<2)
@@ -72,7 +72,7 @@ bool Idiom15::match(iICODE pIcode)
             pIcode->ll()->match(iSHL,(eReg)regi,I) and
             (pIcode->ll()->src.op() == 1) )
     {
-        n++;
+
         m_icodes.push_back(pIcode++);
     }
     return m_icodes.size()>1;
@@ -80,13 +80,13 @@ bool Idiom15::match(iICODE pIcode)
 
 int Idiom15::action()
 {
-    COND_EXPR *lhs,*rhs,*exp;
+    COND_EXPR *lhs,*rhs,*_exp;
     lhs = COND_EXPR::idReg (m_icodes[0]->ll()->dst.regi,
                             m_icodes[0]->ll()->getFlag() & NO_SRC_B,
                              &m_func->localId);
     rhs = COND_EXPR::idKte (m_icodes.size(), 2);
-    exp = COND_EXPR::boolOp (lhs, rhs, SHL);
-    m_icodes[0]->setAsgn(lhs, exp);
+    _exp = COND_EXPR::boolOp (lhs, rhs, SHL);
+    m_icodes[0]->setAsgn(lhs, _exp);
     for (size_t i=1; i<m_icodes.size()-1; ++i)
     {
         m_icodes[i]->invalidate();

+ 4 - 4
src/idioms/xor_idioms.cpp

@@ -28,7 +28,7 @@ bool Idiom21::match (iICODE picode)
 
     dst = &m_icodes[0]->ll()->dst;
     src = &m_icodes[0]->ll()->src;
-    if ((dst->regi == src->regi) && (dst->regi > 0) && (dst->regi < INDEXBASE))
+    if ((dst->regi == src->regi) && (dst->regi > 0) && (dst->regi < INDEX_BX_SI))
     {
         if ((dst->regi == rDX) && m_icodes[1]->ll()->match(rAX))
             return true;
@@ -68,12 +68,12 @@ bool Idiom7::match(iICODE picode)
         if ((dst->segValue == src->segValue) && (dst->off == src->off))
             return true;
     }
-    else if (dst->regi < INDEXBASE)     /* register */
+    else if (dst->regi < INDEX_BX_SI)     /* register */
     {
         if (dst->regi == src->regi)
             return true;
     }
-    else if ((dst->off) && (dst->seg == rSS) && (dst->regi == INDEXBASE + 6)) /* offset from BP */
+    else if ((dst->off) && (dst->seg == rSS) && (dst->regi == INDEX_BP)) /* offset from BP */
     {
         if ((dst->off == src->off) && (dst->seg == src->seg) && (dst->regi == src->regi))
             return true;
@@ -115,7 +115,7 @@ bool Idiom10::match(iICODE pIcode)
     /* Check OR reg, reg */
     if (not m_icodes[0]->ll()->testFlags(I)  &&
             (m_icodes[0]->ll()->src.regi > 0) &&
-            (m_icodes[0]->ll()->src.regi < INDEXBASE) &&
+            (m_icodes[0]->ll()->src.regi < INDEX_BX_SI) &&
             (m_icodes[0]->ll()->src.regi == m_icodes[0]->ll()->dst.regi))
         if (m_icodes[1]->ll()->match(iJNE)) //.conditionalJump()
         {

+ 10 - 9
src/locident.cpp

@@ -116,7 +116,7 @@ int LOCAL_ID::newByteWordStk(hlType t, int off, uint8_t regOff)
  *            regi: indexed register into global variable
  *            ix: index into icode array
  *            t: HIGH_LEVEL type            */
-int LOCAL_ID::newIntIdx(int16_t seg, int16_t off, uint8_t regi, int ix, hlType t)
+int LOCAL_ID::newIntIdx(int16_t seg, int16_t off, eReg regi, int ix, hlType t)
 {
     int idx;
 
@@ -145,7 +145,7 @@ int LOCAL_ID::newIntIdx(int16_t seg, int16_t off, uint8_t regi, int ix, hlType t
  * TYPE_LONG_(UN)SIGN and returns the index to this new entry.  */
 int LOCAL_ID::newLongReg(hlType t, eReg regH, eReg regL, iICODE ix_)
 {
-    int idx;
+    size_t idx;
     //iICODE ix_;
     /* Check for entry in the table */
     for (idx = 0; idx < id_arr.size(); idx++)
@@ -183,7 +183,7 @@ int LOCAL_ID::newLongReg(hlType t, eReg regH, eReg regL, iICODE ix_)
  * TYPE_LONG_(UN)SIGN and returns the index to this new entry.  */
 int LOCAL_ID::newLongGlb(int16_t seg, int16_t offH, int16_t offL,hlType t)
 {
-    int idx;
+    size_t idx;
 
     /* Check for entry in the table */
     for (idx = 0; idx < id_arr.size(); idx++)
@@ -209,7 +209,8 @@ int LOCAL_ID::newLongGlb(int16_t seg, int16_t offH, int16_t offL,hlType t)
  * entry; otherwise creates a new global identifier node of type
  * TYPE_LONG_(UN)SIGN and returns the index to this new entry.  */
 int LOCAL_ID::newLongIdx( int16_t seg, int16_t offH, int16_t offL,uint8_t regi, hlType t)
-{ int idx;
+{
+    size_t idx;
 
     /* Check for entry in the table */
     for (idx = 0; idx < id_arr.size(); idx++)
@@ -237,7 +238,7 @@ int LOCAL_ID::newLongIdx( int16_t seg, int16_t offH, int16_t offL,uint8_t regi,
  * Returns the index to this entry. */
 int LOCAL_ID::newLongStk(hlType t, int offH, int offL)
 {
-    int idx;
+    size_t idx;
 
     /* Check for entry in the table */
     for (idx = 0; idx < id_arr.size(); idx++)
@@ -266,7 +267,7 @@ int LOCAL_ID::newLongStk(hlType t, int offH, int offL)
  *       number in an expression record.    */
 int LOCAL_ID::newLong(opLoc sd, iICODE pIcode, hlFirst f, iICODE ix,operDu du, iICODE atOffset)
 {
-    int idx;
+    size_t idx;
   LLOperand *pmH, *pmL;
 //  iICODE atOffset(pIcode);
 //  advance(atOffset,off);
@@ -285,7 +286,7 @@ int LOCAL_ID::newLong(opLoc sd, iICODE pIcode, hlFirst f, iICODE ix,operDu du, i
     if (pmL->regi == 0)                                 /* global variable */
         idx = newLongGlb(pmH->segValue, pmH->off, pmL->off, TYPE_LONG_SIGN);
 
-    else if (pmL->regi < INDEXBASE)                     /* register */
+    else if (pmL->regi < INDEX_BX_SI)                     /* register */
     {
         idx = newLongReg(TYPE_LONG_SIGN, pmH->regi, pmL->regi, ix);
         if (f == HIGH_FIRST)
@@ -295,9 +296,9 @@ int LOCAL_ID::newLong(opLoc sd, iICODE pIcode, hlFirst f, iICODE ix,operDu du, i
     }
 
     else if (pmL->off) {                                /* offset */
-        if ((pmL->seg == rSS) && (pmL->regi == INDEXBASE + 6)) /* idx on bp */
+        if ((pmL->seg == rSS) && (pmL->regi == INDEX_BP)) /* idx on bp */
             idx = newLongStk(TYPE_LONG_SIGN, pmH->off, pmL->off);
-        else if ((pmL->seg == rDS) && (pmL->regi == INDEXBASE + 7))   /* bx */
+        else if ((pmL->seg == rDS) && (pmL->regi == INDEX_BX))   /* bx */
         {                                       /* glb var indexed on bx */
             printf("Bx indexed global, BX is an unused parameter to newLongIdx\n");
             idx = newLongIdx(pmH->segValue, pmH->off, pmL->off,rBX,TYPE_LONG_SIGN);

+ 26 - 0
src/machine_x86.cpp

@@ -0,0 +1,26 @@
+
+#include "machine_x86.h"
+// Index registers **** temp solution
+static const std::string regNames[] = {
+    "undef",
+    "ax", "cx", "dx", "bx",
+    "sp", "bp", "si", "di",
+    "es", "cs", "ss", "ds",
+    "al", "cl", "dl", "bl",
+    "ah", "ch", "dh", "bh",
+    "tmp",
+    "bx+si", "bx+di", "bp+si", "bp+di",
+    "si", "di", "bp", "bx"
+};
+
+/* uint8_t and uint16_t registers */
+Machine_X86::Machine_X86()
+{
+    static_assert((sizeof(regNames)/sizeof(std::string))==LAST_REG,
+            "Reg count not equal number of strings");
+}
+
+const std::string &Machine_X86::regName(eReg r)
+{
+    return regNames[r];
+}

+ 23 - 22
src/parser.cpp

@@ -425,9 +425,9 @@ boolT Function::process_JMP (ICODE & pIcode, STATE *pstate, CALL_GRAPH * pcallGr
     /* Ensure we have a uint16_t offset & valid seg */
     if (pIcode.ll()->match(iJMP) and (pIcode.ll()->testFlags(WORD_OFF)) &&
             pstate->f[seg] &&
-            (pIcode.ll()->src.regi == INDEXBASE + 4 ||
-             pIcode.ll()->src.regi == INDEXBASE + 5 || /* Idx reg. BX, SI, DI */
-             pIcode.ll()->src.regi == INDEXBASE + 7))
+            (pIcode.ll()->src.regi == INDEX_SI ||
+             pIcode.ll()->src.regi == INDEX_DI || /* Idx reg. BX, SI, DI */
+             pIcode.ll()->src.regi == INDEX_BX))
     {
 
         offTable = ((uint32_t)(uint16_t)pstate->r[seg] << 4) + pIcode.ll()->src.off;
@@ -438,7 +438,7 @@ boolT Function::process_JMP (ICODE & pIcode, STATE *pstate, CALL_GRAPH * pcallGr
          * This is stored in the current state as if we had just
          * followed a JBE branch (i.e. [reg] lies between 0 - immed).
         */
-        if (pstate->JCond.regi == i2r[pIcode.ll()->src.regi-(INDEXBASE+4)])
+        if (pstate->JCond.regi == i2r[pIcode.ll()->src.regi-(INDEX_BX_SI+4)])
             endTable = offTable + pstate->JCond.immed;
         else
             endTable = (uint32_t)prog.cbImage;
@@ -488,7 +488,7 @@ boolT Function::process_JMP (ICODE & pIcode, STATE *pstate, CALL_GRAPH * pcallGr
 
             for (i = offTable, k = 0; i < endTable; i += 2)
             {
-                memcpy(&StCopy, pstate, sizeof(STATE));
+                StCopy = *pstate;
                 StCopy.IP = cs + LH(&prog.Image[i]);
                 iICODE last_current_insn = (++Icode.rbegin()).base();
                 ip = Icode.size();
@@ -643,7 +643,7 @@ static void process_MOV(LLInst & ll, STATE * pstate)
     SYM *  psym, *psym2;        /* Pointer to symbol in global symbol table */
     uint8_t  dstReg = ll.dst.regi;
     uint8_t  srcReg = ll.src.regi;
-    if (dstReg > 0 && dstReg < INDEXBASE)
+    if (dstReg > 0 && dstReg < INDEX_BX_SI)
     {
         if (ll.testFlags(I))
             pstate->setState( dstReg, (int16_t)ll.src.op());
@@ -653,7 +653,7 @@ static void process_MOV(LLInst & ll, STATE * pstate)
             if (psym && ((psym->flg & SEG_IMMED) || psym->duVal.val))
                 pstate->setState( dstReg, LH(&prog.Image[psym->label]));
         }
-        else if (srcReg < INDEXBASE && pstate->f[srcReg])  /* reg */
+        else if (srcReg < INDEX_BX_SI && pstate->f[srcReg])  /* reg */
         {
             pstate->setState( dstReg, pstate->r[srcReg]);
 
@@ -682,12 +682,12 @@ static void process_MOV(LLInst & ll, STATE * pstate)
                 {
                     prog.Image[psym->label] = (uint8_t)prog.Image[psym2->label];
                     if(psym->size>1)
-                        prog.Image[psym->label+1] = (uint8_t)(prog.Image[psym2->label+1] >> 8);
+                        prog.Image[psym->label+1] = prog.Image[psym2->label+1];//(uint8_t)(prog.Image[psym2->label+1] >> 8);
                     psym->duVal.setFlags(eDuVal::DEF);
                     psym2->duVal.setFlags(eDuVal::USE);
                 }
             }
-            else if (srcReg < INDEXBASE && pstate->f[srcReg])  /* reg */
+            else if (srcReg < INDEX_BX_SI && pstate->f[srcReg])  /* reg */
             {
                 prog.Image[psym->label] = (uint8_t)pstate->r[srcReg];
                 if(psym->size>1)
@@ -917,9 +917,9 @@ static void use (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int
     LLOperand * pm   = (d == SRC)? &pIcode.ll()->src: &pIcode.ll()->dst;
     SYM *  psym;
 
-    if (pm->regi == 0 || pm->regi >= INDEXBASE)
+    if (pm->regi == 0 || pm->regi >= INDEX_BX_SI)
     {
-        if (pm->regi == INDEXBASE + 6)      /* indexed on bp */
+        if (pm->regi == INDEX_BP)      /* indexed on bp */
         {
             if (pm->off >= 2)
                 updateFrameOff (&pProc->args, pm->off, size, eDuVal::USE);
@@ -927,13 +927,13 @@ static void use (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int
                 pProc->localId.newByteWordStk (TYPE_WORD_SIGN, pm->off, 0);
         }
 
-        else if (pm->regi == INDEXBASE + 2 || pm->regi == INDEXBASE + 3)
+        else if (pm->regi == INDEX_BP_SI || pm->regi == INDEX_BP_DI)
             pProc->localId.newByteWordStk (TYPE_WORD_SIGN, pm->off,
-                                           (uint8_t)((pm->regi == INDEXBASE + 2) ? rSI : rDI));
+                                           (uint8_t)((pm->regi == INDEX_BP_SI) ? rSI : rDI));
 
-        else if ((pm->regi >= INDEXBASE + 4) && (pm->regi <= INDEXBASE + 7))
+        else if ((pm->regi >= INDEX_SI) && (pm->regi <= INDEX_BX))
         {
-            if ((pm->seg == rDS) && (pm->regi == INDEXBASE + 7))    /* bx */
+            if ((pm->seg == rDS) && (pm->regi == INDEX_BX))    /* bx */
             {
                 if (pm->off > 0)    /* global indexed variable */
                     pProc->localId.newIntIdx(pm->segValue, pm->off, rBX,ix, TYPE_WORD_SIGN);
@@ -964,9 +964,9 @@ static void def (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int
     LLOperand *pm   = (d == SRC)? &pIcode.ll()->src: &pIcode.ll()->dst;
     SYM *  psym;
 
-    if (pm->regi == 0 || pm->regi >= INDEXBASE)
+    if (pm->regi == 0 || pm->regi >= INDEX_BX_SI)
     {
-        if (pm->regi == INDEXBASE + 6)      /* indexed on bp */
+        if (pm->regi == INDEX_BP)      /* indexed on bp */
         {
             if (pm->off >= 2)
                 updateFrameOff (&pProc->args, pm->off, size, eDEF);
@@ -974,15 +974,15 @@ static void def (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int
                 pProc->localId.newByteWordStk (TYPE_WORD_SIGN, pm->off, 0);
         }
 
-        else if (pm->regi == INDEXBASE + 2 || pm->regi == INDEXBASE + 3)
+        else if (pm->regi == INDEX_BP_SI || pm->regi == INDEX_BP_DI)
         {
             pProc->localId.newByteWordStk(TYPE_WORD_SIGN, pm->off,
-                                          (uint8_t)((pm->regi == INDEXBASE + 2) ? rSI : rDI));
+                                          (uint8_t)((pm->regi == INDEX_BP_SI) ? rSI : rDI));
         }
 
-        else if ((pm->regi >= INDEXBASE + 4) && (pm->regi <= INDEXBASE + 7))
+        else if ((pm->regi >= INDEX_SI) && (pm->regi <= INDEX_BX))
         {
-            if ((pm->seg == rDS) && (pm->regi == INDEXBASE + 7))    /* bx */
+            if ((pm->seg == rDS) && (pm->regi == INDEX_BX))    /* bx */
             {
                 if (pm->off > 0)        /* global var */
                     pProc->localId.newIntIdx(pm->segValue, pm->off, rBX,ix, TYPE_WORD_SIGN);
@@ -1017,7 +1017,7 @@ static void use_def(opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, i
 
     use (d, pIcode, pProc, pstate, cb, ix);
 
-    if (pm->regi < INDEXBASE)                   /* register */
+    if (pm->regi < INDEX_BX_SI)                   /* register */
     {
         pIcode.du.def |= duReg[pm->regi];
         pIcode.du1.numRegsDef++;
@@ -1043,6 +1043,7 @@ 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:

+ 0 - 5
src/perfhlib.cpp

@@ -47,11 +47,6 @@ PatternHasher::init(int _NumEntry, int _EntryLen, int _SetSize, char _SetMin,
     g = new short [NumVert + 1];
 //    visited = new bool [NumVert + 1];
     return;
-
-BadAlloc:
-    printf("Could not allocate memory\n");
-    cleanup();
-    exit(1);
 }
 
 void PatternHasher::cleanup(void)

+ 11 - 9
src/procs.cpp

@@ -11,22 +11,23 @@
 
 
 /* Static indentation buffer */
-#define indSize     61          /* size of indentation buffer; max 20 */
+static constexpr int indSize=81;          /* size of indentation buffer; max 20 */
 static char indentBuf[indSize] =
-        "                                                            ";
-
-static char *indent (int indLevel) // Indentation according to the depth of the statement
+        "                                                                                ";
+// not static, used in icode.cpp at emitGotoLabel
+const char *indentStr(int indLevel) // Indentation according to the depth of the statement
 {
-    return (&indentBuf[indSize-(indLevel*3)-1]);
+    return (&indentBuf[indSize-(indLevel*4)-1]);
 }
 
 
 /* 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;
-    int i;
+
 
     /* Check if procedure already exists */
     auto res=std::find_if(outEdges.begin(),outEdges.end(),[newProc](CALL_GRAPH *e) {return e->proc==newProc;});
@@ -73,7 +74,7 @@ void CALL_GRAPH::writeNodeCallGraph(int indIdx)
 {
     int i;
 
-    printf ("%s%s\n", indent(indIdx), proc->name.c_str());
+    printf ("%s%s\n", indentStr(indIdx), proc->name.c_str());
     for (i = 0; i < outEdges.size(); i++)
         outEdges[i]->writeNodeCallGraph (indIdx + 1);
 }
@@ -108,7 +109,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;
@@ -336,7 +337,8 @@ void STKFRAME::adjustForArgType(int numArg_, hlType actType_)
             return;
     }
     /* If formal argument does not exist, do not create new ones, just
-         * ignore actual argument */
+     * ignore actual argument
+     */
     else
         return;
 

+ 3 - 3
src/proplong.cpp

@@ -169,7 +169,7 @@ static int longJCond23 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode, int arc,
 */
 static int longJCond22 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode,iICODE pEnd)
 {
-    int j;
+
     BB * pbb, * obb1, * tbb;
     if(distance(pIcode,pEnd)<4)
         return false;
@@ -229,7 +229,7 @@ static int longJCond22 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode,iICODE pEn
  *            pProc : ptr to current procedure's record.        */
 void Function::propLongStk (int i, const ID &pLocId)
 {
-    int off, arc;
+    int arc;
     Assignment asgn;
     //COND_EXPR *lhs, *rhs;     /* Pointers to left and right hand expression */
     iICODE next1, pEnd;
@@ -389,7 +389,7 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be
         if(next1==pEnd)
             break;
         LLOperand * pmH,* pmL;            /* Pointers to dst LOW_LEVEL icodes */
-        int off,arc;
+        int arc;
 
         if ((pIcode->type == HIGH_LEVEL) || (pIcode->invalid == TRUE))
             continue;

+ 1 - 1
src/reducible.cpp

@@ -100,7 +100,7 @@ static void appendNodeInt (queue &pqH, BB *node, interval *pI)
 void derSeq_Entry::findIntervals (Function *c)
 {
     interval *pI,        /* Interval being processed         */
-            *J;         /* ^ last interval in derivedGi->Ii */
+            *J=0;         /* ^ last interval in derivedGi->Ii */
     BB *h,           /* Node being processed         */
             *header,          /* Current interval's header node   */
             *succ;            /* Successor basic block        */

+ 6 - 6
src/scanner.cpp

@@ -422,8 +422,8 @@ static void setAddress(int i, boolT fdst, uint16_t seg, int16_t reg, uint16_t of
     }
     else
     {	/* no override, check indexed register */
-        if ((reg >= INDEXBASE) && (reg == INDEXBASE + 2 ||
-                                   reg == INDEXBASE + 3 || reg == INDEXBASE + 6))
+        if ((reg >= INDEX_BX_SI) && (reg == INDEX_BP_SI ||
+                                   reg == INDEX_BP_DI || reg == INDEX_BP))
         {
             pm->seg = rSS;		/* indexed on bp */
         }
@@ -435,7 +435,7 @@ static void setAddress(int i, boolT fdst, uint16_t seg, int16_t reg, uint16_t of
 
     pm->regi = (eReg)reg;
     pm->off = (int16_t)off;
-    if (reg && reg < INDEXBASE && (stateTable[i].flg & B))
+    if (reg && reg < INDEX_BX_SI && (stateTable[i].flg & B))
     {
         pm->regi = subRegL(pm->regi);
     }
@@ -462,15 +462,15 @@ static void rm(int i)
                 pIcode->ll()->setFlags(WORD_OFF);
             }
             else
-                setAddress(i, TRUE, SegPrefix, rm + INDEXBASE, 0);
+                setAddress(i, TRUE, SegPrefix, rm + INDEX_BX_SI, 0);
             break;
 
         case 1:		/* 1 uint8_t disp */
-            setAddress(i, TRUE, SegPrefix, rm+INDEXBASE, (uint16_t)signex(*pInst++));
+            setAddress(i, TRUE, SegPrefix, rm+INDEX_BX_SI, (uint16_t)signex(*pInst++));
             break;
 
         case 2:		/* 2 uint8_t disp */
-            setAddress(i, TRUE, SegPrefix, rm + INDEXBASE, getWord());
+            setAddress(i, TRUE, SegPrefix, rm + INDEX_BX_SI, getWord());
             pIcode->ll()->setFlags(WORD_OFF);
             break;
 

+ 1 - 1
src/symtab.cpp

@@ -55,7 +55,7 @@ struct TABLEINFO_TYPE
     {
         symTab=valTab=0;
     }
-    void    deleteVal(uint32_t symOff, Function *symProc, boolT bSymToo);
+    //void deleteVal(uint32_t symOff, Function *symProc, boolT bSymToo);
     void create(tableType type);
     void destroy();
 private: