PIPS
comp_prettyprint.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "linear.h"
#include "genC.h"
#include "text.h"
#include "ri.h"
#include "effects.h"
#include "complexity_ri.h"
#include "database.h"
#include "resources.h"
#include "ri-util.h"
#include "effects-util.h"
#include "pipsdbm.h"
#include "matrice.h"
#include "properties.h"
#include "misc.h"
#include "callgraph.h"
#include "prettyprint.h"
#include "text-util.h"
#include "top-level.h"
#include "complexity.h"
#include "pips-libs.h"
+ Include dependency graph for comp_prettyprint.c:

Go to the source code of this file.

Functions

static text text_complexity (_UNUSED_ entity module, _UNUSED_ int margin, statement stat)
 
static text text_summary_complexity (entity module)
 
static text get_text_complexities (const string module_name)
 
static bool print_code_or_source_comp (const string module_name)
 
bool print_code_complexities (const string module_name)
 comp_prettyprint.c More...
 
bool print_code_as_a_graph_complexities (const string mod_name)
 
bool print_source_complexities (const string module_name)
 
bool print_call_graph_with_complexities (const string module_name)
 

Variables

static bool is_user_view
 useful More...
 
static hash_table nts = hash_table_undefined
 print_code_complexities or print_source_complexities More...
 

Function Documentation

◆ get_text_complexities()

static text get_text_complexities ( const string  module_name)
static

FI: different kind of complexities should later be made available. Instead of the module intrinsic complexity, it would be interesting to have its contextual complexity. The same is true for the icfg

Definition at line 161 of file comp_prettyprint.c.

162 {
163  /* FI: different kind of complexities should later be made
164  available. Instead of the module intrinsic complexity, it would
165  be interesting to have its contextual complexity. The same is
166  true for the icfg
167  */
170 }
static text text_summary_complexity(entity module)
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
static char * module
Definition: pips.c:74
entity module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
Definition: entity.c:1479

References module, module_name(), module_name_to_entity(), and text_summary_complexity().

Referenced by print_call_graph_with_complexities().

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

◆ print_call_graph_with_complexities()

bool print_call_graph_with_complexities ( const string  module_name)
Parameters
module_nameodule_name

Definition at line 254 of file comp_prettyprint.c.

255 {
256  bool success = false;
258  return success;
259 }
bool print_decorated_call_graph(const string, text(*)(const string))
Definition: print.c:64
static text get_text_complexities(const string module_name)
bool success
Definition: gpips-local.h:59

References get_text_complexities(), module_name(), and print_decorated_call_graph().

+ Here is the call graph for this function:

◆ print_code_as_a_graph_complexities()

bool print_code_as_a_graph_complexities ( const string  mod_name)
Parameters
mod_nameod_name

Definition at line 234 of file comp_prettyprint.c.

235 {
236  bool success;
237 
238  set_bool_property("PRETTYPRINT_UNSTRUCTURED_AS_A_GRAPH", true);
239  success = print_code_complexities(mod_name);
240  set_bool_property("PRETTYPRINT_UNSTRUCTURED_AS_A_GRAPH", false);
241 
242  return success;
243 }
bool print_code_complexities(const string module_name)
comp_prettyprint.c
void set_bool_property(const char *, bool)

References print_code_complexities(), and set_bool_property().

+ Here is the call graph for this function:

◆ print_code_complexities()

bool print_code_complexities ( const string  module_name)

comp_prettyprint.c

Parameters
module_nameodule_name

Definition at line 228 of file comp_prettyprint.c.

229 {
230  is_user_view = false;
232 }
static bool is_user_view
useful
static bool print_code_or_source_comp(const string module_name)

References is_user_view, module_name(), and print_code_or_source_comp().

Referenced by print_code_as_a_graph_complexities().

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

◆ print_code_or_source_comp()

static bool print_code_or_source_comp ( const string  module_name)
static

Definition at line 172 of file comp_prettyprint.c.

173 {
174  bool success = true;
175  entity mod;
177  char *file_ext = strdup
178  (concatenate(
179  is_user_view? ".ucomp" : ".comp",
180  get_bool_property("PRETTYPRINT_UNSTRUCTURED_AS_A_GRAPH") ?
181  GRAPH_FILE_EXT : "",
182  NULL));
183  char * resource_name =
184  get_bool_property("PRETTYPRINT_UNSTRUCTURED_AS_A_GRAPH") ?
185  DBR_GRAPH_PRINTED_FILE
186  : is_user_view ? DBR_PARSED_PRINTED_FILE : DBR_PRINTED_FILE;
187  text txt = make_text(NIL);
188 
190  (statement) db_get_memory_resource(DBR_CODE, module_name, true) );
194 
195  if(is_user_view) {
196  user_stat = (statement)
197  db_get_memory_resource(DBR_PARSED_CODE, module_name, true);
198 
201  }
202 
203 
205  db_get_memory_resource(DBR_COMPLEXITIES, module_name, true));
206 
208 
210  MERGE_TEXTS(txt, text_module(mod, is_user_view ? user_stat : mod_stat));
211 
214  (module_name, resource_name, file_ext, txt);
215  free(file_ext);
216 
217  if(is_user_view) {
220  }
224 
225  return success;
226 }
text make_text(list a)
Definition: text.c:107
struct _newgen_struct_statement_ * statement
Definition: cloning.h:21
static hash_table nts
print_code_complexities or print_source_complexities
static text text_complexity(_UNUSED_ entity module, _UNUSED_ int margin, statement stat)
void reset_complexity_map(void)
void set_complexity_map(statement_mapping)
#define resource_name(x)
Definition: database.h:108
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
void free(void *)
void reset_current_module_entity(void)
Reset the current module entity.
Definition: static.c:97
void reset_current_module_statement(void)
Reset the current module statement.
Definition: static.c:221
statement set_current_module_statement(statement)
Set the current module statement.
Definition: static.c:165
statement get_current_module_statement(void)
Get the current module statement.
Definition: static.c:208
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 NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
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
hash_table allocate_number_to_statement(void)
Definition: statement.c:1540
hash_table build_number_to_statement(hash_table, statement)
Definition: statement.c:1516
void hash_table_free(hash_table htp)
this function deletes a hash table that is no longer useful.
Definition: hash.c:327
static statement mod_stat
We want to keep track of the current statement inside the recurse.
Definition: impact_check.c:41
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
#define hash_table_undefined
Value of an undefined hash_table.
Definition: newgen_hash.h:49
void close_prettyprint()
because some prettyprint functions may be used for debug, so the last hook set by somebody may have s...
Definition: misc.c:242
void init_prettyprint(text(*hook)(entity, int, statement))
checks that the prettyprint hook was actually reset...
Definition: misc.c:231
text text_module(entity, statement)
bool make_text_resource_and_free(const char *, const char *, const char *, text)
Definition: print.c:82
#define statement_undefined
Definition: ri.h:2419
char * strdup()
#define MERGE_TEXTS(r, t)

References allocate_number_to_statement(), build_number_to_statement(), close_prettyprint(), concatenate(), db_get_memory_resource(), free(), get_bool_property(), get_current_module_entity(), get_current_module_statement(), hash_table_free(), hash_table_undefined, init_prettyprint(), is_user_view, make_text(), make_text_resource_and_free(), MERGE_TEXTS, mod_stat, module_name(), module_name_to_entity(), NIL, nts, reset_complexity_map(), reset_current_module_entity(), reset_current_module_statement(), resource_name, set_complexity_map(), set_current_module_entity(), set_current_module_statement(), statement_undefined, strdup(), text_complexity(), text_module(), and text_summary_complexity().

Referenced by print_code_complexities(), and print_source_complexities().

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

◆ print_source_complexities()

bool print_source_complexities ( const string  module_name)
Parameters
module_nameodule_name

Definition at line 245 of file comp_prettyprint.c.

246 {
247  is_user_view = true;
249 }

References is_user_view, module_name(), and print_code_or_source_comp().

+ Here is the call graph for this function:

◆ text_complexity()

static text text_complexity ( _UNUSED_ entity  module,
_UNUSED_ int  margin,
statement  stat 
)
static

Definition at line 63 of file comp_prettyprint.c.

67 {
68  complexity stat_comp = complexity_undefined;
69  int print_stats_level = get_int_property("COMPLEXITY_PRINT_STATISTICS");
70  bool print_stats_p = ((print_stats_level == 2) ||
71  ((print_stats_level == 1) &&
72  !statement_call_p(stat)));
73  cons *pc ;
74  char *r ;
75  int nblanks ;
77  char *s;
78  text t = make_text(NIL);
79 
80  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
81  fprintf(stderr, "statement %s, ordering (%td %td)\n",
85  }
86 
87  if(is_user_view) {
89 
90  if(!statement_undefined_p(i)) {
91  stat_comp = load_statement_complexity(i);
92  }
93  else
94  stat_comp = (complexity) HASH_UNDEFINED_VALUE;
95  }
96  else
97  stat_comp = load_statement_complexity(stat);
98 
99  if(stat_comp != (complexity) HASH_UNDEFINED_VALUE) {
100  string it = string_undefined;
101 
102  complexity_check_and_warn("text_complexity", stat_comp);
103  pc = CHAIN_SWORD(NIL, complexity_sprint(stat_comp, print_stats_p,
105  r = words_to_string(pc);
106  nblanks = 65-strlen(r);
107 
108  if (nblanks<1)
109  nblanks = 1;
110 
111  //Becher Molka : Replacing the control structure 'if' by selective structure 'switch case' + Updating of instruction's tags.
112  switch (instruction_tag(ins))
113  {
114  case is_instruction_sequence: it = "(SEQ)"; break;
115  case is_instruction_test: it = "(TEST)"; break;
116  case is_instruction_loop: it = "(DO)"; break;
117  case is_instruction_whileloop: it = "(WHILE)"; break;
118  case is_instruction_goto: it = "(GOTO)"; break;
119  case is_instruction_call: it = "(STMT)"; break;
120  case is_instruction_unstructured: it = "(UNSTR)"; break;
121  case is_instruction_forloop: it = "(FOR)"; break;
122  case is_instruction_expression: it = "(EXPR)"; break;
123  case is_instruction_multitest: it = "(MTEST)"; break;
124  default:
125  pips_internal_error("Never occur!");
126  break;
127  }
128 
129  asprintf(&s, "%s %*s%s %s\n",
130  get_comment_sentinel(), nblanks, "", r, it);
131 
133  }
134 
135  return t;
136 }
int get_int_property(const string)
sentence make_sentence(enum sentence_utype tag, void *val)
Definition: text.c:59
void complexity_check_and_warn(char *s, complexity comp) const
Definition: comp_util.c:108
char * complexity_sprint(complexity comp, bool print_stats_p, bool print_local_names_p)
Definition: comp_util.c:175
#define PRINT_LOCAL_NAMES
complexity load_statement_complexity(statement)
#define complexity_undefined
Definition: complexity_ri.h:66
struct _newgen_struct_complexity_ * complexity
Definition: complexity_ri.h:30
bool statement_call_p(statement)
Definition: statement.c:364
statement apply_number_to_statement(hash_table, _int)
Definition: statement.c:1495
#define asprintf
Definition: misc-local.h:225
#define pips_internal_error
Definition: misc-local.h:149
#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
#define string_undefined
Definition: newgen_types.h:40
string get_comment_sentinel()
Start a single line comment.
Definition: misc.c:154
#define ORDERING_NUMBER(o)
#define ORDERING_STATEMENT(o)
const char * module_local_name(entity e)
Returns the module local user name.
Definition: entity.c:582
#define statement_ordering(x)
Definition: ri.h:2454
#define statement_label(x)
Definition: ri.h:2450
@ is_instruction_goto
Definition: ri.h:1473
@ is_instruction_unstructured
Definition: ri.h:1475
@ is_instruction_whileloop
Definition: ri.h:1472
@ is_instruction_expression
Definition: ri.h:1478
@ is_instruction_test
Definition: ri.h:1470
@ is_instruction_multitest
Definition: ri.h:1476
@ is_instruction_call
Definition: ri.h:1474
@ is_instruction_sequence
Definition: ri.h:1469
@ is_instruction_forloop
Definition: ri.h:1477
@ is_instruction_loop
Definition: ri.h:1471
#define instruction_tag(x)
Definition: ri.h:1511
#define statement_instruction(x)
Definition: ri.h:2458
#define statement_undefined_p(x)
Definition: ri.h:2420
#define statement_number(x)
Definition: ri.h:2452
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
#define CHAIN_SWORD(l, s)
#define ADD_SENTENCE_TO_TEXT(t, p)
string words_to_string(cons *lw)
Definition: print.c:211
@ is_sentence_formatted
Definition: text.h:57

References ADD_SENTENCE_TO_TEXT, apply_number_to_statement(), asprintf, CHAIN_SWORD, complexity_check_and_warn(), complexity_sprint(), complexity_undefined, fprintf(), get_bool_property(), get_comment_sentinel(), get_int_property(), HASH_UNDEFINED_VALUE, instruction_tag, is_instruction_call, is_instruction_expression, is_instruction_forloop, is_instruction_goto, is_instruction_loop, is_instruction_multitest, is_instruction_sequence, is_instruction_test, is_instruction_unstructured, is_instruction_whileloop, is_sentence_formatted, is_user_view, load_statement_complexity(), make_sentence(), make_text(), module_local_name(), NIL, nts, ORDERING_NUMBER, ORDERING_STATEMENT, pips_internal_error, PRINT_LOCAL_NAMES, statement_call_p(), statement_instruction, statement_label, statement_number, statement_ordering, statement_undefined_p, string_undefined, and words_to_string().

Referenced by print_code_or_source_comp().

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

◆ text_summary_complexity()

static text text_summary_complexity ( entity  module)
static

Definition at line 138 of file comp_prettyprint.c.

139 {
140  const char* module_name = module_local_name(module);
141  complexity stat_comp = (complexity)
142  db_get_memory_resource(DBR_SUMMARY_COMPLEXITY, module_name, true);
143  cons *pc = CHAIN_SWORD(NIL, complexity_sprint(stat_comp, false,
145  char *r = words_to_string(pc);
146  int nblanks = 65-strlen(r);
147  char *s;
148  text t = make_text(NIL);
149 
150  if (nblanks < 1)
151  nblanks = 1;
152  asprintf(&s, "%s %*s%s (SUMMARY)\n",
153  fortran_module_p(module)? "C" : "//",
154  nblanks, "", r);
156  s));
157 
158  return t;
159 }
bool fortran_module_p(entity m)
Test if a module is in Fortran.
Definition: entity.c:2799

References ADD_SENTENCE_TO_TEXT, asprintf, CHAIN_SWORD, complexity_sprint(), db_get_memory_resource(), fortran_module_p(), is_sentence_formatted, make_sentence(), make_text(), module, module_local_name(), module_name(), NIL, PRINT_LOCAL_NAMES, and words_to_string().

Referenced by get_text_complexities(), and print_code_or_source_comp().

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

Variable Documentation

◆ is_user_view

bool is_user_view
static

useful

useful
useful useful

Definition at line 60 of file comp_prettyprint.c.

Referenced by print_code_complexities(), print_code_or_source_comp(), print_source_complexities(), and text_complexity().

◆ nts

print_code_complexities or print_source_complexities

Definition at line 61 of file comp_prettyprint.c.

Referenced by print_code_or_source_comp(), and text_complexity().