PIPS
flint_utils.c
Go to the documentation of this file.
1 /*
2 
3  $Id: flint_utils.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 /*
28  * flint_utils.c
29  *
30  *
31  * updated utils coming from size.c, eval.c, expression.c, constant.c used by
32  * flint_check...
33  *
34  * L. Aniort and F. Coelho 1992
35  *
36  */
37 /*************************************************************************/
38 
39 #include "local.h"
40 
41 /* Print error message and exit from flint */
42 #define FATAL(msg,value) {fprintf(stderr,msg,value);exit(1);}
43 
44 /*************************************************************************/
45 /*
46  * this function computes the number of elements of a variable. ld is the
47  * list of dimensions of the variable
48  */
49 
50 bool number_of_elements(ld, the_result)
51  list ld;
52  intptr_t *the_result;
53 {
54  list pc;
55  intptr_t a_temp_int;
56  bool ok = true;
57 
58  (*the_result) = 1;
59 
60  for (pc = ld;
61  (pc != NULL) && (ok = size_of_dimension(DIMENSION(CAR(pc)), &a_temp_int));
62  pc = CDR(pc)) {
63  (*the_result) *= a_temp_int;
64  }
65 
66  return (ok);
67 }
68 /*************************************************************************/
69 /* this function computes the size of a dimension. */
70 
71 bool size_of_dimension(d, the_int)
72  dimension d;
73  intptr_t *the_int;
74 {
75  intptr_t upper_dim, lower_dim;
76 
77  if (expression_integer_value(dimension_upper(d), &upper_dim) &&
78  expression_integer_value(dimension_lower(d), &lower_dim)) {
79  (*the_int) = upper_dim - lower_dim + 1;
80  return (true);
81  }
82  /* else */
83  return (false);
84 }
85 /*************************************************************************/
86 
87 /*
88  * some tools to deal with basics and dimensions each function is looking for
89  * a basic & a dimension if not found, it replies false if found, that's
90  * TRUE. read find_bd_ as "find basic and dimensions" and not find comics!
91  */
92 
93 bool
95  int __attribute__ ((unused)) a_dim,
97 {
98  basic b;
99  list d;
100  intptr_t n;
101  bool ok_dim = false, ok = find_bd_expression(exp, &b, &d);
102 
103  if (ok)
104  ok_dim = number_of_elements(d, &n);
105 
106  if (ok && ok_dim)
107  return ((basic_tag(b) == a_basic) && (n = 1));
108 
109  /* else */
110 
111  flint_message("control type in expression",
112  "warning : cannot verify the type\n");
113  return (true);
114 }
115 /*******************************************/
118  basic *base;
119  list *dims;
120 {
121  type tp = parameter_type(param);
122  return (find_bd_type_variable(tp, base, dims));
123 }
124 /*******************************************/
126  type tp;
127  basic *base;
128  list *dims;
129 {
130  if (!type_variable_p(tp)) {
131  flint_message("find_bd_type_var",
132  "very strange type encountered, waiting for a variable\n");
133  return (false);
134  }
136  *dims = variable_dimensions(type_variable(tp));
137 
138  return (true);
139 }
140 /*******************************************/
142  expression exp;
143  basic *base;
144  list *dims;
145 {
147  reference re;
148  call c;
149 
150  switch (syntax_tag(s)) {
151  case is_syntax_reference:
152  re = syntax_reference(s);
153  return (find_bd_reference(re, base, dims));
154  case is_syntax_range:
155  flint_message("find_bd_expression", "no basic in this expression\n");
156  return (false);
157  case is_syntax_call:
158  c = syntax_call(s);
159  return (find_bd_call(c, base, dims));
160  default:
161  FATAL("find_bd_expression : unexpected tag %u\n", syntax_tag(s));
162  }
163 
164  return (false);
165 }
166 /*******************************************/
168  reference ref;
169  basic *base;
170  list *dims;
171 {
173  list ind = reference_indices(ref);
174  type tp = entity_type(var);
175  int len_ind = gen_length(ind), len_dim, i;
176  bool ok;
177 
178  ok = find_bd_type_variable(tp, base, dims);
179  if (!ok)
180  return (false);
181 
182  len_dim = gen_length((*dims));
183  if (len_dim < len_ind)
184  return (false);
185 
186  for (i = 1; i <= len_ind; i++)
187  (*dims) = CDR(*dims);
188  return (true);
189 }
190 /*******************************************/
191 bool find_bd_call(c, base, dims)
192  call c;
193  basic *base;
194  list *dims;
195 {
196  entity fct = call_function(c);
197  type tp = entity_type(fct);
198 
199  if (!type_functional_p(tp)) {
200  flint_message("find_bd_call",
201  "very strange function encountered\n");
202  return (false);
203  }
205 }
206 
207 /*************************************************************************/
208 /* End of File */
float a2sf[2] __attribute__((aligned(16)))
USER generates a user error (i.e., non fatal) by printing the given MSG according to the FMT.
Definition: 3dnow.h:3
static reference ref
Current stmt (an integer)
Definition: adg_read_paf.c:163
bdt base
Current expression.
Definition: bdt_read_paf.c:100
void flint_message(char *fun, char *fmt,...)
Definition: flint.c:147
bool size_of_dimension(dimension d, intptr_t *the_int)
this function computes the size of a dimension.
Definition: flint_utils.c:71
bool find_bd_type_variable(type tp, basic *base, list *dims)
Definition: flint_utils.c:125
#define FATAL(msg, value)
Print error message and exit from flint.
Definition: flint_utils.c:42
bool find_bd_parameter(parameter param, basic *base, list *dims)
Definition: flint_utils.c:116
bool find_bd_expression(expression exp, basic *base, list *dims)
Definition: flint_utils.c:141
bool find_bd_call(call c, basic *base, list *dims)
Definition: flint_utils.c:191
bool control_type_in_expression(enum basic_utype a_basic, int __attribute__((unused)) a_dim, expression exp)
Definition: flint_utils.c:94
bool find_bd_reference(reference ref, basic *base, list *dims)
Definition: flint_utils.c:167
bool number_of_elements(list ld, intptr_t *the_result)
flint_utils.c
Definition: flint_utils.c:50
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
#define CDR(pcons)
Get the list less its first element.
Definition: newgen_list.h:111
bool expression_integer_value(expression e, intptr_t *pval)
Definition: eval.c:792
#define type_functional_p(x)
Definition: ri.h:2950
basic_utype
Definition: ri.h:570
#define functional_result(x)
Definition: ri.h:1444
#define parameter_type(x)
Definition: ri.h:1819
#define syntax_reference(x)
Definition: ri.h:2730
#define syntax_tag(x)
Definition: ri.h:2727
#define call_function(x)
Definition: ri.h:709
#define reference_variable(x)
Definition: ri.h:2326
#define type_functional(x)
Definition: ri.h:2952
#define dimension_lower(x)
Definition: ri.h:980
#define basic_tag(x)
Definition: ri.h:613
#define type_variable(x)
Definition: ri.h:2949
@ is_syntax_range
Definition: ri.h:2692
@ is_syntax_call
Definition: ri.h:2693
@ is_syntax_reference
Definition: ri.h:2691
#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 variable_dimensions(x)
Definition: ri.h:3122
#define entity_type(x)
Definition: ri.h:2792
#define expression_syntax(x)
Definition: ri.h:1247
#define type_variable_p(x)
Definition: ri.h:2947
#define variable_basic(x)
Definition: ri.h:3120
static bool ok
#define intptr_t
Definition: stdint.in.h:294
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
Definition: replace.c:135
#define exp
Avoid some warnings from "gcc -Wshadow".
Definition: vasnprintf.c:207