2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
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 #include "constructor.h"
39 /* Keep track of indentation for symbol tree dumps. */
40 static int show_level = 0;
42 /* The file handle we're dumping to is kept in a static variable. This
43 is not too cool, but it avoids a lot of passing it around. */
44 static FILE *dumpfile;
46 /* Forward declaration of some of the functions. */
47 static void show_expr (gfc_expr *p);
48 static void show_code_node (int, gfc_code *);
49 static void show_namespace (gfc_namespace *ns);
52 /* Allow dumping of an expression in the debugger. */
53 void gfc_debug_expr (gfc_expr *);
56 gfc_debug_expr (gfc_expr *e)
61 fputc ('\n', dumpfile);
66 /* Do indentation for a specific level. */
69 code_indent (int level, gfc_st_label *label)
74 fprintf (dumpfile, "%-5d ", label->value);
76 fputs (" ", dumpfile);
78 for (i = 0; i < 2 * level; i++)
79 fputc (' ', dumpfile);
83 /* Simple indentation at the current level. This one
84 is used to show symbols. */
89 fputc ('\n', dumpfile);
90 code_indent (show_level, NULL);
94 /* Show type-specific information. */
97 show_typespec (gfc_typespec *ts)
99 fprintf (dumpfile, "(%s ", gfc_basic_typename (ts->type));
104 fprintf (dumpfile, "%s", ts->u.derived->name);
108 show_expr (ts->u.cl->length);
112 fprintf (dumpfile, "%d", ts->kind);
116 fputc (')', dumpfile);
120 /* Show an actual argument list. */
123 show_actual_arglist (gfc_actual_arglist *a)
125 fputc ('(', dumpfile);
127 for (; a; a = a->next)
129 fputc ('(', dumpfile);
131 fprintf (dumpfile, "%s = ", a->name);
135 fputs ("(arg not-present)", dumpfile);
137 fputc (')', dumpfile);
139 fputc (' ', dumpfile);
142 fputc (')', dumpfile);
146 /* Show a gfc_array_spec array specification structure. */
149 show_array_spec (gfc_array_spec *as)
156 fputs ("()", dumpfile);
160 fprintf (dumpfile, "(%d [%d]", as->rank, as->corank);
162 if (as->rank + as->corank > 0)
166 case AS_EXPLICIT: c = "AS_EXPLICIT"; break;
167 case AS_DEFERRED: c = "AS_DEFERRED"; break;
168 case AS_ASSUMED_SIZE: c = "AS_ASSUMED_SIZE"; break;
169 case AS_ASSUMED_SHAPE: c = "AS_ASSUMED_SHAPE"; break;
171 gfc_internal_error ("show_array_spec(): Unhandled array shape "
174 fprintf (dumpfile, " %s ", c);
176 for (i = 0; i < as->rank + as->corank; i++)
178 show_expr (as->lower[i]);
179 fputc (' ', dumpfile);
180 show_expr (as->upper[i]);
181 fputc (' ', dumpfile);
185 fputc (')', dumpfile);
189 /* Show a gfc_array_ref array reference structure. */
192 show_array_ref (gfc_array_ref * ar)
196 fputc ('(', dumpfile);
201 fputs ("FULL", dumpfile);
205 for (i = 0; i < ar->dimen; i++)
207 /* There are two types of array sections: either the
208 elements are identified by an integer array ('vector'),
209 or by an index range. In the former case we only have to
210 print the start expression which contains the vector, in
211 the latter case we have to print any of lower and upper
212 bound and the stride, if they're present. */
214 if (ar->start[i] != NULL)
215 show_expr (ar->start[i]);
217 if (ar->dimen_type[i] == DIMEN_RANGE)
219 fputc (':', dumpfile);
221 if (ar->end[i] != NULL)
222 show_expr (ar->end[i]);
224 if (ar->stride[i] != NULL)
226 fputc (':', dumpfile);
227 show_expr (ar->stride[i]);
231 if (i != ar->dimen - 1)
232 fputs (" , ", dumpfile);
237 for (i = 0; i < ar->dimen; i++)
239 show_expr (ar->start[i]);
240 if (i != ar->dimen - 1)
241 fputs (" , ", dumpfile);
246 fputs ("UNKNOWN", dumpfile);
250 gfc_internal_error ("show_array_ref(): Unknown array reference");
253 fputc (')', dumpfile);
257 /* Show a list of gfc_ref structures. */
260 show_ref (gfc_ref *p)
262 for (; p; p = p->next)
266 show_array_ref (&p->u.ar);
270 fprintf (dumpfile, " %% %s", p->u.c.component->name);
274 fputc ('(', dumpfile);
275 show_expr (p->u.ss.start);
276 fputc (':', dumpfile);
277 show_expr (p->u.ss.end);
278 fputc (')', dumpfile);
282 gfc_internal_error ("show_ref(): Bad component code");
287 /* Display a constructor. Works recursively for array constructors. */
290 show_constructor (gfc_constructor_base base)
293 for (c = gfc_constructor_first (base); c; c = gfc_constructor_next (c))
295 if (c->iterator == NULL)
299 fputc ('(', dumpfile);
302 fputc (' ', dumpfile);
303 show_expr (c->iterator->var);
304 fputc ('=', dumpfile);
305 show_expr (c->iterator->start);
306 fputc (',', dumpfile);
307 show_expr (c->iterator->end);
308 fputc (',', dumpfile);
309 show_expr (c->iterator->step);
311 fputc (')', dumpfile);
314 if (gfc_constructor_next (c) != NULL)
315 fputs (" , ", dumpfile);
321 show_char_const (const gfc_char_t *c, int length)
325 fputc ('\'', dumpfile);
326 for (i = 0; i < length; i++)
329 fputs ("''", dumpfile);
331 fputs (gfc_print_wide_char (c[i]), dumpfile);
333 fputc ('\'', dumpfile);
337 /* Show a component-call expression. */
340 show_compcall (gfc_expr* p)
342 gcc_assert (p->expr_type == EXPR_COMPCALL);
344 fprintf (dumpfile, "%s", p->symtree->n.sym->name);
346 fprintf (dumpfile, "%s", p->value.compcall.name);
348 show_actual_arglist (p->value.compcall.actual);
352 /* Show an expression. */
355 show_expr (gfc_expr *p)
362 fputs ("()", dumpfile);
366 switch (p->expr_type)
369 show_char_const (p->value.character.string, p->value.character.length);
374 fprintf (dumpfile, "%s(", p->ts.u.derived->name);
375 show_constructor (p->value.constructor);
376 fputc (')', dumpfile);
380 fputs ("(/ ", dumpfile);
381 show_constructor (p->value.constructor);
382 fputs (" /)", dumpfile);
388 fputs ("NULL()", dumpfile);
395 mpz_out_str (stdout, 10, p->value.integer);
397 if (p->ts.kind != gfc_default_integer_kind)
398 fprintf (dumpfile, "_%d", p->ts.kind);
402 if (p->value.logical)
403 fputs (".true.", dumpfile);
405 fputs (".false.", dumpfile);
409 mpfr_out_str (stdout, 10, 0, p->value.real, GFC_RND_MODE);
410 if (p->ts.kind != gfc_default_real_kind)
411 fprintf (dumpfile, "_%d", p->ts.kind);
415 show_char_const (p->value.character.string,
416 p->value.character.length);
420 fputs ("(complex ", dumpfile);
422 mpfr_out_str (stdout, 10, 0, mpc_realref (p->value.complex),
424 if (p->ts.kind != gfc_default_complex_kind)
425 fprintf (dumpfile, "_%d", p->ts.kind);
427 fputc (' ', dumpfile);
429 mpfr_out_str (stdout, 10, 0, mpc_imagref (p->value.complex),
431 if (p->ts.kind != gfc_default_complex_kind)
432 fprintf (dumpfile, "_%d", p->ts.kind);
434 fputc (')', dumpfile);
438 fprintf (dumpfile, "%dH", p->representation.length);
439 c = p->representation.string;
440 for (i = 0; i < p->representation.length; i++, c++)
442 fputc (*c, dumpfile);
447 fputs ("???", dumpfile);
451 if (p->representation.string)
453 fputs (" {", dumpfile);
454 c = p->representation.string;
455 for (i = 0; i < p->representation.length; i++, c++)
457 fprintf (dumpfile, "%.2x", (unsigned int) *c);
458 if (i < p->representation.length - 1)
459 fputc (',', dumpfile);
461 fputc ('}', dumpfile);
467 if (p->symtree->n.sym->ns && p->symtree->n.sym->ns->proc_name)
468 fprintf (dumpfile, "%s:", p->symtree->n.sym->ns->proc_name->name);
469 fprintf (dumpfile, "%s", p->symtree->n.sym->name);
474 fputc ('(', dumpfile);
475 switch (p->value.op.op)
477 case INTRINSIC_UPLUS:
478 fputs ("U+ ", dumpfile);
480 case INTRINSIC_UMINUS:
481 fputs ("U- ", dumpfile);
484 fputs ("+ ", dumpfile);
486 case INTRINSIC_MINUS:
487 fputs ("- ", dumpfile);
489 case INTRINSIC_TIMES:
490 fputs ("* ", dumpfile);
492 case INTRINSIC_DIVIDE:
493 fputs ("/ ", dumpfile);
495 case INTRINSIC_POWER:
496 fputs ("** ", dumpfile);
498 case INTRINSIC_CONCAT:
499 fputs ("// ", dumpfile);
502 fputs ("AND ", dumpfile);
505 fputs ("OR ", dumpfile);
508 fputs ("EQV ", dumpfile);
511 fputs ("NEQV ", dumpfile);
514 case INTRINSIC_EQ_OS:
515 fputs ("= ", dumpfile);
518 case INTRINSIC_NE_OS:
519 fputs ("/= ", dumpfile);
522 case INTRINSIC_GT_OS:
523 fputs ("> ", dumpfile);
526 case INTRINSIC_GE_OS:
527 fputs (">= ", dumpfile);
530 case INTRINSIC_LT_OS:
531 fputs ("< ", dumpfile);
534 case INTRINSIC_LE_OS:
535 fputs ("<= ", dumpfile);
538 fputs ("NOT ", dumpfile);
540 case INTRINSIC_PARENTHESES:
541 fputs ("parens", dumpfile);
546 ("show_expr(): Bad intrinsic in expression!");
549 show_expr (p->value.op.op1);
553 fputc (' ', dumpfile);
554 show_expr (p->value.op.op2);
557 fputc (')', dumpfile);
561 if (p->value.function.name == NULL)
563 fprintf (dumpfile, "%s", p->symtree->n.sym->name);
564 if (gfc_is_proc_ptr_comp (p, NULL))
566 fputc ('[', dumpfile);
567 show_actual_arglist (p->value.function.actual);
568 fputc (']', dumpfile);
572 fprintf (dumpfile, "%s", p->value.function.name);
573 if (gfc_is_proc_ptr_comp (p, NULL))
575 fputc ('[', dumpfile);
576 fputc ('[', dumpfile);
577 show_actual_arglist (p->value.function.actual);
578 fputc (']', dumpfile);
579 fputc (']', dumpfile);
589 gfc_internal_error ("show_expr(): Don't know how to show expr");
593 /* Show symbol attributes. The flavor and intent are followed by
594 whatever single bit attributes are present. */
597 show_attr (symbol_attribute *attr)
600 fprintf (dumpfile, "(%s %s %s %s %s",
601 gfc_code2string (flavors, attr->flavor),
602 gfc_intent_string (attr->intent),
603 gfc_code2string (access_types, attr->access),
604 gfc_code2string (procedures, attr->proc),
605 gfc_code2string (save_status, attr->save));
607 if (attr->allocatable)
608 fputs (" ALLOCATABLE", dumpfile);
609 if (attr->asynchronous)
610 fputs (" ASYNCHRONOUS", dumpfile);
611 if (attr->codimension)
612 fputs (" CODIMENSION", dumpfile);
614 fputs (" DIMENSION", dumpfile);
615 if (attr->contiguous)
616 fputs (" CONTIGUOUS", dumpfile);
618 fputs (" EXTERNAL", dumpfile);
620 fputs (" INTRINSIC", dumpfile);
622 fputs (" OPTIONAL", dumpfile);
624 fputs (" POINTER", dumpfile);
625 if (attr->is_protected)
626 fputs (" PROTECTED", dumpfile);
628 fputs (" VALUE", dumpfile);
630 fputs (" VOLATILE", dumpfile);
631 if (attr->threadprivate)
632 fputs (" THREADPRIVATE", dumpfile);
634 fputs (" TARGET", dumpfile);
636 fputs (" DUMMY", dumpfile);
638 fputs (" RESULT", dumpfile);
640 fputs (" ENTRY", dumpfile);
642 fputs (" BIND(C)", dumpfile);
645 fputs (" DATA", dumpfile);
647 fputs (" USE-ASSOC", dumpfile);
648 if (attr->in_namelist)
649 fputs (" IN-NAMELIST", dumpfile);
651 fputs (" IN-COMMON", dumpfile);
654 fputs (" ABSTRACT", dumpfile);
656 fputs (" FUNCTION", dumpfile);
657 if (attr->subroutine)
658 fputs (" SUBROUTINE", dumpfile);
659 if (attr->implicit_type)
660 fputs (" IMPLICIT-TYPE", dumpfile);
663 fputs (" SEQUENCE", dumpfile);
665 fputs (" ELEMENTAL", dumpfile);
667 fputs (" PURE", dumpfile);
669 fputs (" RECURSIVE", dumpfile);
671 fputc (')', dumpfile);
675 /* Show components of a derived type. */
678 show_components (gfc_symbol *sym)
682 for (c = sym->components; c; c = c->next)
684 fprintf (dumpfile, "(%s ", c->name);
685 show_typespec (&c->ts);
687 fputs (" POINTER", dumpfile);
688 if (c->attr.proc_pointer)
689 fputs (" PPC", dumpfile);
690 if (c->attr.dimension)
691 fputs (" DIMENSION", dumpfile);
692 fputc (' ', dumpfile);
693 show_array_spec (c->as);
695 fprintf (dumpfile, " %s", gfc_code2string (access_types, c->attr.access));
696 fputc (')', dumpfile);
698 fputc (' ', dumpfile);
703 /* Show the f2k_derived namespace with procedure bindings. */
706 show_typebound_proc (gfc_typebound_proc* tb, const char* name)
711 fputs ("GENERIC", dumpfile);
714 fputs ("PROCEDURE, ", dumpfile);
716 fputs ("NOPASS", dumpfile);
720 fprintf (dumpfile, "PASS(%s)", tb->pass_arg);
722 fputs ("PASS", dumpfile);
724 if (tb->non_overridable)
725 fputs (", NON_OVERRIDABLE", dumpfile);
728 if (tb->access == ACCESS_PUBLIC)
729 fputs (", PUBLIC", dumpfile);
731 fputs (", PRIVATE", dumpfile);
733 fprintf (dumpfile, " :: %s => ", name);
738 for (g = tb->u.generic; g; g = g->next)
740 fputs (g->specific_st->name, dumpfile);
742 fputs (", ", dumpfile);
746 fputs (tb->u.specific->n.sym->name, dumpfile);
750 show_typebound_symtree (gfc_symtree* st)
752 gcc_assert (st->n.tb);
753 show_typebound_proc (st->n.tb, st->name);
757 show_f2k_derived (gfc_namespace* f2k)
763 fputs ("Procedure bindings:", dumpfile);
766 /* Finalizer bindings. */
767 for (f = f2k->finalizers; f; f = f->next)
770 fprintf (dumpfile, "FINAL %s", f->proc_sym->name);
773 /* Type-bound procedures. */
774 gfc_traverse_symtree (f2k->tb_sym_root, &show_typebound_symtree);
779 fputs ("Operator bindings:", dumpfile);
782 /* User-defined operators. */
783 gfc_traverse_symtree (f2k->tb_uop_root, &show_typebound_symtree);
785 /* Intrinsic operators. */
786 for (op = GFC_INTRINSIC_BEGIN; op != GFC_INTRINSIC_END; ++op)
788 show_typebound_proc (f2k->tb_op[op],
789 gfc_op2string ((gfc_intrinsic_op) op));
795 /* Show a symbol. If a symbol is an ENTRY, SUBROUTINE or FUNCTION, we
796 show the interface. Information needed to reconstruct the list of
797 specific interfaces associated with a generic symbol is done within
801 show_symbol (gfc_symbol *sym)
803 gfc_formal_arglist *formal;
811 fprintf (dumpfile, "symbol %s ", sym->name);
812 show_typespec (&sym->ts);
814 /* If this symbol is an associate-name, show its target expression. */
817 fputs (" => ", dumpfile);
818 show_expr (sym->assoc->target);
819 fputs (" ", dumpfile);
822 show_attr (&sym->attr);
827 fputs ("value: ", dumpfile);
828 show_expr (sym->value);
834 fputs ("Array spec:", dumpfile);
835 show_array_spec (sym->as);
841 fputs ("Generic interfaces:", dumpfile);
842 for (intr = sym->generic; intr; intr = intr->next)
843 fprintf (dumpfile, " %s", intr->sym->name);
849 fprintf (dumpfile, "result: %s", sym->result->name);
855 fputs ("components: ", dumpfile);
856 show_components (sym);
859 if (sym->f2k_derived)
863 fprintf (dumpfile, "hash: %d", sym->hash_value);
864 show_f2k_derived (sym->f2k_derived);
870 fputs ("Formal arglist:", dumpfile);
872 for (formal = sym->formal; formal; formal = formal->next)
874 if (formal->sym != NULL)
875 fprintf (dumpfile, " %s", formal->sym->name);
877 fputs (" [Alt Return]", dumpfile);
881 if (sym->formal_ns && (sym->formal_ns->proc_name != sym))
884 fputs ("Formal namespace", dumpfile);
885 show_namespace (sym->formal_ns);
888 fputc ('\n', dumpfile);
892 /* Show a user-defined operator. Just prints an operator
893 and the name of the associated subroutine, really. */
896 show_uop (gfc_user_op *uop)
901 fprintf (dumpfile, "%s:", uop->name);
903 for (intr = uop->op; intr; intr = intr->next)
904 fprintf (dumpfile, " %s", intr->sym->name);
908 /* Workhorse function for traversing the user operator symtree. */
911 traverse_uop (gfc_symtree *st, void (*func) (gfc_user_op *))
918 traverse_uop (st->left, func);
919 traverse_uop (st->right, func);
923 /* Traverse the tree of user operator nodes. */
926 gfc_traverse_user_op (gfc_namespace *ns, void (*func) (gfc_user_op *))
928 traverse_uop (ns->uop_root, func);
932 /* Function to display a common block. */
935 show_common (gfc_symtree *st)
940 fprintf (dumpfile, "common: /%s/ ", st->name);
942 s = st->n.common->head;
945 fprintf (dumpfile, "%s", s->name);
948 fputs (", ", dumpfile);
950 fputc ('\n', dumpfile);
954 /* Worker function to display the symbol tree. */
957 show_symtree (gfc_symtree *st)
960 fprintf (dumpfile, "symtree: %s Ambig %d", st->name, st->ambiguous);
962 if (st->n.sym->ns != gfc_current_ns)
963 fprintf (dumpfile, " from namespace %s", st->n.sym->ns->proc_name->name);
965 show_symbol (st->n.sym);
969 /******************* Show gfc_code structures **************/
972 /* Show a list of code structures. Mutually recursive with
976 show_code (int level, gfc_code *c)
978 for (; c; c = c->next)
979 show_code_node (level, c);
983 show_namelist (gfc_namelist *n)
985 for (; n->next; n = n->next)
986 fprintf (dumpfile, "%s,", n->sym->name);
987 fprintf (dumpfile, "%s", n->sym->name);
990 /* Show a single OpenMP directive node and everything underneath it
994 show_omp_node (int level, gfc_code *c)
996 gfc_omp_clauses *omp_clauses = NULL;
997 const char *name = NULL;
1001 case EXEC_OMP_ATOMIC: name = "ATOMIC"; break;
1002 case EXEC_OMP_BARRIER: name = "BARRIER"; break;
1003 case EXEC_OMP_CRITICAL: name = "CRITICAL"; break;
1004 case EXEC_OMP_FLUSH: name = "FLUSH"; break;
1005 case EXEC_OMP_DO: name = "DO"; break;
1006 case EXEC_OMP_MASTER: name = "MASTER"; break;
1007 case EXEC_OMP_ORDERED: name = "ORDERED"; break;
1008 case EXEC_OMP_PARALLEL: name = "PARALLEL"; break;
1009 case EXEC_OMP_PARALLEL_DO: name = "PARALLEL DO"; break;
1010 case EXEC_OMP_PARALLEL_SECTIONS: name = "PARALLEL SECTIONS"; break;
1011 case EXEC_OMP_PARALLEL_WORKSHARE: name = "PARALLEL WORKSHARE"; break;
1012 case EXEC_OMP_SECTIONS: name = "SECTIONS"; break;
1013 case EXEC_OMP_SINGLE: name = "SINGLE"; break;
1014 case EXEC_OMP_TASK: name = "TASK"; break;
1015 case EXEC_OMP_TASKWAIT: name = "TASKWAIT"; break;
1016 case EXEC_OMP_WORKSHARE: name = "WORKSHARE"; break;
1020 fprintf (dumpfile, "!$OMP %s", name);
1024 case EXEC_OMP_PARALLEL:
1025 case EXEC_OMP_PARALLEL_DO:
1026 case EXEC_OMP_PARALLEL_SECTIONS:
1027 case EXEC_OMP_SECTIONS:
1028 case EXEC_OMP_SINGLE:
1029 case EXEC_OMP_WORKSHARE:
1030 case EXEC_OMP_PARALLEL_WORKSHARE:
1032 omp_clauses = c->ext.omp_clauses;
1034 case EXEC_OMP_CRITICAL:
1035 if (c->ext.omp_name)
1036 fprintf (dumpfile, " (%s)", c->ext.omp_name);
1038 case EXEC_OMP_FLUSH:
1039 if (c->ext.omp_namelist)
1041 fputs (" (", dumpfile);
1042 show_namelist (c->ext.omp_namelist);
1043 fputc (')', dumpfile);
1046 case EXEC_OMP_BARRIER:
1047 case EXEC_OMP_TASKWAIT:
1056 if (omp_clauses->if_expr)
1058 fputs (" IF(", dumpfile);
1059 show_expr (omp_clauses->if_expr);
1060 fputc (')', dumpfile);
1062 if (omp_clauses->num_threads)
1064 fputs (" NUM_THREADS(", dumpfile);
1065 show_expr (omp_clauses->num_threads);
1066 fputc (')', dumpfile);
1068 if (omp_clauses->sched_kind != OMP_SCHED_NONE)
1071 switch (omp_clauses->sched_kind)
1073 case OMP_SCHED_STATIC: type = "STATIC"; break;
1074 case OMP_SCHED_DYNAMIC: type = "DYNAMIC"; break;
1075 case OMP_SCHED_GUIDED: type = "GUIDED"; break;
1076 case OMP_SCHED_RUNTIME: type = "RUNTIME"; break;
1077 case OMP_SCHED_AUTO: type = "AUTO"; break;
1081 fprintf (dumpfile, " SCHEDULE (%s", type);
1082 if (omp_clauses->chunk_size)
1084 fputc (',', dumpfile);
1085 show_expr (omp_clauses->chunk_size);
1087 fputc (')', dumpfile);
1089 if (omp_clauses->default_sharing != OMP_DEFAULT_UNKNOWN)
1092 switch (omp_clauses->default_sharing)
1094 case OMP_DEFAULT_NONE: type = "NONE"; break;
1095 case OMP_DEFAULT_PRIVATE: type = "PRIVATE"; break;
1096 case OMP_DEFAULT_SHARED: type = "SHARED"; break;
1097 case OMP_DEFAULT_FIRSTPRIVATE: type = "FIRSTPRIVATE"; break;
1101 fprintf (dumpfile, " DEFAULT(%s)", type);
1103 if (omp_clauses->ordered)
1104 fputs (" ORDERED", dumpfile);
1105 if (omp_clauses->untied)
1106 fputs (" UNTIED", dumpfile);
1107 if (omp_clauses->collapse)
1108 fprintf (dumpfile, " COLLAPSE(%d)", omp_clauses->collapse);
1109 for (list_type = 0; list_type < OMP_LIST_NUM; list_type++)
1110 if (omp_clauses->lists[list_type] != NULL
1111 && list_type != OMP_LIST_COPYPRIVATE)
1114 if (list_type >= OMP_LIST_REDUCTION_FIRST)
1118 case OMP_LIST_PLUS: type = "+"; break;
1119 case OMP_LIST_MULT: type = "*"; break;
1120 case OMP_LIST_SUB: type = "-"; break;
1121 case OMP_LIST_AND: type = ".AND."; break;
1122 case OMP_LIST_OR: type = ".OR."; break;
1123 case OMP_LIST_EQV: type = ".EQV."; break;
1124 case OMP_LIST_NEQV: type = ".NEQV."; break;
1125 case OMP_LIST_MAX: type = "MAX"; break;
1126 case OMP_LIST_MIN: type = "MIN"; break;
1127 case OMP_LIST_IAND: type = "IAND"; break;
1128 case OMP_LIST_IOR: type = "IOR"; break;
1129 case OMP_LIST_IEOR: type = "IEOR"; break;
1133 fprintf (dumpfile, " REDUCTION(%s:", type);
1139 case OMP_LIST_PRIVATE: type = "PRIVATE"; break;
1140 case OMP_LIST_FIRSTPRIVATE: type = "FIRSTPRIVATE"; break;
1141 case OMP_LIST_LASTPRIVATE: type = "LASTPRIVATE"; break;
1142 case OMP_LIST_SHARED: type = "SHARED"; break;
1143 case OMP_LIST_COPYIN: type = "COPYIN"; break;
1147 fprintf (dumpfile, " %s(", type);
1149 show_namelist (omp_clauses->lists[list_type]);
1150 fputc (')', dumpfile);
1153 fputc ('\n', dumpfile);
1154 if (c->op == EXEC_OMP_SECTIONS || c->op == EXEC_OMP_PARALLEL_SECTIONS)
1156 gfc_code *d = c->block;
1159 show_code (level + 1, d->next);
1160 if (d->block == NULL)
1162 code_indent (level, 0);
1163 fputs ("!$OMP SECTION\n", dumpfile);
1168 show_code (level + 1, c->block->next);
1169 if (c->op == EXEC_OMP_ATOMIC)
1171 code_indent (level, 0);
1172 fprintf (dumpfile, "!$OMP END %s", name);
1173 if (omp_clauses != NULL)
1175 if (omp_clauses->lists[OMP_LIST_COPYPRIVATE])
1177 fputs (" COPYPRIVATE(", dumpfile);
1178 show_namelist (omp_clauses->lists[OMP_LIST_COPYPRIVATE]);
1179 fputc (')', dumpfile);
1181 else if (omp_clauses->nowait)
1182 fputs (" NOWAIT", dumpfile);
1184 else if (c->op == EXEC_OMP_CRITICAL && c->ext.omp_name)
1185 fprintf (dumpfile, " (%s)", c->ext.omp_name);
1189 /* Show a single code node and everything underneath it if necessary. */
1192 show_code_node (int level, gfc_code *c)
1194 gfc_forall_iterator *fa;
1205 code_indent (level, c->here);
1209 case EXEC_END_PROCEDURE:
1213 fputs ("NOP", dumpfile);
1217 fputs ("CONTINUE", dumpfile);
1221 fprintf (dumpfile, "ENTRY %s", c->ext.entry->sym->name);
1224 case EXEC_INIT_ASSIGN:
1226 fputs ("ASSIGN ", dumpfile);
1227 show_expr (c->expr1);
1228 fputc (' ', dumpfile);
1229 show_expr (c->expr2);
1232 case EXEC_LABEL_ASSIGN:
1233 fputs ("LABEL ASSIGN ", dumpfile);
1234 show_expr (c->expr1);
1235 fprintf (dumpfile, " %d", c->label1->value);
1238 case EXEC_POINTER_ASSIGN:
1239 fputs ("POINTER ASSIGN ", dumpfile);
1240 show_expr (c->expr1);
1241 fputc (' ', dumpfile);
1242 show_expr (c->expr2);
1246 fputs ("GOTO ", dumpfile);
1248 fprintf (dumpfile, "%d", c->label1->value);
1251 show_expr (c->expr1);
1255 fputs (", (", dumpfile);
1256 for (; d; d = d ->block)
1258 code_indent (level, d->label1);
1259 if (d->block != NULL)
1260 fputc (',', dumpfile);
1262 fputc (')', dumpfile);
1269 case EXEC_ASSIGN_CALL:
1270 if (c->resolved_sym)
1271 fprintf (dumpfile, "CALL %s ", c->resolved_sym->name);
1272 else if (c->symtree)
1273 fprintf (dumpfile, "CALL %s ", c->symtree->name);
1275 fputs ("CALL ?? ", dumpfile);
1277 show_actual_arglist (c->ext.actual);
1281 fputs ("CALL ", dumpfile);
1282 show_compcall (c->expr1);
1286 fputs ("CALL ", dumpfile);
1287 show_expr (c->expr1);
1288 show_actual_arglist (c->ext.actual);
1292 fputs ("RETURN ", dumpfile);
1294 show_expr (c->expr1);
1298 fputs ("PAUSE ", dumpfile);
1300 if (c->expr1 != NULL)
1301 show_expr (c->expr1);
1303 fprintf (dumpfile, "%d", c->ext.stop_code);
1307 case EXEC_ERROR_STOP:
1308 fputs ("ERROR ", dumpfile);
1312 fputs ("STOP ", dumpfile);
1314 if (c->expr1 != NULL)
1315 show_expr (c->expr1);
1317 fprintf (dumpfile, "%d", c->ext.stop_code);
1322 fputs ("SYNC ALL ", dumpfile);
1323 if (c->expr2 != NULL)
1325 fputs (" stat=", dumpfile);
1326 show_expr (c->expr2);
1328 if (c->expr3 != NULL)
1330 fputs (" errmsg=", dumpfile);
1331 show_expr (c->expr3);
1335 case EXEC_SYNC_MEMORY:
1336 fputs ("SYNC MEMORY ", dumpfile);
1337 if (c->expr2 != NULL)
1339 fputs (" stat=", dumpfile);
1340 show_expr (c->expr2);
1342 if (c->expr3 != NULL)
1344 fputs (" errmsg=", dumpfile);
1345 show_expr (c->expr3);
1349 case EXEC_SYNC_IMAGES:
1350 fputs ("SYNC IMAGES image-set=", dumpfile);
1351 if (c->expr1 != NULL)
1352 show_expr (c->expr1);
1354 fputs ("* ", dumpfile);
1355 if (c->expr2 != NULL)
1357 fputs (" stat=", dumpfile);
1358 show_expr (c->expr2);
1360 if (c->expr3 != NULL)
1362 fputs (" errmsg=", dumpfile);
1363 show_expr (c->expr3);
1367 case EXEC_ARITHMETIC_IF:
1368 fputs ("IF ", dumpfile);
1369 show_expr (c->expr1);
1370 fprintf (dumpfile, " %d, %d, %d",
1371 c->label1->value, c->label2->value, c->label3->value);
1376 fputs ("IF ", dumpfile);
1377 show_expr (d->expr1);
1378 fputc ('\n', dumpfile);
1379 show_code (level + 1, d->next);
1382 for (; d; d = d->block)
1384 code_indent (level, 0);
1386 if (d->expr1 == NULL)
1387 fputs ("ELSE\n", dumpfile);
1390 fputs ("ELSE IF ", dumpfile);
1391 show_expr (d->expr1);
1392 fputc ('\n', dumpfile);
1395 show_code (level + 1, d->next);
1398 code_indent (level, c->label1);
1400 fputs ("ENDIF", dumpfile);
1405 const char* blocktype;
1406 if (c->ext.block.assoc)
1407 blocktype = "ASSOCIATE";
1409 blocktype = "BLOCK";
1411 fprintf (dumpfile, "%s ", blocktype);
1412 ns = c->ext.block.ns;
1413 show_namespace (ns);
1415 fprintf (dumpfile, "END %s ", blocktype);
1421 fputs ("SELECT CASE ", dumpfile);
1422 show_expr (c->expr1);
1423 fputc ('\n', dumpfile);
1425 for (; d; d = d->block)
1427 code_indent (level, 0);
1429 fputs ("CASE ", dumpfile);
1430 for (cp = d->ext.case_list; cp; cp = cp->next)
1432 fputc ('(', dumpfile);
1433 show_expr (cp->low);
1434 fputc (' ', dumpfile);
1435 show_expr (cp->high);
1436 fputc (')', dumpfile);
1437 fputc (' ', dumpfile);
1439 fputc ('\n', dumpfile);
1441 show_code (level + 1, d->next);
1444 code_indent (level, c->label1);
1445 fputs ("END SELECT", dumpfile);
1449 fputs ("WHERE ", dumpfile);
1452 show_expr (d->expr1);
1453 fputc ('\n', dumpfile);
1455 show_code (level + 1, d->next);
1457 for (d = d->block; d; d = d->block)
1459 code_indent (level, 0);
1460 fputs ("ELSE WHERE ", dumpfile);
1461 show_expr (d->expr1);
1462 fputc ('\n', dumpfile);
1463 show_code (level + 1, d->next);
1466 code_indent (level, 0);
1467 fputs ("END WHERE", dumpfile);
1472 fputs ("FORALL ", dumpfile);
1473 for (fa = c->ext.forall_iterator; fa; fa = fa->next)
1475 show_expr (fa->var);
1476 fputc (' ', dumpfile);
1477 show_expr (fa->start);
1478 fputc (':', dumpfile);
1479 show_expr (fa->end);
1480 fputc (':', dumpfile);
1481 show_expr (fa->stride);
1483 if (fa->next != NULL)
1484 fputc (',', dumpfile);
1487 if (c->expr1 != NULL)
1489 fputc (',', dumpfile);
1490 show_expr (c->expr1);
1492 fputc ('\n', dumpfile);
1494 show_code (level + 1, c->block->next);
1496 code_indent (level, 0);
1497 fputs ("END FORALL", dumpfile);
1501 fputs ("CRITICAL\n", dumpfile);
1502 show_code (level + 1, c->block->next);
1503 code_indent (level, 0);
1504 fputs ("END CRITICAL", dumpfile);
1508 fputs ("DO ", dumpfile);
1510 show_expr (c->ext.iterator->var);
1511 fputc ('=', dumpfile);
1512 show_expr (c->ext.iterator->start);
1513 fputc (' ', dumpfile);
1514 show_expr (c->ext.iterator->end);
1515 fputc (' ', dumpfile);
1516 show_expr (c->ext.iterator->step);
1517 fputc ('\n', dumpfile);
1519 show_code (level + 1, c->block->next);
1521 code_indent (level, 0);
1522 fputs ("END DO", dumpfile);
1526 fputs ("DO WHILE ", dumpfile);
1527 show_expr (c->expr1);
1528 fputc ('\n', dumpfile);
1530 show_code (level + 1, c->block->next);
1532 code_indent (level, c->label1);
1533 fputs ("END DO", dumpfile);
1537 fputs ("CYCLE", dumpfile);
1539 fprintf (dumpfile, " %s", c->symtree->n.sym->name);
1543 fputs ("EXIT", dumpfile);
1545 fprintf (dumpfile, " %s", c->symtree->n.sym->name);
1549 fputs ("ALLOCATE ", dumpfile);
1552 fputs (" STAT=", dumpfile);
1553 show_expr (c->expr1);
1558 fputs (" ERRMSG=", dumpfile);
1559 show_expr (c->expr2);
1562 for (a = c->ext.alloc.list; a; a = a->next)
1564 fputc (' ', dumpfile);
1565 show_expr (a->expr);
1570 case EXEC_DEALLOCATE:
1571 fputs ("DEALLOCATE ", dumpfile);
1574 fputs (" STAT=", dumpfile);
1575 show_expr (c->expr1);
1580 fputs (" ERRMSG=", dumpfile);
1581 show_expr (c->expr2);
1584 for (a = c->ext.alloc.list; a; a = a->next)
1586 fputc (' ', dumpfile);
1587 show_expr (a->expr);
1593 fputs ("OPEN", dumpfile);
1598 fputs (" UNIT=", dumpfile);
1599 show_expr (open->unit);
1603 fputs (" IOMSG=", dumpfile);
1604 show_expr (open->iomsg);
1608 fputs (" IOSTAT=", dumpfile);
1609 show_expr (open->iostat);
1613 fputs (" FILE=", dumpfile);
1614 show_expr (open->file);
1618 fputs (" STATUS=", dumpfile);
1619 show_expr (open->status);
1623 fputs (" ACCESS=", dumpfile);
1624 show_expr (open->access);
1628 fputs (" FORM=", dumpfile);
1629 show_expr (open->form);
1633 fputs (" RECL=", dumpfile);
1634 show_expr (open->recl);
1638 fputs (" BLANK=", dumpfile);
1639 show_expr (open->blank);
1643 fputs (" POSITION=", dumpfile);
1644 show_expr (open->position);
1648 fputs (" ACTION=", dumpfile);
1649 show_expr (open->action);
1653 fputs (" DELIM=", dumpfile);
1654 show_expr (open->delim);
1658 fputs (" PAD=", dumpfile);
1659 show_expr (open->pad);
1663 fputs (" DECIMAL=", dumpfile);
1664 show_expr (open->decimal);
1668 fputs (" ENCODING=", dumpfile);
1669 show_expr (open->encoding);
1673 fputs (" ROUND=", dumpfile);
1674 show_expr (open->round);
1678 fputs (" SIGN=", dumpfile);
1679 show_expr (open->sign);
1683 fputs (" CONVERT=", dumpfile);
1684 show_expr (open->convert);
1686 if (open->asynchronous)
1688 fputs (" ASYNCHRONOUS=", dumpfile);
1689 show_expr (open->asynchronous);
1691 if (open->err != NULL)
1692 fprintf (dumpfile, " ERR=%d", open->err->value);
1697 fputs ("CLOSE", dumpfile);
1698 close = c->ext.close;
1702 fputs (" UNIT=", dumpfile);
1703 show_expr (close->unit);
1707 fputs (" IOMSG=", dumpfile);
1708 show_expr (close->iomsg);
1712 fputs (" IOSTAT=", dumpfile);
1713 show_expr (close->iostat);
1717 fputs (" STATUS=", dumpfile);
1718 show_expr (close->status);
1720 if (close->err != NULL)
1721 fprintf (dumpfile, " ERR=%d", close->err->value);
1724 case EXEC_BACKSPACE:
1725 fputs ("BACKSPACE", dumpfile);
1729 fputs ("ENDFILE", dumpfile);
1733 fputs ("REWIND", dumpfile);
1737 fputs ("FLUSH", dumpfile);
1740 fp = c->ext.filepos;
1744 fputs (" UNIT=", dumpfile);
1745 show_expr (fp->unit);
1749 fputs (" IOMSG=", dumpfile);
1750 show_expr (fp->iomsg);
1754 fputs (" IOSTAT=", dumpfile);
1755 show_expr (fp->iostat);
1757 if (fp->err != NULL)
1758 fprintf (dumpfile, " ERR=%d", fp->err->value);
1762 fputs ("INQUIRE", dumpfile);
1767 fputs (" UNIT=", dumpfile);
1768 show_expr (i->unit);
1772 fputs (" FILE=", dumpfile);
1773 show_expr (i->file);
1778 fputs (" IOMSG=", dumpfile);
1779 show_expr (i->iomsg);
1783 fputs (" IOSTAT=", dumpfile);
1784 show_expr (i->iostat);
1788 fputs (" EXIST=", dumpfile);
1789 show_expr (i->exist);
1793 fputs (" OPENED=", dumpfile);
1794 show_expr (i->opened);
1798 fputs (" NUMBER=", dumpfile);
1799 show_expr (i->number);
1803 fputs (" NAMED=", dumpfile);
1804 show_expr (i->named);
1808 fputs (" NAME=", dumpfile);
1809 show_expr (i->name);
1813 fputs (" ACCESS=", dumpfile);
1814 show_expr (i->access);
1818 fputs (" SEQUENTIAL=", dumpfile);
1819 show_expr (i->sequential);
1824 fputs (" DIRECT=", dumpfile);
1825 show_expr (i->direct);
1829 fputs (" FORM=", dumpfile);
1830 show_expr (i->form);
1834 fputs (" FORMATTED", dumpfile);
1835 show_expr (i->formatted);
1839 fputs (" UNFORMATTED=", dumpfile);
1840 show_expr (i->unformatted);
1844 fputs (" RECL=", dumpfile);
1845 show_expr (i->recl);
1849 fputs (" NEXTREC=", dumpfile);
1850 show_expr (i->nextrec);
1854 fputs (" BLANK=", dumpfile);
1855 show_expr (i->blank);
1859 fputs (" POSITION=", dumpfile);
1860 show_expr (i->position);
1864 fputs (" ACTION=", dumpfile);
1865 show_expr (i->action);
1869 fputs (" READ=", dumpfile);
1870 show_expr (i->read);
1874 fputs (" WRITE=", dumpfile);
1875 show_expr (i->write);
1879 fputs (" READWRITE=", dumpfile);
1880 show_expr (i->readwrite);
1884 fputs (" DELIM=", dumpfile);
1885 show_expr (i->delim);
1889 fputs (" PAD=", dumpfile);
1894 fputs (" CONVERT=", dumpfile);
1895 show_expr (i->convert);
1897 if (i->asynchronous)
1899 fputs (" ASYNCHRONOUS=", dumpfile);
1900 show_expr (i->asynchronous);
1904 fputs (" DECIMAL=", dumpfile);
1905 show_expr (i->decimal);
1909 fputs (" ENCODING=", dumpfile);
1910 show_expr (i->encoding);
1914 fputs (" PENDING=", dumpfile);
1915 show_expr (i->pending);
1919 fputs (" ROUND=", dumpfile);
1920 show_expr (i->round);
1924 fputs (" SIGN=", dumpfile);
1925 show_expr (i->sign);
1929 fputs (" SIZE=", dumpfile);
1930 show_expr (i->size);
1934 fputs (" ID=", dumpfile);
1939 fprintf (dumpfile, " ERR=%d", i->err->value);
1943 fputs ("IOLENGTH ", dumpfile);
1944 show_expr (c->expr1);
1949 fputs ("READ", dumpfile);
1953 fputs ("WRITE", dumpfile);
1959 fputs (" UNIT=", dumpfile);
1960 show_expr (dt->io_unit);
1963 if (dt->format_expr)
1965 fputs (" FMT=", dumpfile);
1966 show_expr (dt->format_expr);
1969 if (dt->format_label != NULL)
1970 fprintf (dumpfile, " FMT=%d", dt->format_label->value);
1972 fprintf (dumpfile, " NML=%s", dt->namelist->name);
1976 fputs (" IOMSG=", dumpfile);
1977 show_expr (dt->iomsg);
1981 fputs (" IOSTAT=", dumpfile);
1982 show_expr (dt->iostat);
1986 fputs (" SIZE=", dumpfile);
1987 show_expr (dt->size);
1991 fputs (" REC=", dumpfile);
1992 show_expr (dt->rec);
1996 fputs (" ADVANCE=", dumpfile);
1997 show_expr (dt->advance);
2001 fputs (" ID=", dumpfile);
2006 fputs (" POS=", dumpfile);
2007 show_expr (dt->pos);
2009 if (dt->asynchronous)
2011 fputs (" ASYNCHRONOUS=", dumpfile);
2012 show_expr (dt->asynchronous);
2016 fputs (" BLANK=", dumpfile);
2017 show_expr (dt->blank);
2021 fputs (" DECIMAL=", dumpfile);
2022 show_expr (dt->decimal);
2026 fputs (" DELIM=", dumpfile);
2027 show_expr (dt->delim);
2031 fputs (" PAD=", dumpfile);
2032 show_expr (dt->pad);
2036 fputs (" ROUND=", dumpfile);
2037 show_expr (dt->round);
2041 fputs (" SIGN=", dumpfile);
2042 show_expr (dt->sign);
2046 fputc ('\n', dumpfile);
2047 for (c = c->block->next; c; c = c->next)
2048 show_code_node (level + (c->next != NULL), c);
2052 fputs ("TRANSFER ", dumpfile);
2053 show_expr (c->expr1);
2057 fputs ("DT_END", dumpfile);
2060 if (dt->err != NULL)
2061 fprintf (dumpfile, " ERR=%d", dt->err->value);
2062 if (dt->end != NULL)
2063 fprintf (dumpfile, " END=%d", dt->end->value);
2064 if (dt->eor != NULL)
2065 fprintf (dumpfile, " EOR=%d", dt->eor->value);
2068 case EXEC_OMP_ATOMIC:
2069 case EXEC_OMP_BARRIER:
2070 case EXEC_OMP_CRITICAL:
2071 case EXEC_OMP_FLUSH:
2073 case EXEC_OMP_MASTER:
2074 case EXEC_OMP_ORDERED:
2075 case EXEC_OMP_PARALLEL:
2076 case EXEC_OMP_PARALLEL_DO:
2077 case EXEC_OMP_PARALLEL_SECTIONS:
2078 case EXEC_OMP_PARALLEL_WORKSHARE:
2079 case EXEC_OMP_SECTIONS:
2080 case EXEC_OMP_SINGLE:
2082 case EXEC_OMP_TASKWAIT:
2083 case EXEC_OMP_WORKSHARE:
2084 show_omp_node (level, c);
2088 gfc_internal_error ("show_code_node(): Bad statement code");
2091 fputc ('\n', dumpfile);
2095 /* Show an equivalence chain. */
2098 show_equiv (gfc_equiv *eq)
2101 fputs ("Equivalence: ", dumpfile);
2104 show_expr (eq->expr);
2107 fputs (", ", dumpfile);
2112 /* Show a freakin' whole namespace. */
2115 show_namespace (gfc_namespace *ns)
2117 gfc_interface *intr;
2118 gfc_namespace *save;
2123 save = gfc_current_ns;
2127 fputs ("Namespace:", dumpfile);
2135 while (i < GFC_LETTERS - 1
2136 && gfc_compare_types(&ns->default_type[i+1],
2137 &ns->default_type[l]))
2141 fprintf (dumpfile, " %c-%c: ", l+'A', i+'A');
2143 fprintf (dumpfile, " %c: ", l+'A');
2145 show_typespec(&ns->default_type[l]);
2147 } while (i < GFC_LETTERS);
2149 if (ns->proc_name != NULL)
2152 fprintf (dumpfile, "procedure name = %s", ns->proc_name->name);
2155 gfc_current_ns = ns;
2156 gfc_traverse_symtree (ns->common_root, show_common);
2158 gfc_traverse_symtree (ns->sym_root, show_symtree);
2160 for (op = GFC_INTRINSIC_BEGIN; op != GFC_INTRINSIC_END; op++)
2162 /* User operator interfaces */
2168 fprintf (dumpfile, "Operator interfaces for %s:",
2169 gfc_op2string ((gfc_intrinsic_op) op));
2171 for (; intr; intr = intr->next)
2172 fprintf (dumpfile, " %s", intr->sym->name);
2175 if (ns->uop_root != NULL)
2178 fputs ("User operators:\n", dumpfile);
2179 gfc_traverse_user_op (ns, show_uop);
2183 for (eq = ns->equiv; eq; eq = eq->next)
2186 fputc ('\n', dumpfile);
2187 fputc ('\n', dumpfile);
2189 show_code (show_level, ns->code);
2191 for (ns = ns->contained; ns; ns = ns->sibling)
2194 fputs ("CONTAINS\n", dumpfile);
2195 show_namespace (ns);
2199 fputc ('\n', dumpfile);
2200 gfc_current_ns = save;
2204 /* Main function for dumping a parse tree. */
2207 gfc_dump_parse_tree (gfc_namespace *ns, FILE *file)
2210 show_namespace (ns);