source: dev/trunk/abdev/BasicCompiler32/Compile_Calc_PushVar.cpp@ 253

Last change on this file since 253 was 253, checked in by dai_9181, 17 years ago
File size: 6.8 KB
Line 
1#include "stdafx.h"
2
3#include <Compiler.h>
4
5#include "../BasicCompiler_Common/common.h"
6#include "Opcode.h"
7
8void 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, Schedule::GlobalVar );
13 }
14 else{
15 //mov ecx,offset
16 compiler.codeGenerator.op_mov_RV(REG_ECX,(int)pRelativeVar->offset, Schedule::GlobalVar );
17
18 //fld ptr[ecx]
19 compiler.codeGenerator.op_fld_basereg(type,REG_ECX);
20 }
21 }
22 else if(pRelativeVar->dwKind==VAR_REFGLOBAL){
23 SetError(300,NULL,cp);
24 }
25 else if(pRelativeVar->dwKind==VAR_LOCAL){
26 if(pRelativeVar->bOffsetOffset){
27 //fld ptr[ebp+ecx+offset]
28 compiler.codeGenerator.localVarPertialSchedules.push_back(
29 compiler.codeGenerator.op_fld_base_offset_ex(type,REG_EBP,REG_ECX,(int)pRelativeVar->offset,USE_OFFSET, Schedule::None, true )
30 );
31 }
32 else{
33 //fld ptr[ebp+offset]
34 compiler.codeGenerator.localVarPertialSchedules.push_back(
35 compiler.codeGenerator.op_fld_base_offset(type,REG_EBP,(int)pRelativeVar->offset, Schedule::None, true )
36 );
37 }
38 }
39 else if(pRelativeVar->dwKind==VAR_REFLOCAL){
40 if(pRelativeVar->bOffsetOffset){
41 //add ecx,qword ptr[ebp+offset]
42 compiler.codeGenerator.localVarPertialSchedules.push_back(
43 compiler.codeGenerator.op_add_RM(sizeof(long),REG_ECX,REG_EBP,(int)pRelativeVar->offset,MOD_BASE_DISP32, Schedule::None, true )
44 );
45 }
46 else{
47 //mov ecx,qword ptr[ebp+offset]
48 compiler.codeGenerator.localVarPertialSchedules.push_back(
49 compiler.codeGenerator.op_mov_RM(sizeof(long),REG_ECX,REG_EBP,(int)pRelativeVar->offset,MOD_BASE_DISP32, Schedule::None, true )
50 );
51 }
52
53 goto directmem;
54 }
55 else if(pRelativeVar->dwKind==VAR_DIRECTMEM){
56directmem:
57 //fld ptr[ecx]
58 compiler.codeGenerator.op_fld_basereg(type,REG_ECX);
59 }
60}
61void SetReg_WholeVariable(int type,RELATIVE_VAR *pRelativeVar,int reg, bool is64Head){
62 int varSize;
63
64 varSize=GetTypeSize(type,-1);
65
66 if(varSize==sizeof(_int64)){
67 //64ビットの場合はedx:eaxにロード
68 if(reg!=REG_EAX){
69 SetError(300,NULL,cp);
70 return;
71 }
72
73 //下位32ビットをeaxにロード
74 SetReg_WholeVariable(DEF_LONG,pRelativeVar,REG_EAX);
75
76 //上位32ビットをedxにロード
77 SetReg_WholeVariable(DEF_LONG,pRelativeVar,REG_EDX, true);
78
79 return;
80 }
81
82 int offsetOf64Head = 0;
83 if( is64Head ){
84 offsetOf64Head = sizeof(long);
85 }
86
87 if(pRelativeVar->dwKind==VAR_GLOBAL){
88 if(pRelativeVar->bOffsetOffset){
89 //mov reg, ptr[ecx+offset]
90 compiler.codeGenerator.op_mov_RM(varSize,reg,REG_ECX,(int)pRelativeVar->offset + offsetOf64Head,MOD_BASE_DISP32, Schedule::GlobalVar );
91 }
92 else{
93 //mov reg, ptr[offset]
94 compiler.codeGenerator.op_mov_RM(varSize,reg,0,(int)pRelativeVar->offset + offsetOf64Head,MOD_DISP32, Schedule::GlobalVar );
95 }
96 }
97 else if(pRelativeVar->dwKind==VAR_REFGLOBAL){
98 if(pRelativeVar->bOffsetOffset){
99 //add ecx,qword ptr[offset]
100 compiler.codeGenerator.op_add_RM(varSize,REG_ECX,REG_NON,(int)pRelativeVar->offset,MOD_DISP32, Schedule::GlobalVar );
101 }
102 else{
103 //mov ecx,qword ptr[offset]
104 compiler.codeGenerator.op_mov_RM(varSize,REG_ECX,REG_NON,(int)pRelativeVar->offset,MOD_DISP32, Schedule::GlobalVar );
105 }
106
107 goto directmem;
108 }
109 else if(pRelativeVar->dwKind==VAR_LOCAL){
110 if(pRelativeVar->bOffsetOffset){
111 //mov reg, ptr[ebp+ecx+offset]
112 compiler.codeGenerator.localVarPertialSchedules.push_back(
113 compiler.codeGenerator.op_mov_RM_ex(varSize,reg,REG_EBP,REG_ECX,(int)pRelativeVar->offset + offsetOf64Head,USE_OFFSET, Schedule::None, true )
114 );
115 }
116 else{
117 //mov reg, ptr[ebp+offset]
118 compiler.codeGenerator.localVarPertialSchedules.push_back(
119 compiler.codeGenerator.op_mov_RM(varSize,reg,REG_EBP,(int)pRelativeVar->offset + offsetOf64Head,MOD_BASE_DISP32, Schedule::None, true )
120 );
121 }
122 }
123 else if(pRelativeVar->dwKind==VAR_REFLOCAL){
124 if(pRelativeVar->bOffsetOffset){
125 //add ecx,qword ptr[ebp+offset]
126 compiler.codeGenerator.localVarPertialSchedules.push_back(
127 compiler.codeGenerator.op_add_RM(varSize,REG_ECX,REG_EBP,(int)pRelativeVar->offset,MOD_BASE_DISP32, Schedule::None, true )
128 );
129 }
130 else{
131 //mov ecx,qword ptr[ebp+offset]
132 compiler.codeGenerator.localVarPertialSchedules.push_back(
133 compiler.codeGenerator.op_mov_RM(varSize,REG_ECX,REG_EBP,(int)pRelativeVar->offset,MOD_BASE_DISP32, Schedule::None, true )
134 );
135 }
136
137 goto directmem;
138 }
139 else if(pRelativeVar->dwKind==VAR_DIRECTMEM){
140directmem:
141 if( is64Head ){
142 //mov reg, ptr[ecx]
143 compiler.codeGenerator.op_mov_RM(varSize,reg,REG_ECX,offsetOf64Head,MOD_BASE_DISP8);
144 }
145 else{
146 //mov reg, ptr[ecx]
147 compiler.codeGenerator.op_mov_RM(varSize,reg,REG_ECX,0,MOD_BASE);
148 }
149 }
150}
151
152
153
154void PushLongVariable(RELATIVE_VAR *pRelativeVar){
155 if(pRelativeVar->dwKind==VAR_GLOBAL){
156 if(pRelativeVar->bOffsetOffset){
157 //push dword ptr[ecx+offset]
158 compiler.codeGenerator.op_push_M( REG_ECX, pRelativeVar->offset, Schedule::GlobalVar );
159 }
160 else{
161 //push dword ptr[offset]
162 compiler.codeGenerator.op_push_M( REG_NON, pRelativeVar->offset, Schedule::GlobalVar );
163 }
164 }
165 else if(pRelativeVar->dwKind==VAR_REFGLOBAL){
166 //mov eax,dword ptr[offset]
167 compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EAX, REG_NON, (int)pRelativeVar->offset, MOD_DISP32, Schedule::GlobalVar );
168
169 if(pRelativeVar->bOffsetOffset){
170 //add eax,ecx
171 compiler.codeGenerator.op_add_RR( REG_EAX, REG_ECX );
172 }
173
174 //push dword ptr[eax]
175 compiler.codeGenerator.op_push_M( REG_EAX );
176 }
177 else if(pRelativeVar->dwKind==VAR_LOCAL){
178 if(pRelativeVar->bOffsetOffset){
179 //add ecx,offset
180 compiler.codeGenerator.localVarPertialSchedules.push_back(
181 compiler.codeGenerator.op_add_RV( REG_ECX, pRelativeVar->offset, Schedule::None, true )
182 );
183
184 //push dword ptr[ebp+ecx]
185 compiler.codeGenerator.PutOld(
186 (char)0xFF,
187 (char)0x74,
188 (char)0x0D,
189 (char)0x00
190 );
191 }
192 else{
193 //push dword ptr[ebp+offset]
194 compiler.codeGenerator.localVarPertialSchedules.push_back(
195 compiler.codeGenerator.op_push_M( REG_EBP, pRelativeVar->offset, Schedule::None, true )
196 );
197 }
198 }
199 else if(pRelativeVar->dwKind==VAR_REFLOCAL){
200 //mov eax,dword ptr[ebp+offset]
201 compiler.codeGenerator.localVarPertialSchedules.push_back(
202 compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EAX, REG_EBP, pRelativeVar->offset, MOD_BASE_DISP32, Schedule::None, true )
203 );
204
205 if(pRelativeVar->bOffsetOffset){
206 //add eax,ecx
207 compiler.codeGenerator.op_add_RR( REG_EAX, REG_ECX );
208 }
209
210 //push dword ptr[eax]
211 compiler.codeGenerator.op_push_M( REG_EAX );
212 }
213 else if(pRelativeVar->dwKind==VAR_DIRECTMEM){
214 //push dword ptr[ecx]
215 compiler.codeGenerator.op_push_M( REG_ECX );
216 }
217}
Note: See TracBrowser for help on using the repository browser.