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

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

64bit版でコンパイルできるようにした。

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()
[131]140 && userProc.GetParentClass().GetName() == "_System_TypeBase" ){
[266]141 compiler.GetObjectModule().meta.GetClasses().Compile_System_InitializeUserTypes();
[86]142 }
[95]143 else if( userProc.GetName() == "RegisterGlobalRoots"
144 && userProc.HasParentClass()
[131]145 && userProc.GetParentClass().GetName() == "_System_CGarbageCollection" ){
[95]146
147 Compile_AddGlobalRootsForGc();
148 }
[309]149 else if( userProc.GetName() == compiler.globalAreaProcName ){
150 ////////////////////////////////////////
151 // グローバル領域をコンパイル
152 ////////////////////////////////////////
153
154 const UserProc *pBackUserProc = &UserProc::CompilingUserProc();
155 UserProc::CompileStartForGlobalArea();
156
157 int BackCp = cp;
158 cp=-1;
159
160 //クラスに属する静的メンバを定義
161 compiler.GetObjectModule().meta.GetClasses().InitStaticMember();
162
163 //グローバル実行領域をコンパイル開始
164 CompileBuffer(0,0);
165
166 //Goto未知ラベルスケジュールが存在したらエラーにする
167 BOOST_FOREACH( const GotoLabelSchedule *pGotoLabelSchedule, compiler.codeGenerator.gotoLabelSchedules )
168 {
169 if(pGotoLabelSchedule->GetName().size()>0){
170 SetError(6,pGotoLabelSchedule->GetName(),pGotoLabelSchedule->GetSourceCodePos());
171 }
172 else{
173 char temporary[255];
174 sprintf(temporary,"%d",pGotoLabelSchedule->GetLineNum());
175 SetError(6,temporary,pGotoLabelSchedule->GetSourceCodePos());
176 }
177 }
178
179 UserProc::CompileStartForUserProc( pBackUserProc );
180 cp=BackCp;
181 }
[86]182 else{
183 SetError();
184 }
[3]185}
[206]186void _compile_proc(const UserProc *pUserProc){
[3]187 extern char *basbuf;
188 extern HANDLE hHeap;
189 extern BOOL bDebugCompile;
[76]190 int i3,i4;
[3]191 char temporary[VN_SIZE];
192
[206]193 if( pUserProc->GetLocalVars().size() ){
[76]194 SetError();
195 return;
196 }
197
[206]198 trace_for_sourcecodestep( "★★★ " << pUserProc->GetFullName() << "のコンパイルを開始" );
199
[75]200 pUserProc->CompleteCompile();
[3]201
202 extern BOOL bSystemProc;
[75]203 if(memcmp(pUserProc->GetName().c_str(),"_System_",8)==0) bSystemProc=1;
[3]204 else bSystemProc=0;
205
206 extern BOOL bDebugSupportProc;
[75]207 if(memcmp(pUserProc->GetName().c_str(),"_DebugSys_",10)==0){
[3]208 if(!bDebugCompile){
209 return;
210 }
211 bDebugSupportProc=1;
212 }
213 else bDebugSupportProc=0;
214
[89]215 //コンパイル中の関数が属するクラス
[206]216 compiler.pCompilingClass=pUserProc->GetParentClassPtr();
[89]217
218 //コンパイルスタートをクラス管理クラスに追加
[266]219 compiler.GetObjectModule().meta.GetClasses().StartCompile( pUserProc );
[89]220
221 //コンパイル中の関数
222 UserProc::CompileStartForUserProc( pUserProc );
223
[101]224 // コンパイル中の関数が属する名前空間
[202]225 compiler.GetNamespaceSupporter().SetLivingNamespaceScopes( pUserProc->GetNamespaceScopes() );
[101]226
[108]227 // コンパイル中の関数でImportsされている名前空間
[202]228 compiler.GetNamespaceSupporter().SetImportedNamespaces( pUserProc->GetImportedNamespaces() );
[108]229
[226]230 // コード生成対象を選択
231 compiler.codeGenerator.Select( (const_cast<UserProc *>(pUserProc))->GetNativeCode() );
232
[75]233 if(pUserProc->IsSystem()){
[3]234 ////////////////////
235 // 特殊関数
236 ////////////////////
237
238 extern int AllLocalVarSize;
239 AllLocalVarSize=0;
240
241 //スタックフレーム管理用オブジェクトを初期化
[308]242 extern StackFrame *pobj_sf;
243 pobj_sf=new StackFrame();
[3]244
[86]245 SystemProc(*pUserProc);
[3]246
247 //スタックフレーム管理用オブジェクトを破棄
248 delete pobj_sf;
249 pobj_sf=0;
250
251 return;
252 }
253
[75]254 cp=pUserProc->GetCodePos();
[3]255 for(;;cp++){
256 if(IsCommandDelimitation(basbuf[cp])) break;
257 }
258 cp--;
259
260 //プロシージャ抜け出しスケジュール(Exit Sub/Function)
[254]261 compiler.codeGenerator.exitSubCodePositions.clear();
[3]262
263 //ラベル用のメモリを確保
[262]264 compiler.codeGenerator.gotoLabels.clear();
[3]265
266 //Gotoラベルスケジュール
[254]267 compiler.codeGenerator.gotoLabelSchedules.clear();
[3]268
269 //With情報のメモリを確保
270 extern WITHINFO WithInfo;
271 WithInfo.ppName=(char **)HeapAlloc(hHeap,0,1);
272 WithInfo.pWithCp=(int *)HeapAlloc(hHeap,0,1);
273 WithInfo.num=0;
274
275 //重複エラー情報管理のメモリを確保
276 extern char **SynonymErrorWords;
277 extern int SynonymErrorNum;
278 SynonymErrorNum=0;
279 SynonymErrorWords=(char **)HeapAlloc(hHeap,0,1);
280
281 //Continueアドレスを初期化
[242]282 compiler.codeGenerator.ClearContinueArea();
[3]283
284 //ローカル変数に関する情報
285 extern int AllLocalVarSize;
286 AllLocalVarSize=0;
287
288 //レキシカルスコープ情報を初期化
[308]289 compiler.codeGenerator.lexicalScopes.Init( compiler.codeGenerator.GetNativeCodeSize() );
[3]290
291
292 /////////////////////////////////////
293 // パラメータ用の変数データを考慮
294 /////////////////////////////////////
295
[75]296 //パラメータ用の変数データを考慮
297 for(i3=(int)pUserProc->RealParams().size()-1;i3>=0;i3--){
298 Parameter &param = *pUserProc->RealParams()[i3];
[3]299
[308]300 Variable *pVar = new Variable( param.GetVarName(), param, false, param.IsRef(), "", false );
[3]301
[75]302 if( param.IsArray() ){
[206]303 pVar->SetArray( param.GetSubscripts() );
[3]304 }
305
[75]306 int varSize;
307 if( param.IsRef() == false && param.IsStruct() ){
[64]308 //構造体のByValパラメータ
[75]309 pVar->ThisIsParameter();
310 varSize=PTR_SIZE;
[3]311 }
312 else{
[75]313 if( param.IsArray() == false ){
314 varSize = pVar->GetMemorySize();
[3]315 }
316 else{
[75]317 varSize=PTR_SIZE;
[3]318 }
319 }
[75]320 AllLocalVarSize+=varSize;
[206]321 pVar->SetOffsetAddress( AllLocalVarSize );
[3]322
323 //レキシカルスコープ情報
[254]324 pVar->SetScopeLevel( compiler.codeGenerator.lexicalScopes.GetNowLevel() );
325 pVar->SetScopeStartAddress( compiler.codeGenerator.lexicalScopes.GetStartAddress() );
[75]326 pVar->bLiving=TRUE;
[3]327
[206]328 pUserProc->GetLocalVars().push_back( pVar );
[3]329 }
330
331 //Thisポインタを示すローカルオフセット値をセット
332 extern int LocalVar_ThisPtrOffset;
333 LocalVar_ThisPtrOffset=AllLocalVarSize;
334
335 //スタックフレーム管理用クラスを初期化
[308]336 extern StackFrame *pobj_sf;
337 pobj_sf=new StackFrame();
[3]338
339
340 ///////////////////////
341 // ここからコード生成
342
[75]343 for(i3=(int)pUserProc->RealParams().size()-1;i3>=0;i3--){
344 Parameter &param = *pUserProc->RealParams()[i3];
[3]345 if(i3==3){
[75]346 if(param.IsReal()&&param.IsRef() == false){
[3]347 //movsd qword ptr[rsp+0x20],xmm3
[226]348 compiler.codeGenerator.op_movsd_MR(REG_XMM3,REG_RSP,0x20,MOD_BASE_DISP32);
[3]349 }
350 else{
351 //mov qword ptr[rsp+0x20],r9
[226]352 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_R9,REG_RSP,0x20,MOD_BASE_DISP32);
[3]353 }
354 }
355 if(i3==2){
[75]356 if(param.IsReal()&&param.IsRef() == false){
[3]357 //movsd qword ptr[rsp+0x18],xmm2
[226]358 compiler.codeGenerator.op_movsd_MR(REG_XMM2,REG_RSP,0x18,MOD_BASE_DISP32);
[3]359 }
360 else{
361 //mov qword ptr[rsp+0x18],r8
[226]362 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_R8,REG_RSP,0x18,MOD_BASE_DISP32);
[3]363 }
364 }
365 if(i3==1){
[75]366 if(param.IsReal()&&param.IsRef() == false){
[3]367 //movsd qword ptr[rsp+0x10],xmm1
[226]368 compiler.codeGenerator.op_movsd_MR(REG_XMM1,REG_RSP,0x10,MOD_BASE_DISP32);
[3]369 }
370 else{
371 //mov qword ptr[rsp+0x10],rdx
[226]372 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_RDX,REG_RSP,0x10,MOD_BASE_DISP32);
[3]373 }
374 }
375 if(i3==0){
[75]376 if(param.IsReal()&&param.IsRef() == false){
[3]377 //movsd qword ptr[rsp+0x8],xmm0
[226]378 compiler.codeGenerator.op_movsd_MR(REG_XMM0,REG_RSP,0x8,MOD_BASE_DISP32);
[3]379 }
380 else{
381 //mov qword ptr[rsp+0x8],rcx
[226]382 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_RCX,REG_RSP,0x8,MOD_BASE_DISP32);
[3]383 }
384 }
385 }
386
387 //ret用のアドレスを考慮
388 AllLocalVarSize+=sizeof(_int64);
389
390 //sub rsp,スタックフレームサイズ
[255]391 const PertialSchedule *pStackFramePertialSchedule = compiler.codeGenerator.op_sub_rsp( 0, true );
[3]392
393 //mov qword ptr[rsp+offset],reg ※スタックフレームを利用
394 pobj_sf->push(REG_RBX);
395 pobj_sf->push(REG_RSI);
396 pobj_sf->push(REG_RDI);
397 pobj_sf->push(REG_R12);
398 pobj_sf->push(REG_R13);
399 pobj_sf->push(REG_R14);
400 pobj_sf->push(REG_R15);
401
402 //ローカル変数のベース値
403 int BaseLocalVar;
404 BaseLocalVar=AllLocalVarSize;
405
[75]406 if( !pUserProc->ReturnType().IsNull() ){
[3]407 //戻り値が存在するとき
408
[75]409 const char *temp = pUserProc->GetName().c_str();
410 if( temp[0]==1&&temp[1]==ESC_OPERATOR ){
411 temp = "_System_ReturnValue";
412 }
[3]413
[75]414 if( pUserProc->ReturnType().IsStruct() ){
[64]415 //戻り値用の構造体(値型)はパラメータで引き渡される
[3]416 }
417 else{
[89]418 if( pUserProc->ReturnType().IsObject() ){
[308]419 sprintf(temporary,"%s=Nothing%c%c%s",temp,1,ESC_AS, compiler.TypeToString( pUserProc->ReturnType() ).c_str() );
[89]420 }
421 else{
422 //戻り値用の変数の定義
[308]423 sprintf(temporary,"%s%c%c%s",temp,1,ESC_AS, compiler.TypeToString( pUserProc->ReturnType() ).c_str() );
[89]424 }
[40]425
[3]426 OpcodeDim(temporary,0);
427 }
428 }
429
[255]430 const PertialSchedule *pRspOffsetPertialSchedule1 = NULL;
431 const PertialSchedule *pRspOffsetPertialSchedule2 = NULL;
[3]432 if(bDebugCompile&&bDebugSupportProc==0){
433 //mov rdx, qword ptr[rsp+スタックフレームサイズ]
[255]434 pRspOffsetPertialSchedule1 = compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_RDX,REG_RSP,0,MOD_BASE_DISP32, Schedule::None, true );
[3]435
436 //mov rcx,rsp
[226]437 compiler.codeGenerator.op_mov_RR(REG_RCX,REG_RSP);
[3]438
439 //add rcx,スタックフレームサイズ+sizeof(_int64) ※ret用のサイズを考慮
[255]440 pRspOffsetPertialSchedule2 = compiler.codeGenerator.op_add_RV(REG_RCX,0, Schedule::None, true );
[3]441
442 //call _DebugSys_StartProc
[206]443 extern const UserProc *pSub_DebugSys_StartProc;
[226]444 compiler.codeGenerator.op_call(pSub_DebugSys_StartProc);
[3]445 }
446
[206]447 if(compiler.pCompilingClass){
448 if( pUserProc->GetName() == compiler.pCompilingClass->GetName() ){
[3]449 ////////////////////////////////////
450 // コンストラクタをコンパイルするとき
451 ////////////////////////////////////
452
[17]453 //コンストラクタのコンパイル開始を通知
[206]454 compiler.pCompilingClass->NotifyStartConstructorCompile();
[17]455
[27]456 //基底クラスかどうかの識別
457 //(継承元がインターフェイスの場合も基底クラスと見なす)
[3]458 BOOL bThisIsSuperClass;
[206]459 if( !compiler.pCompilingClass->HasSuperClass() ) bThisIsSuperClass=1;
460 else if( compiler.pCompilingClass->GetSuperClass().GetConstructorMethod() == NULL ){
[3]461 //インターフェイスを継承したときはコンストラクタを持たない
462 bThisIsSuperClass=1;
463 }
464 else bThisIsSuperClass=0;
465
466 if(!bThisIsSuperClass){
467 /* サブクラスコンストラクタをコンパイルしているときは、
[27]468 基底クラスのコンストラクタを呼び出す */
[3]469
470 i3=cp+1;
471 while(IsCommandDelimitation(basbuf[i3])) i3++;
472 for(i4=0;;i3++,i4++){
473 if(!IsVariableChar(basbuf[i3])){
474 temporary[i4]=0;
475 break;
476 }
477 temporary[i4]=basbuf[i3];
478 }
[206]479 if( compiler.pCompilingClass->GetSuperClass().GetName() == temporary ){
[27]480 //基底クラスのコンストラクタを呼び出す
[3]481 cp=i3;
482 for(i4=0;;cp++,i4++){
483 if(IsCommandDelimitation(basbuf[cp])){
484 temporary[i4]=0;
485 break;
486 }
487 temporary[i4]=basbuf[cp];
488 }
489 if(!(temporary[0]=='('&&temporary[lstrlen(temporary)-1]==')')){
490 SetError(1,NULL,cp);
491 }
492 RemoveStringPare(temporary);
493
[89]494 Type dummyType;
495 CallProc( PROC_DEFAULT
[206]496 , &compiler.pCompilingClass->GetSuperClass().GetConstructorMethod()->GetUserProc()
497 , compiler.pCompilingClass->GetSuperClass().GetConstructorMethod()->GetUserProc().GetName().c_str()
[89]498 , temporary
499 , dummyType );
[3]500 }
501 else{
[27]502 //基底クラスのコンストラクタを暗黙的に呼び出す
[3]503 Opcode_CallProc("",
[206]504 &compiler.pCompilingClass->GetSuperClass().GetConstructorMethod()->GetUserProc(),
[3]505 0,
[308]506 "");
[3]507 }
508 }
509
510 //仮想関数テーブルを初期化
[206]511 if( compiler.pCompilingClass->IsExistVirtualFunctions()
[317]512 && !compiler.pCompilingClass->IsAbstract() )
513 {
514 // mov rax,vtblAddress
515 compiler.codeGenerator.op_mov_RV_vtbl( REG_RAX, compiler.pCompilingClass );
[3]516
[317]517 //Thisポインタをrcxにコピー
518 SetThisPtrToReg(REG_RCX);
[3]519
[317]520 //mov qword ptr[rcx],rax
521 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_RAX,REG_RCX,0,MOD_BASE);
[3]522
[317]523
524 // 仮想関数になるメソッドに使用チェックをつける
525 BOOST_FOREACH( const CMethod *pMethod, compiler.pCompilingClass->GetMethods() )
526 {
527 if( pMethod->IsVirtual() )
528 {
529 pMethod->GetUserProc().Using();
530 }
531 }
[3]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.