PIPS
constant.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <math.h>
#include "linear.h"
#include "genC.h"
#include "misc.h"
#include "ri-util.h"
#include "pips-libs.h"
+ Include dependency graph for constant.c:

Go to the source code of this file.

Macros

#define INTEGER_CONSTANT_NAME_CHARS    "0123456789"
 BEGIN_EOLE. More...
 

Functions

int DefaultLengthOfBasic (tag t)
 Deals with constant expressions and constant entities. More...
 
bool integer_constant_name_p (string name)
 
_int TK_CHARCON_to__int (const char *name)
 
entity make_C_or_Fortran_constant_entity (const char *name, tag bt, size_t size, bool is_fortran, bool(*error_manager)(const char *, const char *))
 This function creates a constant. More...
 
static bool constant_error (const char *f, const char *m)
 
entity make_constant_entity (string name, tag bt, size_t size)
 For historical reason, call the Fortran version. More...
 
entity SafeMakeConstant (string name, tag bt, bool(*error_manager)(const char *, const char *))
 END_EOLE. More...
 
entity MakeConstant (string name, tag bt)
 Make a Fortran constant. More...
 
bool constant_string_entity_p (entity e)
 
entity MakeComplexConstant (expression r, expression i)
 make a complex constant from two calls to real or integer constants More...
 
expression MakeComplexConstantExpression (expression r, expression i)
 
bool complex_constant_expression_p (expression cce)
 
entity float_to_entity (float c)
 
entity int_to_entity (_int c)
 
bool logical_constant_p (entity ent)
 
bool float_constant_p (entity ent)
 ent can be either a numerical or a symbolic float constant More...
 
bool integer_constant_p (entity ent, int *int_p)
 Returns the double value associated to a PIPS constant. More...
 
bool integer_symbolic_constant_p (entity ent, int *int_p)
 (*int_p) gets integer constant if any More...
 
expression MakeCharacterConstantExpression (string s)
 END_EOLE. More...
 
value MakeValueSymbolic (expression e)
 this function creates a value for a symbolic constant. More...
 
bool signed_constant_expression_p (expression e)
 
basic constant_basic (entity c)
 
double float_constant_to_double (entity c)
 
bool expression_is_constant_p (expression e)
 BEGIN_EOLE. More...
 

Macro Definition Documentation

◆ INTEGER_CONSTANT_NAME_CHARS

#define INTEGER_CONSTANT_NAME_CHARS    "0123456789"

BEGIN_EOLE.

  • please do not remove this line Lines between BEGIN_EOLE and END_EOLE tags are automatically included in the EOLE project (JZ - 11/98)

Definition at line 80 of file constant.c.

Function Documentation

◆ complex_constant_expression_p()

bool complex_constant_expression_p ( expression  cce)
Parameters
ccece

Definition at line 416 of file constant.c.

417 {
418  bool is_complex_constant_p = false;
419  if(expression_call_p(cce)) {
421  const char* fn = entity_local_name(f);
422 
423  is_complex_constant_p = (strcmp(fn, IMPLIED_COMPLEX_NAME)==0
424  || strcmp(fn, IMPLIED_DCOMPLEX_NAME)==0);
425  }
426 
427  return is_complex_constant_p;
428 }
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15
#define IMPLIED_DCOMPLEX_NAME
Definition: ri-util-local.h:89
#define IMPLIED_COMPLEX_NAME
Definition: ri-util-local.h:88
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
bool expression_call_p(expression e)
Definition: expression.c:415
#define call_function(x)
Definition: ri.h:709
#define syntax_call(x)
Definition: ri.h:2736
#define expression_syntax(x)
Definition: ri.h:1247

References call_function, entity_local_name(), expression_call_p(), expression_syntax, f(), IMPLIED_COMPLEX_NAME, IMPLIED_DCOMPLEX_NAME, and syntax_call.

Referenced by MakeDataValueSet().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ constant_basic()

basic constant_basic ( entity  c)

Definition at line 633 of file constant.c.

634 {
636  return b;
637 }
#define functional_result(x)
Definition: ri.h:1444
#define type_functional(x)
Definition: ri.h:2952
#define type_variable(x)
Definition: ri.h:2949
#define entity_type(x)
Definition: ri.h:2792
#define variable_basic(x)
Definition: ri.h:3120

References entity_type, functional_result, type_functional, type_variable, and variable_basic.

Referenced by constant_constraint_check(), and float_constant_to_double().

+ Here is the caller graph for this function:

◆ constant_error()

static bool constant_error ( const char *  f,
const char *  m 
)
static

Definition at line 287 of file constant.c.

288 {
289  pips_internal_error("%s in function %s\n.", m, f);
290  return true; // Never reached
291 }
#define pips_internal_error
Definition: misc-local.h:149

References f(), and pips_internal_error.

Referenced by MakeConstant().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ constant_string_entity_p()

bool constant_string_entity_p ( entity  e)

Definition at line 356 of file constant.c.

357 {
358  const char * eun = entity_user_name(e);
359  bool first_quote = eun[0]=='"';
360  bool last_quote = eun[strlen(eun)-1] == '"';
361  return first_quote && last_quote;
362 }
const char * entity_user_name(entity e)
Since entity_local_name may contain PIPS special characters such as prefixes (label,...
Definition: entity.c:487

References entity_user_name().

Referenced by entities_maymust_conflict_p(), expression_string_constant_p(), filter_formal_context_according_to_actual_context(), new_filter_formal_context_according_to_actual_context(), and points_to_translation_mapping_is_typed_p().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DefaultLengthOfBasic()

int DefaultLengthOfBasic ( tag  t)

Deals with constant expressions and constant entities.

constant.c

Definition at line 44 of file constant.c.

45 {
46  int e=-1;
47 
48  switch (t) {
50  e = 0;
51  break;
52  case is_basic_int:
54  break;
55  case is_basic_float:
57  break;
58  case is_basic_logical:
60  break;
61  case is_basic_complex:
63  break;
64  case is_basic_string:
66  break;
67  default:
68  pips_internal_error("case default");
69  break;
70  }
71 
72  return(e);
73 }
#define DEFAULT_LOGICAL_TYPE_SIZE
#define DEFAULT_INTEGER_TYPE_SIZE
#define DEFAULT_REAL_TYPE_SIZE
The standard C integer types are represented as follow char = 1 short_int = 2 int = 4 long_int = 6 lo...
#define DEFAULT_COMPLEX_TYPE_SIZE
#define DEFAULT_CHARACTER_TYPE_SIZE
Default type sizes.
@ is_basic_string
Definition: ri.h:576
@ is_basic_float
Definition: ri.h:572
@ is_basic_overloaded
Definition: ri.h:574
@ is_basic_int
Definition: ri.h:571
@ is_basic_logical
Definition: ri.h:573
@ is_basic_complex
Definition: ri.h:575

References DEFAULT_CHARACTER_TYPE_SIZE, DEFAULT_COMPLEX_TYPE_SIZE, DEFAULT_INTEGER_TYPE_SIZE, DEFAULT_LOGICAL_TYPE_SIZE, DEFAULT_REAL_TYPE_SIZE, is_basic_complex, is_basic_float, is_basic_int, is_basic_logical, is_basic_overloaded, is_basic_string, and pips_internal_error.

Referenced by InitImplicit(), MakeFortranType(), and SafeMakeConstant().

+ Here is the caller graph for this function:

◆ expression_is_constant_p()

bool expression_is_constant_p ( expression  e)

BEGIN_EOLE.

  • please do not remove this line Lines between BEGIN_EOLE and END_EOLE tags are automatically included in the EOLE project (JZ - 11/98) whether the given function is a constant expression, whatever the type. FI -> JZ: unsigned numerical constant expression?

Definition at line 666 of file constant.c.

667 {
668  syntax s = expression_syntax(e);
669 
670  return syntax_call_p(s) ?
672 
673 }
#define false
Definition: newgen_types.h:80
#define entity_constant_p(e)
#define syntax_call_p(x)
Definition: ri.h:2734

References call_function, entity_constant_p, expression_syntax, false, syntax_call, and syntax_call_p.

Referenced by gfc2pips_reduce_repeated_values(), handle_set_directive(), and points_to_indices_to_unbounded_indices().

+ Here is the caller graph for this function:

◆ float_constant_p()

bool float_constant_p ( entity  ent)

ent can be either a numerical or a symbolic float constant

In the initial internal representation, only integer constants were distinguished

Parameters
entnt

Definition at line 487 of file constant.c.

488 {
489  bool yes_p = false;
490  type t = entity_type(ent);
491 
492  if( type_functional_p(t))
493  if(value_constant_p(entity_initial(ent))) {
495  yes_p = true;
497  /* In the initial internal representation, only integer
498  constants were distinguished */
500  type rt = functional_result(f); // ultimate type should not be
501  // useful for constants
502  // generated by a parser
503  yes_p = float_type_p(rt);
504  }
505  }
506 
507  return yes_p;
508 }
bool float_type_p(type)
Definition: type.c:3263
#define type_functional_p(x)
Definition: ri.h:2950
#define value_constant(x)
Definition: ri.h:3073
#define constant_float_p(x)
Definition: ri.h:851
#define value_constant_p(x)
Definition: ri.h:3071
#define constant_call_p(x)
Definition: ri.h:860
#define entity_initial(x)
Definition: ri.h:2796

References constant_call_p, constant_float_p, entity_initial, entity_type, f(), float_type_p(), functional_result, type_functional, type_functional_p, value_constant, and value_constant_p.

Referenced by constant_to_transformer(), and simplify_float_constraint().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ float_constant_to_double()

double float_constant_to_double ( entity  c)

Definition at line 639 of file constant.c.

640 {
641  double d = 0.0;
642  int i = 0;
643 
644  pips_assert("entity is constant", entity_constant_p(c));
645  pips_assert("constant is float", basic_float_p(constant_basic(c)));
646 
647  i = sscanf(module_local_name(c), "%lf", &d);
648  if(i!=1)
649  i = sscanf(module_local_name(c), "%le", &d);
650  if(i!=1)
651  i = sscanf(module_local_name(c), "%lg", &d);
652  if(i!=1)
653  pips_internal_error("No adequate format for float constant");
654 
655  return d;
656 }
basic constant_basic(entity c)
Definition: constant.c:633
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
const char * module_local_name(entity e)
Returns the module local user name.
Definition: entity.c:582
#define basic_float_p(x)
Definition: ri.h:617

References basic_float_p, constant_basic(), entity_constant_p, module_local_name(), pips_assert, and pips_internal_error.

Referenced by constant_constraint_check(), constant_to_transformer(), and simplify_float_constraint().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ float_to_entity()

entity float_to_entity ( float  c)

Definition at line 430 of file constant.c.

431 {
432  string num;
433  // FI: non-significant zeroes are printed in num...
434  asprintf(&num, "%f", c);
435  // FI: the period may be skipped when the value is integer and
436  //then, for some unknown reason, semantics interprets this as an
437  //integer value, maybe because of constant = ... + float:int +...
438  //asprintf(&num, "%g", c);
439 
440  // Remove trailing zeroes.
441  string tz = num+strlen(num)-1;
442  while(*tz=='0') {
443  *tz = '\000';
444  tz--;
445  }
446 
448 
449  free(num);
450  return e;
451 }
static int num
Definition: bourdoncle.c:137
entity MakeConstant(string name, tag bt)
Make a Fortran constant.
Definition: constant.c:351
void free(void *)
#define asprintf
Definition: misc-local.h:225

References asprintf, free(), is_basic_float, MakeConstant(), and num.

Referenced by float_to_expression(), simplify_float_constraint(), and string_to_entity().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ int_to_entity()

entity int_to_entity ( _int  c)

Definition at line 453 of file constant.c.

454 {
455  pips_assert("no negative integer entity in pips",c>=0);
456  string num;
457  asprintf(&num, "%d", (int) c);
459  free(num);
460  return e;
461 }

References asprintf, free(), is_basic_int, MakeConstant(), num, and pips_assert.

Referenced by int_to_expression(), partial_eval_syntax(), string_to_entity(), substitute_unbounded_call(), and zero_expression_p().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ integer_constant_name_p()

bool integer_constant_name_p ( string  name)
Parameters
nameame

Definition at line 83 of file constant.c.

84 {
85  return strlen(name)==strspn(name, INTEGER_CONSTANT_NAME_CHARS);
86 }
#define INTEGER_CONSTANT_NAME_CHARS
BEGIN_EOLE.
Definition: constant.c:80

References INTEGER_CONSTANT_NAME_CHARS.

◆ integer_constant_p()

bool integer_constant_p ( entity  ent,
int int_p 
)

Returns the double value associated to a PIPS constant.

A simpler function alreay exists... and is better for litteral constants... BEGIN_EOLE

  • please do not remove this line Lines between BEGIN_EOLE and END_EOLE tags are automatically included in the EOLE project (JZ - 11/98) (*int_p) gets integer constant if any
Parameters
entnt
int_pnt_p

Definition at line 542 of file constant.c.

543 {
548  return(true);
549  }
550  else
551  return(false);
552 }
#define value_tag(x)
Definition: ri.h:3064
#define constant_tag(x)
Definition: ri.h:847
#define type_tag(x)
Definition: ri.h:2940
#define constant_int(x)
Definition: ri.h:850
@ is_constant_int
Definition: ri.h:817
@ is_value_constant
Definition: ri.h:3033
@ is_type_functional
Definition: ri.h:2901

References constant_int, constant_tag, entity_initial, entity_type, is_constant_int, is_type_functional, is_value_constant, type_tag, value_constant, and value_tag.

Referenced by constant_to_transformer(), integer_constant_expression_p(), logical_expression_to_transformer(), partial_eval_call(), and verify_formal_and_common_variables().

+ Here is the caller graph for this function:

◆ integer_symbolic_constant_p()

bool integer_symbolic_constant_p ( entity  ent,
int int_p 
)

(*int_p) gets integer constant if any

Parameters
entnt
int_pnt_p

Definition at line 556 of file constant.c.

557 {
562  return(true);
563  }
564  else
565  return(false);
566 }
#define symbolic_constant(x)
Definition: ri.h:2599
@ is_value_symbolic
Definition: ri.h:3032
#define value_symbolic(x)
Definition: ri.h:3070

References constant_int, constant_tag, entity_initial, entity_type, is_constant_int, is_type_functional, is_value_symbolic, symbolic_constant, type_tag, value_symbolic, and value_tag.

Referenced by integer_constant_expression_p(), and partial_eval_call().

+ Here is the caller graph for this function:

◆ logical_constant_p()

bool logical_constant_p ( entity  ent)

In the initial internal representation, only integer constants were distinguished

Parameters
entnt

Definition at line 463 of file constant.c.

464 {
465  bool yes_p = false;
466  type t = entity_type(ent);
467 
468  if( type_functional_p(t))
469  if(value_constant_p(entity_initial(ent))) {
471  yes_p = true;
473  /* In the initial internal representation, only integer
474  constants were distinguished */
476  type rt = functional_result(f); // ultimate type should not be
477  // useful for constants
478  // generated by a parser
479  yes_p = logical_type_p(rt);
480  }
481  }
482 
483  return yes_p;
484 }
bool logical_type_p(type)
Definition: type.c:2865
#define constant_logical_p(x)
Definition: ri.h:854

References constant_call_p, constant_logical_p, entity_initial, entity_type, f(), functional_result, logical_type_p(), type_functional, type_functional_p, value_constant, and value_constant_p.

Referenced by logical_expression_to_transformer().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ make_C_or_Fortran_constant_entity()

entity make_C_or_Fortran_constant_entity ( const char *  name,
tag  bt,
size_t  size,
bool  is_fortran,
bool(*)(const char *, const char *)  error_manager 
)

This function creates a constant.

a constant is represented in our internal representation by a function. Its name is the name of the constant, its type is a functional that gives the type of the constant, its storage is rom.

Its initial value is the value of the constant. In case of integer constant, the actual value is stored (as an integer) in constant_int. values of other constants have to be computed with the name, if necessary.

name is the name of the constant 12, 123E10, '3I12', 015 (C octal constant), 0x1ae; (C hexadecimal), 890L (C long constant) ... Initial and final quotes are included in the names of string constants.

basic is the basic type of the constant: int, float, ...

Character constants are typed as int.

Drop the two quotes, but add space for '\0' in C

See all hexadecimal constant as unsigned on 64 bits, elses 0xffffffff generates an overflow, not a -1 (see C-syntax/constants03.c

ld, long; zd, size_t; td, ptrdiff_t

Since the value is stored in a NewGen int that has the size of a pointer, verify is is OK to store it. In should not assume this...

Check conversion errors and make the constant

SG :this ensure everything is ok on 32 bits

Parameters
nameame
btt
sizeize
is_fortrans_fortran

Definition at line 148 of file constant.c.

154 {
155  entity e;
156 
158 
159  if (entity_type(e) == type_undefined) {
162  basic be = basic_undefined;
163 
164  if (bt == is_basic_string) {
165  /* Drop the two quotes, but add space for '\0' in C */
168  (void*) (strlen(name)-2+1-is_fortran))))));
169  }
170  else {
171  be = make_basic(bt, (void*) size);
172  }
173 
175 
176  if (bt == is_basic_int && (size==4 || size==8)) { // int constant
177  //string unsigned int suffix = "uU";
178  //string long int suffix = "lL";
179  bool usuffix = (strchr(name, 'U') != NULL) || (strchr(name, 'u') != NULL);
180  bool lsuffix = (strchr(name, 'L') != NULL) || (strchr(name, 'l') != NULL);
181  int basis = is_fortran? 10 : 0;
182  char * error_string = string_undefined;
183  long long int l = 0;
184  int error_number = 0;
185  //int (* conversion)(string, string *, int);
186 
187  //pips_debug(8, "unsigned int suffix = %s, strspn = %d\n",
188  // unsignedintsuffix, usuffix);
189 
190  /* See all hexadecimal constant as unsigned on 64 bits, elses
191  0xffffffff generates an overflow, not a -1 (see C-syntax/constants03.c */
192  if(strstr(name,"0x")==name) {
193  usuffix = true;
194  lsuffix = true;
195  }
196  /*
197  if(usuffix)
198  if(lsuffix)
199  conversion = (int (*)(string, string *, int)) strtoull;
200  else
201  conversion = (int (*)(string, string *, int)) strtoul;
202  else
203  if(lsuffix)
204  conversion = (int (*)(string, string *, int)) strtoll;
205  else
206  conversion = (int (*)(string, string *, int)) strtol;
207  */
208 
209  errno = 0;
210  if(usuffix)
211  if(lsuffix)
212  l = strtoull(name, &error_string, basis);
213  else
214  l = strtoul(name, &error_string, basis);
215  else
216  if(lsuffix)
217  l = strtoll(name, &error_string, basis);
218  else
219  l = strtol(name, &error_string, basis);
220  error_number = errno;
221  /* %ld, long; %zd, size_t; %td, ptrdiff_t */
222  pips_debug(8, "value = %lld, errno=%d\n", l, error_number);
223  errno = 0;
224 
225  /* Since the value is stored in a NewGen int that has the size of a
226  pointer, verify is is OK to store it. In should not assume
227  this... */
228  if(size==4) { // 32 bit target machine
229  // Well, no problem...
230  }
231  else if(size==8) {
232  pips_assert("pointers have the right size", sizeof(void *)==8);
233  }
234  else
235  pips_internal_error("Unexpected number of bytes for an integer variable");
236 
237  pips_assert("Integer constants are internally stored on 4 or 8 bytes",
238  size==4 || size==8);
239  /* Check conversion errors and make the constant */
240  if(error_number==EINVAL) {
241  pips_user_warning("Integer constant '%s' cannot be converted in %d bytes (%s)\n",
242  name, size, error_string);
243  (*error_manager)(__FUNCTION__,
244  "Integer constant conversion error.\n");
245  }
246  else if(error_number==ERANGE) {
247  pips_user_warning("Overflow, Integer constant '%s' cannot be stored in %d bytes\n",
248  name, size);
249  (*error_manager)(__FUNCTION__,
250  "Integer constant too large for internal representation.\n");
251  }
252  else if(error_number!=0 && (l == LONG_MAX || l == LONG_MIN)) {
253  pips_internal_error("Conversion error for integer constant string");
254  }
255  else if(*error_string!='\0' && strspn(error_string, "LlUu")!=strlen(error_string)) {
256  pips_internal_error("Illegal characters found in integer constant string");
257  }
258  else if(name==error_string) {
259  pips_internal_error("No digit found in integer constant string.\n");
260  }
261 
262  /* SG :this ensure everything is ok on 32 bits */
263  if(l != (long long int)(intptr_t)l)
264  {
265  pips_user_warning("some data lost in conversion, %lli is not representatble in pips \n",l);
266  l = ~(intptr_t)0;
267  }
268  ce = make_constant_int( (intptr_t)l);
269  }
270  else if(bt == is_basic_int && size==1) {
271  // Character constant
272  _int i = TK_CHARCON_to__int(name);
273  // fprintf(stderr,"make integer constant:name=%s\n",name);
274  ce = make_constant(is_constant_int, (void*) i);
275  }
276  else {
278  }
279 
283  }
284  return(e);
285 }
functional make_functional(list a1, type a2)
Definition: ri.c:1109
constant make_constant(enum constant_utype tag, void *val)
Definition: ri.c:406
basic make_basic(enum basic_utype tag, void *val)
Definition: ri.c:155
storage make_storage_rom(void)
Definition: ri.c:2285
value make_value(enum value_utype tag, void *val)
Definition: ri.c:2832
constant make_constant_int(intptr_t _field_)
Definition: ri.c:409
type make_type(enum type_utype tag, void *val)
Definition: ri.c:2706
_int TK_CHARCON_to__int(const char *name)
Definition: constant.c:88
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
#define pips_user_warning
Definition: misc-local.h:146
#define TOP_LEVEL_MODULE_NAME
Module containing the global variables in Fortran and C.
Definition: naming-local.h:101
#define string_undefined
Definition: newgen_types.h:40
intptr_t _int
_INT
Definition: newgen_types.h:53
entity FindOrCreateEntity(const char *package, const char *local_name)
Problem: A functional global entity may be referenced without parenthesis or CALL keyword in a functi...
Definition: entity.c:1586
type MakeTypeVariable(basic, cons *)
BEGIN_EOLE.
Definition: type.c:116
@ is_constant_call
Definition: ri.h:821
#define entity_storage(x)
Definition: ri.h:2794
#define basic_undefined
Definition: ri.h:556
#define type_undefined
Definition: ri.h:2883
#define functional_undefined
Definition: ri.h:1418
#define constant_undefined
Definition: ri.h:802
#define intptr_t
Definition: stdint.in.h:294

References basic_undefined, constant_undefined, entity_initial, entity_storage, entity_type, FindOrCreateEntity(), functional_undefined, intptr_t, is_basic_int, is_basic_string, is_constant_call, is_constant_int, is_type_functional, is_value_constant, make_basic(), make_constant(), make_constant_int(), make_functional(), make_storage_rom(), make_type(), make_value(), MakeTypeVariable(), NIL, pips_assert, pips_debug, pips_internal_error, pips_user_warning, string_undefined, TK_CHARCON_to__int(), TOP_LEVEL_MODULE_NAME, and type_undefined.

Referenced by make_C_constant_entity(), make_constant_entity(), make_Fortran_constant_entity(), and SafeMakeConstant().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ make_constant_entity()

entity make_constant_entity ( string  name,
tag  bt,
size_t  size 
)

For historical reason, call the Fortran version.

It is used in bootstrap, instrumentation, ri-util/constant.c, semantics and task_parallelization.

It is assumed that no errors can be detected, or it would be a PIPS internal error.

Parameters
nameame
btt
sizeize

Definition at line 301 of file constant.c.

304 {
305  return make_C_or_Fortran_constant_entity(name, bt, size, true, NULL);
306 }
entity make_C_or_Fortran_constant_entity(const char *name, tag bt, size_t size, bool is_fortran, bool(*error_manager)(const char *, const char *))
This function creates a constant.
Definition: constant.c:148

References make_C_or_Fortran_constant_entity().

Referenced by cast_constant(), cluster_stage_spire(), constant_to_transformer(), convert_constant_from_double_to_dcomplex(), convert_constant_from_double_to_real(), convert_constant_from_int_to_double(), convert_constant_from_int_to_real(), convert_constant_from_real_to_complex(), convert_constant_from_real_to_double(), convert_constant_from_real_to_int(), edge_cost_polynome(), gen_mpi_send_recv(), make_com_loopbody(), make_special_value(), make_test_condition(), MakeComplexConstant(), mpi_finalize(), mpi_initialize(), mpi_recv_ctx(), mpi_send_ctx(), read_new_entities_from_eole(), simplification_conversion(), and task_time_polynome().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MakeCharacterConstantExpression()

expression MakeCharacterConstantExpression ( string  s)

END_EOLE.

this function creates an character constant and then a call to that constant.

Definition at line 573 of file constant.c.

574 {
576 }
expression MakeNullaryCall(entity f)
Creates a call expression to a function with zero arguments.
Definition: expression.c:331

References is_basic_string, MakeConstant(), and MakeNullaryCall().

Referenced by do_simplify_constant_address_expression(), entity_hpf_number(), generate_string_for_alternate_return_argument(), gfc2pips_code2instruction_(), gfc2pips_expr2expression(), gfc2pips_exprIO(), gfc2pips_exprIO2(), gfc2pips_exprIO3(), hpfc_array_bound(), insert_check_alias_before_statement(), make_print_statement(), make_simple_Fortran_io_instruction(), MakeIoList(), MakeReturn(), MakeSimpleIoInst1(), pvm_encoding_option(), and pvm_what_option_expression().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MakeComplexConstant()

entity MakeComplexConstant ( expression  r,
expression  i 
)

make a complex constant from two calls to real or integer constants

Problem: does not work if either of the components is negative because negative constants are stored as expressions. For instance, (0, -1) is not a complex constant for PIPS but an expression: cmplx(0,unary_minus(1)).

Note: I might have changed that to store DATA statements... (FI)

name has to be allocated by strdup because of nested calls to concatenate

Definition at line 373 of file constant.c.

374 {
377  entity e;
378  char * name;
379  asprintf(&name,"(%s,%s)", entity_local_name(re), entity_local_name(ie));
380  type rt = entity_type(re);
381  type it = entity_type(ie);
386  int rsize = basic_type_size(rb);
387  int isize = basic_type_size(ib);
388  int size = rsize>isize? rsize: isize;
389 
390  e = make_constant_entity(name, is_basic_complex, size);
391  /* name has to be allocated by strdup because of nested calls to
392  concatenate */
393  free(name);
394  return e;
395 }
entity make_constant_entity(string name, tag bt, size_t size)
For historical reason, call the Fortran version.
Definition: constant.c:301
int basic_type_size(basic)
See also SizeOfElements()
Definition: type.c:1074

References asprintf, basic_type_size(), call_function, entity_local_name(), entity_type, expression_syntax, free(), functional_result, is_basic_complex, make_constant_entity(), syntax_call, type_functional, type_variable, and variable_basic.

+ Here is the call graph for this function:

◆ MakeComplexConstantExpression()

expression MakeComplexConstantExpression ( expression  r,
expression  i 
)

Definition at line 397 of file constant.c.

399 {
401 
403  basic rb = basic_of_expression(r);
404  basic ib = basic_of_expression(i);
405  int rsize = basic_type_size(rb);
406  int isize = basic_type_size(ib);
407  int size = rsize>isize? rsize: isize;
408 
410  (size==4? IMPLIED_COMPLEX_NAME: IMPLIED_DCOMPLEX_NAME), r, i);
411  }
412 
413  return cce;
414 }
bool signed_constant_expression_p(expression e)
Definition: constant.c:604
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
expression MakeBinaryCall(entity f, expression eg, expression ed)
Creates a call expression to a function with 2 arguments.
Definition: expression.c:354
basic basic_of_expression(expression)
basic basic_of_expression(expression exp): Makes a basic of the same basic as the expression "exp".
Definition: type.c:1383
#define expression_undefined
Definition: ri.h:1223

References basic_of_expression(), basic_type_size(), expression_undefined, IMPLIED_COMPLEX_NAME, IMPLIED_DCOMPLEX_NAME, local_name_to_top_level_entity(), MakeBinaryCall(), and signed_constant_expression_p().

Referenced by complex_to_expression(), gfc2pips_expr2expression(), gfc2pips_make_zero_for_symbol(), and set_the_i().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MakeConstant()

entity MakeConstant ( string  name,
tag  bt 
)

Make a Fortran constant.

Apparently partly extended fo C...

Parameters
nameame
btt

Definition at line 351 of file constant.c.

352 {
353  return SafeMakeConstant(name, bt, constant_error);
354 }
static bool constant_error(const char *f, const char *m)
Definition: constant.c:287
entity SafeMakeConstant(string name, tag bt, bool(*error_manager)(const char *, const char *))
END_EOLE.
Definition: constant.c:315

References constant_error(), and SafeMakeConstant().

Referenced by bool_to_expression(), buffer_full_condition(), compile_reduction(), float_to_entity(), gfc2pips_int_const2entity(), gfc2pips_logical2entity(), gfc2pips_real2entity(), int_to_entity(), make_C_print_statement(), make_false_expression(), make_special_value(), make_stop_statement(), make_true_expression(), MakeCharacterConstantExpression(), and step_type().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MakeValueSymbolic()

value MakeValueSymbolic ( expression  e)

this function creates a value for a symbolic constant.

the expression e must be evaluable. Well, it does not seem necessary any more...

pips_internal_error("value of parameter must be constant");

s = make_symbolic(e, make_constant(is_constant_unknown, UU));

Definition at line 581 of file constant.c.

582 {
583  symbolic s;
584  value v;
585 
586  if (value_unknown_p(v = EvalExpression(e))) {
587  /* pips_internal_error("value of parameter must be constant"); */
588  free_value(v);
590  /* s = make_symbolic(e, make_constant(is_constant_unknown, UU)); */
591  }
592  else {
593  pips_assert("v is a constant value", value_constant_p(v));
594 
595  s = make_symbolic(e, value_constant(v));
596 
598  free_value(v);
599  }
600 
601  return make_value(is_value_symbolic, s);
602 }
symbolic make_symbolic(expression a1, constant a2)
Definition: ri.c:2369
constant make_constant_unknown(void)
Definition: ri.c:424
void free_value(value p)
Definition: ri.c:2787
value EvalExpression(expression e)
Evaluate statically an expression.
Definition: eval.c:108
#define value_unknown_p(x)
Definition: ri.h:3077

References constant_undefined, EvalExpression(), free_value(), is_value_symbolic, make_constant_unknown(), make_symbolic(), make_value(), pips_assert, value_constant, value_constant_p, and value_unknown_p.

Referenced by gfc2pips_vars_(), and MakeParameter().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SafeMakeConstant()

entity SafeMakeConstant ( string  name,
tag  bt,
bool(*)(const char *, const char *)  error_manager 
)

END_EOLE.

Make a Fortran constant

Apparently partly extended fo C...

SG : I like accurate knowledge of constant suffix to fill all cases accurately, there is still work to do there

The LengthOfBasic should be updated for type "string"

Parameters
nameame
btt

Definition at line 315 of file constant.c.

316 {
317  entity e;
318  size_t len = strlen(name);
319  size_t type_length;
320  /* SG : I like accurate knowledge of constant suffix to fill all
321  cases accurately, there is still work to do there */
322  switch(bt) {
323  case is_basic_float:
324  switch(name[len-1]) {
325  case 'f':
326  type_length = DefaultLengthOfBasic(bt);break;
327  case 'F':
328  default:
329  // SG I am sure the default is double for C, I don't know for Fortran
330  type_length = (c_module_p(get_current_module_entity()) ?
331  2 :
332  1
333  ) *DefaultLengthOfBasic(bt);break;
334  } break;
335  default:
336  type_length = DefaultLengthOfBasic(bt);
337  }
338 
339  //e = make_constant_entity(name, bt, type_length);
340  e = make_C_or_Fortran_constant_entity(name, bt, type_length, true, error_manager);
341 
342  /* The LengthOfBasic should be updated for type "string" */
343 
344  return e;
345 }
int DefaultLengthOfBasic(tag t)
Deals with constant expressions and constant entities.
Definition: constant.c:44
entity get_current_module_entity(void)
Get the entity of the current module.
Definition: static.c:85
bool c_module_p(entity m)
Test if a module "m" is written in C.
Definition: entity.c:2777

References c_module_p(), DefaultLengthOfBasic(), get_current_module_entity(), is_basic_float, and make_C_or_Fortran_constant_entity().

Referenced by MakeConstant().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ signed_constant_expression_p()

bool signed_constant_expression_p ( expression  e)

Definition at line 604 of file constant.c.

605 {
606  syntax es = expression_syntax(e);
607  bool ok = true;
608 
609  if(syntax_call_p(es)) {
610  entity ce = call_function(syntax_call(es));
611 
612  if(!entity_constant_p(ce)) {
613  list args = call_arguments(syntax_call(es));
614 
616  syntax arg = expression_syntax(EXPRESSION(CAR(args)));
617  if( syntax_call_p(arg)) {
618  entity mce = call_function(syntax_call(arg));
619  ok = entity_constant_p(mce);
620  }
621  else {
622  ok = false;
623  }
624  }
625  else {
626  ok = false;
627  }
628  }
629  }
630  return ok;
631 }
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
#define UNARY_MINUS_OPERATOR_NAME
entity CreateIntrinsic(string name)
this function does not create an intrinsic function because they must all be created beforehand by th...
Definition: entity.c:1311
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
#define call_arguments(x)
Definition: ri.h:711
static bool ok
The structure used to build lists in NewGen.
Definition: newgen_list.h:41

References call_arguments, call_function, CAR, CreateIntrinsic(), entity_constant_p, EXPRESSION, expression_syntax, ok, syntax_call, syntax_call_p, and UNARY_MINUS_OPERATOR_NAME.

Referenced by MakeComplexConstantExpression().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ TK_CHARCON_to__int()

_int TK_CHARCON_to__int ( const char *  name)

Should be able to decode any C character constant...

octal constant

Parameters
nameame

Definition at line 88 of file constant.c.

89 {
90  _int r;
91 
92  /* Should be able to decode any C character constant... */
93  if(strlen(name)==3 && name[0]=='\'' && name[2]=='\'')
94  r=name[1];
95  else if(strlen(name)==4 && name[0]=='\'' && name[1]=='\\' && name[3]=='\'')
96  switch(name[2]) {
97  case '\t' :
98  r = 9; // not sure
99  break;
100  case '\n' :
101  r = 10;
102  break;
103  case '\r' :
104  r = 13;
105  break;
106  default:
107  r=name[2];
108  }
109  else if(strlen(name)==6 && name[0]=='\'' && name[1]=='\\' && name[5]=='\'') {
110  /* octal constant */
111  string error_string = string_undefined;
112  errno = 0;
113  r = strtol(&name[2], &error_string, 8);
114  if(errno!=0) {
115  pips_user_warning("character constant %s not recognized\n",name);
116  pips_internal_error("Illegal octal constant");
117  }
118  }
119  else { // Unrecognized format
120  pips_user_warning("character constant %s not recognized\n",name);
121  // pips_internal_error("not implemented yet");
122  r=0;//just temporary
123  }
124 
125  return r;
126 }

References pips_internal_error, pips_user_warning, and string_undefined.

Referenced by make_C_or_Fortran_constant_entity().

+ Here is the caller graph for this function: