Пример #1
0
/* 
 Checks if the entry exists in the locSym, if so, returns the idx to this entry; otherwise creates
 a new register identifier node of type TYPE_LONG_(UN)SIGN and returns the index to this new entry.
*/
int newLongRegId(LOCAL_ID *locSym, hlType t, uint8_t regH, uint8_t regL, int ix)
{
    int idx;

    // Check for entry in the table
    for (idx = 0; idx < locSym->csym; idx++) {
        if ((locSym->id[idx].id.longId.h == regH) && (locSym->id[idx].id.longId.l == regL)) {
            // Check for occurrence in the list
            if (inList(&locSym->id[idx].idx, ix))
                return idx;
            else {
                // Insert icode index in list
                insertIdx(&locSym->id[idx].idx, ix);
                return (idx);
            }
        }
    }

    // Not in the table, create new identifier
    newIdent(locSym, t, REG_FRAME);
    insertIdx(&locSym->id[locSym->csym - 1].idx, ix);
    idx = locSym->csym - 1;
    locSym->id[idx].id.longId.h = regH;
    locSym->id[idx].id.longId.l = regL;
    return idx;
}
Пример #2
0
Ident* getFromArray(Ident* id, int i){
  Ident* ident = newIdent();
  ident->size = 1;
  ident->type = strdup(id->type);
  ident->address = id->address + i;
  ident->idName = strdup(id->type);
  return ident;
}
Пример #3
0
Ident* declareVar(char* nm, char* tp, int addr, int sz){
  Ident* id = newIdent();
  id->address = addr;
  id->type = strdup(tp);
  id->idName = strdup(nm);
  id->size = sz;
  return id;
}
Пример #4
0
/*
 Creates a new register identifier node of TYPE_BYTE_(UN)SIGN or TYPE_WORD_(UN)SIGN type.
 Returns the index to this new entry.
*/
int newByteWordRegId(LOCAL_ID *locSym, hlType t, uint8_t regi)
{
    int idx;

    // Check for entry in the table
    for (idx = 0; idx < locSym->csym; idx++) {
        if ((locSym->id[idx].type == t) && (locSym->id[idx].id.regi == regi))
            return idx;
    }

    // Not in table, create new identifier
    newIdent(locSym, t, REG_FRAME);
    idx = locSym->csym - 1;
    locSym->id[idx].id.regi = regi;
    return idx;
}
Пример #5
0
/*
 Creates a new stack identifier node of TYPE_BYTE_(UN)SIGN or TYPE_WORD_(UN)SIGN type.
 Returns the index to this new entry.
*/
int newByteWordStkId(LOCAL_ID *locSym, hlType t, int off, uint8_t regOff)
{
    int idx;

    // Check for entry in the table
    for (idx = 0; idx < locSym->csym; idx++) {
        if ((locSym->id[idx].id.bwId.off == off) && (locSym->id[idx].id.bwId.regOff == regOff))
            return idx;
    }

    // Not in table, create new identifier
    newIdent(locSym, t, STK_FRAME);
    idx = locSym->csym - 1;
    locSym->id[idx].id.bwId.regOff = regOff;
    locSym->id[idx].id.bwId.off = off;
    return idx;
}
Пример #6
0
/*
 Checks if the entry exists in the locSym, if so, returns the idx to this entry; otherwise creates 
 a new global identifier node of type TYPE_LONG_(UN)SIGN and returns the index to this new entry.
*/
static int newLongGlbId(LOCAL_ID *locSym, int16_t seg, int16_t offH, int16_t offL, int ix, hlType t)
{
    int idx;

    // Check for entry in the table
    for (idx = 0; idx < locSym->csym; idx++) {
        if ((locSym->id[idx].id.longGlb.seg == seg) && (locSym->id[idx].id.longGlb.offH == offH) &&
            (locSym->id[idx].id.longGlb.offL == offL))
            return idx;
    }

    // Not in the table, create new identifier
    newIdent(locSym, t, GLB_FRAME);
    idx = locSym->csym - 1;
    locSym->id[idx].id.longGlb.seg = seg;
    locSym->id[idx].id.longGlb.offH = offH;
    locSym->id[idx].id.longGlb.offL = offL;
    return idx;
}
Пример #7
0
/* 
 Checks if the entry exists in the locSym, if so, returns the idx to this entry; otherwise creates
 a new global identifier node of type TYPE_WORD_(UN)SIGN and returns the index to this new entry.

 @locSym: ptr to the local symbol table
 @seg: segment value for global variable
 @off: offset from segment
 @regi: indexed register into global variable
 #ix: index into icode array
 @t: HIGH_LEVEL type
*/
int newIntIdxId(LOCAL_ID *locSym, int16_t seg, int16_t off, uint8_t regi, int ix, hlType t)
{
    int idx;

    // Check for entry in the table
    for (idx = 0; idx < locSym->csym; idx++) {
        if (// (locSym->id[idx].type == t) &&   Not checking type
            (locSym->id[idx].id.bwGlb.seg == seg) && (locSym->id[idx].id.bwGlb.off == off) &&
            (locSym->id[idx].id.bwGlb.regi == regi))
            return idx;
    }

    // Not in the table, create new identifier
    newIdent(locSym, t, GLB_FRAME);
    idx = locSym->csym - 1;
    locSym->id[idx].id.bwGlb.seg = seg;
    locSym->id[idx].id.bwGlb.off = off;
    locSym->id[idx].id.bwGlb.regi = regi;
    return idx;
}
Пример #8
0
/*
 Creates a new stack identifier node of type TYPE_LONG_(UN)SIGN.
 Returns the index to this entry.
*/
int newLongStkId(LOCAL_ID *locSym, hlType t, int offH, int offL)
{
    int idx;

    // Check for entry in the table
    for (idx = 0; idx < locSym->csym; idx++) {
        if ((locSym->id[idx].type == t) && (locSym->id[idx].id.longStkId.offH == offH) &&
            (locSym->id[idx].id.longStkId.offL == offL))
            return idx;
    }

    // Not in the table; flag as invalid offH and offL
    flagByteWordId(locSym, offH);
    flagByteWordId(locSym, offL);

    // Create new identifier
    newIdent(locSym, t, STK_FRAME);
    idx = locSym->csym - 1;
    locSym->id[idx].id.longStkId.offH = offH;
    locSym->id[idx].id.longStkId.offL = offL;
    return idx;
}