Changeset 1034

Show
Ignore:
Timestamp:
02/11/10 11:18:34 (6 months ago)
Author:
corni
Message:

Replace the friend-relationship between stmt and CheckMemoryManagement?.
Auto-add CheckMemoryManagement? in debug builds after each pass.
Add a pass for return; => return NULL; transformations
Add a cli argument to rphp-analyzer (--lower) which runs all existing passes in a well-defined order.
pPassManager shouldn't have a copy constructor (per comment) so remove the existing empty.
Document which phc pass has been implemented in which corresponding rphp pass.

Location:
trunk/rphp
Files:
2 added
8 modified

Legend:

Unmodified
Added
Removed
  • trunk/rphp/compiler/analysis/CMakeLists.txt

    r1030 r1034  
    8484  passes/CheckMemoryManagement.cpp 
    8585  passes/SimplifyStrings.cpp 
     86  passes/Desugar.cpp 
    8687  passes/DumpAST.cpp 
    8788  passes/DumpStats.cpp 
  • trunk/rphp/compiler/analysis/pPassManager.cpp

    r977 r1034  
    2323#include "rphp/analysis/pPass.h" 
    2424#include "rphp/analysis/pSourceModule.h" 
     25#include "rphp/analysis/passes/CheckMemoryManagement.h" 
    2526 
    2627namespace rphp { 
     
    4647        (*i)->post_run(); 
    4748    } 
     49} 
    4850 
     51void pPassManager::addPass(AST::pPass* p) { 
     52    passQueue_.push_back(p); 
     53#ifdef DEBUG 
     54    passQueue_.push_back(new AST::Pass::CheckMemoryManagement); 
     55#endif 
    4956} 
    5057 
  • trunk/rphp/compiler/analysis/passes/CheckMemoryManagement.cpp

    r1030 r1034  
    3030 
    3131void CheckMemoryManagement::visit_pre_stmt(stmt* s) { 
    32     if(s && s->refCount_ != 1) { 
    33         std::cerr << "The following AST Node has a refCount of " << s->refCount_ << std::endl;  
     32    if(s && s->getRefCount() != 1) { 
     33        std::cerr << "The following AST Node has a refCount of " << s->getRefCount() << std::endl;  
    3434        DumpAST dump(module_); 
    3535        dump.pre_run(); 
  • trunk/rphp/compiler/analysis/passes/Lower_Binary_Op.cpp

    r1030 r1034  
    9797        case binaryOp::GREATER_OR_EQUAL: 
    9898        case binaryOp::GREATER_THAN: 
     99            //TODO: file+line numbers? 
    99100            return new (C_) binaryOp(n->rVal()->retain(), 
    100101                             n->lVal()->retain(), 
  • trunk/rphp/doc/phc-pass-notes.txt

    r977 r1034  
    1010Constant_folding: a) we don't have a match() function in rphp b) We don't call to zend php for folding constant expressions 
    1111Remove_concat_null: Our parser shouldn't create these concats, so this issue is phc specific. 
    12 Desugar: - and/or renaming to && and || happens already in our parser 
     12Desugar *implemented Desugar* : - and/or renaming to && and || happens already in our parser 
    1313                        - we don't have classes yet (no need to replace self:: and parent:: yet) 
    1414                        - same for interfaces 
    1515                        - we don't store cast types as strings but as enum, so we don't have to normalize them. 
    16                         - we already generate the same AST for return; and return NULL; 
     16                        - we need this to replace return; with return NULL; 
    1717                        - i'm unsure whether we want to transform - x to 0 - x 
    1818Split_multiple_arguments: We got a better facility to iterate over children nodes, so we don't need this imho. 
    19 Split_unset_isset: this one makes more sense, but we need a facility to return an expression list first (sth block-like) 
    20 Echo_split: we definitly want this for the reason given in Echo_split.cpp, but see S-u-i... 
    21 Early_lower_control_flow: we want this at least partially because it simplifies loop codegen later on, but we've to be 
     19Split_unset_isset *implemented Split_Builtins*: this one makes more sense, but we need a facility to return an expression list first (sth block-like) 
     20Echo_split *implemented Split_Builtins*: we definitly want this for the reason given in Echo_split.cpp, but see S-u-i... 
     21Early_lower_control_flow *implemented Early_lower_control_flow except switch and foreach!*: we want this at least partially because it simplifies loop codegen later on, but we've to be 
    2222                                                         super careful with continue. Probably the transformations by phc can be used, but we want to 
    2323                                                         sure they are optimized later if the loop body doesn't contain a continue;. 
    24 Lower_expr_flow: We want everything except the comma-seperated list transform. We need an EXPR_LIST anyways, i'd like 
     24Lower_expr_flow *implemented in Lower_Binary_Op and Lower_Conditional_Expr* and: We want everything except the comma-seperated list transform. We need an EXPR_LIST anyways, i'd like 
    2525                                        to have one which is not binary but uses a std::vector or sth like that 
    2626List_shredder: We want this one :) 
     
    2828                                 nearly everything. 
    2929Pre_post_op_shredder: makes sense, but is a bit more complex. 
    30 Switch_bin_op: should simplify codegen a bit :) 
     30Switch_bin_op *implented in Lower_Binary_Op*: should simplify codegen a bit :) 
    3131Remove_solo_exprs: because we don't have an Eval_expr facility, we can't really do this pass so easily as phc can. 
    3232                                          I'm unsure whether we want to support this or not. 
  • trunk/rphp/frontend/cli/rphp-analyzer.cpp

    r1030 r1034  
    3636 
    3737#include "rphp/analysis/passes/CheckMemoryManagement.h" 
     38#include "rphp/analysis/passes/Desugar.h" 
    3839#include "rphp/analysis/passes/DumpAST.h" 
    3940#include "rphp/analysis/passes/DumpStats.h" 
     
    6263    cl::opt<bool> dumpAST ("dump-ast", cl::desc("Dump AST")); 
    6364    cl::opt<bool> debugParse ("debug-parse", cl::desc("Debug output from parser")); 
     65    cl::opt<bool> runPasses ("lower", cl::desc("Lowers the AST and dumps it after lowering")); 
    6466 
    6567    cl::opt<std::string> passListText ("passes", cl::desc("List of passes to run")); 
     
    99101            passManager.addPass<AST::Pass::DumpAST>(); 
    100102            passManager.addPass<AST::Pass::DumpStats>(); 
     103        } 
     104        else if(runPasses) { 
     105            // make all variables etc in strings accessible to passes which need them 
     106            passManager.addPass<AST::Pass::SimplifyStrings>(); 
    101107            passManager.addPass<AST::Pass::CheckMemoryManagement>(); 
     108             
     109            // TODO: get variable names here or use variable names which the zend engine 
     110            // doesn't allow for internal variables. 
     111             
     112            // uses boolean && and || 
     113            passManager.addPass<AST::Pass::Split_Builtins>(); 
     114            // uses boolean ! 
     115            passManager.addPass<AST::Pass::Early_Lower_Loops>(); 
     116            // uses conditionals 
     117            passManager.addPass<AST::Pass::Lower_Binary_Op>(); 
     118 
     119            passManager.addPass<AST::Pass::Lower_Conditional_Expr>(); 
     120             
     121            // do this one late in case other passes are creating return's for whatever reason... 
     122            passManager.addPass<AST::Pass::Desugar>(); 
     123             
     124            // debug output 
     125            passManager.addPass<AST::Pass::DumpAST>(); 
     126            passManager.addPass<AST::Pass::DumpStats>(); 
    102127        } 
    103128        else if (!passListText.empty()) { 
     
    111136                    passManager.addPass<AST::Pass::DumpAST>(); 
    112137                    passManager.addPass<AST::Pass::DumpStats>(); 
    113                     passManager.addPass<AST::Pass::CheckMemoryManagement>(); 
    114138                } 
    115139                else if (*i == "simplifystrings") { 
    116140                    passManager.addPass<AST::Pass::SimplifyStrings>(); 
    117                     passManager.addPass<AST::Pass::CheckMemoryManagement>(); 
    118141                } 
    119142                else if (*i == "split-builtins") { 
    120143                    passManager.addPass<AST::Pass::Split_Builtins>(); 
    121                     passManager.addPass<AST::Pass::CheckMemoryManagement>(); 
    122144                } 
    123145                else if (*i == "early-lower-loops") { 
    124146                    passManager.addPass<AST::Pass::Early_Lower_Loops>(); 
    125                     passManager.addPass<AST::Pass::CheckMemoryManagement>(); 
    126147                } 
    127148                else if (*i == "lower-binary-ops") { 
    128149                    passManager.addPass<AST::Pass::Lower_Binary_Op>(); 
    129                     passManager.addPass<AST::Pass::CheckMemoryManagement>(); 
    130150                } 
    131151                else if (*i == "lower-conditional-exprs") { 
    132152                    passManager.addPass<AST::Pass::Lower_Conditional_Expr>(); 
    133                     passManager.addPass<AST::Pass::CheckMemoryManagement>(); 
    134153                } 
    135154            } 
  • trunk/rphp/include/rphp/analysis/pAST.h

    r1030 r1034  
    136136                                              CLASS * retain() { stmt::retain(); return this; } 
    137137 
    138 namespace Pass { 
    139 class CheckMemoryManagement; 
    140 } 
    141  
    142138// statement base class 
    143139class stmt { 
     
    149145    pUInt startLineNum_; 
    150146    pUInt endLineNum_; 
    151      
    152     // We need this because we access refCount_ over there. 
    153     friend class Pass::CheckMemoryManagement; 
    154147     
    155148protected: 
     
    203196      ++refCount_; 
    204197      return this; 
     198    } 
     199     
     200    pUInt getRefCount() const { 
     201        return refCount_; 
    205202    } 
    206203 
     
    11071104// return statement 
    11081105class returnStmt: public stmt { 
    1109  
     1106     
    11101107    expr* rVal_; 
    11111108     
     
    11271124 
    11281125    expr* rVal(void) { return rVal_; } 
     1126    void setRVal(pParseContext& C, expr* r) { if(rVal_) rVal_->destroy(C); rVal_= r; } 
    11291127 
    11301128    IMPLEMENT_SUPPORT_MEMBERS(returnStmt); 
  • trunk/rphp/include/rphp/analysis/pPassManager.h

    r939 r1034  
    4343 
    4444    // no copy constructor 
    45     pPassManager(const pPassManager&) { } 
     45    pPassManager(const pPassManager&); 
    4646 
    4747public: 
     
    5151 
    5252    /// add a pass. takes ownership. 
    53     void addPass(AST::pPass* p) { 
    54         passQueue_.push_back(p); 
    55     } 
     53    void addPass(AST::pPass* p); 
    5654 
    5755    template <typename PassType>