PIPS
set_return_type.c
Go to the documentation of this file.
1 /*
2 
3  $Id: set_return_type.c 23065 2016-03-02 09:05:50Z coelho $
4 
5  Copyright 1989-2016 MINES ParisTech
6  Copyright 2010 HPC-Project
7 
8  This file is part of PIPS.
9 
10  PIPS is free software: you can redistribute it and/or modify it
11  under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  any later version.
14 
15  PIPS is distributed in the hope that it will be useful, but WITHOUT ANY
16  WARRANTY; without even the implied warranty of MERCHANTABILITY or
17  FITNESS FOR A PARTICULAR PURPOSE.
18 
19  See the GNU General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with PIPS. If not, see <http://www.gnu.org/licenses/>.
23 
24 */
25 
26 // do not compile unless required
27 #include "phases.h"
28 #ifdef BUILDER_SET_RETURN_TYPE_AS_TYPEDEF
29 
30 #ifdef HAVE_CONFIG_H
31  #include "pips_config.h"
32 #endif
33 
34 #include <stdio.h>
35 #include <string.h>
36 
37 #include "genC.h"
38 #include "linear.h"
39 
40 #include "misc.h"
41 #include "properties.h"
42 #include "pipsdbm.h"
43 
44 #include "ri.h"
45 #include "ri-util.h"
46 #include "workspace-util.h"
47 
48 #include "control.h" // PIPS_PHASE_POSTLUDE
49 #include "preprocessor.h" // compilation_unit stuff
50 
51 bool set_return_type_as_typedef(const string mod_name)
52 {
53  // Use this module name and this environment variable to set
55  "SET_RETURN_TYPE_DEBUG_LEVEL");
56 
57 
58  // User give the new type via a string property
59  const char* s_new_type = get_string_property("SET_RETURN_TYPE_AS_TYPEDEF_NEW_TYPE");
60 
61  // We'll now try to recover a valid typedef from this string
62  entity e_new_type = entity_undefined;
63 
65  FOREACH(entity, e, entities ) {
66  /**
67  * Lookup over whole symbol table looking for a corresponding typedef
68  * This is unsecure since there can be typedef in different compilation
69  * unit sharing the same local name. The prefix in pips is random to
70  * distinguish between them
71  */
72  if(typedef_entity_p(e) && strcmp(entity_user_name(e),s_new_type) == 0) {
73  e_new_type = e;
74  }
75  }
76 
77  pips_assert("Requested typedef must be defined", !entity_undefined_p(e_new_type));
78 
79  // Create the new return type
80  type new_return_type = MakeTypeVariable(make_basic_typedef(e_new_type),NULL);
81 
82  entity func = module_name_to_entity(mod_name);
83  pips_assert("func should be functionnal typed\n",type_functional_p(entity_type(func)));
84 
86  functional_result(f) = new_return_type;
87 
88 
92 
93 
94  // Put back the new statement module
96 }
97 
98 #endif // BUILDER_SET_RETURN_TYPE_AS_TYPEDEF
basic make_basic_typedef(entity _field_)
Definition: ri.c:185
static statement module_statement
Definition: alias_check.c:125
char * get_string_property(const char *)
bool gen_true(__attribute__((unused)) gen_chunk *unused)
Return true and ignore the argument.
Definition: genClib.c:2780
#define FOREACH(_fe_CASTER, _fe_item, _fe_list)
Apply/map an instruction block on all the elements of a list.
Definition: newgen_list.h:179
#define PIPS_PHASE_POSTLUDE(new_module_statement)
End a transformation phase by putting back into PIPS the (possibly) modified statement.
#define PIPS_PHASE_PRELUDE(module_name, debug_env_var)
Start a phase that use a module CODE.
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
list gen_filter_tabulated(bool(*)(gen_chunk *), int)
returns the list of entities with this caracteristics.
Definition: tabulated.c:144
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15
const char * entity_user_name(entity e)
Since entity_local_name may contain PIPS special characters such as prefixes (label,...
Definition: entity.c:487
entity module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
Definition: entity.c:1479
bool typedef_entity_p(entity e)
Definition: entity.c:1902
type MakeTypeVariable(basic, cons *)
BEGIN_EOLE.
Definition: type.c:116
#define type_functional_p(x)
Definition: ri.h:2950
#define functional_result(x)
Definition: ri.h:1444
#define type_functional(x)
Definition: ri.h:2952
#define entity_undefined_p(x)
Definition: ri.h:2762
#define entity_undefined
Definition: ri.h:2761
#define entity_type(x)
Definition: ri.h:2792
#define entity_domain
newgen_syntax_domain_defined
Definition: ri.h:410
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
bool set_return_type_as_typedef(const string)
set_return_type.c
void AddEntityToCompilationUnit(entity e, entity cu)
Add an entity to the current's module compilation unit declarations we have to generate its statement...
Definition: module.c:198
void RemoveEntityFromCompilationUnit(entity e, entity cu)
Remove an entity from the current's module compilation unit declarations.
Definition: module.c:265
entity module_entity_to_compilation_unit_entity(entity m)
Retrieve the compilation unit containing a module definition.
Definition: module.c:116