PIPS
allocatable.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "genC.h"
#include "linear.h"
#include "misc.h"
#include "ri.h"
#include "ri-util.h"
#include "prettyprint.h"
+ Include dependency graph for allocatable.c:

Go to the source code of this file.

Functions

static entity make_data_field (basic b, const char *struct_name, const char *name, list dimensions)
 Helper for creating an allocatable structure. More...
 
static entity make_bound (const char *struct_name, const char *lname, int suffix)
 
entity find_or_create_allocatable_struct (basic b, string name, int ndim)
 This function try to find the allocatable structure corresponding to the number of dimensions requested, and create it if necessary. More...
 

Function Documentation

◆ find_or_create_allocatable_struct()

entity find_or_create_allocatable_struct ( basic  b,
string  name,
int  ndim 
)

This function try to find the allocatable structure corresponding to the number of dimensions requested, and create it if necessary.

Warning! Do not modify this file that is automatically generated!

Parameters
nameis the name of the array (prettyprint name)
Parameters
nameame
ndimdim

Definition at line 97 of file allocatable.c.

97  {
98  // FI: scaffolding code is not even guarded...
99  printf("Creating allocatable struct for dim %d\n", ndim);
100 
101  // Create the entity name according to the number of dims
102  string struct_name;
103  string b_str = STRING(CAR(words_basic(b,NULL)));
104  pips_assert("asprintf !",
105  asprintf( &struct_name, ALLOCATABLE_PREFIX"%s_%s_%dD", name, b_str,ndim));
106 
107  // Here is the internal PIPS name, there is a prefix for struct
108  string prefixed_name = strdup(concatenate(STRUCT_PREFIX, struct_name, NULL));
109 
110  // Let's try to localize the structure
111  entity struct_entity = FindEntity(TOP_LEVEL_MODULE_NAME, prefixed_name);
112 
113  // Localization failed, let's create it
114  if(struct_entity == entity_undefined) {
115  list fields = NULL;
116  list dimensions = NULL;
117  for (int dim = ndim; dim >= 1; dim--) {
118  entity lower = make_bound(struct_name, ALLOCATABLE_LBOUND_PREFIX, dim);
119  entity upper = make_bound(struct_name, ALLOCATABLE_UBOUND_PREFIX, dim);
120 
121  // Field for struct
122  fields = CONS(ENTITY,lower,fields);
123  fields = CONS(ENTITY,upper,fields);
124 
125  // Dimensions for the data array
127  entity_to_expression(upper),
128  NIL);
129  dimensions = CONS(DIMENSION,d,dimensions );
130  }
131 
132  // Create data holder
133  fields
134  = CONS(ENTITY,make_data_field(b, struct_name, name, dimensions),fields);
135 
136  // Create the struct
137  string field;
138  asprintf(&field,STRUCT_PREFIX "%s",struct_name);
139  struct_entity = FindOrCreateTopLevelEntity(field);
140  free(field);
141  entity_type(struct_entity) = make_type_struct(fields);
142  entity_storage(struct_entity) = make_storage_rom();
143  entity_initial(struct_entity) = make_value_unknown();
144  }
145 
146  free(prefixed_name);
147  free(struct_name);
148 
149  return struct_entity;
150 }
value make_value_unknown(void)
Definition: ri.c:2847
storage make_storage_rom(void)
Definition: ri.c:2285
type make_type_struct(list _field_)
Definition: ri.c:2730
dimension make_dimension(expression a1, expression a2, list a3)
Definition: ri.c:565
#define STRING(x)
Definition: genC.h:87
void free(void *)
#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
#define asprintf
Definition: misc-local.h:225
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define TOP_LEVEL_MODULE_NAME
Module containing the global variables in Fortran and C.
Definition: naming-local.h:101
#define STRUCT_PREFIX
Definition: naming-local.h:56
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
static entity make_data_field(basic b, const char *struct_name, const char *name, list dimensions)
Helper for creating an allocatable structure.
Definition: allocatable.c:45
static entity make_bound(const char *struct_name, const char *lname, int suffix)
Definition: allocatable.c:65
list words_basic(basic obj, list *ppdl)
what about simple DOUBLE PRECISION, REAL, INTEGER...
Definition: declarations.c:323
#define ALLOCATABLE_UBOUND_PREFIX
#define ALLOCATABLE_PREFIX
#define ALLOCATABLE_LBOUND_PREFIX
entity FindEntity(const char *package, const char *name)
Retrieve an entity from its package/module name and its local name.
Definition: entity.c:1503
entity FindOrCreateTopLevelEntity(const char *name)
Return a top-level entity.
Definition: entity.c:1603
expression entity_to_expression(entity e)
if v is a constant, returns a constant call.
Definition: expression.c:165
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
#define entity_storage(x)
Definition: ri.h:2794
#define entity_undefined
Definition: ri.h:2761
#define entity_type(x)
Definition: ri.h:2792
#define entity_initial(x)
Definition: ri.h:2796
char * strdup()
int printf()
The structure used to build lists in NewGen.
Definition: newgen_list.h:41

References ALLOCATABLE_LBOUND_PREFIX, ALLOCATABLE_PREFIX, ALLOCATABLE_UBOUND_PREFIX, asprintf, CAR, concatenate(), CONS, DIMENSION, ENTITY, entity_initial, entity_storage, entity_to_expression(), entity_type, entity_undefined, FindEntity(), FindOrCreateTopLevelEntity(), free(), make_bound(), make_data_field(), make_dimension(), make_storage_rom(), make_type_struct(), make_value_unknown(), NIL, pips_assert, printf(), strdup(), STRING, STRUCT_PREFIX, TOP_LEVEL_MODULE_NAME, and words_basic().

Referenced by gfc2pips_getbasic(), and gfc2pips_symbol2entity().

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

◆ make_bound()

static entity make_bound ( const char *  struct_name,
const char *  lname,
int  suffix 
)
static

Definition at line 65 of file allocatable.c.

65  {
66  entity bound;
67 
68  // Create the name
69  string name;
70  pips_assert("asprintf !",
71  asprintf( &name,
72  "%s" MEMBER_SEP_STRING "%s%d",
73  struct_name,
74  lname,
75  suffix ));
76 
77  pips_assert("Trying to create lower bound but already existing ?",
79 
80  bound = FindOrCreateTopLevelEntity(name);
81 
83  NULL,
84  NULL));
87 
88  free(name);
89  return bound;
90 }
type make_type_variable(variable _field_)
Definition: ri.c:2715
basic make_basic_int(intptr_t _field_)
Definition: ri.c:158
variable make_variable(basic a1, list a2, list a3)
Definition: ri.c:2895
#define MEMBER_SEP_STRING
Definition: naming-local.h:53
void * gen_find_tabulated(const char *, int)
Definition: tabulated.c:218
#define entity_domain
newgen_syntax_domain_defined
Definition: ri.h:410
static int lname(char *s, int look_for_entry)
check for keywords for subprograms return 0 if comment card, 1 if found name and put in arg string.
Definition: split_file.c:283

References asprintf, entity_domain, entity_initial, entity_storage, entity_type, entity_undefined, FindOrCreateTopLevelEntity(), free(), gen_find_tabulated(), lname(), make_basic_int(), make_storage_rom(), make_type_variable(), make_value_unknown(), make_variable(), MEMBER_SEP_STRING, and pips_assert.

Referenced by find_or_create_allocatable_struct().

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

◆ make_data_field()

static entity make_data_field ( basic  b,
const char *  struct_name,
const char *  name,
list  dimensions 
)
static

Helper for creating an allocatable structure.

Here we create the field corresponding to the data array.

Definition at line 45 of file allocatable.c.

48  {
49 
50  string field ;
51  asprintf(&field, "%s" MEMBER_SEP_STRING"%s", struct_name,name);
52 
53  pips_assert("Trying to create data for an already existing struct ?",
55 
57  free(field);
58  entity_type(data) = make_type_variable(make_variable(b, dimensions, NULL));
61 
62  return data;
63 }
struct _newgen_struct_data_ * data

References asprintf, entity_initial, entity_storage, entity_type, entity_undefined, FindEntity(), FindOrCreateTopLevelEntity(), free(), make_storage_rom(), make_type_variable(), make_value_unknown(), make_variable(), MEMBER_SEP_STRING, pips_assert, and TOP_LEVEL_MODULE_NAME.

Referenced by find_or_create_allocatable_struct().

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