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 
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 
32 #include <setjmp.h>
33 
34 #include "genC.h"
35 #include "linear.h"
36 
37 #include "ri.h"
38 #include "effects.h"
39 
40 #include "ri-util.h"
41 #include "effects-util.h"
42 
43 #include "misc.h"
44 #include "properties.h"
45 
46 #include "text-util.h"
47 
48 #include "effects-generic.h"
49 #include "effects-simple.h" // print_effect
50 #include "effects-convex.h"
51 
52 #include "semantics.h" // module_to_value_mappings
53 #include "transformer.h"
54 
55 #include "pipsdbm.h"
56 
57 #include "prettyprint.h"
58 
59 #define REGION_BUFFER_SIZE 2048
60 #define REGION_FORESYS_PREFIX "C$REG"
61 #define PIPS_NORMAL_PREFIX "C"
62 
63 /*
64 #define BACKWARD TRUE
65 #define FORWARD FALSE
66 */
67 
68 
69 /* text text_region_no_action(effect reg)
70  * input : a region
71  * output : a text consisting of several lines of commentaries,
72  * representing the region BUT WITHOUT THE ACTION TAG (IN/OUT)
73  * modifies : nothing
74  * COPIED FROM THE FUNCTION text_region IN FILE effects-convex/prettyprint.c
75  * AND MODIFIED TO NOT PRINT ACTION (IN/OUT)
76  */
77 #define append(s) add_to_current_line(line_buffer, s, str_prefix, t_reg)
78 
79 static text
81 {
82  text t_reg;
83  bool foresys = get_bool_property("PRETTYPRINT_FOR_FORESYS");
84  string str_prefix = foresys?
87  reference r;
88 /* action ac; */
89  approximation ap;
90  Psysteme sc;
91  Pbase sorted_base;
92  list /* of string */ ls;
93 
94  if(effect_undefined_p(reg))
95  {
96  user_log("[text_region] unexpected effect undefined\n");
97  return
99  strdup(concatenate(str_prefix, "<REGION_UNDEFINED>\n", NULL))),
100  NIL));
101  }
102  /* else the effect is defined...
103  */
104 
105  /* PREFIX
106  */
107  t_reg = make_text(NIL);
109  if (!foresys) append(" <");
110 
111  /* REFERENCE
112  */
113  r = effect_any_reference(reg);
114  ls = foresys? Words_Reference(r): effect_words_reference(r);
115 
116  MAP(STRING, s, append(s), ls);
117  gen_map(free, ls); gen_free_list(ls); ls = NIL;
118 
119  /* ACTION and APPROXIMATION
120  */
121 /* ac = effect_action(reg); */
122  ap = effect_approximation(reg);
123 
124  if (foresys)
125  {
126  append(", RGSTAT(");
127 /* append(action_read_p(ac) ? "R," : "W,"); */
128  append(approximation_may_p(ap) ? "MAY), " : "EXACT), ");
129  }
130  else /* PIPS prettyprint */
131  {
132 /* append("-");
133  append(action_interpretation(action_tag(ac))); */
134  append(approximation_may_p(ap) ? "-MAY" : "-EXACT");
135  append("-");
136  }
137 
138  /* SYSTEM
139  * sorts in such a way that constraints with phi variables come first.
140  */
141  sorted_base = region_sorted_base_dup(reg);
142  sc = sc_dup(region_system(reg));
143  region_sc_sort(sc, sorted_base);
144 
145  system_sorted_text_format(line_buffer, str_prefix, t_reg, sc,
147  vect_contains_phi_p, foresys);
148 
149  sc_rm(sc);
150  base_rm(sorted_base);
151 
152  /* CLOSE */
153  if (!foresys) append(">");
154  close_current_line(line_buffer, t_reg,str_prefix);
155 
156  return t_reg;
157 }
158 
159 
160 static text
162 {
164  list al = NIL;
165  entity module;
166  text txt = make_text(NIL);
167 
168  pips_debug(4,"module %s resource %s\n",module_name,resource_name);
169 
173 
174  pips_debug(9,"got aliases\n");
175 
176  /* ATTENTION: all this is necessary to call module_to_value_mappings
177  * to set up the hash table to translate value into value names
178  * before the call to text_region below
179  */
183  (DBR_CODE, module_name, true));
185  db_get_memory_resource(DBR_CUMULATED_EFFECTS, module_name, true));
187  db_get_memory_resource(DBR_PROPER_EFFECTS, module_name, true));
188  /* that's it, but we musn't forget to rest everything after the call
189  */
190 
192 
193  pips_debug(9,"hash table set up\n");
194 
195 /* set_action_interpretation(ACTION_IN,ACTION_OUT); */
196 
197  MAP(EFFECTS,alias_list_effects,
198  {
199  list alias_list = effects_effects(alias_list_effects);
200 
201  pips_debug(9,"make text for alias list\n");
202 
203  if (alias_list != (list) HASH_UNDEFINED_VALUE
204  && alias_list != list_undefined)
205  {
206  /* have to copy alias_list here */
207  al = alias_list;
208  MAP(EFFECT,alias,
209  {
210  pips_debug(9,"make text for alias:\n");
211 
212  ifdebug(9)
213  {
215  print_region(alias);
217  }
218 
219 /* set_action_interpretation(ACTION_IN,ACTION_OUT);
220  MERGE_TEXTS(txt,text_region(alias));
221  reset_action_interpretation();
222  */
223 
225  },
226  al);
227 
229  txt,
231  );
232 
233  pips_debug(9,"made text for alias list\n");
234  }
235  },alias_lists);
236 
237  pips_debug(4,"end\n");
238 
239 /* reset_action_interpretation(); */
245 
246  return txt;
247 }
248 
249 
250 static bool
251 print_aliases( const char* module_name, string resource_name, string file_extn)
252 {
253  char *file_resource_name;
254  bool success = true;
255 
256  pips_debug(4,"module %s resource %s file extn %s\n",
257  module_name,resource_name,file_extn);
258 
259  file_resource_name = DBR_ALIAS_FILE;
260 
261  success =
263  file_resource_name,
264  file_extn,
266 
267  pips_debug(4,"end\n");
268 
269  return(success);
270 }
271 
272 
274 {
275  bool success = true;
276 
277  debug_on("ALIAS_PAIRS_DEBUG_LEVEL");
278  pips_debug(4,"module %s\n",module_name);
279 
280  success = print_aliases(module_name,DBR_IN_ALIAS_PAIRS,".in_alias");
281 
282  pips_debug(4,"end\n");
283  debug_off();
284 
285  return success;
286 }
287 
288 
290 {
291  bool success = true;
292 
293  debug_on("ALIAS_PAIRS_DEBUG_LEVEL");
294  pips_debug(4,"module %s\n",module_name);
295 
296  success = print_aliases(module_name,DBR_OUT_ALIAS_PAIRS,".out_alias");
297 
298  pips_debug(4,"end\n");
299  debug_off();
300 
301  return success;
302 }
303 
304 bool print_alias_lists( const char* module_name )
305 {
306  bool success = true;
307 
308  debug_on("ALIAS_LISTS_DEBUG_LEVEL");
309  pips_debug(4,"module %s\n",module_name);
310 
311  success = print_aliases(module_name,DBR_ALIAS_LISTS,".alias_lists");
312 
313  pips_debug(4,"end\n");
314  debug_off();
315 
316  return success;
317 }
318 
319 bool print_alias_classes( const char* module_name )
320 {
321  bool success = true;
322 
323  debug_on("ALIAS_CLASSES_DEBUG_LEVEL");
324  pips_debug(4,"module %s\n",module_name);
325 
326 
327  success = print_aliases(module_name,DBR_ALIAS_CLASSES,".alias_classes");
328 
329  pips_debug(4,"end\n");
330  debug_off();
331 
332  return success;
333 }
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
bool print_alias_lists(const char *module_name)
Definition: prettyprint.c:304
#define REGION_FORESYS_PREFIX
Definition: prettyprint.c:60
bool print_alias_classes(const char *module_name)
Definition: prettyprint.c:319
bool print_out_alias_pairs(const char *module_name)
Definition: prettyprint.c:289
static text text_region_no_action(effect reg)
Definition: prettyprint.c:80
bool print_in_alias_pairs(const char *module_name)
prettyprint.c
Definition: prettyprint.c:273
#define append(s)
text text_region_no_action(effect reg) input : a region output : a text consisting of several lines o...
Definition: prettyprint.c:77
static text aliases_text(const char *module_name, string resource_name)
Definition: prettyprint.c:161
static bool print_aliases(const char *module_name, string resource_name, string file_extn)
Definition: prettyprint.c:251
bool alias_lists(const string)
alias_lists.c
Definition: alias_lists.c:328
void system_sorted_text_format(string line, string prefix, text txt, Psysteme ps, string(*variable_name)(Variable), bool(*put_first)(Pvecteur), bool a_la_fortran)
lower level hook for regions.
#define resource_name(x)
Definition: database.h:108
#define region_system(reg)
Pbase region_sorted_base_dup(effect)
void region_sc_sort(Psysteme, Pbase)
#define ACTION_IN
#define ACTION_OUT
void reset_action_interpretation(void)
void reset_proper_rw_effects(void)
void set_proper_rw_effects(statement_effects)
void set_cumulated_rw_effects(statement_effects)
void set_action_interpretation(string, string)
prettyprint.c
void reset_cumulated_rw_effects(void)
#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
const char * pips_region_user_name(entity ent)
char * pips_region_user_name(entity ent) output : the name of entity.
Definition: prettyprint.c:169
bool vect_contains_phi_p(Pvecteur)
bool vect_contains_phi_p(Pvecteur v) input : a vector output : true if v contains a PHI variable,...
Definition: effects.c:1427
#define effect_undefined_p(x)
Definition: effects.h:615
#define EFFECTS(x)
EFFECTS.
Definition: effects.h:682
#define approximation_may_p(x)
Definition: effects.h:363
#define effects_effects(x)
Definition: effects.h:710
#define effects_classes_classes(x)
Definition: effects.h:678
#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....
#define STRING(x)
Definition: genC.h:87
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
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
void gen_map(gen_iter_func_t fp, const list l)
Definition: list.c:172
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
Definition: newgen_list.h:150
void gen_free_list(list l)
free the spine of the list
Definition: list.c:327
#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
#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 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
static char * module
Definition: pips.c:74
string get_comment_sentinel()
Start a single line comment.
Definition: misc.c:154
string get_comment_continuation()
Start a single line comment with continuation (blank spaces)
Definition: misc.c:167
list Words_Reference(reference obj)
Definition: misc.c:786
#define print_region(x)
Definition: print.c:343
bool make_text_resource(const char *, const char *, const char *, text)
print.c
Definition: print.c:55
static int * line_buffer
le buffer contenant la ligne que l'on doit lire en avance pour se rendre compte qu'on a finit de lire...
Definition: reader.c:251
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
void sc_rm(Psysteme ps)
void sc_rm(Psysteme ps): liberation de l'espace memoire occupe par le systeme de contraintes ps;
Definition: sc_alloc.c:277
Psysteme sc_dup(Psysteme ps)
Psysteme sc_dup(Psysteme ps): should becomes a link.
Definition: sc_alloc.c:176
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
#define ifdebug(n)
Definition: sg.c:47
le type des coefficients dans les vecteurs: Value est defini dans le package arithmetique
Definition: vecteur-local.h:89
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
#define FORESYS_CONTINUATION_PREFIX
#define MERGE_TEXTS(r, t)
#define ADD_SENTENCE_TO_TEXT(t, p)
#define MAX_LINE_LENGTH
maximum length of a line when prettyprinting...
void close_current_line(string, text, string)
Definition: util.c:235
#define SENTENCE(x)
newgen_unformatted_domain_defined
Definition: text.h:36
@ is_sentence_formatted
Definition: text.h:57
void free_value_mappings(void)
Normal call to free the mappings.
Definition: value.c:1212
char *(* get_variable_name_t)(Variable)
Definition: vecteur-local.h:62
#define base_rm(b)