dump-parse-tree.c 56.5 KB
Newer Older
1
/* Parse tree dumper
Jakub Jelinek committed
2
   Copyright (C) 2003-2015 Free Software Foundation, Inc.
3 4
   Contributed by Steven Bosscher

5
This file is part of GCC.
6

7 8
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
9
Software Foundation; either version 3, or (at your option) any later
10
version.
11

12 13 14 15
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.
16 17

You should have received a copy of the GNU General Public License
18 19
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.  */
20 21 22 23 24 25 26 27 28 29 30 31 32 33


/* Actually this is just a collection of routines that used to be
   scattered around the sources.  Now that they are all in a single
   file, almost all of them can be static, and the other files don't
   have this mess in them.

   As a nice side-effect, this file can act as documentation of the
   gfc_code and gfc_expr structures and all their friends and
   relatives.

   TODO: Dump DATA.  */

#include "config.h"
34
#include "system.h"
35
#include "coretypes.h"
36
#include "gfortran.h"
Jerry DeLisle committed
37
#include "constructor.h"
38 39 40 41

/* Keep track of indentation for symbol tree dumps.  */
static int show_level = 0;

42 43 44 45 46 47 48 49 50 51
/* The file handle we're dumping to is kept in a static variable.  This
   is not too cool, but it avoids a lot of passing it around.  */
static FILE *dumpfile;

/* Forward declaration of some of the functions.  */
static void show_expr (gfc_expr *p);
static void show_code_node (int, gfc_code *);
static void show_namespace (gfc_namespace *ns);


52 53 54 55 56 57 58
/* Allow dumping of an expression in the debugger.  */
void gfc_debug_expr (gfc_expr *);

void
gfc_debug_expr (gfc_expr *e)
{
  FILE *tmp = dumpfile;
59
  dumpfile = stderr;
60 61 62 63 64 65
  show_expr (e);
  fputc ('\n', dumpfile);
  dumpfile = tmp;
}


66 67 68
/* Do indentation for a specific level.  */

static inline void
69
code_indent (int level, gfc_st_label *label)
70 71 72 73
{
  int i;

  if (label != NULL)
74
    fprintf (dumpfile, "%-5d ", label->value);
75

76
  for (i = 0; i < (2 * level - (label ? 6 : 0)); i++)
77
    fputc (' ', dumpfile);
78 79 80 81 82
}


/* Simple indentation at the current level.  This one
   is used to show symbols.  */
83

84 85 86
static inline void
show_indent (void)
{
87
  fputc ('\n', dumpfile);
88 89 90 91 92
  code_indent (show_level, NULL);
}


/* Show type-specific information.  */
93

94 95
static void
show_typespec (gfc_typespec *ts)
96
{
97 98 99 100 101 102
  if (ts->type == BT_ASSUMED)
    {
      fputs ("(TYPE(*))", dumpfile);
      return;
    }

103
  fprintf (dumpfile, "(%s ", gfc_basic_typename (ts->type));
104 105 106 107

  switch (ts->type)
    {
    case BT_DERIVED:
108
    case BT_CLASS:
109
      fprintf (dumpfile, "%s", ts->u.derived->name);
110 111 112
      break;

    case BT_CHARACTER:
113 114
      if (ts->u.cl)
	show_expr (ts->u.cl->length);
115
      fprintf(dumpfile, " %d", ts->kind);
116 117 118
      break;

    default:
119
      fprintf (dumpfile, "%d", ts->kind);
120 121 122
      break;
    }

123
  fputc (')', dumpfile);
124 125 126 127 128
}


/* Show an actual argument list.  */

129 130
static void
show_actual_arglist (gfc_actual_arglist *a)
131
{
132
  fputc ('(', dumpfile);
133 134 135

  for (; a; a = a->next)
    {
136
      fputc ('(', dumpfile);
137
      if (a->name != NULL)
138
	fprintf (dumpfile, "%s = ", a->name);
139
      if (a->expr != NULL)
140
	show_expr (a->expr);
141
      else
142
	fputs ("(arg not-present)", dumpfile);
143

144
      fputc (')', dumpfile);
145
      if (a->next != NULL)
146
	fputc (' ', dumpfile);
147 148
    }

149
  fputc (')', dumpfile);
150 151 152
}


153
/* Show a gfc_array_spec array specification structure.  */
154

155 156
static void
show_array_spec (gfc_array_spec *as)
157 158 159 160 161 162
{
  const char *c;
  int i;

  if (as == NULL)
    {
163
      fputs ("()", dumpfile);
164 165 166
      return;
    }

167
  fprintf (dumpfile, "(%d [%d]", as->rank, as->corank);
168

169
  if (as->rank + as->corank > 0 || as->rank == -1)
170 171 172 173 174 175 176
    {
      switch (as->type)
      {
	case AS_EXPLICIT:      c = "AS_EXPLICIT";      break;
	case AS_DEFERRED:      c = "AS_DEFERRED";      break;
	case AS_ASSUMED_SIZE:  c = "AS_ASSUMED_SIZE";  break;
	case AS_ASSUMED_SHAPE: c = "AS_ASSUMED_SHAPE"; break;
177
	case AS_ASSUMED_RANK:  c = "AS_ASSUMED_RANK";  break;
178
	default:
179
	  gfc_internal_error ("show_array_spec(): Unhandled array shape "
180
			      "type.");
181
      }
182
      fprintf (dumpfile, " %s ", c);
183

184
      for (i = 0; i < as->rank + as->corank; i++)
185
	{
186 187 188 189
	  show_expr (as->lower[i]);
	  fputc (' ', dumpfile);
	  show_expr (as->upper[i]);
	  fputc (' ', dumpfile);
190 191 192
	}
    }

193
  fputc (')', dumpfile);
194 195 196
}


197
/* Show a gfc_array_ref array reference structure.  */
198

199 200
static void
show_array_ref (gfc_array_ref * ar)
201 202 203
{
  int i;

204
  fputc ('(', dumpfile);
205 206 207 208

  switch (ar->type)
    {
    case AR_FULL:
209
      fputs ("FULL", dumpfile);
210 211 212 213 214
      break;

    case AR_SECTION:
      for (i = 0; i < ar->dimen; i++)
	{
215 216 217 218 219 220 221
	  /* There are two types of array sections: either the
	     elements are identified by an integer array ('vector'),
	     or by an index range. In the former case we only have to
	     print the start expression which contains the vector, in
	     the latter case we have to print any of lower and upper
	     bound and the stride, if they're present.  */
  
222
	  if (ar->start[i] != NULL)
223
	    show_expr (ar->start[i]);
224

225
	  if (ar->dimen_type[i] == DIMEN_RANGE)
226
	    {
227
	      fputc (':', dumpfile);
228 229

	      if (ar->end[i] != NULL)
230
		show_expr (ar->end[i]);
231 232 233

	      if (ar->stride[i] != NULL)
		{
234 235
		  fputc (':', dumpfile);
		  show_expr (ar->stride[i]);
236
		}
237 238 239
	    }

	  if (i != ar->dimen - 1)
240
	    fputs (" , ", dumpfile);
241 242 243 244 245 246
	}
      break;

    case AR_ELEMENT:
      for (i = 0; i < ar->dimen; i++)
	{
247
	  show_expr (ar->start[i]);
248
	  if (i != ar->dimen - 1)
249
	    fputs (" , ", dumpfile);
250 251 252 253
	}
      break;

    case AR_UNKNOWN:
254
      fputs ("UNKNOWN", dumpfile);
255 256 257
      break;

    default:
258
      gfc_internal_error ("show_array_ref(): Unknown array reference");
259 260
    }

261
  fputc (')', dumpfile);
262 263 264 265 266
}


/* Show a list of gfc_ref structures.  */

267 268
static void
show_ref (gfc_ref *p)
269 270 271 272 273
{
  for (; p; p = p->next)
    switch (p->type)
      {
      case REF_ARRAY:
274
	show_array_ref (&p->u.ar);
275 276 277
	break;

      case REF_COMPONENT:
278
	fprintf (dumpfile, " %% %s", p->u.c.component->name);
279 280 281
	break;

      case REF_SUBSTRING:
282 283 284 285 286
	fputc ('(', dumpfile);
	show_expr (p->u.ss.start);
	fputc (':', dumpfile);
	show_expr (p->u.ss.end);
	fputc (')', dumpfile);
287 288 289
	break;

      default:
290
	gfc_internal_error ("show_ref(): Bad component code");
291 292 293 294 295 296
      }
}


/* Display a constructor.  Works recursively for array constructors.  */

297
static void
Jerry DeLisle committed
298
show_constructor (gfc_constructor_base base)
299
{
Jerry DeLisle committed
300 301
  gfc_constructor *c;
  for (c = gfc_constructor_first (base); c; c = gfc_constructor_next (c))
302 303
    {
      if (c->iterator == NULL)
304
	show_expr (c->expr);
305 306
      else
	{
307 308
	  fputc ('(', dumpfile);
	  show_expr (c->expr);
309

310 311 312 313 314 315 316 317
	  fputc (' ', dumpfile);
	  show_expr (c->iterator->var);
	  fputc ('=', dumpfile);
	  show_expr (c->iterator->start);
	  fputc (',', dumpfile);
	  show_expr (c->iterator->end);
	  fputc (',', dumpfile);
	  show_expr (c->iterator->step);
318

319
	  fputc (')', dumpfile);
320 321
	}

Jerry DeLisle committed
322
      if (gfc_constructor_next (c) != NULL)
323
	fputs (" , ", dumpfile);
324 325 326 327
    }
}


328
static void
329
show_char_const (const gfc_char_t *c, int length)
330 331 332
{
  int i;

333
  fputc ('\'', dumpfile);
334 335 336
  for (i = 0; i < length; i++)
    {
      if (c[i] == '\'')
337
	fputs ("''", dumpfile);
338
      else
339
	fputs (gfc_print_wide_char (c[i]), dumpfile);
340
    }
341
  fputc ('\'', dumpfile);
342 343
}

344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359

/* Show a component-call expression.  */

static void
show_compcall (gfc_expr* p)
{
  gcc_assert (p->expr_type == EXPR_COMPCALL);

  fprintf (dumpfile, "%s", p->symtree->n.sym->name);
  show_ref (p->ref);
  fprintf (dumpfile, "%s", p->value.compcall.name);

  show_actual_arglist (p->value.compcall.actual);
}


360 361
/* Show an expression.  */

362 363
static void
show_expr (gfc_expr *p)
364 365 366 367 368 369
{
  const char *c;
  int i;

  if (p == NULL)
    {
370
      fputs ("()", dumpfile);
371 372 373 374 375 376
      return;
    }

  switch (p->expr_type)
    {
    case EXPR_SUBSTRING:
377
      show_char_const (p->value.character.string, p->value.character.length);
378
      show_ref (p->ref);
379 380 381
      break;

    case EXPR_STRUCTURE:
382
      fprintf (dumpfile, "%s(", p->ts.u.derived->name);
383 384
      show_constructor (p->value.constructor);
      fputc (')', dumpfile);
385 386 387
      break;

    case EXPR_ARRAY:
388 389 390
      fputs ("(/ ", dumpfile);
      show_constructor (p->value.constructor);
      fputs (" /)", dumpfile);
391

392
      show_ref (p->ref);
393 394 395
      break;

    case EXPR_NULL:
396
      fputs ("NULL()", dumpfile);
397 398 399 400 401 402 403 404
      break;

    case EXPR_CONSTANT:
      switch (p->ts.type)
	{
	case BT_INTEGER:
	  mpz_out_str (stdout, 10, p->value.integer);

405
	  if (p->ts.kind != gfc_default_integer_kind)
406
	    fprintf (dumpfile, "_%d", p->ts.kind);
407 408 409 410
	  break;

	case BT_LOGICAL:
	  if (p->value.logical)
411
	    fputs (".true.", dumpfile);
412
	  else
413
	    fputs (".false.", dumpfile);
414 415 416
	  break;

	case BT_REAL:
417
	  mpfr_out_str (stdout, 10, 0, p->value.real, GFC_RND_MODE);
418
	  if (p->ts.kind != gfc_default_real_kind)
419
	    fprintf (dumpfile, "_%d", p->ts.kind);
420 421 422
	  break;

	case BT_CHARACTER:
423 424
	  show_char_const (p->value.character.string, 
			   p->value.character.length);
425 426 427
	  break;

	case BT_COMPLEX:
428
	  fputs ("(complex ", dumpfile);
429

430 431
	  mpfr_out_str (stdout, 10, 0, mpc_realref (p->value.complex),
			GFC_RND_MODE);
432
	  if (p->ts.kind != gfc_default_complex_kind)
433
	    fprintf (dumpfile, "_%d", p->ts.kind);
434

435
	  fputc (' ', dumpfile);
436

437 438
	  mpfr_out_str (stdout, 10, 0, mpc_imagref (p->value.complex),
			GFC_RND_MODE);
439
	  if (p->ts.kind != gfc_default_complex_kind)
440
	    fprintf (dumpfile, "_%d", p->ts.kind);
441

442
	  fputc (')', dumpfile);
443 444
	  break;

445
	case BT_HOLLERITH:
446
	  fprintf (dumpfile, "%dH", p->representation.length);
447 448 449
	  c = p->representation.string;
	  for (i = 0; i < p->representation.length; i++, c++)
	    {
450
	      fputc (*c, dumpfile);
451 452 453
	    }
	  break;

454
	default:
455
	  fputs ("???", dumpfile);
456 457 458
	  break;
	}

459 460
      if (p->representation.string)
	{
461
	  fputs (" {", dumpfile);
462 463 464
	  c = p->representation.string;
	  for (i = 0; i < p->representation.length; i++, c++)
	    {
465
	      fprintf (dumpfile, "%.2x", (unsigned int) *c);
466
	      if (i < p->representation.length - 1)
467
		fputc (',', dumpfile);
468
	    }
469
	  fputc ('}', dumpfile);
470 471
	}

472 473 474
      break;

    case EXPR_VARIABLE:
475
      if (p->symtree->n.sym->ns && p->symtree->n.sym->ns->proc_name)
476 477 478
	fprintf (dumpfile, "%s:", p->symtree->n.sym->ns->proc_name->name);
      fprintf (dumpfile, "%s", p->symtree->n.sym->name);
      show_ref (p->ref);
479 480 481
      break;

    case EXPR_OP:
482
      fputc ('(', dumpfile);
483
      switch (p->value.op.op)
484 485
	{
	case INTRINSIC_UPLUS:
486
	  fputs ("U+ ", dumpfile);
487 488
	  break;
	case INTRINSIC_UMINUS:
489
	  fputs ("U- ", dumpfile);
490 491
	  break;
	case INTRINSIC_PLUS:
492
	  fputs ("+ ", dumpfile);
493 494
	  break;
	case INTRINSIC_MINUS:
495
	  fputs ("- ", dumpfile);
496 497
	  break;
	case INTRINSIC_TIMES:
498
	  fputs ("* ", dumpfile);
499 500
	  break;
	case INTRINSIC_DIVIDE:
501
	  fputs ("/ ", dumpfile);
502 503
	  break;
	case INTRINSIC_POWER:
504
	  fputs ("** ", dumpfile);
505 506
	  break;
	case INTRINSIC_CONCAT:
507
	  fputs ("// ", dumpfile);
508 509
	  break;
	case INTRINSIC_AND:
510
	  fputs ("AND ", dumpfile);
511 512
	  break;
	case INTRINSIC_OR:
513
	  fputs ("OR ", dumpfile);
514 515
	  break;
	case INTRINSIC_EQV:
516
	  fputs ("EQV ", dumpfile);
517 518
	  break;
	case INTRINSIC_NEQV:
519
	  fputs ("NEQV ", dumpfile);
520 521
	  break;
	case INTRINSIC_EQ:
522
	case INTRINSIC_EQ_OS:
523
	  fputs ("= ", dumpfile);
524 525
	  break;
	case INTRINSIC_NE:
526
	case INTRINSIC_NE_OS:
527
	  fputs ("/= ", dumpfile);
528 529
	  break;
	case INTRINSIC_GT:
530
	case INTRINSIC_GT_OS:
531
	  fputs ("> ", dumpfile);
532 533
	  break;
	case INTRINSIC_GE:
534
	case INTRINSIC_GE_OS:
535
	  fputs (">= ", dumpfile);
536 537
	  break;
	case INTRINSIC_LT:
538
	case INTRINSIC_LT_OS:
539
	  fputs ("< ", dumpfile);
540 541
	  break;
	case INTRINSIC_LE:
542
	case INTRINSIC_LE_OS:
543
	  fputs ("<= ", dumpfile);
544 545
	  break;
	case INTRINSIC_NOT:
546
	  fputs ("NOT ", dumpfile);
547
	  break;
548
	case INTRINSIC_PARENTHESES:
549
	  fputs ("parens ", dumpfile);
550
	  break;
551 552 553

	default:
	  gfc_internal_error
554
	    ("show_expr(): Bad intrinsic in expression!");
555 556
	}

557
      show_expr (p->value.op.op1);
558

559
      if (p->value.op.op2)
560
	{
561 562
	  fputc (' ', dumpfile);
	  show_expr (p->value.op.op2);
563 564
	}

565
      fputc (')', dumpfile);
566 567 568 569 570
      break;

    case EXPR_FUNCTION:
      if (p->value.function.name == NULL)
	{
571
	  fprintf (dumpfile, "%s", p->symtree->n.sym->name);
572
	  if (gfc_is_proc_ptr_comp (p))
573 574
	    show_ref (p->ref);
	  fputc ('[', dumpfile);
575 576
	  show_actual_arglist (p->value.function.actual);
	  fputc (']', dumpfile);
577 578 579
	}
      else
	{
580
	  fprintf (dumpfile, "%s", p->value.function.name);
581
	  if (gfc_is_proc_ptr_comp (p))
582 583 584
	    show_ref (p->ref);
	  fputc ('[', dumpfile);
	  fputc ('[', dumpfile);
585 586 587
	  show_actual_arglist (p->value.function.actual);
	  fputc (']', dumpfile);
	  fputc (']', dumpfile);
588 589 590 591
	}

      break;

592 593 594 595
    case EXPR_COMPCALL:
      show_compcall (p);
      break;

596
    default:
597
      gfc_internal_error ("show_expr(): Don't know how to show expr");
598 599 600 601 602 603
    }
}

/* Show symbol attributes.  The flavor and intent are followed by
   whatever single bit attributes are present.  */

604
static void
605
show_attr (symbol_attribute *attr, const char * module)
606
{
607 608 609 610 611 612 613 614
  if (attr->flavor != FL_UNKNOWN)
    fprintf (dumpfile, "(%s ", gfc_code2string (flavors, attr->flavor));
  if (attr->access != ACCESS_UNKNOWN)
    fprintf (dumpfile, "%s ", gfc_code2string (access_types, attr->access));
  if (attr->proc != PROC_UNKNOWN)
    fprintf (dumpfile, "%s ", gfc_code2string (procedures, attr->proc));
  if (attr->save != SAVE_NONE)
    fprintf (dumpfile, "%s", gfc_code2string (save_status, attr->save));
615

Tobias Burnus committed
616 617
  if (attr->artificial)
    fputs (" ARTIFICIAL", dumpfile);
618
  if (attr->allocatable)
619
    fputs (" ALLOCATABLE", dumpfile);
620 621
  if (attr->asynchronous)
    fputs (" ASYNCHRONOUS", dumpfile);
622 623
  if (attr->codimension)
    fputs (" CODIMENSION", dumpfile);
624
  if (attr->dimension)
625
    fputs (" DIMENSION", dumpfile);
626 627
  if (attr->contiguous)
    fputs (" CONTIGUOUS", dumpfile);
628
  if (attr->external)
629
    fputs (" EXTERNAL", dumpfile);
630
  if (attr->intrinsic)
631
    fputs (" INTRINSIC", dumpfile);
632
  if (attr->optional)
633
    fputs (" OPTIONAL", dumpfile);
634
  if (attr->pointer)
635
    fputs (" POINTER", dumpfile);
636
  if (attr->is_protected)
637
    fputs (" PROTECTED", dumpfile);
638
  if (attr->value)
639
    fputs (" VALUE", dumpfile);
640
  if (attr->volatile_)
641
    fputs (" VOLATILE", dumpfile);
642
  if (attr->threadprivate)
643
    fputs (" THREADPRIVATE", dumpfile);
644
  if (attr->target)
645
    fputs (" TARGET", dumpfile);
646
  if (attr->dummy)
647 648 649 650 651 652
    {
      fputs (" DUMMY", dumpfile);
      if (attr->intent != INTENT_UNKNOWN)
	fprintf (dumpfile, "(%s)", gfc_intent_string (attr->intent));
    }

653
  if (attr->result)
654
    fputs (" RESULT", dumpfile);
655
  if (attr->entry)
656
    fputs (" ENTRY", dumpfile);
657
  if (attr->is_bind_c)
658
    fputs (" BIND(C)", dumpfile);
659 660

  if (attr->data)
661
    fputs (" DATA", dumpfile);
662
  if (attr->use_assoc)
663 664 665 666 667 668
    {
      fputs (" USE-ASSOC", dumpfile);
      if (module != NULL)
	fprintf (dumpfile, "(%s)", module);
    }

669
  if (attr->in_namelist)
670
    fputs (" IN-NAMELIST", dumpfile);
671
  if (attr->in_common)
672
    fputs (" IN-COMMON", dumpfile);
673

Tobias Burnus committed
674
  if (attr->abstract)
675
    fputs (" ABSTRACT", dumpfile);
676
  if (attr->function)
677
    fputs (" FUNCTION", dumpfile);
678
  if (attr->subroutine)
679
    fputs (" SUBROUTINE", dumpfile);
680
  if (attr->implicit_type)
681
    fputs (" IMPLICIT-TYPE", dumpfile);
682 683

  if (attr->sequence)
684
    fputs (" SEQUENCE", dumpfile);
685
  if (attr->elemental)
686
    fputs (" ELEMENTAL", dumpfile);
687
  if (attr->pure)
688
    fputs (" PURE", dumpfile);
689
  if (attr->recursive)
690
    fputs (" RECURSIVE", dumpfile);
691

692
  fputc (')', dumpfile);
693 694 695 696 697
}


/* Show components of a derived type.  */

698 699
static void
show_components (gfc_symbol *sym)
700 701 702 703 704
{
  gfc_component *c;

  for (c = sym->components; c; c = c->next)
    {
705 706
      fprintf (dumpfile, "(%s ", c->name);
      show_typespec (&c->ts);
707 708
      if (c->attr.allocatable)
	fputs (" ALLOCATABLE", dumpfile);
709
      if (c->attr.pointer)
710
	fputs (" POINTER", dumpfile);
711 712
      if (c->attr.proc_pointer)
	fputs (" PPC", dumpfile);
713
      if (c->attr.dimension)
714 715 716
	fputs (" DIMENSION", dumpfile);
      fputc (' ', dumpfile);
      show_array_spec (c->as);
717 718
      if (c->attr.access)
	fprintf (dumpfile, " %s", gfc_code2string (access_types, c->attr.access));
719
      fputc (')', dumpfile);
720
      if (c->next != NULL)
721
	fputc (' ', dumpfile);
722 723 724 725
    }
}


726 727 728
/* Show the f2k_derived namespace with procedure bindings.  */

static void
729
show_typebound_proc (gfc_typebound_proc* tb, const char* name)
730 731 732
{
  show_indent ();

733
  if (tb->is_generic)
734 735 736 737
    fputs ("GENERIC", dumpfile);
  else
    {
      fputs ("PROCEDURE, ", dumpfile);
738
      if (tb->nopass)
739 740 741
	fputs ("NOPASS", dumpfile);
      else
	{
742 743
	  if (tb->pass_arg)
	    fprintf (dumpfile, "PASS(%s)", tb->pass_arg);
744 745 746
	  else
	    fputs ("PASS", dumpfile);
	}
747
      if (tb->non_overridable)
748 749 750
	fputs (", NON_OVERRIDABLE", dumpfile);
    }

751
  if (tb->access == ACCESS_PUBLIC)
752 753 754 755
    fputs (", PUBLIC", dumpfile);
  else
    fputs (", PRIVATE", dumpfile);

756
  fprintf (dumpfile, " :: %s => ", name);
757

758
  if (tb->is_generic)
759 760
    {
      gfc_tbp_generic* g;
761
      for (g = tb->u.generic; g; g = g->next)
762 763 764 765 766 767 768
	{
	  fputs (g->specific_st->name, dumpfile);
	  if (g->next)
	    fputs (", ", dumpfile);
	}
    }
  else
769 770 771 772 773 774 775 776
    fputs (tb->u.specific->n.sym->name, dumpfile);
}

static void
show_typebound_symtree (gfc_symtree* st)
{
  gcc_assert (st->n.tb);
  show_typebound_proc (st->n.tb, st->name);
777 778 779 780 781 782
}

static void
show_f2k_derived (gfc_namespace* f2k)
{
  gfc_finalizer* f;
783
  int op;
784

785 786
  show_indent ();
  fputs ("Procedure bindings:", dumpfile);
787 788 789 790 791 792
  ++show_level;

  /* Finalizer bindings.  */
  for (f = f2k->finalizers; f; f = f->next)
    {
      show_indent ();
Tobias Burnus committed
793
      fprintf (dumpfile, "FINAL %s", f->proc_tree->n.sym->name);
794 795 796
    }

  /* Type-bound procedures.  */
797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812
  gfc_traverse_symtree (f2k->tb_sym_root, &show_typebound_symtree);

  --show_level;

  show_indent ();
  fputs ("Operator bindings:", dumpfile);
  ++show_level;

  /* User-defined operators.  */
  gfc_traverse_symtree (f2k->tb_uop_root, &show_typebound_symtree);

  /* Intrinsic operators.  */
  for (op = GFC_INTRINSIC_BEGIN; op != GFC_INTRINSIC_END; ++op)
    if (f2k->tb_op[op])
      show_typebound_proc (f2k->tb_op[op],
			   gfc_op2string ((gfc_intrinsic_op) op));
813 814 815 816 817

  --show_level;
}


818 819 820 821 822
/* Show a symbol.  If a symbol is an ENTRY, SUBROUTINE or FUNCTION, we
   show the interface.  Information needed to reconstruct the list of
   specific interfaces associated with a generic symbol is done within
   that symbol.  */

823 824
static void
show_symbol (gfc_symbol *sym)
825 826 827
{
  gfc_formal_arglist *formal;
  gfc_interface *intr;
828
  int i,len;
829 830 831 832

  if (sym == NULL)
    return;

833 834 835 836
  fprintf (dumpfile, "|| symbol: '%s' ", sym->name);
  len = strlen (sym->name);
  for (i=len; i<12; i++)
    fputc(' ', dumpfile);
837

838
  ++show_level;
839

840 841 842
  show_indent ();
  fputs ("type spec : ", dumpfile);
  show_typespec (&sym->ts);
843

844 845 846
  show_indent ();
  fputs ("attributes: ", dumpfile);
  show_attr (&sym->attr, sym->module);
847 848 849 850

  if (sym->value)
    {
      show_indent ();
851 852
      fputs ("value: ", dumpfile);
      show_expr (sym->value);
853 854 855 856 857
    }

  if (sym->as)
    {
      show_indent ();
858 859
      fputs ("Array spec:", dumpfile);
      show_array_spec (sym->as);
860 861 862 863 864
    }

  if (sym->generic)
    {
      show_indent ();
865
      fputs ("Generic interfaces:", dumpfile);
866
      for (intr = sym->generic; intr; intr = intr->next)
867
	fprintf (dumpfile, " %s", intr->sym->name);
868 869 870 871 872
    }

  if (sym->result)
    {
      show_indent ();
873
      fprintf (dumpfile, "result: %s", sym->result->name);
874 875 876 877 878
    }

  if (sym->components)
    {
      show_indent ();
879 880
      fputs ("components: ", dumpfile);
      show_components (sym);
881 882
    }

883
  if (sym->f2k_derived)
884 885
    {
      show_indent ();
886 887
      if (sym->hash_value)
	fprintf (dumpfile, "hash: %d", sym->hash_value);
888 889
      show_f2k_derived (sym->f2k_derived);
    }
890

891 892 893
  if (sym->formal)
    {
      show_indent ();
894
      fputs ("Formal arglist:", dumpfile);
895 896

      for (formal = sym->formal; formal; formal = formal->next)
897 898
	{
	  if (formal->sym != NULL)
899
	    fprintf (dumpfile, " %s", formal->sym->name);
900
	  else
901
	    fputs (" [Alt Return]", dumpfile);
902
	}
903 904
    }

905
  if (sym->formal_ns && (sym->formal_ns->proc_name != sym)
906 907
      && sym->attr.proc != PROC_ST_FUNCTION
      && !sym->attr.entry)
908 909
    {
      show_indent ();
910 911
      fputs ("Formal namespace", dumpfile);
      show_namespace (sym->formal_ns);
912
    }
913
  --show_level;
914 915 916
}


917 918
/* Show a user-defined operator.  Just prints an operator
   and the name of the associated subroutine, really.  */
919

920
static void
921
show_uop (gfc_user_op *uop)
922 923 924 925
{
  gfc_interface *intr;

  show_indent ();
926
  fprintf (dumpfile, "%s:", uop->name);
927

928
  for (intr = uop->op; intr; intr = intr->next)
929
    fprintf (dumpfile, " %s", intr->sym->name);
930 931 932 933 934 935
}


/* Workhorse function for traversing the user operator symtree.  */

static void
936
traverse_uop (gfc_symtree *st, void (*func) (gfc_user_op *))
937 938 939 940 941 942 943 944 945 946 947 948 949 950
{
  if (st == NULL)
    return;

  (*func) (st->n.uop);

  traverse_uop (st->left, func);
  traverse_uop (st->right, func);
}


/* Traverse the tree of user operator nodes.  */

void
951
gfc_traverse_user_op (gfc_namespace *ns, void (*func) (gfc_user_op *))
952 953 954 955 956
{
  traverse_uop (ns->uop_root, func);
}


957 958 959
/* Function to display a common block.  */

static void
960
show_common (gfc_symtree *st)
961 962 963 964
{
  gfc_symbol *s;

  show_indent ();
965
  fprintf (dumpfile, "common: /%s/ ", st->name);
966 967 968 969

  s = st->n.common->head;
  while (s)
    {
970
      fprintf (dumpfile, "%s", s->name);
971 972
      s = s->common_next;
      if (s)
973
	fputs (", ", dumpfile);
974
    }
975
  fputc ('\n', dumpfile);
976 977
}    

978

979 980 981
/* Worker function to display the symbol tree.  */

static void
982
show_symtree (gfc_symtree *st)
983
{
984 985
  int len, i;

986
  show_indent ();
987 988 989 990 991 992 993 994 995

  len = strlen(st->name);
  fprintf (dumpfile, "symtree: '%s'", st->name);

  for (i=len; i<12; i++)
    fputc(' ', dumpfile);

  if (st->ambiguous)
    fputs( " Ambiguous", dumpfile);
996 997

  if (st->n.sym->ns != gfc_current_ns)
998 999
    fprintf (dumpfile, "|| symbol: '%s' from namespace '%s'", st->n.sym->name,
	     st->n.sym->ns->proc_name->name);
1000
  else
1001
    show_symbol (st->n.sym);
1002 1003 1004 1005 1006 1007 1008
}


/******************* Show gfc_code structures **************/


/* Show a list of code structures.  Mutually recursive with
1009
   show_code_node().  */
1010

1011 1012
static void
show_code (int level, gfc_code *c)
1013 1014
{
  for (; c; c = c->next)
1015
    show_code_node (level, c);
1016 1017
}

1018
static void
1019
show_omp_namelist (int list_type, gfc_omp_namelist *n)
1020
{
1021 1022
  for (; n; n = n->next)
    {
1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042
      if (list_type == OMP_LIST_REDUCTION)
	switch (n->u.reduction_op)
	  {
	  case OMP_REDUCTION_PLUS:
	  case OMP_REDUCTION_TIMES:
	  case OMP_REDUCTION_MINUS:
	  case OMP_REDUCTION_AND:
	  case OMP_REDUCTION_OR:
	  case OMP_REDUCTION_EQV:
	  case OMP_REDUCTION_NEQV:
	    fprintf (dumpfile, "%s:",
		     gfc_op2string ((gfc_intrinsic_op) n->u.reduction_op));
	    break;
	  case OMP_REDUCTION_MAX: fputs ("max:", dumpfile); break;
	  case OMP_REDUCTION_MIN: fputs ("min:", dumpfile); break;
	  case OMP_REDUCTION_IAND: fputs ("iand:", dumpfile); break;
	  case OMP_REDUCTION_IOR: fputs ("ior:", dumpfile); break;
	  case OMP_REDUCTION_IEOR: fputs ("ieor:", dumpfile); break;
	  case OMP_REDUCTION_USER:
	    if (n->udr)
1043
	      fprintf (dumpfile, "%s:", n->udr->udr->name);
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063
	    break;
	  default: break;
	  }
      else if (list_type == OMP_LIST_DEPEND)
	switch (n->u.depend_op)
	  {
	  case OMP_DEPEND_IN: fputs ("in:", dumpfile); break;
	  case OMP_DEPEND_OUT: fputs ("out:", dumpfile); break;
	  case OMP_DEPEND_INOUT: fputs ("inout:", dumpfile); break;
	  default: break;
	  }
      else if (list_type == OMP_LIST_MAP)
	switch (n->u.map_op)
	  {
	  case OMP_MAP_ALLOC: fputs ("alloc:", dumpfile); break;
	  case OMP_MAP_TO: fputs ("to:", dumpfile); break;
	  case OMP_MAP_FROM: fputs ("from:", dumpfile); break;
	  case OMP_MAP_TOFROM: fputs ("tofrom:", dumpfile); break;
	  default: break;
	  }
1064 1065 1066 1067 1068 1069 1070 1071 1072
      fprintf (dumpfile, "%s", n->sym->name);
      if (n->expr)
	{
	  fputc (':', dumpfile);
	  show_expr (n->expr);
	}
      if (n->next)
	fputc (',', dumpfile);
    }
1073 1074
}

1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333

/* Show OpenMP or OpenACC clauses.  */

static void
show_omp_clauses (gfc_omp_clauses *omp_clauses)
{
  int list_type;

  switch (omp_clauses->cancel)
    {
    case OMP_CANCEL_UNKNOWN:
      break;
    case OMP_CANCEL_PARALLEL:
      fputs (" PARALLEL", dumpfile);
      break;
    case OMP_CANCEL_SECTIONS:
      fputs (" SECTIONS", dumpfile);
      break;
    case OMP_CANCEL_DO:
      fputs (" DO", dumpfile);
      break;
    case OMP_CANCEL_TASKGROUP:
      fputs (" TASKGROUP", dumpfile);
      break;
    }
  if (omp_clauses->if_expr)
    {
      fputs (" IF(", dumpfile);
      show_expr (omp_clauses->if_expr);
      fputc (')', dumpfile);
    }
  if (omp_clauses->final_expr)
    {
      fputs (" FINAL(", dumpfile);
      show_expr (omp_clauses->final_expr);
      fputc (')', dumpfile);
    }
  if (omp_clauses->num_threads)
    {
      fputs (" NUM_THREADS(", dumpfile);
      show_expr (omp_clauses->num_threads);
      fputc (')', dumpfile);
    }
  if (omp_clauses->async)
    {
      fputs (" ASYNC", dumpfile);
      if (omp_clauses->async_expr)
	{
	  fputc ('(', dumpfile);
	  show_expr (omp_clauses->async_expr);
	  fputc (')', dumpfile);
	}
    }
  if (omp_clauses->num_gangs_expr)
    {
      fputs (" NUM_GANGS(", dumpfile);
      show_expr (omp_clauses->num_gangs_expr);
      fputc (')', dumpfile);
    }
  if (omp_clauses->num_workers_expr)
    {
      fputs (" NUM_WORKERS(", dumpfile);
      show_expr (omp_clauses->num_workers_expr);
      fputc (')', dumpfile);
    }
  if (omp_clauses->vector_length_expr)
    {
      fputs (" VECTOR_LENGTH(", dumpfile);
      show_expr (omp_clauses->vector_length_expr);
      fputc (')', dumpfile);
    }
  if (omp_clauses->gang)
    {
      fputs (" GANG", dumpfile);
      if (omp_clauses->gang_expr)
	{
	  fputc ('(', dumpfile);
	  show_expr (omp_clauses->gang_expr);
	  fputc (')', dumpfile);
	}
    }
  if (omp_clauses->worker)
    {
      fputs (" WORKER", dumpfile);
      if (omp_clauses->worker_expr)
	{
	  fputc ('(', dumpfile);
	  show_expr (omp_clauses->worker_expr);
	  fputc (')', dumpfile);
	}
    }
  if (omp_clauses->vector)
    {
      fputs (" VECTOR", dumpfile);
      if (omp_clauses->vector_expr)
	{
	  fputc ('(', dumpfile);
	  show_expr (omp_clauses->vector_expr);
	  fputc (')', dumpfile);
	}
    }
  if (omp_clauses->sched_kind != OMP_SCHED_NONE)
    {
      const char *type;
      switch (omp_clauses->sched_kind)
	{
	case OMP_SCHED_STATIC: type = "STATIC"; break;
	case OMP_SCHED_DYNAMIC: type = "DYNAMIC"; break;
	case OMP_SCHED_GUIDED: type = "GUIDED"; break;
	case OMP_SCHED_RUNTIME: type = "RUNTIME"; break;
	case OMP_SCHED_AUTO: type = "AUTO"; break;
	default:
	  gcc_unreachable ();
	}
      fprintf (dumpfile, " SCHEDULE (%s", type);
      if (omp_clauses->chunk_size)
	{
	  fputc (',', dumpfile);
	  show_expr (omp_clauses->chunk_size);
	}
      fputc (')', dumpfile);
    }
  if (omp_clauses->default_sharing != OMP_DEFAULT_UNKNOWN)
    {
      const char *type;
      switch (omp_clauses->default_sharing)
	{
	case OMP_DEFAULT_NONE: type = "NONE"; break;
	case OMP_DEFAULT_PRIVATE: type = "PRIVATE"; break;
	case OMP_DEFAULT_SHARED: type = "SHARED"; break;
	case OMP_DEFAULT_FIRSTPRIVATE: type = "FIRSTPRIVATE"; break;
	default:
	  gcc_unreachable ();
	}
      fprintf (dumpfile, " DEFAULT(%s)", type);
    }
  if (omp_clauses->tile_list)
    {
      gfc_expr_list *list;
      fputs (" TILE(", dumpfile);
      for (list = omp_clauses->tile_list; list; list = list->next)
	{
	  show_expr (list->expr);
	  if (list->next) 
	    fputs (", ", dumpfile);
	}
      fputc (')', dumpfile);
    }
  if (omp_clauses->wait_list)
    {
      gfc_expr_list *list;
      fputs (" WAIT(", dumpfile);
      for (list = omp_clauses->wait_list; list; list = list->next)
	{
	  show_expr (list->expr);
	  if (list->next) 
	    fputs (", ", dumpfile);
	}
      fputc (')', dumpfile);
    }
  if (omp_clauses->seq)
    fputs (" SEQ", dumpfile);
  if (omp_clauses->independent)
    fputs (" INDEPENDENT", dumpfile);
  if (omp_clauses->ordered)
    fputs (" ORDERED", dumpfile);
  if (omp_clauses->untied)
    fputs (" UNTIED", dumpfile);
  if (omp_clauses->mergeable)
    fputs (" MERGEABLE", dumpfile);
  if (omp_clauses->collapse)
    fprintf (dumpfile, " COLLAPSE(%d)", omp_clauses->collapse);
  for (list_type = 0; list_type < OMP_LIST_NUM; list_type++)
    if (omp_clauses->lists[list_type] != NULL
	&& list_type != OMP_LIST_COPYPRIVATE)
      {
	const char *type = NULL;
	switch (list_type)
	  {
	  case OMP_LIST_USE_DEVICE: type = "USE_DEVICE"; break;
	  case OMP_LIST_DEVICE_RESIDENT: type = "USE_DEVICE"; break;
	  case OMP_LIST_CACHE: type = ""; break;
	  case OMP_LIST_PRIVATE: type = "PRIVATE"; break;
	  case OMP_LIST_FIRSTPRIVATE: type = "FIRSTPRIVATE"; break;
	  case OMP_LIST_LASTPRIVATE: type = "LASTPRIVATE"; break;
	  case OMP_LIST_SHARED: type = "SHARED"; break;
	  case OMP_LIST_COPYIN: type = "COPYIN"; break;
	  case OMP_LIST_UNIFORM: type = "UNIFORM"; break;
	  case OMP_LIST_ALIGNED: type = "ALIGNED"; break;
	  case OMP_LIST_LINEAR: type = "LINEAR"; break;
	  case OMP_LIST_REDUCTION: type = "REDUCTION"; break;
	  case OMP_LIST_DEPEND: type = "DEPEND"; break;
	  default:
	    gcc_unreachable ();
	  }
	fprintf (dumpfile, " %s(", type);
	show_omp_namelist (list_type, omp_clauses->lists[list_type]);
	fputc (')', dumpfile);
      }
  if (omp_clauses->safelen_expr)
    {
      fputs (" SAFELEN(", dumpfile);
      show_expr (omp_clauses->safelen_expr);
      fputc (')', dumpfile);
    }
  if (omp_clauses->simdlen_expr)
    {
      fputs (" SIMDLEN(", dumpfile);
      show_expr (omp_clauses->simdlen_expr);
      fputc (')', dumpfile);
    }
  if (omp_clauses->inbranch)
    fputs (" INBRANCH", dumpfile);
  if (omp_clauses->notinbranch)
    fputs (" NOTINBRANCH", dumpfile);
  if (omp_clauses->proc_bind != OMP_PROC_BIND_UNKNOWN)
    {
      const char *type;
      switch (omp_clauses->proc_bind)
	{
	case OMP_PROC_BIND_MASTER: type = "MASTER"; break;
	case OMP_PROC_BIND_SPREAD: type = "SPREAD"; break;
	case OMP_PROC_BIND_CLOSE: type = "CLOSE"; break;
	default:
	  gcc_unreachable ();
	}
      fprintf (dumpfile, " PROC_BIND(%s)", type);
    }
  if (omp_clauses->num_teams)
    {
      fputs (" NUM_TEAMS(", dumpfile);
      show_expr (omp_clauses->num_teams);
      fputc (')', dumpfile);
    }
  if (omp_clauses->device)
    {
      fputs (" DEVICE(", dumpfile);
      show_expr (omp_clauses->device);
      fputc (')', dumpfile);
    }
  if (omp_clauses->thread_limit)
    {
      fputs (" THREAD_LIMIT(", dumpfile);
      show_expr (omp_clauses->thread_limit);
      fputc (')', dumpfile);
    }
  if (omp_clauses->dist_sched_kind != OMP_SCHED_NONE)
    {
      fprintf (dumpfile, " DIST_SCHEDULE (static");
      if (omp_clauses->dist_chunk_size)
	{
	  fputc (',', dumpfile);
	  show_expr (omp_clauses->dist_chunk_size);
	}
      fputc (')', dumpfile);
    }
}

/* Show a single OpenMP or OpenACC directive node and everything underneath it
1334 1335 1336
   if necessary.  */

static void
1337
show_omp_node (int level, gfc_code *c)
1338 1339 1340
{
  gfc_omp_clauses *omp_clauses = NULL;
  const char *name = NULL;
1341
  bool is_oacc = false;
1342 1343 1344

  switch (c->op)
    {
1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356
    case EXEC_OACC_PARALLEL_LOOP: name = "PARALLEL LOOP"; is_oacc = true; break;
    case EXEC_OACC_PARALLEL: name = "PARALLEL"; is_oacc = true; break;
    case EXEC_OACC_KERNELS_LOOP: name = "KERNELS LOOP"; is_oacc = true; break;
    case EXEC_OACC_KERNELS: name = "KERNELS"; is_oacc = true; break;
    case EXEC_OACC_DATA: name = "DATA"; is_oacc = true; break;
    case EXEC_OACC_HOST_DATA: name = "HOST_DATA"; is_oacc = true; break;
    case EXEC_OACC_LOOP: name = "LOOP"; is_oacc = true; break;
    case EXEC_OACC_UPDATE: name = "UPDATE"; is_oacc = true; break;
    case EXEC_OACC_WAIT: name = "WAIT"; is_oacc = true; break;
    case EXEC_OACC_CACHE: name = "CACHE"; is_oacc = true; break;
    case EXEC_OACC_ENTER_DATA: name = "ENTER DATA"; is_oacc = true; break;
    case EXEC_OACC_EXIT_DATA: name = "EXIT DATA"; is_oacc = true; break;
1357 1358
    case EXEC_OMP_ATOMIC: name = "ATOMIC"; break;
    case EXEC_OMP_BARRIER: name = "BARRIER"; break;
1359 1360
    case EXEC_OMP_CANCEL: name = "CANCEL"; break;
    case EXEC_OMP_CANCELLATION_POINT: name = "CANCELLATION POINT"; break;
1361 1362 1363
    case EXEC_OMP_CRITICAL: name = "CRITICAL"; break;
    case EXEC_OMP_FLUSH: name = "FLUSH"; break;
    case EXEC_OMP_DO: name = "DO"; break;
1364
    case EXEC_OMP_DO_SIMD: name = "DO SIMD"; break;
1365 1366 1367 1368
    case EXEC_OMP_MASTER: name = "MASTER"; break;
    case EXEC_OMP_ORDERED: name = "ORDERED"; break;
    case EXEC_OMP_PARALLEL: name = "PARALLEL"; break;
    case EXEC_OMP_PARALLEL_DO: name = "PARALLEL DO"; break;
1369
    case EXEC_OMP_PARALLEL_DO_SIMD: name = "PARALLEL DO SIMD"; break;
1370 1371 1372
    case EXEC_OMP_PARALLEL_SECTIONS: name = "PARALLEL SECTIONS"; break;
    case EXEC_OMP_PARALLEL_WORKSHARE: name = "PARALLEL WORKSHARE"; break;
    case EXEC_OMP_SECTIONS: name = "SECTIONS"; break;
1373
    case EXEC_OMP_SIMD: name = "SIMD"; break;
1374
    case EXEC_OMP_SINGLE: name = "SINGLE"; break;
1375
    case EXEC_OMP_TASK: name = "TASK"; break;
1376
    case EXEC_OMP_TASKGROUP: name = "TASKGROUP"; break;
1377
    case EXEC_OMP_TASKWAIT: name = "TASKWAIT"; break;
1378
    case EXEC_OMP_TASKYIELD: name = "TASKYIELD"; break;
1379 1380 1381 1382
    case EXEC_OMP_WORKSHARE: name = "WORKSHARE"; break;
    default:
      gcc_unreachable ();
    }
1383
  fprintf (dumpfile, "!$%s %s", is_oacc ? "ACC" : "OMP", name);
1384 1385
  switch (c->op)
    {
1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397
    case EXEC_OACC_PARALLEL_LOOP:
    case EXEC_OACC_PARALLEL:
    case EXEC_OACC_KERNELS_LOOP:
    case EXEC_OACC_KERNELS:
    case EXEC_OACC_DATA:
    case EXEC_OACC_HOST_DATA:
    case EXEC_OACC_LOOP:
    case EXEC_OACC_UPDATE:
    case EXEC_OACC_WAIT:
    case EXEC_OACC_CACHE:
    case EXEC_OACC_ENTER_DATA:
    case EXEC_OACC_EXIT_DATA:
1398 1399
    case EXEC_OMP_CANCEL:
    case EXEC_OMP_CANCELLATION_POINT:
1400
    case EXEC_OMP_DO:
1401
    case EXEC_OMP_DO_SIMD:
1402 1403
    case EXEC_OMP_PARALLEL:
    case EXEC_OMP_PARALLEL_DO:
1404
    case EXEC_OMP_PARALLEL_DO_SIMD:
1405 1406
    case EXEC_OMP_PARALLEL_SECTIONS:
    case EXEC_OMP_SECTIONS:
1407
    case EXEC_OMP_SIMD:
1408 1409 1410
    case EXEC_OMP_SINGLE:
    case EXEC_OMP_WORKSHARE:
    case EXEC_OMP_PARALLEL_WORKSHARE:
1411
    case EXEC_OMP_TASK:
1412 1413 1414 1415
      omp_clauses = c->ext.omp_clauses;
      break;
    case EXEC_OMP_CRITICAL:
      if (c->ext.omp_name)
1416
	fprintf (dumpfile, " (%s)", c->ext.omp_name);
1417 1418 1419 1420
      break;
    case EXEC_OMP_FLUSH:
      if (c->ext.omp_namelist)
	{
1421
	  fputs (" (", dumpfile);
1422
	  show_omp_namelist (OMP_LIST_NUM, c->ext.omp_namelist);
1423
	  fputc (')', dumpfile);
1424 1425 1426
	}
      return;
    case EXEC_OMP_BARRIER:
1427
    case EXEC_OMP_TASKWAIT:
1428
    case EXEC_OMP_TASKYIELD:
1429 1430 1431 1432 1433
      return;
    default:
      break;
    }
  if (omp_clauses)
1434
    show_omp_clauses (omp_clauses);
1435
  fputc ('\n', dumpfile);
1436 1437 1438 1439 1440

  /* OpenACC executable directives don't have associated blocks.  */
  if (c->op == EXEC_OACC_CACHE || c->op == EXEC_OACC_UPDATE
      || c->op == EXEC_OACC_ENTER_DATA || c->op == EXEC_OACC_EXIT_DATA)
    return;
1441 1442 1443 1444 1445
  if (c->op == EXEC_OMP_SECTIONS || c->op == EXEC_OMP_PARALLEL_SECTIONS)
    {
      gfc_code *d = c->block;
      while (d != NULL)
	{
1446
	  show_code (level + 1, d->next);
1447 1448 1449
	  if (d->block == NULL)
	    break;
	  code_indent (level, 0);
1450
	  fputs ("!$OMP SECTION\n", dumpfile);
1451 1452 1453 1454
	  d = d->block;
	}
    }
  else
1455
    show_code (level + 1, c->block->next);
1456 1457
  if (c->op == EXEC_OMP_ATOMIC)
    return;
1458
  fputc ('\n', dumpfile);
1459
  code_indent (level, 0);
1460
  fprintf (dumpfile, "!$%s END %s", is_oacc ? "ACC" : "OMP", name);
1461 1462 1463 1464
  if (omp_clauses != NULL)
    {
      if (omp_clauses->lists[OMP_LIST_COPYPRIVATE])
	{
1465
	  fputs (" COPYPRIVATE(", dumpfile);
1466 1467
	  show_omp_namelist (OMP_LIST_COPYPRIVATE,
			     omp_clauses->lists[OMP_LIST_COPYPRIVATE]);
1468
	  fputc (')', dumpfile);
1469 1470
	}
      else if (omp_clauses->nowait)
1471
	fputs (" NOWAIT", dumpfile);
1472 1473
    }
  else if (c->op == EXEC_OMP_CRITICAL && c->ext.omp_name)
1474
    fprintf (dumpfile, " (%s)", c->ext.omp_name);
1475
}
1476

1477

1478 1479 1480
/* Show a single code node and everything underneath it if necessary.  */

static void
1481
show_code_node (int level, gfc_code *c)
1482 1483 1484 1485 1486 1487 1488 1489 1490 1491
{
  gfc_forall_iterator *fa;
  gfc_open *open;
  gfc_case *cp;
  gfc_alloc *a;
  gfc_code *d;
  gfc_close *close;
  gfc_filepos *fp;
  gfc_inquire *i;
  gfc_dt *dt;
1492
  gfc_namespace *ns;
1493

1494 1495 1496 1497 1498 1499 1500
  if (c->here)
    {
      fputc ('\n', dumpfile);
      code_indent (level, c->here);
    }
  else
    show_indent ();
1501 1502 1503

  switch (c->op)
    {
1504 1505 1506
    case EXEC_END_PROCEDURE:
      break;

1507
    case EXEC_NOP:
1508
      fputs ("NOP", dumpfile);
1509 1510 1511
      break;

    case EXEC_CONTINUE:
1512
      fputs ("CONTINUE", dumpfile);
1513 1514
      break;

1515
    case EXEC_ENTRY:
1516
      fprintf (dumpfile, "ENTRY %s", c->ext.entry->sym->name);
1517 1518
      break;

Paul Thomas committed
1519
    case EXEC_INIT_ASSIGN:
1520
    case EXEC_ASSIGN:
1521
      fputs ("ASSIGN ", dumpfile);
1522
      show_expr (c->expr1);
1523 1524
      fputc (' ', dumpfile);
      show_expr (c->expr2);
1525
      break;
1526

1527
    case EXEC_LABEL_ASSIGN:
1528
      fputs ("LABEL ASSIGN ", dumpfile);
1529
      show_expr (c->expr1);
1530
      fprintf (dumpfile, " %d", c->label1->value);
1531 1532 1533
      break;

    case EXEC_POINTER_ASSIGN:
1534
      fputs ("POINTER ASSIGN ", dumpfile);
1535
      show_expr (c->expr1);
1536 1537
      fputc (' ', dumpfile);
      show_expr (c->expr2);
1538 1539 1540
      break;

    case EXEC_GOTO:
1541
      fputs ("GOTO ", dumpfile);
1542 1543
      if (c->label1)
	fprintf (dumpfile, "%d", c->label1->value);
1544
      else
1545
	{
1546
	  show_expr (c->expr1);
1547 1548 1549
	  d = c->block;
	  if (d != NULL)
	    {
1550
	      fputs (", (", dumpfile);
1551 1552
	      for (; d; d = d ->block)
		{
1553
		  code_indent (level, d->label1);
1554
		  if (d->block != NULL)
1555
		    fputc (',', dumpfile);
1556
		  else
1557
		    fputc (')', dumpfile);
1558 1559 1560
		}
	    }
	}
1561 1562 1563
      break;

    case EXEC_CALL:
1564
    case EXEC_ASSIGN_CALL:
1565
      if (c->resolved_sym)
1566
	fprintf (dumpfile, "CALL %s ", c->resolved_sym->name);
1567
      else if (c->symtree)
1568
	fprintf (dumpfile, "CALL %s ", c->symtree->name);
1569
      else
1570
	fputs ("CALL ?? ", dumpfile);
1571

1572
      show_actual_arglist (c->ext.actual);
1573 1574
      break;

1575 1576
    case EXEC_COMPCALL:
      fputs ("CALL ", dumpfile);
1577
      show_compcall (c->expr1);
1578 1579
      break;

1580 1581
    case EXEC_CALL_PPC:
      fputs ("CALL ", dumpfile);
1582
      show_expr (c->expr1);
1583 1584 1585
      show_actual_arglist (c->ext.actual);
      break;

1586
    case EXEC_RETURN:
1587
      fputs ("RETURN ", dumpfile);
1588 1589
      if (c->expr1)
	show_expr (c->expr1);
1590 1591 1592
      break;

    case EXEC_PAUSE:
1593
      fputs ("PAUSE ", dumpfile);
1594

1595 1596
      if (c->expr1 != NULL)
	show_expr (c->expr1);
1597
      else
1598
	fprintf (dumpfile, "%d", c->ext.stop_code);
1599 1600 1601

      break;

1602 1603 1604 1605
    case EXEC_ERROR_STOP:
      fputs ("ERROR ", dumpfile);
      /* Fall through.  */

1606
    case EXEC_STOP:
1607
      fputs ("STOP ", dumpfile);
1608

1609 1610
      if (c->expr1 != NULL)
	show_expr (c->expr1);
1611
      else
1612
	fprintf (dumpfile, "%d", c->ext.stop_code);
1613 1614 1615

      break;

1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661
    case EXEC_SYNC_ALL:
      fputs ("SYNC ALL ", dumpfile);
      if (c->expr2 != NULL)
	{
	  fputs (" stat=", dumpfile);
	  show_expr (c->expr2);
	}
      if (c->expr3 != NULL)
	{
	  fputs (" errmsg=", dumpfile);
	  show_expr (c->expr3);
	}
      break;

    case EXEC_SYNC_MEMORY:
      fputs ("SYNC MEMORY ", dumpfile);
      if (c->expr2 != NULL)
 	{
	  fputs (" stat=", dumpfile);
	  show_expr (c->expr2);
	}
      if (c->expr3 != NULL)
	{
	  fputs (" errmsg=", dumpfile);
	  show_expr (c->expr3);
	}
      break;

    case EXEC_SYNC_IMAGES:
      fputs ("SYNC IMAGES  image-set=", dumpfile);
      if (c->expr1 != NULL)
	show_expr (c->expr1);
      else
	fputs ("* ", dumpfile);
      if (c->expr2 != NULL)
	{
	  fputs (" stat=", dumpfile);
	  show_expr (c->expr2);
	}
      if (c->expr3 != NULL)
	{
	  fputs (" errmsg=", dumpfile);
	  show_expr (c->expr3);
	}
      break;

1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688
    case EXEC_LOCK:
    case EXEC_UNLOCK:
      if (c->op == EXEC_LOCK)
	fputs ("LOCK ", dumpfile);
      else
	fputs ("UNLOCK ", dumpfile);

      fputs ("lock-variable=", dumpfile);
      if (c->expr1 != NULL)
	show_expr (c->expr1);
      if (c->expr4 != NULL)
	{
	  fputs (" acquired_lock=", dumpfile);
	  show_expr (c->expr4);
	}
      if (c->expr2 != NULL)
	{
	  fputs (" stat=", dumpfile);
	  show_expr (c->expr2);
	}
      if (c->expr3 != NULL)
	{
	  fputs (" errmsg=", dumpfile);
	  show_expr (c->expr3);
	}
      break;

1689
    case EXEC_ARITHMETIC_IF:
1690
      fputs ("IF ", dumpfile);
1691
      show_expr (c->expr1);
1692
      fprintf (dumpfile, " %d, %d, %d",
1693
		  c->label1->value, c->label2->value, c->label3->value);
1694 1695 1696 1697
      break;

    case EXEC_IF:
      d = c->block;
1698
      fputs ("IF ", dumpfile);
1699
      show_expr (d->expr1);
1700 1701

      ++show_level;
1702
      show_code (level + 1, d->next);
1703
      --show_level;
1704 1705 1706 1707 1708 1709

      d = d->block;
      for (; d; d = d->block)
	{
	  code_indent (level, 0);

1710
	  if (d->expr1 == NULL)
1711
	    fputs ("ELSE", dumpfile);
1712 1713
	  else
	    {
1714
	      fputs ("ELSE IF ", dumpfile);
1715
	      show_expr (d->expr1);
1716 1717
	    }

1718
	  ++show_level;
1719
	  show_code (level + 1, d->next);
1720
	  --show_level;
1721 1722
	}

1723 1724 1725 1726
      if (c->label1)
	code_indent (level, c->label1);
      else
	show_indent ();
1727

1728
      fputs ("ENDIF", dumpfile);
1729 1730
      break;

1731
    case EXEC_BLOCK:
1732 1733
      {
	const char* blocktype;
1734 1735
	gfc_namespace *saved_ns;

1736 1737 1738 1739 1740 1741
	if (c->ext.block.assoc)
	  blocktype = "ASSOCIATE";
	else
	  blocktype = "BLOCK";
	show_indent ();
	fprintf (dumpfile, "%s ", blocktype);
1742
	++show_level;
1743
	ns = c->ext.block.ns;
1744 1745
	saved_ns = gfc_current_ns;
	gfc_current_ns = ns;
1746
	gfc_traverse_symtree (ns->sym_root, show_symtree);
1747
	gfc_current_ns = saved_ns;
1748 1749
	show_code (show_level, ns->code);
	--show_level;
1750 1751 1752 1753
	show_indent ();
	fprintf (dumpfile, "END %s ", blocktype);
	break;
      }
1754

1755 1756
    case EXEC_SELECT:
      d = c->block;
1757
      fputs ("SELECT CASE ", dumpfile);
1758
      show_expr (c->expr1);
1759
      fputc ('\n', dumpfile);
1760 1761 1762 1763 1764

      for (; d; d = d->block)
	{
	  code_indent (level, 0);

1765
	  fputs ("CASE ", dumpfile);
1766
	  for (cp = d->ext.block.case_list; cp; cp = cp->next)
1767
	    {
1768 1769 1770 1771 1772 1773
	      fputc ('(', dumpfile);
	      show_expr (cp->low);
	      fputc (' ', dumpfile);
	      show_expr (cp->high);
	      fputc (')', dumpfile);
	      fputc (' ', dumpfile);
1774
	    }
1775
	  fputc ('\n', dumpfile);
1776

1777
	  show_code (level + 1, d->next);
1778 1779
	}

1780
      code_indent (level, c->label1);
1781
      fputs ("END SELECT", dumpfile);
1782 1783 1784
      break;

    case EXEC_WHERE:
1785
      fputs ("WHERE ", dumpfile);
1786 1787

      d = c->block;
1788
      show_expr (d->expr1);
1789
      fputc ('\n', dumpfile);
1790

1791
      show_code (level + 1, d->next);
1792 1793 1794 1795

      for (d = d->block; d; d = d->block)
	{
	  code_indent (level, 0);
1796
	  fputs ("ELSE WHERE ", dumpfile);
1797
	  show_expr (d->expr1);
1798 1799
	  fputc ('\n', dumpfile);
	  show_code (level + 1, d->next);
1800 1801 1802
	}

      code_indent (level, 0);
1803
      fputs ("END WHERE", dumpfile);
1804 1805 1806 1807
      break;


    case EXEC_FORALL:
1808
      fputs ("FORALL ", dumpfile);
1809 1810
      for (fa = c->ext.forall_iterator; fa; fa = fa->next)
	{
1811 1812 1813 1814 1815 1816 1817
	  show_expr (fa->var);
	  fputc (' ', dumpfile);
	  show_expr (fa->start);
	  fputc (':', dumpfile);
	  show_expr (fa->end);
	  fputc (':', dumpfile);
	  show_expr (fa->stride);
1818 1819

	  if (fa->next != NULL)
1820
	    fputc (',', dumpfile);
1821 1822
	}

1823
      if (c->expr1 != NULL)
1824
	{
1825
	  fputc (',', dumpfile);
1826
	  show_expr (c->expr1);
1827
	}
1828
      fputc ('\n', dumpfile);
1829

1830
      show_code (level + 1, c->block->next);
1831 1832

      code_indent (level, 0);
1833
      fputs ("END FORALL", dumpfile);
1834 1835
      break;

1836 1837 1838 1839 1840 1841 1842
    case EXEC_CRITICAL:
      fputs ("CRITICAL\n", dumpfile);
      show_code (level + 1, c->block->next);
      code_indent (level, 0);
      fputs ("END CRITICAL", dumpfile);
      break;

1843
    case EXEC_DO:
1844
      fputs ("DO ", dumpfile);
1845 1846
      if (c->label1)
	fprintf (dumpfile, " %-5d ", c->label1->value);
1847

1848 1849 1850 1851 1852 1853 1854
      show_expr (c->ext.iterator->var);
      fputc ('=', dumpfile);
      show_expr (c->ext.iterator->start);
      fputc (' ', dumpfile);
      show_expr (c->ext.iterator->end);
      fputc (' ', dumpfile);
      show_expr (c->ext.iterator->step);
1855

1856
      ++show_level;
1857
      show_code (level + 1, c->block->next);
1858
      --show_level;
1859

1860 1861 1862 1863
      if (c->label1)
	break;

      show_indent ();
1864
      fputs ("END DO", dumpfile);
1865 1866
      break;

1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888
    case EXEC_DO_CONCURRENT:
      fputs ("DO CONCURRENT ", dumpfile);
      for (fa = c->ext.forall_iterator; fa; fa = fa->next)
        {
          show_expr (fa->var);
          fputc (' ', dumpfile);
          show_expr (fa->start);
          fputc (':', dumpfile);
          show_expr (fa->end);
          fputc (':', dumpfile);
          show_expr (fa->stride);

          if (fa->next != NULL)
            fputc (',', dumpfile);
        }
      show_expr (c->expr1);

      show_code (level + 1, c->block->next);
      code_indent (level, c->label1);
      fputs ("END DO", dumpfile);
      break;

1889
    case EXEC_DO_WHILE:
1890
      fputs ("DO WHILE ", dumpfile);
1891
      show_expr (c->expr1);
1892
      fputc ('\n', dumpfile);
1893

1894
      show_code (level + 1, c->block->next);
1895

1896
      code_indent (level, c->label1);
1897
      fputs ("END DO", dumpfile);
1898 1899 1900
      break;

    case EXEC_CYCLE:
1901
      fputs ("CYCLE", dumpfile);
1902
      if (c->symtree)
1903
	fprintf (dumpfile, " %s", c->symtree->n.sym->name);
1904 1905 1906
      break;

    case EXEC_EXIT:
1907
      fputs ("EXIT", dumpfile);
1908
      if (c->symtree)
1909
	fprintf (dumpfile, " %s", c->symtree->n.sym->name);
1910 1911 1912
      break;

    case EXEC_ALLOCATE:
1913
      fputs ("ALLOCATE ", dumpfile);
1914
      if (c->expr1)
1915
	{
1916
	  fputs (" STAT=", dumpfile);
1917
	  show_expr (c->expr1);
1918 1919
	}

1920 1921 1922 1923 1924 1925
      if (c->expr2)
	{
	  fputs (" ERRMSG=", dumpfile);
	  show_expr (c->expr2);
	}

1926 1927 1928 1929 1930 1931 1932 1933 1934
      if (c->expr3)
	{
	  if (c->expr3->mold)
	    fputs (" MOLD=", dumpfile);
	  else
	    fputs (" SOURCE=", dumpfile);
	  show_expr (c->expr3);
	}

1935
      for (a = c->ext.alloc.list; a; a = a->next)
1936
	{
1937 1938
	  fputc (' ', dumpfile);
	  show_expr (a->expr);
1939 1940 1941 1942 1943
	}

      break;

    case EXEC_DEALLOCATE:
1944
      fputs ("DEALLOCATE ", dumpfile);
1945
      if (c->expr1)
1946
	{
1947
	  fputs (" STAT=", dumpfile);
1948
	  show_expr (c->expr1);
1949 1950
	}

1951 1952 1953 1954 1955 1956
      if (c->expr2)
	{
	  fputs (" ERRMSG=", dumpfile);
	  show_expr (c->expr2);
	}

1957
      for (a = c->ext.alloc.list; a; a = a->next)
1958
	{
1959 1960
	  fputc (' ', dumpfile);
	  show_expr (a->expr);
1961 1962 1963 1964 1965
	}

      break;

    case EXEC_OPEN:
1966
      fputs ("OPEN", dumpfile);
1967 1968 1969 1970
      open = c->ext.open;

      if (open->unit)
	{
1971 1972
	  fputs (" UNIT=", dumpfile);
	  show_expr (open->unit);
1973
	}
1974 1975
      if (open->iomsg)
	{
1976 1977
	  fputs (" IOMSG=", dumpfile);
	  show_expr (open->iomsg);
1978
	}
1979 1980
      if (open->iostat)
	{
1981 1982
	  fputs (" IOSTAT=", dumpfile);
	  show_expr (open->iostat);
1983 1984 1985
	}
      if (open->file)
	{
1986 1987
	  fputs (" FILE=", dumpfile);
	  show_expr (open->file);
1988 1989 1990
	}
      if (open->status)
	{
1991 1992
	  fputs (" STATUS=", dumpfile);
	  show_expr (open->status);
1993 1994 1995
	}
      if (open->access)
	{
1996 1997
	  fputs (" ACCESS=", dumpfile);
	  show_expr (open->access);
1998 1999 2000
	}
      if (open->form)
	{
2001 2002
	  fputs (" FORM=", dumpfile);
	  show_expr (open->form);
2003 2004 2005
	}
      if (open->recl)
	{
2006 2007
	  fputs (" RECL=", dumpfile);
	  show_expr (open->recl);
2008 2009 2010
	}
      if (open->blank)
	{
2011 2012
	  fputs (" BLANK=", dumpfile);
	  show_expr (open->blank);
2013 2014 2015
	}
      if (open->position)
	{
2016 2017
	  fputs (" POSITION=", dumpfile);
	  show_expr (open->position);
2018 2019 2020
	}
      if (open->action)
	{
2021 2022
	  fputs (" ACTION=", dumpfile);
	  show_expr (open->action);
2023 2024 2025
	}
      if (open->delim)
	{
2026 2027
	  fputs (" DELIM=", dumpfile);
	  show_expr (open->delim);
2028 2029 2030
	}
      if (open->pad)
	{
2031 2032
	  fputs (" PAD=", dumpfile);
	  show_expr (open->pad);
2033
	}
Jerry DeLisle committed
2034 2035
      if (open->decimal)
	{
2036 2037
	  fputs (" DECIMAL=", dumpfile);
	  show_expr (open->decimal);
Jerry DeLisle committed
2038 2039 2040
	}
      if (open->encoding)
	{
2041 2042
	  fputs (" ENCODING=", dumpfile);
	  show_expr (open->encoding);
Jerry DeLisle committed
2043 2044 2045
	}
      if (open->round)
	{
2046 2047
	  fputs (" ROUND=", dumpfile);
	  show_expr (open->round);
Jerry DeLisle committed
2048 2049 2050
	}
      if (open->sign)
	{
2051 2052
	  fputs (" SIGN=", dumpfile);
	  show_expr (open->sign);
Jerry DeLisle committed
2053
	}
2054 2055
      if (open->convert)
	{
2056 2057
	  fputs (" CONVERT=", dumpfile);
	  show_expr (open->convert);
2058
	}
Jerry DeLisle committed
2059 2060
      if (open->asynchronous)
	{
2061 2062
	  fputs (" ASYNCHRONOUS=", dumpfile);
	  show_expr (open->asynchronous);
Jerry DeLisle committed
2063
	}
2064
      if (open->err != NULL)
2065
	fprintf (dumpfile, " ERR=%d", open->err->value);
2066 2067 2068 2069

      break;

    case EXEC_CLOSE:
2070
      fputs ("CLOSE", dumpfile);
2071 2072 2073 2074
      close = c->ext.close;

      if (close->unit)
	{
2075 2076
	  fputs (" UNIT=", dumpfile);
	  show_expr (close->unit);
2077
	}
2078 2079
      if (close->iomsg)
	{
2080 2081
	  fputs (" IOMSG=", dumpfile);
	  show_expr (close->iomsg);
2082
	}
2083 2084
      if (close->iostat)
	{
2085 2086
	  fputs (" IOSTAT=", dumpfile);
	  show_expr (close->iostat);
2087 2088 2089
	}
      if (close->status)
	{
2090 2091
	  fputs (" STATUS=", dumpfile);
	  show_expr (close->status);
2092 2093
	}
      if (close->err != NULL)
2094
	fprintf (dumpfile, " ERR=%d", close->err->value);
2095 2096 2097
      break;

    case EXEC_BACKSPACE:
2098
      fputs ("BACKSPACE", dumpfile);
2099 2100 2101
      goto show_filepos;

    case EXEC_ENDFILE:
2102
      fputs ("ENDFILE", dumpfile);
2103 2104 2105
      goto show_filepos;

    case EXEC_REWIND:
2106
      fputs ("REWIND", dumpfile);
Janne Blomqvist committed
2107 2108 2109
      goto show_filepos;

    case EXEC_FLUSH:
2110
      fputs ("FLUSH", dumpfile);
2111 2112 2113 2114 2115 2116

    show_filepos:
      fp = c->ext.filepos;

      if (fp->unit)
	{
2117 2118
	  fputs (" UNIT=", dumpfile);
	  show_expr (fp->unit);
2119
	}
2120 2121
      if (fp->iomsg)
	{
2122 2123
	  fputs (" IOMSG=", dumpfile);
	  show_expr (fp->iomsg);
2124
	}
2125 2126
      if (fp->iostat)
	{
2127 2128
	  fputs (" IOSTAT=", dumpfile);
	  show_expr (fp->iostat);
2129 2130
	}
      if (fp->err != NULL)
2131
	fprintf (dumpfile, " ERR=%d", fp->err->value);
2132 2133 2134
      break;

    case EXEC_INQUIRE:
2135
      fputs ("INQUIRE", dumpfile);
2136 2137 2138 2139
      i = c->ext.inquire;

      if (i->unit)
	{
2140 2141
	  fputs (" UNIT=", dumpfile);
	  show_expr (i->unit);
2142 2143 2144
	}
      if (i->file)
	{
2145 2146
	  fputs (" FILE=", dumpfile);
	  show_expr (i->file);
2147 2148
	}

2149 2150
      if (i->iomsg)
	{
2151 2152
	  fputs (" IOMSG=", dumpfile);
	  show_expr (i->iomsg);
2153
	}
2154 2155
      if (i->iostat)
	{
2156 2157
	  fputs (" IOSTAT=", dumpfile);
	  show_expr (i->iostat);
2158 2159 2160
	}
      if (i->exist)
	{
2161 2162
	  fputs (" EXIST=", dumpfile);
	  show_expr (i->exist);
2163 2164 2165
	}
      if (i->opened)
	{
2166 2167
	  fputs (" OPENED=", dumpfile);
	  show_expr (i->opened);
2168 2169 2170
	}
      if (i->number)
	{
2171 2172
	  fputs (" NUMBER=", dumpfile);
	  show_expr (i->number);
2173 2174 2175
	}
      if (i->named)
	{
2176 2177
	  fputs (" NAMED=", dumpfile);
	  show_expr (i->named);
2178 2179 2180
	}
      if (i->name)
	{
2181 2182
	  fputs (" NAME=", dumpfile);
	  show_expr (i->name);
2183 2184 2185
	}
      if (i->access)
	{
2186 2187
	  fputs (" ACCESS=", dumpfile);
	  show_expr (i->access);
2188 2189 2190
	}
      if (i->sequential)
	{
2191 2192
	  fputs (" SEQUENTIAL=", dumpfile);
	  show_expr (i->sequential);
2193 2194 2195 2196
	}

      if (i->direct)
	{
2197 2198
	  fputs (" DIRECT=", dumpfile);
	  show_expr (i->direct);
2199 2200 2201
	}
      if (i->form)
	{
2202 2203
	  fputs (" FORM=", dumpfile);
	  show_expr (i->form);
2204 2205 2206
	}
      if (i->formatted)
	{
2207 2208
	  fputs (" FORMATTED", dumpfile);
	  show_expr (i->formatted);
2209 2210 2211
	}
      if (i->unformatted)
	{
2212 2213
	  fputs (" UNFORMATTED=", dumpfile);
	  show_expr (i->unformatted);
2214 2215 2216
	}
      if (i->recl)
	{
2217 2218
	  fputs (" RECL=", dumpfile);
	  show_expr (i->recl);
2219 2220 2221
	}
      if (i->nextrec)
	{
2222 2223
	  fputs (" NEXTREC=", dumpfile);
	  show_expr (i->nextrec);
2224 2225 2226
	}
      if (i->blank)
	{
2227 2228
	  fputs (" BLANK=", dumpfile);
	  show_expr (i->blank);
2229 2230 2231
	}
      if (i->position)
	{
2232 2233
	  fputs (" POSITION=", dumpfile);
	  show_expr (i->position);
2234 2235 2236
	}
      if (i->action)
	{
2237 2238
	  fputs (" ACTION=", dumpfile);
	  show_expr (i->action);
2239 2240 2241
	}
      if (i->read)
	{
2242 2243
	  fputs (" READ=", dumpfile);
	  show_expr (i->read);
2244 2245 2246
	}
      if (i->write)
	{
2247 2248
	  fputs (" WRITE=", dumpfile);
	  show_expr (i->write);
2249 2250 2251
	}
      if (i->readwrite)
	{
2252 2253
	  fputs (" READWRITE=", dumpfile);
	  show_expr (i->readwrite);
2254 2255 2256
	}
      if (i->delim)
	{
2257 2258
	  fputs (" DELIM=", dumpfile);
	  show_expr (i->delim);
2259 2260 2261
	}
      if (i->pad)
	{
2262 2263
	  fputs (" PAD=", dumpfile);
	  show_expr (i->pad);
2264
	}
2265 2266
      if (i->convert)
	{
2267 2268
	  fputs (" CONVERT=", dumpfile);
	  show_expr (i->convert);
2269
	}
Jerry DeLisle committed
2270 2271
      if (i->asynchronous)
	{
2272 2273
	  fputs (" ASYNCHRONOUS=", dumpfile);
	  show_expr (i->asynchronous);
Jerry DeLisle committed
2274 2275 2276
	}
      if (i->decimal)
	{
2277 2278
	  fputs (" DECIMAL=", dumpfile);
	  show_expr (i->decimal);
Jerry DeLisle committed
2279 2280 2281
	}
      if (i->encoding)
	{
2282 2283
	  fputs (" ENCODING=", dumpfile);
	  show_expr (i->encoding);
Jerry DeLisle committed
2284 2285 2286
	}
      if (i->pending)
	{
2287 2288
	  fputs (" PENDING=", dumpfile);
	  show_expr (i->pending);
Jerry DeLisle committed
2289 2290 2291
	}
      if (i->round)
	{
2292 2293
	  fputs (" ROUND=", dumpfile);
	  show_expr (i->round);
Jerry DeLisle committed
2294 2295 2296
	}
      if (i->sign)
	{
2297 2298
	  fputs (" SIGN=", dumpfile);
	  show_expr (i->sign);
Jerry DeLisle committed
2299 2300 2301
	}
      if (i->size)
	{
2302 2303
	  fputs (" SIZE=", dumpfile);
	  show_expr (i->size);
Jerry DeLisle committed
2304 2305 2306
	}
      if (i->id)
	{
2307 2308
	  fputs (" ID=", dumpfile);
	  show_expr (i->id);
Jerry DeLisle committed
2309
	}
2310 2311

      if (i->err != NULL)
2312
	fprintf (dumpfile, " ERR=%d", i->err->value);
2313 2314 2315
      break;

    case EXEC_IOLENGTH:
2316
      fputs ("IOLENGTH ", dumpfile);
2317
      show_expr (c->expr1);
2318
      goto show_dt_code;
2319 2320 2321
      break;

    case EXEC_READ:
2322
      fputs ("READ", dumpfile);
2323 2324 2325
      goto show_dt;

    case EXEC_WRITE:
2326
      fputs ("WRITE", dumpfile);
2327 2328 2329 2330 2331

    show_dt:
      dt = c->ext.dt;
      if (dt->io_unit)
	{
2332 2333
	  fputs (" UNIT=", dumpfile);
	  show_expr (dt->io_unit);
2334 2335 2336 2337
	}

      if (dt->format_expr)
	{
2338 2339
	  fputs (" FMT=", dumpfile);
	  show_expr (dt->format_expr);
2340 2341 2342
	}

      if (dt->format_label != NULL)
2343
	fprintf (dumpfile, " FMT=%d", dt->format_label->value);
2344
      if (dt->namelist)
2345
	fprintf (dumpfile, " NML=%s", dt->namelist->name);
2346 2347 2348

      if (dt->iomsg)
	{
2349 2350
	  fputs (" IOMSG=", dumpfile);
	  show_expr (dt->iomsg);
2351
	}
2352 2353
      if (dt->iostat)
	{
2354 2355
	  fputs (" IOSTAT=", dumpfile);
	  show_expr (dt->iostat);
2356 2357 2358
	}
      if (dt->size)
	{
2359 2360
	  fputs (" SIZE=", dumpfile);
	  show_expr (dt->size);
2361 2362 2363
	}
      if (dt->rec)
	{
2364 2365
	  fputs (" REC=", dumpfile);
	  show_expr (dt->rec);
2366 2367 2368
	}
      if (dt->advance)
	{
2369 2370
	  fputs (" ADVANCE=", dumpfile);
	  show_expr (dt->advance);
2371
	}
Jerry DeLisle committed
2372 2373
      if (dt->id)
	{
2374 2375
	  fputs (" ID=", dumpfile);
	  show_expr (dt->id);
Jerry DeLisle committed
2376 2377 2378
	}
      if (dt->pos)
	{
2379 2380
	  fputs (" POS=", dumpfile);
	  show_expr (dt->pos);
Jerry DeLisle committed
2381 2382 2383
	}
      if (dt->asynchronous)
	{
2384 2385
	  fputs (" ASYNCHRONOUS=", dumpfile);
	  show_expr (dt->asynchronous);
Jerry DeLisle committed
2386 2387 2388
	}
      if (dt->blank)
	{
2389 2390
	  fputs (" BLANK=", dumpfile);
	  show_expr (dt->blank);
Jerry DeLisle committed
2391 2392 2393
	}
      if (dt->decimal)
	{
2394 2395
	  fputs (" DECIMAL=", dumpfile);
	  show_expr (dt->decimal);
Jerry DeLisle committed
2396 2397 2398
	}
      if (dt->delim)
	{
2399 2400
	  fputs (" DELIM=", dumpfile);
	  show_expr (dt->delim);
Jerry DeLisle committed
2401 2402 2403
	}
      if (dt->pad)
	{
2404 2405
	  fputs (" PAD=", dumpfile);
	  show_expr (dt->pad);
Jerry DeLisle committed
2406 2407 2408
	}
      if (dt->round)
	{
2409 2410
	  fputs (" ROUND=", dumpfile);
	  show_expr (dt->round);
Jerry DeLisle committed
2411 2412 2413
	}
      if (dt->sign)
	{
2414 2415
	  fputs (" SIGN=", dumpfile);
	  show_expr (dt->sign);
Jerry DeLisle committed
2416
	}
2417

2418 2419
    show_dt_code:
      for (c = c->block->next; c; c = c->next)
2420
	show_code_node (level + (c->next != NULL), c);
2421
      return;
2422 2423

    case EXEC_TRANSFER:
2424
      fputs ("TRANSFER ", dumpfile);
2425
      show_expr (c->expr1);
2426 2427 2428
      break;

    case EXEC_DT_END:
2429
      fputs ("DT_END", dumpfile);
2430 2431 2432
      dt = c->ext.dt;

      if (dt->err != NULL)
2433
	fprintf (dumpfile, " ERR=%d", dt->err->value);
2434
      if (dt->end != NULL)
2435
	fprintf (dumpfile, " END=%d", dt->end->value);
2436
      if (dt->eor != NULL)
2437
	fprintf (dumpfile, " EOR=%d", dt->eor->value);
2438 2439
      break;

2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451
    case EXEC_OACC_PARALLEL_LOOP:
    case EXEC_OACC_PARALLEL:
    case EXEC_OACC_KERNELS_LOOP:
    case EXEC_OACC_KERNELS:
    case EXEC_OACC_DATA:
    case EXEC_OACC_HOST_DATA:
    case EXEC_OACC_LOOP:
    case EXEC_OACC_UPDATE:
    case EXEC_OACC_WAIT:
    case EXEC_OACC_CACHE:
    case EXEC_OACC_ENTER_DATA:
    case EXEC_OACC_EXIT_DATA:
2452
    case EXEC_OMP_ATOMIC:
2453 2454
    case EXEC_OMP_CANCEL:
    case EXEC_OMP_CANCELLATION_POINT:
2455 2456 2457 2458
    case EXEC_OMP_BARRIER:
    case EXEC_OMP_CRITICAL:
    case EXEC_OMP_FLUSH:
    case EXEC_OMP_DO:
2459
    case EXEC_OMP_DO_SIMD:
2460 2461 2462 2463
    case EXEC_OMP_MASTER:
    case EXEC_OMP_ORDERED:
    case EXEC_OMP_PARALLEL:
    case EXEC_OMP_PARALLEL_DO:
2464
    case EXEC_OMP_PARALLEL_DO_SIMD:
2465 2466 2467
    case EXEC_OMP_PARALLEL_SECTIONS:
    case EXEC_OMP_PARALLEL_WORKSHARE:
    case EXEC_OMP_SECTIONS:
2468
    case EXEC_OMP_SIMD:
2469
    case EXEC_OMP_SINGLE:
2470
    case EXEC_OMP_TASK:
2471
    case EXEC_OMP_TASKGROUP:
2472
    case EXEC_OMP_TASKWAIT:
2473
    case EXEC_OMP_TASKYIELD:
2474
    case EXEC_OMP_WORKSHARE:
2475
      show_omp_node (level, c);
2476 2477
      break;

2478
    default:
2479
      gfc_internal_error ("show_code_node(): Bad statement code");
2480 2481 2482 2483
    }
}


2484
/* Show an equivalence chain.  */
2485

2486 2487
static void
show_equiv (gfc_equiv *eq)
2488 2489
{
  show_indent ();
2490
  fputs ("Equivalence: ", dumpfile);
2491 2492
  while (eq)
    {
2493
      show_expr (eq->expr);
2494 2495
      eq = eq->eq;
      if (eq)
2496
	fputs (", ", dumpfile);
2497 2498 2499
    }
}

2500

2501 2502
/* Show a freakin' whole namespace.  */

2503 2504
static void
show_namespace (gfc_namespace *ns)
2505 2506 2507
{
  gfc_interface *intr;
  gfc_namespace *save;
2508
  int op;
2509
  gfc_equiv *eq;
2510 2511
  int i;

2512
  gcc_assert (ns);
2513 2514 2515
  save = gfc_current_ns;

  show_indent ();
2516
  fputs ("Namespace:", dumpfile);
2517

2518 2519
  i = 0;
  do
2520
    {
2521 2522 2523 2524 2525 2526 2527 2528 2529 2530
      int l = i;
      while (i < GFC_LETTERS - 1
	     && gfc_compare_types (&ns->default_type[i+1],
				   &ns->default_type[l]))
	i++;

      if (i > l)
	fprintf (dumpfile, " %c-%c: ", l+'A', i+'A');
      else
	fprintf (dumpfile, " %c: ", l+'A');
2531

2532 2533 2534
      show_typespec(&ns->default_type[l]);
      i++;
    } while (i < GFC_LETTERS);
2535

2536 2537 2538 2539 2540
  if (ns->proc_name != NULL)
    {
      show_indent ();
      fprintf (dumpfile, "procedure name = %s", ns->proc_name->name);
    }
2541

2542 2543 2544
  ++show_level;
  gfc_current_ns = ns;
  gfc_traverse_symtree (ns->common_root, show_common);
2545

2546
  gfc_traverse_symtree (ns->sym_root, show_symtree);
2547

2548 2549 2550 2551 2552 2553
  for (op = GFC_INTRINSIC_BEGIN; op != GFC_INTRINSIC_END; op++)
    {
      /* User operator interfaces */
      intr = ns->op[op];
      if (intr == NULL)
	continue;
2554

2555 2556 2557
      show_indent ();
      fprintf (dumpfile, "Operator interfaces for %s:",
	       gfc_op2string ((gfc_intrinsic_op) op));
2558

2559 2560 2561
      for (; intr; intr = intr->next)
	fprintf (dumpfile, " %s", intr->sym->name);
    }
2562

2563 2564 2565 2566 2567
  if (ns->uop_root != NULL)
    {
      show_indent ();
      fputs ("User operators:\n", dumpfile);
      gfc_traverse_user_op (ns, show_uop);
2568
    }
2569 2570
  
  for (eq = ns->equiv; eq; eq = eq->next)
2571
    show_equiv (eq);
2572

2573 2574 2575 2576 2577 2578 2579 2580
  if (ns->oacc_declare_clauses)
    {
      /* Dump !$ACC DECLARE clauses.  */
      show_indent ();
      fprintf (dumpfile, "!$ACC DECLARE");
      show_omp_clauses (ns->oacc_declare_clauses);
    }

2581
  fputc ('\n', dumpfile);
2582 2583
  show_indent ();
  fputs ("code:", dumpfile);
2584
  show_code (show_level, ns->code);
2585
  --show_level;
2586 2587 2588

  for (ns = ns->contained; ns; ns = ns->sibling)
    {
2589 2590
      fputs ("\nCONTAINS\n", dumpfile);
      ++show_level;
2591
      show_namespace (ns);
2592
      --show_level;
2593 2594
    }

2595
  fputc ('\n', dumpfile);
2596 2597
  gfc_current_ns = save;
}
2598 2599 2600 2601 2602 2603 2604 2605 2606 2607


/* Main function for dumping a parse tree.  */

void
gfc_dump_parse_tree (gfc_namespace *ns, FILE *file)
{
  dumpfile = file;
  show_namespace (ns);
}
2608