Skip to content

Commit

Permalink
Accidentaly deleted file restored
Browse files Browse the repository at this point in the history
  • Loading branch information
joern274 committed Jun 19, 2024
1 parent f58d03c commit f91a043
Show file tree
Hide file tree
Showing 6 changed files with 609 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ class NETLIST_API NetlistSimulatorController : public QObject {
*/
u32 add_waveform_group(const PinGroup<ModulePin>* pin_group);

/**
* Create a waveform group from the nets of a given gate pin group.
*
* @param pin_group The pin_group to create waveform group from.
* @return ID of new waveform group
*/
u32 add_waveform_group(const Gate* gate, const PinGroup<GatePin>* pin_group);

/**
* Create a waveform group from the nets of a given module pin group.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
#include <unordered_map>
#include "hal_core/defines.h"
#include "hal_core/netlist/boolean_function.h"
#include "hal_core/netlist/pins/module_pin.h"
#include "hal_core/netlist/pins/gate_pin.h"
#include "hal_core/netlist/pins/pin_group.h"

namespace hal {
class Gate;
Expand All @@ -56,10 +59,11 @@ namespace hal {

struct NetGroup
{
std::string name;
std::vector<std::pair<int,Net*> > nets;

NetGroup(const std::string& nam) : name(nam) {;}
bool is_input;
const Gate* gate;
PinGroup<ModulePin>* module_pin_group;
PinGroup<GatePin>* gate_pin_group;
NetGroup() : is_input(true), gate(nullptr), module_pin_group(nullptr), gate_pin_group(nullptr) {;}
};

private:
Expand All @@ -76,7 +80,6 @@ namespace hal {
void compute_input_nets();
void compute_output_nets();
void compute_partial_nets();
void compute_net_groups();

public:
SimulationInput() : mNoClockUsed(false) {;}
Expand Down Expand Up @@ -176,5 +179,9 @@ namespace hal {
* @param filename name of file to be created
*/
void dump(std::string filename = std::string()) const;

void compute_net_groups();

const std::vector<NetGroup>& get_net_groups() const { return m_netgroups; }
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,20 @@ namespace hal
)")

.def("add_waveform_group", py::overload_cast<const PinGroup<ModulePin>*>(&NetlistSimulatorController::add_waveform_group), py::arg("pin_group"), R"(
Create a waveform group from the nets of a given module pin group.
Create a waveform group from the nets of a given module pin group.
:param hal_py.ModulePinGroup pin_group: The pin_group to create waveform group from.
:return: ID of the new waveform group.
:rtype: int
:param hal_py.ModulePinGroup pin_group: The pin_group to create waveform group from.
:return: ID of the new waveform group.
:rtype: int
)")

.def("add_waveform_group", py::overload_cast<const Gate*, const PinGroup<GatePin>*>(&NetlistSimulatorController::add_waveform_group), py::arg("gate"), py::arg("pin_group"), R"(
Create a waveform group from the nets of a given gate pin group.
:param hal_py.Gate: The gate instance the pin_group belongs to.
:param hal_py.GatePinGroup pin_group: The pin_group to create waveform group from.
:return: ID of the new waveform group.
:rtype: int
)")

.def("add_waveform_group", py::overload_cast<const std::string&, const PinGroup<ModulePin>*>(&NetlistSimulatorController::add_waveform_group), py::arg("name"), py::arg("pin_group"), R"(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "hal_core/netlist/project_manager.h"
#include "hal_core/utilities/json_write_document.h"
#include "hal_core/utilities/log.h"
#include "hal_core/netlist/gate_library/enums/pin_direction.h"
#include "netlist_simulator_controller/plugin_netlist_simulator_controller.h"
#include "netlist_simulator_controller/saleae_directory.h"
#include "netlist_simulator_controller/saleae_parser.h"
Expand Down Expand Up @@ -335,6 +336,30 @@ namespace hal
return add_waveform_group(pin_group->get_name(), nets);
}

u32 NetlistSimulatorController::add_waveform_group(const Gate *gate, const PinGroup<GatePin>* pin_group)
{
std::vector<Net*> nets;
for (const auto pin : pin_group->get_pins())
{
Net* n = nullptr;
switch (pin->get_direction())
{
case PinDirection::input:
n = gate->get_fan_in_net(pin);
break;
case PinDirection::output:
n = gate->get_fan_out_net(pin);
break;
default:
break;
}

if (n) nets.push_back(n);
}

return add_waveform_group(pin_group->get_name(), nets);
}

u32 NetlistSimulatorController::add_waveform_group(const std::string& name, const PinGroup<ModulePin>* pin_group)
{
std::vector<Net*> nets;
Expand Down Expand Up @@ -880,30 +905,15 @@ namespace hal

void NetlistSimulatorController::make_waveform_groups()
{
std::unordered_map<Module*,std::unordered_set<const Gate*>> containedModules;
for (const Gate* g: mSimulationInput->get_gates())
{
Module* m = g->get_module();
// test all parent modules whether gates are contained in simulation
while (m)
{
auto it = containedModules.find(m);
if (it == containedModules.end())
{
std::vector<Gate*> gats = m->get_gates(nullptr,true);
containedModules.insert(std::make_pair(m,std::unordered_set<const Gate*>(gats.begin(),gats.end())));
it = containedModules.find(m);
}
auto jt = it->second.find(g);
if (jt!=it->second.end())
it->second.erase(jt);
m = m->get_parent_module();
}
}
for (const auto &it : containedModules)
mSimulationInput->compute_net_groups();

for (const SimulationInput::NetGroup& ng : mSimulationInput->get_net_groups())
{
if (it.second.empty())
std::cerr << it.first->get_id() << " mod simulated <" << it.first->get_name() << ">" << std::endl;
if (!ng.is_input) continue;
if (ng.gate)
add_waveform_group(ng.gate, ng.gate_pin_group);
else
add_waveform_group(ng.module_pin_group);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "netlist_simulator_controller/simulation_input.h"
#include "netlist_simulator_controller/simulation_input.h"
#include "hal_core/netlist/gate.h"
#include "hal_core/netlist/net.h"
#include "hal_core/utilities/log.h"
Expand All @@ -19,7 +19,6 @@ namespace hal {
compute_input_nets();
compute_output_nets();
compute_partial_nets();
compute_net_groups();
}

const std::unordered_set<const Gate*>& SimulationInput::get_gates() const
Expand Down Expand Up @@ -247,14 +246,12 @@ namespace hal {
{
if (pg->size() < 2) continue;
bool pin_group_simulated = true;
NetGroup group(pg->get_name());

for (ModulePin* mp : pg->get_pins())
{
Net* n = mp->get_net();
if (n)
{
group.nets.push_back(std::make_pair(mp->get_group().second,n));
if (single_nets.find(n) == single_nets.end())
{
// pin : net exists and is not part of the simulation, ignore pin group
Expand All @@ -265,8 +262,19 @@ namespace hal {
}
if (pin_group_simulated)
{
m_netgroups.push_back(group);
for (auto pair : group.nets) single_nets.erase(pair.second);
NetGroup group;
group.module_pin_group = pg;
for (ModulePin* mp : pg->get_pins())
{
Net* n = mp->get_net();
if (n)
{
single_nets.erase(n);
if (!is_input_net(n))
group.is_input = false;
}
}
m_netgroups.push_back(group);
}
}

Expand All @@ -282,12 +290,11 @@ namespace hal {
{
if (pg->size() < 2) continue;
bool pin_group_simulated = true;
NetGroup group(pg->get_name());

for (GatePin* gp : pg->get_pins())
{
Net* n = nullptr;
switch (pg->get_direction())
switch (gp->get_direction())
{
case PinDirection::inout:
n = g->get_fan_in_net(gp);
Expand All @@ -300,7 +307,6 @@ namespace hal {
}
if (n)
{
group.nets.push_back(std::make_pair(gp->get_group().second,n));
if (single_nets.find(n) == single_nets.end())
{
// pin : net alreade assigned to module pin group, ignore gate pin group
Expand All @@ -312,8 +318,24 @@ namespace hal {

if (pin_group_simulated)
{
NetGroup group;
group.gate = g;
group.gate_pin_group = pg;
if (pg->get_direction() == PinDirection::input)
{
for (GatePin* gp : pg->get_pins())
{
Net* n = g->get_fan_in_net(gp);
if (n && !is_input_net(n))
{
group.is_input = false;
break;
}
}
}
else
group.is_input = false;
m_netgroups.push_back(group);
for (auto pair : group.nets) single_nets.erase(pair.second);
}
}
}
Expand Down
Loading

0 comments on commit f91a043

Please sign in to comment.