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

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

ObjectModuleに関連するクラス一式をab_commonプロジェクトに移動した。

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