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

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

[632]を64bit版にマージ。

File size: 36.0 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
[633]561 const TypeDef *pTypeDef = compiler.GetObjectModule().meta.GetTypeDefs().Find(
[598]562 LexicalAnalyzer::FullNameToSymbol( VarName )
563 );
[633]564 if( pTypeDef )
565 {
[116]566 // TypeDef後の型名だったとき
[633]567 lstrcpy( VarName, pTypeDef->GetBaseName().c_str() );
[116]568 }
569
[75]570 char temp2[VN_SIZE];
571 sprintf(temp2,"%s.%s",VarName,temporary);
[514]572 pVar = compiler.GetObjectModule().meta.GetGlobalVars().Find( LexicalAnalyzer::FullNameToSymbol( temp2 ) );
[75]573 if( pVar ){
574 lstrcpy(member,tempMember);
575 lstrcpy(array,tempArray);
576 goto GlobalOk;
577 }
[3]578 }
579
[584]580 if( compiler.IsCompilingClass() ){
[75]581 //自身のクラスから静的メンバを参照する場合
582 char temp2[VN_SIZE];
[584]583 sprintf(temp2,"%s.%s",compiler.GetCompilingClass().GetName().c_str(),VarName);
[514]584 pVar = compiler.GetObjectModule().meta.GetGlobalVars().Find( LexicalAnalyzer::FullNameToSymbol( temp2 ) );
[75]585 if( pVar ){
586 goto GlobalOk;
587 }
[3]588 }
589
[75]590 /////////////////////
591 // グローバル変数
592 /////////////////////
[3]593
[584]594 pVar = compiler.GetObjectModule().meta.GetGlobalVars().BackSearch(
595 LexicalAnalyzer::FullNameToSymbol( VarName ),
596 compiler.codeGenerator.lexicalScopes.GetNowLevel()
597 );
[75]598 if( pVar ){
[3]599 goto GlobalOk;
600 }
601
[468]602 if(isErrorEnabled) compiler.errorMessenger.Output(3,variable,cp);
[75]603 pRelativeVar->dwKind=NON_VAR;
604 return false;
[27]605
606
[3]607
608GlobalOk:
[75]609 //ポインタ変数の場合
[206]610 if( pVar->GetType().IsPointer() ){
[75]611 if( !pVar->IsArray() ){
612 lstrcpy(lpPtrOffset,array);
613 array[0]=0;
614 }
[3]615 }
[75]616 else{
617 if(lpPtrOffset[0]){
[468]618 compiler.errorMessenger.Output(16,variable,cp);
[75]619 pRelativeVar->dwKind=NON_VAR;
620 return false;
621 }
[3]622 }
623
[206]624 pRelativeVar->offset=pVar->GetOffsetAddress();
[75]625 pRelativeVar->bOffsetOffset=0;
626 if( pVar->IsRef() ){
627 // 参照型
628 pRelativeVar->dwKind = VAR_REFGLOBAL;
629 }
630 else pRelativeVar->dwKind=VAR_GLOBAL;
[206]631 resultType = pVar->GetType();
632 pSubscripts=&pVar->GetSubscripts();
[75]633 bConst = pVar->IsConst();
[62]634 }
[3]635
636
637
638ok:
639
[18]640 if( bConst && isWriteAccess ){
[11]641 //Const定義の変数に書き込みアクセスをしようとした場合
[75]642 if( resultType.IsObject() ){
[18]643 //オブジェクト定数
[468]644 compiler.errorMessenger.Output(130, VarName, cp );
[18]645 }
646 else{
647 //一般のConst変数
[468]648 compiler.errorMessenger.Output(61,VarName,cp);
[18]649 }
[11]650 }
[3]651
[206]652 if( array[0] == 0 && pSubscripts->size() > 0 ){
[3]653 //配列の先頭ポインタを示す場合
[75]654 resultType.SetBasicType( resultType.GetBasicType() | FLAG_PTR );
[206]655
656 if( pResultSubscripts )
657 {
658 (*pResultSubscripts) = *pSubscripts;
659 }
[75]660 return true;
[3]661 }
662
[49]663 if( array[0] || member[0] ){
[3]664 //xor r11,r11(r11を0に初期化する)
665 //※r11は変数ベースアドレスからの相対オフセットを示す
[226]666 compiler.codeGenerator.op_zero_reg(REG_R11);
[3]667
668 pRelativeVar->bOffsetOffset=1;
669 }
670 if(array[0]){
[206]671 if(!GetArrayOffset(*pSubscripts,array,resultType)){
[468]672 compiler.errorMessenger.Output(14,variable,cp);
[3]673 pRelativeVar->dwKind=NON_VAR;
[75]674 return false;
[3]675 }
676 }
677 if(member[0]){
[75]678 if( resultType.IsObject() || resultType.IsStruct() ){
[3]679 //実態オブジェクトのメンバを参照(obj.member)
[206]680 if( refType != RefDot ){
[468]681 compiler.errorMessenger.Output(104,VarName,cp);
[3]682 pRelativeVar->dwKind=NON_VAR;
[75]683 return false;
[3]684 }
[64]685
[75]686 if( resultType.IsObject() ){
[64]687 // 参照内容へのポインタを抽出
688 SetRelativeOffset( *pRelativeVar );
689 }
[3]690 }
[75]691 else if( resultType.IsObjectPtr() || resultType.IsStructPtr() ){
[3]692 //ポインタオブジェクトが示すメンバを参照
693 if(lpPtrOffset[0]){
694 //pObj[n].member
[206]695 if( refType != RefDot ){
[468]696 compiler.errorMessenger.Output(104,VarName,cp);
[3]697 pRelativeVar->dwKind=NON_VAR;
[75]698 return false;
[3]699 }
[75]700 SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset);
[3]701 pRelativeVar->dwKind=VAR_DIRECTMEM;
702 }
703 else{
704 //pObj->member
[206]705 if( refType != RefPointer ){
[468]706 compiler.errorMessenger.Output(104,VarName,cp);
[3]707 pRelativeVar->dwKind=NON_VAR;
[75]708 return false;
[3]709 }
710
711 SetVarPtrToReg(REG_R12,pRelativeVar);
712 pRelativeVar->dwKind=VAR_DIRECTMEM;
713
714 //mov r11,qword ptr[r12]
[226]715 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_R12,0,MOD_BASE);
[3]716 }
717 }
[75]718 else if( resultType.GetBasicType()==MAKE_PTR_TYPE(DEF_OBJECT,2) || resultType.GetBasicType()==MAKE_PTR_TYPE(DEF_STRUCT,2)){
[3]719 //ポインタオブジェクトが示すメンバを参照
720 if(lpPtrOffset[0]){
721 //ppObj[n]->member
[206]722 if( refType != RefPointer ){
[468]723 compiler.errorMessenger.Output(104,VarName,cp);
[3]724 pRelativeVar->dwKind=NON_VAR;
[75]725 return false;
[3]726 }
727
[75]728 SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset);
[3]729 pRelativeVar->dwKind=VAR_DIRECTMEM;
730
731
732 SetVarPtrToReg(REG_R12,pRelativeVar);
733
734 //mov r11,qword ptr[r12]
[226]735 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_R12,0,MOD_BASE);
[3]736 }
737 else{
[468]738 compiler.errorMessenger.Output(104,VarName,cp);
[3]739 pRelativeVar->dwKind=NON_VAR;
[75]740 return false;
[3]741 }
742 }
743 else{
[468]744 compiler.errorMessenger.Output(102,VarName,cp);
[3]745 pRelativeVar->dwKind=NON_VAR;
[75]746 return false;
[3]747 }
[17]748
[75]749 if(!_member_offset(
[17]750 isErrorEnabled,
751 isWriteAccess,
[316]752 resultType,
[75]753 member,pRelativeVar,resultType,0)) return false;
[17]754
[75]755 return true;
[3]756 }
757
758 if(lpPtrOffset[0]){
[75]759 SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset);
[3]760 pRelativeVar->dwKind=VAR_DIRECTMEM;
761 }
762
[75]763 return true;
[3]764}
765
[206]766bool SetInitGlobalData(int offset,const Type &type,const Subscripts &subscripts,const char *lpszInitBuf){
767 int i2,i3;
[3]768 char temporary[VN_SIZE];
[138]769 char InitBuf[VN_SIZE];
770 lstrcpy( InitBuf, lpszInitBuf );
[3]771
772 if(InitBuf[0]=='['){
773 SlideString(InitBuf+1,-1);
774 InitBuf[lstrlen(InitBuf)-1]=0;
775
[75]776 int typeSize = type.GetSize();
[3]777
[206]778 if( subscripts.size() > 0 ){
779 Subscripts nestSubscripts;
780 for( int i=1; i<(int)subscripts.size(); i++ )
781 {
782 nestSubscripts.push_back( subscripts[i] );
783 }
784
785 typeSize*=JumpSubScripts( nestSubscripts );
786 {
787 int i=0;
788 i2=0;
789 while(1){
790 if( subscripts[0] < i2 ){
[468]791 compiler.errorMessenger.Output(41,0,cp);
[206]792 return 0;
793 }
794 i=GetOneParameter(InitBuf,i,temporary);
795 if(!SetInitGlobalData(
796 offset+i2*typeSize,
797 type,
798 nestSubscripts,
799 temporary)) return false;
800 i2++;
801 if(InitBuf[i]=='\0') break;
[3]802 }
803 }
[75]804 return true;
[3]805 }
806
[75]807 if(type.IsStruct()){
808 const CClass &objClass = type.GetClass();
[3]809
[140]810 int i = 0;
[584]811 BOOST_FOREACH( Member *pMember, objClass.GetDynamicMembers() ){
[140]812 if(InitBuf[i]=='\0'){
[468]813 compiler.errorMessenger.Output(41,0,cp);
[140]814 return false;
815 }
816
[3]817 i=GetOneParameter(InitBuf,i,temporary);
818
[410]819 i3=objClass.GetMemberOffset( pMember->GetName().c_str() );
[3]820
821 if(!SetInitGlobalData(offset+i3,
[140]822 pMember->GetType(),
[206]823 pMember->GetSubscripts(),
[75]824 temporary)) return false;
[3]825 }
[75]826 return true;
[3]827 }
828
[468]829 compiler.errorMessenger.Output(41,0,cp);
[75]830 return false;
[3]831 }
832
[20]833
834 ///////////////////////////////////////
835 // 単発式([]で囲まれていない)
836 ///////////////////////////////////////
837
[206]838 if( subscripts.size() > 0 ){
[468]839 compiler.errorMessenger.Output(41,0,cp);
[75]840 return false;
[3]841 }
842
843 double dbl;
844 _int64 i64data;
[75]845 Type calcType;
[3]846
[75]847 if( !StaticCalculation(false, InitBuf,type.GetBasicType(),&i64data,calcType) ){
[9]848 //動的データだった場合
[75]849 return false;
[9]850 }
[75]851 if( calcType.IsReal() ){
[3]852 memcpy(&dbl,&i64data,sizeof(double));
853 i64data=(_int64)dbl;
854 }
855 else dbl=(double)i64data;
856
857 //型チェック
858 CheckDifferentType(
859 type,
[75]860 calcType,
[3]861 0,0);
862
[75]863 if( type.IsDouble() ){
[308]864 compiler.GetObjectModule().meta.GetGlobalVars().initAreaBuffer.Overwrite(
865 offset,
866 (const char *)&dbl,
867 sizeof(double)
868 );
[75]869 }
870 else if( type.IsSingle() ){
[308]871 float flt = (float)dbl;
872 compiler.GetObjectModule().meta.GetGlobalVars().initAreaBuffer.Overwrite(
873 offset,
874 (const char *)&flt,
875 sizeof(float)
876 );
[75]877 }
878 else if( type.Is64() || type.IsPointer() ){
[454]879 if( type.GetBasicType() == typeOfPtrChar && type.GetIndex() == LITERAL_STRING ){
[3]880 //文字列定数のとき
881
882 char *temp;
883 temp=(char *)i64data;
[592]884 if( compiler.IsUnicode() )
885 {
886 i2 = compiler.GetObjectModule().dataTable.AddWString( Jenga::Common::ToWString( temp ) );
887 }
888 else
889 {
890 i2 = compiler.GetObjectModule().dataTable.AddString( temp );
891 }
[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 ){
[468]960 compiler.errorMessenger.Output(41,0,cp);
[206]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;
[584]980 BOOST_FOREACH( Member *pMember, objClass.GetDynamicMembers() ){
[140]981 if(InitBuf[i]=='\0'){
[468]982 compiler.errorMessenger.Output(41,0,cp);
[140]983 return false;
984 }
985
[3]986 i=GetOneParameter(InitBuf,i,temporary);
987
[410]988 i3=objClass.GetMemberOffset( pMember->GetName().c_str() );
[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
[468]1000 compiler.errorMessenger.Output(41,0,cp);
[75]1001 return false;
[3]1002 }
1003
[41]1004
1005 ///////////////////////////////////////
1006 // 単発式([]で囲まれていない)
1007 ///////////////////////////////////////
1008
[206]1009 if( subscripts.size() > 0 ){
[468]1010 compiler.errorMessenger.Output(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() ){
[454]1055 if( type.GetBasicType() == typeOfPtrChar && type.GetIndex() == LITERAL_STRING ){
[3]1056 //文字列定数のとき
1057
1058 char *temp;
1059 temp=(char *)i64data;
[592]1060 if( compiler.IsUnicode() )
1061 {
1062 i2 = compiler.GetObjectModule().dataTable.AddWString( Jenga::Common::ToWString( temp ) );
1063 }
1064 else
1065 {
1066 i2 = compiler.GetObjectModule().dataTable.AddString( temp );
1067 }
[3]1068 HeapDefaultFree(temp);
1069
1070 //mov rax,i2
[242]1071 compiler.codeGenerator.op_mov_RV(sizeof(_int64),REG_RAX,i2, Schedule::DataTable );
[3]1072
1073 //mov qword ptr[rsp+offset],rax
[254]1074 compiler.codeGenerator.localVarPertialSchedules.push_back(
1075 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_RAX,REG_RSP,offset,MOD_BASE_DISP32, Schedule::None, true )
1076 );
[3]1077 }
1078 else{
1079 if(i64data&0xFFFFFFFF00000000){
1080 //mov rax,i64data
[232]1081 compiler.codeGenerator.op_mov_RV64(REG_RAX,i64data);
[3]1082
1083 //mov qword ptr[rsp+offset],rax
[254]1084 compiler.codeGenerator.localVarPertialSchedules.push_back(
1085 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_RAX,REG_RSP,offset,MOD_BASE_DISP32, Schedule::None, true )
1086 );
[3]1087 }
1088 else{
1089 //mov qword ptr[rsp+offset],value
[254]1090 compiler.codeGenerator.localVarPertialSchedules.push_back(
1091 compiler.codeGenerator.op_mov_MV(sizeof(_int64),REG_RSP,offset, Schedule::None, true, USE_OFFSET,(int)i64data)
1092 );
[3]1093 }
1094 }
1095 }
[75]1096 else if( type.IsDWord() || type.IsLong() ){
[3]1097 //mov dword ptr[rsp+offset],value
[254]1098 compiler.codeGenerator.localVarPertialSchedules.push_back(
1099 compiler.codeGenerator.op_mov_MV(sizeof(long),REG_RSP,offset, Schedule::None, true, USE_OFFSET,(int)i64data)
1100 );
[3]1101 }
[75]1102 else if( type.IsWord() || type.IsInteger() ){
[3]1103 //mov word ptr[rsp+offset],value
[254]1104 compiler.codeGenerator.localVarPertialSchedules.push_back(
1105 compiler.codeGenerator.op_mov_MV(sizeof(short),REG_RSP,offset, Schedule::None, true, USE_OFFSET,(int)i64data)
1106 );
[3]1107 }
[75]1108 else if( type.IsSByte() || type.IsByte() || type.IsBoolean() ){
[3]1109 //mov byte ptr[rsp+offset],value
[254]1110 compiler.codeGenerator.localVarPertialSchedules.push_back(
1111 compiler.codeGenerator.op_mov_MV(sizeof(char),REG_RSP,offset, Schedule::None, true, USE_OFFSET,(int)i64data)
1112 );
[3]1113 }
[75]1114 return true;
[3]1115}
1116
[308]1117void dim( char *VarName, const Subscripts &subscripts, const Type &type,const char *InitBuf,const char *ConstractParameter,DWORD dwFlags)
1118{
[584]1119 if( compiler.IsGlobalAreaCompiling() ){
[64]1120 /////////////////////////
1121 // グローバル変数
1122 /////////////////////////
[3]1123
[206]1124 AddGlobalVariable(VarName,subscripts,type,InitBuf,ConstractParameter,dwFlags);
[64]1125 }
1126 else{
1127 /////////////////
1128 // ローカル変数
1129 /////////////////
1130
[584]1131 if( compiler.GetCompilingUserProc().GetLocalVars().DuplicateCheck( LexicalAnalyzer::FullNameToSymbol( VarName ), compiler.codeGenerator.lexicalScopes.GetNowLevel() ) ){
[75]1132 //2重定義のエラー
[468]1133 compiler.errorMessenger.Output(15,VarName,cp);
[75]1134 return;
[64]1135 }
1136
[75]1137 bool isConst = ( dwFlags & DIMFLAG_CONST ) ? true:false;
[64]1138
[584]1139 Variable *pVar = new Variable(
1140 ActiveBasic::Compiler::LexicalAnalyzer::FullNameToSymbol( VarName ),
1141 type,
1142 isConst,
1143 false,
1144 ConstractParameter,
1145 false
1146 );
[75]1147
[206]1148 if( subscripts.size() > 0 ){
[75]1149 //配列あり
[206]1150 pVar->SetArray( subscripts );
[64]1151 }
1152
[75]1153 //レキシカルスコープ
[254]1154 pVar->SetScopeLevel( compiler.codeGenerator.lexicalScopes.GetNowLevel() );
1155 pVar->SetScopeStartAddress( compiler.codeGenerator.lexicalScopes.GetStartAddress() );
[392]1156 pVar->isLiving = true;
[64]1157
[75]1158 //エラー用
1159 pVar->source_code_address=cp;
[64]1160
[75]1161 // 変数を追加
[584]1162 compiler.GetCompilingUserProc().GetLocalVars().push_back( pVar );
[75]1163
[64]1164 //アラインメントを考慮
[206]1165 if( pVar->GetType().IsStruct() ){
[232]1166 int alignment = pVar->GetType().GetClass().GetFixedAlignment();
[120]1167
[64]1168 if( alignment ){
1169 if( AllLocalVarSize % alignment ){
1170 AllLocalVarSize += alignment - (AllLocalVarSize % alignment);
1171 }
1172 }
[120]1173
1174 if( alignment == PTR_SIZE*2 ){
1175 // ポインタに要するサイズよりも一回り大きなアラインメントが指定されているとき
1176 // (例:CONTEXT構造体など)
1177 // 呼び出し側のオフセットズレを考慮する
1178
[584]1179 if( 0 == ( compiler.GetCompilingUserProc().RealParams().GetMemorySize() + PTR_SIZE /* ret分 */ ) % alignment ){
[120]1180 AllLocalVarSize += PTR_SIZE;
1181 }
1182 }
[64]1183 }
1184
[75]1185 AllLocalVarSize += pVar->GetMemorySize();
[206]1186 pVar->SetOffsetAddress( AllLocalVarSize );
[64]1187
1188 //レキシカルスコープ
[254]1189 pVar->SetScopeLevel( compiler.codeGenerator.lexicalScopes.GetNowLevel() );
1190 pVar->SetScopeStartAddress( compiler.codeGenerator.lexicalScopes.GetStartAddress() );
[392]1191 pVar->isLiving = true;
[64]1192
1193 if(InitBuf[0]){
1194 //初期代入時のみ、書き込みアクセスを許可する
[75]1195 if( isConst ){
1196 pVar->ConstOff();
1197 }
[64]1198
1199 int result = 0;
[206]1200 if( !pVar->GetType().IsObject() ){
1201 result = InitLocalVar(-pVar->GetOffsetAddress(),
1202 pVar->GetType(),
1203 pVar->GetSubscripts(),
[64]1204 InitBuf);
1205 }
1206
1207 if(!result){
1208 //動的な式だった場合は代入演算を行う
1209 char temporary[8192];
1210 sprintf(temporary,"%s=%s",VarName,InitBuf);
1211 OpcodeCalc(temporary);
1212 }
1213
[75]1214 if( isConst ){
1215 pVar->ConstOn();
1216 }
[64]1217 }
1218 else{
1219 //0初期化
1220
1221 //mov r8, 0
[226]1222 compiler.codeGenerator.op_zero_reg( REG_R8 );
[64]1223
1224 //mov rdx, VarSize
[226]1225 compiler.codeGenerator.op_mov_RV( sizeof(_int64), REG_RDX, pVar->GetMemorySize() );
[64]1226
1227 //mov rcx, rsp
[226]1228 compiler.codeGenerator.op_mov_RR( REG_RCX, REG_RSP );
[64]1229
1230 //add rcx, offset
[254]1231 compiler.codeGenerator.localVarPertialSchedules.push_back(
1232 compiler.codeGenerator.op_add_RV( REG_RCX, -pVar->GetOffsetAddress(), Schedule::None, true )
1233 );
[64]1234
1235 //call FillMemory
[75]1236 DllProc *pDllProc;
1237 pDllProc=GetDeclareHash("FillMemory");
[226]1238 compiler.codeGenerator.op_call( pDllProc );
[64]1239 }
1240 }
1241
[350]1242 //New呼び出し
1243 if( type.IsObject()
[370]1244 && !type.IsInterface() && !type.IsComInterface()
[350]1245 &&(dwFlags&DIMFLAG_NONCALL_CONSTRACTOR)==0
1246 &&InitBuf[0]=='\0')
1247 {
[64]1248 char objectSize[255];
[206]1249 if( subscripts.size() == 0 ){
[64]1250 objectSize[0] = 0;
1251 }
1252 else{
[206]1253 if( subscripts.size() > 1 ){
[468]1254 compiler.errorMessenger.Output(300,NULL,cp);
[64]1255 }
[206]1256 sprintf( objectSize, "%d", subscripts[0] );
[64]1257 }
[75]1258 Operator_New( type.GetClass(), objectSize, ConstractParameter, type );
[64]1259
[75]1260 Type tempType;
[64]1261 RELATIVE_VAR RelativeVar;
[75]1262 GetVarOffset( true, false, VarName, &RelativeVar, tempType );
[64]1263 if( RelativeVar.dwKind == VAR_DIRECTMEM ){
[468]1264 compiler.errorMessenger.OutputFatalError();
[64]1265 }
[308]1266 SetVariableFromRax( Type( DEF_OBJECT, *compiler.GetObjectModule().meta.GetClasses().GetObjectClassPtr() ), DEF_OBJECT, &RelativeVar );
[64]1267 }
1268}
[3]1269void SetVarPtrToReg(int reg,RELATIVE_VAR *pRelativeVar){
[468]1270 if(!IsGeneralReg(reg)) compiler.errorMessenger.Output(300,NULL,cp);
[3]1271
1272 if(pRelativeVar->dwKind==VAR_GLOBAL){
1273 if(pRelativeVar->bOffsetOffset){
1274 //add r11,offset
[232]1275 compiler.codeGenerator.op_add_RV( REG_R11, (long)pRelativeVar->offset, Schedule::GlobalVar );
[3]1276
1277 //mov reg,r11
[226]1278 compiler.codeGenerator.op_mov_RR(reg,REG_R11);
[3]1279 }
1280 else{
1281 //mov reg,offset
[232]1282 compiler.codeGenerator.op_mov_RV( sizeof(_int64), reg, (long)pRelativeVar->offset, Schedule::GlobalVar );
[3]1283 }
1284 }
[62]1285 else if( pRelativeVar->dwKind == VAR_REFGLOBAL ){
1286 if(pRelativeVar->bOffsetOffset){
1287 //add r11,qword ptr[offset]
[232]1288 compiler.codeGenerator.op_add_RM( sizeof(_int64), REG_R11, REG_NON, (int)pRelativeVar->offset, MOD_DISP32, Schedule::GlobalVar );
[62]1289 }
1290 else{
1291 //mov r11,qword ptr[offset]
[232]1292 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_NON,(int)pRelativeVar->offset,MOD_DISP32, Schedule::GlobalVar );
[62]1293 }
1294
1295 goto directmem;
1296 }
[3]1297 else if(pRelativeVar->dwKind==VAR_LOCAL){
1298 if(pRelativeVar->bOffsetOffset){
1299 //add r11,offset
[254]1300 compiler.codeGenerator.localVarPertialSchedules.push_back(
1301 compiler.codeGenerator.op_add_RV( REG_R11, (long)pRelativeVar->offset, Schedule::None, true )
1302 );
[3]1303
1304 //add r11,rsp
[228]1305 compiler.codeGenerator.op_add_RR(REG_R11,REG_RSP);
[3]1306
1307 //mov reg,r11
[226]1308 compiler.codeGenerator.op_mov_RR(reg,REG_R11);
[3]1309 }
1310 else{
1311 //mov reg,rsp
[226]1312 compiler.codeGenerator.op_mov_RR(reg,REG_RSP);
[3]1313
1314 //add reg,offset
[254]1315 compiler.codeGenerator.localVarPertialSchedules.push_back(
1316 compiler.codeGenerator.op_add_RV(reg,(long)pRelativeVar->offset, Schedule::None, true )
1317 );
[3]1318 }
1319 }
[40]1320 else if( pRelativeVar->dwKind == VAR_REFLOCAL ){
[3]1321 if(pRelativeVar->bOffsetOffset){
1322 //add r11,qword ptr[rsp+offset]
[254]1323 compiler.codeGenerator.localVarPertialSchedules.push_back(
1324 compiler.codeGenerator.op_add_RM( sizeof(_int64), REG_R11, REG_RSP, (long)pRelativeVar->offset, MOD_BASE_DISP32, Schedule::None, true )
1325 );
[3]1326 }
1327 else{
1328 //mov r11,qword ptr[rsp+offset]
[254]1329 compiler.codeGenerator.localVarPertialSchedules.push_back(
1330 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32, Schedule::None, true )
1331 );
[3]1332 }
1333
1334 goto directmem;
1335 }
1336 else if(pRelativeVar->dwKind==VAR_DIRECTMEM){
1337directmem:
1338 //mov reg,r11
[226]1339 compiler.codeGenerator.op_mov_RR(reg,REG_R11);
[3]1340 }
1341}
[95]1342
1343bool Compile_AddGlobalRootsForGc(){
[206]1344 const UserProc *pUserProc_AddGlobalRootPtr = GetClassMethod( "_System_CGarbageCollection", "AddGlobalRootPtr" );
[95]1345 if( !pUserProc_AddGlobalRootPtr ){
[468]1346 compiler.errorMessenger.Output(3, "_System_CGarbageCollection.AddGlobalRootPtr", -1 );
[95]1347 return false;
1348 }
1349
[266]1350 BOOST_FOREACH( const Variable *pVar, compiler.GetObjectModule().meta.GetGlobalVars() ){
[206]1351 if( pVar->GetType().IsObject() || pVar->GetType().IsPointer() || pVar->GetType().IsStruct() ){
[95]1352 // オブジェクトまたはポインタだったとき
1353 // ※構造体も含む(暫定対応)
1354
1355 // 変数領域に要するLONG_PTR単位の個数を引き渡す
1356 //mov r8,count
[226]1357 compiler.codeGenerator.op_mov_RV(sizeof(_int64), REG_R8,pVar->GetMemorySize()/PTR_SIZE);
[95]1358
1359 // ルートポインタを引き渡す
1360 //mov rdx,offset
[232]1361 compiler.codeGenerator.op_mov_RV(sizeof(_int64), REG_RDX,(int)pVar->GetOffsetAddress(), Schedule::GlobalVar );
[95]1362
1363 // Thisポインタを引き渡す
1364 SetThisPtrToReg(REG_RCX);
1365
1366 // call AddGlobalRootPtr
[226]1367 compiler.codeGenerator.op_call( pUserProc_AddGlobalRootPtr );
[95]1368 }
1369 }
1370
1371 return true;
1372}
Note: See TracBrowser for help on using the repository browser.