duskphantom_middle/ir/instruction/
binary_inst.rs

1// Copyright 2024 Duskphantom Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// SPDX-License-Identifier: Apache-2.0
16
17use super::*;
18use crate::impl_binary_inst;
19use ValueType::{Bool, Float, Int};
20
21/// impl for binary operation and bitwise binary_inst
22pub trait BinaryInst {
23    fn get_lhs(&self) -> &Operand;
24    fn set_lhs(&mut self, lhs: Operand);
25    fn get_rhs(&self) -> &Operand;
26    fn set_rhs(&mut self, rhs: Operand);
27}
28
29impl_binary_inst!(Add, "i32", get_add, lhs, rhs, Int);
30impl_binary_inst!(FAdd, "float", get_fadd, lhs, rhs, Float);
31impl_binary_inst!(Sub, "i32", get_sub, lhs, rhs, Int);
32impl_binary_inst!(FSub, "float", get_fsub, lhs, rhs, Float);
33impl_binary_inst!(Mul, "i32", get_mul, lhs, rhs, Int);
34impl_binary_inst!(FMul, "float", get_fmul, lhs, rhs, Float);
35impl_binary_inst!(UDiv, "i32", get_udiv, lhs, rhs, Int);
36impl_binary_inst!(SDiv, "i32", get_sdiv, lhs, rhs, Int);
37impl_binary_inst!(FDiv, "float", get_fdiv, lhs, rhs, Float);
38impl_binary_inst!(URem, "i32", get_urem, lhs, rhs, Int);
39impl_binary_inst!(SRem, "i32", get_srem, lhs, rhs, Int);
40impl_binary_inst!(Shl, "i32", get_shl, value, shiftamt, Int);
41impl_binary_inst!(LShr, "i32", get_lshr, value, shiftamt, Int);
42impl_binary_inst!(AShr, "i32", get_ashr, value, shiftamt, Int);
43impl_binary_inst!(And, "i1", get_and, lhs, rhs, Bool);
44impl_binary_inst!(Or, "i1", get_or, lhs, rhs, Bool);
45impl_binary_inst!(Xor, "i1", get_xor, lhs, rhs, Bool);