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