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

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

[459]を64bit版にもマージ。

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