Removed 2 lingering TRUE/FALSE references

Removed 2 calls to cCode.appendDecl in walkCondExpr, replaced with
ostringstream usage + 1 call to cCode.appendDecl
Created Type helper class = TypeContainer
This commit is contained in:
Artur K 2012-03-13 00:35:32 +01:00
parent 14b06c252e
commit fe250a822d
4 changed files with 57 additions and 31 deletions

View File

@ -11,7 +11,7 @@
#include <list>
#include <set>
#include <algorithm>
#include "types.h"
#include "Enums.h"
#include "machine_x86.h"
@ -28,12 +28,6 @@ struct IDX_ARRAY : public std::vector<iICODE>
}
};
static constexpr const char * hlTypes[13] = {
"", "char", "unsigned char", "int", "unsigned int",
"long", "unsigned long", "record", "int *", "char *",
"", "float", "double"
};
typedef enum
{
STK_FRAME, /* For stack vars */
@ -97,14 +91,13 @@ struct ID
bool isSigned() const { return (type==TYPE_BYTE_SIGN)||(type==TYPE_WORD_SIGN)||(type==TYPE_LONG_SIGN);}
uint16_t typeBitsize() const
{
switch(type)
{
case TYPE_WORD_SIGN: case TYPE_WORD_UNSIGN:
return 16;
case TYPE_BYTE_SIGN: case TYPE_BYTE_UNSIGN:
return 8;
}
return ~0;
return TypeContainer::typeSize(type)*8;
}
void setLocalName(int i)
{
// char buf[32];
//sprintf (buf, "loc%ld", i);
//name=buf;
}
};

View File

@ -3,9 +3,10 @@
* (C) Cristina Cifuentes, Mike van Emmerik
****************************************************************************/
#pragma once
#include <cassert>
#include <stdint.h>
#include "Enums.h"
/**** Common definitions and macros ****/
typedef unsigned int uint32_t; /* 32 bits */
#define MAX 0x7FFFFFFF
/* Type definitions used in the program */
@ -14,14 +15,6 @@ typedef unsigned short word;/* 16 bits */
typedef short int16; /* 16 bits */
typedef unsigned char boolT; /* 8 bits */
#if defined(__MSDOS__) | defined(WIN32)
#define unlink _unlink // Compiler is picky about non Ansi names
#endif
#define TRUE 1
#define FALSE 0
#define SYNTHESIZED_MIN 0x100000 /* Synthesized labs use bits 21..32 */
/* These are for C library signature detection */
@ -73,3 +66,41 @@ struct eDuVal
}
bool isUSE_VAL() {return use&&val;} /* Use and Val */
};
static constexpr const char * hlTypes[13] = {
"", "char", "unsigned char", "int", "unsigned int",
"long", "unsigned long", "record", "int *", "char *",
"", "float", "double"
};
struct TypeContainer
{
hlType m_type;
size_t m_size;
TypeContainer(hlType t,size_t sz) : m_type(t),m_size(sz)
{
}
static size_t typeSize(hlType t)
{
switch(t)
{
case TYPE_WORD_SIGN: case TYPE_WORD_UNSIGN:
return 2;
case TYPE_BYTE_SIGN: case TYPE_BYTE_UNSIGN:
return 1;
}
return 0;
}
static hlType defaultTypeForSize(size_t x)
{
/* Type of the symbol according to the number of bytes it uses */
static hlType cbType[] = {TYPE_UNKNOWN, TYPE_BYTE_UNSIGN, TYPE_WORD_SIGN,
TYPE_UNKNOWN, TYPE_LONG_SIGN};
assert(x < sizeof(cbType)/sizeof(hlType));
return cbType[x];
}
static constexpr const char *typeName(hlType t)
{
return hlTypes[t];
}
};

View File

@ -628,7 +628,7 @@ string walkCondExpr (const COND_EXPR* expr, Function * pProc, int* numLoc)
bool needBracket; /* Determine whether parenthesis is needed */
BWGLB_TYPE* bwGlb; /* Ptr to BWGLB_TYPE (global indexed var) */
STKSYM * psym; /* Pointer to argument in the stack */
std::ostringstream outStr;
std::ostringstream outStr,codeOut;
if (expr == NULL)
return "";
@ -709,7 +709,8 @@ string walkCondExpr (const COND_EXPR* expr, Function * pProc, int* numLoc)
if (id->name[0] == '\0') /* no name */
{
sprintf (id->name, "loc%ld", ++(*numLoc));
cCode.appendDecl("%s %s; /* %s */\n",hlTypes[id->type], id->name,Machine_X86::regName(id->id.regi).c_str());
codeOut <<TypeContainer::typeName(id->type)<< " "<<id->name<<"; ";
codeOut <<"/* "<<Machine_X86::regName(id->id.regi)<<" */\n";
}
if (id->hasMacro)
o << id->macro << "("<<id->name<<")";
@ -752,9 +753,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,
Machine_X86::regName(id->id.longId.h).c_str(),
Machine_X86::regName(id->id.longId.l).c_str());
codeOut <<TypeContainer::typeName(id->type)<< " "<<id->name<<"; ";
codeOut <<"/* "<<Machine_X86::regName(id->id.longId.h) << ":" <<
Machine_X86::regName(id->id.longId.l) << " */\n";
o << id->name;
pProc->localId.propLongId (id->id.longId.l,id->id.longId.h, id->name);
}
@ -784,6 +785,7 @@ string walkCondExpr (const COND_EXPR* expr, Function * pProc, int* numLoc)
outStr << o.str();
break;
}
cCode.appendDecl(codeOut.str());
return outStr.str();
}

View File

@ -218,7 +218,7 @@ void Function::codeGen (std::ostream &fs)
/* Write arguments */
for (size_t i = 0; i < args.sym.size(); i++)
{
if (args.sym[i].invalid == FALSE)
if (args.sym[i].invalid == false)
{
buf<<hlTypes[args.sym[i].type]<<" "<<args.sym[i].name;
if (i < (args.sym.size() - 1))
@ -238,7 +238,7 @@ void Function::codeGen (std::ostream &fs)
for (ID &refId : localId )
{
/* Output only non-invalidated entries */
if (refId.illegal == FALSE)
if (refId.illegal == false)
{
if (refId.loc == REG_FRAME)
{