Ignore:
Timestamp:
Jul 29, 2007, 12:33:04 PM (17 years ago)
Author:
dai_9181
Message:

BreakPertialScheduleをリファクタリング

Location:
trunk/abdev/BasicCompiler_Common/src
Files:
3 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/abdev/BasicCompiler_Common/src/CommonCodeGenerator.cpp

    r247 r248  
    3333    bool isSuccessful = false;
    3434
    35     CodeGenerator::PertialSchedules::iterator it = pertialSchedules.begin();
     35    PertialSchedules::iterator it = pertialSchedules.begin();
    3636    while( it != pertialSchedules.end() )
    3737    {
     
    8484    }
    8585}
    86 const CodeGenerator::PertialSchedule *CodeGenerator::__jmp_op_format( char opcode, long offset, int op_size, bool isPertialSchedule, bool isSelfOpcodeOffset )
     86const PertialSchedule *CodeGenerator::__jmp_op_format( char opcode, long offset, int op_size, bool isPertialSchedule, bool isSelfOpcodeOffset )
    8787{
    8888    long beginCodePos = pNativeCode->GetSize();
     
    158158    return pPertialSchedule;
    159159}
    160 const CodeGenerator::PertialSchedule *CodeGenerator::op_jle( long offset, int op_size, bool isPertialSchedule )
     160const PertialSchedule *CodeGenerator::op_jle( long offset, int op_size, bool isPertialSchedule )
    161161{
    162162    return __jmp_op_format( (char)0x0E, offset, op_size, isPertialSchedule );
    163163}
    164 const CodeGenerator::PertialSchedule *CodeGenerator::op_jbe( long offset, int op_size, bool isPertialSchedule )
     164const PertialSchedule *CodeGenerator::op_jbe( long offset, int op_size, bool isPertialSchedule )
    165165{
    166166    return __jmp_op_format( (char)0x06, offset, op_size, isPertialSchedule );
    167167}
    168 const CodeGenerator::PertialSchedule *CodeGenerator::op_jge( long offset, int op_size, bool isPertialSchedule )
     168const PertialSchedule *CodeGenerator::op_jge( long offset, int op_size, bool isPertialSchedule )
    169169{
    170170    return __jmp_op_format( (char)0x0D, offset, op_size, isPertialSchedule );
    171171}
    172 const CodeGenerator::PertialSchedule *CodeGenerator::op_jae( long offset, int op_size, bool isPertialSchedule )
     172const PertialSchedule *CodeGenerator::op_jae( long offset, int op_size, bool isPertialSchedule )
    173173{
    174174    return __jmp_op_format( (char)0x03, offset, op_size, isPertialSchedule );
    175175}
    176 const CodeGenerator::PertialSchedule *CodeGenerator::op_jl( long offset, int op_size, bool isPertialSchedule )
     176const PertialSchedule *CodeGenerator::op_jl( long offset, int op_size, bool isPertialSchedule )
    177177{
    178178    return __jmp_op_format( (char)0x0C, offset, op_size, isPertialSchedule );
    179179}
    180 const CodeGenerator::PertialSchedule *CodeGenerator::op_jb( long offset, int op_size, bool isPertialSchedule )
     180const PertialSchedule *CodeGenerator::op_jb( long offset, int op_size, bool isPertialSchedule )
    181181{
    182182    return __jmp_op_format( (char)0x02, offset, op_size, isPertialSchedule );
    183183}
    184 const CodeGenerator::PertialSchedule *CodeGenerator::op_jg( long offset, int op_size, bool isPertialSchedule )
     184const PertialSchedule *CodeGenerator::op_jg( long offset, int op_size, bool isPertialSchedule )
    185185{
    186186    return __jmp_op_format( (char)0x0F, offset, op_size, isPertialSchedule );
    187187}
    188 const CodeGenerator::PertialSchedule *CodeGenerator::op_ja( long offset, int op_size, bool isPertialSchedule )
     188const PertialSchedule *CodeGenerator::op_ja( long offset, int op_size, bool isPertialSchedule )
    189189{
    190190    return __jmp_op_format( (char)0x07, offset, op_size, isPertialSchedule );
    191191}
    192 const CodeGenerator::PertialSchedule *CodeGenerator::op_jne( long offset, int op_size, bool isPertialSchedule )
     192const PertialSchedule *CodeGenerator::op_jne( long offset, int op_size, bool isPertialSchedule )
    193193{
    194194    return __jmp_op_format( (char)0x05, offset, op_size, isPertialSchedule );
    195195}
    196 const CodeGenerator::PertialSchedule *CodeGenerator::op_je( long offset, int op_size, bool isPertialSchedule )
     196const PertialSchedule *CodeGenerator::op_je( long offset, int op_size, bool isPertialSchedule )
    197197{
    198198    return __jmp_op_format( (char)0x04, offset, op_size, isPertialSchedule );
    199199}
    200 const CodeGenerator::PertialSchedule *CodeGenerator::op_jmp( long offset, int op_size, bool isPertialSchedule, bool isSelfOpcodeOffset )
     200const PertialSchedule *CodeGenerator::op_jmp( long offset, int op_size, bool isPertialSchedule, bool isSelfOpcodeOffset )
    201201{
    202202    return __jmp_op_format( (char)0xEB, offset, op_size, isPertialSchedule, isSelfOpcodeOffset );
  • trunk/abdev/BasicCompiler_Common/src/LexicalScope.cpp

    r245 r248  
    11#include "stdafx.h"
    22
    3 #include <LexicalScopingImpl.h>
     3#include <LexicalScope.h>
    44#include <Compiler.h>
    55
     
    1313
    1414
    15 void ScopeImpl::Break(){
     15void LexicalScope::Break(){
    1616    //未解放のローカルオブジェクトを解放する
    17     GetLexicalScopes().CallDestructorsOfReturn( level );
     17    compiler.codeGenerator.lexicalScopes.CallDestructorsOfReturn( level );
    1818
    1919    //jmp ...(Next addr)
    20     OpBuffer[obp++]=(char)0xE9;
    21 
    22     pBreakSchedule=(DWORD *)realloc( pBreakSchedule, ( nBreakSchedule + 1 ) * sizeof(DWORD) );
    23     pBreakSchedule[nBreakSchedule]=obp;
    24     nBreakSchedule++;
    25 
    26     obp+=sizeof(long);
     20    breakPertialSchedules.push_back(
     21        compiler.codeGenerator.op_jmp( 0, sizeof(long), true )
     22    );
    2723}
    28 void ScopeImpl::RunScheduleOfBreak(){
    29     for(int i=0;i<nBreakSchedule;i++){
    30         *((long *)(OpBuffer+pBreakSchedule[i]))=obp-(pBreakSchedule[i]+sizeof(long));
     24void LexicalScope::RunScheduleOfBreak(){
     25    BOOST_FOREACH( const PertialSchedule *pBreakPertialSchedule, breakPertialSchedules )
     26    {
     27        compiler.codeGenerator.opfix_JmpPertialSchedule( pBreakPertialSchedule );
    3128    }
    3229}
    3330
    34 void LexicalScopesImpl::End(){
     31
     32
     33LexicalScope *LexicalScopes::SearchScope( LexicalScope::SCOPE_TYPE TypeOfStatement ){
     34    for( int i = level; i>=0; i-- ){
     35        if( ppScopes[i]->GetTypeOfStatement() == TypeOfStatement ){
     36            return ppScopes[i];
     37        }
     38    }
     39    return NULL;
     40}
     41
     42void LexicalScopes::Init(int addr){
     43    // TODO: エラーチェック
     44
     45    level = -1;
     46    Start( addr, LexicalScope::SCOPE_TYPE_BASE );
     47}
     48void LexicalScopes::Start( int addr, LexicalScope::SCOPE_TYPE TypeOfStatement ){
     49    level++;
     50    ppScopes = (LexicalScope **)realloc( ppScopes, ( level + 1 ) * sizeof( LexicalScope * ) );
     51    ppScopes[level] = new LexicalScope( level, addr, TypeOfStatement );
     52}
     53
     54int LexicalScopes::GetNowLevel(){
     55    return level;
     56}
     57void LexicalScopes::SetNowLevel( int level ){
     58    this->level = level;
     59}
     60int LexicalScopes::GetStartAddress(){
     61    return ppScopes[level]->GetStartAddress();
     62}
     63
     64void LexicalScopes::End(){
    3565    if( level <= 0 ){
    3666        SetError();
     
    6595
    6696// スコープ終了時のデストラクタ呼び出し
    67 void LexicalScopesImpl::CallDestructorsOfScopeEnd(){
     97void LexicalScopes::CallDestructorsOfScopeEnd(){
    6898
    6999    Variables &vars = UserProc::IsGlobalAreaCompiling() ?
     
    134164
    135165// Returnステートメントで発行されるデストラクタを生成
    136 void LexicalScopesImpl::CallDestructorsOfReturn( int BaseLevel ){
     166void LexicalScopes::CallDestructorsOfReturn( int BaseLevel ){
    137167    //現在のスコープレベルを退避
    138168    int backupScopeLevel = GetNowLevel();
     
    147177    SetNowLevel( backupScopeLevel );
    148178}
    149 
    150 LexicalScopesImpl &GetLexicalScopes()
    151 {
    152     static LexicalScopesImpl *pTemp = NULL;
    153     if( !pTemp )
    154     {
    155         pTemp = (LexicalScopesImpl *)Smoothie::Temp::pLexicalScopes;
    156     }
    157     return *pTemp;
    158 }
  • trunk/abdev/BasicCompiler_Common/src/SmoothieImpl.cpp

    r206 r248  
    66#include <Class.h>
    77#include <Procedure.h>
    8 #include <LexicalScopingImpl.h>
    9 
    10 CLexicalScopes *Smoothie::Temp::pLexicalScopes = new LexicalScopesImpl();
     8#include <LexicalScope.h>
  • trunk/abdev/BasicCompiler_Common/src/Variable.cpp

    r206 r248  
    3535        Variable &var = *(*this)[i];
    3636        if( var.bLiving                                         //現在のスコープで有効なもの
    37             && var.GetScopeLevel() == Smoothie::Temp::pLexicalScopes->GetNowLevel() //現在のスコープと同一レベル
    38             ){
    39                 if( var.IsEqualSymbol( symbol ) ){
    40                     return true;
    41                 }
     37            && var.GetScopeLevel() == compiler.codeGenerator.lexicalScopes.GetNowLevel()    //現在のスコープと同一レベル
     38            )
     39        {
     40            if( var.IsEqualSymbol( symbol ) ){
     41                return true;
     42            }
    4243        }
    4344    }
     
    5152        Variable &var = *(*this)[i];
    5253        if( var.bLiving                                         //現在のスコープで有効なもの
    53             && var.GetScopeLevel() <= Smoothie::Temp::pLexicalScopes->GetNowLevel() //現在のスコープレベルを超さないもの(Returnによる解放処理中を考慮)
     54            && var.GetScopeLevel() <= compiler.codeGenerator.lexicalScopes.GetNowLevel()    //現在のスコープレベルを超さないもの(Returnによる解放処理中を考慮)
    5455            ){
    5556                if( var.IsEqualSymbol( symbol ) ){
Note: See TracChangeset for help on using the changeset viewer.