source: dev/trunk/ab5.0/abdev/BasicCompiler64/Compile_ProcOp.cpp@ 463

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

[461]を64bit版にマージ。

File size: 20.4 KB
RevLine 
[206]1#include "stdafx.h"
2
[169]3#include <Program.h>
[198]4#include <Compiler.h>
[206]5#include <Class.h>
[169]6
[3]7#include "../BasicCompiler_Common/common.h"
8#include "Opcode.h"
9
[86]10void SystemProc( const UserProc &userProc ){
11 if( userProc.GetName() == "_System_GetEip" ){
[3]12 //mov rax,qword ptr[rsp]
[226]13 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_RAX,REG_RSP,0,MOD_BASE);
[3]14
15 //ret
[226]16 compiler.codeGenerator.op_ret();
[3]17 }
[86]18 else if( userProc.GetName() == "_System_InitDllGlobalVariables" ){
[3]19 ////////////////////////////////////////
20 // DLLのグローバル領域をコンパイル
21 ////////////////////////////////////////
[266]22 if(!compiler.IsDll()){
[3]23 //ret
[226]24 compiler.codeGenerator.op_ret();
[3]25
26 return;
27 }
28
[206]29 const UserProc *pBackUserProc = &UserProc::CompilingUserProc();
[75]30 UserProc::CompileStartForGlobalArea();
[3]31
32 int BackCp;
33 BackCp=cp;
34 cp=-1;
35
36 //sub rsp,スタックフレームサイズ
[255]37 const PertialSchedule *pStackFramePertialSchedule = compiler.codeGenerator.op_sub_rsp( 0, true );
[3]38
[460]39 if( compiler.IsDebug() )
40 {
[3]41 //デバッグ用の変数を定義
42 DebugVariable();
43 }
44
45 //GC用の変数を定義
46 InitGCVariables();
47
[129]48 //_System_StartupProgramの呼び出し
[206]49 extern const UserProc *pSub_System_StartupProgram;
[226]50 compiler.codeGenerator.op_call(pSub_System_StartupProgram);
[129]51
[42]52 //クラスに属する静的メンバを定義
[266]53 compiler.GetObjectModule().meta.GetClasses().InitStaticMember();
[42]54
[3]55 GetGlobalDataForDll();
56
57 //add rsp,スタックフレームサイズ
[226]58 compiler.codeGenerator.op_add_RV(REG_RSP,pobj_sf->GetFrameSize(0));
[3]59
60 //スタックフレームスケジュール(subコマンドに渡す値)
[255]61 compiler.codeGenerator.opfix( pStackFramePertialSchedule, pobj_sf->GetFrameSize(0) );
[3]62
[75]63 UserProc::CompileStartForUserProc( pBackUserProc );
[3]64 cp=BackCp;
65
66 //ret
[226]67 compiler.codeGenerator.op_ret();
[3]68 }
[86]69 else if( userProc.GetName() == "_System_InitStaticLocalVariables" ){
[3]70 //静的ローカルオブジェクトのコンストラクタ呼び出し
71
72 //sub rsp,スタックフレームサイズ
[255]73 const PertialSchedule *pStackFramePertialSchedule = compiler.codeGenerator.op_sub_rsp( 0, true );
[3]74
[266]75 BOOST_FOREACH( Variable *pVar, compiler.GetObjectModule().meta.GetGlobalVars() ){
[75]76 if(memicmp(pVar->GetName().c_str(),"Static%",7)==0){
[3]77 //コンストラクタ呼び出し
[206]78 if( pVar->GetType().IsObject() ){
[3]79
80 //エラー用
[75]81 cp=pVar->source_code_address;
[3]82
[50]83 CallConstructor(
[75]84 pVar->GetName().c_str(),
[206]85 pVar->GetSubscripts(),
86 pVar->GetType(),
87 pVar->GetParamStrForConstructor().c_str());
[3]88 }
89 }
90 }
91
92 //add rsp,スタックフレームサイズ
[226]93 compiler.codeGenerator.op_add_RV(REG_RSP,pobj_sf->GetFrameSize(0));
[3]94
95 //スタックフレームスケジュール(subコマンドに渡す値)
[255]96 compiler.codeGenerator.opfix( pStackFramePertialSchedule, pobj_sf->GetFrameSize(0) );
[3]97
98 //ret
[226]99 compiler.codeGenerator.op_ret();
[3]100 }
[86]101 else if( userProc.GetName() == "_System_Call_Destructor_of_GlobalObject" ){
[3]102 //sub rsp,8(※RSPを16バイト境界にあわせるため)
[226]103 compiler.codeGenerator.op_sub_rsp(0x8);
[3]104
105
[206]106 const UserProc *pBackUserProc = &UserProc::CompilingUserProc();
[75]107 UserProc::CompileStartForGlobalArea();
[3]108
[254]109 compiler.codeGenerator.lexicalScopes.CallDestructorsOfScopeEnd();
[3]110
[75]111 UserProc::CompileStartForUserProc( pBackUserProc );
[3]112
113
114 //add rsp,8
[226]115 compiler.codeGenerator.op_add_RV(REG_RSP,0x8);
[3]116
117 //ret
[226]118 compiler.codeGenerator.op_ret();
[3]119 }
[90]120 else{
121 SetError();
122 }
123}
[206]124void AutoGeneration(const UserProc &userProc){
[90]125 if( userProc.GetName() == "InitializeUserTypes"
[89]126 && userProc.HasParentClass()
[353]127 && userProc.GetParentClass().GetName() == "_System_TypeBase" )
128 {
129 compiler.GetObjectModule().meta.GetClasses().Compile_System_InitializeUserTypes();
[86]130 }
[355]131 else if( userProc.GetName() == "InitializeUserTypesForBaseType"
132 && userProc.HasParentClass()
133 && userProc.GetParentClass().GetName() == "_System_TypeBase" )
134 {
135 compiler.GetObjectModule().meta.GetClasses().Compile_System_InitializeUserTypesForBaseType();
136 }
[95]137 else if( userProc.GetName() == "RegisterGlobalRoots"
138 && userProc.HasParentClass()
[353]139 && userProc.GetParentClass().GetName() == "_System_CGarbageCollection" )
140 {
141 Compile_AddGlobalRootsForGc();
[95]142 }
[309]143 else if( userProc.GetName() == compiler.globalAreaProcName ){
144 ////////////////////////////////////////
145 // グローバル領域をコンパイル
146 ////////////////////////////////////////
147
[364]148 UserProc::pGlobalProc = &userProc;
149
[309]150 const UserProc *pBackUserProc = &UserProc::CompilingUserProc();
151 UserProc::CompileStartForGlobalArea();
152
153 int BackCp = cp;
154 cp=-1;
155
156 //クラスに属する静的メンバを定義
157 compiler.GetObjectModule().meta.GetClasses().InitStaticMember();
158
159 //グローバル実行領域をコンパイル開始
160 CompileBuffer(0,0);
161
162 //Goto未知ラベルスケジュールが存在したらエラーにする
163 BOOST_FOREACH( const GotoLabelSchedule *pGotoLabelSchedule, compiler.codeGenerator.gotoLabelSchedules )
164 {
165 if(pGotoLabelSchedule->GetName().size()>0){
166 SetError(6,pGotoLabelSchedule->GetName(),pGotoLabelSchedule->GetSourceCodePos());
167 }
168 else{
169 char temporary[255];
170 sprintf(temporary,"%d",pGotoLabelSchedule->GetLineNum());
171 SetError(6,temporary,pGotoLabelSchedule->GetSourceCodePos());
172 }
173 }
174
175 UserProc::CompileStartForUserProc( pBackUserProc );
176 cp=BackCp;
177 }
[350]178 else if( userProc.HasParentClass()
179 && userProc.IsCastOperator()
180 && userProc.ReturnType().IsInterface() )
181 {
182 // インターフェイス型にキャストするためのメソッド
183
184 int vtblMasterListIndex = userProc.GetParentClass().GetVtblMasterListIndex( &userProc.ReturnType().GetClass() );
185
186 char temporary[1024];
187 sprintf( temporary,
[370]188 "Return New %s(ObjPtr( This ),Get_LONG_PTR( (Get_LONG_PTR( ObjPtr(This)+SizeOf(VoidPtr) ) + SizeOf(LONG_PTR)*%d) As VoidPtr ) As VoidPtr )",
[350]189 userProc.ReturnType().GetClass().GetName().c_str(),
190 vtblMasterListIndex
191 );
192 MakeMiddleCode( temporary );
193
194 ChangeOpcode( temporary );
195 }
[86]196 else{
197 SetError();
198 }
[3]199}
[206]200void _compile_proc(const UserProc *pUserProc){
[3]201 extern char *basbuf;
202 extern HANDLE hHeap;
[76]203 int i3,i4;
[3]204 char temporary[VN_SIZE];
205
[206]206 if( pUserProc->GetLocalVars().size() ){
[76]207 SetError();
208 return;
209 }
210
[206]211 trace_for_sourcecodestep( "★★★ " << pUserProc->GetFullName() << "のコンパイルを開始" );
212
[75]213 pUserProc->CompleteCompile();
[3]214
215 extern BOOL bSystemProc;
[75]216 if(memcmp(pUserProc->GetName().c_str(),"_System_",8)==0) bSystemProc=1;
[3]217 else bSystemProc=0;
218
219 extern BOOL bDebugSupportProc;
[75]220 if(memcmp(pUserProc->GetName().c_str(),"_DebugSys_",10)==0){
[460]221 if( !compiler.IsDebug() )
222 {
[3]223 return;
224 }
225 bDebugSupportProc=1;
226 }
227 else bDebugSupportProc=0;
228
[89]229 //コンパイル中の関数が属するクラス
[206]230 compiler.pCompilingClass=pUserProc->GetParentClassPtr();
[89]231
232 //コンパイルスタートをクラス管理クラスに追加
[266]233 compiler.GetObjectModule().meta.GetClasses().StartCompile( pUserProc );
[89]234
235 //コンパイル中の関数
236 UserProc::CompileStartForUserProc( pUserProc );
237
[101]238 // コンパイル中の関数が属する名前空間
[202]239 compiler.GetNamespaceSupporter().SetLivingNamespaceScopes( pUserProc->GetNamespaceScopes() );
[101]240
[108]241 // コンパイル中の関数でImportsされている名前空間
[202]242 compiler.GetNamespaceSupporter().SetImportedNamespaces( pUserProc->GetImportedNamespaces() );
[108]243
[226]244 // コード生成対象を選択
245 compiler.codeGenerator.Select( (const_cast<UserProc *>(pUserProc))->GetNativeCode() );
246
[75]247 if(pUserProc->IsSystem()){
[3]248 ////////////////////
249 // 特殊関数
250 ////////////////////
251
252 extern int AllLocalVarSize;
253 AllLocalVarSize=0;
254
255 //スタックフレーム管理用オブジェクトを初期化
[308]256 extern StackFrame *pobj_sf;
257 pobj_sf=new StackFrame();
[3]258
[86]259 SystemProc(*pUserProc);
[3]260
261 //スタックフレーム管理用オブジェクトを破棄
262 delete pobj_sf;
263 pobj_sf=0;
264
265 return;
266 }
267
[353]268 if( !pUserProc->IsAutoGeneration() )
269 {
270 cp=pUserProc->GetCodePos();
271 for(;;cp++){
272 if(IsCommandDelimitation(basbuf[cp])) break;
273 }
274 cp--;
[3]275 }
276
277 //プロシージャ抜け出しスケジュール(Exit Sub/Function)
[254]278 compiler.codeGenerator.exitSubCodePositions.clear();
[3]279
280 //ラベル用のメモリを確保
[262]281 compiler.codeGenerator.gotoLabels.clear();
[3]282
283 //Gotoラベルスケジュール
[254]284 compiler.codeGenerator.gotoLabelSchedules.clear();
[3]285
286 //With情報のメモリを確保
287 extern WITHINFO WithInfo;
288 WithInfo.ppName=(char **)HeapAlloc(hHeap,0,1);
289 WithInfo.pWithCp=(int *)HeapAlloc(hHeap,0,1);
290 WithInfo.num=0;
291
292 //重複エラー情報管理のメモリを確保
293 extern char **SynonymErrorWords;
294 extern int SynonymErrorNum;
295 SynonymErrorNum=0;
296 SynonymErrorWords=(char **)HeapAlloc(hHeap,0,1);
297
298 //Continueアドレスを初期化
[242]299 compiler.codeGenerator.ClearContinueArea();
[3]300
301 //ローカル変数に関する情報
302 extern int AllLocalVarSize;
303 AllLocalVarSize=0;
304
305 //レキシカルスコープ情報を初期化
[308]306 compiler.codeGenerator.lexicalScopes.Init( compiler.codeGenerator.GetNativeCodeSize() );
[3]307
308
309 /////////////////////////////////////
310 // パラメータ用の変数データを考慮
311 /////////////////////////////////////
312
[75]313 //パラメータ用の変数データを考慮
314 for(i3=(int)pUserProc->RealParams().size()-1;i3>=0;i3--){
315 Parameter &param = *pUserProc->RealParams()[i3];
[3]316
[308]317 Variable *pVar = new Variable( param.GetVarName(), param, false, param.IsRef(), "", false );
[3]318
[75]319 if( param.IsArray() ){
[206]320 pVar->SetArray( param.GetSubscripts() );
[3]321 }
322
[75]323 int varSize;
324 if( param.IsRef() == false && param.IsStruct() ){
[64]325 //構造体のByValパラメータ
[75]326 pVar->ThisIsParameter();
327 varSize=PTR_SIZE;
[3]328 }
329 else{
[75]330 if( param.IsArray() == false ){
331 varSize = pVar->GetMemorySize();
[3]332 }
333 else{
[75]334 varSize=PTR_SIZE;
[3]335 }
336 }
[75]337 AllLocalVarSize+=varSize;
[206]338 pVar->SetOffsetAddress( AllLocalVarSize );
[3]339
340 //レキシカルスコープ情報
[254]341 pVar->SetScopeLevel( compiler.codeGenerator.lexicalScopes.GetNowLevel() );
342 pVar->SetScopeStartAddress( compiler.codeGenerator.lexicalScopes.GetStartAddress() );
[392]343 pVar->isLiving = true;
[3]344
[206]345 pUserProc->GetLocalVars().push_back( pVar );
[3]346 }
347
348 //Thisポインタを示すローカルオフセット値をセット
349 extern int LocalVar_ThisPtrOffset;
350 LocalVar_ThisPtrOffset=AllLocalVarSize;
351
352 //スタックフレーム管理用クラスを初期化
[308]353 extern StackFrame *pobj_sf;
354 pobj_sf=new StackFrame();
[3]355
356
357 ///////////////////////
358 // ここからコード生成
359
[75]360 for(i3=(int)pUserProc->RealParams().size()-1;i3>=0;i3--){
361 Parameter &param = *pUserProc->RealParams()[i3];
[3]362 if(i3==3){
[75]363 if(param.IsReal()&&param.IsRef() == false){
[3]364 //movsd qword ptr[rsp+0x20],xmm3
[226]365 compiler.codeGenerator.op_movsd_MR(REG_XMM3,REG_RSP,0x20,MOD_BASE_DISP32);
[3]366 }
367 else{
368 //mov qword ptr[rsp+0x20],r9
[226]369 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_R9,REG_RSP,0x20,MOD_BASE_DISP32);
[3]370 }
371 }
372 if(i3==2){
[75]373 if(param.IsReal()&&param.IsRef() == false){
[3]374 //movsd qword ptr[rsp+0x18],xmm2
[226]375 compiler.codeGenerator.op_movsd_MR(REG_XMM2,REG_RSP,0x18,MOD_BASE_DISP32);
[3]376 }
377 else{
378 //mov qword ptr[rsp+0x18],r8
[226]379 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_R8,REG_RSP,0x18,MOD_BASE_DISP32);
[3]380 }
381 }
382 if(i3==1){
[75]383 if(param.IsReal()&&param.IsRef() == false){
[3]384 //movsd qword ptr[rsp+0x10],xmm1
[226]385 compiler.codeGenerator.op_movsd_MR(REG_XMM1,REG_RSP,0x10,MOD_BASE_DISP32);
[3]386 }
387 else{
388 //mov qword ptr[rsp+0x10],rdx
[226]389 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_RDX,REG_RSP,0x10,MOD_BASE_DISP32);
[3]390 }
391 }
392 if(i3==0){
[75]393 if(param.IsReal()&&param.IsRef() == false){
[3]394 //movsd qword ptr[rsp+0x8],xmm0
[226]395 compiler.codeGenerator.op_movsd_MR(REG_XMM0,REG_RSP,0x8,MOD_BASE_DISP32);
[3]396 }
397 else{
398 //mov qword ptr[rsp+0x8],rcx
[226]399 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_RCX,REG_RSP,0x8,MOD_BASE_DISP32);
[3]400 }
401 }
402 }
403
404 //ret用のアドレスを考慮
405 AllLocalVarSize+=sizeof(_int64);
406
407 //sub rsp,スタックフレームサイズ
[255]408 const PertialSchedule *pStackFramePertialSchedule = compiler.codeGenerator.op_sub_rsp( 0, true );
[3]409
410 //mov qword ptr[rsp+offset],reg ※スタックフレームを利用
411 pobj_sf->push(REG_RBX);
412 pobj_sf->push(REG_RSI);
413 pobj_sf->push(REG_RDI);
414 pobj_sf->push(REG_R12);
415 pobj_sf->push(REG_R13);
416 pobj_sf->push(REG_R14);
417 pobj_sf->push(REG_R15);
418
419 //ローカル変数のベース値
420 int BaseLocalVar;
421 BaseLocalVar=AllLocalVarSize;
422
[75]423 if( !pUserProc->ReturnType().IsNull() ){
[3]424 //戻り値が存在するとき
425
[75]426 const char *temp = pUserProc->GetName().c_str();
427 if( temp[0]==1&&temp[1]==ESC_OPERATOR ){
428 temp = "_System_ReturnValue";
429 }
[3]430
[75]431 if( pUserProc->ReturnType().IsStruct() ){
[64]432 //戻り値用の構造体(値型)はパラメータで引き渡される
[3]433 }
434 else{
[89]435 if( pUserProc->ReturnType().IsObject() ){
[308]436 sprintf(temporary,"%s=Nothing%c%c%s",temp,1,ESC_AS, compiler.TypeToString( pUserProc->ReturnType() ).c_str() );
[89]437 }
438 else{
439 //戻り値用の変数の定義
[308]440 sprintf(temporary,"%s%c%c%s",temp,1,ESC_AS, compiler.TypeToString( pUserProc->ReturnType() ).c_str() );
[89]441 }
[40]442
[3]443 OpcodeDim(temporary,0);
444 }
445 }
446
[255]447 const PertialSchedule *pRspOffsetPertialSchedule1 = NULL;
448 const PertialSchedule *pRspOffsetPertialSchedule2 = NULL;
[460]449 if( compiler.IsDebug() && bDebugSupportProc == 0 )
450 {
[3]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
[366]591 // Tryスコープの検証
592 Exception::InspectTryScope();
593
[3]594 //With情報のメモリを解放
595 for(i3=0;i3<WithInfo.num;i3++){
596 SetError(22,"With",WithInfo.pWithCp[i3]);
597 HeapDefaultFree(WithInfo.ppName[i3]);
598 }
599 HeapDefaultFree(WithInfo.ppName);
600 HeapDefaultFree(WithInfo.pWithCp);
601
602 //ローカルオブジェクト(レキシカルスコープレベル=0)の解放処理
[254]603 compiler.codeGenerator.lexicalScopes.CallDestructorsOfScopeEnd();
[3]604
[34]605 //プロシージャ抜け出しスケジュール(Exit Sub/Function)
[254]606 compiler.codeGenerator.ResolveExitSubSchedule();
[34]607
[460]608 if( compiler.IsDebug() && bDebugSupportProc == 0 )
609 {
[34]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.