-
Hi all, I am working right now in a code that looks like this: // Instantiate FIFO in case flag is set
FIFOF#(Bit#(10)) stats_fifo = ?;
if (mk_stats) begin
stats_fifo <- mkFIFOF();
end My questions are simple, in the section 9.1. Don’t-care expressions - BSV Reference Guide, it says:
`ifdef MK_STATS_FLAG
// Instantiate FIFO in case flag is set
FIFOF#(Bit#(10)) stats_fifo <- mkFIFOF();
`endif Thank you for your time, JM |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
An interface is not state, it is a value. An interface just a struct of functions. Usually, those functions are connected to state that you have instantiated, but the functions can also just be values that don't refer to any state. When you instantiate a module (with
At a statement like the above, new state is added to an implicit collection that BSC is building up behind the scenes, and what is returned from the instantiation (and assigned to the name on the left-hand side of the arrow) is an interface -- a struct -- whose methods are connected to the ports of that state. The interface itself does not have state. So, for example, you could write this:
This either instantiates real state or it returns an interface whose methods are defined as no-ops. You could also abstract this into a function:
Or it could be abstracted into a module with no state -- which is equivalent to a function:
What you've written assigns a don't-care value (
That is probably OK to write. It won't introduce any state. And in general, BSC will pick In expressions like this:
BSC is allowed to pick the don't-care value to be the same as the other branch, so that the entire if-condition can be removed, leaving just
Then BSC would be allowed to reduce this to
In your example, this situation may not come up. So it's probably OK to use |
Beta Was this translation helpful? Give feedback.
An interface is not state, it is a value. An interface just a struct of functions. Usually, those functions are connected to state that you have instantiated, but the functions can also just be values that don't refer to any state.
When you instantiate a module (with
<-
), that is when state is created:At a statement like the above, new state is added to an implicit collection that BSC is building up behind the scenes, and what is returned from the instantiation (and assigned to the name on the left-hand side of the arrow) is an interface -- a struct -- whose methods are connected to the ports of that state. The interface itself does not have state.
So, for example…