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