More eReg's and fixed writeBitVector for registers
This commit is contained in:
parent
e0740f5ff7
commit
fc0d35cf06
@ -175,3 +175,7 @@ int power2 (int);
|
||||
boolT checkLongEq (LONG_STKID_TYPE, iICODE, int, Function *, Assignment &asgn, iICODE atOffset);
|
||||
boolT checkLongRegEq (LONGID_TYPE, iICODE, int, Function *, Assignment &asgn, iICODE);
|
||||
eReg otherLongRegi(eReg, int, LOCAL_ID *);
|
||||
|
||||
|
||||
extern eReg subRegH(eReg reg);
|
||||
extern eReg subRegL(eReg reg);
|
||||
|
||||
@ -145,6 +145,7 @@ public:
|
||||
opcode=l.opcode;
|
||||
asgn=l.asgn;
|
||||
call=l.call;
|
||||
return *this;
|
||||
}
|
||||
public:
|
||||
std::string write1HlIcode(Function *pProc, int *numLoc);
|
||||
@ -153,9 +154,9 @@ public:
|
||||
/* LOW_LEVEL icode operand record */
|
||||
struct LLOperand //: public llvm::MCOperand
|
||||
{
|
||||
uint8_t seg; /* CS, DS, ES, SS */
|
||||
eReg seg; /* CS, DS, ES, SS */
|
||||
int16_t segValue; /* Value of segment seg during analysis */
|
||||
uint8_t segOver; /* CS, DS, ES, SS if segment override */
|
||||
eReg segOver; /* CS, DS, ES, SS if segment override */
|
||||
eReg regi; /* 0 < regs < INDEXBASE <= index modes */
|
||||
int16_t off; /* memory address offset */
|
||||
uint32_t opz; /* idx of immed src op */
|
||||
@ -333,7 +334,7 @@ public:
|
||||
void hl(const HLTYPE &v) { m_hl=v;}
|
||||
int loc_ip; // used by CICodeRec to number ICODEs
|
||||
|
||||
void setRegDU(uint8_t regi, operDu du_in);
|
||||
void setRegDU(eReg regi, operDu du_in);
|
||||
void invalidate();
|
||||
void newCallHl();
|
||||
void writeDU(int idx);
|
||||
@ -372,11 +373,3 @@ public:
|
||||
iterator labelSrch(uint32_t target);
|
||||
ICODE * GetIcode(int ip);
|
||||
};
|
||||
constexpr eReg subRegH(eReg reg)
|
||||
{
|
||||
return eReg((int)reg + (int)rAH-(int)rAX);
|
||||
}
|
||||
constexpr eReg subRegL(eReg reg)
|
||||
{
|
||||
return eReg((int)reg + (int)rAL-(int)rAX);
|
||||
}
|
||||
|
||||
14
src/ast.cpp
14
src/ast.cpp
@ -40,7 +40,7 @@ static const char *hexStr (uint16_t i)
|
||||
|
||||
|
||||
/* Sets the du record for registers according to the du flag */
|
||||
void ICODE::setRegDU (uint8_t regi, operDu du_in)
|
||||
void ICODE::setRegDU (eReg regi, operDu du_in)
|
||||
{
|
||||
// printf("%s %d %x\n",__FUNCTION__,regi,int(du_in));
|
||||
switch (du_in)
|
||||
@ -402,15 +402,19 @@ COND_EXPR *COND_EXPR::id(const LLInst &ll_insn, opLoc sd, Function * pProc, iICO
|
||||
if ((pm.seg == rDS) && (pm.regi > INDEXBASE + 3)) /* dereference */
|
||||
{
|
||||
switch (pm.regi) {
|
||||
case INDEXBASE + 4: newExp = COND_EXPR::idReg(rSI, 0, &pProc->localId);
|
||||
case INDEXBASE + 4:
|
||||
newExp = COND_EXPR::idReg(rSI, 0, &pProc->localId);
|
||||
duIcode.setRegDU( rSI, du);
|
||||
break;
|
||||
case INDEXBASE + 5: newExp = COND_EXPR::idReg(rDI, 0, &pProc->localId);
|
||||
case INDEXBASE + 5:
|
||||
newExp = COND_EXPR::idReg(rDI, 0, &pProc->localId);
|
||||
duIcode.setRegDU( rDI, du);
|
||||
break;
|
||||
case INDEXBASE + 6: newExp = COND_EXPR::idReg(rBP, 0, &pProc->localId);
|
||||
case INDEXBASE + 6:
|
||||
newExp = COND_EXPR::idReg(rBP, 0, &pProc->localId);
|
||||
break;
|
||||
case INDEXBASE + 7: newExp = COND_EXPR::idReg(rBX, 0, &pProc->localId);
|
||||
case INDEXBASE + 7:
|
||||
newExp = COND_EXPR::idReg(rBX, 0, &pProc->localId);
|
||||
duIcode.setRegDU( rBX, du);
|
||||
break;
|
||||
default:
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
|
||||
#include "dcc.h"
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@ -108,9 +109,9 @@ static void printGlobVar (SYM * psym)
|
||||
{
|
||||
int j;
|
||||
uint32_t relocOp = prog.fCOM ? psym->label : psym->label + 0x100;
|
||||
char *strContents; /* initial contents of variable */
|
||||
|
||||
switch (psym->size) {
|
||||
switch (psym->size)
|
||||
{
|
||||
case 1: cCode.appendDecl( "uint8_t\t%s = %ld;\n",
|
||||
psym->name, prog.Image[relocOp]);
|
||||
break;
|
||||
@ -128,13 +129,12 @@ static void printGlobVar (SYM * psym)
|
||||
prog.Image[relocOp+3]);
|
||||
break;
|
||||
default:
|
||||
strContents = (char *)malloc((psym->size*2+1) *sizeof(char));
|
||||
strContents[0] = '\0';
|
||||
{
|
||||
ostringstream strContents;
|
||||
for (j=0; j < psym->size; j++)
|
||||
strcat (strContents, cChar(prog.Image[relocOp + j]));
|
||||
cCode.appendDecl( "char\t*%s = \"%s\";\n",
|
||||
psym->name, strContents);
|
||||
free(strContents);
|
||||
strContents << cChar(prog.Image[relocOp + j]);
|
||||
cCode.appendDecl( "char\t*%s = \"%s\";\n", psym->name, strContents.str().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -178,7 +178,7 @@ static void writeGlobSymTable()
|
||||
|
||||
/* Writes the header information and global variables to the output C file
|
||||
* fp. */
|
||||
static void writeHeader (std::ostream &ios, char *fileName)
|
||||
static void writeHeader (std::ostream &_ios, char *fileName)
|
||||
{
|
||||
/* Write header information */
|
||||
newBundle (&cCode);
|
||||
@ -189,34 +189,23 @@ static void writeHeader (std::ostream &ios, char *fileName)
|
||||
|
||||
/* Write global symbol table */
|
||||
/** writeGlobSymTable(); *** need to change them into locident fmt ***/
|
||||
writeBundle (ios, cCode);
|
||||
writeBundle (_ios, cCode);
|
||||
freeBundle (&cCode);
|
||||
}
|
||||
|
||||
|
||||
/* Writes the registers that are set in the bitvector */
|
||||
static void writeBitVector (uint32_t regi)
|
||||
static void writeBitVector (const std::bitset<32> ®i)
|
||||
{
|
||||
int j;
|
||||
|
||||
for (j = 0; j < INDEXBASE; j++)
|
||||
{
|
||||
if ((regi & power2(j)) != 0)
|
||||
printf ("%s ", allRegs[j]);
|
||||
}
|
||||
}
|
||||
static void writeBitVector (const std::bitset<32> ®i)
|
||||
{ int j;
|
||||
|
||||
for (j = 0; j < INDEXBASE; j++)
|
||||
for (j = rAX; j < INDEXBASE; j++)
|
||||
{
|
||||
if (regi.test(j))
|
||||
printf ("%s ", allRegs[j]);
|
||||
printf ("%s ", allRegs[j-1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Note: Not currently called!
|
||||
/* Checks the given icode to determine whether it has a label associated
|
||||
* to it. If so, a goto is emitted to this label; otherwise, a new label
|
||||
|
||||
@ -909,37 +909,29 @@ void Function::findExps()
|
||||
|
||||
case HLI_CALL:
|
||||
ticode = picode->du1.idx[0].uses.front();
|
||||
switch (ticode->hl()->opcode) {
|
||||
HLTYPE *ti_hl(ticode->hl());
|
||||
retVal = &picode->hl()->call.proc->retVal;
|
||||
switch (ti_hl->opcode) {
|
||||
case HLI_ASSIGN:
|
||||
exp = COND_EXPR::idFunc (
|
||||
picode->hl()->call.proc,
|
||||
picode->hl()->call.args);
|
||||
res = COND_EXPR::insertSubTreeReg (ticode->hl()->asgn.rhs,
|
||||
exp,
|
||||
picode->hl()->call.proc->retVal.id.regi,
|
||||
&localId);
|
||||
assert(ti_hl->asgn.rhs);
|
||||
exp = COND_EXPR::idFunc ( picode->hl()->call.proc, picode->hl()->call.args);
|
||||
res = COND_EXPR::insertSubTreeReg (ti_hl->asgn.rhs,exp, retVal->id.regi, &localId);
|
||||
if (! res)
|
||||
COND_EXPR::insertSubTreeReg (ticode->hl()->asgn.lhs,
|
||||
exp,
|
||||
picode->hl()->call.proc->retVal.id.regi,
|
||||
&localId);
|
||||
COND_EXPR::insertSubTreeReg (ti_hl->asgn.lhs, exp,retVal->id.regi, &localId);
|
||||
/*** TODO: HERE missing: 2 regs ****/
|
||||
picode->invalidate();
|
||||
numHlIcodes--;
|
||||
break;
|
||||
|
||||
case HLI_PUSH: case HLI_RET:
|
||||
ticode->hl()->expr( COND_EXPR::idFunc ( picode->hl()->call.proc, picode->hl()->call.args) );
|
||||
ti_hl->expr( COND_EXPR::idFunc ( picode->hl()->call.proc, picode->hl()->call.args) );
|
||||
picode->invalidate();
|
||||
numHlIcodes--;
|
||||
break;
|
||||
|
||||
case HLI_JCOND:
|
||||
exp = COND_EXPR::idFunc ( picode->hl()->call.proc, picode->hl()->call.args);
|
||||
retVal = &picode->hl()->call.proc->retVal,
|
||||
res = COND_EXPR::insertSubTreeReg (ticode->hl()->exp.v,
|
||||
exp,
|
||||
retVal->id.regi, &localId);
|
||||
res = COND_EXPR::insertSubTreeReg (ti_hl->exp.v, exp, retVal->id.regi, &localId);
|
||||
if (res) /* was substituted */
|
||||
{
|
||||
picode->invalidate();
|
||||
|
||||
@ -20,6 +20,14 @@ static SYM * lookupAddr (LLOperand *pm, STATE * pstate, int size, uint16_t d
|
||||
void interactDis(Function * initProc, int ic);
|
||||
static uint32_t SynthLab;
|
||||
|
||||
/*constexpr */eReg subRegH(eReg reg)
|
||||
{
|
||||
return eReg((int)reg + (int)rAH-(int)rAX);
|
||||
}
|
||||
/*constexpr */eReg subRegL(eReg reg)
|
||||
{
|
||||
return eReg((int)reg + (int)rAL-(int)rAX);
|
||||
}
|
||||
|
||||
/* Parses the program, builds the call graph, and returns the list of
|
||||
* procedures found */
|
||||
|
||||
@ -418,7 +418,7 @@ static void setAddress(int i, boolT fdst, uint16_t seg, int16_t reg, uint16_t of
|
||||
* provide the value of this segment in the field segValue. */
|
||||
if (seg) /* segment override */
|
||||
{
|
||||
pm->seg = pm->segOver = (uint8_t)seg;
|
||||
pm->seg = pm->segOver = (eReg)seg;
|
||||
}
|
||||
else
|
||||
{ /* no override, check indexed register */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user