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

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

_System_Newに対応(32bit版のみ)。

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