Removed bool.h, replaced by stdboo.h
[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 <stdbool.h>
48
49 #ifndef _TARVAL_TYPEDEF_
50 #define _TARVAL_TYPEDEF_
51 typedef struct tarval tarval;
52 #endif
53
54 /* how to represent target types on host */
55 typedef float  tarval_F;
56 typedef double tarval_D;
57 typedef long double tarval_E;
58 typedef long   tarval_sInt;
59 typedef unsigned long tarval_uInt;
60 typedef char tarval_C;
61 typedef struct {
62   /* if ent then xname is missing or mangled from ent,
63      else if xname then xname is a linker symbol that is not mangled
64        from an entity,
65      else this is tarval_p_void.
66      if this tarval describes a symbolic address of another tarval, tv points
67      to this val */
68   const char *xname;
69   entity *ent;
70   tarval *tv;
71 } tarval_P;
72
73 struct tarval {
74   union {
75     tarval_F F;         /* float */
76     tarval_D D;         /* double */
77     tarval_E E;         /* extended */
78     tarval_sInt sInt;   /* signed integral */
79     tarval_uInt uInt;   /* unsigned integral */
80     tarval_C C;         /* character */
81     tarval_P P;         /* pointer */
82     bool b;             /* boolean */
83   } u;
84   ir_mode *mode;
85 };
86
87
88 extern tarval *tarval_bad;                  tarval *get_tarval_bad();
89 /* We should have a tarval_undefined */
90 extern tarval *tarval_b_false;              tarval *get_tarval_b_false  ();
91 extern tarval *tarval_b_true;               tarval *get_tarval_b_true   ();
92 extern tarval *tarval_D_NaN;                tarval *get_tarval_D_NaN    ();
93 extern tarval *tarval_D_Inf;                tarval *get_tarval_D_Inf    ();
94 extern tarval *tarval_P_void;               tarval *get_tarval_P_void   ();
95 extern tarval *tarval_mode_null[];          tarval *get_tarval_mode_null(ir_mode *mode);
96 /* @@@ These are not initialized!! Don't use. */
97 extern tarval *tarval_mode_min[];           tarval *get_tarval_mode_min (ir_mode *mode);
98 extern tarval *tarval_mode_max[];           tarval *get_tarval_mode_max (ir_mode *mode);
99
100 void tarval_init_1 (void);
101 void tarval_init_2 (void);
102
103 /* ************************ Constructors for tarvals ************************ */
104 tarval *tarval_F_from_str (const char *s, size_t len);
105 tarval *tarval_D_from_str (const char *s, size_t len);
106 tarval *tarval_int_from_str (const char *s, size_t len, int base, ir_mode *m);
107 tarval *tarval_from_long  (ir_mode *m, long val);
108
109 tarval *tarval_P_from_str (const char *xname);
110 /* The tarval represents the address of the entity.  As the address must
111    be constant the entity must have as owner the global type. */
112 tarval *tarval_P_from_entity (entity *ent);
113
114 tarval *tarval_convert_to (tarval *src, ir_mode *m);
115
116 /* Building an irm_C, irm_s, irm_S or irm_B target value step by step. */
117 void tarval_start (void);
118 void tarval_append (const char *p, size_t n);
119 void tarval_append1 (char ch);
120 tarval *tarval_finish_as (ir_mode *m);
121 tarval *tarval_cancel (void); /* returns tarval_bad */
122
123 /* The flags for projecting a comparison result */
124 typedef enum {
125   irpn_False=0, /* 0000 false */
126   irpn_Eq,              /* 0001 equal */
127   irpn_Lt,              /* 0010 less */
128   irpn_Le,              /* 0011 less or equal */
129   irpn_Gt,              /* 0100 greater */
130   irpn_Ge,              /* 0101 greater of equal */
131   irpn_Lg,              /* 0110 less or greater */
132   irpn_Leg,             /* 0111 less, equal or greater = ordered */
133   irpn_Uo,              /* 1000 unordered */
134   irpn_Ue,              /* 1001 unordered or equal */
135   irpn_Ul,              /* 1010 unordered or less */
136   irpn_Ule,             /* 1011 unordered, less or equal */
137   irpn_Ug,              /* 1100 unordered or greater */
138   irpn_Uge,             /* 1101 unordered, greater or equal */
139   irpn_Ne,              /* 1110 unordered, less or greater = not equal */
140   irpn_True             /* 1111 true */
141   /*irpn_notmask = irpn_Leg  @@@ removed for JNI builder */
142 } ir_pncmp;
143 #define irpn_notmask irpn_Leg
144
145 /* ******************** Arithmethic operations on tarvals ******************** */
146 /* Compare a with b and return an ir_pncmp describing the relation
147    between a and b.  This is either Uo, Lt, Eq, Gt, or False if a or b
148    are symbolic pointers which can not be compared at all. */
149 ir_pncmp tarval_comp (tarval *a, tarval *b);
150
151 tarval *tarval_neg (tarval *a);
152 tarval *tarval_add (tarval *a, tarval *b);
153 tarval *tarval_sub (tarval *a, tarval *b);
154 tarval *tarval_mul (tarval *a, tarval *b);
155 tarval *tarval_quo (tarval *a, tarval *b);
156 tarval *tarval_div (tarval *a, tarval *b);
157 tarval *tarval_mod (tarval *a, tarval *b);
158 tarval *tarval_abs (tarval *a);
159 tarval *tarval_and (tarval *a, tarval *b);
160 tarval *tarval_or  (tarval *a, tarval *b);
161 tarval *tarval_eor (tarval *a, tarval *b);
162 tarval *tarval_shl (tarval *a, tarval *b);
163 tarval *tarval_shr (tarval *a, tarval *b);
164
165 /* Identifying some tarvals */
166 long tarval_classify (tarval *tv);
167 long tarval_ord (tarval *tv, int *fail);
168
169 /* return a mode-specific value */
170 tarval_F tv_val_F (tarval *tv);
171 tarval_D tv_val_D (tarval *tv);
172 tarval_sInt tv_val_sInt (tarval *tv);
173 tarval_uInt tv_val_uInt (tarval *tv);
174 /* @@@ temporarily removed.
175    jni builder can not deal with the return value.
176    All definitions of types are interpreted as pointer values until
177    type analysis exists for crecoder.
178    tarval_p tv_val_p (tarval *tv);
179 */;
180 bool     tv_val_b (tarval *tv);
181
182 ir_mode *get_tv_mode (tarval *tv);
183 /* Returns the entity if the tv is a pointer to an entity, else
184    returns NULL; */
185 entity *get_tv_entity(tarval *tv);
186
187 /* Returns 0 if tv is positive, else > 0. @@@ not tested! */
188 int tv_is_negative(tarval *a);
189 #endif  /* _TV_H_ */