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 /*
28  * (pretty)print of reductions.
29  *
30  * FC, June 1996.
31  */
32 
33 #include "local-header.h"
34 #include "text.h"
35 #include "text-util.h"
36 #include "semantics.h"
37 #include "prettyprint.h"
38 
39 #define PROP_SUFFIX ".proper_reductions"
40 #define CUMU_SUFFIX ".cumulated_reductions"
41 
42 #define PROP_DECO "proper reductions"
43 #define CUMU_DECO "cumulated reductions"
44 
45 /****************************************************** STATIC INFORMATION */
46 
48 static string reduction_decoration = NULL;
49 
50 /************************************************************* BASIC WORDS */
51 
52 /* generates a short note to tell about the type of the statement
53  * being decorated.
54  */
56 {
58  switch (instruction_tag(i))
59  {
60  case is_instruction_sequence: return "seq ";
61  case is_instruction_loop: return "loop ";
62  case is_instruction_test: return "test ";
63  case is_instruction_call: return "call ";
64  case is_instruction_unstructured: return "unst ";
65  case is_instruction_whileloop: return "while ";
66  case is_instruction_goto: return "goto ";
67  case is_instruction_forloop: return "for ";
68  case is_instruction_expression: return "expr ";
69  default:
70  pips_internal_error("unexpected instruction tag");
71  break;
72  }
73  return "";
74 }
75 
76 /* returns a (static) string describing the tag t reduction
77  */
79 {
80  switch(t)
81  {
82  case is_reduction_operator_none: return "none";
83  case is_reduction_operator_sum: return "sum";
84  case is_reduction_operator_csum: return "csum";
85  case is_reduction_operator_prod: return "prod";
86  case is_reduction_operator_min: return "min";
87  case is_reduction_operator_max: return "max";
88  case is_reduction_operator_and: return "and";
89  case is_reduction_operator_or: return "or";
90  case is_reduction_operator_bitwise_or: return "bitwise_or";
91  case is_reduction_operator_bitwise_xor: return "bitwise_xor";
92  case is_reduction_operator_bitwise_and: return "bitwise_and";
93  case is_reduction_operator_eqv: return "eqv";
94  case is_reduction_operator_neqv: return "neqv";
95  default: pips_internal_error("unexpected reduction operator tag!");
96  }
97 
98  return NULL;
99 }
100 
101 /* allocates and returns the name of the operator
102  */
104 {
106 }
107 
108 /* returns the name of the reduction (!!! not allocated)
109  */
111 {
113 }
114 
115 /* allocates and returns a list of strings for reduction r
116  */
117 static list /* of string */ words_reduction(reduction r)
118 {
120  CONS(STRING, strdup("["),
122  CONS(STRING, strdup("],"), NIL))));
123 }
124 
125 /* allocates and returns a list of string with note ahead if not empty.
126  * it describes the reductions in rs.
127  */
128 static list /* of string */ words_reductions(string note, reductions rs)
129 {
130  list /* of string */ ls = NIL;
132  ls = gen_nconc(words_reduction(r), ls);
133  }
134  return ls? CONS(STRING, strdup(note), ls): NIL;
135 }
136 
138 {
140  fprintf(stderr, "reduction is %s[",
144  fprintf(stderr, "]\n");
145 }
146 
147 /************************************************* REDUCTION PRETTY PRINT */
148 
149 /* function to allocate and returns a text, passed to the prettyprinter
150  * uses some static variables:
151  * - printed_reductions function
152  * -
153  */
154 /************************************************* REDUCTION PRETTY PRINT */
155 
156 /* function to allocate and returns a text, passed to the prettyprinter
157  * uses some static variables:
158  * - printed_reductions function
159  * -
160  */
161 static text text_reductions(__attribute__((unused)) entity module, __attribute__((unused)) int margin, statement s)
162 {
163  text t;
164 
165  debug_on("REDUCTIONS_DEBUG_LEVEL");
166  pips_debug(1, "considering statement %p\n", s);
167 
168  t = bound_printed_reductions_p(s)? /* unreachable statements? */
173  make_text(NIL);
174 
175  debug_off();
176  return t;
177 }
178 
179 /* returns a reduction-decorated text for statement s
180  */
182 {
183  text t;
184  debug_on("PRETTYPRINT_DEBUG_LEVEL");
188  debug_off();
189  return t;
190 }
191 
192 /* handles the required prettyprint
193  * ??? what about summary reductions?
194  * should be pprinted with cumulated regions.
195  * @ return true if succeed
196  * @param module_name the module name to process
197  * @param resource_name the resource to use
198  * @param decoration_name
199  * @param summary_name
200  * @param file_suffix
201  */
202 static bool
204  const char* module_name,
205  string resource_name,
206  string decoration_name,
207  string summary_name,
208  string file_suffix)
209 {
210  text t;
211 
212  debug_on("REDUCTIONS_DEBUG_LEVEL");
213  pips_debug(1, "considering module %s for %s\n",
214  module_name, decoration_name);
215 
220  db_get_memory_resource(DBR_CODE, module_name, true));
221  reduction_decoration = decoration_name;
222 
224 
225  if (summary_name)
226  {
227  reductions rs = (reductions)
228  db_get_memory_resource(summary_name, module_name, true);
229  text p =
232  MERGE_TEXTS(p, t);
233  t=p;
234  }
235 
236  make_text_resource_and_free(module_name, DBR_PRINTED_FILE, file_suffix, t);
237 
241  reduction_decoration = NULL;
242 
243  debug_off();
244  return true;
245 }
246 
247 /* Handlers for PIPSMAKE
248  */
250 {
252  DBR_PROPER_REDUCTIONS,
253  PROP_DECO,
254  NULL,
255  PROP_SUFFIX);
256 }
257 
259 {
261  DBR_CUMULATED_REDUCTIONS,
262  CUMU_DECO,
263  DBR_SUMMARY_REDUCTIONS,
264  CUMU_SUFFIX);
265 }
266 
267 /* end of it
268  */
text make_text(list a)
Definition: text.c:107
static reference ref
Current stmt (an integer)
Definition: adg_read_paf.c:163
#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
#define STRING(x)
Definition: genC.h:87
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 CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
Definition: newgen_list.h:150
list gen_nconc(list cp1, list cp2)
physically concatenates CP1 and CP2 but do not duplicates the elements
Definition: list.c:344
#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
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
#define debug_on(env)
Definition: misc-local.h:157
#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
#define debug_off()
Definition: misc-local.h:160
#define GENERIC_GLOBAL_FUNCTION(name, type)
int tag
TAG.
Definition: newgen_types.h:92
static char * module
Definition: pips.c:74
void print_reference(reference r)
Definition: expression.c:142
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
list Words_Reference(reference obj)
Definition: misc.c:786
text text_module(entity, statement)
bool make_text_resource_and_free(const char *, const char *, const char *, text)
Definition: print.c:82
#define reduction_tag(r)
bool print_code_proper_reductions(const char *module_name)
Handlers for PIPSMAKE.
Definition: prettyprint.c:249
static list words_reductions(string note, reductions rs)
allocates and returns a list of string with note ahead if not empty.
Definition: prettyprint.c:128
string note_for_statement(statement s)
generates a short note to tell about the type of the statement being decorated.
Definition: prettyprint.c:55
static bool print_any_reductions(const char *module_name, string resource_name, string decoration_name, string summary_name, string file_suffix)
handles the required prettyprint ??? what about summary reductions? should be pprinted with cumulated...
Definition: prettyprint.c:203
string reduction_name(reduction r)
returns the name of the reduction (!!! not allocated)
Definition: prettyprint.c:110
#define CUMU_SUFFIX
Definition: prettyprint.c:40
#define PROP_SUFFIX
Definition: prettyprint.c:39
static text text_reductions(__attribute__((unused)) entity module, __attribute__((unused)) int margin, statement s)
function to allocate and returns a text, passed to the prettyprinter uses some static variables:
Definition: prettyprint.c:161
void print_reduction(reduction r)
Definition: prettyprint.c:137
bool print_code_cumulated_reductions(const char *module_name)
Definition: prettyprint.c:258
string reduction_operator_name(reduction_operator o)
allocates and returns the name of the operator
Definition: prettyprint.c:103
static string reduction_decoration
Definition: prettyprint.c:48
#define PROP_DECO
Definition: prettyprint.c:42
string reduction_operator_tag_name(tag t)
returns a (static) string describing the tag t reduction
Definition: prettyprint.c:78
#define CUMU_DECO
Definition: prettyprint.c:43
static list words_reduction(reduction r)
allocates and returns a list of strings for reduction r
Definition: prettyprint.c:117
static text text_code_reductions(statement s)
returns a reduction-decorated text for statement s
Definition: prettyprint.c:181
void set_printed_reductions(pstatement_reductions)
reductions load_printed_reductions(statement)
void reset_printed_reductions(void)
bool bound_printed_reductions_p(statement)
struct _newgen_struct_reductions_ * reductions
@ is_reduction_operator_bitwise_xor
@ is_reduction_operator_none
@ is_reduction_operator_min
@ is_reduction_operator_bitwise_and
@ is_reduction_operator_neqv
@ is_reduction_operator_max
@ is_reduction_operator_bitwise_or
@ is_reduction_operator_csum
@ is_reduction_operator_eqv
@ is_reduction_operator_prod
@ is_reduction_operator_or
@ is_reduction_operator_and
@ is_reduction_operator_sum
#define REDUCTION(x)
REDUCTION.
#define reduction_operator_tag(x)
#define reduction_op(x)
#define reduction_reference(x)
#define reductions_list(x)
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
#define reference_undefined_p(x)
Definition: ri.h:2303
@ 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_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
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
char * strdup()
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
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
#define MERGE_TEXTS(r, t)