[206] | 1 | #include "stdafx.h"
|
---|
| 2 |
|
---|
[183] | 3 | #include <jenga/include/smoothie/Smoothie.h>
|
---|
| 4 |
|
---|
[193] | 5 | #include <Compiler.h>
|
---|
| 6 |
|
---|
[3] | 7 | #include "../BasicCompiler_Common/common.h"
|
---|
| 8 | #include "Opcode.h"
|
---|
| 9 |
|
---|
| 10 | int GetFunctionFromName(char *FuncName){
|
---|
[325] | 11 | if( lstrcmpi( FuncName, "CUDbl" ) == 0 ) return FUNC_CUDBL;
|
---|
| 12 | if( lstrcmpi( FuncName, "Fix" ) == 0 ) return FUNC_FIX;
|
---|
| 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, "VarPtr" ) == 0 ) return FUNC_VARPTR;
|
---|
| 17 | if( lstrcmpi( FuncName, "ObjPtr" ) == 0 ) return FUNC_OBJPTR;
|
---|
| 18 | if( lstrcmpi( FuncName, "__delegate_dynamicmethod_call" ) == 0 ) return FUNC_DELEGATE_DYNAMICMETHOD_CALL;
|
---|
| 19 | if( lstrcmpi( FuncName, "__delegate_staticmethod_call" ) == 0 ) return FUNC_DELEGATE_STATICMETHOD_CALL;
|
---|
[357] | 20 | if( lstrcmpi( FuncName, "_System_GetNowScopeCatchAddresses" ) == 0 )return FUNC_SYSTEM_GET_NOW_SCOPE_CATCH_ADDRESS;
|
---|
[359] | 21 | if( lstrcmpi( FuncName, "_System_GetNowScopeFinallyAddresses" ) == 0 )return FUNC_SYSTEM_GET_NOW_SCOPE_FINALLY_ADDRESS;
|
---|
[357] | 22 | if( lstrcmpi( FuncName, "_System_GetBp" ) == 0 ) return FUNC_SYSTEM_GET_BP;
|
---|
[358] | 23 | if( lstrcmpi( FuncName, "_System_GetSp" ) == 0 ) return FUNC_SYSTEM_GET_SP;
|
---|
[426] | 24 | if( lstrcmp( FuncName, "_System_New" ) == 0 ) return FUNC_SYSTEM_NEW;
|
---|
[325] | 25 | if( lstrcmpi( FuncName, "GetDouble" ) == 0 ) return FUNC_GETDOUBLE;
|
---|
| 26 | if( lstrcmpi( FuncName, "GetSingle" ) == 0 ) return FUNC_GETSINGLE;
|
---|
| 27 | if( lstrcmpi( FuncName, "GetQWord" ) == 0 ) return FUNC_GETQWORD;
|
---|
| 28 | if( lstrcmpi( FuncName, "GetDWord" ) == 0 ) return FUNC_GETDWORD;
|
---|
| 29 | if( lstrcmpi( FuncName, "GetWord" ) == 0 ) return FUNC_GETWORD;
|
---|
| 30 | if( lstrcmpi( FuncName, "GetByte" ) == 0 ) return FUNC_GETBYTE;
|
---|
[3] | 31 | return 0;
|
---|
| 32 | }
|
---|
| 33 |
|
---|
[76] | 34 | void Opcode_Func_Fix(const char *lpszParms){
|
---|
| 35 | Type resultType;
|
---|
| 36 | if( !NumOpe( lpszParms, Type(), resultType ) ){
|
---|
| 37 | return;
|
---|
| 38 | }
|
---|
[3] | 39 |
|
---|
[76] | 40 | if( resultType.IsDouble() ){
|
---|
[3] | 41 | //fld qword ptr[esp]
|
---|
[225] | 42 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
---|
[3] | 43 |
|
---|
| 44 | //fnstcw word ptr[esp]
|
---|
[250] | 45 | compiler.codeGenerator.PutOld(
|
---|
| 46 | (char)0xD9,
|
---|
| 47 | (char)0x3C,
|
---|
| 48 | (char)0x24
|
---|
| 49 | );
|
---|
[3] | 50 |
|
---|
| 51 | //mov ax,word ptr[esp]
|
---|
[250] | 52 | compiler.codeGenerator.op_mov_RM( sizeof(short), REG_EAX, REG_ESP, 0, MOD_BASE );
|
---|
[3] | 53 |
|
---|
| 54 | //or ah,0Ch
|
---|
[250] | 55 | compiler.codeGenerator.PutOld(
|
---|
| 56 | (char)0x80,
|
---|
| 57 | (char)0xCC,
|
---|
| 58 | (char)0x0C
|
---|
| 59 | );
|
---|
[3] | 60 |
|
---|
| 61 | //mov word ptr[esp-2],ax
|
---|
[250] | 62 | compiler.codeGenerator.op_mov_MR( sizeof(short), REG_EAX, REG_ESP, -2, MOD_BASE_DISP8 );
|
---|
[3] | 63 |
|
---|
| 64 | //fldcw word ptr[esp-2]
|
---|
[250] | 65 | compiler.codeGenerator.PutOld(
|
---|
| 66 | (char)0xD9,
|
---|
| 67 | (char)0x6C,
|
---|
| 68 | (char)0x24,
|
---|
| 69 | (char)0xFE
|
---|
| 70 | );
|
---|
[3] | 71 |
|
---|
| 72 | //fistp dword ptr[esp+4]
|
---|
[250] | 73 | compiler.codeGenerator.PutOld(
|
---|
| 74 | (char)0xDB,
|
---|
| 75 | (char)0x5C,
|
---|
| 76 | (char)0x24,
|
---|
| 77 | (char)0x04
|
---|
| 78 | );
|
---|
[3] | 79 |
|
---|
| 80 | //fldcw word ptr[esp]
|
---|
[250] | 81 | compiler.codeGenerator.PutOld(
|
---|
| 82 | (char)0xD9,
|
---|
| 83 | (char)0x2C,
|
---|
| 84 | (char)0x24
|
---|
| 85 | );
|
---|
[3] | 86 |
|
---|
| 87 | //add esp,4
|
---|
[225] | 88 | compiler.codeGenerator.op_add_esp(4);
|
---|
[3] | 89 | }
|
---|
[76] | 90 | else if( resultType.IsSingle() ){
|
---|
[3] | 91 | //fld dword ptr[esp]
|
---|
[225] | 92 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
---|
[3] | 93 |
|
---|
| 94 | //sub esp,4
|
---|
[225] | 95 | compiler.codeGenerator.op_sub_esp(4);
|
---|
[3] | 96 |
|
---|
| 97 | //fnstcw word ptr[esp]
|
---|
[250] | 98 | compiler.codeGenerator.PutOld(
|
---|
| 99 | (char)0xD9,
|
---|
| 100 | (char)0x3C,
|
---|
| 101 | (char)0x24
|
---|
| 102 | );
|
---|
[3] | 103 |
|
---|
| 104 | //mov ax,word ptr[esp]
|
---|
[250] | 105 | compiler.codeGenerator.op_mov_RM( sizeof(short), REG_EAX, REG_ESP, 0, MOD_BASE );
|
---|
[3] | 106 |
|
---|
| 107 | //or ah,0Ch
|
---|
[250] | 108 | compiler.codeGenerator.PutOld(
|
---|
| 109 | (char)0x80,
|
---|
| 110 | (char)0xCC,
|
---|
| 111 | (char)0x0C
|
---|
| 112 | );
|
---|
[3] | 113 |
|
---|
| 114 | //mov word ptr[esp-2],ax
|
---|
[250] | 115 | compiler.codeGenerator.op_mov_MR( sizeof(short), REG_EAX, REG_ESP, -2, MOD_BASE_DISP8 );
|
---|
[3] | 116 |
|
---|
| 117 | //fldcw word ptr[esp-2]
|
---|
[250] | 118 | compiler.codeGenerator.PutOld(
|
---|
| 119 | (char)0xD9,
|
---|
| 120 | (char)0x6C,
|
---|
| 121 | (char)0x24,
|
---|
| 122 | (char)0xFE
|
---|
| 123 | );
|
---|
[3] | 124 |
|
---|
| 125 | //fistp dword ptr[esp+4]
|
---|
[250] | 126 | compiler.codeGenerator.PutOld(
|
---|
| 127 | (char)0xDB,
|
---|
| 128 | (char)0x5C,
|
---|
| 129 | (char)0x24,
|
---|
| 130 | (char)0x04
|
---|
| 131 | );
|
---|
[3] | 132 |
|
---|
| 133 | //fldcw word ptr[esp]
|
---|
[250] | 134 | compiler.codeGenerator.PutOld(
|
---|
| 135 | (char)0xD9,
|
---|
| 136 | (char)0x2C,
|
---|
| 137 | (char)0x24
|
---|
| 138 | );
|
---|
[3] | 139 |
|
---|
| 140 | //add esp,4
|
---|
[225] | 141 | compiler.codeGenerator.op_add_esp(4);
|
---|
[3] | 142 | }
|
---|
[76] | 143 | else if( resultType.Is64() ){
|
---|
[3] | 144 | //pop eax
|
---|
[225] | 145 | compiler.codeGenerator.op_pop(REG_EAX);
|
---|
[3] | 146 |
|
---|
| 147 | //add esp,4
|
---|
[225] | 148 | compiler.codeGenerator.op_add_esp(4);
|
---|
[3] | 149 |
|
---|
| 150 | //push eax
|
---|
[225] | 151 | compiler.codeGenerator.op_push(REG_EAX);
|
---|
[3] | 152 | }
|
---|
| 153 |
|
---|
| 154 | //pop eax
|
---|
[225] | 155 | compiler.codeGenerator.op_pop(REG_EAX);
|
---|
[3] | 156 | }
|
---|
| 157 |
|
---|
[46] | 158 | void Opcode_Func_CUDbl(const char *Parameter){
|
---|
[76] | 159 | Type resultType;
|
---|
| 160 | if( !NumOpe(Parameter,Type(),resultType) ){
|
---|
| 161 | return;
|
---|
| 162 | }
|
---|
| 163 | ChangeTypeToLong(resultType.GetBasicType());
|
---|
[3] | 164 |
|
---|
| 165 | //pop eax
|
---|
[225] | 166 | compiler.codeGenerator.op_pop(REG_EAX);
|
---|
[3] | 167 |
|
---|
| 168 | //push 0
|
---|
[235] | 169 | compiler.codeGenerator.op_push_V( 0 );
|
---|
[3] | 170 |
|
---|
| 171 | //push eax
|
---|
[225] | 172 | compiler.codeGenerator.op_push(REG_EAX);
|
---|
[3] | 173 |
|
---|
| 174 | //fild qword ptr[esp]
|
---|
[235] | 175 | compiler.codeGenerator.op_fld_ptr_esp(DEF_INT64);
|
---|
[3] | 176 |
|
---|
| 177 | //add esp,8
|
---|
[225] | 178 | compiler.codeGenerator.op_add_esp(8);
|
---|
[3] | 179 | }
|
---|
[46] | 180 | void Opcode_Func_Len(const char *Parameter){
|
---|
[3] | 181 | BOOL bArrayHead;
|
---|
| 182 |
|
---|
[46] | 183 | const char *tempParm=Parameter;
|
---|
[3] | 184 | char temporary[VN_SIZE];
|
---|
| 185 | char temp2[32];
|
---|
[76] | 186 | Type type;
|
---|
| 187 | if( !GetVarType(Parameter,type,0) ){
|
---|
[3] | 188 | sprintf(temporary,"_System_DummyStr2=%s",Parameter);
|
---|
| 189 | OpcodeCalc(temporary);
|
---|
| 190 |
|
---|
| 191 | lstrcpy(temp2,"_System_DummyStr2");
|
---|
| 192 | tempParm=temp2;
|
---|
| 193 |
|
---|
[265] | 194 | type.SetType( DEF_OBJECT, compiler.GetObjectModule().meta.GetClasses().GetStringClassPtr() );
|
---|
[3] | 195 | }
|
---|
| 196 |
|
---|
[97] | 197 | if( type.IsStringClass() ){
|
---|
[3] | 198 | //Stringオブジェクトの場合
|
---|
| 199 | sprintf(temporary,"%s.Length",tempParm);
|
---|
| 200 |
|
---|
[76] | 201 | int reg=REG_RAX;
|
---|
| 202 | NumOpe(temporary,Type(),Type());
|
---|
[3] | 203 |
|
---|
| 204 | //pop eax
|
---|
[225] | 205 | compiler.codeGenerator.op_pop(REG_EAX);
|
---|
[3] | 206 |
|
---|
| 207 | return;
|
---|
| 208 | }
|
---|
| 209 |
|
---|
[206] | 210 | Subscripts subscripts;
|
---|
[3] | 211 | RELATIVE_VAR RelativeVar;
|
---|
[206] | 212 | if(!GetVarOffsetReadOnly(tempParm,&RelativeVar,type,&subscripts)) return;
|
---|
[3] | 213 |
|
---|
[76] | 214 | if(type.GetBasicType()&FLAG_PTR){
|
---|
| 215 | type.SetBasicType( type.GetBasicType() & ( ~FLAG_PTR ) );
|
---|
[3] | 216 |
|
---|
| 217 | bArrayHead=1;
|
---|
| 218 | }
|
---|
| 219 | else bArrayHead=0;
|
---|
| 220 |
|
---|
[76] | 221 | int typeSize = type.GetSize();
|
---|
[3] | 222 |
|
---|
[206] | 223 | if(bArrayHead) typeSize*=JumpSubScripts(subscripts);
|
---|
[3] | 224 |
|
---|
[235] | 225 | //mov eax,typeSize
|
---|
| 226 | compiler.codeGenerator.op_mov_RV( REG_EAX, typeSize );
|
---|
[3] | 227 | }
|
---|
| 228 |
|
---|
[332] | 229 | void _Opcode_Func_AddressOf( const char *methodInstanceName, const UserProc &userProc )
|
---|
| 230 | {
|
---|
| 231 | if( userProc.IsVirtual() ){
|
---|
[3] | 232 | ///////////////////////////////
|
---|
| 233 | // 仮想関数の場合
|
---|
| 234 | // thisポインタをrcxにコピー
|
---|
| 235 | ///////////////////////////////
|
---|
| 236 |
|
---|
[114] | 237 | const CClass *pobj_c;
|
---|
[3] | 238 |
|
---|
| 239 | char ObjectName[VN_SIZE];
|
---|
[290] | 240 | ReferenceKind referenceKind;
|
---|
[332] | 241 | SplitObjectName( methodInstanceName, ObjectName, referenceKind );
|
---|
[3] | 242 |
|
---|
| 243 | if(ObjectName[0]){
|
---|
| 244 | if(lstrcmpi(ObjectName,"Super")==0) goto InClassMember;
|
---|
| 245 | else{
|
---|
| 246 | RELATIVE_VAR RelativeVar;
|
---|
[76] | 247 | Type type;
|
---|
| 248 | if(!GetVarOffsetReadOnly(ObjectName,&RelativeVar,type)) return;
|
---|
[3] | 249 | SetVarPtrToEax(&RelativeVar);
|
---|
| 250 |
|
---|
| 251 | //mov ecx,eax
|
---|
[225] | 252 | compiler.codeGenerator.op_mov_RR(REG_ECX,REG_EAX);
|
---|
[3] | 253 |
|
---|
| 254 | //参照タイプが整合しているかをチェック
|
---|
[290] | 255 | if( !( type.IsObject() && referenceKind == RefDot
|
---|
| 256 | || type.IsObjectPtr() && referenceKind == RefPointer ) )
|
---|
| 257 | {
|
---|
| 258 | SetError(104,ObjectName,cp);
|
---|
| 259 | }
|
---|
[3] | 260 |
|
---|
[76] | 261 | if(type.IsObjectPtr()){
|
---|
[3] | 262 | //mov ecx,dword ptr[ecx]
|
---|
[225] | 263 | compiler.codeGenerator.op_mov_RM(sizeof(long),REG_ECX,REG_ECX,0,MOD_BASE);
|
---|
[3] | 264 | }
|
---|
| 265 | }
|
---|
| 266 | }
|
---|
| 267 | else{
|
---|
| 268 | InClassMember:
|
---|
| 269 | //自身のオブジェクトのThisポインタをrcxにコピー
|
---|
| 270 | SetThisPtrToReg(REG_RCX);
|
---|
| 271 |
|
---|
[206] | 272 | pobj_c=compiler.pCompilingClass;
|
---|
[3] | 273 | }
|
---|
| 274 |
|
---|
| 275 |
|
---|
[349] | 276 | int vtblIndex;
|
---|
| 277 | if( pobj_c->IsInterface() )
|
---|
| 278 | {
|
---|
| 279 | // インターフェイスメソッド呼び出し
|
---|
[3] | 280 |
|
---|
[349] | 281 | int offset_vtbl = compiler.GetObjectModule().meta.GetClasses().GetInterfaceInfoClassPtr()->GetMemberOffset( "__vtbl" );
|
---|
[348] | 282 |
|
---|
[3] | 283 |
|
---|
[349] | 284 | // vtblのポインタを取得
|
---|
| 285 | //mov edx,dword ptr[ecx+offset_vtbl]
|
---|
| 286 | compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EDX, REG_ECX, offset_vtbl, MOD_BASE_DISP8 );
|
---|
| 287 |
|
---|
| 288 | int offset_this = compiler.GetObjectModule().meta.GetClasses().GetInterfaceInfoClassPtr()->GetMemberOffset( "__this" );
|
---|
| 289 |
|
---|
| 290 |
|
---|
| 291 |
|
---|
| 292 | // インターフェイスの場合は更に__thisを取得する
|
---|
| 293 | //mov rcx,qword ptr[rcx+offset_this]
|
---|
| 294 | compiler.codeGenerator.op_mov_RM( sizeof(long), REG_ECX, REG_ECX, offset_this, MOD_BASE_DISP8 );
|
---|
| 295 |
|
---|
| 296 | int vtblMasterListIndex;
|
---|
| 297 | pobj_c->GetVtblMasterListIndexAndVtblIndex( &userProc, vtblMasterListIndex, vtblIndex );
|
---|
| 298 | if( vtblMasterListIndex != 0 )
|
---|
| 299 | {
|
---|
| 300 | SetError();
|
---|
| 301 | }
|
---|
| 302 | }
|
---|
[370] | 303 | else if( pobj_c->IsComInterface() )
|
---|
| 304 | {
|
---|
| 305 | // COMインターフェイス メソッド呼び出し
|
---|
| 306 |
|
---|
| 307 | //仮想関数(オブジェクトメソッド)呼び出し
|
---|
| 308 | // pObj -> vtbl1 -> func1
|
---|
| 309 | // -> func2
|
---|
| 310 | // -> func3
|
---|
| 311 |
|
---|
| 312 | int vtblMasterListIndex;
|
---|
| 313 | pobj_c->GetVtblMasterListIndexAndVtblIndex( &userProc, vtblMasterListIndex, vtblIndex );
|
---|
| 314 |
|
---|
| 315 | // vtblのポインタを取得
|
---|
| 316 | //mov edx,dword ptr[ecx]
|
---|
| 317 | compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EDX, REG_ECX, 0, MOD_BASE );
|
---|
| 318 | }
|
---|
[349] | 319 | else
|
---|
| 320 | {
|
---|
| 321 | //仮想関数(オブジェクトメソッド)呼び出し
|
---|
| 322 | // pObj -> vtbl_master_list -> vtbl1 -> func1
|
---|
| 323 | // -> func2
|
---|
| 324 | // -> func3
|
---|
| 325 | // -> vtbl2 -> func1
|
---|
| 326 | // -> func2
|
---|
| 327 | // -> func3
|
---|
| 328 |
|
---|
| 329 | int vtblMasterListIndex;
|
---|
| 330 | pobj_c->GetVtblMasterListIndexAndVtblIndex( &userProc, vtblMasterListIndex, vtblIndex );
|
---|
| 331 |
|
---|
| 332 | // vtblマスターリストのポインタを取得
|
---|
[370] | 333 | //mov edx,dword ptr[ecx+sizeof(com_vtbl)]
|
---|
| 334 | compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EDX, REG_ECX, PTR_SIZE, MOD_BASE_DISP8 );
|
---|
[349] | 335 |
|
---|
| 336 | // vtblのポインタを取得
|
---|
| 337 | //mov edx,dword ptr[edx+vtblMasterListIndex]
|
---|
[350] | 338 | compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EDX, REG_EDX, vtblMasterListIndex*PTR_SIZE, MOD_BASE_DISP32 );
|
---|
[349] | 339 | }
|
---|
| 340 |
|
---|
[3] | 341 | //mov eax,dword ptr[edx+func_index]
|
---|
[342] | 342 | if( vtblIndex * PTR_SIZE <= 0x7F )
|
---|
| 343 | {
|
---|
| 344 | compiler.codeGenerator.op_mov_RM(sizeof(long),REG_EAX,REG_EDX,vtblIndex*PTR_SIZE,MOD_BASE_DISP8);
|
---|
[3] | 345 | }
|
---|
| 346 | else{
|
---|
[342] | 347 | compiler.codeGenerator.op_mov_RM(sizeof(long),REG_EAX,REG_EDX,vtblIndex*PTR_SIZE,MOD_BASE_DISP32);
|
---|
[3] | 348 | }
|
---|
| 349 | }
|
---|
| 350 | else{
|
---|
| 351 | //一般の関数
|
---|
| 352 |
|
---|
| 353 | //mov eax,ProcAddr
|
---|
[332] | 354 | compiler.codeGenerator.op_addressof( REG_EAX, &userProc );
|
---|
[3] | 355 | }
|
---|
| 356 |
|
---|
[332] | 357 | userProc.Using();
|
---|
[3] | 358 | }
|
---|
[335] | 359 | void Opcode_CreateDelegate( const CClass &dgClass, const char *methodInstanceName, const UserProc &userProc )
|
---|
[332] | 360 | {
|
---|
| 361 | /////////////////////////////////////////////////////////////////
|
---|
| 362 | // 関数ポインタをpush
|
---|
| 363 | /////////////////////////////////////////////////////////////////
|
---|
| 364 |
|
---|
| 365 | //push AddressOf(userProc)
|
---|
| 366 | _Opcode_Func_AddressOf( methodInstanceName, userProc );
|
---|
| 367 | compiler.codeGenerator.op_push( REG_EAX );
|
---|
| 368 |
|
---|
| 369 |
|
---|
[336] | 370 | if( userProc.GetMethod().IsDynamic() )
|
---|
| 371 | {
|
---|
| 372 | /////////////////////////////////////////////////////////////////
|
---|
| 373 | // オブジェクト ポインタをpush
|
---|
| 374 | /////////////////////////////////////////////////////////////////
|
---|
[332] | 375 |
|
---|
[336] | 376 | // オブジェクト名を取得
|
---|
| 377 | char objectName[VN_SIZE];
|
---|
| 378 | char memberName[VN_SIZE];
|
---|
| 379 | char *thisPtrName = "This";
|
---|
| 380 | Type type;
|
---|
| 381 | if( SplitMemberName( methodInstanceName, objectName, memberName ) )
|
---|
[332] | 382 | {
|
---|
[336] | 383 | if( GetVarType( objectName, type, false ) )
|
---|
| 384 | {
|
---|
| 385 | thisPtrName = objectName;
|
---|
| 386 | }
|
---|
[332] | 387 | }
|
---|
| 388 |
|
---|
[336] | 389 | // オブジェクト ポインタを取得
|
---|
| 390 | RELATIVE_VAR relativeVar;
|
---|
| 391 | GetVarOffsetReadOnly( thisPtrName, &relativeVar, type );
|
---|
| 392 | if( !type.IsObject() )
|
---|
| 393 | {
|
---|
| 394 | extern int cp;
|
---|
| 395 | SetError(1,NULL,cp);
|
---|
| 396 | return;
|
---|
| 397 | }
|
---|
[332] | 398 |
|
---|
[336] | 399 | SetVarPtrToEax( &relativeVar );
|
---|
[332] | 400 |
|
---|
[336] | 401 | //mov eax,dword ptr[eax]
|
---|
| 402 | compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EAX, REG_EAX, 0, MOD_BASE );
|
---|
[332] | 403 |
|
---|
[336] | 404 | //push eax
|
---|
| 405 | compiler.codeGenerator.op_push( REG_EAX );
|
---|
| 406 | }
|
---|
[332] | 407 |
|
---|
| 408 |
|
---|
| 409 | /////////////////////////////////////////////////////////////////
|
---|
[336] | 410 | // call _CreateDynamicDelegate/_CreateStaticDelegate
|
---|
[332] | 411 | /////////////////////////////////////////////////////////////////
|
---|
| 412 |
|
---|
[334] | 413 | std::vector<const UserProc *> subs;
|
---|
[336] | 414 | if( userProc.GetMethod().IsDynamic() )
|
---|
| 415 | {
|
---|
| 416 | dgClass.GetStaticMethods().Enum( "_CreateDynamicDelegate", subs );
|
---|
| 417 | }
|
---|
| 418 | else
|
---|
| 419 | {
|
---|
| 420 | dgClass.GetStaticMethods().Enum( "_CreateStaticDelegate", subs );
|
---|
| 421 | }
|
---|
[334] | 422 |
|
---|
[336] | 423 | // call _CreateDynamicDelegate
|
---|
[334] | 424 | compiler.codeGenerator.op_call( subs[0] );
|
---|
[332] | 425 | }
|
---|
[339] | 426 | void Opcode_Func_AddressOf( const char *name, const Type &baseType, bool isCallOn, Type &resultType )
|
---|
| 427 | {
|
---|
[332] | 428 | extern int cp;
|
---|
| 429 | const UserProc *pUserProc;
|
---|
| 430 |
|
---|
| 431 | const Parameters *pBaseParams = NULL;
|
---|
| 432 | if( baseType.IsProcPtr() )
|
---|
| 433 | {
|
---|
| 434 | // 左辺で関数ポインタを要求されているとき
|
---|
| 435 | pBaseParams = &compiler.GetObjectModule().meta.GetProcPointers()[baseType.GetIndex()]->Params();
|
---|
| 436 | }
|
---|
[334] | 437 | else if( baseType.IsDelegate() )
|
---|
[332] | 438 | {
|
---|
| 439 | // 左辺でデリゲートを要求されているとき
|
---|
[334] | 440 | pBaseParams = &baseType.GetClass().GetDelegate().Params();
|
---|
[332] | 441 | }
|
---|
| 442 |
|
---|
| 443 | if( pBaseParams )
|
---|
| 444 | {
|
---|
| 445 | //左辺の型にのっとり、オーバーロードを解決
|
---|
| 446 |
|
---|
| 447 | std::vector<const UserProc *> subs;
|
---|
| 448 | GetOverloadSubHash( name, subs );
|
---|
| 449 | if( subs.size() == 0 ){
|
---|
| 450 | SetError(27,name,cp);
|
---|
| 451 | return;
|
---|
| 452 | }
|
---|
| 453 |
|
---|
| 454 | //オーバーロードを解決
|
---|
[424] | 455 | pUserProc=OverloadSolution( name, subs, *pBaseParams, Type(), Type() );
|
---|
[332] | 456 |
|
---|
[338] | 457 | if( isCallOn && baseType.IsDelegate() )
|
---|
[337] | 458 | {
|
---|
| 459 | // コード生成を伴う場合はエラーチェックを行う
|
---|
| 460 | if( !pUserProc->Params().Equals( *pBaseParams )
|
---|
| 461 | || !pUserProc->ReturnType().Equals( baseType.GetClass().GetDelegate().ReturnType() ) )
|
---|
| 462 | {
|
---|
| 463 | if( baseType.IsDelegate() )
|
---|
| 464 | {
|
---|
| 465 | SetError(67, name, cp );
|
---|
| 466 | }
|
---|
| 467 | else
|
---|
| 468 | {
|
---|
| 469 | SetError(66, name, cp );
|
---|
| 470 | }
|
---|
| 471 | }
|
---|
| 472 | }
|
---|
| 473 |
|
---|
[332] | 474 | if(!pUserProc){
|
---|
| 475 | SetError(27,name,cp);
|
---|
| 476 | return;
|
---|
| 477 | }
|
---|
| 478 | }
|
---|
| 479 | else{
|
---|
| 480 | pUserProc=GetSubHash(name);
|
---|
| 481 | if(!pUserProc){
|
---|
| 482 | SetError(27,name,cp);
|
---|
| 483 | return;
|
---|
| 484 | }
|
---|
| 485 | }
|
---|
| 486 |
|
---|
[334] | 487 | if( baseType.IsDelegate() )
|
---|
[332] | 488 | {
|
---|
| 489 | if( isCallOn )
|
---|
| 490 | {
|
---|
| 491 | // デリゲートのとき
|
---|
[335] | 492 | Opcode_CreateDelegate( baseType.GetClass(), name, *pUserProc );
|
---|
[332] | 493 | }
|
---|
| 494 | resultType = baseType;
|
---|
| 495 | }
|
---|
| 496 | else
|
---|
| 497 | {
|
---|
| 498 | if( isCallOn )
|
---|
| 499 | {
|
---|
| 500 | // 関数ポインタのとき
|
---|
| 501 | _Opcode_Func_AddressOf( name, *pUserProc );
|
---|
| 502 | }
|
---|
| 503 | resultType.SetBasicType( DEF_PTR_VOID );
|
---|
| 504 | }
|
---|
| 505 | }
|
---|
[79] | 506 | void Opcode_Func_SizeOf( const string &typeName ){
|
---|
| 507 | Type tempType;
|
---|
[299] | 508 | if( !compiler.StringToType( typeName, tempType ) ){
|
---|
[79] | 509 | SetError(3,typeName,cp);
|
---|
| 510 | return;
|
---|
[3] | 511 | }
|
---|
| 512 |
|
---|
[79] | 513 | int typeSize = ( tempType.IsObject() ) ?
|
---|
| 514 | tempType.GetClass().GetSize() : tempType.GetSize();
|
---|
| 515 |
|
---|
[3] | 516 | //mov eax,size
|
---|
[225] | 517 | compiler.codeGenerator.op_mov_RV( REG_EAX, typeSize );
|
---|
[3] | 518 | }
|
---|
[76] | 519 | void Opcode_Func_VarPtr( const char *Parameter, Type &resultType, bool isCallOn ){
|
---|
| 520 | if( isCallOn == false ){
|
---|
| 521 | // 戻り値の型を取得するだけ
|
---|
| 522 |
|
---|
| 523 | //変数のアドレスを取得
|
---|
| 524 | if(!GetVarType( Parameter, resultType, true )) return;
|
---|
| 525 |
|
---|
| 526 | resultType.PtrLevelUp();
|
---|
| 527 |
|
---|
| 528 | return;
|
---|
| 529 | }
|
---|
| 530 |
|
---|
[3] | 531 | RELATIVE_VAR RelativeVar;
|
---|
| 532 |
|
---|
| 533 | //変数のアドレスを取得
|
---|
[76] | 534 | if(!GetVarOffsetReadOnly( Parameter, &RelativeVar, resultType )) return;
|
---|
[3] | 535 |
|
---|
[76] | 536 | int beforeType = resultType.GetBasicType();
|
---|
[64] | 537 |
|
---|
[76] | 538 | resultType.PtrLevelUp();
|
---|
[46] | 539 |
|
---|
[3] | 540 | SetVarPtrToEax(&RelativeVar);
|
---|
| 541 | }
|
---|
[109] | 542 | void Opcode_Func_ObjPtr( const char *Parameter, Type &resultType, bool isCallOn ){
|
---|
| 543 | if( isCallOn == false ){
|
---|
| 544 | // 戻り値の型を取得するだけ
|
---|
| 545 |
|
---|
| 546 | //変数のアドレスを取得
|
---|
| 547 | if(!GetVarType( Parameter, resultType, true )) return;
|
---|
| 548 |
|
---|
| 549 | resultType.PtrLevelUp();
|
---|
| 550 |
|
---|
| 551 | return;
|
---|
| 552 | }
|
---|
| 553 |
|
---|
| 554 | RELATIVE_VAR RelativeVar;
|
---|
| 555 |
|
---|
| 556 | //変数のアドレスを取得
|
---|
| 557 | if(!GetVarOffsetReadOnly( Parameter, &RelativeVar, resultType )) return;
|
---|
| 558 |
|
---|
| 559 | int beforeType = resultType.GetBasicType();
|
---|
| 560 |
|
---|
| 561 | resultType.PtrLevelUp();
|
---|
| 562 |
|
---|
| 563 | SetVarPtrToEax(&RelativeVar);
|
---|
| 564 |
|
---|
[111] | 565 | if( lstrcmpi( Parameter, "This" )==0 ){
|
---|
| 566 | // Thisの場合は特別にオブジェクトポインタが返ってくるので、何もせずに抜ける
|
---|
| 567 | }
|
---|
| 568 | else if( beforeType == DEF_OBJECT ){
|
---|
[109] | 569 | //参照をオブジェクトポインタに変更
|
---|
| 570 |
|
---|
| 571 | //mov eax,dword ptr[eax]
|
---|
[225] | 572 | compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EAX, REG_EAX, 0, MOD_BASE );
|
---|
[109] | 573 | }
|
---|
| 574 | else{
|
---|
| 575 | SetError(134,NULL,cp );
|
---|
| 576 | }
|
---|
| 577 | }
|
---|
[325] | 578 |
|
---|
| 579 | void Opcode_Func_delegate_call( const char *paramsStr, Type &resultType, bool isDynamicCall, bool isCallOn )
|
---|
| 580 | {
|
---|
| 581 | if( isCallOn )
|
---|
| 582 | {
|
---|
| 583 | int i = 0;
|
---|
| 584 | char methodPtrParamStr[VN_SIZE];
|
---|
| 585 | i = GetOneParameter( paramsStr, i, methodPtrParamStr );
|
---|
| 586 |
|
---|
[336] | 587 | char objPtrValueStr[VN_SIZE]="";
|
---|
[325] | 588 | if( isDynamicCall )
|
---|
| 589 | {
|
---|
| 590 | i = GetOneParameter( paramsStr, i, objPtrValueStr );
|
---|
| 591 | }
|
---|
| 592 |
|
---|
| 593 | Opcode_CallDelegate( compiler.pCompilingClass->GetDelegate(), methodPtrParamStr, objPtrValueStr, paramsStr + i );
|
---|
| 594 | }
|
---|
| 595 |
|
---|
| 596 | resultType = UserProc::CompilingUserProc().ReturnType();
|
---|
| 597 | }
|
---|
[357] | 598 | void Opcode_Func_System_Get_Bp()
|
---|
| 599 | {
|
---|
| 600 | //mov eax,ebp
|
---|
| 601 | compiler.codeGenerator.op_mov_RR(REG_EAX,REG_EBP);
|
---|
| 602 | }
|
---|
[358] | 603 | void Opcode_Func_System_Get_Sp()
|
---|
| 604 | {
|
---|
| 605 | //mov eax,esp
|
---|
| 606 | compiler.codeGenerator.op_mov_RR(REG_EAX,REG_ESP);
|
---|
| 607 | }
|
---|
[325] | 608 |
|
---|
[426] | 609 | void Opcode_Func_System_New( const char *parameter, Type &resultType, bool isCallOn )
|
---|
| 610 | {
|
---|
| 611 | if( !compiler.StringToType( parameter, resultType ) )
|
---|
| 612 | {
|
---|
| 613 | SetError();
|
---|
| 614 | return;
|
---|
| 615 | }
|
---|
| 616 | if( !resultType.IsObject() )
|
---|
| 617 | {
|
---|
| 618 | SetError();
|
---|
| 619 | return;
|
---|
| 620 | }
|
---|
| 621 |
|
---|
| 622 | if( isCallOn )
|
---|
| 623 | {
|
---|
| 624 | Type tempResultType;
|
---|
| 625 | if( !Operator_New( parameter, resultType, tempResultType ) )
|
---|
| 626 | {
|
---|
| 627 | return;
|
---|
| 628 | }
|
---|
| 629 |
|
---|
| 630 | if( !resultType.Equals( tempResultType ) )
|
---|
| 631 | {
|
---|
| 632 | SetError();
|
---|
| 633 | }
|
---|
| 634 |
|
---|
| 635 | //pop eax
|
---|
| 636 | compiler.codeGenerator.op_pop( REG_EAX );
|
---|
| 637 | }
|
---|
| 638 | }
|
---|
| 639 |
|
---|
[46] | 640 | void Opcode_Func_GetPtrData(const char *Parameter,const int type){
|
---|
[76] | 641 | Type tempType;
|
---|
| 642 | if( !NumOpe(Parameter,Type(),tempType) ){
|
---|
| 643 | return;
|
---|
| 644 | }
|
---|
| 645 | if(!tempType.IsWhole()){
|
---|
| 646 | SetError(11,Parameter,cp);
|
---|
| 647 | return;
|
---|
| 648 | }
|
---|
| 649 | ChangeTypeToLong(tempType.GetBasicType());
|
---|
[3] | 650 |
|
---|
| 651 | if(type==DEF_DOUBLE){
|
---|
| 652 | //pop eax
|
---|
[225] | 653 | compiler.codeGenerator.op_pop(REG_EAX);
|
---|
[3] | 654 |
|
---|
| 655 | //fld qword ptr[eax]
|
---|
[235] | 656 | compiler.codeGenerator.PutOld(
|
---|
| 657 | (char)0xDD,
|
---|
| 658 | (char)0x00
|
---|
| 659 | );
|
---|
[3] | 660 | }
|
---|
| 661 | else if(type==DEF_SINGLE||type==DEF_DWORD){
|
---|
| 662 | //pop eax
|
---|
[225] | 663 | compiler.codeGenerator.op_pop(REG_EAX);
|
---|
[3] | 664 |
|
---|
| 665 | //mov eax,dword ptr[eax]
|
---|
[235] | 666 | compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EAX, REG_EAX, 0, MOD_BASE );
|
---|
[3] | 667 | }
|
---|
| 668 | else if(type==DEF_QWORD){
|
---|
| 669 | //pop ecx
|
---|
[225] | 670 | compiler.codeGenerator.op_pop(REG_ECX);
|
---|
[3] | 671 |
|
---|
| 672 | //mov eax,dword ptr[ecx]
|
---|
[225] | 673 | compiler.codeGenerator.op_mov_RM(sizeof(long),REG_EAX,REG_ECX,0,MOD_BASE);
|
---|
[3] | 674 |
|
---|
| 675 | //mov edx,dword ptr[ecx+sizeof(long)]
|
---|
[225] | 676 | compiler.codeGenerator.op_mov_RM(sizeof(long),REG_EDX,REG_ECX,sizeof(long),MOD_BASE_DISP8);
|
---|
[3] | 677 | }
|
---|
| 678 | else if(type==DEF_WORD){
|
---|
| 679 | //pop ebx
|
---|
[225] | 680 | compiler.codeGenerator.op_pop(REG_EBX);
|
---|
[3] | 681 |
|
---|
| 682 | //xor eax,eax
|
---|
[227] | 683 | compiler.codeGenerator.op_xor_RR(REG_EAX);
|
---|
[3] | 684 |
|
---|
| 685 | //mov ax,word ptr[ebx]
|
---|
[235] | 686 | compiler.codeGenerator.op_mov_RM( sizeof(short), REG_EAX, REG_EBX, 0, MOD_BASE );
|
---|
[3] | 687 | }
|
---|
| 688 | else if(type==DEF_BYTE){
|
---|
| 689 | //pop ebx
|
---|
[225] | 690 | compiler.codeGenerator.op_pop(REG_EBX);
|
---|
[3] | 691 |
|
---|
| 692 | //xor eax,eax
|
---|
[227] | 693 | compiler.codeGenerator.op_xor_RR(REG_EAX);
|
---|
[3] | 694 |
|
---|
| 695 | //mov al,byte ptr[ebx]
|
---|
[235] | 696 | compiler.codeGenerator.op_mov_RM( sizeof(char), REG_EAX, REG_EBX, 0, MOD_BASE );
|
---|
[3] | 697 | }
|
---|
| 698 | }
|
---|
| 699 |
|
---|
[331] | 700 | bool Opcode_CallFunc( const char *Parameter, const int FuncNum, const Type &baseType, Type &resultType, bool isCallOn )
|
---|
| 701 | {
|
---|
[3] | 702 | switch(FuncNum){
|
---|
| 703 | case FUNC_FIX:
|
---|
[76] | 704 | if( isCallOn ) Opcode_Func_Fix(Parameter);
|
---|
| 705 | resultType.SetBasicType( DEF_LONG );
|
---|
[46] | 706 | break;
|
---|
[3] | 707 | case FUNC_CUDBL:
|
---|
[76] | 708 | if( isCallOn ) Opcode_Func_CUDbl(Parameter);
|
---|
| 709 | resultType.SetBasicType( DEF_DOUBLE );
|
---|
[46] | 710 | break;
|
---|
[3] | 711 | case FUNC_LEN:
|
---|
[76] | 712 | if( isCallOn ) Opcode_Func_Len(Parameter);
|
---|
| 713 | resultType.SetBasicType( DEF_LONG );
|
---|
[46] | 714 | break;
|
---|
[3] | 715 | case FUNC_ADDRESSOF:
|
---|
[332] | 716 | Opcode_Func_AddressOf( Parameter, baseType, isCallOn, resultType );
|
---|
[46] | 717 | break;
|
---|
[3] | 718 | case FUNC_SIZEOF:
|
---|
[76] | 719 | if( isCallOn ) Opcode_Func_SizeOf(Parameter);
|
---|
| 720 | resultType.SetBasicType( DEF_LONG );
|
---|
[46] | 721 | break;
|
---|
[3] | 722 | case FUNC_VARPTR:
|
---|
[76] | 723 | Opcode_Func_VarPtr( Parameter, resultType, isCallOn );
|
---|
[46] | 724 | break;
|
---|
[109] | 725 | case FUNC_OBJPTR:
|
---|
| 726 | Opcode_Func_ObjPtr( Parameter, resultType, isCallOn );
|
---|
| 727 | break;
|
---|
[325] | 728 | case FUNC_DELEGATE_DYNAMICMETHOD_CALL:
|
---|
| 729 | Opcode_Func_delegate_call( Parameter, resultType, true, isCallOn );
|
---|
| 730 | break;
|
---|
| 731 | case FUNC_DELEGATE_STATICMETHOD_CALL:
|
---|
| 732 | Opcode_Func_delegate_call( Parameter, resultType, false, isCallOn );
|
---|
| 733 | break;
|
---|
[357] | 734 | case FUNC_SYSTEM_GET_NOW_SCOPE_CATCH_ADDRESS:
|
---|
| 735 | if( isCallOn ) Exception::Opcode_Func_System_GetNowScopeCatchAddress();
|
---|
[358] | 736 | resultType.SetBasicType( DEF_PTR_VOID );
|
---|
[357] | 737 | break;
|
---|
[359] | 738 | case FUNC_SYSTEM_GET_NOW_SCOPE_FINALLY_ADDRESS:
|
---|
| 739 | if( isCallOn ) Exception::Opcode_Func_System_GetNowScopeFinallyAddress();
|
---|
| 740 | resultType.SetBasicType( DEF_PTR_VOID );
|
---|
| 741 | break;
|
---|
[357] | 742 | case FUNC_SYSTEM_GET_BP:
|
---|
| 743 | if( isCallOn ) Opcode_Func_System_Get_Bp();
|
---|
| 744 | resultType.SetBasicType( DEF_LONG );
|
---|
| 745 | break;
|
---|
[358] | 746 | case FUNC_SYSTEM_GET_SP:
|
---|
| 747 | if( isCallOn ) Opcode_Func_System_Get_Sp();
|
---|
| 748 | resultType.SetBasicType( DEF_LONG );
|
---|
| 749 | break;
|
---|
[426] | 750 | case FUNC_SYSTEM_NEW:
|
---|
| 751 | Opcode_Func_System_New( Parameter, resultType, isCallOn );
|
---|
| 752 | break;
|
---|
[3] | 753 |
|
---|
| 754 | case FUNC_GETDOUBLE:
|
---|
[76] | 755 | if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_DOUBLE);
|
---|
| 756 | resultType.SetBasicType( DEF_DOUBLE );
|
---|
[46] | 757 | break;
|
---|
[3] | 758 | case FUNC_GETSINGLE:
|
---|
[76] | 759 | if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_SINGLE);
|
---|
| 760 | resultType.SetBasicType( DEF_SINGLE );
|
---|
[46] | 761 | break;
|
---|
[3] | 762 | case FUNC_GETQWORD:
|
---|
[76] | 763 | if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_QWORD);
|
---|
| 764 | resultType.SetBasicType( DEF_QWORD );
|
---|
[46] | 765 | break;
|
---|
[3] | 766 | case FUNC_GETDWORD:
|
---|
[76] | 767 | if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_DWORD);
|
---|
| 768 | resultType.SetBasicType( DEF_DWORD );
|
---|
[46] | 769 | break;
|
---|
[3] | 770 | case FUNC_GETWORD:
|
---|
[76] | 771 | if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_WORD);
|
---|
| 772 | resultType.SetBasicType( DEF_WORD );
|
---|
[46] | 773 | break;
|
---|
[3] | 774 | case FUNC_GETBYTE:
|
---|
[76] | 775 | if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_BYTE);
|
---|
| 776 | resultType.SetBasicType( DEF_BYTE );
|
---|
[46] | 777 | break;
|
---|
[76] | 778 | default:
|
---|
| 779 | return false;
|
---|
[3] | 780 | }
|
---|
[76] | 781 | return true;
|
---|
[3] | 782 | }
|
---|