Moved some more enums into Enums.h, removed multiple defs of LH macro, fixed missed initialization in STATE

This commit is contained in:
Artur K 2012-02-29 12:05:39 +01:00
parent a0a6f7cc0e
commit 0eab9d1db5
8 changed files with 179 additions and 182 deletions

View File

@ -81,7 +81,165 @@ enum opLoc
DST, /* Destination operand */ DST, /* Destination operand */
LHS_OP /* Left-hand side operand (for HIGH_LEVEL) */ LHS_OP /* Left-hand side operand (for HIGH_LEVEL) */
}; };
/* LOW_LEVEL icode flags */
enum eLLFlags
{
B =0x0000001, /* uint8_t operands (value implicitly used) */
I =0x0000002, /* Immed. source */
NOT_HLL =0x0000004, /* Not HLL inst. */
FLOAT_OP =0x0000008, /* ESC or WAIT */
SEG_IMMED =0x0000010, /* Number is relocated segment value */
IMPURE =0x0000020, /* Instruction modifies code */
WORD_OFF =0x0000040, /* Inst has uint16_t offset ie.could be address */
TERMINATES =0x0000080, /* Instruction terminates program */
CASE =0x0000100, /* Label as case part of switch */
SWITCH =0x0000200, /* Treat indirect JMP as switch stmt */
TARGET =0x0000400, /* Jump target */
SYNTHETIC =0x0000800, /* Synthetic jump instruction */
NO_LABEL =0x0001000, /* Immed. jump cannot be linked to a label */
NO_CODE =0x0002000, /* Hole in Icode array */
SYM_USE =0x0004000, /* Instruction uses a symbol */
SYM_DEF =0x0008000, /* Instruction defines a symbol */
NO_SRC =0x0010000, /* Opcode takes no source */
NO_OPS =0x0020000, /* Opcode takes no operands */
IM_OPS =0x0040000, /* Opcode takes implicit operands */
SRC_B =0x0080000, /* Source operand is uint8_t (dest is uint16_t) */
#define NO_SRC_B 0xF7FFFF /* Masks off SRC_B */
HLL_LABEL =0x0100000, /* Icode has a high level language label */
IM_DST =0x0200000, /* Implicit DST for opcode (SIGNEX) */
IM_SRC =0x0400000, /* Implicit SRC for opcode (dx:ax) */
IM_TMP_DST =0x0800000, /* Implicit rTMP DST for opcode (DIV/IDIV) */
JMP_ICODE =0x1000000, /* Jmp dest immed.op converted to icode index */
JX_LOOP =0x2000000, /* Cond jump is part of loop conditional exp */
REST_STK =0x4000000 /* Stack needs to be restored after CALL */
};
/* Types of icodes */
enum icodeType
{
NOT_SCANNED = 0, /* not even scanned yet */
LOW_LEVEL, /* low-level icode */
HIGH_LEVEL /* high-level icode */
};
/* LOW_LEVEL icode opcodes */
enum llIcode
{
iCBW, /* 0 */
iAAA,
iAAD,
iAAM,
iAAS,
iADC,
iADD,
iAND,
iBOUND,
iCALL,
iCALLF, /* 10 */
iCLC,
iCLD,
iCLI,
iCMC,
iCMP,
iCMPS,
iREPNE_CMPS,
iREPE_CMPS,
iDAA,
iDAS, /* 20 */
iDEC,
iDIV,
iENTER,
iESC,
iHLT,
iIDIV,
iIMUL,
iIN,
iINC,
iINS, /* 30 */
iREP_INS,
iINT,
iIRET,
iJB,
iJBE,
iJAE,
iJA,
iJE,
iJNE,
iJL, /* 40 */
iJGE,
iJLE,
iJG,
iJS,
iJNS,
iJO,
iJNO,
iJP,
iJNP,
iJCXZ, /* 50 */
iJMP,
iJMPF,
iLAHF,
iLDS,
iLEA,
iLEAVE,
iLES,
iLOCK,
iLODS,
iREP_LODS, /* 60 */
iLOOP,
iLOOPE,
iLOOPNE,
iMOV, /* 64 */
iMOVS,
iREP_MOVS,
iMUL, /* 67 */
iNEG,
iNOT,
iOR, /* 70 */
iOUT,
iOUTS,
iREP_OUTS,
iPOP,
iPOPA,
iPOPF,
iPUSH,
iPUSHA,
iPUSHF,
iRCL, /* 80 */
iRCR,
iROL,
iROR,
iRET, /* 84 */
iRETF,
iSAHF,
iSAR,
iSHL,
iSHR,
iSBB, /* 90 */
iSCAS,
iREPNE_SCAS,
iREPE_SCAS,
iSIGNEX,
iSTC,
iSTD,
iSTI,
iSTOS,
iREP_STOS,
iSUB, /* 100 */
iTEST,
iWAIT,
iXCHG,
iXLAT,
iXOR,
iINTO,
iNOP,
iREPNE,
iREPE,
iMOD /* 110 */
};
/* Conditional Expression enumeration nodes and operators */ /* Conditional Expression enumeration nodes and operators */
enum condNodeType enum condNodeType
{ {

View File

@ -17,7 +17,7 @@ struct STKSYM
boolT hasMacro; /* This type needs a macro */ boolT hasMacro; /* This type needs a macro */
char macro[10]; /* Macro name */ char macro[10]; /* Macro name */
char name[10]; /* Name for this symbol/argument */ char name[10]; /* Name for this symbol/argument */
boolT invalid; /* Boolean: invalid entry in formal arg list*/ bool invalid; /* Boolean: invalid entry in formal arg list*/
STKSYM() STKSYM()
{ {
memset(this,0,sizeof(STKSYM)); memset(this,0,sizeof(STKSYM));

View File

@ -160,7 +160,6 @@ void placeStkArg (ICODE *, COND_EXPR *, int);
void adjustActArgType (COND_EXPR *, hlType, Function *); void adjustActArgType (COND_EXPR *, hlType, Function *);
/* Exported functions from ast.c */ /* Exported functions from ast.c */
void removeRegFromLong (uint8_t, LOCAL_ID *, COND_EXPR *);
std::string walkCondExpr (const COND_EXPR *exp, Function * pProc, int *); std::string walkCondExpr (const COND_EXPR *exp, Function * pProc, int *);
int hlTypeSize (const COND_EXPR *, Function *); int hlTypeSize (const COND_EXPR *, Function *);
hlType expType (const COND_EXPR *, Function *); hlType expType (const COND_EXPR *, Function *);
@ -178,6 +177,3 @@ int power2 (int);
boolT checkLongEq (LONG_STKID_TYPE, iICODE, int, Function *, Assignment &asgn, int); boolT checkLongEq (LONG_STKID_TYPE, iICODE, int, Function *, Assignment &asgn, int);
boolT checkLongRegEq (LONGID_TYPE, iICODE, int, Function *, COND_EXPR *&, COND_EXPR *&, int); boolT checkLongRegEq (LONGID_TYPE, iICODE, int, Function *, COND_EXPR *&, COND_EXPR *&, int);
uint8_t otherLongRegi (uint8_t, int, LOCAL_ID *); uint8_t otherLongRegi (uint8_t, int, LOCAL_ID *);
void insertIdx (IDX_ARRAY *, int);

View File

@ -6,53 +6,13 @@
#include <vector> #include <vector>
#include <list> #include <list>
#include <bitset> #include <bitset>
#include <llvm/ADT/ilist.h>
#include <llvm/ADT/ilist_node.h>
#include <llvm/MC/MCInst.h> #include <llvm/MC/MCInst.h>
#include <llvm/MC/MCAsmInfo.h> #include <llvm/MC/MCAsmInfo.h>
#include "Enums.h" #include "Enums.h"
//enum condId; //enum condId;
struct LOCAL_ID; struct LOCAL_ID;
/* LOW_LEVEL icode flags */
enum eLLFlags
{
B =0x0000001, /* uint8_t operands (value implicitly used) */
I =0x0000002, /* Immed. source */
NOT_HLL =0x0000004, /* Not HLL inst. */
FLOAT_OP =0x0000008, /* ESC or WAIT */
SEG_IMMED =0x0000010, /* Number is relocated segment value */
IMPURE =0x0000020, /* Instruction modifies code */
WORD_OFF =0x0000040, /* Inst has uint16_t offset ie.could be address */
TERMINATES =0x0000080, /* Instruction terminates program */
CASE =0x0000100, /* Label as case part of switch */
SWITCH =0x0000200, /* Treat indirect JMP as switch stmt */
TARGET =0x0000400, /* Jump target */
SYNTHETIC =0x0000800, /* Synthetic jump instruction */
NO_LABEL =0x0001000, /* Immed. jump cannot be linked to a label */
NO_CODE =0x0002000, /* Hole in Icode array */
SYM_USE =0x0004000, /* Instruction uses a symbol */
SYM_DEF =0x0008000, /* Instruction defines a symbol */
NO_SRC =0x0010000, /* Opcode takes no source */
NO_OPS =0x0020000, /* Opcode takes no operands */
IM_OPS =0x0040000, /* Opcode takes implicit operands */
SRC_B =0x0080000, /* Source operand is uint8_t (dest is uint16_t) */
#define NO_SRC_B 0xF7FFFF /* Masks off SRC_B */
HLL_LABEL =0x0100000, /* Icode has a high level language label */
IM_DST =0x0200000, /* Implicit DST for opcode (SIGNEX) */
IM_SRC =0x0400000, /* Implicit SRC for opcode (dx:ax) */
IM_TMP_DST =0x0800000, /* Implicit rTMP DST for opcode (DIV/IDIV) */
JMP_ICODE =0x1000000, /* Jmp dest immed.op converted to icode index */
JX_LOOP =0x2000000, /* Cond jump is part of loop conditional exp */
REST_STK =0x4000000 /* Stack needs to be restored after CALL */
};
/* Parser flags */
#define TO_REG 0x000100 /* rm is source */
#define S_EXT 0x000200 /* sign extend */
#define OP386 0x000400 /* 386 op-code */
#define NSP 0x000800 /* NOT_HLL if SP is src or dst */
#define ICODEMASK 0xFF00FF /* Masks off parser flags */
/* LOW_LEVEL icode, DU flag bits */ /* LOW_LEVEL icode, DU flag bits */
enum eDuFlags enum eDuFlags
@ -72,130 +32,6 @@ static const char *const wordReg[21] = {"ax", "cx", "dx", "bx", "sp", "bp",
#include "state.h" // State depends on INDEXBASE, but later need STATE #include "state.h" // State depends on INDEXBASE, but later need STATE
/* Types of icodes */
enum icodeType
{
NOT_SCANNED = 0, /* not even scanned yet */
LOW_LEVEL, /* low-level icode */
HIGH_LEVEL /* high-level icode */
};
/* LOW_LEVEL icode opcodes */
enum llIcode
{
iCBW, /* 0 */
iAAA,
iAAD,
iAAM,
iAAS,
iADC,
iADD,
iAND,
iBOUND,
iCALL,
iCALLF, /* 10 */
iCLC,
iCLD,
iCLI,
iCMC,
iCMP,
iCMPS,
iREPNE_CMPS,
iREPE_CMPS,
iDAA,
iDAS, /* 20 */
iDEC,
iDIV,
iENTER,
iESC,
iHLT,
iIDIV,
iIMUL,
iIN,
iINC,
iINS, /* 30 */
iREP_INS,
iINT,
iIRET,
iJB,
iJBE,
iJAE,
iJA,
iJE,
iJNE,
iJL, /* 40 */
iJGE,
iJLE,
iJG,
iJS,
iJNS,
iJO,
iJNO,
iJP,
iJNP,
iJCXZ, /* 50 */
iJMP,
iJMPF,
iLAHF,
iLDS,
iLEA,
iLEAVE,
iLES,
iLOCK,
iLODS,
iREP_LODS, /* 60 */
iLOOP,
iLOOPE,
iLOOPNE,
iMOV, /* 64 */
iMOVS,
iREP_MOVS,
iMUL, /* 67 */
iNEG,
iNOT,
iOR, /* 70 */
iOUT,
iOUTS,
iREP_OUTS,
iPOP,
iPOPA,
iPOPF,
iPUSH,
iPUSHA,
iPUSHF,
iRCL, /* 80 */
iRCR,
iROL,
iROR,
iRET, /* 84 */
iRETF,
iSAHF,
iSAR,
iSHL,
iSHR,
iSBB, /* 90 */
iSCAS,
iREPNE_SCAS,
iREPE_SCAS,
iSIGNEX,
iSTC,
iSTD,
iSTI,
iSTOS,
iREP_STOS,
iSUB, /* 100 */
iTEST,
iWAIT,
iXCHG,
iXLAT,
iXOR,
iINTO,
iNOP,
iREPNE,
iREPE,
iMOD /* 110 */
};
struct BB; struct BB;
struct Function; struct Function;
struct STKFRAME; struct STKFRAME;
@ -379,19 +215,18 @@ struct ICODE
/* Def/Use of registers and stack variables */ /* Def/Use of registers and stack variables */
struct DU_ICODE struct DU_ICODE
{ {
DU_ICODE()
{
def.reset();
use.reset();
lastDefRegi.reset();
}
std::bitset<32> def; // For Registers: position in bitset is reg index std::bitset<32> def; // For Registers: position in bitset is reg index
std::bitset<32> use; // For Registers: position in uint32_t is reg index std::bitset<32> use; // For Registers: position in uint32_t is reg index
std::bitset<32> lastDefRegi;// Bit set if last def of this register in BB std::bitset<32> lastDefRegi;// Bit set if last def of this register in BB
}; };
struct DU1 struct DU1
{ {
struct DefUse
{
int Reg; // used register
int DefLoc;
std::vector<std::list<ICODE>::iterator > useLoc; // use locations [MAX_USES]
};
struct Use struct Use
{ {
int Reg; // used register int Reg; // used register
@ -408,8 +243,8 @@ struct ICODE
}; };
int numRegsDef; /* # registers defined by this inst */ int numRegsDef; /* # registers defined by this inst */
uint8_t regi[MAX_REGS_DEF]; /* registers defined by this inst */ uint8_t regi[3]; /* registers defined by this inst */
Use idx[MAX_REGS_DEF]; Use idx[3];
//int idx[MAX_REGS_DEF][MAX_USES]; /* inst that uses this def */ //int idx[MAX_REGS_DEF][MAX_USES]; /* inst that uses this def */
bool used(int regIdx) bool used(int regIdx)
{ {

View File

@ -2,6 +2,6 @@
* (C) Cristina Cifuentes, Jeff Ledermann * (C) Cristina Cifuentes, Jeff Ledermann
*/ */
#define LH(p) ((int)((uint8_t *)(p))[0] + ((int)((uint8_t *)(p))[1] << 8)) //#define LH(p) ((int)((uint8_t *)(p))[0] + ((int)((uint8_t *)(p))[1] << 8))
/* Extracts reg bits from middle of mod-reg-rm uint8_t */ /* Extracts reg bits from middle of mod-reg-rm uint8_t */
#define REG(x) ((uint8_t)(x & 0x38) >> 3) #define REG(x) ((uint8_t)(x & 0x38) >> 3)

View File

@ -21,7 +21,9 @@ struct STATE
void checkStartup(); void checkStartup();
STATE() : IP(0) STATE() : IP(0)
{ {
JCond.regi=0;
JCond.immed=0; JCond.immed=0;
memset(r,0,sizeof(int16_t)*INDEXBASE); memset(r,0,sizeof(int16_t)*INDEXBASE);
memset(f,0,sizeof(uint8_t)*INDEXBASE); memset(f,0,sizeof(uint8_t)*INDEXBASE);
} }

View File

@ -34,7 +34,7 @@ typedef unsigned char boolT; /* 8 bits */
/* Macro reads a LH word from the image regardless of host convention */ /* Macro reads a LH word from the image regardless of host convention */
/* Returns a 16 bit quantity, e.g. C000 is read into an Int as C000 */ /* Returns a 16 bit quantity, e.g. C000 is read into an Int as C000 */
//#define LH(p) ((int16)((byte *)(p))[0] + ((int16)((byte *)(p))[1] << 8)) //#define LH(p) ((int16)((byte *)(p))[0] + ((int16)((byte *)(p))[1] << 8))
#define LH(p) ((word)((byte *)(p))[0] + ((word)((byte *)(p))[1] << 8)) #define LH(p) ((uint16_t)((uint8_t *)(p))[0] + ((uint16_t)((uint8_t *)(p))[1] << 8))
/* Macro reads a LH word from the image regardless of host convention */ /* Macro reads a LH word from the image regardless of host convention */
/* Returns a signed quantity, e.g. C000 is read into an Int as FFFFC000 */ /* Returns a signed quantity, e.g. C000 is read into an Int as FFFFC000 */

View File

@ -9,6 +9,12 @@
#include "dcc.h" #include "dcc.h"
#include "scanner.h" #include "scanner.h"
/* Parser flags */
#define TO_REG 0x000100 /* rm is source */
#define S_EXT 0x000200 /* sign extend */
#define OP386 0x000400 /* 386 op-code */
#define NSP 0x000800 /* NOT_HLL if SP is src or dst */
#define ICODEMASK 0xFF00FF /* Masks off parser flags */
static void rm(int i); static void rm(int i);
static void modrm(int i); static void modrm(int i);