PIPS
activate.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include "genC.h"
#include "database.h"
#include "linear.h"
#include "ri.h"
#include "properties.h"
#include "ri-util.h"
#include "pipsdbm.h"
#include "pipsmake.h"
#include "misc.h"
+ Include dependency graph for activate.c:

Go to the source code of this file.

Functions

static void delete_derived_resources ()
 
void save_active_phases (void)
 activate.c More...
 
void retrieve_active_phases (void)
 
bool active_phase_p (const char *phase)
 
bool saved_active_phase_p (const char *phase)
 Debugging function. More...
 
void fprint_activated (FILE *fd)
 
string active_phase_for_resource (string res)
 return the phase which would be used to build a given resource. More...
 
const char * activate_phase (const char *phase)
 
const char * activate (const char *phase)
 
bool activate_phases (void)
 Use property ACTIVE_PHASES to active the phases required by the user. More...
 
void activate_language (language l)
 Choose the right combination of activate and setproperty for a given language. More...
 
static void get_more_derived_resources (string vrn, set set_of_res)
 
bool rule_use_resource_produced (rule r)
 Test if a rule uses a resource it produces. More...
 
static void delete_derived_resources (virtual_resource res)
 

Variables

static list saved_active_phases = NIL
 

Function Documentation

◆ activate()

const char* activate ( const char *  phase)
Parameters
phasehase

Definition at line 214 of file activate.c.

215 {
216  const char* r = activate_phase(phase);
217  if(!r)
218  pips_user_error("Phase activation error: check the phase names\n");
219  return r;
220 }
const char * activate_phase(const char *phase)
Definition: activate.c:124
#define pips_user_error
Definition: misc-local.h:147

References activate_phase(), and pips_user_error.

Referenced by activate_language(), make_pre_post_transformation(), options_select(), select_rule(), and update_options().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ activate_language()

void activate_language ( language  l)

Choose the right combination of activate and setproperty for a given language.

This is not really compatible with the litterate programming of pipsmake-rc.tex, where this information should be encoded.

Usual properties for Fortran

Usual properties for Fortran 90/95

Usual properties for C

The language is unknown

Definition at line 254 of file activate.c.

255 {
256  if(language_fortran_p(l)) {
257  /* Usual properties for Fortran */
258  set_bool_property("PRETTYPRINT_STATEMENT_NUMBER", true);
259  set_bool_property("FOR_TO_WHILE_LOOP_IN_CONTROLIZER", false);
260  set_bool_property("FOR_TO_DO_LOOP_IN_CONTROLIZER", false);
261 
262  if(!active_phase_p("PARSER"))
263  activate("PARSER");
264  } else if(language_fortran95_p(l)) {
265  /* Usual properties for Fortran 90/95 */
266  set_bool_property("PRETTYPRINT_STATEMENT_NUMBER", false);
267  set_bool_property("FOR_TO_WHILE_LOOP_IN_CONTROLIZER", false);
268  set_bool_property("FOR_TO_DO_LOOP_IN_CONTROLIZER", false);
269 
270  // Temporary fix for autogenerated file
271  if(!active_phase_p("PARSER"))
272  activate("PARSER");
273  } else if(language_c_p(l)) {
274  /* Usual properties for C */
275  set_bool_property("PRETTYPRINT_STATEMENT_NUMBER", false);
276  set_bool_property("FOR_TO_WHILE_LOOP_IN_CONTROLIZER", true);
277  set_bool_property("FOR_TO_DO_LOOP_IN_CONTROLIZER", true);
278 
279  if(!active_phase_p("C_PARSER"))
280  activate("C_PARSER");
281  // No longer useful
282  //if(!active_phase_p("C_SYMBOL_TABLE"))
283  // activate("C_SYMBOL_TABLE");
284  }
285  else {
286  /* The language is unknown*/
287  pips_user_warning("Unknown language initialization\n");
288  }
289 }
bool active_phase_p(const char *phase)
Definition: activate.c:80
const char * activate(const char *phase)
Definition: activate.c:214
#define pips_user_warning
Definition: misc-local.h:146
void set_bool_property(const char *, bool)
#define language_fortran95_p(x)
Definition: ri.h:1597
#define language_c_p(x)
Definition: ri.h:1594
#define language_fortran_p(x)
Definition: ri.h:1591

References activate(), active_phase_p(), language_c_p, language_fortran95_p, language_fortran_p, pips_user_warning, and set_bool_property().

Referenced by add_a_file(), and create_workspace().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ activate_phase()

const char* activate_phase ( const char *  phase)

find rule that describes phase

Parameters
phasehase

Definition at line 124 of file activate.c.

125 {
126  makefile current_makefile = parse_makefile();
127  bool rule_cyclic_p = true;
128  const char * status = phase;
129 
130  debug_on("PIPSMAKE_DEBUG_LEVEL");
131  pips_debug(1, "%s - requested\n", phase);
132 
133  pips_assert("a current workspace is defined",
135 
136  /* find rule that describes phase */
137  rule r = find_rule_by_phase(phase);
138 
139  if (r == rule_undefined) {
140  if (get_bool_property("PIPSMAKE_WARNINGS"))
141  pips_user_warning("Rule `%s' undefined.\n"
142  "Check spelling and/or ACTIVE_PHASE property.\n",
143  phase);
144  status = NULL;
145  }
146  else if (active_phase_p(phase)) {
147  if (get_bool_property("PIPSMAKE_WARNINGS"))
148  pips_user_warning ("Rule `%s' already active\n", phase);
149  }
150  else if (!gen_length(rule_produced(r))) {
151  // if (get_bool_property("PIPSMAKE_WARNINGS"))
152  pips_user_warning("Phase %s produces no resource\n", phase);
153  status = NULL;
154  }
155  else {
156  // GO: for many produced resources we loop over them
157  // with the same 'old' code
158  // find resource res that is produced by phase
160  bool require_produced_rule_p = false;
161  string vrn = virtual_resource_name(res);
162 
164  string vrn2 = virtual_resource_name(vr);
165  owner vro = virtual_resource_owner(vr);
166 
167  // We do not check callers and callees
168  // I dropped select also, just in case... FC
169  if (!(owner_callers_p(vro) || owner_callees_p(vro) ||
170  owner_select_p(vro)) && same_string_p(vrn, vrn2))
171  require_produced_rule_p = true;
172  }
173 
174  // If the current produced resource is not required by the new rule
175  if (!require_produced_rule_p) {
176  rule_cyclic_p = false;
177  // find current active phase old_phase that produces res
178  string old_phase = rule_phase(find_rule_by_resource(vrn));
179 
180  // replace old_phase by phase in active phase list
181  if (old_phase != NULL) {
182  pips_debug(5, "replacing %s by %s for %s\n", old_phase, phase, vrn);
183  MAPL(pa, {
184  string s = STRING(CAR(pa));
185 
186  if (strcmp(s, old_phase) == 0) {
187  free(STRING(CAR(pa)));
188  STRING(CAR(pa)) = strdup(phase);
189  }
190  }, makefile_active_phases(current_makefile));
191  }
192 
193  // this generates many warnings when called from select...
194  if (get_bool_property("ACTIVATE_DEL_DERIVED_RES"))
196  else
198  // remove resources with the same name as res
199  // to maintain consistency in the database
200  db_unput_resources(vrn);
201  }
202  }
203  }
204 
205  if (rule_cyclic_p == true) {
206  pips_user_warning("Phase %s is cyclic\n", phase);
207  status = NULL;
208  }
209  }
210  debug_off();
211  return status;
212 }
int db_unput_resources(const char *rname)
Delete all the resources of a given type "rname".
Definition: database.c:915
static void delete_derived_resources()
struct _newgen_struct_status_ * status
Definition: database.h:31
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
#define STRING(x)
Definition: genC.h:87
void free(void *)
size_t gen_length(const list l)
Definition: list.c:150
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
#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 MAPL(_map_list_cp, _code, _l)
Apply some code on the addresses of all the elements of a list.
Definition: newgen_list.h:203
#define rule_phase(x)
Definition: makefile.h:244
#define virtual_resource_owner(x)
Definition: makefile.h:292
#define rule_required(x)
Definition: makefile.h:246
#define owner_callers_p(x)
Definition: makefile.h:158
#define rule_undefined
Definition: makefile.h:215
#define virtual_resource_name(x)
Definition: makefile.h:290
#define makefile_active_phases(x)
Definition: makefile.h:84
#define rule_produced(x)
Definition: makefile.h:248
#define owner_callees_p(x)
Definition: makefile.h:155
#define VIRTUAL_RESOURCE(x)
VIRTUAL_RESOURCE.
Definition: makefile.h:260
#define owner_select_p(x)
Definition: makefile.h:164
#define debug_on(env)
Definition: misc-local.h:157
#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 debug_off()
Definition: misc-local.h:160
#define same_string_p(s1, s2)
string db_get_current_workspace_name(void)
the function is used to check that there is some current workspace...
Definition: workspace.c:82
rule find_rule_by_phase(const char *)
this function returns the rule that defines builder pname
makefile parse_makefile(void)
rule find_rule_by_resource(const char *rname)
This function returns the active rule to produce resource rname.
Definition: pipsmake.c:694
char * strdup()

References active_phase_p(), CAR, db_get_current_workspace_name(), db_unput_resources(), debug_off, debug_on, delete_derived_resources(), find_rule_by_phase(), find_rule_by_resource(), FOREACH, free(), gen_length(), get_bool_property(), makefile_active_phases, MAPL, owner_callees_p, owner_callers_p, owner_select_p, parse_makefile(), pips_assert, pips_debug, pips_user_warning, rule_phase, rule_produced, rule_required, rule_undefined, same_string_p, strdup(), STRING, VIRTUAL_RESOURCE, virtual_resource_name, and virtual_resource_owner.

Referenced by activate(), and activate_phases().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ activate_phases()

bool activate_phases ( void  )

Use property ACTIVE_PHASES to active the phases required by the user.

Definition at line 224 of file activate.c.

225 {
226  string d = " ,\t\n";
227  // strtok breaks its first argument string
228  string ap = strdup(get_string_property("ACTIVE_PHASES"));
229  string cap = strtok(ap, d);
230  bool pips_special =
231  !same_string_p("full", get_string_property("PIPS_VERSION"));
232  bool result = true;
233 
234  while (cap!=NULL) {
235  pips_debug(1, "Phase to activate: %s\n", cap);
236  if (!active_phase_p(cap)) {
237  const char* r = activate_phase(cap);
238  result = r!=NULL;
239  }
240  cap = strtok(NULL, d);
241  }
242  free(ap);
243 
244  // for a specialized pips, accept invalid phase names
245  return pips_special? true: result;
246 }
char * get_string_property(const char *)

References activate_phase(), active_phase_p(), free(), get_string_property(), pips_debug, same_string_p, and strdup().

Referenced by create_workspace().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ active_phase_for_resource()

string active_phase_for_resource ( string  res)

return the phase which would be used to build a given resource.

Parameters
reses

Definition at line 119 of file activate.c.

120 {
121  return rule_phase(find_rule_by_resource(res));
122 }

References find_rule_by_resource(), and rule_phase.

+ Here is the call graph for this function:

◆ active_phase_p()

bool active_phase_p ( const char *  phase)
Parameters
phasehase

Definition at line 80 of file activate.c.

81 {
82  makefile current_makefile = parse_makefile();
83  list apl = makefile_active_phases(current_makefile);
84 
85  FOREACH(STRING, s, apl)
86  if (same_string_p(s, phase))
87  return true; // new line for breakpoints
88 
89  return false;
90 }
The structure used to build lists in NewGen.
Definition: newgen_list.h:41

References FOREACH, makefile_active_phases, parse_makefile(), same_string_p, and STRING.

Referenced by activate_language(), activate_phase(), activate_phases(), make_pre_post_transformation(), points_to_unary_operation_to_transformer(), and ProcessEntry().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ delete_derived_resources() [1/2]

static void delete_derived_resources ( )
static

Referenced by activate_phase().

+ Here is the caller graph for this function:

◆ delete_derived_resources() [2/2]

static void delete_derived_resources ( virtual_resource  res)
static

Get the set of virtual resource to destroy

Definition at line 382 of file activate.c.

383 {
384  set s = set_make (set_pointer);
385  string vrn = virtual_resource_name(res);
386  /* Get the set of virtual resource to destroy */
388  SET_MAP(se, delete_named_resources((string) se), s);
389  set_free(s);
390 }
static void get_more_derived_resources(string vrn, set set_of_res)
Definition: activate.c:294
#define SET_MAP(element, code, the_set)
Definition: newgen_set.h:54
void set_free(set)
Definition: set.c:332
@ set_pointer
Definition: newgen_set.h:44
set set_make(set_type)
Create an empty set of any type but hash_private.
Definition: set.c:102
void delete_named_resources(const char *rn)
Delete from up_to_date_resources make cache all the resources with a given resource name.
Definition: pipsmake.c:1482
FI: I do not understand why the type is duplicated at the set level.
Definition: set.c:59

References delete_named_resources(), get_more_derived_resources(), set_free(), set_make(), SET_MAP, set_pointer, and virtual_resource_name.

+ Here is the call graph for this function:

◆ fprint_activated()

void fprint_activated ( FILE *  fd)
Parameters
fdd

Definition at line 110 of file activate.c.

111 {
112  makefile m = parse_makefile();
114  fprintf(fd, "%s\n", s);
115 }
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...

References FOREACH, fprintf(), makefile_active_phases, parse_makefile(), and STRING.

Referenced by retrieve_active_phases(), and select_rule().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_more_derived_resources()

static void get_more_derived_resources ( string  vrn,
set  set_of_res 
)
static

If the given resource is not in the set

put it into the set

For all active phases

Search in the required rules

If the resource names are equal

make a recursion for all the produced rules

Here, there is no infinite loop problem with rule producing a ressource they require, because the resource has already been had to the set

Definition at line 294 of file activate.c.

297 {
298  makefile m = parse_makefile();
299  rule r;
300 
301  /* If the given resource is not in the set */
302  if (set_belong_p (set_of_res, (char *) vrn))
303  return;
304 
305  /* put it into the set */
306  set_add_element (set_of_res, set_of_res, (char *) vrn);
307 
308  pips_debug(8, "got %s\n", vrn);
309 
310  /* For all active phases*/
311  MAPL(pa, {
312 
313  r = find_rule_by_phase(STRING(CAR(pa)));
314 
315  if (rule_use_resource_produced(r) == true)
316  debug(9, "get_more_derived_resources",
317  "Don't scan cycling phase %s\n",STRING(CAR(pa)));
318  else
319  {
320  debug(9, "get_more_derived_resources",
321  "Scan phase %s\n",STRING(CAR(pa)));
322 
323  /* Search in the required rules */
324  MAPL(pvr, {
326  string vrn2 = virtual_resource_name(res2);
327 
328  /* If the resource names are equal */
329  if (same_string_p(vrn, vrn2)) {
330 
331  debug(9, "get_more_derived_resources",
332  "Resource %s is required by phase %s\n",
333  vrn, STRING(CAR(pa)));
334 
335  /* make a recursion for all the produced rules */
336  MAPL(pvr3, {
337  virtual_resource res3 = VIRTUAL_RESOURCE(CAR(pvr3));
338  string vrn3 = virtual_resource_name(res3);
339  /* Here, there is no infinite loop problem
340  with rule producing a ressource they require,
341  because the resource has already been had
342  to the set */
343  get_more_derived_resources(vrn3, set_of_res);
344  }, (list) rule_produced ( r ) );
345  break;
346  }
347  }, (list) rule_required( r ) );
348  }
349  }, makefile_active_phases(m));
350 }
bool rule_use_resource_produced(rule r)
Test if a rule uses a resource it produces.
Definition: activate.c:353
void debug(const int the_expected_debug_level, const char *calling_function_name, const char *a_message_format,...)
ARARGS0.
Definition: debug.c:189
bool set_belong_p(const set, const void *)
Definition: set.c:194
set set_add_element(set, const set, const void *)
Definition: set.c:152
struct cons * list
Definition: newgen_types.h:106

References CAR, debug(), find_rule_by_phase(), makefile_active_phases, MAPL, parse_makefile(), pips_debug, rule_produced, rule_required, rule_use_resource_produced(), same_string_p, set_add_element(), set_belong_p(), STRING, VIRTUAL_RESOURCE, and virtual_resource_name.

Referenced by delete_derived_resources().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ retrieve_active_phases()

void retrieve_active_phases ( void  )

Definition at line 58 of file activate.c.

59 {
60  makefile current_makefile = parse_makefile();
61 
62  ifdebug(9) {
63  puts("----- BEFORE RETRIEVING -----");
64  fprint_activated(stdout);
65  }
66 
67  if (saved_active_phases != NIL)
68  {
70  makefile_active_phases(current_makefile) = saved_active_phases;
72 
73  ifdebug(9) {
74  puts("----- AFTER RETREIVING -----");
75  fprint_activated(stdout);
76  }
77  }
78 }
static list saved_active_phases
Definition: activate.c:47
void fprint_activated(FILE *fd)
Definition: activate.c:110
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
void gen_free_string_list(list ls)
Definition: list.c:564
#define ifdebug(n)
Definition: sg.c:47

References fprint_activated(), gen_free_string_list(), ifdebug, makefile_active_phases, NIL, parse_makefile(), and saved_active_phases.

Referenced by apply(), concurrent_apply(), make(), safe_concurrent_apply(), and safe_do_something().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rule_use_resource_produced()

bool rule_use_resource_produced ( rule  r)

Test if a rule uses a resource it produces.

find resource res that is produced by phase

owner vro = virtual_resource_owner(vr);

We DO check callers and callees (DB,08/96)

if ( owner_callers_p(vro) || owner_callees_p(vro) ) {} else

Definition at line 353 of file activate.c.

355 {
356  MAPL(pvrp, {
357  /* find resource res that is produced by phase */
359  string vrn = virtual_resource_name(res);
360 
361  MAPL(pvr, {
363  string vrn2 = virtual_resource_name(vr);
364  /* owner vro = virtual_resource_owner(vr); */
365 
366  /* We DO check callers and callees (DB,08/96) */
367  /* if ( owner_callers_p(vro) || owner_callees_p(vro) ) {}
368  else
369  */
370  if (same_string_p(vrn, vrn2))
371  return true;
372  }, (list) rule_required( r ) );
373 
374  }, (list) rule_produced( r ) );
375 
376  return false;
377 }

References CAR, MAPL, rule_produced, rule_required, same_string_p, VIRTUAL_RESOURCE, and virtual_resource_name.

Referenced by get_more_derived_resources().

+ Here is the caller graph for this function:

◆ save_active_phases()

void save_active_phases ( void  )

activate.c

Definition at line 49 of file activate.c.

50 {
51  makefile current_makefile = parse_makefile();
52 
53  if (saved_active_phases == NIL)
56 }
list gen_copy_string_list(list ls)
of string
Definition: list.c:556

References gen_copy_string_list(), makefile_active_phases, NIL, parse_makefile(), and saved_active_phases.

Referenced by apply(), concurrent_apply(), and make().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saved_active_phase_p()

bool saved_active_phase_p ( const char *  phase)

Debugging function.

Parameters
phasehase

Definition at line 93 of file activate.c.

94 {
96 
97  if(ENDP(sapl)) {
98  fprintf(stderr, "Active phases have not been saved\n");
99  }
100  else {
101  FOREACH(STRING, s, sapl)
102  if (same_string_p(s, phase))
103  return true; // new line for breakpoints
104  }
105 
106  return false;
107 }
#define ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66

References ENDP, FOREACH, fprintf(), same_string_p, saved_active_phases, and STRING.

+ Here is the call graph for this function:

Variable Documentation

◆ saved_active_phases

list saved_active_phases = NIL
static

Definition at line 47 of file activate.c.

Referenced by retrieve_active_phases(), save_active_phases(), and saved_active_phase_p().