Skip to content

Commit

Permalink
ast: add PRIORITY to $print cells
Browse files Browse the repository at this point in the history
  • Loading branch information
charlottia authored and wanda-phi committed Aug 11, 2023
1 parent 4ffdee6 commit f9d3825
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
6 changes: 5 additions & 1 deletion docs/source/CHAPTER_CellLib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ has the following parameters:
True if triggered on specific signals defined in ``\TRG``; false if
triggered whenever ``\ARGS`` or ``\EN`` change and ``\EN`` is 1.

If ``\TRG_ENABLE`` is true, the following parameters are also set:
If ``\TRG_ENABLE`` is true, the following parameters also apply:

``\TRG_WIDTH``
The number of bits in the ``\TRG`` port.
Expand All @@ -653,6 +653,10 @@ If ``\TRG_ENABLE`` is true, the following parameters are also set:
For each bit in ``\TRG``, 1 if that signal is positive-edge triggered, 0 if
negative-edge triggered.

``\PRIORITY``
When multiple ``$print`` cells fire on the same trigger, they execute in
descending priority order.

Ports:

``\TRG``
Expand Down
6 changes: 5 additions & 1 deletion frontends/ast/genrtlil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,10 @@ struct AST_INTERNAL::ProcessGenerator
// Buffer for generating the init action
RTLIL::SigSpec init_lvalue, init_rvalue;

ProcessGenerator(AstNode *always, RTLIL::SigSpec initSyncSignalsArg = RTLIL::SigSpec()) : always(always), initSyncSignals(initSyncSignalsArg)
// The most recently assigned $print cell \PRIORITY.
int last_print_priority;

ProcessGenerator(AstNode *always, RTLIL::SigSpec initSyncSignalsArg = RTLIL::SigSpec()) : always(always), initSyncSignals(initSyncSignalsArg), last_print_priority(0)
{
// rewrite lookahead references
LookaheadRewriter la_rewriter(always);
Expand Down Expand Up @@ -716,6 +719,7 @@ struct AST_INTERNAL::ProcessGenerator
cell->parameters[ID::TRG_WIDTH] = triggers.size();
cell->parameters[ID::TRG_ENABLE] = !triggers.empty();
cell->parameters[ID::TRG_POLARITY] = polarity;
cell->parameters[ID::PRIORITY] = --last_print_priority;
cell->setPort(ID::TRG, triggers);

Wire *wire = current_module->addWire(sstr.str() + "_EN", 1);
Expand Down
1 change: 1 addition & 0 deletions kernel/rtlil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1724,6 +1724,7 @@ namespace {
param(ID(FORMAT));
param_bool(ID::TRG_ENABLE);
param(ID::TRG_POLARITY);
param(ID::PRIORITY);
port(ID::EN, 1);
port(ID::TRG, param(ID::TRG_WIDTH));
port(ID::ARGS, param(ID::ARGS_WIDTH));
Expand Down
1 change: 1 addition & 0 deletions techlibs/common/simlib.v
Original file line number Diff line number Diff line change
Expand Up @@ -1805,6 +1805,7 @@ module \$print (EN, TRG, ARGS);

parameter FORMAT = "";
parameter ARGS_WIDTH = 0;
parameter PRIORITY = 0;
parameter TRG_ENABLE = 1;

parameter TRG_WIDTH = 0;
Expand Down

0 comments on commit f9d3825

Please sign in to comment.