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
10 ///////////////////////////////////////////////////////////////////////////////
12 // These are the routines for code generation after partial evaluation
14 ///////////////////////////////////////////////////////////////////////////////
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
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
] ==
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 ";
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
] =
87 list_1_(mkTuple2(state
,rhs
),residue_map
[rule
][arity
])
93 ///////////////////////////////////////////////////////////////////////////////
95 // Method to translate a term into code
97 ///////////////////////////////////////////////////////////////////////////////
98 Exp
TRS::make_exp(Term term
) const
103 switch (term
->tag__
) {
104 case a_Term::tag_CONSterm
: {
105 if (((Term_CONSterm
*)term
)->_2
) {
106 switch (((Term_CONSterm
*)term
)->_3
) {
109 return CONSexp(((Term_CONSterm
*)term
)->_2
,
120 return CONSexp(((Term_CONSterm
*)term
)->_2
,
126 ,make_exp(((Term_CONSterm
*)term
)->_4
[0]));
132 is_list_constructor(((Term_CONSterm
*)term
)->_2
)
151 case a_Term::tag_CONSterm
: {
152 switch (((Term_CONSterm
*)t
)->_3
) {
156 is_list_constructor(((Term_CONSterm
*)t
)->_2
)
161 return LISTexp(((Term_CONSterm
*)term
)->_2
,((Term_CONSterm
*)t
)->_2
,rev(heads
),NOexp
);
167 return LISTexp(((Term_CONSterm
*)term
)->_2
,NOcons
,rev(heads
),make_exp(term
));
174 (((Term_CONSterm
*)term
)->_1
== ((Term_CONSterm
*)t
)->_1
)
182 list_1_(make_exp(((Term_CONSterm
*)t
)->_4
[0]),heads
)
185 ; t
= ((Term_CONSterm
*)t
)->_4
[1];
190 default: { goto L2
; }
193 default: { goto L2
; } break;
206 return CONSexp(((Term_CONSterm
*)term
)->_2
,
213 TUPLEexp(make_exp(((Term_CONSterm
*)term
)->_3
,((Term_CONSterm
*)term
)->_4
)));
217 default: { goto L3
; }
221 return LITERALexp(literal_map
[((Term_CONSterm
*)term
)->_1
]);
225 case a_Term::tag_VARterm
: {
227 return ((Term_VARterm
*)term
)->_3
;
230 case a_Term::tag_CODEterm
: {
232 return ((Term_CODEterm
*)term
)->CODEterm
;
237 bug("TRS::make_exp"); return NOexp
;
247 ///////////////////////////////////////////////////////////////////////////////
249 // Method to translate a term into code
251 ///////////////////////////////////////////////////////////////////////////////
252 Exps
TRS::make_exp(int n
, Term terms
[]) const
260 for (int i
= n
- 1; i
>= 0; i
--)
264 list_1_(make_exp(terms
[i
]),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
)
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
];
293 if (levels
== 1) { C
.pr("%^%t repl__;", rule
->ty
, ""); }
294 Pat pat
= var_pat_map
[r
][i
];
295 Exp pat_exp
= pat
->selector
;
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
));
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
++)
312 } else if (optimized_map
[r
] != NOexp
)
313 { C
.pr("%^%t repl__ = %e;", rule
->ty
, "", optimized_map
[r
]);
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
327 Adaptive matching = enabled
328 Fast string matching = disabled
329 Inline downcasts = enabled
330 --------------------------------------------------------------------------