source: dev/trunk/ab5.0/abdev/compiler_x86/Compile_Func.cpp@ 523

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

ヘッダファイルを整理中

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