PIPS
eval.c File Reference
#include "genC.h"
#include "linear.h"
#include "ri.h"
#include "parser_private.h"
#include "syntax.h"
#include "toklex.h"
+ Include dependency graph for eval.c:

Go to the source code of this file.

Functions

value EvalExpression (expression e)
 lint More...
 
value EvalSyntax (syntax s)
 
value EvalCall (call c)
 only calls to constant, symbolic or intrinsic functions might be evaluated. More...
 
value EvalConstant (ant c) const
 
value EvalIntrinsic (entity e, cons *la)
 this function tries to evaluate a call to an intrinsic function. More...
 
value EvalUnaryOp (int t, cons *la)
 
value EvalBinaryOp (int t, cons *la)
 
int IsUnaryOperator (entity e)
 
int IsBinaryOperator (entity e)
 FI: These string constants are defined in ri-util.h and the tokens in ri-util/operator.h. More...
 
int ipow (int vg, int vd)
 FI: such a function should exist in Linear/arithmetique. More...
 

Variables

char vcid_syntax_eval [] = "%A% ($Date: 1998/04/14 21:28:15 $, ) version $Revision: 16236 $, got on %D%, %T% [%P%].\n Copyright (c) École des Mines de Paris Proprietary."
 

Function Documentation

◆ EvalBinaryOp()

value EvalBinaryOp ( int  t,
cons la 
)

Definition at line 195 of file eval.c.

198 {
199  value v;
200  int argl, argr;
201 
202  pips_assert("EvalBinaryOpt", la != NIL);
203  v = EvalExpression(EXPRESSION(CAR(la)));
205  argl = constant_int(value_constant(v));
206  gen_free(v);
207  }
208  else
209  return(v);
210 
211  la = CDR(la);
212  pips_assert("EvalBinaryOpt", la != NIL);
213  v = EvalExpression(EXPRESSION(CAR(la)));
215  argr = constant_int(value_constant(v));
216  }
217  else
218  return(v);
219 
220  switch (t) {
221  case TK_MINUS:
222  constant_int(value_constant(v)) = argl-argr;
223  break;
224  case TK_PLUS:
225  constant_int(value_constant(v)) = argl+argr;
226  break;
227  case TK_STAR:
228  constant_int(value_constant(v)) = argl*argr;
229  break;
230  case TK_SLASH:
231  if (argr != 0)
232  constant_int(value_constant(v)) = argl/argr;
233  else
234  FatalError("EvalBinaryOp", "zero divide\n");
235  break;
236  case TK_POWER:
237  if (argr >= 0)
238  constant_int(value_constant(v)) = ipow(argl,argr);
239  else {
240  gen_free(v);
241  v = make_value_unknown();
242  }
243  break;
244  default:
245  debug(9, "EvalBinaryOp", "pas encore d'evaluation\n");
246  gen_free(v);
247  v = make_value_unknown();
248  }
249 
250  return(v);
251 }
value make_value_unknown(void)
Definition: ri.c:2847
void gen_free(gen_chunk *obj)
version without shared_pointers.
Definition: genClib.c:992
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
#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
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
void debug(const int the_expected_debug_level, const char *calling_function_name, const char *a_message_format,...)
ARARGS0.
Definition: debug.c:189
value EvalExpression(expression e)
Evaluate statically an expression.
Definition: eval.c:108
int ipow(int vg, int vd)
FI: such a function should exist in Linear/arithmetique.
Definition: eval.c:769
#define value_constant(x)
Definition: ri.h:3073
#define constant_int(x)
Definition: ri.h:850
#define value_constant_p(x)
Definition: ri.h:3071
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
#define constant_int_p(x)
Definition: ri.h:848
#define TK_STAR
Definition: splitc.c:812
#define TK_SLASH
Definition: splitc.c:813
#define TK_PLUS
Definition: splitc.c:810
#define TK_MINUS
Definition: splitc.c:811
#define TK_POWER
Definition: syn_yacc.c:363
#define FatalError(f, m)
Definition: syntax-local.h:56

References CAR, CDR, constant_int, constant_int_p, debug(), EvalExpression(), EXPRESSION, FatalError, gen_free(), ipow(), make_value_unknown(), NIL, pips_assert, TK_MINUS, TK_PLUS, TK_POWER, TK_SLASH, TK_STAR, value_constant, and value_constant_p.

+ Here is the call graph for this function:

◆ EvalCall()

value EvalCall ( call  c)

only calls to constant, symbolic or intrinsic functions might be evaluated.

recall that intrinsic functions are not known.

it might be an intrinsic function

Definition at line 95 of file eval.c.

97 {
98  value vout, vin;
99  entity f;
100 
101  f = call_function(c);
102  vin = entity_initial(f);
103 
104  switch (value_tag(vin)) {
105  case is_value_intrinsic:
106  vout = EvalIntrinsic(f, call_arguments(c));
107  break;
108  case is_value_constant:
109  vout = EvalConstant((value_constant(vin)));
110  break;
111  case is_value_symbolic:
113  break;
114  case is_value_unknown:
115  /* it might be an intrinsic function */
116  vout = EvalIntrinsic(f, call_arguments(c));
117  break;
118  case is_value_code:
119  vout = make_value_unknown();
120  break;
121  default:
122  ParserError("EvalCall", "case default\n");
123  }
124 
125  return(vout);
126 }
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15
value EvalConstant(constant c)
Constant c is returned as field of value v.
Definition: eval.c:235
value EvalIntrinsic(entity e, list la)
This function tries to evaluate a call to an intrinsic function.
Definition: eval.c:290
#define value_tag(x)
Definition: ri.h:3064
#define call_function(x)
Definition: ri.h:709
#define symbolic_constant(x)
Definition: ri.h:2599
@ is_value_intrinsic
Definition: ri.h:3034
@ is_value_unknown
Definition: ri.h:3035
@ is_value_constant
Definition: ri.h:3033
@ is_value_code
Definition: ri.h:3031
@ is_value_symbolic
Definition: ri.h:3032
#define value_symbolic(x)
Definition: ri.h:3070
#define call_arguments(x)
Definition: ri.h:711
#define entity_initial(x)
Definition: ri.h:2796
bool ParserError(const char *f, const char *m)
Definition: parser.c:116

References call_arguments, call_function, entity_initial, EvalConstant(), EvalIntrinsic(), f(), is_value_code, is_value_constant, is_value_intrinsic, is_value_symbolic, is_value_unknown, make_value_unknown(), ParserError(), symbolic_constant, value_constant, value_symbolic, and value_tag.

+ Here is the call graph for this function:

◆ EvalConstant()

value EvalConstant ( ant  c) const

Definition at line 130 of file eval.c.

132 {
133  return((constant_int_p(c)) ?
135  constant_int(c))) :
137 }
constant make_constant(enum constant_utype tag, void *val)
Definition: ri.c:406
value make_value(enum value_utype tag, void *val)
Definition: ri.c:2832
value MakeValueLitteral()
Definition: bootstrap.c:5680
@ is_constant_int
Definition: ri.h:817

References constant_int, constant_int_p, is_constant_int, is_value_constant, make_constant(), make_value(), and MakeValueLitteral().

+ Here is the call graph for this function:

◆ EvalExpression()

value EvalExpression ( expression  e)

lint

cproto-generated files

This file contains a set of functions to evaluate integer constant expressions. The algorithm is built on a recursive analysis of the expression structure. Lower level functions are called until basic atoms are reached. The succes of basic atom evaluation depend on the atom type:

reference: right now, the evaluation fails because we do not compute predicates on variables.

call: a call to a user function is not evaluated. a call to an intrinsic function is successfully evaluated if arguments can be evaluated. a call to a constant function is evaluated if its basic type is integer.

range: a range is not evaluated.

Definition at line 55 of file eval.c.

57 {
58  return(EvalSyntax(expression_syntax(e)));
59 }
value EvalSyntax(syntax s)
Definition: eval.c:113
#define expression_syntax(x)
Definition: ri.h:1247

References EvalSyntax(), and expression_syntax.

+ Here is the call graph for this function:

◆ EvalIntrinsic()

value EvalIntrinsic ( entity  e,
cons la 
)

this function tries to evaluate a call to an intrinsic function.

right now, we only try to evaluate unary and binary intrinsic functions, ie. fortran operators.

e is the intrinsic function.

la is the list of arguments.

Definition at line 150 of file eval.c.

153 {
154  value v;
155  int token;
156 
157  if ((token = IsUnaryOperator(e)) > 0)
158  v = EvalUnaryOp(token, la);
159  else if ((token = IsBinaryOperator(e)) > 0)
160  v = EvalBinaryOp(token, la);
161  else
162  v = make_value_unknown();
163 
164  return(v);
165 }
int IsUnaryOperator(entity e)
Definition: eval.c:632
value EvalBinaryOp(int t, list la)
t defines the operator and la is a list to two sub-expressions.
Definition: eval.c:385
value EvalUnaryOp(int t, list la)
Definition: eval.c:349
int IsBinaryOperator(entity e)
FI: These string constants are defined in ri-util.h and the tokens in ri-util/operator....
Definition: eval.c:660

References EvalBinaryOp(), EvalUnaryOp(), IsBinaryOperator(), IsUnaryOperator(), and make_value_unknown().

+ Here is the call graph for this function:

◆ EvalSyntax()

value EvalSyntax ( syntax  s)

Is it a reference to a const variable?

SG: sizeof is architecture dependant, it is better not to evaluate it by default

Definition at line 63 of file eval.c.

65 {
66  value v;
67 
68  switch (syntax_tag(s)) {
70  case is_syntax_range:
71  v = make_value_unknown();
72  break;
73  case is_syntax_call:
74  v = EvalCall((syntax_call(s)));
75  break;
76  case is_syntax_cast:
80  case is_syntax_va_arg:
81  v = make_value_unknown();
82  break;
83  default:
84  ParserError("EvalExpression", "cas default\n");
85  }
86 
87  return(v);
88 }
value EvalCall(call c)
only calls to constant, symbolic or intrinsic functions might be evaluated.
Definition: eval.c:170
#define syntax_tag(x)
Definition: ri.h:2727
@ is_syntax_range
Definition: ri.h:2692
@ is_syntax_application
Definition: ri.h:2697
@ is_syntax_cast
Definition: ri.h:2694
@ is_syntax_call
Definition: ri.h:2693
@ is_syntax_va_arg
Definition: ri.h:2698
@ is_syntax_reference
Definition: ri.h:2691
@ is_syntax_sizeofexpression
Definition: ri.h:2695
@ is_syntax_subscript
Definition: ri.h:2696
#define syntax_call(x)
Definition: ri.h:2736

References EvalCall(), is_syntax_application, is_syntax_call, is_syntax_cast, is_syntax_range, is_syntax_reference, is_syntax_sizeofexpression, is_syntax_subscript, is_syntax_va_arg, make_value_unknown(), ParserError(), syntax_call, and syntax_tag.

+ Here is the call graph for this function:

◆ EvalUnaryOp()

value EvalUnaryOp ( int  t,
cons la 
)

Definition at line 169 of file eval.c.

172 {
173  value vout, v;
174  int arg;
175 
176  pips_assert("EvalUnaryOpt", la != NIL);
177  v = EvalExpression(EXPRESSION(CAR(la)));
179  arg = constant_int(value_constant(v));
180  else
181  return(v);
182 
183  if (t == TK_MINUS) {
184  constant_int(value_constant(v)) = -arg;
185  vout = v;
186  }
187  else {
188  gen_free(v);
189  vout = make_value_unknown();
190  }
191 
192  return(vout);
193 }

References CAR, constant_int, constant_int_p, EvalExpression(), EXPRESSION, gen_free(), make_value_unknown(), NIL, pips_assert, TK_MINUS, value_constant, and value_constant_p.

+ Here is the call graph for this function:

◆ ipow()

int ipow ( int  vg,
int  vd 
)

FI: such a function should exist in Linear/arithmetique.

FI: should it return a long long int?

FI: see arithmetique library

Parameters
vgg
vdd

Definition at line 315 of file eval.c.

317 {
318  /* FI: see arithmetique library */
319  int i = 1;
320 
321  pips_assert("ipow", vd >= 0);
322 
323  while (vd-- > 0)
324  i *= vg;
325 
326  return(i);
327 }

References pips_assert.

◆ IsBinaryOperator()

int IsBinaryOperator ( entity  e)

FI: These string constants are defined in ri-util.h and the tokens in ri-util/operator.h.

Definition at line 272 of file eval.c.

274 {
275  int token;
276 
277  if (strcmp(entity_local_name(e), "-") == 0)
278  token = TK_MINUS;
279  else if (strcmp(entity_local_name(e), "+") == 0)
280  token = TK_PLUS;
281  else if (strcmp(entity_local_name(e), "*") == 0)
282  token = TK_STAR;
283  else if (strcmp(entity_local_name(e), "/") == 0)
284  token = TK_SLASH;
285  else if (strcmp(entity_local_name(e), "**") == 0)
286  token = TK_POWER;
287  else if (strcmp(entity_local_name(e), ".EQ.") == 0)
288  token = TK_EQ;
289  else if (strcmp(entity_local_name(e), ".NE.") == 0)
290  token = TK_NE;
291  else if (strcmp(entity_local_name(e), ".EQV") == 0)
292  token = TK_EQV;
293  else if (strcmp(entity_local_name(e), ".NEQV") == 0)
294  token = TK_NEQV;
295  else if (strcmp(entity_local_name(e), ".GT.") == 0)
296  token = TK_GT;
297  else if (strcmp(entity_local_name(e), ".LT.") == 0)
298  token = TK_LT;
299  else if (strcmp(entity_local_name(e), ".GE.") == 0)
300  token = TK_GE;
301  else if (strcmp(entity_local_name(e), ".LE.") == 0)
302  token = TK_LE;
303  else if (strcmp(entity_local_name(e), ".OR.") == 0)
304  token = TK_OR;
305  else if (strcmp(entity_local_name(e), ".AND.") == 0)
306  token = TK_AND;
307  else
308  token = -1;
309 
310  return(token);
311 }
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
#define TK_EQ
Definition: splitc.c:791
#define TK_AND
Definition: splitc.c:816
#define TK_GT
Definition: syn_yacc.c:345
#define TK_EQV
Definition: syn_yacc.c:343
#define TK_NEQV
Definition: syn_yacc.c:349
#define TK_GE
Definition: syn_yacc.c:344
#define TK_LT
Definition: syn_yacc.c:347
#define TK_LE
Definition: syn_yacc.c:346
#define TK_NE
Definition: syn_yacc.c:348
#define TK_OR
Definition: syn_yacc.c:351

References entity_local_name(), TK_AND, TK_EQ, TK_EQV, TK_GE, TK_GT, TK_LE, TK_LT, TK_MINUS, TK_NE, TK_NEQV, TK_OR, TK_PLUS, TK_POWER, TK_SLASH, and TK_STAR.

+ Here is the call graph for this function:

◆ IsUnaryOperator()

int IsUnaryOperator ( entity  e)

Definition at line 255 of file eval.c.

257 {
258  int token;
259 
260  if (strcmp(entity_local_name(e), "--") == 0)
261  token = TK_MINUS;
262  else if (strcmp(entity_local_name(e), ".NOT.") == 0)
263  token = TK_NOT;
264  else
265  token = -1;
266 
267  return(token);
268 }
#define TK_NOT
Definition: syn_yacc.c:350

References entity_local_name(), TK_MINUS, and TK_NOT.

+ Here is the call graph for this function:

Variable Documentation

◆ vcid_syntax_eval

char vcid_syntax_eval[] = "%A% ($Date: 1998/04/14 21:28:15 $, ) version $Revision: 16236 $, got on %D%, %T% [%P%].\n Copyright (c) École des Mines de Paris Proprietary."

Definition at line 29 of file eval.c.