PIPS
comp_prettyprint.c
Go to the documentation of this file.
1 /*
2 
3  $Id: comp_prettyprint.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 
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <string.h>
31 
32 #include "linear.h"
33 
34 #include "genC.h"
35 #include "text.h"
36 #include "ri.h"
37 #include "effects.h"
38 #include "complexity_ri.h"
39 #include "database.h" /* useful */
40 
41 #include "resources.h" /* useful */
42 
43 #include "ri-util.h"
44 #include "effects-util.h"
45 
46 #include "pipsdbm.h" /* useful */
47 
48 #include "matrice.h" /* useful */
49 #include "properties.h"
50 #include "misc.h"
51 
52 #include "callgraph.h"
53 #include "prettyprint.h"
54 
55 #include "text-util.h"
56 #include "top-level.h" // GRAPH_FILE_EXT
57 #include "complexity.h"
58 
59 
60 static bool is_user_view; /* print_code_complexities or print_source_complexities */
62 
65  _UNUSED_ int margin,
66  statement stat)
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 }
137 
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 }
160 
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 }
171 
172 static bool print_code_or_source_comp(const string module_name)
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 }
227 
229 {
230  is_user_view = false;
232 }
233 
234 bool print_code_as_a_graph_complexities(const string mod_name)
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 }
244 
246 {
247  is_user_view = true;
249 }
250 
251 /*
252  * Print callgraph with complexities
253  */
255 {
256  bool success = false;
258  return success;
259 }
260 
261 /********************************************************************** ICFG */
262 
263 #include "pips-libs.h"
264 #ifdef HAVE_PIPS_icfg_LIBRARY
265 #include "icfg.h"
266 
267 bool print_icfg_with_complexities(const string module_name)
268 {
269  return generic_print_icfg(module_name, false, false, false,
271 }
272 
274 {
275  return generic_print_icfg(module_name, false, true, false,
277 }
278 
280 {
281  return generic_print_icfg(module_name, true, true, false,
283 }
284 
285 #endif // HAVE_PIPS_icfg_LIBRARY
int get_int_property(const string)
sentence make_sentence(enum sentence_utype tag, void *val)
Definition: text.c:59
text make_text(list a)
Definition: text.c:107
bool print_decorated_call_graph(const string, text(*)(const string))
Definition: print.c:64
struct _newgen_struct_statement_ * statement
Definition: cloning.h:21
bool print_source_complexities(const string module_name)
static bool is_user_view
useful
static bool print_code_or_source_comp(const string module_name)
bool print_code_as_a_graph_complexities(const string mod_name)
bool print_call_graph_with_complexities(const string module_name)
static hash_table nts
print_code_complexities or print_source_complexities
static text get_text_complexities(const string module_name)
bool print_code_complexities(const string module_name)
comp_prettyprint.c
static text text_complexity(_UNUSED_ entity module, _UNUSED_ int margin, statement stat)
static text text_summary_complexity(entity module)
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
bool print_icfg_with_loops_complexities(const string)
bool print_icfg_with_complexities(const string)
complexity load_statement_complexity(statement)
void reset_complexity_map(void)
bool print_icfg_with_control_complexities(const string)
void set_complexity_map(statement_mapping)
#define complexity_undefined
Definition: complexity_ri.h:66
struct _newgen_struct_complexity_ * complexity
Definition: complexity_ri.h:30
#define resource_name(x)
Definition: database.h:108
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
void free(void *)
bool success
Definition: gpips-local.h:59
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
bool statement_call_p(statement)
Definition: statement.c:364
statement apply_number_to_statement(hash_table, _int)
Definition: statement.c:1495
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
bool generic_print_icfg(const string, bool, bool, bool, text(*)(const string))
Definition: icfg_scan.c:713
static statement mod_stat
We want to keep track of the current statement inside the recurse.
Definition: impact_check.c:41
#define _UNUSED_
Definition: misc-local.h:232
#define asprintf
Definition: misc-local.h:225
#define pips_internal_error
Definition: misc-local.h:149
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
#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 hash_table_undefined
Value of an undefined hash_table.
Definition: newgen_hash.h:49
#define string_undefined
Definition: newgen_types.h:40
static char * module
Definition: pips.c:74
string get_comment_sentinel()
Start a single line comment.
Definition: misc.c:154
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
void set_bool_property(const char *, bool)
#define ORDERING_NUMBER(o)
#define ORDERING_STATEMENT(o)
entity module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
Definition: entity.c:1479
const char * module_local_name(entity e)
Returns the module local user name.
Definition: entity.c:582
bool fortran_module_p(entity m)
Test if a module is in Fortran.
Definition: entity.c:2799
#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
#define statement_undefined
Definition: ri.h:2419
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
char * strdup()
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
#define CHAIN_SWORD(l, s)
#define MERGE_TEXTS(r, t)
#define ADD_SENTENCE_TO_TEXT(t, p)
string words_to_string(cons *lw)
Definition: print.c:211
@ is_sentence_formatted
Definition: text.h:57