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

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

ObjectModuleに関連するクラス一式をab_commonプロジェクトに移動した。

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