PIPS
prettyprint.c
Go to the documentation of this file.
1 /*
2 
3  $Id: 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 /* package simple effects : Be'atrice Creusillet 5/97
28  *
29  * File: prettyprint.c
30  * ~~~~~~~~~~~~~~~~~~~
31  *
32  * This File contains the intanciation of the generic functions
33  * necessary
34  * for the computation of all types of simple effects.
35  *
36  */
37 
38 #include <stdio.h>
39 #include <string.h>
40 
41 #include "genC.h"
42 
43 #include "properties.h"
44 #include "linear.h"
45 #include "ri.h"
46 #include "effects.h"
47 
48 #include "misc.h"
49 #include "ri-util.h"
50 #include "prettyprint.h" // for get_comment_continuation() & many more
51 #include "effects-util.h"
52 #include "text.h"
53 
54 #include "text-util.h"
55 #include "database.h"
56 #include "resources.h"
57 #include "callgraph.h"
58 
59 #include "effects-generic.h"
60 #include "effects-simple.h"
61 
62 static string continuation = string_undefined;
63 #define CONTINUATION (string_undefined_p(continuation)? \
64  strdup(concatenate(get_comment_continuation(), " ", NULL)) \
65  : continuation)
66 
67 /* new definitions for action interpretation
68  */
69 #define ACTION_read "read "
70 #define ACTION_write "written"
71 #define ACTION_in "imported"
72 #define ACTION_out "exported"
73 #define ACTION_live_in "alive (in)"
74 #define ACTION_live_out "alive (out)"
75 /* Can be used both for environment and type declaration */
76 #define ACTION_declared "declared"
77 #define ACTION_referenced "referenced"
78 
79 
80 
81 /* Try to factorize code from Alexis Platonoff :
82 
83  Append an_effect_string to an_effect_text and position the
84  exist_flag at TRUE.
85 
86  The procedure is intended to be called for the 4 different types of
87  effects. RK
88 
89  Now, for 12 types of effects, but I do not see the exist_flag
90  positionning (FI)
91 */
92 static void
93 update_an_effect_type(
94  text an_effect_text,
95  string current_line_in_construction,
96  string an_effect_string)
97 {
98  add_to_current_line(current_line_in_construction, " ",
99  CONTINUATION, an_effect_text);
100  add_to_current_line(current_line_in_construction, an_effect_string,
101  CONTINUATION, an_effect_text);
102 }
103 
104 
105 /* text simple_effects_to_text(list sefs_list)
106  *
107  * Updated version of store_text_line for the generic implementation of
108  * effects computation. BC, June 17th, 1997.
109  *
110  * New version of store_text_line() by AP, Nov 4th, 1995.
111  *
112  * This function builds the prettyprint in text format of the list of
113  * effects given in arguments.
114  *
115  * These effects are split into four categories : R-MAY, W-MAY, R-EXACT and
116  * W-EXACT. Then, we first build four texts, each containing the
117  * prettyprint of one kind. Finally, we merge all the texts into a single
118  * one.
119  *
120  * For a given kind of effect, we use a static buffer (of size the length
121  * of a line of prettyprint) and a boolean, and we build a text in which
122  * each sentence corresponds to a line of prettyprint. If the
123  * concatenation of a new effect in the buffer is impossible (overfull),
124  * we save the buffer as a new sentence in the text and begin a new line.
125  * Initially, the bool is set to false, and is turned to true as soon
126  * as we found one effect of this kind in the list. Finally, we merge the
127  * text into the global one only if the bool is TRUE.
128  *
129  * Moreover, we sort the effects list in lexicographic order on the
130  * references. We use gen_sort_list().
131  *
132  * Modification: AP, Nov 10th, 1995. I have replaced the call to
133  * effect_to_string() by adirect transformation of an effect to its
134  * prettyprint format. This is to avoid the problem occuring when the
135  * buffer used in effect_to_string() is too small.
136  */
137 
138 #define is_may " <may be "
139 #define is_exact " < is "
140 #define exact_end ">:"
141 #define may_end exact_end
142 
143 static text
144 simple_effects_to_text(
145  list /* of effect */ sefs_list,
146  string ifread,
147  string ifwrite,
148  string ifdeclared,
149  string ifreferenced)
150 {
151  /* FI: althoug the internal representation does distinguish between
152  variable declarations and type declarations, this print-out
153  ignores the difference. */
154  text sefs_text = make_text(NIL), rt, wt, Rt, Wt, dt, Dt, ut, Ut;
155  char r[MAX_LINE_LENGTH], w[MAX_LINE_LENGTH],
158  bool rb = false, Rb = false,
159  wb = false, Wb = false,
160  db = false, Db = false,
161  ub = false, Ub = false;
162  list ce = list_undefined;
163 
164  if (sefs_list == (list) HASH_UNDEFINED_VALUE ||
165  sefs_list == list_undefined)
166  {
167  pips_debug(9, "Effects list empty\n");
168  return sefs_text;
169  }
170 
171  /* These eight buffers are used to build the current line of prettyprint
172  for a given type of effect. */
173 
174  r[0] = '\0'; strcat(r, concatenate(get_comment_sentinel(), is_may, ifread, may_end, NULL));
175  R[0] = '\0'; strcat(R, concatenate(get_comment_sentinel(), is_exact, ifread, exact_end, NULL));
176  w[0] = '\0'; strcat(w, concatenate(get_comment_sentinel(), is_may, ifwrite, may_end, NULL));
177  W[0] = '\0'; strcat(W, concatenate(get_comment_sentinel(), is_exact, ifwrite, exact_end, NULL));
178  d[0] = '\0'; strcat(d, concatenate(get_comment_sentinel(), is_may, ifdeclared, may_end, NULL));
179  D[0] = '\0'; strcat(D, concatenate(get_comment_sentinel(), is_exact, ifdeclared, exact_end, NULL));
180  u[0] = '\0'; strcat(u, concatenate(get_comment_sentinel(), is_may, ifreferenced, may_end, NULL));
181  U[0] = '\0'; strcat(U, concatenate(get_comment_sentinel(), is_exact, ifreferenced, exact_end, NULL));
182 
183  /* These eight "texts" are used to build all the text of prettyprint
184  for a given type of effect. Each sentence contains one line. */
185  rt = make_text(NIL);
186  Rt = make_text(NIL);
187  wt = make_text(NIL);
188  Wt = make_text(NIL);
189  dt = make_text(NIL);
190  Dt = make_text(NIL);
191  ut = make_text(NIL);
192  Ut = make_text(NIL);
193 
194  /* We sort the list of effects in lexicographic order */
195  if (get_bool_property("PRETTYPRINT_WITH_COMMON_NAMES"))
197  else
199 
200  /* Walk through all the effects */
201  for(ce = sefs_list; !ENDP(ce); POP(ce))
202  {
203  effect eff = EFFECT(CAR(ce));
204  if(store_effect_p(eff)
205  || !get_bool_property("PRETTYPRINT_MEMORY_EFFECTS_ONLY")) {
207  action ac = effect_action(eff);
209  list /* of string */ ls = effect_words_reference(ref);
210  string t;
211 
212  /* We build the string containing the effect's reference */
213  /* Be careful about attachments since the words references are
214  * heavily moved around in the following. words_to_string is now
215  * attachment safe. RK
216  */
217  t = words_to_string(ls);
219 
220  /* We now proceed to the addition of this effect to the current line
221  of prettyprint. First, we select the type of effect : R-MAY, W-MAY,
222  R-EXACT, W-EXACT. Then, if this addition results in a line too long,
223  we save the current line, and begin a new one. */
224  if (action_read_p(ac) && approximation_may_p(ap))
225  if(store_effect_p(eff))
226  update_an_effect_type(rt, r, t), rb = true;
227  else
228  update_an_effect_type(ut, u, t), ub = true;
229  else if (!action_read_p(ac) && approximation_may_p(ap))
230  if(store_effect_p(eff))
231  update_an_effect_type(wt, w, t), wb = true;
232  else
233  update_an_effect_type(dt, d, t), db = true;
234  else if (action_read_p(ac) && !approximation_may_p(ap))
235  if(store_effect_p(eff))
236  update_an_effect_type(Rt, R, t), Rb = true;
237  else
238  update_an_effect_type(Ut, U, t), Ub = true;
239  else if (!action_read_p(ac) && !approximation_may_p(ap))
240  if(store_effect_p(eff))
241  update_an_effect_type(Wt, W, t), Wb = true;
242  else
243  update_an_effect_type(Dt, D, t), Db = true;
244  else
245  pips_internal_error("unrecognized effect");
246 
247  free(t);
248  }
249  }
250 
251  close_current_line(r, rt, CONTINUATION);
252  close_current_line(R, Rt, CONTINUATION);
253  close_current_line(w, wt, CONTINUATION);
254  close_current_line(W, Wt, CONTINUATION);
255  close_current_line(d, dt, CONTINUATION);
256  close_current_line(D, Dt, CONTINUATION);
257  close_current_line(u, ut, CONTINUATION);
258  close_current_line(U, Ut, CONTINUATION);
259 
260  if (rb) { MERGE_TEXTS(sefs_text, rt); } else free_text(rt);
261  if (wb) { MERGE_TEXTS(sefs_text, wt); } else free_text(wt);
262  if (ub) { MERGE_TEXTS(sefs_text, ut); } else free_text(ut);
263  if (db) { MERGE_TEXTS(sefs_text, dt); } else free_text(dt);
264  if (Rb) { MERGE_TEXTS(sefs_text, Rt); } else free_text(Rt);
265  if (Wb) { MERGE_TEXTS(sefs_text, Wt); } else free_text(Wt);
266  if (Ub) { MERGE_TEXTS(sefs_text, Ut); } else free_text(Ut);
267  if (Db) { MERGE_TEXTS(sefs_text, Dt); } else free_text(Dt);
268 
269  return sefs_text;
270 }
271 
272 /* external interfaces
273  */
275 { return simple_effects_to_text(l, ACTION_read, ACTION_write, ACTION_declared, ACTION_referenced);}
276 
278 { return simple_effects_to_text(l, ACTION_in, ACTION_out, ACTION_declared, ACTION_referenced);}
279 
281 { return simple_effects_to_text(l, ACTION_live_in, ACTION_write, ACTION_referenced, ACTION_referenced);}
282 
284 { return simple_effects_to_text(l, ACTION_live_out, ACTION_write, ACTION_referenced, ACTION_referenced);}
285 
286 string
288 {
289  list /* of string */ ls = effect_words_reference(effect_any_reference(eff));
290  string result = words_to_string(ls);
292  return result;
293 }
294 
295 /* Assumed that the cell is a preference and not a reference. */
296 list words_effect_generic(effect obj, bool approximation_p)
297 {
298  list pc = NIL;
300  action ac = effect_action(obj);
302 
303  pc = CHAIN_SWORD(pc,"<");
304  pc = gen_nconc(pc, effect_words_reference(r));
305  pc = CHAIN_SWORD(pc,"-");
307  if(approximation_p)
308  pc = CHAIN_SWORD(pc, approximation_may_p(ap) ? "-MAY>" : "-EXACT>" );
309  return (pc);
310 }
311 
313 {
314  return words_effect_generic(obj, true);
315 }
316 
318 {
319  return words_effect_generic(obj, false);
320 }
321 
322 void print_effect(effect e)
323 {
324  if(!effect_undefined_p(e))
325  {
327  fprintf(stderr, "\t");
328  print_words(stderr, words_effect(e));
329  fprintf(stderr, "\n");
330  }
331  else
332  fprintf(stderr,"\t effect undefined\n");
333 }
334 
335 /* FI: could be placed in effect-generic */
336 void print_effects( list pc)
337 {
338  if (pc != NIL) {
339  FOREACH(EFFECT, e, pc) {
341  if(descriptor_none_p(d))
342  print_effect(e);
343  else {
344  void print_region(effect);
345  print_region(e);
346  }
347  }
348  }
349  else
350  fprintf(stderr, "\t<NONE>\n");
351 }
352 
353 void print_memory_effects( list pc)
354 {
355  if (pc != NIL) {
356  FOREACH(EFFECT, e, pc)
357  {
358  action a = effect_action(e);
360  if(action_kind_store(ak)
361  || !get_bool_property("PRETTYPRINT_MEMORY_EFFECTS_ONLY"))
362  print_effect(e);
363  }
364  }
365  else
366  fprintf(stderr, "\t<NONE>\n");
367 }
368 
369 /*
370  * Print callgraph with proper effects
371  */
373 {
374  bool success = false;
376  return success;
377 }
378 
379 /*
380  * Print callgraph with cumulated effects
381  */
383 {
384  bool success = false;
386  return success;
387 }
388 
bool effect_consistent_p(effect p)
Definition: effects.c:457
text make_text(list a)
Definition: text.c:107
void free_text(text p)
Definition: text.c:74
static reference ref
Current stmt (an integer)
Definition: adg_read_paf.c:163
bool print_decorated_call_graph(const string, text(*)(const string))
Definition: print.c:64
int compare_effect_reference(effect *e1, effect *e2)
int compare_effect_reference(e1, e2):
Definition: compare.c:210
int compare_effect_reference_in_common(effect *e1, effect *e2)
int compare_effect_reference_in_common(e1, e2):
Definition: compare.c:224
#define continuation
Definition: prettyprint.c:102
text simple_inout_effects_to_text(list)
text simple_rw_effects_to_text(list)
prettyprint.c
bool print_call_graph_with_proper_effects(const string)
text get_text_proper_effects(const string)
text get_text_cumulated_effects(const string)
text simple_live_out_paths_to_text(list)
string effect_to_string(effect)
list words_effect(effect)
text simple_live_in_paths_to_text(list)
bool print_call_graph_with_cumulated_effects(const string)
list words_effect_generic(effect, bool)
list words_effect_without_approximation(effect)
void print_memory_effects(list)
#define effect_any_reference(e)
FI: cannot be used as a left hand side.
list effect_words_reference(reference obj)
made from words_reference this function can print entity_name instead of entity_local_name,...
Definition: prettyprint.c:68
string full_action_to_short_string(action)
Definition: effects.c:969
bool store_effect_p(effect)
Definition: effects.c:1062
#define effect_undefined_p(x)
Definition: effects.h:615
#define action_write(x)
Definition: effects.h:316
#define action_kind_store(x)
Definition: effects.h:261
#define effect_action(x)
Definition: effects.h:642
#define approximation_may_p(x)
Definition: effects.h:363
#define action_read(x)
Definition: effects.h:313
#define action_read_p(x)
Definition: effects.h:311
#define effect_descriptor(x)
Definition: effects.h:646
#define descriptor_none_p(x)
Definition: effects.h:602
#define effect_approximation(x)
Definition: effects.h:644
#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
#define ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66
#define POP(l)
Modify a list pointer to point on the next element of the list.
Definition: newgen_list.h:59
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
void gen_free_string_list(list ls)
Definition: list.c:564
list gen_nconc(list cp1, list cp2)
physically concatenates CP1 and CP2 but do not duplicates the elements
Definition: list.c:344
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
#define FOREACH(_fe_CASTER, _fe_item, _fe_list)
Apply/map an instruction block on all the elements of a list.
Definition: newgen_list.h:179
#define list_undefined
Undefined list definition :-)
Definition: newgen_list.h:69
void gen_sort_list(list l, gen_cmp_func_t compare)
Sorts a list of gen_chunks in place, to avoid allocations...
Definition: list.c:796
#define D(A)
Definition: iabrev.h:56
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
#define pips_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 string_undefined
Definition: newgen_types.h:40
int(* gen_cmp_func_t)(const void *, const void *)
Definition: newgen_types.h:114
string get_comment_sentinel()
Start a single line comment.
Definition: misc.c:154
#define print_effect(e)
Definition: print.c:336
#define print_region(x)
Definition: print.c:343
#define print_effects(e)
Definition: print.c:334
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 MERGE_TEXTS(r, t)
#define MAX_LINE_LENGTH
maximum length of a line when prettyprinting...
string words_to_string(cons *lw)
Definition: print.c:211
void print_words(FILE *fd, cons *lw)
Definition: print.c:263
void close_current_line(string, text, string)
Definition: util.c:235
void add_to_current_line(string, const char *, string, text)
Definition: util.c:140