PIPS
statement.c
Go to the documentation of this file.
1 /*
2 
3  $Id: statement.c 23489 2018-10-22 09:12:55Z 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  Function for statement, and its subtypes:
29  - instruction
30  */
31 
32 #include <stdlib.h>
33 #include <stdio.h>
34 #include <string.h>
35 #include <stdlib.h>
36 #include <stdarg.h>
37 
38 #include "linear.h"
39 #include "genC.h"
40 
41 #include "misc.h"
42 #include "properties.h"
43 
44 #include "ri-util.h"
45 #include "text-util.h"
46 
47 #include "prettyprint.h"
48 
49 void print_statement_set(FILE * fd, set r)
50 {
51  fprintf(fd, "Set contains statements");
52 
53  SET_MAP(s, {
54  fprintf(fd, " %02td", statement_number((statement) s));
55  }, r);
56 
57  fprintf(fd, "\n");
58 }
59 
60 
61 /** Print statement "s" on file descriptor "fd"
62 
63  Print the statement according to the current PRETTYPRINT_LANGUAGE
64  property
65 
66  See text_named_module() for improvements.
67 */
68 void fprint_statement(FILE * fd, statement s)
69 {
71  fprintf(fd, "Undefined statement\n");
72  // For debugging with gdb, dynamic type checking
74  (void) fprintf(fd,"Arg. \"s\"is not a statement.\n");
75  else {
76  debug_on("TEXT_DEBUG_LEVEL");
80  list pdl = NIL;
81  text txt = text_statement(entity_undefined, 0, s, &pdl);
82  gen_free_list(pdl);
83  print_text(fd, txt);
84  free_text(txt);
87  debug_off();
88  }
89 }
90 
91 /** Print a statement on stderr
92 
93  Print the statement according to the current PRETTYPRINT_LANGUAGE
94  property
95 
96  See text_named_module() for improvements.
97 */
99 {
100  fprint_statement(stderr, s);
101 }
102 
104 {
105  FOREACH(STATEMENT, s, sl) {
106  print_statement(s);
107  }
108 }
109 
110 
111 void print_statement_of_module(statement s, const char* mn)
112 {
117  print_statement(s);
119  }
120  else
121  print_statement(s);
122 }
123 
125 {
126  text t = text_undefined;
127 
128  debug_on("PRETTYPRINT_DEBUG_LEVEL");
131  list pdl = NIL;
132  t = text_statement(entity_undefined, 0, s, &pdl);
133  gen_free_list(pdl);
135  debug_off();
136 
137  return t;
138 }
139 
141 {
142  if(statement_undefined_p(s)) {
143  fprintf(stderr, "Statement undefined\n");
144  }
145  else if(continue_statement_p(s)
147  /* The return label only can be associated to a RETURN call,
148  however the controlizer does not follow this consistency
149  rule. */
150  fprintf(stderr, "%s\n", statement_identification(s));
151  }
152  else
153  print_statement(s);
154 }
155 
157 {
160  print_statement(s);
162  free(cstyle);
163 }
164 ␌
165 /* A simplified version of find_last_statement() located in
166  * prettyprint.c and designed to be used within the prettyprinter
167  */
169 {
171 
172  pips_assert("statement is defined", !statement_undefined_p(s));
173 
174  if(statement_sequence_p(s)) {
176 
177  last = (ENDP(ls)? statement_undefined :
179  }
180  else if(statement_unstructured_p(s)) {
182  list trail = unstructured_to_trail(u);
183 
184  last = control_statement(CONTROL(CAR(trail)));
185 
186  gen_free_list(trail);
187  }
188  else if(statement_call_p(s)) {
189  /* Hopefully it is a return statement.
190  * Since the semantics of STOP is ignored by the parser, a
191  * final STOp should be followed by a RETURN.
192  */
193  last = s;
194  }
195  else if(statement_goto_p(s))
196  last = s;
197  else if(statement_expression_p(s))
198  last = s;
199  else if(statement_loop_p(s))
200  last = s;
201  else if(statement_whileloop_p(s))
202  last = s;
203  else if(statement_forloop_p(s))
204  last = s;
205 
206  return last;
207 }
208 
210 {
211  HASH_MAP(number, stmt, {
212  fprintf(stderr,"%td\t", (_int) number);
214  }, nts);
215 }
216 
217 
219 {
220  string answer = string_undefined;
221  do {
222  while( string_undefined_p(answer) || empty_string_p(answer) )
223  {
224  user_log("Do you want to pick the following statement ?\n"
225  "*********************************************\n");
226  print_statement(s);
227 
228  answer = user_request(
229  "*********************************************\n"
230  "[y/n] ?"
231  );
232  if( !answer ) pips_user_error("you did not answer !\n");
233  }
234  if( answer[0]!='y' && answer[0]!='n' )
235  {
236  pips_user_warning("answer by 'y' or 'n' !\n");
237  free(answer);
238  answer=string_undefined;
239  }
240  } while(string_undefined_p(answer));
241  bool pick = answer[0]=='y';
242  if(pick) {
243  *l=CONS(STATEMENT,s,*l);
244  return false;
245  }
246  else if( !ENDP(*l) )
247  gen_recurse_stop(NULL);
248  return true;
249 }
250 
251 /**
252  * prompt the user to select contiguous statement in s
253  *
254  * @param s statement to search into
255  *
256  * @return list of selected statement
257  */
259 {
260  list l =NIL;
262  return gen_nreverse(l);
263 }
void user_log(const char *format,...)
Definition: message.c:234
void free_text(text p)
Definition: text.c:74
static hash_table nts
Definition: prettyprint.c:63
bool empty_string_p(const char *s)
Definition: entity_names.c:239
char * get_string_property(const char *)
#define gen_context_recurse(start, ctxt, domain_number, flt, rwt)
Definition: genC.h:285
void free(void *)
void reset_current_module_entity(void)
Reset the current module entity.
Definition: static.c:97
void push_current_module_statement(statement)
Set the statement of the current module and push the statement of the previous one on a stack.
Definition: static.c:180
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
void pop_current_module_statement(void)
Pop the current module statement stack and use it as the current module statement.
Definition: static.c:194
void gen_recurse_stop(void *obj)
Tells the recursion not to go in this object.
Definition: genClib.c:3251
void gen_null2(__attribute__((unused)) void *u1, __attribute__((unused)) void *u2)
idem with 2 args, to please overpeaky compiler checks
Definition: genClib.c:2758
#define ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66
list gen_nreverse(list cp)
reverse a list in place
Definition: list.c:304
#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
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
void gen_free_list(list l)
free the spine of the list
Definition: list.c:327
list gen_last(list l)
Return the last element of a list.
Definition: list.c:578
#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
unstructured statement_unstructured(statement s)
Get the unstructured of a statement.
Definition: statement.c:1416
bool statement_expression_p(statement s)
Definition: statement.c:384
bool statement_goto_p(statement s)
Definition: statement.c:359
bool statement_whileloop_p(statement s)
Definition: statement.c:354
bool statement_call_p(statement s)
Definition: statement.c:364
bool statement_forloop_p(statement s)
Definition: statement.c:374
bool statement_loop_p(statement s)
Definition: statement.c:349
bool statement_sequence_p(statement s)
Statement classes induced from instruction type.
Definition: statement.c:335
bool statement_unstructured_p(statement s)
Definition: statement.c:369
string statement_identification(statement s)
Like external_statement_identification(), but with internal information, the hexadecimal address of t...
Definition: statement.c:1700
bool continue_statement_p(statement s)
Test if a statement is a CONTINUE, that is the FORTRAN nop, the ";" in C or the "pass" in Python....
Definition: statement.c:203
#define debug_on(env)
Definition: misc-local.h:157
#define pips_user_warning
Definition: misc-local.h:146
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define debug_off()
Definition: misc-local.h:160
#define pips_user_error
Definition: misc-local.h:147
string user_request(const char *,...)
#define HASH_MAP(k, v, code, ht)
Definition: newgen_hash.h:60
#define SET_MAP(element, code, the_set)
Definition: newgen_set.h:54
#define string_undefined
Definition: newgen_types.h:40
#define string_undefined_p(s)
Definition: newgen_types.h:41
intptr_t _int
_INT
Definition: newgen_types.h:53
void set_alternate_return_set()
Definition: misc.c:795
void reset_alternate_return_set()
Definition: misc.c:804
void fprint_statement(FILE *fd, statement s)
Print statement "s" on file descriptor "fd".
Definition: statement.c:68
void print_statement(statement s)
Print a statement on stderr.
Definition: statement.c:98
static bool find_statements_interactively_walker(statement s, list *l)
Definition: statement.c:218
void print_statement_of_module(statement s, const char *mn)
Definition: statement.c:111
void print_statement_set(FILE *fd, set r)
statement.c
Definition: statement.c:49
void print_parallel_statement(statement s)
Definition: statement.c:156
void print_number_to_statement(hash_table nts)
Definition: statement.c:209
void print_statements(list sl)
Definition: statement.c:103
void safe_print_statement(statement s)
Definition: statement.c:140
list find_statements_interactively(statement s)
prompt the user to select contiguous statement in s
Definition: statement.c:258
statement last_statement(statement s)
A simplified version of find_last_statement() located in prettyprint.c and designed to be used within...
Definition: statement.c:168
text statement_to_text(statement s)
Definition: statement.c:124
text text_statement(entity, int, statement, list *)
list unstructured_to_trail(unstructured)
Definition: unstructured.c:240
#define PRETTYPRINT_PARALLEL
void set_string_property(const char *, const char *)
#define instruction_block(i)
bool entity_return_label_p(entity e)
Definition: entity.c:673
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 reset_label_counter()
Definition: entity.c:322
#define statement_domain
newgen_sizeofexpression_domain_defined
Definition: ri.h:362
#define CONTROL(x)
CONTROL.
Definition: ri.h:910
#define statement_label(x)
Definition: ri.h:2450
#define entity_undefined_p(x)
Definition: ri.h:2762
#define entity_undefined
Definition: ri.h:2761
#define statement_domain_number(x)
Definition: ri.h:2448
#define statement_instruction(x)
Definition: ri.h:2458
#define control_statement(x)
Definition: ri.h:941
#define statement_undefined_p(x)
Definition: ri.h:2420
#define statement_number(x)
Definition: ri.h:2452
#define statement_undefined
Definition: ri.h:2419
#define STATEMENT(x)
STATEMENT.
Definition: ri.h:2413
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
char * strdup()
FI: I do not understand why the type is duplicated at the set level.
Definition: set.c:59
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
Definition: statement.c:54
void print_text(FILE *fd, text t)
Definition: print.c:195
#define text_undefined
Definition: text.h:91