[phc-internals] [phc commit] r959 - in trunk/src: . hir_to_mir
codesite-noreply at google.com
codesite-noreply at google.com
Thu Dec 20 13:58:20 GMT 2007
Author: paul.biggar
Date: Thu Dec 20 05:57:58 2007
New Revision: 959
Modified:
trunk/src/hir_to_mir/Lower_expr_flow.cpp
trunk/src/phc.cpp
Log:
The remaining lowering passes are going to stay in the AST, except for
Lower_control_flow, which goes to the HIR. As such, this pass is the
first step to slowly moving the Lower_control_flow to the correct place
in the pass queue, by moving it past Lower_expr_flow, and fixing up
lower_expr_flow to print out an if statement instead of using branches.
This if statement is then lowered using lower_control_flow.
Modified: trunk/src/hir_to_mir/Lower_expr_flow.cpp
==============================================================================
--- trunk/src/hir_to_mir/Lower_expr_flow.cpp (original)
+++ trunk/src/hir_to_mir/Lower_expr_flow.cpp Thu Dec 20 05:57:58 2007
@@ -63,32 +63,18 @@
* Translate
* foo(f() ? g() : h());
* into
- * if(f()) goto L1 else goto L2;
- * L1:
- * $TEF2 = g();
- * goto L3;
- * L2:
- * $TEF2 = h();
- * goto L3;
- * L3:
+ * if(f()) $TEF2 = g ();
+ * else $TEF2 = h ();
* foo($TEF2);
*/
Expr* Lower_expr_flow::post_conditional_expr(Conditional_expr* in)
{
- Label* label1 = fresh_label();
- Label* label2 = fresh_label();
- Label* label3 = fresh_label();
Variable* temp = fresh_var("TEF");
- pieces->push_back(new Branch(in->cond, label1->label_name->clone (),
label2->label_name->clone ()));
- pieces->push_back(label1);
- eval(in->iftrue, temp->clone ());
- pieces->push_back(new Goto(label3->label_name->clone ()));
- pieces->push_back(label2);
- eval(in->iffalse, temp->clone ());
- pieces->push_back(new Goto(label3->label_name->clone ()));
- pieces->push_back(label3);
+ pieces->push_back(new If (in->cond,
+ new List<Statement*> (new Eval_expr (new Assignment (temp->clone (),
false, in->iftrue))),
+ new List<Statement*> (new Eval_expr (new Assignment (temp->clone (),
false, in->iffalse)))));
return temp;
}
Modified: trunk/src/phc.cpp
==============================================================================
--- trunk/src/phc.cpp (original)
+++ trunk/src/phc.cpp Thu Dec 20 05:57:58 2007
@@ -140,19 +140,15 @@
// Required passes to lower AST constructs to HIR constructs
- // TODO make lower_expr work from here, redo all the passes using
- // lower_expr, and move shredder much higher so that all the passes are
- // simpler
-
pm->add_hir_pass (new Fake_pass ("hir"));
- pm->add_hir_transform (new Early_lower_control_flow (), "elcf");
- pm->add_hir_transform (new Lower_control_flow (), "lcf");
- pm->add_hir_transform (new Lower_expr_flow (), "lef");
- pm->add_hir_transform (new Pre_post_op_shredder (), "pps");
- pm->add_hir_transform (new Desugar (), "desug");
- pm->add_hir_transform (new List_shredder (), "lish");
- pm->add_hir_transform (new Shredder (), "shred");
- pm->add_hir_transform (new Tidy_print (), "tidyp");
+ pm->add_hir_transform (new Early_lower_control_flow (), "elcf"); // AST
+ pm->add_hir_transform (new Lower_expr_flow (), "lef"); // AST
+ pm->add_hir_transform (new Lower_control_flow (), "lcf"); // HIR
+ pm->add_hir_transform (new Pre_post_op_shredder (), "pps"); // AST
+ pm->add_hir_transform (new Desugar (), "desug"); // AST
+ pm->add_hir_transform (new List_shredder (), "lish"); // AST
+ pm->add_hir_transform (new Shredder (), "shred"); // AST (and HIR?)
+ pm->add_hir_transform (new Tidy_print (), "tidyp"); // AST
// TODO move to the MIR - re-add
// pm->add_mir_pass (new Process_includes (true, new String ("hir"), pm, "incl2"));
More information about the phc-internals
mailing list