Extracted commonalities between SYM and STKSYM into SymbolCommon and

between SYMTAB and STKFRAME into SymbolTableCommon<STKSYM>
This commit is contained in:
Artur K
2012-03-13 01:22:13 +01:00
parent d3e62a99aa
commit 902a5ec3d8
15 changed files with 311 additions and 290 deletions

View File

@@ -3,39 +3,22 @@
#include <cstring>
#include "types.h"
#include "Enums.h"
struct COND_EXPR;
/* STACK FRAME */
struct STKSYM
{
COND_EXPR *actual; /* Expression tree of actual parameter */
COND_EXPR *regs; /* For register arguments only */
int16_t off; /* Immediate off from BP (+:args, -:params) */
uint8_t regOff; /* Offset is a register (e.g. SI, DI) */
int size; /* Size */
hlType type; /* Probable type */
eDuVal duVal; /* DEF, USE, VAL */
boolT hasMacro; /* This type needs a macro */
char macro[10]; /* Macro name */
char name[10]; /* Name for this symbol/argument */
bool invalid; /* Boolean: invalid entry in formal arg list*/
STKSYM()
{
memset(this,0,sizeof(STKSYM));
}
};
#include "symtab.h"
struct STKFRAME
struct STKFRAME : public SymbolTableCommon<STKSYM>
{
std::vector<STKSYM> sym;
//std::vector<STKSYM> sym;
//STKSYM * sym; /* Symbols */
int16_t m_minOff; /* Initial offset in stack frame*/
int16_t maxOff; /* Maximum offset in stack frame*/
int cb; /* Number of bytes in arguments */
int numArgs; /* No. of arguments in the table*/
void adjustForArgType(int numArg_, hlType actType_);
STKFRAME() : sym(0),m_minOff(0),maxOff(0),cb(0),numArgs(0)
STKFRAME() : m_minOff(0),maxOff(0),cb(0),numArgs(0)
{
}
size_t getLocVar(int off);
public:
void updateFrameOff(int16_t off, int size, uint16_t duFlag);
};

View File

@@ -21,27 +21,6 @@
#include "Procedure.h"
#include "BasicBlock.h"
typedef llvm::iplist<Function> FunctionListType;
typedef FunctionListType lFunction;
typedef lFunction::iterator ilFunction;
/* SYMBOL TABLE */
struct SYM
{
SYM() : label(0),size(0),flg(0),type(TYPE_UNKNOWN)
{
}
char name[10]; /* New name for this variable */
uint32_t label; /* physical address (20 bit) */
int size; /* maximum size */
uint32_t flg; /* SEG_IMMED, IMPURE, WORD_OFF */
hlType type; /* probable type */
eDuVal duVal; /* DEF, USE, VAL */
};
typedef std::vector<SYM> SYMTAB;
/* CALL GRAPH NODE */
struct CALL_GRAPH
{
@@ -134,7 +113,6 @@ extern STATS stats; /* Icode statistics */
/**** Global function prototypes ****/
void FrontEnd(char *filename, CALL_GRAPH * *); /* frontend.c */
void *allocMem(int cb); /* frontend.c */
void udm(void); /* udm.c */
void freeCFG(BB * cfg); /* graph.c */
@@ -167,7 +145,7 @@ hlType expType (const COND_EXPR *, Function *);
/* Exported functions from hlicode.c */
std::string writeCall (Function *, STKFRAME *, Function *, int *);
std::string writeCall (Function *, STKFRAME &, Function *, int *);
char *writeJcond (const HLTYPE &, Function *, int *);
char *writeJcondInv (HLTYPE, Function *, int *);

View File

@@ -65,7 +65,7 @@ struct ID
frameType loc; /* Frame location */
bool hasMacro; /* Identifier requires a macro */
char macro[10]; /* Macro for this identifier */
char name[20]; /* Identifier's name */
std::string name; /* Identifier's name */
union { /* Different types of identifiers */
eReg regi; /* For TYPE_BYTE(uint16_t)_(UN)SIGN registers */
struct { /* For TYPE_BYTE(uint16_t)_(UN)SIGN on the stack */
@@ -95,9 +95,9 @@ struct ID
}
void setLocalName(int i)
{
// char buf[32];
//sprintf (buf, "loc%ld", i);
//name=buf;
char buf[32];
sprintf (buf, "loc%ld", i);
name=buf;
}
};

View File

@@ -12,6 +12,76 @@ struct TypeContainer;
/* * * * * * * * * * * * * * * * * */
/* Symbol table structs and protos */
/* * * * * * * * * * * * * * * * * */
struct SymbolCommon
{
std::string name; /* New name for this variable/symbol/argument */
int size; /* Size/maximum size */
hlType type; /* probable type */
eDuVal duVal; /* DEF, USE, VAL */
SymbolCommon() : size(0),type(TYPE_UNKNOWN)
{}
};
struct SYM : public SymbolCommon
{
SYM() : label(0),flg(0)
{
}
int32_t label; /* physical address (20 bit) */
uint32_t flg; /* SEG_IMMED, IMPURE, WORD_OFF */
};
/* STACK FRAME */
struct STKSYM : public SymbolCommon
{
COND_EXPR *actual; /* Expression tree of actual parameter */
COND_EXPR *regs; /* For register arguments only */
int16_t label; /* Immediate off from BP (+:args, -:params) */
uint8_t regOff; /* Offset is a register (e.g. SI, DI) */
bool hasMacro; /* This type needs a macro */
std::string macro; /* Macro name */
bool invalid; /* Boolean: invalid entry in formal arg list*/
STKSYM()
{
actual=regs=0;
label=0;
regOff=0;
invalid=hasMacro = false;
}
void setArgName(int i)
{
char buf[32];
sprintf (buf, "arg%ld", i);
name = buf;
}
};
template<class T>
class SymbolTableCommon : public std::vector<T>
{
public:
typedef typename std::vector<T>::iterator iterator;
typedef typename std::vector<T>::const_iterator const_iterator;
iterator findByLabel(int lab)
{
auto iter = std::find_if(this->begin(),this->end(),
[lab](T &s)->bool {return s.label==lab;});
return iter;
}
const_iterator findByLabel(int lab) const
{
auto iter = std::find_if(this->begin(),this->end(),
[lab](const T &s)->bool {return s.label==lab;});
return iter;
}
};
/* SYMBOL TABLE */
class SYMTAB : public SymbolTableCommon<SYM>
{
public:
void updateSymType(uint32_t symbol, const TypeContainer &tc);
SYM *updateGlobSym(uint32_t operand, int size, uint16_t duFlag, bool &inserted_new);
};
struct Function;
struct SYMTABLE
{