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