Skip to content

Commit c768d5e

Browse files
committed
icell_liberty: start
1 parent 4d8032b commit c768d5e

File tree

2 files changed

+139
-0
lines changed

2 files changed

+139
-0
lines changed

passes/cmds/Makefile.inc

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

passes/cmds/icell_liberty.cc

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/*
2+
* yosys -- Yosys Open SYnthesis Suite
3+
*
4+
* Copyright (C) 2024 Martin Povišer <[email protected]>
5+
*
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.
9+
*
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.
17+
*
18+
*/
19+
#include "kernel/yosys.h"
20+
#include "kernel/celltypes.h"
21+
22+
USING_YOSYS_NAMESPACE
23+
PRIVATE_NAMESPACE_BEGIN
24+
25+
struct LibertyStubber {
26+
CellTypes ct;
27+
CellTypes ct_ff;
28+
LibertyStubber() {
29+
ct.setup();
30+
ct.setup_internals_ff();
31+
}
32+
void liberty_prefix(std::ostream& f)
33+
{
34+
f << "library (yosys) {\n";
35+
f << "\tinput_threshold_pct_fall : 50;\n";
36+
f << "\tinput_threshold_pct_rise : 50;\n";
37+
f << "\toutput_threshold_pct_fall : 50;\n";
38+
f << "\toutput_threshold_pct_rise : 50;\n";
39+
f << "\tslew_lower_threshold_pct_fall : 1;\n";
40+
f << "\tslew_lower_threshold_pct_rise : 1;\n";
41+
f << "\tslew_upper_threshold_pct_fall : 99;\n";
42+
f << "\tslew_upper_threshold_pct_rise : 99;\n";
43+
}
44+
void liberty_suffix(std::ostream& f)
45+
{
46+
f << "}\n";
47+
}
48+
void liberty_cell(Module* base, Module* derived, std::ostream& f)
49+
{
50+
auto base_name = base->name.str().substr(1);
51+
auto derived_name = derived->name.str().substr(1);
52+
if (!ct.cell_types.count(base_name)) {
53+
log_debug("skip skeleton for %s\n", base_name.c_str());
54+
return;
55+
}
56+
auto& base_type = ct.cell_types[base_name];
57+
f << "\tcell (\"" << derived_name << "\") {\n";
58+
for (auto x : derived->ports) {
59+
bool is_input = base_type.inputs.count(x);
60+
bool is_output = base_type.outputs.count(x);
61+
f << "\t\tpin (" << RTLIL::unescape_id(x.str()) << ") {\n";
62+
if (is_input && !is_output) {
63+
f << "\t\t\tdirection : input;\n";
64+
} else if (!is_input && is_output) {
65+
f << "\t\t\tdirection : output;\n";
66+
} else {
67+
f << "\t\t\tdirection : inout;\n";
68+
}
69+
f << "\t\t}\n";
70+
}
71+
f << "\t}\n";
72+
}
73+
};
74+
75+
struct IcellLiberty : Pass {
76+
IcellLiberty() : Pass("icell_liberty", "derive box modules") {}
77+
void help() override
78+
{
79+
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
80+
log("\n");
81+
log(" icell_liberty <liberty_file>\n"); // TODO
82+
log("\n");
83+
log("\n");
84+
}
85+
void execute(std::vector<std::string> args, RTLIL::Design *d) override
86+
{
87+
log_header(d, "Executing ICELL_LIBERTY pass.\n");
88+
89+
size_t argidx;
90+
IdString naming_attr;
91+
std::string liberty_filename;
92+
std::ofstream* liberty_file = new std::ofstream;
93+
94+
for (argidx = 1; argidx < args.size(); argidx++) {
95+
break;
96+
}
97+
if (argidx < args.size())
98+
liberty_filename = args[argidx++];
99+
else
100+
log_error("no Liberty filename specified\n");
101+
102+
// extra_args(args, argidx, d);
103+
104+
if (liberty_filename.size()) {
105+
liberty_file->open(liberty_filename.c_str());
106+
if (liberty_file->fail()) {
107+
delete liberty_file;
108+
log_error("Can't open file `%s' for writing: %s\n", liberty_filename.c_str(), strerror(errno));
109+
}
110+
}
111+
112+
pool<RTLIL::IdString> done;
113+
LibertyStubber stubber = {};
114+
115+
if (liberty_file)
116+
stubber.liberty_prefix(*liberty_file);
117+
118+
for (auto module : d->selected_modules()) {
119+
for (auto cell : module->selected_cells()) {
120+
Module *inst_module = d->module(cell->type);
121+
if (!inst_module || !inst_module->get_blackbox_attribute())
122+
continue;
123+
Module *base = inst_module;
124+
if (!done.count(base->name)) {
125+
stubber.liberty_cell(base, base, *liberty_file);
126+
done.insert(base->name);
127+
}
128+
}
129+
}
130+
131+
if (liberty_file) {
132+
stubber.liberty_suffix(*liberty_file);
133+
delete liberty_file;
134+
}
135+
}
136+
} IcellLiberty;
137+
138+
PRIVATE_NAMESPACE_END

0 commit comments

Comments
 (0)