-
Notifications
You must be signed in to change notification settings - Fork 148
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
Verilog import fails in macro substitution #679
Comments
Oh wow. Yeah, this is a combination of a number of quirks, that come together to cause trouble. Sorry for that. It may be best to just write a script external to BSV which generates the BSV imports for all the modules. You could also see if the BH syntax allows expressing it better than BSV. But if you do want to try expressing this entirely in BSV, one workaround that I found is this:
I tried to make the unique ID implicit, by making it a macro definition that gets updated each time you call BSV's import-BVI syntax is really a wrapper around the very limited import that BSC supports in its internal representation. If you import a Verilog module into BSV with name In BH, the import of raw Verilog is an expression. BH users currently have to manually write the wrapper around an import. But this does provide extra flexibility, because the import is an expression, which can appear inside code, like functions. So you might be able to do this in BH using an ordinary function in place of the macro call. There are some features that BSV provides that BH's import does not (yet), around multiple clocks I think, but it looks like you're not doing anything advanced, so BH syntax might be sufficient. (Note that the wrapper does also include some additional internal code for recording the types of ports and user names, etc, which would need to be manually replicated if written in BH.) The BH import syntax even lets you construct the string for the Verilog module name, which BSV doesn't. So for example, this would be how to import multiple
In your case, the imported interface would seem to already be in raw form, so maybe BSC doesn't need to create There is already an open issue #386 asking to enhance the preprocessor to keep a stack of the multiple positions that result from macro calls. If that was supported, then the There may also be other ways to create unique names. But I think the line number was used because it helps the user connect the identifer back to their source code, if they saw it in a message from the compiler. |
Thank you for the elaborate reply! For now I will stick with the macro workaround. Once I get more into BH I may switch to the BH variant. I really like that you can construct the Verilog module name as string and pass it to the import. |
I have a use case where I have several Verilog modules which implement similar behavior, but their I/O bit widths differ and they are not parametrizable to the bit width. Apart from the interface, the
import "BVI"
-code does not depend on the bit widths.In order to save copy-paste code, I wanted to import all relevant Verilog modules using macro functions in BSV. However, the compiler fails due to conflicting interface declarations.
I built a minimum reproducing example based on the
FIFOF_
-imports. Here is the main part of it:I have a common generic interface:
and I want to bind a module with types
Bit#(8)
andBit#(16)
for type a. If I just hardcode the imports, everything works fine (FIFO1 is just the FIFO1 Verilog module with width set to 8 and FIFO1_16 sets width to 16):If I refactor common code into a macro I get:
The imports then should be obtainable by invoking:
I wrote a test module instantiating the imported FIFOs. However, it fails with the following error:
I checked the output of the preprocessor (by passing the
-E
flag to bsc) for the macro invocations and from my understanding, theline
directive sets the file and line information for the diagnostics messages to the specified values:This leads me to think, that during the second BVI import, the compiler declares an interface
FIFOF_67
according to the set source line number which then conflicts with the interface declared in the previousBIND_FIFO
macro invocation.Invoking the macro only once works, but then I wouldn't need a macro.
When I use the preprocessed code as input source file into the compiler, everything works, if I change the line number in the second
line(MWRE.bsv,65,42,1)
invocation to something arbitrarily different.Is there a way to get around this issue? My feeling is that the intention for the reset line numbers is to provide diagnostics for errors inside macros which makes complete sense from my point of view. Is it really necessary to re-declare interfaces for each imported Verilog module?
I attached my entire code (failing code, preprocessor output, verilog modules) to this issue. You can trigger the error with
Best,
Yannick
bvi_mwre.zip
The text was updated successfully, but these errors were encountered: