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