PIPS
icfg_scan.c File Reference
#include <stdio.h>
#include <string.h>
#include "genC.h"
#include "linear.h"
#include "properties.h"
#include "misc.h"
#include "pipsdbm.h"
#include "ri.h"
#include "effects.h"
#include "text.h"
#include "text-util.h"
#include "ri-util.h"
#include "prettyprint.h"
#include "control.h"
#include "icfg.h"
+ Include dependency graph for icfg_scan.c:

Go to the source code of this file.

Macros

#define st_DO   prettyprint_fortran_icfg_p ? "do " : "for "
 
#define st_ENDDO   prettyprint_fortran_icfg_p ? "enddo" : "}"
 
#define st_FOR   "for "
 
#define st_ENDFOR   "}"
 
#define st_DOWHILE   prettyprint_fortran_icfg_p ? "do while " : "while "
 
#define st_ENDDOWHILE   prettyprint_fortran_icfg_p ? "enddo" : "}"
 
#define st_REPEAT   prettyprint_fortran_icfg_p ? "repeat " : "do {"
 
#define st_UNTIL   prettyprint_fortran_icfg_p ? "until" : "} while ();"
 
#define st_IF   prettyprint_fortran_icfg_p ? "if" : "if () {"
 
#define st_THEN   prettyprint_fortran_icfg_p ? "then" : ""
 
#define st_ELIF   prettyprint_fortran_icfg_p ? "else if" : "} else if () {"
 
#define st_ELSE   prettyprint_fortran_icfg_p ? "else" : "} else {"
 
#define st_ENDIF   prettyprint_fortran_icfg_p ? "endif" : "}"
 
#define st_WHILE   prettyprint_fortran_icfg_p? "while": "while () {"
 These last two strings are used for unstructured. More...
 
#define st_ENDWHILE   prettyprint_fortran_icfg_p? "endwhile": "}"
 
#define some_text_p(t)   (t!=text_undefined && text_sentences(t)!=NIL)
 
#define current_stmt_head()    ((statement) gen_get_ancestor(statement_domain, gen_get_current_object()))
 We want to keep track of the current statement inside the recurse. More...
 
#define ICFG_DEFAULT_INDENTATION   (4)
 

Functions

void icfg_set_indentation (int indent)
 caller More...
 
void icfg_reset_indentation (void)
 
void icfg_error_handler (void)
 
static void append_marged_text (text t, int margin, const char *what1, const char *what2)
 
static bool statement_flt (statement s)
 STATEMENT. More...
 
static void statement_rwt (statement s)
 
static void call_flt (call c)
 CALL. More...
 
static bool loop_flt (loop __attribute__((unused)) l)
 LOOP. More...
 
static void anyloop_rwt (const char *st_what, const char *st_end_what, const char *st_index, statement body)
 
static void loop_rwt (loop l)
 
static void forloop_rwt (forloop l)
 
static void while_rwt (whileloop w)
 
static bool instruction_flt (instruction i)
 INSTRUCTION. More...
 
static void instruction_rwt (instruction i)
 
static bool range_flt (range __attribute__((unused)) r)
 RANGE functions to avoid the indentation when dealing with DO expressions. More...
 
static void range_rwt (range __attribute__((unused)) r)
 
static bool is_elsif_test_p (test t)
 TEST functions to deal with the indentation of ELSIFs. More...
 
static bool has_elsif_test_p (test t)
 This function tests if the ELSE clause of t is an ELIF. More...
 
static bool test_flt (test t)
 
static void test_rwt (test l)
 
static void print_module_icfg (entity module)
 
static bool internal_print_icfg (const string module_name, bool with_ifs, bool with_loops, bool do_graph, bool do_reset, text(*deco1)(const string), text(*deco2)(entity, entity, statement, call), text(*deco3)(entity, statement, call), text(*deco4)(entity, statement))
 
bool generic_print_icfg (const string module_name, bool with_ifs, bool with_loops, bool do_graph, text(*decoration)(const string))
 
bool generic_print_icfg_precise (const string module_name, bool with_ifs, bool with_loops, bool do_graph, text(*decoration)(entity, entity, statement, call))
 
bool generic_print_icfg_filtered (const string module_name, bool with_ifs, bool with_loops, bool do_graph, text(*decoration_call)(entity, statement, call), text(*decoration_stmt)(entity, statement))
 

Variables

static int icfg_indent = ICFG_DEFAULT_INDENTATION
 
static bool print_loops = false
 We store the text for each statement in a mapping during a code traversal in order to print it afterwards. More...
 
static bool print_ifs = false
 
static bool do_reset_current_module_entity_on_decoration = false
 
static bool prettyprint_fortran_icfg_p = true
 
static bool prettyprint_C_icfg_p = false
 
static text(* module_decoration )(const string) = NULL
 
static text(* precise_decoration )(entity, entity, statement, call) = NULL
 
static text(* filter_decoration_call )(entity, statement, call) = NULL
 
static text(* filter_decoration_stmt )(entity, statement) = NULL
 
static int current_margin
 
static list verlist = NIL
 of vertex More...
 
static vertex current_vertex = NULL
 to make graph daVinci More...
 

Macro Definition Documentation

◆ current_stmt_head

#define current_stmt_head ( )     ((statement) gen_get_ancestor(statement_domain, gen_get_current_object()))

We want to keep track of the current statement inside the recurse.

Definition at line 76 of file icfg_scan.c.

◆ ICFG_DEFAULT_INDENTATION

#define ICFG_DEFAULT_INDENTATION   (4)

Definition at line 82 of file icfg_scan.c.

◆ some_text_p

#define some_text_p (   t)    (t!=text_undefined && text_sentences(t)!=NIL)

Definition at line 73 of file icfg_scan.c.

◆ st_DO

#define st_DO   prettyprint_fortran_icfg_p ? "do " : "for "

Definition at line 55 of file icfg_scan.c.

◆ st_DOWHILE

#define st_DOWHILE   prettyprint_fortran_icfg_p ? "do while " : "while "

Definition at line 59 of file icfg_scan.c.

◆ st_ELIF

#define st_ELIF   prettyprint_fortran_icfg_p ? "else if" : "} else if () {"

Definition at line 66 of file icfg_scan.c.

◆ st_ELSE

#define st_ELSE   prettyprint_fortran_icfg_p ? "else" : "} else {"

Definition at line 67 of file icfg_scan.c.

◆ st_ENDDO

#define st_ENDDO   prettyprint_fortran_icfg_p ? "enddo" : "}"

Definition at line 56 of file icfg_scan.c.

◆ st_ENDDOWHILE

#define st_ENDDOWHILE   prettyprint_fortran_icfg_p ? "enddo" : "}"

Definition at line 60 of file icfg_scan.c.

◆ st_ENDFOR

#define st_ENDFOR   "}"

Definition at line 58 of file icfg_scan.c.

◆ st_ENDIF

#define st_ENDIF   prettyprint_fortran_icfg_p ? "endif" : "}"

Definition at line 68 of file icfg_scan.c.

◆ st_ENDWHILE

#define st_ENDWHILE   prettyprint_fortran_icfg_p? "endwhile": "}"

Definition at line 71 of file icfg_scan.c.

◆ st_FOR

#define st_FOR   "for "

Definition at line 57 of file icfg_scan.c.

◆ st_IF

#define st_IF   prettyprint_fortran_icfg_p ? "if" : "if () {"

Definition at line 64 of file icfg_scan.c.

◆ st_REPEAT

#define st_REPEAT   prettyprint_fortran_icfg_p ? "repeat " : "do {"

Definition at line 61 of file icfg_scan.c.

◆ st_THEN

#define st_THEN   prettyprint_fortran_icfg_p ? "then" : ""

Definition at line 65 of file icfg_scan.c.

◆ st_UNTIL

#define st_UNTIL   prettyprint_fortran_icfg_p ? "until" : "} while ();"

Definition at line 62 of file icfg_scan.c.

◆ st_WHILE

#define st_WHILE   prettyprint_fortran_icfg_p? "while": "while () {"

These last two strings are used for unstructured.

Definition at line 70 of file icfg_scan.c.

Function Documentation

◆ anyloop_rwt()

static void anyloop_rwt ( const char *  st_what,
const char *  st_end_what,
const char *  st_index,
statement  body 
)
static

Print the text inside do expressions (before the DO!)

Print the DO

Print the text inside the loop

Print the ENDDO

store it to the statement mapping

Definition at line 221 of file icfg_scan.c.

226 {
227  text inside_the_loop = text_undefined,
228  inside_the_do = text_undefined,
229  t = make_text (NIL);
230  bool text_in_do_p, text_in_loop_p;
231 
232  pips_debug (5,"Loop end\n");
233 
235 
236  inside_the_do = (text) load_statement_icfg (current_stmt_head());
237  text_in_do_p = some_text_p(inside_the_do);
238 
239  inside_the_loop = (text) load_statement_icfg (body);
240  text_in_loop_p = some_text_p(inside_the_loop);
241 
242  /* Print the text inside do expressions (before the DO!)
243  */
244  if (text_in_do_p)
245  {
246  pips_debug(9, "something inside_the_do\n");
247  MERGE_TEXTS (t, inside_the_do);
248  }
249 
250  /* Print the DO
251  */
252  if ((text_in_loop_p || text_in_do_p) && print_loops)
253  {
255  append_marged_text(t, current_margin, st_what, st_index);
256  else {
257  string st_end = string_undefined;
258  asprintf(&st_end, "(%s) {", st_index);
259  append_marged_text(t, current_margin, st_what, st_end);
260  free(st_end);
261  }
262  }
263 
264  /* Print the text inside the loop
265  */
266  if (text_in_loop_p)
267  {
268  pips_debug(9, "something inside_the_loop\n");
269  MERGE_TEXTS (t, inside_the_loop);
270  }
271 
272  /* Print the ENDDO
273  */
274  if ((text_in_loop_p || text_in_do_p) && print_loops)
275  {
276  append_marged_text(t, current_margin, st_end_what, "");
277  }
278 
279  /* store it to the statement mapping */
280  update_statement_icfg (current_stmt_head(), t);
281 
282  return ;
283 }
text make_text(list a)
Definition: text.c:107
void free(void *)
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
static int icfg_indent
Definition: icfg_scan.c:83
#define current_stmt_head()
We want to keep track of the current statement inside the recurse.
Definition: icfg_scan.c:76
#define some_text_p(t)
Definition: icfg_scan.c:73
static void append_marged_text(text t, int margin, const char *what1, const char *what2)
Definition: icfg_scan.c:127
static int current_margin
Definition: icfg_scan.c:105
static bool print_loops
We store the text for each statement in a mapping during a code traversal in order to print it afterw...
Definition: icfg_scan.c:93
static bool prettyprint_fortran_icfg_p
Definition: icfg_scan.c:96
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
#define asprintf
Definition: misc-local.h:225
#define string_undefined
Definition: newgen_types.h:40
return(s1)
#define MERGE_TEXTS(r, t)
struct _newgen_struct_text_ * text
Definition: text.h:23
#define text_undefined
Definition: text.h:91

References append_marged_text(), asprintf, current_margin, current_stmt_head, free(), icfg_indent, make_text(), MERGE_TEXTS, NIL, pips_debug, prettyprint_fortran_icfg_p, print_loops, return(), some_text_p, string_undefined, and text_undefined.

Referenced by forloop_rwt(), loop_rwt(), and while_rwt().

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

◆ append_marged_text()

static void append_marged_text ( text  t,
int  margin,
const char *  what1,
const char *  what2 
)
static

Definition at line 127 of file icfg_scan.c.

132 {
133  char *buffer;
134  asprintf(&buffer, "%*s%s%s\n", margin, "", what1, what2);
136 }
sentence make_sentence(enum sentence_utype tag, void *val)
Definition: text.c:59
static string buffer
Definition: string.c:113
#define ADD_SENTENCE_TO_TEXT(t, p)
@ is_sentence_formatted
Definition: text.h:57

References ADD_SENTENCE_TO_TEXT, asprintf, buffer, is_sentence_formatted, and make_sentence().

Referenced by anyloop_rwt(), call_flt(), instruction_rwt(), print_module_icfg(), and test_rwt().

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

◆ call_flt()

static void call_flt ( call  c)
static

CALL.

If this is a "real function" (defined in the code elsewhere)

hum... pushes the current entity...

append the callee' icfg

ppend_icfg_file (r, callee_name);

store it to the statement mapping

Definition at line 168 of file icfg_scan.c.

169 {
170  entity e_callee = call_function(c);
171  const string callee_name = (const string) module_local_name(e_callee);
172 
173  pips_debug (5,"called entity is %s\n", entity_name(e_callee));
174 
175  /* If this is a "real function" (defined in the code elsewhere) */
176  if (value_code_p(entity_initial(e_callee))) {
177  text r = (text) load_statement_icfg (current_stmt_head());
178 
179  /* hum... pushes the current entity... */
180  entity e_caller = get_current_module_entity();
181 
182  vertex ver_child = get_vertex_by_string(callee_name, verlist);
183  if (ver_child != vertex_undefined)
185 
186  // this hack is really needed...
189 
190  if (module_decoration)
191  MERGE_TEXTS(r, (*module_decoration)(callee_name));
192  else if (precise_decoration)
193  MERGE_TEXTS(r,
194  (*precise_decoration)(e_caller, e_callee, current_stmt_head(), c));
195  else if (filter_decoration_call)
196  MERGE_TEXTS(r,
197  (*filter_decoration_call)(e_caller, current_stmt_head(), c));
198 
199  // really needed, retrieve the caller entity
201  set_current_module_entity(e_caller);
202 
203  /* append the callee' icfg */
204  /*append_icfg_file (r, callee_name);*/
205  append_marged_text(r, current_margin, CALL_MARK, callee_name);
206  /* store it to the statement mapping */
207  update_statement_icfg(current_stmt_head(), r);
208  }
209  return;
210 }
#define vertex_undefined
Definition: graph.h:128
void reset_current_module_entity(void)
Reset the current module entity.
Definition: static.c:97
entity set_current_module_entity(entity)
static.c
Definition: static.c:66
entity get_current_module_entity(void)
Get the entity of the current module.
Definition: static.c:85
#define CALL_MARK
Definition: icfg-local.h:49
list safe_make_successor(vertex, vertex, list)
Definition: util.c:110
vertex get_vertex_by_string(const char *, list)
Definition: util.c:92
static text(* filter_decoration_call)(entity, statement, call)
Definition: icfg_scan.c:102
static text(* precise_decoration)(entity, entity, statement, call)
Definition: icfg_scan.c:100
static text(* module_decoration)(const string)
Definition: icfg_scan.c:99
static vertex current_vertex
to make graph daVinci
Definition: icfg_scan.c:108
static bool do_reset_current_module_entity_on_decoration
Definition: icfg_scan.c:95
static list verlist
of vertex
Definition: icfg_scan.c:107
char * string
STRING.
Definition: newgen_types.h:39
const char * module_local_name(entity e)
Returns the module local user name.
Definition: entity.c:582
#define value_code_p(x)
Definition: ri.h:3065
#define call_function(x)
Definition: ri.h:709
#define entity_name(x)
Definition: ri.h:2790
#define entity_initial(x)
Definition: ri.h:2796

References append_marged_text(), call_function, CALL_MARK, current_margin, current_stmt_head, current_vertex, do_reset_current_module_entity_on_decoration, entity_initial, entity_name, filter_decoration_call, get_current_module_entity(), get_vertex_by_string(), MERGE_TEXTS, module_decoration, module_local_name(), pips_debug, precise_decoration, reset_current_module_entity(), safe_make_successor(), set_current_module_entity(), value_code_p, verlist, and vertex_undefined.

Referenced by print_module_icfg().

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

◆ forloop_rwt()

static void forloop_rwt ( forloop  l)
static

Definition at line 290 of file icfg_scan.c.

291 {
293 }
static void anyloop_rwt(const char *st_what, const char *st_end_what, const char *st_index, statement body)
Definition: icfg_scan.c:221
#define st_ENDFOR
Definition: icfg_scan.c:58
#define st_FOR
Definition: icfg_scan.c:57
#define forloop_body(x)
Definition: ri.h:1372

References anyloop_rwt(), forloop_body, st_ENDFOR, and st_FOR.

Referenced by print_module_icfg().

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

◆ generic_print_icfg()

bool generic_print_icfg ( const string  module_name,
bool  with_ifs,
bool  with_loops,
bool  do_graph,
text(*)(const string decoration 
)
Parameters
module_nameodule_name
with_ifsith_ifs
with_loopsith_loops
do_grapho_graph

Definition at line 713 of file icfg_scan.c.

719 {
720  return internal_print_icfg(module_name, with_ifs, with_loops, do_graph,
721  true, decoration, NULL, NULL, NULL);
722 }
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
static bool internal_print_icfg(const string module_name, bool with_ifs, bool with_loops, bool do_graph, bool do_reset, text(*deco1)(const string), text(*deco2)(entity, entity, statement, call), text(*deco3)(entity, statement, call), text(*deco4)(entity, statement))
Definition: icfg_scan.c:668

References internal_print_icfg(), and module_name().

Referenced by print_icfg(), print_icfg_with_control(), and print_icfg_with_loops().

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

◆ generic_print_icfg_filtered()

bool generic_print_icfg_filtered ( const string  module_name,
bool  with_ifs,
bool  with_loops,
bool  do_graph,
text(*)(entity, statement, call decoration_call,
text(*)(entity, statement decoration_stmt 
)
Parameters
module_nameodule_name
with_ifsith_ifs
with_loopsith_loops
do_grapho_graph

Definition at line 735 of file icfg_scan.c.

742 {
743  return internal_print_icfg(module_name, with_ifs, with_loops, do_graph,
744  false, NULL, NULL, decoration_call, decoration_stmt);
745 }

References internal_print_icfg(), and module_name().

+ Here is the call graph for this function:

◆ generic_print_icfg_precise()

bool generic_print_icfg_precise ( const string  module_name,
bool  with_ifs,
bool  with_loops,
bool  do_graph,
text(*)(entity, entity, statement, call decoration 
)
Parameters
module_nameodule_name
with_ifsith_ifs
with_loopsith_loops
do_grapho_graph

Definition at line 724 of file icfg_scan.c.

730 {
731  return internal_print_icfg(module_name, with_ifs, with_loops, do_graph,
732  true, NULL, decoration, NULL, NULL);
733 }

References internal_print_icfg(), and module_name().

+ Here is the call graph for this function:

◆ has_elsif_test_p()

static bool has_elsif_test_p ( test  t)
static

This function tests if the ELSE clause of t is an ELIF.

Definition at line 464 of file icfg_scan.c.

464  {
465 
466  bool has_elsif_p = false;
467 
468  pips_debug (3, ">>>has_elsif_test_p begins for test=%p\n", t);
469 
470  statement tfs = test_false(t);
472 
473  has_elsif_p = instruction_test_p(tfi);
474 
475  pips_debug (3, "has_elsif_p = %d\n", has_elsif_p);
476  pips_debug (3, ">>>has_elsif_test_p ends for test=%p\n", t);
477 
478  return (has_elsif_p);
479 }
#define test_false(x)
Definition: ri.h:2837
#define statement_instruction(x)
Definition: ri.h:2458
#define instruction_test_p(x)
Definition: ri.h:1515

References instruction_test_p, pips_debug, statement_instruction, and test_false.

Referenced by test_rwt().

+ Here is the caller graph for this function:

◆ icfg_error_handler()

void icfg_error_handler ( void  )

Definition at line 122 of file icfg_scan.c.

123 {
124  // ???
125 }

Referenced by print_module_icfg().

+ Here is the caller graph for this function:

◆ icfg_reset_indentation()

void icfg_reset_indentation ( void  )

Definition at line 117 of file icfg_scan.c.

118 {
120 }
#define ICFG_DEFAULT_INDENTATION
Definition: icfg_scan.c:82

References ICFG_DEFAULT_INDENTATION, and icfg_indent.

Referenced by internal_print_icfg().

+ Here is the caller graph for this function:

◆ icfg_set_indentation()

void icfg_set_indentation ( int  indent)

caller

icfg_scan.c

Parameters
indentndent

Definition at line 112 of file icfg_scan.c.

113 {
114  icfg_indent = indent;
115 }

References icfg_indent.

Referenced by internal_print_icfg().

+ Here is the caller graph for this function:

◆ instruction_flt()

static bool instruction_flt ( instruction  i)
static

INSTRUCTION.

Definition at line 307 of file icfg_scan.c.

308 {
311  pips_debug (5, "While begin\n");
313  }
314  return true;
315 }
bool unstructured_while_p(unstructured u)
Test if an unstructured is found to be like a structured while-loop.
Definition: cfg.c:191
#define instruction_unstructured_p(x)
Definition: ri.h:1530
#define instruction_unstructured(x)
Definition: ri.h:1532

References current_margin, icfg_indent, instruction_unstructured, instruction_unstructured_p, pips_debug, print_loops, and unstructured_while_p().

Referenced by print_module_icfg().

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

◆ instruction_rwt()

static void instruction_rwt ( instruction  i)
static

store it to the statement mapping

SHARING! Every statement gets a pointer to the same precondition! I do not know if it's good or not but beware the bugs!!!

Print the WHILE

Print the text inside the unstructured (possibly the while body)

Print the ENDDWHILE

Definition at line 317 of file icfg_scan.c.

318 {
319  text t = make_text (NIL);
320  bool text_in_unstructured_p = false;
321 
322  pips_debug (5,"going up\n");
323  pips_debug (9,"instruction tag = %d\n", instruction_tag (i));
324 
325  switch (instruction_tag (i)) {
327  {
328  pips_debug (5,"dealing with a block, appending texts\n");
329 
330  MAP(STATEMENT, s,
331  MERGE_TEXTS(t, load_statement_icfg(s)),
332  instruction_block(i));
333 
334  /* store it to the statement mapping */
335  update_statement_icfg (current_stmt_head (), t);
336  break;
337  }
339  {
341  list blocs = NIL ;
342  control ct = unstructured_control(u) ;
343  text inside_the_unstructured = make_text(NIL);
344  bool while_p = false;
345 
346  pips_debug (5,"dealing with an unstructured, appending texts\n");
347 
348  if(unstructured_while_p(u)) {
349  while_p = true;
350  pips_debug (5,"dealing with a WHILE\n");
351  }
352 
353  /* SHARING! Every statement gets a pointer to the same precondition!
354  I do not know if it's good or not but beware the bugs!!! */
356  statement st = control_statement(c) ;
357  MERGE_TEXTS(inside_the_unstructured, load_statement_icfg (st));
358  }, ct, blocs) ;
359 
360  gen_free_list(blocs) ;
361 
362  text_in_unstructured_p = some_text_p(inside_the_unstructured);
363 
364  /* Print the WHILE
365  */
366  if(print_loops && while_p) {
368  if(text_in_unstructured_p) {
370  }
371  }
372 
373  /* Print the text inside the unstructured (possibly the while body)
374  */
375  if(text_in_unstructured_p) {
376  pips_debug(9, "something inside_the_loop\n");
377  MERGE_TEXTS (t, inside_the_unstructured);
378  }
379 
380  /* Print the ENDDWHILE
381  */
382  if (text_in_unstructured_p && print_loops && while_p)
383  {
385  }
386 
387  update_statement_icfg (current_stmt_head (), t);
388  break;
389  }
390  default:
391  break;
392  }
393 
394 }
#define FORWARD_CONTROL_MAP(ctl, code, c, list)
Walk through all the controls forward-reachable from a given control node of an unstructured.
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 st_ENDWHILE
Definition: icfg_scan.c:71
#define st_WHILE
These last two strings are used for unstructured.
Definition: icfg_scan.c:70
#define unstructured_control
After the modification in Newgen: unstructured = entry:control x exit:control we have create a macro ...
#define is_instruction_block
soft block->sequence transition
#define instruction_block(i)
@ is_instruction_unstructured
Definition: ri.h:1475
#define instruction_tag(x)
Definition: ri.h:1511
#define control_statement(x)
Definition: ri.h:941
#define STATEMENT(x)
STATEMENT.
Definition: ri.h:2413
The structure used to build lists in NewGen.
Definition: newgen_list.h:41

References append_marged_text(), control_statement, current_margin, current_stmt_head, FORWARD_CONTROL_MAP, gen_free_list(), icfg_indent, instruction_block, instruction_tag, instruction_unstructured, is_instruction_block, is_instruction_unstructured, make_text(), MAP, MERGE_TEXTS, NIL, pips_debug, print_loops, some_text_p, st_ENDWHILE, st_WHILE, STATEMENT, unstructured_control, and unstructured_while_p().

Referenced by print_module_icfg().

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

◆ internal_print_icfg()

static bool internal_print_icfg ( const string  module_name,
bool  with_ifs,
bool  with_loops,
bool  do_graph,
bool  do_reset,
text(*)(const string deco1,
text(*)(entity, entity, statement, call deco2,
text(*)(entity, statement, call deco3,
text(*)(entity, statement deco4 
)
static

Definition at line 668 of file icfg_scan.c.

678 {
680 
681  pips_debug(1,"===%s===%s===\n", module_name, entity_name(mod));
683 
684  // select language
687 
688  // hmm... not whether sure using properties is a good idea
689  set_bool_property(ICFG_IFs, with_ifs);
690  set_bool_property(ICFG_DOs, with_loops);
691  set_bool_property(ICFG_DV, do_graph);
692 
694 
695  module_decoration = deco1;
696  precise_decoration = deco2;
697  filter_decoration_call = deco3;
698  filter_decoration_stmt = deco4;
699 
700  icfg_set_indentation(get_int_property("ICFG_INDENTATION"));
701  print_module_icfg(mod);
703 
704  module_decoration = NULL;
705  precise_decoration = NULL;
706  filter_decoration_call = NULL;
707  filter_decoration_stmt = NULL;
708 
709  debug_off();
710  return true;
711 }
int get_int_property(const string)
#define ICFG_DV
Definition: icfg-local.h:38
#define ICFG_DEBUG_LEVEL
Definition: icfg-local.h:35
#define ICFG_IFs
Definition: icfg-local.h:37
#define ICFG_DOs
Definition: icfg-local.h:36
static bool prettyprint_C_icfg_p
Definition: icfg_scan.c:97
void icfg_reset_indentation(void)
Definition: icfg_scan.c:117
void icfg_set_indentation(int indent)
caller
Definition: icfg_scan.c:112
static void print_module_icfg(entity module)
Definition: icfg_scan.c:593
static text(* filter_decoration_stmt)(entity, statement)
Definition: icfg_scan.c:103
#define debug_on(env)
Definition: misc-local.h:157
#define debug_off()
Definition: misc-local.h:160
void set_bool_property(const char *, bool)
entity local_name_to_top_level_entity(const char *n)
This function try to find a top-level entity from a local name.
Definition: entity.c:1450
bool c_module_p(entity m)
Test if a module "m" is written in C.
Definition: entity.c:2777
bool fortran_module_p(entity m)
Test if a module is in Fortran.
Definition: entity.c:2799

References c_module_p(), debug_off, debug_on, do_reset_current_module_entity_on_decoration, entity_name, filter_decoration_call, filter_decoration_stmt, fortran_module_p(), get_int_property(), ICFG_DEBUG_LEVEL, ICFG_DOs, ICFG_DV, ICFG_IFs, icfg_reset_indentation(), icfg_set_indentation(), local_name_to_top_level_entity(), module_decoration, module_name(), pips_debug, precise_decoration, prettyprint_C_icfg_p, prettyprint_fortran_icfg_p, print_module_icfg(), and set_bool_property().

Referenced by generic_print_icfg(), generic_print_icfg_filtered(), and generic_print_icfg_precise().

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

◆ is_elsif_test_p()

static bool is_elsif_test_p ( test  t)
static

TEST functions to deal with the indentation of ELSIFs.

This function tests if t is the exact content of and ELSE clause.

Determine if t is inside another test

Definition at line 422 of file icfg_scan.c.

422  {
423 
424  bool elsif_p = false;
425 
426  /*
427  gen_chunk p1 = gen_get_recurse_ancestor((void *)t);
428  gen_chunk * pp1 = &p1;
429  int * pi = pp1;
430  int i = *pi;
431  if (i != ((int)(HASH_UNDEFINED_VALUE)))
432  if ( i != ((int)(NULL)))
433  pips_debug(1, "Type of p1 %d\n", gen_type(i));
434  */
435 
436  /* Determine if t is inside another test */
437  test pt = (test)gen_get_ancestor_type(test_domain, (void *)t);
438  if (pt != (test)HASH_UNDEFINED_VALUE && pt != (test)(NULL)) {
439  // Get the "ELSE Clause" statement of the parent test
440  statement ptf = test_false(pt);
441  ifdebug(4) {
442  pips_debug(4, "Parent test_false is:\n");
443  print_statement(ptf);
444  fprintf(stderr, "\n");
445  }
446 
447  // Get the statement corresponding to t
449  if (ts != (statement)HASH_UNDEFINED_VALUE && ts != (statement)(NULL)) {
450  ifdebug(4) {
451  pips_debug(4, "My test statement is:\n");
452  print_statement(ts);
453  fprintf(stderr, "\n");
454  }
455  // If these two statements are the same, then we are in an ELSIF clause.
456  elsif_p = (ptf == ts);
457  }
458  }
459  return elsif_p;
460 }
struct _newgen_struct_statement_ * statement
Definition: cloning.h:21
#define gen_get_ancestor_type(i, o)
Definition: genC.h:276
#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
void print_statement(statement)
Print a statement on stderr.
Definition: statement.c:98
struct _newgen_struct_test_ * test
Definition: ri.h:423
#define test_domain
newgen_entity_domain_defined
Definition: ri.h:418
#define statement_domain
newgen_sizeofexpression_domain_defined
Definition: ri.h:362
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
#define ifdebug(n)
Definition: sg.c:47

References fprintf(), gen_get_ancestor_type, HASH_UNDEFINED_VALUE, ifdebug, pips_debug, print_statement(), statement_domain, test_domain, and test_false.

Referenced by test_flt(), and test_rwt().

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

◆ loop_flt()

static bool loop_flt ( loop __attribute__((unused))  l)
static

LOOP.

Definition at line 214 of file icfg_scan.c.

215 {
216  pips_debug (5, "Loop begin\n");
218  return true;
219 }

References current_margin, icfg_indent, pips_debug, and print_loops.

Referenced by print_module_icfg().

+ Here is the caller graph for this function:

◆ loop_rwt()

static void loop_rwt ( loop  l)
static

Definition at line 285 of file icfg_scan.c.

286 {
288 }
#define st_ENDDO
Definition: icfg_scan.c:56
#define st_DO
Definition: icfg_scan.c:55
const char * entity_user_name(entity e)
Since entity_local_name may contain PIPS special characters such as prefixes (label,...
Definition: entity.c:487
#define loop_body(x)
Definition: ri.h:1644
#define loop_index(x)
Definition: ri.h:1640

References anyloop_rwt(), entity_user_name(), loop_body, loop_index, st_DO, and st_ENDDO.

Referenced by print_module_icfg().

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

◆ print_module_icfg()

static void print_module_icfg ( entity  module)
static

allocate the mapping

Definition at line 593 of file icfg_scan.c.

594 {
595  const char* module_name = module_local_name(module);
597  text txt = make_text(NIL);
598  append_marged_text(txt, 0, module_name, "");
600 
602 
603  /* allocate the mapping */
604  make_icfg_map();
605 
607 
609 
612 
614  (s,
623  NULL);
624 
625  // ???
628  bool found = false;
629  MAP(SENTENCE, sen, {
630  string one_line = sentence_to_string(sen);
631  if (strstr(one_line, CALL_MARK) == NULL) {
632  found = true;
633  break;
634  }
635  }, text_sentences(load_statement_icfg(s)));
636  if (found) {
638  } else {
641  }
642  } else {
644  }
645  } else {
647  }
648 
650  MERGE_TEXTS(txt, (text) load_statement_icfg(s));
651 
653  get_bool_property(ICFG_IFs) ? ".icfgc" :
654  (get_bool_property(ICFG_DOs) ? ".icfgl" :
655  ".icfg"),
656  current_vertex, verlist, true);
657 
659  make_resource_from_starting_node(module_name, DBR_DVICFG_FILE, ".dvicfg",
660  current_vertex, verlist, false);
661 
662  // cleanup
663  free_icfg_map();
666 }
vertex make_vertex(vertex_label a1, list a2)
Definition: graph.c:140
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
#define vertex_successors(x)
Definition: graph.h:154
#define vertex_undefined_p(x)
Definition: graph.h:129
void gen_multi_recurse(void *o,...)
Multi recursion visitor function.
Definition: genClib.c:3428
void gen_null(__attribute__((unused)) void *unused)
Ignore the argument.
Definition: genClib.c:2752
string db_get_memory_resource(const char *rname, const char *oname, bool pure)
Return the pointer to the resource, whatever it is.
Definition: database.c:755
bool make_resource_from_starting_node(const char *, string, string, vertex, list, bool)
Definition: util.c:221
void safe_free_vertex(vertex, list)
util.c
Definition: util.c:43
list safe_add_vertex_to_list(vertex, list)
Definition: util.c:50
static void test_rwt(test l)
Definition: icfg_scan.c:503
static bool loop_flt(loop __attribute__((unused)) l)
LOOP.
Definition: icfg_scan.c:214
static void forloop_rwt(forloop l)
Definition: icfg_scan.c:290
static void range_rwt(range __attribute__((unused)) r)
Definition: icfg_scan.c:408
static void loop_rwt(loop l)
Definition: icfg_scan.c:285
void icfg_error_handler(void)
Definition: icfg_scan.c:122
static void instruction_rwt(instruction i)
Definition: icfg_scan.c:317
static bool print_ifs
Definition: icfg_scan.c:94
static void call_flt(call c)
CALL.
Definition: icfg_scan.c:168
static void statement_rwt(statement s)
Definition: icfg_scan.c:159
static bool instruction_flt(instruction i)
INSTRUCTION.
Definition: icfg_scan.c:307
static bool range_flt(range __attribute__((unused)) r)
RANGE functions to avoid the indentation when dealing with DO expressions.
Definition: icfg_scan.c:399
static void while_rwt(whileloop w)
Definition: icfg_scan.c:295
static bool test_flt(test t)
Definition: icfg_scan.c:482
static bool statement_flt(statement s)
STATEMENT.
Definition: icfg_scan.c:140
void reset_hooks_unregister(reset_func_t)
remove registered cleanup hook.
Definition: reset_hooks.c:73
void reset_hooks_register(reset_func_t)
reset_hooks.c
Definition: reset_hooks.c:44
static char * module
Definition: pips.c:74
#define forloop_domain
newgen_extensions_domain_defined
Definition: ri.h:178
#define loop_domain
newgen_language_domain_defined
Definition: ri.h:218
#define instruction_domain
newgen_functional_domain_defined
Definition: ri.h:202
#define call_domain
newgen_callees_domain_defined
Definition: ri.h:58
#define whileloop_domain
newgen_variable_domain_defined
Definition: ri.h:466
#define range_domain
newgen_ram_domain_defined
Definition: ri.h:330
string sentence_to_string(sentence sen)
SG: moved here from icfdg.
Definition: print.c:230
#define SENTENCE(x)
newgen_unformatted_domain_defined
Definition: text.h:36
#define text_sentences(x)
Definition: text.h:113

References append_marged_text(), call_domain, call_flt(), CALL_MARK, current_margin, current_vertex, db_get_memory_resource(), filter_decoration_call, forloop_domain, forloop_rwt(), gen_multi_recurse(), gen_null(), get_bool_property(), ICFG_DOs, ICFG_DV, icfg_error_handler(), ICFG_IFs, icfg_indent, instruction_domain, instruction_flt(), instruction_rwt(), loop_domain, loop_flt(), loop_rwt(), make_resource_from_starting_node(), make_text(), make_vertex(), MAP, MERGE_TEXTS, module, module_local_name(), module_name(), NIL, print_ifs, print_loops, range_domain, range_flt(), range_rwt(), reset_current_module_entity(), reset_hooks_register(), reset_hooks_unregister(), safe_add_vertex_to_list(), safe_free_vertex(), SENTENCE, sentence_to_string(), set_current_module_entity(), statement_domain, statement_flt(), statement_rwt(), test_domain, test_flt(), test_rwt(), text_sentences, verlist, vertex_successors, vertex_undefined, vertex_undefined_p, while_rwt(), and whileloop_domain.

Referenced by internal_print_icfg().

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

◆ range_flt()

static bool range_flt ( range __attribute__((unused))  r)
static

RANGE functions to avoid the indentation when dealing with DO expressions.

Definition at line 399 of file icfg_scan.c.

400 {
402 
405  return true;
406 }
loop statement_loop(statement)
Get the loop of a statement.
Definition: statement.c:1374
bool statement_loop_p(statement)
Definition: statement.c:349
#define loop_range(x)
Definition: ri.h:1642

References current_margin, current_stmt_head, icfg_indent, loop_range, print_loops, statement_loop(), and statement_loop_p().

Referenced by print_module_icfg().

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

◆ range_rwt()

static void range_rwt ( range __attribute__((unused))  r)
static

Definition at line 408 of file icfg_scan.c.

409 {
411 
414 }

References current_margin, current_stmt_head, icfg_indent, loop_range, print_loops, statement_loop(), and statement_loop_p().

Referenced by print_module_icfg().

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

◆ statement_flt()

static bool statement_flt ( statement  s)
static

STATEMENT.

process the not call statement to print out filtered proper effects

Definition at line 140 of file icfg_scan.c.

141 {
142  text t;
143 
144  pips_debug (5,"going down\n");
145 
146  /* process the not call statement to print out filtered proper effects */
148  {
149  entity e_caller = get_current_module_entity();
150  t = (*filter_decoration_stmt)(e_caller, s);
151  }
152  else
153  t = make_text (NIL);
154 
155  store_statement_icfg(s, t);
156  return true;
157 }

References filter_decoration_stmt, get_current_module_entity(), make_text(), NIL, and pips_debug.

Referenced by print_module_icfg().

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

◆ statement_rwt()

static void statement_rwt ( statement  s)
static

Definition at line 159 of file icfg_scan.c.

160 {
161  pips_debug (5,"going up\n");
162  ifdebug(9) print_text(stderr,(text) load_statement_icfg (s));
163  return;
164 }
void print_text(FILE *fd, text t)
Definition: print.c:195

References ifdebug, pips_debug, and print_text().

Referenced by print_module_icfg().

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

◆ test_flt()

static bool test_flt ( test  t)
static

Definition at line 482 of file icfg_scan.c.

483 {
484  bool is_elsif_p = false;
485 
486  pips_debug (3, ">>>Test_flt begins for test=%p\n", t);
487 
488  is_elsif_p = is_elsif_test_p(t);
489  int offset = (is_elsif_p ? 0 : icfg_indent);
490 
491  if (print_ifs) {
493  pips_debug( 4, "is_elsif_p = %d\n", is_elsif_p);
494  pips_debug( 4, "current_margin increased: %d -> %d\n",
496  );
497  }
498  pips_debug (3, ">>>Test_flt ends for test=%p\n", t);
499 
500  return true;
501 }
static Value offset
Definition: translation.c:283
static bool is_elsif_test_p(test t)
TEST functions to deal with the indentation of ELSIFs.
Definition: icfg_scan.c:422

References current_margin, icfg_indent, is_elsif_test_p(), offset, pips_debug, and print_ifs.

Referenced by print_module_icfg().

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

◆ test_rwt()

static void test_rwt ( test  l)
static

Print the IF.

If this is the IF of an ELIF, don't print it.

print things in the if expression

print then statements

Print the THEN

print else/elif statements

Print the ELSE / ELIF

Print the ENDIF.

If this is the ENDIF of an ELIF, don't print it

store it to the statement mapping

Definition at line 503 of file icfg_scan.c.

504 {
505  text inside_then = text_undefined;
506  text inside_else = text_undefined;
507  text inside_if = text_undefined;
508  text t = make_text (NIL);
509  bool something_to_print;
510 
511  bool is_elsif_p = false;
512  bool has_elsif_p = false;
513  int offset;
514  int else_margin = current_margin;
515 
516  pips_debug (3, ">>>Test_rwt begins for test=%p\n", l);
517 
518  is_elsif_p = is_elsif_test_p(l);
519  has_elsif_p = has_elsif_test_p(l);
520  offset = (is_elsif_p ? 0 : icfg_indent);
521 
522  inside_if = copy_text((text) load_statement_icfg (current_stmt_head ()));
523  inside_then = copy_text((text) load_statement_icfg (test_true (l)));
524  inside_else = copy_text((text) load_statement_icfg (test_false (l)));
525 
526  something_to_print = (some_text_p(inside_else) ||
527  some_text_p(inside_then) ||
528  some_text_p(inside_if));
529 
530  if (print_ifs) {
532  pips_debug( 4, "is_elsif_p = %d\n", is_elsif_p);
533  pips_debug( 4, "current_margin decreased: %d -> %d\n",
535  );
536  }
537 
538  /* Print the IF.
539 
540  If this is the IF of an ELIF, don't print it.
541  */
542  if (something_to_print && print_ifs && !is_elsif_p)
544 
545  /* print things in the if expression*/
546  if (some_text_p(inside_if))
547  MERGE_TEXTS (t, inside_if);
548 
549  /* print then statements */
550  if (some_text_p(inside_then)) {
551  /* Print the THEN */
552  if (something_to_print && print_ifs && strlen(st_THEN)>0) {
554  }
555  MERGE_TEXTS (t, inside_then);
556  }
557 
558  /* print else/elif statements */
559  if (some_text_p(inside_else)){
560  /* Print the ELSE / ELIF */
561  if (something_to_print && print_ifs) {
562 
563  // Margin correction
564  else_margin -= (is_elsif_p ? icfg_indent : 0);
565  else_margin -= (has_elsif_p && !is_elsif_p ? icfg_indent : 0);
566 
567  //else_margin += (has_elsif_p ? icfg_indent : 0);
568  if (has_elsif_p)
569  append_marged_text(t, else_margin, st_ELIF, "");
570  else {
571  append_marged_text(t, else_margin, st_ELSE, "");
572  }
573  }
574  MERGE_TEXTS (t, inside_else);
575  }
576 
577  /* Print the ENDIF.
578 
579  If this is the ENDIF of an ELIF, don't print it
580  */
581  if (something_to_print && print_ifs && !is_elsif_p) {
583  }
584 
585  /* store it to the statement mapping */
586  update_statement_icfg (current_stmt_head(), t);
587 
588  pips_debug (3, ">>>Test_rwt ends for test=%p\n", l);
589 
590  return;
591 }
text copy_text(text p)
TEXT.
Definition: text.c:71
#define st_THEN
Definition: icfg_scan.c:65
#define st_ELSE
Definition: icfg_scan.c:67
#define st_ELIF
Definition: icfg_scan.c:66
#define st_IF
Definition: icfg_scan.c:64
#define st_ENDIF
Definition: icfg_scan.c:68
static bool has_elsif_test_p(test t)
This function tests if the ELSE clause of t is an ELIF.
Definition: icfg_scan.c:464
#define test_true(x)
Definition: ri.h:2835

References append_marged_text(), copy_text(), current_margin, current_stmt_head, has_elsif_test_p(), icfg_indent, is_elsif_test_p(), make_text(), MERGE_TEXTS, NIL, offset, pips_debug, print_ifs, some_text_p, st_ELIF, st_ELSE, st_ENDIF, st_IF, st_THEN, test_false, test_true, and text_undefined.

Referenced by print_module_icfg().

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

◆ while_rwt()

static void while_rwt ( whileloop  w)
static

Definition at line 295 of file icfg_scan.c.

296 {
298 
299  if(evaluation_before_p(e))
301  else
303 }
#define st_REPEAT
Definition: icfg_scan.c:61
#define st_DOWHILE
Definition: icfg_scan.c:59
#define st_UNTIL
Definition: icfg_scan.c:62
#define st_ENDDOWHILE
Definition: icfg_scan.c:60
#define whileloop_evaluation(x)
Definition: ri.h:3166
#define whileloop_body(x)
Definition: ri.h:3162
#define evaluation_before_p(x)
Definition: ri.h:1159

References anyloop_rwt(), evaluation_before_p, st_DOWHILE, st_ENDDOWHILE, st_REPEAT, st_UNTIL, whileloop_body, and whileloop_evaluation.

Referenced by print_module_icfg().

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

Variable Documentation

◆ current_margin

◆ current_vertex

vertex current_vertex = NULL
static

to make graph daVinci

Definition at line 108 of file icfg_scan.c.

Referenced by call_flt(), and print_module_icfg().

◆ do_reset_current_module_entity_on_decoration

bool do_reset_current_module_entity_on_decoration = false
static

Definition at line 95 of file icfg_scan.c.

Referenced by call_flt(), and internal_print_icfg().

◆ filter_decoration_call

text(* filter_decoration_call) (entity, statement, call) ( entity  ,
statement  ,
call   
) = NULL
static

Definition at line 102 of file icfg_scan.c.

Referenced by call_flt(), internal_print_icfg(), and print_module_icfg().

◆ filter_decoration_stmt

text(* filter_decoration_stmt) (entity, statement) ( entity  ,
statement   
) = NULL
static

Definition at line 103 of file icfg_scan.c.

Referenced by internal_print_icfg(), and statement_flt().

◆ icfg_indent

◆ module_decoration

text(* module_decoration) (const string) ( const  string) = NULL
static

Definition at line 99 of file icfg_scan.c.

Referenced by call_flt(), and internal_print_icfg().

◆ precise_decoration

text(* precise_decoration) (entity, entity, statement, call) ( entity  ,
entity  ,
statement  ,
call   
) = NULL
static

Definition at line 100 of file icfg_scan.c.

Referenced by call_flt(), and internal_print_icfg().

◆ prettyprint_C_icfg_p

bool prettyprint_C_icfg_p = false
static

Definition at line 97 of file icfg_scan.c.

Referenced by internal_print_icfg().

◆ prettyprint_fortran_icfg_p

bool prettyprint_fortran_icfg_p = true
static

Definition at line 96 of file icfg_scan.c.

Referenced by anyloop_rwt(), and internal_print_icfg().

◆ print_ifs

bool print_ifs = false
static

Definition at line 94 of file icfg_scan.c.

Referenced by print_module_icfg(), test_flt(), and test_rwt().

◆ print_loops

bool print_loops = false
static

We store the text for each statement in a mapping during a code traversal in order to print it afterwards.

static drivers

Definition at line 93 of file icfg_scan.c.

Referenced by anyloop_rwt(), instruction_flt(), instruction_rwt(), loop_flt(), print_module_icfg(), range_flt(), and range_rwt().

◆ verlist

list verlist = NIL
static