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

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