macro issue #569
Replies: 6 comments 3 replies
-
Separate files are by default treated as separate compilation units, which means they don't see each other's macro definitions. If you want them to be treated as a single compilation unit (which is what verilator does by default) you can pass the --single-unit command line flag, which internally concatenates all of the files into a single source file. |
Beta Was this translation helpful? Give feedback.
-
After investigation, I think the root cause is identical. bool loadAllSources(Compilation& compilation, SourceManager& sourceManager,
const std::vector<SourceBuffer>& buffers, const Bag& options, bool singleUnit,
bool onlyLint, const std::vector<std::string>& libraryFiles,
const std::vector<std::string>& libDirs,
const std::vector<std::string>& libExts) {
if (singleUnit) {
// Ignored
} else {
// Ignored
}
// Ignored
// Keep loading new files as long as we are making forward progress.
flat_hash_set<string_view> nextMissingNames;
while (true) {
for (auto name : missingNames) {
// Ignored
if (buffer) {
auto tree = SyntaxTree::fromBuffer(buffer, sourceManager, options);
tree->isLibrary = true;
compilation.addSyntaxTree(tree);
}
}
}
} In my case, the buffers size is 1. so single unit doesn't take effect.
|
Beta Was this translation helpful? Give feedback.
-
I see, you are using library files loaded automatically on demand. Library files aren't part of the single unit by design, because they're a separate library. If you want them to be part of the single unit you can specify them all together on the command line. It's strange to want macros to propagate from other source files into library files, but I suppose that's a new feature that code be added. |
Beta Was this translation helpful? Give feedback.
-
My case comes from https://github.com/T-head-Semi/openc910/search?q=APB_BASE_ADDR |
Beta Was this translation helpful? Give feedback.
-
You can always use the -D command line flag to define macros that apply to all loaded units. If you want it to work with automatically loaded library units you'll have to wait for me to add a new feature to slang to support it -- can you create an issue to track that work? |
Beta Was this translation helpful? Give feedback.
-
Hi, I have a similar issue when using the command file. Typically, we will have a nested ".lst" file set (as vcs) in which the order is important for preprocessor dependencies. But currently, the commands does not seem to honor the order described in the lst files. Do you think it makes more sense to make the driver to parse the command files and commands in exact order that is described by the command files (.lst files) For example: I have two lst files:
Then the order of the source files for the preprocessor should be "a1.v, b1.v, b2.v, a2.v". In other words, in a recursive manner. Any comment on this scenario? Thanks. |
Beta Was this translation helpful? Give feedback.
-
I met an issue, ask for help.
Here is top.v
sub.v
In verilator, it works.
But in slang, it output
The root cause comes from
The macro is defined in top, and not propagate to sub. due to separate compilation.
My naive solution is put Preprocessor in the top level, like this
The solution would break API, I don't think it is a good method.
Another idea is putting Preprocessor into SourceManager.
Anyone have good idea?
Beta Was this translation helpful? Give feedback.
All reactions