fix mips immediate dumper
[libfirm] / ir / tv / tv.c
index 9cf374f..964af56 100644 (file)
  * PURPOSE.
  */
 
-/*
- * Project:     libFIRM
- * File name:   ir/tv/tv.c
- * Purpose:     Representation of and static computations on target machine
- *              values.
- * Author:      Mathias Heil
- * Modified by:
- * Created:
- * CVS-ID:      $Id$
- * Copyright:   (c) 2003-2007 Universität Karlsruhe
- */
-
-/*
- *    Values are stored in a format depending upon chosen arithmetic
- *    module. Default uses strcalc and fltcalc.
+/**
+ * @file
+ * @brief    Representation of and static computations on target machine
+ *           values.
+ * @date     2003
+ * @author   Mathias Heil
+ * @version  $Id$
+ * @summary
  *
+ * Values are stored in a format depending upon chosen arithmetic
+ * module. Default uses strcalc and fltcalc.
+ * This implementation assumes:
+ *  - target has IEEE-754 floating-point arithmetic.
  */
-
-/* This implementation assumes:
- *  - target has IEEE-754 floating-point arithmetic.  */
-
-
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
 
-
 #include <assert.h>         /* assertions */
 #include <stdlib.h>         /* atoi() */
 #ifdef HAVE_STRING_H
@@ -109,6 +100,8 @@ static struct set *tarvals = NULL;   /* container for tarval structs */
 static struct set *values = NULL;    /* container for values */
 static tarval_int_overflow_mode_t int_overflow_mode = TV_OVERFLOW_WRAP;
 
+#define no_float 0
+
 /****************************************************************************
  *   private functions
  ****************************************************************************/
@@ -339,7 +332,7 @@ int tarval_is_long(tarval *tv) {
 
        if (sort != irms_int_number && sort != irms_character) return 0;
 
-       if (get_mode_size_bits(tv->mode) > (sizeof(long) << 3)) {
+       if (get_mode_size_bits(tv->mode) > (int) (sizeof(long) << 3)) {
                /* the value might be too big to fit in a long */
                sc_max_from_bits(sizeof(long) << 3, 0, NULL);
                if (sc_comp(sc_get_buffer(), tv->value) == -1) {
@@ -756,6 +749,8 @@ pn_Cmp tarval_cmp(tarval *a, tarval *b) {
                return pn_Cmp_False;
 
        case irms_float_number:
+               if(no_float)
+                       return pn_Cmp_False;
                /*
                 * BEWARE: we cannot compare a == b here, because
                 * a NaN is always Unordered to any other value, even to itself!
@@ -854,7 +849,7 @@ tarval *tarval_convert_to(tarval *src, ir_mode *m) {
                case irms_character:
                        buffer = alloca(sc_get_buffer_length());
                        memcpy(buffer, src->value, sc_get_buffer_length());
-                       sign_extend(buffer, src->mode);
+                       sign_extend(buffer, m);
                        return get_tarval_overflow(buffer, src->length, m);
 
                case irms_internal_boolean:
@@ -908,6 +903,16 @@ tarval *tarval_convert_to(tarval *src, ir_mode *m) {
                break;
 
        case irms_reference:
+               switch(get_mode_sort(m)) {
+               case irms_int_number:
+                       buffer = alloca(sc_get_buffer_length());
+                       memcpy(buffer, src->value, sc_get_buffer_length());
+                       sign_extend(buffer, src->mode);
+                       return get_tarval_overflow(buffer, src->length, m);
+               default:
+                       break;
+               }
+
                break;
        }
 
@@ -966,6 +971,9 @@ tarval *tarval_neg(tarval *a) {
                return get_tarval_overflow(buffer, a->length, a->mode);
 
        case irms_float_number:
+               if(no_float)
+                       return tarval_bad;
+
                fc_neg(a->value, NULL);
                return get_tarval_overflow(fc_get_buffer(), fc_get_buffer_length(), a->mode);
 
@@ -998,6 +1006,9 @@ tarval *tarval_add(tarval *a, tarval *b) {
                return get_tarval_overflow(buffer, a->length, a->mode);
 
        case irms_float_number:
+               if(no_float)
+                       return tarval_bad;
+
                fc_add(a->value, b->value, NULL);
                return get_tarval_overflow(fc_get_buffer(), fc_get_buffer_length(), a->mode);
 
@@ -1029,6 +1040,9 @@ tarval *tarval_sub(tarval *a, tarval *b) {
                return get_tarval_overflow(buffer, a->length, a->mode);
 
        case irms_float_number:
+               if(no_float)
+                       return tarval_bad;
+
                fc_sub(a->value, b->value, NULL);
                return get_tarval_overflow(fc_get_buffer(), fc_get_buffer_length(), a->mode);
 
@@ -1060,6 +1074,9 @@ tarval *tarval_mul(tarval *a, tarval *b) {
                return get_tarval_overflow(buffer, a->length, a->mode);
 
        case irms_float_number:
+               if(no_float)
+                       return tarval_bad;
+
                fc_mul(a->value, b->value, NULL);
                return get_tarval_overflow(fc_get_buffer(), fc_get_buffer_length(), a->mode);
 
@@ -1076,6 +1093,9 @@ tarval *tarval_quo(tarval *a, tarval *b) {
        assert(b);
        assert((a->mode == b->mode) && mode_is_float(a->mode));
 
+       if(no_float)
+               return tarval_bad;
+
        if (get_mode_n_vector_elems(a->mode) > 1) {
                /* vector arithmetic not implemented yet */
                return tarval_bad;
@@ -1151,6 +1171,9 @@ tarval *tarval_abs(tarval *a) {
                return a;
 
        case irms_float_number:
+               if(no_float)
+                       return tarval_bad;
+
                if (fc_comp(a->value, get_mode_null(a->mode)->value) == -1) {
                        fc_neg(a->value, NULL);
                        return get_tarval_overflow(fc_get_buffer(), fc_get_buffer_length(), a->mode);
@@ -1437,7 +1460,7 @@ int tarval_printf(tarval *tv) {
        int res;
 
        res = tarval_snprintf(buf, sizeof(buf), tv);
-       assert(res < sizeof(buf) && "buffer to small for tarval_snprintf");
+       assert(res < (int) sizeof(buf) && "buffer to small for tarval_snprintf");
        printf(buf);
        return res;
 }