PIPS
gfc2pips-util.c File Reference
#include "gfc2pips-private.h"
#include "c_parser_private.h"
#include "misc.h"
#include "text-util.h"
#include <stdio.h>
+ Include dependency graph for gfc2pips-util.c:

Go to the source code of this file.

Functions

list gen_union (list a, list b)
 generate an union of unique elements taken from A and B More...
 
void gfc2pips_add_to_callees (entity e)
 Add an entity to the list of callees. More...
 
char * str2upper (char s[])
 Here are few utility functions to handle splitted files and do comparisons with case insensitive. More...
 
char * strn2upper (char s[], size_t n)
 replace lower case char by upper case ones More...
 
char * strrcpy (char *dest, __const char *src)
 copy a string from the last char (to allow copy on itself) More...
 
int strcmp_ (__const char *__s1, __const char *__s2)
 insensitive case comparison More...
 
int strncmp_ (__const char *__s1, __const char *__s2, size_t __n)
 insensitive case n-comparison More...
 
int fcopy (const char *old, const char *new)
 copy the file called *old to the file called *new More...
 
void gfc2pips_truncate_useless_zeroes (char *s)
 expurgates a string representing a REAL, could be a pre-prettyprinter processing More...
 
void load_entities ()
 
void save_entities ()
 
void pips_init ()
 
void gfc2pips_get_use_st (void)
 
list get_use_entities_list (struct gfc_namespace *ns)
 
gfc_code * gfc2pips_get_last_loop (void)
 
void gfc2pips_push_loop (gfc_code *c)
 
void gfc2pips_pop_loop (void)
 

Variables

list gfc_module_callees = NULL
 FIXME: should be generated... More...
 
list gfc2pips_list_of_declared_code = NULL
 
list gfc2pips_list_of_loops = NULL
 
hash_table ns2use = NULL
 void gfc2pips_get_use_st( void ); More...
 

Function Documentation

◆ fcopy()

int fcopy ( const char *  old,
const char *  new 
)

copy the file called *old to the file called *new

copy the content of the first file to the second one

Definition at line 143 of file gfc2pips-util.c.

143  {
144  if(!old || !new)
145  return 0;
146  FILE * o = fopen(old, "r");
147  if(o) {
148  FILE * n = fopen(new, "w");
149  if(n) {
150  int c = fgetc(o);
151  while(c != EOF) {
152  fputc(c, n);
153  c = fgetc(o);
154  }
155  fclose(n);
156  fclose(o);
157  return 1;
158  }
159  fclose(o);
160  return 0;
161  }
162  return 0;
163 }

Referenced by gfc2pips_namespace().

+ Here is the caller graph for this function:

◆ gen_union()

list gen_union ( list  a,
list  b 
)

generate an union of unique elements taken from A and B

Definition at line 47 of file gfc2pips-util.c.

47  {
48  list c = NULL;
49  while(a) {
50  if(!gen_in_list_p(CHUNK( CAR( a ) ), c))
51  c = gen_cons(CHUNK( CAR( a ) ), c);
52  POP( a );
53  }
54  while(b) {
55  if(!gen_in_list_p(CHUNK( CAR( b ) ), c))
56  c = gen_cons(CHUNK( CAR( b ) ), c);
57  POP( b );
58  }
59  return c;
60 }
#define CHUNK(x)
Definition: genC.h:90
#define POP(l)
Modify a list pointer to point on the next element of the list.
Definition: newgen_list.h:59
list gen_cons(const void *item, const list next)
Definition: list.c:888
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
bool gen_in_list_p(const void *vo, const list lx)
tell whether vo belongs to lx
Definition: list.c:734
The structure used to build lists in NewGen.
Definition: newgen_list.h:41

References CAR, CHUNK, gen_cons(), gen_in_list_p(), and POP.

Referenced by gfc2pips_namespace().

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

◆ get_use_entities_list()

list get_use_entities_list ( struct gfc_namespace *  ns)

Create an entity

Definition at line 316 of file gfc2pips-util.c.

316  {
317  list use_entities = NULL;
318  if(ns2use) {
319  int currentUse = 1;
320  list use_stmts = NULL; // List of entities
321  if((use_stmts = hash_get(ns2use, (char *)ns)) != HASH_UNDEFINED_VALUE) {
322  string use = NULL;
323  int current_len = 1;
324  FOREACH(string, a_use, use_stmts) {
325  int a_len = strlen(a_use);
326  current_len += a_len;
327  if(use == NULL) {
328  use = (string)malloc(current_len * sizeof(char));
329  } else {
330  use = (string)realloc((void*)use, current_len * sizeof(char));
331  }
332  strcpy(&(use[current_len - a_len - 1]), a_use);
333  }
334  /* Create an entity */
335  string entity_name;
336  asprintf(&entity_name, "%s-use-%d", CurrentPackage, currentUse++);
341  use_entities = CONS(ENTITY,e,use_entities);
342  }
343  }
344  return use_entities;
345 }
value make_value_unknown(void)
Definition: ri.c:2847
storage make_storage_rom(void)
Definition: ri.c:2285
type make_type_unknown(void)
Definition: ri.c:2724
void * malloc(YYSIZE_T)
hash_table ns2use
void gfc2pips_get_use_st( void );
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
Definition: newgen_list.h:150
#define FOREACH(_fe_CASTER, _fe_item, _fe_list)
Apply/map an instruction block on all the elements of a list.
Definition: newgen_list.h:179
void * hash_get(const hash_table htp, const void *key)
this function retrieves in the hash table pointed to by htp the couple whose key is equal to key.
Definition: hash.c:449
#define asprintf
Definition: misc-local.h:225
#define F95_USE_LOCAL_NAME
constant names
Definition: naming-local.h:67
#define HASH_UNDEFINED_VALUE
value returned by hash_get() when the key is not found; could also be called HASH_KEY_NOT_FOUND,...
Definition: newgen_hash.h:56
char * string
STRING.
Definition: newgen_types.h:39
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
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
#define entity_storage(x)
Definition: ri.h:2794
#define entity_name(x)
Definition: ri.h:2790
#define entity_type(x)
Definition: ri.h:2792
#define entity_initial(x)
Definition: ri.h:2796
const char * CurrentPackage
the name of the current package, i.e.
Definition: parser.c:58

References asprintf, CONS, CurrentPackage, ENTITY, entity_initial, entity_name, entity_storage, entity_type, F95_USE_LOCAL_NAME, FindOrCreateEntity(), FOREACH, hash_get(), HASH_UNDEFINED_VALUE, make_storage_rom(), make_type_unknown(), make_value_unknown(), malloc(), and ns2use.

Referenced by gfc2pips_namespace().

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

◆ gfc2pips_add_to_callees()

void gfc2pips_add_to_callees ( entity  e)

Add an entity to the list of callees.

Definition at line 67 of file gfc2pips-util.c.

67  {
68 
70  != 0) {
71  gfc2pips_debug(5, "Add callee : %s\n", entity_local_name( e ) );
73  }
74 }
#define gfc2pips_debug
int strcmp_(__const char *__s1, __const char *__s2)
insensitive case comparison
list gfc_module_callees
FIXME: should be generated...
Definition: gfc2pips-util.c:40
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 intrinsic_entity_p(entity e)
Definition: entity.c:1272

References CONS, CurrentPackage, entity_local_name(), gfc2pips_debug, gfc_module_callees, intrinsic_entity_p(), and strcmp_().

Referenced by gfc2pips_code2instruction_(), and gfc2pips_get_extern_entities().

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

◆ gfc2pips_get_last_loop()

gfc_code* gfc2pips_get_last_loop ( void  )

Definition at line 348 of file gfc2pips-util.c.

348  {
350  return gfc2pips_list_of_loops->car.e;
351  return NULL;
352 }
list gfc2pips_list_of_loops
Definition: gfc2pips-util.c:42
gen_chunk car
The data payload of a list element.
Definition: newgen_list.h:42
void * e
For externals (foreign objects)
Definition: genC.h:65

References cons::car, gen_chunk::e, and gfc2pips_list_of_loops.

Referenced by gfc2pips_code2instruction(), and gfc2pips_code2instruction_().

+ Here is the caller graph for this function:

◆ gfc2pips_get_use_st()

void gfc2pips_get_use_st ( void  )

Definition at line 278 of file gfc2pips-util.c.

278  {
279 
280  char c;
281  string use = "USE";
282  int len = strlen(use);
283 
284  gfc_char_t *p = gfc_current_locus.nextc;
285  // Fixme : p == NULL
286  while(!(char)*p == '\0')
287  p++;
288  char use_stmt[len + (p - gfc_current_locus.nextc) + 2];
289 
290  strcpy(use_stmt, use);
291  p = gfc_current_locus.nextc;
292  int pos = len;
293  do {
294  if(p == NULL) {
295  c = '\0';
296  } else {
297  c = *p++;
298  }
299 
300  use_stmt[pos++] = c;
301  } while(c != '\0');
302  if(ns2use == NULL) {
304  }
305  list use_stmts;
306  if((use_stmts = hash_get(ns2use, (char *)gfc_current_ns))
308  use_stmts = CONS(string, strdup(use_stmt), NIL );
309  hash_put(ns2use, (char *)gfc_current_ns, (char *)use_stmts);
310  } else {
311  CONS(string, strdup(use_stmt), use_stmts );
312  }
313 
314 }
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
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_pointer
Definition: newgen_hash.h:32
char * strdup()

References CONS, hash_get(), hash_pointer, hash_put(), hash_table_make(), HASH_UNDEFINED_VALUE, NIL, ns2use, and strdup().

+ Here is the call graph for this function:

◆ gfc2pips_pop_loop()

void gfc2pips_pop_loop ( void  )

Definition at line 356 of file gfc2pips-util.c.

356  {
358 }

References gfc2pips_list_of_loops, and POP.

Referenced by gfc2pips_code2instruction_().

+ Here is the caller graph for this function:

◆ gfc2pips_push_loop()

void gfc2pips_push_loop ( gfc_code *  c)

Definition at line 353 of file gfc2pips-util.c.

References gen_cons(), and gfc2pips_list_of_loops.

Referenced by gfc2pips_code2instruction_().

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

◆ gfc2pips_truncate_useless_zeroes()

void gfc2pips_truncate_useless_zeroes ( char *  s)

expurgates a string representing a REAL, could be a pre-prettyprinter processing

1.0000000000e+00 becomes 1. 1234.5670000e+18 becomes 1234.567e+18

f(*s=='.'){ s='\0'; s–; gfc2pips_debug(9,"final dot retrieved\n"); }

Definition at line 172 of file gfc2pips-util.c.

172  {
173  char *start = s;
174  bool has_dot = false;
175  char *end_sci = NULL;//scientific output ?
176  while(*s) {
177  if(*s == '.') {
178  has_dot = true;
179  gfc2pips_debug(9,"found [dot] at %lu\n",s-start);
180  s++;
181  while(*s) {
182  if(*s == 'e') {
183  end_sci = s;
184  break;
185  }
186  s++;
187  }
188  break;
189  }
190  s++;
191  }
192  if(has_dot) {
193  int nb = 0;
194  if(end_sci) {
195  s = end_sci - 1;
196  } else {
197  s = start + strlen(start);
198  }
199 
200  while(s > start) {
201  if(*s == '0') {
202  *s = '\0';
203  nb++;
204  } else {
205  break;
206  }
207  s--;
208  }
209  gfc2pips_debug(9,"%d zero(s) retrieved\n", nb);
210  /*if(*s=='.'){
211  *s='\0';
212  s--;
213  gfc2pips_debug(9,"final dot retrieved\n");
214  }*/
215  if(end_sci) {
216  if(strcmp(end_sci, "e+00") == 0) {
217  *(s + 1) = '\0';
218  } else if(s != end_sci - 1) {
219  strcpy(s + 1, end_sci);
220  }
221  }
222  }
223 }
static char start[1024]
The name of the variable from which to start counting domain numbers.
Definition: genLisp.c:55

References gfc2pips_debug, and start.

Referenced by gfc2pips_real2entity().

+ Here is the caller graph for this function:

◆ load_entities()

void load_entities ( )

Definition at line 225 of file gfc2pips-util.c.

225  {
226  FILE *entities =
227  (FILE *)safe_fopen((char *)gfc_option.gfc2pips_entities, "r");
228  int read = gen_read_tabulated(entities, FALSE);
229  safe_fclose(entities, (char *)gfc_option.gfc2pips_entities);
230  pips_assert("entities were read", read==entity_domain);
231 }
FILE * safe_fopen(const char *filename, const char *what)
Definition: file.c:67
int safe_fclose(FILE *stream, const char *filename)
Definition: file.c:77
int gen_read_tabulated(FILE *file, int create_p)
GEN_READ_TABULATED reads FILE to update the Gen_tabulated_ table.
Definition: genClib.c:2334
gfc_option_t gfc_option
Cmd line options.
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define entity_domain
newgen_syntax_domain_defined
Definition: ri.h:410

References entity_domain, gen_read_tabulated(), gfc_option, pips_assert, safe_fclose(), and safe_fopen().

Referenced by pips_init().

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

◆ pips_init()

void pips_init ( )

get NewGen data type description

Definition at line 240 of file gfc2pips-util.c.

240  {
241 
242  static int initialized = FALSE;
243 
244  if (!initialized)
245  {
246  // FIXME:
247  set_pips_meta_informations("<unknown>", "<unknown>", "<unknown>");
248 
249  /* get NewGen data type description */
250  // gen_read_spec(ALL_SPECS);
252  text_spec,
255  (char*)NULL);
256 
258  (void* (*)())vect_gen_read,
259  (void(*)())vect_gen_write,
260  (void(*)())vect_gen_free,
261  (void* (*)())vect_gen_copy_tree,
262  (int(*)())vect_gen_allocated_memory);
263 
264  // Pips init
265  load_entities();
266 
267  initialized = TRUE;
268  }
269 }
void set_pips_meta_informations(const char *revs, const char *date, const char *comp)
Definition: message.c:102
#define c_parser_private_spec
#define PVECTEUR_NEWGEN_EXTERNAL
Definition: compsec.h:27
void gen_init_external(int which, void *(*read)(FILE *, int(*)(void)), void(*write)(FILE *, void *), void(*free)(void *), void *(*copy)(void *), int(*allocated_memory)(void *))
GEN_INIT_EXTERNAL defines entry points for free, read and write functions of external types.
Definition: genClib.c:2276
void gen_read_spec(char *spec,...)
Definition: genClib.c:2218
void load_entities()
Pvecteur vect_gen_copy_tree(Pvecteur)
Definition: Pvecteur.c:163
void vect_gen_write(FILE *, Pvecteur)
Pvecteur.c.
Definition: Pvecteur.c:108
Pvecteur vect_gen_read(FILE *, int(*)(void))
int vect_gen_allocated_memory(Pvecteur)
Definition: Pvecteur.c:168
void vect_gen_free(Pvecteur)
Definition: Pvecteur.c:158
#define parser_private_spec
#define ri_spec
Definition: ri.h:3168
#define text_spec
Definition: text.h:157

References c_parser_private_spec, gen_init_external(), gen_read_spec(), load_entities(), parser_private_spec, PVECTEUR_NEWGEN_EXTERNAL, ri_spec, set_pips_meta_informations(), text_spec, vect_gen_allocated_memory(), vect_gen_copy_tree(), vect_gen_free(), vect_gen_read(), and vect_gen_write().

Referenced by gfc2pips_namespace().

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

◆ save_entities()

void save_entities ( )

Definition at line 233 of file gfc2pips-util.c.

233  {
234  FILE *entities =
235  (FILE *)safe_fopen((char *)gfc_option.gfc2pips_entities, "w");
237  safe_fclose(entities, (char *)gfc_option.gfc2pips_entities);
238 }
int gen_write_tabulated(FILE *fd, int domain)
GEN_WRITE_TABULATED writes the tabulated object TABLE on FD.
Definition: genClib.c:1866

References entity_domain, gen_write_tabulated(), gfc_option, safe_fclose(), and safe_fopen().

Referenced by gfc2pips_namespace().

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

◆ str2upper()

char* str2upper ( char  s[])

Here are few utility functions to handle splitted files and do comparisons with case insensitive.

put the given char table to upper case

replace lower case char by upper case ones

Definition at line 83 of file gfc2pips-util.c.

83  {
84 
85  // FIXME Disabled !!!
86  // return s;
87 
88  int n = 0;
89  if(s && s[n] != '\0') {
90  do {
91  s[n] = toupper(s[n]);
92  n++;
93  } while(s[n] != '\0');
94  }
95  return s;
96 }

Referenced by gfc2pips_char2entity(), gfc2pips_check_entity_block_data_exists(), gfc2pips_check_entity_doesnt_exists(), gfc2pips_check_entity_exists(), gfc2pips_check_entity_module_exists(), gfc2pips_check_entity_program_exists(), gfc2pips_expr2entity(), gfc2pips_expr2expression(), gfc2pips_getbasic(), gfc2pips_symbol2entity(), gfc2pips_symbol2top_entity(), gfc2pips_vars_(), strcmp_(), and strncmp_().

+ Here is the caller graph for this function:

◆ strcmp_()

int strcmp_ ( __const char *  __s1,
__const char *  __s2 
)

insensitive case comparison

compare the strings in upper case mode

Definition at line 119 of file gfc2pips-util.c.

119  {
120  char *a = str2upper(strdup(__s1));
121  char *b = str2upper(strdup(__s2));
122  int ret = strcmp(a, b);
123  free(a);
124  free(b);
125  return ret;
126 }
#define ret(why, what)
true if not a remapping for old.
Definition: dynamic.c:986
void free(void *)
char * str2upper(char s[])
Here are few utility functions to handle splitted files and do comparisons with case insensitive.
Definition: gfc2pips-util.c:83

References free(), ret, str2upper(), and strdup().

Referenced by __attribute__(), gfc2pips_add_to_callees(), and gfc2pips_namespace().

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

◆ strn2upper()

char* strn2upper ( char  s[],
size_t  n 
)

replace lower case char by upper case ones

put the n first elements of the given char table to upper case

Definition at line 100 of file gfc2pips-util.c.

100  {
101  while(n) {
102  s[n - 1] = toupper(s[n - 1]);
103  n--;
104  }
105  return s;
106 }

◆ strncmp_()

int strncmp_ ( __const char *  __s1,
__const char *  __s2,
size_t  __n 
)

insensitive case n-comparison

compare the strings in upper case mode

Definition at line 131 of file gfc2pips-util.c.

131  {
132  char *a = str2upper(strdup(__s1));
133  char *b = str2upper(strdup(__s2));
134  int ret = strncmp(a, b, __n);
135  free(a);
136  free(b);
137  return ret;
138 }

References free(), ret, str2upper(), and strdup().

Referenced by gfc2pips_get_safe_name().

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

◆ strrcpy()

char* strrcpy ( char *  dest,
__const char *  src 
)

copy a string from the last char (to allow copy on itself)

same as strcpy, but begin by the end of the string allowing you to give twice the same string

Definition at line 110 of file gfc2pips-util.c.

110  {
111  int i = strlen(src);
112  while(i--)
113  dest[i] = src[i];
114  return dest;
115 }
#define src(name, suf)
HPFC by Fabien Coelho, May 1993 and later...
Definition: compile.c:41

References src.

Referenced by gfc2pips_push_comment().

+ Here is the caller graph for this function:

Variable Documentation

◆ gfc2pips_list_of_declared_code

list gfc2pips_list_of_declared_code = NULL

◆ gfc2pips_list_of_loops

list gfc2pips_list_of_loops = NULL

Definition at line 42 of file gfc2pips-util.c.

Referenced by gfc2pips_get_last_loop(), gfc2pips_pop_loop(), and gfc2pips_push_loop().

◆ gfc_module_callees

list gfc_module_callees = NULL

FIXME: should be generated...

Store the list of callees.

Definition at line 40 of file gfc2pips-util.c.

Referenced by gfc2pips_add_to_callees(), and gfc2pips_namespace().

◆ ns2use

hash_table ns2use = NULL

void gfc2pips_get_use_st( void );

This function is called by the GFC parser when encountering a USE statement. It'll produce an entry in "ns2use" hashtable

Definition at line 277 of file gfc2pips-util.c.

Referenced by get_use_entities_list(), and gfc2pips_get_use_st().