Whitespace changes --flo
[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_f_from_str (const char *, size_t);
116 tarval *tarval_d_from_str (const char *, size_t);
117 tarval *tarval_s_from_str (const char *, size_t);
118 tarval *tarval_S_from_str (const char *, size_t);
119 tarval *tarval_int_from_str (const char *, size_t, int base, ir_mode *m);
120 tarval *tarval_from_long  (ir_mode *, long);
121
122 tarval *tarval_p_from_str (const char *);
123 /* The tarval represents the address of the entity.  As the address must
124    be constant the entity must have as owner the global type. */
125 tarval *tarval_p_from_entity (entity *);
126
127 tarval *tarval_convert_to (tarval *, ir_mode *);
128
129 /* Building an irm_C, irm_s, irm_S or irm_B target value step by step. */
130 void tarval_start (void);
131 void tarval_append (const char *, size_t);
132 void tarval_append1 (char);
133 tarval *tarval_finish_as (ir_mode *);
134 tarval *tarval_cancel (void); /* returns tarval_bad */
135
136 \f
137 /* The flags for projecting a comparison result */
138 typedef enum {
139   irpn_False=0,         /* false */
140   irpn_Eq,              /* equal */
141   irpn_Lt,              /* less */
142   irpn_Le,              /* less or equal */
143   irpn_Gt,              /* greater */
144   irpn_Ge,              /* greater of equal */
145   irpn_Lg,              /* less or greater */
146   irpn_Leg,             /* less, equal or greater = ordered */
147   irpn_Uo,              /* unordered */
148   irpn_Ue,              /* unordered or equal */
149   irpn_Ul,              /* unordered or less */
150   irpn_Ule,             /* unordered, less or equal */
151   irpn_Ug,              /* unordered or greater */
152   irpn_Uge,             /* unordered, greater or equal */
153   irpn_Ne,              /* unordered, less or greater = not equal */
154   irpn_True,            /* true */
155   irpn_notmask = irpn_Leg
156 } ir_pncmp;
157
158 /* ******************** Arithmethic operations on tarvals ******************** */
159 /* Compare a with b and return an ir_pncmp describing the relation
160    between a and b.  This is either Uo, Lt, Eq, Gt, or False if a or b
161    are symbolic pointers which can not be compared at all. */
162 ir_pncmp tarval_comp (tarval *a, tarval *b);
163
164 tarval *tarval_neg (tarval *a);
165 tarval *tarval_add (tarval *, tarval *);
166 tarval *tarval_sub (tarval *, tarval *);
167 tarval *tarval_mul (tarval *, tarval *);
168 tarval *tarval_quo (tarval *, tarval *);
169 tarval *tarval_div (tarval *, tarval *);
170 tarval *tarval_mod (tarval *, tarval *);
171 tarval *tarval_abs (tarval *);
172 tarval *tarval_and (tarval *, tarval *);
173 tarval *tarval_or  (tarval *, tarval *);
174 tarval *tarval_eor (tarval *, tarval *);
175 tarval *tarval_shl (tarval *, tarval *);
176 tarval *tarval_shr (tarval *, tarval *);
177
178 /* Identifying some tarvals */
179 long tarval_classify (tarval *);
180 long tarval_ord (tarval *, int *fail);
181
182 /* moved to tv_t.h
183    int tarval_print (XP_PAR1, const xprintf_info *, XP_PARN); */
184
185 /* return a mode-specific value */
186
187 tarval_f tv_val_f (tarval *tv);
188 tarval_d tv_val_d (tarval *tv);
189 tarval_chil tv_val_chil (tarval *tv);
190 tarval_CHIL tv_val_CHIL (tarval *tv);
191 tarval_Z tv_val_Z (tarval *tv);
192 tarval_p tv_val_p (tarval *tv);
193 bool     tv_val_b (tarval *tv);
194 tarval_B tv_val_B (tarval *tv);
195 tarval_s tv_val_s (tarval *tv);
196
197 #ifdef NDEBUG
198 #define TARVAL_VRFY(val) ((void)0)
199 #else
200 #define TARVAL_VRFY(val) _tarval_vrfy ((val))
201 extern void _tarval_vrfy (const tarval *);
202 #endif
203
204 #ifdef STATS
205 void tarval_stats (void);
206 #else
207 #define tarval_stats() ((void)0)
208 #endif
209
210 ir_mode *get_tv_mode (tarval *tv);
211 entity *get_tv_entity(tarval *tv);
212
213 #endif