12 std::vector<const Net *> retval;
22 if (n) retval.push_back(n);
28 retval.push_back(mp->get_net());
36 return gate_pin_group->get_name();
37 return module_pin_group->get_name();
42 return (mSimulationSet.find(g) != mSimulationSet.end());
47 mSimulationSet.insert(gates.begin(), gates.end());
50 compute_output_nets();
51 compute_partial_nets();
56 return mSimulationSet;
61 for (
const Clock& c: m_clocks)
62 if (c.clock_net == n)
return true;
68 m_clocks.push_back(clk);
73 mSimulationSet.clear();
76 m_output_nets.clear();
77 m_partial_nets.clear();
83 return has_gates() && (!m_clocks.empty() || mNoClockUsed) && !m_input_nets.empty();
88 return !mSimulationSet.empty();
103 return m_partial_nets;
108 return (m_input_nets.find(n) != m_input_nets.end());
124 if (!filename.empty())
125 if (!(of = fopen(filename.c_str(),
"w")))
127 log_warning(
"SimulationInput",
"cannot open simulation input dump file '{}'", filename);
131 fprintf(of,
"Gates:______________________________________\n");
132 for (
const Gate* g: mSimulationSet)
134 fprintf(of,
" %4d <%s>\n", g->get_id(), g->get_name().c_str());
136 fprintf(of,
"Clocks:_____________________________________\n");
137 for (
const Clock& clk: m_clocks)
139 fprintf(of,
" %4d <%s> \t period: %u \n", clk.clock_net->get_id(), clk.clock_net->get_name().c_str(), (
unsigned int) clk.period());
141 fprintf(of,
"Input nets:_________________________________\n");
142 for (
const Net* n: m_input_nets)
144 fprintf(of,
" %4d <%s>\n", n->get_id(), n->get_name().c_str());
146 fprintf(of,
"Output nets:________________________________\n");
147 for (
const Net* n: m_output_nets)
149 fprintf(of,
" %4d <%s>\n", n->get_id(), n->get_name().c_str());
151 fprintf(of,
"Partial netlist nets:________________________________\n");
152 for (
const Net* n: m_partial_nets)
154 fprintf(of,
" %4d <%s>\n", n->get_id(), n->get_name().c_str());
156 if (filename.empty())
162 void SimulationInput::compute_input_nets()
164 m_input_nets.clear();
165 for (
auto gate : mSimulationSet)
167 for (
auto net : gate->get_fan_in_nets())
170 if (
net->is_global_input_net())
172 m_input_nets.insert(
net);
176 int number_sources = 0;
177 for (
auto src :
net->get_sources())
182 m_input_nets.insert(
net);
187 m_input_nets.insert(
net);
193 void SimulationInput::compute_output_nets()
195 m_output_nets.clear();
196 for (
auto gate : mSimulationSet)
198 for (
auto net : gate->get_fan_out_nets())
201 if (
net->is_global_output_net())
203 m_output_nets.push_back(
net);
207 int number_destinations = 0;
208 for (
auto dst :
net->get_destinations())
210 ++number_destinations;
213 m_output_nets.push_back(
net);
217 if (!number_destinations)
218 m_output_nets.push_back(
net);
224 void SimulationInput::compute_partial_nets()
226 m_partial_nets.clear();
227 std::unordered_set<const Net*> found;
228 for (
const Gate* g : mSimulationSet)
230 for (
const Net* n : g->get_fan_in_nets())
232 if (found.find(n) == found.end())
235 m_partial_nets.push_back(n);
238 for (
const Net* n : g->get_fan_out_nets())
240 if (found.find(n) == found.end())
243 m_partial_nets.push_back(n);
251 std::unordered_set<const Module*> simulated_modules;
254 std::unordered_map<const Net*, DirectionType> ungrouped_nets;
256 for (
const Net* n : m_partial_nets) ungrouped_nets[n] =
Undefined;
257 for (
const Net* n : m_input_nets) ungrouped_nets[n] =
InputOnly;
258 for (
const Net* n : m_output_nets) ungrouped_nets[n] =
OutputOnly;
261 for (
const Gate* g : mSimulationSet)
263 const Module *m = g->get_module();
266 simulated_modules.insert(m);
272 auto it = simulated_modules.begin();
273 for (
int level = 0; ! simulated_modules.empty(); )
275 while ((*it)->get_submodule_depth() != level)
277 if (++it == simulated_modules.end())
280 it = simulated_modules.begin();
287 if (pg->size() < 2 || pg->size() > 31)
continue;
288 bool pin_group_simulated =
true;
293 Net* n = mp->get_net();
296 auto itNet = ungrouped_nets.find(n);
297 if (itNet == ungrouped_nets.end())
300 pin_group_simulated =
false;
306 groupType = itNet->second;
307 else if (groupType !=
Mixed && groupType != itNet->second)
312 if (pin_group_simulated)
320 Net* n = mp->get_net();
323 ungrouped_nets.erase(n);
326 m_netgroups.push_back(group);
330 simulated_modules.erase(it);
331 it = simulated_modules.begin();
334 for (
const Gate* g : mSimulationSet)
340 if (pg->size() < 2 || pg->size() > 31)
continue;
341 bool pin_group_simulated =
true;
343 std::unordered_set<const Net*> connectedNets;
345 for (
GatePin* gp : pg->get_pins())
348 switch (gp->get_direction())
351 n = g->get_fan_in_net(gp);
354 n = g->get_fan_out_net(gp);
361 auto itNet = ungrouped_nets.find(n);
362 if (itNet == ungrouped_nets.end())
365 pin_group_simulated =
false;
370 connectedNets.insert(n);
372 groupType = itNet->second;
373 else if (groupType !=
Mixed && groupType != itNet->second)
378 pin_group_simulated =
false;
381 if (pin_group_simulated)
388 for (
const Net* n : connectedNets)
389 ungrouped_nets.erase(n);
390 m_netgroups.push_back(group);
Net * get_fan_in_net(const std::string &pin_name) const
Net * get_fan_out_net(const std::string &pin_name) const
std::vector< PinGroup< GatePin > * > get_pin_groups(const std::function< bool(PinGroup< GatePin > *)> &filter=nullptr) const
Module * get_parent_module() const
std::vector< PinGroup< ModulePin > * > get_pin_groups(const std::function< bool(PinGroup< ModulePin > *)> &filter=nullptr) const
#define log_warning(channel,...)