gcc config
[prop.git] / prop-src / trs3.cc
blob5cb68bf0cbcc18126e623dd52801db4ecb0224a2
1 ///////////////////////////////////////////////////////////////////////////////
2 // This file is generated automatically using Prop (version 2.3.6),
3 // last updated on Nov 2, 1999.
4 // The original source file is "trs3.pcc".
5 ///////////////////////////////////////////////////////////////////////////////
7 #define PROP_TUPLE2_USED
8 #include <propdefs.h>
9 #line 1 "trs3.pcc"
10 ///////////////////////////////////////////////////////////////////////////////
12 // These are the routines for code generation after partial evaluation
14 ///////////////////////////////////////////////////////////////////////////////
15 #include <iostream>
16 #include "trs.h"
17 #include "ir.h"
18 #include "ast.h"
19 #include "type.h"
20 #include "list.h"
21 #include "rwgen.h"
23 ///////////////////////////////////////////////////////////////////////////////
25 // Method to clear statistics
27 ///////////////////////////////////////////////////////////////////////////////
28 void TRS::clear_statistics()
30 number_of_specializations = 0;
33 ///////////////////////////////////////////////////////////////////////////////
35 // Method to print statistics
37 ///////////////////////////////////////////////////////////////////////////////
38 void TRS::print_report(std::ostream& log) const
39 { print(log);
41 log << "Number of specializations = " << number_of_specializations
42 << "\n\nSpecializations follow:\n\n";
44 print_specializations(log);
47 ///////////////////////////////////////////////////////////////////////////////
49 // Method to print the specializations
51 ///////////////////////////////////////////////////////////////////////////////
52 void TRS::print_specializations(std::ostream& log) const
53 { for (Rule r = 0; r < number_of_rules; r++)
54 { MatchRule rule = rule_map[r];
55 for (int i = 0; i < num_var_map[r]; i++)
56 { if (residue_map[r][i] ==
57 #line 47 "trs3.pcc"
58 #line 47 "trs3.pcc"
59 nil_1_
60 #line 47 "trs3.pcc"
61 #line 47 "trs3.pcc"
62 ) continue;
63 for_each (Residue, res, residue_map[r][i])
64 { log << "line " << rule->begin_line << ": " << rule << ' ';
65 print(log,rhs_map[r]); log << '\n';
66 log << "\twhen " << var_pat_map[r][i] << " is in state:\n";
67 treeauto.print_state(log,res._1);
68 log << "\toptimize rhs to ";
69 print(log,res._2);
70 log << "\n\n";
76 ///////////////////////////////////////////////////////////////////////////////
78 // Method to generate residue
80 ///////////////////////////////////////////////////////////////////////////////
81 void TRS::generate_residue(Rule rule, int arity, State state, Term rhs)
82 { number_of_specializations++;
83 // print_residue(rule,rhs);
84 residue_map[rule][arity] =
85 #line 69 "trs3.pcc"
86 #line 69 "trs3.pcc"
87 list_1_(mkTuple2(state,rhs),residue_map[rule][arity])
88 #line 69 "trs3.pcc"
89 #line 69 "trs3.pcc"
93 ///////////////////////////////////////////////////////////////////////////////
95 // Method to translate a term into code
97 ///////////////////////////////////////////////////////////////////////////////
98 Exp TRS::make_exp(Term term) const
100 #line 78 "trs3.pcc"
101 #line 98 "trs3.pcc"
103 switch (term->tag__) {
104 case a_Term::tag_CONSterm: {
105 if (((Term_CONSterm *)term)->_2) {
106 switch (((Term_CONSterm *)term)->_3) {
107 case 0: {
108 #line 80 "trs3.pcc"
109 return CONSexp(((Term_CONSterm *)term)->_2,
110 #line 80 "trs3.pcc"
111 #line 80 "trs3.pcc"
112 nil_1_
113 #line 80 "trs3.pcc"
114 #line 80 "trs3.pcc"
115 ,NOexp);
116 #line 80 "trs3.pcc"
117 } break;
118 case 1: {
119 #line 81 "trs3.pcc"
120 return CONSexp(((Term_CONSterm *)term)->_2,
121 #line 81 "trs3.pcc"
122 #line 81 "trs3.pcc"
123 nil_1_
124 #line 81 "trs3.pcc"
125 #line 81 "trs3.pcc"
126 ,make_exp(((Term_CONSterm *)term)->_4[0]));
127 #line 81 "trs3.pcc"
128 } break;
129 case 2: {
130 if (
131 #line 82 "trs3.pcc"
132 is_list_constructor(((Term_CONSterm *)term)->_2)
133 #line 82 "trs3.pcc"
136 #line 83 "trs3.pcc"
137 Exps heads =
138 #line 83 "trs3.pcc"
139 #line 83 "trs3.pcc"
140 nil_1_
141 #line 83 "trs3.pcc"
142 #line 83 "trs3.pcc"
144 Term t = term;
146 #line 85 "trs3.pcc"
147 #line 91 "trs3.pcc"
149 for (;;) {
150 switch (t->tag__) {
151 case a_Term::tag_CONSterm: {
152 switch (((Term_CONSterm *)t)->_3) {
153 case 0: {
154 if (
155 #line 88 "trs3.pcc"
156 is_list_constructor(((Term_CONSterm *)t)->_2)
157 #line 88 "trs3.pcc"
160 #line 89 "trs3.pcc"
161 return LISTexp(((Term_CONSterm *)term)->_2,((Term_CONSterm *)t)->_2,rev(heads),NOexp);
162 #line 89 "trs3.pcc"
163 } else {
165 L2:;
166 #line 91 "trs3.pcc"
167 return LISTexp(((Term_CONSterm *)term)->_2,NOcons,rev(heads),make_exp(term));
168 #line 91 "trs3.pcc"
170 } break;
171 case 2: {
172 if (
173 #line 86 "trs3.pcc"
174 (((Term_CONSterm *)term)->_1 == ((Term_CONSterm *)t)->_1)
175 #line 86 "trs3.pcc"
178 #line 87 "trs3.pcc"
179 heads =
180 #line 87 "trs3.pcc"
181 #line 87 "trs3.pcc"
182 list_1_(make_exp(((Term_CONSterm *)t)->_4[0]),heads)
183 #line 87 "trs3.pcc"
184 #line 87 "trs3.pcc"
185 ; t = ((Term_CONSterm *)t)->_4[1];
186 #line 87 "trs3.pcc"
187 } else {
188 goto L2; }
189 } break;
190 default: { goto L2; }
192 } break;
193 default: { goto L2; } break;
197 #line 92 "trs3.pcc"
198 #line 92 "trs3.pcc"
201 #line 93 "trs3.pcc"
202 } else {
204 L3:;
205 #line 94 "trs3.pcc"
206 return CONSexp(((Term_CONSterm *)term)->_2,
207 #line 94 "trs3.pcc"
208 #line 94 "trs3.pcc"
209 nil_1_
210 #line 94 "trs3.pcc"
211 #line 94 "trs3.pcc"
213 TUPLEexp(make_exp(((Term_CONSterm *)term)->_3,((Term_CONSterm *)term)->_4)));
214 #line 95 "trs3.pcc"
216 } break;
217 default: { goto L3; }
219 } else {
220 #line 79 "trs3.pcc"
221 return LITERALexp(literal_map[((Term_CONSterm *)term)->_1]);
222 #line 79 "trs3.pcc"
224 } break;
225 case a_Term::tag_VARterm: {
226 #line 96 "trs3.pcc"
227 return ((Term_VARterm *)term)->_3;
228 #line 96 "trs3.pcc"
229 } break;
230 case a_Term::tag_CODEterm: {
231 #line 97 "trs3.pcc"
232 return ((Term_CODEterm *)term)->CODEterm;
233 #line 97 "trs3.pcc"
234 } break;
235 default: {
236 #line 98 "trs3.pcc"
237 bug("TRS::make_exp"); return NOexp;
238 #line 98 "trs3.pcc"
239 } break;
242 #line 99 "trs3.pcc"
243 #line 99 "trs3.pcc"
247 ///////////////////////////////////////////////////////////////////////////////
249 // Method to translate a term into code
251 ///////////////////////////////////////////////////////////////////////////////
252 Exps TRS::make_exp(int n, Term terms[]) const
253 { Exps exps =
254 #line 108 "trs3.pcc"
255 #line 108 "trs3.pcc"
256 nil_1_
257 #line 108 "trs3.pcc"
258 #line 108 "trs3.pcc"
260 for (int i = n - 1; i >= 0; i--)
261 exps =
262 #line 110 "trs3.pcc"
263 #line 110 "trs3.pcc"
264 list_1_(make_exp(terms[i]),exps)
265 #line 110 "trs3.pcc"
266 #line 110 "trs3.pcc"
268 return exps;
271 ///////////////////////////////////////////////////////////////////////////////
273 // Method to emit replacement code for the rhs, taking into account
274 // of the specializations.
276 ///////////////////////////////////////////////////////////////////////////////
277 Bool TRS::gen_replacement(CodeGen& C, Rule r, Exp default_rhs)
278 { int levels = 0;
279 MatchRule rule = rule_map[r];
280 Bool optimized = false;
282 for (int i = 0; i < num_var_map[r]; i++)
283 { Residues residues = residue_map[r][i];
284 if (residues !=
285 #line 127 "trs3.pcc"
286 #line 127 "trs3.pcc"
287 nil_1_
288 #line 127 "trs3.pcc"
289 #line 127 "trs3.pcc"
291 { levels++;
292 optimized = true;
293 if (levels == 1) { C.pr("%^%t repl__;", rule->ty, ""); }
294 Pat pat = var_pat_map[r][i];
295 Exp pat_exp = pat->selector;
296 Ty pat_ty = pat->ty;
297 Id state_var = compiler.gen_get_rewrite_state(pat_ty,pat_exp);
298 C.pr("%^switch (%s) {%+", state_var);
299 for_each(Residue, res, residues)
300 { C.pr("%^case %i: repl__ = %e; break;", res._1, make_exp(res._2));
302 C.pr("%^default: ");
305 if (levels > 0)
306 { if (optimized_map[r] != NOexp) default_rhs = optimized_map[r];
307 C.pr("%^repl__ = %e; break;", default_rhs);
308 for (int j = 0; j < levels; j++)
310 C.pr("%-%^}");
312 } else if (optimized_map[r] != NOexp)
313 { C.pr("%^%t repl__ = %e;", rule->ty, "", optimized_map[r]);
314 optimized = true;
316 return optimized;
318 #line 155 "trs3.pcc"
320 ------------------------------- Statistics -------------------------------
321 Merge matching rules = yes
322 Number of DFA nodes merged = 17
323 Number of ifs generated = 4
324 Number of switches generated = 4
325 Number of labels = 2
326 Number of gotos = 4
327 Adaptive matching = enabled
328 Fast string matching = disabled
329 Inline downcasts = enabled
330 --------------------------------------------------------------------------