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