2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008
3 Free Software Foundation, Inc.
4 Contributed by Steven Bosscher
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
23 /* Actually this is just a collection of routines that used to be
24 scattered around the sources. Now that they are all in a single
25 file, almost all of them can be static, and the other files don't
26 have this mess in them.
28 As a nice side-effect, this file can act as documentation of the
29 gfc_code and gfc_expr structures and all their friends and
37 /* Keep track of indentation for symbol tree dumps. */
38 static int show_level
= 0;
40 /* The file handle we're dumping to is kept in a static variable. This
41 is not too cool, but it avoids a lot of passing it around. */
42 static FILE *dumpfile
;
44 /* Forward declaration of some of the functions. */
45 static void show_expr (gfc_expr
*p
);
46 static void show_code_node (int, gfc_code
*);
47 static void show_namespace (gfc_namespace
*ns
);
50 /* Do indentation for a specific level. */
53 code_indent (int level
, gfc_st_label
*label
)
58 fprintf (dumpfile
, "%-5d ", label
->value
);
60 fputs (" ", dumpfile
);
62 for (i
= 0; i
< 2 * level
; i
++)
63 fputc (' ', dumpfile
);
67 /* Simple indentation at the current level. This one
68 is used to show symbols. */
73 fputc ('\n', dumpfile
);
74 code_indent (show_level
, NULL
);
78 /* Show type-specific information. */
81 show_typespec (gfc_typespec
*ts
)
83 fprintf (dumpfile
, "(%s ", gfc_basic_typename (ts
->type
));
88 fprintf (dumpfile
, "%s", ts
->derived
->name
);
92 show_expr (ts
->cl
->length
);
96 fprintf (dumpfile
, "%d", ts
->kind
);
100 fputc (')', dumpfile
);
104 /* Show an actual argument list. */
107 show_actual_arglist (gfc_actual_arglist
*a
)
109 fputc ('(', dumpfile
);
111 for (; a
; a
= a
->next
)
113 fputc ('(', dumpfile
);
115 fprintf (dumpfile
, "%s = ", a
->name
);
119 fputs ("(arg not-present)", dumpfile
);
121 fputc (')', dumpfile
);
123 fputc (' ', dumpfile
);
126 fputc (')', dumpfile
);
130 /* Show a gfc_array_spec array specification structure. */
133 show_array_spec (gfc_array_spec
*as
)
140 fputs ("()", dumpfile
);
144 fprintf (dumpfile
, "(%d", as
->rank
);
150 case AS_EXPLICIT
: c
= "AS_EXPLICIT"; break;
151 case AS_DEFERRED
: c
= "AS_DEFERRED"; break;
152 case AS_ASSUMED_SIZE
: c
= "AS_ASSUMED_SIZE"; break;
153 case AS_ASSUMED_SHAPE
: c
= "AS_ASSUMED_SHAPE"; break;
155 gfc_internal_error ("show_array_spec(): Unhandled array shape "
158 fprintf (dumpfile
, " %s ", c
);
160 for (i
= 0; i
< as
->rank
; i
++)
162 show_expr (as
->lower
[i
]);
163 fputc (' ', dumpfile
);
164 show_expr (as
->upper
[i
]);
165 fputc (' ', dumpfile
);
169 fputc (')', dumpfile
);
173 /* Show a gfc_array_ref array reference structure. */
176 show_array_ref (gfc_array_ref
* ar
)
180 fputc ('(', dumpfile
);
185 fputs ("FULL", dumpfile
);
189 for (i
= 0; i
< ar
->dimen
; i
++)
191 /* There are two types of array sections: either the
192 elements are identified by an integer array ('vector'),
193 or by an index range. In the former case we only have to
194 print the start expression which contains the vector, in
195 the latter case we have to print any of lower and upper
196 bound and the stride, if they're present. */
198 if (ar
->start
[i
] != NULL
)
199 show_expr (ar
->start
[i
]);
201 if (ar
->dimen_type
[i
] == DIMEN_RANGE
)
203 fputc (':', dumpfile
);
205 if (ar
->end
[i
] != NULL
)
206 show_expr (ar
->end
[i
]);
208 if (ar
->stride
[i
] != NULL
)
210 fputc (':', dumpfile
);
211 show_expr (ar
->stride
[i
]);
215 if (i
!= ar
->dimen
- 1)
216 fputs (" , ", dumpfile
);
221 for (i
= 0; i
< ar
->dimen
; i
++)
223 show_expr (ar
->start
[i
]);
224 if (i
!= ar
->dimen
- 1)
225 fputs (" , ", dumpfile
);
230 fputs ("UNKNOWN", dumpfile
);
234 gfc_internal_error ("show_array_ref(): Unknown array reference");
237 fputc (')', dumpfile
);
241 /* Show a list of gfc_ref structures. */
244 show_ref (gfc_ref
*p
)
246 for (; p
; p
= p
->next
)
250 show_array_ref (&p
->u
.ar
);
254 fprintf (dumpfile
, " %% %s", p
->u
.c
.component
->name
);
258 fputc ('(', dumpfile
);
259 show_expr (p
->u
.ss
.start
);
260 fputc (':', dumpfile
);
261 show_expr (p
->u
.ss
.end
);
262 fputc (')', dumpfile
);
266 gfc_internal_error ("show_ref(): Bad component code");
271 /* Display a constructor. Works recursively for array constructors. */
274 show_constructor (gfc_constructor
*c
)
276 for (; c
; c
= c
->next
)
278 if (c
->iterator
== NULL
)
282 fputc ('(', dumpfile
);
285 fputc (' ', dumpfile
);
286 show_expr (c
->iterator
->var
);
287 fputc ('=', dumpfile
);
288 show_expr (c
->iterator
->start
);
289 fputc (',', dumpfile
);
290 show_expr (c
->iterator
->end
);
291 fputc (',', dumpfile
);
292 show_expr (c
->iterator
->step
);
294 fputc (')', dumpfile
);
298 fputs (" , ", dumpfile
);
304 show_char_const (const gfc_char_t
*c
, int length
)
308 fputc ('\'', dumpfile
);
309 for (i
= 0; i
< length
; i
++)
312 fputs ("''", dumpfile
);
314 fputs (gfc_print_wide_char (c
[i
]), dumpfile
);
316 fputc ('\'', dumpfile
);
320 /* Show a component-call expression. */
323 show_compcall (gfc_expr
* p
)
325 gcc_assert (p
->expr_type
== EXPR_COMPCALL
);
327 fprintf (dumpfile
, "%s", p
->symtree
->n
.sym
->name
);
329 fprintf (dumpfile
, "%s", p
->value
.compcall
.name
);
331 show_actual_arglist (p
->value
.compcall
.actual
);
335 /* Show an expression. */
338 show_expr (gfc_expr
*p
)
345 fputs ("()", dumpfile
);
349 switch (p
->expr_type
)
352 show_char_const (p
->value
.character
.string
, p
->value
.character
.length
);
357 fprintf (dumpfile
, "%s(", p
->ts
.derived
->name
);
358 show_constructor (p
->value
.constructor
);
359 fputc (')', dumpfile
);
363 fputs ("(/ ", dumpfile
);
364 show_constructor (p
->value
.constructor
);
365 fputs (" /)", dumpfile
);
371 fputs ("NULL()", dumpfile
);
378 mpz_out_str (stdout
, 10, p
->value
.integer
);
380 if (p
->ts
.kind
!= gfc_default_integer_kind
)
381 fprintf (dumpfile
, "_%d", p
->ts
.kind
);
385 if (p
->value
.logical
)
386 fputs (".true.", dumpfile
);
388 fputs (".false.", dumpfile
);
392 mpfr_out_str (stdout
, 10, 0, p
->value
.real
, GFC_RND_MODE
);
393 if (p
->ts
.kind
!= gfc_default_real_kind
)
394 fprintf (dumpfile
, "_%d", p
->ts
.kind
);
398 show_char_const (p
->value
.character
.string
,
399 p
->value
.character
.length
);
403 fputs ("(complex ", dumpfile
);
405 mpfr_out_str (stdout
, 10, 0, p
->value
.complex.r
, GFC_RND_MODE
);
406 if (p
->ts
.kind
!= gfc_default_complex_kind
)
407 fprintf (dumpfile
, "_%d", p
->ts
.kind
);
409 fputc (' ', dumpfile
);
411 mpfr_out_str (stdout
, 10, 0, p
->value
.complex.i
, GFC_RND_MODE
);
412 if (p
->ts
.kind
!= gfc_default_complex_kind
)
413 fprintf (dumpfile
, "_%d", p
->ts
.kind
);
415 fputc (')', dumpfile
);
419 fprintf (dumpfile
, "%dH", p
->representation
.length
);
420 c
= p
->representation
.string
;
421 for (i
= 0; i
< p
->representation
.length
; i
++, c
++)
423 fputc (*c
, dumpfile
);
428 fputs ("???", dumpfile
);
432 if (p
->representation
.string
)
434 fputs (" {", dumpfile
);
435 c
= p
->representation
.string
;
436 for (i
= 0; i
< p
->representation
.length
; i
++, c
++)
438 fprintf (dumpfile
, "%.2x", (unsigned int) *c
);
439 if (i
< p
->representation
.length
- 1)
440 fputc (',', dumpfile
);
442 fputc ('}', dumpfile
);
448 if (p
->symtree
->n
.sym
->ns
&& p
->symtree
->n
.sym
->ns
->proc_name
)
449 fprintf (dumpfile
, "%s:", p
->symtree
->n
.sym
->ns
->proc_name
->name
);
450 fprintf (dumpfile
, "%s", p
->symtree
->n
.sym
->name
);
455 fputc ('(', dumpfile
);
456 switch (p
->value
.op
.op
)
458 case INTRINSIC_UPLUS
:
459 fputs ("U+ ", dumpfile
);
461 case INTRINSIC_UMINUS
:
462 fputs ("U- ", dumpfile
);
465 fputs ("+ ", dumpfile
);
467 case INTRINSIC_MINUS
:
468 fputs ("- ", dumpfile
);
470 case INTRINSIC_TIMES
:
471 fputs ("* ", dumpfile
);
473 case INTRINSIC_DIVIDE
:
474 fputs ("/ ", dumpfile
);
476 case INTRINSIC_POWER
:
477 fputs ("** ", dumpfile
);
479 case INTRINSIC_CONCAT
:
480 fputs ("// ", dumpfile
);
483 fputs ("AND ", dumpfile
);
486 fputs ("OR ", dumpfile
);
489 fputs ("EQV ", dumpfile
);
492 fputs ("NEQV ", dumpfile
);
495 case INTRINSIC_EQ_OS
:
496 fputs ("= ", dumpfile
);
499 case INTRINSIC_NE_OS
:
500 fputs ("/= ", dumpfile
);
503 case INTRINSIC_GT_OS
:
504 fputs ("> ", dumpfile
);
507 case INTRINSIC_GE_OS
:
508 fputs (">= ", dumpfile
);
511 case INTRINSIC_LT_OS
:
512 fputs ("< ", dumpfile
);
515 case INTRINSIC_LE_OS
:
516 fputs ("<= ", dumpfile
);
519 fputs ("NOT ", dumpfile
);
521 case INTRINSIC_PARENTHESES
:
522 fputs ("parens", dumpfile
);
527 ("show_expr(): Bad intrinsic in expression!");
530 show_expr (p
->value
.op
.op1
);
534 fputc (' ', dumpfile
);
535 show_expr (p
->value
.op
.op2
);
538 fputc (')', dumpfile
);
542 if (p
->value
.function
.name
== NULL
)
544 fprintf (dumpfile
, "%s[", p
->symtree
->n
.sym
->name
);
545 show_actual_arglist (p
->value
.function
.actual
);
546 fputc (']', dumpfile
);
550 fprintf (dumpfile
, "%s[[", p
->value
.function
.name
);
551 show_actual_arglist (p
->value
.function
.actual
);
552 fputc (']', dumpfile
);
553 fputc (']', dumpfile
);
563 gfc_internal_error ("show_expr(): Don't know how to show expr");
567 /* Show symbol attributes. The flavor and intent are followed by
568 whatever single bit attributes are present. */
571 show_attr (symbol_attribute
*attr
)
574 fprintf (dumpfile
, "(%s %s %s %s %s",
575 gfc_code2string (flavors
, attr
->flavor
),
576 gfc_intent_string (attr
->intent
),
577 gfc_code2string (access_types
, attr
->access
),
578 gfc_code2string (procedures
, attr
->proc
),
579 gfc_code2string (save_status
, attr
->save
));
581 if (attr
->allocatable
)
582 fputs (" ALLOCATABLE", dumpfile
);
584 fputs (" DIMENSION", dumpfile
);
586 fputs (" EXTERNAL", dumpfile
);
588 fputs (" INTRINSIC", dumpfile
);
590 fputs (" OPTIONAL", dumpfile
);
592 fputs (" POINTER", dumpfile
);
593 if (attr
->is_protected
)
594 fputs (" PROTECTED", dumpfile
);
596 fputs (" VALUE", dumpfile
);
598 fputs (" VOLATILE", dumpfile
);
599 if (attr
->threadprivate
)
600 fputs (" THREADPRIVATE", dumpfile
);
602 fputs (" TARGET", dumpfile
);
604 fputs (" DUMMY", dumpfile
);
606 fputs (" RESULT", dumpfile
);
608 fputs (" ENTRY", dumpfile
);
610 fputs (" BIND(C)", dumpfile
);
613 fputs (" DATA", dumpfile
);
615 fputs (" USE-ASSOC", dumpfile
);
616 if (attr
->in_namelist
)
617 fputs (" IN-NAMELIST", dumpfile
);
619 fputs (" IN-COMMON", dumpfile
);
622 fputs (" ABSTRACT", dumpfile
);
624 fputs (" FUNCTION", dumpfile
);
625 if (attr
->subroutine
)
626 fputs (" SUBROUTINE", dumpfile
);
627 if (attr
->implicit_type
)
628 fputs (" IMPLICIT-TYPE", dumpfile
);
631 fputs (" SEQUENCE", dumpfile
);
633 fputs (" ELEMENTAL", dumpfile
);
635 fputs (" PURE", dumpfile
);
637 fputs (" RECURSIVE", dumpfile
);
639 fputc (')', dumpfile
);
643 /* Show components of a derived type. */
646 show_components (gfc_symbol
*sym
)
650 for (c
= sym
->components
; c
; c
= c
->next
)
652 fprintf (dumpfile
, "(%s ", c
->name
);
653 show_typespec (&c
->ts
);
655 fputs (" POINTER", dumpfile
);
656 if (c
->attr
.dimension
)
657 fputs (" DIMENSION", dumpfile
);
658 fputc (' ', dumpfile
);
659 show_array_spec (c
->as
);
661 fprintf (dumpfile
, " %s", gfc_code2string (access_types
, c
->attr
.access
));
662 fputc (')', dumpfile
);
664 fputc (' ', dumpfile
);
669 /* Show the f2k_derived namespace with procedure bindings. */
672 show_typebound (gfc_symtree
* st
)
679 if (st
->typebound
->is_generic
)
680 fputs ("GENERIC", dumpfile
);
683 fputs ("PROCEDURE, ", dumpfile
);
684 if (st
->typebound
->nopass
)
685 fputs ("NOPASS", dumpfile
);
688 if (st
->typebound
->pass_arg
)
689 fprintf (dumpfile
, "PASS(%s)", st
->typebound
->pass_arg
);
691 fputs ("PASS", dumpfile
);
693 if (st
->typebound
->non_overridable
)
694 fputs (", NON_OVERRIDABLE", dumpfile
);
697 if (st
->typebound
->access
== ACCESS_PUBLIC
)
698 fputs (", PUBLIC", dumpfile
);
700 fputs (", PRIVATE", dumpfile
);
702 fprintf (dumpfile
, " :: %s => ", st
->n
.sym
->name
);
704 if (st
->typebound
->is_generic
)
707 for (g
= st
->typebound
->u
.generic
; g
; g
= g
->next
)
709 fputs (g
->specific_st
->name
, dumpfile
);
711 fputs (", ", dumpfile
);
715 fputs (st
->typebound
->u
.specific
->n
.sym
->name
, dumpfile
);
719 show_f2k_derived (gfc_namespace
* f2k
)
725 /* Finalizer bindings. */
726 for (f
= f2k
->finalizers
; f
; f
= f
->next
)
729 fprintf (dumpfile
, "FINAL %s", f
->proc_sym
->name
);
732 /* Type-bound procedures. */
733 gfc_traverse_symtree (f2k
->sym_root
, &show_typebound
);
739 /* Show a symbol. If a symbol is an ENTRY, SUBROUTINE or FUNCTION, we
740 show the interface. Information needed to reconstruct the list of
741 specific interfaces associated with a generic symbol is done within
745 show_symbol (gfc_symbol
*sym
)
747 gfc_formal_arglist
*formal
;
755 fprintf (dumpfile
, "symbol %s ", sym
->name
);
756 show_typespec (&sym
->ts
);
757 show_attr (&sym
->attr
);
762 fputs ("value: ", dumpfile
);
763 show_expr (sym
->value
);
769 fputs ("Array spec:", dumpfile
);
770 show_array_spec (sym
->as
);
776 fputs ("Generic interfaces:", dumpfile
);
777 for (intr
= sym
->generic
; intr
; intr
= intr
->next
)
778 fprintf (dumpfile
, " %s", intr
->sym
->name
);
784 fprintf (dumpfile
, "result: %s", sym
->result
->name
);
790 fputs ("components: ", dumpfile
);
791 show_components (sym
);
794 if (sym
->f2k_derived
)
797 fputs ("Procedure bindings:\n", dumpfile
);
798 show_f2k_derived (sym
->f2k_derived
);
804 fputs ("Formal arglist:", dumpfile
);
806 for (formal
= sym
->formal
; formal
; formal
= formal
->next
)
808 if (formal
->sym
!= NULL
)
809 fprintf (dumpfile
, " %s", formal
->sym
->name
);
811 fputs (" [Alt Return]", dumpfile
);
818 fputs ("Formal namespace", dumpfile
);
819 show_namespace (sym
->formal_ns
);
822 fputc ('\n', dumpfile
);
826 /* Show a user-defined operator. Just prints an operator
827 and the name of the associated subroutine, really. */
830 show_uop (gfc_user_op
*uop
)
835 fprintf (dumpfile
, "%s:", uop
->name
);
837 for (intr
= uop
->op
; intr
; intr
= intr
->next
)
838 fprintf (dumpfile
, " %s", intr
->sym
->name
);
842 /* Workhorse function for traversing the user operator symtree. */
845 traverse_uop (gfc_symtree
*st
, void (*func
) (gfc_user_op
*))
852 traverse_uop (st
->left
, func
);
853 traverse_uop (st
->right
, func
);
857 /* Traverse the tree of user operator nodes. */
860 gfc_traverse_user_op (gfc_namespace
*ns
, void (*func
) (gfc_user_op
*))
862 traverse_uop (ns
->uop_root
, func
);
866 /* Function to display a common block. */
869 show_common (gfc_symtree
*st
)
874 fprintf (dumpfile
, "common: /%s/ ", st
->name
);
876 s
= st
->n
.common
->head
;
879 fprintf (dumpfile
, "%s", s
->name
);
882 fputs (", ", dumpfile
);
884 fputc ('\n', dumpfile
);
888 /* Worker function to display the symbol tree. */
891 show_symtree (gfc_symtree
*st
)
894 fprintf (dumpfile
, "symtree: %s Ambig %d", st
->name
, st
->ambiguous
);
896 if (st
->n
.sym
->ns
!= gfc_current_ns
)
897 fprintf (dumpfile
, " from namespace %s", st
->n
.sym
->ns
->proc_name
->name
);
899 show_symbol (st
->n
.sym
);
903 /******************* Show gfc_code structures **************/
906 /* Show a list of code structures. Mutually recursive with
910 show_code (int level
, gfc_code
*c
)
912 for (; c
; c
= c
->next
)
913 show_code_node (level
, c
);
917 show_namelist (gfc_namelist
*n
)
919 for (; n
->next
; n
= n
->next
)
920 fprintf (dumpfile
, "%s,", n
->sym
->name
);
921 fprintf (dumpfile
, "%s", n
->sym
->name
);
924 /* Show a single OpenMP directive node and everything underneath it
928 show_omp_node (int level
, gfc_code
*c
)
930 gfc_omp_clauses
*omp_clauses
= NULL
;
931 const char *name
= NULL
;
935 case EXEC_OMP_ATOMIC
: name
= "ATOMIC"; break;
936 case EXEC_OMP_BARRIER
: name
= "BARRIER"; break;
937 case EXEC_OMP_CRITICAL
: name
= "CRITICAL"; break;
938 case EXEC_OMP_FLUSH
: name
= "FLUSH"; break;
939 case EXEC_OMP_DO
: name
= "DO"; break;
940 case EXEC_OMP_MASTER
: name
= "MASTER"; break;
941 case EXEC_OMP_ORDERED
: name
= "ORDERED"; break;
942 case EXEC_OMP_PARALLEL
: name
= "PARALLEL"; break;
943 case EXEC_OMP_PARALLEL_DO
: name
= "PARALLEL DO"; break;
944 case EXEC_OMP_PARALLEL_SECTIONS
: name
= "PARALLEL SECTIONS"; break;
945 case EXEC_OMP_PARALLEL_WORKSHARE
: name
= "PARALLEL WORKSHARE"; break;
946 case EXEC_OMP_SECTIONS
: name
= "SECTIONS"; break;
947 case EXEC_OMP_SINGLE
: name
= "SINGLE"; break;
948 case EXEC_OMP_TASK
: name
= "TASK"; break;
949 case EXEC_OMP_TASKWAIT
: name
= "TASKWAIT"; break;
950 case EXEC_OMP_WORKSHARE
: name
= "WORKSHARE"; break;
954 fprintf (dumpfile
, "!$OMP %s", name
);
958 case EXEC_OMP_PARALLEL
:
959 case EXEC_OMP_PARALLEL_DO
:
960 case EXEC_OMP_PARALLEL_SECTIONS
:
961 case EXEC_OMP_SECTIONS
:
962 case EXEC_OMP_SINGLE
:
963 case EXEC_OMP_WORKSHARE
:
964 case EXEC_OMP_PARALLEL_WORKSHARE
:
966 omp_clauses
= c
->ext
.omp_clauses
;
968 case EXEC_OMP_CRITICAL
:
970 fprintf (dumpfile
, " (%s)", c
->ext
.omp_name
);
973 if (c
->ext
.omp_namelist
)
975 fputs (" (", dumpfile
);
976 show_namelist (c
->ext
.omp_namelist
);
977 fputc (')', dumpfile
);
980 case EXEC_OMP_BARRIER
:
981 case EXEC_OMP_TASKWAIT
:
990 if (omp_clauses
->if_expr
)
992 fputs (" IF(", dumpfile
);
993 show_expr (omp_clauses
->if_expr
);
994 fputc (')', dumpfile
);
996 if (omp_clauses
->num_threads
)
998 fputs (" NUM_THREADS(", dumpfile
);
999 show_expr (omp_clauses
->num_threads
);
1000 fputc (')', dumpfile
);
1002 if (omp_clauses
->sched_kind
!= OMP_SCHED_NONE
)
1005 switch (omp_clauses
->sched_kind
)
1007 case OMP_SCHED_STATIC
: type
= "STATIC"; break;
1008 case OMP_SCHED_DYNAMIC
: type
= "DYNAMIC"; break;
1009 case OMP_SCHED_GUIDED
: type
= "GUIDED"; break;
1010 case OMP_SCHED_RUNTIME
: type
= "RUNTIME"; break;
1011 case OMP_SCHED_AUTO
: type
= "AUTO"; break;
1015 fprintf (dumpfile
, " SCHEDULE (%s", type
);
1016 if (omp_clauses
->chunk_size
)
1018 fputc (',', dumpfile
);
1019 show_expr (omp_clauses
->chunk_size
);
1021 fputc (')', dumpfile
);
1023 if (omp_clauses
->default_sharing
!= OMP_DEFAULT_UNKNOWN
)
1026 switch (omp_clauses
->default_sharing
)
1028 case OMP_DEFAULT_NONE
: type
= "NONE"; break;
1029 case OMP_DEFAULT_PRIVATE
: type
= "PRIVATE"; break;
1030 case OMP_DEFAULT_SHARED
: type
= "SHARED"; break;
1031 case OMP_DEFAULT_FIRSTPRIVATE
: type
= "FIRSTPRIVATE"; break;
1035 fprintf (dumpfile
, " DEFAULT(%s)", type
);
1037 if (omp_clauses
->ordered
)
1038 fputs (" ORDERED", dumpfile
);
1039 if (omp_clauses
->untied
)
1040 fputs (" UNTIED", dumpfile
);
1041 if (omp_clauses
->collapse
)
1042 fprintf (dumpfile
, " COLLAPSE(%d)", omp_clauses
->collapse
);
1043 for (list_type
= 0; list_type
< OMP_LIST_NUM
; list_type
++)
1044 if (omp_clauses
->lists
[list_type
] != NULL
1045 && list_type
!= OMP_LIST_COPYPRIVATE
)
1048 if (list_type
>= OMP_LIST_REDUCTION_FIRST
)
1052 case OMP_LIST_PLUS
: type
= "+"; break;
1053 case OMP_LIST_MULT
: type
= "*"; break;
1054 case OMP_LIST_SUB
: type
= "-"; break;
1055 case OMP_LIST_AND
: type
= ".AND."; break;
1056 case OMP_LIST_OR
: type
= ".OR."; break;
1057 case OMP_LIST_EQV
: type
= ".EQV."; break;
1058 case OMP_LIST_NEQV
: type
= ".NEQV."; break;
1059 case OMP_LIST_MAX
: type
= "MAX"; break;
1060 case OMP_LIST_MIN
: type
= "MIN"; break;
1061 case OMP_LIST_IAND
: type
= "IAND"; break;
1062 case OMP_LIST_IOR
: type
= "IOR"; break;
1063 case OMP_LIST_IEOR
: type
= "IEOR"; break;
1067 fprintf (dumpfile
, " REDUCTION(%s:", type
);
1073 case OMP_LIST_PRIVATE
: type
= "PRIVATE"; break;
1074 case OMP_LIST_FIRSTPRIVATE
: type
= "FIRSTPRIVATE"; break;
1075 case OMP_LIST_LASTPRIVATE
: type
= "LASTPRIVATE"; break;
1076 case OMP_LIST_SHARED
: type
= "SHARED"; break;
1077 case OMP_LIST_COPYIN
: type
= "COPYIN"; break;
1081 fprintf (dumpfile
, " %s(", type
);
1083 show_namelist (omp_clauses
->lists
[list_type
]);
1084 fputc (')', dumpfile
);
1087 fputc ('\n', dumpfile
);
1088 if (c
->op
== EXEC_OMP_SECTIONS
|| c
->op
== EXEC_OMP_PARALLEL_SECTIONS
)
1090 gfc_code
*d
= c
->block
;
1093 show_code (level
+ 1, d
->next
);
1094 if (d
->block
== NULL
)
1096 code_indent (level
, 0);
1097 fputs ("!$OMP SECTION\n", dumpfile
);
1102 show_code (level
+ 1, c
->block
->next
);
1103 if (c
->op
== EXEC_OMP_ATOMIC
)
1105 code_indent (level
, 0);
1106 fprintf (dumpfile
, "!$OMP END %s", name
);
1107 if (omp_clauses
!= NULL
)
1109 if (omp_clauses
->lists
[OMP_LIST_COPYPRIVATE
])
1111 fputs (" COPYPRIVATE(", dumpfile
);
1112 show_namelist (omp_clauses
->lists
[OMP_LIST_COPYPRIVATE
]);
1113 fputc (')', dumpfile
);
1115 else if (omp_clauses
->nowait
)
1116 fputs (" NOWAIT", dumpfile
);
1118 else if (c
->op
== EXEC_OMP_CRITICAL
&& c
->ext
.omp_name
)
1119 fprintf (dumpfile
, " (%s)", c
->ext
.omp_name
);
1123 /* Show a single code node and everything underneath it if necessary. */
1126 show_code_node (int level
, gfc_code
*c
)
1128 gfc_forall_iterator
*fa
;
1138 code_indent (level
, c
->here
);
1143 fputs ("NOP", dumpfile
);
1147 fputs ("CONTINUE", dumpfile
);
1151 fprintf (dumpfile
, "ENTRY %s", c
->ext
.entry
->sym
->name
);
1154 case EXEC_INIT_ASSIGN
:
1156 fputs ("ASSIGN ", dumpfile
);
1157 show_expr (c
->expr
);
1158 fputc (' ', dumpfile
);
1159 show_expr (c
->expr2
);
1162 case EXEC_LABEL_ASSIGN
:
1163 fputs ("LABEL ASSIGN ", dumpfile
);
1164 show_expr (c
->expr
);
1165 fprintf (dumpfile
, " %d", c
->label
->value
);
1168 case EXEC_POINTER_ASSIGN
:
1169 fputs ("POINTER ASSIGN ", dumpfile
);
1170 show_expr (c
->expr
);
1171 fputc (' ', dumpfile
);
1172 show_expr (c
->expr2
);
1176 fputs ("GOTO ", dumpfile
);
1178 fprintf (dumpfile
, "%d", c
->label
->value
);
1181 show_expr (c
->expr
);
1185 fputs (", (", dumpfile
);
1186 for (; d
; d
= d
->block
)
1188 code_indent (level
, d
->label
);
1189 if (d
->block
!= NULL
)
1190 fputc (',', dumpfile
);
1192 fputc (')', dumpfile
);
1199 case EXEC_ASSIGN_CALL
:
1200 if (c
->resolved_sym
)
1201 fprintf (dumpfile
, "CALL %s ", c
->resolved_sym
->name
);
1202 else if (c
->symtree
)
1203 fprintf (dumpfile
, "CALL %s ", c
->symtree
->name
);
1205 fputs ("CALL ?? ", dumpfile
);
1207 show_actual_arglist (c
->ext
.actual
);
1211 fputs ("CALL ", dumpfile
);
1212 show_compcall (c
->expr
);
1216 fputs ("RETURN ", dumpfile
);
1218 show_expr (c
->expr
);
1222 fputs ("PAUSE ", dumpfile
);
1224 if (c
->expr
!= NULL
)
1225 show_expr (c
->expr
);
1227 fprintf (dumpfile
, "%d", c
->ext
.stop_code
);
1232 fputs ("STOP ", dumpfile
);
1234 if (c
->expr
!= NULL
)
1235 show_expr (c
->expr
);
1237 fprintf (dumpfile
, "%d", c
->ext
.stop_code
);
1241 case EXEC_ARITHMETIC_IF
:
1242 fputs ("IF ", dumpfile
);
1243 show_expr (c
->expr
);
1244 fprintf (dumpfile
, " %d, %d, %d",
1245 c
->label
->value
, c
->label2
->value
, c
->label3
->value
);
1250 fputs ("IF ", dumpfile
);
1251 show_expr (d
->expr
);
1252 fputc ('\n', dumpfile
);
1253 show_code (level
+ 1, d
->next
);
1256 for (; d
; d
= d
->block
)
1258 code_indent (level
, 0);
1260 if (d
->expr
== NULL
)
1261 fputs ("ELSE\n", dumpfile
);
1264 fputs ("ELSE IF ", dumpfile
);
1265 show_expr (d
->expr
);
1266 fputc ('\n', dumpfile
);
1269 show_code (level
+ 1, d
->next
);
1272 code_indent (level
, c
->label
);
1274 fputs ("ENDIF", dumpfile
);
1279 fputs ("SELECT CASE ", dumpfile
);
1280 show_expr (c
->expr
);
1281 fputc ('\n', dumpfile
);
1283 for (; d
; d
= d
->block
)
1285 code_indent (level
, 0);
1287 fputs ("CASE ", dumpfile
);
1288 for (cp
= d
->ext
.case_list
; cp
; cp
= cp
->next
)
1290 fputc ('(', dumpfile
);
1291 show_expr (cp
->low
);
1292 fputc (' ', dumpfile
);
1293 show_expr (cp
->high
);
1294 fputc (')', dumpfile
);
1295 fputc (' ', dumpfile
);
1297 fputc ('\n', dumpfile
);
1299 show_code (level
+ 1, d
->next
);
1302 code_indent (level
, c
->label
);
1303 fputs ("END SELECT", dumpfile
);
1307 fputs ("WHERE ", dumpfile
);
1310 show_expr (d
->expr
);
1311 fputc ('\n', dumpfile
);
1313 show_code (level
+ 1, d
->next
);
1315 for (d
= d
->block
; d
; d
= d
->block
)
1317 code_indent (level
, 0);
1318 fputs ("ELSE WHERE ", dumpfile
);
1319 show_expr (d
->expr
);
1320 fputc ('\n', dumpfile
);
1321 show_code (level
+ 1, d
->next
);
1324 code_indent (level
, 0);
1325 fputs ("END WHERE", dumpfile
);
1330 fputs ("FORALL ", dumpfile
);
1331 for (fa
= c
->ext
.forall_iterator
; fa
; fa
= fa
->next
)
1333 show_expr (fa
->var
);
1334 fputc (' ', dumpfile
);
1335 show_expr (fa
->start
);
1336 fputc (':', dumpfile
);
1337 show_expr (fa
->end
);
1338 fputc (':', dumpfile
);
1339 show_expr (fa
->stride
);
1341 if (fa
->next
!= NULL
)
1342 fputc (',', dumpfile
);
1345 if (c
->expr
!= NULL
)
1347 fputc (',', dumpfile
);
1348 show_expr (c
->expr
);
1350 fputc ('\n', dumpfile
);
1352 show_code (level
+ 1, c
->block
->next
);
1354 code_indent (level
, 0);
1355 fputs ("END FORALL", dumpfile
);
1359 fputs ("DO ", dumpfile
);
1361 show_expr (c
->ext
.iterator
->var
);
1362 fputc ('=', dumpfile
);
1363 show_expr (c
->ext
.iterator
->start
);
1364 fputc (' ', dumpfile
);
1365 show_expr (c
->ext
.iterator
->end
);
1366 fputc (' ', dumpfile
);
1367 show_expr (c
->ext
.iterator
->step
);
1368 fputc ('\n', dumpfile
);
1370 show_code (level
+ 1, c
->block
->next
);
1372 code_indent (level
, 0);
1373 fputs ("END DO", dumpfile
);
1377 fputs ("DO WHILE ", dumpfile
);
1378 show_expr (c
->expr
);
1379 fputc ('\n', dumpfile
);
1381 show_code (level
+ 1, c
->block
->next
);
1383 code_indent (level
, c
->label
);
1384 fputs ("END DO", dumpfile
);
1388 fputs ("CYCLE", dumpfile
);
1390 fprintf (dumpfile
, " %s", c
->symtree
->n
.sym
->name
);
1394 fputs ("EXIT", dumpfile
);
1396 fprintf (dumpfile
, " %s", c
->symtree
->n
.sym
->name
);
1400 fputs ("ALLOCATE ", dumpfile
);
1403 fputs (" STAT=", dumpfile
);
1404 show_expr (c
->expr
);
1407 for (a
= c
->ext
.alloc_list
; a
; a
= a
->next
)
1409 fputc (' ', dumpfile
);
1410 show_expr (a
->expr
);
1415 case EXEC_DEALLOCATE
:
1416 fputs ("DEALLOCATE ", dumpfile
);
1419 fputs (" STAT=", dumpfile
);
1420 show_expr (c
->expr
);
1423 for (a
= c
->ext
.alloc_list
; a
; a
= a
->next
)
1425 fputc (' ', dumpfile
);
1426 show_expr (a
->expr
);
1432 fputs ("OPEN", dumpfile
);
1437 fputs (" UNIT=", dumpfile
);
1438 show_expr (open
->unit
);
1442 fputs (" IOMSG=", dumpfile
);
1443 show_expr (open
->iomsg
);
1447 fputs (" IOSTAT=", dumpfile
);
1448 show_expr (open
->iostat
);
1452 fputs (" FILE=", dumpfile
);
1453 show_expr (open
->file
);
1457 fputs (" STATUS=", dumpfile
);
1458 show_expr (open
->status
);
1462 fputs (" ACCESS=", dumpfile
);
1463 show_expr (open
->access
);
1467 fputs (" FORM=", dumpfile
);
1468 show_expr (open
->form
);
1472 fputs (" RECL=", dumpfile
);
1473 show_expr (open
->recl
);
1477 fputs (" BLANK=", dumpfile
);
1478 show_expr (open
->blank
);
1482 fputs (" POSITION=", dumpfile
);
1483 show_expr (open
->position
);
1487 fputs (" ACTION=", dumpfile
);
1488 show_expr (open
->action
);
1492 fputs (" DELIM=", dumpfile
);
1493 show_expr (open
->delim
);
1497 fputs (" PAD=", dumpfile
);
1498 show_expr (open
->pad
);
1502 fputs (" DECIMAL=", dumpfile
);
1503 show_expr (open
->decimal
);
1507 fputs (" ENCODING=", dumpfile
);
1508 show_expr (open
->encoding
);
1512 fputs (" ROUND=", dumpfile
);
1513 show_expr (open
->round
);
1517 fputs (" SIGN=", dumpfile
);
1518 show_expr (open
->sign
);
1522 fputs (" CONVERT=", dumpfile
);
1523 show_expr (open
->convert
);
1525 if (open
->asynchronous
)
1527 fputs (" ASYNCHRONOUS=", dumpfile
);
1528 show_expr (open
->asynchronous
);
1530 if (open
->err
!= NULL
)
1531 fprintf (dumpfile
, " ERR=%d", open
->err
->value
);
1536 fputs ("CLOSE", dumpfile
);
1537 close
= c
->ext
.close
;
1541 fputs (" UNIT=", dumpfile
);
1542 show_expr (close
->unit
);
1546 fputs (" IOMSG=", dumpfile
);
1547 show_expr (close
->iomsg
);
1551 fputs (" IOSTAT=", dumpfile
);
1552 show_expr (close
->iostat
);
1556 fputs (" STATUS=", dumpfile
);
1557 show_expr (close
->status
);
1559 if (close
->err
!= NULL
)
1560 fprintf (dumpfile
, " ERR=%d", close
->err
->value
);
1563 case EXEC_BACKSPACE
:
1564 fputs ("BACKSPACE", dumpfile
);
1568 fputs ("ENDFILE", dumpfile
);
1572 fputs ("REWIND", dumpfile
);
1576 fputs ("FLUSH", dumpfile
);
1579 fp
= c
->ext
.filepos
;
1583 fputs (" UNIT=", dumpfile
);
1584 show_expr (fp
->unit
);
1588 fputs (" IOMSG=", dumpfile
);
1589 show_expr (fp
->iomsg
);
1593 fputs (" IOSTAT=", dumpfile
);
1594 show_expr (fp
->iostat
);
1596 if (fp
->err
!= NULL
)
1597 fprintf (dumpfile
, " ERR=%d", fp
->err
->value
);
1601 fputs ("INQUIRE", dumpfile
);
1606 fputs (" UNIT=", dumpfile
);
1607 show_expr (i
->unit
);
1611 fputs (" FILE=", dumpfile
);
1612 show_expr (i
->file
);
1617 fputs (" IOMSG=", dumpfile
);
1618 show_expr (i
->iomsg
);
1622 fputs (" IOSTAT=", dumpfile
);
1623 show_expr (i
->iostat
);
1627 fputs (" EXIST=", dumpfile
);
1628 show_expr (i
->exist
);
1632 fputs (" OPENED=", dumpfile
);
1633 show_expr (i
->opened
);
1637 fputs (" NUMBER=", dumpfile
);
1638 show_expr (i
->number
);
1642 fputs (" NAMED=", dumpfile
);
1643 show_expr (i
->named
);
1647 fputs (" NAME=", dumpfile
);
1648 show_expr (i
->name
);
1652 fputs (" ACCESS=", dumpfile
);
1653 show_expr (i
->access
);
1657 fputs (" SEQUENTIAL=", dumpfile
);
1658 show_expr (i
->sequential
);
1663 fputs (" DIRECT=", dumpfile
);
1664 show_expr (i
->direct
);
1668 fputs (" FORM=", dumpfile
);
1669 show_expr (i
->form
);
1673 fputs (" FORMATTED", dumpfile
);
1674 show_expr (i
->formatted
);
1678 fputs (" UNFORMATTED=", dumpfile
);
1679 show_expr (i
->unformatted
);
1683 fputs (" RECL=", dumpfile
);
1684 show_expr (i
->recl
);
1688 fputs (" NEXTREC=", dumpfile
);
1689 show_expr (i
->nextrec
);
1693 fputs (" BLANK=", dumpfile
);
1694 show_expr (i
->blank
);
1698 fputs (" POSITION=", dumpfile
);
1699 show_expr (i
->position
);
1703 fputs (" ACTION=", dumpfile
);
1704 show_expr (i
->action
);
1708 fputs (" READ=", dumpfile
);
1709 show_expr (i
->read
);
1713 fputs (" WRITE=", dumpfile
);
1714 show_expr (i
->write
);
1718 fputs (" READWRITE=", dumpfile
);
1719 show_expr (i
->readwrite
);
1723 fputs (" DELIM=", dumpfile
);
1724 show_expr (i
->delim
);
1728 fputs (" PAD=", dumpfile
);
1733 fputs (" CONVERT=", dumpfile
);
1734 show_expr (i
->convert
);
1736 if (i
->asynchronous
)
1738 fputs (" ASYNCHRONOUS=", dumpfile
);
1739 show_expr (i
->asynchronous
);
1743 fputs (" DECIMAL=", dumpfile
);
1744 show_expr (i
->decimal
);
1748 fputs (" ENCODING=", dumpfile
);
1749 show_expr (i
->encoding
);
1753 fputs (" PENDING=", dumpfile
);
1754 show_expr (i
->pending
);
1758 fputs (" ROUND=", dumpfile
);
1759 show_expr (i
->round
);
1763 fputs (" SIGN=", dumpfile
);
1764 show_expr (i
->sign
);
1768 fputs (" SIZE=", dumpfile
);
1769 show_expr (i
->size
);
1773 fputs (" ID=", dumpfile
);
1778 fprintf (dumpfile
, " ERR=%d", i
->err
->value
);
1782 fputs ("IOLENGTH ", dumpfile
);
1783 show_expr (c
->expr
);
1788 fputs ("READ", dumpfile
);
1792 fputs ("WRITE", dumpfile
);
1798 fputs (" UNIT=", dumpfile
);
1799 show_expr (dt
->io_unit
);
1802 if (dt
->format_expr
)
1804 fputs (" FMT=", dumpfile
);
1805 show_expr (dt
->format_expr
);
1808 if (dt
->format_label
!= NULL
)
1809 fprintf (dumpfile
, " FMT=%d", dt
->format_label
->value
);
1811 fprintf (dumpfile
, " NML=%s", dt
->namelist
->name
);
1815 fputs (" IOMSG=", dumpfile
);
1816 show_expr (dt
->iomsg
);
1820 fputs (" IOSTAT=", dumpfile
);
1821 show_expr (dt
->iostat
);
1825 fputs (" SIZE=", dumpfile
);
1826 show_expr (dt
->size
);
1830 fputs (" REC=", dumpfile
);
1831 show_expr (dt
->rec
);
1835 fputs (" ADVANCE=", dumpfile
);
1836 show_expr (dt
->advance
);
1840 fputs (" ID=", dumpfile
);
1845 fputs (" POS=", dumpfile
);
1846 show_expr (dt
->pos
);
1848 if (dt
->asynchronous
)
1850 fputs (" ASYNCHRONOUS=", dumpfile
);
1851 show_expr (dt
->asynchronous
);
1855 fputs (" BLANK=", dumpfile
);
1856 show_expr (dt
->blank
);
1860 fputs (" DECIMAL=", dumpfile
);
1861 show_expr (dt
->decimal
);
1865 fputs (" DELIM=", dumpfile
);
1866 show_expr (dt
->delim
);
1870 fputs (" PAD=", dumpfile
);
1871 show_expr (dt
->pad
);
1875 fputs (" ROUND=", dumpfile
);
1876 show_expr (dt
->round
);
1880 fputs (" SIGN=", dumpfile
);
1881 show_expr (dt
->sign
);
1885 fputc ('\n', dumpfile
);
1886 for (c
= c
->block
->next
; c
; c
= c
->next
)
1887 show_code_node (level
+ (c
->next
!= NULL
), c
);
1891 fputs ("TRANSFER ", dumpfile
);
1892 show_expr (c
->expr
);
1896 fputs ("DT_END", dumpfile
);
1899 if (dt
->err
!= NULL
)
1900 fprintf (dumpfile
, " ERR=%d", dt
->err
->value
);
1901 if (dt
->end
!= NULL
)
1902 fprintf (dumpfile
, " END=%d", dt
->end
->value
);
1903 if (dt
->eor
!= NULL
)
1904 fprintf (dumpfile
, " EOR=%d", dt
->eor
->value
);
1907 case EXEC_OMP_ATOMIC
:
1908 case EXEC_OMP_BARRIER
:
1909 case EXEC_OMP_CRITICAL
:
1910 case EXEC_OMP_FLUSH
:
1912 case EXEC_OMP_MASTER
:
1913 case EXEC_OMP_ORDERED
:
1914 case EXEC_OMP_PARALLEL
:
1915 case EXEC_OMP_PARALLEL_DO
:
1916 case EXEC_OMP_PARALLEL_SECTIONS
:
1917 case EXEC_OMP_PARALLEL_WORKSHARE
:
1918 case EXEC_OMP_SECTIONS
:
1919 case EXEC_OMP_SINGLE
:
1921 case EXEC_OMP_TASKWAIT
:
1922 case EXEC_OMP_WORKSHARE
:
1923 show_omp_node (level
, c
);
1927 gfc_internal_error ("show_code_node(): Bad statement code");
1930 fputc ('\n', dumpfile
);
1934 /* Show an equivalence chain. */
1937 show_equiv (gfc_equiv
*eq
)
1940 fputs ("Equivalence: ", dumpfile
);
1943 show_expr (eq
->expr
);
1946 fputs (", ", dumpfile
);
1951 /* Show a freakin' whole namespace. */
1954 show_namespace (gfc_namespace
*ns
)
1956 gfc_interface
*intr
;
1957 gfc_namespace
*save
;
1958 gfc_intrinsic_op op
;
1962 save
= gfc_current_ns
;
1966 fputs ("Namespace:", dumpfile
);
1974 while (i
< GFC_LETTERS
- 1
1975 && gfc_compare_types(&ns
->default_type
[i
+1],
1976 &ns
->default_type
[l
]))
1980 fprintf (dumpfile
, " %c-%c: ", l
+'A', i
+'A');
1982 fprintf (dumpfile
, " %c: ", l
+'A');
1984 show_typespec(&ns
->default_type
[l
]);
1986 } while (i
< GFC_LETTERS
);
1988 if (ns
->proc_name
!= NULL
)
1991 fprintf (dumpfile
, "procedure name = %s", ns
->proc_name
->name
);
1994 gfc_current_ns
= ns
;
1995 gfc_traverse_symtree (ns
->common_root
, show_common
);
1997 gfc_traverse_symtree (ns
->sym_root
, show_symtree
);
1999 for (op
= GFC_INTRINSIC_BEGIN
; op
!= GFC_INTRINSIC_END
; op
++)
2001 /* User operator interfaces */
2007 fprintf (dumpfile
, "Operator interfaces for %s:",
2008 gfc_op2string (op
));
2010 for (; intr
; intr
= intr
->next
)
2011 fprintf (dumpfile
, " %s", intr
->sym
->name
);
2014 if (ns
->uop_root
!= NULL
)
2017 fputs ("User operators:\n", dumpfile
);
2018 gfc_traverse_user_op (ns
, show_uop
);
2022 for (eq
= ns
->equiv
; eq
; eq
= eq
->next
)
2025 fputc ('\n', dumpfile
);
2026 fputc ('\n', dumpfile
);
2028 show_code (0, ns
->code
);
2030 for (ns
= ns
->contained
; ns
; ns
= ns
->sibling
)
2033 fputs ("CONTAINS\n", dumpfile
);
2034 show_namespace (ns
);
2038 fputc ('\n', dumpfile
);
2039 gfc_current_ns
= save
;
2043 /* Main function for dumping a parse tree. */
2046 gfc_dump_parse_tree (gfc_namespace
*ns
, FILE *file
)
2049 show_namespace (ns
);