PR rtl-optimization/43520
[official-gcc.git] / gcc / fortran / dump-parse-tree.c
blob967a0a543ff20388fc341c5657e4ed49673a082d
1 /* Parse tree dumper
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
11 version.
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
16 for more details.
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
30 relatives.
32 TODO: Dump DATA. */
34 #include "config.h"
35 #include "gfortran.h"
36 #include "constructor.h"
38 /* Keep track of indentation for symbol tree dumps. */
39 static int show_level = 0;
41 /* The file handle we're dumping to is kept in a static variable. This
42 is not too cool, but it avoids a lot of passing it around. */
43 static FILE *dumpfile;
45 /* Forward declaration of some of the functions. */
46 static void show_expr (gfc_expr *p);
47 static void show_code_node (int, gfc_code *);
48 static void show_namespace (gfc_namespace *ns);
51 /* Do indentation for a specific level. */
53 static inline void
54 code_indent (int level, gfc_st_label *label)
56 int i;
58 if (label != NULL)
59 fprintf (dumpfile, "%-5d ", label->value);
60 else
61 fputs (" ", dumpfile);
63 for (i = 0; i < 2 * level; i++)
64 fputc (' ', dumpfile);
68 /* Simple indentation at the current level. This one
69 is used to show symbols. */
71 static inline void
72 show_indent (void)
74 fputc ('\n', dumpfile);
75 code_indent (show_level, NULL);
79 /* Show type-specific information. */
81 static void
82 show_typespec (gfc_typespec *ts)
84 fprintf (dumpfile, "(%s ", gfc_basic_typename (ts->type));
86 switch (ts->type)
88 case BT_DERIVED:
89 fprintf (dumpfile, "%s", ts->u.derived->name);
90 break;
92 case BT_CHARACTER:
93 show_expr (ts->u.cl->length);
94 break;
96 default:
97 fprintf (dumpfile, "%d", ts->kind);
98 break;
101 fputc (')', dumpfile);
105 /* Show an actual argument list. */
107 static void
108 show_actual_arglist (gfc_actual_arglist *a)
110 fputc ('(', dumpfile);
112 for (; a; a = a->next)
114 fputc ('(', dumpfile);
115 if (a->name != NULL)
116 fprintf (dumpfile, "%s = ", a->name);
117 if (a->expr != NULL)
118 show_expr (a->expr);
119 else
120 fputs ("(arg not-present)", dumpfile);
122 fputc (')', dumpfile);
123 if (a->next != NULL)
124 fputc (' ', dumpfile);
127 fputc (')', dumpfile);
131 /* Show a gfc_array_spec array specification structure. */
133 static void
134 show_array_spec (gfc_array_spec *as)
136 const char *c;
137 int i;
139 if (as == NULL)
141 fputs ("()", dumpfile);
142 return;
145 fprintf (dumpfile, "(%d [%d]", as->rank, as->corank);
147 if (as->rank + as->corank > 0)
149 switch (as->type)
151 case AS_EXPLICIT: c = "AS_EXPLICIT"; break;
152 case AS_DEFERRED: c = "AS_DEFERRED"; break;
153 case AS_ASSUMED_SIZE: c = "AS_ASSUMED_SIZE"; break;
154 case AS_ASSUMED_SHAPE: c = "AS_ASSUMED_SHAPE"; break;
155 default:
156 gfc_internal_error ("show_array_spec(): Unhandled array shape "
157 "type.");
159 fprintf (dumpfile, " %s ", c);
161 for (i = 0; i < as->rank + as->corank; i++)
163 show_expr (as->lower[i]);
164 fputc (' ', dumpfile);
165 show_expr (as->upper[i]);
166 fputc (' ', dumpfile);
170 fputc (')', dumpfile);
174 /* Show a gfc_array_ref array reference structure. */
176 static void
177 show_array_ref (gfc_array_ref * ar)
179 int i;
181 fputc ('(', dumpfile);
183 switch (ar->type)
185 case AR_FULL:
186 fputs ("FULL", dumpfile);
187 break;
189 case AR_SECTION:
190 for (i = 0; i < ar->dimen; i++)
192 /* There are two types of array sections: either the
193 elements are identified by an integer array ('vector'),
194 or by an index range. In the former case we only have to
195 print the start expression which contains the vector, in
196 the latter case we have to print any of lower and upper
197 bound and the stride, if they're present. */
199 if (ar->start[i] != NULL)
200 show_expr (ar->start[i]);
202 if (ar->dimen_type[i] == DIMEN_RANGE)
204 fputc (':', dumpfile);
206 if (ar->end[i] != NULL)
207 show_expr (ar->end[i]);
209 if (ar->stride[i] != NULL)
211 fputc (':', dumpfile);
212 show_expr (ar->stride[i]);
216 if (i != ar->dimen - 1)
217 fputs (" , ", dumpfile);
219 break;
221 case AR_ELEMENT:
222 for (i = 0; i < ar->dimen; i++)
224 show_expr (ar->start[i]);
225 if (i != ar->dimen - 1)
226 fputs (" , ", dumpfile);
228 break;
230 case AR_UNKNOWN:
231 fputs ("UNKNOWN", dumpfile);
232 break;
234 default:
235 gfc_internal_error ("show_array_ref(): Unknown array reference");
238 fputc (')', dumpfile);
242 /* Show a list of gfc_ref structures. */
244 static void
245 show_ref (gfc_ref *p)
247 for (; p; p = p->next)
248 switch (p->type)
250 case REF_ARRAY:
251 show_array_ref (&p->u.ar);
252 break;
254 case REF_COMPONENT:
255 fprintf (dumpfile, " %% %s", p->u.c.component->name);
256 break;
258 case REF_SUBSTRING:
259 fputc ('(', dumpfile);
260 show_expr (p->u.ss.start);
261 fputc (':', dumpfile);
262 show_expr (p->u.ss.end);
263 fputc (')', dumpfile);
264 break;
266 default:
267 gfc_internal_error ("show_ref(): Bad component code");
272 /* Display a constructor. Works recursively for array constructors. */
274 static void
275 show_constructor (gfc_constructor_base base)
277 gfc_constructor *c;
278 for (c = gfc_constructor_first (base); c; c = gfc_constructor_next (c))
280 if (c->iterator == NULL)
281 show_expr (c->expr);
282 else
284 fputc ('(', dumpfile);
285 show_expr (c->expr);
287 fputc (' ', dumpfile);
288 show_expr (c->iterator->var);
289 fputc ('=', dumpfile);
290 show_expr (c->iterator->start);
291 fputc (',', dumpfile);
292 show_expr (c->iterator->end);
293 fputc (',', dumpfile);
294 show_expr (c->iterator->step);
296 fputc (')', dumpfile);
299 if (gfc_constructor_next (c) != NULL)
300 fputs (" , ", dumpfile);
305 static void
306 show_char_const (const gfc_char_t *c, int length)
308 int i;
310 fputc ('\'', dumpfile);
311 for (i = 0; i < length; i++)
313 if (c[i] == '\'')
314 fputs ("''", dumpfile);
315 else
316 fputs (gfc_print_wide_char (c[i]), dumpfile);
318 fputc ('\'', dumpfile);
322 /* Show a component-call expression. */
324 static void
325 show_compcall (gfc_expr* p)
327 gcc_assert (p->expr_type == EXPR_COMPCALL);
329 fprintf (dumpfile, "%s", p->symtree->n.sym->name);
330 show_ref (p->ref);
331 fprintf (dumpfile, "%s", p->value.compcall.name);
333 show_actual_arglist (p->value.compcall.actual);
337 /* Show an expression. */
339 static void
340 show_expr (gfc_expr *p)
342 const char *c;
343 int i;
345 if (p == NULL)
347 fputs ("()", dumpfile);
348 return;
351 switch (p->expr_type)
353 case EXPR_SUBSTRING:
354 show_char_const (p->value.character.string, p->value.character.length);
355 show_ref (p->ref);
356 break;
358 case EXPR_STRUCTURE:
359 fprintf (dumpfile, "%s(", p->ts.u.derived->name);
360 show_constructor (p->value.constructor);
361 fputc (')', dumpfile);
362 break;
364 case EXPR_ARRAY:
365 fputs ("(/ ", dumpfile);
366 show_constructor (p->value.constructor);
367 fputs (" /)", dumpfile);
369 show_ref (p->ref);
370 break;
372 case EXPR_NULL:
373 fputs ("NULL()", dumpfile);
374 break;
376 case EXPR_CONSTANT:
377 switch (p->ts.type)
379 case BT_INTEGER:
380 mpz_out_str (stdout, 10, p->value.integer);
382 if (p->ts.kind != gfc_default_integer_kind)
383 fprintf (dumpfile, "_%d", p->ts.kind);
384 break;
386 case BT_LOGICAL:
387 if (p->value.logical)
388 fputs (".true.", dumpfile);
389 else
390 fputs (".false.", dumpfile);
391 break;
393 case BT_REAL:
394 mpfr_out_str (stdout, 10, 0, p->value.real, GFC_RND_MODE);
395 if (p->ts.kind != gfc_default_real_kind)
396 fprintf (dumpfile, "_%d", p->ts.kind);
397 break;
399 case BT_CHARACTER:
400 show_char_const (p->value.character.string,
401 p->value.character.length);
402 break;
404 case BT_COMPLEX:
405 fputs ("(complex ", dumpfile);
407 mpfr_out_str (stdout, 10, 0, mpc_realref (p->value.complex),
408 GFC_RND_MODE);
409 if (p->ts.kind != gfc_default_complex_kind)
410 fprintf (dumpfile, "_%d", p->ts.kind);
412 fputc (' ', dumpfile);
414 mpfr_out_str (stdout, 10, 0, mpc_imagref (p->value.complex),
415 GFC_RND_MODE);
416 if (p->ts.kind != gfc_default_complex_kind)
417 fprintf (dumpfile, "_%d", p->ts.kind);
419 fputc (')', dumpfile);
420 break;
422 case BT_HOLLERITH:
423 fprintf (dumpfile, "%dH", p->representation.length);
424 c = p->representation.string;
425 for (i = 0; i < p->representation.length; i++, c++)
427 fputc (*c, dumpfile);
429 break;
431 default:
432 fputs ("???", dumpfile);
433 break;
436 if (p->representation.string)
438 fputs (" {", dumpfile);
439 c = p->representation.string;
440 for (i = 0; i < p->representation.length; i++, c++)
442 fprintf (dumpfile, "%.2x", (unsigned int) *c);
443 if (i < p->representation.length - 1)
444 fputc (',', dumpfile);
446 fputc ('}', dumpfile);
449 break;
451 case EXPR_VARIABLE:
452 if (p->symtree->n.sym->ns && p->symtree->n.sym->ns->proc_name)
453 fprintf (dumpfile, "%s:", p->symtree->n.sym->ns->proc_name->name);
454 fprintf (dumpfile, "%s", p->symtree->n.sym->name);
455 show_ref (p->ref);
456 break;
458 case EXPR_OP:
459 fputc ('(', dumpfile);
460 switch (p->value.op.op)
462 case INTRINSIC_UPLUS:
463 fputs ("U+ ", dumpfile);
464 break;
465 case INTRINSIC_UMINUS:
466 fputs ("U- ", dumpfile);
467 break;
468 case INTRINSIC_PLUS:
469 fputs ("+ ", dumpfile);
470 break;
471 case INTRINSIC_MINUS:
472 fputs ("- ", dumpfile);
473 break;
474 case INTRINSIC_TIMES:
475 fputs ("* ", dumpfile);
476 break;
477 case INTRINSIC_DIVIDE:
478 fputs ("/ ", dumpfile);
479 break;
480 case INTRINSIC_POWER:
481 fputs ("** ", dumpfile);
482 break;
483 case INTRINSIC_CONCAT:
484 fputs ("// ", dumpfile);
485 break;
486 case INTRINSIC_AND:
487 fputs ("AND ", dumpfile);
488 break;
489 case INTRINSIC_OR:
490 fputs ("OR ", dumpfile);
491 break;
492 case INTRINSIC_EQV:
493 fputs ("EQV ", dumpfile);
494 break;
495 case INTRINSIC_NEQV:
496 fputs ("NEQV ", dumpfile);
497 break;
498 case INTRINSIC_EQ:
499 case INTRINSIC_EQ_OS:
500 fputs ("= ", dumpfile);
501 break;
502 case INTRINSIC_NE:
503 case INTRINSIC_NE_OS:
504 fputs ("/= ", dumpfile);
505 break;
506 case INTRINSIC_GT:
507 case INTRINSIC_GT_OS:
508 fputs ("> ", dumpfile);
509 break;
510 case INTRINSIC_GE:
511 case INTRINSIC_GE_OS:
512 fputs (">= ", dumpfile);
513 break;
514 case INTRINSIC_LT:
515 case INTRINSIC_LT_OS:
516 fputs ("< ", dumpfile);
517 break;
518 case INTRINSIC_LE:
519 case INTRINSIC_LE_OS:
520 fputs ("<= ", dumpfile);
521 break;
522 case INTRINSIC_NOT:
523 fputs ("NOT ", dumpfile);
524 break;
525 case INTRINSIC_PARENTHESES:
526 fputs ("parens", dumpfile);
527 break;
529 default:
530 gfc_internal_error
531 ("show_expr(): Bad intrinsic in expression!");
534 show_expr (p->value.op.op1);
536 if (p->value.op.op2)
538 fputc (' ', dumpfile);
539 show_expr (p->value.op.op2);
542 fputc (')', dumpfile);
543 break;
545 case EXPR_FUNCTION:
546 if (p->value.function.name == NULL)
548 fprintf (dumpfile, "%s", p->symtree->n.sym->name);
549 if (gfc_is_proc_ptr_comp (p, NULL))
550 show_ref (p->ref);
551 fputc ('[', dumpfile);
552 show_actual_arglist (p->value.function.actual);
553 fputc (']', dumpfile);
555 else
557 fprintf (dumpfile, "%s", p->value.function.name);
558 if (gfc_is_proc_ptr_comp (p, NULL))
559 show_ref (p->ref);
560 fputc ('[', dumpfile);
561 fputc ('[', dumpfile);
562 show_actual_arglist (p->value.function.actual);
563 fputc (']', dumpfile);
564 fputc (']', dumpfile);
567 break;
569 case EXPR_COMPCALL:
570 show_compcall (p);
571 break;
573 default:
574 gfc_internal_error ("show_expr(): Don't know how to show expr");
578 /* Show symbol attributes. The flavor and intent are followed by
579 whatever single bit attributes are present. */
581 static void
582 show_attr (symbol_attribute *attr)
585 fprintf (dumpfile, "(%s %s %s %s %s",
586 gfc_code2string (flavors, attr->flavor),
587 gfc_intent_string (attr->intent),
588 gfc_code2string (access_types, attr->access),
589 gfc_code2string (procedures, attr->proc),
590 gfc_code2string (save_status, attr->save));
592 if (attr->allocatable)
593 fputs (" ALLOCATABLE", dumpfile);
594 if (attr->asynchronous)
595 fputs (" ASYNCHRONOUS", dumpfile);
596 if (attr->codimension)
597 fputs (" CODIMENSION", dumpfile);
598 if (attr->dimension)
599 fputs (" DIMENSION", dumpfile);
600 if (attr->external)
601 fputs (" EXTERNAL", dumpfile);
602 if (attr->intrinsic)
603 fputs (" INTRINSIC", dumpfile);
604 if (attr->optional)
605 fputs (" OPTIONAL", dumpfile);
606 if (attr->pointer)
607 fputs (" POINTER", dumpfile);
608 if (attr->is_protected)
609 fputs (" PROTECTED", dumpfile);
610 if (attr->value)
611 fputs (" VALUE", dumpfile);
612 if (attr->volatile_)
613 fputs (" VOLATILE", dumpfile);
614 if (attr->threadprivate)
615 fputs (" THREADPRIVATE", dumpfile);
616 if (attr->target)
617 fputs (" TARGET", dumpfile);
618 if (attr->dummy)
619 fputs (" DUMMY", dumpfile);
620 if (attr->result)
621 fputs (" RESULT", dumpfile);
622 if (attr->entry)
623 fputs (" ENTRY", dumpfile);
624 if (attr->is_bind_c)
625 fputs (" BIND(C)", dumpfile);
627 if (attr->data)
628 fputs (" DATA", dumpfile);
629 if (attr->use_assoc)
630 fputs (" USE-ASSOC", dumpfile);
631 if (attr->in_namelist)
632 fputs (" IN-NAMELIST", dumpfile);
633 if (attr->in_common)
634 fputs (" IN-COMMON", dumpfile);
636 if (attr->abstract)
637 fputs (" ABSTRACT", dumpfile);
638 if (attr->function)
639 fputs (" FUNCTION", dumpfile);
640 if (attr->subroutine)
641 fputs (" SUBROUTINE", dumpfile);
642 if (attr->implicit_type)
643 fputs (" IMPLICIT-TYPE", dumpfile);
645 if (attr->sequence)
646 fputs (" SEQUENCE", dumpfile);
647 if (attr->elemental)
648 fputs (" ELEMENTAL", dumpfile);
649 if (attr->pure)
650 fputs (" PURE", dumpfile);
651 if (attr->recursive)
652 fputs (" RECURSIVE", dumpfile);
654 fputc (')', dumpfile);
658 /* Show components of a derived type. */
660 static void
661 show_components (gfc_symbol *sym)
663 gfc_component *c;
665 for (c = sym->components; c; c = c->next)
667 fprintf (dumpfile, "(%s ", c->name);
668 show_typespec (&c->ts);
669 if (c->attr.pointer)
670 fputs (" POINTER", dumpfile);
671 if (c->attr.proc_pointer)
672 fputs (" PPC", dumpfile);
673 if (c->attr.dimension)
674 fputs (" DIMENSION", dumpfile);
675 fputc (' ', dumpfile);
676 show_array_spec (c->as);
677 if (c->attr.access)
678 fprintf (dumpfile, " %s", gfc_code2string (access_types, c->attr.access));
679 fputc (')', dumpfile);
680 if (c->next != NULL)
681 fputc (' ', dumpfile);
686 /* Show the f2k_derived namespace with procedure bindings. */
688 static void
689 show_typebound_proc (gfc_typebound_proc* tb, const char* name)
691 show_indent ();
693 if (tb->is_generic)
694 fputs ("GENERIC", dumpfile);
695 else
697 fputs ("PROCEDURE, ", dumpfile);
698 if (tb->nopass)
699 fputs ("NOPASS", dumpfile);
700 else
702 if (tb->pass_arg)
703 fprintf (dumpfile, "PASS(%s)", tb->pass_arg);
704 else
705 fputs ("PASS", dumpfile);
707 if (tb->non_overridable)
708 fputs (", NON_OVERRIDABLE", dumpfile);
711 if (tb->access == ACCESS_PUBLIC)
712 fputs (", PUBLIC", dumpfile);
713 else
714 fputs (", PRIVATE", dumpfile);
716 fprintf (dumpfile, " :: %s => ", name);
718 if (tb->is_generic)
720 gfc_tbp_generic* g;
721 for (g = tb->u.generic; g; g = g->next)
723 fputs (g->specific_st->name, dumpfile);
724 if (g->next)
725 fputs (", ", dumpfile);
728 else
729 fputs (tb->u.specific->n.sym->name, dumpfile);
732 static void
733 show_typebound_symtree (gfc_symtree* st)
735 gcc_assert (st->n.tb);
736 show_typebound_proc (st->n.tb, st->name);
739 static void
740 show_f2k_derived (gfc_namespace* f2k)
742 gfc_finalizer* f;
743 int op;
745 show_indent ();
746 fputs ("Procedure bindings:", dumpfile);
747 ++show_level;
749 /* Finalizer bindings. */
750 for (f = f2k->finalizers; f; f = f->next)
752 show_indent ();
753 fprintf (dumpfile, "FINAL %s", f->proc_sym->name);
756 /* Type-bound procedures. */
757 gfc_traverse_symtree (f2k->tb_sym_root, &show_typebound_symtree);
759 --show_level;
761 show_indent ();
762 fputs ("Operator bindings:", dumpfile);
763 ++show_level;
765 /* User-defined operators. */
766 gfc_traverse_symtree (f2k->tb_uop_root, &show_typebound_symtree);
768 /* Intrinsic operators. */
769 for (op = GFC_INTRINSIC_BEGIN; op != GFC_INTRINSIC_END; ++op)
770 if (f2k->tb_op[op])
771 show_typebound_proc (f2k->tb_op[op],
772 gfc_op2string ((gfc_intrinsic_op) op));
774 --show_level;
778 /* Show a symbol. If a symbol is an ENTRY, SUBROUTINE or FUNCTION, we
779 show the interface. Information needed to reconstruct the list of
780 specific interfaces associated with a generic symbol is done within
781 that symbol. */
783 static void
784 show_symbol (gfc_symbol *sym)
786 gfc_formal_arglist *formal;
787 gfc_interface *intr;
789 if (sym == NULL)
790 return;
792 show_indent ();
794 fprintf (dumpfile, "symbol %s ", sym->name);
795 show_typespec (&sym->ts);
796 show_attr (&sym->attr);
798 if (sym->value)
800 show_indent ();
801 fputs ("value: ", dumpfile);
802 show_expr (sym->value);
805 if (sym->as)
807 show_indent ();
808 fputs ("Array spec:", dumpfile);
809 show_array_spec (sym->as);
812 if (sym->generic)
814 show_indent ();
815 fputs ("Generic interfaces:", dumpfile);
816 for (intr = sym->generic; intr; intr = intr->next)
817 fprintf (dumpfile, " %s", intr->sym->name);
820 if (sym->result)
822 show_indent ();
823 fprintf (dumpfile, "result: %s", sym->result->name);
826 if (sym->components)
828 show_indent ();
829 fputs ("components: ", dumpfile);
830 show_components (sym);
833 if (sym->f2k_derived)
835 show_indent ();
836 if (sym->hash_value)
837 fprintf (dumpfile, "hash: %d", sym->hash_value);
838 show_f2k_derived (sym->f2k_derived);
841 if (sym->formal)
843 show_indent ();
844 fputs ("Formal arglist:", dumpfile);
846 for (formal = sym->formal; formal; formal = formal->next)
848 if (formal->sym != NULL)
849 fprintf (dumpfile, " %s", formal->sym->name);
850 else
851 fputs (" [Alt Return]", dumpfile);
855 if (sym->formal_ns)
857 show_indent ();
858 fputs ("Formal namespace", dumpfile);
859 show_namespace (sym->formal_ns);
862 fputc ('\n', dumpfile);
866 /* Show a user-defined operator. Just prints an operator
867 and the name of the associated subroutine, really. */
869 static void
870 show_uop (gfc_user_op *uop)
872 gfc_interface *intr;
874 show_indent ();
875 fprintf (dumpfile, "%s:", uop->name);
877 for (intr = uop->op; intr; intr = intr->next)
878 fprintf (dumpfile, " %s", intr->sym->name);
882 /* Workhorse function for traversing the user operator symtree. */
884 static void
885 traverse_uop (gfc_symtree *st, void (*func) (gfc_user_op *))
887 if (st == NULL)
888 return;
890 (*func) (st->n.uop);
892 traverse_uop (st->left, func);
893 traverse_uop (st->right, func);
897 /* Traverse the tree of user operator nodes. */
899 void
900 gfc_traverse_user_op (gfc_namespace *ns, void (*func) (gfc_user_op *))
902 traverse_uop (ns->uop_root, func);
906 /* Function to display a common block. */
908 static void
909 show_common (gfc_symtree *st)
911 gfc_symbol *s;
913 show_indent ();
914 fprintf (dumpfile, "common: /%s/ ", st->name);
916 s = st->n.common->head;
917 while (s)
919 fprintf (dumpfile, "%s", s->name);
920 s = s->common_next;
921 if (s)
922 fputs (", ", dumpfile);
924 fputc ('\n', dumpfile);
928 /* Worker function to display the symbol tree. */
930 static void
931 show_symtree (gfc_symtree *st)
933 show_indent ();
934 fprintf (dumpfile, "symtree: %s Ambig %d", st->name, st->ambiguous);
936 if (st->n.sym->ns != gfc_current_ns)
937 fprintf (dumpfile, " from namespace %s", st->n.sym->ns->proc_name->name);
938 else
939 show_symbol (st->n.sym);
943 /******************* Show gfc_code structures **************/
946 /* Show a list of code structures. Mutually recursive with
947 show_code_node(). */
949 static void
950 show_code (int level, gfc_code *c)
952 for (; c; c = c->next)
953 show_code_node (level, c);
956 static void
957 show_namelist (gfc_namelist *n)
959 for (; n->next; n = n->next)
960 fprintf (dumpfile, "%s,", n->sym->name);
961 fprintf (dumpfile, "%s", n->sym->name);
964 /* Show a single OpenMP directive node and everything underneath it
965 if necessary. */
967 static void
968 show_omp_node (int level, gfc_code *c)
970 gfc_omp_clauses *omp_clauses = NULL;
971 const char *name = NULL;
973 switch (c->op)
975 case EXEC_OMP_ATOMIC: name = "ATOMIC"; break;
976 case EXEC_OMP_BARRIER: name = "BARRIER"; break;
977 case EXEC_OMP_CRITICAL: name = "CRITICAL"; break;
978 case EXEC_OMP_FLUSH: name = "FLUSH"; break;
979 case EXEC_OMP_DO: name = "DO"; break;
980 case EXEC_OMP_MASTER: name = "MASTER"; break;
981 case EXEC_OMP_ORDERED: name = "ORDERED"; break;
982 case EXEC_OMP_PARALLEL: name = "PARALLEL"; break;
983 case EXEC_OMP_PARALLEL_DO: name = "PARALLEL DO"; break;
984 case EXEC_OMP_PARALLEL_SECTIONS: name = "PARALLEL SECTIONS"; break;
985 case EXEC_OMP_PARALLEL_WORKSHARE: name = "PARALLEL WORKSHARE"; break;
986 case EXEC_OMP_SECTIONS: name = "SECTIONS"; break;
987 case EXEC_OMP_SINGLE: name = "SINGLE"; break;
988 case EXEC_OMP_TASK: name = "TASK"; break;
989 case EXEC_OMP_TASKWAIT: name = "TASKWAIT"; break;
990 case EXEC_OMP_WORKSHARE: name = "WORKSHARE"; break;
991 default:
992 gcc_unreachable ();
994 fprintf (dumpfile, "!$OMP %s", name);
995 switch (c->op)
997 case EXEC_OMP_DO:
998 case EXEC_OMP_PARALLEL:
999 case EXEC_OMP_PARALLEL_DO:
1000 case EXEC_OMP_PARALLEL_SECTIONS:
1001 case EXEC_OMP_SECTIONS:
1002 case EXEC_OMP_SINGLE:
1003 case EXEC_OMP_WORKSHARE:
1004 case EXEC_OMP_PARALLEL_WORKSHARE:
1005 case EXEC_OMP_TASK:
1006 omp_clauses = c->ext.omp_clauses;
1007 break;
1008 case EXEC_OMP_CRITICAL:
1009 if (c->ext.omp_name)
1010 fprintf (dumpfile, " (%s)", c->ext.omp_name);
1011 break;
1012 case EXEC_OMP_FLUSH:
1013 if (c->ext.omp_namelist)
1015 fputs (" (", dumpfile);
1016 show_namelist (c->ext.omp_namelist);
1017 fputc (')', dumpfile);
1019 return;
1020 case EXEC_OMP_BARRIER:
1021 case EXEC_OMP_TASKWAIT:
1022 return;
1023 default:
1024 break;
1026 if (omp_clauses)
1028 int list_type;
1030 if (omp_clauses->if_expr)
1032 fputs (" IF(", dumpfile);
1033 show_expr (omp_clauses->if_expr);
1034 fputc (')', dumpfile);
1036 if (omp_clauses->num_threads)
1038 fputs (" NUM_THREADS(", dumpfile);
1039 show_expr (omp_clauses->num_threads);
1040 fputc (')', dumpfile);
1042 if (omp_clauses->sched_kind != OMP_SCHED_NONE)
1044 const char *type;
1045 switch (omp_clauses->sched_kind)
1047 case OMP_SCHED_STATIC: type = "STATIC"; break;
1048 case OMP_SCHED_DYNAMIC: type = "DYNAMIC"; break;
1049 case OMP_SCHED_GUIDED: type = "GUIDED"; break;
1050 case OMP_SCHED_RUNTIME: type = "RUNTIME"; break;
1051 case OMP_SCHED_AUTO: type = "AUTO"; break;
1052 default:
1053 gcc_unreachable ();
1055 fprintf (dumpfile, " SCHEDULE (%s", type);
1056 if (omp_clauses->chunk_size)
1058 fputc (',', dumpfile);
1059 show_expr (omp_clauses->chunk_size);
1061 fputc (')', dumpfile);
1063 if (omp_clauses->default_sharing != OMP_DEFAULT_UNKNOWN)
1065 const char *type;
1066 switch (omp_clauses->default_sharing)
1068 case OMP_DEFAULT_NONE: type = "NONE"; break;
1069 case OMP_DEFAULT_PRIVATE: type = "PRIVATE"; break;
1070 case OMP_DEFAULT_SHARED: type = "SHARED"; break;
1071 case OMP_DEFAULT_FIRSTPRIVATE: type = "FIRSTPRIVATE"; break;
1072 default:
1073 gcc_unreachable ();
1075 fprintf (dumpfile, " DEFAULT(%s)", type);
1077 if (omp_clauses->ordered)
1078 fputs (" ORDERED", dumpfile);
1079 if (omp_clauses->untied)
1080 fputs (" UNTIED", dumpfile);
1081 if (omp_clauses->collapse)
1082 fprintf (dumpfile, " COLLAPSE(%d)", omp_clauses->collapse);
1083 for (list_type = 0; list_type < OMP_LIST_NUM; list_type++)
1084 if (omp_clauses->lists[list_type] != NULL
1085 && list_type != OMP_LIST_COPYPRIVATE)
1087 const char *type;
1088 if (list_type >= OMP_LIST_REDUCTION_FIRST)
1090 switch (list_type)
1092 case OMP_LIST_PLUS: type = "+"; break;
1093 case OMP_LIST_MULT: type = "*"; break;
1094 case OMP_LIST_SUB: type = "-"; break;
1095 case OMP_LIST_AND: type = ".AND."; break;
1096 case OMP_LIST_OR: type = ".OR."; break;
1097 case OMP_LIST_EQV: type = ".EQV."; break;
1098 case OMP_LIST_NEQV: type = ".NEQV."; break;
1099 case OMP_LIST_MAX: type = "MAX"; break;
1100 case OMP_LIST_MIN: type = "MIN"; break;
1101 case OMP_LIST_IAND: type = "IAND"; break;
1102 case OMP_LIST_IOR: type = "IOR"; break;
1103 case OMP_LIST_IEOR: type = "IEOR"; break;
1104 default:
1105 gcc_unreachable ();
1107 fprintf (dumpfile, " REDUCTION(%s:", type);
1109 else
1111 switch (list_type)
1113 case OMP_LIST_PRIVATE: type = "PRIVATE"; break;
1114 case OMP_LIST_FIRSTPRIVATE: type = "FIRSTPRIVATE"; break;
1115 case OMP_LIST_LASTPRIVATE: type = "LASTPRIVATE"; break;
1116 case OMP_LIST_SHARED: type = "SHARED"; break;
1117 case OMP_LIST_COPYIN: type = "COPYIN"; break;
1118 default:
1119 gcc_unreachable ();
1121 fprintf (dumpfile, " %s(", type);
1123 show_namelist (omp_clauses->lists[list_type]);
1124 fputc (')', dumpfile);
1127 fputc ('\n', dumpfile);
1128 if (c->op == EXEC_OMP_SECTIONS || c->op == EXEC_OMP_PARALLEL_SECTIONS)
1130 gfc_code *d = c->block;
1131 while (d != NULL)
1133 show_code (level + 1, d->next);
1134 if (d->block == NULL)
1135 break;
1136 code_indent (level, 0);
1137 fputs ("!$OMP SECTION\n", dumpfile);
1138 d = d->block;
1141 else
1142 show_code (level + 1, c->block->next);
1143 if (c->op == EXEC_OMP_ATOMIC)
1144 return;
1145 code_indent (level, 0);
1146 fprintf (dumpfile, "!$OMP END %s", name);
1147 if (omp_clauses != NULL)
1149 if (omp_clauses->lists[OMP_LIST_COPYPRIVATE])
1151 fputs (" COPYPRIVATE(", dumpfile);
1152 show_namelist (omp_clauses->lists[OMP_LIST_COPYPRIVATE]);
1153 fputc (')', dumpfile);
1155 else if (omp_clauses->nowait)
1156 fputs (" NOWAIT", dumpfile);
1158 else if (c->op == EXEC_OMP_CRITICAL && c->ext.omp_name)
1159 fprintf (dumpfile, " (%s)", c->ext.omp_name);
1163 /* Show a single code node and everything underneath it if necessary. */
1165 static void
1166 show_code_node (int level, gfc_code *c)
1168 gfc_forall_iterator *fa;
1169 gfc_open *open;
1170 gfc_case *cp;
1171 gfc_alloc *a;
1172 gfc_code *d;
1173 gfc_close *close;
1174 gfc_filepos *fp;
1175 gfc_inquire *i;
1176 gfc_dt *dt;
1178 code_indent (level, c->here);
1180 switch (c->op)
1182 case EXEC_END_PROCEDURE:
1183 break;
1185 case EXEC_NOP:
1186 fputs ("NOP", dumpfile);
1187 break;
1189 case EXEC_CONTINUE:
1190 fputs ("CONTINUE", dumpfile);
1191 break;
1193 case EXEC_ENTRY:
1194 fprintf (dumpfile, "ENTRY %s", c->ext.entry->sym->name);
1195 break;
1197 case EXEC_INIT_ASSIGN:
1198 case EXEC_ASSIGN:
1199 fputs ("ASSIGN ", dumpfile);
1200 show_expr (c->expr1);
1201 fputc (' ', dumpfile);
1202 show_expr (c->expr2);
1203 break;
1205 case EXEC_LABEL_ASSIGN:
1206 fputs ("LABEL ASSIGN ", dumpfile);
1207 show_expr (c->expr1);
1208 fprintf (dumpfile, " %d", c->label1->value);
1209 break;
1211 case EXEC_POINTER_ASSIGN:
1212 fputs ("POINTER ASSIGN ", dumpfile);
1213 show_expr (c->expr1);
1214 fputc (' ', dumpfile);
1215 show_expr (c->expr2);
1216 break;
1218 case EXEC_GOTO:
1219 fputs ("GOTO ", dumpfile);
1220 if (c->label1)
1221 fprintf (dumpfile, "%d", c->label1->value);
1222 else
1224 show_expr (c->expr1);
1225 d = c->block;
1226 if (d != NULL)
1228 fputs (", (", dumpfile);
1229 for (; d; d = d ->block)
1231 code_indent (level, d->label1);
1232 if (d->block != NULL)
1233 fputc (',', dumpfile);
1234 else
1235 fputc (')', dumpfile);
1239 break;
1241 case EXEC_CALL:
1242 case EXEC_ASSIGN_CALL:
1243 if (c->resolved_sym)
1244 fprintf (dumpfile, "CALL %s ", c->resolved_sym->name);
1245 else if (c->symtree)
1246 fprintf (dumpfile, "CALL %s ", c->symtree->name);
1247 else
1248 fputs ("CALL ?? ", dumpfile);
1250 show_actual_arglist (c->ext.actual);
1251 break;
1253 case EXEC_COMPCALL:
1254 fputs ("CALL ", dumpfile);
1255 show_compcall (c->expr1);
1256 break;
1258 case EXEC_CALL_PPC:
1259 fputs ("CALL ", dumpfile);
1260 show_expr (c->expr1);
1261 show_actual_arglist (c->ext.actual);
1262 break;
1264 case EXEC_RETURN:
1265 fputs ("RETURN ", dumpfile);
1266 if (c->expr1)
1267 show_expr (c->expr1);
1268 break;
1270 case EXEC_PAUSE:
1271 fputs ("PAUSE ", dumpfile);
1273 if (c->expr1 != NULL)
1274 show_expr (c->expr1);
1275 else
1276 fprintf (dumpfile, "%d", c->ext.stop_code);
1278 break;
1280 case EXEC_ERROR_STOP:
1281 fputs ("ERROR ", dumpfile);
1282 /* Fall through. */
1284 case EXEC_STOP:
1285 fputs ("STOP ", dumpfile);
1287 if (c->expr1 != NULL)
1288 show_expr (c->expr1);
1289 else
1290 fprintf (dumpfile, "%d", c->ext.stop_code);
1292 break;
1294 case EXEC_SYNC_ALL:
1295 fputs ("SYNC ALL ", dumpfile);
1296 if (c->expr2 != NULL)
1298 fputs (" stat=", dumpfile);
1299 show_expr (c->expr2);
1301 if (c->expr3 != NULL)
1303 fputs (" errmsg=", dumpfile);
1304 show_expr (c->expr3);
1306 break;
1308 case EXEC_SYNC_MEMORY:
1309 fputs ("SYNC MEMORY ", dumpfile);
1310 if (c->expr2 != NULL)
1312 fputs (" stat=", dumpfile);
1313 show_expr (c->expr2);
1315 if (c->expr3 != NULL)
1317 fputs (" errmsg=", dumpfile);
1318 show_expr (c->expr3);
1320 break;
1322 case EXEC_SYNC_IMAGES:
1323 fputs ("SYNC IMAGES image-set=", dumpfile);
1324 if (c->expr1 != NULL)
1325 show_expr (c->expr1);
1326 else
1327 fputs ("* ", dumpfile);
1328 if (c->expr2 != NULL)
1330 fputs (" stat=", dumpfile);
1331 show_expr (c->expr2);
1333 if (c->expr3 != NULL)
1335 fputs (" errmsg=", dumpfile);
1336 show_expr (c->expr3);
1338 break;
1340 case EXEC_ARITHMETIC_IF:
1341 fputs ("IF ", dumpfile);
1342 show_expr (c->expr1);
1343 fprintf (dumpfile, " %d, %d, %d",
1344 c->label1->value, c->label2->value, c->label3->value);
1345 break;
1347 case EXEC_IF:
1348 d = c->block;
1349 fputs ("IF ", dumpfile);
1350 show_expr (d->expr1);
1351 fputc ('\n', dumpfile);
1352 show_code (level + 1, d->next);
1354 d = d->block;
1355 for (; d; d = d->block)
1357 code_indent (level, 0);
1359 if (d->expr1 == NULL)
1360 fputs ("ELSE\n", dumpfile);
1361 else
1363 fputs ("ELSE IF ", dumpfile);
1364 show_expr (d->expr1);
1365 fputc ('\n', dumpfile);
1368 show_code (level + 1, d->next);
1371 code_indent (level, c->label1);
1373 fputs ("ENDIF", dumpfile);
1374 break;
1376 case EXEC_SELECT:
1377 d = c->block;
1378 fputs ("SELECT CASE ", dumpfile);
1379 show_expr (c->expr1);
1380 fputc ('\n', dumpfile);
1382 for (; d; d = d->block)
1384 code_indent (level, 0);
1386 fputs ("CASE ", dumpfile);
1387 for (cp = d->ext.case_list; cp; cp = cp->next)
1389 fputc ('(', dumpfile);
1390 show_expr (cp->low);
1391 fputc (' ', dumpfile);
1392 show_expr (cp->high);
1393 fputc (')', dumpfile);
1394 fputc (' ', dumpfile);
1396 fputc ('\n', dumpfile);
1398 show_code (level + 1, d->next);
1401 code_indent (level, c->label1);
1402 fputs ("END SELECT", dumpfile);
1403 break;
1405 case EXEC_WHERE:
1406 fputs ("WHERE ", dumpfile);
1408 d = c->block;
1409 show_expr (d->expr1);
1410 fputc ('\n', dumpfile);
1412 show_code (level + 1, d->next);
1414 for (d = d->block; d; d = d->block)
1416 code_indent (level, 0);
1417 fputs ("ELSE WHERE ", dumpfile);
1418 show_expr (d->expr1);
1419 fputc ('\n', dumpfile);
1420 show_code (level + 1, d->next);
1423 code_indent (level, 0);
1424 fputs ("END WHERE", dumpfile);
1425 break;
1428 case EXEC_FORALL:
1429 fputs ("FORALL ", dumpfile);
1430 for (fa = c->ext.forall_iterator; fa; fa = fa->next)
1432 show_expr (fa->var);
1433 fputc (' ', dumpfile);
1434 show_expr (fa->start);
1435 fputc (':', dumpfile);
1436 show_expr (fa->end);
1437 fputc (':', dumpfile);
1438 show_expr (fa->stride);
1440 if (fa->next != NULL)
1441 fputc (',', dumpfile);
1444 if (c->expr1 != NULL)
1446 fputc (',', dumpfile);
1447 show_expr (c->expr1);
1449 fputc ('\n', dumpfile);
1451 show_code (level + 1, c->block->next);
1453 code_indent (level, 0);
1454 fputs ("END FORALL", dumpfile);
1455 break;
1457 case EXEC_CRITICAL:
1458 fputs ("CRITICAL\n", dumpfile);
1459 show_code (level + 1, c->block->next);
1460 code_indent (level, 0);
1461 fputs ("END CRITICAL", dumpfile);
1462 break;
1464 case EXEC_DO:
1465 fputs ("DO ", dumpfile);
1467 show_expr (c->ext.iterator->var);
1468 fputc ('=', dumpfile);
1469 show_expr (c->ext.iterator->start);
1470 fputc (' ', dumpfile);
1471 show_expr (c->ext.iterator->end);
1472 fputc (' ', dumpfile);
1473 show_expr (c->ext.iterator->step);
1474 fputc ('\n', dumpfile);
1476 show_code (level + 1, c->block->next);
1478 code_indent (level, 0);
1479 fputs ("END DO", dumpfile);
1480 break;
1482 case EXEC_DO_WHILE:
1483 fputs ("DO WHILE ", dumpfile);
1484 show_expr (c->expr1);
1485 fputc ('\n', dumpfile);
1487 show_code (level + 1, c->block->next);
1489 code_indent (level, c->label1);
1490 fputs ("END DO", dumpfile);
1491 break;
1493 case EXEC_CYCLE:
1494 fputs ("CYCLE", dumpfile);
1495 if (c->symtree)
1496 fprintf (dumpfile, " %s", c->symtree->n.sym->name);
1497 break;
1499 case EXEC_EXIT:
1500 fputs ("EXIT", dumpfile);
1501 if (c->symtree)
1502 fprintf (dumpfile, " %s", c->symtree->n.sym->name);
1503 break;
1505 case EXEC_ALLOCATE:
1506 fputs ("ALLOCATE ", dumpfile);
1507 if (c->expr1)
1509 fputs (" STAT=", dumpfile);
1510 show_expr (c->expr1);
1513 if (c->expr2)
1515 fputs (" ERRMSG=", dumpfile);
1516 show_expr (c->expr2);
1519 for (a = c->ext.alloc.list; a; a = a->next)
1521 fputc (' ', dumpfile);
1522 show_expr (a->expr);
1525 break;
1527 case EXEC_DEALLOCATE:
1528 fputs ("DEALLOCATE ", dumpfile);
1529 if (c->expr1)
1531 fputs (" STAT=", dumpfile);
1532 show_expr (c->expr1);
1535 if (c->expr2)
1537 fputs (" ERRMSG=", dumpfile);
1538 show_expr (c->expr2);
1541 for (a = c->ext.alloc.list; a; a = a->next)
1543 fputc (' ', dumpfile);
1544 show_expr (a->expr);
1547 break;
1549 case EXEC_OPEN:
1550 fputs ("OPEN", dumpfile);
1551 open = c->ext.open;
1553 if (open->unit)
1555 fputs (" UNIT=", dumpfile);
1556 show_expr (open->unit);
1558 if (open->iomsg)
1560 fputs (" IOMSG=", dumpfile);
1561 show_expr (open->iomsg);
1563 if (open->iostat)
1565 fputs (" IOSTAT=", dumpfile);
1566 show_expr (open->iostat);
1568 if (open->file)
1570 fputs (" FILE=", dumpfile);
1571 show_expr (open->file);
1573 if (open->status)
1575 fputs (" STATUS=", dumpfile);
1576 show_expr (open->status);
1578 if (open->access)
1580 fputs (" ACCESS=", dumpfile);
1581 show_expr (open->access);
1583 if (open->form)
1585 fputs (" FORM=", dumpfile);
1586 show_expr (open->form);
1588 if (open->recl)
1590 fputs (" RECL=", dumpfile);
1591 show_expr (open->recl);
1593 if (open->blank)
1595 fputs (" BLANK=", dumpfile);
1596 show_expr (open->blank);
1598 if (open->position)
1600 fputs (" POSITION=", dumpfile);
1601 show_expr (open->position);
1603 if (open->action)
1605 fputs (" ACTION=", dumpfile);
1606 show_expr (open->action);
1608 if (open->delim)
1610 fputs (" DELIM=", dumpfile);
1611 show_expr (open->delim);
1613 if (open->pad)
1615 fputs (" PAD=", dumpfile);
1616 show_expr (open->pad);
1618 if (open->decimal)
1620 fputs (" DECIMAL=", dumpfile);
1621 show_expr (open->decimal);
1623 if (open->encoding)
1625 fputs (" ENCODING=", dumpfile);
1626 show_expr (open->encoding);
1628 if (open->round)
1630 fputs (" ROUND=", dumpfile);
1631 show_expr (open->round);
1633 if (open->sign)
1635 fputs (" SIGN=", dumpfile);
1636 show_expr (open->sign);
1638 if (open->convert)
1640 fputs (" CONVERT=", dumpfile);
1641 show_expr (open->convert);
1643 if (open->asynchronous)
1645 fputs (" ASYNCHRONOUS=", dumpfile);
1646 show_expr (open->asynchronous);
1648 if (open->err != NULL)
1649 fprintf (dumpfile, " ERR=%d", open->err->value);
1651 break;
1653 case EXEC_CLOSE:
1654 fputs ("CLOSE", dumpfile);
1655 close = c->ext.close;
1657 if (close->unit)
1659 fputs (" UNIT=", dumpfile);
1660 show_expr (close->unit);
1662 if (close->iomsg)
1664 fputs (" IOMSG=", dumpfile);
1665 show_expr (close->iomsg);
1667 if (close->iostat)
1669 fputs (" IOSTAT=", dumpfile);
1670 show_expr (close->iostat);
1672 if (close->status)
1674 fputs (" STATUS=", dumpfile);
1675 show_expr (close->status);
1677 if (close->err != NULL)
1678 fprintf (dumpfile, " ERR=%d", close->err->value);
1679 break;
1681 case EXEC_BACKSPACE:
1682 fputs ("BACKSPACE", dumpfile);
1683 goto show_filepos;
1685 case EXEC_ENDFILE:
1686 fputs ("ENDFILE", dumpfile);
1687 goto show_filepos;
1689 case EXEC_REWIND:
1690 fputs ("REWIND", dumpfile);
1691 goto show_filepos;
1693 case EXEC_FLUSH:
1694 fputs ("FLUSH", dumpfile);
1696 show_filepos:
1697 fp = c->ext.filepos;
1699 if (fp->unit)
1701 fputs (" UNIT=", dumpfile);
1702 show_expr (fp->unit);
1704 if (fp->iomsg)
1706 fputs (" IOMSG=", dumpfile);
1707 show_expr (fp->iomsg);
1709 if (fp->iostat)
1711 fputs (" IOSTAT=", dumpfile);
1712 show_expr (fp->iostat);
1714 if (fp->err != NULL)
1715 fprintf (dumpfile, " ERR=%d", fp->err->value);
1716 break;
1718 case EXEC_INQUIRE:
1719 fputs ("INQUIRE", dumpfile);
1720 i = c->ext.inquire;
1722 if (i->unit)
1724 fputs (" UNIT=", dumpfile);
1725 show_expr (i->unit);
1727 if (i->file)
1729 fputs (" FILE=", dumpfile);
1730 show_expr (i->file);
1733 if (i->iomsg)
1735 fputs (" IOMSG=", dumpfile);
1736 show_expr (i->iomsg);
1738 if (i->iostat)
1740 fputs (" IOSTAT=", dumpfile);
1741 show_expr (i->iostat);
1743 if (i->exist)
1745 fputs (" EXIST=", dumpfile);
1746 show_expr (i->exist);
1748 if (i->opened)
1750 fputs (" OPENED=", dumpfile);
1751 show_expr (i->opened);
1753 if (i->number)
1755 fputs (" NUMBER=", dumpfile);
1756 show_expr (i->number);
1758 if (i->named)
1760 fputs (" NAMED=", dumpfile);
1761 show_expr (i->named);
1763 if (i->name)
1765 fputs (" NAME=", dumpfile);
1766 show_expr (i->name);
1768 if (i->access)
1770 fputs (" ACCESS=", dumpfile);
1771 show_expr (i->access);
1773 if (i->sequential)
1775 fputs (" SEQUENTIAL=", dumpfile);
1776 show_expr (i->sequential);
1779 if (i->direct)
1781 fputs (" DIRECT=", dumpfile);
1782 show_expr (i->direct);
1784 if (i->form)
1786 fputs (" FORM=", dumpfile);
1787 show_expr (i->form);
1789 if (i->formatted)
1791 fputs (" FORMATTED", dumpfile);
1792 show_expr (i->formatted);
1794 if (i->unformatted)
1796 fputs (" UNFORMATTED=", dumpfile);
1797 show_expr (i->unformatted);
1799 if (i->recl)
1801 fputs (" RECL=", dumpfile);
1802 show_expr (i->recl);
1804 if (i->nextrec)
1806 fputs (" NEXTREC=", dumpfile);
1807 show_expr (i->nextrec);
1809 if (i->blank)
1811 fputs (" BLANK=", dumpfile);
1812 show_expr (i->blank);
1814 if (i->position)
1816 fputs (" POSITION=", dumpfile);
1817 show_expr (i->position);
1819 if (i->action)
1821 fputs (" ACTION=", dumpfile);
1822 show_expr (i->action);
1824 if (i->read)
1826 fputs (" READ=", dumpfile);
1827 show_expr (i->read);
1829 if (i->write)
1831 fputs (" WRITE=", dumpfile);
1832 show_expr (i->write);
1834 if (i->readwrite)
1836 fputs (" READWRITE=", dumpfile);
1837 show_expr (i->readwrite);
1839 if (i->delim)
1841 fputs (" DELIM=", dumpfile);
1842 show_expr (i->delim);
1844 if (i->pad)
1846 fputs (" PAD=", dumpfile);
1847 show_expr (i->pad);
1849 if (i->convert)
1851 fputs (" CONVERT=", dumpfile);
1852 show_expr (i->convert);
1854 if (i->asynchronous)
1856 fputs (" ASYNCHRONOUS=", dumpfile);
1857 show_expr (i->asynchronous);
1859 if (i->decimal)
1861 fputs (" DECIMAL=", dumpfile);
1862 show_expr (i->decimal);
1864 if (i->encoding)
1866 fputs (" ENCODING=", dumpfile);
1867 show_expr (i->encoding);
1869 if (i->pending)
1871 fputs (" PENDING=", dumpfile);
1872 show_expr (i->pending);
1874 if (i->round)
1876 fputs (" ROUND=", dumpfile);
1877 show_expr (i->round);
1879 if (i->sign)
1881 fputs (" SIGN=", dumpfile);
1882 show_expr (i->sign);
1884 if (i->size)
1886 fputs (" SIZE=", dumpfile);
1887 show_expr (i->size);
1889 if (i->id)
1891 fputs (" ID=", dumpfile);
1892 show_expr (i->id);
1895 if (i->err != NULL)
1896 fprintf (dumpfile, " ERR=%d", i->err->value);
1897 break;
1899 case EXEC_IOLENGTH:
1900 fputs ("IOLENGTH ", dumpfile);
1901 show_expr (c->expr1);
1902 goto show_dt_code;
1903 break;
1905 case EXEC_READ:
1906 fputs ("READ", dumpfile);
1907 goto show_dt;
1909 case EXEC_WRITE:
1910 fputs ("WRITE", dumpfile);
1912 show_dt:
1913 dt = c->ext.dt;
1914 if (dt->io_unit)
1916 fputs (" UNIT=", dumpfile);
1917 show_expr (dt->io_unit);
1920 if (dt->format_expr)
1922 fputs (" FMT=", dumpfile);
1923 show_expr (dt->format_expr);
1926 if (dt->format_label != NULL)
1927 fprintf (dumpfile, " FMT=%d", dt->format_label->value);
1928 if (dt->namelist)
1929 fprintf (dumpfile, " NML=%s", dt->namelist->name);
1931 if (dt->iomsg)
1933 fputs (" IOMSG=", dumpfile);
1934 show_expr (dt->iomsg);
1936 if (dt->iostat)
1938 fputs (" IOSTAT=", dumpfile);
1939 show_expr (dt->iostat);
1941 if (dt->size)
1943 fputs (" SIZE=", dumpfile);
1944 show_expr (dt->size);
1946 if (dt->rec)
1948 fputs (" REC=", dumpfile);
1949 show_expr (dt->rec);
1951 if (dt->advance)
1953 fputs (" ADVANCE=", dumpfile);
1954 show_expr (dt->advance);
1956 if (dt->id)
1958 fputs (" ID=", dumpfile);
1959 show_expr (dt->id);
1961 if (dt->pos)
1963 fputs (" POS=", dumpfile);
1964 show_expr (dt->pos);
1966 if (dt->asynchronous)
1968 fputs (" ASYNCHRONOUS=", dumpfile);
1969 show_expr (dt->asynchronous);
1971 if (dt->blank)
1973 fputs (" BLANK=", dumpfile);
1974 show_expr (dt->blank);
1976 if (dt->decimal)
1978 fputs (" DECIMAL=", dumpfile);
1979 show_expr (dt->decimal);
1981 if (dt->delim)
1983 fputs (" DELIM=", dumpfile);
1984 show_expr (dt->delim);
1986 if (dt->pad)
1988 fputs (" PAD=", dumpfile);
1989 show_expr (dt->pad);
1991 if (dt->round)
1993 fputs (" ROUND=", dumpfile);
1994 show_expr (dt->round);
1996 if (dt->sign)
1998 fputs (" SIGN=", dumpfile);
1999 show_expr (dt->sign);
2002 show_dt_code:
2003 fputc ('\n', dumpfile);
2004 for (c = c->block->next; c; c = c->next)
2005 show_code_node (level + (c->next != NULL), c);
2006 return;
2008 case EXEC_TRANSFER:
2009 fputs ("TRANSFER ", dumpfile);
2010 show_expr (c->expr1);
2011 break;
2013 case EXEC_DT_END:
2014 fputs ("DT_END", dumpfile);
2015 dt = c->ext.dt;
2017 if (dt->err != NULL)
2018 fprintf (dumpfile, " ERR=%d", dt->err->value);
2019 if (dt->end != NULL)
2020 fprintf (dumpfile, " END=%d", dt->end->value);
2021 if (dt->eor != NULL)
2022 fprintf (dumpfile, " EOR=%d", dt->eor->value);
2023 break;
2025 case EXEC_OMP_ATOMIC:
2026 case EXEC_OMP_BARRIER:
2027 case EXEC_OMP_CRITICAL:
2028 case EXEC_OMP_FLUSH:
2029 case EXEC_OMP_DO:
2030 case EXEC_OMP_MASTER:
2031 case EXEC_OMP_ORDERED:
2032 case EXEC_OMP_PARALLEL:
2033 case EXEC_OMP_PARALLEL_DO:
2034 case EXEC_OMP_PARALLEL_SECTIONS:
2035 case EXEC_OMP_PARALLEL_WORKSHARE:
2036 case EXEC_OMP_SECTIONS:
2037 case EXEC_OMP_SINGLE:
2038 case EXEC_OMP_TASK:
2039 case EXEC_OMP_TASKWAIT:
2040 case EXEC_OMP_WORKSHARE:
2041 show_omp_node (level, c);
2042 break;
2044 default:
2045 gfc_internal_error ("show_code_node(): Bad statement code");
2048 fputc ('\n', dumpfile);
2052 /* Show an equivalence chain. */
2054 static void
2055 show_equiv (gfc_equiv *eq)
2057 show_indent ();
2058 fputs ("Equivalence: ", dumpfile);
2059 while (eq)
2061 show_expr (eq->expr);
2062 eq = eq->eq;
2063 if (eq)
2064 fputs (", ", dumpfile);
2069 /* Show a freakin' whole namespace. */
2071 static void
2072 show_namespace (gfc_namespace *ns)
2074 gfc_interface *intr;
2075 gfc_namespace *save;
2076 int op;
2077 gfc_equiv *eq;
2078 int i;
2080 save = gfc_current_ns;
2081 show_level++;
2083 show_indent ();
2084 fputs ("Namespace:", dumpfile);
2086 if (ns != NULL)
2088 i = 0;
2091 int l = i;
2092 while (i < GFC_LETTERS - 1
2093 && gfc_compare_types(&ns->default_type[i+1],
2094 &ns->default_type[l]))
2095 i++;
2097 if (i > l)
2098 fprintf (dumpfile, " %c-%c: ", l+'A', i+'A');
2099 else
2100 fprintf (dumpfile, " %c: ", l+'A');
2102 show_typespec(&ns->default_type[l]);
2103 i++;
2104 } while (i < GFC_LETTERS);
2106 if (ns->proc_name != NULL)
2108 show_indent ();
2109 fprintf (dumpfile, "procedure name = %s", ns->proc_name->name);
2112 gfc_current_ns = ns;
2113 gfc_traverse_symtree (ns->common_root, show_common);
2115 gfc_traverse_symtree (ns->sym_root, show_symtree);
2117 for (op = GFC_INTRINSIC_BEGIN; op != GFC_INTRINSIC_END; op++)
2119 /* User operator interfaces */
2120 intr = ns->op[op];
2121 if (intr == NULL)
2122 continue;
2124 show_indent ();
2125 fprintf (dumpfile, "Operator interfaces for %s:",
2126 gfc_op2string ((gfc_intrinsic_op) op));
2128 for (; intr; intr = intr->next)
2129 fprintf (dumpfile, " %s", intr->sym->name);
2132 if (ns->uop_root != NULL)
2134 show_indent ();
2135 fputs ("User operators:\n", dumpfile);
2136 gfc_traverse_user_op (ns, show_uop);
2140 for (eq = ns->equiv; eq; eq = eq->next)
2141 show_equiv (eq);
2143 fputc ('\n', dumpfile);
2144 fputc ('\n', dumpfile);
2146 show_code (0, ns->code);
2148 for (ns = ns->contained; ns; ns = ns->sibling)
2150 show_indent ();
2151 fputs ("CONTAINS\n", dumpfile);
2152 show_namespace (ns);
2155 show_level--;
2156 fputc ('\n', dumpfile);
2157 gfc_current_ns = save;
2161 /* Main function for dumping a parse tree. */
2163 void
2164 gfc_dump_parse_tree (gfc_namespace *ns, FILE *file)
2166 dumpfile = file;
2167 show_namespace (ns);