2 * yosys -- Yosys Open SYnthesis Suite
4 * Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include "kernel/yosys.h"
23 PRIVATE_NAMESPACE_BEGIN
25 static void add_wire(RTLIL::Design
*design
, RTLIL::Module
*module
, std::string name
, int width
, bool flag_input
, bool flag_output
, bool flag_global
)
27 RTLIL::Wire
*wire
= nullptr;
28 name
= RTLIL::escape_id(name
);
30 if (module
->count_id(name
) != 0)
32 wire
= module
->wire(name
);
34 if (wire
!= nullptr && wire
->width
!= width
)
37 if (wire
!= nullptr && wire
->port_input
!= flag_input
)
40 if (wire
!= nullptr && wire
->port_output
!= flag_output
)
44 log_cmd_error("Found incompatible object with same name in module %s!\n", module
->name
.c_str());
46 log("Module %s already has such an object.\n", module
->name
.c_str());
50 wire
= module
->addWire(name
, width
);
51 wire
->port_input
= flag_input
;
52 wire
->port_output
= flag_output
;
54 if (flag_input
|| flag_output
) {
55 module
->fixup_ports();
58 log("Added wire %s to module %s.\n", name
.c_str(), module
->name
.c_str());
64 for (auto cell
: module
->cells())
66 RTLIL::Module
*mod
= design
->module(cell
->type
);
69 if (!design
->selected_whole_module(mod
->name
))
71 if (mod
->get_blackbox_attribute())
73 if (cell
->hasPort(name
))
76 cell
->setPort(name
, wire
);
77 log("Added connection %s to cell %s.%s (%s).\n", name
.c_str(), module
->name
.c_str(), cell
->name
.c_str(), cell
->type
.c_str());
81 struct AddPass
: public Pass
{
82 AddPass() : Pass("add", "add objects to the design") { }
83 void help() YS_OVERRIDE
85 // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
87 log(" add <command> [selection]\n");
89 log("This command adds objects to the design. It operates on all fully selected\n");
90 log("modules. So e.g. 'add -wire foo' will add a wire foo to all selected modules.\n");
93 log(" add {-wire|-input|-inout|-output} <name> <width> [selection]\n");
95 log("Add a wire (input, inout, output port) with the given name and width. The\n");
96 log("command will fail if the object exists already and has different properties\n");
97 log("than the object to be created.\n");
100 log(" add -global_input <name> <width> [selection]\n");
102 log("Like 'add -input', but also connect the signal between instances of the\n");
103 log("selected modules.\n");
106 log(" add -mod <name[s]>\n");
108 log("Add module[s] with the specified name[s].\n");
111 void execute(std::vector
<std::string
> args
, RTLIL::Design
*design
) YS_OVERRIDE
114 std::string arg_name
;
115 bool arg_flag_input
= false;
116 bool arg_flag_output
= false;
117 bool arg_flag_global
= false;
118 bool mod_mode
= false;
122 for (argidx
= 1; argidx
< args
.size(); argidx
++)
124 std::string arg
= args
[argidx
];
125 if (arg
== "-wire" || arg
== "-input" || arg
== "-inout" || arg
== "-output" || arg
== "-global_input") {
126 if (argidx
+2 >= args
.size())
129 if (arg
== "-input" || arg
== "-inout" || arg
== "-global_input")
130 arg_flag_input
= true;
131 if (arg
== "-output" || arg
== "-inout")
132 arg_flag_output
= true;
133 if (arg
== "-global_input")
134 arg_flag_global
= true;
135 arg_name
= args
[++argidx
];
136 arg_width
= atoi(args
[++argidx
].c_str());
148 for (; argidx
< args
.size(); argidx
++)
149 design
->addModule(RTLIL::escape_id(args
[argidx
]));
153 extra_args(args
, argidx
, design
);
155 for (auto module
: design
->modules())
157 log_assert(module
!= nullptr);
158 if (!design
->selected_whole_module(module
->name
))
160 if (module
->get_bool_attribute("\\blackbox"))
163 if (command
== "wire")
164 add_wire(design
, module
, arg_name
, arg_width
, arg_flag_input
, arg_flag_output
, arg_flag_global
);
169 PRIVATE_NAMESPACE_END