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 */
47 #include "set.h" /* to store tarvals in */
48 #include "tune.h" /* some constants */
49 #include "entity_t.h" /* needed to store pointers to entities */
50 #include "irmode.h" /* defines modes etc */
52 #include "irnode.h" /* defines boolean return values */
57 /****************************************************************************
58 * local definitions and macros
59 ****************************************************************************/
61 # define TARVAL_VERIFY(a) tarval_verify((a))
63 # define TARVAL_VERIFY(a) ((void)0)
66 #define INSERT_TARVAL(tv) ((tarval*)set_insert(tarvals, (tv), sizeof(tarval), hash_tv((tv))))
67 #define FIND_TARVAL(tv) ((tarval*)set_find(tarvals, (tv), sizeof(tarval), hash_tv((tv))))
69 #define INSERT_VALUE(val, size) (set_insert(values, (val), size, hash_val((val), size)))
70 #define FIND_VALUE(val, size) (set_find(values, (val), size, hash_val((val), size)))
72 #define fail_verify(a) _fail_verify((a), __FILE__, __LINE__)
74 static long long count = 0;
75 # define ANNOUNCE() printf(__FILE__": call no. %lld (%s)\n", count++, __FUNCTION__);
77 # define ANNOUNCE() ((void)0)
79 /****************************************************************************
81 ****************************************************************************/
82 static struct set *tarvals; /* container for tarval structs */
83 static struct set *values; /* container for values */
85 /****************************************************************************
87 ****************************************************************************/
89 static int hash_val(const void *value, unsigned int length);
90 static int hash_tv(tarval *tv);
91 static void _fail_verify(tarval *tv, const char* file, int line)
93 /* print a memory image of the tarval and throw an assertion */
95 printf("%s:%d: Invalid tarval:\n mode: %s\n value: [%p]\n", file, line, get_mode_name(tv->mode), tv->value);
97 printf("%s:%d: Invalid tarval (null)", file, line);
101 INLINE static void tarval_verify(tarval *tv) __attribute__ ((unused));
104 INLINE static void tarval_verify(tarval *tv)
110 if ((tv == tarval_bad) || (tv == tarval_undefined)) return;
111 if ((tv == tarval_b_true) || (tv == tarval_b_false)) return;
113 if (!FIND_TARVAL(tv)) fail_verify(tv);
114 if (tv->length > 0 && !FIND_VALUE(tv->value, tv->length)) fail_verify(tv);
120 static int hash_tv(tarval *tv)
122 return ((unsigned int)tv->value ^ (unsigned int)tv->mode) + tv->length;
125 static int hash_val(const void *value, unsigned int length)
128 unsigned int hash = 0;
130 /* scramble the byte - array */
131 for (i = 0; i < length; i++)
133 hash += (hash << 5) ^ (hash >> 27) ^ ((char*)value)[i];
134 hash += (hash << 11) ^ (hash >> 17);
140 /* finds tarval with value/mode or creates new tarval */
141 static tarval *get_tarval(const void *value, int length, ir_mode *mode)
148 /* if there already is such a value, it is returned, else value
149 * is copied into the set */
150 tv.value = INSERT_VALUE(value, length);
154 /* if there is such a tarval, it is returned, else tv is copied
156 return (tarval *)INSERT_TARVAL(&tv);
160 * Returns non-zero if a tarval overflows.
162 * @todo Implementation did not work on all modes
164 static int overflows(tarval *tv)
166 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 return ((get_mode_sort(tv->mode) == irms_int_number) || (get_mode_sort(tv->mode) == irms_character));
298 /* this might overflow the machine's long, so use only with small values */
299 long tarval_to_long(tarval* tv)
302 assert(tv && get_mode_sort(tv->mode) == irms_int_number);
304 return sc_val_to_long(tv->value); /* might overflow */
307 tarval *new_tarval_from_double(long double d, ir_mode *mode)
310 assert(mode && (get_mode_sort(mode) == irms_float_number));
312 fc_val_from_float(d);
313 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
316 /* returns non-zero if can be converted to double */
317 int tarval_is_double(tarval *tv)
322 return (get_mode_sort(tv->mode) == irms_float_number);
325 long double tarval_to_double(tarval *tv)
328 assert(tarval_is_double(tv));
330 return fc_val_to_float(tv->value);
333 /* The tarval represents the address of the entity. As the address must
334 be constant the entity must have as owner the global type. */
335 tarval *new_tarval_from_entity (entity *ent, ir_mode *mode)
339 assert(mode && (get_mode_sort(mode) == irms_reference));
341 return get_tarval((void *)ent, 0, mode);
343 int tarval_is_entity(tarval *tv)
347 /* tv->value == NULL means dereferencing a null pointer */
348 return ((get_mode_sort(tv->mode) == irms_reference) && (tv->value != NULL) && (tv->length == 0)
349 && (tv != tarval_P_void));
352 entity *tarval_to_entity(tarval *tv)
357 if (tarval_is_entity(tv))
358 return (entity *)tv->value;
360 assert(0 && "tarval did not represent an entity");
365 void free_tarval_entity(entity *ent) {
366 /* There can be a tarval referencing this entity. Even if the
367 tarval is not used by the code any more, it can still reference
368 the entity as tarvals live indepently of the entity referenced.
369 Further the tarval is hashed into a set. If a hash function
370 evaluation happens to collide with this tarval, we will vrfy that
371 it contains a proper entity and we will crash if the entity is
374 Unluckily, tarvals can neither be changed nor deleted, and to find
375 one, all existing reference modes have to be tried -> a facility
376 to retrieve all modes of a kind is needed. */
381 * Access routines for tarval fields ========================================
383 ir_mode *get_tarval_mode (tarval *tv) /* get the mode of the tarval */
391 * Special value query functions ============================================
393 * These functions calculate and return a tarval representing the requested
395 * The functions get_mode_{Max,Min,...} return tarvals retrieved from these
396 * functions, but these are stored on initialization of the irmode module and
397 * therefore the irmode functions should be prefered to the functions below.
400 tarval *get_tarval_bad(void)
405 tarval *get_tarval_undefined(void)
408 return tarval_undefined;
410 tarval *get_tarval_b_false(void)
413 return tarval_b_false;
415 tarval *get_tarval_b_true(void)
418 return tarval_b_true;
420 tarval *get_tarval_P_void(void)
423 return tarval_P_void;
426 tarval *get_tarval_max(ir_mode *mode)
431 switch(get_mode_sort(mode))
434 case irms_control_flow:
440 case irms_internal_boolean:
441 return tarval_b_true;
443 case irms_float_number:
444 fc_get_max(get_mode_size_bits(mode));
445 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
447 case irms_int_number:
449 sc_max_from_bits(get_mode_size_bits(mode), mode_is_signed(mode));
450 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), mode);
455 tarval *get_tarval_min(ir_mode *mode)
460 switch(get_mode_sort(mode))
463 case irms_control_flow:
469 case irms_internal_boolean:
470 return tarval_b_false;
472 case irms_float_number:
473 fc_get_min(get_mode_size_bits(mode));
474 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
476 case irms_int_number:
478 sc_min_from_bits(get_mode_size_bits(mode), mode_is_signed(mode));
479 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), mode);
484 tarval *get_tarval_null(ir_mode *mode)
489 switch(get_mode_sort(mode))
491 case irms_control_flow:
494 case irms_internal_boolean:
498 case irms_float_number:
499 return new_tarval_from_double(0.0, mode);
501 case irms_int_number:
503 return new_tarval_from_long(0l, mode);
506 return tarval_P_void;
511 tarval *get_tarval_one(ir_mode *mode)
516 switch(get_mode_sort(mode))
518 case irms_control_flow:
521 case irms_internal_boolean:
526 case irms_float_number:
527 return new_tarval_from_double(1.0, mode);
529 case irms_int_number:
531 return new_tarval_from_long(1l, mode);
537 tarval *get_tarval_nan(ir_mode *mode)
542 if (get_mode_sort(mode) == irms_float_number) {
544 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
547 assert(0 && "tarval is not floating point");
552 tarval *get_tarval_inf(ir_mode *mode)
557 if (get_mode_sort(mode) == irms_float_number) {
559 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
562 assert(0 && "tarval is not floating point");
568 * Arithmethic operations on tarvals ========================================
572 * test if negative number, 1 means 'yes'
574 int tarval_is_negative(tarval *a)
579 switch (get_mode_sort(a->mode))
581 case irms_int_number:
582 if (!mode_is_signed(a->mode)) return 0;
584 return sc_comp(a->value, get_mode_null(a->mode)->value) == -1 ? 1 : 0;
586 case irms_float_number:
587 return fc_comp(a->value, get_mode_null(a->mode)->value) == -1 ? 1 : 0;
590 assert(0 && "not implemented");
596 * test if null, 1 means 'yes'
598 int tarval_is_null(tarval *a)
600 ir_mode *m = get_tarval_mode(a);
602 return a == get_tarval_null(m);
608 pnc_number tarval_cmp(tarval *a, tarval *b)
614 if (a == tarval_bad || b == tarval_bad) assert(0 && "Comparison with tarval_bad");
615 if (a == tarval_undefined || b == tarval_undefined) return False;
616 if (a == b) return Eq;
617 if (get_tarval_mode(a) != get_tarval_mode(b)) return Uo;
619 /* Here the two tarvals are unequal and of the same mode */
620 switch (get_mode_sort(a->mode))
622 case irms_control_flow:
627 case irms_float_number:
628 return (fc_comp(a->value, b->value)==1)?(Gt):(Lt);
630 case irms_int_number:
632 return (sc_comp(a->value, b->value)==1)?(Gt):(Lt);
634 case irms_internal_boolean:
635 return (a == tarval_b_true)?(Gt):(Lt);
644 * convert to other mode
646 tarval *tarval_convert_to(tarval *src, ir_mode *m)
654 if (src->mode == m) return src;
656 switch (get_mode_sort(src->mode))
658 case irms_control_flow:
663 case irms_float_number:
664 switch (get_mode_sort(m)) {
665 case irms_float_number:
667 tv.length = src->length;
668 tv.value = src->value;
669 if (overflows(&tv)) {
673 return INSERT_TARVAL(&tv);
680 case irms_int_number:
681 switch (get_mode_sort(m)) {
682 case irms_int_number:
685 tv.length = src->length;
686 tv.value = src->value;
690 return INSERT_TARVAL(&tv);
692 case irms_internal_boolean:
693 /* XXX C semantics */
694 if (src == get_mode_null(src->mode)) return tarval_b_false;
695 else return tarval_b_true;
702 case irms_internal_boolean:
703 switch (get_mode_sort(m))
705 case irms_int_number:
706 if (src == tarval_b_true) return get_mode_one(m);
707 else return get_mode_null(m);
726 tarval *tarval_neg(tarval *a)
730 assert(mode_is_num(a->mode)); /* negation only for numerical values */
731 assert(mode_is_signed(a->mode)); /* negation is difficult without negative numbers, isn't it */
733 switch (get_mode_sort(a->mode))
735 case irms_int_number:
737 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
739 case irms_float_number:
741 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), a->mode);
751 tarval *tarval_add(tarval *a, tarval *b)
756 assert((a->mode == b->mode) || (get_mode_sort(a->mode) == irms_character && mode_is_int(b->mode)));
758 switch (get_mode_sort(a->mode))
761 case irms_int_number:
762 /* modes of a,b are equal, so result has mode of a as this might be the character */
763 sc_add(a->value, b->value);
764 /* FIXME: Check for overflow */
765 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
767 case irms_float_number:
768 /* FIXME: Overflow/Underflow/transition to inf when mode < 80bit */
769 fc_add(a->value, b->value);
770 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), a->mode);
780 tarval *tarval_sub(tarval *a, tarval *b)
785 assert((a->mode == b->mode) || (get_mode_sort(a->mode) == irms_character && mode_is_int(b->mode)));
787 switch (get_mode_sort(a->mode))
790 case irms_int_number:
791 /* modes of a,b are equal, so result has mode of a as this might be the character */
792 sc_sub(a->value, b->value);
793 /* FIXME: check for overflow */
794 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
796 case irms_float_number:
797 /* FIXME: Overflow/Underflow/transition to inf when mode < 80bit */
798 fc_add(a->value, b->value);
799 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), a->mode);
809 tarval *tarval_mul(tarval *a, tarval *b)
814 assert((a->mode == b->mode) && mode_is_num(a->mode));
816 switch (get_mode_sort(a->mode))
818 case irms_int_number:
819 /* modes of a,b are equal */
820 sc_mul(a->value, b->value);
821 /* FIXME: check for overflow */
822 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
824 case irms_float_number:
825 /* FIXME: Overflow/Underflow/transition to inf when mode < 80bit */
826 fc_add(a->value, b->value);
827 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), a->mode);
835 * floating point division
837 tarval *tarval_quo(tarval *a, tarval *b)
842 assert((a->mode == b->mode) && mode_is_float(a->mode));
844 /* FIXME: Overflow/Underflow/transition to inf when mode < 80bit */
845 fc_div(a->value, b->value);
846 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), a->mode);
852 tarval *tarval_div(tarval *a, tarval *b)
857 assert((a->mode == b->mode) && mode_is_int(a->mode));
859 /* modes of a,b are equal */
860 sc_div(a->value, b->value);
861 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
867 tarval *tarval_mod(tarval *a, tarval *b)
872 assert((a->mode == b->mode) && mode_is_int(a->mode));
874 /* modes of a,b are equal */
875 sc_mod(a->value, b->value);
876 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
882 tarval *tarval_abs(tarval *a)
886 assert(mode_is_num(a->mode));
888 switch (get_mode_sort(a->mode))
890 case irms_int_number:
891 if (sc_comp(a->value, get_mode_null(a->mode)->value) == -1)
894 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
898 case irms_float_number:
910 tarval *tarval_and(tarval *a, tarval *b)
915 assert(a->mode == b->mode);
917 /* GL: needed for easy optimization. */
918 if (a->mode == mode_b) return (a == tarval_b_false) ? a : b;
920 assert(mode_is_int(a->mode));
922 sc_and(a->value, b->value);
923 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
929 tarval *tarval_or (tarval *a, tarval *b)
934 assert(a->mode == b->mode);
936 /* GL: needed for easy optimization. */
937 if (a->mode == mode_b) return (a == tarval_b_true) ? a : b;
940 assert(mode_is_int(a->mode));
942 sc_or(a->value, b->value);
943 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
947 * bitwise exclusive or (xor)
949 tarval *tarval_eor(tarval *a, tarval *b)
954 assert((a->mode == b->mode) && mode_is_int(a->mode));
956 sc_or(a->value, b->value);
957 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
963 tarval *tarval_shl(tarval *a, tarval *b)
968 assert(mode_is_int(a->mode) && mode_is_int(b->mode));
970 sc_shl(a->value, b->value, get_mode_size_bits(a->mode), mode_is_signed(a->mode));
971 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
975 * bitwise unsigned right shift
977 tarval *tarval_shr(tarval *a, tarval *b)
982 assert(mode_is_int(a->mode) && mode_is_int(b->mode));
984 sc_shr(a->value, b->value, get_mode_size_bits(a->mode), mode_is_signed(a->mode));
985 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
989 * bitwise signed right shift
991 tarval *tarval_shrs(tarval *a, tarval *b)
996 assert(mode_is_int(a->mode) && mode_is_int(b->mode));
998 sc_shrs(a->value, b->value, get_mode_size_bits(a->mode), mode_is_signed(a->mode));
999 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
1005 tarval *tarval_rot(tarval *a, tarval *b)
1010 assert(mode_is_int(a->mode) && mode_is_int(b->mode));
1012 sc_rot(a->value, b->value, get_mode_size_bits(a->mode), mode_is_signed(a->mode));
1013 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
1020 int tarval_snprintf(char *buf, size_t len, tarval *tv)
1022 static const tarval_mode_info default_info = { TVO_NATIVE, NULL, NULL };
1026 const tarval_mode_info *mode_info;
1027 const char *prefix, *suffix;
1031 mode_info = tv->mode->tv_priv;
1033 mode_info = &default_info;
1034 prefix = mode_info->mode_prefix ? mode_info->mode_prefix : "";
1035 suffix = mode_info->mode_suffix ? mode_info->mode_suffix : "";
1037 switch (get_mode_sort(tv->mode))
1039 case irms_int_number:
1040 case irms_character:
1041 switch (mode_info->mode_output) {
1044 str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_DEC);
1048 str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_OCT);
1054 str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_HEX);
1057 return snprintf(buf, len, "%s%s%s", prefix, str, suffix);
1059 case irms_float_number:
1060 return snprintf(buf, len, "%s%s%s", prefix, fc_print_dec(tv->value, tv_buf, sizeof(tv_buf)), suffix);
1062 case irms_reference:
1063 if (tv->value != NULL)
1064 if (tarval_is_entity(tv)) {
1065 if (get_entity_peculiarity((entity *)tv->value) == existent)
1066 return snprintf(buf, len, "%s%s%s", prefix, get_entity_ld_name((entity *)tv->value), suffix);
1068 if (mode_info->mode_output == TVO_NATIVE)
1069 return snprintf(buf, len, "NULL");
1071 return snprintf(buf, len, "0");
1075 if (size > tv->length) {
1076 memcpy(buf, tv->value, tv->length);
1077 buf[tv->length] = '\0';
1081 memcpy(buf, tv->value, size-1);
1087 return snprintf(buf, len, "void");
1089 case irms_internal_boolean:
1090 switch (mode_info->mode_output) {
1096 return snprintf(buf, len, "%s%c%s", prefix, (tv == tarval_b_true) ? '1' : '0', suffix);
1100 return snprintf(buf, len, "%s%s%s", prefix, (tv == tarval_b_true) ? "true" : "false", suffix);
1103 case irms_control_flow:
1105 case irms_auxiliary:
1106 return snprintf(buf, len, "<BAD>");
1114 * Output of tarvals to stdio.
1116 int tarval_printf(tarval *tv) {
1120 res = tarval_snprintf(buf, sizeof(buf), tv);
1121 assert(res < sizeof(buf) && "buffer to small for tarval_snprintf");
1127 char *tarval_bitpattern(tarval *tv)
1133 * access to the bitpattern
1135 unsigned char tarval_sub_bits(tarval *tv, unsigned byte_ofs)
1137 switch (get_mode_sort(tv->mode)) {
1138 case irms_int_number:
1139 case irms_character:
1140 return sc_sub_bits(tv->value, tv->length, byte_ofs);
1142 case irms_float_number:
1143 return fc_sub_bits(tv->value, get_mode_size_bits(tv->mode), byte_ofs);
1151 * Specify the output options of one mode.
1153 * This functions stores the modinfo, so DO NOT DESTROY it.
1155 * Returns zero on success.
1157 int tarval_set_mode_output_option(ir_mode *mode, const tarval_mode_info *modeinfo)
1161 mode->tv_priv = modeinfo;
1165 /* Identifying some tarvals ??? */
1166 /* Implemented in old tv.c as such:
1167 * return 0 for additive neutral,
1168 * 1 for multiplicative neutral,
1169 * -1 for bitwise-and neutral
1172 * Implemented for completeness */
1173 long tarval_classify(tarval *tv)
1176 if (!tv || tv == tarval_bad) return 2;
1178 if (tv == get_mode_null(tv->mode)) return 0;
1179 else if (tv == get_mode_one(tv->mode)) return 1;
1180 else if ((get_mode_sort(tv->mode) == irms_int_number)
1181 && (tv == new_tarval_from_long(-1, tv->mode))) return -1;
1187 * Initialization of the tarval module: called before init_mode()
1189 void init_tarval_1(void)
1192 /* initialize the sets holding the tarvals with a comparison function and
1193 * an initial size, which is the expected number of constants */
1194 tarvals = new_set(memcmp, TUNE_NCONSTANTS);
1195 values = new_set(memcmp, TUNE_NCONSTANTS);
1196 /* init with default precision */
1198 /* init_fltcalc(0); not yet*/
1202 * default mode_info for output as HEX
1204 static const tarval_mode_info hex_output = {
1211 * default mode_info for output as reference
1213 static const tarval_mode_info reference_output = {
1221 * Initialization of the tarval module: called after init_mode()
1223 void init_tarval_2(void)
1227 tarval_bad = (tarval*)malloc(sizeof(tarval));
1228 tarval_bad->mode = mode_BAD;
1230 tarval_undefined = (tarval*)malloc(sizeof(tarval));
1231 tarval_undefined->mode = mode_ANY;
1233 tarval_b_true = (tarval*)malloc(sizeof(tarval));
1234 tarval_b_true->mode = mode_b;
1236 tarval_b_false = (tarval*)malloc(sizeof(tarval));
1237 tarval_b_false->mode = mode_b;
1239 tarval_P_void = (tarval*)malloc(sizeof(tarval));
1240 tarval_P_void->mode = mode_P;
1243 * assign output modes that are compatible with the
1244 * old implementation: Hex output
1246 tarval_set_mode_output_option(mode_U, &hex_output);
1247 tarval_set_mode_output_option(mode_C, &hex_output);
1248 tarval_set_mode_output_option(mode_Bs, &hex_output);
1249 tarval_set_mode_output_option(mode_Bu, &hex_output);
1250 tarval_set_mode_output_option(mode_Hs, &hex_output);
1251 tarval_set_mode_output_option(mode_Hu, &hex_output);
1252 tarval_set_mode_output_option(mode_Hs, &hex_output);
1253 tarval_set_mode_output_option(mode_Hu, &hex_output);
1254 tarval_set_mode_output_option(mode_Is, &hex_output);
1255 tarval_set_mode_output_option(mode_Iu, &hex_output);
1256 tarval_set_mode_output_option(mode_Ls, &hex_output);
1257 tarval_set_mode_output_option(mode_Lu, &hex_output);
1258 tarval_set_mode_output_option(mode_P, &reference_output);
1261 /****************************************************************************
1263 ****************************************************************************/