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

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

Try-Catchを試験的に実装。
(まだ下記の動作しか実装していません)
・Try
・Catch(パラメータ無し)
・Throw(パラメータ無し)

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{
124 SetError();
125 }
126}
127void AutoGeneration(const UserProc &userProc){
128 if( userProc.GetName() == "InitializeUserTypes"
129 && userProc.HasParentClass()
130 && userProc.GetParentClass().GetName() == "_System_TypeBase" )
131 {
132 compiler.GetObjectModule().meta.GetClasses().Compile_System_InitializeUserTypes();
133 }
134 else if( userProc.GetName() == "InitializeUserTypesForBaseType"
135 && userProc.HasParentClass()
136 && userProc.GetParentClass().GetName() == "_System_TypeBase" )
137 {
138 compiler.GetObjectModule().meta.GetClasses().Compile_System_InitializeUserTypesForBaseType();
139 }
140 else if( userProc.GetName() == "RegisterGlobalRoots"
141 && userProc.HasParentClass()
142 && userProc.GetParentClass().GetName() == "_System_CGarbageCollection" )
143 {
144 Compile_AddGlobalRootsForGc();
145 }
146 else if( userProc.GetName() == compiler.globalAreaProcName ){
147 ////////////////////////////////////////
148 // グローバル領域をコンパイル
149 ////////////////////////////////////////
150
151 const UserProc *pBackUserProc = &UserProc::CompilingUserProc();
152 UserProc::CompileStartForGlobalArea();
153
154 int BackCp = cp;
155 cp=-1;
156
157 //クラスに属する静的メンバを定義
158 compiler.GetObjectModule().meta.GetClasses().InitStaticMember();
159
160 //グローバル実行領域をコンパイル開始
161 CompileBuffer(0,0);
162
163 //Goto未知ラベルスケジュールが存在したらエラーにする
164 BOOST_FOREACH( const GotoLabelSchedule *pGotoLabelSchedule, compiler.codeGenerator.gotoLabelSchedules )
165 {
166 if(pGotoLabelSchedule->GetName().size()>0){
167 SetError(6,pGotoLabelSchedule->GetName(),pGotoLabelSchedule->GetSourceCodePos());
168 }
169 else{
170 char temporary[255];
171 sprintf(temporary,"%d",pGotoLabelSchedule->GetLineNum());
172 SetError(6,temporary,pGotoLabelSchedule->GetSourceCodePos());
173 }
174 }
175
176 UserProc::CompileStartForUserProc( pBackUserProc );
177 cp=BackCp;
178 }
179 else if( userProc.HasParentClass()
180 && userProc.IsCastOperator()
181 && userProc.ReturnType().IsInterface() )
182 {
183 // インターフェイス型にキャストするためのメソッド
184
185 int vtblMasterListIndex = userProc.GetParentClass().GetVtblMasterListIndex( &userProc.ReturnType().GetClass() );
186
187 char temporary[1024];
188 sprintf( temporary,
189 "Return New %s(ObjPtr( This ),Get_LONG_PTR( (Get_LONG_PTR( ObjPtr(This) ) + SizeOf(LONG_PTR)*%d) As VoidPtr ) As VoidPtr )",
190 userProc.ReturnType().GetClass().GetName().c_str(),
191 vtblMasterListIndex
192 );
193 MakeMiddleCode( temporary );
194
195 ChangeOpcode( temporary );
196 }
197 else{
198 SetError();
199 }
200}
201void _compile_proc(const UserProc *pUserProc){
202 extern char *basbuf;
203 extern HANDLE hHeap;
204 extern BOOL bDebugCompile;
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(!bDebugCompile){
224 return;
225 }
226 bDebugSupportProc=1;
227 }
228 else bDebugSupportProc=0;
229
230 //コンパイル中の関数が属するクラス
231 compiler.pCompilingClass=pUserProc->GetParentClassPtr();
232
233 //コンパイルスタートをクラス管理クラスに追加
234 compiler.GetObjectModule().meta.GetClasses().StartCompile( pUserProc );
235
236 //コンパイル中の関数
237 UserProc::CompileStartForUserProc( pUserProc );
238
239 // コンパイル中の関数が属する名前空間
240 compiler.GetNamespaceSupporter().SetLivingNamespaceScopes( pUserProc->GetNamespaceScopes() );
241
242 // コンパイル中の関数でImportsされている名前空間
243 compiler.GetNamespaceSupporter().SetImportedNamespaces( pUserProc->GetImportedNamespaces() );
244
245 // コード生成対象を選択
246 compiler.codeGenerator.Select( (const_cast<UserProc *>(pUserProc))->GetNativeCode() );
247
248 if(pUserProc->IsSystem()){
249 ////////////////////
250 // 特殊関数
251 ////////////////////
252
253 extern int AllLocalVarSize;
254 AllLocalVarSize=0;
255
256 //スタックフレーム管理用オブジェクトを初期化
257 extern StackFrame *pobj_sf;
258 pobj_sf=new StackFrame();
259
260 SystemProc(*pUserProc);
261
262 //スタックフレーム管理用オブジェクトを破棄
263 delete pobj_sf;
264 pobj_sf=0;
265
266 return;
267 }
268
269 if( !pUserProc->IsAutoGeneration() )
270 {
271 cp=pUserProc->GetCodePos();
272 for(;;cp++){
273 if(IsCommandDelimitation(basbuf[cp])) break;
274 }
275 cp--;
276 }
277
278 //プロシージャ抜け出しスケジュール(Exit Sub/Function)
279 compiler.codeGenerator.exitSubCodePositions.clear();
280
281 //ラベル用のメモリを確保
282 compiler.codeGenerator.gotoLabels.clear();
283
284 //Gotoラベルスケジュール
285 compiler.codeGenerator.gotoLabelSchedules.clear();
286
287 //With情報のメモリを確保
288 extern WITHINFO WithInfo;
289 WithInfo.ppName=(char **)HeapAlloc(hHeap,0,1);
290 WithInfo.pWithCp=(int *)HeapAlloc(hHeap,0,1);
291 WithInfo.num=0;
292
293 //重複エラー情報管理のメモリを確保
294 extern char **SynonymErrorWords;
295 extern int SynonymErrorNum;
296 SynonymErrorNum=0;
297 SynonymErrorWords=(char **)HeapAlloc(hHeap,0,1);
298
299 //Continueアドレスを初期化
300 compiler.codeGenerator.ClearContinueArea();
301
302 //ローカル変数に関する情報
303 extern int AllLocalVarSize;
304 AllLocalVarSize=0;
305
306 //レキシカルスコープ情報を初期化
307 compiler.codeGenerator.lexicalScopes.Init( compiler.codeGenerator.GetNativeCodeSize() );
308
309
310 /////////////////////////////////////
311 // パラメータ用の変数データを考慮
312 /////////////////////////////////////
313
314 //パラメータ用の変数データを考慮
315 for(i3=(int)pUserProc->RealParams().size()-1;i3>=0;i3--){
316 Parameter &param = *pUserProc->RealParams()[i3];
317
318 Variable *pVar = new Variable( param.GetVarName(), param, false, param.IsRef(), "", false );
319
320 if( param.IsArray() ){
321 pVar->SetArray( param.GetSubscripts() );
322 }
323
324 int varSize;
325 if( param.IsRef() == false && param.IsStruct() ){
326 //構造体のByValパラメータ
327 pVar->ThisIsParameter();
328 varSize=PTR_SIZE;
329 }
330 else{
331 if( param.IsArray() == false ){
332 varSize = pVar->GetMemorySize();
333 }
334 else{
335 varSize=PTR_SIZE;
336 }
337 }
338 AllLocalVarSize+=varSize;
339 pVar->SetOffsetAddress( AllLocalVarSize );
340
341 //レキシカルスコープ情報
342 pVar->SetScopeLevel( compiler.codeGenerator.lexicalScopes.GetNowLevel() );
343 pVar->SetScopeStartAddress( compiler.codeGenerator.lexicalScopes.GetStartAddress() );
344 pVar->bLiving=TRUE;
345
346 pUserProc->GetLocalVars().push_back( pVar );
347 }
348
349 //Thisポインタを示すローカルオフセット値をセット
350 extern int LocalVar_ThisPtrOffset;
351 LocalVar_ThisPtrOffset=AllLocalVarSize;
352
353 //スタックフレーム管理用クラスを初期化
354 extern StackFrame *pobj_sf;
355 pobj_sf=new StackFrame();
356
357
358 ///////////////////////
359 // ここからコード生成
360
361 for(i3=(int)pUserProc->RealParams().size()-1;i3>=0;i3--){
362 Parameter &param = *pUserProc->RealParams()[i3];
363 if(i3==3){
364 if(param.IsReal()&&param.IsRef() == false){
365 //movsd qword ptr[rsp+0x20],xmm3
366 compiler.codeGenerator.op_movsd_MR(REG_XMM3,REG_RSP,0x20,MOD_BASE_DISP32);
367 }
368 else{
369 //mov qword ptr[rsp+0x20],r9
370 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_R9,REG_RSP,0x20,MOD_BASE_DISP32);
371 }
372 }
373 if(i3==2){
374 if(param.IsReal()&&param.IsRef() == false){
375 //movsd qword ptr[rsp+0x18],xmm2
376 compiler.codeGenerator.op_movsd_MR(REG_XMM2,REG_RSP,0x18,MOD_BASE_DISP32);
377 }
378 else{
379 //mov qword ptr[rsp+0x18],r8
380 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_R8,REG_RSP,0x18,MOD_BASE_DISP32);
381 }
382 }
383 if(i3==1){
384 if(param.IsReal()&&param.IsRef() == false){
385 //movsd qword ptr[rsp+0x10],xmm1
386 compiler.codeGenerator.op_movsd_MR(REG_XMM1,REG_RSP,0x10,MOD_BASE_DISP32);
387 }
388 else{
389 //mov qword ptr[rsp+0x10],rdx
390 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_RDX,REG_RSP,0x10,MOD_BASE_DISP32);
391 }
392 }
393 if(i3==0){
394 if(param.IsReal()&&param.IsRef() == false){
395 //movsd qword ptr[rsp+0x8],xmm0
396 compiler.codeGenerator.op_movsd_MR(REG_XMM0,REG_RSP,0x8,MOD_BASE_DISP32);
397 }
398 else{
399 //mov qword ptr[rsp+0x8],rcx
400 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_RCX,REG_RSP,0x8,MOD_BASE_DISP32);
401 }
402 }
403 }
404
405 //ret用のアドレスを考慮
406 AllLocalVarSize+=sizeof(_int64);
407
408 //sub rsp,スタックフレームサイズ
409 const PertialSchedule *pStackFramePertialSchedule = compiler.codeGenerator.op_sub_rsp( 0, true );
410
411 //mov qword ptr[rsp+offset],reg ※スタックフレームを利用
412 pobj_sf->push(REG_RBX);
413 pobj_sf->push(REG_RSI);
414 pobj_sf->push(REG_RDI);
415 pobj_sf->push(REG_R12);
416 pobj_sf->push(REG_R13);
417 pobj_sf->push(REG_R14);
418 pobj_sf->push(REG_R15);
419
420 //ローカル変数のベース値
421 int BaseLocalVar;
422 BaseLocalVar=AllLocalVarSize;
423
424 if( !pUserProc->ReturnType().IsNull() ){
425 //戻り値が存在するとき
426
427 const char *temp = pUserProc->GetName().c_str();
428 if( temp[0]==1&&temp[1]==ESC_OPERATOR ){
429 temp = "_System_ReturnValue";
430 }
431
432 if( pUserProc->ReturnType().IsStruct() ){
433 //戻り値用の構造体(値型)はパラメータで引き渡される
434 }
435 else{
436 if( pUserProc->ReturnType().IsObject() ){
437 sprintf(temporary,"%s=Nothing%c%c%s",temp,1,ESC_AS, compiler.TypeToString( pUserProc->ReturnType() ).c_str() );
438 }
439 else{
440 //戻り値用の変数の定義
441 sprintf(temporary,"%s%c%c%s",temp,1,ESC_AS, compiler.TypeToString( pUserProc->ReturnType() ).c_str() );
442 }
443
444 OpcodeDim(temporary,0);
445 }
446 }
447
448 const PertialSchedule *pRspOffsetPertialSchedule1 = NULL;
449 const PertialSchedule *pRspOffsetPertialSchedule2 = NULL;
450 if(bDebugCompile&&bDebugSupportProc==0){
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 //With情報のメモリを解放
592 for(i3=0;i3<WithInfo.num;i3++){
593 SetError(22,"With",WithInfo.pWithCp[i3]);
594 HeapDefaultFree(WithInfo.ppName[i3]);
595 }
596 HeapDefaultFree(WithInfo.ppName);
597 HeapDefaultFree(WithInfo.pWithCp);
598
599 //ローカルオブジェクト(レキシカルスコープレベル=0)の解放処理
600 compiler.codeGenerator.lexicalScopes.CallDestructorsOfScopeEnd();
601
602 //プロシージャ抜け出しスケジュール(Exit Sub/Function)
603 compiler.codeGenerator.ResolveExitSubSchedule();
604
605 if(bDebugCompile&&bDebugSupportProc==0){
606 //call _DebugSys_EndProc
607 extern const UserProc *pSub_DebugSys_EndProc;
608 compiler.codeGenerator.op_call(pSub_DebugSys_EndProc);
609 }
610
611 if( !pUserProc->ReturnType().IsNull() ){
612 //////////////////////////////////
613 // 戻り値をraxまたはxmm0に設定
614 //////////////////////////////////
615
616 RELATIVE_VAR RelativeVar;
617
618 const char *temp = pUserProc->GetName().c_str();
619 if( temp[0]==1 && temp[1]==ESC_OPERATOR ){
620 temp="_System_ReturnValue";
621 }
622 GetVarOffsetReadWrite(temp,&RelativeVar,Type());
623
624 const Type &returnType = pUserProc->ReturnType();
625 if( returnType.IsObject() || returnType.IsStruct() )
626 {
627 SetVarPtrToReg(REG_RAX,&RelativeVar);
628 if( returnType.IsObject() )
629 {
630 //mov rax,qword ptr[rax]
631 compiler.codeGenerator.op_mov_RM( sizeof(_int64), REG_RAX, REG_RAX, 0, MOD_BASE );
632 }
633 }
634 else if( returnType.IsDouble() )
635 {
636 //64ビット実数型
637 SetXmmReg_DoubleVariable(&RelativeVar,REG_XMM0);
638 }
639 else if( returnType.IsSingle() )
640 {
641 //32ビット実数型
642 SetXmmReg_SingleVariable(&RelativeVar,REG_XMM0);
643 }
644 else if( returnType.IsWhole() )
645 {
646 //整数型
647 SetReg_WholeVariable(returnType,&RelativeVar,REG_RAX);
648 }
649 else SetError(300,NULL,cp);
650 }
651
652 //ローカル変数領域のサイズをスタックフレームに通知
653 int localParmSize = AllLocalVarSize - BaseLocalVar;
654 int stackFrameSize = pobj_sf->GetFrameSize( localParmSize );
655
656 //ローカル変数アドレススケジュール
657 BOOST_FOREACH( const PertialSchedule *pPertialSchedule, compiler.codeGenerator.localVarPertialSchedules )
658 {
659 compiler.codeGenerator.opfix_offset( pPertialSchedule, AllLocalVarSize + stackFrameSize );
660 }
661 compiler.codeGenerator.localVarPertialSchedules.clear();
662 BOOST_FOREACH( Variable *pVar, pUserProc->GetLocalVars() ){
663 //後にデバッグで利用する
664 pVar->SetOffsetAddress(
665 AllLocalVarSize + stackFrameSize - pVar->GetOffsetAddress()
666 );
667 }
668
669 //mov reg,qword ptr[rsp+offset] ※スタックフレームを利用
670 pobj_sf->pop(REG_R15);
671 pobj_sf->pop(REG_R14);
672 pobj_sf->pop(REG_R13);
673 pobj_sf->pop(REG_R12);
674 pobj_sf->pop(REG_RDI);
675 pobj_sf->pop(REG_RSI);
676 pobj_sf->pop(REG_RBX);
677
678 int stackFrameAndLocalParamSize = localParmSize + stackFrameSize;
679
680 //add rsp,スタックフレームサイズ
681 compiler.codeGenerator.op_add_rsp(stackFrameAndLocalParamSize);
682
683 //ret
684 compiler.codeGenerator.op_ret();
685
686
687 //デバッグ用
688 if( pRspOffsetPertialSchedule1 ){
689 compiler.codeGenerator.opfix( pRspOffsetPertialSchedule1, stackFrameAndLocalParamSize );
690 compiler.codeGenerator.opfix( pRspOffsetPertialSchedule2, stackFrameAndLocalParamSize + sizeof(_int64) );
691 }
692
693
694 //スタックフレームスケジュール(subコマンド)
695 compiler.codeGenerator.opfix( pStackFramePertialSchedule, stackFrameAndLocalParamSize );
696
697 //スタックフレームスケジュールを実行
698 pobj_sf->RunningSchedule( stackFrameSize );
699 delete pobj_sf;
700 pobj_sf=0;
701
702
703 //重複エラー情報管理のメモリを解放
704 for(i3=0;i3<SynonymErrorNum;i3++) HeapDefaultFree(SynonymErrorWords[i3]);
705 HeapDefaultFree(SynonymErrorWords);
706}
Note: See TracBrowser for help on using the repository browser.