yosys-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TopoSort< T, C > Struct Template Reference

#include <utils.h>

Public Member Functions

 TopoSort ()
 
void node (T n)
 
void edge (T left, T right)
 
void sort_worker (const T &n, std::set< T, C > &marked_cells, std::set< T, C > &active_cells, std::vector< T > &active_stack)
 
bool sort ()
 

Data Fields

bool analyze_loops
 
bool found_loops
 
std::map< T, std::set< T, C >, C > database
 
std::set< std::set< T, C > > loops
 
std::vector< T > sorted
 

Detailed Description

template<typename T, typename C = std::less<T>>
struct TopoSort< T, C >

Definition at line 132 of file utils.h.

Constructor & Destructor Documentation

template<typename T, typename C = std::less<T>>
TopoSort< T, C >::TopoSort ( )
inline

Definition at line 139 of file utils.h.

140  {
141  analyze_loops = true;
142  found_loops = false;
143  }
bool found_loops
Definition: utils.h:134
bool analyze_loops
Definition: utils.h:134

Member Function Documentation

template<typename T, typename C = std::less<T>>
void TopoSort< T, C >::edge ( left,
right 
)
inline

Definition at line 151 of file utils.h.

152  {
153  node(left);
154  database[right].insert(left);
155  }
void node(T n)
Definition: utils.h:145
std::map< T, std::set< T, C >, C > database
Definition: utils.h:135

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename T, typename C = std::less<T>>
void TopoSort< T, C >::node ( n)
inline

Definition at line 145 of file utils.h.

146  {
147  if (database.count(n) == 0)
148  database[n] = std::set<T, C>();
149  }
tuple n
Definition: fsm/generate.py:59
std::map< T, std::set< T, C >, C > database
Definition: utils.h:135

+ Here is the caller graph for this function:

template<typename T, typename C = std::less<T>>
bool TopoSort< T, C >::sort ( )
inline

Definition at line 194 of file utils.h.

195  {
196  loops.clear();
197  sorted.clear();
198  found_loops = false;
199 
200  std::set<T, C> marked_cells;
201  std::set<T, C> active_cells;
202  std::vector<T> active_stack;
203 
204  for (auto &it : database)
205  sort_worker(it.first, marked_cells, active_cells, active_stack);
206 
207  log_assert(GetSize(sorted) == GetSize(database));
208  return !found_loops;
209  }
std::set< std::set< T, C > > loops
Definition: utils.h:136
bool found_loops
Definition: utils.h:134
void sort_worker(const T &n, std::set< T, C > &marked_cells, std::set< T, C > &active_cells, std::vector< T > &active_stack)
Definition: utils.h:157
int GetSize(RTLIL::Wire *wire)
Definition: yosys.cc:334
#define log_assert(_assert_expr_)
Definition: log.h:85
std::map< T, std::set< T, C >, C > database
Definition: utils.h:135
std::vector< T > sorted
Definition: utils.h:137

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename T, typename C = std::less<T>>
void TopoSort< T, C >::sort_worker ( const T &  n,
std::set< T, C > &  marked_cells,
std::set< T, C > &  active_cells,
std::vector< T > &  active_stack 
)
inline

Definition at line 157 of file utils.h.

158  {
159  if (active_cells.count(n)) {
160  found_loops = true;
161  if (analyze_loops) {
162  std::set<T, C> loop;
163  for (int i = GetSize(active_stack)-1; i >= 0; i--) {
164  loop.insert(active_stack[i]);
165  if (active_stack[i] == n)
166  break;
167  }
168  loops.insert(loop);
169  }
170  return;
171  }
172 
173  if (marked_cells.count(n))
174  return;
175 
176  if (!database.at(n).empty())
177  {
178  if (analyze_loops)
179  active_stack.push_back(n);
180  active_cells.insert(n);
181 
182  for (auto &left_n : database.at(n))
183  sort_worker(left_n, marked_cells, active_cells, active_stack);
184 
185  if (analyze_loops)
186  active_stack.pop_back();
187  active_cells.erase(n);
188  }
189 
190  marked_cells.insert(n);
191  sorted.push_back(n);
192  }
std::set< std::set< T, C > > loops
Definition: utils.h:136
tuple n
Definition: fsm/generate.py:59
bool found_loops
Definition: utils.h:134
void sort_worker(const T &n, std::set< T, C > &marked_cells, std::set< T, C > &active_cells, std::vector< T > &active_stack)
Definition: utils.h:157
int GetSize(RTLIL::Wire *wire)
Definition: yosys.cc:334
std::map< T, std::set< T, C >, C > database
Definition: utils.h:135
bool analyze_loops
Definition: utils.h:134
std::vector< T > sorted
Definition: utils.h:137

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

template<typename T, typename C = std::less<T>>
bool TopoSort< T, C >::analyze_loops

Definition at line 134 of file utils.h.

template<typename T, typename C = std::less<T>>
std::map<T, std::set<T, C>, C> TopoSort< T, C >::database

Definition at line 135 of file utils.h.

template<typename T, typename C = std::less<T>>
bool TopoSort< T, C >::found_loops

Definition at line 134 of file utils.h.

template<typename T, typename C = std::less<T>>
std::set<std::set<T, C> > TopoSort< T, C >::loops

Definition at line 136 of file utils.h.

template<typename T, typename C = std::less<T>>
std::vector<T> TopoSort< T, C >::sorted

Definition at line 137 of file utils.h.


The documentation for this struct was generated from the following file: