[206] | 1 | #include "stdafx.h"
|
---|
| 2 |
|
---|
[183] | 3 | #include <jenga/include/smoothie/Smoothie.h>
|
---|
| 4 |
|
---|
[198] | 5 | #include <Compiler.h>
|
---|
| 6 |
|
---|
[3] | 7 | #include "../BasicCompiler_Common/common.h"
|
---|
| 8 | #include "Opcode.h"
|
---|
| 9 |
|
---|
| 10 | int GetFunctionFromName(char *FuncName){
|
---|
[325] | 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;
|
---|
[330] | 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;
|
---|
[325] | 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;
|
---|
[3] | 24 | return 0;
|
---|
| 25 | }
|
---|
[46] | 26 | void Opcode_Func_Len( const char *Parameter ){
|
---|
[3] | 27 | BOOL bArrayHead;
|
---|
| 28 |
|
---|
[46] | 29 | const char *tempParm=Parameter;
|
---|
[3] | 30 | char temporary[VN_SIZE];
|
---|
| 31 | char temp2[32];
|
---|
[75] | 32 | Type type;
|
---|
| 33 | if( !GetVarType(Parameter,type,0) ){
|
---|
[3] | 34 | sprintf(temporary,"_System_DummyStr2=%s",Parameter);
|
---|
| 35 | OpcodeCalc(temporary);
|
---|
| 36 |
|
---|
| 37 | lstrcpy(temp2,"_System_DummyStr2");
|
---|
| 38 | tempParm=temp2;
|
---|
| 39 |
|
---|
[266] | 40 | type.SetType( DEF_OBJECT, compiler.GetObjectModule().meta.GetClasses().GetStringClassPtr() );
|
---|
[3] | 41 | }
|
---|
| 42 |
|
---|
[97] | 43 | if( type.IsStringClass() ){
|
---|
[3] | 44 | //Stringオブジェクトの場合
|
---|
| 45 | sprintf(temporary,"%s.Length",tempParm);
|
---|
| 46 |
|
---|
| 47 | int reg=REG_RAX;
|
---|
[76] | 48 | NumOpe(®,temporary,Type(),Type());
|
---|
[3] | 49 | return;
|
---|
| 50 | }
|
---|
| 51 |
|
---|
[206] | 52 | Subscripts subscripts;
|
---|
[3] | 53 | RELATIVE_VAR RelativeVar;
|
---|
[206] | 54 | if(!GetVarOffsetReadOnly(tempParm,&RelativeVar,type,&subscripts)) return;
|
---|
[3] | 55 |
|
---|
[75] | 56 | if(type.GetBasicType()&FLAG_PTR){
|
---|
| 57 | type.SetBasicType( type.GetBasicType() & ( ~FLAG_PTR ) );
|
---|
[3] | 58 |
|
---|
| 59 | bArrayHead=1;
|
---|
| 60 | }
|
---|
| 61 | else bArrayHead=0;
|
---|
| 62 |
|
---|
[75] | 63 | int typeSize = type.GetSize();
|
---|
[3] | 64 |
|
---|
[206] | 65 | if(bArrayHead) typeSize*=JumpSubScripts(subscripts);
|
---|
[3] | 66 |
|
---|
| 67 | //mov rax,TypeSize
|
---|
[226] | 68 | compiler.codeGenerator.op_mov_RV(sizeof(_int64),REG_RAX,typeSize);
|
---|
[3] | 69 |
|
---|
| 70 | return;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
[339] | 73 | void _Opcode_Func_AddressOf( const char *methodInstanceName, const UserProc &userProc )
|
---|
| 74 | {
|
---|
| 75 | if( userProc.IsVirtual() )
|
---|
[331] | 76 | {
|
---|
[3] | 77 | ///////////////////////////////
|
---|
| 78 | // 仮想関数の場合
|
---|
| 79 | // thisポインタをrcxにコピー
|
---|
| 80 | ///////////////////////////////
|
---|
| 81 |
|
---|
[115] | 82 | const CClass *pobj_c;
|
---|
[3] | 83 |
|
---|
| 84 | char ObjectName[VN_SIZE];
|
---|
[308] | 85 | ReferenceKind referenceKind;
|
---|
[339] | 86 | SplitObjectName(methodInstanceName,ObjectName, referenceKind );
|
---|
[3] | 87 |
|
---|
| 88 | if(ObjectName[0]){
|
---|
| 89 | if(lstrcmpi(ObjectName,"Super")==0) goto InClassMember;
|
---|
| 90 | else{
|
---|
| 91 | RELATIVE_VAR RelativeVar;
|
---|
[75] | 92 | Type type;
|
---|
| 93 | if(!GetVarOffsetReadOnly(ObjectName,&RelativeVar,type)) return;
|
---|
[3] | 94 | SetVarPtrToReg(REG_RCX,&RelativeVar);
|
---|
| 95 |
|
---|
| 96 | //参照タイプが整合しているかをチェック
|
---|
[308] | 97 | if( !( type.IsObject() && referenceKind == RefDot
|
---|
| 98 | || type.IsObjectPtr() && referenceKind == RefPointer ) )
|
---|
| 99 | {
|
---|
| 100 | SetError(104,ObjectName,cp);
|
---|
| 101 | }
|
---|
[3] | 102 |
|
---|
[75] | 103 | if(type.IsObjectPtr()){
|
---|
[3] | 104 | //mov rcx,qword ptr[rcx]
|
---|
[226] | 105 | compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_RCX,REG_RCX,0,MOD_BASE);
|
---|
[3] | 106 | }
|
---|
| 107 | }
|
---|
| 108 | }
|
---|
| 109 | else{
|
---|
| 110 | InClassMember:
|
---|
| 111 | //自身のオブジェクトのThisポインタをrcxにコピー
|
---|
| 112 | SetThisPtrToReg(REG_RCX);
|
---|
| 113 |
|
---|
[206] | 114 | pobj_c=compiler.pCompilingClass;
|
---|
[3] | 115 | }
|
---|
| 116 |
|
---|
| 117 |
|
---|
[349] | 118 | int vtblIndex;
|
---|
| 119 | if( pobj_c->IsInterface() )
|
---|
| 120 | {
|
---|
| 121 | // インターフェイスメソッド
|
---|
[3] | 122 |
|
---|
[349] | 123 | int offset_vtbl = compiler.GetObjectModule().meta.GetClasses().GetInterfaceInfoClassPtr()->GetMemberOffset( "__vtbl" );
|
---|
[348] | 124 |
|
---|
[349] | 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);
|
---|
[3] | 128 |
|
---|
[349] | 129 | int offset_this = compiler.GetObjectModule().meta.GetClasses().GetInterfaceInfoClassPtr()->GetMemberOffset( "__this" );
|
---|
[3] | 130 |
|
---|
[349] | 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 |
|
---|
[3] | 164 | //mov rax,qword ptr[r11+func_index]
|
---|
[345] | 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);
|
---|
[3] | 168 | }
|
---|
[345] | 169 | else
|
---|
| 170 | {
|
---|
| 171 | compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_RAX,REG_R11,vtblIndex*PTR_SIZE,MOD_BASE_DISP32);
|
---|
[3] | 172 | }
|
---|
| 173 | }
|
---|
| 174 | else{
|
---|
| 175 | //一般の関数
|
---|
| 176 |
|
---|
| 177 | //mov rax,ProcAddr
|
---|
[339] | 178 | compiler.codeGenerator.op_addressof( REG_RAX, &userProc );
|
---|
[3] | 179 | }
|
---|
| 180 |
|
---|
[339] | 181 | userProc.Using();
|
---|
[3] | 182 | }
|
---|
[339] | 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 | }
|
---|
[79] | 339 | void Opcode_Func_SizeOf( const string &typeName ){
|
---|
| 340 | Type tempType;
|
---|
[308] | 341 | if( !compiler.StringToType( typeName, tempType ) ){
|
---|
[79] | 342 | SetError(3,typeName,cp);
|
---|
| 343 | return;
|
---|
[64] | 344 | }
|
---|
[3] | 345 |
|
---|
[79] | 346 | int typeSize = ( tempType.IsObject() ) ?
|
---|
| 347 | tempType.GetClass().GetSize() : tempType.GetSize();
|
---|
| 348 |
|
---|
[3] | 349 | //mov rax,size
|
---|
[226] | 350 | compiler.codeGenerator.op_mov_RV(sizeof(_int64),REG_RAX,typeSize);
|
---|
[3] | 351 | }
|
---|
[75] | 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 |
|
---|
[3] | 364 | RELATIVE_VAR RelativeVar;
|
---|
| 365 |
|
---|
| 366 | //変数のアドレスを取得
|
---|
[75] | 367 | if(!GetVarOffsetReadOnly( Parameter, &RelativeVar, resultType )) return;
|
---|
[3] | 368 |
|
---|
[75] | 369 | int beforeType = resultType.GetBasicType();
|
---|
[64] | 370 |
|
---|
[75] | 371 | resultType.PtrLevelUp();
|
---|
[46] | 372 |
|
---|
[3] | 373 | SetVarPtrToReg(REG_RAX,&RelativeVar);
|
---|
[64] | 374 |
|
---|
[109] | 375 | // TODO: 取り除く(この動きはObjPtrに託す)
|
---|
[130] | 376 | /*
|
---|
[64] | 377 | if( beforeType == DEF_OBJECT && lstrcmpi( Parameter, "This" ) != 0 ){
|
---|
| 378 | //参照をオブジェクトポインタに変更
|
---|
| 379 |
|
---|
| 380 | //mov rax,qword ptr[rax]
|
---|
[226] | 381 | compiler.codeGenerator.op_mov_RM( sizeof(_int64), REG_RAX, REG_RAX, 0, MOD_BASE );
|
---|
[111] | 382 |
|
---|
| 383 | SetError(-120,NULL,cp);
|
---|
[130] | 384 | }*/
|
---|
[3] | 385 | }
|
---|
[109] | 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 |
|
---|
[111] | 409 | if( lstrcmpi( Parameter, "This" )==0 ){
|
---|
| 410 | // Thisの場合は特別にオブジェクトポインタが返ってくるので、何もせずに抜ける
|
---|
| 411 | }
|
---|
| 412 | else if( beforeType == DEF_OBJECT ){
|
---|
[109] | 413 | //参照をオブジェクトポインタに変更
|
---|
| 414 |
|
---|
| 415 | //mov rax,qword ptr[rax]
|
---|
[226] | 416 | compiler.codeGenerator.op_mov_RM( sizeof(_int64), REG_RAX, REG_RAX, 0, MOD_BASE );
|
---|
[109] | 417 | }
|
---|
| 418 | else{
|
---|
| 419 | SetError(134,NULL,cp );
|
---|
| 420 | }
|
---|
| 421 | }
|
---|
[325] | 422 |
|
---|
[330] | 423 | void Opcode_Func_delegate_call( const char *paramsStr, Type &resultType, bool isDynamicCall, bool isCallOn )
|
---|
[325] | 424 | {
|
---|
| 425 | if( isCallOn )
|
---|
| 426 | {
|
---|
| 427 | int i = 0;
|
---|
[330] | 428 | char methodPtrParamStr[VN_SIZE];
|
---|
| 429 | i = GetOneParameter( paramsStr, i, methodPtrParamStr );
|
---|
| 430 |
|
---|
[339] | 431 | char objPtrValueStr[VN_SIZE] = "";
|
---|
[330] | 432 | if( isDynamicCall )
|
---|
| 433 | {
|
---|
| 434 | i = GetOneParameter( paramsStr, i, objPtrValueStr );
|
---|
| 435 | }
|
---|
| 436 |
|
---|
| 437 | Opcode_CallDelegate( compiler.pCompilingClass->GetDelegate(), methodPtrParamStr, objPtrValueStr, paramsStr + i );
|
---|
[325] | 438 | }
|
---|
| 439 |
|
---|
| 440 | resultType = UserProc::CompilingUserProc().ReturnType();
|
---|
| 441 | }
|
---|
| 442 |
|
---|
[46] | 443 | void Opcode_Func_GetPtrData( const char *Parameter, const int type ){
|
---|
[3] | 444 | int reg=REG_RAX;
|
---|
[75] | 445 | Type tempType;
|
---|
| 446 | if( !NumOpe(®,Parameter,Type(),tempType) ){
|
---|
| 447 | return;
|
---|
| 448 | }
|
---|
| 449 | if(!tempType.IsWhole()){
|
---|
[3] | 450 | SetError(11,Parameter,cp);
|
---|
| 451 | return;
|
---|
| 452 | }
|
---|
| 453 |
|
---|
| 454 | if(type==DEF_DOUBLE){
|
---|
| 455 | //movlpd xmm0,qword ptr[rax]
|
---|
[226] | 456 | compiler.codeGenerator.op_movlpd_RM(REG_XMM0,REG_RAX,0,MOD_BASE);
|
---|
[3] | 457 | }
|
---|
| 458 | else if(type==DEF_SINGLE){
|
---|
| 459 | //movss xmm0,dword ptr[rax]
|
---|
[226] | 460 | compiler.codeGenerator.op_movss_RM(REG_XMM0,REG_RAX,0,MOD_BASE);
|
---|
[3] | 461 | }
|
---|
| 462 | else{
|
---|
| 463 | //mov rax,ptr[rax]
|
---|
[308] | 464 | compiler.codeGenerator.op_mov_RM(Type(type).GetSize(),REG_RAX,REG_RAX,0,MOD_BASE);
|
---|
[3] | 465 | }
|
---|
| 466 | }
|
---|
| 467 |
|
---|
[331] | 468 | bool Opcode_CallFunc( const char *Parameter, const int FuncNum, const Type &baseType, Type &resultType, bool isCallOn )
|
---|
| 469 | {
|
---|
[3] | 470 | switch(FuncNum){
|
---|
| 471 | case FUNC_LEN:
|
---|
[75] | 472 | if( isCallOn ) Opcode_Func_Len(Parameter);
|
---|
| 473 | resultType.SetBasicType( DEF_LONG );
|
---|
[46] | 474 | break;
|
---|
[3] | 475 | case FUNC_ADDRESSOF:
|
---|
[339] | 476 | Opcode_Func_AddressOf( Parameter, baseType, isCallOn, resultType );
|
---|
[46] | 477 | break;
|
---|
[3] | 478 | case FUNC_SIZEOF:
|
---|
[75] | 479 | if( isCallOn ) Opcode_Func_SizeOf(Parameter);
|
---|
| 480 | resultType.SetBasicType( DEF_LONG );
|
---|
[46] | 481 | break;
|
---|
[3] | 482 | case FUNC_VARPTR:
|
---|
[75] | 483 | Opcode_Func_VarPtr( Parameter, resultType, isCallOn );
|
---|
[46] | 484 | break;
|
---|
[109] | 485 | case FUNC_OBJPTR:
|
---|
| 486 | Opcode_Func_ObjPtr( Parameter, resultType, isCallOn );
|
---|
| 487 | break;
|
---|
[330] | 488 | case FUNC_DELEGATE_DYNAMICMETHOD_CALL:
|
---|
| 489 | Opcode_Func_delegate_call( Parameter, resultType, true, isCallOn );
|
---|
[325] | 490 | break;
|
---|
[330] | 491 | case FUNC_DELEGATE_STATICMETHOD_CALL:
|
---|
| 492 | Opcode_Func_delegate_call( Parameter, resultType, false, isCallOn );
|
---|
| 493 | break;
|
---|
[3] | 494 |
|
---|
| 495 | case FUNC_GETDOUBLE:
|
---|
[75] | 496 | if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_DOUBLE);
|
---|
| 497 | resultType.SetBasicType( DEF_DOUBLE );
|
---|
[46] | 498 | break;
|
---|
[3] | 499 | case FUNC_GETSINGLE:
|
---|
[75] | 500 | if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_SINGLE);
|
---|
| 501 | resultType.SetBasicType( DEF_SINGLE );
|
---|
[46] | 502 | break;
|
---|
[3] | 503 | case FUNC_GETQWORD:
|
---|
[75] | 504 | if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_QWORD);
|
---|
| 505 | resultType.SetBasicType( DEF_QWORD );
|
---|
[46] | 506 | break;
|
---|
[3] | 507 | case FUNC_GETDWORD:
|
---|
[75] | 508 | if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_DWORD);
|
---|
| 509 | resultType.SetBasicType( DEF_DWORD );
|
---|
[46] | 510 | break;
|
---|
[3] | 511 | case FUNC_GETWORD:
|
---|
[75] | 512 | if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_WORD);
|
---|
| 513 | resultType.SetBasicType( DEF_WORD );
|
---|
[46] | 514 | break;
|
---|
[3] | 515 | case FUNC_GETBYTE:
|
---|
[75] | 516 | if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_BYTE);
|
---|
| 517 | resultType.SetBasicType( DEF_BYTE );
|
---|
[46] | 518 | break;
|
---|
[75] | 519 | default:
|
---|
| 520 | return false;
|
---|
[3] | 521 | }
|
---|
[75] | 522 | return true;
|
---|
[3] | 523 | }
|
---|