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