more fixes
This commit is contained in:
@@ -42,7 +42,7 @@ private:
|
||||
iICODE range_end;
|
||||
public:
|
||||
iICODE begin();
|
||||
iICODE end();
|
||||
iICODE end() const;
|
||||
riICODE rbegin();
|
||||
riICODE rend();
|
||||
ICODE &front();
|
||||
|
||||
@@ -1,34 +1,4 @@
|
||||
#pragma once
|
||||
/* Machine registers */
|
||||
enum eReg
|
||||
{
|
||||
rUNDEF = 0,
|
||||
rAX = 1, /* These are numbered relative to real 8086 */
|
||||
rCX = 2,
|
||||
rDX = 3,
|
||||
rBX = 4,
|
||||
rSP = 5,
|
||||
rBP = 6,
|
||||
rSI = 7,
|
||||
rDI = 8,
|
||||
|
||||
rES = 9,
|
||||
rCS = 10,
|
||||
rSS = 11,
|
||||
rDS = 12,
|
||||
|
||||
rAL = 13,
|
||||
rCL = 14,
|
||||
rDL = 15,
|
||||
rBL = 16,
|
||||
rAH = 17,
|
||||
rCH = 18,
|
||||
rDH = 19,
|
||||
rBH = 20,
|
||||
|
||||
rTMP= 21, /* temp register for DIV/IDIV/MOD */
|
||||
INDEXBASE = 22 /* Indexed modes go from INDEXBASE to INDEXBASE+7 */
|
||||
};
|
||||
|
||||
/* Register types */
|
||||
enum regType
|
||||
@@ -285,11 +255,11 @@ enum hlType
|
||||
TYPE_WORD_UNSIGN, /* unsigned word (16 bits) */
|
||||
TYPE_LONG_SIGN, /* signed long (32 bits) */
|
||||
TYPE_LONG_UNSIGN, /* unsigned long (32 bits) */
|
||||
TYPE_RECORD, /* record structure */
|
||||
TYPE_RECORD, /* record structure */
|
||||
TYPE_PTR, /* pointer (32 bit ptr) */
|
||||
TYPE_STR, /* string */
|
||||
TYPE_CONST, /* constant (any type) */
|
||||
TYPE_FLOAT, /* floating point */
|
||||
TYPE_CONST, /* constant (any type) */
|
||||
TYPE_FLOAT, /* floating point */
|
||||
TYPE_DOUBLE /* double precision float */
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include "ast.h"
|
||||
#include "types.h"
|
||||
#include "machine_x86.h"
|
||||
struct IDENTTYPE
|
||||
{
|
||||
condId idType;
|
||||
@@ -23,8 +24,8 @@ struct IDENTTYPE
|
||||
STKFRAME *args;
|
||||
} call;
|
||||
struct { /* for OTHER; tmp struct */
|
||||
uint8_t seg; /* segment */
|
||||
uint8_t regi; /* index mode */
|
||||
eReg seg; /* segment */
|
||||
eReg regi; /* index mode */
|
||||
int16_t off; /* offset */
|
||||
} other;
|
||||
} idNode;
|
||||
|
||||
@@ -102,8 +102,8 @@ public:
|
||||
std::list<BB*> heldBBs;
|
||||
//BB * *dfsLast; /* Array of pointers to BBs in dfsLast
|
||||
// * (reverse postorder) order */
|
||||
int numBBs; /* Number of BBs in the graph cfg */
|
||||
boolT hasCase; /* Procedure has a case node */
|
||||
size_t numBBs; /* Number of BBs in the graph cfg */
|
||||
bool hasCase; /* Procedure has a case node */
|
||||
|
||||
/* For interprocedural live analysis */
|
||||
std::bitset<32> liveIn; /* Registers used before defined */
|
||||
|
||||
@@ -37,5 +37,5 @@ struct STKFRAME
|
||||
{
|
||||
|
||||
}
|
||||
int getLocVar(int off);
|
||||
size_t getLocVar(int off);
|
||||
};
|
||||
|
||||
@@ -76,7 +76,7 @@ public:
|
||||
static COND_EXPR *idLoc(int off, LOCAL_ID *localId);
|
||||
static COND_EXPR *idReg(eReg regi, uint32_t icodeFlg, LOCAL_ID *locsym);
|
||||
static COND_EXPR *idLongIdx(int idx);
|
||||
static COND_EXPR *idOther(uint8_t seg, uint8_t regi, int16_t off);
|
||||
static COND_EXPR *idOther(eReg seg, eReg regi, int16_t off);
|
||||
static COND_EXPR *idParam(int off, const STKFRAME *argSymtab);
|
||||
static COND_EXPR *unary(condNodeType t, COND_EXPR *sub_expr);
|
||||
static COND_EXPR *idLong(LOCAL_ID *localId, opLoc sd, iICODE pIcode, hlFirst f, iICODE ix, operDu du, iICODE atOffset);
|
||||
|
||||
@@ -83,7 +83,7 @@ struct PROG /* Loaded program image parameters */
|
||||
int16_t initCS;
|
||||
int16_t initIP; /* These are initial load values */
|
||||
int16_t initSS; /* Probably not of great interest */
|
||||
int16_t initSP;
|
||||
uint16_t initSP;
|
||||
bool fCOM; /* Flag set if COM program (else EXE)*/
|
||||
int cReloc; /* No. of relocation table entries */
|
||||
uint32_t * relocTable; /* Ptr. to relocation table */
|
||||
@@ -179,3 +179,4 @@ eReg otherLongRegi(eReg, int, LOCAL_ID *);
|
||||
|
||||
extern eReg subRegH(eReg reg);
|
||||
extern eReg subRegL(eReg reg);
|
||||
extern const char *indentStr(int level);
|
||||
|
||||
@@ -30,7 +30,7 @@ enum eErrorId
|
||||
WHILE_FAIL
|
||||
};
|
||||
|
||||
|
||||
//lint -function(exit,fatalError)
|
||||
void fatalError(eErrorId errId, ...);
|
||||
void reportError(eErrorId errId, ...);
|
||||
|
||||
|
||||
@@ -23,13 +23,6 @@ struct ICODE;
|
||||
typedef std::list<ICODE>::iterator iICODE;
|
||||
typedef std::list<ICODE>::reverse_iterator riICODE;
|
||||
|
||||
/* uint8_t and uint16_t registers */
|
||||
static const char *const byteReg[9] = {"al", "cl", "dl", "bl",
|
||||
"ah", "ch", "dh", "bh", "tmp" };
|
||||
static const char *const wordReg[21] = {"ax", "cx", "dx", "bx", "sp", "bp",
|
||||
"si", "di", "es", "cs", "ss", "ds",
|
||||
"", "", "", "", "", "", "", "", "tmp"};
|
||||
|
||||
/* Def/use of flags - low 4 bits represent flags */
|
||||
struct DU
|
||||
{
|
||||
@@ -251,7 +244,7 @@ public:
|
||||
opcode = op;
|
||||
}
|
||||
void emitGotoLabel(int indLevel);
|
||||
void findJumpTargets(CIcodeRec &pc);
|
||||
void findJumpTargets(CIcodeRec &_pc);
|
||||
void writeIntComment(std::ostringstream &s);
|
||||
void dis1Line(int loc_ip, int pass);
|
||||
std::ostringstream &strSrc(std::ostringstream &os,bool skip_comma=false);
|
||||
@@ -349,7 +342,7 @@ public:
|
||||
type=HIGH_LEVEL;
|
||||
hl()->setAsgn(lhs,rhs);
|
||||
}
|
||||
void setUnary(hlIcode op, COND_EXPR *exp);
|
||||
void setUnary(hlIcode op, COND_EXPR *_exp);
|
||||
void setJCond(COND_EXPR *cexp);
|
||||
|
||||
void emitGotoLabel(int indLevel);
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include "Enums.h"
|
||||
#include "machine_x86.h"
|
||||
|
||||
/* Type definition */
|
||||
// this array has to stay in-order of addition i.e. not std::set<iICODE,std::less<iICODE> >
|
||||
@@ -44,7 +45,7 @@ typedef struct
|
||||
{
|
||||
int16_t seg; /* segment value */
|
||||
int16_t off; /* offset */
|
||||
uint8_t regi; /* optional indexed register */
|
||||
eReg regi; /* optional indexed register */
|
||||
} BWGLB_TYPE;
|
||||
|
||||
|
||||
@@ -100,6 +101,8 @@ struct ID
|
||||
{
|
||||
case TYPE_WORD_SIGN: case TYPE_WORD_UNSIGN:
|
||||
return 16;
|
||||
case TYPE_BYTE_SIGN: case TYPE_BYTE_UNSIGN:
|
||||
return 8;
|
||||
}
|
||||
return ~0;
|
||||
}
|
||||
@@ -113,9 +116,12 @@ public:
|
||||
{
|
||||
id_arr.reserve(256);
|
||||
}
|
||||
// interface to allow range based iteration
|
||||
std::vector<ID>::iterator begin() {return id_arr.begin();}
|
||||
std::vector<ID>::iterator end() {return id_arr.end();}
|
||||
int newByteWordReg(hlType t, eReg regi);
|
||||
int newByteWordStk(hlType t, int off, uint8_t regOff);
|
||||
int newIntIdx(int16_t seg, int16_t off, uint8_t regi, int ix, hlType t);
|
||||
int newIntIdx(int16_t seg, int16_t off, eReg regi, int ix, hlType t);
|
||||
int newLongReg(hlType t, eReg regH, eReg regL, iICODE ix_);
|
||||
int newLong(opLoc sd, iICODE pIcode, hlFirst f, iICODE ix, operDu du, int off);
|
||||
int newLong(opLoc sd, iICODE pIcode, hlFirst f, iICODE ix, operDu du, iICODE atOffset);
|
||||
|
||||
48
include/machine_x86.h
Normal file
48
include/machine_x86.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
/* Machine registers */
|
||||
enum eReg
|
||||
{
|
||||
rUNDEF = 0,
|
||||
rAX = 1, /* These are numbered relative to real 8086 */
|
||||
rCX = 2,
|
||||
rDX = 3,
|
||||
rBX = 4,
|
||||
rSP = 5,
|
||||
rBP = 6,
|
||||
rSI = 7,
|
||||
rDI = 8,
|
||||
|
||||
rES = 9,
|
||||
rCS = 10,
|
||||
rSS = 11,
|
||||
rDS = 12,
|
||||
|
||||
rAL = 13,
|
||||
rCL = 14,
|
||||
rDL = 15,
|
||||
rBL = 16,
|
||||
rAH = 17,
|
||||
rCH = 18,
|
||||
rDH = 19,
|
||||
rBH = 20,
|
||||
|
||||
rTMP= 21, /* temp register for DIV/IDIV/MOD */
|
||||
/* Indexed modes go from INDEXBASE to INDEXBASE+7 */
|
||||
INDEX_BX_SI = 22, // "bx+si"
|
||||
INDEX_BX_DI, // "bx+di"
|
||||
INDEX_BP_SI, // "bp+si"
|
||||
INDEX_BP_DI, // "bp+di"
|
||||
INDEX_SI, // "si"
|
||||
INDEX_DI, // "di"
|
||||
INDEX_BP, // "bp"
|
||||
INDEX_BX, // "bx"
|
||||
LAST_REG
|
||||
};
|
||||
|
||||
class Machine_X86
|
||||
{
|
||||
public:
|
||||
Machine_X86();
|
||||
static const std::string ®Name(eReg r);
|
||||
};
|
||||
@@ -1,11 +1,9 @@
|
||||
#pragma once
|
||||
/* Perfect hashing function library. Contains functions to generate perfect
|
||||
hashing functions
|
||||
* (C) Mike van Emmerik
|
||||
*/
|
||||
|
||||
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
//#define bool unsigned char
|
||||
#define uint8_t unsigned char
|
||||
#define uint16_t unsigned short
|
||||
|
||||
@@ -5,13 +5,14 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <cstring>
|
||||
#include "Enums.h"
|
||||
#include "machine_x86.h"
|
||||
|
||||
/* STATE TABLE */
|
||||
struct STATE
|
||||
{
|
||||
uint32_t IP; /* Offset into Image */
|
||||
int16_t r[INDEXBASE]; /* Value of segs and AX */
|
||||
uint8_t f[INDEXBASE]; /* True if r[.] has a value */
|
||||
int16_t r[INDEX_BX_SI]; /* Value of segs and AX */
|
||||
uint8_t f[INDEX_BX_SI]; /* True if r[.] has a value */
|
||||
struct
|
||||
{ /* For case stmt indexed reg */
|
||||
uint8_t regi; /* Last conditional jump */
|
||||
@@ -24,8 +25,8 @@ struct STATE
|
||||
JCond.regi=0;
|
||||
JCond.immed=0;
|
||||
|
||||
memset(r,0,sizeof(int16_t)*INDEXBASE);
|
||||
memset(f,0,sizeof(uint8_t)*INDEXBASE);
|
||||
memset(r,0,sizeof(int16_t)*INDEX_BX_SI);
|
||||
memset(f,0,sizeof(uint8_t)*INDEX_BX_SI);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user