PIPS
prettyprint.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "linear.h"
#include "genC.h"
#include "text.h"
#include "text-util.h"
#include "top-level.h"
#include "ri.h"
#include "effects.h"
#include "ri-util.h"
#include "effects-util.h"
#include "database.h"
#include "pipsdbm.h"
#include "resources.h"
#include "misc.h"
#include "properties.h"
#include "prettyprint.h"
#include "transformer.h"
#include "effects-generic.h"
#include "semantics.h"
#include "continuation.h"
+ Include dependency graph for prettyprint.c:

Go to the source code of this file.

Macros

#define PREC_FORESYS_PREFIX   "C$PREC"
 package continuation : Be'atrice Creusillet, 1996 More...
 
#define TRAN_FORESYS_PREFIX   "C$TRAN"
 
#define continuation   get_comment_continuation()
 
#define append(s)   add_to_current_line(crt_line, s, continuation, txt)
 

Functions

static int is_inferior_pvarval (Pvecteur *pvarval1, Pvecteur *pvarval2)
 The strange argument type is required by qsort(), deep down in the calls. More...
 
static text text_continuation (transformer cont, bool is_must)
 text text_continuation(transformer tran) input : a transformer representing a transformer or a precondition output : a text containing commentaries representing the transformer modifies : nothing. More...
 
static text text_continuation_conditions (transformer must_cont_t, transformer may_cont_t)
 
static text text_statement_continuation_conditions (entity module, int margin, statement stat)
 
static text get_continuation_condition_text (const char *module_name, bool give_code_p)
 
static bool print_continuation_conditions (const char *module_name)
 
bool print_code_continuation_conditions (const string module_name)
 prettyprint.c More...
 
bool print_source_continuation_conditions (const string module_name)
 

Variables

static bool is_user_view_p
 
static hash_table nts = hash_table_undefined
 

Macro Definition Documentation

◆ append

#define append (   s)    add_to_current_line(crt_line, s, continuation, txt)

Definition at line 103 of file prettyprint.c.

◆ continuation

#define continuation   get_comment_continuation()

Definition at line 102 of file prettyprint.c.

◆ PREC_FORESYS_PREFIX

#define PREC_FORESYS_PREFIX   "C$PREC"

package continuation : Be'atrice Creusillet, 1996

This File contains the functions to prettyprint continuation conditions of a module (over- and under-approximations.

Definition at line 67 of file prettyprint.c.

◆ TRAN_FORESYS_PREFIX

#define TRAN_FORESYS_PREFIX   "C$TRAN"

Definition at line 68 of file prettyprint.c.

Function Documentation

◆ get_continuation_condition_text()

static text get_continuation_condition_text ( const char *  module_name,
bool  give_code_p 
)
static

To set up the hash table to translate value into value names

prepare the prettyprinting

summary information first

then code with regions, using text_statement_continuation_conditions

Definition at line 228 of file prettyprint.c.

229 {
230  entity module;
231  statement module_stat, user_stat = statement_undefined;
232  text txt = make_text(NIL);
234 
238  (DBR_CODE, module_name, true));
239  module_stat = get_current_module_statement();
240 
241  /* To set up the hash table to translate value into value names */
243  db_get_memory_resource(DBR_CUMULATED_EFFECTS, module_name, true));
245 
246 
247  if(is_user_view_p)
248  {
249  user_stat = (statement)
250  db_get_memory_resource(DBR_PARSED_CODE, module_name, true);
251 
253  nts = build_number_to_statement(nts, module_stat);
254 
255  ifdebug(1)
256  {
258  }
259  }
260 
261  debug_on("CONTINUATION_DEBUG_LEVEL");
262 
264  db_get_memory_resource(DBR_MUST_CONTINUATION, module_name, true) );
266  db_get_memory_resource(DBR_MAY_CONTINUATION, module_name, true) );
268  db_get_memory_resource(DBR_MUST_SUMMARY_CONTINUATION, module_name, true);
270  db_get_memory_resource(DBR_MAY_SUMMARY_CONTINUATION, module_name, true);
271 
272  /* prepare the prettyprinting */
274  /* summary information first */
277 
278  if (give_code_p)
279  /* then code with regions,
280  * using text_statement_continuation_conditions */
282  is_user_view_p? user_stat : module_stat));
283 
284  debug_off();
285 
286  if(is_user_view_p)
287  {
290  }
291 
293 
300 
301  return txt;
302 }
text make_text(list a)
Definition: text.c:107
struct _newgen_struct_statement_ * statement
Definition: cloning.h:21
static text text_statement_continuation_conditions(entity module, int margin, statement stat)
Definition: prettyprint.c:192
static text text_continuation(transformer cont, bool is_must)
text text_continuation(transformer tran) input : a transformer representing a transformer or a precon...
Definition: prettyprint.c:118
static bool is_user_view_p
Definition: prettyprint.c:70
static hash_table nts
Definition: prettyprint.c:71
static transformer may_sum_cont_t
Definition: continuation.c:68
static transformer must_sum_cont_t
package continuation : Be'atrice Creusillet, 1996
Definition: continuation.c:67
void set_may_continuation_map(statement_mapping)
void set_must_continuation_map(statement_mapping)
void reset_may_continuation_map(void)
void reset_must_continuation_map(void)
void set_cumulated_rw_effects(statement_effects)
void reset_cumulated_rw_effects(void)
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
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
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
#define debug_on(env)
Definition: misc-local.h:157
#define debug_off()
Definition: misc-local.h:160
#define hash_table_undefined
Value of an undefined hash_table.
Definition: newgen_hash.h:49
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
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
struct _newgen_struct_transformer_ * transformer
Definition: ri.h:431
#define statement_undefined
Definition: ri.h:2419
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
#define MERGE_TEXTS(r, t)
void free_value_mappings(void)
Normal call to free the mappings.
Definition: value.c:1212

References allocate_number_to_statement(), build_number_to_statement(), close_prettyprint(), db_get_memory_resource(), debug_off, debug_on, free_value_mappings(), get_current_module_entity(), get_current_module_statement(), hash_table_free(), hash_table_undefined, ifdebug, init_prettyprint(), is_user_view_p, local_name_to_top_level_entity(), make_text(), may_sum_cont_t, MERGE_TEXTS, module, module_name(), module_to_value_mappings(), must_sum_cont_t, NIL, nts, print_number_to_statement(), reset_cumulated_rw_effects(), reset_current_module_entity(), reset_current_module_statement(), reset_may_continuation_map(), reset_must_continuation_map(), set_cumulated_rw_effects(), set_current_module_entity(), set_current_module_statement(), set_may_continuation_map(), set_must_continuation_map(), statement_undefined, text_continuation(), text_module(), and text_statement_continuation_conditions().

Referenced by print_continuation_conditions().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ is_inferior_pvarval()

static int is_inferior_pvarval ( Pvecteur pvarval1,
Pvecteur pvarval2 
)
static

The strange argument type is required by qsort(), deep down in the calls.

The constant term is given the highest weight to push constant terms at the end of the constraints and to make those easy to compare. If not, constant 0 will be handled differently from other constants. However, it would be nice to give constant terms the lowest weight to print simple constraints first...

Either I define two comparison functions, or I cheat somewhere else. Let's cheat?

Definition at line 75 of file prettyprint.c.

76 {
77  /* The constant term is given the highest weight to push constant
78  terms at the end of the constraints and to make those easy
79  to compare. If not, constant 0 will be handled differently from
80  other constants. However, it would be nice to give constant terms
81  the lowest weight to print simple constraints first...
82 
83  Either I define two comparison functions, or I cheat somewhere else.
84  Let's cheat? */
85  int is_equal = 0;
86 
87  if (term_cst(*pvarval1) && !term_cst(*pvarval2))
88  is_equal = 1;
89  else if (term_cst(*pvarval1) && term_cst(*pvarval2))
90  is_equal = 0;
91  else if(term_cst(*pvarval2))
92  is_equal = -1;
93  else
94  is_equal =
95  strcmp(pips_user_value_name((entity) vecteur_var(*pvarval1)),
97 
98 
99  return is_equal;
100 }
const char * pips_user_value_name(entity)
This function is called many times when the constraints and the system of constraints are sorted usin...
Definition: value.c:815
#define vecteur_var(v)
#define term_cst(varval)

References pips_user_value_name(), term_cst, and vecteur_var.

Referenced by text_continuation().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ print_code_continuation_conditions()

bool print_code_continuation_conditions ( const string  module_name)

prettyprint.c

Parameters
module_nameodule_name

Definition at line 331 of file prettyprint.c.

332 {
333  is_user_view_p = false;
335 }
static bool print_continuation_conditions(const char *module_name)
Definition: prettyprint.c:305

References is_user_view_p, module_name(), and print_continuation_conditions().

+ Here is the call graph for this function:

◆ print_continuation_conditions()

static bool print_continuation_conditions ( const char *  module_name)
static

Definition at line 305 of file prettyprint.c.

306 {
307  char *file_name, *file_resource_name;
308  bool success = true;
309 
310  file_name = strdup(concatenate(".cont",
312  ("PRETTYPRINT_UNSTRUCTURED_AS_A_GRAPH") ?
313  GRAPH_FILE_EXT : "",
314  NULL));
315  file_resource_name =
316  get_bool_property("PRETTYPRINT_UNSTRUCTURED_AS_A_GRAPH") ?
317  DBR_GRAPH_PRINTED_FILE :
318  (is_user_view_p ? DBR_PARSED_PRINTED_FILE : DBR_PRINTED_FILE);
319 
320  success =
322  module_name,
323  file_resource_name,
324  file_name,
326 
327  free(file_name);
328  return(success);
329 }
static text get_continuation_condition_text(const char *module_name, bool give_code_p)
Definition: prettyprint.c:228
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
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
bool make_text_resource_and_free(const char *, const char *, const char *, text)
Definition: print.c:82
char * strdup()
static string file_name

References concatenate(), file_name, free(), get_bool_property(), get_continuation_condition_text(), is_user_view_p, make_text_resource_and_free(), module_name(), and strdup().

Referenced by print_code_continuation_conditions(), and print_source_continuation_conditions().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ print_source_continuation_conditions()

bool print_source_continuation_conditions ( const string  module_name)
Parameters
module_nameodule_name

Definition at line 338 of file prettyprint.c.

339 {
340  is_user_view_p = true;
342 }

References is_user_view_p, module_name(), and print_continuation_conditions().

+ Here is the call graph for this function:

◆ text_continuation()

static text text_continuation ( transformer  cont,
bool  is_must 
)
static

text text_continuation(transformer tran) input : a transformer representing a transformer or a precondition output : a text containing commentaries representing the transformer modifies : nothing.

Modification: AP, Nov 10th, 1995. Instead of building a (very long) string, I directly use the transformer to build the prettyprint in text format. This is to avoid the problem occuring when the buffer used in transformer[precondition]_to_string() is too small. I also use a static buffer to build each constraint; we are restricted to constraints of lengths smaller than the line length.

else an empty text is returned.

Definition at line 118 of file prettyprint.c.

119 {
120  text txt = make_text(NIL);
121  char crt_line[MAX_LINE_LENGTH];
122 
123  crt_line[0] = '\0';
125  append(" ");
126 
127  if(cont != (transformer) HASH_UNDEFINED_VALUE )
128  {
129  if(cont==transformer_undefined)
130  {
131  append(" CONTINUATION: TRANSFORMER_UNDEFINED");
132  }
133  else
134  {
137 
138  append(is_must? "C-MUST-":"C-MAY-");
139  system_text_format(crt_line, continuation, txt, ps,
141  false);
142  }
143 
144  close_current_line(crt_line, txt,continuation);
145  }
146  /* else an empty text is returned.
147  */
148 
149  return txt;
150 }
void system_text_format(string line, string prefix, text txt, Psysteme ps, string(*variable_name)(Variable), bool a_la_fortran)
appends ps to line/txt with prefix continuations.
static int is_inferior_pvarval(Pvecteur *pvarval1, Pvecteur *pvarval2)
The strange argument type is required by qsort(), deep down in the calls.
Definition: prettyprint.c:75
#define continuation
Definition: prettyprint.c:102
#define append(s)
Definition: prettyprint.c:103
#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
string get_comment_sentinel()
Start a single line comment.
Definition: misc.c:154
#define transformer_undefined
Definition: ri.h:2847
#define transformer_relation(x)
Definition: ri.h:2873
#define predicate_system(x)
Definition: ri.h:2069
void sc_lexicographic_sort(Psysteme sc, int(*compare)(Pvecteur *, Pvecteur *))
Minimize first the lexico-graphic weight of each constraint according to the comparison function "com...
Definition: sc_unaires.c:206
#define MAX_LINE_LENGTH
maximum length of a line when prettyprinting...
void close_current_line(string, text, string)
Definition: util.c:235
char *(* get_variable_name_t)(Variable)
Definition: vecteur-local.h:62

References append, close_current_line(), continuation, get_comment_sentinel(), HASH_UNDEFINED_VALUE, is_inferior_pvarval(), make_text(), MAX_LINE_LENGTH, NIL, pips_user_value_name(), predicate_system, sc_lexicographic_sort(), system_text_format(), transformer_relation, and transformer_undefined.

Referenced by get_continuation_condition_text(), and text_continuation_conditions().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ text_continuation_conditions()

static text text_continuation_conditions ( transformer  must_cont_t,
transformer  may_cont_t 
)
static

First: must continuation conditions

Then: may continuation conditions

Definition at line 153 of file prettyprint.c.

156 {
157 
158  text cont_text = make_text(NIL);
159  bool loose_p = get_bool_property("PRETTYPRINT_LOOSE");
160 
161  if ((must_cont_t ==(transformer) HASH_UNDEFINED_VALUE) &&
162  (may_cont_t ==(transformer) HASH_UNDEFINED_VALUE) )
163  return(cont_text);
164 
165  if (loose_p)
166  {
167  ADD_SENTENCE_TO_TEXT(cont_text,
169  strdup("\n")));
170  }
171 
172  /* First: must continuation conditions */
173  if (must_cont_t !=(transformer) HASH_UNDEFINED_VALUE)
174  {
175  MERGE_TEXTS(cont_text, text_continuation(must_cont_t,true));
176  }
177 
178  /* Then: may continuation conditions */
179  if (may_cont_t !=(transformer) HASH_UNDEFINED_VALUE)
180  {
181  MERGE_TEXTS(cont_text, text_continuation(may_cont_t,false));
182  }
183  if (loose_p)
184  ADD_SENTENCE_TO_TEXT(cont_text,
186  strdup("\n")));
187 
188  return(cont_text);
189 }
sentence make_sentence(enum sentence_utype tag, void *val)
Definition: text.c:59
#define ADD_SENTENCE_TO_TEXT(t, p)
@ is_sentence_formatted
Definition: text.h:57

References ADD_SENTENCE_TO_TEXT, get_bool_property(), HASH_UNDEFINED_VALUE, is_sentence_formatted, make_sentence(), make_text(), MERGE_TEXTS, NIL, strdup(), and text_continuation().

Referenced by text_statement_continuation_conditions().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ text_statement_continuation_conditions()

static text text_statement_continuation_conditions ( entity  module,
int  margin,
statement  stat 
)
static

Definition at line 192 of file prettyprint.c.

196 {
197  pips_assert("true", module==module && margin==margin);
198 
199  transformer must_cont_t, may_cont_t;
200  statement s;
201 
202  s = is_user_view_p?
203  (statement) hash_get(nts, (char *) statement_number(stat)) :
204  stat;
205 
206  if (is_user_view_p)
207  {
208  s = (statement) hash_get(nts, (char *) statement_number(stat));
209  }
210 
211 
212  if (s != (statement) HASH_UNDEFINED_VALUE)
213  {
214  must_cont_t = load_statement_must_continuation(s);
215  may_cont_t = load_statement_may_continuation(s);
216  }
217  else
218  {
219  must_cont_t = (transformer) HASH_UNDEFINED_VALUE;
220  may_cont_t = (transformer) HASH_UNDEFINED_VALUE;
221  }
222 
223  return text_continuation_conditions(must_cont_t, may_cont_t);
224 }
static text text_continuation_conditions(transformer must_cont_t, transformer may_cont_t)
Definition: prettyprint.c:153
transformer load_statement_must_continuation(statement)
transformer load_statement_may_continuation(statement)
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
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define statement_number(x)
Definition: ri.h:2452

References hash_get(), HASH_UNDEFINED_VALUE, is_user_view_p, load_statement_may_continuation(), load_statement_must_continuation(), module, nts, pips_assert, statement_number, and text_continuation_conditions().

Referenced by get_continuation_condition_text().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ is_user_view_p

◆ nts