X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCicode.c;h=bc3ccc161b9877f681f4abe5d7f1b3253458b7e6;hb=275002aa4adfc706244119c7333ae5c319f3b7d0;hp=ccc9ec6632b69d6d210034047db8d3d043a9beed;hpb=9f27173cb8b5814d638e82497ae1e303a7194b35;p=fw%2Fsdcc diff --git a/src/SDCCicode.c b/src/SDCCicode.c index ccc9ec66..bc3ccc16 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -115,6 +115,26 @@ iCodeTable codeTable[] = {ARRAYINIT, "arrayInit", picGenericOne, NULL}, }; +// this makes it more easy to catch bugs +struct bitVect *OP_DEFS(struct operand *op) { + wassert (IS_SYMOP(op)); + return OP_SYMBOL(op)->defs; +} +struct bitVect *OP_DEFS_SET(struct operand *op, struct bitVect *bv) { + wassert (IS_SYMOP(op)); + OP_SYMBOL(op)->defs=bv; + return bv; +} +struct bitVect *OP_USES(struct operand *op) { + wassert (IS_SYMOP(op)); + return OP_SYMBOL(op)->uses; +} +struct bitVect *OP_USES_SET(struct operand *op, struct bitVect *bv) { + wassert (IS_SYMOP(op)); + OP_SYMBOL(op)->uses=bv; + return bv; +} + /*-----------------------------------------------------------------*/ /* checkConstantRange: check a constant against the type */ /*-----------------------------------------------------------------*/ @@ -224,14 +244,14 @@ printOperand (operand * op, FILE * file) case SYMBOL: #define REGA 1 #ifdef REGA - fprintf (file, "%s [k%d lr%d:%d so:%d]{ ia%d re%d rm%d nos%d ru%d}", /*{ar%d rm%d ru%d p%d a%d u%d i%d au%d k%d ks%d}" , */ + fprintf (file, "%s [k%d lr%d:%d so:%d]{ ia%d re%d rm%d nos%d ru%d dp%d}", /*{ar%d rm%d ru%d p%d a%d u%d i%d au%d k%d ks%d}" , */ (OP_SYMBOL (op)->rname[0] ? OP_SYMBOL (op)->rname : OP_SYMBOL (op)->name), op->key, OP_LIVEFROM (op), OP_LIVETO (op), OP_SYMBOL (op)->stack, op->isaddr, OP_SYMBOL (op)->isreqv, OP_SYMBOL (op)->remat,OP_SYMBOL(op)->noSpilLoc, - OP_SYMBOL(op)->ruonly + OP_SYMBOL(op)->ruonly,OP_SYMBOL(op)->dptr ); { fprintf (file, "{"); @@ -386,6 +406,9 @@ PRINTFUNC (picGenericOne) if (!IC_RESULT (ic) && !IC_LEFT (ic)) fprintf (of, s); + if (ic->op == SEND || ic->op == RECEIVE) { + fprintf(of,"{argreg = %d}",ic->argreg); + } fprintf (of, "\n"); } @@ -932,6 +955,8 @@ isOperandInCodeSpace (operand * op) if (!IS_SYMOP (op)) return FALSE; + etype = getSpec (operandType (op)); + if (!IS_TRUE_SYMOP (op)) { if (SPIL_LOC (op)) @@ -1073,14 +1098,27 @@ operandOperation (operand * left, operand * right, (unsigned long) operandLitValue (right) : (long) operandLitValue (right))); break; - case RIGHT_OP: - retval = operandFromLit ((SPEC_USIGN(let) ? - (unsigned long) operandLitValue (left) : - (long) operandLitValue (left)) >> - (SPEC_USIGN(ret) ? - (unsigned long) operandLitValue (right) : - (long) operandLitValue (right))); + case RIGHT_OP: { + double lval = operandLitValue(left), rval = operandLitValue(right); + double res=0; + switch ((SPEC_USIGN(let) ? 2 : 0) + (SPEC_USIGN(ret) ? 1 : 0)) + { + case 0: // left=unsigned right=unsigned + res=(unsigned long)lval >> (unsigned long)rval; + break; + case 1: // left=unsigned right=signed + res=(unsigned long)lval >> (signed long)rval; + break; + case 2: // left=signed right=unsigned + res=(signed long)lval >> (unsigned long)rval; + break; + case 3: // left=signed right=signed + res=(signed long)lval >> (signed long)rval; + break; + } + retval = operandFromLit (res); break; + } case EQ_OP: retval = operandFromLit (operandLitValue (left) == operandLitValue (right)); @@ -1599,6 +1637,7 @@ usualBinaryConversions (operand ** op1, operand ** op2) sym_link *ltype = operandType (*op1); ctype = computeType (ltype, rtype); + *op1 = geniCodeCast (ctype, *op1, TRUE); *op2 = geniCodeCast (ctype, *op2, TRUE); @@ -1640,7 +1679,6 @@ geniCodeRValue (operand * op, bool force) if (IS_SPEC (type) && IS_TRUE_SYMOP (op) && (!IN_FARSPACE (SPEC_OCLS (etype)) || - /* TARGET_IS_DS390)) */ (options.model == MODEL_FLAT24) )) { op = operandFromOperand (op); @@ -1776,7 +1814,8 @@ geniCodeCast (sym_link * type, operand * op, bool implicit) /* preserve the storage class & output class */ /* of the original variable */ restype = getSpec (operandType (IC_RESULT (ic))); - SPEC_SCLS (restype) = SPEC_SCLS (opetype); + if (!IS_LITERAL(opetype)) + SPEC_SCLS (restype) = SPEC_SCLS (opetype); SPEC_OCLS (restype) = SPEC_OCLS (opetype); ADDTOCHAIN (ic); @@ -1886,10 +1925,12 @@ geniCodeDivision (operand * left, operand * right) resType = usualBinaryConversions (&left, &right); - /* if the right is a literal & power of 2 */ - /* then make it a right shift */ + /* if the right is a literal & power of 2 + and left is unsigned then make it a + right shift */ if (IS_LITERAL (retype) && !IS_FLOAT (letype) && + SPEC_USIGN(letype) && (p2 = powof2 ((unsigned long) floatFromVal (right->operand.valOperand)))) { ic = newiCode (RIGHT_OP, left, operandFromLit (p2)); /* right shift */ @@ -1959,6 +2000,11 @@ geniCodePtrPtrSubtract (operand * left, operand * right) ADDTOCHAIN (ic); subtractExit: + if (IS_VOID(ltype->next) || IS_VOID(rtype->next)) { + return result; + } + + // should we really do this? is this ANSI? return geniCodeDivision (result, operandFromLit (getSize (ltype->next))); } @@ -2023,9 +2069,11 @@ geniCodeAdd (operand * left, operand * right, int lvl) int isarray = 0; LRTYPE; +#if 0 /* if left is an array then array access */ if (IS_ARRAY (ltype)) return geniCodeArray (left, right,lvl); +#endif /* if the right side is LITERAL zero */ /* return the left side */ @@ -2037,7 +2085,7 @@ geniCodeAdd (operand * left, operand * right, int lvl) return right; /* if left is a pointer then size */ - if (IS_PTR (ltype)) + if (IS_PTR (ltype) || IS_ARRAY(ltype)) { isarray = left->isaddr; // there is no need to multiply with 1 @@ -2769,10 +2817,12 @@ geniCodeSEParms (ast * parms,int lvl) IS_ADDRESS_OF_OP (parms->right)) parms->right->left->lvalue = 1; - parms->opval.oprnd = + parms->opval.oprnd = geniCodeRValue (ast2iCode (parms,lvl+1), FALSE); - + parms->type = EX_OPERAND; + AST_ARGREG(parms) = parms->etype ? SPEC_ARGREG(parms->etype) : + SPEC_ARGREG(parms->ftype); } /*-----------------------------------------------------------------*/ @@ -2825,6 +2875,7 @@ geniCodeParms (ast * parms, value *argVals, int *stack, IFFUNC_ISBUILTIN(func->type)) { ic = newiCode (SEND, pval, NULL); + ic->argreg = SPEC_ARGREG(parms->etype); ic->builtinSEND = FUNC_ISBUILTIN(func->type); ADDTOCHAIN (ic); } @@ -2837,7 +2888,7 @@ geniCodeParms (ast * parms, value *argVals, int *stack, /* assign */ operand *top = operandFromSymbol (argVals->sym); /* clear useDef and other bitVectors */ - OP_USES (top) = OP_DEFS (top) = OP_SYMBOL(top)->clashes = NULL; + OP_USES_SET ((top), OP_DEFS_SET ((top), OP_SYMBOL(top)->clashes = NULL)); geniCodeAssign (top, pval, 1); } else @@ -2910,7 +2961,7 @@ geniCodeReceive (value * args) /* for all arguments that are passed in registers */ while (args) { - + int first = 1; if (IS_REGPARM (args->etype)) { operand *opr = operandFromValue (args); @@ -2925,7 +2976,6 @@ geniCodeReceive (value * args) if (IN_FARSPACE (SPEC_OCLS (sym->etype)) && options.stackAuto == 0 && - /* !TARGET_IS_DS390) */ (!(options.model == MODEL_FLAT24)) ) { } @@ -2941,8 +2991,12 @@ geniCodeReceive (value * args) } } - ic = newiCode (RECEIVE, NULL, NULL); - currFunc->recvSize = getSize (sym->etype); + ic = newiCode (RECEIVE, NULL, NULL); + ic->argreg = SPEC_ARGREG(args->etype); + if (first) { + currFunc->recvSize = getSize (sym->type); + first = 0; + } IC_RESULT (ic) = opr; ADDTOCHAIN (ic); } @@ -2979,7 +3033,7 @@ geniCodeFunctionBody (ast * tree,int lvl) /* create a proc icode */ ic = newiCode (FUNCTION, func, NULL); - ic->lineno = OP_SYMBOL (func)->lineDef; + lineno=ic->lineno = OP_SYMBOL (func)->lineDef; ADDTOCHAIN (ic); @@ -3319,6 +3373,7 @@ ast2iCode (ast * tree,int lvl) operand *right = NULL; if (!tree) return NULL; + /* set the global variables for filename & line number */ if (tree->filename) filename = tree->filename;