From a85d460fe6b6eee2dee86da354309f3e4c0747e9 Mon Sep 17 00:00:00 2001 From: Artur K Date: Tue, 6 Mar 2012 23:58:16 +0100 Subject: [PATCH] Linting 1 --- include/Enums.h | 24 +++--- include/ast.h | 14 +++- include/locident.h | 2 +- src/ast.cpp | 180 ++++++++++++++++++++++++++++++++------------- src/dataflow.cpp | 8 +- src/dcc.cpp | 23 +++--- src/idioms.cpp | 4 +- 7 files changed, 168 insertions(+), 87 deletions(-) diff --git a/include/Enums.h b/include/Enums.h index e323f13..117e8ee 100644 --- a/include/Enums.h +++ b/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 }; diff --git a/include/ast.h b/include/ast.h index 8e9edf3..918180e 100644 --- a/include/ast.h +++ b/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 { diff --git a/include/locident.h b/include/locident.h index 8d96be6..778f371 100644 --- a/include/locident.h +++ b/include/locident.h @@ -27,7 +27,7 @@ struct IDX_ARRAY : public std::vector } }; -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" diff --git a/src/ast.cpp b/src/ast.cpp index 1eef40d..b238278 100644 --- a/src/ast.cpp +++ b/src/ast.cpp @@ -5,7 +5,7 @@ * (C) Cristina Cifuentes */ #include -#include /* For free() */ +//#include // For free() #include #include #include @@ -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; - } - 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; + } + 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; } diff --git a/src/dataflow.cpp b/src/dataflow.cpp index 7f8df02..e6386f6 100644 --- a/src/dataflow.cpp +++ b/src/dataflow.cpp @@ -6,14 +6,14 @@ ****************************************************************************/ #include "dcc.h" -#include -#include -#include +//#include +//#include +//#include #include #include #include #include -using namespace boost; +//using namespace boost; struct ExpStack { typedef std::list EXP_STK; diff --git a/src/dcc.cpp b/src/dcc.cpp index 920a733..69f16ac 100644 --- a/src/dcc.cpp +++ b/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 -#include /**************************************************************************** * 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; diff --git a/src/idioms.cpp b/src/idioms.cpp index 582bd61..0d75b91 100644 --- a/src/idioms.cpp +++ b/src/idioms.cpp @@ -16,7 +16,7 @@ #include "arith_idioms.h" #include "dcc.h" #include -#include +//#include /***************************************************************************** * 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 ifICODE; + //typedef boost::filter_iterator ifICODE; while (pIcode != pEnd) { switch (pIcode->ll()->getOpcode())