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
RevLine 
[206]1#include "stdafx.h"
2
[225]3#include <Compiler.h>
4
[3]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]
[229]12 compiler.codeGenerator.op_fld_base_offset(type,REG_ECX,(int)pRelativeVar->offset, Schedule::GlobalVar );
[3]13 }
14 else{
15 //mov ecx,offset
[229]16 compiler.codeGenerator.op_mov_RV(REG_ECX,(int)pRelativeVar->offset, Schedule::GlobalVar );
[3]17
18 //fld ptr[ecx]
[225]19 compiler.codeGenerator.op_fld_basereg(type,REG_ECX);
[3]20 }
21 }
[62]22 else if(pRelativeVar->dwKind==VAR_REFGLOBAL){
23 SetError(300,NULL,cp);
24 }
[3]25 else if(pRelativeVar->dwKind==VAR_LOCAL){
26 if(pRelativeVar->bOffsetOffset){
27 //fld ptr[ebp+ecx+offset]
[229]28 compiler.codeGenerator.op_fld_base_offset_ex(type,REG_EBP,REG_ECX,(int)pRelativeVar->offset,USE_OFFSET, Schedule::LocalVar );
[3]29 }
30 else{
31 //fld ptr[ebp+offset]
[229]32 compiler.codeGenerator.op_fld_base_offset(type,REG_EBP,(int)pRelativeVar->offset, Schedule::LocalVar );
[3]33 }
34 }
35 else if(pRelativeVar->dwKind==VAR_REFLOCAL){
36 if(pRelativeVar->bOffsetOffset){
37 //add ecx,qword ptr[ebp+offset]
[229]38 compiler.codeGenerator.op_add_RM(sizeof(long),REG_ECX,REG_EBP,(int)pRelativeVar->offset,MOD_BASE_DISP32, Schedule::LocalVar );
[3]39 }
40 else{
41 //mov ecx,qword ptr[ebp+offset]
[229]42 compiler.codeGenerator.op_mov_RM(sizeof(long),REG_ECX,REG_EBP,(int)pRelativeVar->offset,MOD_BASE_DISP32, Schedule::LocalVar );
[3]43 }
44
45 goto directmem;
46 }
47 else if(pRelativeVar->dwKind==VAR_DIRECTMEM){
48directmem:
49 //fld ptr[ecx]
[225]50 compiler.codeGenerator.op_fld_basereg(type,REG_ECX);
[3]51 }
52}
[97]53void SetReg_WholeVariable(int type,RELATIVE_VAR *pRelativeVar,int reg, bool is64Head){
[66]54 int varSize;
[3]55
[66]56 varSize=GetTypeSize(type,-1);
[3]57
[66]58 if(varSize==sizeof(_int64)){
[3]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にロード
[97]69 SetReg_WholeVariable(DEF_LONG,pRelativeVar,REG_EDX, true);
[3]70
71 return;
72 }
73
[97]74 int offsetOf64Head = 0;
75 if( is64Head ){
76 offsetOf64Head = sizeof(long);
77 }
78
[3]79 if(pRelativeVar->dwKind==VAR_GLOBAL){
80 if(pRelativeVar->bOffsetOffset){
81 //mov reg, ptr[ecx+offset]
[229]82 compiler.codeGenerator.op_mov_RM(varSize,reg,REG_ECX,(int)pRelativeVar->offset + offsetOf64Head,MOD_BASE_DISP32, Schedule::GlobalVar );
[3]83 }
84 else{
85 //mov reg, ptr[offset]
[229]86 compiler.codeGenerator.op_mov_RM(varSize,reg,0,(int)pRelativeVar->offset + offsetOf64Head,MOD_DISP32, Schedule::GlobalVar );
[3]87 }
88 }
[62]89 else if(pRelativeVar->dwKind==VAR_REFGLOBAL){
90 if(pRelativeVar->bOffsetOffset){
91 //add ecx,qword ptr[offset]
[229]92 compiler.codeGenerator.op_add_RM(varSize,REG_ECX,REG_NON,(int)pRelativeVar->offset,MOD_DISP32, Schedule::GlobalVar );
[62]93 }
94 else{
95 //mov ecx,qword ptr[offset]
[229]96 compiler.codeGenerator.op_mov_RM(varSize,REG_ECX,REG_NON,(int)pRelativeVar->offset,MOD_DISP32, Schedule::GlobalVar );
[62]97 }
98
99 goto directmem;
100 }
[3]101 else if(pRelativeVar->dwKind==VAR_LOCAL){
102 if(pRelativeVar->bOffsetOffset){
103 //mov reg, ptr[ebp+ecx+offset]
[229]104 compiler.codeGenerator.op_mov_RM_ex(varSize,reg,REG_EBP,REG_ECX,(int)pRelativeVar->offset + offsetOf64Head,USE_OFFSET, Schedule::LocalVar );
[3]105 }
106 else{
107 //mov reg, ptr[ebp+offset]
[229]108 compiler.codeGenerator.op_mov_RM(varSize,reg,REG_EBP,(int)pRelativeVar->offset + offsetOf64Head,MOD_BASE_DISP32, Schedule::LocalVar );
[3]109 }
110 }
111 else if(pRelativeVar->dwKind==VAR_REFLOCAL){
112 if(pRelativeVar->bOffsetOffset){
113 //add ecx,qword ptr[ebp+offset]
[229]114 compiler.codeGenerator.op_add_RM(varSize,REG_ECX,REG_EBP,(int)pRelativeVar->offset,MOD_BASE_DISP32, Schedule::LocalVar );
[3]115 }
116 else{
117 //mov ecx,qword ptr[ebp+offset]
[229]118 compiler.codeGenerator.op_mov_RM(varSize,REG_ECX,REG_EBP,(int)pRelativeVar->offset,MOD_BASE_DISP32, Schedule::LocalVar );
[3]119 }
120
121 goto directmem;
122 }
123 else if(pRelativeVar->dwKind==VAR_DIRECTMEM){
124directmem:
[97]125 if( is64Head ){
126 //mov reg, ptr[ecx]
[225]127 compiler.codeGenerator.op_mov_RM(varSize,reg,REG_ECX,offsetOf64Head,MOD_BASE_DISP8);
[97]128 }
129 else{
130 //mov reg, ptr[ecx]
[225]131 compiler.codeGenerator.op_mov_RM(varSize,reg,REG_ECX,0,MOD_BASE);
[97]132 }
[3]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]
[229]142 compiler.codeGenerator.op_push_M( REG_ECX, pRelativeVar->offset, Schedule::GlobalVar );
[3]143 }
144 else{
145 //push dword ptr[offset]
[229]146 compiler.codeGenerator.op_push_M( REG_NON, pRelativeVar->offset, Schedule::GlobalVar );
[3]147 }
148 }
[62]149 else if(pRelativeVar->dwKind==VAR_REFGLOBAL){
150 //mov eax,dword ptr[offset]
[229]151 compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EAX, REG_NON, (int)pRelativeVar->offset, MOD_DISP32, Schedule::GlobalVar );
[62]152
153 if(pRelativeVar->bOffsetOffset){
154 //add eax,ecx
[225]155 compiler.codeGenerator.op_add_RR( REG_EAX, REG_ECX );
[62]156 }
157
158 //push dword ptr[eax]
[225]159 compiler.codeGenerator.op_push_M( REG_EAX );
[62]160 }
[3]161 else if(pRelativeVar->dwKind==VAR_LOCAL){
162 if(pRelativeVar->bOffsetOffset){
163 //add ecx,offset
[231]164 compiler.codeGenerator.op_add_RV( REG_ECX, pRelativeVar->offset, Schedule::LocalVar );
[3]165
166 //push dword ptr[ebp+ecx]
[225]167 compiler.codeGenerator.PutOld(
168 (char)0xFF,
169 (char)0x74,
170 (char)0x0D,
171 (char)0x00
172 );
[3]173 }
174 else{
175 //push dword ptr[ebp+offset]
[231]176 compiler.codeGenerator.op_push_M( REG_EBP, pRelativeVar->offset, Schedule::LocalVar );
[3]177 }
178 }
179 else if(pRelativeVar->dwKind==VAR_REFLOCAL){
180 //mov eax,dword ptr[ebp+offset]
[231]181 compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EAX, REG_EBP, pRelativeVar->offset, MOD_BASE_DISP32, Schedule::LocalVar );
[3]182
183 if(pRelativeVar->bOffsetOffset){
184 //add eax,ecx
[225]185 compiler.codeGenerator.op_add_RR( REG_EAX, REG_ECX );
[3]186 }
187
188 //push dword ptr[eax]
[225]189 compiler.codeGenerator.op_push_M( REG_EAX );
[3]190 }
191 else if(pRelativeVar->dwKind==VAR_DIRECTMEM){
192 //push dword ptr[ecx]
[225]193 compiler.codeGenerator.op_push_M( REG_ECX );
[3]194 }
195}
Note: See TracBrowser for help on using the repository browser.