Wiki Roadmap Timeline Tickets New Ticket Source Search Help / Guide About Trac Login

Changeset 1145:40caa8207b3e

Show
Ignore:
Timestamp:
03/26/09 13:46:21 (3 years ago)
Author:
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
branch:
default
Message:

Moved IRTargetScopeS from IRState into IrFunction?, fixes #240 .

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gen/irstate.h

    r1141 r1145  
    3737struct BaseClass; 
    3838struct AnonDeclaration; 
    39 struct EnclosingHandler; 
    4039 
    4140struct IrModule; 
     
    5049    IRScope(); 
    5150    IRScope(llvm::BasicBlock* b, llvm::BasicBlock* e); 
    52 }; 
    53  
    54 // scope statements that can be target of jumps 
    55 // includes loops, switch, case, labels 
    56 struct IRTargetScope 
    57 { 
    58     // generating statement 
    59     Statement* s; 
    60      
    61     // the try of a TryFinally that encloses the loop 
    62     EnclosingHandler* enclosinghandler; 
    63      
    64     llvm::BasicBlock* breakTarget; 
    65     llvm::BasicBlock* continueTarget; 
    66  
    67     IRTargetScope(); 
    68     IRTargetScope(Statement* s, EnclosingHandler* enclosinghandler, llvm::BasicBlock* continueTarget, llvm::BasicBlock* breakTarget); 
    6951}; 
    7052 
     
    160142    llvm::CallSite CreateCallOrInvoke4(LLValue* Callee, LLValue* Arg1, LLValue* Arg2,  LLValue* Arg3, LLValue* Arg4, const char* Name=""); 
    161143 
    162     // loop blocks 
    163     typedef std::vector<IRTargetScope> TargetScopeVec; 
    164     TargetScopeVec targetScopes; 
    165  
    166144    // this holds the array being indexed or sliced so $ will work 
    167145    // might be a better way but it works. problem is I only get a 
  • gen/llvmhelpers.cpp

    r1141 r1145  
    249249 
    250250    // figure out up until what handler we need to emit 
    251     IRState::TargetScopeVec::reverse_iterator targetit; 
    252     for (targetit = gIR->targetScopes.rbegin(); targetit != gIR->targetScopes.rend(); ++targetit) { 
     251    IrFunction::TargetScopeVec::reverse_iterator targetit = gIR->func()->targetScopes.rbegin(); 
     252    IrFunction::TargetScopeVec::reverse_iterator it_end = gIR->func()->targetScopes.rend(); 
     253    while(targetit != it_end) { 
    253254        if (targetit->s == target) { 
    254255            break; 
    255256        } 
    256     } 
    257  
    258     if (target && targetit == gIR->targetScopes.rend()) { 
     257        ++targetit; 
     258    } 
     259 
     260    if (target && targetit == it_end) { 
    259261        if (lblstmt) 
    260262            error(loc, "cannot goto into try, volatile or synchronized statement at %s", target->loc.toChars()); 
     
    271273    // and might already exist push a label scope 
    272274    gIR->func()->pushUniqueLabelScope("enclosing"); 
    273     IRState::TargetScopeVec::reverse_iterator it
    274     for (it = gIR->targetScopes.rbegin(); it != targetit; ++it) { 
     275    IrFunction::TargetScopeVec::reverse_iterator it = gIR->func()->targetScopes.rbegin()
     276    while (it != targetit) { 
    275277        if (it->enclosinghandler) 
    276278            it->enclosinghandler->emitCode(gIR); 
     279        ++it; 
    277280    } 
    278281    gIR->func()->popLabelScope(); 
  • gen/statements.cpp

    r1141 r1145  
    297297 
    298298    // while body code 
    299     p->targetScopes.push_back(IRTargetScope(this,NULL,whilebb,endbb)); 
     299    p->func()->targetScopes.push_back(IRTargetScope(this,NULL,whilebb,endbb)); 
    300300    body->toIR(p); 
    301     p->targetScopes.pop_back(); 
     301    p->func()->targetScopes.pop_back(); 
    302302 
    303303    // loop 
     
    333333 
    334334    // do-while body code 
    335     p->targetScopes.push_back(IRTargetScope(this,NULL,condbb,endbb)); 
     335    p->func()->targetScopes.push_back(IRTargetScope(this,NULL,condbb,endbb)); 
    336336    body->toIR(p); 
    337     p->targetScopes.pop_back(); 
     337    p->func()->targetScopes.pop_back(); 
    338338 
    339339    // branch to condition block 
     
    378378    llvm::BranchInst::Create(forbb, gIR->scopebb()); 
    379379 
    380     p->targetScopes.push_back(IRTargetScope(this,NULL,forincbb,endbb)); 
     380    p->func()->targetScopes.push_back(IRTargetScope(this,NULL,forincbb,endbb)); 
    381381 
    382382    // replace current scope 
     
    421421        llvm::BranchInst::Create(forbb, gIR->scopebb()); 
    422422 
    423     p->targetScopes.pop_back(); 
     423    p->func()->targetScopes.pop_back(); 
    424424 
    425425    // rewrite the scope 
     
    455455        // find the right break block and jump there 
    456456        bool found = false; 
    457         IRState::TargetScopeVec::reverse_iterator it; 
    458         for(it = p->targetScopes.rbegin(); it != p->targetScopes.rend(); ++it) { 
     457        IrFunction::TargetScopeVec::reverse_iterator it = p->func()->targetScopes.rbegin(); 
     458        IrFunction::TargetScopeVec::reverse_iterator it_end = p->func()->targetScopes.rend(); 
     459        while(it != it_end) { 
    459460            if(it->s == targetLoopStatement) { 
    460461                llvm::BranchInst::Create(it->breakTarget, p->scopebb()); 
     
    462463                break; 
    463464            } 
     465            ++it; 
    464466        } 
    465467        assert(found); 
     
    467469    else { 
    468470        // find closest scope with a break target 
    469         IRState::TargetScopeVec::reverse_iterator it; 
    470         for(it = gIR->targetScopes.rbegin(); it != gIR->targetScopes.rend(); ++it) { 
     471        IrFunction::TargetScopeVec::reverse_iterator it = p->func()->targetScopes.rbegin(); 
     472        IrFunction::TargetScopeVec::reverse_iterator it_end = p->func()->targetScopes.rend(); 
     473        while(it != it_end) { 
    471474            if(it->breakTarget) { 
    472475                break; 
    473476            } 
     477            ++it; 
    474478        } 
    475479        DtoEnclosingHandlers(loc, it->s); 
     
    506510        // find the right continue block and jump there 
    507511        bool found = false; 
    508         IRState::TargetScopeVec::reverse_iterator it; 
    509         for(it = gIR->targetScopes.rbegin(); it != gIR->targetScopes.rend(); ++it) { 
     512        IrFunction::TargetScopeVec::reverse_iterator it = p->func()->targetScopes.rbegin(); 
     513        IrFunction::TargetScopeVec::reverse_iterator it_end = p->func()->targetScopes.rend(); 
     514        while(it != it_end) { 
    510515            if(it->s == targetLoopStatement) { 
    511516                llvm::BranchInst::Create(it->continueTarget, gIR->scopebb()); 
     
    513518                break; 
    514519            } 
     520            ++it; 
    515521        } 
    516522        assert(found); 
     
    518524    else { 
    519525        // find closest scope with a continue target 
    520         IRState::TargetScopeVec::reverse_iterator it; 
    521         for(it = gIR->targetScopes.rbegin(); it != gIR->targetScopes.rend(); ++it) { 
     526        IrFunction::TargetScopeVec::reverse_iterator it = p->func()->targetScopes.rbegin(); 
     527        IrFunction::TargetScopeVec::reverse_iterator it_end = p->func()->targetScopes.rend(); 
     528        while(it != it_end) { 
    522529            if(it->continueTarget) { 
    523530                break; 
    524531            } 
     532            ++it; 
    525533        } 
    526534        DtoEnclosingHandlers(loc, it->s); 
     
    594602 
    595603    assert(body); 
    596     p->targetScopes.push_back(IRTargetScope(this,new EnclosingTryFinally(this),NULL,NULL)); 
     604    p->func()->targetScopes.push_back(IRTargetScope(this,new EnclosingTryFinally(this),NULL,NULL)); 
    597605    body->toIR(p); 
    598     p->targetScopes.pop_back(); 
     606    p->func()->targetScopes.pop_back(); 
    599607 
    600608    // terminate try BB 
     
    852860 
    853861    p->scope() = IRScope(bodybb, endbb); 
    854     p->targetScopes.push_back(IRTargetScope(this,NULL,NULL,endbb)); 
     862    p->func()->targetScopes.push_back(IRTargetScope(this,NULL,NULL,endbb)); 
    855863    body->toIR(p); 
    856     p->targetScopes.pop_back(); 
     864    p->func()->targetScopes.pop_back(); 
    857865 
    858866    if (!p->scopereturned()) 
     
    973981        // push loop scope 
    974982        // continue goes to next statement, break goes to end 
    975         p->targetScopes.push_back(IRTargetScope(this,NULL,nextbb,endbb)); 
     983        p->func()->targetScopes.push_back(IRTargetScope(this,NULL,nextbb,endbb)); 
    976984 
    977985        // do statement 
     
    979987 
    980988        // pop loop scope 
    981         p->targetScopes.pop_back(); 
     989        p->func()->targetScopes.pop_back(); 
    982990 
    983991        // next stmt 
     
    10961104 
    10971105    // emit body 
    1098     p->targetScopes.push_back(IRTargetScope(this,NULL,nextbb,endbb)); 
     1106    p->func()->targetScopes.push_back(IRTargetScope(this,NULL,nextbb,endbb)); 
    10991107    if(body) 
    11001108        body->toIR(p); 
    1101     p->targetScopes.pop_back(); 
     1109    p->func()->targetScopes.pop_back(); 
    11021110 
    11031111    if (!p->scopereturned()) 
     
    11921200 
    11931201    // emit body 
    1194     p->targetScopes.push_back(IRTargetScope(this,NULL,nextbb,endbb)); 
     1202    p->func()->targetScopes.push_back(IRTargetScope(this,NULL,nextbb,endbb)); 
    11951203    if (body) 
    11961204        body->toIR(p); 
    1197     p->targetScopes.pop_back(); 
     1205    p->func()->targetScopes.pop_back(); 
    11981206 
    11991207    // jump to next iteration 
     
    12621270 
    12631271    if (statement) { 
    1264         p->targetScopes.push_back(IRTargetScope(this,NULL,NULL,NULL)); 
     1272        p->func()->targetScopes.push_back(IRTargetScope(this,NULL,NULL,NULL)); 
    12651273        statement->toIR(p); 
    1266         p->targetScopes.pop_back(); 
     1274        p->func()->targetScopes.pop_back(); 
    12671275    } 
    12681276} 
     
    13861394 
    13871395    // emit body 
    1388     p->targetScopes.push_back(IRTargetScope(this,new EnclosingSynchro(this),NULL,NULL)); 
     1396    p->func()->targetScopes.push_back(IRTargetScope(this,new EnclosingSynchro(this),NULL,NULL)); 
    13891397    body->toIR(p); 
    1390     p->targetScopes.pop_back(); 
     1398    p->func()->targetScopes.pop_back(); 
    13911399 
    13921400    // exit lock 
     
    14201428 
    14211429        // do statement 
    1422     p->targetScopes.push_back(IRTargetScope(this,new EnclosingVolatile(this),NULL,NULL)); 
     1430    p->func()->targetScopes.push_back(IRTargetScope(this,new EnclosingVolatile(this),NULL,NULL)); 
    14231431        statement->toIR(p); 
    1424     p->targetScopes.pop_back(); 
     1432    p->func()->targetScopes.pop_back(); 
    14251433 
    14261434        // no point in a unreachable barrier, terminating statements must insert this themselves. 
  • ir/irfunction.h

    r1051 r1145  
    99#include <stack> 
    1010#include <map> 
     11 
     12struct Statement; 
     13struct EnclosingHandler; 
     14 
     15// scope statements that can be target of jumps 
     16// includes loops, switch, case, labels 
     17struct IRTargetScope 
     18{ 
     19    // generating statement 
     20    Statement* s; 
     21     
     22    // the try of a TryFinally that encloses the loop 
     23    EnclosingHandler* enclosinghandler; 
     24     
     25    llvm::BasicBlock* breakTarget; 
     26    llvm::BasicBlock* continueTarget; 
     27 
     28    IRTargetScope(); 
     29    IRTargetScope(Statement* s, EnclosingHandler* enclosinghandler, llvm::BasicBlock* continueTarget, llvm::BasicBlock* breakTarget); 
     30}; 
    1131 
    1232// represents a function 
     
    4969    IRLandingPad landingPad; 
    5070 
     71    // loop blocks 
     72    typedef std::vector<IRTargetScope> TargetScopeVec; 
     73    TargetScopeVec targetScopes; 
     74 
     75    // constructor 
    5176    IrFunction(FuncDeclaration* fd); 
    5277 
Copyright © 2008, LDC Development Team.