| 1 | #include "stdafx.h" | 
|---|
| 2 |  | 
|---|
| 3 | #include <jenga/include/smoothie/Smoothie.h> | 
|---|
| 4 |  | 
|---|
| 5 | #include <Compiler.h> | 
|---|
| 6 |  | 
|---|
| 7 | #include "../BasicCompiler_Common/common.h" | 
|---|
| 8 | #include "Opcode.h" | 
|---|
| 9 |  | 
|---|
| 10 | int GetFunctionFromName(char *FuncName){ | 
|---|
| 11 | if( lstrcmpi( FuncName, "Len" ) == 0 )              return FUNC_LEN; | 
|---|
| 12 | if( lstrcmpi( FuncName, "AddressOf" ) == 0 )        return FUNC_ADDRESSOF; | 
|---|
| 13 | if( lstrcmpi( FuncName, "SizeOf" ) == 0 )           return FUNC_SIZEOF; | 
|---|
| 14 | if( lstrcmpi( FuncName, "VarPtr" ) == 0 )           return FUNC_VARPTR; | 
|---|
| 15 | if( lstrcmpi( FuncName, "ObjPtr" ) == 0 )           return FUNC_OBJPTR; | 
|---|
| 16 | if( lstrcmpi( FuncName, "__delegate_dynamicmethod_call" ) == 0 )    return FUNC_DELEGATE_DYNAMICMETHOD_CALL; | 
|---|
| 17 | if( lstrcmpi( FuncName, "__delegate_staticmethod_call" ) == 0 )     return FUNC_DELEGATE_STATICMETHOD_CALL; | 
|---|
| 18 | if( lstrcmpi( FuncName, "GetDouble" ) == 0 )        return FUNC_GETDOUBLE; | 
|---|
| 19 | if( lstrcmpi( FuncName, "GetSingle" ) == 0 )        return FUNC_GETSINGLE; | 
|---|
| 20 | if( lstrcmpi( FuncName, "GetQWord" ) == 0 )         return FUNC_GETQWORD; | 
|---|
| 21 | if( lstrcmpi( FuncName, "GetDWord" ) == 0 )         return FUNC_GETDWORD; | 
|---|
| 22 | if( lstrcmpi( FuncName, "GetWord" ) == 0 )          return FUNC_GETWORD; | 
|---|
| 23 | if( lstrcmpi( FuncName, "GetByte" ) == 0 )          return FUNC_GETBYTE; | 
|---|
| 24 | return 0; | 
|---|
| 25 | } | 
|---|
| 26 | void Opcode_Func_Len( const char *Parameter ){ | 
|---|
| 27 | BOOL bArrayHead; | 
|---|
| 28 |  | 
|---|
| 29 | const char *tempParm=Parameter; | 
|---|
| 30 | char temporary[VN_SIZE]; | 
|---|
| 31 | char temp2[32]; | 
|---|
| 32 | Type type; | 
|---|
| 33 | if( !GetVarType(Parameter,type,0) ){ | 
|---|
| 34 | sprintf(temporary,"_System_DummyStr2=%s",Parameter); | 
|---|
| 35 | OpcodeCalc(temporary); | 
|---|
| 36 |  | 
|---|
| 37 | lstrcpy(temp2,"_System_DummyStr2"); | 
|---|
| 38 | tempParm=temp2; | 
|---|
| 39 |  | 
|---|
| 40 | type.SetType( DEF_OBJECT, compiler.GetObjectModule().meta.GetClasses().GetStringClassPtr() ); | 
|---|
| 41 | } | 
|---|
| 42 |  | 
|---|
| 43 | if( type.IsStringClass() ){ | 
|---|
| 44 | //Stringオブジェクトの場合 | 
|---|
| 45 | sprintf(temporary,"%s.Length",tempParm); | 
|---|
| 46 |  | 
|---|
| 47 | int reg=REG_RAX; | 
|---|
| 48 | NumOpe(®,temporary,Type(),Type()); | 
|---|
| 49 | return; | 
|---|
| 50 | } | 
|---|
| 51 |  | 
|---|
| 52 | Subscripts subscripts; | 
|---|
| 53 | RELATIVE_VAR RelativeVar; | 
|---|
| 54 | if(!GetVarOffsetReadOnly(tempParm,&RelativeVar,type,&subscripts)) return; | 
|---|
| 55 |  | 
|---|
| 56 | if(type.GetBasicType()&FLAG_PTR){ | 
|---|
| 57 | type.SetBasicType( type.GetBasicType() & ( ~FLAG_PTR ) ); | 
|---|
| 58 |  | 
|---|
| 59 | bArrayHead=1; | 
|---|
| 60 | } | 
|---|
| 61 | else bArrayHead=0; | 
|---|
| 62 |  | 
|---|
| 63 | int typeSize = type.GetSize(); | 
|---|
| 64 |  | 
|---|
| 65 | if(bArrayHead) typeSize*=JumpSubScripts(subscripts); | 
|---|
| 66 |  | 
|---|
| 67 | //mov rax,TypeSize | 
|---|
| 68 | compiler.codeGenerator.op_mov_RV(sizeof(_int64),REG_RAX,typeSize); | 
|---|
| 69 |  | 
|---|
| 70 | return; | 
|---|
| 71 | } | 
|---|
| 72 |  | 
|---|
| 73 | void _Opcode_Func_AddressOf( const char *methodInstanceName, const UserProc &userProc ) | 
|---|
| 74 | { | 
|---|
| 75 | if( userProc.IsVirtual() ) | 
|---|
| 76 | { | 
|---|
| 77 | /////////////////////////////// | 
|---|
| 78 | // 仮想関数の場合 | 
|---|
| 79 | // thisポインタをrcxにコピー | 
|---|
| 80 | /////////////////////////////// | 
|---|
| 81 |  | 
|---|
| 82 | const CClass *pobj_c; | 
|---|
| 83 |  | 
|---|
| 84 | char ObjectName[VN_SIZE]; | 
|---|
| 85 | ReferenceKind referenceKind; | 
|---|
| 86 | SplitObjectName(methodInstanceName,ObjectName, referenceKind ); | 
|---|
| 87 |  | 
|---|
| 88 | if(ObjectName[0]){ | 
|---|
| 89 | if(lstrcmpi(ObjectName,"Super")==0) goto InClassMember; | 
|---|
| 90 | else{ | 
|---|
| 91 | RELATIVE_VAR RelativeVar; | 
|---|
| 92 | Type type; | 
|---|
| 93 | if(!GetVarOffsetReadOnly(ObjectName,&RelativeVar,type)) return; | 
|---|
| 94 | SetVarPtrToReg(REG_RCX,&RelativeVar); | 
|---|
| 95 |  | 
|---|
| 96 | //参照タイプが整合しているかをチェック | 
|---|
| 97 | if( !( type.IsObject() && referenceKind == RefDot | 
|---|
| 98 | || type.IsObjectPtr() && referenceKind == RefPointer ) ) | 
|---|
| 99 | { | 
|---|
| 100 | SetError(104,ObjectName,cp); | 
|---|
| 101 | } | 
|---|
| 102 |  | 
|---|
| 103 | if(type.IsObjectPtr()){ | 
|---|
| 104 | //mov rcx,qword ptr[rcx] | 
|---|
| 105 | compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_RCX,REG_RCX,0,MOD_BASE); | 
|---|
| 106 | } | 
|---|
| 107 | } | 
|---|
| 108 | } | 
|---|
| 109 | else{ | 
|---|
| 110 | InClassMember: | 
|---|
| 111 | //自身のオブジェクトのThisポインタをrcxにコピー | 
|---|
| 112 | SetThisPtrToReg(REG_RCX); | 
|---|
| 113 |  | 
|---|
| 114 | pobj_c=compiler.pCompilingClass; | 
|---|
| 115 | } | 
|---|
| 116 |  | 
|---|
| 117 |  | 
|---|
| 118 | int vtblIndex; | 
|---|
| 119 | if( pobj_c->IsInterface() ) | 
|---|
| 120 | { | 
|---|
| 121 | // インターフェイスメソッド | 
|---|
| 122 |  | 
|---|
| 123 | int offset_vtbl = compiler.GetObjectModule().meta.GetClasses().GetInterfaceInfoClassPtr()->GetMemberOffset( "__vtbl" ); | 
|---|
| 124 |  | 
|---|
| 125 | // vtblのポインタを取得 | 
|---|
| 126 | //mov r11,qword ptr[rcx+offset_vtbl] | 
|---|
| 127 | compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_RCX,offset_vtbl,MOD_BASE_DISP8); | 
|---|
| 128 |  | 
|---|
| 129 | int offset_this = compiler.GetObjectModule().meta.GetClasses().GetInterfaceInfoClassPtr()->GetMemberOffset( "__this" ); | 
|---|
| 130 |  | 
|---|
| 131 | // インターフェイスの場合は更に__thisを取得する | 
|---|
| 132 | //mov rcx,qword ptr[rcx+offset_this] | 
|---|
| 133 | compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_RCX,REG_RCX,offset_this,MOD_BASE_DISP8); | 
|---|
| 134 |  | 
|---|
| 135 | int vtblMasterListIndex; | 
|---|
| 136 | pobj_c->GetVtblMasterListIndexAndVtblIndex( &userProc, vtblMasterListIndex, vtblIndex ); | 
|---|
| 137 | if( vtblMasterListIndex != 0 ) | 
|---|
| 138 | { | 
|---|
| 139 | SetError(); | 
|---|
| 140 | } | 
|---|
| 141 | } | 
|---|
| 142 | else | 
|---|
| 143 | { | 
|---|
| 144 | //仮想関数(オブジェクトメソッド) | 
|---|
| 145 | // pObj -> vtbl_master_list -> vtbl1 -> func1 | 
|---|
| 146 | //                                   -> func2 | 
|---|
| 147 | //                                   -> func3 | 
|---|
| 148 | //                          -> vtbl2 -> func1 | 
|---|
| 149 | //                                   -> func2 | 
|---|
| 150 | //                                   -> func3 | 
|---|
| 151 |  | 
|---|
| 152 | int vtblMasterListIndex; | 
|---|
| 153 | pobj_c->GetVtblMasterListIndexAndVtblIndex( &userProc, vtblMasterListIndex, vtblIndex ); | 
|---|
| 154 |  | 
|---|
| 155 | // vtblマスターリストのポインタを取得 | 
|---|
| 156 | //mov r11,qword ptr[rcx] | 
|---|
| 157 | compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_RCX,0,MOD_BASE); | 
|---|
| 158 |  | 
|---|
| 159 | // vtblのポインタを取得 | 
|---|
| 160 | //mov r11,dword ptr[r11+vtblMasterListIndex] | 
|---|
| 161 | compiler.codeGenerator.op_mov_RM( sizeof(_int64), REG_R11, REG_R11, vtblMasterListIndex, MOD_BASE_DISP32 ); | 
|---|
| 162 | } | 
|---|
| 163 |  | 
|---|
| 164 | //mov rax,qword ptr[r11+func_index] | 
|---|
| 165 | if( vtblIndex * PTR_SIZE <= 0x7F ) | 
|---|
| 166 | { | 
|---|
| 167 | compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_RAX,REG_R11,vtblIndex*PTR_SIZE,MOD_BASE_DISP8); | 
|---|
| 168 | } | 
|---|
| 169 | else | 
|---|
| 170 | { | 
|---|
| 171 | compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_RAX,REG_R11,vtblIndex*PTR_SIZE,MOD_BASE_DISP32); | 
|---|
| 172 | } | 
|---|
| 173 | } | 
|---|
| 174 | else{ | 
|---|
| 175 | //一般の関数 | 
|---|
| 176 |  | 
|---|
| 177 | //mov rax,ProcAddr | 
|---|
| 178 | compiler.codeGenerator.op_addressof( REG_RAX, &userProc ); | 
|---|
| 179 | } | 
|---|
| 180 |  | 
|---|
| 181 | userProc.Using(); | 
|---|
| 182 | } | 
|---|
| 183 | void Opcode_CreateDelegate( const CClass &dgClass, const char *methodInstanceName, const UserProc &userProc ) | 
|---|
| 184 | { | 
|---|
| 185 | ///////////////////////////////////////////////////////////////// | 
|---|
| 186 | // 関数ポインタをpush | 
|---|
| 187 | ///////////////////////////////////////////////////////////////// | 
|---|
| 188 |  | 
|---|
| 189 | //mov rax,AddressOf | 
|---|
| 190 | _Opcode_Func_AddressOf( methodInstanceName, userProc ); | 
|---|
| 191 |  | 
|---|
| 192 |  | 
|---|
| 193 | if( userProc.GetMethod().IsDynamic() ) | 
|---|
| 194 | { | 
|---|
| 195 | //mov rdx,rax | 
|---|
| 196 | compiler.codeGenerator.op_mov_RR( REG_RDX, REG_RAX ); | 
|---|
| 197 |  | 
|---|
| 198 | pobj_BlockReg->lock( REG_RDX ); | 
|---|
| 199 |  | 
|---|
| 200 |  | 
|---|
| 201 | ///////////////////////////////////////////////////////////////// | 
|---|
| 202 | // オブジェクト ポインタをpush | 
|---|
| 203 | ///////////////////////////////////////////////////////////////// | 
|---|
| 204 |  | 
|---|
| 205 | // オブジェクト名を取得 | 
|---|
| 206 | char objectName[VN_SIZE]; | 
|---|
| 207 | char memberName[VN_SIZE]; | 
|---|
| 208 | char *thisPtrName = "This"; | 
|---|
| 209 | Type type; | 
|---|
| 210 | if( SplitMemberName( methodInstanceName, objectName, memberName ) ) | 
|---|
| 211 | { | 
|---|
| 212 | if( GetVarType( objectName, type, false ) ) | 
|---|
| 213 | { | 
|---|
| 214 | thisPtrName = objectName; | 
|---|
| 215 | } | 
|---|
| 216 | } | 
|---|
| 217 |  | 
|---|
| 218 | // オブジェクト ポインタを取得 | 
|---|
| 219 | RELATIVE_VAR relativeVar; | 
|---|
| 220 | GetVarOffsetReadOnly( thisPtrName, &relativeVar, type ); | 
|---|
| 221 | if( !type.IsObject() ) | 
|---|
| 222 | { | 
|---|
| 223 | extern int cp; | 
|---|
| 224 | SetError(1,NULL,cp); | 
|---|
| 225 | return; | 
|---|
| 226 | } | 
|---|
| 227 |  | 
|---|
| 228 | SetVarPtrToReg( REG_RAX, &relativeVar ); | 
|---|
| 229 |  | 
|---|
| 230 | //mov rcx,dword ptr[rax] | 
|---|
| 231 | compiler.codeGenerator.op_mov_RM( sizeof(_int64), REG_RCX, REG_RAX, 0, MOD_BASE ); | 
|---|
| 232 |  | 
|---|
| 233 | pobj_BlockReg->unlock( REG_RDX ); | 
|---|
| 234 | } | 
|---|
| 235 | else | 
|---|
| 236 | { | 
|---|
| 237 | //mov rcx,rax | 
|---|
| 238 | compiler.codeGenerator.op_mov_RR( REG_RCX, REG_RAX ); | 
|---|
| 239 | } | 
|---|
| 240 |  | 
|---|
| 241 |  | 
|---|
| 242 | ///////////////////////////////////////////////////////////////// | 
|---|
| 243 | // call _CreateDynamicDelegate/_CreateStaticDelegate | 
|---|
| 244 | ///////////////////////////////////////////////////////////////// | 
|---|
| 245 |  | 
|---|
| 246 | std::vector<const UserProc *> subs; | 
|---|
| 247 | if( userProc.GetMethod().IsDynamic() ) | 
|---|
| 248 | { | 
|---|
| 249 | dgClass.GetStaticMethods().Enum( "_CreateDynamicDelegate", subs ); | 
|---|
| 250 | } | 
|---|
| 251 | else | 
|---|
| 252 | { | 
|---|
| 253 | dgClass.GetStaticMethods().Enum( "_CreateStaticDelegate", subs ); | 
|---|
| 254 | } | 
|---|
| 255 |  | 
|---|
| 256 | // call _CreateDynamicDelegate | 
|---|
| 257 | compiler.codeGenerator.op_call( subs[0] ); | 
|---|
| 258 | } | 
|---|
| 259 | void Opcode_Func_AddressOf( const char *name, const Type &baseType, bool isCallOn, Type &resultType ) | 
|---|
| 260 | { | 
|---|
| 261 | extern int cp; | 
|---|
| 262 | const UserProc *pUserProc; | 
|---|
| 263 |  | 
|---|
| 264 | const Parameters *pBaseParams = NULL; | 
|---|
| 265 | if( baseType.IsProcPtr() ) | 
|---|
| 266 | { | 
|---|
| 267 | // 左辺で関数ポインタを要求されているとき | 
|---|
| 268 | pBaseParams = &compiler.GetObjectModule().meta.GetProcPointers()[baseType.GetIndex()]->Params(); | 
|---|
| 269 | } | 
|---|
| 270 | else if( baseType.IsDelegate() ) | 
|---|
| 271 | { | 
|---|
| 272 | // 左辺でデリゲートを要求されているとき | 
|---|
| 273 | pBaseParams = &baseType.GetClass().GetDelegate().Params(); | 
|---|
| 274 | } | 
|---|
| 275 |  | 
|---|
| 276 | if( pBaseParams ) | 
|---|
| 277 | { | 
|---|
| 278 | //左辺の型にのっとり、オーバーロードを解決 | 
|---|
| 279 |  | 
|---|
| 280 | std::vector<const UserProc *> subs; | 
|---|
| 281 | GetOverloadSubHash( name, subs ); | 
|---|
| 282 | if( subs.size() == 0 ){ | 
|---|
| 283 | SetError(27,name,cp); | 
|---|
| 284 | return; | 
|---|
| 285 | } | 
|---|
| 286 |  | 
|---|
| 287 | //オーバーロードを解決 | 
|---|
| 288 | pUserProc=OverloadSolution( name, subs, *pBaseParams, Type() ); | 
|---|
| 289 |  | 
|---|
| 290 | if( isCallOn && baseType.IsDelegate() ) | 
|---|
| 291 | { | 
|---|
| 292 | // コード生成を伴う場合はエラーチェックを行う | 
|---|
| 293 | if( !pUserProc->Params().Equals( *pBaseParams ) | 
|---|
| 294 | || !pUserProc->ReturnType().Equals( baseType.GetClass().GetDelegate().ReturnType() ) ) | 
|---|
| 295 | { | 
|---|
| 296 | if( baseType.IsDelegate() ) | 
|---|
| 297 | { | 
|---|
| 298 | SetError(67, name, cp ); | 
|---|
| 299 | } | 
|---|
| 300 | else | 
|---|
| 301 | { | 
|---|
| 302 | SetError(66, name, cp ); | 
|---|
| 303 | } | 
|---|
| 304 | } | 
|---|
| 305 | } | 
|---|
| 306 |  | 
|---|
| 307 | if(!pUserProc){ | 
|---|
| 308 | SetError(27,name,cp); | 
|---|
| 309 | return; | 
|---|
| 310 | } | 
|---|
| 311 | } | 
|---|
| 312 | else{ | 
|---|
| 313 | pUserProc=GetSubHash(name); | 
|---|
| 314 | if(!pUserProc){ | 
|---|
| 315 | SetError(27,name,cp); | 
|---|
| 316 | return; | 
|---|
| 317 | } | 
|---|
| 318 | } | 
|---|
| 319 |  | 
|---|
| 320 | if( baseType.IsDelegate() ) | 
|---|
| 321 | { | 
|---|
| 322 | if( isCallOn ) | 
|---|
| 323 | { | 
|---|
| 324 | // デリゲートのとき | 
|---|
| 325 | Opcode_CreateDelegate( baseType.GetClass(), name, *pUserProc ); | 
|---|
| 326 | } | 
|---|
| 327 | resultType = baseType; | 
|---|
| 328 | } | 
|---|
| 329 | else | 
|---|
| 330 | { | 
|---|
| 331 | if( isCallOn ) | 
|---|
| 332 | { | 
|---|
| 333 | // 関数ポインタのとき | 
|---|
| 334 | _Opcode_Func_AddressOf( name, *pUserProc ); | 
|---|
| 335 | } | 
|---|
| 336 | resultType.SetBasicType( DEF_PTR_VOID ); | 
|---|
| 337 | } | 
|---|
| 338 | } | 
|---|
| 339 | void Opcode_Func_SizeOf( const string &typeName ){ | 
|---|
| 340 | Type tempType; | 
|---|
| 341 | if( !compiler.StringToType( typeName, tempType ) ){ | 
|---|
| 342 | SetError(3,typeName,cp); | 
|---|
| 343 | return; | 
|---|
| 344 | } | 
|---|
| 345 |  | 
|---|
| 346 | int typeSize = ( tempType.IsObject() ) ? | 
|---|
| 347 | tempType.GetClass().GetSize() : tempType.GetSize(); | 
|---|
| 348 |  | 
|---|
| 349 | //mov rax,size | 
|---|
| 350 | compiler.codeGenerator.op_mov_RV(sizeof(_int64),REG_RAX,typeSize); | 
|---|
| 351 | } | 
|---|
| 352 | void Opcode_Func_VarPtr( const char *Parameter, Type &resultType, bool isCallOn ){ | 
|---|
| 353 | if( isCallOn == false ){ | 
|---|
| 354 | // 戻り値の型を取得するだけ | 
|---|
| 355 |  | 
|---|
| 356 | //変数のアドレスを取得 | 
|---|
| 357 | if(!GetVarType( Parameter, resultType, true )) return; | 
|---|
| 358 |  | 
|---|
| 359 | resultType.PtrLevelUp(); | 
|---|
| 360 |  | 
|---|
| 361 | return; | 
|---|
| 362 | } | 
|---|
| 363 |  | 
|---|
| 364 | RELATIVE_VAR RelativeVar; | 
|---|
| 365 |  | 
|---|
| 366 | //変数のアドレスを取得 | 
|---|
| 367 | if(!GetVarOffsetReadOnly( Parameter, &RelativeVar, resultType )) return; | 
|---|
| 368 |  | 
|---|
| 369 | int beforeType = resultType.GetBasicType(); | 
|---|
| 370 |  | 
|---|
| 371 | resultType.PtrLevelUp(); | 
|---|
| 372 |  | 
|---|
| 373 | SetVarPtrToReg(REG_RAX,&RelativeVar); | 
|---|
| 374 |  | 
|---|
| 375 | // TODO: 取り除く(この動きはObjPtrに託す) | 
|---|
| 376 | /* | 
|---|
| 377 | if( beforeType == DEF_OBJECT && lstrcmpi( Parameter, "This" ) != 0 ){ | 
|---|
| 378 | //参照をオブジェクトポインタに変更 | 
|---|
| 379 |  | 
|---|
| 380 | //mov rax,qword ptr[rax] | 
|---|
| 381 | compiler.codeGenerator.op_mov_RM( sizeof(_int64), REG_RAX, REG_RAX, 0, MOD_BASE ); | 
|---|
| 382 |  | 
|---|
| 383 | SetError(-120,NULL,cp); | 
|---|
| 384 | }*/ | 
|---|
| 385 | } | 
|---|
| 386 | void Opcode_Func_ObjPtr( const char *Parameter, Type &resultType, bool isCallOn ){ | 
|---|
| 387 | if( isCallOn == false ){ | 
|---|
| 388 | // 戻り値の型を取得するだけ | 
|---|
| 389 |  | 
|---|
| 390 | //変数のアドレスを取得 | 
|---|
| 391 | if(!GetVarType( Parameter, resultType, true )) return; | 
|---|
| 392 |  | 
|---|
| 393 | resultType.PtrLevelUp(); | 
|---|
| 394 |  | 
|---|
| 395 | return; | 
|---|
| 396 | } | 
|---|
| 397 |  | 
|---|
| 398 | RELATIVE_VAR RelativeVar; | 
|---|
| 399 |  | 
|---|
| 400 | //変数のアドレスを取得 | 
|---|
| 401 | if(!GetVarOffsetReadOnly( Parameter, &RelativeVar, resultType )) return; | 
|---|
| 402 |  | 
|---|
| 403 | int beforeType = resultType.GetBasicType(); | 
|---|
| 404 |  | 
|---|
| 405 | resultType.PtrLevelUp(); | 
|---|
| 406 |  | 
|---|
| 407 | SetVarPtrToReg(REG_RAX,&RelativeVar); | 
|---|
| 408 |  | 
|---|
| 409 | if( lstrcmpi( Parameter, "This" )==0 ){ | 
|---|
| 410 | // Thisの場合は特別にオブジェクトポインタが返ってくるので、何もせずに抜ける | 
|---|
| 411 | } | 
|---|
| 412 | else if( beforeType == DEF_OBJECT ){ | 
|---|
| 413 | //参照をオブジェクトポインタに変更 | 
|---|
| 414 |  | 
|---|
| 415 | //mov rax,qword ptr[rax] | 
|---|
| 416 | compiler.codeGenerator.op_mov_RM( sizeof(_int64), REG_RAX, REG_RAX, 0, MOD_BASE ); | 
|---|
| 417 | } | 
|---|
| 418 | else{ | 
|---|
| 419 | SetError(134,NULL,cp ); | 
|---|
| 420 | } | 
|---|
| 421 | } | 
|---|
| 422 |  | 
|---|
| 423 | void Opcode_Func_delegate_call( const char *paramsStr, Type &resultType, bool isDynamicCall, bool isCallOn ) | 
|---|
| 424 | { | 
|---|
| 425 | if( isCallOn ) | 
|---|
| 426 | { | 
|---|
| 427 | int i = 0; | 
|---|
| 428 | char methodPtrParamStr[VN_SIZE]; | 
|---|
| 429 | i = GetOneParameter( paramsStr, i, methodPtrParamStr ); | 
|---|
| 430 |  | 
|---|
| 431 | char objPtrValueStr[VN_SIZE] = ""; | 
|---|
| 432 | if( isDynamicCall ) | 
|---|
| 433 | { | 
|---|
| 434 | i = GetOneParameter( paramsStr, i, objPtrValueStr ); | 
|---|
| 435 | } | 
|---|
| 436 |  | 
|---|
| 437 | Opcode_CallDelegate( compiler.pCompilingClass->GetDelegate(), methodPtrParamStr, objPtrValueStr, paramsStr + i ); | 
|---|
| 438 | } | 
|---|
| 439 |  | 
|---|
| 440 | resultType = UserProc::CompilingUserProc().ReturnType(); | 
|---|
| 441 | } | 
|---|
| 442 |  | 
|---|
| 443 | void Opcode_Func_GetPtrData( const char *Parameter, const int type ){ | 
|---|
| 444 | int reg=REG_RAX; | 
|---|
| 445 | Type tempType; | 
|---|
| 446 | if( !NumOpe(®,Parameter,Type(),tempType) ){ | 
|---|
| 447 | return; | 
|---|
| 448 | } | 
|---|
| 449 | if(!tempType.IsWhole()){ | 
|---|
| 450 | SetError(11,Parameter,cp); | 
|---|
| 451 | return; | 
|---|
| 452 | } | 
|---|
| 453 |  | 
|---|
| 454 | if(type==DEF_DOUBLE){ | 
|---|
| 455 | //movlpd xmm0,qword ptr[rax] | 
|---|
| 456 | compiler.codeGenerator.op_movlpd_RM(REG_XMM0,REG_RAX,0,MOD_BASE); | 
|---|
| 457 | } | 
|---|
| 458 | else if(type==DEF_SINGLE){ | 
|---|
| 459 | //movss xmm0,dword ptr[rax] | 
|---|
| 460 | compiler.codeGenerator.op_movss_RM(REG_XMM0,REG_RAX,0,MOD_BASE); | 
|---|
| 461 | } | 
|---|
| 462 | else{ | 
|---|
| 463 | //mov rax,ptr[rax] | 
|---|
| 464 | compiler.codeGenerator.op_mov_RM(Type(type).GetSize(),REG_RAX,REG_RAX,0,MOD_BASE); | 
|---|
| 465 | } | 
|---|
| 466 | } | 
|---|
| 467 |  | 
|---|
| 468 | bool Opcode_CallFunc( const char *Parameter, const int FuncNum, const Type &baseType, Type &resultType, bool isCallOn ) | 
|---|
| 469 | { | 
|---|
| 470 | switch(FuncNum){ | 
|---|
| 471 | case FUNC_LEN: | 
|---|
| 472 | if( isCallOn ) Opcode_Func_Len(Parameter); | 
|---|
| 473 | resultType.SetBasicType( DEF_LONG ); | 
|---|
| 474 | break; | 
|---|
| 475 | case FUNC_ADDRESSOF: | 
|---|
| 476 | Opcode_Func_AddressOf( Parameter, baseType, isCallOn, resultType ); | 
|---|
| 477 | break; | 
|---|
| 478 | case FUNC_SIZEOF: | 
|---|
| 479 | if( isCallOn ) Opcode_Func_SizeOf(Parameter); | 
|---|
| 480 | resultType.SetBasicType( DEF_LONG ); | 
|---|
| 481 | break; | 
|---|
| 482 | case FUNC_VARPTR: | 
|---|
| 483 | Opcode_Func_VarPtr( Parameter, resultType, isCallOn ); | 
|---|
| 484 | break; | 
|---|
| 485 | case FUNC_OBJPTR: | 
|---|
| 486 | Opcode_Func_ObjPtr( Parameter, resultType, isCallOn ); | 
|---|
| 487 | break; | 
|---|
| 488 | case FUNC_DELEGATE_DYNAMICMETHOD_CALL: | 
|---|
| 489 | Opcode_Func_delegate_call( Parameter, resultType, true, isCallOn ); | 
|---|
| 490 | break; | 
|---|
| 491 | case FUNC_DELEGATE_STATICMETHOD_CALL: | 
|---|
| 492 | Opcode_Func_delegate_call( Parameter, resultType, false, isCallOn ); | 
|---|
| 493 | break; | 
|---|
| 494 |  | 
|---|
| 495 | case FUNC_GETDOUBLE: | 
|---|
| 496 | if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_DOUBLE); | 
|---|
| 497 | resultType.SetBasicType( DEF_DOUBLE ); | 
|---|
| 498 | break; | 
|---|
| 499 | case FUNC_GETSINGLE: | 
|---|
| 500 | if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_SINGLE); | 
|---|
| 501 | resultType.SetBasicType( DEF_SINGLE ); | 
|---|
| 502 | break; | 
|---|
| 503 | case FUNC_GETQWORD: | 
|---|
| 504 | if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_QWORD); | 
|---|
| 505 | resultType.SetBasicType( DEF_QWORD ); | 
|---|
| 506 | break; | 
|---|
| 507 | case FUNC_GETDWORD: | 
|---|
| 508 | if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_DWORD); | 
|---|
| 509 | resultType.SetBasicType( DEF_DWORD ); | 
|---|
| 510 | break; | 
|---|
| 511 | case FUNC_GETWORD: | 
|---|
| 512 | if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_WORD); | 
|---|
| 513 | resultType.SetBasicType( DEF_WORD ); | 
|---|
| 514 | break; | 
|---|
| 515 | case FUNC_GETBYTE: | 
|---|
| 516 | if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_BYTE); | 
|---|
| 517 | resultType.SetBasicType( DEF_BYTE ); | 
|---|
| 518 | break; | 
|---|
| 519 | default: | 
|---|
| 520 | return false; | 
|---|
| 521 | } | 
|---|
| 522 | return true; | 
|---|
| 523 | } | 
|---|