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

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