*src/SDCCicode.c: fixed bug #1870216 - Error 122: dividing by zero
[fw/sdcc] / src / SDCCval.h
index 92e622fbb4972d45629129e034b214d640f3d936..98a1a7eb8b33df29db4c895324da058857545104 100644 (file)
@@ -6,33 +6,47 @@
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 2, or (at your option) any
   later version.
-  
+
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
-  
+
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-  
+
   In other words, you are welcome to use, share and improve this program.
   You are forbidden to forbid anyone else to use, share and improve
   what you give them.   Help stamp out software-hoarding!  
 -------------------------------------------------------------------------*/
-#include "SDCCsymt.h"
 #ifndef SDCCVAL_H
 #define SDCCVAL_H
 
+#include "SDCCsymt.h"
+
+
+/* double to unsigned long conversion */
+/*
+ * See ISO/IEC 9899, chapter 6.3.1.4 Real floating and integer:
+ * If the value of the integral part cannot be represented by the integer type, the behavior is undefined.
+ * This shows up on Mac OS X i386 platform which useus SSE unit instead of the x87 FPU for floating-point operations
+ */
+/*
+ * on Mac OS X ppc (long) 2147483648.0 equals to 2147483647, so we explicitely convert it to 0x80000000
+ * on other known platforms (long) 2147483648.0 equals to -2147483648
+ */
+#define double2ul(val)  (((val) < 0) ? (((val) < -2147483647.0) ? 0x80000000UL : (unsigned long) -((long) -(val))) : (unsigned long) (val))
+
 /* value wrapper */
 typedef struct value
   {
-    char name[SDCC_NAME_MAX + 1];      /* operand accessing this value */
-    sym_link *type;            /* start of type chain     */
-    sym_link *etype;           /* end of type chain       */
-    symbol *sym;               /* Original Symbol         */
-    struct value *next;                /* used in initializer list */
-    unsigned vArgs:1;          /* arg list ended with variable arg           */
+    char name[SDCC_NAME_MAX + 1]; /* operand accessing this value     */
+    sym_link *type;               /* start of type chain              */
+    sym_link *etype;              /* end of type chain                */
+    symbol *sym;                  /* Original Symbol                  */
+    struct value *next;           /* used in initializer list         */
+    unsigned vArgs:1;             /* arg list ended with variable arg */
 
   }
 value;
@@ -44,7 +58,6 @@ typedef struct literalList
     struct literalList *next;
 } literalList;
 
-
 enum
   {
     INIT_NODE,
@@ -57,10 +70,11 @@ typedef struct initList
   {
     int type;
     int lineno;
+    char *filename;
     union
       {
-       struct ast *node;
-       struct initList *deep;
+        struct ast *node;
+        struct initList *deep;
       }
     init;
 
@@ -68,21 +82,40 @@ typedef struct initList
   }
 initList;
 
-#define  IS_VARG(x)            (x->vArgs)
+/* return values from checkConstantRange */
+typedef enum
+  {
+    CCR_OK,           /* evaluate at runtime */
+    CCR_OVL,
+    CCR_ALWAYS_FALSE,
+    CCR_ALWAYS_TRUE
+  }
+CCR_RESULT;
+
+#define  IS_VARG(x)             (x->vArgs)
 
 /* forward definitions for the symbol table related functions */
 void initValue ();
 value *newValue ();
-value *constVal (char *);
+value *constVal (const char *);
 value *reverseVal (value *);
 value *reverseValWithType (value *);
 value *copyValue (value *);
 value *copyValueChain (value *);
-value *strVal (char *);
-value *charVal (char *);
+value *strVal (const char *);
+value *charVal (const char *);
 value *symbolVal (symbol *);
 void printVal (value *);
 double floatFromVal (value *);
+unsigned long ulFromVal (value *);
+
+/* convert a fixed16x16 type to double */
+double doubleFromFixed16x16(TYPE_TARGET_ULONG value);
+
+/* convert a double type to fixed16x16 */
+TYPE_TARGET_ULONG fixed16x16FromDouble(double value);
+
+CCR_RESULT checkConstantRange (sym_link *var, sym_link *lit, int op, bool exchangeOps);
 value *array2Ptr (value *);
 value *valUnaryPM (value *);
 value *valComplement (value *);
@@ -107,6 +140,7 @@ struct ast *list2expr (initList *);
 void resolveIvalSym (initList *, sym_link *);
 value *valFromType (sym_link *);
 value *constFloatVal (char *);
+value *constFixed16x16Val (char *);
 int getNelements (sym_link *, initList *);
 value *valForArray (struct ast *);
 value *valForStructElem (struct ast *, struct ast *);