1 /* Declarations for Target Values.
2 Copyright (C) 1995, 1996 Christian von Roques
8 * Declarations for Target Values.
14 Discussion of new interface, proposals by Prof. Waite:
16 > 1. You say that you plan to replace the tv module. That replacement is
17 > absolutely essential for an ANSI C translator: Section 6.1.3.2 of the
18 > standard says that the representation of an integer_constant depends
19 > upon its value as well as any suffixes that are attached to it. The
20 > possible Firm modes for such a constant are i, I, l, and L. The
21 > current tv module provides only one integer conversion routine, and
22 > that requires conversion by the client. Since the type of the value
23 > argument is long, this may preclude the representation of an unsigned
26 > There is a similar problem with floating constants. Floating
27 > constants can be suffixed in C, and the mode depends upon the suffix.
28 > It can indicate that the constant is of type long double, which your
29 > current tv module is incapable of representing.
31 > Your tv module interface accepts two kinds of information: modes and
32 > values. Values obtained from the program text might be uninterpreted
33 > strings, strings interpreted as integers, and strings interpreted as
34 > reals. Values provided by the compiler are usually integers. Modes are
35 > always Firm modes. It seems to me that the tv module should provide
36 > tarval* constructors for three of the four kinds of values. Each of these
37 > constructors should have an ir_mode parameter and one or more parameters
38 > appropriate for the kind of value. As is currently the case, one
39 > constructor should be provided for both compiler-generated integers and
40 > source strings interpreted as integers. (This avoids problems of
41 > different conversion radices -- the client does the conversion.) For
42 > symmetry, the constructor for source strings interpreted as reals should
43 > accept a long double parameter and require the client to do the
55 #ifndef _TARVAL_TYPEDEF_
56 #define _TARVAL_TYPEDEF_
57 typedef struct tarval tarval;
61 /** how to represent target types on host */
62 typedef float tarval_F;
63 typedef double tarval_D;
64 typedef long double tarval_E;
65 typedef long tarval_sInt;
66 typedef unsigned long tarval_uInt;
67 typedef char tarval_C;
68 typedef unsigned short tarval_U; /* 16 bit ?! wchar could be defined as char... */
73 /** if ent then xname is missing or mangled from ent,
74 else if xname then xname is a linker symbol that is not mangled
76 else this is tarval_p_void.
77 if this tarval describes a symbolic address of another tarval, tv points
87 tarval_F F; /**< float */
88 tarval_D D; /**< double */
89 tarval_E E; /**< extended */
90 tarval_sInt sInt; /**< signed integral */
91 tarval_uInt uInt; /**< unsigned integral */
92 tarval_C C; /**< character */
93 tarval_U U; /**< unicode character */
94 tarval_P P; /**< pointer */
95 bool b; /**< boolean */
101 extern tarval *tarval_bad; tarval *get_tarval_bad(void);
102 /* We should have a tarval_undefined */
103 extern tarval *tarval_b_false; tarval *get_tarval_b_false (void);
104 extern tarval *tarval_b_true; tarval *get_tarval_b_true (void);
105 extern tarval *tarval_D_NaN; tarval *get_tarval_D_NaN (void);
106 extern tarval *tarval_D_Inf; tarval *get_tarval_D_Inf (void);
107 extern tarval *tarval_P_void; tarval *get_tarval_P_void (void);
108 extern tarval *tarval_mode_null[]; tarval *get_tarval_mode_null(ir_mode *mode);
111 /** @bug These are not initialized!! Don't use. */
112 extern tarval *tarval_mode_min[]; tarval *get_tarval_mode_min (ir_mode *mode);
113 extern tarval *tarval_mode_max[]; tarval *get_tarval_mode_max (ir_mode *mode);
116 void tarval_init_1 (void);
117 void tarval_init_2 (void);
120 /** Constructors for tarvals */
121 tarval *tarval_F_from_str (const char *s, size_t len);
122 tarval *tarval_D_from_str (const char *s, size_t len);
123 tarval *tarval_int_from_str (const char *s, size_t len, int base, ir_mode *m);
124 tarval *tarval_from_long (ir_mode *m, long val);
127 tarval *tarval_P_from_str (const char *xname);
128 /* The tarval represents the address of the entity. As the address must
129 be constant the entity must have as owner the global type. */
130 tarval *tarval_P_from_entity (entity *ent);
132 tarval *tarval_convert_to (tarval *src, ir_mode *m);
134 /* Building an irm_C, irm_s, irm_S or irm_B target value step by step. */
135 void tarval_start (void);
136 void tarval_append (const char *p, size_t n);
137 void tarval_append1 (char ch);
138 tarval *tarval_finish_as (ir_mode *m);
139 tarval *tarval_cancel (void); /* returns tarval_bad */
141 /** The flags for projecting a comparison result */
143 irpn_False=0, /**< 0000 false */
144 irpn_Eq, /**< 0001 equal */
145 irpn_Lt, /**< 0010 less */
146 irpn_Le, /**< 0011 less or equal */
147 irpn_Gt, /**< 0100 greater */
148 irpn_Ge, /**< 0101 greater of equal */
149 irpn_Lg, /**< 0110 less or greater */
150 irpn_Leg, /**< 0111 less, equal or greater = ordered */
151 irpn_Uo, /**< 1000 unordered */
152 irpn_Ue, /**< 1001 unordered or equal */
153 irpn_Ul, /**< 1010 unordered or less */
154 irpn_Ule, /**< 1011 unordered, less or equal */
155 irpn_Ug, /**< 1100 unordered or greater */
156 irpn_Uge, /**< 1101 unordered, greater or equal */
157 irpn_Ne, /**< 1110 unordered, less or greater = not equal */
158 irpn_True /**< 1111 true */
159 /*irpn_notmask = irpn_Leg @@@ removed for JNI builder */
161 #define irpn_notmask irpn_Leg
164 /** Arithmethic operations on tarvals */
165 tarval *tarval_neg (tarval *a);
166 tarval *tarval_add (tarval *a, tarval *b);
167 tarval *tarval_sub (tarval *a, tarval *b);
168 tarval *tarval_mul (tarval *a, tarval *b);
169 tarval *tarval_quo (tarval *a, tarval *b);
170 tarval *tarval_div (tarval *a, tarval *b);
171 tarval *tarval_mod (tarval *a, tarval *b);
172 tarval *tarval_abs (tarval *a);
173 tarval *tarval_and (tarval *a, tarval *b);
174 tarval *tarval_or (tarval *a, tarval *b);
175 tarval *tarval_eor (tarval *a, tarval *b);
176 tarval *tarval_shl (tarval *a, tarval *b);
177 tarval *tarval_shr (tarval *a, tarval *b);
180 /** Compare a with b and return an ir_pncmp describing the relation
181 between a and b. This is either Uo, Lt, Eq, Gt, or False if a or b
182 are symbolic pointers which can not be compared at all. */
183 ir_pncmp tarval_comp (tarval *a, tarval *b);
186 /* Identifying some tarvals */
187 long tarval_classify (tarval *tv);
188 long tarval_ord (tarval *tv, int *fail);
191 /** return a mode-specific value */
192 tarval_F tv_val_F (tarval *tv);
193 tarval_D tv_val_D (tarval *tv);
194 tarval_sInt tv_val_sInt (tarval *tv);
195 tarval_uInt tv_val_uInt (tarval *tv);
196 /* @@@ temporarily removed.
197 jni builder can not deal with the return value.
198 All definitions of types are interpreted as pointer values until
199 type analysis exists for crecoder.
200 tarval_p tv_val_p (tarval *tv);
202 bool tv_val_b (tarval *tv);
205 ir_mode *get_tv_mode (tarval *tv);
206 /** Returns the entity if the tv is a pointer to an entity, else
208 entity *get_tv_entity(tarval *tv);
210 /** Returns 0 if tv is positive, else > 0. @todo not tested! */
211 int tv_is_negative(tarval *a);