source: dev/BasicCompiler32/increment.cpp@ 86

Last change on this file since 86 was 75, checked in by dai_9181, 18 years ago

TYPEINFO→Typeへのリファクタリングを実施。64bitはほぼ完了。32bitが全般的に未完成。

File size: 4.2 KB
RevLine 
[3]1#include "../BasicCompiler_Common/common.h"
2#include "Opcode.h"
3
4void IncDec(int idCalc, char *lpszLeft, char *lpszRight){
5
6 ///////////////////////////
7 // 変数アドレスを取得
8 ///////////////////////////
9
[75]10 RELATIVE_VAR VarRelativeVar;
11 Type varType;
[11]12 if(!GetVarOffsetReadWrite(
[3]13 lpszLeft,
14 &VarRelativeVar,
[75]15 varType)) return;
[3]16
17 if(IsUse_ecx(&VarRelativeVar)){
18 //push ecx
19 op_push(REG_ECX);
20 }
21
22
23 ///////////////////////////////////
24 // レジスタへ変数の内容をコピー
25 ///////////////////////////////////
26
[75]27 if( varType.IsReal() ){
[3]28 //実数
[75]29 SetReg_RealVariable(varType.GetBasicType(),&VarRelativeVar);
[3]30 }
31 else{
32 //整数
[75]33 SetReg_WholeVariable(varType.GetBasicType(),&VarRelativeVar,REG_EAX);
[3]34 }
35
36
[75]37 if(varType.IsWhole()&&lstrcmp(lpszRight,"1")==0&&
[3]38 (idCalc==CALC_ADDITION||idCalc==CALC_SUBTRACTION)){
39 ////////////////////////////////////////////
40 // 整数型のインクリメント・デクリメント
41 ////////////////////////////////////////////
42
[75]43 if( varType.Is64() ){
[3]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
[75]79 if( varType.IsDouble() ){
[3]80 //sub esp,8
81 op_sub_esp(8);
82
83 //fstp qword ptr[esp]
[75]84 op_fstp_basereg(varType.GetBasicType(),REG_ESP);
[3]85 }
[75]86 else if( varType.IsSingle() ){
[3]87 //sub esp,4
88 op_sub_esp(4);
89
90 //fstp dword ptr[esp]
[75]91 op_fstp_basereg(varType.GetBasicType(),REG_ESP);
[3]92 }
[75]93 else if( varType.Is64() ){
[3]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
[75]105 Type calcType;
106 if( !NumOpe(lpszRight,varType,calcType) ){
107 return;
108 }
[3]109
[75]110 if( varType.IsDouble() ) ChangeTypeToDouble(calcType.GetBasicType());
111 else if( varType.IsSingle() ) ChangeTypeToSingle(calcType.GetBasicType());
112 else ChangeTypeToWhole(calcType.GetBasicType(),varType.GetBasicType());
[3]113
[75]114 int type_stack[255],sp;
[3]115 LONG_PTR index_stack[255];
[75]116 type_stack[0]=varType.GetBasicType();
117 type_stack[1]=varType.GetBasicType();
118 index_stack[0]=varType.GetIndex();
119 index_stack[1]=varType.GetIndex();
[3]120 sp=2;
121
122 switch(idCalc){
123 case CALC_XOR:
[75]124 Calc_Xor(type_stack,index_stack,&sp);
[3]125 break;
126 case CALC_OR:
[75]127 Calc_Or(type_stack,index_stack,&sp);
[3]128 break;
129 case CALC_AND:
[75]130 Calc_And(type_stack,index_stack,&sp);
[3]131 break;
132 case CALC_SHL:
[75]133 Calc_SHL(type_stack,&sp);
[3]134 break;
135 case CALC_SHR:
[75]136 Calc_SHR(type_stack,&sp);
[3]137 break;
138 case CALC_ADDITION:
139 case CALC_SUBTRACTION:
140 case CALC_PRODUCT:
[75]141 CalcTwoTerm_Arithmetic(idCalc,type_stack,index_stack,&sp);
[3]142 break;
143 case CALC_MOD:
[75]144 Calc_Mod(type_stack,&sp);
[3]145 break;
146 case CALC_QUOTIENT:
[75]147 Calc_Divide(type_stack,&sp,varType.GetBasicType());
[3]148 break;
149 case CALC_INTQUOTIENT:
[75]150 Calc_IntDivide(type_stack,index_stack,&sp);
[3]151 break;
152 case CALC_POWER:
[75]153 Calc_Power(type_stack,&sp);
[3]154 break;
155 }
156
157
[75]158 if( varType.IsDouble() ){
[3]159 //fld qword ptr[esp]
[75]160 op_fld_basereg(varType.GetBasicType(),REG_ESP);
[3]161
162 //add esp,8
163 op_add_esp(8);
164 }
[75]165 else if( varType.IsSingle() ){
[3]166 //fld dword ptr[esp]
[75]167 op_fld_basereg(varType.GetBasicType(),REG_ESP);
[3]168
169 //add esp,4
170 op_add_esp(4);
171 }
[75]172 else if( varType.Is64() ){
[3]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
[75]200 SetVariableFromEax(varType.GetBasicType(),varType.GetBasicType(),&VarRelativeVar);
[3]201}
Note: See TracBrowser for help on using the repository browser.