source: dev/trunk/abdev/BasicCompiler64/Compile_Var.cpp@ 254

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