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

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

BasicSourceのシリアライズがうまくいっていない

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