Add Lowlevel::Or

This commit is contained in:
Ahmad Sattar 2023-02-16 21:06:21 +01:00
parent f8b0a99e6d
commit 214ee6ed8e
No known key found for this signature in database
GPG key ID: 457C18819D9C9570
3 changed files with 41 additions and 0 deletions

View file

@ -1148,6 +1148,22 @@ impl<
}
}
fn build_or(&mut self, dst: &Symbol, src1: &Symbol, src2: &Symbol, arg_layout: &InLayout<'a>) {
match *arg_layout {
Layout::BOOL => {
let dst_reg = self.storage_manager.claim_general_reg(&mut self.buf, dst);
let src1_reg = self
.storage_manager
.load_to_general_reg(&mut self.buf, src1);
let src2_reg = self
.storage_manager
.load_to_general_reg(&mut self.buf, src2);
ASM::or_reg64_reg64_reg64(&mut self.buf, dst_reg, src1_reg, src2_reg);
}
x => todo!("Or: layout, {:?}", x),
}
}
fn build_num_lt(
&mut self,
dst: &Symbol,

View file

@ -636,6 +636,19 @@ trait Backend<'a> {
);
self.build_and(sym, &args[0], &args[1], &arg_layouts[0])
}
LowLevel::Or => {
debug_assert_eq!(2, args.len(), "Or: expected to have exactly two argument");
debug_assert_eq!(
arg_layouts[0], arg_layouts[1],
"Or: expected all arguments of to have the same layout"
);
debug_assert_eq!(
Layout::BOOL,
*ret_layout,
"Or: expected to have return layout of type Bool"
);
self.build_or(sym, &args[0], &args[1], &arg_layouts[0])
}
LowLevel::NumLt => {
debug_assert_eq!(
2,
@ -1032,6 +1045,9 @@ trait Backend<'a> {
/// build_and stores the result of `src1 && src2` into dst.
fn build_and(&mut self, dst: &Symbol, src1: &Symbol, src2: &Symbol, arg_layout: &InLayout<'a>);
/// build_or stores the result of `src1 || src2` into dst.
fn build_or(&mut self, dst: &Symbol, src1: &Symbol, src2: &Symbol, arg_layout: &InLayout<'a>);
/// build_num_lt stores the result of `src1 < src2` into dst.
fn build_num_lt(
&mut self,

View file

@ -120,6 +120,15 @@ fn and_bool() {
assert_evals_to!("Bool.false && Bool.false", false, bool);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn or_bool() {
assert_evals_to!("Bool.true || Bool.true", true, bool);
assert_evals_to!("Bool.true || Bool.false", true, bool);
assert_evals_to!("Bool.false || Bool.true", true, bool);
assert_evals_to!("Bool.false || Bool.false", false, bool);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn empty_record() {