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

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

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

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