Skip to content

Commit

Permalink
bug fixes to make tests run
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Klix committed Mar 15, 2024
1 parent fc353af commit 063ef8d
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 26 deletions.
9 changes: 9 additions & 0 deletions plugins/bitwuzla_utils/src/bitwuzla_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,15 @@ namespace hal
}
return OK(BooleanFunction::Var(name.value(), size));
}
else if (t.is_variable())
{
const auto name = t.symbol();
if (!name.has_value())
{
return ERR("cannot translate term to hal Boolean function: failed to extract symbol");
}
return OK(BooleanFunction::Var(name.value(), size));
}
}
// else
// {
Expand Down
1 change: 0 additions & 1 deletion plugins/xilinx_toolbox/src/preprocessing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ namespace hal
{
auto* o5 = g->get_fan_out_net("O5");
auto* o6 = g->get_fan_out_net("O6");
const auto* i5 = g->get_fan_in_net("I5");

const auto init_get_res = g->get_init_data();
if (init_get_res.is_error())
Expand Down
18 changes: 14 additions & 4 deletions src/netlist/decorators/netlist_modification_decorator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,19 @@ namespace hal
return ERR("cannot create a GND net: found multiple ground pins for gate type " + gnd_type->get_name() + ". This is currently not handled.");
}

auto gnd_gate = m_netlist.create_gate(gnd_type);
auto gnd_gate = m_netlist.create_gate(gnd_type, "GND_TEMP");
if (gnd_gate == nullptr)
{
return ERR("cannot create a GND net: failed to create GND gate in netlist");
}
// set gate name to be likely a unique gate name
gnd_gate->set_name("GND_" + std::to_string(gnd_gate->get_id()));

if (!gnd_gate->mark_gnd_gate())
{
return ERR("cannot create GND net: failed to mark created GND gate as such");
}

auto gnd_net = m_netlist.create_net("GND_TEMP");
if (gnd_net == nullptr)
{
Expand Down Expand Up @@ -427,15 +432,15 @@ namespace hal

if (vcc_pins.size() < 1)
{
return ERR("cannot create a VCC net: found no ground pins for gate type " + vcc_type->get_name());
return ERR("cannot create a VCC net: found no power pins for gate type " + vcc_type->get_name());
}

if (vcc_pins.size() > 1)
{
return ERR("cannot create a VCC net: found multiple ground pins for gate type " + vcc_type->get_name() + ". This is currently not handled.");
return ERR("cannot create a VCC net: found multiple power pins for gate type " + vcc_type->get_name() + ". This is currently not handled.");
}

auto vcc_gate = m_netlist.create_gate(vcc_type);
auto vcc_gate = m_netlist.create_gate(vcc_type, "VCC_TEMP");
if (vcc_gate == nullptr)
{
return ERR("cannot create a VCC net: failed to create VCC gate in netlist");
Expand All @@ -451,6 +456,11 @@ namespace hal
// set net name to be likely a unique net name
vcc_net->set_name("VCC_" + std::to_string(vcc_net->get_id()));

if (!vcc_gate->mark_vcc_gate())
{
return ERR("cannot create VCC net: failed to mark created VCC gate as such");
}

const auto vcc_ep = vcc_net->add_source(vcc_gate, vcc_pins.front());
if (vcc_ep == nullptr)
{
Expand Down
2 changes: 1 addition & 1 deletion src/netlist/gate_library/gate_library_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace hal
}

GateType* gt = lib->create_gate_type(name, {GateTypeProperty::combinational, GateTypeProperty::power});
if (auto res = gt->create_pin("O", PinDirection::output, PinType::ground); res.is_error())
if (auto res = gt->create_pin("O", PinDirection::output, PinType::power); res.is_error())
{
return ERR_APPEND(res.get_error(), "could not prepare gate library '" + lib->get_name() + "': failed to create output pin 'O' for gate type 'HAL_VDD'");
}
Expand Down
6 changes: 2 additions & 4 deletions src/netlist/gate_library/gate_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,8 @@ namespace hal
{
if (auto res = assign_pin_to_group(pin_group, pin, delete_empty_groups); res.is_error())
{
assert(delete_pin_group(pin_group).is_ok());
auto delete_res = delete_pin_group(pin_group);
assert(delete_res.is_ok());
return ERR(res.get_error());
}
}
Expand Down Expand Up @@ -438,12 +439,9 @@ namespace hal
+ ": pin group does not belong to gate type");
}

bool removed_pins = false;

std::vector<GatePin*> pins_copy = pin_group->get_pins();
for (auto* pin : pins_copy)
{
removed_pins = true;
if (auto res = create_pin_group(pin->get_name(), {pin}, pin->get_direction(), pin->get_type(), true, 0, false); res.is_error())
{
return ERR(res.get_error());
Expand Down
5 changes: 2 additions & 3 deletions src/netlist/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1391,10 +1391,9 @@ namespace hal
+ std::to_string(pin_group->get_id()) + " of module '" + m_name + "' with ID " + std::to_string(m_id) + ": pin does not belong to module");
}

if (pin->get_group().first == pin_group)
if (pin_group->contains_pin(pin))
{
return ERR("could not assign pin '" + pin->get_name() + "' with ID " + std::to_string(pin->get_id()) + " to pin group '" + pin_group->get_name() + "' with ID "
+ std::to_string(pin_group->get_id()) + " of module '" + m_name + "' with ID " + std::to_string(m_id) + ": pin already belongs to pin group");
return OK({});
}

if (PinGroup<ModulePin>* pg = pin->get_group().first; pg != nullptr)
Expand Down
27 changes: 14 additions & 13 deletions tests/netlist/netlist_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,21 @@ namespace hal
// -- remove the net
test_nl->delete_net(multi_src_net);
}
{
// The output net has no source
// -- create such a net
Net* no_src_net = test_nl->create_net("muli_src_net");
// {
// // NOTE: while a net without a source that is not a global input net should not occur in a perfect netlist, this proved to be unrealistic
// // The output net has no source
// // -- create such a net
// Net* no_src_net = test_nl->create_net("muli_src_net");

const std::vector<const Gate*> subgraph_gates({gate_0, gate_3});
const Net* output_net = no_src_net;
auto res = netlist_utils::get_subgraph_function(output_net, subgraph_gates);
ASSERT_TRUE(res.is_error());
// -- remove the net
test_nl->delete_net(no_src_net);
}
// const std::vector<const Gate*> subgraph_gates({gate_0, gate_3});
// const Net* output_net = no_src_net;

// auto res = netlist_utils::get_subgraph_function(output_net, subgraph_gates);
// ASSERT_TRUE(res.is_error());

// // -- remove the net
// test_nl->delete_net(no_src_net);
// }
{
// A net in between has multiple sources
// -- add a source to net 30 temporarily
Expand Down

0 comments on commit 063ef8d

Please sign in to comment.