source: dev/BasicCompiler32/Compile_Set_Var.cpp@ 15

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