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

BreakPertialScheduleをリファクタリング

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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()
Note: See TracChangeset for help on using the changeset viewer.