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))
170 case irms_int_number:
171 if (sc_comp(tv->value, get_mode_max(tv->mode)->value) == 1) return 1;
172 if (sc_comp(tv->value, get_mode_min(tv->mode)->value) == -1) return 1;
175 case irms_float_number:
179 if (fc_comp(tv->value, get_mode_max(tv->mode)->value) == 1) return 1;
180 if (fc_comp(tv->value, get_mode_min(tv->mode)->value) == -1) return 1;
191 * public variables declared in tv.h
194 tarval *tarval_undefined;
195 tarval *tarval_b_false;
196 tarval *tarval_b_true;
197 tarval *tarval_P_void;
200 * public functions declared in tv.h
204 * Constructors =============================================================
206 tarval *new_tarval_from_str(const char *str, size_t len, ir_mode *mode)
213 switch (get_mode_sort(mode))
215 case irms_control_flow:
221 case irms_internal_boolean:
222 /* match tTrRuUeE/fFaAlLsSeE */
223 if (strcasecmp(str, "true")) return tarval_b_true;
224 else if (strcasecmp(str, "false")) return tarval_b_true;
226 return atoi(str) ? tarval_b_true : tarval_b_false;
228 case irms_float_number:
229 fc_val_from_str(str, len);
230 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
232 case irms_int_number:
234 sc_val_from_str(str, len);
235 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), mode);
238 return get_tarval(str, len, mode);
241 assert(0); /* can't be reached, can it? */
246 int tarval_is_str(tarval *tv)
251 return ((get_mode_sort(tv->mode) == reference) && (tv->value != NULL) && (tv->length > 0));
253 char *tarval_to_str(tarval *tv)
256 assert(tarval_is_str(tv));
257 return (char *)tv->value;
262 * helper function, create a tarval from long
264 tarval *new_tarval_from_long(long l, ir_mode *mode)
267 assert(mode && !((get_mode_sort(mode) == irms_memory)||(get_mode_sort(mode)==irms_control_flow)||(get_mode_sort(mode)==irms_auxiliary)));
269 switch(get_mode_sort(mode))
271 case irms_internal_boolean:
272 /* XXX C-Semantics ! */
273 return l ? tarval_b_true : tarval_b_false ;
275 case irms_int_number:
278 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), mode);
280 case irms_float_number:
281 return new_tarval_from_double((long double)l, mode);
284 return l ? tarval_bad : get_tarval(NULL, 0, mode); /* null pointer or tarval_bad */
292 /* returns non-zero if can be converted to long */
293 int tarval_is_long(tarval *tv)
296 return ((get_mode_sort(tv->mode) == irms_int_number) || (get_mode_sort(tv->mode) == irms_character));
299 /* this might overflow the machine's long, so use only with small values */
300 long tarval_to_long(tarval* tv)
303 assert(tv && get_mode_sort(tv->mode) == irms_int_number);
305 return sc_val_to_long(tv->value); /* might overflow */
308 tarval *new_tarval_from_double(long double d, ir_mode *mode)
311 assert(mode && (get_mode_sort(mode) == irms_float_number));
313 fc_val_from_float(d);
314 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
317 /* returns non-zero if can be converted to double */
318 int tarval_is_double(tarval *tv)
323 return (get_mode_sort(tv->mode) == irms_float_number);
326 long double tarval_to_double(tarval *tv)
329 assert(tarval_is_double(tv));
331 return fc_val_to_float(tv->value);
334 /* The tarval represents the address of the entity. As the address must
335 be constant the entity must have as owner the global type. */
336 tarval *new_tarval_from_entity (entity *ent, ir_mode *mode)
340 assert(mode && (get_mode_sort(mode) == irms_reference));
342 return get_tarval((void *)ent, 0, mode);
344 int tarval_is_entity(tarval *tv)
348 /* tv->value == NULL means dereferencing a null pointer */
349 return ((get_mode_sort(tv->mode) == irms_reference) && (tv->value != NULL) && (tv->length == 0)
350 && (tv != tarval_P_void));
353 entity *tarval_to_entity(tarval *tv)
358 if (tarval_is_entity(tv))
359 return (entity *)tv->value;
361 assert(0 && "tarval did not represent an entity");
366 void free_tarval_entity(entity *ent) {
367 /* There can be a tarval referencing this entity. Even if the
368 tarval is not used by the code any more, it can still reference
369 the entity as tarvals live indepently of the entity referenced.
370 Further the tarval is hashed into a set. If a hash function
371 evaluation happens to collide with this tarval, we will vrfy that
372 it contains a proper entity and we will crash if the entity is
375 Unluckily, tarvals can neither be changed nor deleted, and to find
376 one, all existing reference modes have to be tried -> a facility
377 to retrieve all modes of a kind is needed. */
382 * Access routines for tarval fields ========================================
384 ir_mode *get_tarval_mode (tarval *tv) /* get the mode of the tarval */
392 * Special value query functions ============================================
394 * These functions calculate and return a tarval representing the requested
396 * The functions get_mode_{Max,Min,...} return tarvals retrieved from these
397 * functions, but these are stored on initialization of the irmode module and
398 * therefore the irmode functions should be prefered to the functions below.
401 tarval *get_tarval_bad(void)
406 tarval *get_tarval_undefined(void)
409 return tarval_undefined;
411 tarval *get_tarval_b_false(void)
414 return tarval_b_false;
416 tarval *get_tarval_b_true(void)
419 return tarval_b_true;
421 tarval *get_tarval_P_void(void)
424 return tarval_P_void;
427 tarval *get_tarval_max(ir_mode *mode)
432 switch(get_mode_sort(mode))
435 case irms_control_flow:
441 case irms_internal_boolean:
442 return tarval_b_true;
444 case irms_float_number:
445 fc_get_max(get_mode_size_bits(mode));
446 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
448 case irms_int_number:
450 sc_max_from_bits(get_mode_size_bits(mode), mode_is_signed(mode));
451 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), mode);
456 tarval *get_tarval_min(ir_mode *mode)
461 switch(get_mode_sort(mode))
464 case irms_control_flow:
470 case irms_internal_boolean:
471 return tarval_b_false;
473 case irms_float_number:
474 fc_get_min(get_mode_size_bits(mode));
475 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
477 case irms_int_number:
479 sc_min_from_bits(get_mode_size_bits(mode), mode_is_signed(mode));
480 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), mode);
485 tarval *get_tarval_null(ir_mode *mode)
490 switch(get_mode_sort(mode))
492 case irms_control_flow:
495 case irms_internal_boolean:
499 case irms_float_number:
500 return new_tarval_from_double(0.0, mode);
502 case irms_int_number:
504 return new_tarval_from_long(0l, mode);
507 return tarval_P_void;
512 tarval *get_tarval_one(ir_mode *mode)
517 switch(get_mode_sort(mode))
519 case irms_control_flow:
522 case irms_internal_boolean:
527 case irms_float_number:
528 return new_tarval_from_double(1.0, mode);
530 case irms_int_number:
532 return new_tarval_from_long(1l, mode);
538 tarval *get_tarval_nan(ir_mode *mode)
543 if (get_mode_sort(mode) == irms_float_number) {
545 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
548 assert(0 && "tarval is not floating point");
553 tarval *get_tarval_inf(ir_mode *mode)
558 if (get_mode_sort(mode) == irms_float_number) {
560 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
563 assert(0 && "tarval is not floating point");
569 * Arithmethic operations on tarvals ========================================
573 * test if negative number, 1 means 'yes'
575 int tarval_is_negative(tarval *a)
580 switch (get_mode_sort(a->mode))
582 case irms_int_number:
583 if (!mode_is_signed(a->mode)) return 0;
585 return sc_comp(a->value, get_mode_null(a->mode)->value) == -1 ? 1 : 0;
587 case irms_float_number:
588 return fc_comp(a->value, get_mode_null(a->mode)->value) == -1 ? 1 : 0;
591 assert(0 && "not implemented");
597 * test if null, 1 means 'yes'
599 int tarval_is_null(tarval *a)
601 ir_mode *m = get_tarval_mode(a);
603 return a == get_tarval_null(m);
609 pnc_number tarval_cmp(tarval *a, tarval *b)
615 if (a == tarval_bad || b == tarval_bad) assert(0 && "Comparison with tarval_bad");
616 if (a == tarval_undefined || b == tarval_undefined) return False;
617 if (a == b) return Eq;
618 if (get_tarval_mode(a) != get_tarval_mode(b)) return Uo;
620 /* Here the two tarvals are unequal and of the same mode */
621 switch (get_mode_sort(a->mode))
623 case irms_control_flow:
628 case irms_float_number:
629 return (fc_comp(a->value, b->value)==1)?(Gt):(Lt);
631 case irms_int_number:
633 return (sc_comp(a->value, b->value)==1)?(Gt):(Lt);
635 case irms_internal_boolean:
636 return (a == tarval_b_true)?(Gt):(Lt);
645 * convert to other mode
647 tarval *tarval_convert_to(tarval *src, ir_mode *m)
655 if (src->mode == m) return src;
657 switch (get_mode_sort(src->mode))
659 case irms_control_flow:
664 case irms_float_number:
665 switch (get_mode_sort(m)) {
666 case irms_float_number:
668 tv.length = src->length;
669 tv.value = src->value;
670 if (overflows(&tv)) {
674 return INSERT_TARVAL(&tv);
681 case irms_int_number:
682 switch (get_mode_sort(m)) {
683 case irms_int_number:
686 tv.length = src->length;
687 tv.value = src->value;
691 return INSERT_TARVAL(&tv);
693 case irms_internal_boolean:
694 /* XXX C semantics */
695 if (src == get_mode_null(src->mode)) return tarval_b_false;
696 else return tarval_b_true;
703 case irms_internal_boolean:
704 switch (get_mode_sort(m))
706 case irms_int_number:
707 if (src == tarval_b_true) return get_mode_one(m);
708 else return get_mode_null(m);
727 tarval *tarval_neg(tarval *a)
731 assert(mode_is_num(a->mode)); /* negation only for numerical values */
732 assert(mode_is_signed(a->mode)); /* negation is difficult without negative numbers, isn't it */
734 switch (get_mode_sort(a->mode))
736 case irms_int_number:
738 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
740 case irms_float_number:
742 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), a->mode);
752 tarval *tarval_add(tarval *a, tarval *b)
757 assert((a->mode == b->mode) || (get_mode_sort(a->mode) == irms_character && mode_is_int(b->mode)));
759 switch (get_mode_sort(a->mode))
762 case irms_int_number:
763 /* modes of a,b are equal, so result has mode of a as this might be the character */
764 sc_add(a->value, b->value);
765 /* FIXME: Check for overflow */
766 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
768 case irms_float_number:
769 /* FIXME: Overflow/Underflow/transition to inf when mode < 80bit */
770 fc_add(a->value, b->value);
771 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), a->mode);
781 tarval *tarval_sub(tarval *a, tarval *b)
786 assert((a->mode == b->mode) || (get_mode_sort(a->mode) == irms_character && mode_is_int(b->mode)));
788 switch (get_mode_sort(a->mode))
791 case irms_int_number:
792 /* modes of a,b are equal, so result has mode of a as this might be the character */
793 sc_sub(a->value, b->value);
794 /* FIXME: check for overflow */
795 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
797 case irms_float_number:
798 /* FIXME: Overflow/Underflow/transition to inf when mode < 80bit */
799 fc_add(a->value, b->value);
800 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), a->mode);
810 tarval *tarval_mul(tarval *a, tarval *b)
815 assert((a->mode == b->mode) && mode_is_num(a->mode));
817 switch (get_mode_sort(a->mode))
819 case irms_int_number:
820 /* modes of a,b are equal */
821 sc_mul(a->value, b->value);
822 /* FIXME: check for overflow */
823 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
825 case irms_float_number:
826 /* FIXME: Overflow/Underflow/transition to inf when mode < 80bit */
827 fc_add(a->value, b->value);
828 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), a->mode);
836 * floating point division
838 tarval *tarval_quo(tarval *a, tarval *b)
843 assert((a->mode == b->mode) && mode_is_float(a->mode));
845 /* FIXME: Overflow/Underflow/transition to inf when mode < 80bit */
846 fc_div(a->value, b->value);
847 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), a->mode);
853 tarval *tarval_div(tarval *a, tarval *b)
858 assert((a->mode == b->mode) && mode_is_int(a->mode));
860 /* modes of a,b are equal */
861 sc_div(a->value, b->value);
862 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
868 tarval *tarval_mod(tarval *a, tarval *b)
873 assert((a->mode == b->mode) && mode_is_int(a->mode));
875 /* modes of a,b are equal */
876 sc_mod(a->value, b->value);
877 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
883 tarval *tarval_abs(tarval *a)
887 assert(mode_is_num(a->mode));
889 switch (get_mode_sort(a->mode))
891 case irms_int_number:
892 if (sc_comp(a->value, get_mode_null(a->mode)->value) == -1)
895 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
899 case irms_float_number:
911 tarval *tarval_and(tarval *a, tarval *b)
916 assert(a->mode == b->mode);
918 /* GL: needed for easy optimization. */
919 if (a->mode == mode_b) return (a == tarval_b_false) ? a : b;
921 assert(mode_is_int(a->mode));
923 sc_and(a->value, b->value);
924 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
930 tarval *tarval_or (tarval *a, tarval *b)
935 assert(a->mode == b->mode);
937 /* GL: needed for easy optimization. */
938 if (a->mode == mode_b) return (a == tarval_b_true) ? a : b;
941 assert(mode_is_int(a->mode));
943 sc_or(a->value, b->value);
944 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
948 * bitwise exclusive or (xor)
950 tarval *tarval_eor(tarval *a, tarval *b)
955 assert((a->mode == b->mode) && mode_is_int(a->mode));
957 sc_or(a->value, b->value);
958 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
964 tarval *tarval_shl(tarval *a, tarval *b)
969 assert(mode_is_int(a->mode) && mode_is_int(b->mode));
971 sc_shl(a->value, b->value, get_mode_size_bits(a->mode), mode_is_signed(a->mode));
972 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
976 * bitwise unsigned right shift
978 tarval *tarval_shr(tarval *a, tarval *b)
983 assert(mode_is_int(a->mode) && mode_is_int(b->mode));
985 sc_shr(a->value, b->value, get_mode_size_bits(a->mode), mode_is_signed(a->mode));
986 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
990 * bitwise signed right shift
992 tarval *tarval_shrs(tarval *a, tarval *b)
997 assert(mode_is_int(a->mode) && mode_is_int(b->mode));
999 sc_shrs(a->value, b->value, get_mode_size_bits(a->mode), mode_is_signed(a->mode));
1000 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
1006 tarval *tarval_rot(tarval *a, tarval *b)
1011 assert(mode_is_int(a->mode) && mode_is_int(b->mode));
1013 sc_rot(a->value, b->value, get_mode_size_bits(a->mode), mode_is_signed(a->mode));
1014 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
1021 int tarval_snprintf(char *buf, size_t len, tarval *tv)
1023 static const tarval_mode_info default_info = { TVO_NATIVE, NULL, NULL };
1027 const tarval_mode_info *mode_info;
1028 const char *prefix, *suffix;
1032 mode_info = tv->mode->tv_priv;
1034 mode_info = &default_info;
1035 prefix = mode_info->mode_prefix ? mode_info->mode_prefix : "";
1036 suffix = mode_info->mode_suffix ? mode_info->mode_suffix : "";
1038 switch (get_mode_sort(tv->mode))
1040 case irms_int_number:
1041 case irms_character:
1042 switch (mode_info->mode_output) {
1045 str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_DEC);
1049 str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_OCT);
1055 str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_HEX);
1058 return snprintf(buf, len, "%s%s%s", prefix, str, suffix);
1060 case irms_float_number:
1061 return snprintf(buf, len, "%s%s%s", prefix, fc_print_dec(tv->value, tv_buf, sizeof(tv_buf)), suffix);
1063 case irms_reference:
1064 if (tv->value != NULL)
1065 if (tarval_is_entity(tv)) {
1066 if (get_entity_peculiarity((entity *)tv->value) == existent)
1067 return snprintf(buf, len, "%s%s%s", prefix, get_entity_ld_name((entity *)tv->value), suffix);
1069 if (mode_info->mode_output == TVO_NATIVE)
1070 return snprintf(buf, len, "NULL");
1072 return snprintf(buf, len, "0");
1076 if (size > tv->length) {
1077 memcpy(buf, tv->value, tv->length);
1078 buf[tv->length] = '\0';
1082 memcpy(buf, tv->value, size-1);
1088 return snprintf(buf, len, "void");
1090 case irms_internal_boolean:
1091 switch (mode_info->mode_output) {
1097 return snprintf(buf, len, "%s%c%s", prefix, (tv == tarval_b_true) ? '1' : '0', suffix);
1101 return snprintf(buf, len, "%s%s%s", prefix, (tv == tarval_b_true) ? "true" : "false", suffix);
1104 case irms_control_flow:
1106 case irms_auxiliary:
1107 return snprintf(buf, len, "<BAD>");
1115 * Output of tarvals to stdio.
1117 int tarval_printf(tarval *tv) {
1121 res = tarval_snprintf(buf, sizeof(buf), tv);
1122 assert(res < sizeof(buf) && "buffer to small for tarval_snprintf");
1128 char *tarval_bitpattern(tarval *tv)
1134 * access to the bitpattern
1136 unsigned char tarval_sub_bits(tarval *tv, unsigned byte_ofs)
1138 switch (get_mode_sort(tv->mode)) {
1139 case irms_int_number:
1140 case irms_character:
1141 return sc_sub_bits(tv->value, tv->length, byte_ofs);
1143 case irms_float_number:
1144 return fc_sub_bits(tv->value, get_mode_size_bits(tv->mode), byte_ofs);
1152 * Specify the output options of one mode.
1154 * This functions stores the modinfo, so DO NOT DESTROY it.
1156 * Returns zero on success.
1158 int tarval_set_mode_output_option(ir_mode *mode, const tarval_mode_info *modeinfo)
1162 mode->tv_priv = modeinfo;
1166 /* Identifying some tarvals ??? */
1167 /* Implemented in old tv.c as such:
1168 * return 0 for additive neutral,
1169 * 1 for multiplicative neutral,
1170 * -1 for bitwise-and neutral
1173 * Implemented for completeness */
1174 long tarval_classify(tarval *tv)
1177 if (!tv || tv == tarval_bad) return 2;
1179 if (tv == get_mode_null(tv->mode)) return 0;
1180 else if (tv == get_mode_one(tv->mode)) return 1;
1181 else if ((get_mode_sort(tv->mode) == irms_int_number)
1182 && (tv == new_tarval_from_long(-1, tv->mode))) return -1;
1188 * Initialization of the tarval module: called before init_mode()
1190 void init_tarval_1(void)
1193 /* initialize the sets holding the tarvals with a comparison function and
1194 * an initial size, which is the expected number of constants */
1195 tarvals = new_set(memcmp, TUNE_NCONSTANTS);
1196 values = new_set(memcmp, TUNE_NCONSTANTS);
1197 /* init with default precision */
1199 /* init_fltcalc(0); not yet*/
1200 tarval_bad = (tarval*)malloc(sizeof(tarval));
1201 tarval_undefined = (tarval*)malloc(sizeof(tarval));
1202 tarval_b_true = (tarval*)malloc(sizeof(tarval));
1203 tarval_b_false = (tarval*)malloc(sizeof(tarval));
1204 tarval_P_void = (tarval*)malloc(sizeof(tarval));
1208 * default mode_info for output as HEX
1210 static const tarval_mode_info hex_output = {
1217 * default mode_info for output as reference
1219 static const tarval_mode_info reference_output = {
1227 * Initialization of the tarval module: called after init_mode()
1229 void init_tarval_2(void)
1233 tarval_bad->mode = mode_BAD;
1234 tarval_undefined->mode = mode_ANY;
1235 tarval_b_true->mode = mode_b;
1236 tarval_b_false->mode = mode_b;
1237 tarval_P_void->mode = mode_P;
1240 * assign output modes that are compatible with the
1241 * old implementation: Hex output
1243 tarval_set_mode_output_option(mode_U, &hex_output);
1244 tarval_set_mode_output_option(mode_C, &hex_output);
1245 tarval_set_mode_output_option(mode_Bs, &hex_output);
1246 tarval_set_mode_output_option(mode_Bu, &hex_output);
1247 tarval_set_mode_output_option(mode_Hs, &hex_output);
1248 tarval_set_mode_output_option(mode_Hu, &hex_output);
1249 tarval_set_mode_output_option(mode_Hs, &hex_output);
1250 tarval_set_mode_output_option(mode_Hu, &hex_output);
1251 tarval_set_mode_output_option(mode_Is, &hex_output);
1252 tarval_set_mode_output_option(mode_Iu, &hex_output);
1253 tarval_set_mode_output_option(mode_Ls, &hex_output);
1254 tarval_set_mode_output_option(mode_Lu, &hex_output);
1255 tarval_set_mode_output_option(mode_P, &reference_output);
1258 /****************************************************************************
1260 ****************************************************************************/