source: dev/trunk/abdev/BasicCompiler32/Compile_Func.cpp@ 370

Last change on this file since 370 was 370, checked in by dai_9181, 17 years ago

COM修飾子に対応。COMインターフェイスを呼び出せるようにした

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