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
Line 
1#include "stdafx.h"
2
3#include <jenga/include/smoothie/Smoothie.h>
4#include <jenga/include/smoothie/LexicalAnalysis.h>
5
6#include <Program.h>
7#include <Compiler.h>
8#include <Class.h>
9
10#include "../BasicCompiler_Common/common.h"
11#include "Opcode.h"
12
13void SystemProc( const UserProc &userProc ){
14 if( userProc.GetName() == "_System_GetEip" ){
15 //mov rax,qword ptr[rsp]
16 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_RAX,REG_RSP,0,MOD_BASE);
17
18 //ret
19 compiler.codeGenerator.op_ret();
20 }
21 else if( userProc.GetName() == "_System_InitDllGlobalVariables" ){
22 ////////////////////////////////////////
23 // DLLのグローバル領域をコンパイル
24 ////////////////////////////////////////
25 if(!compiler.IsDll()){
26 //ret
27 compiler.codeGenerator.op_ret();
28
29 return;
30 }
31
32 const UserProc *pBackUserProc = &UserProc::CompilingUserProc();
33 UserProc::CompileStartForGlobalArea();
34
35 int BackCp;
36 BackCp=cp;
37 cp=-1;
38
39 //sub rsp,スタックフレームサイズ
40 const PertialSchedule *pStackFramePertialSchedule = compiler.codeGenerator.op_sub_rsp( 0, true );
41
42 extern BOOL bDebugCompile;
43 if(bDebugCompile){
44 //デバッグ用の変数を定義
45 DebugVariable();
46 }
47
48 //GC用の変数を定義
49 InitGCVariables();
50
51 //_System_StartupProgramの呼び出し
52 extern const UserProc *pSub_System_StartupProgram;
53 compiler.codeGenerator.op_call(pSub_System_StartupProgram);
54
55 //クラスに属する静的メンバを定義
56 compiler.GetObjectModule().meta.GetClasses().InitStaticMember();
57
58 GetGlobalDataForDll();
59
60 //add rsp,スタックフレームサイズ
61 compiler.codeGenerator.op_add_RV(REG_RSP,pobj_sf->GetFrameSize(0));
62
63 //スタックフレームスケジュール(subコマンドに渡す値)
64 compiler.codeGenerator.opfix( pStackFramePertialSchedule, pobj_sf->GetFrameSize(0) );
65
66 UserProc::CompileStartForUserProc( pBackUserProc );
67 cp=BackCp;
68
69 //ret
70 compiler.codeGenerator.op_ret();
71 }
72 else if( userProc.GetName() == "_System_InitStaticLocalVariables" ){
73 //静的ローカルオブジェクトのコンストラクタ呼び出し
74
75 //sub rsp,スタックフレームサイズ
76 const PertialSchedule *pStackFramePertialSchedule = compiler.codeGenerator.op_sub_rsp( 0, true );
77
78 BOOST_FOREACH( Variable *pVar, compiler.GetObjectModule().meta.GetGlobalVars() ){
79 if(memicmp(pVar->GetName().c_str(),"Static%",7)==0){
80 //コンストラクタ呼び出し
81 if( pVar->GetType().IsObject() ){
82
83 //エラー用
84 cp=pVar->source_code_address;
85
86 CallConstructor(
87 pVar->GetName().c_str(),
88 pVar->GetSubscripts(),
89 pVar->GetType(),
90 pVar->GetParamStrForConstructor().c_str());
91 }
92 }
93 }
94
95 //add rsp,スタックフレームサイズ
96 compiler.codeGenerator.op_add_RV(REG_RSP,pobj_sf->GetFrameSize(0));
97
98 //スタックフレームスケジュール(subコマンドに渡す値)
99 compiler.codeGenerator.opfix( pStackFramePertialSchedule, pobj_sf->GetFrameSize(0) );
100
101 //ret
102 compiler.codeGenerator.op_ret();
103 }
104 else if( userProc.GetName() == "_System_Call_Destructor_of_GlobalObject" ){
105 //sub rsp,8(※RSPを16バイト境界にあわせるため)
106 compiler.codeGenerator.op_sub_rsp(0x8);
107
108
109 const UserProc *pBackUserProc = &UserProc::CompilingUserProc();
110 UserProc::CompileStartForGlobalArea();
111
112 compiler.codeGenerator.lexicalScopes.CallDestructorsOfScopeEnd();
113
114 UserProc::CompileStartForUserProc( pBackUserProc );
115
116
117 //add rsp,8
118 compiler.codeGenerator.op_add_RV(REG_RSP,0x8);
119
120 //ret
121 compiler.codeGenerator.op_ret();
122 }
123 else if( userProc.GetName() == "_System_GetSp" ){
124 //mov rax,rsp
125 compiler.codeGenerator.op_mov_RR(REG_RAX,REG_RSP);
126
127 //add rax,PTR_SIZE
128 compiler.codeGenerator.op_add_RV(REG_RAX,PTR_SIZE);
129
130 //ret
131 compiler.codeGenerator.op_ret();
132 }
133 else{
134 SetError();
135 }
136}
137void AutoGeneration(const UserProc &userProc){
138 if( userProc.GetName() == "InitializeUserTypes"
139 && userProc.HasParentClass()
140 && userProc.GetParentClass().GetName() == "_System_TypeBase" ){
141 compiler.GetObjectModule().meta.GetClasses().Compile_System_InitializeUserTypes();
142 }
143 else if( userProc.GetName() == "RegisterGlobalRoots"
144 && userProc.HasParentClass()
145 && userProc.GetParentClass().GetName() == "_System_CGarbageCollection" ){
146
147 Compile_AddGlobalRootsForGc();
148 }
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 }
182 else{
183 SetError();
184 }
185}
186void _compile_proc(const UserProc *pUserProc){
187 extern char *basbuf;
188 extern HANDLE hHeap;
189 extern BOOL bDebugCompile;
190 int i3,i4;
191 char temporary[VN_SIZE];
192
193 if( pUserProc->GetLocalVars().size() ){
194 SetError();
195 return;
196 }
197
198 trace_for_sourcecodestep( "★★★ " << pUserProc->GetFullName() << "のコンパイルを開始" );
199
200 pUserProc->CompleteCompile();
201
202 extern BOOL bSystemProc;
203 if(memcmp(pUserProc->GetName().c_str(),"_System_",8)==0) bSystemProc=1;
204 else bSystemProc=0;
205
206 extern BOOL bDebugSupportProc;
207 if(memcmp(pUserProc->GetName().c_str(),"_DebugSys_",10)==0){
208 if(!bDebugCompile){
209 return;
210 }
211 bDebugSupportProc=1;
212 }
213 else bDebugSupportProc=0;
214
215 //コンパイル中の関数が属するクラス
216 compiler.pCompilingClass=pUserProc->GetParentClassPtr();
217
218 //コンパイルスタートをクラス管理クラスに追加
219 compiler.GetObjectModule().meta.GetClasses().StartCompile( pUserProc );
220
221 //コンパイル中の関数
222 UserProc::CompileStartForUserProc( pUserProc );
223
224 // コンパイル中の関数が属する名前空間
225 compiler.GetNamespaceSupporter().SetLivingNamespaceScopes( pUserProc->GetNamespaceScopes() );
226
227 // コンパイル中の関数でImportsされている名前空間
228 compiler.GetNamespaceSupporter().SetImportedNamespaces( pUserProc->GetImportedNamespaces() );
229
230 // コード生成対象を選択
231 compiler.codeGenerator.Select( (const_cast<UserProc *>(pUserProc))->GetNativeCode() );
232
233 if(pUserProc->IsSystem()){
234 ////////////////////
235 // 特殊関数
236 ////////////////////
237
238 extern int AllLocalVarSize;
239 AllLocalVarSize=0;
240
241 //スタックフレーム管理用オブジェクトを初期化
242 extern StackFrame *pobj_sf;
243 pobj_sf=new StackFrame();
244
245 SystemProc(*pUserProc);
246
247 //スタックフレーム管理用オブジェクトを破棄
248 delete pobj_sf;
249 pobj_sf=0;
250
251 return;
252 }
253
254 cp=pUserProc->GetCodePos();
255 for(;;cp++){
256 if(IsCommandDelimitation(basbuf[cp])) break;
257 }
258 cp--;
259
260 //プロシージャ抜け出しスケジュール(Exit Sub/Function)
261 compiler.codeGenerator.exitSubCodePositions.clear();
262
263 //ラベル用のメモリを確保
264 compiler.codeGenerator.gotoLabels.clear();
265
266 //Gotoラベルスケジュール
267 compiler.codeGenerator.gotoLabelSchedules.clear();
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アドレスを初期化
282 compiler.codeGenerator.ClearContinueArea();
283
284 //ローカル変数に関する情報
285 extern int AllLocalVarSize;
286 AllLocalVarSize=0;
287
288 //レキシカルスコープ情報を初期化
289 compiler.codeGenerator.lexicalScopes.Init( compiler.codeGenerator.GetNativeCodeSize() );
290
291
292 /////////////////////////////////////
293 // パラメータ用の変数データを考慮
294 /////////////////////////////////////
295
296 //パラメータ用の変数データを考慮
297 for(i3=(int)pUserProc->RealParams().size()-1;i3>=0;i3--){
298 Parameter &param = *pUserProc->RealParams()[i3];
299
300 Variable *pVar = new Variable( param.GetVarName(), param, false, param.IsRef(), "", false );
301
302 if( param.IsArray() ){
303 pVar->SetArray( param.GetSubscripts() );
304 }
305
306 int varSize;
307 if( param.IsRef() == false && param.IsStruct() ){
308 //構造体のByValパラメータ
309 pVar->ThisIsParameter();
310 varSize=PTR_SIZE;
311 }
312 else{
313 if( param.IsArray() == false ){
314 varSize = pVar->GetMemorySize();
315 }
316 else{
317 varSize=PTR_SIZE;
318 }
319 }
320 AllLocalVarSize+=varSize;
321 pVar->SetOffsetAddress( AllLocalVarSize );
322
323 //レキシカルスコープ情報
324 pVar->SetScopeLevel( compiler.codeGenerator.lexicalScopes.GetNowLevel() );
325 pVar->SetScopeStartAddress( compiler.codeGenerator.lexicalScopes.GetStartAddress() );
326 pVar->bLiving=TRUE;
327
328 pUserProc->GetLocalVars().push_back( pVar );
329 }
330
331 //Thisポインタを示すローカルオフセット値をセット
332 extern int LocalVar_ThisPtrOffset;
333 LocalVar_ThisPtrOffset=AllLocalVarSize;
334
335 //スタックフレーム管理用クラスを初期化
336 extern StackFrame *pobj_sf;
337 pobj_sf=new StackFrame();
338
339
340 ///////////////////////
341 // ここからコード生成
342
343 for(i3=(int)pUserProc->RealParams().size()-1;i3>=0;i3--){
344 Parameter &param = *pUserProc->RealParams()[i3];
345 if(i3==3){
346 if(param.IsReal()&&param.IsRef() == false){
347 //movsd qword ptr[rsp+0x20],xmm3
348 compiler.codeGenerator.op_movsd_MR(REG_XMM3,REG_RSP,0x20,MOD_BASE_DISP32);
349 }
350 else{
351 //mov qword ptr[rsp+0x20],r9
352 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_R9,REG_RSP,0x20,MOD_BASE_DISP32);
353 }
354 }
355 if(i3==2){
356 if(param.IsReal()&&param.IsRef() == false){
357 //movsd qword ptr[rsp+0x18],xmm2
358 compiler.codeGenerator.op_movsd_MR(REG_XMM2,REG_RSP,0x18,MOD_BASE_DISP32);
359 }
360 else{
361 //mov qword ptr[rsp+0x18],r8
362 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_R8,REG_RSP,0x18,MOD_BASE_DISP32);
363 }
364 }
365 if(i3==1){
366 if(param.IsReal()&&param.IsRef() == false){
367 //movsd qword ptr[rsp+0x10],xmm1
368 compiler.codeGenerator.op_movsd_MR(REG_XMM1,REG_RSP,0x10,MOD_BASE_DISP32);
369 }
370 else{
371 //mov qword ptr[rsp+0x10],rdx
372 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_RDX,REG_RSP,0x10,MOD_BASE_DISP32);
373 }
374 }
375 if(i3==0){
376 if(param.IsReal()&&param.IsRef() == false){
377 //movsd qword ptr[rsp+0x8],xmm0
378 compiler.codeGenerator.op_movsd_MR(REG_XMM0,REG_RSP,0x8,MOD_BASE_DISP32);
379 }
380 else{
381 //mov qword ptr[rsp+0x8],rcx
382 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_RCX,REG_RSP,0x8,MOD_BASE_DISP32);
383 }
384 }
385 }
386
387 //ret用のアドレスを考慮
388 AllLocalVarSize+=sizeof(_int64);
389
390 //sub rsp,スタックフレームサイズ
391 const PertialSchedule *pStackFramePertialSchedule = compiler.codeGenerator.op_sub_rsp( 0, true );
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
406 if( !pUserProc->ReturnType().IsNull() ){
407 //戻り値が存在するとき
408
409 const char *temp = pUserProc->GetName().c_str();
410 if( temp[0]==1&&temp[1]==ESC_OPERATOR ){
411 temp = "_System_ReturnValue";
412 }
413
414 if( pUserProc->ReturnType().IsStruct() ){
415 //戻り値用の構造体(値型)はパラメータで引き渡される
416 }
417 else{
418 if( pUserProc->ReturnType().IsObject() ){
419 sprintf(temporary,"%s=Nothing%c%c%s",temp,1,ESC_AS, compiler.TypeToString( pUserProc->ReturnType() ).c_str() );
420 }
421 else{
422 //戻り値用の変数の定義
423 sprintf(temporary,"%s%c%c%s",temp,1,ESC_AS, compiler.TypeToString( pUserProc->ReturnType() ).c_str() );
424 }
425
426 OpcodeDim(temporary,0);
427 }
428 }
429
430 const PertialSchedule *pRspOffsetPertialSchedule1 = NULL;
431 const PertialSchedule *pRspOffsetPertialSchedule2 = NULL;
432 if(bDebugCompile&&bDebugSupportProc==0){
433 //mov rdx, qword ptr[rsp+スタックフレームサイズ]
434 pRspOffsetPertialSchedule1 = compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_RDX,REG_RSP,0,MOD_BASE_DISP32, Schedule::None, true );
435
436 //mov rcx,rsp
437 compiler.codeGenerator.op_mov_RR(REG_RCX,REG_RSP);
438
439 //add rcx,スタックフレームサイズ+sizeof(_int64) ※ret用のサイズを考慮
440 pRspOffsetPertialSchedule2 = compiler.codeGenerator.op_add_RV(REG_RCX,0, Schedule::None, true );
441
442 //call _DebugSys_StartProc
443 extern const UserProc *pSub_DebugSys_StartProc;
444 compiler.codeGenerator.op_call(pSub_DebugSys_StartProc);
445 }
446
447 if(compiler.pCompilingClass){
448 if( pUserProc->GetName() == compiler.pCompilingClass->GetName() ){
449 ////////////////////////////////////
450 // コンストラクタをコンパイルするとき
451 ////////////////////////////////////
452
453 //コンストラクタのコンパイル開始を通知
454 compiler.pCompilingClass->NotifyStartConstructorCompile();
455
456 //基底クラスかどうかの識別
457 //(継承元がインターフェイスの場合も基底クラスと見なす)
458 BOOL bThisIsSuperClass;
459 if( !compiler.pCompilingClass->HasSuperClass() ) bThisIsSuperClass=1;
460 else if( compiler.pCompilingClass->GetSuperClass().GetConstructorMethod() == NULL ){
461 //インターフェイスを継承したときはコンストラクタを持たない
462 bThisIsSuperClass=1;
463 }
464 else bThisIsSuperClass=0;
465
466 if(!bThisIsSuperClass){
467 /* サブクラスコンストラクタをコンパイルしているときは、
468 基底クラスのコンストラクタを呼び出す */
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 }
479 if( compiler.pCompilingClass->GetSuperClass().GetName() == temporary ){
480 //基底クラスのコンストラクタを呼び出す
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
494 Type dummyType;
495 CallProc( PROC_DEFAULT
496 , &compiler.pCompilingClass->GetSuperClass().GetConstructorMethod()->GetUserProc()
497 , compiler.pCompilingClass->GetSuperClass().GetConstructorMethod()->GetUserProc().GetName().c_str()
498 , temporary
499 , dummyType );
500 }
501 else{
502 //基底クラスのコンストラクタを暗黙的に呼び出す
503 Opcode_CallProc("",
504 &compiler.pCompilingClass->GetSuperClass().GetConstructorMethod()->GetUserProc(),
505 0,
506 "");
507 }
508 }
509
510 //仮想関数テーブルを初期化
511 if( compiler.pCompilingClass->IsExistVirtualFunctions()
512 && !compiler.pCompilingClass->IsAbstract() )
513 {
514 // mov rax,vtblAddress
515 compiler.codeGenerator.op_mov_RV_vtbl( REG_RAX, compiler.pCompilingClass );
516
517 //Thisポインタをrcxにコピー
518 SetThisPtrToReg(REG_RCX);
519
520 //mov qword ptr[rcx],rax
521 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_RAX,REG_RCX,0,MOD_BASE);
522
523
524 // 仮想関数になるメソッドに使用チェックをつける
525 BOOST_FOREACH( const CMethod *pMethod, compiler.pCompilingClass->GetMethods() )
526 {
527 if( pMethod->IsVirtual() )
528 {
529 pMethod->GetUserProc().Using();
530 }
531 }
532 }
533 }
534 else if( pUserProc->IsDestructor() ){
535 //デストラクタをコンパイルしたとき
536
537 //デストラクタのコンパイル開始を通知
538 compiler.pCompilingClass->NotifyStartDestructorCompile();
539 }
540 }
541
542 //////////////////////////////////////////
543 //////////////////////////////////////////
544 ////// プロシージャ内をコンパイル ////////
545 if( pUserProc->IsAutoGeneration() ){
546 AutoGeneration( *pUserProc );
547 }
548 else{
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 }
560 }
561 //////////////////////////////////////////
562 //////////////////////////////////////////
563
564 if( compiler.pCompilingClass ){
565
566 if( compiler.pCompilingClass->IsCompilingConstructor() ){
567 // コンストラクタをコンパイルしていたとき
568
569 // コンストラクタのコンパイルが完了したことを通知
570 compiler.pCompilingClass->NotifyFinishConstructorCompile();
571 }
572 else if( pUserProc->IsDestructor() ){
573 ////////////////////////////////////
574 //デストラクタをコンパイルしたとき
575 ////////////////////////////////////
576
577 // デストラクタのコンパイルが完了したことを通知
578 compiler.pCompilingClass->NotifyFinishDestructorCompile();
579
580 if( compiler.pCompilingClass->HasSuperClass() ){
581 /* サブクラスのデストラクタをコンパイルしているときは、
582 基底クラスのデストラクタを呼び出す */
583
584 const CMethod *method = compiler.pCompilingClass->GetSuperClass().GetDestructorMethod();
585 if( method ){
586 Opcode_CallProc("",
587 &method->GetUserProc(),
588 0,
589 "");
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)の解放処理
604 compiler.codeGenerator.lexicalScopes.CallDestructorsOfScopeEnd();
605
606 //プロシージャ抜け出しスケジュール(Exit Sub/Function)
607 compiler.codeGenerator.ResolveExitSubSchedule();
608
609 if(bDebugCompile&&bDebugSupportProc==0){
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.