Bladeren bron

Linting 1

Artur K 12 jaren geleden
bovenliggende
commit
a85d460fe6
7 gewijzigde bestanden met toevoegingen van 167 en 86 verwijderingen
  1. 11 13
      include/Enums.h
  2. 11 3
      include/ast.h
  3. 1 1
      include/locident.h
  4. 126 52
      src/ast.cpp
  5. 4 4
      src/dataflow.cpp
  6. 12 11
      src/dcc.cpp
  7. 2 2
      src/idioms.cpp

+ 11 - 13
include/Enums.h

@@ -82,6 +82,7 @@ enum opLoc
     LHS_OP						/* Left-hand side operand (for HIGH_LEVEL) */
 };
 /* LOW_LEVEL icode flags */
+#define NO_SRC_B    0xF7FFFF    /* Masks off SRC_B */
 enum eLLFlags
 {
 
@@ -101,27 +102,24 @@ enum eLLFlags
     NO_CODE     =0x0002000,    /* Hole in Icode array */
     SYM_USE     =0x0004000,    /* Instruction uses a symbol */
     SYM_DEF     =0x0008000,    /* Instruction defines a symbol */
-
     NO_SRC      =0x0010000,    /* Opcode takes no source */
     NO_OPS      =0x0020000,    /* Opcode takes no operands */
     IM_OPS      =0x0040000,    /* Opcode takes implicit operands */
     SRC_B       =0x0080000,    /* Source operand is uint8_t (dest is uint16_t) */
-#define NO_SRC_B    0xF7FFFF    /* Masks off SRC_B */
-    HLL_LABEL   =0x0100000,    /* Icode has a high level language label */
-    IM_DST      =0x0200000,	/* Implicit DST for opcode (SIGNEX) */
-    IM_SRC      =0x0400000,	/* Implicit SRC for opcode (dx:ax)	*/
-    IM_TMP_DST  =0x0800000,	/* Implicit rTMP DST for opcode (DIV/IDIV) */
-
-    JMP_ICODE   =0x1000000,    /* Jmp dest immed.op converted to icode index */
-    JX_LOOP     =0x2000000,	/* Cond jump is part of loop conditional exp */
-    REST_STK    =0x4000000	/* Stack needs to be restored after CALL */
+    HLL_LABEL   =0x0100000, /* Icode has a high level language label */
+    IM_DST      =0x0200000, /* Implicit DST for opcode (SIGNEX) */
+    IM_SRC      =0x0400000, /* Implicit SRC for opcode (dx:ax)	*/
+    IM_TMP_DST  =0x0800000, /* Implicit rTMP DST for opcode (DIV/IDIV) */
+    JMP_ICODE   =0x1000000, /* Jmp dest immed.op converted to icode index */
+    JX_LOOP     =0x2000000, /* Cond jump is part of loop conditional exp */
+    REST_STK    =0x4000000  /* Stack needs to be restored after CALL */
 };
 /* Types of icodes */
 enum icodeType
 {
-    NOT_SCANNED = 0,    /* not even scanned yet */
-    LOW_LEVEL,          /* low-level icode  */
-    HIGH_LEVEL          /* high-level icode */
+    NOT_SCANNED = 0,    // not even scanned yet
+    LOW_LEVEL,          // low-level icode
+    HIGH_LEVEL          // high-level icode
 };
 
 

+ 11 - 3
include/ast.h

@@ -83,7 +83,7 @@ public:
     static COND_EXPR *idFunc(Function *pproc, STKFRAME *args);
     static COND_EXPR *idID(const ID *retVal, LOCAL_ID *locsym, iICODE ix_);
     static COND_EXPR *  id(const LLInst &ll_insn, opLoc sd, Function *pProc, iICODE ix_, ICODE &duIcode, operDu du);
-    static COND_EXPR *boolOp(COND_EXPR *lhs, COND_EXPR *rhs, condOp op);
+    static COND_EXPR *boolOp(COND_EXPR *_lhs, COND_EXPR *_rhs, condOp _op);
     static bool         insertSubTreeLongReg(COND_EXPR *exp, COND_EXPR **tree, int longIdx);
     static bool         insertSubTreeReg(COND_EXPR *&tree, COND_EXPR *_expr, uint8_t regi, LOCAL_ID *locsym);
 public:
@@ -106,21 +106,27 @@ public:
 public:
     virtual COND_EXPR *inverse(); // return new COND_EXPR that is invarse of this
     virtual bool xClear(iICODE f, iICODE t, iICODE lastBBinst, Function *pproc);
+    virtual COND_EXPR *insertSubTreeReg(COND_EXPR *_expr, uint8_t regi, LOCAL_ID *locsym);
+    virtual COND_EXPR *insertSubTreeLongReg(COND_EXPR *_expr, int longIdx);
 };
 struct BinaryOperator : public COND_EXPR
 {
     condOp      m_op;
     COND_EXPR *m_lhs;
     COND_EXPR *m_rhs;
-    BinaryOperator()
+    BinaryOperator(condOp o)
     {
-        m_op = DUMMY;
+        m_op = o;
         m_lhs=m_rhs=nullptr;
     }
+    static BinaryOperator *Create(condOp o,COND_EXPR *l,COND_EXPR *r);
     static BinaryOperator *CreateAdd(COND_EXPR *l,COND_EXPR *r);
     virtual COND_EXPR *inverse();
     virtual COND_EXPR *clone();
     virtual bool xClear(iICODE f, iICODE t, iICODE lastBBinst, Function *pproc);
+    virtual COND_EXPR *insertSubTreeReg(COND_EXPR *_expr, uint8_t regi, LOCAL_ID *locsym);
+    virtual COND_EXPR *insertSubTreeLongReg(COND_EXPR *_expr, int longIdx);
+
     COND_EXPR *lhs()
     {
         assert(type==BOOLEAN_OP);
@@ -142,6 +148,8 @@ struct BinaryOperator : public COND_EXPR
         return m_rhs;
     }
     condOp op() const { return m_op;}
+    /* Changes the boolean conditional operator at the root of this expression */
+    void op(condOp o) { m_op=o;}
 };
 struct UnaryOperator : public COND_EXPR
 {

+ 1 - 1
include/locident.h

@@ -27,7 +27,7 @@ struct IDX_ARRAY : public std::vector<iICODE>
     }
 };
 
-static constexpr const char *hlTypes[13] = {
+static constexpr const char * hlTypes[13] = {
     "", "char", "unsigned char", "int", "unsigned int",
     "long", "unsigned long", "record", "int *", "char *",
     "", "float", "double"

+ 126 - 52
src/ast.cpp

@@ -5,7 +5,7 @@
  * (C) Cristina Cifuentes
  */
 #include <stdint.h>
-#include <malloc.h>		/* For free() */
+//#include <malloc.h>		// For free()
 #include <string>
 #include <sstream>
 #include <iostream>
@@ -13,16 +13,16 @@
 #include "types.h"
 #include "dcc.h"
 using namespace std;
-/* Index registers **** temp solution */
-static const char *idxReg[8] = {"bx+si", "bx+di", "bp+si", "bp+di",
+// 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 *condOpSym[] = { " <= ", " < ", " == ", " != ", " > ", " >= ",
+// Conditional operator symbols in C.  Index by condOp enumeration type
+static const char * const condOpSym[] = { " <= ", " < ", " == ", " != ", " > ", " >= ",
                                    " & ", " | ", " ^ ", " ~ ",
                                    " + ", " - ", " * ", " / ",
                                    " >> ", " << ", " % ", " && ", " || " };
 
-#define EXP_SIZE 200		/* Size of the expression buffer */
+//#define EXP_SIZE 200		/* Size of the expression buffer */
 
 /* Local expression stack */
 //typedef struct _EXP_STK {
@@ -31,7 +31,7 @@ static const char *condOpSym[] = { " <= ", " < ", " == ", " != ", " > ", " >= ",
 //} EXP_STK; - for local expression stack
 
 /* Returns the integer i in C hexadecimal format */
-static char *hexStr (uint16_t i)
+static const char *hexStr (uint16_t i)
 {
     static char buf[10];
     sprintf (buf, "%s%x", (i > 9) ? "0x" : "", i);
@@ -88,23 +88,21 @@ void ICODE::copyDU(const ICODE &duIcode, operDu _du, operDu duDu)
         assert(false);
         break;
     }
-    printf("%s end: %x,%x\n",__FUNCTION__,du.def,du.use);
 }
 
 
 /* Creates a conditional boolean expression and returns it */
-COND_EXPR *COND_EXPR::boolOp(COND_EXPR *lhs, COND_EXPR *rhs, condOp op)
+COND_EXPR *COND_EXPR::boolOp(COND_EXPR *_lhs, COND_EXPR *_rhs, condOp _op)
 {
     COND_EXPR *newExp;
 
     newExp = new COND_EXPR(BOOLEAN_OP);
-    newExp->boolExpr.op = op;
-    newExp->boolExpr.lhs = lhs;
-    newExp->boolExpr.rhs = rhs;
+    newExp->boolExpr.op = _op;
+    newExp->boolExpr.lhs = _lhs;
+    newExp->boolExpr.rhs = _rhs;
     return (newExp);
 }
 
-
 /* Returns a unary conditional expression node.  This procedure should
  * only be used with the following conditional node types: NEGATION,
  * ADDRESSOF, DEREFERENCE, POST_INC, POST_DEC, PRE_INC, PRE_DEC	*/
@@ -829,80 +827,158 @@ void COND_EXPR::changeBoolOp (condOp newOp)
  * register regi */
 bool COND_EXPR::insertSubTreeReg (COND_EXPR *&tree, COND_EXPR *_expr, uint8_t regi,LOCAL_ID *locsym)
 {
-    HlTypeSupport *set_val;
-    uint8_t treeReg;
-
     if (tree == NULL)
         return false;
+    COND_EXPR *temp=tree->insertSubTreeReg(_expr,regi,locsym);
+    if(nullptr!=temp)
+    {
+        tree=temp;
+        return true;
+    }
+    return false;
+}
+COND_EXPR *COND_EXPR::insertSubTreeReg (COND_EXPR *_expr, uint8_t regi,LOCAL_ID *locsym)
+{
+    HlTypeSupport *set_val;
+    uint8_t treeReg;
+    COND_EXPR *temp;
 
-    switch (tree->type) {
+    switch (type) {
     case IDENTIFIER:
-        if (tree->expr.ident.idType == REGISTER)
+        if (expr.ident.idType == REGISTER)
         {
-            treeReg = locsym->id_arr[tree->expr.ident.idNode.regiIdx].id.regi;
+            treeReg = locsym->id_arr[expr.ident.idNode.regiIdx].id.regi;
             if (treeReg == regi)                        /* uint16_t reg */
             {
-                tree = _expr;
-                return true;
+                return _expr;
             }
             else if ((regi >= rAX) && (regi <= rBX))    /* uint16_t/uint8_t reg */
             {
                 if ((treeReg == (regi + rAL-1)) || (treeReg == (regi + rAH-1)))
                 {
-                    tree = _expr;
-                    return true;
+                    return _expr;
                 }
             }
         }
         return FALSE;
 
     case BOOLEAN_OP:
-        if (insertSubTreeReg (tree->boolExpr.lhs, _expr, regi, locsym))
-            return true;
-        if (insertSubTreeReg (tree->boolExpr.rhs, _expr, regi, locsym))
-            return true;
-        return false;
+        temp = lhs()->insertSubTreeReg( _expr, regi, locsym);
+        if (nullptr!=temp)
+        {
+            boolExpr.lhs = temp;
+            return this;
+        }
+        temp = rhs()->insertSubTreeReg( _expr, regi, locsym);
+        if (nullptr!=temp)
+        {
+            boolExpr.rhs = temp;
+            return this;
+        }
+        return nullptr;
 
     case NEGATION:
     case ADDRESSOF:
     case DEREFERENCE:
-        if (insertSubTreeReg(tree->expr.unaryExp, _expr, regi, locsym))
-            return TRUE;
-        return FALSE;
+        temp = expr.unaryExp->insertSubTreeReg( _expr, regi, locsym);
+        if (nullptr!=temp)
+        {
+            expr.unaryExp = temp;
+            return this;
+        }
+        return nullptr;
+}
+    return nullptr;
+}
+COND_EXPR *BinaryOperator::insertSubTreeReg(COND_EXPR *_expr, uint8_t regi, LOCAL_ID *locsym)
+{
+    COND_EXPR *r;
+    r=m_lhs->insertSubTreeReg(_expr,regi,locsym);
+    if(r)
+    {
+        m_lhs = r;
+        return this;
     }
-    return FALSE;
+    r=m_rhs->insertSubTreeReg(_expr,regi,locsym);
+    if(r)
+    {
+        m_rhs = r;
+        return this;
+    }
+    return nullptr;
 }
 
-
 /* Inserts the expression exp into the tree at the location specified by the
  * long register index longIdx*/
 bool COND_EXPR::insertSubTreeLongReg(COND_EXPR *_expr, COND_EXPR **tree, int longIdx)
 {
-    switch ((*tree)->type)
+    if (tree == NULL)
+        return false;
+    COND_EXPR *temp=(*tree)->insertSubTreeLongReg(_expr,longIdx);
+    if(nullptr!=temp)
+    {
+        *tree=temp;
+        return true;
+    }
+    return false;
+}
+COND_EXPR *COND_EXPR::insertSubTreeLongReg(COND_EXPR *_expr, int longIdx)
+{
+        COND_EXPR *temp;
+    switch (type)
     {
     case IDENTIFIER:
-        if ((*tree)->expr.ident.idNode.longIdx == longIdx)
+        if (expr.ident.idNode.longIdx == longIdx)
         {
-            *tree = _expr;
-            return true;
+            return _expr;
         }
-        return false;
+        return nullptr;
 
     case BOOLEAN_OP:
-        if (insertSubTreeLongReg (_expr, &(*tree)->boolExpr.lhs, longIdx))
-            return true;
-        if (insertSubTreeLongReg (_expr, &(*tree)->boolExpr.rhs, longIdx))
-            return true;
-        return false;
+        temp = lhs()->insertSubTreeLongReg( _expr,longIdx);
+        if (nullptr!=temp)
+        {
+            boolExpr.lhs = temp;
+            return this;
+        }
+        temp = rhs()->insertSubTreeLongReg( _expr,longIdx);
+        if (nullptr!=temp)
+        {
+            boolExpr.rhs = temp;
+            return this;
+        }
+        return nullptr;
 
     case NEGATION:
     case ADDRESSOF:
     case DEREFERENCE:
-        if (insertSubTreeLongReg (_expr, &(*tree)->expr.unaryExp, longIdx))
-            return true;
-        return false;
+        COND_EXPR *temp = expr.unaryExp->insertSubTreeLongReg(_expr,longIdx);
+        if (nullptr!=temp)
+        {
+            expr.unaryExp = temp;
+            return this;
     }
-    return false;
+        return nullptr;
+    }
+    return nullptr;
+}
+COND_EXPR *BinaryOperator::insertSubTreeLongReg(COND_EXPR *_expr, int longIdx)
+{
+    COND_EXPR *r;
+    r=m_lhs->insertSubTreeLongReg(_expr,longIdx);
+    if(r)
+    {
+        m_lhs = r;
+        return this;
+    }
+    r=m_rhs->insertSubTreeLongReg(_expr,longIdx);
+    if(r)
+    {
+        m_rhs = r;
+        return this;
+    }
+    return nullptr;
+
 }
 
 
@@ -924,7 +1000,7 @@ void COND_EXPR::release()
     delete (this);
 }
 
-
+//
 COND_EXPR *BinaryOperator::inverse()
 {
     static condOp invCondOp[] = {GREATER, GREATER_EQUAL, NOT_EQUAL, EQUAL,
@@ -957,10 +1033,8 @@ COND_EXPR *BinaryOperator::inverse()
  * node.  Returns the copy. */
 COND_EXPR *BinaryOperator::clone()
 {
-    BinaryOperator* newExp=0;        /* Expression node copy */
-    newExp = new BinaryOperator();
-    newExp->m_op  = m_op;
+    BinaryOperator* newExp=new BinaryOperator(m_op);        /* Expression node copy */
     newExp->m_lhs = m_lhs->clone();
     newExp->m_rhs = m_rhs->clone();
-
+    return newExp;
 }

+ 4 - 4
src/dataflow.cpp

@@ -6,14 +6,14 @@
  ****************************************************************************/
 
 #include "dcc.h"
-#include <boost/range.hpp>
-#include <boost/range/adaptors.hpp>
-#include <boost/range/algorithm.hpp>
+//#include <boost/range.hpp>
+//#include <boost/range/adaptors.hpp>
+//#include <boost/range/algorithm.hpp>
 #include <string.h>
 #include <iostream>
 #include <iomanip>
 #include <stdio.h>
-using namespace boost;
+//using namespace boost;
 struct ExpStack
 {
     typedef std::list<COND_EXPR *> EXP_STK;

+ 12 - 11
src/dcc.cpp

@@ -20,9 +20,8 @@ FunctionListType pProcList;
 CALL_GRAPH	*callGraph;		/* Call graph of the program			  */
 
 static char *initargs(int argc, char *argv[]);
-static void displayTotalStats();
+static void displayTotalStats(void);
 #include <llvm/Support/raw_os_ostream.h>
-#include <llvm/Support/raw_ostream.h>
 
 /****************************************************************************
  * main
@@ -83,28 +82,29 @@ static char *initargs(int argc, char *argv[])
             {
                 case 'a':       /* Print assembler listing */
                     if (*(pc+1) == '2')
-                        option.asm2 = TRUE;
+                        option.asm2 = true;
                     else
-                        option.asm1 = TRUE;
+                        option.asm1 = true;
                     if (*(pc+1) == '1' || *(pc+1) == '2')
                         pc++;
                     break;
                 case 'c':
-                    option.Calls = TRUE;
+                    option.Calls = true;
                     break;
                 case 'i':
-                    option.Interact = TRUE;
+                    option.Interact = true;
                     break;
                 case 'm':       /* Print memory map */
-                    option.Map = TRUE;
+                    option.Map = true;
                     break;
                 case 's':       /* Print Stats */
-                    option.Stats = TRUE;
+                    option.Stats = true;
                     break;
                 case 'V':       /* Very verbose => verbose */
-                    option.VeryVerbose = TRUE;
-                case 'v':       /* Make everything verbose */
-                    option.verbose = TRUE;
+                    option.VeryVerbose = true;
+                //lint -fallthrough
+                case 'v':
+                    option.verbose = true; /* Make everything verbose */
                     break;
                 case 'o':       /* assembler output file */
                     if (*(pc+1)) {
@@ -115,6 +115,7 @@ static char *initargs(int argc, char *argv[])
                         asm1_name = asm2_name = *++argv;
                         goto NextArg;
                     }
+                //lint -fallthrough
                 default:
                     fatalError(INVALID_ARG, *pc);
                     return *argv;

+ 2 - 2
src/idioms.cpp

@@ -16,7 +16,7 @@
 #include "arith_idioms.h"
 #include "dcc.h"
 #include <llvm/Support/PatternMatch.h>
-#include <boost/iterator/filter_iterator.hpp>
+//#include <boost/iterator/filter_iterator.hpp>
 /*****************************************************************************
  * JmpInst - Returns TRUE if opcode is a conditional or unconditional jump
  ****************************************************************************/
@@ -76,7 +76,7 @@ void Function::findIdioms()
     {
         bool operator()(ICODE &z) { return not z.invalid;}
     };
-    typedef boost::filter_iterator<is_valid,iICODE> ifICODE;
+    //typedef boost::filter_iterator<is_valid,iICODE> ifICODE;
     while (pIcode != pEnd)
     {
         switch (pIcode->ll()->getOpcode())