source: dev/BasicCompiler32/increment.cpp@ 143

Last change on this file since 143 was 129, checked in by dai_9181, 17 years ago

_System_StartupProgramの呼び出し順序を変更。

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