yosys-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
select.cc File Reference
#include "kernel/yosys.h"
#include "kernel/celltypes.h"
#include "kernel/sigtools.h"
#include <string.h>
#include <errno.h>
+ Include dependency graph for select.cc:

Go to the source code of this file.

Data Structures

struct  SelectPass
 
struct  CdPass
 
struct  LsPass
 

Macros

#define LOG_OBJECT(...)   { if (list_mode) log(__VA_ARGS__); if (f != NULL) fprintf(f, __VA_ARGS__); total_count++; }
 

Functions

static bool match_ids (RTLIL::IdString id, std::string pattern)
 
static bool match_attr_val (const RTLIL::Const &value, std::string pattern, char match_op)
 
static bool match_attr (const std::map< RTLIL::IdString, RTLIL::Const > &attributes, std::string name_pat, std::string value_pat, char match_op)
 
static bool match_attr (const std::map< RTLIL::IdString, RTLIL::Const > &attributes, std::string match_expr)
 
static void select_op_neg (RTLIL::Design *design, RTLIL::Selection &lhs)
 
static void select_op_submod (RTLIL::Design *design, RTLIL::Selection &lhs)
 
static void select_op_fullmod (RTLIL::Design *design, RTLIL::Selection &lhs)
 
static void select_op_alias (RTLIL::Design *design, RTLIL::Selection &lhs)
 
static void select_op_union (RTLIL::Design *, RTLIL::Selection &lhs, const RTLIL::Selection &rhs)
 
static void select_op_diff (RTLIL::Design *design, RTLIL::Selection &lhs, const RTLIL::Selection &rhs)
 
static void select_op_intersect (RTLIL::Design *design, RTLIL::Selection &lhs, const RTLIL::Selection &rhs)
 
static int parse_comma_list (std::set< RTLIL::IdString > &tokens, std::string str, size_t pos, std::string stopchar)
 
static int select_op_expand (RTLIL::Design *design, RTLIL::Selection &lhs, std::vector< expand_rule_t > &rules, std::set< RTLIL::IdString > &limits, int max_objects, char mode, CellTypes &ct)
 
static void select_op_expand (RTLIL::Design *design, std::string arg, char mode)
 
static void select_filter_active_mod (RTLIL::Design *design, RTLIL::Selection &sel)
 
static void select_stmt (RTLIL::Design *design, std::string arg)
 
PRIVATE_NAMESPACE_END
YOSYS_NAMESPACE_BEGIN void 
handle_extra_select_args (Pass *pass, std::vector< std::string > args, size_t argidx, size_t args_size, RTLIL::Design *design)
 
template<typename T >
static int log_matches (const char *title, std::string pattern, T list)
 

Variables

static std::vector
< RTLIL::Selection
work_stack
 
SelectPass SelectPass
 
CdPass CdPass
 
LsPass LsPass
 

Macro Definition Documentation

#define LOG_OBJECT (   ...)    { if (list_mode) log(__VA_ARGS__); if (f != NULL) fprintf(f, __VA_ARGS__); total_count++; }

Function Documentation

PRIVATE_NAMESPACE_END YOSYS_NAMESPACE_BEGIN void handle_extra_select_args ( Pass pass,
std::vector< std::string >  args,
size_t  argidx,
size_t  args_size,
RTLIL::Design design 
)

Definition at line 803 of file select.cc.

804 {
805  work_stack.clear();
806  for (; argidx < args_size; argidx++) {
807  if (args[argidx].substr(0, 1) == "-") {
808  if (pass != NULL)
809  pass->cmd_error(args, argidx, "Unexpected option in selection arguments.");
810  else
811  log_cmd_error("Unexpected option in selection arguments.");
812  }
813  select_stmt(design, args[argidx]);
814  }
815  while (work_stack.size() > 1) {
816  select_op_union(design, work_stack.front(), work_stack.back());
817  work_stack.pop_back();
818  }
819  if (work_stack.size() > 0)
820  design->selection_stack.push_back(work_stack.back());
821  else
822  design->selection_stack.push_back(RTLIL::Selection(false));
823 }
void cmd_error(const std::vector< std::string > &args, size_t argidx, std::string msg)
Definition: register.cc:110
std::vector< RTLIL::Selection > selection_stack
Definition: rtlil.h:509
static std::vector< RTLIL::Selection > work_stack
Definition: select.cc:31
static void select_stmt(RTLIL::Design *design, std::string arg)
Definition: select.cc:564
void log_cmd_error(const char *format,...)
Definition: log.cc:211
#define NULL
static void select_op_union(RTLIL::Design *, RTLIL::Selection &lhs, const RTLIL::Selection &rhs)
Definition: select.cc:229

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename T >
static int log_matches ( const char *  title,
std::string  pattern,
list 
)
static

Definition at line 1330 of file select.cc.

1331 {
1332  std::vector<RTLIL::IdString> matches;
1333 
1334  for (auto &it : list)
1335  if (pattern.empty() || match_ids(it.first, pattern))
1336  matches.push_back(it.first);
1337 
1338  if (matches.empty())
1339  return 0;
1340 
1341  log("\n%d %s:\n", int(matches.size()), title);
1342  for (auto &id : matches)
1343  log(" %s\n", RTLIL::id2cstr(id));
1344  return matches.size();
1345 }
static bool match_ids(RTLIL::IdString id, std::string pattern)
Definition: select.cc:33
static const char * id2cstr(const RTLIL::IdString &str)
Definition: rtlil.h:267
void log(const char *format,...)
Definition: log.cc:180

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool match_attr ( const std::map< RTLIL::IdString, RTLIL::Const > &  attributes,
std::string  name_pat,
std::string  value_pat,
char  match_op 
)
static

Definition at line 104 of file select.cc.

105 {
106  if (name_pat.find('*') != std::string::npos || name_pat.find('?') != std::string::npos || name_pat.find('[') != std::string::npos) {
107  for (auto &it : attributes) {
108  if (patmatch(name_pat.c_str(), it.first.c_str()) && match_attr_val(it.second, value_pat, match_op))
109  return true;
110  if (it.first.size() > 0 && it.first[0] == '\\' && patmatch(name_pat.c_str(), it.first.substr(1).c_str()) && match_attr_val(it.second, value_pat, match_op))
111  return true;
112  }
113  } else {
114  if (name_pat.size() > 0 && (name_pat[0] == '\\' || name_pat[0] == '$') && attributes.count(name_pat) && match_attr_val(attributes.at(name_pat), value_pat, match_op))
115  return true;
116  if (attributes.count("\\" + name_pat) && match_attr_val(attributes.at("\\" + name_pat), value_pat, match_op))
117  return true;
118  }
119  return false;
120 }
bool patmatch(const char *pattern, const char *string)
Definition: yosys.cc:144
static bool match_attr_val(const RTLIL::Const &value, std::string pattern, char match_op)
Definition: select.cc:52

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool match_attr ( const std::map< RTLIL::IdString, RTLIL::Const > &  attributes,
std::string  match_expr 
)
static

Definition at line 122 of file select.cc.

123 {
124  size_t pos = match_expr.find_first_of("<!=>");
125 
126  if (pos != std::string::npos) {
127  if (match_expr.substr(pos, 2) == "!=")
128  return match_attr(attributes, match_expr.substr(0, pos), match_expr.substr(pos+2), '!');
129  if (match_expr.substr(pos, 2) == "<=")
130  return match_attr(attributes, match_expr.substr(0, pos), match_expr.substr(pos+2), '[');
131  if (match_expr.substr(pos, 2) == ">=")
132  return match_attr(attributes, match_expr.substr(0, pos), match_expr.substr(pos+2), ']');
133  return match_attr(attributes, match_expr.substr(0, pos), match_expr.substr(pos+1), match_expr[pos]);
134  }
135 
136  return match_attr(attributes, match_expr, std::string(), 0);
137 }
static bool match_attr(const std::map< RTLIL::IdString, RTLIL::Const > &attributes, std::string name_pat, std::string value_pat, char match_op)
Definition: select.cc:104

+ Here is the call graph for this function:

static bool match_attr_val ( const RTLIL::Const value,
std::string  pattern,
char  match_op 
)
static

Definition at line 52 of file select.cc.

53 {
54  if (match_op == 0)
55  return true;
56 
57  if ((value.flags & RTLIL::CONST_FLAG_STRING) == 0)
58  {
59  RTLIL::SigSpec sig_value;
60 
61  if (!RTLIL::SigSpec::parse(sig_value, NULL, pattern))
62  return false;
63 
64  RTLIL::Const pattern_value = sig_value.as_const();
65 
66  if (match_op == '=')
67  return value == pattern_value;
68  if (match_op == '!')
69  return value != pattern_value;
70  if (match_op == '<')
71  return value.as_int() < pattern_value.as_int();
72  if (match_op == '>')
73  return value.as_int() > pattern_value.as_int();
74  if (match_op == '[')
75  return value.as_int() <= pattern_value.as_int();
76  if (match_op == ']')
77  return value.as_int() >= pattern_value.as_int();
78  }
79  else
80  {
81  std::string value_str = value.decode_string();
82 
83  if (match_op == '=')
84  if (patmatch(pattern.c_str(), value.decode_string().c_str()))
85  return true;
86 
87  if (match_op == '=')
88  return value_str == pattern;
89  if (match_op == '!')
90  return value_str != pattern;
91  if (match_op == '<')
92  return value_str < pattern;
93  if (match_op == '>')
94  return value_str > pattern;
95  if (match_op == '[')
96  return value_str <= pattern;
97  if (match_op == ']')
98  return value_str >= pattern;
99  }
100 
101  log_abort();
102 }
int flags
Definition: rtlil.h:437
RTLIL::Const as_const() const
Definition: rtlil.cc:2857
#define log_abort()
Definition: log.h:84
bool patmatch(const char *pattern, const char *string)
Definition: yosys.cc:144
std::string decode_string() const
Definition: rtlil.cc:131
int as_int(bool is_signed=false) const
Definition: rtlil.cc:104
#define NULL
static bool parse(RTLIL::SigSpec &sig, RTLIL::Module *module, std::string str)
Definition: rtlil.cc:2972

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool match_ids ( RTLIL::IdString  id,
std::string  pattern 
)
static

Definition at line 33 of file select.cc.

34 {
35  if (id == pattern)
36  return true;
37  if (id.size() > 0 && id[0] == '\\' && id.substr(1) == pattern)
38  return true;
39  if (patmatch(pattern.c_str(), id.c_str()))
40  return true;
41  if (id.size() > 0 && id[0] == '\\' && patmatch(pattern.c_str(), id.substr(1).c_str()))
42  return true;
43  if (id.size() > 0 && id[0] == '$' && pattern.size() > 0 && pattern[0] == '$') {
44  const char *p = id.c_str();
45  const char *q = strrchr(p, '$');
46  if (pattern == q)
47  return true;
48  }
49  return false;
50 }
bool patmatch(const char *pattern, const char *string)
Definition: yosys.cc:144

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int parse_comma_list ( std::set< RTLIL::IdString > &  tokens,
std::string  str,
size_t  pos,
std::string  stopchar 
)
static

Definition at line 352 of file select.cc.

353 {
354  stopchar += ',';
355  while (1) {
356  size_t endpos = str.find_first_of(stopchar, pos);
357  if (endpos == std::string::npos)
358  endpos = str.size();
359  if (endpos != pos)
360  tokens.insert(RTLIL::escape_id(str.substr(pos, endpos-pos)));
361  pos = endpos;
362  if (pos == str.size() || str[pos] != ',')
363  return pos;
364  pos++;
365  }
366 }
static std::string escape_id(std::string str)
Definition: rtlil.h:251

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void select_filter_active_mod ( RTLIL::Design design,
RTLIL::Selection sel 
)
static

Definition at line 538 of file select.cc.

539 {
540  if (design->selected_active_module.empty())
541  return;
542 
543  if (sel.full_selection) {
544  sel.full_selection = false;
545  sel.selected_modules.clear();
546  sel.selected_members.clear();
547  sel.selected_modules.insert(design->selected_active_module);
548  return;
549  }
550 
551  std::vector<RTLIL::IdString> del_list;
552  for (auto mod_name : sel.selected_modules)
553  if (mod_name != design->selected_active_module)
554  del_list.push_back(mod_name);
555  for (auto &it : sel.selected_members)
556  if (it.first != design->selected_active_module)
557  del_list.push_back(it.first);
558  for (auto mod_name : del_list) {
559  sel.selected_modules.erase(mod_name);
560  sel.selected_members.erase(mod_name);
561  }
562 }
std::set< RTLIL::IdString > selected_modules
Definition: rtlil.h:463
std::map< RTLIL::IdString, std::set< RTLIL::IdString > > selected_members
Definition: rtlil.h:464
bool full_selection
Definition: rtlil.h:462
std::string selected_active_module
Definition: rtlil.h:511

+ Here is the caller graph for this function:

static void select_op_alias ( RTLIL::Design design,
RTLIL::Selection lhs 
)
static

Definition at line 207 of file select.cc.

208 {
209  for (auto &mod_it : design->modules_)
210  {
211  if (lhs.selected_whole_module(mod_it.first))
212  continue;
213  if (!lhs.selected_module(mod_it.first))
214  continue;
215 
216  SigMap sigmap(mod_it.second);
217  SigPool selected_bits;
218 
219  for (auto &it : mod_it.second->wires_)
220  if (lhs.selected_member(mod_it.first, it.first))
221  selected_bits.add(sigmap(it.second));
222 
223  for (auto &it : mod_it.second->wires_)
224  if (!lhs.selected_member(mod_it.first, it.first) && selected_bits.check_any(sigmap(it.second)))
225  lhs.selected_members[mod_it.first].insert(it.first);
226  }
227 }
bool selected_module(RTLIL::IdString mod_name) const
Definition: rtlil.cc:148
bool selected_whole_module(RTLIL::IdString mod_name) const
Definition: rtlil.cc:159
bool selected_member(RTLIL::IdString mod_name, RTLIL::IdString memb_name) const
Definition: rtlil.cc:168
std::map< RTLIL::IdString, std::set< RTLIL::IdString > > selected_members
Definition: rtlil.h:464
bool check_any(RTLIL::SigSpec sig)
Definition: sigtools.h:100
void add(RTLIL::SigSpec sig)
Definition: sigtools.h:41
std::map< RTLIL::IdString, RTLIL::Module * > modules_
Definition: rtlil.h:507

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void select_op_diff ( RTLIL::Design design,
RTLIL::Selection lhs,
const RTLIL::Selection rhs 
)
static

Definition at line 251 of file select.cc.

252 {
253  if (rhs.full_selection) {
254  lhs.full_selection = false;
255  lhs.selected_modules.clear();
256  lhs.selected_members.clear();
257  return;
258  }
259 
260  if (lhs.full_selection) {
261  if (!rhs.full_selection && rhs.selected_modules.size() == 0 && rhs.selected_members.size() == 0)
262  return;
263  lhs.full_selection = false;
264  for (auto &it : design->modules_)
265  lhs.selected_modules.insert(it.first);
266  }
267 
268  for (auto &it : rhs.selected_modules) {
269  lhs.selected_modules.erase(it);
270  lhs.selected_members.erase(it);
271  }
272 
273  for (auto &it : rhs.selected_members)
274  {
275  if (design->modules_.count(it.first) == 0)
276  continue;
277 
278  RTLIL::Module *mod = design->modules_[it.first];
279 
280  if (lhs.selected_modules.count(mod->name) > 0)
281  {
282  for (auto &it : mod->wires_)
283  lhs.selected_members[mod->name].insert(it.first);
284  for (auto &it : mod->memories)
285  lhs.selected_members[mod->name].insert(it.first);
286  for (auto &it : mod->cells_)
287  lhs.selected_members[mod->name].insert(it.first);
288  for (auto &it : mod->processes)
289  lhs.selected_members[mod->name].insert(it.first);
290  lhs.selected_modules.erase(mod->name);
291  }
292 
293  if (lhs.selected_members.count(mod->name) == 0)
294  continue;
295 
296  for (auto &it2 : it.second)
297  lhs.selected_members[mod->name].erase(it2);
298  }
299 }
std::set< RTLIL::IdString > selected_modules
Definition: rtlil.h:463
std::map< RTLIL::IdString, std::set< RTLIL::IdString > > selected_members
Definition: rtlil.h:464
std::map< RTLIL::IdString, RTLIL::Wire * > wires_
Definition: rtlil.h:595
std::map< RTLIL::IdString, RTLIL::Memory * > memories
Definition: rtlil.h:601
RTLIL::IdString name
Definition: rtlil.h:599
bool full_selection
Definition: rtlil.h:462
std::map< RTLIL::IdString, RTLIL::Process * > processes
Definition: rtlil.h:602
std::map< RTLIL::IdString, RTLIL::Module * > modules_
Definition: rtlil.h:507
std::map< RTLIL::IdString, RTLIL::Cell * > cells_
Definition: rtlil.h:596

+ Here is the caller graph for this function:

static int select_op_expand ( RTLIL::Design design,
RTLIL::Selection lhs,
std::vector< expand_rule_t > &  rules,
std::set< RTLIL::IdString > &  limits,
int  max_objects,
char  mode,
CellTypes ct 
)
static

Definition at line 368 of file select.cc.

369 {
370  int sel_objects = 0;
371  bool is_input, is_output;
372  for (auto &mod_it : design->modules_)
373  {
374  if (lhs.selected_whole_module(mod_it.first) || !lhs.selected_module(mod_it.first))
375  continue;
376 
377  RTLIL::Module *mod = mod_it.second;
378  std::set<RTLIL::Wire*> selected_wires;
379 
380  for (auto &it : mod->wires_)
381  if (lhs.selected_member(mod_it.first, it.first) && limits.count(it.first) == 0)
382  selected_wires.insert(it.second);
383 
384  for (auto &conn : mod->connections())
385  {
386  std::vector<RTLIL::SigBit> conn_lhs = conn.first.to_sigbit_vector();
387  std::vector<RTLIL::SigBit> conn_rhs = conn.second.to_sigbit_vector();
388 
389  for (size_t i = 0; i < conn_lhs.size(); i++) {
390  if (conn_lhs[i].wire == NULL || conn_rhs[i].wire == NULL)
391  continue;
392  if (mode != 'i' && selected_wires.count(conn_rhs[i].wire) && lhs.selected_members[mod->name].count(conn_lhs[i].wire->name) == 0)
393  lhs.selected_members[mod->name].insert(conn_lhs[i].wire->name), sel_objects++, max_objects--;
394  if (mode != 'o' && selected_wires.count(conn_lhs[i].wire) && lhs.selected_members[mod->name].count(conn_rhs[i].wire->name) == 0)
395  lhs.selected_members[mod->name].insert(conn_rhs[i].wire->name), sel_objects++, max_objects--;
396  }
397  }
398 
399  for (auto &cell : mod->cells_)
400  for (auto &conn : cell.second->connections())
401  {
402  char last_mode = '-';
403  for (auto &rule : rules) {
404  last_mode = rule.mode;
405  if (rule.cell_types.size() > 0 && rule.cell_types.count(cell.second->type) == 0)
406  continue;
407  if (rule.port_names.size() > 0 && rule.port_names.count(conn.first) == 0)
408  continue;
409  if (rule.mode == '+')
410  goto include_match;
411  else
412  goto exclude_match;
413  }
414  if (last_mode == '+')
415  goto exclude_match;
416  include_match:
417  is_input = mode == 'x' || ct.cell_input(cell.second->type, conn.first);
418  is_output = mode == 'x' || ct.cell_output(cell.second->type, conn.first);
419  for (auto &chunk : conn.second.chunks())
420  if (chunk.wire != NULL) {
421  if (max_objects != 0 && selected_wires.count(chunk.wire) > 0 && lhs.selected_members[mod->name].count(cell.first) == 0)
422  if (mode == 'x' || (mode == 'i' && is_output) || (mode == 'o' && is_input))
423  lhs.selected_members[mod->name].insert(cell.first), sel_objects++, max_objects--;
424  if (max_objects != 0 && lhs.selected_members[mod->name].count(cell.first) > 0 && limits.count(cell.first) == 0 && lhs.selected_members[mod->name].count(chunk.wire->name) == 0)
425  if (mode == 'x' || (mode == 'i' && is_input) || (mode == 'o' && is_output))
426  lhs.selected_members[mod->name].insert(chunk.wire->name), sel_objects++, max_objects--;
427  }
428  exclude_match:;
429  }
430  }
431 
432  return sel_objects;
433 }
bool selected_module(RTLIL::IdString mod_name) const
Definition: rtlil.cc:148
bool selected_whole_module(RTLIL::IdString mod_name) const
Definition: rtlil.cc:159
bool selected_member(RTLIL::IdString mod_name, RTLIL::IdString memb_name) const
Definition: rtlil.cc:168
const std::vector< RTLIL::SigSig > & connections() const
Definition: rtlil.cc:1307
std::map< RTLIL::IdString, std::set< RTLIL::IdString > > selected_members
Definition: rtlil.h:464
std::map< RTLIL::IdString, RTLIL::Wire * > wires_
Definition: rtlil.h:595
bool cell_output(RTLIL::IdString type, RTLIL::IdString port)
Definition: celltypes.h:193
RTLIL::IdString name
Definition: rtlil.h:599
std::map< RTLIL::IdString, RTLIL::Module * > modules_
Definition: rtlil.h:507
#define NULL
std::map< RTLIL::IdString, RTLIL::Cell * > cells_
Definition: rtlil.h:596
bool cell_input(RTLIL::IdString type, RTLIL::IdString port)
Definition: celltypes.h:199

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void select_op_expand ( RTLIL::Design design,
std::string  arg,
char  mode 
)
static

Definition at line 435 of file select.cc.

436 {
437  int pos = mode == 'x' ? 2 : 3, levels = 1, rem_objects = -1;
438  std::vector<expand_rule_t> rules;
439  std::set<RTLIL::IdString> limits;
440 
441  CellTypes ct;
442 
443  if (mode != 'x')
444  ct.setup(design);
445 
446  if (pos < int(arg.size()) && arg[pos] == '*') {
447  levels = 1000000;
448  pos++;
449  } else
450  if (pos < int(arg.size()) && '0' <= arg[pos] && arg[pos] <= '9') {
451  size_t endpos = arg.find_first_not_of("0123456789", pos);
452  if (endpos == std::string::npos)
453  endpos = arg.size();
454  levels = atoi(arg.substr(pos, endpos-pos).c_str());
455  pos = endpos;
456  }
457 
458  if (pos < int(arg.size()) && arg[pos] == '.') {
459  size_t endpos = arg.find_first_not_of("0123456789", ++pos);
460  if (endpos == std::string::npos)
461  endpos = arg.size();
462  if (int(endpos) > pos)
463  rem_objects = atoi(arg.substr(pos, endpos-pos).c_str());
464  pos = endpos;
465  }
466 
467  while (pos < int(arg.size())) {
468  if (arg[pos] != ':' || pos+1 == int(arg.size()))
469  log_cmd_error("Syntax error in expand operator '%s'.\n", arg.c_str());
470  pos++;
471  if (arg[pos] == '+' || arg[pos] == '-') {
472  expand_rule_t rule;
473  rule.mode = arg[pos++];
474  pos = parse_comma_list(rule.cell_types, arg, pos, "[:");
475  if (pos < int(arg.size()) && arg[pos] == '[') {
476  pos = parse_comma_list(rule.port_names, arg, pos+1, "]:");
477  if (pos < int(arg.size()) && arg[pos] == ']')
478  pos++;
479  }
480  rules.push_back(rule);
481  } else {
482  size_t endpos = arg.find(':', pos);
483  if (endpos == std::string::npos)
484  endpos = arg.size();
485  if (int(endpos) > pos) {
486  std::string str = arg.substr(pos, endpos-pos);
487  if (str[0] == '@') {
488  str = RTLIL::escape_id(str.substr(1));
489  if (design->selection_vars.count(str) > 0) {
490  for (auto i1 : design->selection_vars.at(str).selected_members)
491  for (auto i2 : i1.second)
492  limits.insert(i2);
493  } else
494  log_cmd_error("Selection %s is not defined!\n", RTLIL::unescape_id(str).c_str());
495  } else
496  limits.insert(RTLIL::escape_id(str));
497  }
498  pos = endpos;
499  }
500  }
501 
502 #if 0
503  log("expand by %d levels (max. %d objects):\n", levels, rem_objects);
504  for (auto &rule : rules) {
505  log(" rule (%c):\n", rule.mode);
506  if (rule.cell_types.size() > 0) {
507  log(" cell types:");
508  for (auto &it : rule.cell_types)
509  log(" %s", it.c_str());
510  log("\n");
511  }
512  if (rule.port_names.size() > 0) {
513  log(" port names:");
514  for (auto &it : rule.port_names)
515  log(" %s", it.c_str());
516  log("\n");
517  }
518  }
519  if (limits.size() > 0) {
520  log(" limits:");
521  for (auto &it : limits)
522  log(" %s", it.c_str());
523  log("\n");
524  }
525 #endif
526 
527  while (levels-- > 0 && rem_objects != 0) {
528  int num_objects = select_op_expand(design, work_stack.back(), rules, limits, rem_objects, mode, ct);
529  if (num_objects == 0)
530  break;
531  rem_objects -= num_objects;
532  }
533 
534  if (rem_objects == 0)
535  log_warning("reached configured limit at `%s'.\n", arg.c_str());
536 }
static int parse_comma_list(std::set< RTLIL::IdString > &tokens, std::string str, size_t pos, std::string stopchar)
Definition: select.cc:352
void log_warning(const char *format,...)
Definition: log.cc:196
static std::vector< RTLIL::Selection > work_stack
Definition: select.cc:31
void setup(RTLIL::Design *design=NULL)
Definition: celltypes.h:47
CellTypes ct
Definition: opt_clean.cc:33
static std::string unescape_id(std::string str)
Definition: rtlil.h:257
static std::string escape_id(std::string str)
Definition: rtlil.h:251
static int select_op_expand(RTLIL::Design *design, RTLIL::Selection &lhs, std::vector< expand_rule_t > &rules, std::set< RTLIL::IdString > &limits, int max_objects, char mode, CellTypes &ct)
Definition: select.cc:368
std::map< RTLIL::IdString, RTLIL::Selection > selection_vars
Definition: rtlil.h:510
void log_cmd_error(const char *format,...)
Definition: log.cc:211
void log(const char *format,...)
Definition: log.cc:180

+ Here is the call graph for this function:

static void select_op_fullmod ( RTLIL::Design design,
RTLIL::Selection lhs 
)
static

Definition at line 199 of file select.cc.

200 {
201  lhs.optimize(design);
202  for (auto &it : lhs.selected_members)
203  lhs.selected_modules.insert(it.first);
204  lhs.selected_members.clear();
205 }
std::set< RTLIL::IdString > selected_modules
Definition: rtlil.h:463
std::map< RTLIL::IdString, std::set< RTLIL::IdString > > selected_members
Definition: rtlil.h:464
void optimize(RTLIL::Design *design)
Definition: rtlil.cc:180

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void select_op_intersect ( RTLIL::Design design,
RTLIL::Selection lhs,
const RTLIL::Selection rhs 
)
static

Definition at line 301 of file select.cc.

302 {
303  if (rhs.full_selection)
304  return;
305 
306  if (lhs.full_selection) {
307  lhs.full_selection = false;
308  for (auto &it : design->modules_)
309  lhs.selected_modules.insert(it.first);
310  }
311 
312  std::vector<RTLIL::IdString> del_list;
313 
314  for (auto &it : lhs.selected_modules)
315  if (rhs.selected_modules.count(it) == 0) {
316  if (rhs.selected_members.count(it) > 0)
317  for (auto &it2 : rhs.selected_members.at(it))
318  lhs.selected_members[it].insert(it2);
319  del_list.push_back(it);
320  }
321  for (auto &it : del_list)
322  lhs.selected_modules.erase(it);
323 
324  del_list.clear();
325  for (auto &it : lhs.selected_members) {
326  if (rhs.selected_modules.count(it.first) > 0)
327  continue;
328  if (rhs.selected_members.count(it.first) == 0) {
329  del_list.push_back(it.first);
330  continue;
331  }
332  std::vector<RTLIL::IdString> del_list2;
333  for (auto &it2 : it.second)
334  if (rhs.selected_members.at(it.first).count(it2) == 0)
335  del_list2.push_back(it2);
336  for (auto &it2 : del_list2)
337  it.second.erase(it2);
338  if (it.second.size() == 0)
339  del_list.push_back(it.first);
340  }
341  for (auto &it : del_list)
342  lhs.selected_members.erase(it);
343 }
std::set< RTLIL::IdString > selected_modules
Definition: rtlil.h:463
std::map< RTLIL::IdString, std::set< RTLIL::IdString > > selected_members
Definition: rtlil.h:464
bool full_selection
Definition: rtlil.h:462
std::map< RTLIL::IdString, RTLIL::Module * > modules_
Definition: rtlil.h:507

+ Here is the caller graph for this function:

static void select_op_neg ( RTLIL::Design design,
RTLIL::Selection lhs 
)
static

Definition at line 139 of file select.cc.

140 {
141  if (lhs.full_selection) {
142  lhs.full_selection = false;
143  lhs.selected_modules.clear();
144  lhs.selected_members.clear();
145  return;
146  }
147 
148  if (lhs.selected_modules.size() == 0 && lhs.selected_members.size() == 0) {
149  lhs.full_selection = true;
150  return;
151  }
152 
153  RTLIL::Selection new_sel(false);
154 
155  for (auto &mod_it : design->modules_)
156  {
157  if (lhs.selected_whole_module(mod_it.first))
158  continue;
159  if (!lhs.selected_module(mod_it.first)) {
160  new_sel.selected_modules.insert(mod_it.first);
161  continue;
162  }
163 
164  RTLIL::Module *mod = mod_it.second;
165  for (auto &it : mod->wires_)
166  if (!lhs.selected_member(mod_it.first, it.first))
167  new_sel.selected_members[mod->name].insert(it.first);
168  for (auto &it : mod->memories)
169  if (!lhs.selected_member(mod_it.first, it.first))
170  new_sel.selected_members[mod->name].insert(it.first);
171  for (auto &it : mod->cells_)
172  if (!lhs.selected_member(mod_it.first, it.first))
173  new_sel.selected_members[mod->name].insert(it.first);
174  for (auto &it : mod->processes)
175  if (!lhs.selected_member(mod_it.first, it.first))
176  new_sel.selected_members[mod->name].insert(it.first);
177  }
178 
179  lhs.selected_modules.swap(new_sel.selected_modules);
180  lhs.selected_members.swap(new_sel.selected_members);
181 }
bool selected_module(RTLIL::IdString mod_name) const
Definition: rtlil.cc:148
bool selected_whole_module(RTLIL::IdString mod_name) const
Definition: rtlil.cc:159
bool selected_member(RTLIL::IdString mod_name, RTLIL::IdString memb_name) const
Definition: rtlil.cc:168
std::set< RTLIL::IdString > selected_modules
Definition: rtlil.h:463
std::map< RTLIL::IdString, std::set< RTLIL::IdString > > selected_members
Definition: rtlil.h:464
std::map< RTLIL::IdString, RTLIL::Wire * > wires_
Definition: rtlil.h:595
std::map< RTLIL::IdString, RTLIL::Memory * > memories
Definition: rtlil.h:601
RTLIL::IdString name
Definition: rtlil.h:599
bool full_selection
Definition: rtlil.h:462
std::map< RTLIL::IdString, RTLIL::Process * > processes
Definition: rtlil.h:602
std::map< RTLIL::IdString, RTLIL::Module * > modules_
Definition: rtlil.h:507
std::map< RTLIL::IdString, RTLIL::Cell * > cells_
Definition: rtlil.h:596

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void select_op_submod ( RTLIL::Design design,
RTLIL::Selection lhs 
)
static

Definition at line 183 of file select.cc.

184 {
185  for (auto &mod_it : design->modules_)
186  {
187  if (lhs.selected_whole_module(mod_it.first))
188  {
189  for (auto &cell_it : mod_it.second->cells_)
190  {
191  if (design->modules_.count(cell_it.second->type) == 0)
192  continue;
193  lhs.selected_modules.insert(cell_it.second->type);
194  }
195  }
196  }
197 }
bool selected_whole_module(RTLIL::IdString mod_name) const
Definition: rtlil.cc:159
std::set< RTLIL::IdString > selected_modules
Definition: rtlil.h:463
std::map< RTLIL::IdString, RTLIL::Module * > modules_
Definition: rtlil.h:507

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void select_op_union ( RTLIL::Design ,
RTLIL::Selection lhs,
const RTLIL::Selection rhs 
)
static

Definition at line 229 of file select.cc.

230 {
231  if (rhs.full_selection) {
232  lhs.full_selection = true;
233  lhs.selected_modules.clear();
234  lhs.selected_members.clear();
235  return;
236  }
237 
238  if (lhs.full_selection)
239  return;
240 
241  for (auto &it : rhs.selected_members)
242  for (auto &it2 : it.second)
243  lhs.selected_members[it.first].insert(it2);
244 
245  for (auto &it : rhs.selected_modules) {
246  lhs.selected_modules.insert(it);
247  lhs.selected_members.erase(it);
248  }
249 }
std::set< RTLIL::IdString > selected_modules
Definition: rtlil.h:463
std::map< RTLIL::IdString, std::set< RTLIL::IdString > > selected_members
Definition: rtlil.h:464
bool full_selection
Definition: rtlil.h:462

+ Here is the caller graph for this function:

static void select_stmt ( RTLIL::Design design,
std::string  arg 
)
static

Definition at line 564 of file select.cc.

565 {
566  std::string arg_mod, arg_memb;
567 
568  if (arg.size() == 0)
569  return;
570 
571  if (arg[0] == '%') {
572  if (arg == "%") {
573  if (design->selection_stack.size() > 0)
574  work_stack.push_back(design->selection_stack.back());
575  } else
576  if (arg == "%%") {
577  while (work_stack.size() > 1) {
578  select_op_union(design, work_stack.front(), work_stack.back());
579  work_stack.pop_back();
580  }
581  } else
582  if (arg == "%n") {
583  if (work_stack.size() < 1)
584  log_cmd_error("Must have at least one element on the stack for operator %%n.\n");
585  select_op_neg(design, work_stack[work_stack.size()-1]);
586  } else
587  if (arg == "%u") {
588  if (work_stack.size() < 2)
589  log_cmd_error("Must have at least two elements on the stack for operator %%u.\n");
590  select_op_union(design, work_stack[work_stack.size()-2], work_stack[work_stack.size()-1]);
591  work_stack.pop_back();
592  } else
593  if (arg == "%d") {
594  if (work_stack.size() < 2)
595  log_cmd_error("Must have at least two elements on the stack for operator %%d.\n");
596  select_op_diff(design, work_stack[work_stack.size()-2], work_stack[work_stack.size()-1]);
597  work_stack.pop_back();
598  } else
599  if (arg == "%D") {
600  if (work_stack.size() < 2)
601  log_cmd_error("Must have at least two elements on the stack for operator %%d.\n");
602  select_op_diff(design, work_stack[work_stack.size()-1], work_stack[work_stack.size()-2]);
603  work_stack[work_stack.size()-2] = work_stack[work_stack.size()-1];
604  work_stack.pop_back();
605  } else
606  if (arg == "%i") {
607  if (work_stack.size() < 2)
608  log_cmd_error("Must have at least two elements on the stack for operator %%i.\n");
609  select_op_intersect(design, work_stack[work_stack.size()-2], work_stack[work_stack.size()-1]);
610  work_stack.pop_back();
611  } else
612  if (arg == "%s") {
613  if (work_stack.size() < 1)
614  log_cmd_error("Must have at least one element on the stack for operator %%s.\n");
615  select_op_submod(design, work_stack[work_stack.size()-1]);
616  } else
617  if (arg == "%c") {
618  if (work_stack.size() < 1)
619  log_cmd_error("Must have at least one element on the stack for operator %%c.\n");
620  work_stack.push_back(work_stack.back());
621  } else
622  if (arg == "%m") {
623  if (work_stack.size() < 1)
624  log_cmd_error("Must have at least one element on the stack for operator %%m.\n");
625  select_op_fullmod(design, work_stack[work_stack.size()-1]);
626  } else
627  if (arg == "%a") {
628  if (work_stack.size() < 1)
629  log_cmd_error("Must have at least one element on the stack for operator %%a.\n");
630  select_op_alias(design, work_stack[work_stack.size()-1]);
631  } else
632  if (arg == "%x" || (arg.size() > 2 && arg.substr(0, 2) == "%x" && (arg[2] == ':' || arg[2] == '*' || arg[2] == '.' || ('0' <= arg[2] && arg[2] <= '9')))) {
633  if (work_stack.size() < 1)
634  log_cmd_error("Must have at least one element on the stack for operator %%x.\n");
635  select_op_expand(design, arg, 'x');
636  } else
637  if (arg == "%ci" || (arg.size() > 3 && arg.substr(0, 3) == "%ci" && (arg[3] == ':' || arg[3] == '*' || arg[3] == '.' || ('0' <= arg[3] && arg[3] <= '9')))) {
638  if (work_stack.size() < 1)
639  log_cmd_error("Must have at least one element on the stack for operator %%ci.\n");
640  select_op_expand(design, arg, 'i');
641  } else
642  if (arg == "%co" || (arg.size() > 3 && arg.substr(0, 3) == "%co" && (arg[3] == ':' || arg[3] == '*' || arg[3] == '.' || ('0' <= arg[3] && arg[3] <= '9')))) {
643  if (work_stack.size() < 1)
644  log_cmd_error("Must have at least one element on the stack for operator %%co.\n");
645  select_op_expand(design, arg, 'o');
646  } else
647  log_cmd_error("Unknown selection operator '%s'.\n", arg.c_str());
648  if (work_stack.size() >= 1)
649  select_filter_active_mod(design, work_stack.back());
650  return;
651  }
652 
653  if (arg[0] == '@') {
654  std::string set_name = RTLIL::escape_id(arg.substr(1));
655  if (design->selection_vars.count(set_name) > 0)
656  work_stack.push_back(design->selection_vars[set_name]);
657  else
658  log_cmd_error("Selection @%s is not defined!\n", RTLIL::unescape_id(set_name).c_str());
659  select_filter_active_mod(design, work_stack.back());
660  return;
661  }
662 
663  if (!design->selected_active_module.empty()) {
664  arg_mod = design->selected_active_module;
665  arg_memb = arg;
666  } else {
667  size_t pos = arg.find('/');
668  if (pos == std::string::npos) {
669  if (arg.find(':') == std::string::npos || arg.substr(0, 1) == "A")
670  arg_mod = arg;
671  else
672  arg_mod = "*", arg_memb = arg;
673  } else {
674  arg_mod = arg.substr(0, pos);
675  arg_memb = arg.substr(pos+1);
676  }
677  }
678 
679  work_stack.push_back(RTLIL::Selection());
680  RTLIL::Selection &sel = work_stack.back();
681 
682  if (arg == "*" && arg_mod == "*") {
683  select_filter_active_mod(design, work_stack.back());
684  return;
685  }
686 
687  sel.full_selection = false;
688  for (auto &mod_it : design->modules_)
689  {
690  if (arg_mod.substr(0, 2) == "A:") {
691  if (!match_attr(mod_it.second->attributes, arg_mod.substr(2)))
692  continue;
693  } else
694  if (!match_ids(mod_it.first, arg_mod))
695  continue;
696 
697  if (arg_memb == "") {
698  sel.selected_modules.insert(mod_it.first);
699  continue;
700  }
701 
702  RTLIL::Module *mod = mod_it.second;
703  if (arg_memb.substr(0, 2) == "w:") {
704  for (auto &it : mod->wires_)
705  if (match_ids(it.first, arg_memb.substr(2)))
706  sel.selected_members[mod->name].insert(it.first);
707  } else
708  if (arg_memb.substr(0, 2) == "i:") {
709  for (auto &it : mod->wires_)
710  if (it.second->port_input && match_ids(it.first, arg_memb.substr(2)))
711  sel.selected_members[mod->name].insert(it.first);
712  } else
713  if (arg_memb.substr(0, 2) == "o:") {
714  for (auto &it : mod->wires_)
715  if (it.second->port_output && match_ids(it.first, arg_memb.substr(2)))
716  sel.selected_members[mod->name].insert(it.first);
717  } else
718  if (arg_memb.substr(0, 2) == "x:") {
719  for (auto &it : mod->wires_)
720  if ((it.second->port_input || it.second->port_output) && match_ids(it.first, arg_memb.substr(2)))
721  sel.selected_members[mod->name].insert(it.first);
722  } else
723  if (arg_memb.substr(0, 2) == "s:") {
724  size_t delim = arg_memb.substr(2).find(':');
725  if (delim == std::string::npos) {
726  int width = atoi(arg_memb.substr(2).c_str());
727  for (auto &it : mod->wires_)
728  if (it.second->width == width)
729  sel.selected_members[mod->name].insert(it.first);
730  } else {
731  std::string min_str = arg_memb.substr(2, delim);
732  std::string max_str = arg_memb.substr(2+delim+1);
733  int min_width = min_str.empty() ? 0 : atoi(min_str.c_str());
734  int max_width = max_str.empty() ? -1 : atoi(max_str.c_str());
735  for (auto &it : mod->wires_)
736  if (min_width <= it.second->width && (it.second->width <= max_width || max_width == -1))
737  sel.selected_members[mod->name].insert(it.first);
738  }
739  } else
740  if (arg_memb.substr(0, 2) == "m:") {
741  for (auto &it : mod->memories)
742  if (match_ids(it.first, arg_memb.substr(2)))
743  sel.selected_members[mod->name].insert(it.first);
744  } else
745  if (arg_memb.substr(0, 2) == "c:") {
746  for (auto &it : mod->cells_)
747  if (match_ids(it.first, arg_memb.substr(2)))
748  sel.selected_members[mod->name].insert(it.first);
749  } else
750  if (arg_memb.substr(0, 2) == "t:") {
751  for (auto &it : mod->cells_)
752  if (match_ids(it.second->type, arg_memb.substr(2)))
753  sel.selected_members[mod->name].insert(it.first);
754  } else
755  if (arg_memb.substr(0, 2) == "p:") {
756  for (auto &it : mod->processes)
757  if (match_ids(it.first, arg_memb.substr(2)))
758  sel.selected_members[mod->name].insert(it.first);
759  } else
760  if (arg_memb.substr(0, 2) == "a:") {
761  for (auto &it : mod->wires_)
762  if (match_attr(it.second->attributes, arg_memb.substr(2)))
763  sel.selected_members[mod->name].insert(it.first);
764  for (auto &it : mod->memories)
765  if (match_attr(it.second->attributes, arg_memb.substr(2)))
766  sel.selected_members[mod->name].insert(it.first);
767  for (auto &it : mod->cells_)
768  if (match_attr(it.second->attributes, arg_memb.substr(2)))
769  sel.selected_members[mod->name].insert(it.first);
770  for (auto &it : mod->processes)
771  if (match_attr(it.second->attributes, arg_memb.substr(2)))
772  sel.selected_members[mod->name].insert(it.first);
773  } else
774  if (arg_memb.substr(0, 2) == "r:") {
775  for (auto &it : mod->cells_)
776  if (match_attr(it.second->parameters, arg_memb.substr(2)))
777  sel.selected_members[mod->name].insert(it.first);
778  } else {
779  if (arg_memb.substr(0, 2) == "n:")
780  arg_memb = arg_memb.substr(2);
781  for (auto &it : mod->wires_)
782  if (match_ids(it.first, arg_memb))
783  sel.selected_members[mod->name].insert(it.first);
784  for (auto &it : mod->memories)
785  if (match_ids(it.first, arg_memb))
786  sel.selected_members[mod->name].insert(it.first);
787  for (auto &it : mod->cells_)
788  if (match_ids(it.first, arg_memb))
789  sel.selected_members[mod->name].insert(it.first);
790  for (auto &it : mod->processes)
791  if (match_ids(it.first, arg_memb))
792  sel.selected_members[mod->name].insert(it.first);
793  }
794  }
795 
796  select_filter_active_mod(design, work_stack.back());
797 }
static void select_op_intersect(RTLIL::Design *design, RTLIL::Selection &lhs, const RTLIL::Selection &rhs)
Definition: select.cc:301
static void select_filter_active_mod(RTLIL::Design *design, RTLIL::Selection &sel)
Definition: select.cc:538
std::vector< RTLIL::Selection > selection_stack
Definition: rtlil.h:509
static std::vector< RTLIL::Selection > work_stack
Definition: select.cc:31
std::set< RTLIL::IdString > selected_modules
Definition: rtlil.h:463
static bool match_ids(RTLIL::IdString id, std::string pattern)
Definition: select.cc:33
std::map< RTLIL::IdString, std::set< RTLIL::IdString > > selected_members
Definition: rtlil.h:464
std::map< RTLIL::IdString, RTLIL::Wire * > wires_
Definition: rtlil.h:595
static std::string unescape_id(std::string str)
Definition: rtlil.h:257
std::map< RTLIL::IdString, RTLIL::Memory * > memories
Definition: rtlil.h:601
static std::string escape_id(std::string str)
Definition: rtlil.h:251
static int select_op_expand(RTLIL::Design *design, RTLIL::Selection &lhs, std::vector< expand_rule_t > &rules, std::set< RTLIL::IdString > &limits, int max_objects, char mode, CellTypes &ct)
Definition: select.cc:368
static void select_op_alias(RTLIL::Design *design, RTLIL::Selection &lhs)
Definition: select.cc:207
std::map< RTLIL::IdString, RTLIL::Selection > selection_vars
Definition: rtlil.h:510
static void select_op_neg(RTLIL::Design *design, RTLIL::Selection &lhs)
Definition: select.cc:139
static void select_op_fullmod(RTLIL::Design *design, RTLIL::Selection &lhs)
Definition: select.cc:199
RTLIL::IdString name
Definition: rtlil.h:599
bool full_selection
Definition: rtlil.h:462
void log_cmd_error(const char *format,...)
Definition: log.cc:211
std::map< RTLIL::IdString, RTLIL::Process * > processes
Definition: rtlil.h:602
std::map< RTLIL::IdString, RTLIL::Module * > modules_
Definition: rtlil.h:507
static bool match_attr(const std::map< RTLIL::IdString, RTLIL::Const > &attributes, std::string name_pat, std::string value_pat, char match_op)
Definition: select.cc:104
std::map< RTLIL::IdString, RTLIL::Cell * > cells_
Definition: rtlil.h:596
static void select_op_diff(RTLIL::Design *design, RTLIL::Selection &lhs, const RTLIL::Selection &rhs)
Definition: select.cc:251
std::string selected_active_module
Definition: rtlil.h:511
static void select_op_submod(RTLIL::Design *design, RTLIL::Selection &lhs)
Definition: select.cc:183
static void select_op_union(RTLIL::Design *, RTLIL::Selection &lhs, const RTLIL::Selection &rhs)
Definition: select.cc:229

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

std::vector<RTLIL::Selection> work_stack
static

Definition at line 31 of file select.cc.