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

Last change on this file since 353 was 353, checked in by dai_9181, 17 years ago

インターフェイス実装周りの仕様整備

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