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

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

Try-Catchを試験的に実装。
(まだ下記の動作しか実装していません)
・Try
・Catch(パラメータ無し)
・Throw(パラメータ無し)

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