Break DS80C390 support into seperate port (ds390); first pass at spilling temporaries...
[fw/sdcc] / src / SDCCicode.c
index 93d84027af5c7e777d4b0efb0fee3a7a88ba3daa..2704b942ec9e9630f20e828ce24f75276b8ae070 100644 (file)
@@ -751,8 +751,10 @@ bool isOperandInFarSpace (operand *op)
        else            
            return FALSE;
     }
-
-    etype = getSpec(operandType(op));
+    else
+    {
+       etype = getSpec(operandType(op));
+    }
     return (IN_FARSPACE(SPEC_OCLS(etype)) ? TRUE : FALSE);
 }
 
@@ -1545,7 +1547,8 @@ operand *geniCodeSubtract (operand *left, operand *right)
        return geniCodePtrPtrSubtract (left,right);
     
     /* if they are both literal then we know the result */
-    if (IS_LITERAL(letype) && IS_LITERAL(retype)) 
+    if (IS_LITERAL(letype) && IS_LITERAL(retype)
+       && left->isLiteral && right->isLiteral) 
        return operandFromValue (valMinus(left->operand.valOperand,
                                          right->operand.valOperand));
     
@@ -1585,18 +1588,18 @@ operand *geniCodeAdd (operand *left, operand *right )
     operand *size ;
     int isarray = 0;
     LRTYPE ;
-    
+
     /* if left is an array then array access */
     if (IS_ARRAY(ltype)) 
        return geniCodeArray (left,right);           
     
     /* if the right side is LITERAL zero */
     /* return the left side              */
-    if (IS_LITERAL(retype) && !floatFromVal(valFromType(retype)))
+    if (IS_LITERAL(retype) && right->isLiteral && !floatFromVal(valFromType(retype)))
        return left;
     
     /* if left is literal zero return right */
-    if (IS_LITERAL(letype) && !floatFromVal(valFromType(letype)))
+    if (IS_LITERAL(letype) && left->isLiteral && !floatFromVal(valFromType(letype)))
        return right ;
     
     /* if left is an array or pointer then size */
@@ -1615,7 +1618,8 @@ operand *geniCodeAdd (operand *left, operand *right )
     }
     
     /* if they are both literals then we know */
-    if (IS_LITERAL(letype) && IS_LITERAL(retype))
+    if (IS_LITERAL(letype) && IS_LITERAL(retype)
+       && left->isLiteral && right->isLiteral)
        return operandFromValue (valPlus(valFromType(letype),
                                         valFromType(retype)));
     
@@ -1653,7 +1657,7 @@ link *aggrToPtr ( link *type, bool force)
     ptype->next = type;
     /* if the output class is generic */
     if ((DCL_TYPE(ptype) = PTR_TYPE(SPEC_OCLS(etype))) == CPOINTER)
-       DCL_PTR_CONST(ptype) = 1;
+       DCL_PTR_CONST(ptype) = port->mem.code_ro;
 
     /* if the variable was declared a constant */
     /* then the pointer points to a constant */
@@ -1676,7 +1680,7 @@ operand *geniCodeArray2Ptr (operand *op)
 
     /* set the pointer depending on the storage class */    
     if ((DCL_TYPE(optype) = PTR_TYPE(SPEC_OCLS(opetype))) == CPOINTER)
-       DCL_PTR_CONST(optype) = 1;
+       DCL_PTR_CONST(optype) = port->mem.code_ro;
 
     
     /* if the variable was declared a constant */
@@ -1943,7 +1947,7 @@ operand *geniCodeAddressOf (operand *op)
     
     /* set the pointer depending on the storage class */
     if ((DCL_TYPE(p) = PTR_TYPE(SPEC_OCLS(opetype))) == CPOINTER)
-       DCL_PTR_CONST(p) = 1;
+       DCL_PTR_CONST(p) = port->mem.code_ro;
 
     /* make sure we preserve the const & volatile */
     if (IS_CONSTANT(opetype)) 
@@ -2337,8 +2341,9 @@ static void geniCodeParms ( ast *parms , int *stack, link *fetype)
     }
 
     /* if register parm then make it a send */
-    if ((parms->argSym && IS_REGPARM(parms->argSym->etype)) ||
-       IS_REGPARM(parms->etype)) {
+    if (((parms->argSym && IS_REGPARM(parms->argSym->etype)) ||
+       IS_REGPARM(parms->etype)) && 
+       !IS_RENT(fetype)) {
        ic = newiCode(SEND,pval,NULL);
        ADDTOCHAIN(ic);
     } else {
@@ -2754,8 +2759,16 @@ operand *ast2iCode (ast *tree)
            (tree->opval.op == '&' && !tree->right) ||
            tree->opval.op == PTR_OP) {
            lvaluereq++;
-           left = operandFromAst(tree->left);
-           lvaluereq--;
+           if (IS_ARRAY_OP(tree->left) && IS_ARRAY_OP(tree->left->left))
+           {
+               lvaluereq--;
+               left = operandFromAst(tree->left);
+           } else {
+               left = operandFromAst(tree->left);
+               lvaluereq--;
+           }
+           if (IS_DEREF_OP(tree) && IS_DEREF_OP(tree->left))
+                   left = geniCodeRValue(left,TRUE);
        } else {
            left =  operandFromAst(tree->left);
        }