Skip to content

Commit 4d8032b

Browse files
committed
publish: add pass for renaming private cell types to public
1 parent aa1daa7 commit 4d8032b

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

passes/cmds/Makefile.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,4 @@ OBJS += passes/cmds/abstract.o
5757
OBJS += passes/cmds/test_select.o
5858
OBJS += passes/cmds/timeest.o
5959
OBJS += passes/cmds/linecoverage.o
60+
OBJS += passes/cmds/publish.o

passes/cmds/publish.cc

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include "kernel/register.h"
2+
#include "kernel/rtlil.h"
3+
#include "kernel/log.h"
4+
5+
USING_YOSYS_NAMESPACE
6+
PRIVATE_NAMESPACE_BEGIN
7+
8+
struct PublishPass : public Pass {
9+
private:
10+
static void publish(RTLIL::IdString& id) {
11+
if (id.begins_with("$")) {
12+
log_debug("publishing %s\n", id.c_str());
13+
id = "\\" + id.str();
14+
log_debug("published %s\n", id.c_str());
15+
}
16+
}
17+
public:
18+
PublishPass() : Pass("publish", "publish private cell types") { }
19+
void help() override
20+
{
21+
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
22+
log("\n");
23+
log(" publish\n");
24+
log("Makes all module names and cell types public by prefixing\n");
25+
log("%% with \\.\n");
26+
}
27+
void execute(std::vector<std::string> args, RTLIL::Design *design) override
28+
{
29+
log_header(design, "Executing PUBLISH pass. (make cell types public)\n");
30+
extra_args(args, 1, design);
31+
for (auto& [name, mod] : design->modules_) {
32+
publish(name);
33+
publish(mod->name);
34+
for (auto* cell : mod->cells())
35+
publish(cell->type);
36+
}
37+
}
38+
} PublishPass;
39+
40+
PRIVATE_NAMESPACE_END

0 commit comments

Comments
 (0)