source: dev/trunk/abdev/BasicCompiler32/NumOpe_Relation.cpp@ 209

Last change on this file since 209 was 206, checked in by dai_9181, 17 years ago

コード全体のリファクタリングを実施

File size: 27.4 KB
RevLine 
[206]1#include "stdafx.h"
2
[3]3#include "../BasicCompiler_Common/common.h"
4#include "Opcode.h"
5
[97]6void AutoExtendToBigType( int *type_stack,int sp, int reg1, int reg2 ){
7 /*
8 int bigSize = GetTypeSize( type_stack[sp-1], -1 );
9 if( bigSize != GetTypeSize( type_stack[sp-2], -1 ) ){
10 int extReg = reg2;
11 int oldType = type_stack[sp-2];
12 if( bigSize < GetTypeSize( type_stack[sp-2], -1 ) ){
13 bigSize = GetTypeSize( type_stack[sp-2], -1 );
14 extReg = reg1;
15 oldType = type_stack[sp-1];
16 }
17 if( bigSize == 2 ){
18 ExtendTypeTo16( oldType, extReg );
19 }
20 else if( bigSize == 4 ){
21 ExtendTypeTo32( oldType, extReg );
22 }
23 else{
24 SetError();
25 }
26 }*/
27}
28
29
[3]30BOOL Calc_Relation_PE(int *type_stack,LONG_PTR *index_stack,int *pStackPointer){
31 //value[sp-2]<=value[sp-1]
32
33 int sp;
34 sp=*pStackPointer;
35
36 int AnswerType;
37 AnswerType=NeutralizationType(type_stack[sp-2],index_stack[sp-2],type_stack[sp-1],index_stack[sp-1]);
38
39 if(IsRealNumberType(AnswerType)){
40 //////////////
41 // 実数演算
42 //////////////
43
44 if(type_stack[sp-1]==DEF_DOUBLE){
45 //fld qword ptr[esp]
46 op_fld_ptr_esp(DEF_DOUBLE);
47
48 //add esp,8
49 op_add_esp(8);
50 }
51 else if(type_stack[sp-1]==DEF_SINGLE){
52 //fld dword ptr[esp]
53 op_fld_ptr_esp(DEF_SINGLE);
54
55 //add esp,4
56 op_add_esp(4);
57 }
58 else if(type_stack[sp-1]==DEF_INT64||type_stack[sp-1]==DEF_QWORD){
59 //64ビット整数値
60
61 //fild qword ptr[esp]
62 op_fld_ptr_esp(DEF_INT64);
63
64 //add esp,8
65 op_add_esp(8);
66 }
67 else{
68 //その他整数型
69
70 //fild dword ptr[esp]
71 op_fld_ptr_esp(DEF_LONG);
72
73 //add esp,4
74 op_add_esp(4);
75 }
76
77 if(type_stack[sp-2]==DEF_DOUBLE){
78 //fld qword ptr[esp]
79 op_fld_ptr_esp(DEF_DOUBLE);
80
81 //add esp,4
82 op_add_esp(4);
83 }
84 else if(type_stack[sp-2]==DEF_SINGLE){
85 //fld dword ptr[esp]
86 op_fld_ptr_esp(DEF_SINGLE);
87 }
88 else if(type_stack[sp-2]==DEF_INT64||type_stack[sp-2]==DEF_QWORD){
89 //64ビット整数値
90
91 //fild qword ptr[esp]
92 op_fld_ptr_esp(DEF_INT64);
93
94 //add esp,4
95 op_add_esp(4);
96 }
97 else{
98 //その他整数型
99
100 //fild dword ptr[esp]
101 op_fld_ptr_esp(DEF_LONG);
102 }
103
104 //fcompp
105 OpBuffer[obp++]=(char)0xDE;
106 OpBuffer[obp++]=(char)0xD9;
107
108 //fnstsw ax
109 OpBuffer[obp++]=(char)0xDF;
110 OpBuffer[obp++]=(char)0xE0;
111
[36]112 //mov ecx,1
[3]113 OpBuffer[obp++]=(char)0xB9;
[36]114 *((long *)(OpBuffer+obp))=1;
[3]115 obp+=sizeof(long);
116
117 //test ah,41h
118 OpBuffer[obp++]=(char)0xF6;
119 OpBuffer[obp++]=(char)0xC4;
120 OpBuffer[obp++]=(char)0x41;
121
122 //jne 5
123 OpBuffer[obp++]=(char)0x75;
124 OpBuffer[obp++]=(char)0x02;
125
126 //xor ecx,ecx(ecxを0にする)
127 op_zero_reg(REG_ECX);
128
129 //mov dword ptr[esp],ecx
130 OpBuffer[obp++]=(char)0x89;
131 OpBuffer[obp++]=(char)0x0C;
132 OpBuffer[obp++]=(char)0x24;
133 }
134 else if(Is64Type(AnswerType)){
135 ////////////////////
136 // 64ビット整数演算
137 ////////////////////
138 int TrueSchedule,
139 FalseSchedule1,
140 FalseSchedule2;
141
142 // 第1項 <= 第2項
143
144 //第1項 edx:eax
145 //第2項 ecx:ebx
146 GetStackData_ToRegister(type_stack,sp);
147
148 //cmp edx,ecx
149 OpBuffer[obp++]=(char)0x3B;
150 OpBuffer[obp++]=(char)0xD1;
151
152 if(IsSignedType(type_stack[sp-2])==0&&IsSignedType(type_stack[sp-1])==0){
153 //符号なし演算
154
155 //ja FalseSchedule1(偽へジャンプ)
156 OpBuffer[obp++]=(char)0x77;
157 }
158 else{
159 //符号あり演算
160
161 //jg FalseSchedule1(偽へジャンプ)
162 OpBuffer[obp++]=(char)0x7F;
163 }
164 FalseSchedule1=obp;
165 obp++;
166
167 if(IsSignedType(type_stack[sp-2])==0&&IsSignedType(type_stack[sp-1])==0){
168 //符号なし演算
169
170 //jb TrueSchedule(真へジャンプ)
171 OpBuffer[obp++]=(char)0x72;
172 }
173 else{
174 //符号あり演算
175
176 //jl TrueSchedule(真へジャンプ)
177 OpBuffer[obp++]=(char)0x7C;
178 }
179 TrueSchedule=obp;
180 obp++;
181
182 //cmp eax,ebx
183 OpBuffer[obp++]=(char)0x3B;
184 OpBuffer[obp++]=(char)0xC3;
185
186 //ja FalseSchedule2(偽へジャンプ)
187 OpBuffer[obp++]=(char)0x77;
188 FalseSchedule2=obp;
189 obp++;
190
191 //TrueScheduleのジャンプ先の設定
192 OpBuffer[TrueSchedule]=obp-(TrueSchedule+1);
193
[36]194 //mov eax,1
[3]195 OpBuffer[obp++]=(char)0xB8;
[36]196 *((long *)(OpBuffer+obp))=1;
[3]197 obp+=sizeof(long);
198
199 //jmp 2(演算終了位置へジャンプ)
200 OpBuffer[obp++]=(char)0xEB;
201 OpBuffer[obp++]=(char)0x02;
202
203 //FalseScheduleのジャンプ先の設定
204 OpBuffer[FalseSchedule1]=obp-(FalseSchedule1+1);
205 OpBuffer[FalseSchedule2]=obp-(FalseSchedule2+1);
206
207 //xor eax,eax(eaxを0にする)
208 op_zero_reg(REG_EAX);
209
210 //push eax
211 op_push(REG_EAX);
212 }
213 else{
214 ////////////////////
215 // 32ビット整数演算
216 ////////////////////
217
218 //pop ebx
219 op_pop(REG_EBX);
220
221 //pop eax
222 op_pop(REG_EAX);
223
[97]224 // どちらかのサイズが足りない場合は自動拡張する
225 AutoExtendToBigType( type_stack, sp, REG_EAX, REG_EBX );
226
[3]227 //sub esp,4
228 op_sub_esp(4);
229
[36]230 //mov ecx,1
[3]231 OpBuffer[obp++]=(char)0xB9;
[36]232 *((long *)(OpBuffer+obp))=1;
[3]233 obp+=sizeof(long);
234
235 //cmp eax,ebx
236 OpBuffer[obp++]=(char)0x3B;
237 OpBuffer[obp++]=(char)0xC3;
238
239 if(IsSignedType(type_stack[sp-2])==0&&IsSignedType(type_stack[sp-1])==0){
240 //符号なし演算
241
242 //jbe 5(次のmovを飛び越す)
243 OpBuffer[obp++]=(char)0x76;
244 OpBuffer[obp++]=(char)0x05;
245 }
246 else{
247 //符号あり演算
248
249 //jle 5(次のmovを飛び越す)
250 OpBuffer[obp++]=(char)0x7E;
251 OpBuffer[obp++]=(char)0x05;
252 }
253
254 //mov ecx,0
255 OpBuffer[obp++]=(char)0xB9;
256 *((long *)(OpBuffer+obp))=0;
257 obp+=sizeof(long);
258
259 //mov dword ptr[esp],ecx
260 OpBuffer[obp++]=(char)0x89;
261 OpBuffer[obp++]=(char)0x0C;
262 OpBuffer[obp++]=(char)0x24;
263 }
264
265 sp--;
[36]266 type_stack[sp-1]=DEF_BOOLEAN;
[3]267
268 *pStackPointer=sp;
269 return 1;
270}
271
272BOOL Calc_Relation_QE(int *type_stack,LONG_PTR *index_stack,int *pStackPointer){
273 //value[sp-2]>=value[sp-1]
274
275 int sp;
276 sp=*pStackPointer;
277
278 int AnswerType;
279 AnswerType=NeutralizationType(type_stack[sp-2],index_stack[sp-2],type_stack[sp-1],index_stack[sp-1]);
280
281 if(IsRealNumberType(AnswerType)){
282 //浮動小数点演算
283 if(type_stack[sp-1]==DEF_DOUBLE){
284 //fld qword ptr[esp]
285 op_fld_ptr_esp(DEF_DOUBLE);
286
287 //add esp,8
288 op_add_esp(8);
289 }
290 else if(type_stack[sp-1]==DEF_SINGLE){
291 //fld dword ptr[esp]
292 op_fld_ptr_esp(DEF_SINGLE);
293
294 //add esp,4
295 op_add_esp(4);
296 }
297 else if(type_stack[sp-1]==DEF_INT64||type_stack[sp-1]==DEF_QWORD){
298 //64ビット整数値
299
300 //fild qword ptr[esp]
301 op_fld_ptr_esp(DEF_INT64);
302
303 //add esp,8
304 op_add_esp(8);
305 }
306 else{
307 //その他整数型
308
309 //fild dword ptr[esp]
310 op_fld_ptr_esp(DEF_LONG);
311
312 //add esp,4
313 op_add_esp(4);
314 }
315
316 if(type_stack[sp-2]==DEF_DOUBLE){
317 //fld qword ptr[esp]
318 op_fld_ptr_esp(DEF_DOUBLE);
319
320 //add esp,4
321 op_add_esp(4);
322 }
323 else if(type_stack[sp-2]==DEF_SINGLE){
324 //fld dword ptr[esp]
325 op_fld_ptr_esp(DEF_SINGLE);
326 }
327 else if(type_stack[sp-2]==DEF_INT64||type_stack[sp-2]==DEF_QWORD){
328 //64ビット整数値
329
330 //fild qword ptr[esp]
331 op_fld_ptr_esp(DEF_INT64);
332
333 //add esp,4
334 op_add_esp(4);
335 }
336 else{
337 //その他整数型
338
339 //fild dword ptr[esp]
340 op_fld_ptr_esp(DEF_LONG);
341 }
342
343 //fcompp
344 OpBuffer[obp++]=(char)0xDE;
345 OpBuffer[obp++]=(char)0xD9;
346
347 //fnstsw ax
348 OpBuffer[obp++]=(char)0xDF;
349 OpBuffer[obp++]=(char)0xE0;
350
[36]351 //mov ecx,1
[3]352 OpBuffer[obp++]=(char)0xB9;
[36]353 *((long *)(OpBuffer+obp))=1;
[3]354 obp+=sizeof(long);
355
356 //test ah,1
357 OpBuffer[obp++]=(char)0xF6;
358 OpBuffer[obp++]=(char)0xC4;
359 OpBuffer[obp++]=(char)0x01;
360
361 //je 5
362 OpBuffer[obp++]=(char)0x74;
363 OpBuffer[obp++]=(char)0x05;
364
365 //mov ecx,0
366 OpBuffer[obp++]=(char)0xB9;
367 *((long *)(OpBuffer+obp))=0;
368 obp+=sizeof(long);
369
370 //mov dword ptr[esp],ecx
371 OpBuffer[obp++]=(char)0x89;
372 OpBuffer[obp++]=(char)0x0C;
373 OpBuffer[obp++]=(char)0x24;
374 }
375 else if(Is64Type(AnswerType)){
376 ////////////////////
377 // 64ビット整数演算
378 ////////////////////
379 int TrueSchedule,
380 FalseSchedule1,
381 FalseSchedule2;
382
383 // 第1項 >= 第2項
384
385 //第1項 edx:eax
386 //第2項 ecx:ebx
387 GetStackData_ToRegister(type_stack,sp);
388
389 //cmp edx,ecx
390 OpBuffer[obp++]=(char)0x3B;
391 OpBuffer[obp++]=(char)0xD1;
392
393 if(IsSignedType(AnswerType)){
394 //符号あり演算
395
396 //jl FalseSchedule1(偽へジャンプ)
397 OpBuffer[obp++]=(char)0x7C;
398 }
399 else{
400 //符号なし演算
401
402 //jb FalseSchedule1(偽へジャンプ)
403 OpBuffer[obp++]=(char)0x72;
404 }
405 FalseSchedule1=obp;
406 obp++;
407
408 if(IsSignedType(AnswerType)){
409 //符号あり演算
410
411 //jg TrueSchedule(真へジャンプ)
412 OpBuffer[obp++]=(char)0x7F;
413 }
414 else{
415 //符号なし演算
416
417 //ja TrueSchedule(真へジャンプ)
418 OpBuffer[obp++]=(char)0x77;
419 }
420 TrueSchedule=obp;
421 obp++;
422
423 //cmp eax,ebx
424 OpBuffer[obp++]=(char)0x3B;
425 OpBuffer[obp++]=(char)0xC3;
426
427 //jb FalseSchedule2(偽へジャンプ)
428 OpBuffer[obp++]=(char)0x72;
429 FalseSchedule2=obp;
430 obp++;
431
432 //TrueScheduleのジャンプ先の設定
433 OpBuffer[TrueSchedule]=obp-(TrueSchedule+1);
434
[36]435 //mov eax,1
[3]436 OpBuffer[obp++]=(char)0xB8;
[36]437 *((long *)(OpBuffer+obp))=1;
[3]438 obp+=sizeof(long);
439
440 //jmp 2(演算終了位置へジャンプ)
441 OpBuffer[obp++]=(char)0xEB;
442 OpBuffer[obp++]=(char)0x02;
443
444 //FalseScheduleのジャンプ先の設定
445 OpBuffer[FalseSchedule1]=obp-(FalseSchedule1+1);
446 OpBuffer[FalseSchedule2]=obp-(FalseSchedule2+1);
447
448 //xor eax,eax(eaxを0にする)
449 op_zero_reg(REG_EAX);
450
451 //push eax
452 op_push(REG_EAX);
453 }
454 else{
455 ////////////////////
456 // 32ビット整数演算
457 ////////////////////
458
459 //pop ebx
460 op_pop(REG_EBX);
461
462 //pop eax
463 op_pop(REG_EAX);
464
[97]465 // どちらかのサイズが足りない場合は自動拡張する
466 AutoExtendToBigType( type_stack, sp, REG_EAX, REG_EBX );
467
[3]468 //sub esp,4
469 op_sub_esp(4);
470
[36]471 //mov ecx,1
[3]472 OpBuffer[obp++]=(char)0xB9;
[36]473 *((long *)(OpBuffer+obp))=1;
[3]474 obp+=sizeof(long);
475
476 //cmp eax,ebx
477 OpBuffer[obp++]=(char)0x3B;
478 OpBuffer[obp++]=(char)0xC3;
479
480 if(IsSignedType(AnswerType)){
481 //符号あり演算
482
483 //jge 5(次のmovを飛び越す)符号有り
484 OpBuffer[obp++]=(char)0x7D;
485 OpBuffer[obp++]=(char)0x05;
486 }
487 else{
488 //符号なし演算
489
490 //jae 5(次のmovを飛び越す)
491 OpBuffer[obp++]=(char)0x73;
492 OpBuffer[obp++]=(char)0x05;
493 }
494
495 //mov ecx,0
496 OpBuffer[obp++]=(char)0xB9;
497 *((long *)(OpBuffer+obp))=0;
498 obp+=sizeof(long);
499
500 //mov dword ptr[esp],ecx
501 OpBuffer[obp++]=(char)0x89;
502 OpBuffer[obp++]=(char)0x0C;
503 OpBuffer[obp++]=(char)0x24;
504 }
505
506 sp--;
[36]507 type_stack[sp-1]=DEF_BOOLEAN;
[3]508
509 *pStackPointer=sp;
510 return 1;
511}
512
513BOOL Calc_Relation_P(int *type_stack,LONG_PTR *index_stack,int *pStackPointer){
514 //value[sp-2]<value[sp-1]
515
516 int sp;
517 sp=*pStackPointer;
518
519 int AnswerType;
520 AnswerType=NeutralizationType(type_stack[sp-2],index_stack[sp-2],type_stack[sp-1],index_stack[sp-1]);
521
522 if(IsRealNumberType(AnswerType)){
523 //////////////
524 // 実数演算
525 //////////////
526
527 if(type_stack[sp-1]==DEF_DOUBLE){
528 //fld qword ptr[esp]
529 op_fld_ptr_esp(DEF_DOUBLE);
530
531 //add esp,8
532 op_add_esp(8);
533 }
534 else if(type_stack[sp-1]==DEF_SINGLE){
535 //fld dword ptr[esp]
536 op_fld_ptr_esp(DEF_SINGLE);
537
538 //add esp,4
539 op_add_esp(4);
540 }
541 else if(type_stack[sp-1]==DEF_INT64||type_stack[sp-1]==DEF_QWORD){
542 //64ビット整数値
543
544 //fild qword ptr[esp]
545 op_fld_ptr_esp(DEF_INT64);
546
547 //add esp,8
548 op_add_esp(8);
549 }
550 else{
551 //その他整数型
552
553 //fild dword ptr[esp]
554 op_fld_ptr_esp(DEF_LONG);
555
556 //add esp,4
557 op_add_esp(4);
558 }
559
560 if(type_stack[sp-2]==DEF_DOUBLE){
561 //fld qword ptr[esp]
562 op_fld_ptr_esp(DEF_DOUBLE);
563
564 //add esp,4
565 op_add_esp(4);
566 }
567 else if(type_stack[sp-2]==DEF_SINGLE){
568 //fld dword ptr[esp]
569 op_fld_ptr_esp(DEF_SINGLE);
570 }
571 else if(type_stack[sp-2]==DEF_INT64||type_stack[sp-2]==DEF_QWORD){
572 //64ビット整数値
573
574 //fild qword ptr[esp]
575 op_fld_ptr_esp(DEF_INT64);
576
577 //add esp,4
578 op_add_esp(4);
579 }
580 else{
581 //その他整数型
582
583 //fild dword ptr[esp]
584 op_fld_ptr_esp(DEF_LONG);
585 }
586
587 //fcompp
588 OpBuffer[obp++]=(char)0xDE;
589 OpBuffer[obp++]=(char)0xD9;
590
591 //fnstsw ax
592 OpBuffer[obp++]=(char)0xDF;
593 OpBuffer[obp++]=(char)0xE0;
594
[36]595 //mov ecx,1
[3]596 OpBuffer[obp++]=(char)0xB9;
[36]597 *((long *)(OpBuffer+obp))=1;
[3]598 obp+=sizeof(long);
599
600 //test ah,01h
601 OpBuffer[obp++]=(char)0xF6;
602 OpBuffer[obp++]=(char)0xC4;
603 OpBuffer[obp++]=(char)0x01;
604
605 //jne 5
606 OpBuffer[obp++]=(char)0x75;
607 OpBuffer[obp++]=(char)0x05;
608
609 //mov ecx,0
610 OpBuffer[obp++]=(char)0xB9;
611 *((long *)(OpBuffer+obp))=0;
612 obp+=sizeof(long);
613
614 //mov dword ptr[esp],ecx
615 OpBuffer[obp++]=(char)0x89;
616 OpBuffer[obp++]=(char)0x0C;
617 OpBuffer[obp++]=(char)0x24;
618 }
619 else if(Is64Type(AnswerType)){
620 ////////////////////
621 // 64ビット整数演算
622 ////////////////////
623 int TrueSchedule1,
624 TrueSchedule2,
625 FalseSchedule;
626
627 // 第1項 < 第2項
628
629 //第1項 edx:eax
630 //第2項 ecx:ebx
631 GetStackData_ToRegister(type_stack,sp);
632
633 //cmp edx,ecx
634 OpBuffer[obp++]=(char)0x3B;
635 OpBuffer[obp++]=(char)0xD1;
636
637 if(IsSignedType(AnswerType)){
638 //符号あり演算
639
640 //jl TrueSchedule1(真へジャンプ)
641 OpBuffer[obp++]=(char)0x7C;
642 }
643 else{
644 //符号なし演算
645
646 //jb TrueSchedule1(真へジャンプ)
647 OpBuffer[obp++]=(char)0x72;
648 }
649 TrueSchedule1=obp;
650 obp++;
651
652 if(IsSignedType(AnswerType)){
653 //符号あり演算
654
655 //jg FalseSchedule(偽へジャンプ)
656 OpBuffer[obp++]=(char)0x7F;
657 }
658 else{
659 //符号なし演算
660
661 //ja FalseSchedule(偽へジャンプ)
662 OpBuffer[obp++]=(char)0x77;
663 }
664 FalseSchedule=obp;
665 obp++;
666
667 //cmp eax,ebx
668 OpBuffer[obp++]=(char)0x3B;
669 OpBuffer[obp++]=(char)0xC3;
670
671 //jb TrueSchedule2(真へジャンプ)
672 OpBuffer[obp++]=(char)0x72;
673 TrueSchedule2=obp;
674 obp++;
675
676 //FalseScheduleのジャンプ先の設定
677 OpBuffer[FalseSchedule]=obp-(FalseSchedule+1);
678
679 //xor eax,eax(eaxを0にする)
680 op_zero_reg(REG_EAX);
681
682 //jmp 5(演算終了位置へジャンプ)
683 OpBuffer[obp++]=(char)0xEB;
684 OpBuffer[obp++]=(char)0x05;
685
686 //TrueScheduleのジャンプ先の設定
687 OpBuffer[TrueSchedule1]=obp-(TrueSchedule1+1);
688 OpBuffer[TrueSchedule2]=obp-(TrueSchedule2+1);
689
[36]690 //mov eax,1
[3]691 OpBuffer[obp++]=(char)0xB8;
[36]692 *((long *)(OpBuffer+obp))=1;
[3]693 obp+=sizeof(long);
694
695 //push eax
696 op_push(REG_EAX);
697 }
698 else{
699 ///////////////////
700 //32ビット整数演算
701 ///////////////////
702
703 //pop ebx
704 op_pop(REG_EBX);
705
706 //pop eax
707 op_pop(REG_EAX);
708
[97]709 // どちらかのサイズが足りない場合は自動拡張する
710 AutoExtendToBigType( type_stack, sp, REG_EAX, REG_EBX );
711
[3]712 //sub esp,4
713 op_sub_esp(4);
714
[36]715 //mov ecx,1
[3]716 OpBuffer[obp++]=(char)0xB9;
[36]717 *((long *)(OpBuffer+obp))=1;
[3]718 obp+=sizeof(long);
719
720 //cmp eax,ebx
721 OpBuffer[obp++]=(char)0x3B;
722 OpBuffer[obp++]=(char)0xC3;
723
724 if(IsSignedType(AnswerType)){
725 //符号あり演算
726
727 //jl 5(次のmovを飛び越す)
728 OpBuffer[obp++]=(char)0x7C;
729 OpBuffer[obp++]=(char)0x05;
730 }
731 else{
732 //符号なし演算
733
734 //jb 5(次のmovを飛び越す)
735 OpBuffer[obp++]=(char)0x72;
736 OpBuffer[obp++]=(char)0x05;
737 }
738
739 //mov ecx,0
740 OpBuffer[obp++]=(char)0xB9;
741 *((long *)(OpBuffer+obp))=0;
742 obp+=sizeof(long);
743
744 //mov dword ptr[esp],ecx
745 OpBuffer[obp++]=(char)0x89;
746 OpBuffer[obp++]=(char)0x0C;
747 OpBuffer[obp++]=(char)0x24;
748 }
749
750 sp--;
[36]751 type_stack[sp-1]=DEF_BOOLEAN;
[3]752
753 *pStackPointer=sp;
754 return 1;
755}
756
757BOOL Calc_Relation_Q(int *type_stack,LONG_PTR *index_stack,int *pStackPointer){
758 //value[sp-2]>value[sp-1]
759
760 int sp;
761 sp=*pStackPointer;
762
763 int AnswerType;
764 AnswerType=NeutralizationType(type_stack[sp-2],index_stack[sp-2],type_stack[sp-1],index_stack[sp-1]);
765
766 if(IsRealNumberType(AnswerType)){
767 //////////////
768 // 実数演算
769 //////////////
770
771 if(type_stack[sp-1]==DEF_DOUBLE){
772 //fld qword ptr[esp]
773 op_fld_ptr_esp(DEF_DOUBLE);
774
775 //add esp,8
776 op_add_esp(8);
777 }
778 else if(type_stack[sp-1]==DEF_SINGLE){
779 //fld dword ptr[esp]
780 op_fld_ptr_esp(DEF_SINGLE);
781
782 //add esp,4
783 op_add_esp(4);
784 }
785 else if(type_stack[sp-1]==DEF_INT64||type_stack[sp-1]==DEF_QWORD){
786 //64ビット整数値
787
788 //fild qword ptr[esp]
789 op_fld_ptr_esp(DEF_INT64);
790
791 //add esp,8
792 op_add_esp(8);
793 }
794 else{ //Long、DWord
795 //fild dword ptr[esp]
796 op_fld_ptr_esp(DEF_LONG);
797
798 //add esp,4
799 op_add_esp(4);
800 }
801
802 if(type_stack[sp-2]==DEF_DOUBLE){
803 //fld qword ptr[esp]
804 op_fld_ptr_esp(DEF_DOUBLE);
805
806 //add esp,4
807 op_add_esp(4);
808 }
809 else if(type_stack[sp-2]==DEF_SINGLE){
810 //fld dword ptr[esp]
811 op_fld_ptr_esp(DEF_SINGLE);
812 }
813 else if(type_stack[sp-2]==DEF_INT64||type_stack[sp-2]==DEF_QWORD){
814 //64ビット整数値
815
816 //fild qword ptr[esp]
817 op_fld_ptr_esp(DEF_INT64);
818
819 //add esp,4
820 op_add_esp(4);
821 }
822 else{ //Long、DWord
823 //fild dword ptr[esp]
824 op_fld_ptr_esp(DEF_LONG);
825 }
826
827 //fcompp
828 OpBuffer[obp++]=(char)0xDE;
829 OpBuffer[obp++]=(char)0xD9;
830
831 //fnstsw ax
832 OpBuffer[obp++]=(char)0xDF;
833 OpBuffer[obp++]=(char)0xE0;
834
[36]835 //mov ecx,1
[3]836 OpBuffer[obp++]=(char)0xB9;
[36]837 *((long *)(OpBuffer+obp))=1;
[3]838 obp+=sizeof(long);
839
840 //test ah,41
841 OpBuffer[obp++]=(char)0xF6;
842 OpBuffer[obp++]=(char)0xC4;
843 OpBuffer[obp++]=(char)0x41;
844
845 //je 5
846 OpBuffer[obp++]=(char)0x74;
847 OpBuffer[obp++]=(char)0x05;
848
849 //mov ecx,0
850 OpBuffer[obp++]=(char)0xB9;
851 *((long *)(OpBuffer+obp))=0;
852 obp+=sizeof(long);
853
854 //mov dword ptr[esp],ecx
855 OpBuffer[obp++]=(char)0x89;
856 OpBuffer[obp++]=(char)0x0C;
857 OpBuffer[obp++]=(char)0x24;
858 }
859 else if(Is64Type(AnswerType)){
860 ////////////////////
861 // 64ビット整数演算
862 ////////////////////
863 int FalseSchedule,
864 TrueSchedule1,
865 TrueSchedule2;
866
867 // 第1項 > 第2項
868
869 //第1項 edx:eax
870 //第2項 ecx:ebx
871 GetStackData_ToRegister(type_stack,sp);
872
873 //cmp edx,ecx
874 OpBuffer[obp++]=(char)0x3B;
875 OpBuffer[obp++]=(char)0xD1;
876
877 if(IsSignedType(AnswerType)){
878 //符号有り
879
880 //jg TrueSchedule1(真へジャンプ)
881 OpBuffer[obp++]=(char)0x7F;
882 }
883 else{
884 //符号無し
885
886 //ja TrueSchedule1(真へジャンプ)
887 OpBuffer[obp++]=(char)0x77;
888 }
889 TrueSchedule1=obp;
890 obp++;
891
892 if(IsSignedType(AnswerType)){
893 //符号有り
894
895 //jl FalseSchedule(偽へジャンプ)
896 OpBuffer[obp++]=(char)0x7C;
897 }
898 else{
899 //符号無し
900
901 //jb FalseSchedule(偽へジャンプ)
902 OpBuffer[obp++]=(char)0x72;
903 }
904 FalseSchedule=obp;
905 obp++;
906
907 //cmp eax,ebx
908 OpBuffer[obp++]=(char)0x3B;
909 OpBuffer[obp++]=(char)0xC3;
910
911 //ja TrueSchedule2(真へジャンプ)
912 OpBuffer[obp++]=(char)0x77;
913 TrueSchedule2=obp;
914 obp++;
915
916 //FalseScheduleのジャンプ先の設定
917 OpBuffer[FalseSchedule]=obp-(FalseSchedule+1);
918
919 //xor eax,eax(eaxを0にする)
920 op_zero_reg(REG_EAX);
921
922 //jmp 5(演算終了位置へジャンプ)
923 OpBuffer[obp++]=(char)0xEB;
924 OpBuffer[obp++]=(char)0x05;
925
926 //TrueScheduleのジャンプ先の設定
927 OpBuffer[TrueSchedule1]=obp-(TrueSchedule1+1);
928 OpBuffer[TrueSchedule2]=obp-(TrueSchedule2+1);
929
[36]930 //mov eax,1
[3]931 OpBuffer[obp++]=(char)0xB8;
[36]932 *((long *)(OpBuffer+obp))=1;
[3]933 obp+=sizeof(long);
934
935 //push eax
936 op_push(REG_EAX);
937 }
938 else{
939 ////////////////////
940 // 32ビット整数演算
941 ////////////////////
942
943 //pop ebx
944 op_pop(REG_EBX);
945
946 //pop eax
947 op_pop(REG_EAX);
948
[97]949 // どちらかのサイズが足りない場合は自動拡張する
950 AutoExtendToBigType( type_stack, sp, REG_EAX, REG_EBX );
951
[3]952 //sub esp,4
953 op_sub_esp(4);
954
[36]955 //mov ecx,1
[3]956 OpBuffer[obp++]=(char)0xB9;
[36]957 *((long *)(OpBuffer+obp))=1;
[3]958 obp+=sizeof(long);
959
960 //cmp eax,ebx
961 OpBuffer[obp++]=(char)0x3B;
962 OpBuffer[obp++]=(char)0xC3;
963
964 if(IsSignedType(AnswerType)){
965 //jg 5(次のmovを飛び越す)
966 OpBuffer[obp++]=(char)0x7F;
967 OpBuffer[obp++]=(char)0x05;
968 }
969 else{
970 //ja 5(次のmovを飛び越す)
971 OpBuffer[obp++]=(char)0x77;
972 OpBuffer[obp++]=(char)0x05;
973 }
974
975 //mov ecx,0
976 OpBuffer[obp++]=(char)0xB9;
977 *((long *)(OpBuffer+obp))=0;
978 obp+=sizeof(long);
979
980 //mov dword ptr[esp],ecx
981 OpBuffer[obp++]=(char)0x89;
982 OpBuffer[obp++]=(char)0x0C;
983 OpBuffer[obp++]=(char)0x24;
984 }
985
986 sp--;
[36]987 type_stack[sp-1]=DEF_BOOLEAN;
[3]988
989 *pStackPointer=sp;
990 return 1;
991}
992
993BOOL Calc_Relation_NotEqual(int *type,int *pStackPointer){
994 //value[sp-2]<>value[sp-1]
995
996 int sp;
997 sp=*pStackPointer;
998
999 if(type[sp-2]==DEF_DOUBLE||type[sp-2]==DEF_SINGLE||
1000 type[sp-1]==DEF_DOUBLE||type[sp-1]==DEF_SINGLE){
1001 //////////////
1002 // 実数演算
1003 //////////////
1004
1005 if(type[sp-1]==DEF_DOUBLE){
1006 //fld qword ptr[esp]
1007 op_fld_ptr_esp(DEF_DOUBLE);
1008
1009 //add esp,8
1010 op_add_esp(8);
1011 }
1012 else if(type[sp-1]==DEF_SINGLE){
1013 //fld dword ptr[esp]
1014 op_fld_ptr_esp(DEF_SINGLE);
1015
1016 //add esp,4
1017 op_add_esp(4);
1018 }
1019 else if(type[sp-1]==DEF_INT64||type[sp-1]==DEF_QWORD){
1020 //64ビット整数値
1021
1022 //fild qword ptr[esp]
1023 op_fld_ptr_esp(DEF_INT64);
1024
1025 //add esp,8
1026 op_add_esp(8);
1027 }
1028 else{ //Long、DWord
1029 //fild dword ptr[esp]
1030 op_fld_ptr_esp(DEF_LONG);
1031
1032 //add esp,4
1033 op_add_esp(4);
1034 }
1035
1036 if(type[sp-2]==DEF_DOUBLE){
1037 //fld qword ptr[esp]
1038 op_fld_ptr_esp(DEF_DOUBLE);
1039
1040 //add esp,4
1041 op_add_esp(4);
1042 }
1043 else if(type[sp-2]==DEF_SINGLE){
1044 //fld dword ptr[esp]
1045 op_fld_ptr_esp(DEF_SINGLE);
1046 }
1047 else if(type[sp-2]==DEF_INT64||type[sp-2]==DEF_QWORD){
1048 //64ビット整数値
1049
1050 //fild qword ptr[esp]
1051 op_fld_ptr_esp(DEF_INT64);
1052
1053 //add esp,4
1054 op_add_esp(4);
1055 }
1056 else{ //Long、DWord
1057 //fild dword ptr[esp]
1058 op_fld_ptr_esp(DEF_LONG);
1059 }
1060
1061 //fcompp
1062 OpBuffer[obp++]=(char)0xDE;
1063 OpBuffer[obp++]=(char)0xD9;
1064
1065 //fnstsw ax
1066 OpBuffer[obp++]=(char)0xDF;
1067 OpBuffer[obp++]=(char)0xE0;
1068
[36]1069 //mov ecx,1
[3]1070 OpBuffer[obp++]=(char)0xB9;
[36]1071 *((long *)(OpBuffer+obp))=1;
[3]1072 obp+=sizeof(long);
1073
1074 //test ah,40
1075 OpBuffer[obp++]=(char)0xF6;
1076 OpBuffer[obp++]=(char)0xC4;
1077 OpBuffer[obp++]=(char)0x40;
1078
1079 //je 5
1080 OpBuffer[obp++]=(char)0x74;
1081 OpBuffer[obp++]=(char)0x05;
1082
1083 //mov ecx,0
1084 OpBuffer[obp++]=(char)0xB9;
1085 *((long *)(OpBuffer+obp))=0;
1086 obp+=sizeof(long);
1087
1088 //mov dword ptr[esp],ecx
1089 OpBuffer[obp++]=(char)0x89;
1090 OpBuffer[obp++]=(char)0x0C;
1091 OpBuffer[obp++]=(char)0x24;
1092 }
1093 else if(type[sp-2]==DEF_INT64||type[sp-2]==DEF_QWORD||
1094 type[sp-1]==DEF_INT64||type[sp-1]==DEF_QWORD){
1095 ////////////////////
1096 // 64ビット整数演算
1097 ////////////////////
1098 int TrueSchedule1,
1099 TrueSchedule2;
1100
1101 // 第1項 <> 第2項
1102
1103 //第1項 edx:eax
1104 //第2項 ecx:ebx
1105 GetStackData_ToRegister(type,sp);
1106
1107 //cmp eax,ebx
1108 OpBuffer[obp++]=(char)0x3B;
1109 OpBuffer[obp++]=(char)0xC3;
1110
1111 //jnz TrueSchedule1(真へジャンプ)
1112 OpBuffer[obp++]=(char)0x75;
1113 TrueSchedule1=obp;
1114 obp++;
1115
1116 //cmp edx,ecx
1117 OpBuffer[obp++]=(char)0x3B;
1118 OpBuffer[obp++]=(char)0xD1;
1119
1120 //jnz TrueSchedule2(真へジャンプ)
1121 OpBuffer[obp++]=(char)0x75;
1122 TrueSchedule2=obp;
1123 obp++;
1124
1125 //xor eax,eax(eaxを0にする)
1126 op_zero_reg(REG_EAX);
1127
1128 //jmp 5(演算終了位置へジャンプ)
1129 OpBuffer[obp++]=(char)0xEB;
1130 OpBuffer[obp++]=(char)0x05;
1131
1132 //TrueScheduleのジャンプ先の設定
1133 OpBuffer[TrueSchedule1]=obp-(TrueSchedule1+1);
1134 OpBuffer[TrueSchedule2]=obp-(TrueSchedule2+1);
1135
[36]1136 //mov eax,1
[3]1137 OpBuffer[obp++]=(char)0xB8;
[36]1138 *((long *)(OpBuffer+obp))=1;
[3]1139 obp+=sizeof(long);
1140
1141 //push eax
1142 op_push(REG_EAX);
1143 }
1144 else{
1145 ////////////////////
1146 // 32ビット整数演算
1147 ////////////////////
1148
1149 //pop eax
1150 op_pop(REG_EAX);
1151
1152 //pop ebx
1153 op_pop(REG_EBX);
1154
[97]1155 // どちらかのサイズが足りない場合は自動拡張する
1156 AutoExtendToBigType( type, sp, REG_EAX, REG_EBX );
1157
[3]1158 //sub esp,4
1159 op_sub_esp(4);
1160
1161 //xor eax,ebx
1162 OpBuffer[obp++]=(char)0x33;
1163 OpBuffer[obp++]=(char)0xC3;
1164
1165 //jz 5(次のmovを飛び越す)
1166 OpBuffer[obp++]=(char)0x74;
1167 OpBuffer[obp++]=(char)0x05;
1168
[36]1169 //mov eax,1
[3]1170 OpBuffer[obp++]=(char)0xB8;
[36]1171 *((long *)(OpBuffer+obp))=1;
[3]1172 obp+=sizeof(long);
1173
1174 //mov dword ptr[esp],eax
1175 OpBuffer[obp++]=(char)0x89;
1176 OpBuffer[obp++]=(char)0x04;
1177 OpBuffer[obp++]=(char)0x24;
1178 }
1179
1180 sp--;
[36]1181 type[sp-1]=DEF_BOOLEAN;
[3]1182
1183 *pStackPointer=sp;
1184 return 1;
1185}
1186
1187BOOL Calc_Relation_Equal(int *type,int *pStackPointer){
1188 //value[sp-2]=value[sp-1]
1189
1190 int sp;
1191 sp=*pStackPointer;
1192
1193 if(type[sp-2]==DEF_DOUBLE||type[sp-2]==DEF_SINGLE||
1194 type[sp-1]==DEF_DOUBLE||type[sp-1]==DEF_SINGLE){
1195 //////////////
1196 // 実数演算
1197 //////////////
1198
1199 if(type[sp-1]==DEF_DOUBLE){
1200 //fld qword ptr[esp]
1201 op_fld_ptr_esp(DEF_DOUBLE);
1202
1203 //add esp,8
1204 op_add_esp(8);
1205 }
1206 else if(type[sp-1]==DEF_SINGLE){
1207 //fld dword ptr[esp]
1208 op_fld_ptr_esp(DEF_SINGLE);
1209
1210 //add esp,4
1211 op_add_esp(4);
1212 }
1213 else if(type[sp-1]==DEF_INT64||type[sp-1]==DEF_QWORD){
1214 //64ビット整数値
1215
1216 //fild qword ptr[esp]
1217 op_fld_ptr_esp(DEF_INT64);
1218
1219 //add esp,8
1220 op_add_esp(8);
1221 }
1222 else{ //Long、DWord
1223 //fild dword ptr[esp]
1224 op_fld_ptr_esp(DEF_LONG);
1225
1226 //add esp,4
1227 op_add_esp(4);
1228 }
1229
1230 if(type[sp-2]==DEF_DOUBLE){
1231 //fld qword ptr[esp]
1232 op_fld_ptr_esp(DEF_DOUBLE);
1233
1234 //add esp,4
1235 op_add_esp(4);
1236 }
1237 else if(type[sp-2]==DEF_SINGLE){
1238 //fld dword ptr[esp]
1239 op_fld_ptr_esp(DEF_SINGLE);
1240 }
1241 else if(type[sp-2]==DEF_INT64||type[sp-2]==DEF_QWORD){
1242 //64ビット整数値
1243
1244 //fild qword ptr[esp]
1245 op_fld_ptr_esp(DEF_INT64);
1246
1247 //add esp,4
1248 op_add_esp(4);
1249 }
1250 else{ //Long、DWord
1251 //fild dword ptr[esp]
1252 op_fld_ptr_esp(DEF_LONG);
1253 }
1254
1255 //fcompp
1256 OpBuffer[obp++]=(char)0xDE;
1257 OpBuffer[obp++]=(char)0xD9;
1258
1259 //fnstsw ax
1260 OpBuffer[obp++]=(char)0xDF;
1261 OpBuffer[obp++]=(char)0xE0;
1262
[36]1263 //mov ecx,1
[3]1264 OpBuffer[obp++]=(char)0xB9;
[36]1265 *((long *)(OpBuffer+obp))=1;
[3]1266 obp+=sizeof(long);
1267
1268 //test ah,40
1269 OpBuffer[obp++]=(char)0xF6;
1270 OpBuffer[obp++]=(char)0xC4;
1271 OpBuffer[obp++]=(char)0x40;
1272
1273 //jne 5
1274 OpBuffer[obp++]=(char)0x75;
1275 OpBuffer[obp++]=(char)0x05;
1276
1277 //mov ecx,0
1278 OpBuffer[obp++]=(char)0xB9;
1279 *((long *)(OpBuffer+obp))=0;
1280 obp+=sizeof(long);
1281
1282 //mov dword ptr[esp],ecx
1283 OpBuffer[obp++]=(char)0x89;
1284 OpBuffer[obp++]=(char)0x0C;
1285 OpBuffer[obp++]=(char)0x24;
1286 }
1287 else if(type[sp-2]==DEF_INT64||type[sp-2]==DEF_QWORD||
1288 type[sp-1]==DEF_INT64||type[sp-1]==DEF_QWORD){
1289 ////////////////////
1290 // 64ビット整数演算
1291 ////////////////////
1292 int FalseSchedule1,
1293 FalseSchedule2;
1294
1295 // 第1項 == 第2項
1296
1297 //第1項 edx:eax
1298 //第2項 ecx:ebx
1299 GetStackData_ToRegister(type,sp);
1300
1301 //cmp eax,ebx
1302 OpBuffer[obp++]=(char)0x3B;
1303 OpBuffer[obp++]=(char)0xC3;
1304
1305 //jnz FalseSchedule1(偽へジャンプ)
1306 OpBuffer[obp++]=(char)0x75;
1307 FalseSchedule1=obp;
1308 obp++;
1309
1310 //cmp edx,ecx
1311 OpBuffer[obp++]=(char)0x3B;
1312 OpBuffer[obp++]=(char)0xD1;
1313
1314 //jnz FalseSchedule2(偽へジャンプ)
1315 OpBuffer[obp++]=(char)0x75;
1316 FalseSchedule2=obp;
1317 obp++;
1318
[36]1319 //mov eax,1
[3]1320 OpBuffer[obp++]=(char)0xB8;
[36]1321 *((long *)(OpBuffer+obp))=1;
[3]1322 obp+=sizeof(long);
1323
1324 //jmp 2(演算終了位置へジャンプ)
1325 OpBuffer[obp++]=(char)0xEB;
1326 OpBuffer[obp++]=(char)0x02;
1327
1328 //FalseScheduleのジャンプ先の設定
1329 OpBuffer[FalseSchedule1]=obp-(FalseSchedule1+1);
1330 OpBuffer[FalseSchedule2]=obp-(FalseSchedule2+1);
1331
1332 //xor eax,eax(eaxを0にする)
1333 op_zero_reg(REG_EAX);
1334
1335 //push eax
1336 op_push(REG_EAX);
1337 }
1338 else{
1339 ////////////////////
1340 // 32ビット整数演算
1341 ////////////////////
1342
1343 //pop eax
1344 op_pop(REG_EAX);
1345
1346 //pop ebx
1347 op_pop(REG_EBX);
1348
[97]1349 // どちらかのサイズが足りない場合は自動拡張する
1350 AutoExtendToBigType( type, sp, REG_EAX, REG_EBX );
1351
[3]1352 //sub esp,4
1353 op_sub_esp(4);
1354
1355 //xor eax,ebx
1356 OpBuffer[obp++]=(char)0x33;
1357 OpBuffer[obp++]=(char)0xC3;
1358
[64]1359 //jz 4(次のxorとjmpを飛び越す)
[3]1360 OpBuffer[obp++]=(char)0x74;
[36]1361 OpBuffer[obp++]=(char)0x04;
1362
1363 //xor eax,eax
1364 OpBuffer[obp++]=(char)0x33;
1365 OpBuffer[obp++]=(char)0xC0;
1366
1367 //jmp 5
1368 OpBuffer[obp++]=(char)0xEB;
[3]1369 OpBuffer[obp++]=(char)0x05;
1370
[36]1371 //mov eax,1
[3]1372 OpBuffer[obp++]=(char)0xB8;
[36]1373 *((long *)(OpBuffer+obp))=1;
[3]1374 obp+=sizeof(long);
1375
1376 //mov dword ptr[esp],eax
1377 OpBuffer[obp++]=(char)0x89;
1378 OpBuffer[obp++]=(char)0x04;
1379 OpBuffer[obp++]=(char)0x24;
1380 }
1381
1382 sp--;
[36]1383 type[sp-1]=DEF_BOOLEAN;
[3]1384
1385 *pStackPointer=sp;
1386 return 1;
1387}
Note: See TracBrowser for help on using the repository browser.