Mercurial > hg > CbC > CbC_gcc
comparison gcc/fortran/module.c @ 131:84e7813d76e9
gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 07:37:49 +0900 |
parents | 04ced10e8804 |
children | 1830386684a0 |
comparison
equal
deleted
inserted
replaced
111:04ced10e8804 | 131:84e7813d76e9 |
---|---|
1 /* Handle modules, which amounts to loading and saving symbols and | 1 /* Handle modules, which amounts to loading and saving symbols and |
2 their attendant structures. | 2 their attendant structures. |
3 Copyright (C) 2000-2017 Free Software Foundation, Inc. | 3 Copyright (C) 2000-2018 Free Software Foundation, Inc. |
4 Contributed by Andy Vaught | 4 Contributed by Andy Vaught |
5 | 5 |
6 This file is part of GCC. | 6 This file is part of GCC. |
7 | 7 |
8 GCC is free software; you can redistribute it and/or modify it under | 8 GCC is free software; you can redistribute it and/or modify it under |
141 }; | 141 }; |
142 | 142 |
143 typedef struct pointer_info | 143 typedef struct pointer_info |
144 { | 144 { |
145 BBT_HEADER (pointer_info); | 145 BBT_HEADER (pointer_info); |
146 int integer; | 146 HOST_WIDE_INT integer; |
147 pointer_t type; | 147 pointer_t type; |
148 | 148 |
149 /* The first component of each member of the union is the pointer | 149 /* The first component of each member of the union is the pointer |
150 being stored. */ | 150 being stored. */ |
151 | 151 |
366 | 366 |
367 /* Given an integer during reading, find it in the pointer_info tree, | 367 /* Given an integer during reading, find it in the pointer_info tree, |
368 creating the node if not found. */ | 368 creating the node if not found. */ |
369 | 369 |
370 static pointer_info * | 370 static pointer_info * |
371 get_integer (int integer) | 371 get_integer (HOST_WIDE_INT integer) |
372 { | 372 { |
373 pointer_info *p, t; | 373 pointer_info *p, t; |
374 int c; | 374 int c; |
375 | 375 |
376 t.integer = integer; | 376 t.integer = integer; |
466 the reference has been actually stored, or nonzero if the reference | 466 the reference has been actually stored, or nonzero if the reference |
467 must be fixed later (i.e., associate_integer_pointer must be called | 467 must be fixed later (i.e., associate_integer_pointer must be called |
468 sometime later. Returns the pointer_info structure. */ | 468 sometime later. Returns the pointer_info structure. */ |
469 | 469 |
470 static pointer_info * | 470 static pointer_info * |
471 add_fixup (int integer, void *gp) | 471 add_fixup (HOST_WIDE_INT integer, void *gp) |
472 { | 472 { |
473 pointer_info *p; | 473 pointer_info *p; |
474 fixup_t *f; | 474 fixup_t *f; |
475 char **cp; | 475 char **cp; |
476 | 476 |
1143 number to be preserved (this can't be done by a decimal | 1143 number to be preserved (this can't be done by a decimal |
1144 representation). Worry about that later. TODO! */ | 1144 representation). Worry about that later. TODO! */ |
1145 | 1145 |
1146 #define MAX_ATOM_SIZE 100 | 1146 #define MAX_ATOM_SIZE 100 |
1147 | 1147 |
1148 static int atom_int; | 1148 static HOST_WIDE_INT atom_int; |
1149 static char *atom_string, atom_name[MAX_ATOM_SIZE]; | 1149 static char *atom_string, atom_name[MAX_ATOM_SIZE]; |
1150 | 1150 |
1151 | 1151 |
1152 /* Report problems with a module. Error reporting is not very | 1152 /* Report problems with a module. Error reporting is not very |
1153 elaborate, since this sorts of errors shouldn't really happen. | 1153 elaborate, since this sorts of errors shouldn't really happen. |
1273 atom_string = XRESIZEVEC (char, atom_string, len + 1); | 1273 atom_string = XRESIZEVEC (char, atom_string, len + 1); |
1274 atom_string[len] = '\0'; /* C-style string for debug purposes. */ | 1274 atom_string[len] = '\0'; /* C-style string for debug purposes. */ |
1275 } | 1275 } |
1276 | 1276 |
1277 | 1277 |
1278 /* Parse a small integer. */ | 1278 /* Parse an integer. Should fit in a HOST_WIDE_INT. */ |
1279 | 1279 |
1280 static void | 1280 static void |
1281 parse_integer (int c) | 1281 parse_integer (int c) |
1282 { | 1282 { |
1283 atom_int = c - '0'; | 1283 atom_int = c - '0'; |
1290 module_unget_char (); | 1290 module_unget_char (); |
1291 break; | 1291 break; |
1292 } | 1292 } |
1293 | 1293 |
1294 atom_int = 10 * atom_int + c - '0'; | 1294 atom_int = 10 * atom_int + c - '0'; |
1295 if (atom_int > 99999999) | |
1296 bad_module ("Integer overflow"); | |
1297 } | 1295 } |
1298 | 1296 |
1299 } | 1297 } |
1300 | 1298 |
1301 | 1299 |
1633 the file really isn't meant to be read by people anyway. */ | 1631 the file really isn't meant to be read by people anyway. */ |
1634 | 1632 |
1635 static void | 1633 static void |
1636 write_atom (atom_type atom, const void *v) | 1634 write_atom (atom_type atom, const void *v) |
1637 { | 1635 { |
1638 char buffer[20]; | 1636 char buffer[32]; |
1639 | 1637 |
1640 /* Workaround -Wmaybe-uninitialized false positive during | 1638 /* Workaround -Wmaybe-uninitialized false positive during |
1641 profiledbootstrap by initializing them. */ | 1639 profiledbootstrap by initializing them. */ |
1642 int i = 0, len; | 1640 int len; |
1641 HOST_WIDE_INT i = 0; | |
1643 const char *p; | 1642 const char *p; |
1644 | 1643 |
1645 switch (atom) | 1644 switch (atom) |
1646 { | 1645 { |
1647 case ATOM_STRING: | 1646 case ATOM_STRING: |
1656 case ATOM_RPAREN: | 1655 case ATOM_RPAREN: |
1657 p = ")"; | 1656 p = ")"; |
1658 break; | 1657 break; |
1659 | 1658 |
1660 case ATOM_INTEGER: | 1659 case ATOM_INTEGER: |
1661 i = *((const int *) v); | 1660 i = *((const HOST_WIDE_INT *) v); |
1662 if (i < 0) | 1661 |
1663 gfc_internal_error ("write_atom(): Writing negative integer"); | 1662 snprintf (buffer, sizeof (buffer), HOST_WIDE_INT_PRINT_DEC, i); |
1664 | |
1665 sprintf (buffer, "%d", i); | |
1666 p = buffer; | 1663 p = buffer; |
1667 break; | 1664 break; |
1668 | 1665 |
1669 default: | 1666 default: |
1670 gfc_internal_error ("write_atom(): Trying to write dab atom"); | 1667 gfc_internal_error ("write_atom(): Trying to write dab atom"); |
1768 | 1765 |
1769 static void | 1766 static void |
1770 mio_integer (int *ip) | 1767 mio_integer (int *ip) |
1771 { | 1768 { |
1772 if (iomode == IO_OUTPUT) | 1769 if (iomode == IO_OUTPUT) |
1773 write_atom (ATOM_INTEGER, ip); | 1770 { |
1771 HOST_WIDE_INT hwi = *ip; | |
1772 write_atom (ATOM_INTEGER, &hwi); | |
1773 } | |
1774 else | 1774 else |
1775 { | 1775 { |
1776 require_atom (ATOM_INTEGER); | 1776 require_atom (ATOM_INTEGER); |
1777 *ip = atom_int; | 1777 *ip = atom_int; |
1778 } | 1778 } |
1779 } | 1779 } |
1780 | 1780 |
1781 static void | |
1782 mio_hwi (HOST_WIDE_INT *hwi) | |
1783 { | |
1784 if (iomode == IO_OUTPUT) | |
1785 write_atom (ATOM_INTEGER, hwi); | |
1786 else | |
1787 { | |
1788 require_atom (ATOM_INTEGER); | |
1789 *hwi = atom_int; | |
1790 } | |
1791 } | |
1792 | |
1781 | 1793 |
1782 /* Read or write a gfc_intrinsic_op value. */ | 1794 /* Read or write a gfc_intrinsic_op value. */ |
1783 | 1795 |
1784 static void | 1796 static void |
1785 mio_intrinsic_op (gfc_intrinsic_op* op) | 1797 mio_intrinsic_op (gfc_intrinsic_op* op) |
1786 { | 1798 { |
1787 /* FIXME: Would be nicer to do this via the operators symbolic name. */ | 1799 /* FIXME: Would be nicer to do this via the operators symbolic name. */ |
1788 if (iomode == IO_OUTPUT) | 1800 if (iomode == IO_OUTPUT) |
1789 { | 1801 { |
1790 int converted = (int) *op; | 1802 HOST_WIDE_INT converted = (HOST_WIDE_INT) *op; |
1791 write_atom (ATOM_INTEGER, &converted); | 1803 write_atom (ATOM_INTEGER, &converted); |
1792 } | 1804 } |
1793 else | 1805 else |
1794 { | 1806 { |
1795 require_atom (ATOM_INTEGER); | 1807 require_atom (ATOM_INTEGER); |
2717 and cast it to/from an integer. */ | 2729 and cast it to/from an integer. */ |
2718 if (iomode == IO_OUTPUT) | 2730 if (iomode == IO_OUTPUT) |
2719 { | 2731 { |
2720 for (i = 0; i < ar->dimen; i++) | 2732 for (i = 0; i < ar->dimen; i++) |
2721 { | 2733 { |
2722 int tmp = (int)ar->dimen_type[i]; | 2734 HOST_WIDE_INT tmp = (HOST_WIDE_INT)ar->dimen_type[i]; |
2723 write_atom (ATOM_INTEGER, &tmp); | 2735 write_atom (ATOM_INTEGER, &tmp); |
2724 } | 2736 } |
2725 } | 2737 } |
2726 else | 2738 else |
2727 { | 2739 { |
2754 pointer_info *p; | 2766 pointer_info *p; |
2755 | 2767 |
2756 if (iomode == IO_OUTPUT) | 2768 if (iomode == IO_OUTPUT) |
2757 { | 2769 { |
2758 p = get_pointer (*((char **) gp)); | 2770 p = get_pointer (*((char **) gp)); |
2759 write_atom (ATOM_INTEGER, &p->integer); | 2771 HOST_WIDE_INT hwi = p->integer; |
2772 write_atom (ATOM_INTEGER, &hwi); | |
2760 } | 2773 } |
2761 else | 2774 else |
2762 { | 2775 { |
2763 require_atom (ATOM_INTEGER); | 2776 require_atom (ATOM_INTEGER); |
2764 p = add_fixup (atom_int, gp); | 2777 p = add_fixup (atom_int, gp); |
2792 | 2805 |
2793 static void | 2806 static void |
2794 mio_component (gfc_component *c, int vtype) | 2807 mio_component (gfc_component *c, int vtype) |
2795 { | 2808 { |
2796 pointer_info *p; | 2809 pointer_info *p; |
2797 int n; | |
2798 | 2810 |
2799 mio_lparen (); | 2811 mio_lparen (); |
2800 | 2812 |
2801 if (iomode == IO_OUTPUT) | 2813 if (iomode == IO_OUTPUT) |
2802 { | 2814 { |
2803 p = get_pointer (c); | 2815 p = get_pointer (c); |
2804 mio_integer (&p->integer); | 2816 mio_hwi (&p->integer); |
2805 } | 2817 } |
2806 else | 2818 else |
2807 { | 2819 { |
2808 mio_integer (&n); | 2820 HOST_WIDE_INT n; |
2821 mio_hwi (&n); | |
2809 p = get_integer (n); | 2822 p = get_integer (n); |
2810 associate_integer_pointer (p, c); | 2823 associate_integer_pointer (p, c); |
2811 } | 2824 } |
2812 | 2825 |
2813 if (p->type == P_UNKNOWN) | 2826 if (p->type == P_UNKNOWN) |
2832 || strcmp (c->name, "_hash") == 0) | 2845 || strcmp (c->name, "_hash") == 0) |
2833 mio_expr (&c->initializer); | 2846 mio_expr (&c->initializer); |
2834 | 2847 |
2835 if (c->attr.proc_pointer) | 2848 if (c->attr.proc_pointer) |
2836 mio_typebound_proc (&c->tb); | 2849 mio_typebound_proc (&c->tb); |
2850 | |
2851 c->loc = gfc_current_locus; | |
2837 | 2852 |
2838 mio_rparen (); | 2853 mio_rparen (); |
2839 } | 2854 } |
2840 | 2855 |
2841 | 2856 |
3428 NULL expression. */ | 3443 NULL expression. */ |
3429 | 3444 |
3430 static void | 3445 static void |
3431 mio_expr (gfc_expr **ep) | 3446 mio_expr (gfc_expr **ep) |
3432 { | 3447 { |
3448 HOST_WIDE_INT hwi; | |
3433 gfc_expr *e; | 3449 gfc_expr *e; |
3434 atom_type t; | 3450 atom_type t; |
3435 int flag; | 3451 int flag; |
3436 | 3452 |
3437 mio_lparen (); | 3453 mio_lparen (); |
3642 case BT_LOGICAL: | 3658 case BT_LOGICAL: |
3643 mio_integer (&e->value.logical); | 3659 mio_integer (&e->value.logical); |
3644 break; | 3660 break; |
3645 | 3661 |
3646 case BT_CHARACTER: | 3662 case BT_CHARACTER: |
3647 mio_integer (&e->value.character.length); | 3663 hwi = e->value.character.length; |
3664 mio_hwi (&hwi); | |
3665 e->value.character.length = hwi; | |
3648 e->value.character.string | 3666 e->value.character.string |
3649 = CONST_CAST (gfc_char_t *, | 3667 = CONST_CAST (gfc_char_t *, |
3650 mio_allocated_wide_string (e->value.character.string, | 3668 mio_allocated_wide_string (e->value.character.string, |
3651 e->value.character.length)); | 3669 e->value.character.length)); |
3652 break; | 3670 break; |
4080 minit ("NOTINBRANCH", 1), | 4098 minit ("NOTINBRANCH", 1), |
4081 minit ("SIMDLEN", 2), | 4099 minit ("SIMDLEN", 2), |
4082 minit ("UNIFORM", 3), | 4100 minit ("UNIFORM", 3), |
4083 minit ("LINEAR", 4), | 4101 minit ("LINEAR", 4), |
4084 minit ("ALIGNED", 5), | 4102 minit ("ALIGNED", 5), |
4103 minit ("LINEAR_REF", 33), | |
4104 minit ("LINEAR_VAL", 34), | |
4105 minit ("LINEAR_UVAL", 35), | |
4085 minit (NULL, -1) | 4106 minit (NULL, -1) |
4086 }; | 4107 }; |
4087 | 4108 |
4088 /* Handle !$omp declare simd. */ | 4109 /* Handle !$omp declare simd. */ |
4089 | 4110 |
4122 mio_name (3, omp_declare_simd_clauses); | 4143 mio_name (3, omp_declare_simd_clauses); |
4123 mio_symbol_ref (&n->sym); | 4144 mio_symbol_ref (&n->sym); |
4124 } | 4145 } |
4125 for (n = ods->clauses->lists[OMP_LIST_LINEAR]; n; n = n->next) | 4146 for (n = ods->clauses->lists[OMP_LIST_LINEAR]; n; n = n->next) |
4126 { | 4147 { |
4127 mio_name (4, omp_declare_simd_clauses); | 4148 if (n->u.linear_op == OMP_LINEAR_DEFAULT) |
4149 mio_name (4, omp_declare_simd_clauses); | |
4150 else | |
4151 mio_name (32 + n->u.linear_op, omp_declare_simd_clauses); | |
4128 mio_symbol_ref (&n->sym); | 4152 mio_symbol_ref (&n->sym); |
4129 mio_expr (&n->expr); | 4153 mio_expr (&n->expr); |
4130 } | 4154 } |
4131 for (n = ods->clauses->lists[OMP_LIST_ALIGNED]; n; n = n->next) | 4155 for (n = ods->clauses->lists[OMP_LIST_ALIGNED]; n; n = n->next) |
4132 { | 4156 { |
4163 case 2: mio_expr (&ods->clauses->simdlen_expr); break; | 4187 case 2: mio_expr (&ods->clauses->simdlen_expr); break; |
4164 case 3: | 4188 case 3: |
4165 case 4: | 4189 case 4: |
4166 case 5: | 4190 case 5: |
4167 *ptrs[t - 3] = n = gfc_get_omp_namelist (); | 4191 *ptrs[t - 3] = n = gfc_get_omp_namelist (); |
4192 finish_namelist: | |
4193 n->where = gfc_current_locus; | |
4168 ptrs[t - 3] = &n->next; | 4194 ptrs[t - 3] = &n->next; |
4169 mio_symbol_ref (&n->sym); | 4195 mio_symbol_ref (&n->sym); |
4170 if (t != 3) | 4196 if (t != 3) |
4171 mio_expr (&n->expr); | 4197 mio_expr (&n->expr); |
4172 break; | 4198 break; |
4199 case 33: | |
4200 case 34: | |
4201 case 35: | |
4202 *ptrs[1] = n = gfc_get_omp_namelist (); | |
4203 n->u.linear_op = (enum gfc_omp_linear_op) (t - 32); | |
4204 t = 4; | |
4205 goto finish_namelist; | |
4173 } | 4206 } |
4174 } | 4207 } |
4175 } | 4208 } |
4176 | 4209 |
4177 mio_omp_declare_simd (ns, &ods->next); | 4210 mio_omp_declare_simd (ns, &ods->next); |
4524 { | 4557 { |
4525 gfc_symtree *st; | 4558 gfc_symtree *st; |
4526 /* Decide if we need to load this one or not. */ | 4559 /* Decide if we need to load this one or not. */ |
4527 p = find_use_name_n (name, &i, false); | 4560 p = find_use_name_n (name, &i, false); |
4528 | 4561 |
4529 st = find_symbol (gfc_current_ns->sym_root, | |
4530 name, module_name, 1); | |
4531 | |
4532 if (!p || gfc_find_symbol (p, NULL, 0, &sym)) | 4562 if (!p || gfc_find_symbol (p, NULL, 0, &sym)) |
4533 { | 4563 { |
4534 /* Skip the specific names for these cases. */ | 4564 /* Skip the specific names for these cases. */ |
4535 while (i == 1 && parse_atom () != ATOM_RPAREN); | 4565 while (i == 1 && parse_atom () != ATOM_RPAREN); |
4536 | 4566 |
4537 continue; | 4567 continue; |
4538 } | 4568 } |
4569 | |
4570 st = find_symbol (gfc_current_ns->sym_root, | |
4571 name, module_name, 1); | |
4539 | 4572 |
4540 /* If the symbol exists already and is being USEd without being | 4573 /* If the symbol exists already and is being USEd without being |
4541 in an ONLY clause, do not load a new symtree(11.3.2). */ | 4574 in an ONLY clause, do not load a new symtree(11.3.2). */ |
4542 if (!only_flag && st) | 4575 if (!only_flag && st) |
4543 sym = st->n.sym; | 4576 sym = st->n.sym; |
4756 | 4789 |
4757 mio_lparen (); | 4790 mio_lparen (); |
4758 mio_pool_string (&name); | 4791 mio_pool_string (&name); |
4759 gfc_clear_ts (&ts); | 4792 gfc_clear_ts (&ts); |
4760 mio_typespec (&ts); | 4793 mio_typespec (&ts); |
4761 if (strncmp (name, "operator ", sizeof ("operator ") - 1) == 0) | 4794 if (gfc_str_startswith (name, "operator ")) |
4762 { | 4795 { |
4763 const char *p = name + sizeof ("operator ") - 1; | 4796 const char *p = name + sizeof ("operator ") - 1; |
4764 if (strcmp (p, "+") == 0) | 4797 if (strcmp (p, "+") == 0) |
4765 rop = OMP_REDUCTION_PLUS; | 4798 rop = OMP_REDUCTION_PLUS; |
4766 else if (strcmp (p, "*") == 0) | 4799 else if (strcmp (p, "*") == 0) |
5198 if (p == NULL && strcmp (name, module_name) == 0) | 5231 if (p == NULL && strcmp (name, module_name) == 0) |
5199 p = name; | 5232 p = name; |
5200 | 5233 |
5201 /* Exception: Always import vtabs & vtypes. */ | 5234 /* Exception: Always import vtabs & vtypes. */ |
5202 if (p == NULL && name[0] == '_' | 5235 if (p == NULL && name[0] == '_' |
5203 && (strncmp (name, "__vtab_", 5) == 0 | 5236 && (gfc_str_startswith (name, "__vtab_") |
5204 || strncmp (name, "__vtype_", 6) == 0)) | 5237 || gfc_str_startswith (name, "__vtype_"))) |
5205 p = name; | 5238 p = name; |
5206 | 5239 |
5207 /* Skip symtree nodes not in an ONLY clause, unless there | 5240 /* Skip symtree nodes not in an ONLY clause, unless there |
5208 is an existing symtree loaded from another USE statement. */ | 5241 is an existing symtree loaded from another USE statement. */ |
5209 if (p == NULL) | 5242 if (p == NULL) |
5284 | 5317 |
5285 if (strcmp (name, p) != 0) | 5318 if (strcmp (name, p) != 0) |
5286 sym->attr.use_rename = 1; | 5319 sym->attr.use_rename = 1; |
5287 | 5320 |
5288 if (name[0] != '_' | 5321 if (name[0] != '_' |
5289 || (strncmp (name, "__vtab_", 5) != 0 | 5322 || (!gfc_str_startswith (name, "__vtab_") |
5290 && strncmp (name, "__vtype_", 6) != 0)) | 5323 && !gfc_str_startswith (name, "__vtype_"))) |
5291 sym->attr.use_only = only_flag; | 5324 sym->attr.use_only = only_flag; |
5292 | 5325 |
5293 /* Store the symtree pointing to this symbol. */ | 5326 /* Store the symtree pointing to this symbol. */ |
5294 info->u.rsym.symtree = st; | 5327 info->u.rsym.symtree = st; |
5295 | 5328 |
5944 if (p == NULL) | 5977 if (p == NULL) |
5945 gfc_internal_error ("write_symtree(): Symbol not written"); | 5978 gfc_internal_error ("write_symtree(): Symbol not written"); |
5946 | 5979 |
5947 mio_pool_string (&st->name); | 5980 mio_pool_string (&st->name); |
5948 mio_integer (&st->ambiguous); | 5981 mio_integer (&st->ambiguous); |
5949 mio_integer (&p->integer); | 5982 mio_hwi (&p->integer); |
5950 } | 5983 } |
5951 | 5984 |
5952 | 5985 |
5953 static void | 5986 static void |
5954 write_module (void) | 5987 write_module (void) |
6130 module_fp = gzopen (filename_tmp, "w"); | 6163 module_fp = gzopen (filename_tmp, "w"); |
6131 if (module_fp == NULL) | 6164 if (module_fp == NULL) |
6132 gfc_fatal_error ("Can't open module file %qs for writing at %C: %s", | 6165 gfc_fatal_error ("Can't open module file %qs for writing at %C: %s", |
6133 filename_tmp, xstrerror (errno)); | 6166 filename_tmp, xstrerror (errno)); |
6134 | 6167 |
6168 /* Use lbasename to ensure module files are reproducible regardless | |
6169 of the build path (see the reproducible builds project). */ | |
6135 gzprintf (module_fp, "GFORTRAN module version '%s' created from %s\n", | 6170 gzprintf (module_fp, "GFORTRAN module version '%s' created from %s\n", |
6136 MOD_VERSION, gfc_source_file); | 6171 MOD_VERSION, lbasename (gfc_source_file)); |
6137 | 6172 |
6138 /* Write the module itself. */ | 6173 /* Write the module itself. */ |
6139 iomode = IO_OUTPUT; | 6174 iomode = IO_OUTPUT; |
6140 | 6175 |
6141 init_pi_tree (); | 6176 init_pi_tree (); |