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