Changeset 248 in dev


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

BreakPertialScheduleをリファクタリング

Location:
trunk/abdev
Files:
12 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/abdev/BasicCompiler32/BasicCompiler.vcproj

    r237 r248  
    12811281                    </File>
    12821282                    <File
    1283                         RelativePath="..\BasicCompiler_Common\src\LexicalScopingImpl.cpp"
     1283                        RelativePath="..\BasicCompiler_Common\src\LexicalScope.cpp"
    12841284                        >
    12851285                    </File>
     
    14191419                </File>
    14201420                <File
    1421                     RelativePath="..\BasicCompiler_Common\include\LexicalScopingImpl.h"
     1421                    RelativePath="..\BasicCompiler_Common\include\LexicalScope.h"
    14221422                    >
    14231423                </File>
  • trunk/abdev/BasicCompiler32/Compile_ProcOp.cpp

    r247 r248  
    66#include <Program.h>
    77#include <Compiler.h>
    8 #include <LexicalScopingImpl.h>
     8#include <LexicalScope.h>
    99#include <Class.h>
    1010#include <Variable.h>
     
    9797        UserProc::CompileStartForGlobalArea();
    9898
    99         GetLexicalScopes().CallDestructorsOfScopeEnd();
     99        compiler.codeGenerator.lexicalScopes.CallDestructorsOfScopeEnd();
    100100
    101101        UserProc::CompileStartForUserProc( pBackUserProc );
     
    349349
    350350        //レキシカルスコープ情報
    351         pVar->SetScopeLevel( GetLexicalScopes().GetNowLevel() );
    352         pVar->SetScopeStartAddress( GetLexicalScopes().GetStartAddress() );
     351        pVar->SetScopeLevel( compiler.codeGenerator.lexicalScopes.GetNowLevel() );
     352        pVar->SetScopeStartAddress( compiler.codeGenerator.lexicalScopes.GetStartAddress() );
    353353        pVar->bLiving=TRUE;
    354354
     
    615615
    616616    //ローカルオブジェクトの解放処理
    617     GetLexicalScopes().CallDestructorsOfScopeEnd();
     617    compiler.codeGenerator.lexicalScopes.CallDestructorsOfScopeEnd();
    618618
    619619    //プロシージャ抜け出しスケジュール(Exit Sub/Function)
  • trunk/abdev/BasicCompiler32/Compile_Statement.cpp

    r247 r248  
    33#include <jenga/include/smoothie/LexicalAnalysis.h>
    44
    5 #include <LexicalScopingImpl.h>
     5#include <LexicalScope.h>
    66#include <Compiler.h>
    77
     
    140140    }
    141141
    142     const CodeGenerator::PertialSchedule *pIfPertialSchedule = NULL;
     142    const PertialSchedule *pIfPertialSchedule = NULL;
    143143    if( !NumOpe(Parameter,Type(),tempType) ){
    144144        //NumOpe内でエラー
     
    207207
    208208        //jne
    209         const CodeGenerator::PertialSchedule *pTempPertialSchedule1 = compiler.codeGenerator.op_jne( 0, sizeof(char), true );
     209        const PertialSchedule *pTempPertialSchedule1 = compiler.codeGenerator.op_jne( 0, sizeof(char), true );
    210210
    211211        //cmp ebx,0
     
    213213
    214214        //jne
    215         const CodeGenerator::PertialSchedule *pTempPertialSchedule2 = compiler.codeGenerator.op_jne( 0, sizeof(char), true );
     215        const PertialSchedule *pTempPertialSchedule2 = compiler.codeGenerator.op_jne( 0, sizeof(char), true );
    216216
    217217        //jmp (endif、または else までジャンプ)
     
    240240
    241241    //レキシカルスコープをレベルアップ
    242     GetLexicalScopes().Start( obp, SCOPE_TYPE_IF );
     242    compiler.codeGenerator.lexicalScopes.Start( obp, LexicalScope::SCOPE_TYPE_IF );
    243243
    244244    i2=CompileBuffer(ESC_ENDIF,0);
    245245
    246246    //レキシカルスコープをレベルダウン
    247     GetLexicalScopes().End();
     247    compiler.codeGenerator.lexicalScopes.End();
    248248
    249249
     
    252252    if(i2==ESC_ELSE){
    253253        //jmp (endifまで)
    254         const CodeGenerator::PertialSchedule *pTempPertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(long), true );
     254        const PertialSchedule *pTempPertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(long), true );
    255255
    256256        compiler.codeGenerator.opfix_JmpPertialSchedule( pIfPertialSchedule );
     
    262262
    263263        //レキシカルスコープをレベルアップ
    264         GetLexicalScopes().Start( obp, SCOPE_TYPE_IF );
     264        compiler.codeGenerator.lexicalScopes.Start( obp, LexicalScope::SCOPE_TYPE_IF );
    265265
    266266        CompileBuffer(ESC_ENDIF,0);
    267267
    268268        //レキシカルスコープをレベルダウン
    269         GetLexicalScopes().End();
     269        compiler.codeGenerator.lexicalScopes.End();
    270270
    271271
     
    340340    if(!Parameter[0]) SetError(10,"While",cp);
    341341
    342     const CodeGenerator::PertialSchedule *pWhilePertialSchedule = NULL;
     342    const PertialSchedule *pWhilePertialSchedule = NULL;
    343343    Type tempType;
    344344    if( !NumOpe(Parameter,Type(),tempType) ){
     
    408408
    409409        //jne
    410         const CodeGenerator::PertialSchedule *pTempPertialSchedule1 = compiler.codeGenerator.op_jne( 0, sizeof(char), true );
     410        const PertialSchedule *pTempPertialSchedule1 = compiler.codeGenerator.op_jne( 0, sizeof(char), true );
    411411
    412412        //cmp ebx,0
     
    414414
    415415        //jne
    416         const CodeGenerator::PertialSchedule *pTempPertialSchedule2 = compiler.codeGenerator.op_jne( 0, sizeof(char), true );
     416        const PertialSchedule *pTempPertialSchedule2 = compiler.codeGenerator.op_jne( 0, sizeof(char), true );
    417417
    418418        //jmp (Wendまでジャンプ)
     
    436436
    437437    //レキシカルスコープをレベルアップ
    438     GetLexicalScopes().Start( obp, SCOPE_TYPE_WHILE );
     438    compiler.codeGenerator.lexicalScopes.Start( obp, LexicalScope::SCOPE_TYPE_WHILE );
    439439
    440440    //While内をコンパイル
    441441    CompileBuffer(0,COM_WEND);
    442442
    443     GetLexicalScopes().CallDestructorsOfScopeEnd();
     443    compiler.codeGenerator.lexicalScopes.CallDestructorsOfScopeEnd();
    444444
    445445    //jmp ...
     
    447447
    448448    //レキシカルスコープをレベルダウン
    449     GetLexicalScopes().End();
     449    compiler.codeGenerator.lexicalScopes.End();
    450450
    451451    if( pWhilePertialSchedule )
     
    486486
    487487    //jmp ...
    488     const CodeGenerator::PertialSchedule *pTempPertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(long), true );
     488    const PertialSchedule *pTempPertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(long), true );
    489489
    490490    //Continueアドレスのバックアップとセット
     
    528528
    529529    //jmp [カウンタ減少の場合の判定を飛び越す]
    530     const CodeGenerator::PertialSchedule *pTempPertialSchedule2 = compiler.codeGenerator.op_jmp( 0, sizeof(long), true );
     530    const PertialSchedule *pTempPertialSchedule2 = compiler.codeGenerator.op_jmp( 0, sizeof(long), true );
    531531
    532532    //jeジャンプ先のオフセット値
     
    552552
    553553    //レキシカルスコープをレベルアップ
    554     GetLexicalScopes().Start( obp, SCOPE_TYPE_FOR );
     554    compiler.codeGenerator.lexicalScopes.Start( obp, LexicalScope::SCOPE_TYPE_FOR );
    555555
    556556    //For内をコンパイル
    557557    CompileBuffer(0,COM_NEXT);
    558558
    559     GetLexicalScopes().CallDestructorsOfScopeEnd();
     559    compiler.codeGenerator.lexicalScopes.CallDestructorsOfScopeEnd();
    560560
    561561    if(szNextVariable[0]){
     
    569569
    570570    //レキシカルスコープをレベルダウン
    571     GetLexicalScopes().End();
     571    compiler.codeGenerator.lexicalScopes.End();
    572572
    573573    //jeジャンプ先のオフセット値
     
    588588
    589589    //レキシカルスコープをレベルアップ
    590     GetLexicalScopes().Start( obp, SCOPE_TYPE_DO );
     590    compiler.codeGenerator.lexicalScopes.Start( obp, LexicalScope::SCOPE_TYPE_DO );
    591591
    592592    //Do内をコンパイル
    593593    CompileBuffer(0,COM_LOOP);
    594594
    595     GetLexicalScopes().CallDestructorsOfScopeEnd();
    596 
    597     const CodeGenerator::PertialSchedule *pDoPertialSchedule = NULL;
     595    compiler.codeGenerator.lexicalScopes.CallDestructorsOfScopeEnd();
     596
     597    const PertialSchedule *pDoPertialSchedule = NULL;
    598598
    599599    extern char *basbuf;
     
    702702
    703703                //jne
    704                 const CodeGenerator::PertialSchedule *pTempPertialSchedule1 = compiler.codeGenerator.op_jne( 0, sizeof(char), true );
     704                const PertialSchedule *pTempPertialSchedule1 = compiler.codeGenerator.op_jne( 0, sizeof(char), true );
    705705
    706706                //cmp ebx,0
     
    708708
    709709                //jne
    710                 const CodeGenerator::PertialSchedule *pTempPertialSchedule2 = compiler.codeGenerator.op_jne( 0, sizeof(char), true );
     710                const PertialSchedule *pTempPertialSchedule2 = compiler.codeGenerator.op_jne( 0, sizeof(char), true );
    711711
    712712                if(basbuf[i3]=='0'){
     
    723723
    724724                    //jmp 2(ループを続ける)
    725                     const CodeGenerator::PertialSchedule *pTempPertialSchedule3 = compiler.codeGenerator.op_jmp( 0, sizeof(char), true );
     725                    const PertialSchedule *pTempPertialSchedule3 = compiler.codeGenerator.op_jmp( 0, sizeof(char), true );
    726726
    727727                    compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule1 );
     
    767767
    768768    //jmp ...
    769     const CodeGenerator::PertialSchedule *pTempPertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(long), true );
     769    const PertialSchedule *pTempPertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(long), true );
    770770
    771771    //レキシカルスコープをレベルダウン
    772     GetLexicalScopes().End();
     772    compiler.codeGenerator.lexicalScopes.End();
    773773
    774774    //jmpジャンプ先のオフセット値
     
    792792
    793793    //未解放のローカルオブジェクトのデストラクタを呼び出す
    794     GetLexicalScopes().CallDestructorsOfReturn();
     794    compiler.codeGenerator.lexicalScopes.CallDestructorsOfReturn();
    795795
    796796    //jmp ...(End Sub/Function)
     
    10491049
    10501050    //レキシカルスコープをレベルアップ
    1051     GetLexicalScopes().Start( obp, SCOPE_TYPE_SELECT );
     1051    compiler.codeGenerator.lexicalScopes.Start( obp, LexicalScope::SCOPE_TYPE_SELECT );
    10521052
    10531053    //Select Case内をコンパイル
     
    10661066
    10671067    //レキシカルスコープをレベルダウン
    1068     GetLexicalScopes().End();
     1068    compiler.codeGenerator.lexicalScopes.End();
    10691069
    10701070    pCaseSchedule=temp_pCaseSchedule;
  • trunk/abdev/BasicCompiler32/Compile_Var.cpp

    r241 r248  
    44#include <jenga/include/smoothie/LexicalAnalysis.h>
    55
    6 #include <LexicalScopingImpl.h>
     6#include <LexicalScope.h>
    77#include <CodeGenerator.h>
    88#include <Compiler.h>
     
    10551055
    10561056        //レキシカルスコープ
    1057         pVar->SetScopeLevel( GetLexicalScopes().GetNowLevel() );
    1058         pVar->SetScopeStartAddress( GetLexicalScopes().GetStartAddress() );
     1057        pVar->SetScopeLevel( compiler.codeGenerator.lexicalScopes.GetNowLevel() );
     1058        pVar->SetScopeStartAddress( compiler.codeGenerator.lexicalScopes.GetStartAddress() );
    10591059        pVar->bLiving=TRUE;
    10601060
     
    10901090
    10911091        //レキシカルスコープ
    1092         pVar->SetScopeLevel( GetLexicalScopes().GetNowLevel() );
    1093         pVar->SetScopeStartAddress( GetLexicalScopes().GetStartAddress() );
     1092        pVar->SetScopeLevel( compiler.codeGenerator.lexicalScopes.GetNowLevel() );
     1093        pVar->SetScopeStartAddress( compiler.codeGenerator.lexicalScopes.GetStartAddress() );
    10941094        pVar->bLiving=TRUE;
    10951095
  • trunk/abdev/BasicCompiler32/MakePeHdr.cpp

    r246 r248  
    55#include <jenga/include/smoothie/Smoothie.h>
    66
    7 #include <LexicalScopingImpl.h>
     7#include <LexicalScope.h>
    88#include <Class.h>
    99#include <Compiler.h>
     
    387387
    388388    //レキシカルスコープ情報を初期化
    389     GetLexicalScopes().Init(obp);
     389    compiler.codeGenerator.lexicalScopes.Init(obp);
    390390
    391391
  • trunk/abdev/BasicCompiler32/NumOpe_Relation.cpp

    r245 r248  
    142142        compiler.codeGenerator.op_cmp_RR( REG_EDX, REG_ECX );
    143143
    144         const CodeGenerator::PertialSchedule *pFalsePertialSchedule1;
     144        const PertialSchedule *pFalsePertialSchedule1;
    145145        if(IsSignedType(type_stack[sp-2])==0&&IsSignedType(type_stack[sp-1])==0){
    146146            //符号なし演算
     
    156156        }
    157157
    158         const CodeGenerator::PertialSchedule *pTruePertialSchedule;
     158        const PertialSchedule *pTruePertialSchedule;
    159159        if(IsSignedType(type_stack[sp-2])==0&&IsSignedType(type_stack[sp-1])==0){
    160160            //符号なし演算
     
    174174
    175175        //ja FalseSchedule2(偽へジャンプ)
    176         const CodeGenerator::PertialSchedule *pFalsePertialSchedule2 = compiler.codeGenerator.op_ja( 0, sizeof(char), true );
     176        const PertialSchedule *pFalsePertialSchedule2 = compiler.codeGenerator.op_ja( 0, sizeof(char), true );
    177177
    178178        //TrueScheduleのジャンプ先の設定
     
    351351        compiler.codeGenerator.op_cmp_RR( REG_EDX, REG_ECX );
    352352
    353         const CodeGenerator::PertialSchedule *pFalsePertialSchedule1;
     353        const PertialSchedule *pFalsePertialSchedule1;
    354354        if(IsSignedType(AnswerType)){
    355355            //符号あり演算
     
    365365        }
    366366
    367         const CodeGenerator::PertialSchedule *pTruePertialSchedule;
     367        const PertialSchedule *pTruePertialSchedule;
    368368        if(IsSignedType(AnswerType)){
    369369            //符号あり演算
     
    383383
    384384        //jb FalseSchedule2(偽へジャンプ)
    385         const CodeGenerator::PertialSchedule *pFalsePertialSchedule2 = compiler.codeGenerator.op_jb( 0, sizeof(char), true );
     385        const PertialSchedule *pFalsePertialSchedule2 = compiler.codeGenerator.op_jb( 0, sizeof(char), true );
    386386
    387387        //TrueScheduleのジャンプ先の設定
     
    563563        compiler.codeGenerator.op_cmp_RR( REG_EDX, REG_ECX );
    564564
    565         const CodeGenerator::PertialSchedule *pTruePertialSchedule1;
     565        const PertialSchedule *pTruePertialSchedule1;
    566566        if(IsSignedType(AnswerType)){
    567567            //符号あり演算
     
    577577        }
    578578
    579         const CodeGenerator::PertialSchedule *pFalsePertialSchedule;
     579        const PertialSchedule *pFalsePertialSchedule;
    580580        if(IsSignedType(AnswerType)){
    581581            //符号あり演算
     
    595595
    596596        //jb TrueSchedule2(真へジャンプ)
    597         const CodeGenerator::PertialSchedule *pTruePertialSchedule2 = compiler.codeGenerator.op_jb( 0, sizeof(char), true );
     597        const PertialSchedule *pTruePertialSchedule2 = compiler.codeGenerator.op_jb( 0, sizeof(char), true );
    598598
    599599        //FalseScheduleのジャンプ先の設定
     
    771771        compiler.codeGenerator.op_cmp_RR( REG_EDX, REG_ECX );
    772772
    773         const CodeGenerator::PertialSchedule *pTruePertialSchedule1;
     773        const PertialSchedule *pTruePertialSchedule1;
    774774        if(IsSignedType(AnswerType)){
    775775            //符号有り
     
    785785        }
    786786
    787         const CodeGenerator::PertialSchedule *pFalsePertialSchedule;
     787        const PertialSchedule *pFalsePertialSchedule;
    788788        if(IsSignedType(AnswerType)){
    789789            //符号有り
     
    803803
    804804        //ja TrueSchedule2(真へジャンプ)
    805         const CodeGenerator::PertialSchedule *pTruePertialSchedule2 = compiler.codeGenerator.op_ja( 0, sizeof(char), true );
     805        const PertialSchedule *pTruePertialSchedule2 = compiler.codeGenerator.op_ja( 0, sizeof(char), true );
    806806
    807807        //FalseScheduleのジャンプ先の設定
     
    975975
    976976        //jne TrueSchedule1(真へジャンプ)
    977         const CodeGenerator::PertialSchedule *pTruePertialSchedule1 = compiler.codeGenerator.op_jne( 0, sizeof(char), true );
     977        const PertialSchedule *pTruePertialSchedule1 = compiler.codeGenerator.op_jne( 0, sizeof(char), true );
    978978
    979979        //cmp edx,ecx
     
    981981
    982982        //jne TrueSchedule2(真へジャンプ)
    983         const CodeGenerator::PertialSchedule *pTruePertialSchedule2 = compiler.codeGenerator.op_jne( 0, sizeof(char), true );
     983        const PertialSchedule *pTruePertialSchedule2 = compiler.codeGenerator.op_jne( 0, sizeof(char), true );
    984984
    985985        //xor eax,eax(eaxを0にする)
     
    11411141
    11421142        //jne FalseSchedule1(偽へジャンプ)
    1143         const CodeGenerator::PertialSchedule *pFalsePertialSchedule1 = compiler.codeGenerator.op_jne( 0, sizeof(char), true );
     1143        const PertialSchedule *pFalsePertialSchedule1 = compiler.codeGenerator.op_jne( 0, sizeof(char), true );
    11441144
    11451145        //cmp edx,ecx
     
    11471147
    11481148        //jne FalseSchedule2(偽へジャンプ)
    1149         const CodeGenerator::PertialSchedule *pFalsePertialSchedule2 = compiler.codeGenerator.op_jne( 0, sizeof(char), true );
     1149        const PertialSchedule *pFalsePertialSchedule2 = compiler.codeGenerator.op_jne( 0, sizeof(char), true );
    11501150
    11511151        //mov eax,1
  • trunk/abdev/BasicCompiler_Common/Compile.cpp

    r247 r248  
    55#include <jenga/include/smoothie/SmoothieException.h>
    66
    7 #include <LexicalScopingImpl.h>
     7#include <LexicalScope.h>
    88#include <CodeGenerator.h>
    99#include <Compiler.h>
     
    173173            case ESC_EXITWHILE:
    174174                {
    175                     CScope *pScope = GetLexicalScopes().SearchScope( SCOPE_TYPE_WHILE );
     175                    LexicalScope *pScope = compiler.codeGenerator.lexicalScopes.SearchScope( LexicalScope::SCOPE_TYPE_WHILE );
    176176                    if( !pScope ){
    177177                        SetError(12,"Exit While",cp);
     
    183183            case ESC_EXITFOR:
    184184                {
    185                     CScope *pScope = GetLexicalScopes().SearchScope( SCOPE_TYPE_FOR );
     185                    LexicalScope *pScope = compiler.codeGenerator.lexicalScopes.SearchScope( LexicalScope::SCOPE_TYPE_FOR );
    186186                    if( !pScope ){
    187187                        SetError(12,"Exit For",cp);
     
    193193            case ESC_EXITDO:
    194194                {
    195                     CScope *pScope = GetLexicalScopes().SearchScope( SCOPE_TYPE_DO );
     195                    LexicalScope *pScope = compiler.codeGenerator.lexicalScopes.SearchScope( LexicalScope::SCOPE_TYPE_DO );
    196196                    if( !pScope ){
    197197                        SetError(12,"Exit Do",cp);
  • trunk/abdev/BasicCompiler_Common/VariableOpe.cpp

    r232 r248  
    55
    66#include <Compiler.h>
    7 #include <LexicalScopingImpl.h>
     7#include <LexicalScope.h>
    88#include <Variable.h>
    99#include <NamespaceSupporter.h>
     
    989989
    990990    //レキシカルスコープ
    991     pVar->SetScopeLevel( GetLexicalScopes().GetNowLevel() );
    992     pVar->SetScopeStartAddress( GetLexicalScopes().GetStartAddress() );
     991    pVar->SetScopeLevel( compiler.codeGenerator.lexicalScopes.GetNowLevel() );
     992    pVar->SetScopeStartAddress( compiler.codeGenerator.lexicalScopes.GetStartAddress() );
    993993    pVar->bLiving=TRUE;
    994994
  • trunk/abdev/BasicCompiler_Common/include/CodeGenerator.h

    r247 r248  
    22
    33#include <NativeCode.h>
     4#include <LexicalScope.h>
    45
    56#ifdef _AMD64_
     
    89#include "../../BasicCompiler32/MachineFixed.h"
    910#endif
    10 
    1111
    1212void ReallocNativeCodeBuffer();
     
    5151};
    5252
     53// コード生成時の部分的なスケジューリング
     54class PertialSchedule
     55{
     56    int codePos;    // バッファ位置
     57    int typeSize;   // 対象サイズ(一般的には8bit/32bit)
     58
     59    int _obpOld;    // 未完成
     60public:
     61    PertialSchedule( int codePos, int typeSize )
     62        : codePos( codePos )
     63        , typeSize( typeSize )
     64    {
     65        extern int obp;
     66        _obpOld = obp;
     67    }
     68    ~PertialSchedule()
     69    {
     70    }
     71
     72    int GetCodePos() const
     73    {
     74        return codePos;
     75    }
     76    int GetTypeSize() const
     77    {
     78        return typeSize;
     79    }
     80    int GetObpOld() const
     81    {
     82        return _obpOld;
     83    }
     84};
     85typedef std::vector<const PertialSchedule *> PertialSchedules;
     86
     87class LexicalScope
     88{
     89public:
     90    enum SCOPE_TYPE{
     91        //ベース
     92        SCOPE_TYPE_BASE,
     93
     94        //分岐
     95        SCOPE_TYPE_IF,
     96
     97        //ループ
     98        SCOPE_TYPE_DO,
     99        SCOPE_TYPE_FOR,
     100        SCOPE_TYPE_WHILE,
     101
     102        //ケース分け
     103        SCOPE_TYPE_SELECT,
     104    };
     105
     106private:
     107    int level;
     108    int StartAddress;
     109    SCOPE_TYPE TypeOfStatement;
     110
     111    PertialSchedules breakPertialSchedules;
     112
     113public:
     114    LexicalScope( int level, int addr, SCOPE_TYPE TypeOfStatement )
     115        : level( level )
     116        , StartAddress( addr )
     117        , TypeOfStatement( TypeOfStatement )
     118    {
     119    }
     120    ~LexicalScope()
     121    {
     122    }
     123
     124    int GetStartAddress()
     125    {
     126        return StartAddress;
     127    }
     128    SCOPE_TYPE GetTypeOfStatement()
     129    {
     130        return TypeOfStatement;
     131    }
     132
     133    void Break();
     134    void RunScheduleOfBreak();
     135};
     136
     137class LexicalScopes
     138{
     139    LexicalScope **ppScopes;
     140    int level;
     141
     142public:
     143
     144    LexicalScopes(){
     145        ppScopes = (LexicalScope **)malloc( 1 );
     146        level=0;
     147    }
     148    ~LexicalScopes(){
     149        free( ppScopes );
     150    }
     151
     152    //初期化(関数コンパイルの開始時に呼び出される)
     153    void Init(int addr);
     154
     155    // スコープを開始
     156    void Start( int addr, LexicalScope::SCOPE_TYPE TypeOfStatement );
     157
     158    // スコープを検索
     159    LexicalScope *SearchScope( LexicalScope::SCOPE_TYPE TypeOfStatement );
     160
     161    int GetNowLevel(void);
     162    void SetNowLevel( int level );
     163    int GetStartAddress(void);
     164
     165    void End();
     166
     167    //スコープ終了時のデストラクタ呼び出し
     168    void CallDestructorsOfScopeEnd();
     169
     170    //Returnステートメント用のデストラクタ呼び出し
     171    void CallDestructorsOfReturn( int BaseLevel = 0 );
     172};
     173
    53174class CodeGenerator
    54175{
    55176    NativeCode *pNativeCode;
    56177
    57 public:
    58 
    59     // コード生成時の部分的なスケジューリング
    60     class PertialSchedule
    61     {
    62         int codePos;    // バッファ位置
    63         int typeSize;   // 対象サイズ(一般的には8bit/32bit)
    64 
    65         int _obpOld;    // 未完成
    66     public:
    67         PertialSchedule( int codePos, int typeSize )
    68             : codePos( codePos )
    69             , typeSize( typeSize )
    70         {
    71             extern int obp;
    72             _obpOld = obp;
    73         }
    74         ~PertialSchedule()
    75         {
    76         }
    77 
    78         int GetCodePos() const
    79         {
    80             return codePos;
    81         }
    82         int GetTypeSize() const
    83         {
    84             return typeSize;
    85         }
    86         int GetObpOld() const
    87         {
    88             return _obpOld;
    89         }
    90     };
    91 
    92178private:
    93179    // 部分スケジュールの管理
    94     typedef std::vector<const PertialSchedule *> PertialSchedules;
    95180    PertialSchedules pertialSchedules;
    96181
     
    107192    // Gotoスケジュールの管理
    108193    std::vector<GotoLabelSchedule> gotoLabelSchedules;
     194
     195    // レキシカルスコープの管理
     196    LexicalScopes lexicalScopes;
    109197
    110198    CodeGenerator()
  • trunk/abdev/BasicCompiler_Common/include/LexicalScope.h

    r245 r248  
    22
    33#include <jenga/include/smoothie/Smoothie.h>
    4 #include <jenga/include/smoothie/LexicalScoping.h>
    54
    6 class ScopeImpl : public CScope
    7 {
    8 public:
    9     ScopeImpl( int level, int addr, SCOPE_TYPE TypeOfStatement )
    10         : CScope( level, addr, TypeOfStatement )
    11     {
    12     }
    13     ~ScopeImpl();
     5#include <CodeGenerator.h>
    146
    15     virtual void Break();
    16     virtual void RunScheduleOfBreak();
    17 };
    18 
    19 class LexicalScopesImpl : public CLexicalScopes
    20 {
    21     virtual CScope *CreateScope( int level, int addr, SCOPE_TYPE TypeOfStatement )
    22     {
    23         return new ScopeImpl( level, addr, TypeOfStatement );
    24     }
    25 
    26 public:
    27 
    28     virtual void End();
    29 
    30     //スコープ終了時のデストラクタ呼び出し
    31     virtual void CallDestructorsOfScopeEnd();
    32 
    33     //Returnステートメント用のデストラクタ呼び出し
    34     virtual void CallDestructorsOfReturn( int BaseLevel = 0 );
    35 };
    36 
    37 LexicalScopesImpl &GetLexicalScopes();
  • 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.