Changeset 248 in dev for trunk/abdev/BasicCompiler_Common/include
- Timestamp:
- Jul 29, 2007, 12:33:04 PM (17 years ago)
- Location:
- trunk/abdev/BasicCompiler_Common/include
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/abdev/BasicCompiler_Common/include/CodeGenerator.h
r247 r248 2 2 3 3 #include <NativeCode.h> 4 #include <LexicalScope.h> 4 5 5 6 #ifdef _AMD64_ … … 8 9 #include "../../BasicCompiler32/MachineFixed.h" 9 10 #endif 10 11 11 12 12 void ReallocNativeCodeBuffer(); … … 51 51 }; 52 52 53 // コード生成時の部分的なスケジューリング 54 class PertialSchedule 55 { 56 int codePos; // バッファ位置 57 int typeSize; // 対象サイズ(一般的には8bit/32bit) 58 59 int _obpOld; // 未完成 60 public: 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 }; 85 typedef std::vector<const PertialSchedule *> PertialSchedules; 86 87 class LexicalScope 88 { 89 public: 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 106 private: 107 int level; 108 int StartAddress; 109 SCOPE_TYPE TypeOfStatement; 110 111 PertialSchedules breakPertialSchedules; 112 113 public: 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 137 class LexicalScopes 138 { 139 LexicalScope **ppScopes; 140 int level; 141 142 public: 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 53 174 class CodeGenerator 54 175 { 55 176 NativeCode *pNativeCode; 56 177 57 public:58 59 // コード生成時の部分的なスケジューリング60 class PertialSchedule61 {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() const79 {80 return codePos;81 }82 int GetTypeSize() const83 {84 return typeSize;85 }86 int GetObpOld() const87 {88 return _obpOld;89 }90 };91 92 178 private: 93 179 // 部分スケジュールの管理 94 typedef std::vector<const PertialSchedule *> PertialSchedules;95 180 PertialSchedules pertialSchedules; 96 181 … … 107 192 // Gotoスケジュールの管理 108 193 std::vector<GotoLabelSchedule> gotoLabelSchedules; 194 195 // レキシカルスコープの管理 196 LexicalScopes lexicalScopes; 109 197 110 198 CodeGenerator() -
trunk/abdev/BasicCompiler_Common/include/LexicalScope.h
r245 r248 2 2 3 3 #include <jenga/include/smoothie/Smoothie.h> 4 #include <jenga/include/smoothie/LexicalScoping.h>5 4 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> 14 6 15 virtual void Break();16 virtual void RunScheduleOfBreak();17 };18 19 class LexicalScopesImpl : public CLexicalScopes20 {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();
Note:
See TracChangeset
for help on using the changeset viewer.