1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
/* Prove equivalence of modes.
Copyright (C) 2001-2023 J. Marcel van der Veer.
Copyright (C) 2025 Jose E. Marchesi.
Original implementation by J. Marcel van der Veer.
Adapted for GCC by Jose E. Marchesi.
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 Software Foundation; either version 3, or (at your option)
any later version.
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.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "a68.h"
/* Routines for establishing equivalence of modes.
After I made this mode equivalencer (in 1993), I found:
Algol Bulletin 30.3.3 C.H.A. Koster: On infinite modes, 86-89 [1969],
which essentially concurs with this test on mode equivalence I wrote.
It is elementary logic anyway: prove equivalence, assuming equivalence. */
/* Forward declarations of some of the functions defined below. */
static bool are_modes_equivalent (MOID_T * a, MOID_T * b);
/* Whether packs are equivalent, same sequence of equivalence modes. */
static bool
are_packs_equivalent (PACK_T *s, PACK_T *t,
bool compare_names = true)
{
for (; s != NO_PACK && t != NO_PACK; s = s->next, t = t->next)
{
if (!are_modes_equivalent (MOID (s), MOID (t)))
return false;
if (compare_names)
{
if (TEXT (s) != TEXT (t)
&& TEXT (s) != NO_TEXT
&& TEXT (t) != NO_TEXT
&& strcmp (TEXT (s), TEXT (t)) != 0)
return false;
}
}
return s == NO_PACK && t == NO_PACK;
}
/* Whether packs are subsets. */
static bool
is_united_subset (PACK_T *s, PACK_T *t)
{
/* For all modes in 's' there must be an equivalent in 't'. */
for (PACK_T *p = s; p != NO_PACK; p = p->next)
{
bool f = false;
for (PACK_T *q = t; q != NO_PACK && !f; q = q->next)
f = are_modes_equivalent (MOID (p), MOID (q));
if (!f)
return false;
}
return true;
}
/* Whether packs are subsets. */
static bool
are_united_packs_equivalent (PACK_T *s, PACK_T *t)
{
return is_united_subset (s, t) && is_united_subset (t, s);
}
/* Whether moids A and B are structurally equivalent. */
static bool
are_modes_equivalent (MOID_T * a, MOID_T * b)
{
/* First lets try some cheap heuristics. */
if (a == NO_MOID || b == NO_MOID)
/* Modes can be NO_MOID in partial argument lists. */
return false;
else if (a == M_ERROR || b == M_ERROR)
return false;
else if (a == b)
return true;
else if (ATTRIBUTE (a) != ATTRIBUTE (b))
return false;
else if (DIM (a) != DIM (b))
return false;
else if (IS (a, STANDARD))
return (a == b);
else if (EQUIVALENT (a) == b || EQUIVALENT (b) == a)
return true;
else if (a68_is_postulated_pair (A68 (top_postulate), a, b)
|| a68_is_postulated_pair (A68 (top_postulate), b, a))
return true;
else if (IS (a, INDICANT))
{
if (NODE (a) == NO_NODE || NODE (b) == NO_NODE)
return false;
else
return (NODE (a) == NODE (b)
|| strcmp (NSYMBOL (NODE (a)), NSYMBOL (NODE (b))) == 0);
}
/* Investigate structure. */
/* We now know that 'a' and 'b' have same attribute, dimension, ... */
if (IS (a, REF_SYMBOL))
/* REF MODE */
return are_modes_equivalent (a->sub, b->sub);
else if (IS (a, ROW_SYMBOL))
/* [] MODE */
return are_modes_equivalent (a->sub, b->sub);
else if (IS (a, FLEX_SYMBOL))
/* FLEX [...] MODE */
return are_modes_equivalent (a->sub, b->sub);
else if (IS (a, STRUCT_SYMBOL))
{
/* STRUCT (...) */
POSTULATE_T *save = A68 (top_postulate);
a68_make_postulate (&A68 (top_postulate), a, b);
bool z = are_packs_equivalent (PACK (a), PACK (b));
a68_free_postulate_list (A68 (top_postulate), save);
A68 (top_postulate) = save;
return z;
}
else if (IS (a, UNION_SYMBOL))
/* UNION (...) */
return are_united_packs_equivalent (PACK (a), PACK (b));
else if (IS (a, PROC_SYMBOL) && PACK (a) == NO_PACK && PACK (b) == NO_PACK)
/* PROC MOID */
return are_modes_equivalent (a->sub, b->sub);
else if (IS (a, PROC_SYMBOL) && PACK (a) != NO_PACK && PACK (b) != NO_PACK)
{
/* PROC (...) MOID */
POSTULATE_T *save = A68 (top_postulate);
a68_make_postulate (&A68 (top_postulate), a, b);
bool z = are_modes_equivalent (a->sub, b->sub);
if (z)
z = are_packs_equivalent (PACK (a), PACK (b),
false /* compare_names */);
a68_free_postulate_list (A68 (top_postulate), save);
A68 (top_postulate) = save;
return z;
}
else if (IS (a, SERIES_MODE) || IS (a, STOWED_MODE))
/* Modes occurring in displays. */
return are_packs_equivalent (PACK (a), PACK (b));
return false;
}
//! @brief Whether two modes are structurally equivalent.
bool
a68_prove_moid_equivalence (MOID_T *p, MOID_T *q)
{
// Prove two modes to be equivalent under assumption that they indeed are.
POSTULATE_T *save = A68 (top_postulate);
bool z = are_modes_equivalent (p, q);
a68_free_postulate_list (A68 (top_postulate), save);
A68 (top_postulate) = save;
return z;
}
|