PIPS
static.c
Go to the documentation of this file.
1 /*
2 
3  $Id: static.c 23065 2016-03-02 09:05:50Z coelho $
4 
5  Copyright 1989-2016 MINES ParisTech
6 
7  This file is part of PIPS.
8 
9  PIPS is free software: you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  any later version.
13 
14  PIPS is distributed in the hope that it will be useful, but WITHOUT ANY
15  WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  FITNESS FOR A PARTICULAR PURPOSE.
17 
18  See the GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with PIPS. If not, see <http://www.gnu.org/licenses/>.
22 
23 */
24 #ifdef HAVE_CONFIG_H
25  #include "pips_config.h"
26 #endif
27 /* static variables and related access functions concerning the current module
28  *
29  * Be'atrice Apvrille, august 27, 1993
30  */
31 
32 /* used to store the summary transformer ?
33  to retrieve intraprocedural effects ? */
34 
35 #include <stdio.h>
36 #include <string.h>
37 
38 #include "linear.h"
39 
40 #include "genC.h"
41 #include "misc.h"
42 
43 #include "ri.h"
44 #include "ri-util.h"
45 
46 
47 /*********************************************************** CURRENT ENTITY */
48 
51 
52 /** @defgroup current_module Methods related to the current module
53 
54  Many parts of PIPS guesses that a current module is defined.
55 
56  These methods are used to set or get the module statement, entity, name...
57 
58  @{
59 */
60 
61 /** Set the current module entity
62 
63  It returns also the given entity to ease macro writing
64 */
65 entity
67 {
68  pips_assert("entity is a module", entity_module_p(e));
69 
70  /* FI: I should perform some kind of memorization for all static variables
71  including the value maps (especially them) */
72 
73  pips_assert("current module is undefined",
75 
78  return e;
79 }
80 
81 
82 /** Get the entity of the current module
83  */
84 entity
86 {
87  return current_module_entity;
88 }
89 
90 
91 
92 /** Reset the current module entity
93 
94  It asserts the module entity was previously set.
95  */
96 void
98 {
99  pips_assert("current entity defined",
103 }
104 
105 /** @} */
106 
107 /* To be called by an error management routine only */
108 void
110 {
113 }
114 
115 
116 /** @addtogroup current_module
117  @{
118 */
119 
120 /** Get the name of the current module */
122 {
124  return string_undefined;
125  else
127  /* return entity_user_name(current_module_entity); */
128 }
129 
130 
132 {
134 }
135 
137 {
139 }
140 
142 {
144 }
145 
146 /** @} */
147 
148 
149 /******************************************************* CURRENT STATEMENT */
150 
151 /* used to retrieve the intraprocedural effects of the current module */
152 
155 
156 /** @addtogroup current_module
157  @{
158 */
159 
160 /** Set the current module statement
161 
162  It returns also the given statement to ease macro writing
163 */
164 statement
166 {
167  pips_assert("The current module statement is undefined",
169  pips_assert("The new module statement is not undefined",
170  s != statement_undefined);
173  return s;
174 }
175 
176 
177 /** Set the statement of the current module and push the statement of the
178  previous one on a stack
179  */
181 {
182  pips_assert("The stacked_current module statement is undefined",
184  pips_assert("The new module statement is not undefined",
185  s != statement_undefined);
188 }
189 
190 
191 /** Pop the current module statement stack and use it as the current
192  module statement
193  */
195 {
196  pips_assert("The current module statement is undefined",
200 }
201 
202 
203 /** Get the current module statement
204 
205  It returns also the given statement to ease macro writing
206 */
207 statement
209 {
210  pips_assert("The current module statement is defined",
213 }
214 
215 
216 /** Reset the current module statement
217 
218  It asserts the module statement was previously set.
219  */
220 void
222 {
223  pips_assert("current module statement defined",
227 }
228 
229 /** @} */
230 
231 
232 /* To be called by an error management routine only */
233 void
235 {
239 }
240 ␌
241 /* Because of typedefs, the C lexers need help to decide if a
242  * character string such as toto is a type name or a keyword or an identifier.
243  *
244  * Such a table is used by the C preprocessor and by the C parser. It
245  * is also updated for in- or outlining with new typedef names.
246  *
247  * The table must be initialized with token values generated by
248  * bison. The token values could possibly be different for the PIPS
249  * preprocessor and syntactic analyzer. Each has its own
250  * initialization function, parser_init_keyword_typedef_table() and
251  * preprocessor_init_keyword_table().
252  */
254 static int token_named_type = -1;
255 
257 {
258  token_named_type = tk;
260  return keyword_typedef_table;
261 }
262 
264 {
266 }
267 
269 {
271  // No need to reset this value. It is a constant defined by Bison.
272  // token_named_type = -1;
273 }
274 
276 {
279  // No need to reset this value. It is a constant defined by Bison.
280  // token_named_type = -1;
281 }
282 
283 void declare_new_typedef(const string tn)
284 {
285  hash_put(keyword_typedef_table, strdup(tn), (const void *) ((long long int) token_named_type));
286 }
287 
288 /* This function checks if s is a C keyword or typedef name and
289  * returns the token number thanks to the hash-table
290  * keyword_typedef_table.
291  *
292  * It returns an integer number corresponding to the keyword.
293  *
294  * It returns 0 if s is not a keyword/typedef name
295  */
296 _int
298 {
300  return ((char *) i == HASH_UNDEFINED_VALUE) ? 0: i;
301 }
302 /*********
303  * Begin definition for the stack current_statement_global_stack
304  *
305  * Because Newgen makes it easy to define a statement stack using
306  * DEFINE_LOCAL_STACK(), the very same functions are redefined each
307  * time they are needed (transformations/sequence_gcm_cse.s,
308  * transformations/simple_atomizer.c, hpfc/io-util.c,
309  * instrumentation/alias_propagation.c,
310  * transformations/array_resizing_top_down.c and
311  * transformations/dead_code_elimination.c). And because they are
312  * defined by macro-expansion, they are a pain to use for debugging
313  * with gdb.
314  */
315 
317 
319 {
320  /* This assert is too strong when user errors occur. Each pass
321  * should pprovide a "clean-up" function to be called by
322  * user_error() without creating a library cycle
323  */
324  //pips_assert("statement_global_stack is undefined",
325  // stack_undefined_p(statement_global_stack));
327  /* This is an error recovery */
329  }
331 }
332 
334 {
335  stack_push((void *) st, statement_global_stack);
336 }
337 
338 //static int get_current_statement_line_number()
339 //{
340 // statement st = (statement) stack_head(statement_global_stack));
341 // return statement_number(st);
342 //}
343 
345 {
349  return st;
350 }
351 
353 {
355  return st;
356 }
357 
359 {
362 }
363 
365 {
367 }
368 
369 /*********
370  * End definition for the stack statement_global_stack
371  */
struct _newgen_struct_statement_ * statement
Definition: cloning.h:21
void set_current_module_declarations(list l)
Definition: static.c:131
list get_current_module_declarations()
Definition: static.c:141
void reset_current_module_entity()
Reset the current module entity.
Definition: static.c:97
void reset_current_module_statement()
Reset the current module statement.
Definition: static.c:221
const char * get_current_module_name()
Get the name of the current module.
Definition: static.c:121
statement set_current_module_statement(statement s)
Set the current module statement.
Definition: static.c:165
void push_current_module_statement(statement s)
Set the statement of the current module and push the statement of the previous one on a stack.
Definition: static.c:180
statement get_current_module_statement()
Get the current module statement.
Definition: static.c:208
void reset_current_module_declarations()
Definition: static.c:136
entity set_current_module_entity(entity e)
Set the current module entity.
Definition: static.c:66
entity get_current_module_entity()
Get the entity of the current module.
Definition: static.c:85
void pop_current_module_statement(void)
Pop the current module statement stack and use it as the current module statement.
Definition: static.c:194
#define list_undefined
Undefined list definition :-)
Definition: newgen_list.h:69
hash_table hash_table_make(hash_key_type key_type, size_t size)
Definition: hash.c:294
void * hash_get(const hash_table htp, const void *key)
this function retrieves in the hash table pointed to by htp the couple whose key is equal to key.
Definition: hash.c:449
void hash_put(hash_table htp, const void *key, const void *val)
This functions stores a couple (key,val) in the hash table pointed to by htp.
Definition: hash.c:364
void hash_table_free(hash_table htp)
this function deletes a hash table that is no longer useful.
Definition: hash.c:327
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
@ hash_string
Definition: newgen_hash.h:32
#define HASH_UNDEFINED_VALUE
value returned by hash_get() when the key is not found; could also be called HASH_KEY_NOT_FOUND,...
Definition: newgen_hash.h:56
#define hash_table_undefined
Value of an undefined hash_table.
Definition: newgen_hash.h:49
#define stack_undefined
Definition: newgen_stack.h:55
bool stack_empty_p(const stack)
void * stack_head(const stack)
returns the item on top of stack s
Definition: stack.c:420
void stack_push(void *, stack)
stack use
Definition: stack.c:373
void stack_free(stack *)
type, bucket_size, policy
Definition: stack.c:292
stack stack_make(int, int, int)
allocation
Definition: stack.c:246
void * stack_pop(stack)
POPs one item from stack s.
Definition: stack.c:399
#define stack_undefined_p(s)
Definition: newgen_stack.h:56
#define string_undefined
Definition: newgen_types.h:40
intptr_t _int
_INT
Definition: newgen_types.h:53
const char * module_local_name(entity e)
Returns the module local user name.
Definition: entity.c:582
bool entity_module_p(entity e)
Definition: entity.c:683
#define statement_domain
newgen_sizeofexpression_domain_defined
Definition: ri.h:362
#define entity_undefined_p(x)
Definition: ri.h:2762
#define entity_undefined
Definition: ri.h:2761
#define statement_undefined_p(x)
Definition: ri.h:2420
#define statement_undefined
Definition: ri.h:2419
char * strdup()
static int token_named_type
Definition: static.c:254
void free_keyword_typedef_table()
Definition: static.c:275
void error_reset_current_module_statement()
To be called by an error management routine only.
Definition: static.c:234
static entity current_module_entity
static variables and related access functions concerning the current module
Definition: static.c:49
static list current_module_declaration_list
Definition: static.c:50
static statement current_module_statement
used to retrieve the intraprocedural effects of the current module
Definition: static.c:153
statement pop_statement_global_stack(void)
Definition: static.c:352
void make_statement_global_stack()
Definition: static.c:318
_int is_c_keyword_typedef(char *s)
This function checks if s is a C keyword or typedef name and returns the token number thanks to the h...
Definition: static.c:297
static statement stacked_current_module_statement
Definition: static.c:154
void push_statement_on_statement_global_stack(statement st)
Definition: static.c:333
static stack statement_global_stack
Definition: static.c:316
bool statement_global_stack_defined_p()
Definition: static.c:364
void error_reset_current_module_entity()
To be called by an error management routine only.
Definition: static.c:109
hash_table keyword_typedef_table
Because of typedefs, the C lexers need help to decide if a character string such as toto is a type na...
Definition: static.c:253
void set_keyword_typedef_table(hash_table h)
Definition: static.c:263
void free_statement_global_stack()
Definition: static.c:358
void declare_new_typedef(const string tn)
Definition: static.c:283
void reset_keyword_typedef_table()
Definition: static.c:268
hash_table make_keyword_typedef_table(int tk)
Definition: static.c:256
statement get_current_statement_from_statement_global_stack()
Definition: static.c:344
the stack head
Definition: stack.c:62
The structure used to build lists in NewGen.
Definition: newgen_list.h:41