source: dev/trunk/abdev/BasicCompiler64/Compile_ProcOp.cpp @ 353

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

インターフェイス実装周りの仕様整備

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    {
142        compiler.GetObjectModule().meta.GetClasses().Compile_System_InitializeUserTypes();
143    }
144    else if( userProc.GetName() == "RegisterGlobalRoots"
145        && userProc.HasParentClass()
146        && userProc.GetParentClass().GetName() == "_System_CGarbageCollection" )
147    {
148        Compile_AddGlobalRootsForGc();
149    }
150    else if( userProc.GetName() == compiler.globalAreaProcName ){
151        ////////////////////////////////////////
152        // グローバル領域をコンパイル
153        ////////////////////////////////////////
154
155        const UserProc *pBackUserProc = &UserProc::CompilingUserProc();
156        UserProc::CompileStartForGlobalArea();
157
158        int BackCp = cp;
159        cp=-1;
160
161        //クラスに属する静的メンバを定義
162        compiler.GetObjectModule().meta.GetClasses().InitStaticMember();
163
164        //グローバル実行領域をコンパイル開始
165        CompileBuffer(0,0);
166
167        //Goto未知ラベルスケジュールが存在したらエラーにする
168        BOOST_FOREACH( const GotoLabelSchedule *pGotoLabelSchedule, compiler.codeGenerator.gotoLabelSchedules )
169        {
170            if(pGotoLabelSchedule->GetName().size()>0){
171                SetError(6,pGotoLabelSchedule->GetName(),pGotoLabelSchedule->GetSourceCodePos());
172            }
173            else{
174                char temporary[255];
175                sprintf(temporary,"%d",pGotoLabelSchedule->GetLineNum());
176                SetError(6,temporary,pGotoLabelSchedule->GetSourceCodePos());
177            }
178        }
179
180        UserProc::CompileStartForUserProc( pBackUserProc );
181        cp=BackCp;
182    }
183    else if( userProc.HasParentClass()
184        && userProc.IsCastOperator()
185        && userProc.ReturnType().IsInterface() )
186    {
187        // インターフェイス型にキャストするためのメソッド
188
189        int vtblMasterListIndex = userProc.GetParentClass().GetVtblMasterListIndex( &userProc.ReturnType().GetClass() );
190
191        char temporary[1024];
192        sprintf( temporary,
193            "Return New %s(ObjPtr( This ),Get_LONG_PTR( (Get_LONG_PTR( ObjPtr(This) ) + SizeOf(LONG_PTR)*%d) As VoidPtr ) As VoidPtr )",
194            userProc.ReturnType().GetClass().GetName().c_str(),
195            vtblMasterListIndex
196        );
197        MakeMiddleCode( temporary );
198
199        ChangeOpcode( temporary );
200    }
201    else{
202        SetError();
203    }
204}
205void _compile_proc(const UserProc *pUserProc){
206    extern char *basbuf;
207    extern HANDLE hHeap;
208    extern BOOL bDebugCompile;
209    int i3,i4;
210    char temporary[VN_SIZE];
211
212    if( pUserProc->GetLocalVars().size() ){
213        SetError();
214        return;
215    }
216
217    trace_for_sourcecodestep( "★★★ " << pUserProc->GetFullName() << "のコンパイルを開始" );
218
219    pUserProc->CompleteCompile();
220
221    extern BOOL bSystemProc;
222    if(memcmp(pUserProc->GetName().c_str(),"_System_",8)==0) bSystemProc=1;
223    else bSystemProc=0;
224
225    extern BOOL bDebugSupportProc;
226    if(memcmp(pUserProc->GetName().c_str(),"_DebugSys_",10)==0){
227        if(!bDebugCompile){
228            return;
229        }
230        bDebugSupportProc=1;
231    }
232    else bDebugSupportProc=0;
233
234    //コンパイル中の関数が属するクラス
235    compiler.pCompilingClass=pUserProc->GetParentClassPtr();
236
237    //コンパイルスタートをクラス管理クラスに追加
238    compiler.GetObjectModule().meta.GetClasses().StartCompile( pUserProc );
239
240    //コンパイル中の関数
241    UserProc::CompileStartForUserProc( pUserProc );
242
243    // コンパイル中の関数が属する名前空間
244    compiler.GetNamespaceSupporter().SetLivingNamespaceScopes( pUserProc->GetNamespaceScopes() );
245
246    // コンパイル中の関数でImportsされている名前空間
247    compiler.GetNamespaceSupporter().SetImportedNamespaces( pUserProc->GetImportedNamespaces() );
248
249    // コード生成対象を選択
250    compiler.codeGenerator.Select( (const_cast<UserProc *>(pUserProc))->GetNativeCode() );
251
252    if(pUserProc->IsSystem()){
253        ////////////////////
254        // 特殊関数
255        ////////////////////
256
257        extern int AllLocalVarSize;
258        AllLocalVarSize=0;
259
260        //スタックフレーム管理用オブジェクトを初期化
261        extern StackFrame *pobj_sf;
262        pobj_sf=new StackFrame();
263
264        SystemProc(*pUserProc);
265
266        //スタックフレーム管理用オブジェクトを破棄
267        delete pobj_sf;
268        pobj_sf=0;
269
270        return;
271    }
272
273    if( !pUserProc->IsAutoGeneration() )
274    {
275        cp=pUserProc->GetCodePos();
276        for(;;cp++){
277            if(IsCommandDelimitation(basbuf[cp])) break;
278        }
279        cp--;
280    }
281
282    //プロシージャ抜け出しスケジュール(Exit Sub/Function)
283    compiler.codeGenerator.exitSubCodePositions.clear();
284
285    //ラベル用のメモリを確保
286    compiler.codeGenerator.gotoLabels.clear();
287
288    //Gotoラベルスケジュール
289    compiler.codeGenerator.gotoLabelSchedules.clear();
290
291    //With情報のメモリを確保
292    extern WITHINFO WithInfo;
293    WithInfo.ppName=(char **)HeapAlloc(hHeap,0,1);
294    WithInfo.pWithCp=(int *)HeapAlloc(hHeap,0,1);
295    WithInfo.num=0;
296
297    //重複エラー情報管理のメモリを確保
298    extern char **SynonymErrorWords;
299    extern int SynonymErrorNum;
300    SynonymErrorNum=0;
301    SynonymErrorWords=(char **)HeapAlloc(hHeap,0,1);
302
303    //Continueアドレスを初期化
304    compiler.codeGenerator.ClearContinueArea();
305
306    //ローカル変数に関する情報
307    extern int AllLocalVarSize;
308    AllLocalVarSize=0;
309
310    //レキシカルスコープ情報を初期化
311    compiler.codeGenerator.lexicalScopes.Init( compiler.codeGenerator.GetNativeCodeSize() );
312
313
314    /////////////////////////////////////
315    // パラメータ用の変数データを考慮
316    /////////////////////////////////////
317
318    //パラメータ用の変数データを考慮
319    for(i3=(int)pUserProc->RealParams().size()-1;i3>=0;i3--){
320        Parameter &param = *pUserProc->RealParams()[i3];
321
322        Variable *pVar = new Variable( param.GetVarName(), param, false, param.IsRef(), "", false );
323
324        if( param.IsArray() ){
325            pVar->SetArray( param.GetSubscripts() );
326        }
327
328        int varSize;
329        if( param.IsRef() == false && param.IsStruct() ){
330            //構造体のByValパラメータ
331            pVar->ThisIsParameter();
332            varSize=PTR_SIZE;
333        }
334        else{
335            if( param.IsArray() == false ){
336                varSize = pVar->GetMemorySize();
337            }
338            else{
339                varSize=PTR_SIZE;
340            }
341        }
342        AllLocalVarSize+=varSize;
343        pVar->SetOffsetAddress( AllLocalVarSize );
344
345        //レキシカルスコープ情報
346        pVar->SetScopeLevel( compiler.codeGenerator.lexicalScopes.GetNowLevel() );
347        pVar->SetScopeStartAddress( compiler.codeGenerator.lexicalScopes.GetStartAddress() );
348        pVar->bLiving=TRUE;
349
350        pUserProc->GetLocalVars().push_back( pVar );
351    }
352
353    //Thisポインタを示すローカルオフセット値をセット
354    extern int LocalVar_ThisPtrOffset;
355    LocalVar_ThisPtrOffset=AllLocalVarSize;
356
357    //スタックフレーム管理用クラスを初期化
358    extern StackFrame *pobj_sf;
359    pobj_sf=new StackFrame();
360
361
362    ///////////////////////
363    // ここからコード生成
364
365    for(i3=(int)pUserProc->RealParams().size()-1;i3>=0;i3--){
366        Parameter &param = *pUserProc->RealParams()[i3];
367        if(i3==3){
368            if(param.IsReal()&&param.IsRef() == false){
369                //movsd qword ptr[rsp+0x20],xmm3
370                compiler.codeGenerator.op_movsd_MR(REG_XMM3,REG_RSP,0x20,MOD_BASE_DISP32);
371            }
372            else{
373                //mov qword ptr[rsp+0x20],r9
374                compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_R9,REG_RSP,0x20,MOD_BASE_DISP32);
375            }
376        }
377        if(i3==2){
378            if(param.IsReal()&&param.IsRef() == false){
379                //movsd qword ptr[rsp+0x18],xmm2
380                compiler.codeGenerator.op_movsd_MR(REG_XMM2,REG_RSP,0x18,MOD_BASE_DISP32);
381            }
382            else{
383                //mov qword ptr[rsp+0x18],r8
384                compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_R8,REG_RSP,0x18,MOD_BASE_DISP32);
385            }
386        }
387        if(i3==1){
388            if(param.IsReal()&&param.IsRef() == false){
389                //movsd qword ptr[rsp+0x10],xmm1
390                compiler.codeGenerator.op_movsd_MR(REG_XMM1,REG_RSP,0x10,MOD_BASE_DISP32);
391            }
392            else{
393                //mov qword ptr[rsp+0x10],rdx
394                compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_RDX,REG_RSP,0x10,MOD_BASE_DISP32);
395            }
396        }
397        if(i3==0){
398            if(param.IsReal()&&param.IsRef() == false){
399                //movsd qword ptr[rsp+0x8],xmm0
400                compiler.codeGenerator.op_movsd_MR(REG_XMM0,REG_RSP,0x8,MOD_BASE_DISP32);
401            }
402            else{
403                //mov qword ptr[rsp+0x8],rcx
404                compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_RCX,REG_RSP,0x8,MOD_BASE_DISP32);
405            }
406        }
407    }
408
409    //ret用のアドレスを考慮
410    AllLocalVarSize+=sizeof(_int64);
411
412    //sub rsp,スタックフレームサイズ
413    const PertialSchedule *pStackFramePertialSchedule = compiler.codeGenerator.op_sub_rsp( 0, true );
414
415    //mov qword ptr[rsp+offset],reg     ※スタックフレームを利用
416    pobj_sf->push(REG_RBX);
417    pobj_sf->push(REG_RSI);
418    pobj_sf->push(REG_RDI);
419    pobj_sf->push(REG_R12);
420    pobj_sf->push(REG_R13);
421    pobj_sf->push(REG_R14);
422    pobj_sf->push(REG_R15);
423
424    //ローカル変数のベース値
425    int BaseLocalVar;
426    BaseLocalVar=AllLocalVarSize;
427
428    if( !pUserProc->ReturnType().IsNull() ){
429        //戻り値が存在するとき
430
431        const char *temp = pUserProc->GetName().c_str();
432        if( temp[0]==1&&temp[1]==ESC_OPERATOR ){
433            temp = "_System_ReturnValue";
434        }
435
436        if( pUserProc->ReturnType().IsStruct() ){
437            //戻り値用の構造体(値型)はパラメータで引き渡される
438        }
439        else{
440            if( pUserProc->ReturnType().IsObject() ){
441                sprintf(temporary,"%s=Nothing%c%c%s",temp,1,ESC_AS, compiler.TypeToString( pUserProc->ReturnType() ).c_str() );
442            }
443            else{
444                //戻り値用の変数の定義
445                sprintf(temporary,"%s%c%c%s",temp,1,ESC_AS, compiler.TypeToString( pUserProc->ReturnType() ).c_str() );
446            }
447
448            OpcodeDim(temporary,0);
449        }
450    }
451
452    const PertialSchedule *pRspOffsetPertialSchedule1 = NULL;
453    const PertialSchedule *pRspOffsetPertialSchedule2 = NULL;
454    if(bDebugCompile&&bDebugSupportProc==0){
455        //mov rdx, qword ptr[rsp+スタックフレームサイズ]
456        pRspOffsetPertialSchedule1 = compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_RDX,REG_RSP,0,MOD_BASE_DISP32, Schedule::None, true );
457
458        //mov rcx,rsp
459        compiler.codeGenerator.op_mov_RR(REG_RCX,REG_RSP);
460
461        //add rcx,スタックフレームサイズ+sizeof(_int64) ※ret用のサイズを考慮
462        pRspOffsetPertialSchedule2 = compiler.codeGenerator.op_add_RV(REG_RCX,0, Schedule::None, true );
463
464        //call _DebugSys_StartProc
465        extern const UserProc *pSub_DebugSys_StartProc;
466        compiler.codeGenerator.op_call(pSub_DebugSys_StartProc);
467    }
468
469    if(compiler.pCompilingClass){
470        if( pUserProc->GetName() == compiler.pCompilingClass->GetName() ){
471            ////////////////////////////////////
472            // コンストラクタをコンパイルするとき
473            ////////////////////////////////////
474
475            //コンストラクタのコンパイル開始を通知
476            compiler.pCompilingClass->NotifyStartConstructorCompile();
477
478            //基底クラスかどうかの識別
479            //(継承元がインターフェイスの場合も基底クラスと見なす)
480            BOOL bThisIsSuperClass;
481            if( !compiler.pCompilingClass->HasSuperClass() ) bThisIsSuperClass=1;
482            else if( compiler.pCompilingClass->GetSuperClass().GetConstructorMethod() == NULL ){
483                //インターフェイスを継承したときはコンストラクタを持たない
484                bThisIsSuperClass=1;
485            }
486            else bThisIsSuperClass=0;
487
488            if(!bThisIsSuperClass){
489                /* サブクラスコンストラクタをコンパイルしているときは、
490                    基底クラスのコンストラクタを呼び出す */
491
492                i3=cp+1;
493                while(IsCommandDelimitation(basbuf[i3])) i3++;
494                for(i4=0;;i3++,i4++){
495                    if(!IsVariableChar(basbuf[i3])){
496                        temporary[i4]=0;
497                        break;
498                    }
499                    temporary[i4]=basbuf[i3];
500                }
501                if( compiler.pCompilingClass->GetSuperClass().GetName() == temporary ){
502                    //基底クラスのコンストラクタを呼び出す
503                    cp=i3;
504                    for(i4=0;;cp++,i4++){
505                        if(IsCommandDelimitation(basbuf[cp])){
506                            temporary[i4]=0;
507                            break;
508                        }
509                        temporary[i4]=basbuf[cp];
510                    }
511                    if(!(temporary[0]=='('&&temporary[lstrlen(temporary)-1]==')')){
512                        SetError(1,NULL,cp);
513                    }
514                    RemoveStringPare(temporary);
515
516                    Type dummyType;
517                    CallProc( PROC_DEFAULT
518                        , &compiler.pCompilingClass->GetSuperClass().GetConstructorMethod()->GetUserProc()
519                        , compiler.pCompilingClass->GetSuperClass().GetConstructorMethod()->GetUserProc().GetName().c_str()
520                        , temporary
521                        , Type()        // baseTypeはなし
522                        , dummyType
523                    );
524                }
525                else{
526                    //基底クラスのコンストラクタを暗黙的に呼び出す
527                    Opcode_CallProc("",
528                        &compiler.pCompilingClass->GetSuperClass().GetConstructorMethod()->GetUserProc(),
529                        0,
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.