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

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

静的リンクライブラリにより、複数のグローバル領域が存在することになったのでそれぞれを関数ベースに分けた

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