More eReg's and fixed writeBitVector for registers

This commit is contained in:
Artur K 2012-03-07 22:34:36 +01:00
parent e0740f5ff7
commit fc0d35cf06
7 changed files with 48 additions and 58 deletions

View File

@ -175,3 +175,7 @@ int power2 (int);
boolT checkLongEq (LONG_STKID_TYPE, iICODE, int, Function *, Assignment &asgn, iICODE atOffset); boolT checkLongEq (LONG_STKID_TYPE, iICODE, int, Function *, Assignment &asgn, iICODE atOffset);
boolT checkLongRegEq (LONGID_TYPE, iICODE, int, Function *, Assignment &asgn, iICODE); boolT checkLongRegEq (LONGID_TYPE, iICODE, int, Function *, Assignment &asgn, iICODE);
eReg otherLongRegi(eReg, int, LOCAL_ID *); eReg otherLongRegi(eReg, int, LOCAL_ID *);
extern eReg subRegH(eReg reg);
extern eReg subRegL(eReg reg);

View File

@ -145,6 +145,7 @@ public:
opcode=l.opcode; opcode=l.opcode;
asgn=l.asgn; asgn=l.asgn;
call=l.call; call=l.call;
return *this;
} }
public: public:
std::string write1HlIcode(Function *pProc, int *numLoc); std::string write1HlIcode(Function *pProc, int *numLoc);
@ -153,9 +154,9 @@ public:
/* LOW_LEVEL icode operand record */ /* LOW_LEVEL icode operand record */
struct LLOperand //: public llvm::MCOperand 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 */ 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 */ eReg regi; /* 0 < regs < INDEXBASE <= index modes */
int16_t off; /* memory address offset */ int16_t off; /* memory address offset */
uint32_t opz; /* idx of immed src op */ uint32_t opz; /* idx of immed src op */
@ -333,7 +334,7 @@ public:
void hl(const HLTYPE &v) { m_hl=v;} void hl(const HLTYPE &v) { m_hl=v;}
int loc_ip; // used by CICodeRec to number ICODEs 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 invalidate();
void newCallHl(); void newCallHl();
void writeDU(int idx); void writeDU(int idx);
@ -372,11 +373,3 @@ public:
iterator labelSrch(uint32_t target); iterator labelSrch(uint32_t target);
ICODE * GetIcode(int ip); 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);
}

View File

@ -40,7 +40,7 @@ static const char *hexStr (uint16_t i)
/* Sets the du record for registers according to the du flag */ /* 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)); // printf("%s %d %x\n",__FUNCTION__,regi,int(du_in));
switch (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 */ if ((pm.seg == rDS) && (pm.regi > INDEXBASE + 3)) /* dereference */
{ {
switch (pm.regi) { 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); duIcode.setRegDU( rSI, du);
break; 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); duIcode.setRegDU( rDI, du);
break; break;
case INDEXBASE + 6: newExp = COND_EXPR::idReg(rBP, 0, &pProc->localId); case INDEXBASE + 6:
newExp = COND_EXPR::idReg(rBP, 0, &pProc->localId);
break; 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); duIcode.setRegDU( rBX, du);
break; break;
default: default:

View File

@ -9,6 +9,7 @@
#include "dcc.h" #include "dcc.h"
#include <fstream> #include <fstream>
#include <sstream>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
@ -108,9 +109,9 @@ static void printGlobVar (SYM * psym)
{ {
int j; int j;
uint32_t relocOp = prog.fCOM ? psym->label : psym->label + 0x100; 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", case 1: cCode.appendDecl( "uint8_t\t%s = %ld;\n",
psym->name, prog.Image[relocOp]); psym->name, prog.Image[relocOp]);
break; break;
@ -128,13 +129,12 @@ static void printGlobVar (SYM * psym)
prog.Image[relocOp+3]); prog.Image[relocOp+3]);
break; break;
default: default:
strContents = (char *)malloc((psym->size*2+1) *sizeof(char)); {
strContents[0] = '\0'; ostringstream strContents;
for (j=0; j < psym->size; j++) for (j=0; j < psym->size; j++)
strcat (strContents, cChar(prog.Image[relocOp + j])); strContents << cChar(prog.Image[relocOp + j]);
cCode.appendDecl( "char\t*%s = \"%s\";\n", cCode.appendDecl( "char\t*%s = \"%s\";\n", psym->name, strContents.str().c_str());
psym->name, strContents); }
free(strContents);
} }
} }
@ -178,7 +178,7 @@ static void writeGlobSymTable()
/* Writes the header information and global variables to the output C file /* Writes the header information and global variables to the output C file
* fp. */ * fp. */
static void writeHeader (std::ostream &ios, char *fileName) static void writeHeader (std::ostream &_ios, char *fileName)
{ {
/* Write header information */ /* Write header information */
newBundle (&cCode); newBundle (&cCode);
@ -189,34 +189,23 @@ static void writeHeader (std::ostream &ios, char *fileName)
/* Write global symbol table */ /* Write global symbol table */
/** writeGlobSymTable(); *** need to change them into locident fmt ***/ /** writeGlobSymTable(); *** need to change them into locident fmt ***/
writeBundle (ios, cCode); writeBundle (_ios, cCode);
freeBundle (&cCode); freeBundle (&cCode);
} }
/* Writes the registers that are set in the bitvector */ /* Writes the registers that are set in the bitvector */
static void writeBitVector (uint32_t regi) static void writeBitVector (const std::bitset<32> &regi)
{ {
int j; int j;
for (j = 0; j < INDEXBASE; j++) for (j = rAX; j < INDEXBASE; j++)
{
if ((regi & power2(j)) != 0)
printf ("%s ", allRegs[j]);
}
}
static void writeBitVector (const std::bitset<32> &regi)
{ int j;
for (j = 0; j < INDEXBASE; j++)
{ {
if (regi.test(j)) if (regi.test(j))
printf ("%s ", allRegs[j]); printf ("%s ", allRegs[j-1]);
} }
} }
// Note: Not currently called! // Note: Not currently called!
/* Checks the given icode to determine whether it has a label associated /* 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 * to it. If so, a goto is emitted to this label; otherwise, a new label

View File

@ -909,37 +909,29 @@ void Function::findExps()
case HLI_CALL: case HLI_CALL:
ticode = picode->du1.idx[0].uses.front(); 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: case HLI_ASSIGN:
exp = COND_EXPR::idFunc ( assert(ti_hl->asgn.rhs);
picode->hl()->call.proc, exp = COND_EXPR::idFunc ( picode->hl()->call.proc, picode->hl()->call.args);
picode->hl()->call.args); res = COND_EXPR::insertSubTreeReg (ti_hl->asgn.rhs,exp, retVal->id.regi, &localId);
res = COND_EXPR::insertSubTreeReg (ticode->hl()->asgn.rhs,
exp,
picode->hl()->call.proc->retVal.id.regi,
&localId);
if (! res) if (! res)
COND_EXPR::insertSubTreeReg (ticode->hl()->asgn.lhs, COND_EXPR::insertSubTreeReg (ti_hl->asgn.lhs, exp,retVal->id.regi, &localId);
exp,
picode->hl()->call.proc->retVal.id.regi,
&localId);
/*** TODO: HERE missing: 2 regs ****/ /*** TODO: HERE missing: 2 regs ****/
picode->invalidate(); picode->invalidate();
numHlIcodes--; numHlIcodes--;
break; break;
case HLI_PUSH: case HLI_RET: 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(); picode->invalidate();
numHlIcodes--; numHlIcodes--;
break; break;
case HLI_JCOND: case HLI_JCOND:
exp = COND_EXPR::idFunc ( picode->hl()->call.proc, picode->hl()->call.args); exp = COND_EXPR::idFunc ( picode->hl()->call.proc, picode->hl()->call.args);
retVal = &picode->hl()->call.proc->retVal, res = COND_EXPR::insertSubTreeReg (ti_hl->exp.v, exp, retVal->id.regi, &localId);
res = COND_EXPR::insertSubTreeReg (ticode->hl()->exp.v,
exp,
retVal->id.regi, &localId);
if (res) /* was substituted */ if (res) /* was substituted */
{ {
picode->invalidate(); picode->invalidate();

View File

@ -20,6 +20,14 @@ static SYM * lookupAddr (LLOperand *pm, STATE * pstate, int size, uint16_t d
void interactDis(Function * initProc, int ic); void interactDis(Function * initProc, int ic);
static uint32_t SynthLab; 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 /* Parses the program, builds the call graph, and returns the list of
* procedures found */ * procedures found */

View File

@ -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. */ * provide the value of this segment in the field segValue. */
if (seg) /* segment override */ if (seg) /* segment override */
{ {
pm->seg = pm->segOver = (uint8_t)seg; pm->seg = pm->segOver = (eReg)seg;
} }
else else
{ /* no override, check indexed register */ { /* no override, check indexed register */