Changed file names.
[libfirm] / ir / tv / tv.h
1 /* Declarations for Target Values.
2    Copyright (C) 1995, 1996 Christian von Roques
3 */
4
5 /* $Id$ */
6
7 /*
8 Discussion of new interface, proposals by Prof. Waite:
9 (email of 13.6.2001)
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
18 >    long constant.
19 >
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.
24 >
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
38 >    conversion.
39
40 */
41
42 #ifndef _TV_H
43 #define _TV_H
44
45 # include "irmode.h"
46 # include "entity.h"
47 # include "bool.h"
48
49 #ifndef _TARVAL_TYPEDEF_
50 #define _TARVAL_TYPEDEF_
51 typedef struct tarval tarval;
52 #endif
53
54 #include "gmp.h"
55 #undef __need_size_t            /* erroneously defined by 1.3.2's gmp.h */
56
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;
63 typedef struct {
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
66        from an entity,
67      else this is tarval_p_void.
68      if this tarval describes a symbolic address of another tarval, tv points
69      to this val */
70   const char *xname;
71   entity *ent;
72   tarval *tv;
73 } tarval_p;
74 typedef struct {
75   unsigned char *p;             /* may contain embedded 0, not 0-terminated */
76   size_t n;
77 } tarval_s;
78 typedef tarval_s tarval_B;
79
80 struct tarval {
81   union {
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 */
88     bool b;                     /* boolean */
89     tarval_B B;                 /* universal bits */
90     tarval_s s;                 /* string */
91   } u;
92   ir_mode *mode;
93 };
94
95 extern tarval *tarval_bad;
96 /* We should have a tarval_undefined */
97 extern tarval *tarval_b_false;
98 extern tarval *tarval_b_true;
99 extern tarval *tarval_d_NaN;
100 extern tarval *tarval_d_Inf;
101 extern tarval *tarval_p_void;
102 extern tarval *tarval_mode_null[];
103 extern tarval *tarval_mode_min[];
104 extern tarval *tarval_mode_max[];
105
106 void tarval_init_1 (void);
107 void tarval_init_2 (void);
108
109 /* Hash function on tarvals */
110 unsigned tarval_hash (tarval *);
111
112 /* ************************ Constructors for tarvals ************************ */
113 tarval *tarval_Z_from_str (const char *, size_t, int base);
114 tarval *tarval_B_from_str (const char *, size_t);
115 tarval *tarval_d_from_str (const char *, size_t);
116 tarval *tarval_s_from_str (const char *, size_t);
117 tarval *tarval_S_from_str (const char *, size_t);
118 tarval *tarval_from_long  (ir_mode *, long);
119 tarval *tarval_p_from_str (const char *);
120 /* The tarval represents the address of the entity.  As the address must be constant
121    the entity must have as owner the global type. */
122 tarval *tarval_p_from_entity (entity *);
123
124 tarval *tarval_convert_to (tarval *, ir_mode *);
125
126 /* Building an irm_C, irm_s, irm_S or irm_B target value step by step. */
127 void tarval_start (void);
128 void tarval_append (const char *, size_t);
129 void tarval_append1 (char);
130 tarval *tarval_finish_as (ir_mode *);
131 tarval *tarval_cancel (void); /* returns tarval_bad */
132
133 \f
134 /* The flags for projecting a comparison result */
135 typedef enum {
136   irpn_False=0,         /* false */
137   irpn_Eq,              /* equal */
138   irpn_Lt,              /* less */
139   irpn_Le,              /* less or equal */
140   irpn_Gt,              /* greater */
141   irpn_Ge,              /* greater of equal */
142   irpn_Lg,              /* less or greater */
143   irpn_Leg,             /* less, equal or greater = ordered */
144   irpn_Uo,              /* unordered */
145   irpn_Ue,              /* unordered or equal */
146   irpn_Ul,              /* unordered or less */
147   irpn_Ule,             /* unordered, less or equal */
148   irpn_Ug,              /* unordered or greater */
149   irpn_Uge,             /* unordered, greater or equal */
150   irpn_Ne,              /* unordered, less or greater = not equal */
151   irpn_True,            /* true */
152   irpn_notmask = irpn_Leg
153 } ir_pncmp;
154
155 /* ******************** Arithmethic operations on tarvals ******************** */
156 /* Compare a with b and return an ir_pncmp describing the relation
157    between a and b.  This is either Uo, Lt, Eq, Gt, or False if a or b
158    are symbolic pointers which can not be compared at all. */
159 ir_pncmp tarval_comp (tarval *a, tarval *b);
160
161 tarval *tarval_neg (tarval *a);
162 tarval *tarval_add (tarval *, tarval *);
163 tarval *tarval_sub (tarval *, tarval *);
164 tarval *tarval_mul (tarval *, tarval *);
165 tarval *tarval_quo (tarval *, tarval *);
166 tarval *tarval_div (tarval *, tarval *);
167 tarval *tarval_mod (tarval *, tarval *);
168 tarval *tarval_abs (tarval *);
169 tarval *tarval_and (tarval *, tarval *);
170 tarval *tarval_or  (tarval *, tarval *);
171 tarval *tarval_eor (tarval *, tarval *);
172 tarval *tarval_shl (tarval *, tarval *);
173 tarval *tarval_shr (tarval *, tarval *);
174
175 /* Identifying some tarvals */
176 long tarval_classify (tarval *);
177 long tarval_ord (tarval *, int *fail);
178
179 /* moved to tv_t.h
180    int tarval_print (XP_PAR1, const xprintf_info *, XP_PARN); */
181
182 /* return a mode-specific value */
183
184 tarval_f tv_val_f (tarval *tv);
185 tarval_d tv_val_d (tarval *tv);
186 tarval_chil tv_val_chil (tarval *tv);
187 tarval_CHIL tv_val_CHIL (tarval *tv);
188 tarval_Z tv_val_Z (tarval *tv);
189 tarval_p tv_val_p (tarval *tv);
190 bool     tv_val_b (tarval *tv);
191 tarval_B tv_val_B (tarval *tv);
192 tarval_s tv_val_s (tarval *tv);
193
194 #ifdef NDEBUG
195 #define TARVAL_VRFY(val) ((void)0)
196 #else
197 #define TARVAL_VRFY(val) _tarval_vrfy ((val))
198 extern void _tarval_vrfy (const tarval *);
199 #endif
200
201 #ifdef STATS
202 void tarval_stats (void);
203 #else
204 #define tarval_stats() ((void)0)
205 #endif
206
207 ir_mode *get_tv_mode (tarval *tv);
208
209 #endif