PIPS
flint_walk.c
Go to the documentation of this file.
1 /*
2 
3  $Id: flint_walk.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 /* This file contains a set of functions defined to walk through the
28  * internal representation of a module and chek different things, as the
29  * number of arguments, the compatibility of the types of these arguments,
30  * ... There is one function for each domain. Its basic principle is to
31  * walk through the internal representation by recursive calls to
32  * functions handling sub-domains.
33  *
34  * Laurent Aniort & Fabien Coelho 1992
35  */
36 
37 #include "local.h"
38 
39 /************************************************************/
40 
41 /* Print message and exit violently from flint */
42 #define FATAL(msg,value) {fprintf(stderr,msg,value);exit(1);}
43 
44 /************************************************************/
45 /* The only global variable : the name of the current module */
46 /* extern char *current_module_name; unused and changed */
47 
48 /************************************************************/
49 /* These two functions deal with the boundaries of finite */
50 /* arrays, verifying their definition as expressions */
51 
53  list pc;
54 {
56 }
57 
59  dimension d;
60 {
63 
64  flint_expression(el);
65  flint_expression(eu);
66 
67  return (d);
68 }
69 
70 /************************************************************/
71 /* This function checks the syntax of a call and recursively */
72 /* verifies its arguments */
73 
75  call c;
76 {
77  list la = call_arguments(c);
78 
79  check_the_call(c);
80 
82 
83  return (c);
84 }
85 /************************************************************/
86 /* This function verifies that incremented or decremented */
87 /* loop(for) indices do not overflow or underflow their */
88 /* limits */
89 
91  range r;
92 {
93  expression el = range_lower(r);
94  expression eu = range_upper(r);
96 
97  flint_expression(el);
98  flint_expression(eu);
99  flint_expression(ei);
100 
101  return (r);
102 }
103 /************************************************************/
104 /* A reference is used when given a function the address of */
105 /* an element instead of its value. */
106 
108  reference r;
109 {
110  list pc = reference_indices(r);
111 
112  (void) check_the_reference(r);
113 
115 
116  return (r);
117 }
118 /************************************************************/
119 /* verification of syntaxes */
120 
122  syntax s;
123 {
124  reference re;
125  range ra;
126  call c;
127 
128  /* branch according to the syntax subclass */
129  switch (syntax_tag(s)) {
130  case is_syntax_reference:
131  re = syntax_reference(s);
132  flint_reference(re);
133  break;
134  case is_syntax_range:
135  ra = syntax_range(s);
136  flint_range(ra);
137  break;
138  case is_syntax_call:
139  c = syntax_call(s);
140  flint_call(c);
141  break;
142  default:
143  FATAL("flint_syntax: unexpected tag %u\n", syntax_tag(s));
144  }
145 }
146 
147 /************************************************************/
148 /* These two functions operate on the list of expressions */
149 
151  list pc;
152 {
154 }
155 
156 
157 void
159 {
160  expression e = EXPRESSION(CAR(pc));
161 
162  /* An array actual argument may have no indices */
163  if(expression_reference_p(e)) {
165 
166  if(gen_length(reference_indices(r))!=0)
167  flint_expression(e);
168  }
169  else {
170  flint_expression(e);
171  }
172 }
173 
175  expression e;
176 {
177  syntax s = expression_syntax(e);
178 
179  flint_syntax(s);
180 
181  return (e);
182 }
183 /************************************************************/
184 /* Recursive verification of a loop as (range)+(expression) */
185 
187  loop l;
188 {
189  range r = loop_range(l);
190  statement s = loop_body(l);
191 
192  flint_range(r);
193  flint_statement(s);
194 
195  return (l);
196 }
197 /************************************************************/
198 /* A test is taken as (expression)+(statement)+(statement) */
199 
201  test t;
202 {
203  expression e = test_condition(t);
204  statement st = test_true(t);
205  statement sf = test_false(t);
206 
207  flint_expression(e);
208  flint_statement(st);
209  flint_statement(sf);
210 
211  return (t);
212 }
213 /************************************************************/
214 /* Verification of an instruction with branching according */
215 /* to its subclass as defined in the data structure */
216 
218 instruction i;
219 {
220  list pc;
221  test t;
222  loop l;
223  call c;
224  unstructured u;
225 
226  switch (instruction_tag(i)) {
228  pc = instruction_block(i);
230  break;
231  case is_instruction_test:
232  t = instruction_test(i);
233  flint_test(t);
234  break;
235  case is_instruction_loop:
236  l = instruction_loop(i);
237  flint_loop(l);
238  break;
239  case is_instruction_goto:
240  break;
244  break;
245  case is_instruction_call:
246  c = instruction_call(i);
247  (void) check_procedure(c);
248  flint_call(c);
249  break;
250  default:
251  FATAL("flint_instruction: unexpected tag %u\n", instruction_tag(i));
252  }
253 
254  return (i);
255 }
256 /************************************************************/
258  unstructured u;
259 {
260  list blocs = NIL;
261 
262  CONTROL_MAP(c, {
264  }, unstructured_control(u), blocs);
265 
266  gen_free_list(blocs);
267 }
268 /************************************************************/
270  list pc;
271 {
273 }
274 
275 extern statement
277 
279 statement s;
280 {
281  instruction
282  i = statement_instruction(s);
283  statement
284  saved = flint_current_statement;
285 
287 
289 
290  flint_current_statement = saved;
291  return (s);
292 }
293 
294 /************************************************************/
295 /* End of File */
bool check_procedure(call)
flint_check.c
Definition: flint_check.c:88
void check_the_reference(reference)
Definition: flint_check.c:396
bool check_the_call(call)
Definition: flint_check.c:130
dimension flint_dimension(dimension d)
Definition: flint_walk.c:58
void flint_cons_dimension(list pc)
The only global variable : the name of the current module.
Definition: flint_walk.c:52
loop flint_loop(loop l)
Recursive verification of a loop as (range)+(expression)
Definition: flint_walk.c:186
call flint_call(call c)
This function checks the syntax of a call and recursively.
Definition: flint_walk.c:74
statement flint_statement(statement s)
Definition: flint_walk.c:278
expression flint_expression(expression e)
Definition: flint_walk.c:174
void flint_cons_expression(list pc)
These two functions operate on the list of expressions
Definition: flint_walk.c:150
reference flint_reference(reference r)
A reference is used when given a function the address of.
Definition: flint_walk.c:107
test flint_test(test t)
A test is taken as (expression)+(statement)+(statement)
Definition: flint_walk.c:200
#define FATAL(msg, value)
This file contains a set of functions defined to walk through the internal representation of a module...
Definition: flint_walk.c:42
void flint_unstructured(unstructured u)
Definition: flint_walk.c:257
instruction flint_instruction(instruction i)
Verification of an instruction with branching according
Definition: flint_walk.c:217
range flint_range(range r)
This function verifies that incremented or decremented
Definition: flint_walk.c:90
statement flint_current_statement
cproto-generated files
Definition: flint.c:46
void flint_syntax(syntax s)
verification of syntaxes
Definition: flint_walk.c:121
void flint_cons_statement(list pc)
Definition: flint_walk.c:269
void flint_cons_actual_argument(list pc)
Definition: flint_walk.c:158
#define CONTROL_MAP(ctl, code, c, list)
Macro to walk through all the controls reachable from a given control node of an unstructured.
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
size_t gen_length(const list l)
Definition: list.c: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
void gen_mapl(gen_iter_func_t fp, const list l)
MAP.
Definition: list.c:165
void(* gen_iter_func_t)(void *)
Definition: newgen_types.h:116
#define unstructured_control
After the modification in Newgen: unstructured = entry:control x exit:control we have create a macro ...
#define is_instruction_block
soft block->sequence transition
#define instruction_block(i)
bool expression_reference_p(expression e)
Test if an expression is a reference.
Definition: expression.c:528
reference expression_reference(expression e)
Short cut, meaningful only if expression_reference_p(e) holds.
Definition: expression.c:1832
#define loop_body(x)
Definition: ri.h:1644
#define syntax_reference(x)
Definition: ri.h:2730
#define syntax_tag(x)
Definition: ri.h:2727
#define range_upper(x)
Definition: ri.h:2290
#define instruction_loop(x)
Definition: ri.h:1520
#define test_false(x)
Definition: ri.h:2837
#define dimension_lower(x)
Definition: ri.h:980
#define syntax_range(x)
Definition: ri.h:2733
@ is_syntax_range
Definition: ri.h:2692
@ is_syntax_call
Definition: ri.h:2693
@ is_syntax_reference
Definition: ri.h:2691
#define range_increment(x)
Definition: ri.h:2292
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
@ is_instruction_goto
Definition: ri.h:1473
@ is_instruction_unstructured
Definition: ri.h:1475
@ is_instruction_test
Definition: ri.h:1470
@ is_instruction_call
Definition: ri.h:1474
@ is_instruction_loop
Definition: ri.h:1471
#define instruction_tag(x)
Definition: ri.h:1511
#define test_true(x)
Definition: ri.h:2835
#define dimension_upper(x)
Definition: ri.h:982
#define reference_indices(x)
Definition: ri.h:2328
#define syntax_call(x)
Definition: ri.h:2736
#define test_condition(x)
Definition: ri.h:2833
#define range_lower(x)
Definition: ri.h:2288
#define statement_instruction(x)
Definition: ri.h:2458
#define instruction_call(x)
Definition: ri.h:1529
#define loop_range(x)
Definition: ri.h:1642
#define call_arguments(x)
Definition: ri.h:711
#define control_statement(x)
Definition: ri.h:941
#define instruction_test(x)
Definition: ri.h:1517
#define expression_syntax(x)
Definition: ri.h:1247
#define instruction_unstructured(x)
Definition: ri.h:1532
#define STATEMENT(x)
STATEMENT.
Definition: ri.h:2413
The structure used to build lists in NewGen.
Definition: newgen_list.h:41