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