source: dev/trunk/ab5.0/abdev/BasicCompiler32/Compile_Func.cpp@ 449

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

・デリゲートの共変戻り値、反変引数に対応した。
・core.libで定義されたデリゲートがアプリケーションプロジェクトで利用できないバグを修正。

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