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:
parent
14b06c252e
commit
fe250a822d
@ -11,7 +11,7 @@
|
|||||||
#include <list>
|
#include <list>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include "types.h"
|
||||||
#include "Enums.h"
|
#include "Enums.h"
|
||||||
#include "machine_x86.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
|
typedef enum
|
||||||
{
|
{
|
||||||
STK_FRAME, /* For stack vars */
|
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);}
|
bool isSigned() const { return (type==TYPE_BYTE_SIGN)||(type==TYPE_WORD_SIGN)||(type==TYPE_LONG_SIGN);}
|
||||||
uint16_t typeBitsize() const
|
uint16_t typeBitsize() const
|
||||||
{
|
{
|
||||||
switch(type)
|
return TypeContainer::typeSize(type)*8;
|
||||||
{
|
}
|
||||||
case TYPE_WORD_SIGN: case TYPE_WORD_UNSIGN:
|
void setLocalName(int i)
|
||||||
return 16;
|
{
|
||||||
case TYPE_BYTE_SIGN: case TYPE_BYTE_UNSIGN:
|
// char buf[32];
|
||||||
return 8;
|
//sprintf (buf, "loc%ld", i);
|
||||||
}
|
//name=buf;
|
||||||
return ~0;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -3,9 +3,10 @@
|
|||||||
* (C) Cristina Cifuentes, Mike van Emmerik
|
* (C) Cristina Cifuentes, Mike van Emmerik
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include <cassert>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include "Enums.h"
|
||||||
/**** Common definitions and macros ****/
|
/**** Common definitions and macros ****/
|
||||||
typedef unsigned int uint32_t; /* 32 bits */
|
|
||||||
#define MAX 0x7FFFFFFF
|
#define MAX 0x7FFFFFFF
|
||||||
|
|
||||||
/* Type definitions used in the program */
|
/* Type definitions used in the program */
|
||||||
@ -14,14 +15,6 @@ typedef unsigned short word;/* 16 bits */
|
|||||||
typedef short int16; /* 16 bits */
|
typedef short int16; /* 16 bits */
|
||||||
typedef unsigned char boolT; /* 8 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 */
|
#define SYNTHESIZED_MIN 0x100000 /* Synthesized labs use bits 21..32 */
|
||||||
|
|
||||||
/* These are for C library signature detection */
|
/* These are for C library signature detection */
|
||||||
@ -73,3 +66,41 @@ struct eDuVal
|
|||||||
}
|
}
|
||||||
bool isUSE_VAL() {return use&&val;} /* Use and Val */
|
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];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
12
src/ast.cpp
12
src/ast.cpp
@ -628,7 +628,7 @@ string walkCondExpr (const COND_EXPR* expr, Function * pProc, int* numLoc)
|
|||||||
bool needBracket; /* Determine whether parenthesis is needed */
|
bool needBracket; /* Determine whether parenthesis is needed */
|
||||||
BWGLB_TYPE* bwGlb; /* Ptr to BWGLB_TYPE (global indexed var) */
|
BWGLB_TYPE* bwGlb; /* Ptr to BWGLB_TYPE (global indexed var) */
|
||||||
STKSYM * psym; /* Pointer to argument in the stack */
|
STKSYM * psym; /* Pointer to argument in the stack */
|
||||||
std::ostringstream outStr;
|
std::ostringstream outStr,codeOut;
|
||||||
|
|
||||||
if (expr == NULL)
|
if (expr == NULL)
|
||||||
return "";
|
return "";
|
||||||
@ -709,7 +709,8 @@ string walkCondExpr (const COND_EXPR* expr, Function * pProc, int* numLoc)
|
|||||||
if (id->name[0] == '\0') /* no name */
|
if (id->name[0] == '\0') /* no name */
|
||||||
{
|
{
|
||||||
sprintf (id->name, "loc%ld", ++(*numLoc));
|
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)
|
if (id->hasMacro)
|
||||||
o << id->macro << "("<<id->name<<")";
|
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)
|
else if (id->loc == REG_FRAME)
|
||||||
{
|
{
|
||||||
sprintf (id->name, "loc%ld", ++(*numLoc));
|
sprintf (id->name, "loc%ld", ++(*numLoc));
|
||||||
cCode.appendDecl("%s %s; /* %s:%s */\n",hlTypes[id->type], id->name,
|
codeOut <<TypeContainer::typeName(id->type)<< " "<<id->name<<"; ";
|
||||||
Machine_X86::regName(id->id.longId.h).c_str(),
|
codeOut <<"/* "<<Machine_X86::regName(id->id.longId.h) << ":" <<
|
||||||
Machine_X86::regName(id->id.longId.l).c_str());
|
Machine_X86::regName(id->id.longId.l) << " */\n";
|
||||||
o << id->name;
|
o << id->name;
|
||||||
pProc->localId.propLongId (id->id.longId.l,id->id.longId.h, 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();
|
outStr << o.str();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
cCode.appendDecl(codeOut.str());
|
||||||
|
|
||||||
return outStr.str();
|
return outStr.str();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -218,7 +218,7 @@ void Function::codeGen (std::ostream &fs)
|
|||||||
/* Write arguments */
|
/* Write arguments */
|
||||||
for (size_t i = 0; i < args.sym.size(); i++)
|
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;
|
buf<<hlTypes[args.sym[i].type]<<" "<<args.sym[i].name;
|
||||||
if (i < (args.sym.size() - 1))
|
if (i < (args.sym.size() - 1))
|
||||||
@ -238,7 +238,7 @@ void Function::codeGen (std::ostream &fs)
|
|||||||
for (ID &refId : localId )
|
for (ID &refId : localId )
|
||||||
{
|
{
|
||||||
/* Output only non-invalidated entries */
|
/* Output only non-invalidated entries */
|
||||||
if (refId.illegal == FALSE)
|
if (refId.illegal == false)
|
||||||
{
|
{
|
||||||
if (refId.loc == REG_FRAME)
|
if (refId.loc == REG_FRAME)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user