PIPS
prettyprint.c
Go to the documentation of this file.
1 /*
2 
3  $Id: prettyprint.c 23412 2017-08-09 15:07:09Z irigoin $
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 /* print complementary sections */
28 #include <stdlib.h>
29 #include <stdlib.h>
30 
31 #include "all.h"
32 #include "text-util.h"
33 #include "text.h"
34 #include "prettyprint.h"
35 #include "top-level.h"
36 
37 /* {{{ banner */
38 
39 /*
40  * package comp_regions : Alexis Platonoff, 5 September 1990,
41  * Beatrice Creusillet, April 1994
42  *
43  * --------------
44  * prettyprint.c
45  * --------------
46  *
47  * This file contains the functions specific to the prettyprinting of comp_regions.
48  *
49  */
50 
51 /* }}} */
52 
53 
54 #define REGION_BUFFER_SIZE 2048
55 
56 #define REGION_FORESYS_PREFIX "C$REG"
57 #define PIPS_NORMAL_PREFIX "C"
58 
59 /* {{{ function prototype */
60 
61 static bool in_out_comp_regions_p = false;
62 static bool is_user_view_p = false;
64 
67 static bool print_code_with_comp_regions(const char*, string, string, string);
68 static text get_any_comp_regions_text(const char*, string, string, bool);
69 
70 /* }}} */
71 
73 {
74  is_user_view_p = false;
75  in_out_comp_regions_p = false;
76 
78  DBR_REGIONS,
79  DBR_SUMMARY_REGIONS,
80  false);
81 }
82 
83 
84 /* bool print_source_regions(const char* module_name)
85  * input : the name of the current module
86  * modifies : nothing.
87  * comment : prints the original source code with the corresponding regions.
88  */
90 const char* module_name;
91 {
92  is_user_view_p = true;
93  in_out_comp_regions_p = false;
94 
96  DBR_REGIONS,
97  DBR_SUMMARY_REGIONS,
99 }
100 
101 
102 /* bool print_code_comp_regions(const char* module_name)
103  * input : the name of the current module
104  * modifies : nothing.
105  * comment : prints the source code with the corresponding regions.
106  */
108 const char* module_name;
109 {
110  is_user_view_p = false;
111  in_out_comp_regions_p = false;
112 
114  DBR_COMPSEC,
115  DBR_SUMMARY_COMPSEC,
117 }
118 
119 /* bool print_code_with_comp_regions(const char* module_name, list summary_comp_regions)
120  * input : the name of the current module, the name of the region and
121  * summary region resources and the file suffix
122  * the comp_regions are in the global variable local_regions_map.
123  * modifies : nothing.
124  * comment : prints the source code with the corresponding comp_regions.
125  */
127  string resource_name,
128  string summary_resource_name,
129  string file_suffix)
130 {
131  char *file_name, *file_resource_name;
132 
133  file_name = strdup(concatenate(file_suffix,
135  ("PRETTYPRINT_UNSTRUCTURED_AS_A_GRAPH") ?
136  GRAPH_FILE_EXT : "",
137  NULL));
138  file_resource_name = get_bool_property("PRETTYPRINT_UNSTRUCTURED_AS_A_GRAPH") ?
139  DBR_GRAPH_PRINTED_FILE :
140  (is_user_view_p ? DBR_PARSED_PRINTED_FILE : DBR_PRINTED_FILE);
141 
142  bool success = make_text_resource(module_name, file_resource_name,
143  file_name,
146  summary_resource_name,
147  true));
148 
149  free(file_name);
150  return success ;
151 }
152 
153 /*{{{ get any comp_regions text*/
155  string resource_name,
156  string summary_resource_name,
157  bool give_code_p)
158 {
159  list summary_comp_regions;
160  entity module;
161  statement module_stat, user_stat = statement_undefined;
162  text txt = make_text(NIL);
163 
164  debug_on("COMP_REGIONS_DEBUG_LEVEL");
165 
166  /* load comp_regions corresponding to the current module */
167  /* change later */
168 
172  (resource_name, module_name, true)) );
173 
174  summary_comp_regions =
176  (summary_resource_name,
177  module_name, true));
178 
181 
183  (DBR_CODE, module_name, true));
184 
185  module_stat = get_current_module_statement();
186 
187  /* To set up the hash table to translate value into value names */
189  db_get_memory_resource(DBR_CUMULATED_EFFECTS, module_name, true));
191  db_get_memory_resource(DBR_PROPER_EFFECTS, module_name, true));
193 
194  if(is_user_view_p)
195  {
196  user_stat = (statement)
197  db_get_memory_resource(DBR_PARSED_CODE, module_name, true);
198 
200  nts = build_number_to_statement(nts, module_stat);
201 
202  ifdebug(5)
203  {
205  }
206  }
207 
208  /* prepare the prettyprinting */
209  /* summary comp_regions first */
211  MERGE_TEXTS(txt, text_array_comp_regions(summary_comp_regions));
212 
213  if (give_code_p)
214  /* then code with comp_regions, using text_array_comp_regions */
216  is_user_view_p? user_stat : module_stat));
217 
218  if(is_user_view_p)
219  {
222  }
223 
225 
226  debug_off();
227 
233 
234  return txt;
235 }
236 /*}}}*/
237 /*{{{ text statement array comp_regions*/
238 /* static text text_statement_array_comp_regions(entity module, int margin, statement stat)
239  * output : a text representing the list of array comp_regions associated with the
240  * statement stat.
241  * comment : if the number of array comp_regions is not nul, then empty lines are
242  * added before and after the text of the list of comp_regions.
243  */
244 static text
246  int __attribute__ ((unused)) margin,
247  statement stat)
248 {
249  list l_reg = NIL;
250 
251  if (is_user_view_p) {
252  statement i;
253 
254  i = (statement) hash_get(nts, (char *) statement_number(stat));
255 
256  if (i != (statement) HASH_UNDEFINED_VALUE) {
258  }
259  else
260  l_reg = (list) HASH_UNDEFINED_VALUE;
261  }
262  else
263  l_reg = load_statement_local_comp_regions(stat);
264 
265 
266  /* Necessary because of unreachable statements - In this case, no comp_regions
267  * are stored in the statement_mapping, and their values are thus
268  * HASH_UNDEFINED_VALUE or list_undefined. BC. 25/07/95. */
269  /* GO 31/7/95: I replace it by a different test in text_array_comp_regions */
270 
271  return text_array_comp_regions(l_reg);
272 }
273 
274 /*}}}*/
275 /*{{{ text array comp_regions*/
276 
277 /* static text text_array_comp_regions(list l_reg)
278  * input : a list of comp_regions
279  * output : a text representing this list of comp_regions.
280  * comment : if the number of array comp_regions is not nul, and if
281  * PRETTYPRINT_LOOSE is true, then empty lines are
282  * added before and after the text of the list of comp_regions.
283  */
285 list l_reg;
286 {
287  text reg_text = make_text(NIL);
288  /* in case of loose_prettyprint, at least one region to print? */
289  bool loose_p = get_bool_property("PRETTYPRINT_LOOSE");
290  bool one_p = false;
291 
292  /* GO: No redundant test anymore, see text_statement_array_comp_regions */
293  if (l_reg != (list) HASH_UNDEFINED_VALUE && l_reg != list_undefined)
294  {
295 /*
296  MAP(COMP_DESC, reg,
297  {
298  entity ent = effect_entity(reg);
299  if ( get_bool_property("PRETTYPRINT_SCALAR_comp_regions") ||
300  ! entity_scalar_p(ent))
301  {
302  if (loose_p && !one_p )
303  {
304  ADD_SENTENCE_TO_TEXT(reg_text,
305  make_sentence(is_sentence_formatted,
306  strdup("\n")));
307  one_p = true;
308  }
309  MERGE_TEXTS(reg_text, text_comp_region(reg));
310  }
311  },
312  l_reg);
313  */
314 
315  if (loose_p && one_p)
316  ADD_SENTENCE_TO_TEXT(reg_text,
318  strdup("\n")));
319  }
320  return(reg_text);
321 }
322 /*}}}*/
323 /*{{{ text all comp_regions*/
324 
325 /* text text_all_comp_regions(list l_reg)
326  * input : a list of comp_regions
327  * output : a text representing this list (with non-array comp_regions)
328  */
330 list l_reg;
331 {
332  text reg_text = make_text(NIL);
333 
334  MAP(EFFECT, reg,
335  {
336  MERGE_TEXTS(reg_text, text_region(reg));
337  },
338  l_reg);
339  return(reg_text);
340 }
341 /*}}}*/
342 /*{{{ text comp_regions*/
343 /* text text_comp_regions(list l_reg)
344  * input : a list of comp_regions
345  * output : a text representing this list (with non-array comp_regions)
346  */
348 list l_reg;
349 {
350 
351  text reg_text = make_text(NIL);
352  /* change later */
353  return(reg_text);
354 
355  MAP(EFFECT, reg,
356  {
357  entity ent = effect_entity(reg);
358  if (! entity_scalar_p(ent))
359  {
360  MERGE_TEXTS(reg_text, text_comp_region(reg));
361  }
362  },
363  l_reg);
364 
365  return(reg_text);
366 }
367 /*}}}*/
368 /*{{{ text region*/
369 /* text text_region(effect reg)
370  * input : a region
371  * output : a text consisting of several lines of commentaries,
372  * representing the region
373  * modifies : nothing
374  */
376 effect reg;
377 {
378  text t_reg = make_text(NIL);
379  bool foresys = get_bool_property("PRETTYPRINT_FOR_FORESYS");
380  string str_prefix;
381 
382  if (foresys)
383  str_prefix = REGION_FORESYS_PREFIX;
384  else
385  str_prefix = PIPS_NORMAL_PREFIX;
386 
387  if(reg == effect_undefined)
388  {
389  ADD_SENTENCE_TO_TEXT(t_reg,
390  make_pred_commentary_sentence(strdup("<REGION_UNDEFINED>"),
391  str_prefix));
392  user_log("[region_to_string] unexpected effect undefined\n");
393  }
394  else
395  {
396  free_text(t_reg);
397  t_reg = words_predicate_to_commentary(words_effect(reg), str_prefix);
398  }
399 
400  return(t_reg);
401 }
402 #if 0
403 
404 /* list words_comp_region(comp_desc Dad)
405  * input : a region.
406  * output : a list of strings representing the region.
407  * modifies : nothing.
408  * comment : because of 'buffer', this function cannot be called twice before
409  * its output is processed. Also, overflows in relation_to_string()
410  * cannot be prevented. They are checked on return.
411  */
412 list words_comp_region(comp_desc Dad)
413 {
415 
416  int Rank;
417  int i;
418  tag RefType;
419  list pc = NIL;
420 
423 
424  buffer[0] = '\0';
425 
426 
427  sprintf(buffer, "\nReference Template :: \n[ ");
428  for (i=0; i < Rank; i++) {
430  switch(RefType) {
432  sprintf(buffer, "INV");
433  break;
434  case is_rtype_linvariant:
435  sprintf(buffer, "VAR");
436  break;
437  case is_rtype_nonlinear:
438  sprintf(buffer, "NON");
439  break;
440  default:
441  sprintf(buffer, "NUL");
442  break;
443  }
444 
445  if( i < (Rank-1) )
446  sprintf(buffer, ", ");
447  else
448  sprintf(buffer, " ]\n");
449  }
450  sprintf(buffer,"\n");
451 
452  pc = CHAIN_SWORD(pc, buffer);
453 
454  return(pc);
455 }
456 #endif
457 
458 /*}}}*/
459 
460 
461 
462 
463 
464 
465 
466 
467 
void user_log(const char *format,...)
Definition: message.c:234
sentence make_sentence(enum sentence_utype tag, void *val)
Definition: text.c:59
text make_text(list a)
Definition: text.c:107
void free_text(text p)
Definition: text.c:74
struct _newgen_struct_statement_ * statement
Definition: cloning.h:21
#define SEQUENTIAL_COMPSEC_SUFFIX
static text text_array_comp_regions(list)
}}
Definition: prettyprint.c:284
bool print_code_comp_regions(char *module_name) const
bool print_code_comp_regions(const char* module_name) input : the name of the current module modifies...
Definition: prettyprint.c:107
#define REGION_FORESYS_PREFIX
Definition: prettyprint.c:56
bool print_source_comp_regions(char *module_name) const
bool print_source_regions(const char* module_name) input : the name of the current module modifies : ...
Definition: prettyprint.c:89
text text_comp_regions(list l_reg)
}}
Definition: prettyprint.c:347
static text get_any_comp_regions_text(const char *, string, string, bool)
{{ get any comp_regions text
Definition: prettyprint.c:154
#define REGION_BUFFER_SIZE
print complementary sections
Definition: prettyprint.c:54
static bool is_user_view_p
Definition: prettyprint.c:62
static text text_statement_array_comp_regions(entity, int, statement)
static bool print_code_with_comp_regions(const char *, string, string, string)
bool print_code_with_comp_regions(const char* module_name, list summary_comp_regions) input : the nam...
Definition: prettyprint.c:126
static hash_table nts
Definition: prettyprint.c:63
text get_text_comp_regions(const char *module_name)
}}}
Definition: prettyprint.c:72
#define PIPS_NORMAL_PREFIX
Definition: prettyprint.c:57
static bool in_out_comp_regions_p
{{{ function prototype
Definition: prettyprint.c:61
text text_all_comp_regions(list l_reg)
}}
Definition: prettyprint.c:329
text text_comp_region(effect reg)
}}
Definition: prettyprint.c:375
list load_statement_local_comp_regions(statement)
statement_mapping comp_secs_map_to_listmap(statement_mapping)
Definition: dbase.c:60
void free_local_comp_regions_map(void)
tag GetRefTemp(simple_section, _int)
}}
Definition: ss.c:229
void set_local_comp_regions_map(statement_mapping)
list comp_desc_set_to_list(comp_desc_set)
Definition: dbase.c:40
#define comp_desc_section(x)
Definition: compsec.h:181
#define comp_sec_hull(x)
Definition: compsec.h:247
#define simple_section_context(x)
Definition: compsec.h:449
@ is_rtype_nonlinear
Definition: compsec.h:385
@ is_rtype_lininvariant
Definition: compsec.h:387
@ is_rtype_linvariant
Definition: compsec.h:386
#define context_info_rank(x)
Definition: compsec.h:286
#define resource_name(x)
Definition: database.h:108
#define USER_REGION_SUFFIX
text text_region(effect)
void reset_proper_rw_effects(void)
void set_proper_rw_effects(statement_effects)
void set_cumulated_rw_effects(statement_effects)
void reset_cumulated_rw_effects(void)
list words_effect(effect)
entity effect_entity(effect)
cproto-generated files
Definition: effects.c:52
#define effect_undefined
Definition: effects.h:614
#define EFFECT(x)
EFFECT.
Definition: effects.h:608
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
#define list_undefined
Undefined list definition :-)
Definition: newgen_list.h:69
#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
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_get(const hash_table htp, const void *key)
this function retrieves in the hash table pointed to by htp the couple whose key is equal to key.
Definition: hash.c:449
void hash_table_free(hash_table htp)
this function deletes a hash table that is no longer useful.
Definition: hash.c:327
#define debug_on(env)
Definition: misc-local.h:157
#define debug_off()
Definition: misc-local.h:160
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
int tag
TAG.
Definition: newgen_types.h:92
struct cons * list
Definition: newgen_types.h:106
static char * module
Definition: pips.c:74
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)
void print_number_to_statement(hash_table)
Definition: statement.c:209
bool make_text_resource(const char *, const char *, const char *, text)
print.c
Definition: print.c:55
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 entity_scalar_p(entity)
The concrete type of e is a scalar type.
Definition: variable.c:1113
#define statement_number(x)
Definition: ri.h:2452
#define statement_undefined
Definition: ri.h:2419
char * strdup()
void module_to_value_mappings(entity m)
void module_to_value_mappings(entity m): build hash tables between variables and values (old,...
Definition: mappings.c:624
sentence make_pred_commentary_sentence(string str_pred, string comment_prefix)
sentence make_pred_commentary_sentence(string str_pred, string comment_prefix) input : a substring fo...
Definition: prettyprint.c:678
text words_predicate_to_commentary(list w_pred, string comment_prefix)
text words_predicate_to_commentary(list w_pred, string comment_prefix) input : a list of strings,...
Definition: prettyprint.c:653
static bool __attribute__((unused))
Definition: prettyprint.c:435
#define ifdebug(n)
Definition: sg.c:47
static string buffer
Definition: string.c:113
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)
@ is_sentence_formatted
Definition: text.h:57
static string file_name