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

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

Throw→Catch間のパラメータ引渡しに対応。
グローバル領域でのTryスコープを可能にした。これで例外処理機構実装完了。
エディタの補間機能にTry/Catch/Finally/EndTryを追加。

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