yosys-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
my_cmd.cc
Go to the documentation of this file.
1 #include "kernel/yosys.h"
2 #include "kernel/sigtools.h"
3 
6 
7 struct MyPass : public Pass {
8  MyPass() : Pass("my_cmd", "just a simple test") { }
9  virtual void execute(std::vector<std::string> args, RTLIL::Design *design)
10  {
11  log("Arguments to my_cmd:\n");
12  for (auto &arg : args)
13  log(" %s\n", arg.c_str());
14 
15  log("Modules in current design:\n");
16  for (auto mod : design->modules())
17  log(" %s (%zd wires, %zd cells)\n", log_id(mod),
18  GetSize(mod->wires()), GetSize(mod->cells()));
19  }
20 } MyPass;
21 
22 
23 struct Test1Pass : public Pass {
24  Test1Pass() : Pass("test1", "creating the absval module") { }
25  virtual void execute(std::vector<std::string>, RTLIL::Design *design)
26  {
27  if (design->has("\\absval") != 0)
28  log_error("A module with the name absval already exists!\n");
29 
30  RTLIL::Module *module = design->addModule("\\absval");
31  log("Name of this module: %s\n", log_id(module));
32 
33  RTLIL::Wire *a = module->addWire("\\a", 4);
34  a->port_input = true;
35  a->port_id = 1;
36 
37  RTLIL::Wire *y = module->addWire("\\y", 4);
38  y->port_output = true;
39  y->port_id = 2;
40 
41  RTLIL::Wire *a_inv = module->addWire(NEW_ID, 4);
42  module->addNeg(NEW_ID, a, a_inv, true);
43  module->addMux(NEW_ID, a, a_inv, RTLIL::SigSpec(a, 3), y);
44 
45  module->fixup_ports();
46  }
47 } Test1Pass;
48 
49 
50 struct Test2Pass : public Pass {
51  Test2Pass() : Pass("test2", "demonstrating sigmap on test module") { }
52  virtual void execute(std::vector<std::string>, RTLIL::Design *design)
53  {
54  if (design->selection_stack.back().empty())
55  log_cmd_error("This command can't operator on an empty selection!\n");
56 
57  RTLIL::Module *module = design->modules_.at("\\test");
58 
59  RTLIL::SigSpec a(module->wire("\\a")), x(module->wire("\\x")), y(module->wire("\\y"));
60  log("%d %d %d\n", a == x, x == y, y == a); // will print "0 0 0"
61 
62  SigMap sigmap(module);
63  log("%d %d %d\n", sigmap(a) == sigmap(x), sigmap(x) == sigmap(y),
64  sigmap(y) == sigmap(a)); // will print "1 1 1"
65 
66  log("Mapped signal x: %s\n", log_signal(sigmap(x)));
67 
68  log_header("Doing important stuff!\n");
69  log_push();
70  for (int i = 0; i < 10; i++)
71  log("Log message #%d.\n", i);
72  log_pop();
73  }
74 } Test2Pass;
75 
RTLIL::Wire * wire(RTLIL::IdString id)
Definition: rtlil.h:637
std::vector< RTLIL::Selection > selection_stack
Definition: rtlil.h:509
MyPass()
Definition: my_cmd.cc:8
void log_header(const char *format,...)
Definition: log.cc:188
Test1Pass Test1Pass
virtual void execute(std::vector< std::string > args, RTLIL::Design *design)
Definition: my_cmd.cc:9
const char * log_signal(const RTLIL::SigSpec &sig, bool autoint)
Definition: log.cc:269
bool port_input
Definition: rtlil.h:827
Test1Pass()
Definition: my_cmd.cc:24
void log_error(const char *format,...)
Definition: log.cc:204
RTLIL::Module * module
Definition: abc.cc:94
virtual void execute(std::vector< std::string >, RTLIL::Design *design)
Definition: my_cmd.cc:25
int port_id
Definition: rtlil.h:826
void log_pop()
Definition: log.cc:237
bool port_output
Definition: rtlil.h:827
RTLIL::Cell * addNeg(RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_y, bool is_signed=false)
#define PRIVATE_NAMESPACE_BEGIN
Definition: yosys.h:97
MyPass MyPass
int GetSize(RTLIL::Wire *wire)
Definition: yosys.cc:334
void fixup_ports()
Definition: rtlil.cc:1312
RTLIL::Wire * addWire(RTLIL::IdString name, int width=1)
Definition: rtlil.cc:1331
#define NEW_ID
Definition: yosys.h:166
#define PRIVATE_NAMESPACE_END
Definition: yosys.h:98
Definition: register.h:27
void log_cmd_error(const char *format,...)
Definition: log.cc:211
RTLIL::Module * addModule(RTLIL::IdString name)
Definition: rtlil.cc:270
bool has(RTLIL::IdString id) const
Definition: rtlil.h:519
#define USING_YOSYS_NAMESPACE
Definition: yosys.h:102
RTLIL::ObjRange< RTLIL::Module * > modules()
Definition: rtlil.cc:249
std::map< RTLIL::IdString, RTLIL::Module * > modules_
Definition: rtlil.h:507
RTLIL::Cell * addMux(RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_s, RTLIL::SigSpec sig_y)
void log(const char *format,...)
Definition: log.cc:180
void log_push()
Definition: log.cc:232
Test2Pass Test2Pass
Definition: my_cmd.cc:7
const char * log_id(RTLIL::IdString str)
Definition: log.cc:283
Test2Pass()
Definition: my_cmd.cc:51
virtual void execute(std::vector< std::string >, RTLIL::Design *design)
Definition: my_cmd.cc:52