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 | |
---|
16 | int GetFunctionFromName(char *FuncName){ |
---|
17 | if( lstrcmpi( FuncName, "Len" ) == 0 ) return FUNC_LEN; |
---|
18 | if( lstrcmpi( FuncName, "AddressOf" ) == 0 ) return FUNC_ADDRESSOF; |
---|
19 | if( lstrcmpi( FuncName, "SizeOf" ) == 0 ) return FUNC_SIZEOF; |
---|
20 | if( lstrcmpi( FuncName, "VarPtr" ) == 0 ) return FUNC_VARPTR; |
---|
21 | if( lstrcmpi( FuncName, "ObjPtr" ) == 0 ) return FUNC_OBJPTR; |
---|
22 | if( lstrcmpi( FuncName, "__delegate_dynamicmethod_call" ) == 0 ) return FUNC_DELEGATE_DYNAMICMETHOD_CALL; |
---|
23 | if( lstrcmpi( FuncName, "__delegate_staticmethod_call" ) == 0 ) return FUNC_DELEGATE_STATICMETHOD_CALL; |
---|
24 | if( lstrcmpi( FuncName, "_System_GetNowScopeCatchAddresses" ) == 0 )return FUNC_SYSTEM_GET_NOW_SCOPE_CATCH_ADDRESS; |
---|
25 | if( lstrcmpi( FuncName, "_System_GetNowScopeFinallyAddresses" ) == 0 )return FUNC_SYSTEM_GET_NOW_SCOPE_FINALLY_ADDRESS; |
---|
26 | if( lstrcmpi( FuncName, "_System_GetBp" ) == 0 ) return FUNC_SYSTEM_GET_BP; |
---|
27 | if( lstrcmpi( FuncName, "_System_GetSp" ) == 0 ) return FUNC_SYSTEM_GET_SP; |
---|
28 | if( lstrcmp( FuncName, "_System_GetComVtbl" ) == 0 ) return FUNC_SYSTEM_GET_COM_VTBL; |
---|
29 | if( lstrcmp( FuncName, "_System_GetVtblList" ) == 0 ) return FUNC_SYSTEM_GET_VTBL_LIST; |
---|
30 | if( lstrcmp( FuncName, "_System_GetDefaultConstructor" ) == 0 ) return FUNC_SYSTEM_GET_DEFAULT_CONSTRUCTOR; |
---|
31 | if( lstrcmp( FuncName, "_System_GetDestructor" ) == 0 ) return FUNC_SYSTEM_GET_DESTRUCTOR; |
---|
32 | if( lstrcmpi( FuncName, "GetDouble" ) == 0 ) return FUNC_GETDOUBLE; |
---|
33 | if( lstrcmpi( FuncName, "GetSingle" ) == 0 ) return FUNC_GETSINGLE; |
---|
34 | if( lstrcmpi( FuncName, "GetQWord" ) == 0 ) return FUNC_GETQWORD; |
---|
35 | if( lstrcmpi( FuncName, "GetDWord" ) == 0 ) return FUNC_GETDWORD; |
---|
36 | if( lstrcmpi( FuncName, "GetWord" ) == 0 ) return FUNC_GETWORD; |
---|
37 | if( lstrcmpi( FuncName, "GetByte" ) == 0 ) return FUNC_GETBYTE; |
---|
38 | return 0; |
---|
39 | } |
---|
40 | void Opcode_Func_Len( const char *Parameter ){ |
---|
41 | BOOL bArrayHead; |
---|
42 | |
---|
43 | const char *tempParm=Parameter; |
---|
44 | char temporary[VN_SIZE]; |
---|
45 | char temp2[32]; |
---|
46 | Type type; |
---|
47 | if( !GetVarType(Parameter,type,0) ){ |
---|
48 | sprintf(temporary,"_System_DummyStr2=%s",Parameter); |
---|
49 | OpcodeCalc(temporary); |
---|
50 | |
---|
51 | lstrcpy(temp2,"_System_DummyStr2"); |
---|
52 | tempParm=temp2; |
---|
53 | |
---|
54 | type.SetType( DEF_OBJECT, compiler.GetObjectModule().meta.GetClasses().GetStringClassPtr() ); |
---|
55 | } |
---|
56 | |
---|
57 | if( type.IsStringClass() ){ |
---|
58 | //Stringオブジェクトの場合 |
---|
59 | sprintf(temporary,"%s.Length",tempParm); |
---|
60 | |
---|
61 | int reg=REG_RAX; |
---|
62 | NumOpe(®,temporary,Type(),Type()); |
---|
63 | return; |
---|
64 | } |
---|
65 | |
---|
66 | Subscripts subscripts; |
---|
67 | RELATIVE_VAR RelativeVar; |
---|
68 | if(!GetVarOffsetReadOnly(tempParm,&RelativeVar,type,&subscripts)) return; |
---|
69 | |
---|
70 | if(type.GetBasicType()&FLAG_PTR){ |
---|
71 | type.SetBasicType( type.GetBasicType() & ( ~FLAG_PTR ) ); |
---|
72 | |
---|
73 | bArrayHead=1; |
---|
74 | } |
---|
75 | else bArrayHead=0; |
---|
76 | |
---|
77 | int typeSize = type.GetSize(); |
---|
78 | |
---|
79 | if(bArrayHead) typeSize*=JumpSubScripts(subscripts); |
---|
80 | |
---|
81 | //mov rax,TypeSize |
---|
82 | compiler.codeGenerator.op_mov_RV(sizeof(_int64),REG_RAX,typeSize); |
---|
83 | |
---|
84 | return; |
---|
85 | } |
---|
86 | |
---|
87 | void _Opcode_Func_AddressOf( const char *methodInstanceName, const UserProc &userProc ) |
---|
88 | { |
---|
89 | if( userProc.IsVirtual() ) |
---|
90 | { |
---|
91 | /////////////////////////////// |
---|
92 | // 仮想関数の場合 |
---|
93 | // thisポインタをrcxにコピー |
---|
94 | /////////////////////////////// |
---|
95 | |
---|
96 | const CClass *pobj_c; |
---|
97 | |
---|
98 | char ObjectName[VN_SIZE]; |
---|
99 | ReferenceKind referenceKind; |
---|
100 | SplitObjectName(methodInstanceName,ObjectName, referenceKind ); |
---|
101 | |
---|
102 | if(ObjectName[0]){ |
---|
103 | if(lstrcmpi(ObjectName,"Super")==0) goto InClassMember; |
---|
104 | else{ |
---|
105 | RELATIVE_VAR RelativeVar; |
---|
106 | Type type; |
---|
107 | if(!GetVarOffsetReadOnly(ObjectName,&RelativeVar,type)) return; |
---|
108 | SetVarPtrToReg(REG_RCX,&RelativeVar); |
---|
109 | |
---|
110 | //参照タイプが整合しているかをチェック |
---|
111 | if( !( type.IsObject() && referenceKind == RefDot |
---|
112 | || type.IsObjectPtr() && referenceKind == RefPointer ) ) |
---|
113 | { |
---|
114 | SetError(104,ObjectName,cp); |
---|
115 | } |
---|
116 | |
---|
117 | if(type.IsObjectPtr()){ |
---|
118 | //mov rcx,qword ptr[rcx] |
---|
119 | compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_RCX,REG_RCX,0,MOD_BASE); |
---|
120 | } |
---|
121 | } |
---|
122 | } |
---|
123 | else{ |
---|
124 | InClassMember: |
---|
125 | //自身のオブジェクトのThisポインタをrcxにコピー |
---|
126 | SetThisPtrToReg(REG_RCX); |
---|
127 | |
---|
128 | pobj_c=compiler.pCompilingClass; |
---|
129 | } |
---|
130 | |
---|
131 | |
---|
132 | int vtblIndex; |
---|
133 | if( pobj_c->IsInterface() ) |
---|
134 | { |
---|
135 | // インターフェイスメソッド |
---|
136 | |
---|
137 | int offset_vtbl = compiler.GetObjectModule().meta.GetClasses().GetInterfaceInfoClassPtr()->GetMemberOffset( "__vtbl" ); |
---|
138 | |
---|
139 | // vtblのポインタを取得 |
---|
140 | //mov r11,qword ptr[rcx+offset_vtbl] |
---|
141 | compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_RCX,offset_vtbl,MOD_BASE_DISP8); |
---|
142 | |
---|
143 | int offset_this = compiler.GetObjectModule().meta.GetClasses().GetInterfaceInfoClassPtr()->GetMemberOffset( "__this" ); |
---|
144 | |
---|
145 | // インターフェイスの場合は更に__thisを取得する |
---|
146 | //mov rcx,qword ptr[rcx+offset_this] |
---|
147 | compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_RCX,REG_RCX,offset_this,MOD_BASE_DISP8); |
---|
148 | |
---|
149 | int vtblMasterListIndex; |
---|
150 | pobj_c->GetVtblMasterListIndexAndVtblIndex( &userProc, vtblMasterListIndex, vtblIndex ); |
---|
151 | if( vtblMasterListIndex != 0 ) |
---|
152 | { |
---|
153 | SetError(); |
---|
154 | } |
---|
155 | } |
---|
156 | else if( pobj_c->IsComInterface() ) |
---|
157 | { |
---|
158 | //仮想関数(オブジェクトメソッド) |
---|
159 | // pObj -> vtbl1 -> func1 |
---|
160 | // -> func2 |
---|
161 | // -> func3 |
---|
162 | |
---|
163 | int vtblMasterListIndex; |
---|
164 | pobj_c->GetVtblMasterListIndexAndVtblIndex( &userProc, vtblMasterListIndex, vtblIndex ); |
---|
165 | |
---|
166 | // vtblのポインタを取得 |
---|
167 | //mov r11,qword ptr[rcx] |
---|
168 | compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_RCX,0,MOD_BASE); |
---|
169 | } |
---|
170 | else |
---|
171 | { |
---|
172 | //仮想関数(オブジェクトメソッド) |
---|
173 | // pObj -> vtbl_master_list -> vtbl1 -> func1 |
---|
174 | // -> func2 |
---|
175 | // -> func3 |
---|
176 | // -> vtbl2 -> func1 |
---|
177 | // -> func2 |
---|
178 | // -> func3 |
---|
179 | |
---|
180 | int vtblMasterListIndex; |
---|
181 | pobj_c->GetVtblMasterListIndexAndVtblIndex( &userProc, vtblMasterListIndex, vtblIndex ); |
---|
182 | |
---|
183 | // vtblマスターリストのポインタを取得 |
---|
184 | //mov r11,qword ptr[rcx+sizeof(com_vtbl)] |
---|
185 | compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_RCX,PTR_SIZE,MOD_BASE_DISP8); |
---|
186 | |
---|
187 | // vtblのポインタを取得 |
---|
188 | //mov r11,dword ptr[r11+vtblMasterListIndex] |
---|
189 | compiler.codeGenerator.op_mov_RM( sizeof(_int64), REG_R11, REG_R11, vtblMasterListIndex, MOD_BASE_DISP32 ); |
---|
190 | } |
---|
191 | |
---|
192 | //mov rax,qword ptr[r11+func_index] |
---|
193 | if( vtblIndex * PTR_SIZE <= 0x7F ) |
---|
194 | { |
---|
195 | compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_RAX,REG_R11,vtblIndex*PTR_SIZE,MOD_BASE_DISP8); |
---|
196 | } |
---|
197 | else |
---|
198 | { |
---|
199 | compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_RAX,REG_R11,vtblIndex*PTR_SIZE,MOD_BASE_DISP32); |
---|
200 | } |
---|
201 | } |
---|
202 | else{ |
---|
203 | //一般の関数 |
---|
204 | |
---|
205 | //mov rax,ProcAddr |
---|
206 | compiler.codeGenerator.op_addressof( REG_RAX, &userProc ); |
---|
207 | } |
---|
208 | |
---|
209 | userProc.Using(); |
---|
210 | } |
---|
211 | void Opcode_CreateDelegate( const CClass &dgClass, const char *methodInstanceName, const UserProc &userProc ) |
---|
212 | { |
---|
213 | ///////////////////////////////////////////////////////////////// |
---|
214 | // 関数ポインタをpush |
---|
215 | ///////////////////////////////////////////////////////////////// |
---|
216 | |
---|
217 | //mov rax,AddressOf |
---|
218 | _Opcode_Func_AddressOf( methodInstanceName, userProc ); |
---|
219 | |
---|
220 | |
---|
221 | if( userProc.GetMethod().IsDynamic() ) |
---|
222 | { |
---|
223 | //mov rdx,rax |
---|
224 | compiler.codeGenerator.op_mov_RR( REG_RDX, REG_RAX ); |
---|
225 | |
---|
226 | pobj_BlockReg->lock( REG_RDX ); |
---|
227 | |
---|
228 | |
---|
229 | ///////////////////////////////////////////////////////////////// |
---|
230 | // オブジェクト ポインタをpush |
---|
231 | ///////////////////////////////////////////////////////////////// |
---|
232 | |
---|
233 | // オブジェクト名を取得 |
---|
234 | char objectName[VN_SIZE]; |
---|
235 | char memberName[VN_SIZE]; |
---|
236 | char *thisPtrName = "This"; |
---|
237 | Type type; |
---|
238 | if( SplitMemberName( methodInstanceName, objectName, memberName ) ) |
---|
239 | { |
---|
240 | if( GetVarType( objectName, type, false ) ) |
---|
241 | { |
---|
242 | thisPtrName = objectName; |
---|
243 | } |
---|
244 | } |
---|
245 | |
---|
246 | // オブジェクト ポインタを取得 |
---|
247 | RELATIVE_VAR relativeVar; |
---|
248 | GetVarOffsetReadOnly( thisPtrName, &relativeVar, type ); |
---|
249 | if( !type.IsObject() ) |
---|
250 | { |
---|
251 | extern int cp; |
---|
252 | SetError(1,NULL,cp); |
---|
253 | return; |
---|
254 | } |
---|
255 | |
---|
256 | SetVarPtrToReg( REG_RAX, &relativeVar ); |
---|
257 | |
---|
258 | //mov rcx,dword ptr[rax] |
---|
259 | compiler.codeGenerator.op_mov_RM( sizeof(_int64), REG_RCX, REG_RAX, 0, MOD_BASE ); |
---|
260 | |
---|
261 | pobj_BlockReg->unlock( REG_RDX ); |
---|
262 | } |
---|
263 | else |
---|
264 | { |
---|
265 | //mov rcx,rax |
---|
266 | compiler.codeGenerator.op_mov_RR( REG_RCX, REG_RAX ); |
---|
267 | } |
---|
268 | |
---|
269 | |
---|
270 | ///////////////////////////////////////////////////////////////// |
---|
271 | // call _CreateDynamicDelegate/_CreateStaticDelegate |
---|
272 | ///////////////////////////////////////////////////////////////// |
---|
273 | |
---|
274 | std::vector<const UserProc *> subs; |
---|
275 | if( userProc.GetMethod().IsDynamic() ) |
---|
276 | { |
---|
277 | dgClass.GetStaticMethods().Enum( "_CreateDynamicDelegate", subs ); |
---|
278 | } |
---|
279 | else |
---|
280 | { |
---|
281 | dgClass.GetStaticMethods().Enum( "_CreateStaticDelegate", subs ); |
---|
282 | } |
---|
283 | |
---|
284 | // call _CreateDynamicDelegate |
---|
285 | compiler.codeGenerator.op_call( subs[0] ); |
---|
286 | } |
---|
287 | void Opcode_Func_AddressOf( const char *name, const Type &baseType, bool isCallOn, Type &resultType ) |
---|
288 | { |
---|
289 | extern int cp; |
---|
290 | |
---|
291 | const Parameters *pBaseParams = NULL; |
---|
292 | const Type *pBaseReturnType = NULL; |
---|
293 | if( baseType.IsProcPtr() ) |
---|
294 | { |
---|
295 | // 左辺で関数ポインタを要求されているとき |
---|
296 | const ProcPointer *pTempProcPointer = compiler.GetObjectModule().meta.GetProcPointers()[baseType.GetIndex()]; |
---|
297 | pBaseParams = &pTempProcPointer->Params(); |
---|
298 | pBaseReturnType = &pTempProcPointer->ReturnType(); |
---|
299 | } |
---|
300 | else if( baseType.IsDelegate() ) |
---|
301 | { |
---|
302 | // 左辺でデリゲートを要求されているとき |
---|
303 | const Delegate *pTempDelegate = &baseType.GetClass().GetDelegate(); |
---|
304 | pBaseParams = &pTempDelegate->Params(); |
---|
305 | pBaseReturnType = &pTempDelegate->ReturnType(); |
---|
306 | } |
---|
307 | |
---|
308 | const UserProc *pUserProc; |
---|
309 | if( pBaseParams && pBaseReturnType ) |
---|
310 | { |
---|
311 | //左辺の型にのっとり、オーバーロードを解決 |
---|
312 | |
---|
313 | std::vector<const UserProc *> subs; |
---|
314 | GetOverloadSubHash( name, subs ); |
---|
315 | if( subs.size() == 0 ){ |
---|
316 | SetError(27,name,cp); |
---|
317 | return; |
---|
318 | } |
---|
319 | |
---|
320 | //オーバーロードを解決 |
---|
321 | pUserProc=OverloadSolution( name, subs, *pBaseParams, Type(), Type() ); |
---|
322 | |
---|
323 | if( isCallOn ) |
---|
324 | { |
---|
325 | // コード生成を伴う場合はエラーチェックを行う |
---|
326 | |
---|
327 | if( baseType.IsDelegate() ) |
---|
328 | { |
---|
329 | // デリゲート |
---|
330 | // 共変戻り値、反変引数をサポート |
---|
331 | if( !( |
---|
332 | pBaseParams->Equals( pUserProc->Params(), true ) |
---|
333 | && ( pBaseReturnType->Equals( pUserProc->ReturnType() ) || pBaseReturnType->IsCovariant( pUserProc->ReturnType() ) ) |
---|
334 | ) ) |
---|
335 | { |
---|
336 | SetError(67, name, cp ); |
---|
337 | } |
---|
338 | } |
---|
339 | else |
---|
340 | { |
---|
341 | // 関数ポインタ |
---|
342 | if( !( |
---|
343 | pBaseParams->Equals( pUserProc->Params() ) |
---|
344 | && pBaseReturnType->Equals( pUserProc->ReturnType() ) |
---|
345 | ) ) |
---|
346 | { |
---|
347 | SetError(66, name, cp ); |
---|
348 | } |
---|
349 | } |
---|
350 | } |
---|
351 | |
---|
352 | if(!pUserProc){ |
---|
353 | SetError(27,name,cp); |
---|
354 | return; |
---|
355 | } |
---|
356 | } |
---|
357 | else{ |
---|
358 | pUserProc=GetSubHash(name); |
---|
359 | if(!pUserProc){ |
---|
360 | SetError(27,name,cp); |
---|
361 | return; |
---|
362 | } |
---|
363 | } |
---|
364 | |
---|
365 | if( baseType.IsDelegate() ) |
---|
366 | { |
---|
367 | if( isCallOn ) |
---|
368 | { |
---|
369 | // デリゲートのとき |
---|
370 | Opcode_CreateDelegate( baseType.GetClass(), name, *pUserProc ); |
---|
371 | } |
---|
372 | resultType = baseType; |
---|
373 | } |
---|
374 | else |
---|
375 | { |
---|
376 | if( isCallOn ) |
---|
377 | { |
---|
378 | // 関数ポインタのとき |
---|
379 | _Opcode_Func_AddressOf( name, *pUserProc ); |
---|
380 | } |
---|
381 | resultType.SetBasicType( DEF_PTR_VOID ); |
---|
382 | } |
---|
383 | } |
---|
384 | void Opcode_Func_SizeOf( const string &typeName ){ |
---|
385 | Type tempType; |
---|
386 | if( !compiler.StringToType( typeName, tempType ) ){ |
---|
387 | SetError(3,typeName,cp); |
---|
388 | return; |
---|
389 | } |
---|
390 | |
---|
391 | int typeSize = ( tempType.IsObject() ) ? |
---|
392 | tempType.GetClass().GetSize() : tempType.GetSize(); |
---|
393 | |
---|
394 | //mov rax,size |
---|
395 | compiler.codeGenerator.op_mov_RV(sizeof(_int64),REG_RAX,typeSize); |
---|
396 | } |
---|
397 | void Opcode_Func_VarPtr( const char *Parameter, Type &resultType, bool isCallOn ){ |
---|
398 | if( isCallOn == false ){ |
---|
399 | // 戻り値の型を取得するだけ |
---|
400 | |
---|
401 | //変数のアドレスを取得 |
---|
402 | if(!GetVarType( Parameter, resultType, true )) return; |
---|
403 | |
---|
404 | resultType.PtrLevelUp(); |
---|
405 | |
---|
406 | return; |
---|
407 | } |
---|
408 | |
---|
409 | RELATIVE_VAR RelativeVar; |
---|
410 | |
---|
411 | //変数のアドレスを取得 |
---|
412 | if(!GetVarOffsetReadOnly( Parameter, &RelativeVar, resultType )) return; |
---|
413 | |
---|
414 | int beforeType = resultType.GetBasicType(); |
---|
415 | |
---|
416 | resultType.PtrLevelUp(); |
---|
417 | |
---|
418 | SetVarPtrToReg(REG_RAX,&RelativeVar); |
---|
419 | |
---|
420 | // TODO: 取り除く(この動きはObjPtrに託す) |
---|
421 | /* |
---|
422 | if( beforeType == DEF_OBJECT && lstrcmpi( Parameter, "This" ) != 0 ){ |
---|
423 | //参照をオブジェクトポインタに変更 |
---|
424 | |
---|
425 | //mov rax,qword ptr[rax] |
---|
426 | compiler.codeGenerator.op_mov_RM( sizeof(_int64), REG_RAX, REG_RAX, 0, MOD_BASE ); |
---|
427 | |
---|
428 | SetError(-120,NULL,cp); |
---|
429 | }*/ |
---|
430 | } |
---|
431 | void Opcode_Func_ObjPtr( const char *Parameter, Type &resultType, bool isCallOn ){ |
---|
432 | if( isCallOn == false ){ |
---|
433 | // 戻り値の型を取得するだけ |
---|
434 | |
---|
435 | //変数のアドレスを取得 |
---|
436 | if(!GetVarType( Parameter, resultType, true )) return; |
---|
437 | |
---|
438 | resultType.PtrLevelUp(); |
---|
439 | |
---|
440 | return; |
---|
441 | } |
---|
442 | |
---|
443 | RELATIVE_VAR RelativeVar; |
---|
444 | |
---|
445 | //変数のアドレスを取得 |
---|
446 | if(!GetVarOffsetReadOnly( Parameter, &RelativeVar, resultType )) return; |
---|
447 | |
---|
448 | int beforeType = resultType.GetBasicType(); |
---|
449 | |
---|
450 | resultType.PtrLevelUp(); |
---|
451 | |
---|
452 | SetVarPtrToReg(REG_RAX,&RelativeVar); |
---|
453 | |
---|
454 | if( lstrcmpi( Parameter, "This" )==0 ){ |
---|
455 | // Thisの場合は特別にオブジェクトポインタが返ってくるので、何もせずに抜ける |
---|
456 | } |
---|
457 | else if( beforeType == DEF_OBJECT ){ |
---|
458 | //参照をオブジェクトポインタに変更 |
---|
459 | |
---|
460 | //mov rax,qword ptr[rax] |
---|
461 | compiler.codeGenerator.op_mov_RM( sizeof(_int64), REG_RAX, REG_RAX, 0, MOD_BASE ); |
---|
462 | } |
---|
463 | else{ |
---|
464 | SetError(134,NULL,cp ); |
---|
465 | } |
---|
466 | } |
---|
467 | |
---|
468 | void Opcode_Func_delegate_call( const char *paramsStr, Type &resultType, bool isDynamicCall, bool isCallOn ) |
---|
469 | { |
---|
470 | if( isCallOn ) |
---|
471 | { |
---|
472 | int i = 0; |
---|
473 | char methodPtrParamStr[VN_SIZE]; |
---|
474 | i = GetOneParameter( paramsStr, i, methodPtrParamStr ); |
---|
475 | |
---|
476 | char objPtrValueStr[VN_SIZE] = ""; |
---|
477 | if( isDynamicCall ) |
---|
478 | { |
---|
479 | i = GetOneParameter( paramsStr, i, objPtrValueStr ); |
---|
480 | } |
---|
481 | |
---|
482 | Opcode_CallDelegate( compiler.pCompilingClass->GetDelegate(), methodPtrParamStr, objPtrValueStr, paramsStr + i ); |
---|
483 | } |
---|
484 | |
---|
485 | resultType = UserProc::CompilingUserProc().ReturnType(); |
---|
486 | } |
---|
487 | |
---|
488 | void Opcode_Func_System_Get_Bp() |
---|
489 | { |
---|
490 | //mov rax,rbp |
---|
491 | compiler.codeGenerator.op_mov_RR(REG_RAX,REG_RBP); |
---|
492 | } |
---|
493 | void Opcode_Func_System_Get_Sp() |
---|
494 | { |
---|
495 | //mov rax,rsp |
---|
496 | compiler.codeGenerator.op_mov_RR(REG_RAX,REG_RSP); |
---|
497 | } |
---|
498 | |
---|
499 | void Opcode_Func_System_GetComVtbl( const char *parameter ) |
---|
500 | { |
---|
501 | Type classType; |
---|
502 | compiler.StringToType( parameter, classType ); |
---|
503 | |
---|
504 | // mov rax,com_vtbl |
---|
505 | compiler.codeGenerator.op_mov_RV_com_vtbl( REG_RAX, &classType.GetClass() ); |
---|
506 | } |
---|
507 | void Opcode_Func_System_GetVtblList( const char *parameter ) |
---|
508 | { |
---|
509 | Type classType; |
---|
510 | compiler.StringToType( parameter, classType ); |
---|
511 | |
---|
512 | // mov rax,com_vtbl |
---|
513 | compiler.codeGenerator.op_mov_RV_vtbl( REG_RAX, &classType.GetClass() ); |
---|
514 | } |
---|
515 | void Opcode_Func_System_GetDefaultConstructor( const char *parameter ) |
---|
516 | { |
---|
517 | Type classType; |
---|
518 | compiler.StringToType( parameter, classType ); |
---|
519 | |
---|
520 | if( classType.GetClass().GetConstructorMethod() ) |
---|
521 | { |
---|
522 | //mov rax,ProcAddr |
---|
523 | compiler.codeGenerator.op_addressof( REG_RAX, &classType.GetClass().GetConstructorMethod()->GetUserProc() ); |
---|
524 | } |
---|
525 | else |
---|
526 | { |
---|
527 | // デフォルトコンストラクタを持たない |
---|
528 | |
---|
529 | //xor rax,rax |
---|
530 | compiler.codeGenerator.op_zero_reg( REG_RAX ); |
---|
531 | } |
---|
532 | } |
---|
533 | void Opcode_Func_System_GetDestructor( const char *parameter ) |
---|
534 | { |
---|
535 | Type classType; |
---|
536 | compiler.StringToType( parameter, classType ); |
---|
537 | |
---|
538 | //mov rax,ProcAddr |
---|
539 | compiler.codeGenerator.op_addressof( REG_RAX, &classType.GetClass().GetDestructorMethod()->GetUserProc() ); |
---|
540 | } |
---|
541 | |
---|
542 | void Opcode_Func_GetPtrData( const char *Parameter, const int type ){ |
---|
543 | int reg=REG_RAX; |
---|
544 | Type tempType; |
---|
545 | if( !NumOpe(®,Parameter,Type(),tempType) ){ |
---|
546 | return; |
---|
547 | } |
---|
548 | if(!tempType.IsWhole()){ |
---|
549 | SetError(11,Parameter,cp); |
---|
550 | return; |
---|
551 | } |
---|
552 | |
---|
553 | if(type==DEF_DOUBLE){ |
---|
554 | //movlpd xmm0,qword ptr[rax] |
---|
555 | compiler.codeGenerator.op_movlpd_RM(REG_XMM0,REG_RAX,0,MOD_BASE); |
---|
556 | } |
---|
557 | else if(type==DEF_SINGLE){ |
---|
558 | //movss xmm0,dword ptr[rax] |
---|
559 | compiler.codeGenerator.op_movss_RM(REG_XMM0,REG_RAX,0,MOD_BASE); |
---|
560 | } |
---|
561 | else{ |
---|
562 | //mov rax,ptr[rax] |
---|
563 | compiler.codeGenerator.op_mov_RM(Type(type).GetSize(),REG_RAX,REG_RAX,0,MOD_BASE); |
---|
564 | } |
---|
565 | } |
---|
566 | |
---|
567 | bool Opcode_CallFunc( const char *Parameter, const int FuncNum, const Type &baseType, Type &resultType, bool isCallOn ) |
---|
568 | { |
---|
569 | switch(FuncNum){ |
---|
570 | case FUNC_LEN: |
---|
571 | if( isCallOn ) Opcode_Func_Len(Parameter); |
---|
572 | resultType.SetBasicType( DEF_LONG ); |
---|
573 | break; |
---|
574 | case FUNC_ADDRESSOF: |
---|
575 | Opcode_Func_AddressOf( Parameter, baseType, isCallOn, resultType ); |
---|
576 | break; |
---|
577 | case FUNC_SIZEOF: |
---|
578 | if( isCallOn ) Opcode_Func_SizeOf(Parameter); |
---|
579 | resultType.SetBasicType( DEF_LONG ); |
---|
580 | break; |
---|
581 | case FUNC_VARPTR: |
---|
582 | Opcode_Func_VarPtr( Parameter, resultType, isCallOn ); |
---|
583 | break; |
---|
584 | case FUNC_OBJPTR: |
---|
585 | Opcode_Func_ObjPtr( Parameter, resultType, isCallOn ); |
---|
586 | break; |
---|
587 | case FUNC_DELEGATE_DYNAMICMETHOD_CALL: |
---|
588 | Opcode_Func_delegate_call( Parameter, resultType, true, isCallOn ); |
---|
589 | break; |
---|
590 | case FUNC_DELEGATE_STATICMETHOD_CALL: |
---|
591 | Opcode_Func_delegate_call( Parameter, resultType, false, isCallOn ); |
---|
592 | break; |
---|
593 | case FUNC_SYSTEM_GET_NOW_SCOPE_CATCH_ADDRESS: |
---|
594 | if( isCallOn ) Exception::Opcode_Func_System_GetNowScopeCatchAddress(); |
---|
595 | resultType.SetBasicType( DEF_PTR_VOID ); |
---|
596 | break; |
---|
597 | case FUNC_SYSTEM_GET_NOW_SCOPE_FINALLY_ADDRESS: |
---|
598 | if( isCallOn ) Exception::Opcode_Func_System_GetNowScopeFinallyAddress(); |
---|
599 | resultType.SetBasicType( DEF_PTR_VOID ); |
---|
600 | break; |
---|
601 | case FUNC_SYSTEM_GET_BP: |
---|
602 | if( isCallOn ) Opcode_Func_System_Get_Bp(); |
---|
603 | resultType.SetBasicType( DEF_INT64 ); |
---|
604 | break; |
---|
605 | case FUNC_SYSTEM_GET_SP: |
---|
606 | if( isCallOn ) Opcode_Func_System_Get_Sp(); |
---|
607 | resultType.SetBasicType( DEF_INT64 ); |
---|
608 | break; |
---|
609 | case FUNC_SYSTEM_GET_COM_VTBL: |
---|
610 | if( isCallOn ) Opcode_Func_System_GetComVtbl( Parameter ); |
---|
611 | resultType.SetBasicType( DEF_PTR_VOID ); |
---|
612 | break; |
---|
613 | case FUNC_SYSTEM_GET_VTBL_LIST: |
---|
614 | if( isCallOn ) Opcode_Func_System_GetVtblList( Parameter ); |
---|
615 | resultType.SetBasicType( DEF_PTR_VOID ); |
---|
616 | break; |
---|
617 | case FUNC_SYSTEM_GET_DEFAULT_CONSTRUCTOR: |
---|
618 | if( isCallOn ) Opcode_Func_System_GetDefaultConstructor( Parameter ); |
---|
619 | resultType.SetBasicType( DEF_PTR_VOID ); |
---|
620 | break; |
---|
621 | case FUNC_SYSTEM_GET_DESTRUCTOR: |
---|
622 | if( isCallOn ) Opcode_Func_System_GetDestructor( Parameter ); |
---|
623 | resultType.SetBasicType( DEF_PTR_VOID ); |
---|
624 | break; |
---|
625 | |
---|
626 | case FUNC_GETDOUBLE: |
---|
627 | if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_DOUBLE); |
---|
628 | resultType.SetBasicType( DEF_DOUBLE ); |
---|
629 | break; |
---|
630 | case FUNC_GETSINGLE: |
---|
631 | if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_SINGLE); |
---|
632 | resultType.SetBasicType( DEF_SINGLE ); |
---|
633 | break; |
---|
634 | case FUNC_GETQWORD: |
---|
635 | if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_QWORD); |
---|
636 | resultType.SetBasicType( DEF_QWORD ); |
---|
637 | break; |
---|
638 | case FUNC_GETDWORD: |
---|
639 | if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_DWORD); |
---|
640 | resultType.SetBasicType( DEF_DWORD ); |
---|
641 | break; |
---|
642 | case FUNC_GETWORD: |
---|
643 | if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_WORD); |
---|
644 | resultType.SetBasicType( DEF_WORD ); |
---|
645 | break; |
---|
646 | case FUNC_GETBYTE: |
---|
647 | if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_BYTE); |
---|
648 | resultType.SetBasicType( DEF_BYTE ); |
---|
649 | break; |
---|
650 | default: |
---|
651 | return false; |
---|
652 | } |
---|
653 | return true; |
---|
654 | } |
---|