X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCicode.c;h=4b44dd2540c427dc1b0b439d6e47f91e2592a997;hb=7fa8b834cb5e6f5785c5fc92b2d61460782f4084;hp=c2feabde7fb799ac69ea0dbec88f4471b4f25fbd;hpb=cb437439dfe19810a8b7529c9af6289afaaf4ca1;p=fw%2Fsdcc diff --git a/src/SDCCicode.c b/src/SDCCicode.c index c2feabde..4b44dd25 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -224,13 +224,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->isaddr, OP_SYMBOL (op)->isreqv, + OP_SYMBOL (op)->remat,OP_SYMBOL(op)->noSpilLoc, + OP_SYMBOL(op)->ruonly,OP_SYMBOL(op)->dptr ); { fprintf (file, "{"); @@ -385,6 +386,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"); } @@ -917,12 +921,11 @@ isOperandInDirSpace (operand * op) return (IN_DIRSPACE (SPEC_OCLS (etype)) ? TRUE : FALSE); } -/*-----------------------------------------------------------------*/ -/* isOperandOnStack - will return true if operand is on stack */ -/*-----------------------------------------------------------------*/ -#if 0 +/*--------------------------------------------------------------------*/ +/* isOperandInCodeSpace - will return true if operand is in codeSpace */ +/*--------------------------------------------------------------------*/ bool -isOperandOnStack (operand * op) +isOperandInCodeSpace (operand * op) { sym_link *etype; @@ -934,9 +937,23 @@ isOperandOnStack (operand * op) etype = getSpec (operandType (op)); - return ((IN_STACK (etype)) ? TRUE : FALSE); + if (!IS_TRUE_SYMOP (op)) + { + if (SPIL_LOC (op)) + etype = SPIL_LOC (op)->etype; + else + return FALSE; + } + else + { + etype = getSpec (operandType (op)); + } + return (IN_CODESPACE (SPEC_OCLS (etype)) ? TRUE : FALSE); } -#else + +/*-----------------------------------------------------------------*/ +/* isOperandOnStack - will return true if operand is on stack */ +/*-----------------------------------------------------------------*/ bool isOperandOnStack (operand * op) { @@ -956,7 +973,6 @@ isOperandOnStack (operand * op) return FALSE; } -#endif /*-----------------------------------------------------------------*/ /* operandLitValue - literal value of an operand */ @@ -1581,15 +1597,15 @@ usualUnaryConversions (operand * op) /* perform "usual binary conversions" */ /*-----------------------------------------------------------------*/ sym_link * -usualBinaryConversions (operand ** op1, operand ** op2, int implicit) +usualBinaryConversions (operand ** op1, operand ** op2) { sym_link *ctype; sym_link *rtype = operandType (*op2); sym_link *ltype = operandType (*op1); ctype = computeType (ltype, rtype); - *op1 = geniCodeCast (ctype, *op1, implicit); - *op2 = geniCodeCast (ctype, *op2, implicit); + *op1 = geniCodeCast (ctype, *op1, TRUE); + *op2 = geniCodeCast (ctype, *op2, TRUE); return ctype; } @@ -1629,7 +1645,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); @@ -1686,9 +1701,7 @@ geniCodeCast (sym_link * type, operand * op, bool implicit) if (!IS_PTR(optype) && !IS_FUNC(optype) && !IS_AGGREGATE(optype)) { // from a non pointer if (IS_INTEGRAL(optype)) { // maybe this is NULL, than it's ok. - // !implicit is always ok, e.g. "(char *) = (char *) + 3;" - if (implicit && - !(IS_LITERAL(optype) && (SPEC_CVAL(optype).v_ulong ==0))) { + if (!(IS_LITERAL(optype) && (SPEC_CVAL(optype).v_ulong ==0))) { if (!TARGET_IS_Z80 && !TARGET_IS_GBZ80 && IS_GENPTR(type)) { // no way to set the storage if (IS_LITERAL(optype)) { @@ -1698,7 +1711,7 @@ geniCodeCast (sym_link * type, operand * op, bool implicit) werror(E_NONPTR2_GENPTR); errors++; } - } else { + } else if (implicit) { werror(W_INTEGRAL2PTR_NOCAST); errors++; } @@ -1767,7 +1780,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); @@ -1818,7 +1832,7 @@ geniCodeMultiply (operand * left, operand * right,int resultIsInt) p2 = powof2 ((unsigned long) floatFromVal (right->operand.valOperand)); } - resType = usualBinaryConversions (&left, &right, TRUE); + resType = usualBinaryConversions (&left, &right); #if 1 rtype = operandType (right); retype = getSpec (rtype); @@ -1875,7 +1889,7 @@ geniCodeDivision (operand * left, operand * right) sym_link *ltype = operandType (left); sym_link *letype = getSpec (ltype); - resType = usualBinaryConversions (&left, &right, TRUE); + resType = usualBinaryConversions (&left, &right); /* if the right is a literal & power of 2 */ /* then make it a right shift */ @@ -1912,7 +1926,7 @@ geniCodeModulus (operand * left, operand * right) return operandFromValue (valMod (left->operand.valOperand, right->operand.valOperand)); - resType = usualBinaryConversions (&left, &right, TRUE); + resType = usualBinaryConversions (&left, &right); /* now they are the same size */ ic = newiCode ('%', left, right); @@ -1986,7 +2000,7 @@ geniCodeSubtract (operand * left, operand * right) } else { /* make them the same size */ - resType = usualBinaryConversions (&left, &right, TRUE); + resType = usualBinaryConversions (&left, &right); } ic = newiCode ('-', left, right); @@ -2006,7 +2020,7 @@ geniCodeSubtract (operand * left, operand * right) /* geniCodeAdd - generates iCode for addition */ /*-----------------------------------------------------------------*/ operand * -geniCodeAdd (operand * left, operand * right, int lvl, int ptrMath) +geniCodeAdd (operand * left, operand * right, int lvl) { iCode *ic; sym_link *resType; @@ -2027,8 +2041,8 @@ geniCodeAdd (operand * left, operand * right, int lvl, int ptrMath) if (IS_LITERAL (letype) && left->isLiteral && !floatFromVal (valFromType (letype))) return right; - /* if left is an array or pointer then size */ - if (ptrMath && IS_PTR (ltype)) + /* if left is a pointer then size */ + if (IS_PTR (ltype)) { isarray = left->isaddr; // there is no need to multiply with 1 @@ -2040,7 +2054,7 @@ geniCodeAdd (operand * left, operand * right, int lvl, int ptrMath) } else { // make them the same size - resType = usualBinaryConversions (&left, &right, FALSE); + resType = usualBinaryConversions (&left, &right); } /* if they are both literals then we know */ @@ -2139,7 +2153,7 @@ geniCodeArray (operand * left, operand * right,int lvl) { left = geniCodeRValue (left, FALSE); } - return geniCodeDerefPtr (geniCodeAdd (left, right, lvl, 1), lvl); + return geniCodeDerefPtr (geniCodeAdd (left, right, lvl), lvl); } right = geniCodeMultiply (right, @@ -2594,7 +2608,7 @@ geniCodeLogic (operand * left, operand * right, int op) OP_VALUE(right), "compare operation", 1); } - ctype = usualBinaryConversions (&left, &right, TRUE); + ctype = usualBinaryConversions (&left, &right); ic = newiCode (op, left, right); IC_RESULT (ic) = newiTempOperand (newCharLink (), 1); @@ -2760,10 +2774,11 @@ 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) = SPEC_ARGREG(parms->etype); } /*-----------------------------------------------------------------*/ @@ -2816,6 +2831,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); } @@ -2873,10 +2889,11 @@ geniCodeCall (operand * left, ast * parms,int lvl) geniCodeParms (parms, NULL, &stack, getSpec (operandType (left)), OP_SYMBOL (left),lvl); /* now call : if symbol then pcall */ - if (IS_OP_POINTER (left) || IS_ITEMP(left)) + if (IS_OP_POINTER (left) || IS_ITEMP(left)) { ic = newiCode (PCALL, left, NULL); - else + } else { ic = newiCode (CALL, left, NULL); + } type = copyLinkChain (operandType (left)->next); etype = getSpec (type); @@ -2900,7 +2917,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); @@ -2915,7 +2932,6 @@ geniCodeReceive (value * args) if (IN_FARSPACE (SPEC_OCLS (sym->etype)) && options.stackAuto == 0 && - /* !TARGET_IS_DS390) */ (!(options.model == MODEL_FLAT24)) ) { } @@ -2931,8 +2947,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); } @@ -2969,7 +2989,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); @@ -3309,6 +3329,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; @@ -3466,7 +3487,7 @@ ast2iCode (ast * tree,int lvl) case '+': if (right) return geniCodeAdd (geniCodeRValue (left, FALSE), - geniCodeRValue (right, FALSE),lvl, 0); + geniCodeRValue (right, FALSE),lvl); else return geniCodeRValue (left, FALSE); /* unary '+' has no meaning */ @@ -3556,7 +3577,7 @@ ast2iCode (ast * tree,int lvl) return geniCodeAssign (left, geniCodeAdd (geniCodeRValue (operandFromOperand (left), FALSE), - right,lvl,1), 0); + right,lvl), 0); } case SUB_ASSIGN: {