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

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