Skip to content

Commit

Permalink
setundef: Add -blackbox option
Browse files Browse the repository at this point in the history
If used, all instances of blackboxes in a module will be removed via `cutpoint -undef`.
The undef wires can then be handled as usual by `setundef`.
e.g. `setundef -blackbox -anyseq` will remove instances of blackboxes and replace their outputs with `$anyseq` cells.
  • Loading branch information
KrystalDelusion committed Dec 10, 2024
1 parent 4bd6061 commit 15b1423
Showing 1 changed file with 29 additions and 0 deletions.
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

0 comments on commit 15b1423

Please sign in to comment.