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

@@ -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;
}
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;
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -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())