1 /* Declarations for Target Values.
2 Copyright (C) 1995, 1996 Christian von Roques
8 Discussion of new interface, proposals by Prof. Waite:
10 > 1. You say that you plan to replace the tv module. That replacement is
11 > absolutely essential for an ANSI C translator: Section 6.1.3.2 of the
12 > standard says that the representation of an integer_constant depends
13 > upon its value as well as any suffixes that are attached to it. The
14 > possible Firm modes for such a constant are i, I, l, and L. The
15 > current tv module provides only one integer conversion routine, and
16 > that requires conversion by the client. Since the type of the value
17 > argument is long, this may preclude the representation of an unsigned
20 > There is a similar problem with floating constants. Floating
21 > constants can be suffixed in C, and the mode depends upon the suffix.
22 > It can indicate that the constant is of type long double, which your
23 > current tv module is incapable of representing.
25 > Your tv module interface accepts two kinds of information: modes and
26 > values. Values obtained from the program text might be uninterpreted
27 > strings, strings interpreted as integers, and strings interpreted as
28 > reals. Values provided by the compiler are usually integers. Modes are
29 > always Firm modes. It seems to me that the tv module should provide
30 > tarval* constructors for three of the four kinds of values. Each of these
31 > constructors should have an ir_mode parameter and one or more parameters
32 > appropriate for the kind of value. As is currently the case, one
33 > constructor should be provided for both compiler-generated integers and
34 > source strings interpreted as integers. (This avoids problems of
35 > different conversion radices -- the client does the conversion.) For
36 > symmetry, the constructor for source strings interpreted as reals should
37 > accept a long double parameter and require the client to do the
49 #ifndef _TARVAL_TYPEDEF_
50 #define _TARVAL_TYPEDEF_
51 typedef struct tarval tarval;
55 #undef __need_size_t /* erroneously defined by 1.3.2's gmp.h */
57 /* how to represent target types on host */
58 typedef float tarval_f;
59 typedef double tarval_d;
60 typedef long tarval_chil;
61 typedef unsigned long tarval_CHIL;
62 typedef MP_INT tarval_Z;
64 /* if ent then xname is missing or mangled from ent,
65 else if xname then xname is a linker symbol that is not mangled
67 else this is tarval_p_void.
68 if this tarval describes a symbolic address of another tarval, tv points
75 unsigned char *p; /* may contain embedded 0, not 0-terminated */
78 typedef tarval_s tarval_B;
82 tarval_f f; /* float */
83 tarval_d d; /* double */
84 tarval_chil chil; /* signed integral */
85 tarval_CHIL CHIL; /* unsigned integral */
86 tarval_Z Z; /* universal int */
87 tarval_p p; /* pointer */
89 tarval_B B; /* universal bits */
90 tarval_s s; /* string */
95 extern tarval *tarval_bad; tarval *get_tarval_bad();
96 /* We should have a tarval_undefined */
97 extern tarval *tarval_b_false; tarval *get_tarval_b_false ();
98 extern tarval *tarval_b_true; tarval *get_tarval_b_true ();
99 extern tarval *tarval_d_NaN; tarval *get_tarval_d_NaN ();
100 extern tarval *tarval_d_Inf; tarval *get_tarval_d_Inf ();
101 extern tarval *tarval_p_void; tarval *get_tarval_p_void ();
102 extern tarval *tarval_mode_null[]; tarval *get_tarval_mode_null(ir_mode *mode);
103 /* @@@ These are not initialized!! Don't use. */
104 extern tarval *tarval_mode_min[]; tarval *get_tarval_mode_min (ir_mode *mode);
105 extern tarval *tarval_mode_max[]; tarval *get_tarval_mode_max (ir_mode *mode);
107 void tarval_init_1 (void);
108 void tarval_init_2 (void);
110 /* Hash function on tarvals */
111 unsigned tarval_hash (tarval *);
113 /* ************************ Constructors for tarvals ************************ */
114 tarval *tarval_Z_from_str (const char *, size_t, int base);
115 tarval *tarval_B_from_str (const char *, size_t);
116 tarval *tarval_f_from_str (const char *, size_t);
117 tarval *tarval_d_from_str (const char *, size_t);
118 tarval *tarval_s_from_str (const char *, size_t);
119 tarval *tarval_S_from_str (const char *, size_t);
120 tarval *tarval_int_from_str (const char *, size_t, int base, ir_mode *m);
121 tarval *tarval_from_long (ir_mode *, long);
123 tarval *tarval_p_from_str (const char *);
124 /* The tarval represents the address of the entity. As the address must
125 be constant the entity must have as owner the global type. */
126 tarval *tarval_p_from_entity (entity *);
128 tarval *tarval_convert_to (tarval *, ir_mode *);
130 /* Building an irm_C, irm_s, irm_S or irm_B target value step by step. */
131 void tarval_start (void);
132 void tarval_append (const char *, size_t);
133 void tarval_append1 (char);
134 tarval *tarval_finish_as (ir_mode *);
135 tarval *tarval_cancel (void); /* returns tarval_bad */
138 /* The flags for projecting a comparison result */
140 irpn_False=0, /* 0000 false */
141 irpn_Eq, /* 0001 equal */
142 irpn_Lt, /* 0010 less */
143 irpn_Le, /* 0011 less or equal */
144 irpn_Gt, /* 0100 greater */
145 irpn_Ge, /* 0101 greater of equal */
146 irpn_Lg, /* 0110 less or greater */
147 irpn_Leg, /* 0111 less, equal or greater = ordered */
148 irpn_Uo, /* 1000 unordered */
149 irpn_Ue, /* 1001 unordered or equal */
150 irpn_Ul, /* 1010 unordered or less */
151 irpn_Ule, /* 1011 unordered, less or equal */
152 irpn_Ug, /* 1100 unordered or greater */
153 irpn_Uge, /* 1101 unordered, greater or equal */
154 irpn_Ne, /* 1110 unordered, less or greater = not equal */
155 irpn_True, /* 1111 true */
156 irpn_notmask = irpn_Leg
159 /* ******************** Arithmethic operations on tarvals ******************** */
160 /* Compare a with b and return an ir_pncmp describing the relation
161 between a and b. This is either Uo, Lt, Eq, Gt, or False if a or b
162 are symbolic pointers which can not be compared at all. */
163 ir_pncmp tarval_comp (tarval *a, tarval *b);
165 tarval *tarval_neg (tarval *a);
166 tarval *tarval_add (tarval *, tarval *);
167 tarval *tarval_sub (tarval *, tarval *);
168 tarval *tarval_mul (tarval *, tarval *);
169 tarval *tarval_quo (tarval *, tarval *);
170 tarval *tarval_div (tarval *, tarval *);
171 tarval *tarval_mod (tarval *, tarval *);
172 tarval *tarval_abs (tarval *);
173 tarval *tarval_and (tarval *, tarval *);
174 tarval *tarval_or (tarval *, tarval *);
175 tarval *tarval_eor (tarval *, tarval *);
176 tarval *tarval_shl (tarval *, tarval *);
177 tarval *tarval_shr (tarval *, tarval *);
179 /* Identifying some tarvals */
180 long tarval_classify (tarval *);
181 long tarval_ord (tarval *, int *fail);
184 int tarval_print (XP_PAR1, const xprintf_info *, XP_PARN); */
186 /* return a mode-specific value */
188 tarval_f tv_val_f (tarval *tv);
189 tarval_d tv_val_d (tarval *tv);
190 tarval_chil tv_val_chil (tarval *tv);
191 tarval_CHIL tv_val_CHIL (tarval *tv);
192 tarval_Z tv_val_Z (tarval *tv);
193 tarval_p tv_val_p (tarval *tv);
194 bool tv_val_b (tarval *tv);
195 tarval_B tv_val_B (tarval *tv);
196 tarval_s tv_val_s (tarval *tv);
198 ir_mode *get_tv_mode (tarval *tv);
199 /* Returns the entity if the tv is a pointer to an entity, else
201 entity *get_tv_entity(tarval *tv);
203 /* Returns 0 if tv is positive, else > 0. @@@ not tested! */
204 int tv_is_negative(tarval *a);