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

Last change on this file since 355 was 355, checked in by dai_9181, 17 years ago

静的領域に初期オブジェクトを配置可能にした

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