Skip to content

Commit

Permalink
tested and fixed Boolean function decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
SJulianS committed Nov 30, 2022
1 parent 7ea5514 commit 73b8355
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/netlist/decorators/boolean_function_decorator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ namespace hal
return ERR("could not concatenate nets: nets contain a 'nullptr'.");
}

if (auto res = BooleanFunction::Concat(BooleanFunction::Var(BooleanFunctionNetDecorator(*(nets.at(i))).get_boolean_variable_name(), 1), var.clone(), i + 1); res.is_error())
if (auto res = BooleanFunction::Concat(var.clone(), BooleanFunction::Var(BooleanFunctionNetDecorator(*(nets.at(i))).get_boolean_variable_name(), 1), i + 1); res.is_ok())
{
var = res.get();
}
Expand All @@ -90,7 +90,7 @@ namespace hal
{
if (sign_extend == false)
{
if (auto res = BooleanFunction::Zext(var.clone(), BooleanFunction::Index(extend_to_size, extend_to_size), extend_to_size); res.is_error())
if (auto res = BooleanFunction::Zext(var.clone(), BooleanFunction::Index(extend_to_size, extend_to_size), extend_to_size); res.is_ok())
{
var = res.get();
}
Expand All @@ -102,7 +102,7 @@ namespace hal
}
else
{
if (auto res = BooleanFunction::Sext(var.clone(), BooleanFunction::Index(extend_to_size, extend_to_size), extend_to_size); res.is_error())
if (auto res = BooleanFunction::Sext(var.clone(), BooleanFunction::Index(extend_to_size, extend_to_size), extend_to_size); res.is_ok())
{
var = res.get();
}
Expand Down Expand Up @@ -130,7 +130,7 @@ namespace hal
for (u32 i = 1; i < functions.size(); i++)
{
size += functions.at(i).size();
if (auto res = BooleanFunction::Concat(functions.at(i).clone(), var.clone(), size); res.is_error())
if (auto res = BooleanFunction::Concat(var.clone(), functions.at(i).clone(), size); res.is_ok())
{
var = res.get();
}
Expand All @@ -146,7 +146,7 @@ namespace hal
{
if (sign_extend == false)
{
if (auto res = BooleanFunction::Zext(var.clone(), BooleanFunction::Index(extend_to_size, extend_to_size), extend_to_size); res.is_error())
if (auto res = BooleanFunction::Zext(var.clone(), BooleanFunction::Index(extend_to_size, extend_to_size), extend_to_size); res.is_ok())
{
var = res.get();
}
Expand All @@ -158,7 +158,7 @@ namespace hal
}
else
{
if (auto res = BooleanFunction::Sext(var.clone(), BooleanFunction::Index(extend_to_size, extend_to_size), extend_to_size); res.is_error())
if (auto res = BooleanFunction::Sext(var.clone(), BooleanFunction::Index(extend_to_size, extend_to_size), extend_to_size); res.is_ok())
{
var = res.get();
}
Expand Down
50 changes: 49 additions & 1 deletion tests/netlist/decorators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace hal {
{
TEST_START
{
// test BooleanFunctionDecorator::substitute_power_ground_nets()
// test BooleanFunctionDecorator::substitute_power_ground_nets(const Netlist*)
std::unique_ptr<Netlist> nl_owner = test_utils::create_empty_netlist();
auto* nl = nl_owner.get();
ASSERT_NE(nl, nullptr);
Expand Down Expand Up @@ -71,6 +71,54 @@ namespace hal {
ASSERT_TRUE(subs_res.is_ok());
EXPECT_EQ(subs_res.get().get_variable_names(), std::set<std::string>({BooleanFunctionNetDecorator(*n0).get_boolean_variable_name(), BooleanFunctionNetDecorator(*n3).get_boolean_variable_name()}));
}
{
// test BooleanFunctionDecorator::get_boolean_function_from(const std::vector<Net*>&, u32, bool)
std::unique_ptr<Netlist> nl_owner = test_utils::create_empty_netlist();
auto* nl = nl_owner.get();
ASSERT_NE(nl, nullptr);
const auto* gl = nl->get_gate_library();

Net* n0 = nl->create_net(1, "n0");
ASSERT_NE(n0, nullptr);
Net* n1 = nl->create_net(2, "n1");
ASSERT_NE(n1, nullptr);
Net* n2 = nl->create_net(3, "n2");
ASSERT_NE(n2, nullptr);

auto bf_n0 = BooleanFunctionNetDecorator(*n0).get_boolean_variable();
auto bf_n1 = BooleanFunctionNetDecorator(*n1).get_boolean_variable();
auto bf_n2 = BooleanFunctionNetDecorator(*n2).get_boolean_variable();

auto bf_concat = BooleanFunctionDecorator::get_boolean_function_from({n0, n1, n2});
ASSERT_TRUE(bf_concat.is_ok());
EXPECT_EQ(bf_concat.get(), BooleanFunction::Concat(BooleanFunction::Concat(bf_n0.clone(), bf_n1.clone(), 2).get(), bf_n2.clone(), 3).get());

const auto bf_concat_zext = BooleanFunctionDecorator::get_boolean_function_from({n0, n1, n2}, 6, false);
ASSERT_TRUE(bf_concat_zext.is_ok());
EXPECT_EQ(bf_concat_zext.get(), BooleanFunction::Zext(BooleanFunction::Concat(BooleanFunction::Concat(bf_n0.clone(), bf_n1.clone(), 2).get(), bf_n2.clone(), 3).get(), BooleanFunction::Index(6, 6), 6).get());

const auto bf_concat_sext = BooleanFunctionDecorator::get_boolean_function_from({n0, n1, n2}, 6, true);
ASSERT_TRUE(bf_concat_sext.is_ok());
EXPECT_EQ(bf_concat_sext.get(), BooleanFunction::Sext(BooleanFunction::Concat(BooleanFunction::Concat(bf_n0.clone(), bf_n1.clone(), 2).get(), bf_n2.clone(), 3).get(), BooleanFunction::Index(6, 6), 6).get());
}
{
// test BooleanFunctionDecorator::get_boolean_function_from(const std::vector<BooleanFunction>&, u32, bool)
auto bf_a = BooleanFunction::Var("A", 1);
auto bf_b = BooleanFunction::Var("B", 1);
auto bf_c = BooleanFunction::Var("C", 1);

auto bf_concat = BooleanFunctionDecorator::get_boolean_function_from({bf_a, bf_b, bf_c});
ASSERT_TRUE(bf_concat.is_ok());
EXPECT_EQ(bf_concat.get(), BooleanFunction::Concat(BooleanFunction::Concat(bf_a.clone(), bf_b.clone(), 2).get(), bf_c.clone(), 3).get());

const auto bf_concat_zext = BooleanFunctionDecorator::get_boolean_function_from({bf_a, bf_b, bf_c}, 6, false);
ASSERT_TRUE(bf_concat_zext.is_ok());
EXPECT_EQ(bf_concat_zext.get(), BooleanFunction::Zext(BooleanFunction::Concat(BooleanFunction::Concat(bf_a.clone(), bf_b.clone(), 2).get(), bf_c.clone(), 3).get(), BooleanFunction::Index(6, 6), 6).get());

const auto bf_concat_sext = BooleanFunctionDecorator::get_boolean_function_from({bf_a, bf_b, bf_c}, 6, true);
ASSERT_TRUE(bf_concat_sext.is_ok());
EXPECT_EQ(bf_concat_sext.get(), BooleanFunction::Sext(BooleanFunction::Concat(BooleanFunction::Concat(bf_a.clone(), bf_b.clone(), 2).get(), bf_c.clone(), 3).get(), BooleanFunction::Index(6, 6), 6).get());
}
TEST_END
}
}

0 comments on commit 73b8355

Please sign in to comment.