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

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