a ppc endian fix
[fw/sdcc] / src / SDCCicode.c
index 5755fc38557d06ba07b0db25117ee26e7cd08394..62b3a119b11e94d8141a84a725a0f57bac9940f2 100644 (file)
@@ -136,7 +136,14 @@ void checkConstantRange(sym_link *ltype, value *val, char *msg, int pedantic) {
   char message[132]="";
   int warnings=0;
   int negative=0;
-  long v=SPEC_CVAL(val->type).v_long;
+  long v;
+
+  if (SPEC_LONG(val->type)) {
+    v=SPEC_CVAL(val->type).v_long;
+  } else {
+    v=SPEC_CVAL(val->type).v_int;
+  }
+
 
 #if 0
   // this could be a good idea
@@ -499,7 +506,7 @@ newOperand ()
 {
   operand *op;
 
-  op = Safe_calloc (1, sizeof (operand));
+  op = Safe_alloc ( sizeof (operand));
 
   op->key = 0;
   return op;
@@ -513,7 +520,7 @@ newiCode (int op, operand * left, operand * right)
 {
   iCode *ic;
 
-  ic = Safe_calloc (1, sizeof (iCode));
+  ic = Safe_alloc ( sizeof (iCode));
 
   ic->lineno = lineno;
   ic->filename = filename;
@@ -965,20 +972,20 @@ operandOperation (operand * left, operand * right,
 
       break;
     case LEFT_OP:
-      retval = operandFromLit (((SPEC_USIGN(let) ? 
+      retval = operandFromLit ((SPEC_USIGN(let) ? 
                                  (unsigned long) operandLitValue (left) :
                                  (long) operandLitValue (left)) <<
                                 (SPEC_USIGN(ret) ? 
                                  (unsigned long) operandLitValue (right) :
-                                 (long) operandLitValue (right))));
+                                 (long) operandLitValue (right)));
       break;
     case RIGHT_OP:
-      retval = operandFromLit (((SPEC_USIGN(let) ? 
+      retval = operandFromLit ((SPEC_USIGN(let) ? 
                                  (unsigned long) operandLitValue (left) :
                                  (long) operandLitValue (left)) >>
                                 (SPEC_USIGN(ret) ? 
                                  (unsigned long) operandLitValue (right) :
-                                 (long) operandLitValue (right))));
+                                 (long) operandLitValue (right)));
       break;
     case EQ_OP:
       retval = operandFromLit (operandLitValue (left) ==
@@ -1005,16 +1012,16 @@ operandOperation (operand * left, operand * right,
                               operandLitValue (right));
       break;
     case BITWISEAND:
-      retval = operandFromLit ((unsigned long) operandLitValue (left) &
-                              (unsigned long) operandLitValue (right));
+      retval = operandFromLit ((long)operandLitValue(left) & 
+                              (long)operandLitValue(right));
       break;
     case '|':
-      retval = operandFromLit ((unsigned long) operandLitValue (left) |
-                              (unsigned long) operandLitValue (right));
+      retval = operandFromLit ((long)operandLitValue (left) |
+                              (long)operandLitValue (right));
       break;
     case '^':
-      retval = operandFromLit ((unsigned long) operandLitValue (left) ^
-                              (unsigned long) operandLitValue (right));
+      retval = operandFromLit ((long)operandLitValue (left) ^
+                              (long)operandLitValue (right));
       break;
     case AND_OP:
       retval = operandFromLit (operandLitValue (left) &&
@@ -1101,9 +1108,9 @@ isOperandEqual (operand * left, operand * right)
   return 0;
 }
 
-/*-----------------------------------------------------------------*/
-/* isiCodeEqual - comapres two iCodes are returns true if yes      */
-/*-----------------------------------------------------------------*/
+/*-------------------------------------------------------------------*/
+/* isiCodeEqual - compares two iCodes are equal, returns true if yes */
+/*-------------------------------------------------------------------*/
 int 
 isiCodeEqual (iCode * left, iCode * right)
 {
@@ -1137,6 +1144,7 @@ isiCodeEqual (iCode * left, iCode * right)
          if (!isSymbolEqual (IC_FALSE (left), IC_FALSE (right)))
            return 0;
        }
+      
       return 1;
     }
   return 0;
@@ -1598,7 +1606,7 @@ geniCodeCast (sym_link * type, operand * op, bool implicit)
 
   /* if casting to/from pointers, do some checking */
   if (IS_PTR(type)) { // to a pointer
-    if (!IS_PTR(optype) && !IS_FUNC(optype)) { // from a non pointer
+    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.
        if (!(IS_LITERAL(optype) && (SPEC_CVAL(optype).v_ulong ==0))) {
@@ -3166,7 +3174,7 @@ lvalItem;
 /*-----------------------------------------------------------------*/
 void addLvaluereq(int lvl)
 {
-  lvalItem * lpItem = (lvalItem *)Safe_calloc (1, sizeof (lvalItem));
+  lvalItem * lpItem = (lvalItem *)Safe_alloc ( sizeof (lvalItem));
   lpItem->req=1;
   lpItem->lvl=lvl;
   addSetHead(&lvaluereqSet,lpItem);
@@ -3179,7 +3187,7 @@ void delLvaluereq()
 {
   lvalItem * lpItem;
   lpItem = getSet(&lvaluereqSet);
-  if(lpItem) free(lpItem);
+  if(lpItem) Safe_free(lpItem);
 }
 /*-----------------------------------------------------------------*/
 /* clearLvaluereq - clear lvalreq flag                            */