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

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

64ビットコンパイラもデリゲートに対応させた

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