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