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 /* Name : prettyprint.c
28  * package : static_controlize
29  * Author : Arnauld LESERVOT
30  * Date : May 93
31  * Modified :
32  * Documents : "Implementation of Array Data Flow Graph in Pips"
33  * Comments :
34  */
35 
36 /* Ansi includes */
37 #include <stdio.h>
38 #include <string.h>
39 #include <stdlib.h>
40 #include <limits.h>
41 
42 /* Newgen includes */
43 #include "genC.h"
44 
45 #include "boolean.h"
46 #include "arithmetique.h"
47 #include "vecteur.h"
48 #include "contrainte.h"
49 #include "ray_dte.h"
50 #include "sommet.h"
51 #include "sg.h"
52 #include "sc.h"
53 #include "polyedre.h"
54 #include "matrix.h"
55 
56 /* Pips includes */
57 #include "ri.h"
58 #include "effects.h"
59 /* Types arc_label and vertex_label must be defined although they are
60  not used */
61 typedef void * arc_label;
62 typedef void * vertex_label;
63 #include "graph.h"
64 #include "paf_ri.h"
65 #include "database.h"
66 #include "misc.h"
67 #include "ri-util.h"
68 #include "effects-util.h"
69 #include "text.h"
70 #include "static_controlize.h"
71 #include "text-util.h"
72 #include "pipsdbm.h"
73 #include "resources.h"
74 #include "prettyprint.h"
75 #include "paf-util.h"
76 
77 #define MAX_STATIC_CONTROL_LINE_NUMBER 2048
78 #define CODE_WITH_STATIC_CONTROLIZE_EXT ".stco"
79 
80 /* Global variables */
82 
83 /*=================================================================*/
84 /* void print_code_static_control((char*) module_name) AL 05/93
85  * Prettyprints a static_control mapping attached to a module_name.
86  */
88 {
89  entity module;
90  statement module_stat;
91  text txt = make_text(NIL);
92  bool success;
93 
94  debug_on( "PRINT_STATIC_CONTROL_DEBUG_LEVEL" );
95 
96  ifdebug(1)
97  user_log("\n\n *** PRINTING STATIC CONTROL for %s\n",
98  module_name);
99 
101  module_stat = (statement)
102  db_get_memory_resource(DBR_CODE, module_name, true);
104  db_get_memory_resource( DBR_STATIC_CONTROL, module_name, true);
106 
107 /*
108  filename = strdup(concatenate(db_get_current_workspace_directory(),
109  "/", module_name, ".stco", NULL));
110  fd = safe_fopen(filename, "w");
111 */
112 
113  MERGE_TEXTS(txt, text_module(module, module_stat));
114 
115 /*
116  print_text(fd, txt);
117  safe_fclose(fd, filename);
118  DB_PUT_FILE_RESOURCE(DBR_PRINTED_FILE, strdup(module_name),
119  filename);
120 */
121 
123  DBR_PRINTED_FILE,
125  txt);
126 
128 
129  debug_off();
130 
131  return(success);
132 }
133 
134 
135 /*=================================================================*/
136 /* text text_static_control((entity) module, (int) margin, (statement) stat)
137  * Function hook used by package text-util to prettyprint a static_control.
138  */
140  int margin __attribute__ ((unused)),
141  statement stat)
142 {
144 
145  return( store_sc_text_line( sc ));
146 }
147 
148 /*=================================================================*/
149 /* text store_sc_text_line((static_control) sc) AL 05/93
150  * Stores a static_control prettyprinted.
151  */
153 static_control sc;
154 {
155  text sc_text = make_text(NIL);
156  char *t = NULL;
157  string comment;
158 
159  /* pips_assert("store_text_line", sefs_list != NIL); */
161  comment = "//";
162  else
163  comment = "C";
164 
165 
166  t = concatenate(comment,"\t\t< is static >",
167  (static_control_yes(sc)?" TRUE":" FALSE"), "\n", NULL);
168  ADD_SENTENCE_TO_TEXT( sc_text,
170  t = concatenate(comment,"\t\t< parameter >",
172  "\n", NULL);
173  ADD_SENTENCE_TO_TEXT( sc_text,
175  t = concatenate(comment,"\t\t< loops >",
177  NULL);
178  ADD_SENTENCE_TO_TEXT( sc_text,
180  t = concatenate(comment,"\t\t< tests >",
182  NULL);
183  ADD_SENTENCE_TO_TEXT( sc_text,
185 
186  return ( sc_text );
187 }
188 
189 #define MAX_CHAR_NUMBER 39
190 
191 /*=================================================================*/
192 /* cons *words_test_list((list) obj) AL 05/93
193  * Makes a list of strings from a list of test expressions.
194  */
196 list obj;
197 {
198  cons* ret_cons = NIL;
199  string before_string = strdup(" ");
200  string blank_string;
202  blank_string = strdup("// ");
203  else
204  blank_string = strdup("C ");
205 
206  pips_debug(7, "doing \n");
207  MAPL( exp_ptr, {
208  cons* pc = NIL;
209  expression exp = EXPRESSION(CAR(exp_ptr));
210 
211  pc = CHAIN_SWORD(pc, strdup( before_string ));
212  pc = gen_nconc(pc, Words_Expression(exp));
213  pc = CHAIN_SWORD(pc,"\n") ;
214  ret_cons = gen_nconc(ret_cons, gen_copy_seq(pc));
215  before_string = blank_string;
216  }, obj);
217 
218  if( ret_cons == NIL ) ret_cons = CHAIN_SWORD(ret_cons, "\n");
219  return( ret_cons );
220 }
221 
222 /*=================================================================*/
223 /* cons *words_loop_list((list) obj) AL 05/93
224  * Returns a list of strings from a list of loops.
225  */
227 list obj;
228 {
229  cons* ret_cons = NIL;
230  string before_string = strdup(" ");
231  string blank_string;
233  blank_string = strdup("// ");
234  else
235  blank_string = strdup("C ");
236 
237 
238  pips_debug(7, "doing \n");
239  FOREACH(LOOP, l, obj) {
240  cons* pc = NIL;
241  entity ind = loop_index( l );
242  expression low = range_lower(loop_range( l ));
243  expression up = range_upper(loop_range( l ));
244  pc = CHAIN_SWORD(pc, strdup( before_string ));
245  pc = gen_nconc(pc, Words_Expression(low));
246  pc = CHAIN_SWORD(pc," <= ");
247  pc = CHAIN_SWORD(pc, entity_local_name(ind));
248  pc = CHAIN_SWORD(pc," <= ");
249  pc = gen_nconc(pc, Words_Expression(up));
250  pc = CHAIN_SWORD(pc,"\n") ;
251  ret_cons = gen_nconc(ret_cons, gen_copy_seq(pc));
252  before_string = blank_string;
253  }
254 
255  if( ret_cons == NIL ) ret_cons = CHAIN_SWORD(ret_cons, "\n");
256  return( ret_cons );
257 }
258 
259 /*=================================================================*/
260 /* cons *words_entity_list((list) obj) AL 05/93
261  * Returns a list of strings from a list of entities.
262  *
263  * FI: Should be moved in ri-util/entity.c or entities.c when it exists
264  */
266 {
267  list the_list = NIL;
268  pips_debug(7, "doing \n");
269  the_list = CHAIN_SWORD(the_list, " ");
270  FOREACH(ENTITY, ent, obj)
271  {
272  string s = strdup(concatenate(entity_local_name(ent), ", ", NULL));
273  ADD_ELEMENT_TO_LIST( the_list, STRING, s );
274  }
275  return the_list;
276 }
277 
278 /*=================================================================*/
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
struct _newgen_struct_statement_ * statement
Definition: cloning.h:21
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
static void comment(string_buffer code, spoc_hardware_type hw, dagvtx v, int stage, int side, bool flip)
Definition: freia_spoc.c:52
#define STRING(x)
Definition: genC.h:87
bool success
Definition: gpips-local.h:59
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
list gen_copy_seq(list l)
Copy a list structure.
Definition: list.c:501
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 MAPL(_map_list_cp, _code, _l)
Apply some code on the addresses of all the elements of a list.
Definition: newgen_list.h:203
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 ADD_ELEMENT_TO_LIST(_list, _type, _element)
Definition: icfg-local.h:50
enum language_utype get_prettyprint_language_tag()
Definition: language.c:67
#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
#define GET_STATEMENT_MAPPING(map, stat)
Definition: newgen-local.h:49
hash_table statement_mapping
these macros are obsolete! newgen functions (->) should be used instead
Definition: newgen-local.h:42
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
#define static_control_loops(x)
Definition: paf_ri.h:757
struct _newgen_struct_static_control_ * static_control
Definition: paf_ri.h:184
#define static_control_params(x)
Definition: paf_ri.h:755
#define static_control_yes(x)
Definition: paf_ri.h:753
#define static_control_tests(x)
Definition: paf_ri.h:759
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
list Words_Expression(expression obj)
of string
Definition: misc.c:2616
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)
bool make_text_resource(const char *, const char *, const char *, text)
print.c
Definition: print.c:55
dfg_arc_label arc_label
Definition: prettyprint.c:81
dfg_vertex_label vertex_label
Local defines.
Definition: prettyprint.c:80
const char * entity_local_name(entity e)
entity_local_name modified so that it does not core when used in vect_fprint, since someone thought t...
Definition: entity.c:453
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 LOOP(x)
LOOP.
Definition: ri.h:1606
#define range_upper(x)
Definition: ri.h:2290
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
#define range_lower(x)
Definition: ri.h:2288
#define loop_range(x)
Definition: ri.h:1642
@ is_language_c
Definition: ri.h:1567
#define loop_index(x)
Definition: ri.h:1640
char * strdup()
static bool __attribute__((unused))
Definition: prettyprint.c:435
#define ifdebug(n)
Definition: sg.c:47
cons * words_test_list(list obj)
================================================================
Definition: prettyprint.c:195
text text_static_control(entity module __attribute__((unused)), int margin __attribute__((unused)), statement stat)
================================================================
Definition: prettyprint.c:139
#define CODE_WITH_STATIC_CONTROLIZE_EXT
Definition: prettyprint.c:78
list words_entity_list(list obj)
================================================================
Definition: prettyprint.c:265
text store_sc_text_line(static_control sc)
================================================================
Definition: prettyprint.c:152
bool print_code_static_control(const string module_name)
================================================================
Definition: prettyprint.c:87
static statement_mapping Gsc_map
Global variables.
Definition: prettyprint.c:81
cons * words_loop_list(list obj)
================================================================
Definition: prettyprint.c:226
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)
string words_to_string(cons *lw)
Definition: print.c:211
@ is_sentence_formatted
Definition: text.h:57
#define exp
Avoid some warnings from "gcc -Wshadow".
Definition: vasnprintf.c:207