source: dev/BasicCompiler32/Compile_Set_Var.cpp@ 58

Last change on this file since 58 was 55, checked in by dai_9181, 18 years ago

・コマンドラインオプション "/unicode" に対応。
・Unicode文字セットを使用する場合に "UNICODE" が自動的に#defineされるようにしました。
・SByte型(8ビット符号付き整数型)を追加。
・Char型を文字型に変更。
・プロジェクトオプションから「Unicode文字セットを使用する」チェックを選択できるようにしました。

File size: 21.0 KB
Line 
1#include "../BasicCompiler_Common/common.h"
2#include "Opcode.h"
3
4BOOL IsUse_ecx(RELATIVE_VAR *pRelativeVar){
5 if(pRelativeVar->bOffsetOffset||pRelativeVar->dwKind==VAR_DIRECTMEM) return 1;
6 return 0;
7}
8
9void SetObjectVariable(LONG_PTR lpVarIndex,int CalcType,LONG_PTR lpCalcIndex,BOOL bUseHeap){
10 ///////////////////////////////////////////////////////////////////
11 // オペレータ '=' のオーバーロード関数を呼ぶ
12 ///////////////////////////////////////////////////////////////////
13
14 int type[10];
15 LONG_PTR index_stack[10];
16 BOOL array_bUseHeap[10];
17 int sp=2;
18
19 //左辺
20 type[0]=DEF_OBJECT;
21 index_stack[0]=lpVarIndex;
22 array_bUseHeap[0]=0;
23
24 //右辺
25 type[1]=CalcType;
26 index_stack[1]=lpCalcIndex;
27 array_bUseHeap[1]=bUseHeap;
28
29 int iRet;
30 iRet=CallOperatorProc(CALC_SUBSITUATION,NULL,type,index_stack,array_bUseHeap,sp);
31 if(iRet==-1||iRet==1){
32 //成功したとき、またはエラーが発行されたとき
33 return;
34 }
35
36
37 if( CalcType == DEF_OBJECT ){
38 CClass *pVarClass = (CClass *)lpVarIndex;
39 CClass *pCalcClass = (CClass *)lpCalcIndex;
40
41
42 if( pVarClass->IsEquals( pCalcClass ) //等しい
43 || pVarClass->IsSubClass( pCalcClass ) ){ //派生・継承関係
44
45 //双方のオブジェクト型が一致、または派生・継承関係にあるとき
46 //※コピーを行う
47
48 int object_size;
49 object_size=GetSizeOfClass((CClass *)lpVarIndex);
50
51 //mov ecx,object_size
52 op_mov_RV(REG_ECX,object_size);
53
54 //pop esi
55 op_pop(REG_ESI);
56
57 //pop edi
58 op_pop(REG_EDI);
59
60 if(bUseHeap){
61 //mov eax,esi
62 op_mov_RR(REG_EAX,REG_ESI);
63 }
64
65 //rep movs byte ptr[edi],byte ptr[esi]
66 op_rep_movs(sizeof(BYTE));
67
68 if(bUseHeap){
69 //push eax
70 op_push(REG_EAX);
71
72 //call free
73 extern SUBINFO *pSub_free;
74 op_call(pSub_free);
75 }
76
77 return;
78 }
79 }
80
81 SetError(1,NULL,cp);
82}
83
84void SetDoubleVariable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset){
85 ChangeTypeToDouble(type);
86
87 //pop ebx
88 op_pop(REG_EBX);
89
90 //pop eax
91 op_pop(REG_EAX);
92
93 if(VarKind==VAR_GLOBAL){
94 if(bOffsetOffset){
95 //mov dword ptr[ecx+offset],ebx
96 OpBuffer[obp++]=(char)0x89;
97 OpBuffer[obp++]=(char)0x99;
98 *((long *)(OpBuffer+obp))=offset;
99 pobj_GlobalVarSchedule->add();
100 obp+=sizeof(long);
101
102 //mov dword ptr[ecx+offset+sizeof(long)],eax
103 OpBuffer[obp++]=(char)0x89;
104 OpBuffer[obp++]=(char)0x81;
105 *((long *)(OpBuffer+obp))=offset+sizeof(long);
106 pobj_GlobalVarSchedule->add();
107 obp+=sizeof(long);
108 }
109 else{
110 //mov dword ptr[offset],ebx
111 OpBuffer[obp++]=(char)0x89;
112 OpBuffer[obp++]=(char)0x1D;
113 *((long *)(OpBuffer+obp))=offset;
114 pobj_GlobalVarSchedule->add();
115 obp+=sizeof(long);
116
117 //mov dword ptr[offset+sizeof(long)],eax
118 OpBuffer[obp++]=(char)0xA3;
119 *((long *)(OpBuffer+obp))=offset+sizeof(long);
120 pobj_GlobalVarSchedule->add();
121 obp+=sizeof(long);
122 }
123 }
124 else if(VarKind==VAR_LOCAL){
125 if(bOffsetOffset){
126 //add ecx,offset
127 OpBuffer[obp++]=(char)0x81;
128 OpBuffer[obp++]=(char)0xC1;
129 *((long *)(OpBuffer+obp))=offset;
130 AddLocalVarAddrSchedule();
131 obp+=sizeof(long);
132
133 //mov dword ptr[ebp+ecx],ebx
134 OpBuffer[obp++]=(char)0x89;
135 OpBuffer[obp++]=(char)0x5C;
136 OpBuffer[obp++]=(char)0x0D;
137 OpBuffer[obp++]=(char)0x00;
138
139 //add ecx,sizeof(long)
140 OpBuffer[obp++]=(char)0x83;
141 OpBuffer[obp++]=(char)0xC1;
142 OpBuffer[obp++]=(char)0x04;
143
144 //mov dword ptr[ebp+ecx],eax
145 OpBuffer[obp++]=(char)0x89;
146 OpBuffer[obp++]=(char)0x44;
147 OpBuffer[obp++]=(char)0x0D;
148 OpBuffer[obp++]=(char)0x00;
149 }
150 else{
151 //mov dword ptr[ebp+offset],ebx
152 OpBuffer[obp++]=(char)0x89;
153 OpBuffer[obp++]=(char)0x9D;
154 *((long *)(OpBuffer+obp))=offset;
155 AddLocalVarAddrSchedule();
156 obp+=sizeof(long);
157
158 //mov dword ptr[ebp+offset+sizeof(long)],eax
159 OpBuffer[obp++]=(char)0x89;
160 OpBuffer[obp++]=(char)0x85;
161 *((long *)(OpBuffer+obp))=offset+sizeof(long);
162 AddLocalVarAddrSchedule();
163 obp+=sizeof(long);
164 }
165 }
166 else if(VarKind==VAR_REFLOCAL){
167 if(bOffsetOffset){
168 //add ecx,dword ptr[ebp+offset]
169 OpBuffer[obp++]=(char)0x03;
170 OpBuffer[obp++]=(char)0x8D;
171 *((long *)(OpBuffer+obp))=offset;
172 AddLocalVarAddrSchedule();
173 obp+=sizeof(long);
174 }
175 else{
176 //mov ecx,dword ptr[ebp+offset]
177 OpBuffer[obp++]=(char)0x8B;
178 OpBuffer[obp++]=(char)0x8D;
179 *((long *)(OpBuffer+obp))=offset;
180 AddLocalVarAddrSchedule();
181 obp+=sizeof(long);
182 }
183
184 //mov dword ptr[ecx],ebx
185 OpBuffer[obp++]=(char)0x89;
186 OpBuffer[obp++]=(char)0x19;
187
188 //mov dword ptr[ecx+sizeof(long)],eax
189 OpBuffer[obp++]=(char)0x89;
190 OpBuffer[obp++]=(char)0x41;
191 OpBuffer[obp++]=(char)0x04;
192 }
193 else if(VarKind==VAR_DIRECTMEM){
194 //mov dword ptr[ecx],ebx
195 OpBuffer[obp++]=(char)0x89;
196 OpBuffer[obp++]=(char)0x19;
197
198 //mov dword ptr[ecx+sizeof(long)],eax
199 OpBuffer[obp++]=(char)0x89;
200 OpBuffer[obp++]=(char)0x41;
201 OpBuffer[obp++]=(char)0x04;
202 }
203}
204void SetSingleVariable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset){
205 if(type==DEF_SINGLE){
206 //32ビット変数としてそのままコピーする
207 SetDWordVariable(DEF_DWORD,VarKind,offset,bOffsetOffset);
208 return;
209 }
210
211 if(type==DEF_DOUBLE){
212 //fld qword ptr[esp]
213 op_fld_ptr_esp(DEF_DOUBLE);
214
215 //add esp,8
216 op_add_esp(8);
217 }
218 else if(type==DEF_INT64||type==DEF_QWORD){
219 //64ビット整数
220
221 //fild qword ptr[esp]
222 op_fld_ptr_esp(DEF_INT64);
223
224 //add esp,8
225 op_add_esp(8);
226 }
227 else if(IsSignedType(type)){
228 //符号あり整数
229
230 //fild dword ptr[esp]
231 op_fld_ptr_esp(DEF_LONG);
232
233 //add esp,4
234 op_add_esp(4);
235 }
236 else{
237 if(!IsWholeNumberType(type)){
238 //不正な型の場合
239 SetError(9,NULL,cp);
240 return;
241 }
242
243 //符号なし整数
244
245 //pop eax
246 op_pop(REG_EAX);
247
248 //push 0
249 op_push_value(0);
250
251 //push eax
252 op_push(REG_EAX);
253
254 //fild qword ptr[esp]
255 OpBuffer[obp++]=(char)0xDF;
256 OpBuffer[obp++]=(char)0x2C;
257 OpBuffer[obp++]=(char)0x24;
258
259 //add esp,8
260 op_add_esp(8);
261 }
262
263 if(VarKind==VAR_GLOBAL){
264 if(bOffsetOffset){
265 //fstp dword ptr[ecx+offset]
266 OpBuffer[obp++]=(char)0xD9;
267 OpBuffer[obp++]=(char)0x99;
268 *((long *)(OpBuffer+obp))=offset;
269 pobj_GlobalVarSchedule->add();
270 obp+=sizeof(long);
271 }
272 else{
273 //fstp dword ptr[offset]
274 OpBuffer[obp++]=(char)0xD9;
275 OpBuffer[obp++]=(char)0x1D;
276 *((long *)(OpBuffer+obp))=offset;
277 pobj_GlobalVarSchedule->add();
278 obp+=sizeof(long);
279 }
280 }
281 else if(VarKind==VAR_LOCAL){
282 if(bOffsetOffset){
283 //add ecx,offset
284 OpBuffer[obp++]=(char)0x81;
285 OpBuffer[obp++]=(char)0xC1;
286 *((long *)(OpBuffer+obp))=offset;
287 AddLocalVarAddrSchedule();
288 obp+=sizeof(long);
289
290 //fstp dword ptr[ebp+ecx]
291 OpBuffer[obp++]=(char)0xD9;
292 OpBuffer[obp++]=(char)0x5C;
293 OpBuffer[obp++]=(char)0x0D;
294 OpBuffer[obp++]=(char)0x00;
295 }
296 else{
297 //fstp dword ptr[ebp+offset]
298 OpBuffer[obp++]=(char)0xD9;
299 OpBuffer[obp++]=(char)0x9D;
300 *((long *)(OpBuffer+obp))=offset;
301 AddLocalVarAddrSchedule();
302 obp+=sizeof(long);
303 }
304 }
305 else if(VarKind==VAR_REFLOCAL){
306 //mov eax,dword ptr[ebp+offset]
307 OpBuffer[obp++]=(char)0x8B;
308 OpBuffer[obp++]=(char)0x85;
309 *((long *)(OpBuffer+obp))=offset;
310 AddLocalVarAddrSchedule();
311 obp+=sizeof(long);
312
313 if(bOffsetOffset){
314 //add eax,ecx
315 OpBuffer[obp++]=(char)0x03;
316 OpBuffer[obp++]=(char)0xC1;
317 }
318
319 //fstp dword ptr[eax]
320 OpBuffer[obp++]=(char)0xD9;
321 OpBuffer[obp++]=(char)0x18;
322 }
323 else if(VarKind==VAR_DIRECTMEM){
324 //fstp dword ptr[ecx]
325 OpBuffer[obp++]=(char)0xD9;
326 OpBuffer[obp++]=(char)0x19;
327 }
328}
329void SetInt64Variable(int type,RELATIVE_VAR *pRelative){
330 if(type==DEF_DOUBLE){
331 //fld qword ptr[esp]
332 op_fld_ptr_esp(DEF_DOUBLE);
333
334 //fistp qword ptr[esp]
335 fpu_cast();
336 OpBuffer[obp++]=(char)0xDF;
337 OpBuffer[obp++]=(char)0x3C;
338 OpBuffer[obp++]=(char)0x24;
339 fpu_cast_end();
340
341 //pop eax
342 op_pop(REG_EAX);
343
344 //pop edx
345 op_pop(REG_EDX);
346 }
347 else if(type==DEF_SINGLE){
348 //fld dword ptr[esp]
349 op_fld_ptr_esp(DEF_SINGLE);
350
351 //sub esp,4
352 op_sub_esp(4);
353
354 //fistp qword ptr[esp]
355 fpu_cast();
356 OpBuffer[obp++]=(char)0xDF;
357 OpBuffer[obp++]=(char)0x3C;
358 OpBuffer[obp++]=(char)0x24;
359 fpu_cast_end();
360
361 //pop eax
362 op_pop(REG_EAX);
363
364 //pop edx
365 op_pop(REG_EDX);
366 }
367 else if(type==DEF_INT64||type==DEF_QWORD){
368 //pop eax
369 op_pop(REG_EAX);
370
371 //pop edx
372 op_pop(REG_EDX);
373 }
374 else if(IsSignedType(type)){
375 //符号拡張
376 //edx:eax ← eax
377
378 //pop eax
379 op_pop(REG_EAX);
380
381 //cdq
382 op_cdq();
383 }
384 else{
385 if(!IsWholeNumberType(type)){
386 //不正な型の場合
387 SetError(9,NULL,cp);
388 return;
389 }
390
391 //符号拡張
392 //edx=0:eax
393
394 //pop eax
395 op_pop(REG_EAX);
396
397 //xor edx,edx
398 op_zero_reg(REG_EDX);
399 }
400
401 if(pRelative->dwKind==VAR_GLOBAL){
402 if(pRelative->bOffsetOffset){
403 //mov dword ptr[ecx+offset],eax
404 OpBuffer[obp++]=(char)0x89;
405 OpBuffer[obp++]=(char)0x81;
406 *((long *)(OpBuffer+obp))=pRelative->offset;
407 pobj_GlobalVarSchedule->add();
408 obp+=sizeof(long);
409
410 //mov dword ptr[ecx+offset+sizeof(long)],edx
411 OpBuffer[obp++]=(char)0x89;
412 OpBuffer[obp++]=(char)0x91;
413 *((long *)(OpBuffer+obp))=pRelative->offset+sizeof(long);
414 pobj_GlobalVarSchedule->add();
415 obp+=sizeof(long);
416 }
417 else{
418 //mov dword ptr[offset],eax
419 OpBuffer[obp++]=(char)0xA3;
420 *((long *)(OpBuffer+obp))=pRelative->offset;
421 pobj_GlobalVarSchedule->add();
422 obp+=sizeof(long);
423
424 //mov dword ptr[offset+sizeof(long)],edx
425 OpBuffer[obp++]=(char)0x89;
426 OpBuffer[obp++]=(char)0x15;
427 *((long *)(OpBuffer+obp))=pRelative->offset+sizeof(DWORD);
428 pobj_GlobalVarSchedule->add();
429 obp+=sizeof(long);
430 }
431 }
432 else if(pRelative->dwKind==VAR_LOCAL){
433 if(pRelative->bOffsetOffset){
434 //add ecx,offset
435 OpBuffer[obp++]=(char)0x81;
436 OpBuffer[obp++]=(char)0xC1;
437 *((long *)(OpBuffer+obp))=pRelative->offset;
438 AddLocalVarAddrSchedule();
439 obp+=sizeof(long);
440
441 //mov dword ptr[ebp+ecx],eax
442 OpBuffer[obp++]=(char)0x89;
443 OpBuffer[obp++]=(char)0x44;
444 OpBuffer[obp++]=(char)0x0D;
445 OpBuffer[obp++]=(char)0x00;
446
447 //add ecx,sizeof(long)
448 OpBuffer[obp++]=(char)0x83;
449 OpBuffer[obp++]=(char)0xC1;
450 OpBuffer[obp++]=(char)0x04;
451
452 //mov dword ptr[ebp+ecx],edx
453 OpBuffer[obp++]=(char)0x89;
454 OpBuffer[obp++]=(char)0x54;
455 OpBuffer[obp++]=(char)0x0D;
456 OpBuffer[obp++]=(char)0x00;
457 }
458 else{
459 //mov dword ptr[ebp+offset],eax
460 OpBuffer[obp++]=(char)0x89;
461 OpBuffer[obp++]=(char)0x85;
462 *((long *)(OpBuffer+obp))=pRelative->offset;
463 AddLocalVarAddrSchedule();
464 obp+=sizeof(long);
465
466 //mov dword ptr[ebp+offset+sizeof(long)],edx
467 OpBuffer[obp++]=(char)0x89;
468 OpBuffer[obp++]=(char)0x95;
469 *((long *)(OpBuffer+obp))=pRelative->offset+sizeof(long);
470 AddLocalVarAddrSchedule();
471 obp+=sizeof(long);
472 }
473 }
474 else if(pRelative->dwKind==VAR_REFLOCAL){
475 if(pRelative->bOffsetOffset){
476 //add ecx,dword ptr[ebp+offset]
477 OpBuffer[obp++]=(char)0x03;
478 OpBuffer[obp++]=(char)0x8D;
479 *((long *)(OpBuffer+obp))=pRelative->offset;
480 AddLocalVarAddrSchedule();
481 obp+=sizeof(long);
482 }
483 else{
484 //mov ecx,dword ptr[ebp+offset]
485 OpBuffer[obp++]=(char)0x8B;
486 OpBuffer[obp++]=(char)0x8D;
487 *((long *)(OpBuffer+obp))=pRelative->offset;
488 AddLocalVarAddrSchedule();
489 obp+=sizeof(long);
490 }
491
492 //mov dword ptr[ecx],eax
493 OpBuffer[obp++]=(char)0x89;
494 OpBuffer[obp++]=(char)0x01;
495
496 //mov dword ptr[ecx+sizeof(long)],edx
497 OpBuffer[obp++]=(char)0x89;
498 OpBuffer[obp++]=(char)0x51;
499 OpBuffer[obp++]=(char)0x04;
500 }
501 else if(pRelative->dwKind==VAR_DIRECTMEM){
502 //mov dword ptr[ecx],eax
503 OpBuffer[obp++]=(char)0x89;
504 OpBuffer[obp++]=(char)0x01;
505
506 //mov dword ptr[ecx+sizeof(long)],edx
507 OpBuffer[obp++]=(char)0x89;
508 OpBuffer[obp++]=(char)0x51;
509 OpBuffer[obp++]=(char)0x04;
510 }
511}
512void SetDWordVariable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset){
513 if(type==DEF_DOUBLE||type==DEF_SINGLE){
514 if(type==DEF_DOUBLE){
515 //fld qword ptr[esp]
516 op_fld_ptr_esp(DEF_DOUBLE);
517 }
518 else if(type==DEF_SINGLE){
519 //fld dword ptr[esp]
520 op_fld_ptr_esp(DEF_SINGLE);
521
522 //sub esp,4
523 op_sub_esp(4);
524 }
525
526 //fistp qword ptr[esp]
527 fpu_cast();
528 OpBuffer[obp++]=(char)0xDF;
529 OpBuffer[obp++]=(char)0x3C;
530 OpBuffer[obp++]=(char)0x24;
531 fpu_cast_end();
532
533 //pop eax
534 op_pop(REG_EAX);
535
536 //add esp,4
537 op_add_esp(4);
538 }
539 else if(type==DEF_INT64||type==DEF_QWORD){
540 //pop eax
541 op_pop(REG_EAX);
542
543 //add esp,4
544 op_add_esp(4);
545 }
546 else{
547 if(!IsWholeNumberType(type)){
548 //不正な型の場合
549 SetError(9,NULL,cp);
550 return;
551 }
552
553 ChangeTypeToWhole(type,DEF_LONG);
554
555 //pop eax
556 op_pop(REG_EAX);
557 }
558
559 if(VarKind==VAR_GLOBAL){
560 if(bOffsetOffset){
561 //mov dword ptr[ecx+offset],eax
562 OpBuffer[obp++]=(char)0x89;
563 OpBuffer[obp++]=(char)0x81;
564 *((long *)(OpBuffer+obp))=offset;
565 pobj_GlobalVarSchedule->add();
566 obp+=sizeof(long);
567 }
568 else{
569 //mov dword ptr[offset],eax
570 OpBuffer[obp++]=(char)0xA3;
571 *((long *)(OpBuffer+obp))=offset;
572 pobj_GlobalVarSchedule->add();
573 obp+=sizeof(long);
574 }
575 }
576 else if(VarKind==VAR_LOCAL){
577 if(bOffsetOffset){
578 //add ecx,offset
579 OpBuffer[obp++]=(char)0x81;
580 OpBuffer[obp++]=(char)0xC1;
581 *((long *)(OpBuffer+obp))=offset;
582 AddLocalVarAddrSchedule();
583 obp+=sizeof(long);
584
585 //mov dword ptr[ebp+ecx],eax
586 OpBuffer[obp++]=(char)0x89;
587 OpBuffer[obp++]=(char)0x44;
588 OpBuffer[obp++]=(char)0x0D;
589 OpBuffer[obp++]=(char)0x00;
590 }
591 else{
592 //mov dword ptr[ebp+offset],eax
593 OpBuffer[obp++]=(char)0x89;
594 OpBuffer[obp++]=(char)0x85;
595 *((long *)(OpBuffer+obp))=offset;
596 AddLocalVarAddrSchedule();
597 obp+=sizeof(long);
598 }
599 }
600 else if(VarKind==VAR_REFLOCAL){
601 if(bOffsetOffset){
602 //add ecx,dword ptr[ebp+offset]
603 OpBuffer[obp++]=(char)0x03;
604 OpBuffer[obp++]=(char)0x8D;
605 *((long *)(OpBuffer+obp))=offset;
606 AddLocalVarAddrSchedule();
607 obp+=sizeof(long);
608 }
609 else{
610 //mov ecx,dword ptr[ebp+offset]
611 OpBuffer[obp++]=(char)0x8B;
612 OpBuffer[obp++]=(char)0x8D;
613 *((long *)(OpBuffer+obp))=offset;
614 AddLocalVarAddrSchedule();
615 obp+=sizeof(long);
616 }
617
618 //mov dword ptr[ecx],eax
619 OpBuffer[obp++]=(char)0x89;
620 OpBuffer[obp++]=(char)0x01;
621 }
622 else if(VarKind==VAR_DIRECTMEM){
623 //mov dword ptr[ecx],eax
624 OpBuffer[obp++]=(char)0x89;
625 OpBuffer[obp++]=(char)0x01;
626 }
627}
628void SetLongVariable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset){
629 if(type==DEF_DOUBLE||type==DEF_SINGLE){
630 if(type==DEF_DOUBLE){
631 //fld qword ptr[esp]
632 op_fld_ptr_esp(DEF_DOUBLE);
633
634 //add esp,8
635 op_add_esp(8);
636 }
637 else if(type==DEF_SINGLE){
638 //fld dword ptr[esp]
639 op_fld_ptr_esp(DEF_SINGLE);
640
641 //add esp,4
642 op_add_esp(4);
643 }
644
645 if(VarKind==VAR_GLOBAL){
646 if(bOffsetOffset){
647 //fistp dword ptr[ecx+offset]
648 fpu_cast();
649 OpBuffer[obp++]=(char)0xDB;
650 OpBuffer[obp++]=(char)0x99;
651 *((long *)(OpBuffer+obp))=offset;
652 pobj_GlobalVarSchedule->add();
653 obp+=sizeof(long);
654 fpu_cast_end();
655 }
656 else{
657 //fistp dword ptr[offset]
658 fpu_cast();
659 OpBuffer[obp++]=(char)0xDB;
660 OpBuffer[obp++]=(char)0x1D;
661 *((long *)(OpBuffer+obp))=offset;
662 pobj_GlobalVarSchedule->add();
663 obp+=sizeof(long);
664 fpu_cast_end();
665 }
666 }
667 else if(VarKind==VAR_LOCAL){
668 if(bOffsetOffset){
669 //add ecx,offset
670 OpBuffer[obp++]=(char)0x81;
671 OpBuffer[obp++]=(char)0xC1;
672 *((long *)(OpBuffer+obp))=offset;
673 AddLocalVarAddrSchedule();
674 obp+=sizeof(long);
675
676 //fistp dword ptr[ebp+ecx]
677 fpu_cast();
678 OpBuffer[obp++]=(char)0xDB;
679 OpBuffer[obp++]=(char)0x5C;
680 OpBuffer[obp++]=(char)0x0D;
681 OpBuffer[obp++]=(char)0x00;
682 fpu_cast_end();
683 }
684 else{
685 //fistp dword ptr[ebp+offset]
686 fpu_cast();
687 OpBuffer[obp++]=(char)0xDB;
688 OpBuffer[obp++]=(char)0x9D;
689 *((long *)(OpBuffer+obp))=offset;
690 AddLocalVarAddrSchedule();
691 obp+=sizeof(long);
692 fpu_cast_end();
693 }
694 }
695 else if(VarKind==VAR_REFLOCAL){
696 //mov eax,dword ptr[ebp+offset]
697 OpBuffer[obp++]=(char)0x8B;
698 OpBuffer[obp++]=(char)0x85;
699 *((long *)(OpBuffer+obp))=offset;
700 AddLocalVarAddrSchedule();
701 obp+=sizeof(long);
702
703 if(bOffsetOffset){
704 //add eax,ecx
705 OpBuffer[obp++]=(char)0x03;
706 OpBuffer[obp++]=(char)0xC1;
707 }
708
709 //fistp dword ptr[eax]
710 fpu_cast();
711 OpBuffer[obp++]=(char)0xDB;
712 OpBuffer[obp++]=(char)0x18;
713 fpu_cast_end();
714 }
715 else if(VarKind==VAR_DIRECTMEM){
716 //fistp dword ptr[ecx]
717 fpu_cast();
718 OpBuffer[obp++]=(char)0xDB;
719 OpBuffer[obp++]=(char)0x19;
720 fpu_cast_end();
721 }
722 }
723 else{
724 //実数以外の型からの代入処理はDWordのものと同様
725 SetDWordVariable(type,VarKind,offset,bOffsetOffset);
726 }
727}
728void Set16Variable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset){
729 ChangeTypeToWhole(type,DEF_INTEGER);
730
731 //pop eax
732 op_pop(REG_EAX);
733
734 if(VarKind==VAR_GLOBAL){
735 if(bOffsetOffset){
736 //mov word ptr[ecx+offset],ax
737 OpBuffer[obp++]=(char)0x66;
738 OpBuffer[obp++]=(char)0x89;
739 OpBuffer[obp++]=(char)0x81;
740 *((long *)(OpBuffer+obp))=offset;
741 pobj_GlobalVarSchedule->add();
742 obp+=sizeof(long);
743 }
744 else{
745 //mov word ptr[offset],ax
746 OpBuffer[obp++]=(char)0x66;
747 OpBuffer[obp++]=(char)0xA3;
748 *((long *)(OpBuffer+obp))=offset;
749 pobj_GlobalVarSchedule->add();
750 obp+=sizeof(long);
751 }
752 }
753 else if(VarKind==VAR_LOCAL){
754 if(bOffsetOffset){
755 //add ecx,offset
756 OpBuffer[obp++]=(char)0x81;
757 OpBuffer[obp++]=(char)0xC1;
758 *((long *)(OpBuffer+obp))=offset;
759 AddLocalVarAddrSchedule();
760 obp+=sizeof(long);
761
762 //mov word ptr[ebp+ecx],ax
763 OpBuffer[obp++]=(char)0x66;
764 OpBuffer[obp++]=(char)0x89;
765 OpBuffer[obp++]=(char)0x44;
766 OpBuffer[obp++]=(char)0x0D;
767 OpBuffer[obp++]=(char)0x00;
768 }
769 else{
770 //mov word ptr[ebp+offset],ax
771 OpBuffer[obp++]=(char)0x66;
772 OpBuffer[obp++]=(char)0x89;
773 OpBuffer[obp++]=(char)0x85;
774 *((long *)(OpBuffer+obp))=offset;
775 AddLocalVarAddrSchedule();
776 obp+=sizeof(long);
777 }
778 }
779 else if(VarKind==VAR_REFLOCAL){
780 //mov ebx,dword ptr[ebp+offset]
781 OpBuffer[obp++]=(char)0x8B;
782 OpBuffer[obp++]=(char)0x9D;
783 *((long *)(OpBuffer+obp))=offset;
784 AddLocalVarAddrSchedule();
785 obp+=sizeof(long);
786
787 if(bOffsetOffset){
788 //add ebx,ecx
789 OpBuffer[obp++]=(char)0x03;
790 OpBuffer[obp++]=(char)0xD9;
791 }
792
793 //mov word ptr[ebx],ax
794 OpBuffer[obp++]=(char)0x66;
795 OpBuffer[obp++]=(char)0x89;
796 OpBuffer[obp++]=(char)0x03;
797 }
798 else if(VarKind==VAR_DIRECTMEM){
799 //mov word ptr[ecx],ax
800 OpBuffer[obp++]=(char)0x66;
801 OpBuffer[obp++]=(char)0x89;
802 OpBuffer[obp++]=(char)0x01;
803 }
804}
805void Set8Variable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset){
806 ChangeTypeToWhole(type,DEF_SBYTE);
807
808 //pop eax
809 op_pop(REG_EAX);
810
811 if(VarKind==VAR_GLOBAL){
812 if(bOffsetOffset){
813 //mov byte ptr[ecx+offset],al
814 OpBuffer[obp++]=(char)0x88;
815 OpBuffer[obp++]=(char)0x81;
816 *((long *)(OpBuffer+obp))=offset;
817 pobj_GlobalVarSchedule->add();
818 obp+=sizeof(long);
819 }
820 else{
821 //mov byte ptr[offset],al
822 OpBuffer[obp++]=(char)0xA2;
823 *((long *)(OpBuffer+obp))=offset;
824 pobj_GlobalVarSchedule->add();
825 obp+=sizeof(long);
826 }
827 }
828 else if(VarKind==VAR_LOCAL){
829 if(bOffsetOffset){
830 //add ecx,offset
831 OpBuffer[obp++]=(char)0x81;
832 OpBuffer[obp++]=(char)0xC1;
833 *((long *)(OpBuffer+obp))=offset;
834 AddLocalVarAddrSchedule();
835 obp+=sizeof(long);
836
837 //mov byte ptr[ebp+ecx],al
838 OpBuffer[obp++]=(char)0x88;
839 OpBuffer[obp++]=(char)0x44;
840 OpBuffer[obp++]=(char)0x0D;
841 OpBuffer[obp++]=(char)0x00;
842 }
843 else{
844 //mov byte ptr[ebp+offset],al
845 OpBuffer[obp++]=(char)0x88;
846 OpBuffer[obp++]=(char)0x85;
847 *((long *)(OpBuffer+obp))=offset;
848 AddLocalVarAddrSchedule();
849 obp+=sizeof(long);
850 }
851 }
852 else if(VarKind==VAR_REFLOCAL){
853 //mov ebx,dword ptr[ebp+offset]
854 OpBuffer[obp++]=(char)0x8B;
855 OpBuffer[obp++]=(char)0x9D;
856 *((long *)(OpBuffer+obp))=offset;
857 AddLocalVarAddrSchedule();
858 obp+=sizeof(long);
859
860 if(bOffsetOffset){
861 //add ebx,ecx
862 OpBuffer[obp++]=(char)0x03;
863 OpBuffer[obp++]=(char)0xD9;
864 }
865
866 //mov byte ptr[ebx],al
867 OpBuffer[obp++]=(char)0x88;
868 OpBuffer[obp++]=(char)0x03;
869 }
870 else if(VarKind==VAR_DIRECTMEM){
871 //mov byte ptr[ecx],al
872 OpBuffer[obp++]=(char)0x88;
873 OpBuffer[obp++]=(char)0x01;
874 }
875}
876void SetBooleanVariable(int type,RELATIVE_VAR *pRelative){
877 if(type==DEF_DOUBLE){
878 // TODO: 実装
879 }
880 else if(type==DEF_SINGLE){
881 // TODO: 実装
882 }
883 else if(type==DEF_INT64||type==DEF_QWORD){
884 // TODO: 実装
885
886 //pop eax
887 op_pop(REG_EAX);
888
889 //cmp eax,0
890 op_cmp_value(GetTypeSize(type,-1),REG_EAX,0);
891
892 //setne al
893 op_setne( REG_EAX );
894
895 //pop ecx
896 op_pop(REG_ECX);
897
898 //cmp ecx,0
899 op_cmp_value(GetTypeSize(type,-1),REG_ECX,0);
900
901 //setne cl
902 op_setne( REG_ECX );
903
904 //or al,cl
905 op_or_RR( sizeof( _int8 ), REG_EAX, REG_ECX );
906 }
907 else{
908 if(!IsWholeNumberType(type)){
909 //不正な型の場合
910 SetError(9,NULL,cp);
911 return;
912 }
913
914 //pop eax
915 op_pop(REG_EAX);
916 }
917
918 //cmp eax,0
919 op_cmp_value(GetTypeSize(type,-1),REG_EAX,0);
920
921 //setne al
922 op_setne( REG_EAX );
923
924 //push eax
925 op_push(REG_EAX);
926
927 Set8Variable(DEF_BYTE,pRelative->dwKind,pRelative->offset,pRelative->bOffsetOffset);
928}
Note: See TracBrowser for help on using the repository browser.