Linting 1

This commit is contained in:
Artur K 2012-03-06 23:58:16 +01:00
parent ddd501de1f
commit a85d460fe6
7 changed files with 168 additions and 87 deletions

View File

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

View File

@ -83,7 +83,7 @@ public:
static COND_EXPR *idFunc(Function *pproc, STKFRAME *args); static COND_EXPR *idFunc(Function *pproc, STKFRAME *args);
static COND_EXPR *idID(const ID *retVal, LOCAL_ID *locsym, iICODE ix_); 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 * 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 insertSubTreeLongReg(COND_EXPR *exp, COND_EXPR **tree, int longIdx);
static bool insertSubTreeReg(COND_EXPR *&tree, COND_EXPR *_expr, uint8_t regi, LOCAL_ID *locsym); static bool insertSubTreeReg(COND_EXPR *&tree, COND_EXPR *_expr, uint8_t regi, LOCAL_ID *locsym);
public: public:
@ -106,21 +106,27 @@ public:
public: public:
virtual COND_EXPR *inverse(); // return new COND_EXPR that is invarse of this 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 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 struct BinaryOperator : public COND_EXPR
{ {
condOp m_op; condOp m_op;
COND_EXPR *m_lhs; COND_EXPR *m_lhs;
COND_EXPR *m_rhs; COND_EXPR *m_rhs;
BinaryOperator() BinaryOperator(condOp o)
{ {
m_op = DUMMY; m_op = o;
m_lhs=m_rhs=nullptr; 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); static BinaryOperator *CreateAdd(COND_EXPR *l,COND_EXPR *r);
virtual COND_EXPR *inverse(); virtual COND_EXPR *inverse();
virtual COND_EXPR *clone(); virtual COND_EXPR *clone();
virtual bool xClear(iICODE f, iICODE t, iICODE lastBBinst, Function *pproc); 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() COND_EXPR *lhs()
{ {
assert(type==BOOLEAN_OP); assert(type==BOOLEAN_OP);
@ -142,6 +148,8 @@ struct BinaryOperator : public COND_EXPR
return m_rhs; return m_rhs;
} }
condOp op() const { return m_op;} 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 struct UnaryOperator : public COND_EXPR
{ {

View File

@ -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", "", "char", "unsigned char", "int", "unsigned int",
"long", "unsigned long", "record", "int *", "char *", "long", "unsigned long", "record", "int *", "char *",
"", "float", "double" "", "float", "double"

View File

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

View File

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

View File

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

View File

@ -16,7 +16,7 @@
#include "arith_idioms.h" #include "arith_idioms.h"
#include "dcc.h" #include "dcc.h"
#include <llvm/Support/PatternMatch.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 * 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;} 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) while (pIcode != pEnd)
{ {
switch (pIcode->ll()->getOpcode()) switch (pIcode->ll()->getOpcode())