Example #1
0
/*
 Returns the index to an appropriate long identifier.

 Note: long constants should be checked first and stored as a long integer number in an expression record.
*/
int newLongId(LOCAL_ID *locSym, opLoc sd, PICODE pIcode, hlFirst f, int ix, operDu du, int off)
{
    int idx = 0;
    PMEM pmH, pmL;

    if (f == LOW_FIRST) {
        pmL = (sd == SRC) ? &pIcode->ll.src : &pIcode->ll.dst;
        pmH = (sd == SRC) ? &(pIcode + off)->ll.src : &(pIcode + off)->ll.dst;
    } else { // HIGH_FIRST
        pmH = (sd == SRC) ? &pIcode->ll.src : &pIcode->ll.dst;
        pmL = (sd == SRC) ? &(pIcode + off)->ll.src : &(pIcode + off)->ll.dst;
    }

    if (pmL->regi == 0) // global variable
        idx = newLongGlbId(locSym, pmH->segValue, pmH->off, pmL->off, ix, TYPE_LONG_SIGN);

    else if (pmL->regi < INDEXBASE) { // register
        idx = newLongRegId(locSym, TYPE_LONG_SIGN, pmH->regi, pmL->regi, ix);
        if (f == HIGH_FIRST)
            setRegDU(pIcode, pmL->regi, du); // low part
        else
            setRegDU(pIcode, pmH->regi, du); // high part
    }

    else if (pmL->off) { // offset
        if ((pmL->seg == rSS) && (pmL->regi == INDEXBASE + 6)) // idx on bp
            idx = newLongStkId(locSym, TYPE_LONG_SIGN, pmH->off, pmL->off);
        else if ((pmL->seg == rDS) && (pmL->regi == INDEXBASE + 7)) { // bx
            // glb var indexed on bx
            idx = newLongIdxId(locSym, pmH->segValue, pmH->off, pmL->off, rBX, ix, TYPE_LONG_SIGN);
            setRegDU(pIcode, rBX, USE);
        } else // idx <> bp, bx
            printf("long not supported, idx <> bp\n");
    }

    else // (pm->regi >= INDEXBASE && pm->off = 0) => indexed && no off
        printf("long not supported, idx && no off\n");

    return idx;
}
Example #2
0
File: PROCS.C Project: 8l/dcc
void newRegArg (PPROC pproc, PICODE picode, PICODE ticode)
/* Updates the argument table by including the register(s) (ie. lhs of
 * picode) and the actual expression (ie. rhs of picode).
 * Note: register(s) are only included once in the table.   */
{ COND_EXPR *lhs;
  PSTKFRAME ps, ts;
  ID *id;
  Int i, tidx;
  boolT regExist;
  condId type;
  PPROC tproc;
  byte regL, regH;		/* Registers involved in arguments */

	/* Flag ticode as having register arguments */
	tproc = ticode->ic.hl.oper.call.proc;
	tproc->flg |= REG_ARGS;

	/* Get registers and index into target procedure's local list */
	ps = ticode->ic.hl.oper.call.args;
	ts = &tproc->args;
	lhs = picode->ic.hl.oper.asgn.lhs;
	type = lhs->expr.ident.idType;
	if (type == REGISTER)
	{
		regL = pproc->localId.id[lhs->expr.ident.idNode.regiIdx].id.regi;
		if (regL < rAL)
			tidx = newByteWordRegId (&tproc->localId, TYPE_WORD_SIGN, regL);
		else
			tidx = newByteWordRegId (&tproc->localId, TYPE_BYTE_SIGN, regL);
	}
	else if (type == LONG_VAR)
	{
		regL = pproc->localId.id[lhs->expr.ident.idNode.longIdx].id.longId.l;
		regH = pproc->localId.id[lhs->expr.ident.idNode.longIdx].id.longId.h;
		tidx = newLongRegId (&tproc->localId, TYPE_LONG_SIGN, regH, regL, 0);
	}

	/* Check if register argument already on the formal argument list */
	regExist = FALSE;
	for (i = 0; i < ts->csym; i++)
	{
		if (type == REGISTER)
		{
			if ((ts->sym[i].regs != NULL) && 
				(ts->sym[i].regs->expr.ident.idNode.regiIdx == tidx))
			{
				regExist = TRUE;
				i = ts->csym;
			}
		}
		else if (type == LONG_VAR)
		{
			if ((ts->sym[i].regs != NULL) && 
				(ts->sym[i].regs->expr.ident.idNode.longIdx == tidx))
			{
				regExist = TRUE;
				i = ts->csym;
			}
		}
	}

	/* Do ts (formal arguments) */
	if (regExist == FALSE)
	{
    	if (ts->csym == ts->alloc) 
    	{
			ts->alloc += 5;
        	ts->sym = allocVar(ts->sym, ts->alloc * sizeof(STKSYM));
    	}
    	sprintf (ts->sym[ts->csym].name, "arg%ld", ts->csym);
		if (type == REGISTER)
		{
			if (regL < rAL)
			{
    			ts->sym[ts->csym].type = TYPE_WORD_SIGN;
    			ts->sym[ts->csym].regs = idCondExpRegIdx (tidx, WORD_REG);
			}
			else
			{
				ts->sym[ts->csym].type = TYPE_BYTE_SIGN;
    			ts->sym[ts->csym].regs = idCondExpRegIdx (tidx, BYTE_REG);
			}
			sprintf (tproc->localId.id[tidx].name, "arg%ld", ts->csym);
		}
		else if (type == LONG_VAR)
		{
    		ts->sym[ts->csym].regs = idCondExpLongIdx (tidx);
    		ts->sym[ts->csym].type = TYPE_LONG_SIGN; 
			sprintf (tproc->localId.id[tidx].name, "arg%ld", ts->csym);
			propLongId (&tproc->localId, regL, regH,
										tproc->localId.id[tidx].name);
		}

		ts->csym++;
		ts->numArgs++;
	}

	/* Do ps (actual arguments) */
    if (ps->csym == ps->alloc) 
    {
        ps->alloc += 5;
        ps->sym = allocVar(ps->sym, ps->alloc * sizeof(STKSYM));
    }
    sprintf (ps->sym[ps->csym].name, "arg%ld", ps->csym);
    ps->sym[ps->csym].actual = picode->ic.hl.oper.asgn.rhs;
    ps->sym[ps->csym].regs = lhs;

	/* Mask off high and low register(s) in picode */
	switch (type) {
	  case REGISTER:	
		id = &pproc->localId.id[lhs->expr.ident.idNode.regiIdx];
		picode->du.def &= maskDuReg[id->id.regi];
		if (id->id.regi < rAL)
    		ps->sym[ps->csym].type = TYPE_WORD_SIGN;
		else
			ps->sym[ps->csym].type = TYPE_BYTE_SIGN;
		break;
	  case LONG_VAR: 
		id = &pproc->localId.id[lhs->expr.ident.idNode.longIdx];
		picode->du.def &= maskDuReg[id->id.longId.h];
		picode->du.def &= maskDuReg[id->id.longId.l];
    	ps->sym[ps->csym].type = TYPE_LONG_SIGN; 
		break;
	}

	ps->csym++;
	ps->numArgs++;
}