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