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

Add -blackbox option to setundef pass #4812

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
29 changes: 29 additions & 0 deletions passes/cmds/setundef.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ struct SetundefPass : public Pass {
log(" -params\n");
log(" replace undef in cell parameters\n");
log("\n");
log(" -blackbox\n");
log(" remove instances of blackbox modules in selection and treat their\n");
log(" outputs as undef by calling `cutpoint -undef`\n");
log("\n");
}
void execute(std::vector<std::string> args, RTLIL::Design *design) override
{
Expand All @@ -155,6 +159,7 @@ struct SetundefPass : public Pass {
bool expose_mode = false;
bool init_mode = false;
bool params_mode = false;
bool blackbox_mode = false;
SetundefWorker worker;

log_header(design, "Executing SETUNDEF pass (replace undef values with defined constants).\n");
Expand Down Expand Up @@ -208,6 +213,10 @@ struct SetundefPass : public Pass {
params_mode = true;
continue;
}
if (args[argidx] == "-blackbox") {
blackbox_mode = true;
continue;
}
if (args[argidx] == "-random" && argidx+1 < args.size()) {
got_value++;
worker.next_bit_mode = MODE_RANDOM;
Expand All @@ -227,6 +236,13 @@ struct SetundefPass : public Pass {
worker.next_bit_state = 0;
}

if (!got_value && blackbox_mode) {
log("Using default as -undef with -blackbox.\n");
got_value++;
worker.next_bit_mode = MODE_UNDEF;
worker.next_bit_state = 0;
}

if (expose_mode && !undriven_mode)
log_cmd_error("Option -expose must be used with option -undriven.\n");
if (!got_value)
Expand All @@ -239,6 +255,19 @@ struct SetundefPass : public Pass {

for (auto module : design->selected_modules())
{
if (blackbox_mode)
{
RTLIL::Selection module_boxes(false);
for (auto *cell : module->selected_cells()) {
auto mod = design->module(cell->type);
if (mod != nullptr && mod->get_blackbox_attribute())
module_boxes.select(module, cell);
}
log_push();
call_on_selection(design, module_boxes, "cutpoint -undef");
log_pop();
}

if (params_mode)
{
for (auto *cell : module->selected_cells()) {
Expand Down
32 changes: 32 additions & 0 deletions tests/various/setundef_blackbox.ys
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
read_verilog -specify << EOT
module top(input a, b, output o);
wire c, d;
bb bb1 (.a (a), .b (b), .o (c));
wb wb1 (.a (a), .b (b), .o (d));
some_mod some_inst (.a (c), .b (d), .o (o));
endmodule

(* blackbox *)
module bb(input a, b, output o);
assign o = a | b;
specify
(a => o) = 1;
endspecify
endmodule

(* whitebox *)
module wb(input a, b, output o);
assign o = a ^ b;
endmodule

module some_mod(input a, b, output o);
assign o = a & b;
endmodule
EOT

select top

select -assert-count 2 =t:?b
setundef -blackbox -anyseq
select -assert-count 2 t:$anyseq
select -assert-count 0 =t:?b
Loading