source: dev/trunk/abdev/BasicCompiler64/NumOpe_Logical.cpp@ 308

Last change on this file since 308 was 308, checked in by dai_9181, 17 years ago

静的リンクライブラリにより、複数のグローバル領域が存在することになったのでそれぞれを関数ベースに分けた

File size: 3.6 KB
Line 
1#include "stdafx.h"
2
3#include <Compiler.h>
4
5#include "../BasicCompiler_Common/common.h"
6#include "Opcode.h"
7
8BOOL 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 SetError(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,&reg1,&reg2);
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
43 if(reg1==REG_R14){
44 //mov qword ptr[rsp+offset],r14 ※スタックフレームを利用
45 pobj_sf->push(REG_R14);
46 }
47
48 sp--;
49 type[sp-1]=NeutralizationType(type[sp-1],index_stack[sp-1],type[sp],index_stack[sp]);
50 }
51 else{
52 //32ビット以下の整数演算
53
54 SetTowTermToReg_Whole32Calc(type,sp,&reg1,&reg2);
55
56 if(idCalc==CALC_ADDITION){
57 //add reg1,reg2
58 compiler.codeGenerator.op_xor_reg(sizeof(long),reg1,reg2);
59 }
60 else if(idCalc==CALC_OR){
61 //or reg1,reg2
62 compiler.codeGenerator.op_or_reg(sizeof(long),reg1,reg2);
63 }
64 else if(idCalc==CALC_AND){
65 //and reg1,reg2
66 compiler.codeGenerator.op_and_reg(sizeof(long),reg1,reg2);
67 }
68
69 if(reg1==REG_R14){
70 //mov qword ptr[rsp+offset],r14 ※スタックフレームを利用
71 pobj_sf->push(REG_R14);
72 }
73
74 sp--;
75 type[sp-1]=NeutralizationType(type[sp-1],index_stack[sp-1],type[sp],index_stack[sp]);
76 }
77
78 *pStackPointer=sp;
79 return 1;
80}
81
82BOOL Calc_Not(int *type,int sp){
83 //value[sp-1]=Not value[sp-1]
84 //NOT演算子
85
86 if(IsRealNumberType(type[sp-1])){
87 //実数のとき
88 SetError(45,"Not",cp);
89 return 0;
90 }
91
92 int reg;
93
94 if( type[sp - 1] == DEF_BOOLEAN ){
95 SetOneTermToReg_Whole32Calc(type[sp-1],&reg);
96
97 if( reg != REG_RAX ){
98 //mov rax,qword ptr[rsp+offset] ※スタックフレームを利用
99 pobj_sf->pop(REG_RAX);
100 }
101
102 //cmp reg,0
103 compiler.codeGenerator.op_cmp_value(Type(type[sp-1]).GetSize(),reg,0);
104
105 //setne al
106 compiler.codeGenerator.op_setne( REG_RAX );
107
108 //and rax,000000FFh
109 compiler.codeGenerator.op_and64_value(REG_RAX,(int)0xFF);
110
111 //neg
112 compiler.codeGenerator.op_neg( REG_RAX );
113
114 //sbb rax, rax
115 compiler.codeGenerator.op_sbb_RR( sizeof(_int64), REG_RAX, REG_RAX );
116
117 //add rax, 1
118 compiler.codeGenerator.op_add_RV( REG_RAX, 1 );
119
120 if( reg != REG_RAX ){
121 //mov reg,rax
122 compiler.codeGenerator.op_mov_RR( reg, REG_RAX );
123
124 //mov qword ptr[rsp+offset],rax ※スタックフレームを利用
125 pobj_sf->push(REG_RAX);
126 }
127
128 if(reg==REG_R14){
129 //mov qword ptr[rsp+offset],r14 ※スタックフレームを利用
130 pobj_sf->push(REG_R14);
131 }
132 }
133 else if(type[sp-1]==DEF_INT64||type[sp-1]==DEF_QWORD){
134 SetOneTermToReg_Whole64Calc(type[sp-1],&reg);
135
136 //not reg
137 compiler.codeGenerator.op_not_reg(sizeof(_int64),reg);
138
139 if(reg==REG_R14){
140 //mov qword ptr[rsp+offset],r14 ※スタックフレームを利用
141 pobj_sf->push(REG_R14);
142 }
143 }
144 else if(IsWholeNumberType(type[sp-1])){
145 SetOneTermToReg_Whole32Calc(type[sp-1],&reg);
146
147 //not reg
148 compiler.codeGenerator.op_not_reg(sizeof(long),reg);
149
150 if(reg==REG_R14){
151 //mov qword ptr[rsp+offset],r14 ※スタックフレームを利用
152 pobj_sf->push(REG_R14);
153 }
154 }
155
156 return 1;
157}
Note: See TracBrowser for help on using the repository browser.