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