* src/pic/gen.c (SetIrp,genNearPointerGet,genNearPointerSet):
[fw/sdcc] / src / SDCCicode.c
index fe436aa48631ecd53e9fc8d9dea419f9411beabb..03da8a0c88f8dc811ee1bb93c4a0ac4895b46af9 100644 (file)
@@ -561,8 +561,8 @@ newiCode (int op, operand * left, operand * right)
   ic = Safe_alloc ( sizeof (iCode));
 
   ic->seqPoint = seqPoint;
-  ic->lineno = lineno;
   ic->filename = filename;
+  ic->lineno = lineno;
   ic->block = block;
   ic->level = scopeLevel;
   ic->op = op;
@@ -701,8 +701,8 @@ copyiCode (iCode * ic)
 {
   iCode *nic = newiCode (ic->op, NULL, NULL);
 
-  nic->lineno = ic->lineno;
   nic->filename = ic->filename;
+  nic->lineno = ic->lineno;
   nic->block = ic->block;
   nic->level = ic->level;
   nic->parmBytes = ic->parmBytes;
@@ -822,7 +822,7 @@ operandType (operand * op)
 /*-----------------------------------------------------------------*/
 /* operandSize - returns size of an operand in bytes               */
 /*-----------------------------------------------------------------*/
-unsigned int 
+unsigned int
 operandSize (operand * op)
 {
   sym_link *type;
@@ -1226,28 +1226,29 @@ operandOperation (operand * left, operand * right,
                                                    operandLitValue (right)));
       break;
     case '/':
-      if ((TYPE_TARGET_ULONG) double2ul (operandLitValue (right)) == 0)
+      if (IS_UNSIGNED (type))
         {
-          werror (E_DIVIDE_BY_ZERO);
-          retval = right;
-
+          if ((TYPE_TARGET_ULONG) double2ul (operandLitValue (right)) == 0)
+            {
+              werror (E_DIVIDE_BY_ZERO);
+              retval = right;
+            }
+          SPEC_USIGN (let) = 1;
+          SPEC_USIGN (ret) = 1;
+          retval = operandFromValue (valCastLiteral (type,
+                                    (TYPE_TARGET_ULONG) double2ul (operandLitValue (left)) /
+                                    (TYPE_TARGET_ULONG) double2ul (operandLitValue (right))));
         }
       else
         {
-          if (IS_UNSIGNED (type))
+          if (operandLitValue (right) == 0)
             {
-              SPEC_USIGN (let) = 1;
-              SPEC_USIGN (ret) = 1;
-              retval = operandFromValue (valCastLiteral (type,
-                                        (TYPE_TARGET_ULONG) double2ul (operandLitValue (left)) /
-                                        (TYPE_TARGET_ULONG) double2ul (operandLitValue (right))));
-            }
-          else
-            {
-              retval = operandFromValue (valCastLiteral (type,
-                                                     operandLitValue (left) /
-                                                     operandLitValue (right)));
+              werror (E_DIVIDE_BY_ZERO);
+              retval = right;
             }
+          retval = operandFromValue (valCastLiteral (type,
+                                                 operandLitValue (left) /
+                                                 operandLitValue (right)));
         }
       break;
     case '%':
@@ -2067,7 +2068,7 @@ geniCodeCast (sym_link * type, operand * op, bool implicit)
       !IS_FIXED (type) &&
       !IS_FIXED (optype) &&
       ((IS_SPEC (type) && IS_SPEC (optype)) ||
-       (!IS_SPEC (type) && !IS_SPEC (optype))))
+       (IS_DECL (type) && IS_DECL (optype) && DCL_TYPE (type) == DCL_TYPE (optype))))
     {
       ic = newiCode ('=', NULL, op);
       IC_RESULT (ic) = newiTempOperand (type, 0);
@@ -3524,6 +3525,7 @@ geniCodeFunctionBody (ast * tree,int lvl)
   iCode *ic;
   operand *func;
   sym_link *fetype;
+  char *savefilename;
   int savelineno;
 
   /* reset the auto generation */
@@ -3535,15 +3537,19 @@ geniCodeFunctionBody (ast * tree,int lvl)
   func = ast2iCode (tree->left,lvl+1);
   fetype = getSpec (operandType (func));
 
+  savefilename = filename;
   savelineno = lineno;
+  filename = OP_SYMBOL (func)->fileDef;
   lineno = OP_SYMBOL (func)->lineDef;
   /* create an entry label */
   geniCodeLabel (entryLabel);
+  filename = savefilename;
   lineno = savelineno;
 
   /* create a proc icode */
   ic = newiCode (FUNCTION, func, NULL);
-  lineno=ic->lineno = OP_SYMBOL (func)->lineDef;
+  filename = ic->filename = OP_SYMBOL (func)->fileDef;
+  lineno = ic->lineno = OP_SYMBOL (func)->lineDef;
   ic->tree = tree;
 
   ADDTOCHAIN (ic);