source: dev/trunk/abdev/BasicCompiler32/increment.cpp@ 220

Last change on this file since 220 was 206, checked in by dai_9181, 17 years ago

コード全体のリファクタリングを実施

File size: 4.2 KB
Line 
1#include "stdafx.h"
2
3#include "../BasicCompiler_Common/common.h"
4#include "Opcode.h"
5
6void IncDec(int idCalc, const char *lpszLeft, const char *lpszRight){
7
8 ///////////////////////////
9 // 変数アドレスを取得
10 ///////////////////////////
11
12 RELATIVE_VAR VarRelativeVar;
13 Type varType;
14 if(!GetVarOffsetReadWrite(
15 lpszLeft,
16 &VarRelativeVar,
17 varType)) return;
18
19 if(IsUse_ecx(&VarRelativeVar)){
20 //push ecx
21 op_push(REG_ECX);
22 }
23
24
25 ///////////////////////////////////
26 // レジスタへ変数の内容をコピー
27 ///////////////////////////////////
28
29 if( varType.IsReal() ){
30 //実数
31 SetReg_RealVariable(varType.GetBasicType(),&VarRelativeVar);
32 }
33 else{
34 //整数
35 SetReg_WholeVariable(varType.GetBasicType(),&VarRelativeVar,REG_EAX);
36 }
37
38
39 if(varType.IsWhole()&&lstrcmp(lpszRight,"1")==0&&
40 (idCalc==CALC_ADDITION||idCalc==CALC_SUBTRACTION)){
41 ////////////////////////////////////////////
42 // 整数型のインクリメント・デクリメント
43 ////////////////////////////////////////////
44
45 if( varType.Is64() ){
46 if(idCalc==CALC_ADDITION){
47 //64ビット インクリメント
48
49 //add eax,1
50 op_add_RV8(REG_EAX,1);
51
52 //adc edx,0
53 op_adc_RV8(REG_EDX,0);
54 }
55 else if(idCalc==CALC_SUBTRACTION){
56 //64ビット デクリメント
57
58 //sub eax,1
59 op_sub_RV8(REG_EAX,1);
60
61 //sbb edx,0
62 op_sbb_RV8(REG_EDX,0);
63 }
64 }
65 else{
66 if(idCalc==CALC_ADDITION){
67 //インクリメント
68 op_inc(REG_EAX);
69 }
70 else if(idCalc==CALC_SUBTRACTION){
71 //デクリメント
72 op_dec(REG_EAX);
73 }
74 }
75 }
76 else{
77 //変数オフセットを一時退避
78 //push ecx
79 op_push(REG_ECX);
80
81 if( varType.IsDouble() ){
82 //sub esp,8
83 op_sub_esp(8);
84
85 //fstp qword ptr[esp]
86 op_fstp_basereg(varType.GetBasicType(),REG_ESP);
87 }
88 else if( varType.IsSingle() ){
89 //sub esp,4
90 op_sub_esp(4);
91
92 //fstp dword ptr[esp]
93 op_fstp_basereg(varType.GetBasicType(),REG_ESP);
94 }
95 else if( varType.Is64() ){
96 //push edx
97 op_push(REG_EDX);
98
99 //push eax
100 op_push(REG_EAX);
101 }
102 else{
103 //push eax
104 op_push(REG_EAX);
105 }
106
107 Type calcType;
108 if( !NumOpe(lpszRight,varType,calcType) ){
109 return;
110 }
111
112 if( varType.IsDouble() ) ChangeTypeToDouble(calcType.GetBasicType());
113 else if( varType.IsSingle() ) ChangeTypeToSingle(calcType.GetBasicType());
114 else ChangeTypeToWhole(calcType.GetBasicType(),varType.GetBasicType());
115
116 int type_stack[255],sp;
117 LONG_PTR index_stack[255];
118 type_stack[0]=varType.GetBasicType();
119 type_stack[1]=varType.GetBasicType();
120 index_stack[0]=varType.GetIndex();
121 index_stack[1]=varType.GetIndex();
122 sp=2;
123
124 switch(idCalc){
125 case CALC_XOR:
126 Calc_Xor(type_stack,index_stack,&sp);
127 break;
128 case CALC_OR:
129 Calc_Or(type_stack,index_stack,&sp);
130 break;
131 case CALC_AND:
132 Calc_And(type_stack,index_stack,&sp);
133 break;
134 case CALC_SHL:
135 Calc_SHL(type_stack,&sp);
136 break;
137 case CALC_SHR:
138 Calc_SHR(type_stack,&sp);
139 break;
140 case CALC_ADDITION:
141 case CALC_SUBTRACTION:
142 case CALC_PRODUCT:
143 CalcTwoTerm_Arithmetic(idCalc,type_stack,index_stack,&sp);
144 break;
145 case CALC_MOD:
146 Calc_Mod(type_stack,&sp);
147 break;
148 case CALC_QUOTIENT:
149 Calc_Divide(type_stack,&sp,varType.GetBasicType());
150 break;
151 case CALC_INTQUOTIENT:
152 Calc_IntDivide(type_stack,index_stack,&sp);
153 break;
154 case CALC_POWER:
155 Calc_Power(type_stack,&sp);
156 break;
157 }
158
159
160 if( varType.IsDouble() ){
161 //fld qword ptr[esp]
162 op_fld_basereg(varType.GetBasicType(),REG_ESP);
163
164 //add esp,8
165 op_add_esp(8);
166 }
167 else if( varType.IsSingle() ){
168 //fld dword ptr[esp]
169 op_fld_basereg(varType.GetBasicType(),REG_ESP);
170
171 //add esp,4
172 op_add_esp(4);
173 }
174 else if( varType.Is64() ){
175 //pop eax
176 op_pop(REG_EAX);
177
178 //pop edx
179 op_pop(REG_EDX);
180 }
181 else{
182 //pop eax
183 op_pop(REG_EAX);
184 }
185
186
187 //変数オフセットを復元
188 //pop ecx
189 op_pop(REG_ECX);
190 }
191
192
193 /////////////////////////////////////////////////
194 // レジスタの内容を変数にコピー
195 /////////////////////////////////////////////////
196
197 if(IsUse_ecx(&VarRelativeVar)){
198 //pop ecx
199 op_pop(REG_ECX);
200 }
201
202 SetVariableFromEax(varType.GetBasicType(),varType.GetBasicType(),&VarRelativeVar);
203}
Note: See TracBrowser for help on using the repository browser.