source: dev/trunk/abdev/BasicCompiler64/Compile_ProcOp.cpp@ 366

Last change on this file since 366 was 366, checked in by dai_9181, 16 years ago

Tryスコープのコード補完機能のバグを修正(EndTryコード補間が過剰に行われていた)。
コンパイラのログ生成処理をきった。

File size: 20.5 KB
RevLine 
[206]1#include "stdafx.h"
2
[183]3#include <jenga/include/smoothie/Smoothie.h>
4#include <jenga/include/smoothie/LexicalAnalysis.h>
5
[169]6#include <Program.h>
[198]7#include <Compiler.h>
[206]8#include <Class.h>
[169]9
[3]10#include "../BasicCompiler_Common/common.h"
11#include "Opcode.h"
12
[86]13void SystemProc( const UserProc &userProc ){
14 if( userProc.GetName() == "_System_GetEip" ){
[3]15 //mov rax,qword ptr[rsp]
[226]16 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_RAX,REG_RSP,0,MOD_BASE);
[3]17
18 //ret
[226]19 compiler.codeGenerator.op_ret();
[3]20 }
[86]21 else if( userProc.GetName() == "_System_InitDllGlobalVariables" ){
[3]22 ////////////////////////////////////////
23 // DLLのグローバル領域をコンパイル
24 ////////////////////////////////////////
[266]25 if(!compiler.IsDll()){
[3]26 //ret
[226]27 compiler.codeGenerator.op_ret();
[3]28
29 return;
30 }
31
[206]32 const UserProc *pBackUserProc = &UserProc::CompilingUserProc();
[75]33 UserProc::CompileStartForGlobalArea();
[3]34
35 int BackCp;
36 BackCp=cp;
37 cp=-1;
38
39 //sub rsp,スタックフレームサイズ
[255]40 const PertialSchedule *pStackFramePertialSchedule = compiler.codeGenerator.op_sub_rsp( 0, true );
[3]41
42 extern BOOL bDebugCompile;
43 if(bDebugCompile){
44 //デバッグ用の変数を定義
45 DebugVariable();
46 }
47
48 //GC用の変数を定義
49 InitGCVariables();
50
[129]51 //_System_StartupProgramの呼び出し
[206]52 extern const UserProc *pSub_System_StartupProgram;
[226]53 compiler.codeGenerator.op_call(pSub_System_StartupProgram);
[129]54
[42]55 //クラスに属する静的メンバを定義
[266]56 compiler.GetObjectModule().meta.GetClasses().InitStaticMember();
[42]57
[3]58 GetGlobalDataForDll();
59
60 //add rsp,スタックフレームサイズ
[226]61 compiler.codeGenerator.op_add_RV(REG_RSP,pobj_sf->GetFrameSize(0));
[3]62
63 //スタックフレームスケジュール(subコマンドに渡す値)
[255]64 compiler.codeGenerator.opfix( pStackFramePertialSchedule, pobj_sf->GetFrameSize(0) );
[3]65
[75]66 UserProc::CompileStartForUserProc( pBackUserProc );
[3]67 cp=BackCp;
68
69 //ret
[226]70 compiler.codeGenerator.op_ret();
[3]71 }
[86]72 else if( userProc.GetName() == "_System_InitStaticLocalVariables" ){
[3]73 //静的ローカルオブジェクトのコンストラクタ呼び出し
74
75 //sub rsp,スタックフレームサイズ
[255]76 const PertialSchedule *pStackFramePertialSchedule = compiler.codeGenerator.op_sub_rsp( 0, true );
[3]77
[266]78 BOOST_FOREACH( Variable *pVar, compiler.GetObjectModule().meta.GetGlobalVars() ){
[75]79 if(memicmp(pVar->GetName().c_str(),"Static%",7)==0){
[3]80 //コンストラクタ呼び出し
[206]81 if( pVar->GetType().IsObject() ){
[3]82
83 //エラー用
[75]84 cp=pVar->source_code_address;
[3]85
[50]86 CallConstructor(
[75]87 pVar->GetName().c_str(),
[206]88 pVar->GetSubscripts(),
89 pVar->GetType(),
90 pVar->GetParamStrForConstructor().c_str());
[3]91 }
92 }
93 }
94
95 //add rsp,スタックフレームサイズ
[226]96 compiler.codeGenerator.op_add_RV(REG_RSP,pobj_sf->GetFrameSize(0));
[3]97
98 //スタックフレームスケジュール(subコマンドに渡す値)
[255]99 compiler.codeGenerator.opfix( pStackFramePertialSchedule, pobj_sf->GetFrameSize(0) );
[3]100
101 //ret
[226]102 compiler.codeGenerator.op_ret();
[3]103 }
[86]104 else if( userProc.GetName() == "_System_Call_Destructor_of_GlobalObject" ){
[3]105 //sub rsp,8(※RSPを16バイト境界にあわせるため)
[226]106 compiler.codeGenerator.op_sub_rsp(0x8);
[3]107
108
[206]109 const UserProc *pBackUserProc = &UserProc::CompilingUserProc();
[75]110 UserProc::CompileStartForGlobalArea();
[3]111
[254]112 compiler.codeGenerator.lexicalScopes.CallDestructorsOfScopeEnd();
[3]113
[75]114 UserProc::CompileStartForUserProc( pBackUserProc );
[3]115
116
117 //add rsp,8
[226]118 compiler.codeGenerator.op_add_RV(REG_RSP,0x8);
[3]119
120 //ret
[226]121 compiler.codeGenerator.op_ret();
[3]122 }
[90]123 else{
124 SetError();
125 }
126}
[206]127void AutoGeneration(const UserProc &userProc){
[90]128 if( userProc.GetName() == "InitializeUserTypes"
[89]129 && userProc.HasParentClass()
[353]130 && userProc.GetParentClass().GetName() == "_System_TypeBase" )
131 {
132 compiler.GetObjectModule().meta.GetClasses().Compile_System_InitializeUserTypes();
[86]133 }
[355]134 else if( userProc.GetName() == "InitializeUserTypesForBaseType"
135 && userProc.HasParentClass()
136 && userProc.GetParentClass().GetName() == "_System_TypeBase" )
137 {
138 compiler.GetObjectModule().meta.GetClasses().Compile_System_InitializeUserTypesForBaseType();
139 }
[95]140 else if( userProc.GetName() == "RegisterGlobalRoots"
141 && userProc.HasParentClass()
[353]142 && userProc.GetParentClass().GetName() == "_System_CGarbageCollection" )
143 {
144 Compile_AddGlobalRootsForGc();
[95]145 }
[309]146 else if( userProc.GetName() == compiler.globalAreaProcName ){
147 ////////////////////////////////////////
148 // グローバル領域をコンパイル
149 ////////////////////////////////////////
150
[364]151 UserProc::pGlobalProc = &userProc;
152
[309]153 const UserProc *pBackUserProc = &UserProc::CompilingUserProc();
154 UserProc::CompileStartForGlobalArea();
155
156 int BackCp = cp;
157 cp=-1;
158
159 //クラスに属する静的メンバを定義
160 compiler.GetObjectModule().meta.GetClasses().InitStaticMember();
161
162 //グローバル実行領域をコンパイル開始
163 CompileBuffer(0,0);
164
165 //Goto未知ラベルスケジュールが存在したらエラーにする
166 BOOST_FOREACH( const GotoLabelSchedule *pGotoLabelSchedule, compiler.codeGenerator.gotoLabelSchedules )
167 {
168 if(pGotoLabelSchedule->GetName().size()>0){
169 SetError(6,pGotoLabelSchedule->GetName(),pGotoLabelSchedule->GetSourceCodePos());
170 }
171 else{
172 char temporary[255];
173 sprintf(temporary,"%d",pGotoLabelSchedule->GetLineNum());
174 SetError(6,temporary,pGotoLabelSchedule->GetSourceCodePos());
175 }
176 }
177
178 UserProc::CompileStartForUserProc( pBackUserProc );
179 cp=BackCp;
180 }
[350]181 else if( userProc.HasParentClass()
182 && userProc.IsCastOperator()
183 && userProc.ReturnType().IsInterface() )
184 {
185 // インターフェイス型にキャストするためのメソッド
186
187 int vtblMasterListIndex = userProc.GetParentClass().GetVtblMasterListIndex( &userProc.ReturnType().GetClass() );
188
189 char temporary[1024];
190 sprintf( temporary,
191 "Return New %s(ObjPtr( This ),Get_LONG_PTR( (Get_LONG_PTR( ObjPtr(This) ) + SizeOf(LONG_PTR)*%d) As VoidPtr ) As VoidPtr )",
192 userProc.ReturnType().GetClass().GetName().c_str(),
193 vtblMasterListIndex
194 );
195 MakeMiddleCode( temporary );
196
197 ChangeOpcode( temporary );
198 }
[86]199 else{
200 SetError();
201 }
[3]202}
[206]203void _compile_proc(const UserProc *pUserProc){
[3]204 extern char *basbuf;
205 extern HANDLE hHeap;
206 extern BOOL bDebugCompile;
[76]207 int i3,i4;
[3]208 char temporary[VN_SIZE];
209
[206]210 if( pUserProc->GetLocalVars().size() ){
[76]211 SetError();
212 return;
213 }
214
[206]215 trace_for_sourcecodestep( "★★★ " << pUserProc->GetFullName() << "のコンパイルを開始" );
216
[75]217 pUserProc->CompleteCompile();
[3]218
219 extern BOOL bSystemProc;
[75]220 if(memcmp(pUserProc->GetName().c_str(),"_System_",8)==0) bSystemProc=1;
[3]221 else bSystemProc=0;
222
223 extern BOOL bDebugSupportProc;
[75]224 if(memcmp(pUserProc->GetName().c_str(),"_DebugSys_",10)==0){
[3]225 if(!bDebugCompile){
226 return;
227 }
228 bDebugSupportProc=1;
229 }
230 else bDebugSupportProc=0;
231
[89]232 //コンパイル中の関数が属するクラス
[206]233 compiler.pCompilingClass=pUserProc->GetParentClassPtr();
[89]234
235 //コンパイルスタートをクラス管理クラスに追加
[266]236 compiler.GetObjectModule().meta.GetClasses().StartCompile( pUserProc );
[89]237
238 //コンパイル中の関数
239 UserProc::CompileStartForUserProc( pUserProc );
240
[101]241 // コンパイル中の関数が属する名前空間
[202]242 compiler.GetNamespaceSupporter().SetLivingNamespaceScopes( pUserProc->GetNamespaceScopes() );
[101]243
[108]244 // コンパイル中の関数でImportsされている名前空間
[202]245 compiler.GetNamespaceSupporter().SetImportedNamespaces( pUserProc->GetImportedNamespaces() );
[108]246
[226]247 // コード生成対象を選択
248 compiler.codeGenerator.Select( (const_cast<UserProc *>(pUserProc))->GetNativeCode() );
249
[75]250 if(pUserProc->IsSystem()){
[3]251 ////////////////////
252 // 特殊関数
253 ////////////////////
254
255 extern int AllLocalVarSize;
256 AllLocalVarSize=0;
257
258 //スタックフレーム管理用オブジェクトを初期化
[308]259 extern StackFrame *pobj_sf;
260 pobj_sf=new StackFrame();
[3]261
[86]262 SystemProc(*pUserProc);
[3]263
264 //スタックフレーム管理用オブジェクトを破棄
265 delete pobj_sf;
266 pobj_sf=0;
267
268 return;
269 }
270
[353]271 if( !pUserProc->IsAutoGeneration() )
272 {
273 cp=pUserProc->GetCodePos();
274 for(;;cp++){
275 if(IsCommandDelimitation(basbuf[cp])) break;
276 }
277 cp--;
[3]278 }
279
280 //プロシージャ抜け出しスケジュール(Exit Sub/Function)
[254]281 compiler.codeGenerator.exitSubCodePositions.clear();
[3]282
283 //ラベル用のメモリを確保
[262]284 compiler.codeGenerator.gotoLabels.clear();
[3]285
286 //Gotoラベルスケジュール
[254]287 compiler.codeGenerator.gotoLabelSchedules.clear();
[3]288
289 //With情報のメモリを確保
290 extern WITHINFO WithInfo;
291 WithInfo.ppName=(char **)HeapAlloc(hHeap,0,1);
292 WithInfo.pWithCp=(int *)HeapAlloc(hHeap,0,1);
293 WithInfo.num=0;
294
295 //重複エラー情報管理のメモリを確保
296 extern char **SynonymErrorWords;
297 extern int SynonymErrorNum;
298 SynonymErrorNum=0;
299 SynonymErrorWords=(char **)HeapAlloc(hHeap,0,1);
300
301 //Continueアドレスを初期化
[242]302 compiler.codeGenerator.ClearContinueArea();
[3]303
304 //ローカル変数に関する情報
305 extern int AllLocalVarSize;
306 AllLocalVarSize=0;
307
308 //レキシカルスコープ情報を初期化
[308]309 compiler.codeGenerator.lexicalScopes.Init( compiler.codeGenerator.GetNativeCodeSize() );
[3]310
311
312 /////////////////////////////////////
313 // パラメータ用の変数データを考慮
314 /////////////////////////////////////
315
[75]316 //パラメータ用の変数データを考慮
317 for(i3=(int)pUserProc->RealParams().size()-1;i3>=0;i3--){
318 Parameter &param = *pUserProc->RealParams()[i3];
[3]319
[308]320 Variable *pVar = new Variable( param.GetVarName(), param, false, param.IsRef(), "", false );
[3]321
[75]322 if( param.IsArray() ){
[206]323 pVar->SetArray( param.GetSubscripts() );
[3]324 }
325
[75]326 int varSize;
327 if( param.IsRef() == false && param.IsStruct() ){
[64]328 //構造体のByValパラメータ
[75]329 pVar->ThisIsParameter();
330 varSize=PTR_SIZE;
[3]331 }
332 else{
[75]333 if( param.IsArray() == false ){
334 varSize = pVar->GetMemorySize();
[3]335 }
336 else{
[75]337 varSize=PTR_SIZE;
[3]338 }
339 }
[75]340 AllLocalVarSize+=varSize;
[206]341 pVar->SetOffsetAddress( AllLocalVarSize );
[3]342
343 //レキシカルスコープ情報
[254]344 pVar->SetScopeLevel( compiler.codeGenerator.lexicalScopes.GetNowLevel() );
345 pVar->SetScopeStartAddress( compiler.codeGenerator.lexicalScopes.GetStartAddress() );
[75]346 pVar->bLiving=TRUE;
[3]347
[206]348 pUserProc->GetLocalVars().push_back( pVar );
[3]349 }
350
351 //Thisポインタを示すローカルオフセット値をセット
352 extern int LocalVar_ThisPtrOffset;
353 LocalVar_ThisPtrOffset=AllLocalVarSize;
354
355 //スタックフレーム管理用クラスを初期化
[308]356 extern StackFrame *pobj_sf;
357 pobj_sf=new StackFrame();
[3]358
359
360 ///////////////////////
361 // ここからコード生成
362
[75]363 for(i3=(int)pUserProc->RealParams().size()-1;i3>=0;i3--){
364 Parameter &param = *pUserProc->RealParams()[i3];
[3]365 if(i3==3){
[75]366 if(param.IsReal()&&param.IsRef() == false){
[3]367 //movsd qword ptr[rsp+0x20],xmm3
[226]368 compiler.codeGenerator.op_movsd_MR(REG_XMM3,REG_RSP,0x20,MOD_BASE_DISP32);
[3]369 }
370 else{
371 //mov qword ptr[rsp+0x20],r9
[226]372 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_R9,REG_RSP,0x20,MOD_BASE_DISP32);
[3]373 }
374 }
375 if(i3==2){
[75]376 if(param.IsReal()&&param.IsRef() == false){
[3]377 //movsd qword ptr[rsp+0x18],xmm2
[226]378 compiler.codeGenerator.op_movsd_MR(REG_XMM2,REG_RSP,0x18,MOD_BASE_DISP32);
[3]379 }
380 else{
381 //mov qword ptr[rsp+0x18],r8
[226]382 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_R8,REG_RSP,0x18,MOD_BASE_DISP32);
[3]383 }
384 }
385 if(i3==1){
[75]386 if(param.IsReal()&&param.IsRef() == false){
[3]387 //movsd qword ptr[rsp+0x10],xmm1
[226]388 compiler.codeGenerator.op_movsd_MR(REG_XMM1,REG_RSP,0x10,MOD_BASE_DISP32);
[3]389 }
390 else{
391 //mov qword ptr[rsp+0x10],rdx
[226]392 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_RDX,REG_RSP,0x10,MOD_BASE_DISP32);
[3]393 }
394 }
395 if(i3==0){
[75]396 if(param.IsReal()&&param.IsRef() == false){
[3]397 //movsd qword ptr[rsp+0x8],xmm0
[226]398 compiler.codeGenerator.op_movsd_MR(REG_XMM0,REG_RSP,0x8,MOD_BASE_DISP32);
[3]399 }
400 else{
401 //mov qword ptr[rsp+0x8],rcx
[226]402 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_RCX,REG_RSP,0x8,MOD_BASE_DISP32);
[3]403 }
404 }
405 }
406
407 //ret用のアドレスを考慮
408 AllLocalVarSize+=sizeof(_int64);
409
410 //sub rsp,スタックフレームサイズ
[255]411 const PertialSchedule *pStackFramePertialSchedule = compiler.codeGenerator.op_sub_rsp( 0, true );
[3]412
413 //mov qword ptr[rsp+offset],reg ※スタックフレームを利用
414 pobj_sf->push(REG_RBX);
415 pobj_sf->push(REG_RSI);
416 pobj_sf->push(REG_RDI);
417 pobj_sf->push(REG_R12);
418 pobj_sf->push(REG_R13);
419 pobj_sf->push(REG_R14);
420 pobj_sf->push(REG_R15);
421
422 //ローカル変数のベース値
423 int BaseLocalVar;
424 BaseLocalVar=AllLocalVarSize;
425
[75]426 if( !pUserProc->ReturnType().IsNull() ){
[3]427 //戻り値が存在するとき
428
[75]429 const char *temp = pUserProc->GetName().c_str();
430 if( temp[0]==1&&temp[1]==ESC_OPERATOR ){
431 temp = "_System_ReturnValue";
432 }
[3]433
[75]434 if( pUserProc->ReturnType().IsStruct() ){
[64]435 //戻り値用の構造体(値型)はパラメータで引き渡される
[3]436 }
437 else{
[89]438 if( pUserProc->ReturnType().IsObject() ){
[308]439 sprintf(temporary,"%s=Nothing%c%c%s",temp,1,ESC_AS, compiler.TypeToString( pUserProc->ReturnType() ).c_str() );
[89]440 }
441 else{
442 //戻り値用の変数の定義
[308]443 sprintf(temporary,"%s%c%c%s",temp,1,ESC_AS, compiler.TypeToString( pUserProc->ReturnType() ).c_str() );
[89]444 }
[40]445
[3]446 OpcodeDim(temporary,0);
447 }
448 }
449
[255]450 const PertialSchedule *pRspOffsetPertialSchedule1 = NULL;
451 const PertialSchedule *pRspOffsetPertialSchedule2 = NULL;
[3]452 if(bDebugCompile&&bDebugSupportProc==0){
453 //mov rdx, qword ptr[rsp+スタックフレームサイズ]
[255]454 pRspOffsetPertialSchedule1 = compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_RDX,REG_RSP,0,MOD_BASE_DISP32, Schedule::None, true );
[3]455
456 //mov rcx,rsp
[226]457 compiler.codeGenerator.op_mov_RR(REG_RCX,REG_RSP);
[3]458
459 //add rcx,スタックフレームサイズ+sizeof(_int64) ※ret用のサイズを考慮
[255]460 pRspOffsetPertialSchedule2 = compiler.codeGenerator.op_add_RV(REG_RCX,0, Schedule::None, true );
[3]461
462 //call _DebugSys_StartProc
[206]463 extern const UserProc *pSub_DebugSys_StartProc;
[226]464 compiler.codeGenerator.op_call(pSub_DebugSys_StartProc);
[3]465 }
466
[206]467 if(compiler.pCompilingClass){
468 if( pUserProc->GetName() == compiler.pCompilingClass->GetName() ){
[3]469 ////////////////////////////////////
470 // コンストラクタをコンパイルするとき
471 ////////////////////////////////////
472
[17]473 //コンストラクタのコンパイル開始を通知
[206]474 compiler.pCompilingClass->NotifyStartConstructorCompile();
[17]475
[27]476 //基底クラスかどうかの識別
477 //(継承元がインターフェイスの場合も基底クラスと見なす)
[3]478 BOOL bThisIsSuperClass;
[206]479 if( !compiler.pCompilingClass->HasSuperClass() ) bThisIsSuperClass=1;
480 else if( compiler.pCompilingClass->GetSuperClass().GetConstructorMethod() == NULL ){
[3]481 //インターフェイスを継承したときはコンストラクタを持たない
482 bThisIsSuperClass=1;
483 }
484 else bThisIsSuperClass=0;
485
486 if(!bThisIsSuperClass){
487 /* サブクラスコンストラクタをコンパイルしているときは、
[27]488 基底クラスのコンストラクタを呼び出す */
[3]489
490 i3=cp+1;
491 while(IsCommandDelimitation(basbuf[i3])) i3++;
492 for(i4=0;;i3++,i4++){
493 if(!IsVariableChar(basbuf[i3])){
494 temporary[i4]=0;
495 break;
496 }
497 temporary[i4]=basbuf[i3];
498 }
[206]499 if( compiler.pCompilingClass->GetSuperClass().GetName() == temporary ){
[27]500 //基底クラスのコンストラクタを呼び出す
[3]501 cp=i3;
502 for(i4=0;;cp++,i4++){
503 if(IsCommandDelimitation(basbuf[cp])){
504 temporary[i4]=0;
505 break;
506 }
507 temporary[i4]=basbuf[cp];
508 }
509 if(!(temporary[0]=='('&&temporary[lstrlen(temporary)-1]==')')){
510 SetError(1,NULL,cp);
511 }
512 RemoveStringPare(temporary);
513
[89]514 Type dummyType;
515 CallProc( PROC_DEFAULT
[206]516 , &compiler.pCompilingClass->GetSuperClass().GetConstructorMethod()->GetUserProc()
517 , compiler.pCompilingClass->GetSuperClass().GetConstructorMethod()->GetUserProc().GetName().c_str()
[89]518 , temporary
[331]519 , Type() // baseTypeはなし
520 , dummyType
521 );
[3]522 }
523 else{
[27]524 //基底クラスのコンストラクタを暗黙的に呼び出す
[3]525 Opcode_CallProc("",
[206]526 &compiler.pCompilingClass->GetSuperClass().GetConstructorMethod()->GetUserProc(),
[3]527 0,
[308]528 "");
[3]529 }
530 }
531 }
[75]532 else if( pUserProc->IsDestructor() ){
[18]533 //デストラクタをコンパイルしたとき
534
535 //デストラクタのコンパイル開始を通知
[206]536 compiler.pCompilingClass->NotifyStartDestructorCompile();
[18]537 }
[3]538 }
539
540 //////////////////////////////////////////
541 //////////////////////////////////////////
542 ////// プロシージャ内をコンパイル ////////
[90]543 if( pUserProc->IsAutoGeneration() ){
544 AutoGeneration( *pUserProc );
545 }
[75]546 else{
[90]547 if(pUserProc->IsMacro()){
548 CompileBuffer(ESC_ENDMACRO,0);
549 }
550 else{
551 if(pUserProc->IsSub()){
552 CompileBuffer(ESC_ENDSUB,0);
553 }
554 else if(pUserProc->IsFunction()){
555 CompileBuffer(ESC_ENDFUNCTION,0);
556 }
557 }
[75]558 }
[3]559 //////////////////////////////////////////
560 //////////////////////////////////////////
561
[206]562 if( compiler.pCompilingClass ){
[17]563
[206]564 if( compiler.pCompilingClass->IsCompilingConstructor() ){
[17]565 // コンストラクタをコンパイルしていたとき
[18]566
[17]567 // コンストラクタのコンパイルが完了したことを通知
[206]568 compiler.pCompilingClass->NotifyFinishConstructorCompile();
[17]569 }
[75]570 else if( pUserProc->IsDestructor() ){
[3]571 ////////////////////////////////////
572 //デストラクタをコンパイルしたとき
573 ////////////////////////////////////
574
[18]575 // デストラクタのコンパイルが完了したことを通知
[206]576 compiler.pCompilingClass->NotifyFinishDestructorCompile();
[18]577
[206]578 if( compiler.pCompilingClass->HasSuperClass() ){
[3]579 /* サブクラスのデストラクタをコンパイルしているときは、
[27]580 基底クラスのデストラクタを呼び出す */
[3]581
[206]582 const CMethod *method = compiler.pCompilingClass->GetSuperClass().GetDestructorMethod();
[51]583 if( method ){
[3]584 Opcode_CallProc("",
[206]585 &method->GetUserProc(),
[3]586 0,
[308]587 "");
[3]588 }
589 }
590 }
591 }
592
[366]593 // Tryスコープの検証
594 Exception::InspectTryScope();
595
[3]596 //With情報のメモリを解放
597 for(i3=0;i3<WithInfo.num;i3++){
598 SetError(22,"With",WithInfo.pWithCp[i3]);
599 HeapDefaultFree(WithInfo.ppName[i3]);
600 }
601 HeapDefaultFree(WithInfo.ppName);
602 HeapDefaultFree(WithInfo.pWithCp);
603
604 //ローカルオブジェクト(レキシカルスコープレベル=0)の解放処理
[254]605 compiler.codeGenerator.lexicalScopes.CallDestructorsOfScopeEnd();
[3]606
[34]607 //プロシージャ抜け出しスケジュール(Exit Sub/Function)
[254]608 compiler.codeGenerator.ResolveExitSubSchedule();
[34]609
610 if(bDebugCompile&&bDebugSupportProc==0){
611 //call _DebugSys_EndProc
[206]612 extern const UserProc *pSub_DebugSys_EndProc;
[226]613 compiler.codeGenerator.op_call(pSub_DebugSys_EndProc);
[34]614 }
615
[75]616 if( !pUserProc->ReturnType().IsNull() ){
[3]617 //////////////////////////////////
618 // 戻り値をraxまたはxmm0に設定
619 //////////////////////////////////
620
621 RELATIVE_VAR RelativeVar;
622
[75]623 const char *temp = pUserProc->GetName().c_str();
624 if( temp[0]==1 && temp[1]==ESC_OPERATOR ){
[3]625 temp="_System_ReturnValue";
[75]626 }
627 GetVarOffsetReadWrite(temp,&RelativeVar,Type());
[3]628
[316]629 const Type &returnType = pUserProc->ReturnType();
630 if( returnType.IsObject() || returnType.IsStruct() )
631 {
[3]632 SetVarPtrToReg(REG_RAX,&RelativeVar);
[316]633 if( returnType.IsObject() )
634 {
[64]635 //mov rax,qword ptr[rax]
[226]636 compiler.codeGenerator.op_mov_RM( sizeof(_int64), REG_RAX, REG_RAX, 0, MOD_BASE );
[64]637 }
[3]638 }
[316]639 else if( returnType.IsDouble() )
640 {
[3]641 //64ビット実数型
642 SetXmmReg_DoubleVariable(&RelativeVar,REG_XMM0);
643 }
[316]644 else if( returnType.IsSingle() )
645 {
[3]646 //32ビット実数型
647 SetXmmReg_SingleVariable(&RelativeVar,REG_XMM0);
648 }
[316]649 else if( returnType.IsWhole() )
650 {
[3]651 //整数型
[318]652 SetReg_WholeVariable(returnType,&RelativeVar,REG_RAX);
[3]653 }
654 else SetError(300,NULL,cp);
655 }
656
657 //ローカル変数領域のサイズをスタックフレームに通知
[220]658 int localParmSize = AllLocalVarSize - BaseLocalVar;
[232]659 int stackFrameSize = pobj_sf->GetFrameSize( localParmSize );
[3]660
661 //ローカル変数アドレススケジュール
[254]662 BOOST_FOREACH( const PertialSchedule *pPertialSchedule, compiler.codeGenerator.localVarPertialSchedules )
663 {
[255]664 compiler.codeGenerator.opfix_offset( pPertialSchedule, AllLocalVarSize + stackFrameSize );
[3]665 }
[254]666 compiler.codeGenerator.localVarPertialSchedules.clear();
[206]667 BOOST_FOREACH( Variable *pVar, pUserProc->GetLocalVars() ){
[3]668 //後にデバッグで利用する
[206]669 pVar->SetOffsetAddress(
[220]670 AllLocalVarSize + stackFrameSize - pVar->GetOffsetAddress()
[206]671 );
[3]672 }
673
674 //mov reg,qword ptr[rsp+offset] ※スタックフレームを利用
675 pobj_sf->pop(REG_R15);
676 pobj_sf->pop(REG_R14);
677 pobj_sf->pop(REG_R13);
678 pobj_sf->pop(REG_R12);
679 pobj_sf->pop(REG_RDI);
680 pobj_sf->pop(REG_RSI);
681 pobj_sf->pop(REG_RBX);
682
[220]683 int stackFrameAndLocalParamSize = localParmSize + stackFrameSize;
[3]684
685 //add rsp,スタックフレームサイズ
[226]686 compiler.codeGenerator.op_add_rsp(stackFrameAndLocalParamSize);
[3]687
[142]688 //ret
[226]689 compiler.codeGenerator.op_ret();
[3]690
691
692 //デバッグ用
[255]693 if( pRspOffsetPertialSchedule1 ){
694 compiler.codeGenerator.opfix( pRspOffsetPertialSchedule1, stackFrameAndLocalParamSize );
695 compiler.codeGenerator.opfix( pRspOffsetPertialSchedule2, stackFrameAndLocalParamSize + sizeof(_int64) );
[3]696 }
697
698
699 //スタックフレームスケジュール(subコマンド)
[255]700 compiler.codeGenerator.opfix( pStackFramePertialSchedule, stackFrameAndLocalParamSize );
[3]701
702 //スタックフレームスケジュールを実行
[220]703 pobj_sf->RunningSchedule( stackFrameSize );
[3]704 delete pobj_sf;
705 pobj_sf=0;
706
707
[75]708 //重複エラー情報管理のメモリを解放
709 for(i3=0;i3<SynonymErrorNum;i3++) HeapDefaultFree(SynonymErrorWords[i3]);
710 HeapDefaultFree(SynonymErrorWords);
[3]711}
Note: See TracBrowser for help on using the repository browser.