source: dev/trunk/abdev/BasicCompiler64/increment.cpp@ 210

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

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

File size: 3.8 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 //変数オフセットを一時退避
20 if(IsUse_r11(&VarRelativeVar)){
21 //mov qword ptr[rsp+offset],r11 ※スタックフレームを利用
22 pobj_sf->push(REG_R11);
23 }
24
25
26 ///////////////////////////////////
27 // レジスタへ変数の内容をコピー
28 ///////////////////////////////////
29
30 int reg;
31 if( varType.IsDouble() ){
32 reg=REG_XMM0;
33 SetXmmReg_DoubleVariable(&VarRelativeVar,reg);
34 }
35 else if( varType.IsSingle() ){
36 reg=REG_XMM0;
37 SetXmmReg_SingleVariable(&VarRelativeVar,reg);
38 }
39 else{
40 reg=REG_RAX;
41 SetReg_WholeVariable(varType.GetBasicType(),&VarRelativeVar,reg);
42 }
43
44
45 if(varType.IsWhole()&&lstrcmp(lpszRight,"1")==0&&
46 (idCalc==CALC_ADDITION||idCalc==CALC_SUBTRACTION)){
47 if(idCalc==CALC_ADDITION){
48 //インクリメント
49 op_inc(REG_RAX);
50 }
51 else if(idCalc==CALC_SUBTRACTION){
52 //デクリメント
53 op_dec(REG_RAX);
54 }
55 }
56 else{
57 //結果を格納しているレジスタをブロッキング
58 pobj_BlockReg->lock(reg);
59
60 //右辺を計算
61 Type calcType;
62 if(reg==REG_RAX) reg=REG_RCX;
63 else reg=REG_RAX;
64 NumOpe(&reg,lpszRight,varType,calcType);
65
66 //レジスタのブロッキングを解除
67 pobj_BlockReg->clear();
68
69
70 if(varType.IsPointer()&&calcType.IsWhole()&&(!calcType.IsPointer())){
71 //左辺がポインタ型、右辺が整数型の場合は、エラーをださないようにする
72 calcType = varType;
73 }
74
75
76 /////////////////////////////////
77 // 右辺、左辺の型チェックを行う
78 /////////////////////////////////
79
80 CheckDifferentType(varType,calcType,0,0);
81
82
83 //レジスタ管理オブジェクトを生成
84 pobj_reg=new CRegister(REG_RAX);
85
86 //左辺用レジスタ
87 if(varType.IsReal())
88 pobj_reg->LockXmmReg();
89 else
90 pobj_reg->LockReg();
91
92 //右辺値レジスタ
93 if(varType.IsDouble())
94 ChangeTypeToXmm_Double(calcType.GetBasicType(),
95 pobj_reg->LockXmmReg(),
96 pobj_reg->GetNextReg());
97 else if(varType.IsSingle())
98 ChangeTypeToXmm_Single(calcType.GetBasicType(),
99 pobj_reg->LockXmmReg(),
100 pobj_reg->GetNextReg());
101 else
102 ChangeTypeToWhole(calcType.GetBasicType(),varType.GetBasicType(),
103 pobj_reg->LockReg(),
104 pobj_reg->GetNextXmmReg());
105
106 int type_stack[255],sp;
107 LONG_PTR index_stack[255];
108 type_stack[0]=varType.GetBasicType();
109 type_stack[1]=varType.GetBasicType();
110 index_stack[0]=varType.GetIndex();
111 index_stack[1]=varType.GetIndex();
112 sp=2;
113
114 switch(idCalc){
115 case CALC_XOR:
116 case CALC_OR:
117 case CALC_AND:
118 CalcTwoTerm_Logical(idCalc,type_stack,index_stack,&sp);
119 break;
120 case CALC_SHL:
121 case CALC_SHR:
122 Calc_Shift(idCalc,type_stack,&sp);
123 break;
124 case CALC_ADDITION:
125 case CALC_SUBTRACTION:
126 case CALC_PRODUCT:
127 CalcTwoTerm_Arithmetic(idCalc,type_stack,index_stack,&sp);
128 break;
129 case CALC_MOD:
130 Calc_Mod(type_stack,index_stack,&sp);
131 break;
132 case CALC_QUOTIENT:
133 Calc_Divide(type_stack,&sp,varType.GetBasicType());
134 break;
135 case CALC_INTQUOTIENT:
136 Calc_IntDivide(type_stack,index_stack,&sp);
137 break;
138 case CALC_POWER:
139 Calc_Power(type_stack,&sp);
140 break;
141 }
142
143 //レジスタ管理オブジェクトを解放
144 delete pobj_reg;
145 pobj_reg=0;
146 }
147
148
149 /////////////////////////////////////////////////
150 // rax(実数はxmm0)の内容を変数にコピー
151 /////////////////////////////////////////////////
152
153 //変数オフセットを復元
154 if(IsUse_r11(&VarRelativeVar)){
155 //mov r11,qword ptr[rsp+offset] ※スタックフレームを利用
156 pobj_sf->pop(REG_R11);
157 }
158
159 SetVariableFromRax(varType.GetBasicType(),varType.GetBasicType(),&VarRelativeVar);
160}
Note: See TracBrowser for help on using the repository browser.