source: dev/trunk/ab5.0/abdev/compiler_x64/Compile_Var.cpp@ 598

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

SplitMemberNameの依存関係を排除。

File size: 36.2 KB
Line 
1#include "stdafx.h"
2
3#include <CodeGenerator.h>
4#include <Compiler.h>
5#include <Variable.h>
6
7#include "../BasicCompiler_Common/common.h"
8#include "Opcode.h"
9
10//変数
11// TODO: xml未完成
12int AllLocalVarSize;
13
14using namespace ActiveBasic::Compiler;
15
16void SetRelativeOffset( Type &resultType, RELATIVE_VAR *pRelativeVar,const char *lpPtrOffset){
17 /////////////////////////////////////////////
18 // 先頭ポインタをr12に取得してメモリへ退避
19 /////////////////////////////////////////////
20
21 SetReg_WholeVariable(Type(DEF_INT64),pRelativeVar,REG_R11);
22
23 //mov qword ptr[rsp+offset],r11 ※スタックフレームを利用
24 pobj_sf->push(REG_R11);
25
26
27 ////////////////////////////////
28 // 添え字を計算する
29 ////////////////////////////////
30
31 int reg=REG_NON;
32 Type type;
33 NumOpe( &reg, lpPtrOffset, Type(), type );
34 if( !type.IsWhole() ){
35 compiler.errorMessenger.Output(46,NULL,cp);
36 }
37 ExtendTypeTo64(type.GetBasicType(),reg);
38
39 if(reg==REG_R14){
40 //mov r14,qword ptr[rsp+offset] ※スタックフレームを利用
41 pobj_sf->pop(REG_R14);
42 }
43
44 if( resultType.PtrLevel() ){
45 resultType.PtrLevelDown();
46
47 int typeSize = resultType.GetSize();
48 if(typeSize>=2){
49 //imul reg,i2
50 compiler.codeGenerator.op_imul_RV(sizeof(_int64),reg,typeSize);
51 }
52 }
53 else{
54 //エラー
55 compiler.errorMessenger.Output(1,NULL,cp);
56 return;
57 }
58
59
60 //////////////////////////////
61 // 先頭ポインタに添え字を加算
62 //////////////////////////////
63
64 //mov r11,qword ptr[rsp+offset] ※スタックフレームを利用
65 pobj_sf->pop(REG_R11);
66
67 //add r11,reg
68 compiler.codeGenerator.op_add_RR(REG_R11,reg);
69}
70void SetRelativeOffset( RELATIVE_VAR &relativeVar ){
71 if(relativeVar.dwKind==VAR_DIRECTMEM){
72 //mov r11,qword ptr[r11]
73 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_R11,0,MOD_BASE);
74 }
75 else{
76 //直接参照に切り替え
77 SetVarPtrToReg(REG_R12,&relativeVar);
78 relativeVar.dwKind=VAR_DIRECTMEM;
79
80 //mov r11,qword ptr[r12]
81 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_R12,0,MOD_BASE);
82 }
83}
84bool GetArrayOffset(const Subscripts &subscripts,char *array, const Type &type){
85 extern HANDLE hHeap;
86 int i,i2,i3,i4;
87 char temporary[VN_SIZE],*pParm[MAX_PARMS];
88
89 for(i=0,i2=0,i3=0;;i++,i2++){
90 if(array[i]=='('){
91 i4=GetStringInPare(temporary+i2,array+i);
92 i+=i4-1;
93 i2+=i4-1;
94 continue;
95 }
96 if(array[i]=='['){
97 i4=GetStringInBracket(temporary+i2,array+i);
98 i+=i4-1;
99 i2+=i4-1;
100 continue;
101 }
102 if(array[i]==','||array[i]=='\0'){
103 if( i3 >= (int)subscripts.size() )
104 {
105 for(i3--;i3>=0;i3--) HeapDefaultFree(pParm[i3]);
106 return false;
107 }
108
109 temporary[i2]=0;
110
111 pParm[i3]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);
112 lstrcpy(pParm[i3],temporary);
113
114 i3++;
115
116 if(array[i]=='\0'){
117 if( i3 < (int)subscripts.size() )
118 {
119 for(i3--;i3>=0;i3--) HeapDefaultFree(pParm[i3]);
120 return false;
121 }
122 break;
123 }
124
125 i2=-1;
126 continue;
127 }
128 temporary[i2]=array[i];
129 }
130
131 //mov qword ptr[rsp+offset],r11 ※スタックフレームを利用
132 pobj_sf->push(REG_R11);
133
134 //xor r12,r12
135 compiler.codeGenerator.op_zero_reg(REG_R12);
136
137 for(i=i3-1;i>=0;i--){
138 //mov qword ptr[rsp+offset],r12 ※スタックフレームを利用
139 pobj_sf->push(REG_R12);
140
141 int reg=REG_NON;
142 Type type;
143 bool isNeedHeapFreeStructure;
144 NumOpe( &reg, pParm[i], Type( DEF_LONG ), type, &isNeedHeapFreeStructure );
145 if( type.IsObject() )
146 {
147 //キャスト演算子のオーバーロードに対応する
148 CallCastOperatorProc(reg,
149 type,
150 isNeedHeapFreeStructure, Type(DEF_LONG) );
151 type.SetBasicType( DEF_LONG );
152 }
153
154 if( !type.IsWhole() )
155 {
156 compiler.errorMessenger.Output(46,NULL,cp);
157 }
158 ExtendTypeTo64( type.GetBasicType(), reg );
159
160 if(reg==REG_R14){
161 //mov r14,qword ptr[rsp+offset] ※スタックフレームを利用
162 pobj_sf->pop(REG_R14);
163 }
164
165 //mov r12,qword ptr[rsp+offset] ※スタックフレームを利用
166 pobj_sf->pop(REG_R12);
167
168 for(i2=i+1,i4=1;i2<i3;i2++) i4*=subscripts[i2]+1;
169
170 //imul reg,i4
171 compiler.codeGenerator.op_imul_RV(sizeof(_int64),reg,i4);
172
173 //add r12,reg
174 compiler.codeGenerator.op_add_RR(REG_R12,reg);
175
176 HeapDefaultFree(pParm[i]);
177 }
178
179 //imul r12,TypeSize
180 compiler.codeGenerator.op_imul_RV( sizeof(_int64), REG_R12, type.GetSize() );
181
182 //mov r11,qword ptr[rsp+offset] ※スタックフレームを利用
183 pobj_sf->pop(REG_R11);
184
185 //add r11,r12
186 compiler.codeGenerator.op_add_RR( REG_R11, REG_R12 );
187
188 return true;
189}
190bool _member_offset(bool isErrorEnabled, bool isWriteAccess, const Type &classType, const char *member, RELATIVE_VAR *pRelativeVar, Type &resultType, BOOL bPrivateAccess)
191{
192 const CClass &objClass = classType.GetClass();
193
194 //////////////////////////////////////
195 // クラス、配列の構成要素を解析する
196 //////////////////////////////////////
197
198 char VarName[VN_SIZE]; //変数名
199 char array[VN_SIZE]; //第1次配列
200 char lpPtrOffset[VN_SIZE]; //第2次配列
201 char NestMember[VN_SIZE]; //入れ子メンバ
202 ReferenceKind refType;
203 lstrcpy(VarName,member);
204 if(!GetVarFormatString(VarName,array,lpPtrOffset,NestMember,refType)) return false;
205
206
207 ////////////////////////////
208 // メンバオフセットを取得
209 ////////////////////////////
210
211 const Member *pMember = objClass.FindDynamicMember( VarName );
212 if( !pMember )
213 {
214 if(isErrorEnabled) compiler.errorMessenger.Output(103,VarName,cp);
215 return false;
216 }
217
218 int offset = objClass.GetMemberOffset( VarName );
219
220
221 //アクセシビリティをチェック
222 if( compiler.IsCompilingClass() && &objClass == &compiler.GetCompilingClass() ){
223 //同一クラスオブジェクトの場合はプライベートアクセスを容認する
224 if(pMember->IsNoneAccess()){
225 if(isErrorEnabled) compiler.errorMessenger.Output(107,VarName,cp);
226 return false;
227 }
228 }
229 else{
230 if((bPrivateAccess==0&&pMember->IsPrivate())||
231 pMember->IsNoneAccess()){
232 if(isErrorEnabled) compiler.errorMessenger.Output(107,VarName,cp);
233 return false;
234 }
235 else if(bPrivateAccess==0&&pMember->IsProtected()){
236 if(isErrorEnabled) compiler.errorMessenger.Output(108,VarName,cp);
237 return false;
238 }
239 }
240
241 //Const定義の場合は書き込みアクセスを制限する
242 //※コンストラクタをコンパイル中の場合は例外的に許可する
243 if( pMember->IsConst() && //定数メンバである
244 isWriteAccess && //書き込みアクセスを要求されている
245 objClass.IsCompilingConstructor() == false //コンストラクタ コンパイル中を除く
246 ){
247 //Const定義の変数に書き込みアクセスをしようとした場合
248 compiler.errorMessenger.Output(61,VarName,cp);
249 }
250
251 resultType = pMember->GetType();
252
253 // 型パラメータを解決
254 ResolveFormalGenericTypeParameter( resultType, classType );
255
256 //ポインタ変数の場合
257 if( resultType.IsPointer() ){
258 if( pMember->GetSubscripts().size() == 0 ){
259 lstrcpy(lpPtrOffset,array);
260 array[0]=0;
261 }
262 }
263 else{
264 if(lpPtrOffset[0]){
265 if(isErrorEnabled) compiler.errorMessenger.Output(16,member,cp);
266 return false;
267 }
268 }
269
270 if(offset){
271 //add r11,offset
272 compiler.codeGenerator.op_add_RV( REG_R11, offset );
273 }
274
275 if(array[0]){
276 //配列オフセット
277 if(!GetArrayOffset(pMember->GetSubscripts(),array,pMember->GetType())){
278 if(isErrorEnabled) compiler.errorMessenger.Output(14,member,cp);
279 return false;
280 }
281 }
282 else if( pMember->GetSubscripts().size() > 0 ){
283 resultType.SetBasicType( resultType.GetBasicType() | FLAG_PTR );
284 }
285
286 if(NestMember[0]){
287 //入れ子構造の場合
288
289 if( resultType.IsObject() || resultType.IsStruct() ){
290 if( refType != RefDot ){
291 if(isErrorEnabled) compiler.errorMessenger.Output(104,member,cp);
292 return false;
293 }
294
295 if( resultType.IsObject() ){
296 // 参照内容へのポインタを抽出
297 SetRelativeOffset( *pRelativeVar );
298 }
299 }
300 else if( resultType.IsObjectPtr() || resultType.IsStructPtr() ){
301 //構造体ポインタ型メンバ変数
302
303 if(lpPtrOffset[0]){
304 //pObj[n].member
305 if( ( resultType.IsObjectPtr() || resultType.IsStructPtr() )
306 && refType != RefDot ){
307 if(isErrorEnabled) compiler.errorMessenger.Output(104,member,cp);
308 return false;
309 }
310
311 //直接参照に切り替え
312 SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset);
313 pRelativeVar->dwKind=VAR_DIRECTMEM;
314
315 lpPtrOffset[0]=0;
316 }
317 else{
318 //pObj->member
319 if( (resultType.IsObjectPtr() || resultType.IsStructPtr() )
320 && refType != RefPointer ){
321 if(isErrorEnabled) compiler.errorMessenger.Output(104,member,cp);
322 return false;
323 }
324
325 SetRelativeOffset( *pRelativeVar );
326 }
327 }
328 else if( resultType.GetBasicType() == MAKE_PTR_TYPE(DEF_OBJECT,2)
329 || resultType.GetBasicType() == MAKE_PTR_TYPE(DEF_STRUCT,2)){
330 //構造体ポインタのポインタ型メンバ変数
331
332 if(lpPtrOffset[0]){
333 //ppObj[n]->member
334 if( refType != RefPointer ){
335 if(isErrorEnabled) compiler.errorMessenger.Output(104,member,cp);
336 return false;
337 }
338
339 //直接参照に切り替え
340 SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset);
341 pRelativeVar->dwKind=VAR_DIRECTMEM;
342
343 lpPtrOffset[0]=0;
344
345 //mov r11,qword ptr[r11]
346 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_R11,0,MOD_BASE);
347 }
348 else{
349 if(isErrorEnabled) compiler.errorMessenger.Output(104,member,cp);
350 return false;
351 }
352 }
353
354 if(!_member_offset(
355 isErrorEnabled,
356 isWriteAccess,
357 pMember->GetType(),
358 NestMember,
359 pRelativeVar,
360 resultType,
361 0)) return false;
362 }
363
364 if(lpPtrOffset[0]){
365 SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset);
366 pRelativeVar->dwKind=VAR_DIRECTMEM;
367 }
368
369 return true;
370}
371
372int LocalVar_ThisPtrOffset;
373void SetThisPtrToReg(int reg){
374 //自身のオブジェクトのThisポインタをregにコピー
375
376 RELATIVE_VAR RelativeVar;
377 RelativeVar.dwKind=VAR_LOCAL;
378 RelativeVar.bOffsetOffset=0;
379 RelativeVar.offset=-LocalVar_ThisPtrOffset;
380
381 SetReg_WholeVariable(Type(DEF_PTR_VOID),&RelativeVar,reg);
382}
383bool GetVarOffset(bool isErrorEnabled,bool isWriteAccess,const char *NameBuffer,RELATIVE_VAR *pRelativeVar,Type &resultType, Subscripts *pResultSubscripts ){
384 char variable[VN_SIZE];
385
386 if(NameBuffer[0]=='.'){
387 GetWithName(variable);
388 lstrcat(variable,NameBuffer);
389 }
390 else lstrcpy(variable,NameBuffer);
391
392 // 名前空間を分離
393 char namespaceStr[VN_SIZE]="", simpleName[VN_SIZE];
394 compiler.GetObjectModule().meta.GetNamespaces().SplitNamespace( variable, namespaceStr, simpleName );
395
396 // 先頭オブジェクトまたはクラス名と入れ子メンバに分割
397 ReferenceKind refType;
398 char member[VN_SIZE],array[VN_SIZE],lpPtrOffset[VN_SIZE];
399 GetVarFormatString(simpleName,array,lpPtrOffset,member,refType);
400
401 // 名前空間を分離していた場合は結合
402 char VarName[VN_SIZE];
403 if( namespaceStr[0] ){
404 sprintf( VarName, "%s.%s", namespaceStr, simpleName );
405 }
406 else{
407 lstrcpy( VarName, simpleName );
408 }
409
410 const Subscripts *pSubscripts;
411 bool bConst = false;
412
413
414 if( compiler.IsLocalAreaCompiling() ){
415 //////////////////
416 // ローカル変数
417 //////////////////
418
419 const Variable *pVar = compiler.GetCompilingUserProc().GetLocalVars().BackSearch(
420 LexicalAnalyzer::FullNameToSymbol( VarName ),
421 compiler.codeGenerator.lexicalScopes.GetNowLevel()
422 );
423 if( pVar ){
424 //ポインタ変数の場合
425 if( pVar->GetType().IsPointer() ){
426 if( !pVar->IsArray() ){
427 lstrcpy(lpPtrOffset,array);
428 array[0]=0;
429 }
430 }
431 else{
432 if(lpPtrOffset[0]){
433 compiler.errorMessenger.Output(16,variable,cp);
434 pRelativeVar->dwKind=NON_VAR;
435 return false;
436 }
437 }
438
439 pRelativeVar->offset=-pVar->GetOffsetAddress();
440 pRelativeVar->bOffsetOffset=0;
441 if( pVar->IsRef() ){
442 // 参照型
443 pRelativeVar->dwKind = VAR_REFLOCAL;
444 }
445 else pRelativeVar->dwKind=VAR_LOCAL;
446 resultType = pVar->GetType();
447 pSubscripts = &pVar->GetSubscripts();
448 bConst = pVar->IsConst();
449
450 /////////////////////////////////////////////////////////
451 // ☆★☆ ジェネリクスサポート ☆★☆
452
453 if( resultType.IsTypeParameter() )
454 {
455 // 型パラメータだったとき
456
457 int ptrLevel = PTR_LEVEL( resultType.GetBasicType() );
458
459 // 制約クラス(指定されていないときはObjectクラス)にセットする
460 resultType.SetBasicType( DEF_OBJECT );
461
462 for( int i=0; i<ptrLevel; i++ )
463 {
464 resultType.PtrLevelUp();
465 }
466 }
467
468 //
469 /////////////////////////////////////////////////////////
470
471 goto ok;
472 }
473 }
474
475 if( compiler.IsCompilingClass() ){
476 //////////////////////
477 // クラスメンバの参照
478 //////////////////////
479
480 if(lstrcmpi(variable,"This")==0){
481 //自身のオブジェクトのThisポインタをr11にコピー
482 SetThisPtrToReg(REG_R11);
483
484 pRelativeVar->dwKind=VAR_DIRECTMEM;
485
486 resultType.SetType( DEF_OBJECT, &compiler.GetCompilingClass() );
487 return true;
488 }
489
490 if(memicmp(variable,"This.",5)==0){
491 //Thisオブジェクトのメンバを参照するとき
492 SlideString(variable+5,-5);
493 lstrcpy(VarName,variable);
494 }
495 else{
496 //クラス内の動的メンバを参照するとき(通常)
497
498 if( !compiler.GetCompilingClass().HasDynamicMember( VarName ) )
499 {
500 goto NonClassMember;
501 }
502 }
503
504 //Const修飾子のメソッド内でメンバ書き込みアクセスが発生したとき
505 //(コンストラクタ、デストラクタ内を除く)
506 const CMethod *pMethod = &compiler.GetCompilingUserProc().GetMethod();
507 if( isWriteAccess &&
508 pMethod->IsConst() &&
509 compiler.GetCompilingClass().IsCompilingConstructor() == false &&
510 compiler.GetCompilingClass().IsCompilingDestructor() == false
511 ){
512 compiler.errorMessenger.Output(131, NULL, cp );
513 }
514
515 //自身のオブジェクトのThisポインタをr11にコピー
516 SetThisPtrToReg(REG_R11);
517
518 pRelativeVar->dwKind=VAR_DIRECTMEM;
519 if(!_member_offset(
520 isErrorEnabled,
521 isWriteAccess,
522 Type( DEF_OBJECT, compiler.GetCompilingClass() ),
523 variable,
524 pRelativeVar,
525 resultType,1)) return false;
526 return true;
527 }
528
529NonClassMember:
530
531 {
532 const Variable *pVar;
533
534 //////////////////////////
535 // 静的ローカル変数
536 // ※"Static.Object.Method.Variable"
537 //////////////////////////
538
539 char temporary[VN_SIZE];
540 if( compiler.IsLocalAreaCompiling() ){
541 GetNowStaticVarFullName(VarName,temporary);
542
543 pVar = compiler.GetObjectModule().meta.GetGlobalVars().Find( LexicalAnalyzer::FullNameToSymbol( temporary ) );
544 if( pVar ){
545 goto GlobalOk;
546 }
547 }
548
549
550 //////////////////////////
551 // クラスの静的メンバ
552 //////////////////////////
553
554 if(member[0]){
555 lstrcpy(temporary,member);
556
557 // TODO: 名前空間を考慮したコードになっていない
558
559 char tempMember[VN_SIZE];
560 char tempArray[VN_SIZE];
561 {
562 ReferenceKind refType;
563 GetVarFormatString(temporary,tempArray,lpPtrOffset,tempMember, refType );
564 }
565
566 int typeDefIndex = compiler.GetObjectModule().meta.GetTypeDefs().GetIndex(
567 LexicalAnalyzer::FullNameToSymbol( VarName )
568 );
569 if( typeDefIndex != -1 ){
570 // TypeDef後の型名だったとき
571 lstrcpy( VarName, compiler.GetObjectModule().meta.GetTypeDefs()[typeDefIndex].GetBaseName().c_str() );
572 }
573
574 char temp2[VN_SIZE];
575 sprintf(temp2,"%s.%s",VarName,temporary);
576 pVar = compiler.GetObjectModule().meta.GetGlobalVars().Find( LexicalAnalyzer::FullNameToSymbol( temp2 ) );
577 if( pVar ){
578 lstrcpy(member,tempMember);
579 lstrcpy(array,tempArray);
580 goto GlobalOk;
581 }
582 }
583
584 if( compiler.IsCompilingClass() ){
585 //自身のクラスから静的メンバを参照する場合
586 char temp2[VN_SIZE];
587 sprintf(temp2,"%s.%s",compiler.GetCompilingClass().GetName().c_str(),VarName);
588 pVar = compiler.GetObjectModule().meta.GetGlobalVars().Find( LexicalAnalyzer::FullNameToSymbol( temp2 ) );
589 if( pVar ){
590 goto GlobalOk;
591 }
592 }
593
594 /////////////////////
595 // グローバル変数
596 /////////////////////
597
598 pVar = compiler.GetObjectModule().meta.GetGlobalVars().BackSearch(
599 LexicalAnalyzer::FullNameToSymbol( VarName ),
600 compiler.codeGenerator.lexicalScopes.GetNowLevel()
601 );
602 if( pVar ){
603 goto GlobalOk;
604 }
605
606 if(isErrorEnabled) compiler.errorMessenger.Output(3,variable,cp);
607 pRelativeVar->dwKind=NON_VAR;
608 return false;
609
610
611
612GlobalOk:
613 //ポインタ変数の場合
614 if( pVar->GetType().IsPointer() ){
615 if( !pVar->IsArray() ){
616 lstrcpy(lpPtrOffset,array);
617 array[0]=0;
618 }
619 }
620 else{
621 if(lpPtrOffset[0]){
622 compiler.errorMessenger.Output(16,variable,cp);
623 pRelativeVar->dwKind=NON_VAR;
624 return false;
625 }
626 }
627
628 pRelativeVar->offset=pVar->GetOffsetAddress();
629 pRelativeVar->bOffsetOffset=0;
630 if( pVar->IsRef() ){
631 // 参照型
632 pRelativeVar->dwKind = VAR_REFGLOBAL;
633 }
634 else pRelativeVar->dwKind=VAR_GLOBAL;
635 resultType = pVar->GetType();
636 pSubscripts=&pVar->GetSubscripts();
637 bConst = pVar->IsConst();
638 }
639
640
641
642ok:
643
644 if( bConst && isWriteAccess ){
645 //Const定義の変数に書き込みアクセスをしようとした場合
646 if( resultType.IsObject() ){
647 //オブジェクト定数
648 compiler.errorMessenger.Output(130, VarName, cp );
649 }
650 else{
651 //一般のConst変数
652 compiler.errorMessenger.Output(61,VarName,cp);
653 }
654 }
655
656 if( array[0] == 0 && pSubscripts->size() > 0 ){
657 //配列の先頭ポインタを示す場合
658 resultType.SetBasicType( resultType.GetBasicType() | FLAG_PTR );
659
660 if( pResultSubscripts )
661 {
662 (*pResultSubscripts) = *pSubscripts;
663 }
664 return true;
665 }
666
667 if( array[0] || member[0] ){
668 //xor r11,r11(r11を0に初期化する)
669 //※r11は変数ベースアドレスからの相対オフセットを示す
670 compiler.codeGenerator.op_zero_reg(REG_R11);
671
672 pRelativeVar->bOffsetOffset=1;
673 }
674 if(array[0]){
675 if(!GetArrayOffset(*pSubscripts,array,resultType)){
676 compiler.errorMessenger.Output(14,variable,cp);
677 pRelativeVar->dwKind=NON_VAR;
678 return false;
679 }
680 }
681 if(member[0]){
682 if( resultType.IsObject() || resultType.IsStruct() ){
683 //実態オブジェクトのメンバを参照(obj.member)
684 if( refType != RefDot ){
685 compiler.errorMessenger.Output(104,VarName,cp);
686 pRelativeVar->dwKind=NON_VAR;
687 return false;
688 }
689
690 if( resultType.IsObject() ){
691 // 参照内容へのポインタを抽出
692 SetRelativeOffset( *pRelativeVar );
693 }
694 }
695 else if( resultType.IsObjectPtr() || resultType.IsStructPtr() ){
696 //ポインタオブジェクトが示すメンバを参照
697 if(lpPtrOffset[0]){
698 //pObj[n].member
699 if( refType != RefDot ){
700 compiler.errorMessenger.Output(104,VarName,cp);
701 pRelativeVar->dwKind=NON_VAR;
702 return false;
703 }
704 SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset);
705 pRelativeVar->dwKind=VAR_DIRECTMEM;
706 }
707 else{
708 //pObj->member
709 if( refType != RefPointer ){
710 compiler.errorMessenger.Output(104,VarName,cp);
711 pRelativeVar->dwKind=NON_VAR;
712 return false;
713 }
714
715 SetVarPtrToReg(REG_R12,pRelativeVar);
716 pRelativeVar->dwKind=VAR_DIRECTMEM;
717
718 //mov r11,qword ptr[r12]
719 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_R12,0,MOD_BASE);
720 }
721 }
722 else if( resultType.GetBasicType()==MAKE_PTR_TYPE(DEF_OBJECT,2) || resultType.GetBasicType()==MAKE_PTR_TYPE(DEF_STRUCT,2)){
723 //ポインタオブジェクトが示すメンバを参照
724 if(lpPtrOffset[0]){
725 //ppObj[n]->member
726 if( refType != RefPointer ){
727 compiler.errorMessenger.Output(104,VarName,cp);
728 pRelativeVar->dwKind=NON_VAR;
729 return false;
730 }
731
732 SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset);
733 pRelativeVar->dwKind=VAR_DIRECTMEM;
734
735
736 SetVarPtrToReg(REG_R12,pRelativeVar);
737
738 //mov r11,qword ptr[r12]
739 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_R12,0,MOD_BASE);
740 }
741 else{
742 compiler.errorMessenger.Output(104,VarName,cp);
743 pRelativeVar->dwKind=NON_VAR;
744 return false;
745 }
746 }
747 else{
748 compiler.errorMessenger.Output(102,VarName,cp);
749 pRelativeVar->dwKind=NON_VAR;
750 return false;
751 }
752
753 if(!_member_offset(
754 isErrorEnabled,
755 isWriteAccess,
756 resultType,
757 member,pRelativeVar,resultType,0)) return false;
758
759 return true;
760 }
761
762 if(lpPtrOffset[0]){
763 SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset);
764 pRelativeVar->dwKind=VAR_DIRECTMEM;
765 }
766
767 return true;
768}
769
770bool SetInitGlobalData(int offset,const Type &type,const Subscripts &subscripts,const char *lpszInitBuf){
771 int i2,i3;
772 char temporary[VN_SIZE];
773 char InitBuf[VN_SIZE];
774 lstrcpy( InitBuf, lpszInitBuf );
775
776 if(InitBuf[0]=='['){
777 SlideString(InitBuf+1,-1);
778 InitBuf[lstrlen(InitBuf)-1]=0;
779
780 int typeSize = type.GetSize();
781
782 if( subscripts.size() > 0 ){
783 Subscripts nestSubscripts;
784 for( int i=1; i<(int)subscripts.size(); i++ )
785 {
786 nestSubscripts.push_back( subscripts[i] );
787 }
788
789 typeSize*=JumpSubScripts( nestSubscripts );
790 {
791 int i=0;
792 i2=0;
793 while(1){
794 if( subscripts[0] < i2 ){
795 compiler.errorMessenger.Output(41,0,cp);
796 return 0;
797 }
798 i=GetOneParameter(InitBuf,i,temporary);
799 if(!SetInitGlobalData(
800 offset+i2*typeSize,
801 type,
802 nestSubscripts,
803 temporary)) return false;
804 i2++;
805 if(InitBuf[i]=='\0') break;
806 }
807 }
808 return true;
809 }
810
811 if(type.IsStruct()){
812 const CClass &objClass = type.GetClass();
813
814 int i = 0;
815 BOOST_FOREACH( Member *pMember, objClass.GetDynamicMembers() ){
816 if(InitBuf[i]=='\0'){
817 compiler.errorMessenger.Output(41,0,cp);
818 return false;
819 }
820
821 i=GetOneParameter(InitBuf,i,temporary);
822
823 i3=objClass.GetMemberOffset( pMember->GetName().c_str() );
824
825 if(!SetInitGlobalData(offset+i3,
826 pMember->GetType(),
827 pMember->GetSubscripts(),
828 temporary)) return false;
829 }
830 return true;
831 }
832
833 compiler.errorMessenger.Output(41,0,cp);
834 return false;
835 }
836
837
838 ///////////////////////////////////////
839 // 単発式([]で囲まれていない)
840 ///////////////////////////////////////
841
842 if( subscripts.size() > 0 ){
843 compiler.errorMessenger.Output(41,0,cp);
844 return false;
845 }
846
847 double dbl;
848 _int64 i64data;
849 Type calcType;
850
851 if( !StaticCalculation(false, InitBuf,type.GetBasicType(),&i64data,calcType) ){
852 //動的データだった場合
853 return false;
854 }
855 if( calcType.IsReal() ){
856 memcpy(&dbl,&i64data,sizeof(double));
857 i64data=(_int64)dbl;
858 }
859 else dbl=(double)i64data;
860
861 //型チェック
862 CheckDifferentType(
863 type,
864 calcType,
865 0,0);
866
867 if( type.IsDouble() ){
868 compiler.GetObjectModule().meta.GetGlobalVars().initAreaBuffer.Overwrite(
869 offset,
870 (const char *)&dbl,
871 sizeof(double)
872 );
873 }
874 else if( type.IsSingle() ){
875 float flt = (float)dbl;
876 compiler.GetObjectModule().meta.GetGlobalVars().initAreaBuffer.Overwrite(
877 offset,
878 (const char *)&flt,
879 sizeof(float)
880 );
881 }
882 else if( type.Is64() || type.IsPointer() ){
883 if( type.GetBasicType() == typeOfPtrChar && type.GetIndex() == LITERAL_STRING ){
884 //文字列定数のとき
885
886 char *temp;
887 temp=(char *)i64data;
888 if( compiler.IsUnicode() )
889 {
890 i2 = compiler.GetObjectModule().dataTable.AddWString( Jenga::Common::ToWString( temp ) );
891 }
892 else
893 {
894 i2 = compiler.GetObjectModule().dataTable.AddString( temp );
895 }
896 HeapDefaultFree(temp);
897
898 //mov rax,DataPos
899 compiler.codeGenerator.op_mov_RV(sizeof(_int64),REG_RAX,i2, Schedule::DataTable );
900
901 //mov qword ptr[offset],rax
902 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_RAX,0,offset,MOD_DISP32, Schedule::GlobalVar );
903 }
904 else{
905 compiler.GetObjectModule().meta.GetGlobalVars().initAreaBuffer.Overwrite(
906 offset,
907 (const char *)&i64data,
908 sizeof(_int64)
909 );
910 }
911 }
912 else if( type.IsDWord() || type.IsLong() ){
913 long l = (long)i64data;
914 compiler.GetObjectModule().meta.GetGlobalVars().initAreaBuffer.Overwrite(
915 offset,
916 (const char *)&l,
917 sizeof(long)
918 );
919 }
920 else if( type.IsWord() || type.IsInteger() ){
921 short s = (short)i64data;
922 compiler.GetObjectModule().meta.GetGlobalVars().initAreaBuffer.Overwrite(
923 offset,
924 (const char *)&s,
925 sizeof(short)
926 );
927 }
928 else if( type.IsSByte() || type.IsByte() || type.IsBoolean() ){
929 char c = (char)i64data;
930 compiler.GetObjectModule().meta.GetGlobalVars().initAreaBuffer.Overwrite(
931 offset,
932 (const char *)&c,
933 sizeof(char)
934 );
935 }
936
937 return true;
938}
939bool InitLocalVar(int offset,const Type &type,const Subscripts &subscripts,const char *lpszInitBuf){
940 int i2,i3;
941 char temporary[VN_SIZE];
942 char InitBuf[VN_SIZE];
943 lstrcpy( InitBuf, lpszInitBuf );
944
945 if(InitBuf[0]=='['){
946 SlideString(InitBuf+1,-1);
947 InitBuf[lstrlen(InitBuf)-1]=0;
948
949 int typeSize = type.GetSize();
950
951 if( subscripts.size() > 0 ){
952 Subscripts nestSubscripts;
953 for( int i=1; i<(int)subscripts.size(); i++ )
954 {
955 nestSubscripts.push_back( subscripts[i] );
956 }
957
958 typeSize*=JumpSubScripts( nestSubscripts );
959 {
960 int i=0;
961 i2=0;
962 while(1){
963 if( subscripts[0] < i2 ){
964 compiler.errorMessenger.Output(41,0,cp);
965 return 0;
966 }
967 i=GetOneParameter(InitBuf,i,temporary);
968 if(!InitLocalVar(
969 offset+i2*typeSize,
970 type,
971 nestSubscripts,
972 temporary)) return false;
973 i2++;
974 if(InitBuf[i]=='\0') break;
975 }
976 }
977 return true;
978 }
979
980 if(type.IsStruct()){
981 const CClass &objClass = type.GetClass();
982
983 int i = 0;
984 BOOST_FOREACH( Member *pMember, objClass.GetDynamicMembers() ){
985 if(InitBuf[i]=='\0'){
986 compiler.errorMessenger.Output(41,0,cp);
987 return false;
988 }
989
990 i=GetOneParameter(InitBuf,i,temporary);
991
992 i3=objClass.GetMemberOffset( pMember->GetName().c_str() );
993
994 if(!InitLocalVar(offset+i3,
995 pMember->GetType(),
996 pMember->GetSubscripts(),
997 temporary)) return false;
998
999 if(InitBuf[i]=='\0') break;
1000 }
1001 return true;
1002 }
1003
1004 compiler.errorMessenger.Output(41,0,cp);
1005 return false;
1006 }
1007
1008
1009 ///////////////////////////////////////
1010 // 単発式([]で囲まれていない)
1011 ///////////////////////////////////////
1012
1013 if( subscripts.size() > 0 ){
1014 compiler.errorMessenger.Output(41,0,cp);
1015 return false;
1016 }
1017
1018 double dbl;
1019 _int64 i64data;
1020 Type calcType;
1021
1022 if( !StaticCalculation(false, InitBuf,type.GetBasicType(),&i64data,calcType) ){
1023 //動的データだった場合
1024 return false;
1025 }
1026 if( calcType.IsReal() ){
1027 memcpy(&dbl,&i64data,sizeof(double));
1028 i64data=(_int64)dbl;
1029 }
1030 else dbl=(double)i64data;
1031
1032 //型チェック
1033 CheckDifferentType(
1034 type,
1035 calcType,
1036 0,0);
1037
1038 if( type.IsDouble() ){
1039 memcpy(&i64data,&dbl,sizeof(double));
1040
1041 //mov rax,i64data
1042 compiler.codeGenerator.op_mov_RV64(REG_RAX,i64data);
1043
1044 //mov qword ptr[rsp+offset],rax
1045 compiler.codeGenerator.localVarPertialSchedules.push_back(
1046 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_RAX,REG_RSP,offset,MOD_BASE_DISP32, Schedule::None, true )
1047 );
1048 }
1049 else if( type.IsSingle() ){
1050 float flt;
1051 flt=(float)dbl;
1052
1053 //mov dword ptr[rsp+offset],value
1054 compiler.codeGenerator.localVarPertialSchedules.push_back(
1055 compiler.codeGenerator.op_mov_MV(sizeof(long),REG_RSP,offset, Schedule::None, true, USE_OFFSET,*(int *)&flt)
1056 );
1057 }
1058 else if( type.Is64() || type.IsPointer() ){
1059 if( type.GetBasicType() == typeOfPtrChar && type.GetIndex() == LITERAL_STRING ){
1060 //文字列定数のとき
1061
1062 char *temp;
1063 temp=(char *)i64data;
1064 if( compiler.IsUnicode() )
1065 {
1066 i2 = compiler.GetObjectModule().dataTable.AddWString( Jenga::Common::ToWString( temp ) );
1067 }
1068 else
1069 {
1070 i2 = compiler.GetObjectModule().dataTable.AddString( temp );
1071 }
1072 HeapDefaultFree(temp);
1073
1074 //mov rax,i2
1075 compiler.codeGenerator.op_mov_RV(sizeof(_int64),REG_RAX,i2, Schedule::DataTable );
1076
1077 //mov qword ptr[rsp+offset],rax
1078 compiler.codeGenerator.localVarPertialSchedules.push_back(
1079 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_RAX,REG_RSP,offset,MOD_BASE_DISP32, Schedule::None, true )
1080 );
1081 }
1082 else{
1083 if(i64data&0xFFFFFFFF00000000){
1084 //mov rax,i64data
1085 compiler.codeGenerator.op_mov_RV64(REG_RAX,i64data);
1086
1087 //mov qword ptr[rsp+offset],rax
1088 compiler.codeGenerator.localVarPertialSchedules.push_back(
1089 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_RAX,REG_RSP,offset,MOD_BASE_DISP32, Schedule::None, true )
1090 );
1091 }
1092 else{
1093 //mov qword ptr[rsp+offset],value
1094 compiler.codeGenerator.localVarPertialSchedules.push_back(
1095 compiler.codeGenerator.op_mov_MV(sizeof(_int64),REG_RSP,offset, Schedule::None, true, USE_OFFSET,(int)i64data)
1096 );
1097 }
1098 }
1099 }
1100 else if( type.IsDWord() || type.IsLong() ){
1101 //mov dword ptr[rsp+offset],value
1102 compiler.codeGenerator.localVarPertialSchedules.push_back(
1103 compiler.codeGenerator.op_mov_MV(sizeof(long),REG_RSP,offset, Schedule::None, true, USE_OFFSET,(int)i64data)
1104 );
1105 }
1106 else if( type.IsWord() || type.IsInteger() ){
1107 //mov word ptr[rsp+offset],value
1108 compiler.codeGenerator.localVarPertialSchedules.push_back(
1109 compiler.codeGenerator.op_mov_MV(sizeof(short),REG_RSP,offset, Schedule::None, true, USE_OFFSET,(int)i64data)
1110 );
1111 }
1112 else if( type.IsSByte() || type.IsByte() || type.IsBoolean() ){
1113 //mov byte ptr[rsp+offset],value
1114 compiler.codeGenerator.localVarPertialSchedules.push_back(
1115 compiler.codeGenerator.op_mov_MV(sizeof(char),REG_RSP,offset, Schedule::None, true, USE_OFFSET,(int)i64data)
1116 );
1117 }
1118 return true;
1119}
1120
1121void dim( char *VarName, const Subscripts &subscripts, const Type &type,const char *InitBuf,const char *ConstractParameter,DWORD dwFlags)
1122{
1123 if( compiler.IsGlobalAreaCompiling() ){
1124 /////////////////////////
1125 // グローバル変数
1126 /////////////////////////
1127
1128 AddGlobalVariable(VarName,subscripts,type,InitBuf,ConstractParameter,dwFlags);
1129 }
1130 else{
1131 /////////////////
1132 // ローカル変数
1133 /////////////////
1134
1135 if( compiler.GetCompilingUserProc().GetLocalVars().DuplicateCheck( LexicalAnalyzer::FullNameToSymbol( VarName ), compiler.codeGenerator.lexicalScopes.GetNowLevel() ) ){
1136 //2重定義のエラー
1137 compiler.errorMessenger.Output(15,VarName,cp);
1138 return;
1139 }
1140
1141 bool isConst = ( dwFlags & DIMFLAG_CONST ) ? true:false;
1142
1143 Variable *pVar = new Variable(
1144 ActiveBasic::Compiler::LexicalAnalyzer::FullNameToSymbol( VarName ),
1145 type,
1146 isConst,
1147 false,
1148 ConstractParameter,
1149 false
1150 );
1151
1152 if( subscripts.size() > 0 ){
1153 //配列あり
1154 pVar->SetArray( subscripts );
1155 }
1156
1157 //レキシカルスコープ
1158 pVar->SetScopeLevel( compiler.codeGenerator.lexicalScopes.GetNowLevel() );
1159 pVar->SetScopeStartAddress( compiler.codeGenerator.lexicalScopes.GetStartAddress() );
1160 pVar->isLiving = true;
1161
1162 //エラー用
1163 pVar->source_code_address=cp;
1164
1165 // 変数を追加
1166 compiler.GetCompilingUserProc().GetLocalVars().push_back( pVar );
1167
1168 //アラインメントを考慮
1169 if( pVar->GetType().IsStruct() ){
1170 int alignment = pVar->GetType().GetClass().GetFixedAlignment();
1171
1172 if( alignment ){
1173 if( AllLocalVarSize % alignment ){
1174 AllLocalVarSize += alignment - (AllLocalVarSize % alignment);
1175 }
1176 }
1177
1178 if( alignment == PTR_SIZE*2 ){
1179 // ポインタに要するサイズよりも一回り大きなアラインメントが指定されているとき
1180 // (例:CONTEXT構造体など)
1181 // 呼び出し側のオフセットズレを考慮する
1182
1183 if( 0 == ( compiler.GetCompilingUserProc().RealParams().GetMemorySize() + PTR_SIZE /* ret分 */ ) % alignment ){
1184 AllLocalVarSize += PTR_SIZE;
1185 }
1186 }
1187 }
1188
1189 AllLocalVarSize += pVar->GetMemorySize();
1190 pVar->SetOffsetAddress( AllLocalVarSize );
1191
1192 //レキシカルスコープ
1193 pVar->SetScopeLevel( compiler.codeGenerator.lexicalScopes.GetNowLevel() );
1194 pVar->SetScopeStartAddress( compiler.codeGenerator.lexicalScopes.GetStartAddress() );
1195 pVar->isLiving = true;
1196
1197 if(InitBuf[0]){
1198 //初期代入時のみ、書き込みアクセスを許可する
1199 if( isConst ){
1200 pVar->ConstOff();
1201 }
1202
1203 int result = 0;
1204 if( !pVar->GetType().IsObject() ){
1205 result = InitLocalVar(-pVar->GetOffsetAddress(),
1206 pVar->GetType(),
1207 pVar->GetSubscripts(),
1208 InitBuf);
1209 }
1210
1211 if(!result){
1212 //動的な式だった場合は代入演算を行う
1213 char temporary[8192];
1214 sprintf(temporary,"%s=%s",VarName,InitBuf);
1215 OpcodeCalc(temporary);
1216 }
1217
1218 if( isConst ){
1219 pVar->ConstOn();
1220 }
1221 }
1222 else{
1223 //0初期化
1224
1225 //mov r8, 0
1226 compiler.codeGenerator.op_zero_reg( REG_R8 );
1227
1228 //mov rdx, VarSize
1229 compiler.codeGenerator.op_mov_RV( sizeof(_int64), REG_RDX, pVar->GetMemorySize() );
1230
1231 //mov rcx, rsp
1232 compiler.codeGenerator.op_mov_RR( REG_RCX, REG_RSP );
1233
1234 //add rcx, offset
1235 compiler.codeGenerator.localVarPertialSchedules.push_back(
1236 compiler.codeGenerator.op_add_RV( REG_RCX, -pVar->GetOffsetAddress(), Schedule::None, true )
1237 );
1238
1239 //call FillMemory
1240 DllProc *pDllProc;
1241 pDllProc=GetDeclareHash("FillMemory");
1242 compiler.codeGenerator.op_call( pDllProc );
1243 }
1244 }
1245
1246 //New呼び出し
1247 if( type.IsObject()
1248 && !type.IsInterface() && !type.IsComInterface()
1249 &&(dwFlags&DIMFLAG_NONCALL_CONSTRACTOR)==0
1250 &&InitBuf[0]=='\0')
1251 {
1252 char objectSize[255];
1253 if( subscripts.size() == 0 ){
1254 objectSize[0] = 0;
1255 }
1256 else{
1257 if( subscripts.size() > 1 ){
1258 compiler.errorMessenger.Output(300,NULL,cp);
1259 }
1260 sprintf( objectSize, "%d", subscripts[0] );
1261 }
1262 Operator_New( type.GetClass(), objectSize, ConstractParameter, type );
1263
1264 Type tempType;
1265 RELATIVE_VAR RelativeVar;
1266 GetVarOffset( true, false, VarName, &RelativeVar, tempType );
1267 if( RelativeVar.dwKind == VAR_DIRECTMEM ){
1268 compiler.errorMessenger.OutputFatalError();
1269 }
1270 SetVariableFromRax( Type( DEF_OBJECT, *compiler.GetObjectModule().meta.GetClasses().GetObjectClassPtr() ), DEF_OBJECT, &RelativeVar );
1271 }
1272}
1273void SetVarPtrToReg(int reg,RELATIVE_VAR *pRelativeVar){
1274 if(!IsGeneralReg(reg)) compiler.errorMessenger.Output(300,NULL,cp);
1275
1276 if(pRelativeVar->dwKind==VAR_GLOBAL){
1277 if(pRelativeVar->bOffsetOffset){
1278 //add r11,offset
1279 compiler.codeGenerator.op_add_RV( REG_R11, (long)pRelativeVar->offset, Schedule::GlobalVar );
1280
1281 //mov reg,r11
1282 compiler.codeGenerator.op_mov_RR(reg,REG_R11);
1283 }
1284 else{
1285 //mov reg,offset
1286 compiler.codeGenerator.op_mov_RV( sizeof(_int64), reg, (long)pRelativeVar->offset, Schedule::GlobalVar );
1287 }
1288 }
1289 else if( pRelativeVar->dwKind == VAR_REFGLOBAL ){
1290 if(pRelativeVar->bOffsetOffset){
1291 //add r11,qword ptr[offset]
1292 compiler.codeGenerator.op_add_RM( sizeof(_int64), REG_R11, REG_NON, (int)pRelativeVar->offset, MOD_DISP32, Schedule::GlobalVar );
1293 }
1294 else{
1295 //mov r11,qword ptr[offset]
1296 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_NON,(int)pRelativeVar->offset,MOD_DISP32, Schedule::GlobalVar );
1297 }
1298
1299 goto directmem;
1300 }
1301 else if(pRelativeVar->dwKind==VAR_LOCAL){
1302 if(pRelativeVar->bOffsetOffset){
1303 //add r11,offset
1304 compiler.codeGenerator.localVarPertialSchedules.push_back(
1305 compiler.codeGenerator.op_add_RV( REG_R11, (long)pRelativeVar->offset, Schedule::None, true )
1306 );
1307
1308 //add r11,rsp
1309 compiler.codeGenerator.op_add_RR(REG_R11,REG_RSP);
1310
1311 //mov reg,r11
1312 compiler.codeGenerator.op_mov_RR(reg,REG_R11);
1313 }
1314 else{
1315 //mov reg,rsp
1316 compiler.codeGenerator.op_mov_RR(reg,REG_RSP);
1317
1318 //add reg,offset
1319 compiler.codeGenerator.localVarPertialSchedules.push_back(
1320 compiler.codeGenerator.op_add_RV(reg,(long)pRelativeVar->offset, Schedule::None, true )
1321 );
1322 }
1323 }
1324 else if( pRelativeVar->dwKind == VAR_REFLOCAL ){
1325 if(pRelativeVar->bOffsetOffset){
1326 //add r11,qword ptr[rsp+offset]
1327 compiler.codeGenerator.localVarPertialSchedules.push_back(
1328 compiler.codeGenerator.op_add_RM( sizeof(_int64), REG_R11, REG_RSP, (long)pRelativeVar->offset, MOD_BASE_DISP32, Schedule::None, true )
1329 );
1330 }
1331 else{
1332 //mov r11,qword ptr[rsp+offset]
1333 compiler.codeGenerator.localVarPertialSchedules.push_back(
1334 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32, Schedule::None, true )
1335 );
1336 }
1337
1338 goto directmem;
1339 }
1340 else if(pRelativeVar->dwKind==VAR_DIRECTMEM){
1341directmem:
1342 //mov reg,r11
1343 compiler.codeGenerator.op_mov_RR(reg,REG_R11);
1344 }
1345}
1346
1347bool Compile_AddGlobalRootsForGc(){
1348 const UserProc *pUserProc_AddGlobalRootPtr = GetClassMethod( "_System_CGarbageCollection", "AddGlobalRootPtr" );
1349 if( !pUserProc_AddGlobalRootPtr ){
1350 compiler.errorMessenger.Output(3, "_System_CGarbageCollection.AddGlobalRootPtr", -1 );
1351 return false;
1352 }
1353
1354 BOOST_FOREACH( const Variable *pVar, compiler.GetObjectModule().meta.GetGlobalVars() ){
1355 if( pVar->GetType().IsObject() || pVar->GetType().IsPointer() || pVar->GetType().IsStruct() ){
1356 // オブジェクトまたはポインタだったとき
1357 // ※構造体も含む(暫定対応)
1358
1359 // 変数領域に要するLONG_PTR単位の個数を引き渡す
1360 //mov r8,count
1361 compiler.codeGenerator.op_mov_RV(sizeof(_int64), REG_R8,pVar->GetMemorySize()/PTR_SIZE);
1362
1363 // ルートポインタを引き渡す
1364 //mov rdx,offset
1365 compiler.codeGenerator.op_mov_RV(sizeof(_int64), REG_RDX,(int)pVar->GetOffsetAddress(), Schedule::GlobalVar );
1366
1367 // Thisポインタを引き渡す
1368 SetThisPtrToReg(REG_RCX);
1369
1370 // call AddGlobalRootPtr
1371 compiler.codeGenerator.op_call( pUserProc_AddGlobalRootPtr );
1372 }
1373 }
1374
1375 return true;
1376}
Note: See TracBrowser for help on using the repository browser.