source: dev/trunk/ab5.0/abdev/compiler_x64/Compile_ProcOp.cpp@ 584

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

[530][583]を64bit版にマージ。

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