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