PIPS
gfc2pips-private.h
Go to the documentation of this file.
1 /*
2 
3  $Id: gfc2pips-private.h 23065 2016-03-02 09:05:50Z coelho $
4 
5  Copyright 1989-2016 MINES ParisTech
6  Copyright 2009-2010 HPC-Project
7 
8  This file is part of PIPS.
9 
10  PIPS is free software: you can redistribute it and/or modify it
11  under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  any later version.
14 
15  PIPS is distributed in the hope that it will be useful, but WITHOUT ANY
16  WARRANTY; without even the implied warranty of MERCHANTABILITY or
17  FITNESS FOR A PARTICULAR PURPOSE.
18 
19  See the GNU General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with PIPS. If not, see <http://www.gnu.org/licenses/>.
23 
24  */
25 
26 /*
27 * includes for newgen
28 * a link to the newgen binary file is missing
29 */
30 
31 #ifndef GFC_2_PIPS_PRIVATE
32 #define GFC_2_PIPS_PRIVATE
33 
34 
35 #include "genC.h"
36 #include "gfc2pips.h"
37 
38 #include "linear.h"
39 #include "ri.h"
40 #include "ri-util.h"
41 
42 
43 #include "parser_private.h"
44 #include "syntax.h"
45 
46 
47 /* We have here to HACK GCC include that prevent use of these function */
48 #undef toupper
49 #undef fgetc
50 #undef fputc
51 #undef fread
52 #undef asprintf
53 int asprintf(char **strp, const char *fmt, ...);
54 
55 
56 
57 
58 
59 #define gfc2pips_debug pips_debug
60 
61 //an enum to know what kind of main entity we are dealing with
65 
66 
67 /* Store the list of callees */
69 
70 
73 
74 
76 void pips_init();
77 list get_use_entities_list(struct gfc_namespace *ns);
78 void save_entities();
79 basic gfc2pips_getbasic(gfc_symbol *s);
80 
81 /**
82  * @brief put the given char table to upper case
83  */
84 char * str2upper(char s[]);
85 /**
86  * @brief put the n first elements of the given char table to upper case
87  */
88 char * strn2upper(char s[], size_t n);
89 /**
90  * @brief same as strcpy, but begin by the end of the string allowing you to give twice the same string
91  */
92 char * strrcpy(char *dest, __const char *src);
93 /**
94  * @brief compare the strings in upper case mode
95  */
96 int strcmp_ (__const char *__s1, __const char *__s2);
97 /**
98  * @brief compare the strings in upper case mode
99  */
100 int strncmp_ (__const char *__s1, __const char *__s2, size_t __n);
101 /**
102  * @brief copy the content of the first file to the second one
103  */
104 int fcopy(const char* old, const char* new );
105 
106 
108 
109 
110 
111 /*
112  * Dump a namespace
113  */
114 void gfc2pips_namespace(gfc_namespace* ns);
115 
116 /*
117  * Return a list of every and each arguments for PIPS from a gfc function/subroutine
118  */
119 list gfc2pips_args(gfc_namespace* ns);
120 
121 void gfc2pips_generate_parameters_list(list parameters);
122 
123 /*
124  * Find a symbol by it reference name
125  * Simplified version of
126  * static gfc_symtree * find_symbol (gfc_symtree *st, const char *name, const char *module, int generic);
127  */
128 gfc_symtree* gfc2pips_getSymtreeByName (const char* name, gfc_symtree *st);
129 
130 gfc2pips_main_entity_type get_symbol_token( gfc_symbol *root_sym );
131 
132 list gfc2pips_vars(gfc_namespace *ns);
133 list gfc2pips_parameters( gfc_namespace * ns,
134  gfc2pips_main_entity_type bloc_token );
135 list gfc2pips_vars_(gfc_namespace *ns,list variables_p);
136 void gfc2pips_getTypesDeclared(gfc_namespace *ns);
137 list gfc2pips_get_extern_entities(gfc_namespace *ns);
138 list gfc2pips_get_data_vars(gfc_namespace *ns);
139 list gfc2pips_get_save(gfc_namespace *ns);
140 
141 list gfc2pips_get_list_of_dimensions(gfc_symtree *st);
143 
144 /*
145  * Find a list of symbols if they verify the predicate function
146  */
147 list getSymbolBy(gfc_namespace* ns, gfc_symtree *st, bool (*func)(gfc_namespace*, gfc_symtree *));
148 
149 /*
150  * Predicate functions
151  */
152 bool gfc2pips_test_variable(gfc_namespace* __attribute__ ((__unused__)) ns, gfc_symtree *st);
153 bool gfc2pips_test_variable2(gfc_namespace* __attribute__ ((__unused__)) ns, gfc_symtree *st );
154 bool gfc2pips_test_derived(gfc_namespace __attribute__ ((__unused__)) *ns, gfc_symtree *st );
155 bool gfc2pips_test_extern(gfc_namespace* __attribute__ ((__unused__)) ns, gfc_symtree *st );
156 bool gfc2pips_test_subroutine(gfc_namespace* __attribute__ ((__unused__)) ns, gfc_symtree *st );
157 //bool gfc2pips_test_name(gfc_namespace* ns, gfc_symtree *st, int param);
158 bool gfc2pips_test_data(gfc_namespace* __attribute__ ((__unused__)) ns, gfc_symtree *st );
159 bool gfc2pips_test_save(gfc_namespace* __attribute__ ((__unused__)) ns, gfc_symtree *st );
160 bool gfc2pips_get_commons(gfc_namespace* __attribute__ ((__unused__)) ns, gfc_symtree* __attribute__ ((__unused__)) st );
161 bool gfc2pips_get_incommon(gfc_namespace* __attribute__ ((__unused__)) ns, gfc_symtree* __attribute__ ((__unused__)) st );
162 bool gfc2pips_test_dimensions(gfc_namespace* __attribute__ ((__unused__)) ns, gfc_symtree* st );
163 
168 entity gfc2pips_check_entity_exists(const char *s);
169 entity gfc2pips_symbol2entity(gfc_symbol* sym);
170 entity gfc2pips_symbol2top_entity(gfc_symbol* sym);
171 entity gfc2pips_char2entity(char*p, char* s);
172 char* gfc2pips_get_safe_name(const char* str);
173 
174 
175 /*
176  * Functions about the translation of something from gfc into a pips "dimension" object
177  */
179 
180 expression gfc2pips_int2expression(int n);//PIPS: expression int_to_expression(_int)
183 
186 entity gfc2pips_real2entity(double r);
188 char* gfc2pips_gfc_char_t2string(gfc_char_t *c,int nb);
189 char* gfc2pips_gfc_char_t2string2(gfc_char_t *c);
190 char* gfc2pips_gfc_char_t2string_(gfc_char_t *c,int nb);
191 
193 
194 type gfc2pips_symbol2type(gfc_symbol *s);
195 int gfc2pips_symbol2size(gfc_symbol *s);
196 int gfc2pips_symbol2sizeArray(gfc_symbol *s);
197 
198 list gfc2pips_array_ref2indices(gfc_array_ref *ar);
199 bool gfc2pips_there_is_a_range(gfc_array_ref *ar);
200 list gfc2pips_mkRangeExpression(gfc_array_ref *ar);
201 
202 
203 instruction gfc2pips_code2instruction__TOP(gfc_namespace *ns, gfc_code* c);
204 instruction gfc2pips_code2instruction(gfc_code* c, bool force_sequence);
206 expression gfc2pips_buildCaseTest(gfc_expr *tested_variable, gfc_case *cp);
207 list gfc2pips_dumpSELECT(gfc_code *c);
211 entity gfc2pips_code2get_label(gfc_code *c);
212 entity gfc2pips_code2get_label2(gfc_code *c);
213 entity gfc2pips_code2get_label3(gfc_code *c);
214 entity gfc2pips_code2get_label4(gfc_code *c);
215 
216 expression gfc2pips_expr2expression(gfc_expr *expr);
217 int gfc2pips_expr2int(gfc_expr *expr);
218 bool gfc2pips_exprIsVariable(gfc_expr * expr);
219 entity gfc2pips_expr2entity(gfc_expr *expr);
220 
221 //translate an expression or a value of a IO statement
222 list gfc2pips_exprIO(char* s, gfc_expr* e, list l);
223 list gfc2pips_exprIO2(char* s, int e, list l);
224 list gfc2pips_exprIO3(char* s, string e, list l);
225 
226 list gfc2pips_arglist2arglist(gfc_actual_arglist *act);
227 
228 //memory related functions
230 void gfc2pips_computeAdresses(void);
235 void gfc2pips_shiftAdressesOfArea( entity _area, int old_offset, int size, int max_offset, int shift );
236 
238 
239 
240 void gfc2pips_push_comment(locus l, unsigned long nb, char s);
241 bool gfc2pips_check_already_done(locus l);
242 unsigned long gfc2pips_get_num_of_gfc_code(gfc_code *c);
243 string gfc2pips_get_comment_of_code(gfc_code *c);
245 //void gfc2pips_set_last_comments_done(gfc_code *c);
246 void gfc2pips_set_last_comments_done(unsigned long nb);
247 void gfc2pips_assign_num_to_last_comments(unsigned long nb);
249 void gfc2pips_replace_comments_num(unsigned long old, unsigned long new);
250 void gfc2pips_assign_gfc_code_to_num_comments(gfc_code *c, unsigned long num);
251 bool gfc2pips_comment_num_exists(unsigned long num);
253 
254 void gfc2pips_shift_comments(void);
255 
256 void gfc2pips_push_last_code(gfc_code *c);
257 
258 gfc_code* gfc2pips_get_last_loop(void);
259 void gfc2pips_push_loop(gfc_code *c);
260 void gfc2pips_pop_loop(void);
261 
262 list gen_union(list a, list b);
263 
264 #endif /* GFC_2_PIPS */
265 
float a2sf[2] __attribute__((aligned(16)))
USER generates a user error (i.e., non fatal) by printing the given MSG according to the FMT.
Definition: 3dnow.h:3
static int num
Definition: bourdoncle.c:137
void gfc2pips_shift_comments(void)
We assign a gfc_code depending to a list of comments if any depending on the number of the statement.
bool gfc2pips_test_extern(gfc_namespace *__attribute__((__unused__)) ns, gfc_symtree *st)
list gfc2pips_dumpSELECT(gfc_code *c)
Definition: gfc2pips.c:3399
void gfc2pips_computeAdressesDynamic(void)
compute the addresses of the entities declared in DynamicArea
Definition: gfc2pips.c:4347
entity gfc2pips_code2get_label(gfc_code *c)
Definition: gfc2pips.c:3756
list gfc2pips_parameters(gfc_namespace *ns, gfc2pips_main_entity_type bloc_token)
Definition: gfc2pips.c:793
expression gfc2pips_make_zero_for_symbol(gfc_symbol *sym)
Definition: gfc2pips.c:3646
int asprintf(char **strp, const char *fmt,...)
We have here to HACK GCC include that prevent use of these function.
Definition: asprintf.c:30
void gfc2pips_computeAdressesStatic(void)
compute the addresses of the entities declared in StaticArea
Definition: gfc2pips.c:4341
list gfc2pips_args(gfc_namespace *ns)
Retrieve the list of names of every argument of the function, if any.
Definition: gfc2pips.c:847
bool gfc2pips_get_incommon(gfc_namespace *__attribute__((__unused__)) ns, gfc_symtree *__attribute__((__unused__)) st)
list gfc2pips_exprIO(char *s, gfc_expr *e, list l)
Definition: gfc2pips.c:4309
expression gfc2pips_expr2expression(gfc_expr *expr)
Definition: gfc2pips.c:3837
int gfc2pips_computeAdressesOfArea(entity _area)
compute the addresses of the entities declared in the given entity
Definition: gfc2pips.c:4360
void gfc2pips_getTypesDeclared(gfc_namespace *ns)
Definition: gfc2pips.c:1119
list gfc2pips_exprIO3(char *s, string e, list l)
Definition: gfc2pips.c:4319
list gen_union(list a, list b)
generate an union of unique elements taken from A and B
Definition: gfc2pips-util.c:47
string gfc2pips_get_comment_of_code(gfc_code *c)
entity gfc2pips_int2label(int n)
dump an integer to a PIPS label entity
Definition: gfc2pips.c:1785
unsigned long gfc2pips_get_num_of_gfc_code(gfc_code *c)
char * gfc2pips_get_safe_name(const char *str)
gfc replace some functions by an homemade one, we check and return a copy of the original one if it i...
Definition: gfc2pips.c:1720
gfc2pips_main_entity_type
@ MET_PROG
@ MET_MOD
@ MET_FUNC
@ MET_MODULE
@ MET_SUB
@ MET_BLOCK
void gfc2pips_truncate_useless_zeroes(char *s)
expurgates a string representing a REAL, could be a pre-prettyprinter processing
entity gfc2pips_check_entity_doesnt_exists(char *s)
Definition: gfc2pips.c:1497
list * gfc2pips_list_of_all_modules
bool gfc2pips_check_already_done(locus l)
int fcopy(const char *old, const char *new)
copy the content of the first file to the second one
list gfc2pips_get_list_of_dimensions2(gfc_symbol *s)
build a list - if any - of dimension elements from the gfc_symbol given
Definition: gfc2pips.c:1267
void gfc2pips_generate_parameters_list(list parameters)
replace a list of entities by a list of parameters to those entities
Definition: gfc2pips.c:896
type gfc2pips_symbol2type(gfc_symbol *s)
try to create the PIPS type that would be associated by the PIPS default parser
Definition: gfc2pips.c:1966
entity gfc2pips_real2entity(double r)
dump reals to PIPS entities
Definition: gfc2pips.c:1801
bool gfc2pips_comment_num_exists(unsigned long num)
void gfc2pips_replace_comments_num(unsigned long old, unsigned long new)
void gfc2pips_computeAdresses(void)
compute addresses of the stack, heap, dynamic and static areas
Definition: gfc2pips.c:4332
list getSymbolBy(gfc_namespace *ns, gfc_symtree *st, bool(*func)(gfc_namespace *, gfc_symtree *))
Look for a set of symbols filtered by a predicate function.
Definition: gfc2pips.c:1344
void gfc2pips_add_to_callees(entity e)
Add an entity to the list of callees.
Definition: gfc2pips-util.c:67
instruction gfc2pips_code2instruction_(gfc_code *c)
this function create an atomic statement, no block of data
Definition: gfc2pips.c:2479
instruction gfc2pips_code2instruction(gfc_code *c, bool force_sequence)
Build an instruction sequence.
Definition: gfc2pips.c:2368
list gfc2pips_exprIO2(char *s, int e, list l)
Definition: gfc2pips.c:4314
void pips_init()
char * strrcpy(char *dest, __const char *src)
same as strcpy, but begin by the end of the string allowing you to give twice the same string
list gfc2pips_get_extern_entities(gfc_namespace *ns)
build a list of externals entities
Definition: gfc2pips.c:1219
int strcmp_(__const char *__s1, __const char *__s2)
compare the strings in upper case mode
bool gfc2pips_test_variable2(gfc_namespace *__attribute__((__unused__)) ns, gfc_symtree *st)
char * gfc2pips_gfc_char_t2string_(gfc_char_t *c, int nb)
translate a string from a table of integers in gfc to one of chars in PIPS, escape all ' in the strin...
Definition: gfc2pips.c:1853
list gfc2pips_get_data_vars(gfc_namespace *ns)
return a list of elements needing a DATA statement
Definition: gfc2pips.c:1244
list gfc2pips_list_of_loops
Definition: gfc2pips-util.c:42
list gfc2pips_get_list_of_dimensions(gfc_symtree *st)
build a list - if any - of dimension elements from the gfc_symtree given
Definition: gfc2pips.c:1257
void gfc2pips_set_last_comments_done(unsigned long nb)
void gfc2pips_push_comment(locus l, unsigned long nb, char s)
list gfc2pips_get_save(gfc_namespace *ns)
return a list of SAVE elements
Definition: gfc2pips.c:1250
entity gfc2pips_int_const2entity(int n)
translate an integer to a PIPS constant, assume n is positive (or it will not be handled properly)
Definition: gfc2pips.c:1776
void gfc2pips_namespace(gfc_namespace *ns)
Entry point for gfc2pips translation This will be called each time the parser encounter subroutine,...
Definition: gfc2pips.c:114
entity gfc2pips_code2get_label4(gfc_code *c)
Definition: gfc2pips.c:3814
entity gfc2pips_check_entity_block_data_exists(char *s)
Definition: gfc2pips.c:1558
void gfc2pips_assign_gfc_code_to_last_comments(gfc_code *c)
void gfc2pips_assign_gfc_code_to_num_comments(gfc_code *c, unsigned long num)
void gfc2pips_initAreas(void)
void gfc2pips_assign_num_to_last_comments(unsigned long nb)
entity gfc2pips_symbol2top_entity(gfc_symbol *sym)
translate a gfc symbol to a top-level entity
Definition: gfc2pips.c:1684
instruction gfc2pips_code2instruction__TOP(gfc_namespace *ns, gfc_code *c)
Declaration of instructions.
Definition: gfc2pips.c:2119
list gfc2pips_arglist2arglist(gfc_actual_arglist *act)
Definition: gfc2pips.c:4287
expression gfc2pips_int2expression(int n)
translate a int to an expression
Definition: gfc2pips.c:1745
instruction gfc2pips_symbol2data_instruction(gfc_symbol *sym)
build a DATA statement, filling blanks with zeroes.
Definition: gfc2pips.c:3501
entity gfc2pips_code2get_label2(gfc_code *c)
Definition: gfc2pips.c:3778
entity gfc2pips_symbol2entity(gfc_symbol *sym)
translate a gfc symbol to a PIPS entity, check if it is a function, program, subroutine or else
Definition: gfc2pips.c:1582
gfc2pips_main_entity_type get_symbol_token(gfc_symbol *root_sym)
Definition: gfc2pips.c:772
gfc_code * gfc2pips_get_last_loop(void)
char * gfc2pips_gfc_char_t2string(gfc_char_t *c, int nb)
translate a string from a table of integers in gfc to one of chars in PIPS, escape all ' in the strin...
Definition: gfc2pips.c:1832
expression gfc2pips_logical2expression(bool b)
translate a bool to an expression
Definition: gfc2pips.c:1768
bool gfc2pips_test_subroutine(gfc_namespace *__attribute__((__unused__)) ns, gfc_symtree *st)
bool gfc2pips_exprIsVariable(gfc_expr *expr)
Definition: gfc2pips.c:4242
gfc_symtree * gfc2pips_getSymtreeByName(const char *name, gfc_symtree *st)
list gfc2pips_mkRangeExpression(gfc_array_ref *ar)
bool gfc2pips_test_variable(gfc_namespace *__attribute__((__unused__)) ns, gfc_symtree *st)
expression gfc2pips_real2expression(double r)
translate a real to an expression
Definition: gfc2pips.c:1757
void save_entities()
int gfc2pips_symbol2sizeArray(gfc_symbol *s)
calculate the total size of the array whatever the bounds are: A(-5,5)
Definition: gfc2pips.c:2008
entity gfc2pips_check_entity_module_exists(char *s)
Definition: gfc2pips.c:1537
list gfc2pips_array_ref2indices(gfc_array_ref *ar)
convert a list of indices from gfc to PIPS, assume there is no range (dump only the min range element...
Definition: gfc2pips.c:2032
list gfc2pips_vars(gfc_namespace *ns)
Extract every and each variable from a namespace.
Definition: gfc2pips.c:954
list gfc_module_callees
Store the list of callees.
Definition: gfc2pips-util.c:40
list get_use_entities_list(struct gfc_namespace *ns)
char * gfc2pips_gfc_char_t2string2(gfc_char_t *c)
translate the <nb> first elements of from a wide integer representation to a char representation
Definition: gfc2pips.c:1875
void gfc2pips_pop_not_done_comments(void)
void gfc2pips_computeAdressesHeap(void)
compute the addresses of the entities declared in StaticArea
Definition: gfc2pips.c:4353
bool gfc2pips_test_derived(gfc_namespace __attribute__((__unused__)) *ns, gfc_symtree *st)
Definition: gfc2pips.c:1407
expression gfc2pips_buildCaseTest(gfc_expr *tested_variable, gfc_case *cp)
Definition: gfc2pips.c:3364
dimension gfc2pips_int2dimension(int n)
create a <dimension> from the integer value given
Definition: gfc2pips.c:1736
int strncmp_(__const char *__s1, __const char *__s2, size_t __n)
compare the strings in upper case mode
void gfc2pips_push_last_code(gfc_code *c)
basic gfc2pips_getbasic(gfc_symbol *s)
Definition: gfc2pips.c:1909
gfc2pips_comments gfc2pips_pop_comment(void)
int gfc2pips_symbol2size(gfc_symbol *s)
return the size of an elementary element: REAL*16 A CHARACTER*17 B
Definition: gfc2pips.c:1990
list gfc2pips_list_of_declared_code
Definition: gfc2pips-util.c:41
entity gfc2pips_expr2entity(gfc_expr *expr)
create an entity based on an expression, assume it is used only for incremented variables in loops
Definition: gfc2pips.c:4249
entity gfc2pips_check_entity_program_exists(char *s)
Definition: gfc2pips.c:1527
void gfc2pips_push_loop(gfc_code *c)
bool gfc2pips_test_data(gfc_namespace *__attribute__((__unused__)) ns, gfc_symtree *st)
list gfc2pips_reduce_repeated_values(list l)
look for repeated values (integers or real) in the list (list for DATA instructions) and transform th...
Definition: gfc2pips.c:3669
value gfc2pips_symbol2value(gfc_symbol *s)
entity gfc2pips_check_entity_exists(const char *s)
Definition: gfc2pips.c:1567
bool gfc2pips_there_is_a_range(gfc_array_ref *ar)
entity gfc2pips_logical2entity(bool b)
translate a boolean to a PIPS/fortran entity
Definition: gfc2pips.c:1820
char * strn2upper(char s[], size_t n)
put the n first elements of the given char table to upper case
char * str2upper(char s[])
put the given char table to upper case
Definition: gfc2pips-util.c:83
bool gfc2pips_test_save(gfc_namespace *__attribute__((__unused__)) ns, gfc_symtree *st)
bool gfc2pips_test_dimensions(gfc_namespace *__attribute__((__unused__)) ns, gfc_symtree *st)
entity gfc2pips_char2entity(char *p, char *s)
a little bit more elaborated FindOrCreateEntity
Definition: gfc2pips.c:1705
bool gfc2pips_get_commons(gfc_namespace *__attribute__((__unused__)) ns, gfc_symtree *__attribute__((__unused__)) st)
void gfc2pips_shiftAdressesOfArea(entity _area, int old_offset, int size, int max_offset, int shift)
Definition: gfc2pips.c:4488
int gfc2pips_expr2int(gfc_expr *expr)
Definition: gfc2pips.c:4238
entity gfc2pips_code2get_label3(gfc_code *c)
Definition: gfc2pips.c:3796
list gfc2pips_vars_(gfc_namespace *ns, list variables_p)
Convert the list of gfc symbols into a list of pips entities with storage, type, everything.
Definition: gfc2pips.c:966
void gfc2pips_pop_loop(void)
#define src(name, suf)
HPFC by Fabien Coelho, May 1993 and later...
Definition: compile.c:41
Pvecteur cp
pointeur sur l'egalite ou l'inegalite courante
Definition: sc_read.c:87
The structure used to build lists in NewGen.
Definition: newgen_list.h:41