initial
[prop.git] / prop-src / rwmix.pcc
blob9b49b26c7014bee77e48334cac6a8360692c4e76
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 //  This file implements the rewriting partial evaluator/supercompiler.
4 //  This is used to optimize Prop's rewriting systems. 
5 //
6 ///////////////////////////////////////////////////////////////////////////////
7 #include <AD/automata/topdowng.h>
8 #include "ast.ph"
9 #include "ir.ph"
10 #include "rwmix.ph"
11 #include "patenv.h"
12 #include "type.h"
13 #include "funmap.h"
14 #include "options.h"
15 #include "trs.h"
17 ///////////////////////////////////////////////////////////////////////////////
19 //  The constructors and destructors 
21 ///////////////////////////////////////////////////////////////////////////////
22 RewriteMix::RewriteMix() { reduction_limit = 10; }
23 RewriteMix::~RewriteMix() {}
25 ///////////////////////////////////////////////////////////////////////////////
27 //  Method to optimize a set of rewrite rules.
28 //  Currently, we'll only optimize if there are no other rules
29 //  except bottomup rules.
31 ///////////////////////////////////////////////////////////////////////////////
32 void RewriteMix::optimize_rewrite()
33 {  if (options.optimize_rewrite && Fmap != 0)
34    {  if (Fmap->topdown_rule_map.size() > 0 ||
35           Fmap->preorder_rule_map.size() > 0 ||
36           Fmap->postorder_rule_map.size() > 0 ||
37           Fmap->before_rule_map.size() > 0)
38       {  msg("%Lrewrite class %s will not be optimized due to the presence"
39              " of non-bottomup rules\n",Fmap->class_name);
40          return;
41       }
42       
43       msg("%Lpartial evaluating rewrite class %s\n", Fmap->class_name);
44       trs = new TRS(*this);
45       trs->mix();
46       msg("%Lfinished optimizing rewrite class %s\n", Fmap->class_name);
47    }