[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 | void Call_DebugSys_SaveContext(){
|
---|
| 11 | //call _System_GetEip
|
---|
[206] | 12 | extern const UserProc *pSub_System_GetEip;
|
---|
[226] | 13 | compiler.codeGenerator.op_call(pSub_System_GetEip);
|
---|
[3] | 14 |
|
---|
| 15 | //mov rdx,rax
|
---|
[226] | 16 | compiler.codeGenerator.op_mov_RR(REG_RDX,REG_RAX);
|
---|
[3] | 17 |
|
---|
| 18 | //mov rcx,rsp
|
---|
[226] | 19 | compiler.codeGenerator.op_mov_RR(REG_RCX,REG_RSP);
|
---|
[3] | 20 |
|
---|
| 21 | //call _DebugSys_SaveContext
|
---|
[206] | 22 | extern const UserProc *pSub_DebugSys_SaveContext;
|
---|
[226] | 23 | compiler.codeGenerator.op_call(pSub_DebugSys_SaveContext);
|
---|
[3] | 24 | }
|
---|
| 25 |
|
---|
[330] | 26 | bool Opcode_CallProcPtr( const char *variable, const char *lpszParms,ProcPointer *pProcPointer)
|
---|
| 27 | {
|
---|
[3] | 28 | extern BOOL bDebugCompile;
|
---|
| 29 | extern BOOL bDebugSupportProc;
|
---|
| 30 | if(bDebugCompile&&bDebugSupportProc==0)
|
---|
| 31 | Call_DebugSys_SaveContext();
|
---|
| 32 |
|
---|
| 33 |
|
---|
| 34 | ////////////////////////
|
---|
| 35 | // パラメータのセット
|
---|
| 36 | ////////////////////////
|
---|
| 37 |
|
---|
| 38 | //パラメータオブジェクトを生成
|
---|
[71] | 39 | ParamImpl *pobj_parameter=0;
|
---|
[75] | 40 | pobj_parameter=new ParamImpl(lpszParms);
|
---|
[3] | 41 |
|
---|
[77] | 42 | // デフォルト引数を適用
|
---|
| 43 | pobj_parameter->ApplyDefaultParameters( pProcPointer->Params() );
|
---|
| 44 |
|
---|
[3] | 45 | //エラーチェック
|
---|
[75] | 46 | if( !pobj_parameter->ErrorCheck(variable,pProcPointer->Params() ) ){
|
---|
[31] | 47 | //パラメータにエラーがあるときは処理を終える
|
---|
[75] | 48 | return false;
|
---|
[31] | 49 | }
|
---|
[3] | 50 |
|
---|
| 51 | //スタックフレームに存在する既存のパラメータをバックアップ
|
---|
[75] | 52 | pobj_parameter->BackupParameter( (int)pProcPointer->Params().size() );
|
---|
[3] | 53 |
|
---|
[20] | 54 | //一時オブジェクトを生成
|
---|
[75] | 55 | pobj_parameter->NewTempParameters( variable,pProcPointer->Params() );
|
---|
[20] | 56 |
|
---|
[3] | 57 | //レジスタ、スタックフレームにセット
|
---|
[75] | 58 | pobj_parameter->SetParameter(variable,pProcPointer->Params() );
|
---|
[3] | 59 |
|
---|
| 60 |
|
---|
| 61 |
|
---|
| 62 | RELATIVE_VAR RelativeVar;
|
---|
[75] | 63 | GetVarOffsetReadOnly(variable,&RelativeVar,Type());
|
---|
[3] | 64 | SetVarPtrToReg(REG_RAX,&RelativeVar);
|
---|
| 65 |
|
---|
| 66 | //mov rax,qword ptr[rax]
|
---|
[226] | 67 | compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_RAX,REG_RAX,0,MOD_BASE);
|
---|
[3] | 68 |
|
---|
| 69 | //call rax
|
---|
[228] | 70 | compiler.codeGenerator.PutOld(
|
---|
| 71 | (char)0xFF,
|
---|
| 72 | (char)0xD0
|
---|
| 73 | );
|
---|
[3] | 74 |
|
---|
| 75 |
|
---|
| 76 | //レジスタのブロッキングを解除 ※パラメータセット時にロックされたレジスタ
|
---|
| 77 | pobj_BlockReg->clear();
|
---|
| 78 |
|
---|
[20] | 79 | //一時オブジェクトを破棄
|
---|
| 80 | pobj_parameter->DeleteTempParameters();
|
---|
| 81 |
|
---|
[3] | 82 | //スタックフレームに存在する既存のパラメータを復元
|
---|
[75] | 83 | pobj_parameter->RestoreParameter( (int)pProcPointer->Params().size() );
|
---|
[3] | 84 |
|
---|
| 85 | //パラメータオブジェクトを破棄
|
---|
| 86 | delete pobj_parameter;
|
---|
| 87 |
|
---|
[75] | 88 | return true;
|
---|
[3] | 89 | }
|
---|
| 90 |
|
---|
[345] | 91 | bool Opcode_CallProc(const char *Parameter,const UserProc *pUserProc,DWORD dwFlags,const char *ObjectName)
|
---|
| 92 | {
|
---|
[75] | 93 | if( pUserProc->IsMacro() ){
|
---|
| 94 | if( lstrcmpi( pUserProc->GetName().c_str(), "Print" ) == 0 ){
|
---|
[3] | 95 | Opcode_Print(Parameter,0);
|
---|
[75] | 96 | return true;
|
---|
[3] | 97 | }
|
---|
[75] | 98 | if( lstrcmpi( pUserProc->GetName().c_str(), "Input" ) == 0 ){
|
---|
[3] | 99 | Opcode_Input(Parameter);
|
---|
[75] | 100 | return true;
|
---|
[3] | 101 | }
|
---|
[75] | 102 | if( lstrcmpi( pUserProc->GetName().c_str(), "Write" ) == 0 ){
|
---|
[3] | 103 | Opcode_Print(Parameter,1);
|
---|
[75] | 104 | return true;
|
---|
[3] | 105 | }
|
---|
| 106 | }
|
---|
| 107 |
|
---|
[75] | 108 | pUserProc->Using();
|
---|
[3] | 109 |
|
---|
[47] | 110 | bool isStatic = false;
|
---|
[75] | 111 | const CClass *pobj_c = NULL;
|
---|
[135] | 112 | const CMethod *pMethod = NULL;
|
---|
[304] | 113 | Type leftType;
|
---|
| 114 | bool isFixedClass = false;
|
---|
[75] | 115 | if( pUserProc->GetParentClassPtr() ){
|
---|
[3] | 116 | //クラスのメンバ関数を呼び出す場合はアクセスチェックを行う
|
---|
[304] | 117 | if(ObjectName[0] && (dwFlags&PROCFLAG_NEW)==0)
|
---|
| 118 | {
|
---|
| 119 | if(lstrcmpi(ObjectName,"Super")==0)
|
---|
| 120 | {
|
---|
[27] | 121 | //クラスメンバ関数内から基底クラスの呼び出し
|
---|
[304] | 122 | pobj_c=&compiler.pCompilingClass->GetSuperClass();
|
---|
| 123 |
|
---|
| 124 | isFixedClass = true;
|
---|
[3] | 125 | }
|
---|
[304] | 126 | else
|
---|
| 127 | {
|
---|
[47] | 128 | //"->"によってオブジェクトを指定する通常のメンバ関数呼び出し
|
---|
[75] | 129 | Type varType;
|
---|
[416] | 130 | if( GetTermType( ObjectName, varType ) )
|
---|
[308] | 131 | {
|
---|
[416] | 132 | if( varType.IsObject() )
|
---|
| 133 | {
|
---|
| 134 | pobj_c = &varType.GetClass();
|
---|
| 135 | leftType = varType;
|
---|
| 136 | }
|
---|
[308] | 137 | }
|
---|
[416] | 138 |
|
---|
| 139 | if( !pobj_c )
|
---|
[308] | 140 | {
|
---|
[266] | 141 | pobj_c=compiler.GetObjectModule().meta.GetClasses().Find(ObjectName);
|
---|
[47] | 142 | if( pobj_c ){
|
---|
| 143 | isStatic = true;
|
---|
| 144 | }
|
---|
| 145 | else{
|
---|
| 146 | SetError(300,NULL,cp);
|
---|
| 147 | }
|
---|
[3] | 148 | }
|
---|
| 149 | }
|
---|
| 150 | }
|
---|
| 151 | else{
|
---|
| 152 | if(dwFlags&PROCFLAG_NEW){
|
---|
[316] | 153 | GetVarType( ObjectName, leftType, false );
|
---|
| 154 |
|
---|
[3] | 155 | //New演算子によるコンストラクタ呼び出し
|
---|
[75] | 156 | pobj_c=pUserProc->GetParentClassPtr();
|
---|
[3] | 157 | }
|
---|
| 158 | else{
|
---|
| 159 | //クラスメンバ関数内から同一クラスのメンバ関数の呼び出し
|
---|
[206] | 160 | pobj_c=compiler.pCompilingClass;
|
---|
[3] | 161 | }
|
---|
| 162 | }
|
---|
| 163 |
|
---|
[18] | 164 |
|
---|
| 165 | /////////////////////////////////
|
---|
| 166 | // メソッド情報を取得
|
---|
| 167 | /////////////////////////////////
|
---|
[27] | 168 | pMethod = NULL;
|
---|
[350] | 169 | if( ! isStatic ) pMethod = pobj_c->GetDynamicMethodOrInterfaceMethod( pUserProc );
|
---|
[27] | 170 | if( ! pMethod ){
|
---|
[18] | 171 | //動的メソッドが取得できなかったときは静的メソッドを当たる
|
---|
[135] | 172 | pMethod = pobj_c->GetStaticMethods().GetMethodPtr( pUserProc );
|
---|
[18] | 173 | if( !pMethod ){
|
---|
| 174 | SetError(300,NULL,cp);
|
---|
[75] | 175 | return false;
|
---|
[3] | 176 | }
|
---|
[26] | 177 |
|
---|
| 178 | //静的メンバ
|
---|
[47] | 179 | isStatic = true;
|
---|
[3] | 180 | }
|
---|
| 181 |
|
---|
| 182 |
|
---|
| 183 | //////////////////////////////
|
---|
| 184 | // アクセスエラーチェック
|
---|
| 185 | //////////////////////////////
|
---|
| 186 |
|
---|
| 187 | if(ObjectName[0]){
|
---|
| 188 | //外部からの呼び出し
|
---|
[206] | 189 | if(pobj_c==compiler.pCompilingClass){
|
---|
[3] | 190 | //同一クラスオブジェクトの場合はプライベートアクセスを容認する
|
---|
[137] | 191 | if( pMethod->IsNoneAccess() ){
|
---|
[75] | 192 | SetError(109,pUserProc->GetName(),cp);
|
---|
| 193 | return false;
|
---|
[3] | 194 | }
|
---|
| 195 | }
|
---|
| 196 | else{
|
---|
[137] | 197 | if( pMethod->IsPrivate()
|
---|
| 198 | || pMethod->IsNoneAccess() ){
|
---|
[75] | 199 | SetError(109,pUserProc->GetName(),cp);
|
---|
| 200 | return false;
|
---|
[3] | 201 | }
|
---|
[339] | 202 | if( !pMethod->GetUserProc().GetParentClass().IsEqualsOrSubClass( pobj_c ) && pMethod->IsProtected() ){
|
---|
[75] | 203 | SetError(110,pUserProc->GetName(),cp);
|
---|
| 204 | return false;
|
---|
[3] | 205 | }
|
---|
| 206 | }
|
---|
| 207 | }
|
---|
| 208 | else{
|
---|
| 209 | //クラス内部からの呼び出し(継承によるACCESS_NONのみをエラーとする)
|
---|
[137] | 210 | if( pMethod->IsNoneAccess() ){
|
---|
[75] | 211 | SetError(109,pUserProc->GetName(),cp);
|
---|
| 212 | return false;
|
---|
[3] | 213 | }
|
---|
| 214 | }
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 |
|
---|
| 218 | ///////////////////////////////////////////////////////////////
|
---|
[64] | 219 | // _System_LocalThisのダミーをセット
|
---|
[3] | 220 | ///////////////////////////////////////////////////////////////
|
---|
| 221 |
|
---|
| 222 | char temporary[VN_SIZE]={0};
|
---|
[75] | 223 | if( pUserProc->GetParentClassPtr() && isStatic == false ){
|
---|
[3] | 224 | //_System_LocalThis(第一パラメータ)のダミーを作成
|
---|
| 225 | lstrcpy(temporary,"0,");
|
---|
| 226 | }
|
---|
[320] | 227 | if( pUserProc->ReturnType().IsStruct() ){
|
---|
| 228 | // ※ByRef _System_ReturnValue パラメータのダミーをセット
|
---|
| 229 | lstrcat(temporary,"0,");
|
---|
| 230 | }
|
---|
[3] | 231 |
|
---|
| 232 | if(Parameter[0]=='\0'&&temporary[0])
|
---|
| 233 | temporary[lstrlen(temporary)-1]=0;
|
---|
| 234 | else lstrcat(temporary,Parameter);
|
---|
| 235 |
|
---|
| 236 |
|
---|
[64] | 237 | //パラメータセット前のspオフセットを取得(Newの場合はここにThisポインタが格納されている)
|
---|
| 238 | int this_sp_offset = pobj_sf->GetNowSp();
|
---|
| 239 |
|
---|
| 240 |
|
---|
[3] | 241 | ////////////////////////
|
---|
| 242 | // パラメータをセット
|
---|
| 243 | ////////////////////////
|
---|
| 244 |
|
---|
| 245 | //パラメータオブジェクトを生成
|
---|
[71] | 246 | ParamImpl *pobj_parameter=0;
|
---|
| 247 | pobj_parameter=new ParamImpl(temporary);
|
---|
[3] | 248 |
|
---|
[77] | 249 | // デフォルト引数を適用
|
---|
| 250 | pobj_parameter->ApplyDefaultParameters( pUserProc->RealParams() );
|
---|
| 251 |
|
---|
[316] | 252 | // 型パラメータを適用
|
---|
| 253 | pobj_parameter->SetLeftType( leftType );
|
---|
| 254 |
|
---|
[3] | 255 | //エラーチェック
|
---|
[75] | 256 | if( !pobj_parameter->ErrorCheck(pUserProc->GetName(),pUserProc->RealParams(),pUserProc->GetSecondParmNum() ) ){
|
---|
[31] | 257 | //パラメータにエラーがあるときは処理を終える
|
---|
[75] | 258 | return false;
|
---|
[31] | 259 | }
|
---|
[3] | 260 |
|
---|
[75] | 261 | if(pUserProc->IsMacro()){
|
---|
[3] | 262 | //マクロ関数の場合は、パラメータ省略を考慮する
|
---|
[75] | 263 | pobj_parameter->MacroParameterSupport( pUserProc->RealParams() );
|
---|
[3] | 264 | }
|
---|
| 265 |
|
---|
| 266 | //スタックフレームに存在する既存のパラメータをバックアップ
|
---|
[75] | 267 | pobj_parameter->BackupParameter( (int)pUserProc->RealParams().size() );
|
---|
[3] | 268 |
|
---|
[20] | 269 | //一時オブジェクトを生成
|
---|
[75] | 270 | pobj_parameter->NewTempParameters( pUserProc->GetName(),pUserProc->RealParams(),pUserProc->GetRealSecondParmNum() );
|
---|
[20] | 271 |
|
---|
[3] | 272 | //レジスタ、スタックフレームにセット
|
---|
[316] | 273 | pobj_parameter->SetParameter(pUserProc->GetName(),pUserProc->RealParams(),pUserProc->GetRealSecondParmNum(), pUserProc );
|
---|
[3] | 274 |
|
---|
[320] | 275 | if( pUserProc->ReturnType().IsStruct() ){
|
---|
[3] | 276 | //////////////////////////////////////////////////////
|
---|
[64] | 277 | // 戻り値に構造体インスタンスを持つ場合
|
---|
| 278 | // ※ByRef _System_ReturnValue パラメータをセット
|
---|
[3] | 279 | //////////////////////////////////////////////////////
|
---|
| 280 |
|
---|
| 281 |
|
---|
| 282 | //////////////////////////////////////////////////////
|
---|
| 283 | ///// レジスタ資源のバックアップ
|
---|
| 284 | { BACKUP_REGISTER_RESOURCE
|
---|
| 285 | //////////////////////////////////////////////////////
|
---|
| 286 |
|
---|
[75] | 287 | int object_size = pUserProc->ReturnType().GetClass().GetSize();
|
---|
[3] | 288 |
|
---|
| 289 | //mov rcx,object_size
|
---|
[226] | 290 | compiler.codeGenerator.op_mov_RV(sizeof(_int64),REG_RCX,object_size);
|
---|
[3] | 291 |
|
---|
| 292 | //call calloc
|
---|
[206] | 293 | extern const UserProc *pSub_calloc;
|
---|
[226] | 294 | compiler.codeGenerator.op_call(pSub_calloc);
|
---|
[3] | 295 |
|
---|
| 296 | //mov r13,rax
|
---|
[226] | 297 | compiler.codeGenerator.op_mov_RR(REG_R13,REG_RAX);
|
---|
[3] | 298 |
|
---|
| 299 | /////////////////////////////////////////////
|
---|
| 300 | ////// レジスタ資源を復元
|
---|
| 301 | RESTORE_REGISTER_RESOURCE
|
---|
| 302 | }////////////////////////////////////////////
|
---|
| 303 |
|
---|
[75] | 304 | if( pUserProc->GetParentClassPtr() && isStatic == false ){
|
---|
[3] | 305 | //mov rdx,r13
|
---|
[226] | 306 | compiler.codeGenerator.op_mov_RR(REG_RDX,REG_R13);
|
---|
[3] | 307 | }
|
---|
| 308 | else{
|
---|
| 309 | //mov rcx,r13
|
---|
[226] | 310 | compiler.codeGenerator.op_mov_RR(REG_RCX,REG_R13);
|
---|
[3] | 311 | }
|
---|
| 312 | }
|
---|
| 313 |
|
---|
| 314 |
|
---|
[75] | 315 | if( pUserProc->GetParentClassPtr() && isStatic == false ){
|
---|
[3] | 316 | ///////////////////////////////
|
---|
| 317 | // メンバ関数の場合
|
---|
| 318 | // thisポインタをrcxで受け渡す
|
---|
| 319 | ///////////////////////////////
|
---|
| 320 |
|
---|
[97] | 321 | if(ObjectName[0] && (dwFlags&PROCFLAG_NEW)==0){
|
---|
[3] | 322 | if(lstrcmpi(ObjectName,"Super")==0) goto InClassMember;
|
---|
| 323 | else{
|
---|
[416] | 324 | bool isLiteral;
|
---|
| 325 | if( !TermOpe( ObjectName, Type(), Type(), isLiteral, NULL, NULL, false, !pMethod->IsConst() ) )
|
---|
| 326 | {
|
---|
| 327 | return false;
|
---|
[18] | 328 | }
|
---|
| 329 |
|
---|
[416] | 330 | // 実態ポインタをraxにコピー
|
---|
| 331 | compiler.codeGenerator.op_mov_RR( REG_RCX, REG_RAX );
|
---|
[3] | 332 | }
|
---|
| 333 | }
|
---|
| 334 | else{
|
---|
| 335 | InClassMember:
|
---|
| 336 | if(dwFlags&PROCFLAG_NEW){
|
---|
| 337 | //New演算子によるコンストラクタ呼び出しの場合
|
---|
| 338 |
|
---|
| 339 | //mov rcx,qword ptr[rsp+offset] ※スタックフレームを利用
|
---|
[64] | 340 | pobj_sf->ref_offset_data(REG_RCX, this_sp_offset);
|
---|
[3] | 341 | }
|
---|
| 342 | else{
|
---|
| 343 | //自身のオブジェクトのThisポインタをrcxにコピー
|
---|
| 344 | SetThisPtrToReg(REG_RCX);
|
---|
| 345 | }
|
---|
| 346 | }
|
---|
| 347 | }
|
---|
| 348 |
|
---|
[304] | 349 | if( pUserProc->IsVirtual() && !isFixedClass ){
|
---|
[349] | 350 | int vtblIndex;
|
---|
| 351 | if( pobj_c->IsInterface() )
|
---|
| 352 | {
|
---|
[370] | 353 | // インターフェイス メソッド呼び出し
|
---|
[3] | 354 |
|
---|
[349] | 355 | int offset_vtbl = compiler.GetObjectModule().meta.GetClasses().GetInterfaceInfoClassPtr()->GetMemberOffset( "__vtbl" );
|
---|
[348] | 356 |
|
---|
[349] | 357 | // vtblのポインタを取得
|
---|
| 358 | //mov r11,qword ptr[rcx+offset_vtbl]
|
---|
| 359 | compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_RCX,offset_vtbl,MOD_BASE_DISP8);
|
---|
[3] | 360 |
|
---|
[349] | 361 | int offset_this = compiler.GetObjectModule().meta.GetClasses().GetInterfaceInfoClassPtr()->GetMemberOffset( "__this" );
|
---|
[3] | 362 |
|
---|
[349] | 363 | // インターフェイスの場合は更に__thisを取得する
|
---|
| 364 | //mov rcx,qword ptr[rcx+offset_this]
|
---|
| 365 | compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_RCX,REG_RCX,offset_this,MOD_BASE_DISP8);
|
---|
| 366 |
|
---|
| 367 | int vtblMasterListIndex;
|
---|
| 368 | pobj_c->GetVtblMasterListIndexAndVtblIndex( pUserProc, vtblMasterListIndex, vtblIndex );
|
---|
| 369 | if( vtblMasterListIndex != 0 )
|
---|
| 370 | {
|
---|
| 371 | SetError();
|
---|
| 372 | }
|
---|
| 373 | }
|
---|
[370] | 374 | else if( pobj_c->IsComInterface() )
|
---|
| 375 | {
|
---|
| 376 | // COMインターフェイス メソッド呼び出し
|
---|
| 377 |
|
---|
| 378 | //仮想関数(オブジェクトメソッド)呼び出し
|
---|
| 379 | // pObj -> vtbl1 -> func1
|
---|
| 380 | // -> func2
|
---|
| 381 | // -> func3
|
---|
| 382 |
|
---|
| 383 | int vtblMasterListIndex;
|
---|
| 384 | pobj_c->GetVtblMasterListIndexAndVtblIndex( pUserProc, vtblMasterListIndex, vtblIndex );
|
---|
| 385 |
|
---|
| 386 | // vtblのポインタを取得
|
---|
| 387 | //mov r11,qword ptr[rcx]
|
---|
| 388 | compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_RCX,0,MOD_BASE); }
|
---|
[349] | 389 | else
|
---|
| 390 | {
|
---|
| 391 | //仮想関数(オブジェクトメソッド)呼び出し
|
---|
| 392 | // pObj -> vtbl_master_list -> vtbl1 -> func1
|
---|
| 393 | // -> func2
|
---|
| 394 | // -> func3
|
---|
| 395 | // -> vtbl2 -> func1
|
---|
| 396 | // -> func2
|
---|
| 397 | // -> func3
|
---|
| 398 |
|
---|
| 399 | int vtblMasterListIndex;
|
---|
| 400 | pobj_c->GetVtblMasterListIndexAndVtblIndex( pUserProc, vtblMasterListIndex, vtblIndex );
|
---|
| 401 |
|
---|
| 402 | // vtblマスターリストのポインタを取得
|
---|
[370] | 403 | //mov r11,qword ptr[rcx+sizeof(com_vtbl)]
|
---|
| 404 | compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_RCX,PTR_SIZE,MOD_BASE_DISP8);
|
---|
[349] | 405 |
|
---|
| 406 | // vtblのポインタを取得
|
---|
| 407 | //mov r11,dword ptr[r11+vtblMasterListIndex]
|
---|
| 408 | compiler.codeGenerator.op_mov_RM( sizeof(_int64), REG_R11, REG_R11, vtblMasterListIndex*PTR_SIZE, MOD_BASE_DISP32 );
|
---|
| 409 | }
|
---|
| 410 |
|
---|
[3] | 411 | //call qword ptr[r11+func_index]
|
---|
[345] | 412 | if( vtblIndex * PTR_SIZE <= 0x7F ){
|
---|
[228] | 413 | compiler.codeGenerator.PutOld(
|
---|
| 414 | (char)0x41,
|
---|
| 415 | (char)0xFF,
|
---|
| 416 | (char)0x53,
|
---|
[345] | 417 | (char)(vtblIndex*PTR_SIZE)
|
---|
[228] | 418 | );
|
---|
[3] | 419 | }
|
---|
| 420 | else{
|
---|
[228] | 421 | compiler.codeGenerator.PutOld(
|
---|
| 422 | (char)0x41,
|
---|
| 423 | (char)0xFF,
|
---|
| 424 | (char)0x93,
|
---|
[345] | 425 | (long)(vtblIndex*PTR_SIZE)
|
---|
[228] | 426 | );
|
---|
[3] | 427 | }
|
---|
| 428 | }
|
---|
| 429 | else{
|
---|
| 430 | //通常呼び出し
|
---|
| 431 |
|
---|
| 432 | //call ProcAddr
|
---|
[226] | 433 | compiler.codeGenerator.op_call(pUserProc);
|
---|
[3] | 434 | }
|
---|
| 435 |
|
---|
| 436 | /* 64コンパイラでは不要
|
---|
[75] | 437 | if(pDllProc->bCdecl){
|
---|
[3] | 438 | //add esp,ParmSize
|
---|
| 439 | }*/
|
---|
| 440 |
|
---|
| 441 |
|
---|
| 442 | //レジスタのブロッキングを解除 ※パラメータセット時にロックされたレジスタ
|
---|
| 443 | pobj_BlockReg->clear();
|
---|
| 444 |
|
---|
[20] | 445 | //一時オブジェクトを破棄
|
---|
| 446 | pobj_parameter->DeleteTempParameters();
|
---|
| 447 |
|
---|
[3] | 448 | //スタックフレームに存在する既存のパラメータを復元
|
---|
[75] | 449 | pobj_parameter->RestoreParameter( (int)pUserProc->RealParams().size() );
|
---|
[3] | 450 |
|
---|
| 451 | //パラメータオブジェクトを破棄
|
---|
| 452 | delete pobj_parameter;
|
---|
[75] | 453 |
|
---|
| 454 | return true;
|
---|
[3] | 455 | }
|
---|
| 456 |
|
---|
[75] | 457 | bool Opcode_CallDllProc( const char *lpszParms, DllProc *pDllProc ){
|
---|
[3] | 458 |
|
---|
| 459 | extern BOOL bDebugCompile;
|
---|
| 460 | extern BOOL bDebugSupportProc;
|
---|
[75] | 461 | if(bDebugCompile&&bDebugSupportProc==0&& pDllProc->GetName() != "DebugBreak" ){
|
---|
[3] | 462 | Call_DebugSys_SaveContext();
|
---|
[75] | 463 | }
|
---|
[3] | 464 |
|
---|
| 465 |
|
---|
| 466 | ////////////////////////
|
---|
| 467 | // パラメータのセット
|
---|
| 468 | ////////////////////////
|
---|
| 469 |
|
---|
| 470 | //パラメータオブジェクトを生成
|
---|
[71] | 471 | ParamImpl *pobj_parameter=0;
|
---|
[75] | 472 | pobj_parameter=new ParamImpl(lpszParms);
|
---|
[3] | 473 |
|
---|
[77] | 474 | // デフォルト引数を適用
|
---|
| 475 | pobj_parameter->ApplyDefaultParameters( pDllProc->Params() );
|
---|
| 476 |
|
---|
[3] | 477 | //エラーチェック
|
---|
[75] | 478 | if( !pobj_parameter->ErrorCheck( pDllProc->GetName(), pDllProc->Params() ) ){
|
---|
[31] | 479 | //パラメータにエラーがあるときは処理を終える
|
---|
[75] | 480 | return false;
|
---|
[31] | 481 | }
|
---|
[3] | 482 |
|
---|
| 483 | //スタックフレームに存在する既存のパラメータをバックアップ
|
---|
[75] | 484 | pobj_parameter->BackupParameter( (int)pDllProc->Params().size() );
|
---|
[3] | 485 |
|
---|
[45] | 486 | //一時オブジェクトを生成
|
---|
[75] | 487 | pobj_parameter->NewTempParameters( pDllProc->GetName(), pDllProc->Params() );
|
---|
[45] | 488 |
|
---|
[3] | 489 | //レジスタ、スタックフレームにセット
|
---|
[75] | 490 | pobj_parameter->SetParameter(pDllProc->GetName(), pDllProc->Params() );
|
---|
[3] | 491 |
|
---|
| 492 |
|
---|
| 493 | //レジスタのブロッキングを解除 ※パラメータセット時にロックされたレジスタ
|
---|
| 494 | pobj_BlockReg->clear();
|
---|
| 495 |
|
---|
| 496 |
|
---|
| 497 | //動的リンクされたプロシージャの呼び出し
|
---|
| 498 |
|
---|
| 499 | //call dword ptr[ImportTable]
|
---|
[226] | 500 | compiler.codeGenerator.op_call( pDllProc );
|
---|
[3] | 501 |
|
---|
| 502 | /* 64コンパイラでは不要
|
---|
[75] | 503 | if(pDllProc->bCdecl){
|
---|
[3] | 504 | //add esp,ParmSize
|
---|
| 505 | }*/
|
---|
| 506 |
|
---|
[45] | 507 | //一時オブジェクトを破棄
|
---|
| 508 | pobj_parameter->DeleteTempParameters();
|
---|
| 509 |
|
---|
[3] | 510 | //スタックフレームに存在する既存のパラメータを復元
|
---|
[75] | 511 | pobj_parameter->RestoreParameter( (int)pDllProc->Params().size() );
|
---|
[3] | 512 |
|
---|
| 513 | //パラメータオブジェクトを破棄
|
---|
| 514 | delete pobj_parameter;
|
---|
| 515 |
|
---|
[75] | 516 | return true;
|
---|
[3] | 517 | }
|
---|
[325] | 518 |
|
---|
[330] | 519 | void Opcode_CallDelegate( const Delegate &dg, const char *methodPtrValueStr, const char *objPtrValueStr, const char *params )
|
---|
[325] | 520 | {
|
---|
[339] | 521 | extern BOOL bDebugCompile;
|
---|
| 522 | extern BOOL bDebugSupportProc;
|
---|
| 523 | if(bDebugCompile&&bDebugSupportProc==0)
|
---|
| 524 | Call_DebugSys_SaveContext();
|
---|
| 525 |
|
---|
| 526 |
|
---|
[330] | 527 | ///////////////////////////////////////////////////////////////
|
---|
| 528 | // _System_LocalThisのダミーをセット
|
---|
| 529 | ///////////////////////////////////////////////////////////////
|
---|
| 530 |
|
---|
| 531 | char temporary[VN_SIZE]={0};
|
---|
[339] | 532 | bool isDynamicCall = false;
|
---|
[330] | 533 | if( objPtrValueStr && objPtrValueStr[0] ){
|
---|
| 534 | //_System_LocalThis(第一パラメータ)のダミーを作成
|
---|
| 535 | lstrcpy(temporary,"0,");
|
---|
[339] | 536 |
|
---|
| 537 | isDynamicCall = true;
|
---|
[330] | 538 | }
|
---|
| 539 | if( dg.ReturnType().IsStruct() ){
|
---|
| 540 | // ※ByRef _System_ReturnValue パラメータのダミーをセット
|
---|
| 541 | lstrcat(temporary,"0,");
|
---|
| 542 | }
|
---|
| 543 |
|
---|
| 544 | if(params[0]=='\0'&&temporary[0])
|
---|
| 545 | temporary[lstrlen(temporary)-1]=0;
|
---|
| 546 | else lstrcat(temporary,params);
|
---|
| 547 |
|
---|
[339] | 548 | const Parameters *pParams = &dg.Params();
|
---|
| 549 | if( isDynamicCall )
|
---|
| 550 | {
|
---|
| 551 | pParams = &dg.GetDynamicParams();
|
---|
| 552 | }
|
---|
[330] | 553 |
|
---|
| 554 |
|
---|
[339] | 555 | ParamImpl *pobj_parameter = new ParamImpl( temporary );
|
---|
| 556 |
|
---|
[330] | 557 | //スタックフレームに存在する既存のパラメータをバックアップ
|
---|
[339] | 558 | pobj_parameter->BackupParameter( (int)pParams->size() );
|
---|
[330] | 559 |
|
---|
| 560 | //一時オブジェクトを生成
|
---|
[339] | 561 | pobj_parameter->NewTempParameters( dg.GetName(), *pParams );
|
---|
[330] | 562 |
|
---|
| 563 | //レジスタ、スタックフレームにセット
|
---|
[339] | 564 | pobj_parameter->SetParameter( dg.GetName(), *pParams );
|
---|
[330] | 565 |
|
---|
| 566 |
|
---|
| 567 | if( objPtrValueStr && objPtrValueStr[0] )
|
---|
| 568 | {
|
---|
| 569 | RELATIVE_VAR RelativeVar;
|
---|
| 570 | //Constアクセスが不可能なメソッドの場合
|
---|
| 571 | if( !GetVarOffsetReadWrite( objPtrValueStr, &RelativeVar, Type() ) ){
|
---|
| 572 | Jenga::Throw( "Opcode_CallDelegate関数内で呼ばれるGetVarOffsetReadWrite関数に失敗" );
|
---|
| 573 | return;
|
---|
| 574 | }
|
---|
| 575 |
|
---|
| 576 | SetVarPtrToReg(REG_RCX,&RelativeVar);
|
---|
| 577 |
|
---|
| 578 | // 参照を実体ポインタにする
|
---|
| 579 | //mov rcx,qword ptr[rcx]
|
---|
| 580 | compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_RCX,REG_RCX,0,MOD_BASE);
|
---|
| 581 | }
|
---|
| 582 |
|
---|
| 583 |
|
---|
| 584 | {
|
---|
| 585 | ////////////////////////
|
---|
| 586 | // call
|
---|
| 587 | ////////////////////////
|
---|
| 588 | RELATIVE_VAR RelativeVar;
|
---|
| 589 | GetVarOffsetReadOnly( methodPtrValueStr, &RelativeVar, Type() );
|
---|
| 590 | SetVarPtrToReg(REG_RAX,&RelativeVar);
|
---|
| 591 |
|
---|
| 592 | //mov rax,qword ptr[rax]
|
---|
| 593 | compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_RAX,REG_RAX,0,MOD_BASE);
|
---|
| 594 |
|
---|
| 595 | //call rax
|
---|
| 596 | compiler.codeGenerator.PutOld(
|
---|
| 597 | (char)0xFF,
|
---|
| 598 | (char)0xD0
|
---|
| 599 | );
|
---|
| 600 | }
|
---|
| 601 |
|
---|
| 602 |
|
---|
| 603 | //レジスタのブロッキングを解除 ※パラメータセット時にロックされたレジスタ
|
---|
| 604 | pobj_BlockReg->clear();
|
---|
| 605 |
|
---|
| 606 | //一時オブジェクトを破棄
|
---|
| 607 | pobj_parameter->DeleteTempParameters();
|
---|
| 608 |
|
---|
| 609 | //スタックフレームに存在する既存のパラメータを復元
|
---|
[339] | 610 | pobj_parameter->RestoreParameter( (int)pParams->size() );
|
---|
[330] | 611 |
|
---|
| 612 | //パラメータオブジェクトを破棄
|
---|
| 613 | delete pobj_parameter;
|
---|
[325] | 614 | }
|
---|