PIPS
clean.c
Go to the documentation of this file.
1 /*
2 
3  $Id: clean.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 #include <stdio.h>
28 
29 #include "genC.h"
30 #include "linear.h"
31 #include "ri.h"
32 
33 #include "misc.h"
34 #include "ri-util.h"
35 
36 
37 
39 static const char *current_function_local_name = NULL;
40 
41 
42 static void set_current_function(function)
44 {
45  pips_assert("set_current_function", top_level_entity_p(function)
47  current_function = function;
49 }
50 
51 
52 
54 entity e;
55 {
57 }
58 
59 
60 /* Useful when the user edit a source file and parse it again or when
61  a program transformation is performed by prettyprinting and
62  reparsing. */
63 void GenericCleanEntities(list el, entity function, bool fortran_p)
64 {
65  /* FI: A memory leak is better than a dangling pointer? */
66  /* My explanation: CleanLocalEntities is called by MakeCurrentFunction when
67  * the begin_inst rule is reduced; by that time, the module entity and its
68  * formal parameters have already been parsed and allocated... but they
69  * are not yet fully initialized; thus the gen_full_free is a killer while
70  * the undefinitions are ok.
71  */
72  /*gen_full_free_list(function_local_entities);*/
73 
74  list pe = list_undefined;
75 
76  for(pe=el; !ENDP(pe); POP(pe)) {
77  entity e = ENTITY(CAR(pe));
78  storage s = entity_storage(e);
79 
80  pips_debug(8, "Clean up %s?\n", entity_local_name(e));
81 
82  if(!storage_undefined_p(s) && storage_ram_p(s)) {
83  entity sec = ram_section(storage_ram(s));
84  type t = entity_type(sec);
85  if(!type_undefined_p(t)) {
86  pips_assert("t is an area", type_area_p(t));
88  }
89  }
90 
91  /* In C, parameter typing may have already occured and the return
92  entity may be already defined. They must be preserved. */
93  if(fortran_p
97  pips_debug(8, "Clean up %s? YES\n", entity_local_name(e));
98  if(!type_undefined_p(entity_type(e))) {
99  /* free_type(entity_type(e)); */
101  }
103  /* free_storage(entity_storage(e)); */
105  }
107  /* free_value(entity_initial(e)); */
109  }
110  if(!fortran_p) {
111  /* In C, the entity must be removed from the declarations and
112  from the symbol table */
114  free_entity(e);
115  }
116  }
117  else {
118  pips_debug(8, "Clean up %s? NO\n", entity_local_name(e));
119  }
120  }
121 }
122 
123 void GenericCleanLocalEntities(entity function, bool fortran_p)
124 {
125  list function_local_entities = NIL;
126  //list pe = NIL;
127 
128  set_current_function(function);
129 
130  function_local_entities =
132  entity_domain);
133 
134  GenericCleanEntities(function_local_entities, function, fortran_p);
135 
136  gen_free_list(function_local_entities);
137 }
138 
139 /* Fortran version */
141 {
142  GenericCleanLocalEntities(function, true);
143 }
144 
145 /* C language version */
147 {
148  GenericCleanLocalEntities(function, false);
149 }
150 
151 /* Useful for ParserError()? */
152 void RemoveLocalEntities(function)
154 {
155 
156  set_current_function(function);
157 
158 #if 0
159  list function_local_entities =
161  entity_domain);
162 #endif
163 
164  /* FI: dangling pointers? Some variables may be referenced in area_layouts of
165  global common entities! */
166  /* gen_full_free_list(function_local_entities); */
167  /* A gen_multi_recurse would be required but it's hard to be at the
168  list level to remove the elements?!? */
169  pips_assert("implemented", false);
170 }
void free_entity(entity p)
Definition: ri.c:2524
void GenericCleanEntities(list el, entity function, bool fortran_p)
Useful when the user edit a source file and parse it again or when a program transformation is perfor...
Definition: clean.c:63
void CleanLocalEntities(entity function)
Fortran version.
Definition: clean.c:140
static void set_current_function(entity function)
Definition: clean.c:42
void CCleanLocalEntities(entity function)
C language version.
Definition: clean.c:146
void GenericCleanLocalEntities(entity function, bool fortran_p)
Definition: clean.c:123
static entity current_function
Definition: clean.c:38
static const char * current_function_local_name
Definition: clean.c:39
static bool local_entity_of_current_function_p(entity e)
Definition: clean.c:53
void RemoveLocalEntities(entity function)
Useful for ParserError()?
Definition: clean.c:152
bool compilation_unit_p(const char *module_name)
The names of PIPS entities carry information about their nature.
Definition: entity_names.c:56
#define ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66
void gen_remove(list *cpp, const void *o)
remove all occurences of item o from list *cpp, which is thus modified.
Definition: list.c:685
#define POP(l)
Modify a list pointer to point on the next element of the list.
Definition: newgen_list.h:59
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
void gen_free_list(list l)
free the spine of the list
Definition: list.c:327
#define list_undefined
Undefined list definition :-)
Definition: newgen_list.h:69
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define same_string_p(s1, s2)
list gen_filter_tabulated(bool(*)(gen_chunk *), int)
returns the list of entities with this caracteristics.
Definition: tabulated.c:144
const char * entity_local_name(entity e)
entity_local_name modified so that it does not core when used in vect_fprint, since someone thought t...
Definition: entity.c:453
const char * module_local_name(entity e)
Returns the module local user name.
Definition: entity.c:582
bool top_level_entity_p(entity e)
Check if the scope of entity e is global.
Definition: entity.c:1130
const char * entity_module_name(entity e)
See comments about module_name().
Definition: entity.c:1092
#define value_undefined_p(x)
Definition: ri.h:3017
#define value_undefined
Definition: ri.h:3016
#define storage_formal_p(x)
Definition: ri.h:2522
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
#define entity_storage(x)
Definition: ri.h:2794
#define code_declarations(x)
Definition: ri.h:784
#define storage_ram_p(x)
Definition: ri.h:2519
#define ram_section(x)
Definition: ri.h:2249
#define type_undefined_p(x)
Definition: ri.h:2884
#define entity_undefined
Definition: ri.h:2761
#define area_layout(x)
Definition: ri.h:546
#define value_code(x)
Definition: ri.h:3067
#define type_area(x)
Definition: ri.h:2946
#define storage_ram(x)
Definition: ri.h:2521
#define type_undefined
Definition: ri.h:2883
#define type_area_p(x)
Definition: ri.h:2944
#define entity_type(x)
Definition: ri.h:2792
#define storage_return_p(x)
Definition: ri.h:2516
#define storage_undefined_p(x)
Definition: ri.h:2477
#define entity_domain
newgen_syntax_domain_defined
Definition: ri.h:410
#define storage_undefined
Definition: ri.h:2476
#define entity_initial(x)
Definition: ri.h:2796
The structure used to build lists in NewGen.
Definition: newgen_list.h:41