PIPS
externals.c File Reference
#include "private.h"
#include "paf_ri.h"
#include "ri-util.h"
+ Include dependency graph for externals.c:

Go to the source code of this file.

Macros

#define STATEMENT_FUNCTION_MAP(k, v, code, _map_hash_h)
 this piece of code makes low level assumptions about newgen internals. More...
 

Functions

static int lire_int (FILE *fd)
 reads an int while sharing file and buffers with newgen... More...
 
char * pipsdbm_read_entities (FILE *fd)
 externals.c More...
 
void pipsdbm_free_entities (char *p)
 
static int statement_mapping_count (statement_mapping h)
 The old statement_mapping is an hash_table managed directly. More...
 
void pipsdbm_write_statement_mapping (FILE *fd, statement_mapping h)
 Write a statement mapping. More...
 
hash_table pipsdbm_read_statement_mapping (FILE *fd)
 Read a statement mapping. More...
 
bool pipsdbm_check_statement_mapping (statement_mapping h)
 a little bit partial, because domain are not checked. More...
 
void pipsdbm_free_statement_mapping (statement_mapping h)
 
static int number_of_ordered_statements (hash_table h)
 count the number of statements with a valid ordering. More...
 
bool pipsdbm_consistent_statement_function (gen_chunkp map)
 
void pipsdbm_write_statement_function (FILE *fd, gen_chunkp map)
 the stored stuff need be based on the ordering... More...
 
gen_chunkp pipsdbm_read_statement_function (FILE *fd)
 Should use a higher level pipsdbm_read_statement_mapping() to survive to XML. More...
 
void free_static_control_mapping (statement_mapping map)
 Modification Dec 11 1995: ne pas utiliser free_static_control car il libere des champs qui appartiennent a d'autres structures que celles controlees par static_controlize...(champs d'origine) Les liberation de ces champs par un autre transformer (use_def_elim) entrainait alors un core dump au niveau de cette procedure. More...
 
void declarations_write (FILE *f, hash_table h)
 Functions to read and write declarations resource, which is a hash table whose key and value are string (keyword/typedef and TK_keyword/TK_typedef) More...
 
hash_table declarations_read (FILE *f)
 

Macro Definition Documentation

◆ STATEMENT_FUNCTION_MAP

#define STATEMENT_FUNCTION_MAP (   k,
  v,
  code,
  _map_hash_h 
)
Value:
{ void * _map_hash_p = NULL; \
void * _map_k; void * _map_v; \
while ((_map_hash_p = \
hash_table_scan(_map_hash_h,_map_hash_p,&_map_k,&_map_v))) { \
statement k = (statement) ((gen_chunkp)_map_k)->p ; \
gen_chunkp v = ((gen_chunkp)_map_v)->p; \
code ; }}
struct _newgen_struct_statement_ * statement
Definition: cloning.h:21
union gen_chunk * gen_chunkp
void * hash_table_scan(hash_table htp, void *hentryp_arg, void **pkey, void **pval)
Definition: hash.c:844
A gen_chunk is used to store every object.
Definition: genC.h:58

this piece of code makes low level assumptions about newgen internals.

see also the comments about statement mappings above.

Definition at line 202 of file externals.c.

Function Documentation

◆ declarations_read()

hash_table declarations_read ( FILE *  f)

Definition at line 345 of file externals.c.

346 {
348  int c;
349  while ((c = getc(f)) && c != EOF)
350  {
351  ungetc(c,f);
352  char* key = safe_readline(f);
353  _int value = atoi(safe_readline(f));
354 
355  hash_put(result,key,(void*)value);
356  }
357  return result;
358 }
char * safe_readline(FILE *file)
returns the allocated line read, whatever its length.
Definition: file.c:497
hash_table hash_table_make(hash_key_type key_type, size_t size)
Definition: hash.c:294
void hash_put(hash_table htp, const void *key, const void *val)
This functions stores a couple (key,val) in the hash table pointed to by htp.
Definition: hash.c:364
@ hash_string
Definition: newgen_hash.h:32
intptr_t _int
_INT
Definition: newgen_types.h:53
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15

References f(), hash_put(), hash_string, hash_table_make(), and safe_readline().

+ Here is the call graph for this function:

◆ declarations_write()

void declarations_write ( FILE *  f,
hash_table  h 
)

Functions to read and write declarations resource, which is a hash table whose key and value are string (keyword/typedef and TK_keyword/TK_typedef)

Definition at line 335 of file externals.c.

336 {
337  HASH_MAP(k,v,
338  {
339  fprintf(f, "%s\n", (char *) k);
340  fprintf(f, "%td\n", (_int) v);
341  },h);
342 }
#define HASH_MAP(k, v, code, ht)
Definition: newgen_hash.h:60
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...

References f(), fprintf(), and HASH_MAP.

+ Here is the call graph for this function:

◆ free_static_control_mapping()

void free_static_control_mapping ( statement_mapping  map)

Modification Dec 11 1995: ne pas utiliser free_static_control car il libere des champs qui appartiennent a d'autres structures que celles controlees par static_controlize...(champs d'origine) Les liberation de ces champs par un autre transformer (use_def_elim) entrainait alors un core dump au niveau de cette procedure.

On fait a la place des gen_free_list en detail –DB ]

Parameters
mapap

Definition at line 318 of file externals.c.

319 {
320  STATEMENT_MAPPING_MAP(s, val, {
326  gen_free( (void*) val );
327  }, map);
328 
330 }
void gen_free(gen_chunk *obj)
version without shared_pointers.
Definition: genClib.c:992
void gen_free_list(list l)
free the spine of the list
Definition: list.c:327
#define FREE_STATEMENT_MAPPING(map)
Definition: newgen-local.h:45
#define STATEMENT_MAPPING_MAP(s, v, code, h)
Definition: newgen-local.h:53
#define static_control_loops(x)
Definition: paf_ri.h:757
#define static_control_params(x)
Definition: paf_ri.h:755
#define static_control_tests(x)
Definition: paf_ri.h:759

References FREE_STATEMENT_MAPPING, gen_free(), gen_free_list(), STATEMENT_MAPPING_MAP, static_control_loops, static_control_params, and static_control_tests.

+ Here is the call graph for this function:

◆ lire_int()

static int lire_int ( FILE *  fd)
static

reads an int while sharing file and buffers with newgen...

trim

Definition at line 40 of file externals.c.

41 {
42  int c, i = 0, sign = 1;
43  genread_in = fd;
44 
45  while (isspace(c = genread_input())) ; /* trim */
46 
47  if (c == '-') sign = -1;
48  else if (isdigit(c))
49  i = c-'0';
50  else if(c==EOF)
51  pips_internal_error("Unexpected EOF, corrupted resource file");
52  else
53  pips_internal_error("digit or '-' expected : %c %x", c, c);
54 
55  while (isdigit(c = genread_input()))
56  i = 10*i + (c-'0');
57 
58  return sign*i;
59 }
FILE * genread_in
int genread_input(void)
#define pips_internal_error
Definition: misc-local.h:149

References genread_in, genread_input(), and pips_internal_error.

Referenced by pipsdbm_read_statement_function(), and pipsdbm_read_statement_mapping().

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

◆ number_of_ordered_statements()

static int number_of_ordered_statements ( hash_table  h)
static

count the number of statements with a valid ordering.

Definition at line 213 of file externals.c.

214 {
215  int n = 0;
217  {
218  pips_assert("variable not used", x==x);
220  },
221  h);
222  return n;
223 }
#define STATEMENT_FUNCTION_MAP(k, v, code, _map_hash_h)
this piece of code makes low level assumptions about newgen internals.
Definition: externals.c:202
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define STATEMENT_ORDERING_UNDEFINED
mapping.h inclusion
Definition: newgen-local.h:35
#define statement_ordering(x)
Definition: ri.h:2454
static char * x
Definition: split_file.c:159

References pips_assert, STATEMENT_FUNCTION_MAP, statement_ordering, STATEMENT_ORDERING_UNDEFINED, and x.

Referenced by pipsdbm_write_statement_function().

+ Here is the caller graph for this function:

◆ pipsdbm_check_statement_mapping()

bool pipsdbm_check_statement_mapping ( statement_mapping  h)

a little bit partial, because domain are not checked.

Definition at line 178 of file externals.c.

179 {
180  STATEMENT_MAPPING_MAP(k, v, {
181  pips_assert("consistent statement",
183  pips_assert("consistent val", gen_consistent_p((void*) v));
184  },
185  h);
186  return true;
187 }
bool statement_consistent_p(statement p)
Definition: ri.c:2195
int gen_consistent_p(gen_chunk *obj)
GEN_CONSISTENT_P dynamically checks the type correctness of OBJ.
Definition: genClib.c:2398

References gen_consistent_p(), pips_assert, statement_consistent_p(), and STATEMENT_MAPPING_MAP.

+ Here is the call graph for this function:

◆ pipsdbm_consistent_statement_function()

bool pipsdbm_consistent_statement_function ( gen_chunkp  map)
Parameters
mapap

Definition at line 226 of file externals.c.

227 {
228  hash_table h = (map+1)->h;
230  {
231  if (gen_type((void*)s)!=statement_domain) return false;
232  if (!gen_consistent_p((void*)x)) return false;
233  },
234  h);
235  return true;
236 }
int gen_type(gen_chunk *obj)
GEN_TYPE returns the domain number for the object in argument.
Definition: genClib.c:82
#define statement_domain
newgen_sizeofexpression_domain_defined
Definition: ri.h:362

References gen_consistent_p(), gen_type(), statement_domain, STATEMENT_FUNCTION_MAP, and x.

+ Here is the call graph for this function:

◆ pipsdbm_free_entities()

void pipsdbm_free_entities ( char *  p)

Definition at line 72 of file externals.c.

73 {
74  pips_assert("argument not used", p==p);
76 }
int gen_free_tabulated(int domain)
free tabulated elements of this domain.
Definition: genClib.c:1461
#define entity_domain
newgen_syntax_domain_defined
Definition: ri.h:410

References entity_domain, gen_free_tabulated(), and pips_assert.

+ Here is the call graph for this function:

◆ pipsdbm_free_statement_mapping()

void pipsdbm_free_statement_mapping ( statement_mapping  h)

Definition at line 190 of file externals.c.

191 {
192  STATEMENT_MAPPING_MAP(k, v, gen_free((void*) v), h);
194 }

References FREE_STATEMENT_MAPPING, gen_free(), and STATEMENT_MAPPING_MAP.

+ Here is the call graph for this function:

◆ pipsdbm_read_entities()

char* pipsdbm_read_entities ( FILE *  fd)

externals.c

Parameters
fdd

Definition at line 64 of file externals.c.

65 {
66  int read = gen_read_tabulated(fd, false);
67  pips_assert("entities were read", read==entity_domain);
68  return (char *) entity_domain;
69 }
int gen_read_tabulated(FILE *file, int create_p)
GEN_READ_TABULATED reads FILE to update the Gen_tabulated_ table.
Definition: genClib.c:2334

References entity_domain, gen_read_tabulated(), and pips_assert.

+ Here is the call graph for this function:

◆ pipsdbm_read_statement_function()

gen_chunkp pipsdbm_read_statement_function ( FILE *  fd)

Should use a higher level pipsdbm_read_statement_mapping() to survive to XML.

get meta data.

allocate the statement function.

now reads each couple and rebuild the function.

Parameters
fdfile to read from

Definition at line 271 of file externals.c.

272 {
273  statement stat;
274  int domain, n;
275  gen_chunkp result;
276  hash_table h;
277 
278  pips_assert("some current module name", dbll_current_module);
279  pips_debug(3, "statement -> ??? for %s\n", dbll_current_module);
280  stat = (statement)
282 
284 
285  /* get meta data.
286  */
287  domain = lire_int(fd);
288  n = lire_int(fd);
289 
290  /* allocate the statement function.
291  */
292  result = gen_alloc(2*sizeof(gen_chunk), GEN_CHECK_ALLOC, domain);
293  h = (result+1)->h;
294 
295  /* now reads each couple and rebuild the function.
296  */
297  while(n-->0) {
298  int so = lire_int(fd);
299  pips_assert("valid ordering", so!=STATEMENT_ORDERING_UNDEFINED);
300  HASH_EXTEND(p, p, h, ordering_to_statement(so), gen_read(fd));
301  }
302 
304 
305  return result;
306 }
static int lire_int(FILE *fd)
reads an int while sharing file and buffers with newgen...
Definition: externals.c:40
#define GEN_CHECK_ALLOC
Definition: genC.h:307
gen_chunk * gen_alloc(int size, int gen_check_p, int dom,...)
allocates something in newgen.
Definition: genClib.c:298
gen_chunk * gen_read(FILE *file)
GEN_READ reads any object from the FILE stream.
Definition: genClib.c:2323
string db_get_memory_resource(const char *rname, const char *oname, bool pure)
Return the pointer to the resource, whatever it is.
Definition: database.c:755
const char * dbll_current_module
the current module is expected by some load/save functions...
Definition: lowlevel.c:41
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
#define HASH_EXTEND(start, image, h, k, v)
Definition: newgen_map.h:36
hash_table set_ordering_to_statement(statement s)
To be used instead of initialize_ordering_to_statement() to make sure that the hash table ots is in s...
Definition: ordering.c:172
statement ordering_to_statement(int o)
Get the statement associated to a given ordering.
Definition: ordering.c:111
void reset_ordering_to_statement(void)
Reset the mapping from ordering to statement.
Definition: ordering.c:185
A DOMAIN union describes the structure of a user type.

References db_get_memory_resource(), dbll_current_module, gen_alloc(), GEN_CHECK_ALLOC, gen_read(), HASH_EXTEND, lire_int(), ordering_to_statement(), pips_assert, pips_debug, reset_ordering_to_statement(), set_ordering_to_statement(), and STATEMENT_ORDERING_UNDEFINED.

+ Here is the call graph for this function:

◆ pipsdbm_read_statement_mapping()

hash_table pipsdbm_read_statement_mapping ( FILE *  fd)

Read a statement mapping.

This function is quite too low level... It mixes raw getc() from a FILE with gen_read. To survive other NewGen backend (XML), fprintf could be replaced with a gen_getc() that could peek in a CDATA for example in the case of XML.

But in this case it should be a call to something like so = gen_read_int(fd) instead to do even simpler and read an int value (in textual form or in <int>...</int> in the case of XML.

get meta data.

Parameters
fdd

Definition at line 147 of file externals.c.

148 {
149  statement stat;
151  int n;
152 
153  pips_assert("some current module name", dbll_current_module);
154  pips_debug(3, "statement -> ??? for %s\n", dbll_current_module);
155  stat = (statement)
157 
159 
160  /* get meta data.
161  */
162  n = lire_int(fd);
163 
164  while (n-->0) {
165  int so = lire_int(fd);
166  pips_assert("valid ordering", so!=STATEMENT_ORDERING_UNDEFINED);
167  hash_put(result,(void*)ordering_to_statement(so),(void*)gen_read(fd));
168  }
169 
171 
172  return result;
173 }
@ hash_pointer
Definition: newgen_hash.h:32

References db_get_memory_resource(), dbll_current_module, gen_read(), hash_pointer, hash_put(), hash_table_make(), lire_int(), ordering_to_statement(), pips_assert, pips_debug, reset_ordering_to_statement(), set_ordering_to_statement(), and STATEMENT_ORDERING_UNDEFINED.

+ Here is the call graph for this function:

◆ pipsdbm_write_statement_function()

void pipsdbm_write_statement_function ( FILE *  fd,
gen_chunkp  map 
)

the stored stuff need be based on the ordering...

because newgen won't regenerate pointers...

Should use a higher level pipsdbm_write_statement_mapping() to survive to XML

save it!

Parameters
fdfile to write to
mapstatement function

Definition at line 245 of file externals.c.

248 {
249  hash_table h = (map+1)->h;
250  fprintf(fd, "%td\n%d\n", map->i, number_of_ordered_statements(h));
252  {
253  int order = statement_ordering(s);
254  if (order!=STATEMENT_ORDERING_UNDEFINED) { /* save it! */
255  fprintf(fd, "%d\n", order);
256  gen_write(fd, x);
257  }
258  else {
259  pips_user_warning("Statement with illegal ordering, lost data: %s\n",
261  }
262  },
263  h);
264 }
static int number_of_ordered_statements(hash_table h)
count the number of statements with a valid ordering.
Definition: externals.c:213
void gen_write(FILE *fd, gen_chunk *obj)
GEN_WRITE writes the OBJect on the stream FD.
Definition: genClib.c:1745
string statement_identification(statement)
Like external_statement_identification(), but with internal information, the hexadecimal address of t...
Definition: statement.c:1700
#define pips_user_warning
Definition: misc-local.h:146
_int i
Definition: genC.h:62

References fprintf(), gen_write(), gen_chunk::i, number_of_ordered_statements(), pips_user_warning, STATEMENT_FUNCTION_MAP, statement_identification(), statement_ordering, STATEMENT_ORDERING_UNDEFINED, and x.

+ Here is the call graph for this function:

◆ pipsdbm_write_statement_mapping()

void pipsdbm_write_statement_mapping ( FILE *  fd,
statement_mapping  h 
)

Write a statement mapping.

This function is quite too low level... It mixes raw printf in a FILE with gen_write. To survive other NewGen backend (XML), fprintf could be replaced with a gen_fprintf() that could encapsulate the output in a CDATA for example in the case of XML.

But in this case it should be a call to something like gen_write_int(fd, order) instead to do even simpler.

save it!

Parameters
fdfile to write to
hhash table to dump

Definition at line 115 of file externals.c.

118 {
119  fprintf(fd, "%d\n", statement_mapping_count(h));
121  {
122  statement key = (statement) s;
123  gen_chunkp val = (gen_chunkp) v;
124  int order = statement_ordering(key);
125  if (order!=STATEMENT_ORDERING_UNDEFINED) { /* save it! */
126  fprintf(fd, "%d\n", order);
127  gen_write(fd, (gen_chunkp) val);
128  }
129  else pips_user_warning("statement with illegal ordering\n");
130  },
131  h);
132 }
static int statement_mapping_count(statement_mapping h)
The old statement_mapping is an hash_table managed directly.
Definition: externals.c:94

References fprintf(), gen_write(), pips_user_warning, statement_mapping_count(), STATEMENT_MAPPING_MAP, statement_ordering, and STATEMENT_ORDERING_UNDEFINED.

+ Here is the call graph for this function:

◆ statement_mapping_count()

static int statement_mapping_count ( statement_mapping  h)
static

The old statement_mapping is an hash_table managed directly.

this table associates statement to any newgen type. Now explicit newgen functions ("->") should be prefered. the storing of the mapping is based on the statement ordering for later reconstruction with the CODE. tabulating statements would help, but is that desirable?

MY opinion is that all newgen objects should have a unique id associated to it, as an addditional hidden field, to support persistence more easily. Well, there would be some problemes, too.

FC.

Definition at line 94 of file externals.c.

95 {
96  int n = 0;
99  n++,
100  h);
101  return n;
102 }

References STATEMENT_MAPPING_MAP, statement_ordering, and STATEMENT_ORDERING_UNDEFINED.

Referenced by pipsdbm_write_statement_mapping().

+ Here is the caller graph for this function: