[206] | 1 | #include "stdafx.h"
|
---|
| 2 |
|
---|
[3] | 3 | #include "../BasicCompiler_Common/common.h"
|
---|
| 4 | #include "Opcode.h"
|
---|
| 5 |
|
---|
| 6 | BOOL CalcTwoTerm_Logical(int idCalc,int *type,LONG_PTR *index_stack,int *pStackPointer){
|
---|
| 7 | //value[sp-2] xor= value[sp-1]
|
---|
| 8 | //xor演算
|
---|
| 9 |
|
---|
| 10 | int sp;
|
---|
| 11 | sp=*pStackPointer;
|
---|
| 12 |
|
---|
| 13 | if(IsRealNumberType(type[sp-2])||IsRealNumberType(type[sp-1])){
|
---|
| 14 | //いずれかの項が実数のとき
|
---|
| 15 | SetError(45,"xor",cp);
|
---|
| 16 | return 0;
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | int reg1,reg2;
|
---|
| 20 |
|
---|
| 21 | if(Is64Type(type[sp-2])||Is64Type(type[sp-1])){
|
---|
| 22 | //////////////////////
|
---|
| 23 | // 64ビット整数演算
|
---|
| 24 | //////////////////////
|
---|
| 25 |
|
---|
| 26 | SetTowTermToReg_Whole64Calc(type,sp,®1,®2);
|
---|
| 27 |
|
---|
| 28 | if(idCalc==CALC_XOR){
|
---|
| 29 | //xor reg1,reg2
|
---|
| 30 | op_xor_reg(sizeof(_int64),reg1,reg2);
|
---|
| 31 | }
|
---|
| 32 | else if(idCalc==CALC_OR){
|
---|
| 33 | //or reg1,reg2
|
---|
| 34 | op_or_reg(sizeof(_int64),reg1,reg2);
|
---|
| 35 | }
|
---|
| 36 | else if(idCalc==CALC_AND){
|
---|
| 37 | //and reg1,reg2
|
---|
| 38 | op_and_reg(sizeof(_int64),reg1,reg2);
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | if(reg1==REG_R14){
|
---|
| 42 | //mov qword ptr[rsp+offset],r14 ※スタックフレームを利用
|
---|
| 43 | pobj_sf->push(REG_R14);
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | sp--;
|
---|
| 47 | type[sp-1]=NeutralizationType(type[sp-1],index_stack[sp-1],type[sp],index_stack[sp]);
|
---|
| 48 | }
|
---|
| 49 | else{
|
---|
| 50 | //32ビット以下の整数演算
|
---|
| 51 |
|
---|
| 52 | SetTowTermToReg_Whole32Calc(type,sp,®1,®2);
|
---|
| 53 |
|
---|
| 54 | if(idCalc==CALC_ADDITION){
|
---|
| 55 | //add reg1,reg2
|
---|
| 56 | op_xor_reg(sizeof(long),reg1,reg2);
|
---|
| 57 | }
|
---|
| 58 | else if(idCalc==CALC_OR){
|
---|
| 59 | //or reg1,reg2
|
---|
| 60 | op_or_reg(sizeof(long),reg1,reg2);
|
---|
| 61 | }
|
---|
| 62 | else if(idCalc==CALC_AND){
|
---|
| 63 | //and reg1,reg2
|
---|
| 64 | op_and_reg(sizeof(long),reg1,reg2);
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | if(reg1==REG_R14){
|
---|
| 68 | //mov qword ptr[rsp+offset],r14 ※スタックフレームを利用
|
---|
| 69 | pobj_sf->push(REG_R14);
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | sp--;
|
---|
| 73 | type[sp-1]=NeutralizationType(type[sp-1],index_stack[sp-1],type[sp],index_stack[sp]);
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | *pStackPointer=sp;
|
---|
| 77 | return 1;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | BOOL Calc_Not(int *type,int sp){
|
---|
| 81 | //value[sp-1]=Not value[sp-1]
|
---|
| 82 | //NOT演算子
|
---|
| 83 |
|
---|
| 84 | if(IsRealNumberType(type[sp-1])){
|
---|
| 85 | //実数のとき
|
---|
| 86 | SetError(45,"Not",cp);
|
---|
| 87 | return 0;
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | int reg;
|
---|
| 91 |
|
---|
[36] | 92 | if( type[sp - 1] == DEF_BOOLEAN ){
|
---|
| 93 | SetOneTermToReg_Whole32Calc(type[sp-1],®);
|
---|
| 94 |
|
---|
| 95 | if( reg != REG_RAX ){
|
---|
| 96 | //mov rax,qword ptr[rsp+offset] ※スタックフレームを利用
|
---|
| 97 | pobj_sf->pop(REG_RAX);
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | //cmp reg,0
|
---|
| 101 | op_cmp_value(GetTypeSize(type[sp-1],-1),reg,0);
|
---|
| 102 |
|
---|
| 103 | //setne al
|
---|
| 104 | op_setne( REG_RAX );
|
---|
| 105 |
|
---|
| 106 | //and rax,000000FFh
|
---|
| 107 | op_and64_value(REG_RAX,(int)0xFF);
|
---|
| 108 |
|
---|
| 109 | //neg
|
---|
| 110 | op_neg( REG_RAX );
|
---|
| 111 |
|
---|
| 112 | //sbb rax, rax
|
---|
| 113 | op_sbb_RR( sizeof(_int64), REG_RAX, REG_RAX );
|
---|
| 114 |
|
---|
| 115 | //add rax, 1
|
---|
[64] | 116 | op_add_RV( REG_RAX, 1 );
|
---|
[36] | 117 |
|
---|
| 118 | if( reg != REG_RAX ){
|
---|
| 119 | //mov reg,rax
|
---|
| 120 | op_mov_RR( reg, REG_RAX );
|
---|
| 121 |
|
---|
| 122 | //mov qword ptr[rsp+offset],rax ※スタックフレームを利用
|
---|
| 123 | pobj_sf->push(REG_RAX);
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | if(reg==REG_R14){
|
---|
| 127 | //mov qword ptr[rsp+offset],r14 ※スタックフレームを利用
|
---|
| 128 | pobj_sf->push(REG_R14);
|
---|
| 129 | }
|
---|
| 130 | }
|
---|
| 131 | else if(type[sp-1]==DEF_INT64||type[sp-1]==DEF_QWORD){
|
---|
[3] | 132 | SetOneTermToReg_Whole64Calc(type[sp-1],®);
|
---|
| 133 |
|
---|
| 134 | //not reg
|
---|
| 135 | op_not_reg(sizeof(_int64),reg);
|
---|
| 136 |
|
---|
| 137 | if(reg==REG_R14){
|
---|
| 138 | //mov qword ptr[rsp+offset],r14 ※スタックフレームを利用
|
---|
| 139 | pobj_sf->push(REG_R14);
|
---|
| 140 | }
|
---|
| 141 | }
|
---|
| 142 | else if(IsWholeNumberType(type[sp-1])){
|
---|
| 143 | SetOneTermToReg_Whole32Calc(type[sp-1],®);
|
---|
| 144 |
|
---|
| 145 | //not reg
|
---|
| 146 | op_not_reg(sizeof(long),reg);
|
---|
| 147 |
|
---|
| 148 | if(reg==REG_R14){
|
---|
| 149 | //mov qword ptr[rsp+offset],r14 ※スタックフレームを利用
|
---|
| 150 | pobj_sf->push(REG_R14);
|
---|
| 151 | }
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | return 1;
|
---|
| 155 | }
|
---|