]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/fortran/trans.h
Daily bump.
[thirdparty/gcc.git] / gcc / fortran / trans.h
CommitLineData
6de9cd9a 1/* Header for code translation functions
710a179f
TS
2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Free Software
3 Foundation, Inc.
6de9cd9a
DN
4 Contributed by Paul Brook
5
9fc4d79b 6This file is part of GCC.
6de9cd9a 7
9fc4d79b
TS
8GCC is free software; you can redistribute it and/or modify it under
9the terms of the GNU General Public License as published by the Free
d234d788 10Software Foundation; either version 3, or (at your option) any later
9fc4d79b 11version.
6de9cd9a 12
9fc4d79b
TS
13GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14WARRANTY; without even the implied warranty of MERCHANTABILITY or
15FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16for more details.
6de9cd9a
DN
17
18You should have received a copy of the GNU General Public License
d234d788
NC
19along with GCC; see the file COPYING3. If not see
20<http://www.gnu.org/licenses/>. */
6de9cd9a
DN
21
22#ifndef GFC_TRANS_H
23#define GFC_TRANS_H
24
25/* Mangled symbols take the form __module__name. */
26#define GFC_MAX_MANGLED_SYMBOL_LEN (GFC_MAX_SYMBOL_LEN*2+4)
27
28/* Struct for holding a block of statements. It should be treated as an
29 opaque entity and not modified directly. This allows us to change the
30 underlying representation of statement lists. */
31typedef struct
32{
33 tree head;
b40410b9 34 unsigned int has_scope:1;
6de9cd9a
DN
35}
36stmtblock_t;
37
1f2959f0 38/* a simplified expression */
6de9cd9a
DN
39typedef struct gfc_se
40{
41 /* Code blocks to be executed before and after using the value. */
42 stmtblock_t pre;
43 stmtblock_t post;
44
45 /* the result of the expression */
46 tree expr;
47
48 /* The length of a character string value. */
49 tree string_length;
50
51 /* If set gfc_conv_variable will return an expression for the array
52 descriptor. When set, want_pointer should also be set.
53 If not set scalarizing variables will be substituted. */
54 unsigned descriptor_only:1;
55
56 /* When this is set gfc_conv_expr returns the address of a variable. Only
57 applies to EXPR_VARIABLE nodes.
58 Also used by gfc_conv_array_parameter. When set this indicates a pointer
59 to the descriptor should be returned, rather than the descriptor itself.
60 */
61 unsigned want_pointer:1;
62
63 /* An array function call returning without a temporary. Also used for array
64 pointer assignments. */
65 unsigned direct_byref:1;
66
67 /* Ignore absent optional arguments. Used for some intrinsics. */
68 unsigned ignore_optional:1;
69
ad5dd90d
PT
70 /* When this is set the data and offset fields of the returned descriptor
71 are NULL. Used by intrinsic size. */
72 unsigned data_not_needed:1;
73
0ee8e250
PT
74 /* If set, gfc_conv_function_call does not put byref calls into se->pre. */
75 unsigned no_function_call:1;
76
6de9cd9a
DN
77 /* Scalarization parameters. */
78 struct gfc_se *parent;
79 struct gfc_ss *ss;
80 struct gfc_loopinfo *loop;
81}
82gfc_se;
83
84
e7dc5b4f 85/* Scalarization State chain. Created by walking an expression tree before
6de9cd9a
DN
86 creating the scalarization loops. Then passed as part of a gfc_se structure
87 to translate the expression inside the loop. Note that these chains are
88 terminated by gfc_se_terminator, not NULL. A NULL pointer in a gfc_se
89 indicates to gfc_conv_* that this is a scalar expression.
90 Note that some member arrays correspond to scalarizer rank and others
91 are the variable rank. */
92
93typedef struct gfc_ss_info
94{
95 int dimen;
96 /* The ref that holds information on this section. */
97 gfc_ref *ref;
98 /* The descriptor of this array. */
99 tree descriptor;
100 /* holds the pointer to the data array. */
101 tree data;
102 /* To move some of the array index calculation out of the innermost loop. */
103 tree offset;
104 tree saved_offset;
105 tree stride0;
106 /* Holds the SS for a subscript. Indexed by actual dimension. */
107 struct gfc_ss *subscript[GFC_MAX_DIMENSIONS];
108
109 /* stride and delta are used to access this inside a scalarization loop.
110 start is used in the calculation of these. Indexed by scalarizer
111 dimension. */
112 tree start[GFC_MAX_DIMENSIONS];
8424e0d8 113 tree end[GFC_MAX_DIMENSIONS];
6de9cd9a
DN
114 tree stride[GFC_MAX_DIMENSIONS];
115 tree delta[GFC_MAX_DIMENSIONS];
116
e7dc5b4f 117 /* Translation from scalarizer dimensions to actual dimensions.
6de9cd9a
DN
118 actual = dim[scalarizer] */
119 int dim[GFC_MAX_DIMENSIONS];
120}
121gfc_ss_info;
122
123typedef enum
124{
125 /* A scalar value. This will be evaluated before entering the
126 scalarization loop. */
127 GFC_SS_SCALAR,
128
2054fc29 129 /* Like GFC_SS_SCALAR except it evaluates a pointer to the expression.
6de9cd9a
DN
130 Used for elemental function parameters. */
131 GFC_SS_REFERENCE,
132
133 /* An array section. Scalarization indices will be substituted during
134 expression translation. */
135 GFC_SS_SECTION,
136
137 /* A non-elemental function call returning an array. The call is executed
138 before entering the scalarization loop, storing the result in a
139 temporary. This temporary is then used inside the scalarization loop.
140 Simple assignments, eg. a(:) = fn() are handles without a temporary
141 as a special case. */
142 GFC_SS_FUNCTION,
143
144 /* An array constructor. The current implementation is sub-optimal in
145 many cases. It allocated a temporary, assigns the values to it, then
146 uses this temporary inside the scalarization loop. */
147 GFC_SS_CONSTRUCTOR,
148
7a70c12d
RS
149 /* A vector subscript. The vector's descriptor is cached in the
150 "descriptor" field of the associated gfc_ss_info. */
6de9cd9a
DN
151 GFC_SS_VECTOR,
152
153 /* A temporary array allocated by the scalarizer. Its rank can be less
154 than that of the assignment expression. */
155 GFC_SS_TEMP,
156
157 /* An intrinsic function call. Many intrinsic functions which map directly
158 to library calls are created as GFC_SS_FUNCTION nodes. */
e9cfef64
PB
159 GFC_SS_INTRINSIC,
160
161 /* A component of a derived type. */
162 GFC_SS_COMPONENT
6de9cd9a
DN
163}
164gfc_ss_type;
165
166/* SS structures can only belong to a single loopinfo. They must be added
167 otherwise they will not get freed. */
168typedef struct gfc_ss
169{
170 gfc_ss_type type;
171 gfc_expr *expr;
e9cfef64 172 mpz_t *shape;
40f20186 173 tree string_length;
6de9cd9a
DN
174 union
175 {
176 /* If type is GFC_SS_SCALAR or GFC_SS_REFERENCE. */
177 struct
178 {
179 tree expr;
6de9cd9a
DN
180 }
181 scalar;
182
183 /* GFC_SS_TEMP. */
184 struct
185 {
186 /* The rank of the temporary. May be less than the rank of the
187 assigned expression. */
188 int dimen;
189 tree type;
6de9cd9a
DN
190 }
191 temp;
192 /* All other types. */
193 gfc_ss_info info;
194 }
195 data;
196
197 /* All the SS in a loop and linked through loop_chain. The SS for an
198 expression are linked by the next pointer. */
199 struct gfc_ss *loop_chain;
200 struct gfc_ss *next;
201
e7dc5b4f 202 /* This is used by assignments requiring temporaries. The bits specify which
6de9cd9a
DN
203 loops the terms appear in. This will be 1 for the RHS expressions,
204 2 for the LHS expressions, and 3(=1|2) for the temporary. */
205 unsigned useflags:2;
206}
207gfc_ss;
208#define gfc_get_ss() gfc_getmem(sizeof(gfc_ss))
209
1f2959f0 210/* The contents of this aren't actually used. A NULL SS chain indicates a
6de9cd9a
DN
211 scalar expression, so this pointer is used to terminate SS chains. */
212extern gfc_ss * const gfc_ss_terminator;
213
214/* Holds information about an expression while it is being scalarized. */
215typedef struct gfc_loopinfo
216{
217 stmtblock_t pre;
218 stmtblock_t post;
219
220 int dimen;
221
222 /* All the SS involved with this loop. */
223 gfc_ss *ss;
e7dc5b4f 224 /* The SS describing the temporary used in an assignment. */
6de9cd9a
DN
225 gfc_ss *temp_ss;
226
227 /* The scalarization loop index variables. */
228 tree loopvar[GFC_MAX_DIMENSIONS];
229
230 /* The bounds of the scalarization loops. */
231 tree from[GFC_MAX_DIMENSIONS];
232 tree to[GFC_MAX_DIMENSIONS];
233 gfc_ss *specloop[GFC_MAX_DIMENSIONS];
234
235 /* The code member contains the code for the body of the next outer loop. */
236 stmtblock_t code[GFC_MAX_DIMENSIONS];
237
238 /* Order in which the dimensions should be looped, innermost first. */
239 int order[GFC_MAX_DIMENSIONS];
240
241 /* The number of dimensions for which a temporary is used. */
242 int temp_dim;
243
244 /* If set we don't need the loop variables. */
245 unsigned array_parameter:1;
246}
247gfc_loopinfo;
248
7b5b57b7
PB
249
250/* Information about a symbol that has been shadowed by a temporary. */
251typedef struct
252{
253 symbol_attribute attr;
254 tree decl;
255}
256gfc_saved_var;
257
258
6de9cd9a
DN
259/* Advance the SS chain to the next term. */
260void gfc_advance_se_ss_chain (gfc_se *);
261
aa9c57ec
KH
262/* Call this to initialize a gfc_se structure before use
263 first parameter is structure to initialize, second is
6de9cd9a
DN
264 parent to get scalarization data from, or NULL. */
265void gfc_init_se (gfc_se *, gfc_se *);
266
267/* Create an artificial variable decl and add it to the current scope. */
268tree gfc_create_var (tree, const char *);
269/* Like above but doesn't add it to the current scope. */
270tree gfc_create_var_np (tree, const char *);
271
272/* Store the result of an expression in a temp variable so it can be used
273 repeatedly even if the original changes */
274void gfc_make_safe_expr (gfc_se * se);
275
276/* Makes sure se is suitable for passing as a function string parameter. */
277void gfc_conv_string_parameter (gfc_se * se);
278
0a821a92
FW
279/* Compare two strings. */
280tree gfc_build_compare_string (tree, tree, tree, tree);
281
6de9cd9a
DN
282/* Add an item to the end of TREE_LIST. */
283tree gfc_chainon_list (tree, tree);
284
13795658 285/* When using the gfc_conv_* make sure you understand what they do, i.e.
69de3b83 286 when a POST chain may be created, and what the returned expression may be
6de9cd9a
DN
287 used for. Note that character strings have special handling. This
288 should not be a problem as most statements/operations only deal with
a4f5cd44
PB
289 numeric/logical types. See the implementations in trans-expr.c
290 for details of the individual functions. */
6de9cd9a 291
6de9cd9a 292void gfc_conv_expr (gfc_se * se, gfc_expr * expr);
6de9cd9a 293void gfc_conv_expr_val (gfc_se * se, gfc_expr * expr);
6de9cd9a 294void gfc_conv_expr_lhs (gfc_se * se, gfc_expr * expr);
6de9cd9a 295void gfc_conv_expr_reference (gfc_se * se, gfc_expr *);
6de9cd9a 296void gfc_conv_expr_type (gfc_se * se, gfc_expr *, tree);
a4f5cd44 297
e032c2a1
CR
298/* trans-expr.c */
299void gfc_conv_scalar_char_value (gfc_symbol *sym, gfc_se *se, gfc_expr **expr);
300
ce2df7c6
FW
301/* Find the decl containing the auxiliary variables for assigned variables. */
302void gfc_conv_label_variable (gfc_se * se, gfc_expr * expr);
6de9cd9a
DN
303/* If the value is not constant, Create a temporary and copy the value. */
304tree gfc_evaluate_now (tree, stmtblock_t *);
305
306/* Intrinsic function handling. */
307void gfc_conv_intrinsic_function (gfc_se *, gfc_expr *);
308
309/* Does an intrinsic map directly to an external library call. */
310int gfc_is_intrinsic_libcall (gfc_expr *);
311
a00b8d1a
PT
312/* Used to call the elemental subroutines used in operator assignments. */
313tree gfc_conv_operator_assign (gfc_se *, gfc_se *, gfc_symbol *);
314
6de9cd9a 315/* Also used to CALL subroutines. */
5a0aad31
FXC
316int gfc_conv_function_call (gfc_se *, gfc_symbol *, gfc_actual_arglist *,
317 tree);
d4feb3d3 318
1d6b7f39 319void gfc_conv_subref_array_arg (gfc_se *, gfc_expr *, int, sym_intent);
d4feb3d3 320
6de9cd9a
DN
321/* gfc_trans_* shouldn't call push/poplevel, use gfc_push/pop_scope */
322
323/* Generate code for a scalar assignment. */
5046aff5 324tree gfc_trans_scalar_assign (gfc_se *, gfc_se *, gfc_typespec, bool, bool);
6de9cd9a
DN
325
326/* Translate COMMON blocks. */
327void gfc_trans_common (gfc_namespace *);
328
f7b529fa 329/* Translate a derived type constructor. */
6de9cd9a
DN
330void gfc_conv_structure (gfc_se *, gfc_expr *, int);
331
332/* Return an expression which determines if a dummy parameter is present. */
333tree gfc_conv_expr_present (gfc_symbol *);
e15e9be3
PT
334/* Convert a missing, dummy argument into a null or zero. */
335void gfc_conv_missing_dummy (gfc_se *, gfc_expr *, gfc_typespec);
6de9cd9a
DN
336
337/* Generate code to allocate a string temporary. */
338tree gfc_conv_string_tmp (gfc_se *, tree, tree);
ca2940c3
TS
339/* Get the string length variable belonging to an expression. */
340tree gfc_get_expr_charlen (gfc_expr *);
6de9cd9a 341/* Initialize a string length variable. */
07368af0 342void gfc_conv_string_length (gfc_charlen *, stmtblock_t *);
417ab240
JJ
343/* Ensure type sizes can be gimplified. */
344void gfc_trans_vla_type_sizes (gfc_symbol *, stmtblock_t *);
6de9cd9a
DN
345
346/* Add an expression to the end of a block. */
347void gfc_add_expr_to_block (stmtblock_t *, tree);
348/* Add a block to the end of a block. */
349void gfc_add_block_to_block (stmtblock_t *, stmtblock_t *);
07beea0d
AH
350/* Add a MODIFY_EXPR or a GIMPLE_MODIFY_STMT to a block. */
351void gfc_add_modify (stmtblock_t *, tree, tree, bool);
352#define gfc_add_modify_expr(BLOCK, LHS, RHS) \
353 gfc_add_modify ((BLOCK), (LHS), (RHS), false)
354#define gfc_add_modify_stmt(BLOCK, LHS, RHS) \
355 gfc_add_modify ((BLOCK), (LHS), (RHS), true)
6de9cd9a
DN
356
357/* Initialize a statement block. */
358void gfc_init_block (stmtblock_t *);
69de3b83 359/* Start a new statement block. Like gfc_init_block but also starts a new
6de9cd9a
DN
360 variable scope. */
361void gfc_start_block (stmtblock_t *);
362/* Finish a statement block. Also closes the scope if the block was created
363 with gfc_start_block. */
364tree gfc_finish_block (stmtblock_t *);
365/* Merge the scope of a block with its parent. */
366void gfc_merge_block_scope (stmtblock_t * block);
367
368/* Return the backend label decl. */
369tree gfc_get_label_decl (gfc_st_label *);
370
371/* Return the decl for an external function. */
372tree gfc_get_extern_function_decl (gfc_symbol *);
373
374/* Return the decl for a function. */
375tree gfc_get_function_decl (gfc_symbol *);
376
6de9cd9a
DN
377/* Build an ADDR_EXPR. */
378tree gfc_build_addr_expr (tree, tree);
379
6de9cd9a 380/* Build an ARRAY_REF. */
1d6b7f39 381tree gfc_build_array_ref (tree, tree, tree);
6de9cd9a 382
49de9e73 383/* Creates a label. Decl is artificial if label_id == NULL_TREE. */
6de9cd9a
DN
384tree gfc_build_label_decl (tree);
385
386/* Return the decl used to hold the function return value.
387 Do not use if the function has an explicit result variable. */
5f20c93a 388tree gfc_get_fake_result_decl (gfc_symbol *, int);
6de9cd9a
DN
389
390/* Get the return label for the current function. */
391tree gfc_get_return_label (void);
392
393/* Add a decl to the binding level for the current function. */
394void gfc_add_decl_to_function (tree);
395
396/* Make prototypes for runtime library functions. */
397void gfc_build_builtin_function_decls (void);
398
c8cc8542
PB
399/* Set the backend source location of a decl. */
400void gfc_set_decl_location (tree, locus *);
401
6de9cd9a
DN
402/* Return the variable decl for a symbol. */
403tree gfc_get_symbol_decl (gfc_symbol *);
404
597073ac
PB
405/* Build a static initializer. */
406tree gfc_conv_initializer (gfc_expr *, gfc_typespec *, tree, bool, bool);
407
7b5b57b7
PB
408/* Substitute a temporary variable in place of the real one. */
409void gfc_shadow_sym (gfc_symbol *, tree, gfc_saved_var *);
410
411/* Restore the original variable. */
412void gfc_restore_sym (gfc_symbol *, gfc_saved_var *);
413
bae88af6
TS
414/* Returns true if a variable of specified size should go on the stack. */
415int gfc_can_put_var_on_stack (tree);
416
69de3b83 417/* Allocate the lang-specific part of a decl node. */
6de9cd9a
DN
418void gfc_allocate_lang_decl (tree);
419
420/* Advance along a TREE_CHAIN. */
421tree gfc_advance_chain (tree, int);
422
423/* Create a decl for a function. */
3d79abbd 424void gfc_create_function_decl (gfc_namespace *);
6de9cd9a
DN
425/* Generate the code for a function. */
426void gfc_generate_function_code (gfc_namespace *);
0de4325e
TS
427/* Output a BLOCK DATA program unit. */
428void gfc_generate_block_data (gfc_namespace *);
6de9cd9a
DN
429/* Output a decl for a module variable. */
430void gfc_generate_module_vars (gfc_namespace *);
431
432/* Get and set the current location. */
433void gfc_set_backend_locus (locus *);
434void gfc_get_backend_locus (locus *);
435
436/* Handle static constructor functions. */
437extern GTY(()) tree gfc_static_ctors;
438void gfc_generate_constructors (void);
439
636da744 440/* Get the string length of an array constructor. */
0ee8e250 441bool get_array_ctor_strlen (stmtblock_t *, gfc_constructor *, tree *);
636da744 442
6de9cd9a 443/* Generate a runtime error check. */
c8fe94c7 444void gfc_trans_runtime_check (tree, stmtblock_t *, locus *, const char *, ...);
6de9cd9a 445
1529b8d9
FXC
446/* Generate a call to free() after checking that its arg is non-NULL. */
447tree gfc_call_free (tree);
448
449/* Allocate memory after performing a few checks. */
450tree gfc_call_malloc (stmtblock_t *, tree, tree);
451
4376b7cf
FXC
452/* Allocate memory for arrays, with optional status variable. */
453tree gfc_allocate_array_with_status (stmtblock_t *, tree, tree, tree);
454
455/* Allocate memory, with optional status variable. */
456tree gfc_allocate_with_status (stmtblock_t *, tree, tree);
457
458/* Generate code to deallocate an array. */
459tree gfc_deallocate_with_status (tree, tree, bool);
460
461/* Generate code to call realloc(). */
462tree gfc_call_realloc (stmtblock_t *, tree, tree);
463
1f2959f0 464/* Generate code for an assignment, includes scalarization. */
6b591ec0 465tree gfc_trans_assignment (gfc_expr *, gfc_expr *, bool);
6de9cd9a 466
49de9e73 467/* Generate code for a pointer assignment. */
6de9cd9a
DN
468tree gfc_trans_pointer_assignment (gfc_expr *, gfc_expr *);
469
470/* Initialize function decls for library functions. */
471void gfc_build_intrinsic_lib_fndecls (void);
472/* Create function decls for IO library functions. */
f96d606f 473void gfc_trans_io_runtime_check (tree, tree, int, const char *, stmtblock_t *);
6de9cd9a
DN
474void gfc_build_io_library_fndecls (void);
475/* Build a function decl for a library function. */
476tree gfc_build_library_function_decl (tree, tree, int, ...);
477
478/* somewhere! */
479tree pushdecl (tree);
480tree pushdecl_top_level (tree);
481void pushlevel (int);
482tree poplevel (int, int, int);
483tree getdecls (void);
484tree gfc_truthvalue_conversion (tree);
c79efc4d 485tree gfc_builtin_function (tree);
6de9cd9a 486
6c7a4dfd 487/* In trans-openmp.c */
58f9752a 488bool gfc_omp_privatize_by_reference (const_tree);
6c7a4dfd 489enum omp_clause_default_kind gfc_omp_predetermined_sharing (tree);
cd75853e 490tree gfc_omp_clause_default_ctor (tree, tree);
6c7a4dfd
JJ
491bool gfc_omp_disregard_value_expr (tree, bool);
492bool gfc_omp_private_debug_clause (tree, bool);
493struct gimplify_omp_ctx;
494void gfc_omp_firstprivatize_type_sizes (struct gimplify_omp_ctx *, tree);
495
6de9cd9a 496/* Runtime library function decls. */
6de9cd9a
DN
497extern GTY(()) tree gfor_fndecl_pause_numeric;
498extern GTY(()) tree gfor_fndecl_pause_string;
499extern GTY(()) tree gfor_fndecl_stop_numeric;
500extern GTY(()) tree gfor_fndecl_stop_string;
501extern GTY(()) tree gfor_fndecl_select_string;
502extern GTY(()) tree gfor_fndecl_runtime_error;
f96d606f 503extern GTY(()) tree gfor_fndecl_runtime_error_at;
1529b8d9 504extern GTY(()) tree gfor_fndecl_os_error;
f96d606f 505extern GTY(()) tree gfor_fndecl_generate_error;
944b8b35 506extern GTY(()) tree gfor_fndecl_set_fpe;
68d2e027 507extern GTY(()) tree gfor_fndecl_set_options;
25fc05eb 508extern GTY(()) tree gfor_fndecl_ttynam;
35059811
FXC
509extern GTY(()) tree gfor_fndecl_ctime;
510extern GTY(()) tree gfor_fndecl_fdate;
6de9cd9a
DN
511extern GTY(()) tree gfor_fndecl_in_pack;
512extern GTY(()) tree gfor_fndecl_in_unpack;
513extern GTY(()) tree gfor_fndecl_associated;
514
515/* Math functions. Many other math functions are handled in
516 trans-intrinsic.c. */
5b200ac2
FW
517
518typedef struct gfc_powdecl_list GTY(())
519{
520 tree integer;
521 tree real;
522 tree cmplx;
523}
524gfc_powdecl_list;
525
644cb69f 526extern GTY(()) gfc_powdecl_list gfor_fndecl_math_powi[4][3];
6de9cd9a
DN
527extern GTY(()) tree gfor_fndecl_math_cpowf;
528extern GTY(()) tree gfor_fndecl_math_cpow;
644cb69f
FXC
529extern GTY(()) tree gfor_fndecl_math_cpowl10;
530extern GTY(()) tree gfor_fndecl_math_cpowl16;
6de9cd9a
DN
531extern GTY(()) tree gfor_fndecl_math_ishftc4;
532extern GTY(()) tree gfor_fndecl_math_ishftc8;
644cb69f 533extern GTY(()) tree gfor_fndecl_math_ishftc16;
6de9cd9a
DN
534extern GTY(()) tree gfor_fndecl_math_exponent4;
535extern GTY(()) tree gfor_fndecl_math_exponent8;
644cb69f
FXC
536extern GTY(()) tree gfor_fndecl_math_exponent10;
537extern GTY(()) tree gfor_fndecl_math_exponent16;
6de9cd9a 538
5a0aad31
FXC
539/* BLAS functions. */
540extern GTY(()) tree gfor_fndecl_sgemm;
541extern GTY(()) tree gfor_fndecl_dgemm;
542extern GTY(()) tree gfor_fndecl_cgemm;
543extern GTY(()) tree gfor_fndecl_zgemm;
544
6de9cd9a 545/* String functions. */
6de9cd9a
DN
546extern GTY(()) tree gfor_fndecl_compare_string;
547extern GTY(()) tree gfor_fndecl_concat_string;
548extern GTY(()) tree gfor_fndecl_string_len_trim;
549extern GTY(()) tree gfor_fndecl_string_index;
550extern GTY(()) tree gfor_fndecl_string_scan;
551extern GTY(()) tree gfor_fndecl_string_verify;
552extern GTY(()) tree gfor_fndecl_string_trim;
2263c775 553extern GTY(()) tree gfor_fndecl_string_minmax;
6de9cd9a
DN
554extern GTY(()) tree gfor_fndecl_adjustl;
555extern GTY(()) tree gfor_fndecl_adjustr;
556
557/* Other misc. runtime library functions. */
558extern GTY(()) tree gfor_fndecl_size0;
559extern GTY(()) tree gfor_fndecl_size1;
b41b2534 560extern GTY(()) tree gfor_fndecl_iargc;
6de9cd9a
DN
561
562/* Implemented in FORTRAN. */
563extern GTY(()) tree gfor_fndecl_si_kind;
564extern GTY(()) tree gfor_fndecl_sr_kind;
565
566
567/* True if node is an integer constant. */
568#define INTEGER_CST_P(node) (TREE_CODE(node) == INTEGER_CST)
569
570/* G95-specific declaration information. */
571
572/* Array types only. */
573struct lang_type GTY(())
574{
575 int rank;
576 tree lbound[GFC_MAX_DIMENSIONS];
577 tree ubound[GFC_MAX_DIMENSIONS];
578 tree stride[GFC_MAX_DIMENSIONS];
579 tree size;
580 tree offset;
581 tree dtype;
582 tree dataptr_type;
583};
584
585struct lang_decl GTY(())
586{
587 /* Dummy variables. */
588 tree saved_descriptor;
589 /* Assigned integer nodes. Stringlength is the IO format string's length.
590 Addr is the address of the string or the target label. Stringlength is
1f2959f0 591 initialized to -2 and assigned to -1 when addr is assigned to the
6de9cd9a
DN
592 address of target label. */
593 tree stringlen;
594 tree addr;
1d6b7f39 595 tree span;
6de9cd9a
DN
596};
597
598
599#define GFC_DECL_ASSIGN_ADDR(node) DECL_LANG_SPECIFIC(node)->addr
600#define GFC_DECL_STRING_LEN(node) DECL_LANG_SPECIFIC(node)->stringlen
1d6b7f39 601#define GFC_DECL_SPAN(node) DECL_LANG_SPECIFIC(node)->span
6de9cd9a
DN
602#define GFC_DECL_SAVED_DESCRIPTOR(node) \
603 (DECL_LANG_SPECIFIC(node)->saved_descriptor)
604#define GFC_DECL_PACKED_ARRAY(node) DECL_LANG_FLAG_0(node)
605#define GFC_DECL_PARTIAL_PACKED_ARRAY(node) DECL_LANG_FLAG_1(node)
606#define GFC_DECL_ASSIGN(node) DECL_LANG_FLAG_2(node)
6c7a4dfd
JJ
607#define GFC_DECL_COMMON_OR_EQUIV(node) DECL_LANG_FLAG_3(node)
608#define GFC_DECL_CRAY_POINTEE(node) DECL_LANG_FLAG_4(node)
609#define GFC_DECL_RESULT(node) DECL_LANG_FLAG_5(node)
1d6b7f39 610#define GFC_DECL_SUBREF_ARRAY_P(node) DECL_LANG_FLAG_6(node)
6de9cd9a
DN
611
612/* An array descriptor. */
613#define GFC_DESCRIPTOR_TYPE_P(node) TYPE_LANG_FLAG_1(node)
614/* An array without a descriptor. */
615#define GFC_ARRAY_TYPE_P(node) TYPE_LANG_FLAG_2(node)
e1c82219
JJ
616/* Fortran POINTER type. */
617#define GFC_POINTER_TYPE_P(node) TYPE_LANG_FLAG_3(node)
6de9cd9a
DN
618/* The GFC_TYPE_ARRAY_* members are present in both descriptor and
619 descriptorless array types. */
620#define GFC_TYPE_ARRAY_LBOUND(node, dim) \
621 (TYPE_LANG_SPECIFIC(node)->lbound[dim])
622#define GFC_TYPE_ARRAY_UBOUND(node, dim) \
623 (TYPE_LANG_SPECIFIC(node)->ubound[dim])
624#define GFC_TYPE_ARRAY_STRIDE(node, dim) \
625 (TYPE_LANG_SPECIFIC(node)->stride[dim])
626#define GFC_TYPE_ARRAY_RANK(node) (TYPE_LANG_SPECIFIC(node)->rank)
627#define GFC_TYPE_ARRAY_SIZE(node) (TYPE_LANG_SPECIFIC(node)->size)
628#define GFC_TYPE_ARRAY_OFFSET(node) (TYPE_LANG_SPECIFIC(node)->offset)
40b026d8
PB
629/* Code should use gfc_get_dtype instead of accesig this directly. It may
630 not be known when the type is created. */
6de9cd9a
DN
631#define GFC_TYPE_ARRAY_DTYPE(node) (TYPE_LANG_SPECIFIC(node)->dtype)
632#define GFC_TYPE_ARRAY_DATAPTR_TYPE(node) \
633 (TYPE_LANG_SPECIFIC(node)->dataptr_type)
634
6de9cd9a 635/* Build an expression with void type. */
5d5c039f 636#define build1_v(code, arg) build1(code, void_type_node, arg)
923ab88c
TS
637#define build2_v(code, arg1, arg2) build2(code, void_type_node, \
638 arg1, arg2)
639#define build3_v(code, arg1, arg2, arg3) build3(code, void_type_node, \
640 arg1, arg2, arg3)
6c7a4dfd
JJ
641#define build4_v(code, arg1, arg2, arg3, arg4) build4(code, void_type_node, \
642 arg1, arg2, arg3, arg4)
62ab4a54
RS
643
644/* This group of functions allows a caller to evaluate an expression from
645 the callee's interface. It establishes a mapping between the interface's
646 dummy arguments and the caller's actual arguments, then applies that
647 mapping to a given gfc_expr.
648
649 You can initialize a mapping structure like so:
650
651 gfc_interface_mapping mapping;
652 ...
653 gfc_init_interface_mapping (&mapping);
654
655 You should then evaluate each actual argument into a temporary
656 gfc_se structure, here called "se", and map the result to the
657 dummy argument's symbol, here called "sym":
658
659 gfc_add_interface_mapping (&mapping, sym, &se);
660
661 After adding all mappings, you should call:
662
663 gfc_finish_interface_mapping (&mapping, pre, post);
664
665 where "pre" and "post" are statement blocks for initialization
666 and finalization code respectively. You can then evaluate an
667 interface expression "expr" as follows:
668
669 gfc_apply_interface_mapping (&mapping, se, expr);
670
671 Once you've evaluated all expressions, you should free
672 the mapping structure with:
673
674 gfc_free_interface_mapping (&mapping); */
675
676
677/* This structure represents a mapping from OLD to NEW, where OLD is a
678 dummy argument symbol and NEW is a symbol that represents the value
679 of an actual argument. Mappings are linked together using NEXT
680 (in no particular order). */
681typedef struct gfc_interface_sym_mapping
682{
683 struct gfc_interface_sym_mapping *next;
684 gfc_symbol *old;
685 gfc_symtree *new;
686}
687gfc_interface_sym_mapping;
688
689
690/* This structure is used by callers to evaluate an expression from
691 a callee's interface. */
692typedef struct gfc_interface_mapping
693{
694 /* Maps the interface's dummy arguments to the values that the caller
695 is passing. The whole list is owned by this gfc_interface_mapping. */
696 gfc_interface_sym_mapping *syms;
697
698 /* A list of gfc_charlens that were needed when creating copies of
699 expressions. The whole list is owned by this gfc_interface_mapping. */
700 gfc_charlen *charlens;
701}
702gfc_interface_mapping;
703
704void gfc_init_interface_mapping (gfc_interface_mapping *);
705void gfc_free_interface_mapping (gfc_interface_mapping *);
706void gfc_add_interface_mapping (gfc_interface_mapping *,
707 gfc_symbol *, gfc_se *);
708void gfc_finish_interface_mapping (gfc_interface_mapping *,
709 stmtblock_t *, stmtblock_t *);
710void gfc_apply_interface_mapping (gfc_interface_mapping *,
711 gfc_se *, gfc_expr *);
712
dd18a33b
FXC
713
714/* Standard error messages used in all the trans-*.c files. */
7e49f965
TS
715extern const char gfc_msg_bounds[];
716extern const char gfc_msg_fault[];
717extern const char gfc_msg_wrong_return[];
dd18a33b
FXC
718
719
6de9cd9a 720#endif /* GFC_TRANS_H */