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

Last change on this file since 358 was 358, checked in by dai_9181, 16 years ago

Try-Catchを試験的に実装。
(まだ下記の動作しか実装していません)
・Try
・Catch(パラメータ無し)
・Throw(パラメータ無し)

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