PIPS
area.c
Go to the documentation of this file.
1 /*
2 
3  $Id: area.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 /* Functions closely related to the entity class, constructors, predicates,...
28  */
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <ctype.h>
33 
34 #include "linear.h"
35 
36 #include "genC.h"
37 #include "misc.h"
38 #include "ri.h"
39 #include "properties.h"
40 #include "ri-util.h"
41 
42 #include "prettyprint.h"
43 
44 /* returns true if l contains an entity with same type, local name and offset.
45  */
46 static bool comparable_entity_in_list_p(entity common, entity v, list l)
47 {
49  bool ok, sn, so = false, st = false;
50 
51  /* first find an entity with the same NAME.
52  */
53  const char* nv = entity_local_name(v);
54  MAP(ENTITY, e,
55  {
57  {
58  ref = e;
59  break;
60  }
61  },
62  l);
63 
64  ok = sn = !entity_undefined_p(ref);
65 
66  pips_assert("v storage ram", storage_ram_p(entity_storage(v)));
67  if (ok) pips_assert("ref storage ram", storage_ram_p(entity_storage(ref)));
68 
69  /* same OFFSET?
70  */
71  if (ok) ok = so = (ram_offset(storage_ram(entity_storage(v))) ==
73 
74  /* same TYPE?
75  */
76  /* SG we cannot rely on same_type_p or type_equal_p because we want a syntactic comparison,
77  * there used to be a hack in expression_equal_p to handle this particular case, I prefer to have the hack right here
78  */
79  if( ok ) {
80  if(entity_undefined_p(ref)) ok = st =false;
81  else {
82  type tv = entity_type(v),
83  tref = entity_type(ref);
84  ok = st = same_type_name_p(tv,tref);
85  }
86  }
87 
88  pips_debug(4, "%s ~ %s? %d: n=%d,o=%d,t=%d\n", entity_name(v),
89  entity_undefined_p(ref)? "<undef>": entity_name(ref),
90  ok, sn, so, st);
91 
92  /* temporary for CA
93  */
94  if (!ok) {
95  pips_debug(1, "common /%s/: %s != %s (n=%d,o=%d,t=%d)\n",
96  entity_name(common), entity_name(v),
97  entity_undefined_p(ref)? "<undef>": entity_name(ref),
98  sn, so, st);
99  }
100 
101  return ok;
102 }
103 
104 /* check whether a common declaration can be simply included, that is
105  * it is declared with the same names, orders and types in all instances.
106  */
108 {
109  bool ok = true;
110  list /* of entity */ lv, lref;
111  entity ref;
112  pips_assert("entity is a common", entity_area_p(common));
113  lv = area_layout(type_area(entity_type(common)));
114 
115  if (!lv) return true; /* empty common! */
116 
117  /* take the first function as the reference for the check. */
119  lref = common_members_of_module(common, ref, false);
120 
121  /* SAME name, type, offset */
122  while (lv && ok)
123  {
124  entity v = ENTITY(CAR(lv));
126  ok = comparable_entity_in_list_p(common, v, lref);
127  POP(lv);
128  }
129 
130  gen_free_list(lref);
131  return ok;
132 }
static reference ref
Current stmt (an integer)
Definition: adg_read_paf.c:163
#define POP(l)
Modify a list pointer to point on the next element of the list.
Definition: newgen_list.h:59
#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 MAP(_map_CASTER, _map_item, _map_code, _map_list)
Apply/map an instruction block on all the elements of a list (old fashioned)
Definition: newgen_list.h:226
#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)
static bool comparable_entity_in_list_p(entity common, entity v, list l)
Functions closely related to the entity class, constructors, predicates,...
Definition: area.c:46
bool check_common_inclusion(entity common)
check whether a common declaration can be simply included, that is it is declared with the same names...
Definition: area.c:107
bool same_type_name_p(const type, const type)
For naming homogeneity: expression_to_string(), reference_to_string()...
Definition: type.c:74
bool entity_area_p(entity e)
Definition: area.c:149
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
list common_members_of_module(entity common, entity module, bool only_primary)
returns the list of entity to appear in the common declaration.
Definition: entity.c:1741
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
#define entity_storage(x)
Definition: ri.h:2794
#define storage_ram_p(x)
Definition: ri.h:2519
#define entity_undefined_p(x)
Definition: ri.h:2762
#define entity_undefined
Definition: ri.h:2761
#define entity_name(x)
Definition: ri.h:2790
#define area_layout(x)
Definition: ri.h:546
#define type_area(x)
Definition: ri.h:2946
#define storage_ram(x)
Definition: ri.h:2521
#define ram_function(x)
Definition: ri.h:2247
#define entity_type(x)
Definition: ri.h:2792
#define ram_offset(x)
Definition: ri.h:2251
static bool ok
The structure used to build lists in NewGen.
Definition: newgen_list.h:41