[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 |
|
---|
[336] | 309 | if( userProc.GetMethod().IsDynamic() )
|
---|
| 310 | {
|
---|
| 311 | /////////////////////////////////////////////////////////////////
|
---|
| 312 | // オブジェクト ポインタをpush
|
---|
| 313 | /////////////////////////////////////////////////////////////////
|
---|
[332] | 314 |
|
---|
[336] | 315 | // オブジェクト名を取得
|
---|
| 316 | char objectName[VN_SIZE];
|
---|
| 317 | char memberName[VN_SIZE];
|
---|
| 318 | char *thisPtrName = "This";
|
---|
| 319 | Type type;
|
---|
| 320 | if( SplitMemberName( methodInstanceName, objectName, memberName ) )
|
---|
[332] | 321 | {
|
---|
[336] | 322 | if( GetVarType( objectName, type, false ) )
|
---|
| 323 | {
|
---|
| 324 | thisPtrName = objectName;
|
---|
| 325 | }
|
---|
[332] | 326 | }
|
---|
| 327 |
|
---|
[336] | 328 | // オブジェクト ポインタを取得
|
---|
| 329 | RELATIVE_VAR relativeVar;
|
---|
| 330 | GetVarOffsetReadOnly( thisPtrName, &relativeVar, type );
|
---|
| 331 | if( !type.IsObject() )
|
---|
| 332 | {
|
---|
| 333 | extern int cp;
|
---|
| 334 | SetError(1,NULL,cp);
|
---|
| 335 | return;
|
---|
| 336 | }
|
---|
[332] | 337 |
|
---|
[336] | 338 | SetVarPtrToEax( &relativeVar );
|
---|
[332] | 339 |
|
---|
[336] | 340 | //mov eax,dword ptr[eax]
|
---|
| 341 | compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EAX, REG_EAX, 0, MOD_BASE );
|
---|
[332] | 342 |
|
---|
[336] | 343 | //push eax
|
---|
| 344 | compiler.codeGenerator.op_push( REG_EAX );
|
---|
| 345 | }
|
---|
[332] | 346 |
|
---|
| 347 |
|
---|
| 348 | /////////////////////////////////////////////////////////////////
|
---|
[336] | 349 | // call _CreateDynamicDelegate/_CreateStaticDelegate
|
---|
[332] | 350 | /////////////////////////////////////////////////////////////////
|
---|
| 351 |
|
---|
[334] | 352 | std::vector<const UserProc *> subs;
|
---|
[336] | 353 | if( userProc.GetMethod().IsDynamic() )
|
---|
| 354 | {
|
---|
| 355 | dgClass.GetStaticMethods().Enum( "_CreateDynamicDelegate", subs );
|
---|
| 356 | }
|
---|
| 357 | else
|
---|
| 358 | {
|
---|
| 359 | dgClass.GetStaticMethods().Enum( "_CreateStaticDelegate", subs );
|
---|
| 360 | }
|
---|
[334] | 361 |
|
---|
[336] | 362 | // call _CreateDynamicDelegate
|
---|
[334] | 363 | compiler.codeGenerator.op_call( subs[0] );
|
---|
[332] | 364 | }
|
---|
| 365 | void Opcode_Func_AddressOf( const char *name, const Type &baseType, bool isCallOn, Type &resultType ){
|
---|
| 366 | extern int cp;
|
---|
| 367 | const UserProc *pUserProc;
|
---|
| 368 |
|
---|
| 369 | const Parameters *pBaseParams = NULL;
|
---|
| 370 | if( baseType.IsProcPtr() )
|
---|
| 371 | {
|
---|
| 372 | // 左辺で関数ポインタを要求されているとき
|
---|
| 373 | pBaseParams = &compiler.GetObjectModule().meta.GetProcPointers()[baseType.GetIndex()]->Params();
|
---|
| 374 | }
|
---|
[334] | 375 | else if( baseType.IsDelegate() )
|
---|
[332] | 376 | {
|
---|
| 377 | // 左辺でデリゲートを要求されているとき
|
---|
[334] | 378 | pBaseParams = &baseType.GetClass().GetDelegate().Params();
|
---|
[332] | 379 | }
|
---|
| 380 |
|
---|
| 381 | if( pBaseParams )
|
---|
| 382 | {
|
---|
| 383 | //左辺の型にのっとり、オーバーロードを解決
|
---|
| 384 |
|
---|
| 385 | std::vector<const UserProc *> subs;
|
---|
| 386 | GetOverloadSubHash( name, subs );
|
---|
| 387 | if( subs.size() == 0 ){
|
---|
| 388 | SetError(27,name,cp);
|
---|
| 389 | return;
|
---|
| 390 | }
|
---|
| 391 |
|
---|
| 392 | //オーバーロードを解決
|
---|
| 393 | pUserProc=OverloadSolution( name, subs, *pBaseParams, Type() );
|
---|
| 394 |
|
---|
[337] | 395 | if( isCallOn )
|
---|
| 396 | {
|
---|
| 397 | // コード生成を伴う場合はエラーチェックを行う
|
---|
| 398 | if( !pUserProc->Params().Equals( *pBaseParams )
|
---|
| 399 | || !pUserProc->ReturnType().Equals( baseType.GetClass().GetDelegate().ReturnType() ) )
|
---|
| 400 | {
|
---|
| 401 | if( baseType.IsDelegate() )
|
---|
| 402 | {
|
---|
| 403 | SetError(67, name, cp );
|
---|
| 404 | }
|
---|
| 405 | else
|
---|
| 406 | {
|
---|
| 407 | SetError(66, name, cp );
|
---|
| 408 | }
|
---|
| 409 | }
|
---|
| 410 | }
|
---|
| 411 |
|
---|
[332] | 412 | if(!pUserProc){
|
---|
| 413 | SetError(27,name,cp);
|
---|
| 414 | return;
|
---|
| 415 | }
|
---|
| 416 | }
|
---|
| 417 | else{
|
---|
| 418 | pUserProc=GetSubHash(name);
|
---|
| 419 | if(!pUserProc){
|
---|
| 420 | SetError(27,name,cp);
|
---|
| 421 | return;
|
---|
| 422 | }
|
---|
| 423 | }
|
---|
| 424 |
|
---|
[334] | 425 | if( baseType.IsDelegate() )
|
---|
[332] | 426 | {
|
---|
| 427 | if( isCallOn )
|
---|
| 428 | {
|
---|
| 429 | // デリゲートのとき
|
---|
[335] | 430 | Opcode_CreateDelegate( baseType.GetClass(), name, *pUserProc );
|
---|
[332] | 431 | }
|
---|
| 432 | resultType = baseType;
|
---|
| 433 | }
|
---|
| 434 | else
|
---|
| 435 | {
|
---|
| 436 | if( isCallOn )
|
---|
| 437 | {
|
---|
| 438 | // 関数ポインタのとき
|
---|
| 439 | _Opcode_Func_AddressOf( name, *pUserProc );
|
---|
| 440 | }
|
---|
| 441 | resultType.SetBasicType( DEF_PTR_VOID );
|
---|
| 442 | }
|
---|
| 443 | }
|
---|
[79] | 444 | void Opcode_Func_SizeOf( const string &typeName ){
|
---|
| 445 | Type tempType;
|
---|
[299] | 446 | if( !compiler.StringToType( typeName, tempType ) ){
|
---|
[79] | 447 | SetError(3,typeName,cp);
|
---|
| 448 | return;
|
---|
[3] | 449 | }
|
---|
| 450 |
|
---|
[79] | 451 | int typeSize = ( tempType.IsObject() ) ?
|
---|
| 452 | tempType.GetClass().GetSize() : tempType.GetSize();
|
---|
| 453 |
|
---|
[3] | 454 | //mov eax,size
|
---|
[225] | 455 | compiler.codeGenerator.op_mov_RV( REG_EAX, typeSize );
|
---|
[3] | 456 | }
|
---|
[76] | 457 | void Opcode_Func_VarPtr( const char *Parameter, Type &resultType, bool isCallOn ){
|
---|
| 458 | if( isCallOn == false ){
|
---|
| 459 | // 戻り値の型を取得するだけ
|
---|
| 460 |
|
---|
| 461 | //変数のアドレスを取得
|
---|
| 462 | if(!GetVarType( Parameter, resultType, true )) return;
|
---|
| 463 |
|
---|
| 464 | resultType.PtrLevelUp();
|
---|
| 465 |
|
---|
| 466 | return;
|
---|
| 467 | }
|
---|
| 468 |
|
---|
[3] | 469 | RELATIVE_VAR RelativeVar;
|
---|
| 470 |
|
---|
| 471 | //変数のアドレスを取得
|
---|
[76] | 472 | if(!GetVarOffsetReadOnly( Parameter, &RelativeVar, resultType )) return;
|
---|
[3] | 473 |
|
---|
[76] | 474 | int beforeType = resultType.GetBasicType();
|
---|
[64] | 475 |
|
---|
[76] | 476 | resultType.PtrLevelUp();
|
---|
[46] | 477 |
|
---|
[3] | 478 | SetVarPtrToEax(&RelativeVar);
|
---|
| 479 | }
|
---|
[109] | 480 | void Opcode_Func_ObjPtr( const char *Parameter, Type &resultType, bool isCallOn ){
|
---|
| 481 | if( isCallOn == false ){
|
---|
| 482 | // 戻り値の型を取得するだけ
|
---|
| 483 |
|
---|
| 484 | //変数のアドレスを取得
|
---|
| 485 | if(!GetVarType( Parameter, resultType, true )) return;
|
---|
| 486 |
|
---|
| 487 | resultType.PtrLevelUp();
|
---|
| 488 |
|
---|
| 489 | return;
|
---|
| 490 | }
|
---|
| 491 |
|
---|
| 492 | RELATIVE_VAR RelativeVar;
|
---|
| 493 |
|
---|
| 494 | //変数のアドレスを取得
|
---|
| 495 | if(!GetVarOffsetReadOnly( Parameter, &RelativeVar, resultType )) return;
|
---|
| 496 |
|
---|
| 497 | int beforeType = resultType.GetBasicType();
|
---|
| 498 |
|
---|
| 499 | resultType.PtrLevelUp();
|
---|
| 500 |
|
---|
| 501 | SetVarPtrToEax(&RelativeVar);
|
---|
| 502 |
|
---|
[111] | 503 | if( lstrcmpi( Parameter, "This" )==0 ){
|
---|
| 504 | // Thisの場合は特別にオブジェクトポインタが返ってくるので、何もせずに抜ける
|
---|
| 505 | }
|
---|
| 506 | else if( beforeType == DEF_OBJECT ){
|
---|
[109] | 507 | //参照をオブジェクトポインタに変更
|
---|
| 508 |
|
---|
| 509 | //mov eax,dword ptr[eax]
|
---|
[225] | 510 | compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EAX, REG_EAX, 0, MOD_BASE );
|
---|
[109] | 511 | }
|
---|
| 512 | else{
|
---|
| 513 | SetError(134,NULL,cp );
|
---|
| 514 | }
|
---|
| 515 | }
|
---|
[325] | 516 |
|
---|
| 517 | void Opcode_Func_delegate_call( const char *paramsStr, Type &resultType, bool isDynamicCall, bool isCallOn )
|
---|
| 518 | {
|
---|
| 519 | if( isCallOn )
|
---|
| 520 | {
|
---|
| 521 | int i = 0;
|
---|
| 522 | char methodPtrParamStr[VN_SIZE];
|
---|
| 523 | i = GetOneParameter( paramsStr, i, methodPtrParamStr );
|
---|
| 524 |
|
---|
[336] | 525 | char objPtrValueStr[VN_SIZE]="";
|
---|
[325] | 526 | if( isDynamicCall )
|
---|
| 527 | {
|
---|
| 528 | i = GetOneParameter( paramsStr, i, objPtrValueStr );
|
---|
| 529 | }
|
---|
| 530 |
|
---|
| 531 | Opcode_CallDelegate( compiler.pCompilingClass->GetDelegate(), methodPtrParamStr, objPtrValueStr, paramsStr + i );
|
---|
| 532 | }
|
---|
| 533 |
|
---|
| 534 | resultType = UserProc::CompilingUserProc().ReturnType();
|
---|
| 535 | }
|
---|
| 536 |
|
---|
[46] | 537 | void Opcode_Func_GetPtrData(const char *Parameter,const int type){
|
---|
[76] | 538 | Type tempType;
|
---|
| 539 | if( !NumOpe(Parameter,Type(),tempType) ){
|
---|
| 540 | return;
|
---|
| 541 | }
|
---|
| 542 | if(!tempType.IsWhole()){
|
---|
| 543 | SetError(11,Parameter,cp);
|
---|
| 544 | return;
|
---|
| 545 | }
|
---|
| 546 | ChangeTypeToLong(tempType.GetBasicType());
|
---|
[3] | 547 |
|
---|
| 548 | if(type==DEF_DOUBLE){
|
---|
| 549 | //pop eax
|
---|
[225] | 550 | compiler.codeGenerator.op_pop(REG_EAX);
|
---|
[3] | 551 |
|
---|
| 552 | //fld qword ptr[eax]
|
---|
[235] | 553 | compiler.codeGenerator.PutOld(
|
---|
| 554 | (char)0xDD,
|
---|
| 555 | (char)0x00
|
---|
| 556 | );
|
---|
[3] | 557 | }
|
---|
| 558 | else if(type==DEF_SINGLE||type==DEF_DWORD){
|
---|
| 559 | //pop eax
|
---|
[225] | 560 | compiler.codeGenerator.op_pop(REG_EAX);
|
---|
[3] | 561 |
|
---|
| 562 | //mov eax,dword ptr[eax]
|
---|
[235] | 563 | compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EAX, REG_EAX, 0, MOD_BASE );
|
---|
[3] | 564 | }
|
---|
| 565 | else if(type==DEF_QWORD){
|
---|
| 566 | //pop ecx
|
---|
[225] | 567 | compiler.codeGenerator.op_pop(REG_ECX);
|
---|
[3] | 568 |
|
---|
| 569 | //mov eax,dword ptr[ecx]
|
---|
[225] | 570 | compiler.codeGenerator.op_mov_RM(sizeof(long),REG_EAX,REG_ECX,0,MOD_BASE);
|
---|
[3] | 571 |
|
---|
| 572 | //mov edx,dword ptr[ecx+sizeof(long)]
|
---|
[225] | 573 | compiler.codeGenerator.op_mov_RM(sizeof(long),REG_EDX,REG_ECX,sizeof(long),MOD_BASE_DISP8);
|
---|
[3] | 574 | }
|
---|
| 575 | else if(type==DEF_WORD){
|
---|
| 576 | //pop ebx
|
---|
[225] | 577 | compiler.codeGenerator.op_pop(REG_EBX);
|
---|
[3] | 578 |
|
---|
| 579 | //xor eax,eax
|
---|
[227] | 580 | compiler.codeGenerator.op_xor_RR(REG_EAX);
|
---|
[3] | 581 |
|
---|
| 582 | //mov ax,word ptr[ebx]
|
---|
[235] | 583 | compiler.codeGenerator.op_mov_RM( sizeof(short), REG_EAX, REG_EBX, 0, MOD_BASE );
|
---|
[3] | 584 | }
|
---|
| 585 | else if(type==DEF_BYTE){
|
---|
| 586 | //pop ebx
|
---|
[225] | 587 | compiler.codeGenerator.op_pop(REG_EBX);
|
---|
[3] | 588 |
|
---|
| 589 | //xor eax,eax
|
---|
[227] | 590 | compiler.codeGenerator.op_xor_RR(REG_EAX);
|
---|
[3] | 591 |
|
---|
| 592 | //mov al,byte ptr[ebx]
|
---|
[235] | 593 | compiler.codeGenerator.op_mov_RM( sizeof(char), REG_EAX, REG_EBX, 0, MOD_BASE );
|
---|
[3] | 594 | }
|
---|
| 595 | }
|
---|
| 596 |
|
---|
[331] | 597 | bool Opcode_CallFunc( const char *Parameter, const int FuncNum, const Type &baseType, Type &resultType, bool isCallOn )
|
---|
| 598 | {
|
---|
[3] | 599 | switch(FuncNum){
|
---|
| 600 | case FUNC_FIX:
|
---|
[76] | 601 | if( isCallOn ) Opcode_Func_Fix(Parameter);
|
---|
| 602 | resultType.SetBasicType( DEF_LONG );
|
---|
[46] | 603 | break;
|
---|
[3] | 604 | case FUNC_CUDBL:
|
---|
[76] | 605 | if( isCallOn ) Opcode_Func_CUDbl(Parameter);
|
---|
| 606 | resultType.SetBasicType( DEF_DOUBLE );
|
---|
[46] | 607 | break;
|
---|
[3] | 608 | case FUNC_LEN:
|
---|
[76] | 609 | if( isCallOn ) Opcode_Func_Len(Parameter);
|
---|
| 610 | resultType.SetBasicType( DEF_LONG );
|
---|
[46] | 611 | break;
|
---|
[3] | 612 | case FUNC_ADDRESSOF:
|
---|
[332] | 613 | Opcode_Func_AddressOf( Parameter, baseType, isCallOn, resultType );
|
---|
[46] | 614 | break;
|
---|
[3] | 615 | case FUNC_SIZEOF:
|
---|
[76] | 616 | if( isCallOn ) Opcode_Func_SizeOf(Parameter);
|
---|
| 617 | resultType.SetBasicType( DEF_LONG );
|
---|
[46] | 618 | break;
|
---|
[3] | 619 | case FUNC_VARPTR:
|
---|
[76] | 620 | Opcode_Func_VarPtr( Parameter, resultType, isCallOn );
|
---|
[46] | 621 | break;
|
---|
[109] | 622 | case FUNC_OBJPTR:
|
---|
| 623 | Opcode_Func_ObjPtr( Parameter, resultType, isCallOn );
|
---|
| 624 | break;
|
---|
[325] | 625 | case FUNC_DELEGATE_DYNAMICMETHOD_CALL:
|
---|
| 626 | Opcode_Func_delegate_call( Parameter, resultType, true, isCallOn );
|
---|
| 627 | break;
|
---|
| 628 | case FUNC_DELEGATE_STATICMETHOD_CALL:
|
---|
| 629 | Opcode_Func_delegate_call( Parameter, resultType, false, isCallOn );
|
---|
| 630 | break;
|
---|
[3] | 631 |
|
---|
| 632 | case FUNC_GETDOUBLE:
|
---|
[76] | 633 | if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_DOUBLE);
|
---|
| 634 | resultType.SetBasicType( DEF_DOUBLE );
|
---|
[46] | 635 | break;
|
---|
[3] | 636 | case FUNC_GETSINGLE:
|
---|
[76] | 637 | if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_SINGLE);
|
---|
| 638 | resultType.SetBasicType( DEF_SINGLE );
|
---|
[46] | 639 | break;
|
---|
[3] | 640 | case FUNC_GETQWORD:
|
---|
[76] | 641 | if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_QWORD);
|
---|
| 642 | resultType.SetBasicType( DEF_QWORD );
|
---|
[46] | 643 | break;
|
---|
[3] | 644 | case FUNC_GETDWORD:
|
---|
[76] | 645 | if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_DWORD);
|
---|
| 646 | resultType.SetBasicType( DEF_DWORD );
|
---|
[46] | 647 | break;
|
---|
[3] | 648 | case FUNC_GETWORD:
|
---|
[76] | 649 | if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_WORD);
|
---|
| 650 | resultType.SetBasicType( DEF_WORD );
|
---|
[46] | 651 | break;
|
---|
[3] | 652 | case FUNC_GETBYTE:
|
---|
[76] | 653 | if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_BYTE);
|
---|
| 654 | resultType.SetBasicType( DEF_BYTE );
|
---|
[46] | 655 | break;
|
---|
[76] | 656 | default:
|
---|
| 657 | return false;
|
---|
[3] | 658 | }
|
---|
[76] | 659 | return true;
|
---|
[3] | 660 | }
|
---|