X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fds390%2Fgen.c;h=99dba5b475767aa9516308518a7a4564bd8d78f1;hb=ed70c6e0de82527c2ee28c9c52a5eaf1b8f51650;hp=129900af02a4545892cca3834652377a393108da;hpb=a5a286c47796b77807a0f0c12c1a3d1c447435a8;p=fw%2Fsdcc diff --git a/src/ds390/gen.c b/src/ds390/gen.c index 129900af..99dba5b4 100644 --- a/src/ds390/gen.c +++ b/src/ds390/gen.c @@ -438,6 +438,72 @@ pointerCode (sym_link * etype) } +/*-----------------------------------------------------------------*/ +/* leftRightUseAcc - returns size of accumulator use by operands */ +/*-----------------------------------------------------------------*/ +static int +leftRightUseAcc(iCode *ic) +{ + operand *op; + int size; + int accuseSize = 0; + int accuse = 0; + + if (!ic) + { + werror (E_INTERNAL_ERROR, __FILE__, __LINE__, + "null iCode pointer"); + return 0; + } + + if (ic->op == IFX) + { + op = IC_COND (ic); + if (IS_SYMOP (op) && OP_SYMBOL (op) && OP_SYMBOL (op)->accuse) + { + accuse = 1; + size = getSize (OP_SYMBOL (op)->type); + if (size>accuseSize) + accuseSize = size; + } + } + else if (ic->op == JUMPTABLE) + { + op = IC_JTCOND (ic); + if (IS_SYMOP (op) && OP_SYMBOL (op) && OP_SYMBOL (op)->accuse) + { + accuse = 1; + size = getSize (OP_SYMBOL (op)->type); + if (size>accuseSize) + accuseSize = size; + } + } + else + { + op = IC_LEFT (ic); + if (IS_SYMOP (op) && OP_SYMBOL (op) && OP_SYMBOL (op)->accuse) + { + accuse = 1; + size = getSize (OP_SYMBOL (op)->type); + if (size>accuseSize) + accuseSize = size; + } + op = IC_RIGHT (ic); + if (IS_SYMOP (op) && OP_SYMBOL (op) && OP_SYMBOL (op)->accuse) + { + accuse = 1; + size = getSize (OP_SYMBOL (op)->type); + if (size>accuseSize) + accuseSize = size; + } + } + + if (accuseSize) + return accuseSize; + else + return accuse; +} + /*-----------------------------------------------------------------*/ /* aopForSym - for a true symbol */ /*-----------------------------------------------------------------*/ @@ -446,6 +512,7 @@ aopForSym (iCode * ic, symbol * sym, bool result, bool useDP2) { asmop *aop; memmap *space = SPEC_OCLS (sym->etype); + int accuse = leftRightUseAcc (ic); /* if already has one */ if (sym->aop) @@ -467,10 +534,10 @@ aopForSym (iCode * ic, symbol * sym, bool result, bool useDP2) if (sym->onStack) { - if (_G.accInUse) + if (_G.accInUse || accuse) emitcode ("push", "acc"); - if (_G.bInUse) + if (_G.bInUse || (accuse>1)) emitcode ("push", "b"); emitcode ("mov", "a,_bp"); @@ -481,10 +548,10 @@ aopForSym (iCode * ic, symbol * sym, bool result, bool useDP2) emitcode ("mov", "%s,a", aop->aopu.aop_ptr->name); - if (_G.bInUse) + if (_G.bInUse || (accuse>1)) emitcode ("pop", "b"); - if (_G.accInUse) + if (_G.accInUse || accuse) emitcode ("pop", "acc"); } else @@ -543,10 +610,10 @@ aopForSym (iCode * ic, symbol * sym, bool result, bool useDP2) emitcode("mov","dps,#0"); } } else { - if (_G.accInUse) + if (_G.accInUse || accuse) emitcode ("push", "acc"); - if (_G.bInUse) + if (_G.bInUse || (accuse>1)) emitcode ("push", "b"); emitcode ("mov", "a,_bpx"); @@ -573,10 +640,10 @@ aopForSym (iCode * ic, symbol * sym, bool result, bool useDP2) emitcode ("mov", "dpl,b"); } - if (_G.bInUse) + if (_G.bInUse || (accuse>1)) emitcode ("pop", "b"); - if (_G.accInUse) + if (_G.accInUse || accuse) emitcode ("pop", "acc"); } sym->aop = aop = newAsmop ((short) (useDP2 ? AOP_DPTR2 : AOP_DPTR)); @@ -602,14 +669,14 @@ aopForSym (iCode * ic, symbol * sym, bool result, bool useDP2) } /* special case for a function */ - if (IS_FUNC (sym->type)) + if (IS_FUNC (sym->type) && !(sym->isitmp)) { sym->aop = aop = newAsmop (AOP_IMMD); - aop->aopu.aop_immd.aop_immd1 = Safe_strdup(sym->rname); + aop->aopu.aop_immd.aop_immd1 = Safe_strdup(sym->rname); aop->size = FPTRSIZE; return aop; } - + /* only remaining is far space */ /* in which case DPTR gets the address */ sym->aop = aop = newAsmop ((short) (useDP2 ? AOP_DPTR2 : AOP_DPTR)); @@ -939,13 +1006,22 @@ aopOp (operand * op, iCode * ic, bool result, bool useDP2) aop->aopu.dptr = sym->dptr; return ; } - /* else spill location */ - if (sym->usl.spillLoc && getSize(sym->type) != getSize(sym->usl.spillLoc->type)) { - /* force a new aop if sizes differ */ - sym->usl.spillLoc->aop = NULL; - } - sym->aop = op->aop = aop = - aopForSym (ic, sym->usl.spillLoc, result, useDP2); + + if (sym->usl.spillLoc) + { + if (getSize(sym->type) != getSize(sym->usl.spillLoc->type)) + { + /* force a new aop if sizes differ */ + sym->usl.spillLoc->aop = NULL; + } + sym->aop = op->aop = aop = + aopForSym (ic, sym->usl.spillLoc, result, useDP2); + aop->size = getSize (sym->type); + return; + } + + /* else must be a dummy iTemp */ + sym->aop = op->aop = aop = newAsmop (AOP_DUMMY); aop->size = getSize (sym->type); return; } @@ -1115,6 +1191,8 @@ aopGet (asmop *aop, /* depending on type */ switch (aop->type) { + case AOP_DUMMY: + return zero; case AOP_R0: case AOP_R1: @@ -1316,6 +1394,10 @@ aopPut (asmop * aop, char *s, int offset) /* depending on where it is ofcourse */ switch (aop->type) { + case AOP_DUMMY: + MOVA (s); /* read s in case it was volatile */ + break; + case AOP_DIR: if (offset) { @@ -1607,47 +1689,6 @@ reAdjustPreg (asmop * aop) emitcode("nop", "; workaround for DS80C390 div bug."); \ } -/*-----------------------------------------------------------------*/ -/* genNotFloat - generates not for float operations */ -/*-----------------------------------------------------------------*/ -static void -genNotFloat (operand * op, operand * res) -{ - int size, offset; - symbol *tlbl; - - D (emitcode (";", "genNotFloat ");); - - /* we will put 127 in the first byte of - the result */ - aopPut (AOP (res), "#127", 0); - size = AOP_SIZE (op) - 1; - offset = 1; - - _startLazyDPSEvaluation (); - MOVA(aopGet(op->aop, offset++, FALSE, FALSE, NULL)); - - while (size--) - { - emitcode ("orl", "a,%s", - aopGet (op->aop, - offset++, FALSE, FALSE, - DP2_RESULT_REG)); - } - _endLazyDPSEvaluation (); - - tlbl = newiTempLabel (NULL); - aopPut (res->aop, one, 1); - emitcode ("jz", "!tlabel", (tlbl->key + 100)); - aopPut (res->aop, zero, 1); - emitcode ("", "!tlabeldef", (tlbl->key + 100)); - - size = res->aop->size - 2; - offset = 2; - /* put zeros in the rest */ - while (size--) - aopPut (res->aop, zero, offset++); -} /*-----------------------------------------------------------------*/ /* opIsGptr: returns non-zero if the passed operand is */ @@ -1797,7 +1838,6 @@ static void genNot (iCode * ic) { symbol *tlbl; - sym_link *optype = operandType (IC_LEFT (ic)); D (emitcode (";", "genNot ");); @@ -1814,13 +1854,6 @@ genNot (iCode * ic) goto release; } - /* if type float then do float */ - if (IS_FLOAT (optype)) - { - genNotFloat (IC_LEFT (ic), IC_RESULT (ic)); - goto release; - } - toBoolean (IC_LEFT (ic)); tlbl = newiTempLabel (NULL); @@ -2045,8 +2078,8 @@ saveRegisters (iCode * lic) /* if the registers have been saved already then do nothing */ - if (ic->regsSaved || - (IS_SYMOP(IC_LEFT(ic)) && IFFUNC_ISNAKED(OP_SYM_TYPE(IC_LEFT(ic))))) + if (ic->regsSaved + || (IS_SYMOP(IC_LEFT(ic)) && IFFUNC_ISNAKED(OP_SYM_TYPE(IC_LEFT(ic))) && !TARGET_IS_DS400) ) return ; /* special case if DPTR alive across a function call then must save it @@ -2549,7 +2582,7 @@ genCall (iCode * ic) the same register bank then we need to save the destination registers on the stack */ dtype = operandType (IC_LEFT (ic)); - if (currFunc && dtype && !IFFUNC_ISNAKED(dtype) && + if (currFunc && dtype && (!IFFUNC_ISNAKED(dtype) || TARGET_IS_DS400) && (FUNC_REGBANK (currFunc->type) != FUNC_REGBANK (dtype)) && IFFUNC_ISISR (currFunc->type)) { @@ -2705,7 +2738,7 @@ genPcall (iCode * ic) the same register bank then we need to save the destination registers on the stack */ dtype = operandType (IC_LEFT (ic)); - if (currFunc && dtype && !IFFUNC_ISNAKED(dtype) && + if (currFunc && dtype && (!IFFUNC_ISNAKED(dtype) || TARGET_IS_DS400) && IFFUNC_ISISR (currFunc->type) && (FUNC_REGBANK (currFunc->type) != FUNC_REGBANK (dtype))) { saveRBank (FUNC_REGBANK (dtype), ic, TRUE); @@ -2879,9 +2912,6 @@ genFunction (iCode * ic) if (options.stack_probe) emitcode ("lcall","__stack_probe"); - /* if critical function then turn interrupts off */ - if (IFFUNC_ISCRITICAL (ftype)) - emitcode ("clr", "ea"); /* here we need to generate the equates for the register bank if required */ @@ -3160,6 +3190,14 @@ genFunction (iCode * ic) emitcode ("add", "a,#!constbyte", ((char) sym->xstack & 0xff)); emitcode ("mov", "_spx,a"); } + + /* if critical function then turn interrupts off */ + if (IFFUNC_ISCRITICAL (ftype)) + { + emitcode ("mov", "c,ea"); + emitcode ("push", "psw"); /* save old ea via c in psw */ + emitcode ("clr", "ea"); + } } @@ -3179,6 +3217,12 @@ genEndFunction (iCode * ic) return; } + if (IFFUNC_ISCRITICAL (sym->type)) + { + emitcode ("pop", "psw"); /* restore ea via c in psw */ + emitcode ("mov", "ea,c"); + } + if ((IFFUNC_ISREENT (sym->type) || options.stackAuto) && (sym->stack || FUNC_HASSTACKPARM(sym->type))) { @@ -3323,9 +3367,6 @@ genEndFunction (iCode * ic) if (!inExcludeList ("acc")) emitcode ("pop", "acc"); - if (IFFUNC_ISCRITICAL (sym->type)) - emitcode ("setb", "ea"); - /* if debug then send end of function */ if (options.debug && currFunc) { _G.debugLine = 1; @@ -3343,9 +3384,6 @@ genEndFunction (iCode * ic) } else { - if (IFFUNC_ISCRITICAL (sym->type)) - emitcode ("setb", "ea"); - if (IFFUNC_CALLEESAVES(sym->type)) { int i; @@ -4000,7 +4038,7 @@ genPlus (iCode * ic) if ( AOP_IS_STR(IC_LEFT(ic)) && isOperandLiteral(IC_RIGHT(ic)) && OP_SYMBOL(IC_RESULT(ic))->ruonly) { aopOp (IC_RIGHT (ic), ic, TRUE, FALSE); - size = floatFromVal (AOP (IC_RIGHT(ic))->aopu.aop_lit); + size = (int)floatFromVal (AOP (IC_RIGHT(ic))->aopu.aop_lit); if (size <= 9) { while (size--) emitcode ("inc","dptr"); } else { @@ -4586,7 +4624,7 @@ genMultOneByte (operand * left, /* if literal */ if (AOP_TYPE(right)==AOP_LIT) { - signed char val=floatFromVal (AOP (right)->aopu.aop_lit); + signed char val=(signed char)floatFromVal (AOP (right)->aopu.aop_lit); /* AND literal negative */ if ((int) val < 0) { emitcode ("cpl", "F0"); // complement sign flag @@ -4667,7 +4705,7 @@ static void genMultTwoByte (operand *left, operand *right, if (!umult) { emitcode("clr","F0"); if (AOP_TYPE(right) == AOP_LIT) { - int val=floatFromVal (AOP (right)->aopu.aop_lit); + int val=(int)floatFromVal (AOP (right)->aopu.aop_lit); if (val < 0) { emitcode("setb","F0"); val = -val; @@ -5010,7 +5048,7 @@ static void genDivTwoByte (operand *left, operand *right, /* load up MB with right */ if (!umult) { if (AOP_TYPE(right) == AOP_LIT) { - int val=floatFromVal (AOP (right)->aopu.aop_lit); + int val=(int)floatFromVal (AOP (right)->aopu.aop_lit); if (val < 0) { lbl = newiTempLabel(NULL); emitcode ("jbc","F0,!tlabel",lbl->key+100); @@ -5267,7 +5305,7 @@ static void genModTwoByte (operand *left, operand *right, /* load up MB with right */ if (!umult) { if (AOP_TYPE(right) == AOP_LIT) { - int val=floatFromVal (AOP (right)->aopu.aop_lit); + int val=(int)floatFromVal (AOP (right)->aopu.aop_lit); if (val < 0) { val = -val; } @@ -8644,7 +8682,7 @@ genRightShiftLiteral (operand * left, && (shCount < (size * 8)) && (size != 1) && (size != 2) - /* && (size != 4) in a minute... */) + && (size != 4)) { D(emitcode (";", "genRightShiftLiteral wimping out");); return FALSE; @@ -8972,116 +9010,148 @@ release: freeAsmop (result, NULL, ic, TRUE); } + /*-----------------------------------------------------------------*/ -/* genUnpackBits - generates code for unpacking bits */ +/* emitPtrByteGet - emits code to get a byte into A through a */ +/* pointer register (R0, R1, or DPTR). The */ +/* original value of A can be preserved in B. */ /*-----------------------------------------------------------------*/ static void -genUnpackBits (operand * result, char *rname, int ptype) +emitPtrByteGet (char *rname, int p_type, bool preserveAinB) { - int shCnt; - int rlen; - sym_link *etype; - int offset = 0; - - D (emitcode (";", "genUnpackBits ");); - - etype = getSpec (operandType (result)); - - /* read the first byte */ - switch (ptype) + switch (p_type) { - - case POINTER: case IPOINTER: + case POINTER: + if (preserveAinB) + emitcode ("mov", "b,a"); emitcode ("mov", "a,@%s", rname); break; case PPOINTER: + if (preserveAinB) + emitcode ("mov", "b,a"); emitcode ("movx", "a,@%s", rname); break; - + case FPOINTER: + if (preserveAinB) + emitcode ("mov", "b,a"); emitcode ("movx", "a,@dptr"); break; case CPOINTER: + if (preserveAinB) + emitcode ("mov", "b,a"); emitcode ("clr", "a"); emitcode ("movc", "a,@a+dptr"); break; case GPOINTER: + if (preserveAinB) + { + emitcode ("push", "b"); + emitcode ("push", "acc"); + } emitcode ("lcall", "__gptrget"); + if (preserveAinB) + emitcode ("pop", "b"); break; } +} - /* if we have bitdisplacement then it fits */ - /* into this byte completely or if length is */ - /* less than a byte */ - if (((shCnt = SPEC_BSTR (etype)) != 0) || (SPEC_BLEN (etype) <= 8)) +/*-----------------------------------------------------------------*/ +/* emitPtrByteSet - emits code to set a byte from src through a */ +/* pointer register (R0, R1, or DPTR). */ +/*-----------------------------------------------------------------*/ +static void +emitPtrByteSet (char *rname, int p_type, char *src) +{ + switch (p_type) { + case IPOINTER: + case POINTER: + if (*src=='@') + { + MOVA (src); + emitcode ("mov", "@%s,a", rname); + } + else + emitcode ("mov", "@%s,%s", rname, src); + break; - /* shift right acc */ - AccRsh (shCnt); + case PPOINTER: + MOVA (src); + emitcode ("movx", "@%s,a", rname); + break; + + case FPOINTER: + MOVA (src); + emitcode ("movx", "@dptr,a"); + break; - emitcode ("anl", "a,#!constbyte", - ((unsigned char) -1) >> (8 - SPEC_BLEN (etype))); - aopPut (AOP (result), "a", offset); - return; + case GPOINTER: + MOVA (src); + emitcode ("lcall", "__gptrput"); + break; } +} - /* bit field did not fit in a byte */ - rlen = SPEC_BLEN (etype) - 8; - aopPut (AOP (result), "a", offset++); - - while (1) - { - - switch (ptype) - { - case POINTER: - case IPOINTER: - emitcode ("inc", "%s", rname); - emitcode ("mov", "a,@%s", rname); - break; - - case PPOINTER: - emitcode ("inc", "%s", rname); - emitcode ("movx", "a,@%s", rname); - break; - - case FPOINTER: - emitcode ("inc", "dptr"); - emitcode ("movx", "a,@dptr"); - break; +/*-----------------------------------------------------------------*/ +/* genUnpackBits - generates code for unpacking bits */ +/*-----------------------------------------------------------------*/ +static void +genUnpackBits (operand * result, char *rname, int ptype) +{ + int offset = 0; /* result byte offset */ + int rsize; /* result size */ + int rlen = 0; /* remaining bitfield length */ + sym_link *etype; /* bitfield type information */ + int blen; /* bitfield length */ + int bstr; /* bitfield starting bit within byte */ - case CPOINTER: - emitcode ("clr", "a"); - emitcode ("inc", "dptr"); - emitcode ("movc", "a,@a+dptr"); - break; + D(emitcode ("; genUnpackBits","")); - case GPOINTER: - emitcode ("inc", "dptr"); - emitcode ("lcall", "__gptrget"); - break; - } - - rlen -= 8; - /* if we are done */ - if (rlen < 8) - break; + etype = getSpec (operandType (result)); + rsize = getSize (operandType (result)); + blen = SPEC_BLEN (etype); + bstr = SPEC_BSTR (etype); + /* If the bitfield length is less than a byte */ + if (blen < 8) + { + emitPtrByteGet (rname, ptype, FALSE); + AccRsh (bstr); + emitcode ("anl", "a,#!constbyte", ((unsigned char) -1) >> (8 - blen)); aopPut (AOP (result), "a", offset++); + goto finish; + } + /* Bit field did not fit in a byte. Copy all + but the partial byte at the end. */ + for (rlen=blen;rlen>=8;rlen-=8) + { + emitPtrByteGet (rname, ptype, FALSE); + aopPut (AOP (result), "a", offset++); + if (rlen>8) + emitcode ("inc", "%s", rname); } + /* Handle the partial byte at the end */ if (rlen) { - emitcode ("anl", "a,#!constbyte", ((unsigned char) -1) >> (rlen)); - aopPut (AOP (result), "a", offset); + emitPtrByteGet (rname, ptype, FALSE); + emitcode ("anl", "a,#!constbyte", ((unsigned char) -1) >> (8-rlen)); + aopPut (AOP (result), "a", offset++); } - return; +finish: + if (offset < rsize) + { + rsize -= offset; + while (rsize--) + aopPut (AOP (result), zero, offset++); + } } @@ -9760,162 +9830,125 @@ genPackBits (sym_link * etype, operand * right, char *rname, int p_type) { - int offset = 0; - int rLen; - int blen, bstr; - char *l; + int offset = 0; /* source byte offset */ + int rlen = 0; /* remaining bitfield length */ + int blen; /* bitfield length */ + int bstr; /* bitfield starting bit within byte */ + int litval; /* source literal value (if AOP_LIT) */ + unsigned char mask; /* bitmask within current byte */ + + D(emitcode ("; genPackBits","")); blen = SPEC_BLEN (etype); bstr = SPEC_BSTR (etype); - MOVA (aopGet (AOP (right), offset++, FALSE, FALSE, NULL)); - - /* if the bit lenth is less than or */ - /* it exactly fits a byte then */ - if (SPEC_BLEN (etype) <= 8) + /* If the bitfield length is less than a byte */ + if (blen < 8) { - /* shift left acc */ - AccLsh (SPEC_BSTR (etype)); - - if (SPEC_BLEN (etype) < 8) - { /* if smaller than a byte */ + mask = ((unsigned char) (0xFF << (blen + bstr)) | + (unsigned char) (0xFF >> (8 - bstr))); + if (AOP_TYPE (right) == AOP_LIT) + { + /* Case with a bitfield length <8 and literal source + */ + litval = (int) floatFromVal (AOP (right)->aopu.aop_lit); + litval <<= bstr; + litval &= (~mask) & 0xff; + emitPtrByteGet (rname, p_type, FALSE); + if ((mask|litval)!=0xff) + emitcode ("anl","a,#!constbyte", mask); + if (litval) + emitcode ("orl","a,#!constbyte", litval); + } + else + { + if ((blen==1) && (p_type!=GPOINTER)) + { + /* Case with a bitfield length == 1 and no generic pointer + */ + if (AOP_TYPE (right) == AOP_CRY) + emitcode ("mov", "c,%s", AOP(right)->aopu.aop_dir); + else + { + MOVA (aopGet (AOP (right), 0, FALSE, FALSE, NULL)); + emitcode ("rrc","a"); + } + emitPtrByteGet (rname, p_type, FALSE); + emitcode ("mov","acc.%d,c",bstr); + } + else + { + /* Case with a bitfield length < 8 and arbitrary source + */ + MOVA (aopGet (AOP (right), 0, FALSE, FALSE, NULL)); + /* shift and mask source value */ + AccLsh (bstr); + emitcode ("anl", "a,#!constbyte", (~mask) & 0xff); + + /* transfer A to B and get next byte */ + emitPtrByteGet (rname, p_type, TRUE); + + emitcode ("anl", "a,#!constbyte", mask); + emitcode ("orl", "a,b"); + if (p_type == GPOINTER) + emitcode ("pop", "b"); + } + } - switch (p_type) - { - case POINTER: - emitcode ("mov", "b,a"); - emitcode ("mov", "a,@%s", rname); - break; - - case FPOINTER: - emitcode ("mov", "b,a"); - emitcode ("movx", "a,@dptr"); - break; - - case GPOINTER: - emitcode ("push", "b"); - emitcode ("push", "acc"); - emitcode ("lcall", "__gptrget"); - emitcode ("pop", "b"); - break; - } - - emitcode ("anl", "a,#!constbyte", (unsigned char) - ((unsigned char) (0xFF << (blen + bstr)) | - (unsigned char) (0xFF >> (8 - bstr)))); - emitcode ("orl", "a,b"); - if (p_type == GPOINTER) - emitcode ("pop", "b"); - } + emitPtrByteSet (rname, p_type, "a"); + return; } - switch (p_type) + /* Bit length is greater than 7 bits. In this case, copy */ + /* all except the partial byte at the end */ + for (rlen=blen;rlen>=8;rlen-=8) { - case POINTER: - emitcode ("mov", "@%s,a", rname); - break; - - case FPOINTER: - emitcode ("movx", "@dptr,a"); - break; - - case GPOINTER: - emitcode ("lcall", "__gptrput"); - break; + emitPtrByteSet (rname, p_type, + aopGet (AOP (right), offset++, FALSE, TRUE, NULL) ); + if (rlen>8) + emitcode ("inc", "%s", rname); } - /* if we r done */ - if (SPEC_BLEN (etype) <= 8) - return; - - emitcode ("inc", "%s", rname); - rLen = SPEC_BLEN (etype); - - /* now generate for lengths greater than one byte */ - while (1) - { - - l = aopGet (AOP (right), offset++, FALSE, TRUE, NULL); - - rLen -= 8; - if (rLen < 8) - break; - - switch (p_type) - { - case POINTER: - if (*l == '@') - { - MOVA (l); - emitcode ("mov", "@%s,a", rname); - } - else - emitcode ("mov", "@%s,%s", rname, l); - break; - - case FPOINTER: - MOVA (l); - emitcode ("movx", "@dptr,a"); - break; - - case GPOINTER: - MOVA (l); - emitcode ("lcall", "__gptrput"); - break; - } - emitcode ("inc", "%s", rname); - } - - MOVA (l); - - /* last last was not complete */ - if (rLen) + /* If there was a partial byte at the end */ + if (rlen) { - /* save the byte & read byte */ - switch (p_type) - { - case POINTER: - emitcode ("mov", "b,a"); - emitcode ("mov", "a,@%s", rname); - break; - - case FPOINTER: - emitcode ("mov", "b,a"); - emitcode ("movx", "a,@dptr"); - break; - - case GPOINTER: - emitcode ("push", "b"); - emitcode ("push", "acc"); - emitcode ("lcall", "__gptrget"); - emitcode ("pop", "b"); - break; - } - - emitcode ("anl", "a,#!constbyte", ((unsigned char) -1 << rLen)); - emitcode ("orl", "a,b"); + mask = (((unsigned char) -1 << rlen) & 0xff); + + if (AOP_TYPE (right) == AOP_LIT) + { + /* Case with partial byte and literal source + */ + litval = (int) floatFromVal (AOP (right)->aopu.aop_lit); + litval >>= (blen-rlen); + litval &= (~mask) & 0xff; + emitPtrByteGet (rname, p_type, FALSE); + if ((mask|litval)!=0xff) + emitcode ("anl","a,#!constbyte", mask); + if (litval) + emitcode ("orl","a,#!constbyte", litval); + } + else + { + /* Case with partial byte and arbitrary source + */ + MOVA (aopGet (AOP (right), offset++, FALSE, FALSE, NULL)); + emitcode ("anl", "a,#!constbyte", (~mask) & 0xff); + + /* transfer A to B and get next byte */ + emitPtrByteGet (rname, p_type, TRUE); + + emitcode ("anl", "a,#!constbyte", mask); + emitcode ("orl", "a,b"); + if (p_type == GPOINTER) + emitcode ("pop", "b"); + } + emitPtrByteSet (rname, p_type, "a"); } - if (p_type == GPOINTER) - emitcode ("pop", "b"); - - switch (p_type) - { - - case POINTER: - emitcode ("mov", "@%s,a", rname); - break; +} - case FPOINTER: - emitcode ("movx", "@dptr,a"); - break; - case GPOINTER: - emitcode ("lcall", "__gptrput"); - break; - } -} /*-----------------------------------------------------------------*/ /* genDataPointerSet - remat pointer to data space */ /*-----------------------------------------------------------------*/ @@ -11017,8 +11050,8 @@ genCast (iCode * ic) aopOp (result, ic, FALSE, AOP_USESDPTR(right)); /* if the result is a bit */ - // if (AOP_TYPE (result) == AOP_CRY) /* works only for true symbols */ - if (IS_BITVAR(OP_SYMBOL(result)->type)) + if (IS_BITVAR (OP_SYMBOL (result)->type) + && !IS_BITFIELD (OP_SYMBOL (result)->type) ) { /* if the right size is a literal then we know what the value is */ @@ -12604,6 +12637,42 @@ static void genSystemGetCurrentID(iCode *ic,int nparms, operand **parms,char *na } } +/*-----------------------------------------------------------------*/ +/* genDummyRead - generate code for dummy read of volatiles */ +/*-----------------------------------------------------------------*/ +static void +genDummyRead (iCode * ic) +{ + operand *right; + int size, offset; + + D(emitcode("; genDummyRead","")); + + right = IC_RIGHT (ic); + + aopOp (right, ic, FALSE, FALSE); + + /* if the result is a bit */ + if (AOP_TYPE (right) == AOP_CRY) + { + emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir); + goto release; + } + + /* bit variables done */ + /* general case */ + size = AOP_SIZE (right); + offset = 0; + while (size--) + { + MOVA (aopGet (AOP (right), offset, FALSE, FALSE, FALSE)); + offset++; + } + +release: + freeAsmop (right, NULL, ic, TRUE); +} + /*-----------------------------------------------------------------*/ /* genBuiltIn - calls the appropriate function to generating code */ /* for a built in function */ @@ -12973,6 +13042,10 @@ gen390Code (iCode * lic) else addSet (&_G.sendSet, ic); break; + case DUMMY_READ_VOLATILE: + genDummyRead (ic); + break; + #if 0 // obsolete, and buggy for != xdata case ARRAYINIT: genArrayInit(ic);