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