Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling inout port after flattening wrapper #771

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ add_custom_target(
COMMAND $(MAKE) install ${YOSYS_RS_PLUGIN_MK_ARGS}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/design_edit
COMMENT "Compile Yosys Design Edit plugin with given Makefile"
DEPENDS GeneratePrimitive
)
add_custom_target(
yosys-rs-plugin_clean
Expand All @@ -298,7 +299,6 @@ add_dependencies(yosys_clean yosys-rs-plugin_clean)

add_dependencies(pow_extract yosys)
add_dependencies(yosys_clean pow_extract_clean)
add_dependencies(design_edit rs_primitive)
add_dependencies(design_edit yosys )
add_dependencies(yosys_clean design_edit_clean)

Expand Down
53 changes: 53 additions & 0 deletions design_edit/src/rs_design_edit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ struct DesignEditRapidSilicon : public ScriptPass {
std::unordered_set<Wire *> orig_intermediate_wires;
std::unordered_set<Wire *> interface_intermediate_wires;
std::map<RTLIL::SigBit, std::vector<RTLIL::Wire *>> io_prim_conn;
std::map<RTLIL::SigBit, RTLIL::SigBit> inout_conn_map;
pool<SigBit> prim_out_bits;
pool<SigBit> unused_prim_outs;
pool<SigBit> used_bits;
Expand Down Expand Up @@ -585,6 +586,57 @@ struct DesignEditRapidSilicon : public ScriptPass {
}
}

void handle_inout_connection(Module* mod)
{
for(auto &conn : mod->connections())
{
std::vector<RTLIL::SigBit> conn_lhs = conn.first.to_sigbit_vector();
std::vector<RTLIL::SigBit> conn_rhs = conn.second.to_sigbit_vector();
bool remove_conn = false;
for (size_t i = 0; i < conn_lhs.size(); ++i)
{
if (conn_rhs[i].wire != nullptr)
if (conn_rhs[i].wire->port_input && conn_rhs[i].wire->port_output)
{
inout_conn_map[conn_lhs[i]] = conn_rhs[i];
remove_conn = true;
}
}
if (remove_conn)
{
connections_to_remove.insert(conn);
}
}

remove_extra_conns(mod);
connections_to_remove.clear();

for (auto cell : mod->cells())
{
for (auto conn : cell->connections())
{
IdString portName = conn.first;
bool unset_port = true;
RTLIL::SigSpec sigspec;
for (SigBit bit : conn.second)
{
if (inout_conn_map.count(bit) > 0)
{
if (unset_port)
{
cell->unsetPort(portName);
unset_port = false;
}
sigspec.append(inout_conn_map[bit]);
} else {
sigspec.append(bit);
}
}
if (!unset_port) cell->setPort(portName, sigspec);
}
}
}

void process_wire(Cell *cell, const IdString &portName, RTLIL::Wire *wire) {
if (cell->input(portName)) {
if (wire->port_input) {
Expand Down Expand Up @@ -1735,6 +1787,7 @@ struct DesignEditRapidSilicon : public ScriptPass {
new_design->add(interface_mod);
}
Pass::call(new_design, "flatten");
handle_inout_connection(wrapper_mod);

for (auto file : wrapper_files) {
std::string extension = get_extension(file);
Expand Down
Loading