1 | #include "stdafx.h"
|
---|
2 |
|
---|
3 | #include <Compiler.h>
|
---|
4 |
|
---|
5 | #include "../BasicCompiler_Common/common.h"
|
---|
6 | #include "Opcode.h"
|
---|
7 |
|
---|
8 | void SetReg_RealVariable(int type,RELATIVE_VAR *pRelativeVar){
|
---|
9 | if(pRelativeVar->dwKind==VAR_GLOBAL){
|
---|
10 | if(pRelativeVar->bOffsetOffset){
|
---|
11 | //fld ptr[ecx+offset]
|
---|
12 | compiler.codeGenerator.op_fld_base_offset(type,REG_ECX,(int)pRelativeVar->offset);
|
---|
13 | obp-=sizeof(long);
|
---|
14 | pobj_GlobalVarSchedule->add();
|
---|
15 | obp+=sizeof(long);
|
---|
16 | }
|
---|
17 | else{
|
---|
18 | //mov ecx,offset
|
---|
19 | compiler.codeGenerator.op_mov_RV(REG_ECX,(int)pRelativeVar->offset);
|
---|
20 | obp-=sizeof(long);
|
---|
21 | pobj_GlobalVarSchedule->add();
|
---|
22 | obp+=sizeof(long);
|
---|
23 |
|
---|
24 | //fld ptr[ecx]
|
---|
25 | compiler.codeGenerator.op_fld_basereg(type,REG_ECX);
|
---|
26 | }
|
---|
27 | }
|
---|
28 | else if(pRelativeVar->dwKind==VAR_REFGLOBAL){
|
---|
29 | SetError(300,NULL,cp);
|
---|
30 | }
|
---|
31 | else if(pRelativeVar->dwKind==VAR_LOCAL){
|
---|
32 | if(pRelativeVar->bOffsetOffset){
|
---|
33 | //fld ptr[ebp+ecx+offset]
|
---|
34 | compiler.codeGenerator.op_fld_base_offset_ex(type,REG_EBP,REG_ECX,(int)pRelativeVar->offset,USE_OFFSET);
|
---|
35 | obp-=sizeof(long);
|
---|
36 | AddLocalVarAddrSchedule();
|
---|
37 | obp+=sizeof(long);
|
---|
38 | }
|
---|
39 | else{
|
---|
40 | //fld ptr[ebp+offset]
|
---|
41 | compiler.codeGenerator.op_fld_base_offset(type,REG_EBP,(int)pRelativeVar->offset);
|
---|
42 | obp-=sizeof(long);
|
---|
43 | AddLocalVarAddrSchedule();
|
---|
44 | obp+=sizeof(long);
|
---|
45 | }
|
---|
46 | }
|
---|
47 | else if(pRelativeVar->dwKind==VAR_REFLOCAL){
|
---|
48 | if(pRelativeVar->bOffsetOffset){
|
---|
49 | //add ecx,qword ptr[ebp+offset]
|
---|
50 | compiler.codeGenerator.op_add_RM(sizeof(long),REG_ECX,REG_EBP,(int)pRelativeVar->offset,MOD_BASE_DISP32);
|
---|
51 | obp-=sizeof(long);
|
---|
52 | AddLocalVarAddrSchedule();
|
---|
53 | obp+=sizeof(long);
|
---|
54 | }
|
---|
55 | else{
|
---|
56 | //mov ecx,qword ptr[ebp+offset]
|
---|
57 | compiler.codeGenerator.op_mov_RM(sizeof(long),REG_ECX,REG_EBP,(int)pRelativeVar->offset,MOD_BASE_DISP32);
|
---|
58 | obp-=sizeof(long);
|
---|
59 | AddLocalVarAddrSchedule();
|
---|
60 | obp+=sizeof(long);
|
---|
61 | }
|
---|
62 |
|
---|
63 | goto directmem;
|
---|
64 | }
|
---|
65 | else if(pRelativeVar->dwKind==VAR_DIRECTMEM){
|
---|
66 | directmem:
|
---|
67 | //fld ptr[ecx]
|
---|
68 | compiler.codeGenerator.op_fld_basereg(type,REG_ECX);
|
---|
69 | }
|
---|
70 | }
|
---|
71 | void SetReg_WholeVariable(int type,RELATIVE_VAR *pRelativeVar,int reg, bool is64Head){
|
---|
72 | int varSize;
|
---|
73 |
|
---|
74 | varSize=GetTypeSize(type,-1);
|
---|
75 |
|
---|
76 | if(varSize==sizeof(_int64)){
|
---|
77 | //64ビットの場合はedx:eaxにロード
|
---|
78 | if(reg!=REG_EAX){
|
---|
79 | SetError(300,NULL,cp);
|
---|
80 | return;
|
---|
81 | }
|
---|
82 |
|
---|
83 | //下位32ビットをeaxにロード
|
---|
84 | SetReg_WholeVariable(DEF_LONG,pRelativeVar,REG_EAX);
|
---|
85 |
|
---|
86 | //上位32ビットをedxにロード
|
---|
87 | SetReg_WholeVariable(DEF_LONG,pRelativeVar,REG_EDX, true);
|
---|
88 |
|
---|
89 | return;
|
---|
90 | }
|
---|
91 |
|
---|
92 | int offsetOf64Head = 0;
|
---|
93 | if( is64Head ){
|
---|
94 | offsetOf64Head = sizeof(long);
|
---|
95 | }
|
---|
96 |
|
---|
97 | if(pRelativeVar->dwKind==VAR_GLOBAL){
|
---|
98 | if(pRelativeVar->bOffsetOffset){
|
---|
99 | //mov reg, ptr[ecx+offset]
|
---|
100 | compiler.codeGenerator.op_mov_RM(varSize,reg,REG_ECX,(int)pRelativeVar->offset + offsetOf64Head,MOD_BASE_DISP32);
|
---|
101 | }
|
---|
102 | else{
|
---|
103 | //mov reg, ptr[offset]
|
---|
104 | compiler.codeGenerator.op_mov_RM(varSize,reg,0,(int)pRelativeVar->offset + offsetOf64Head,MOD_DISP32);
|
---|
105 | }
|
---|
106 | obp-=sizeof(long);
|
---|
107 | pobj_GlobalVarSchedule->add();
|
---|
108 | obp+=sizeof(long);
|
---|
109 | }
|
---|
110 | else if(pRelativeVar->dwKind==VAR_REFGLOBAL){
|
---|
111 | if(pRelativeVar->bOffsetOffset){
|
---|
112 | //add ecx,qword ptr[offset]
|
---|
113 | compiler.codeGenerator.op_add_RM(varSize,REG_ECX,REG_NON,(int)pRelativeVar->offset,MOD_DISP32);
|
---|
114 | }
|
---|
115 | else{
|
---|
116 | //mov ecx,qword ptr[offset]
|
---|
117 | compiler.codeGenerator.op_mov_RM(varSize,REG_ECX,REG_NON,(int)pRelativeVar->offset,MOD_DISP32);
|
---|
118 | }
|
---|
119 | obp-=sizeof(long);
|
---|
120 | pobj_GlobalVarSchedule->add();
|
---|
121 | obp+=sizeof(long);
|
---|
122 |
|
---|
123 | goto directmem;
|
---|
124 | }
|
---|
125 | else if(pRelativeVar->dwKind==VAR_LOCAL){
|
---|
126 | if(pRelativeVar->bOffsetOffset){
|
---|
127 | //mov reg, ptr[ebp+ecx+offset]
|
---|
128 | compiler.codeGenerator.op_mov_RM_ex(varSize,reg,REG_EBP,REG_ECX,(int)pRelativeVar->offset + offsetOf64Head,USE_OFFSET);
|
---|
129 | }
|
---|
130 | else{
|
---|
131 | //mov reg, ptr[ebp+offset]
|
---|
132 | compiler.codeGenerator.op_mov_RM(varSize,reg,REG_EBP,(int)pRelativeVar->offset + offsetOf64Head,MOD_BASE_DISP32);
|
---|
133 | }
|
---|
134 | obp-=sizeof(long);
|
---|
135 | AddLocalVarAddrSchedule();
|
---|
136 | obp+=sizeof(long);
|
---|
137 | }
|
---|
138 | else if(pRelativeVar->dwKind==VAR_REFLOCAL){
|
---|
139 | if(pRelativeVar->bOffsetOffset){
|
---|
140 | //add ecx,qword ptr[ebp+offset]
|
---|
141 | compiler.codeGenerator.op_add_RM(varSize,REG_ECX,REG_EBP,(int)pRelativeVar->offset,MOD_BASE_DISP32);
|
---|
142 | }
|
---|
143 | else{
|
---|
144 | //mov ecx,qword ptr[ebp+offset]
|
---|
145 | compiler.codeGenerator.op_mov_RM(varSize,REG_ECX,REG_EBP,(int)pRelativeVar->offset,MOD_BASE_DISP32);
|
---|
146 | }
|
---|
147 | obp-=sizeof(long);
|
---|
148 | AddLocalVarAddrSchedule();
|
---|
149 | obp+=sizeof(long);
|
---|
150 |
|
---|
151 | goto directmem;
|
---|
152 | }
|
---|
153 | else if(pRelativeVar->dwKind==VAR_DIRECTMEM){
|
---|
154 | directmem:
|
---|
155 | if( is64Head ){
|
---|
156 | //mov reg, ptr[ecx]
|
---|
157 | compiler.codeGenerator.op_mov_RM(varSize,reg,REG_ECX,offsetOf64Head,MOD_BASE_DISP8);
|
---|
158 | }
|
---|
159 | else{
|
---|
160 | //mov reg, ptr[ecx]
|
---|
161 | compiler.codeGenerator.op_mov_RM(varSize,reg,REG_ECX,0,MOD_BASE);
|
---|
162 | }
|
---|
163 | }
|
---|
164 | }
|
---|
165 |
|
---|
166 |
|
---|
167 |
|
---|
168 | void PushLongVariable(RELATIVE_VAR *pRelativeVar){
|
---|
169 | if(pRelativeVar->dwKind==VAR_GLOBAL){
|
---|
170 | if(pRelativeVar->bOffsetOffset){
|
---|
171 | //push dword ptr[ecx+offset]
|
---|
172 | OpBuffer[obp++]=(char)0xFF;
|
---|
173 | OpBuffer[obp++]=(char)0xB1;
|
---|
174 | *((long *)(OpBuffer+obp))=pRelativeVar->offset;
|
---|
175 | pobj_GlobalVarSchedule->add();
|
---|
176 | obp+=sizeof(long);
|
---|
177 | }
|
---|
178 | else{
|
---|
179 | //push dword ptr[offset]
|
---|
180 | OpBuffer[obp++]=(char)0xFF;
|
---|
181 | OpBuffer[obp++]=(char)0x35;
|
---|
182 | *((long *)(OpBuffer+obp))=pRelativeVar->offset;
|
---|
183 | pobj_GlobalVarSchedule->add();
|
---|
184 | obp+=sizeof(long);
|
---|
185 | }
|
---|
186 | }
|
---|
187 | else if(pRelativeVar->dwKind==VAR_REFGLOBAL){
|
---|
188 | //mov eax,dword ptr[offset]
|
---|
189 | compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EAX, REG_NON, (int)pRelativeVar->offset, MOD_DISP32 );
|
---|
190 | obp-=sizeof(long);
|
---|
191 | pobj_GlobalVarSchedule->add();
|
---|
192 | obp+=sizeof(long);
|
---|
193 |
|
---|
194 | if(pRelativeVar->bOffsetOffset){
|
---|
195 | //add eax,ecx
|
---|
196 | compiler.codeGenerator.op_add_RR( REG_EAX, REG_ECX );
|
---|
197 | }
|
---|
198 |
|
---|
199 | //push dword ptr[eax]
|
---|
200 | compiler.codeGenerator.op_push_M( REG_EAX );
|
---|
201 | }
|
---|
202 | else if(pRelativeVar->dwKind==VAR_LOCAL){
|
---|
203 | if(pRelativeVar->bOffsetOffset){
|
---|
204 | //add ecx,offset
|
---|
205 | OpBuffer[obp++]=(char)0x81;
|
---|
206 | OpBuffer[obp++]=(char)0xC1;
|
---|
207 | *((long *)(OpBuffer+obp))=pRelativeVar->offset;
|
---|
208 | AddLocalVarAddrSchedule();
|
---|
209 | obp+=sizeof(long);
|
---|
210 |
|
---|
211 | //push dword ptr[ebp+ecx]
|
---|
212 | compiler.codeGenerator.PutOld(
|
---|
213 | (char)0xFF,
|
---|
214 | (char)0x74,
|
---|
215 | (char)0x0D,
|
---|
216 | (char)0x00
|
---|
217 | );
|
---|
218 | }
|
---|
219 | else{
|
---|
220 | //push dword ptr[ebp+offset]
|
---|
221 | OpBuffer[obp++]=(char)0xFF;
|
---|
222 | OpBuffer[obp++]=(char)0xB5;
|
---|
223 | *((long *)(OpBuffer+obp))=pRelativeVar->offset;
|
---|
224 | AddLocalVarAddrSchedule();
|
---|
225 | obp+=sizeof(long);
|
---|
226 | }
|
---|
227 | }
|
---|
228 | else if(pRelativeVar->dwKind==VAR_REFLOCAL){
|
---|
229 | //mov eax,dword ptr[ebp+offset]
|
---|
230 | OpBuffer[obp++]=(char)0x8B;
|
---|
231 | OpBuffer[obp++]=(char)0x85;
|
---|
232 | *((long *)(OpBuffer+obp))=pRelativeVar->offset;
|
---|
233 | AddLocalVarAddrSchedule();
|
---|
234 | obp+=sizeof(long);
|
---|
235 |
|
---|
236 | if(pRelativeVar->bOffsetOffset){
|
---|
237 | //add eax,ecx
|
---|
238 | compiler.codeGenerator.op_add_RR( REG_EAX, REG_ECX );
|
---|
239 | }
|
---|
240 |
|
---|
241 | //push dword ptr[eax]
|
---|
242 | compiler.codeGenerator.op_push_M( REG_EAX );
|
---|
243 | }
|
---|
244 | else if(pRelativeVar->dwKind==VAR_DIRECTMEM){
|
---|
245 | //push dword ptr[ecx]
|
---|
246 | compiler.codeGenerator.op_push_M( REG_ECX );
|
---|
247 | }
|
---|
248 | }
|
---|