1 /* TV --- Target Values, aka Constant Table.
2 Copyright (C) 1995, 1996 Christian von Roques */
6 /****i* tv/implementation
13 * Internal storage for tarvals, 1st draft:
14 * Integers as well as pointers are stored in a hex formatted string holding
15 * 16 characters. Booleans are not stored as there are only two of them.
17 * Floats are just reinterpreted as byte strings, because I am not sure if
18 * there is loss if I convert float to long double and back and furthermore
19 * the implementation of a fully ieee compatible floating point emulation
20 * is not sensible for now
21 * With this information it is easy to decide the kind of stored value:
22 * Integers have size 16, floats 4, doubles 8, long doubles 12.
25 /* This implementation assumes:
26 * both host and target have IEEE-754 floating-point arithmetic. */
28 /* !!! float and double divides MUST NOT SIGNAL !!! */
29 /* @@@ query the floating-point expception status flags */
31 /* @@@ Problem: All Values are stored twice, once as Univ_*s and a 2nd
32 time in their real target mode. :-( */
34 #define MAX_INT_LENGTH 8
35 #define CHAR_BUFFER_SIZE ((MAX_INT_LENGTH) * 2)
41 #include <assert.h> /* assertions */
42 #include <stdlib.h> /* atoi() */
43 #include <string.h> /* nice things for strings */
44 #include <strings.h> /* nice things for strings */
48 #include "set.h" /* to store tarvals in */
49 #include "tune.h" /* some constants */
50 #include "entity_t.h" /* needed to store pointers to entities */
51 #include "irmode.h" /* defines modes etc */
53 #include "irnode.h" /* defines boolean return values */
58 /****************************************************************************
59 * local definitions and macros
60 ****************************************************************************/
62 # define TARVAL_VERIFY(a) tarval_verify((a))
64 # define TARVAL_VERIFY(a) ((void)0)
67 #define INSERT_TARVAL(tv) ((tarval*)set_insert(tarvals, (tv), sizeof(tarval), hash_tv((tv))))
68 #define FIND_TARVAL(tv) ((tarval*)set_find(tarvals, (tv), sizeof(tarval), hash_tv((tv))))
70 #define INSERT_VALUE(val, size) (set_insert(values, (val), size, hash_val((val), size)))
71 #define FIND_VALUE(val, size) (set_find(values, (val), size, hash_val((val), size)))
73 #define fail_verify(a) _fail_verify((a), __FILE__, __LINE__)
75 static long long count = 0;
76 # define ANNOUNCE() printf(__FILE__": call no. %lld (%s)\n", count++, __FUNCTION__);
78 # define ANNOUNCE() ((void)0)
80 /****************************************************************************
82 ****************************************************************************/
83 static struct set *tarvals; /* container for tarval structs */
84 static struct set *values; /* container for values */
86 /****************************************************************************
88 ****************************************************************************/
90 static int hash_val(const void *value, unsigned int length);
91 static int hash_tv(tarval *tv);
92 static void _fail_verify(tarval *tv, const char* file, int line)
94 /* print a memory image of the tarval and throw an assertion */
96 printf("%s:%d: Invalid tarval:\n mode: %s\n value: [%p]\n", file, line, get_mode_name(tv->mode), tv->value);
98 printf("%s:%d: Invalid tarval (null)", file, line);
102 INLINE static void tarval_verify(tarval *tv) __attribute__ ((unused));
105 INLINE static void tarval_verify(tarval *tv)
111 if ((tv == tarval_bad) || (tv == tarval_undefined)) return;
112 if ((tv == tarval_b_true) || (tv == tarval_b_false)) return;
114 if (!FIND_TARVAL(tv)) fail_verify(tv);
115 if (tv->length > 0 && !FIND_VALUE(tv->value, tv->length)) fail_verify(tv);
121 static int hash_tv(tarval *tv)
123 return ((unsigned int)tv->value ^ (unsigned int)tv->mode) + tv->length;
126 static int hash_val(const void *value, unsigned int length)
129 unsigned int hash = 0;
131 /* scramble the byte - array */
132 for (i = 0; i < length; i++)
134 hash += (hash << 5) ^ (hash >> 27) ^ ((char*)value)[i];
135 hash += (hash << 11) ^ (hash >> 17);
141 /* finds tarval with value/mode or creates new tarval */
142 static tarval *get_tarval(const void *value, int length, ir_mode *mode)
149 /* if there already is such a value, it is returned, else value
150 * is copied into the set */
151 tv.value = INSERT_VALUE(value, length);
155 /* if there is such a tarval, it is returned, else tv is copied
157 return (tarval *)INSERT_TARVAL(&tv);
161 * Returns non-zero if a tarval overflows.
163 * @todo Implementation did not work on all modes
165 static int overflows(tarval *tv)
167 switch (get_mode_sort(tv->mode))
169 case irms_int_number:
170 if (sc_comp(tv->value, get_mode_max(tv->mode)->value) == 1) return 1;
171 if (sc_comp(tv->value, get_mode_min(tv->mode)->value) == -1) return 1;
174 case irms_float_number:
178 if (fc_comp(tv->value, get_mode_max(tv->mode)->value) == 1) return 1;
179 if (fc_comp(tv->value, get_mode_min(tv->mode)->value) == -1) return 1;
190 * public variables declared in tv.h
193 tarval *tarval_undefined;
194 tarval *tarval_b_false;
195 tarval *tarval_b_true;
196 tarval *tarval_P_void;
199 * public functions declared in tv.h
203 * Constructors =============================================================
205 tarval *new_tarval_from_str(const char *str, size_t len, ir_mode *mode)
212 switch (get_mode_sort(mode))
214 case irms_control_flow:
220 case irms_internal_boolean:
221 /* match tTrRuUeE/fFaAlLsSeE */
222 if (strcasecmp(str, "true")) return tarval_b_true;
223 else if (strcasecmp(str, "false")) return tarval_b_true;
225 return atoi(str) ? tarval_b_true : tarval_b_false;
227 case irms_float_number:
228 fc_val_from_str(str, len);
229 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
231 case irms_int_number:
233 sc_val_from_str(str, len);
234 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), mode);
237 return get_tarval(str, len, mode);
240 assert(0); /* can't be reached, can it? */
245 int tarval_is_str(tarval *tv)
250 return ((get_mode_sort(tv->mode) == reference) && (tv->value != NULL) && (tv->length > 0));
252 char *tarval_to_str(tarval *tv)
255 assert(tarval_is_str(tv));
256 return (char *)tv->value;
261 * helper function, create a tarval from long
263 tarval *new_tarval_from_long(long l, ir_mode *mode)
266 assert(mode && !((get_mode_sort(mode) == irms_memory)||(get_mode_sort(mode)==irms_control_flow)||(get_mode_sort(mode)==irms_auxiliary)));
268 switch(get_mode_sort(mode))
270 case irms_internal_boolean:
271 /* XXX C-Semantics ! */
272 return l ? tarval_b_true : tarval_b_false ;
274 case irms_int_number:
277 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), mode);
279 case irms_float_number:
280 return new_tarval_from_double((long double)l, mode);
283 return l ? tarval_bad : get_tarval(NULL, 0, mode); /* null pointer or tarval_bad */
291 /* returns non-zero if can be converted to long */
292 int tarval_is_long(tarval *tv)
295 if (get_mode_sort(tv->mode) != irms_int_number) return 0;
297 if (get_mode_size_bits(tv->mode) > sizeof(long)<<3)
299 /* the value might be too big to fit in a long */
300 sc_max_from_bits(sizeof(long)<<3, 0);
301 if (sc_comp(sc_get_buffer(), tv->value) == -1)
303 /* really doesn't fit */
310 /* this might overflow the machine's long, so use only with small values */
311 long tarval_to_long(tarval* tv)
314 assert(tarval_is_long(tv) && "tarval too big to fit in long");
316 return sc_val_to_long(tv->value);
319 tarval *new_tarval_from_double(long double d, ir_mode *mode)
322 assert(mode && (get_mode_sort(mode) == irms_float_number));
324 fc_val_from_float(d);
325 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
328 /* returns non-zero if can be converted to double */
329 int tarval_is_double(tarval *tv)
334 return (get_mode_sort(tv->mode) == irms_float_number);
337 long double tarval_to_double(tarval *tv)
340 assert(tarval_is_double(tv));
342 return fc_val_to_float(tv->value);
345 /* The tarval represents the address of the entity. As the address must
346 be constant the entity must have as owner the global type. */
347 tarval *new_tarval_from_entity (entity *ent, ir_mode *mode)
351 assert(mode && (get_mode_sort(mode) == irms_reference));
353 return get_tarval((void *)ent, 0, mode);
355 int tarval_is_entity(tarval *tv)
359 /* tv->value == NULL means dereferencing a null pointer */
360 return ((get_mode_sort(tv->mode) == irms_reference) && (tv->value != NULL) && (tv->length == 0)
361 && (tv != tarval_P_void));
364 entity *tarval_to_entity(tarval *tv)
369 if (tarval_is_entity(tv))
370 return (entity *)tv->value;
372 assert(0 && "tarval did not represent an entity");
377 void free_tarval_entity(entity *ent) {
378 /* There can be a tarval referencing this entity. Even if the
379 tarval is not used by the code any more, it can still reference
380 the entity as tarvals live indepently of the entity referenced.
381 Further the tarval is hashed into a set. If a hash function
382 evaluation happens to collide with this tarval, we will vrfy that
383 it contains a proper entity and we will crash if the entity is
386 Unluckily, tarvals can neither be changed nor deleted, and to find
387 one, all existing reference modes have to be tried -> a facility
388 to retrieve all modes of a kind is needed. */
393 * Access routines for tarval fields ========================================
395 ir_mode *get_tarval_mode (tarval *tv) /* get the mode of the tarval */
403 * Special value query functions ============================================
405 * These functions calculate and return a tarval representing the requested
407 * The functions get_mode_{Max,Min,...} return tarvals retrieved from these
408 * functions, but these are stored on initialization of the irmode module and
409 * therefore the irmode functions should be prefered to the functions below.
412 tarval *get_tarval_bad(void)
417 tarval *get_tarval_undefined(void)
420 return tarval_undefined;
422 tarval *get_tarval_b_false(void)
425 return tarval_b_false;
427 tarval *get_tarval_b_true(void)
430 return tarval_b_true;
432 tarval *get_tarval_P_void(void)
435 return tarval_P_void;
438 tarval *get_tarval_max(ir_mode *mode)
443 switch(get_mode_sort(mode))
446 case irms_control_flow:
452 case irms_internal_boolean:
453 return tarval_b_true;
455 case irms_float_number:
456 fc_get_max(get_mode_size_bits(mode));
457 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
459 case irms_int_number:
461 sc_max_from_bits(get_mode_size_bits(mode), mode_is_signed(mode));
462 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), mode);
467 tarval *get_tarval_min(ir_mode *mode)
472 switch(get_mode_sort(mode))
475 case irms_control_flow:
481 case irms_internal_boolean:
482 return tarval_b_false;
484 case irms_float_number:
485 fc_get_min(get_mode_size_bits(mode));
486 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
488 case irms_int_number:
490 sc_min_from_bits(get_mode_size_bits(mode), mode_is_signed(mode));
491 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), mode);
496 tarval *get_tarval_null(ir_mode *mode)
501 switch(get_mode_sort(mode))
503 case irms_control_flow:
506 case irms_internal_boolean:
510 case irms_float_number:
511 return new_tarval_from_double(0.0, mode);
513 case irms_int_number:
515 return new_tarval_from_long(0l, mode);
518 return tarval_P_void;
523 tarval *get_tarval_one(ir_mode *mode)
528 switch(get_mode_sort(mode))
530 case irms_control_flow:
533 case irms_internal_boolean:
538 case irms_float_number:
539 return new_tarval_from_double(1.0, mode);
541 case irms_int_number:
543 return new_tarval_from_long(1l, mode);
549 tarval *get_tarval_nan(ir_mode *mode)
554 if (get_mode_sort(mode) == irms_float_number) {
556 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
559 assert(0 && "tarval is not floating point");
564 tarval *get_tarval_inf(ir_mode *mode)
569 if (get_mode_sort(mode) == irms_float_number) {
571 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
574 assert(0 && "tarval is not floating point");
580 * Arithmethic operations on tarvals ========================================
584 * test if negative number, 1 means 'yes'
586 int tarval_is_negative(tarval *a)
591 switch (get_mode_sort(a->mode))
593 case irms_int_number:
594 if (!mode_is_signed(a->mode)) return 0;
596 return sc_comp(a->value, get_mode_null(a->mode)->value) == -1 ? 1 : 0;
598 case irms_float_number:
599 return fc_comp(a->value, get_mode_null(a->mode)->value) == -1 ? 1 : 0;
602 assert(0 && "not implemented");
608 * test if null, 1 means 'yes'
610 int tarval_is_null(tarval *a)
612 ir_mode *m = get_tarval_mode(a);
614 return a == get_tarval_null(m);
620 pnc_number tarval_cmp(tarval *a, tarval *b)
626 if (a == tarval_bad || b == tarval_bad) assert(0 && "Comparison with tarval_bad");
627 if (a == tarval_undefined || b == tarval_undefined) return False;
628 if (a == b) return Eq;
629 if (get_tarval_mode(a) != get_tarval_mode(b)) return Uo;
631 /* Here the two tarvals are unequal and of the same mode */
632 switch (get_mode_sort(a->mode))
634 case irms_control_flow:
639 case irms_float_number:
640 return (fc_comp(a->value, b->value)==1)?(Gt):(Lt);
642 case irms_int_number:
644 return (sc_comp(a->value, b->value)==1)?(Gt):(Lt);
646 case irms_internal_boolean:
647 return (a == tarval_b_true)?(Gt):(Lt);
656 * convert to other mode
658 tarval *tarval_convert_to(tarval *src, ir_mode *m)
666 if (src->mode == m) return src;
668 switch (get_mode_sort(src->mode))
670 case irms_control_flow:
675 case irms_float_number:
676 switch (get_mode_sort(m)) {
677 case irms_float_number:
679 tv.length = src->length;
680 tv.value = src->value;
681 if (overflows(&tv)) {
685 return INSERT_TARVAL(&tv);
692 case irms_int_number:
693 switch (get_mode_sort(m)) {
694 case irms_int_number:
697 tv.length = src->length;
698 tv.value = src->value;
702 return INSERT_TARVAL(&tv);
704 case irms_internal_boolean:
705 /* XXX C semantics */
706 if (src == get_mode_null(src->mode)) return tarval_b_false;
707 else return tarval_b_true;
714 case irms_internal_boolean:
715 switch (get_mode_sort(m))
717 case irms_int_number:
718 if (src == tarval_b_true) return get_mode_one(m);
719 else return get_mode_null(m);
738 tarval *tarval_neg(tarval *a)
742 assert(mode_is_num(a->mode)); /* negation only for numerical values */
743 assert(mode_is_signed(a->mode)); /* negation is difficult without negative numbers, isn't it */
745 switch (get_mode_sort(a->mode))
747 case irms_int_number:
749 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
751 case irms_float_number:
753 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), a->mode);
763 tarval *tarval_add(tarval *a, tarval *b)
768 assert((a->mode == b->mode) || (get_mode_sort(a->mode) == irms_character && mode_is_int(b->mode)));
770 switch (get_mode_sort(a->mode))
773 case irms_int_number:
774 /* modes of a,b are equal, so result has mode of a as this might be the character */
775 sc_add(a->value, b->value);
776 /* FIXME: Check for overflow */
777 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
779 case irms_float_number:
780 /* FIXME: Overflow/Underflow/transition to inf when mode < 80bit */
781 fc_add(a->value, b->value);
782 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), a->mode);
792 tarval *tarval_sub(tarval *a, tarval *b)
797 assert((a->mode == b->mode) || (get_mode_sort(a->mode) == irms_character && mode_is_int(b->mode)));
799 switch (get_mode_sort(a->mode))
802 case irms_int_number:
803 /* modes of a,b are equal, so result has mode of a as this might be the character */
804 sc_sub(a->value, b->value);
805 /* FIXME: check for overflow */
806 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
808 case irms_float_number:
809 /* FIXME: Overflow/Underflow/transition to inf when mode < 80bit */
810 fc_add(a->value, b->value);
811 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), a->mode);
821 tarval *tarval_mul(tarval *a, tarval *b)
826 assert((a->mode == b->mode) && mode_is_num(a->mode));
828 switch (get_mode_sort(a->mode))
830 case irms_int_number:
831 /* modes of a,b are equal */
832 sc_mul(a->value, b->value);
833 /* FIXME: check for overflow */
834 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
836 case irms_float_number:
837 /* FIXME: Overflow/Underflow/transition to inf when mode < 80bit */
838 fc_add(a->value, b->value);
839 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), a->mode);
847 * floating point division
849 tarval *tarval_quo(tarval *a, tarval *b)
854 assert((a->mode == b->mode) && mode_is_float(a->mode));
856 /* FIXME: Overflow/Underflow/transition to inf when mode < 80bit */
857 fc_div(a->value, b->value);
858 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), a->mode);
864 tarval *tarval_div(tarval *a, tarval *b)
869 assert((a->mode == b->mode) && mode_is_int(a->mode));
871 /* modes of a,b are equal */
872 sc_div(a->value, b->value);
873 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
879 tarval *tarval_mod(tarval *a, tarval *b)
884 assert((a->mode == b->mode) && mode_is_int(a->mode));
886 /* modes of a,b are equal */
887 sc_mod(a->value, b->value);
888 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
894 tarval *tarval_abs(tarval *a)
898 assert(mode_is_num(a->mode));
900 switch (get_mode_sort(a->mode))
902 case irms_int_number:
903 if (sc_comp(a->value, get_mode_null(a->mode)->value) == -1)
906 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
910 case irms_float_number:
922 tarval *tarval_and(tarval *a, tarval *b)
927 assert(a->mode == b->mode);
929 /* GL: needed for easy optimization. */
930 if (a->mode == mode_b) return (a == tarval_b_false) ? a : b;
932 assert(mode_is_int(a->mode));
934 sc_and(a->value, b->value);
935 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
941 tarval *tarval_or (tarval *a, tarval *b)
946 assert(a->mode == b->mode);
948 /* GL: needed for easy optimization. */
949 if (a->mode == mode_b) return (a == tarval_b_true) ? a : b;
952 assert(mode_is_int(a->mode));
954 sc_or(a->value, b->value);
955 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
959 * bitwise exclusive or (xor)
961 tarval *tarval_eor(tarval *a, tarval *b)
966 assert((a->mode == b->mode) && mode_is_int(a->mode));
968 sc_or(a->value, b->value);
969 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
975 tarval *tarval_shl(tarval *a, tarval *b)
980 assert(mode_is_int(a->mode) && mode_is_int(b->mode));
982 sc_shl(a->value, b->value, get_mode_size_bits(a->mode), mode_is_signed(a->mode));
983 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
987 * bitwise unsigned right shift
989 tarval *tarval_shr(tarval *a, tarval *b)
994 assert(mode_is_int(a->mode) && mode_is_int(b->mode));
996 sc_shr(a->value, b->value, get_mode_size_bits(a->mode), mode_is_signed(a->mode));
997 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
1001 * bitwise signed right shift
1003 tarval *tarval_shrs(tarval *a, tarval *b)
1008 assert(mode_is_int(a->mode) && mode_is_int(b->mode));
1010 sc_shrs(a->value, b->value, get_mode_size_bits(a->mode), mode_is_signed(a->mode));
1011 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
1017 tarval *tarval_rot(tarval *a, tarval *b)
1022 assert(mode_is_int(a->mode) && mode_is_int(b->mode));
1024 sc_rot(a->value, b->value, get_mode_size_bits(a->mode), mode_is_signed(a->mode));
1025 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
1032 int tarval_snprintf(char *buf, size_t len, tarval *tv)
1034 static const tarval_mode_info default_info = { TVO_NATIVE, NULL, NULL };
1038 const tarval_mode_info *mode_info;
1039 const char *prefix, *suffix;
1043 mode_info = tv->mode->tv_priv;
1045 mode_info = &default_info;
1046 prefix = mode_info->mode_prefix ? mode_info->mode_prefix : "";
1047 suffix = mode_info->mode_suffix ? mode_info->mode_suffix : "";
1049 switch (get_mode_sort(tv->mode))
1051 case irms_int_number:
1052 case irms_character:
1053 switch (mode_info->mode_output) {
1056 str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_DEC);
1060 str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_OCT);
1066 str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_HEX);
1069 return snprintf(buf, len, "%s%s%s", prefix, str, suffix);
1071 case irms_float_number:
1072 return snprintf(buf, len, "%s%s%s", prefix, fc_print_dec(tv->value, tv_buf, sizeof(tv_buf)), suffix);
1074 case irms_reference:
1075 if (tv==tarval_P_void) return snprintf(buf, len, "NULL");
1076 if (tv->value != NULL)
1077 if (tarval_is_entity(tv)) {
1078 if (get_entity_peculiarity((entity *)tv->value) == existent)
1079 return snprintf(buf, len, "%s%s%s", prefix, get_entity_ld_name((entity *)tv->value), suffix);
1081 if (mode_info->mode_output == TVO_NATIVE)
1082 return snprintf(buf, len, "NULL");
1084 return snprintf(buf, len, "0");
1088 if (size > tv->length) {
1089 memcpy(buf, tv->value, tv->length);
1090 buf[tv->length] = '\0';
1094 memcpy(buf, tv->value, size-1);
1100 return snprintf(buf, len, "void");
1102 case irms_internal_boolean:
1103 switch (mode_info->mode_output) {
1109 return snprintf(buf, len, "%s%c%s", prefix, (tv == tarval_b_true) ? '1' : '0', suffix);
1113 return snprintf(buf, len, "%s%s%s", prefix, (tv == tarval_b_true) ? "true" : "false", suffix);
1116 case irms_control_flow:
1118 case irms_auxiliary:
1119 return snprintf(buf, len, "<BAD>");
1127 * Output of tarvals to stdio.
1129 int tarval_printf(tarval *tv) {
1133 res = tarval_snprintf(buf, sizeof(buf), tv);
1134 assert(res < sizeof(buf) && "buffer to small for tarval_snprintf");
1140 char *tarval_bitpattern(tarval *tv)
1146 * access to the bitpattern
1148 unsigned char tarval_sub_bits(tarval *tv, unsigned byte_ofs)
1150 switch (get_mode_sort(tv->mode)) {
1151 case irms_int_number:
1152 case irms_character:
1153 return sc_sub_bits(tv->value, tv->length, byte_ofs);
1155 case irms_float_number:
1156 return fc_sub_bits(tv->value, get_mode_size_bits(tv->mode), byte_ofs);
1164 * Specify the output options of one mode.
1166 * This functions stores the modinfo, so DO NOT DESTROY it.
1168 * Returns zero on success.
1170 int tarval_set_mode_output_option(ir_mode *mode, const tarval_mode_info *modeinfo)
1174 mode->tv_priv = modeinfo;
1179 * Returns the output options of one mode.
1181 * This functions returns the modinfo of a given mode.
1183 const tarval_mode_info *tarval_get_mode_output_option(ir_mode *mode)
1187 return mode->tv_priv;
1191 /* Identifying some tarvals ??? */
1192 /* Implemented in old tv.c as such:
1193 * return 0 for additive neutral,
1194 * 1 for multiplicative neutral,
1195 * -1 for bitwise-and neutral
1198 * Implemented for completeness */
1199 long tarval_classify(tarval *tv)
1202 if (!tv || tv == tarval_bad) return 2;
1204 if (tv == get_mode_null(tv->mode)) return 0;
1205 else if (tv == get_mode_one(tv->mode)) return 1;
1206 else if ((get_mode_sort(tv->mode) == irms_int_number)
1207 && (tv == new_tarval_from_long(-1, tv->mode))) return -1;
1213 * Initialization of the tarval module: called before init_mode()
1215 void init_tarval_1(void)
1218 /* initialize the sets holding the tarvals with a comparison function and
1219 * an initial size, which is the expected number of constants */
1220 tarvals = new_set(memcmp, TUNE_NCONSTANTS);
1221 values = new_set(memcmp, TUNE_NCONSTANTS);
1222 /* init with default precision */
1224 /* init_fltcalc(0); not yet*/
1225 tarval_bad = (tarval*)malloc(sizeof(tarval));
1226 tarval_undefined = (tarval*)malloc(sizeof(tarval));
1227 tarval_b_true = (tarval*)malloc(sizeof(tarval));
1228 tarval_b_false = (tarval*)malloc(sizeof(tarval));
1229 tarval_P_void = (tarval*)malloc(sizeof(tarval));
1233 * default mode_info for output as HEX
1235 static const tarval_mode_info hex_output = {
1242 * default mode_info for output as reference
1244 static const tarval_mode_info reference_output = {
1252 * Initialization of the tarval module: called after init_mode()
1254 void init_tarval_2(void)
1258 tarval_bad->mode = mode_BAD;
1259 tarval_undefined->mode = mode_ANY;
1260 tarval_b_true->mode = mode_b;
1261 tarval_b_false->mode = mode_b;
1262 tarval_P_void->mode = mode_P;
1265 * assign output modes that are compatible with the
1266 * old implementation: Hex output
1268 tarval_set_mode_output_option(mode_U, &hex_output);
1269 tarval_set_mode_output_option(mode_C, &hex_output);
1270 tarval_set_mode_output_option(mode_Bs, &hex_output);
1271 tarval_set_mode_output_option(mode_Bu, &hex_output);
1272 tarval_set_mode_output_option(mode_Hs, &hex_output);
1273 tarval_set_mode_output_option(mode_Hu, &hex_output);
1274 tarval_set_mode_output_option(mode_Hs, &hex_output);
1275 tarval_set_mode_output_option(mode_Hu, &hex_output);
1276 tarval_set_mode_output_option(mode_Is, &hex_output);
1277 tarval_set_mode_output_option(mode_Iu, &hex_output);
1278 tarval_set_mode_output_option(mode_Ls, &hex_output);
1279 tarval_set_mode_output_option(mode_Lu, &hex_output);
1280 tarval_set_mode_output_option(mode_P, &reference_output);
1283 /****************************************************************************
1285 ****************************************************************************/