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

Last change on this file since 326 was 308, 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( const Type &type, RELATIVE_VAR *pRelativeVar,int reg, bool is64Head)
62{
63 int varSize;
64
65 varSize = type.GetSize();
66
67 if(varSize==sizeof(_int64)){
68 //64ビットの場合はedx:eaxにロード
69 if(reg!=REG_EAX){
70 SetError(300,NULL,cp);
71 return;
72 }
73
74 //下位32ビットをeaxにロード
75 SetReg_WholeVariable( Type(DEF_LONG),pRelativeVar,REG_EAX);
76
77 //上位32ビットをedxにロード
78 SetReg_WholeVariable( Type(DEF_LONG),pRelativeVar,REG_EDX, true);
79
80 return;
81 }
82
83 int offsetOf64Head = 0;
84 if( is64Head ){
85 offsetOf64Head = sizeof(long);
86 }
87
88 if(pRelativeVar->dwKind==VAR_GLOBAL){
89 if(pRelativeVar->bOffsetOffset){
90 //mov reg, ptr[ecx+offset]
91 compiler.codeGenerator.op_mov_RM(varSize,reg,REG_ECX,(int)pRelativeVar->offset + offsetOf64Head,MOD_BASE_DISP32, Schedule::GlobalVar );
92 }
93 else{
94 //mov reg, ptr[offset]
95 compiler.codeGenerator.op_mov_RM(varSize,reg,0,(int)pRelativeVar->offset + offsetOf64Head,MOD_DISP32, Schedule::GlobalVar );
96 }
97 }
98 else if(pRelativeVar->dwKind==VAR_REFGLOBAL){
99 if(pRelativeVar->bOffsetOffset){
100 //add ecx,qword ptr[offset]
101 compiler.codeGenerator.op_add_RM(varSize,REG_ECX,REG_NON,(int)pRelativeVar->offset,MOD_DISP32, Schedule::GlobalVar );
102 }
103 else{
104 //mov ecx,qword ptr[offset]
105 compiler.codeGenerator.op_mov_RM(varSize,REG_ECX,REG_NON,(int)pRelativeVar->offset,MOD_DISP32, Schedule::GlobalVar );
106 }
107
108 goto directmem;
109 }
110 else if(pRelativeVar->dwKind==VAR_LOCAL){
111 if(pRelativeVar->bOffsetOffset){
112 //mov reg, ptr[ebp+ecx+offset]
113 compiler.codeGenerator.localVarPertialSchedules.push_back(
114 compiler.codeGenerator.op_mov_RM_ex(varSize,reg,REG_EBP,REG_ECX,(int)pRelativeVar->offset + offsetOf64Head,USE_OFFSET, Schedule::None, true )
115 );
116 }
117 else{
118 //mov reg, ptr[ebp+offset]
119 compiler.codeGenerator.localVarPertialSchedules.push_back(
120 compiler.codeGenerator.op_mov_RM(varSize,reg,REG_EBP,(int)pRelativeVar->offset + offsetOf64Head,MOD_BASE_DISP32, Schedule::None, true )
121 );
122 }
123 }
124 else if(pRelativeVar->dwKind==VAR_REFLOCAL){
125 if(pRelativeVar->bOffsetOffset){
126 //add ecx,qword ptr[ebp+offset]
127 compiler.codeGenerator.localVarPertialSchedules.push_back(
128 compiler.codeGenerator.op_add_RM(varSize,REG_ECX,REG_EBP,(int)pRelativeVar->offset,MOD_BASE_DISP32, Schedule::None, true )
129 );
130 }
131 else{
132 //mov ecx,qword ptr[ebp+offset]
133 compiler.codeGenerator.localVarPertialSchedules.push_back(
134 compiler.codeGenerator.op_mov_RM(varSize,REG_ECX,REG_EBP,(int)pRelativeVar->offset,MOD_BASE_DISP32, Schedule::None, true )
135 );
136 }
137
138 goto directmem;
139 }
140 else if(pRelativeVar->dwKind==VAR_DIRECTMEM){
141directmem:
142 if( is64Head ){
143 //mov reg, ptr[ecx]
144 compiler.codeGenerator.op_mov_RM(varSize,reg,REG_ECX,offsetOf64Head,MOD_BASE_DISP8);
145 }
146 else{
147 //mov reg, ptr[ecx]
148 compiler.codeGenerator.op_mov_RM(varSize,reg,REG_ECX,0,MOD_BASE);
149 }
150 }
151}
152
153
154
155void PushLongVariable(RELATIVE_VAR *pRelativeVar){
156 if(pRelativeVar->dwKind==VAR_GLOBAL){
157 if(pRelativeVar->bOffsetOffset){
158 //push dword ptr[ecx+offset]
159 compiler.codeGenerator.op_push_M( REG_ECX, pRelativeVar->offset, Schedule::GlobalVar );
160 }
161 else{
162 //push dword ptr[offset]
163 compiler.codeGenerator.op_push_M( REG_NON, pRelativeVar->offset, Schedule::GlobalVar );
164 }
165 }
166 else if(pRelativeVar->dwKind==VAR_REFGLOBAL){
167 //mov eax,dword ptr[offset]
168 compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EAX, REG_NON, (int)pRelativeVar->offset, MOD_DISP32, Schedule::GlobalVar );
169
170 if(pRelativeVar->bOffsetOffset){
171 //add eax,ecx
172 compiler.codeGenerator.op_add_RR( REG_EAX, REG_ECX );
173 }
174
175 //push dword ptr[eax]
176 compiler.codeGenerator.op_push_M( REG_EAX );
177 }
178 else if(pRelativeVar->dwKind==VAR_LOCAL){
179 if(pRelativeVar->bOffsetOffset){
180 //add ecx,offset
181 compiler.codeGenerator.localVarPertialSchedules.push_back(
182 compiler.codeGenerator.op_add_RV( REG_ECX, pRelativeVar->offset, Schedule::None, true )
183 );
184
185 //push dword ptr[ebp+ecx]
186 compiler.codeGenerator.PutOld(
187 (char)0xFF,
188 (char)0x74,
189 (char)0x0D,
190 (char)0x00
191 );
192 }
193 else{
194 //push dword ptr[ebp+offset]
195 compiler.codeGenerator.localVarPertialSchedules.push_back(
196 compiler.codeGenerator.op_push_M( REG_EBP, pRelativeVar->offset, Schedule::None, true )
197 );
198 }
199 }
200 else if(pRelativeVar->dwKind==VAR_REFLOCAL){
201 //mov eax,dword ptr[ebp+offset]
202 compiler.codeGenerator.localVarPertialSchedules.push_back(
203 compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EAX, REG_EBP, pRelativeVar->offset, MOD_BASE_DISP32, Schedule::None, true )
204 );
205
206 if(pRelativeVar->bOffsetOffset){
207 //add eax,ecx
208 compiler.codeGenerator.op_add_RR( REG_EAX, REG_ECX );
209 }
210
211 //push dword ptr[eax]
212 compiler.codeGenerator.op_push_M( REG_EAX );
213 }
214 else if(pRelativeVar->dwKind==VAR_DIRECTMEM){
215 //push dword ptr[ecx]
216 compiler.codeGenerator.op_push_M( REG_ECX );
217 }
218}
Note: See TracBrowser for help on using the repository browser.