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