rename otherLongRegi to getPairedRegisterAt, make it a method of

LOCAL_ID struct.
This commit is contained in:
nemerle 2017-02-13 12:31:30 +01:00
parent a5f1d17e83
commit d7acc8cd4d
5 changed files with 29 additions and 48 deletions

View File

@ -221,9 +221,6 @@ struct AstIdent : public UnaryOperator
virtual Expr *insertSubTreeReg(Expr *_expr, eReg regi, const LOCAL_ID *locsym); virtual Expr *insertSubTreeReg(Expr *_expr, eReg regi, const LOCAL_ID *locsym);
virtual Expr *insertSubTreeLongReg(Expr *_expr, int longIdx); virtual Expr *insertSubTreeLongReg(Expr *_expr, int longIdx);
virtual bool xClear(rICODE range_to_check, iICODE lastBBinst, const LOCAL_ID &locId); virtual bool xClear(rICODE range_to_check, iICODE lastBBinst, const LOCAL_ID &locId);
protected:
eReg otherLongRegi (eReg regi, int idx, LOCAL_ID *locTbl);
}; };
struct GlobalVariable : public AstIdent struct GlobalVariable : public AstIdent
{ {
@ -272,7 +269,7 @@ struct Constant : public AstIdent
} }
QString walkCondExpr(Function *pProc, int *numLoc) const; QString walkCondExpr(Function *pProc, int *numLoc) const;
int hlTypeSize(Function *pproc) const; int hlTypeSize(Function *pproc) const;
hlType expType(Function *pproc) const; hlType expType(Function *pproc) const { return TYPE_CONST; }
}; };
struct FuncNode : public AstIdent struct FuncNode : public AstIdent
{ {

View File

@ -100,7 +100,5 @@ QString writeJcondInv(HLTYPE, Function *, int *);
/* Exported funcions from locident.c */ /* Exported funcions from locident.c */
bool checkLongEq(LONG_STKID_TYPE, iICODE, int, Function *, Assignment &asgn, LLInst &atOffset); bool checkLongEq(LONG_STKID_TYPE, iICODE, int, Function *, Assignment &asgn, LLInst &atOffset);
bool checkLongRegEq(LONGID_TYPE, iICODE, int, Function *, Assignment &asgn, LLInst &); bool checkLongRegEq(LONGID_TYPE, iICODE, int, Function *, Assignment &asgn, LLInst &);
eReg otherLongRegi(eReg, int, LOCAL_ID *);
extern const char *indentStr(int level); extern const char *indentStr(int level);

View File

@ -96,10 +96,9 @@ protected:
LONGID_TYPE m_longId; /* For TYPE_LONG_(UN)SIGN registers */ LONGID_TYPE m_longId; /* For TYPE_LONG_(UN)SIGN registers */
public: public:
hlType type; /* Probable type */ hlType type; /* Probable type */
bool illegal; /* Boolean: not a valid field any more */
//std::vector<iICODE> idx;
IDX_ARRAY idx; /* Index into icode array (REG_FRAME only) */ IDX_ARRAY idx; /* Index into icode array (REG_FRAME only) */
frameType loc; /* Frame location */ frameType loc; /* Frame location */
bool illegal; /* Boolean: not a valid field any more */
bool hasMacro; /* Identifier requires a macro */ bool hasMacro; /* Identifier requires a macro */
char macro[10]; /* Macro for this identifier */ char macro[10]; /* Macro for this identifier */
QString name; /* Identifier's name */ QString name; /* Identifier's name */
@ -143,6 +142,8 @@ public:
sprintf (buf, "loc%d", i); sprintf (buf, "loc%d", i);
name=buf; name=buf;
} }
bool isLongRegisterPair() const { return (loc == REG_FRAME) and isLong();}
eReg getPairedRegister(eReg first) const;
}; };
struct LOCAL_ID struct LOCAL_ID
@ -174,6 +175,7 @@ public:
void processTargetIcode(ICODE & picode, int &numHlIcodes, ICODE & ticode, bool isLong) const; void processTargetIcode(ICODE & picode, int &numHlIcodes, ICODE & ticode, bool isLong) const;
void forwardSubs(Expr *lhs, Expr *rhs, ICODE & picode, ICODE & ticode, int &numHlIcodes) const; void forwardSubs(Expr *lhs, Expr *rhs, ICODE & picode, ICODE & ticode, int &numHlIcodes) const;
AstIdent *createId(const ID *retVal, iICODE ix_); AstIdent *createId(const ID *retVal, iICODE ix_);
eReg getPairedRegisterAt(int idx,eReg first) const;
}; };

View File

@ -850,26 +850,12 @@ Expr *AstIdent::performLongRemoval(eReg regi, LOCAL_ID *locId)
if (ident.idType == LONG_VAR) if (ident.idType == LONG_VAR)
{ {
otherRegi = otherLongRegi (regi, ident.idNode.longIdx, locId); otherRegi = locId->getPairedRegisterAt(ident.idNode.longIdx,regi);
delete this; delete this;
return new RegisterNode(locId->newByteWordReg(TYPE_WORD_SIGN,otherRegi),WORD_REG,locId); return new RegisterNode(locId->newByteWordReg(TYPE_WORD_SIGN,otherRegi),WORD_REG,locId);
} }
return this; return this;
} }
eReg AstIdent::otherLongRegi (eReg regi, int idx, LOCAL_ID *locTbl)
{
ID *id = &locTbl->id_arr[idx];
if ((id->loc == REG_FRAME) and ((id->type == TYPE_LONG_SIGN) or
(id->type == TYPE_LONG_UNSIGN)))
{
if (id->longId().h() == regi)
return (id->longId().l());
else if (id->longId().l() == regi)
return (id->longId().h());
}
return rUNDEF; // Cristina: please check this!
}
QString Constant::walkCondExpr(Function *, int *) const QString Constant::walkCondExpr(Function *, int *) const
{ {
@ -884,10 +870,7 @@ int Constant::hlTypeSize(Function *) const
return kte.size; return kte.size;
} }
hlType Constant::expType(Function *pproc) const
{
return TYPE_CONST;
}
QString FuncNode::walkCondExpr(Function *pProc, int *numLoc) const QString FuncNode::walkCondExpr(Function *pProc, int *numLoc) const
{ {

View File

@ -10,6 +10,8 @@
#include "msvc_fixes.h" #include "msvc_fixes.h"
#include <cstring> #include <cstring>
#include <QtCore/QDebug>
static const int LOCAL_ID_DELTA = 25; static const int LOCAL_ID_DELTA = 25;
static const int IDX_ARRAY_DELTA = 5; static const int IDX_ARRAY_DELTA = 5;
@ -57,6 +59,14 @@ ID::ID(hlType t, const LONGGLB_TYPE &s) : type(t),illegal(false)
assert((t==TYPE_LONG_SIGN) or (t==TYPE_LONG_UNSIGN)); assert((t==TYPE_LONG_SIGN) or (t==TYPE_LONG_UNSIGN));
} }
eReg ID::getPairedRegister(eReg first) const {
if (longId().h() == first)
return (longId().l());
else if (longId().l() == first)
return (longId().h());
return rUNDEF;
}
/* Creates a new identifier node of type t and returns it. /* Creates a new identifier node of type t and returns it.
* Arguments: locSym : local long symbol table * Arguments: locSym : local long symbol table
@ -174,7 +184,7 @@ int LOCAL_ID::newLongReg(hlType t, const LONGID_TYPE &longT, iICODE ix_)
for (idx = 0; idx < id_arr.size(); idx++) for (idx = 0; idx < id_arr.size(); idx++)
{ {
ID &entry(id_arr[idx]); ID &entry(id_arr[idx]);
if(not entry.isLong() or (entry.loc != REG_FRAME)) if(not entry.isLongRegisterPair())
continue; continue;
if (/*(locSym->id[idx].type == t) and Not checking type */ if (/*(locSym->id[idx].type == t) and Not checking type */
(entry.longId().h() == regH) and (entry.longId().h() == regH) and
@ -222,7 +232,7 @@ int LOCAL_ID::newLongGlb(int16_t seg, int16_t offH, int16_t offL,hlType t)
printf("%d",t); printf("%d",t);
/* Not in the table, create new identifier */ /* Not in the table, create new identifier */
id_arr.emplace_back(t, LONGGLB_TYPE(seg,offH,offL)); id_arr.emplace_back(t, LONGGLB_TYPE(seg,offH,offL));
return (id_arr.size() - 1); return id_arr.size() - 1;
} }
@ -232,10 +242,8 @@ int LOCAL_ID::newLongGlb(int16_t seg, int16_t offH, int16_t offL,hlType t)
* TYPE_LONG_(UN)SIGN and returns the index to this new entry. */ * TYPE_LONG_(UN)SIGN and returns the index to this new entry. */
int LOCAL_ID::newLongIdx( int16_t seg, int16_t offH, int16_t offL,uint8_t regi, hlType t) int LOCAL_ID::newLongIdx( int16_t seg, int16_t offH, int16_t offL,uint8_t regi, hlType t)
{ {
size_t idx;
/* Check for entry in the table */ /* Check for entry in the table */
for (idx = 0; idx < id_arr.size(); idx++) for (size_t idx = 0; idx < id_arr.size(); idx++)
{ {
if (/*(locSym->id[idx].type == t) and Not checking type */ if (/*(locSym->id[idx].type == t) and Not checking type */
(id_arr[idx].id.longGlb.seg == seg) and (id_arr[idx].id.longGlb.seg == seg) and
@ -247,8 +255,7 @@ int LOCAL_ID::newLongIdx( int16_t seg, int16_t offH, int16_t offL,uint8_t regi,
/* Not in the table, create new identifier */ /* Not in the table, create new identifier */
id_arr.emplace_back(t,LONGGLB_TYPE(seg,offH,offL,regi)); id_arr.emplace_back(t,LONGGLB_TYPE(seg,offH,offL,regi));
idx = id_arr.size() - 1; return id_arr.size() - 1;
return (idx);
} }
@ -326,7 +333,7 @@ int LOCAL_ID::newLong(opLoc sd, iICODE pIcode, hlFirst f, iICODE ix,operDu du, L
else /* (pm->regi >= INDEXBASE and pm->off = 0) => indexed and no off */ else /* (pm->regi >= INDEXBASE and pm->off = 0) => indexed and no off */
printf ("long not supported, idx and no off\n"); printf ("long not supported, idx and no off\n");
return (idx); return idx;
} }
@ -423,25 +430,19 @@ bool checkLongRegEq (LONGID_TYPE longId, iICODE pIcode, int i,
return false; return false;
} }
/* Given an index into the local identifier table for a long register /* Given an index into the local identifier table for a long register
* variable, determines whether regi is the high or low part, and returns * variable, determines whether regi is the high or low part, and returns
* the other part */ * the other part */
eReg otherLongRegi (eReg regi, int idx, LOCAL_ID *locTbl) eReg LOCAL_ID::getPairedRegisterAt(int idx,eReg regi) const
{ {
ID *id; eReg res=rUNDEF; // Cristina: please check this!
const ID *id = &id_arr[idx];
id = &locTbl->id_arr[idx]; if (id->isLongRegisterPair())
if ((id->loc == REG_FRAME) and ((id->type == TYPE_LONG_SIGN) or
(id->type == TYPE_LONG_UNSIGN)))
{ {
if (id->longId().h() == regi) res = id->getPairedRegister(regi);
return (id->longId().l());
else if (id->longId().l() == regi)
return (id->longId().h());
} }
return rUNDEF; // Cristina: please check this! qWarning() << "Cannot find paired register";
return res;
} }