source: dev/BasicCompiler32/NumOpe_TypeOperation.cpp@ 67

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

[32bit Compiler]op_push_value → op_push_V
Nothingに対応。

File size: 3.4 KB
Line 
1#include "../BasicCompiler_Common/common.h"
2#include "Opcode.h"
3
4void ExtendStackTo32(int type);
5void ExtendStackTo64(int type){
6 if(Is64Type(type)) return;
7
8 //32ビットに拡張
9 ExtendStackTo32(type);
10
11 //64ビットに拡張
12 if(IsSignedType(type)){
13 //符号あり
14
15 //pop eax
16 op_pop(REG_EAX);
17
18 //cdq
19 op_cdq();
20
21 //push edx
22 op_push(REG_EDX);
23
24 //push eax
25 op_push(REG_EAX);
26 }
27 else{
28 //符号なし
29
30 //pop eax
31 op_pop(REG_EAX);
32
33 //push 0
34 op_push_V(0);
35
36 //push eax
37 op_push(REG_EAX);
38 }
39}
40void ExtendStackTo32(int type){
41 if(GetTypeSize(type,-1)==sizeof(long)) return;
42
43 if(Is64Type(type)){
44 //pop eax
45 op_pop(REG_EAX);
46
47 //pop edx
48 op_pop(REG_EDX);
49
50 //push eax
51 op_push(REG_EAX);
52 }
53 else if(type==DEF_INTEGER || (isUnicode&&type==DEF_CHAR)){
54 //pop eax
55 op_pop(REG_EAX);
56
57 //movsx eax,ax
58 OpBuffer[obp++]=(char)0x0F;
59 OpBuffer[obp++]=(char)0xBF;
60 OpBuffer[obp++]=(char)0xC0;
61
62 //push eax
63 op_push(REG_EAX);
64 }
65 else if(type==DEF_WORD){
66 //pop eax
67 op_pop(REG_EAX);
68
69 //and eax,0000FFFFh
70 OpBuffer[obp++]=(char)0x25;
71 *((long *)(OpBuffer+obp))=0x0000FFFF;
72 obp+=sizeof(long);
73
74 //push eax
75 op_push(REG_EAX);
76 }
77 else if(type==DEF_SBYTE || (isUnicode==false&&type==DEF_CHAR)){
78 //pop eax
79 op_pop(REG_EAX);
80
81 //movsx eax,al
82 OpBuffer[obp++]=(char)0x0F;
83 OpBuffer[obp++]=(char)0xBE;
84 OpBuffer[obp++]=(char)0xC0;
85
86 //push eax
87 op_push(REG_EAX);
88 }
89 else if(type==DEF_BYTE||type==DEF_BOOLEAN){
90 //pop eax
91 op_pop(REG_EAX);
92
93 //and eax,000000FFh
94 OpBuffer[obp++]=(char)0x25;
95 *((long *)(OpBuffer+obp))=0x000000FF;
96 obp+=sizeof(long);
97
98 //push eax
99 op_push(REG_EAX);
100 }
101}
102void ExtendStackTo16(int type){
103 if(type==DEF_SBYTE || (isUnicode==false&&type==DEF_CHAR)){
104 //pop eax
105 op_pop(REG_EAX);
106
107 //movsx eax,al
108 OpBuffer[obp++]=(char)0x0F;
109 OpBuffer[obp++]=(char)0xBE;
110 OpBuffer[obp++]=(char)0xC0;
111
112 //push eax
113 op_push(REG_EAX);
114 }
115 else if(type==DEF_BYTE){
116 //pop eax
117 op_pop(REG_EAX);
118
119 //and eax,000000FFh
120 OpBuffer[obp++]=(char)0x25;
121 *((long *)(OpBuffer+obp))=0x000000FF;
122 obp+=sizeof(long);
123
124 //push eax
125 op_push(REG_EAX);
126 }
127}
128void ExtendStackTo8(int type){
129 if(Is64Type(type)){
130 //pop eax
131 op_pop(REG_EAX);
132
133 //pop edx
134 op_pop(REG_EDX);
135
136 //push eax
137 op_push(REG_EAX);
138 }
139}
140
141
142void ChangeTypeToWhole(int OldType,int NewType){
143 if(OldType==DEF_DOUBLE){
144 if(Is64Type(NewType)){
145 //fld qword ptr[esp]
146 op_fld_ptr_esp(DEF_DOUBLE);
147
148 //fistp qword ptr[esp]
149 op_fistp_ptr_esp( sizeof(_int64) );
150 }
151 else{
152 //fld qword ptr[esp]
153 op_fld_ptr_esp(DEF_DOUBLE);
154
155 //add esp,4
156 op_add_esp(4);
157
158 //fistp dword ptr[esp]
159 op_fistp_ptr_esp( sizeof(long) );
160 }
161 }
162 else if(OldType==DEF_SINGLE){
163 if(Is64Type(NewType)){
164 //fld dword ptr[esp]
165 op_fld_ptr_esp(DEF_SINGLE);
166
167 //sub esp,4
168 op_sub_esp(4);
169
170 //fistp qword ptr[esp]
171 op_fistp_ptr_esp( sizeof(_int64) );
172 }
173 else{
174 //fld dword ptr[esp]
175 op_fld_ptr_esp(DEF_SINGLE);
176
177 //fistp dword ptr[esp]
178 op_fistp_ptr_esp( sizeof(long) );
179 }
180 }
181 else{
182 //整数から整数へ変換
183
184 if(Is64Type(NewType)){
185 ExtendStackTo64(OldType);
186 }
187 else if(GetTypeSize(NewType,-1)==sizeof(long)){
188 ExtendStackTo32(OldType);
189 }
190 else if(GetTypeSize(NewType,-1)==sizeof(short)){
191 ExtendStackTo16(OldType);
192 }
193 else if(GetTypeSize(NewType,-1)==sizeof(char)){
194 ExtendStackTo8(OldType);
195 }
196 }
197}
Note: See TracBrowser for help on using the repository browser.