| 1 | #include "stdafx.h"
|
|---|
| 2 |
|
|---|
| 3 | #include <Compiler.h>
|
|---|
| 4 |
|
|---|
| 5 | #include "../BasicCompiler_Common/common.h"
|
|---|
| 6 | #include "Opcode.h"
|
|---|
| 7 |
|
|---|
| 8 | void 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 | if(IsUse_ecx(&VarRelativeVar)){
|
|---|
| 22 | //push ecx
|
|---|
| 23 | compiler.codeGenerator.op_push(REG_ECX);
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 | ///////////////////////////////////
|
|---|
| 28 | // レジスタへ変数の内容をコピー
|
|---|
| 29 | ///////////////////////////////////
|
|---|
| 30 |
|
|---|
| 31 | if( varType.IsReal() ){
|
|---|
| 32 | //実数
|
|---|
| 33 | SetReg_RealVariable(varType.GetBasicType(),&VarRelativeVar);
|
|---|
| 34 | }
|
|---|
| 35 | else{
|
|---|
| 36 | //整数
|
|---|
| 37 | SetReg_WholeVariable(varType,&VarRelativeVar,REG_EAX);
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 | if(varType.IsWhole()&&lstrcmp(lpszRight,"1")==0&&
|
|---|
| 42 | (idCalc==CALC_ADDITION||idCalc==CALC_SUBTRACTION)){
|
|---|
| 43 | ////////////////////////////////////////////
|
|---|
| 44 | // 整数型のインクリメント・デクリメント
|
|---|
| 45 | ////////////////////////////////////////////
|
|---|
| 46 |
|
|---|
| 47 | if( varType.Is64() ){
|
|---|
| 48 | if(idCalc==CALC_ADDITION){
|
|---|
| 49 | //64ビット インクリメント
|
|---|
| 50 |
|
|---|
| 51 | //add eax,1
|
|---|
| 52 | compiler.codeGenerator.op_add_RV8(REG_EAX,1);
|
|---|
| 53 |
|
|---|
| 54 | //adc edx,0
|
|---|
| 55 | compiler.codeGenerator.op_adc_RV8(REG_EDX,0);
|
|---|
| 56 | }
|
|---|
| 57 | else if(idCalc==CALC_SUBTRACTION){
|
|---|
| 58 | //64ビット デクリメント
|
|---|
| 59 |
|
|---|
| 60 | //sub eax,1
|
|---|
| 61 | compiler.codeGenerator.op_sub_RV8(REG_EAX,1);
|
|---|
| 62 |
|
|---|
| 63 | //sbb edx,0
|
|---|
| 64 | compiler.codeGenerator.op_sbb_RV8(REG_EDX,0);
|
|---|
| 65 | }
|
|---|
| 66 | }
|
|---|
| 67 | else{
|
|---|
| 68 | if(idCalc==CALC_ADDITION){
|
|---|
| 69 | //インクリメント
|
|---|
| 70 | compiler.codeGenerator.op_inc(REG_EAX);
|
|---|
| 71 | }
|
|---|
| 72 | else if(idCalc==CALC_SUBTRACTION){
|
|---|
| 73 | //デクリメント
|
|---|
| 74 | compiler.codeGenerator.op_dec(REG_EAX);
|
|---|
| 75 | }
|
|---|
| 76 | }
|
|---|
| 77 | }
|
|---|
| 78 | else{
|
|---|
| 79 | //変数オフセットを一時退避
|
|---|
| 80 | //push ecx
|
|---|
| 81 | compiler.codeGenerator.op_push(REG_ECX);
|
|---|
| 82 |
|
|---|
| 83 | if( varType.IsDouble() ){
|
|---|
| 84 | //sub esp,8
|
|---|
| 85 | compiler.codeGenerator.op_sub_esp(8);
|
|---|
| 86 |
|
|---|
| 87 | //fstp qword ptr[esp]
|
|---|
| 88 | compiler.codeGenerator.op_fstp_basereg(varType.GetBasicType(),REG_ESP);
|
|---|
| 89 | }
|
|---|
| 90 | else if( varType.IsSingle() ){
|
|---|
| 91 | //sub esp,4
|
|---|
| 92 | compiler.codeGenerator.op_sub_esp(4);
|
|---|
| 93 |
|
|---|
| 94 | //fstp dword ptr[esp]
|
|---|
| 95 | compiler.codeGenerator.op_fstp_basereg(varType.GetBasicType(),REG_ESP);
|
|---|
| 96 | }
|
|---|
| 97 | else if( varType.Is64() ){
|
|---|
| 98 | //push edx
|
|---|
| 99 | compiler.codeGenerator.op_push(REG_EDX);
|
|---|
| 100 |
|
|---|
| 101 | //push eax
|
|---|
| 102 | compiler.codeGenerator.op_push(REG_EAX);
|
|---|
| 103 | }
|
|---|
| 104 | else{
|
|---|
| 105 | //push eax
|
|---|
| 106 | compiler.codeGenerator.op_push(REG_EAX);
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | Type calcType;
|
|---|
| 110 | if( !NumOpe(lpszRight,varType,calcType) ){
|
|---|
| 111 | return;
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | if( varType.IsDouble() ) ChangeTypeToDouble(calcType.GetBasicType());
|
|---|
| 115 | else if( varType.IsSingle() ) ChangeTypeToSingle(calcType.GetBasicType());
|
|---|
| 116 | else ChangeTypeToWhole( calcType, varType );
|
|---|
| 117 |
|
|---|
| 118 | int type_stack[255],sp;
|
|---|
| 119 | LONG_PTR index_stack[255];
|
|---|
| 120 | type_stack[0]=varType.GetBasicType();
|
|---|
| 121 | type_stack[1]=varType.GetBasicType();
|
|---|
| 122 | index_stack[0]=varType.GetIndex();
|
|---|
| 123 | index_stack[1]=varType.GetIndex();
|
|---|
| 124 | sp=2;
|
|---|
| 125 |
|
|---|
| 126 | switch(idCalc){
|
|---|
| 127 | case CALC_XOR:
|
|---|
| 128 | Calc_Xor(type_stack,index_stack,&sp);
|
|---|
| 129 | break;
|
|---|
| 130 | case CALC_OR:
|
|---|
| 131 | Calc_Or(type_stack,index_stack,&sp);
|
|---|
| 132 | break;
|
|---|
| 133 | case CALC_AND:
|
|---|
| 134 | Calc_And(type_stack,index_stack,&sp);
|
|---|
| 135 | break;
|
|---|
| 136 | case CALC_SHL:
|
|---|
| 137 | Calc_SHL(type_stack,&sp);
|
|---|
| 138 | break;
|
|---|
| 139 | case CALC_SHR:
|
|---|
| 140 | Calc_SHR(type_stack,&sp);
|
|---|
| 141 | break;
|
|---|
| 142 | case CALC_ADDITION:
|
|---|
| 143 | case CALC_SUBTRACTION:
|
|---|
| 144 | case CALC_PRODUCT:
|
|---|
| 145 | CalcTwoTerm_Arithmetic(idCalc,type_stack,index_stack,&sp);
|
|---|
| 146 | break;
|
|---|
| 147 | case CALC_MOD:
|
|---|
| 148 | Calc_Mod(type_stack,&sp);
|
|---|
| 149 | break;
|
|---|
| 150 | case CALC_QUOTIENT:
|
|---|
| 151 | Calc_Divide(type_stack,&sp,varType.GetBasicType());
|
|---|
| 152 | break;
|
|---|
| 153 | case CALC_INTQUOTIENT:
|
|---|
| 154 | Calc_IntDivide(type_stack,index_stack,&sp);
|
|---|
| 155 | break;
|
|---|
| 156 | case CALC_POWER:
|
|---|
| 157 | Calc_Power(type_stack,&sp);
|
|---|
| 158 | break;
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 | if( varType.IsDouble() ){
|
|---|
| 163 | //fld qword ptr[esp]
|
|---|
| 164 | compiler.codeGenerator.op_fld_basereg(varType.GetBasicType(),REG_ESP);
|
|---|
| 165 |
|
|---|
| 166 | //add esp,8
|
|---|
| 167 | compiler.codeGenerator.op_add_esp(8);
|
|---|
| 168 | }
|
|---|
| 169 | else if( varType.IsSingle() ){
|
|---|
| 170 | //fld dword ptr[esp]
|
|---|
| 171 | compiler.codeGenerator.op_fld_basereg(varType.GetBasicType(),REG_ESP);
|
|---|
| 172 |
|
|---|
| 173 | //add esp,4
|
|---|
| 174 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 175 | }
|
|---|
| 176 | else if( varType.Is64() ){
|
|---|
| 177 | //pop eax
|
|---|
| 178 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 179 |
|
|---|
| 180 | //pop edx
|
|---|
| 181 | compiler.codeGenerator.op_pop(REG_EDX);
|
|---|
| 182 | }
|
|---|
| 183 | else{
|
|---|
| 184 | //pop eax
|
|---|
| 185 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 | //変数オフセットを復元
|
|---|
| 190 | //pop ecx
|
|---|
| 191 | compiler.codeGenerator.op_pop(REG_ECX);
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 | /////////////////////////////////////////////////
|
|---|
| 196 | // レジスタの内容を変数にコピー
|
|---|
| 197 | /////////////////////////////////////////////////
|
|---|
| 198 |
|
|---|
| 199 | if(IsUse_ecx(&VarRelativeVar)){
|
|---|
| 200 | //pop ecx
|
|---|
| 201 | compiler.codeGenerator.op_pop(REG_ECX);
|
|---|
| 202 | }
|
|---|
| 203 |
|
|---|
| 204 | SetVariableFromEax(varType,varType.GetBasicType(),&VarRelativeVar);
|
|---|
| 205 | }
|
|---|