slang::driver::SourceLoader class

Handles loading and parsing of groups of source files.

This class handles high-level descriptions of how to load and parse source files, such as via library mapping files or search directories to look in. The actual loading and parsing are delegated to classes like SourceManager and SyntaxTree.

Constructors, destructors, conversion operators

SourceLoader(SourceManager& sourceManager) explicit
Constructs a new instance of the SourceLoader class.

Public functions

void addBuffer(SourceBuffer buffer)
Adds a pre-loaded buffer.
void addFiles(std::string_view pattern)
Adds files to be loaded, specified via the given pattern.
void addLibraryFiles(std::string_view libraryName, std::string_view pattern)
Adds library files to be loaded, specified via the given pattern.
void addSearchDirectories(std::string_view pattern)
Adds directories in which to search for library module files, specified via the given pattern.
void addSearchExtension(std::string_view extension)
Adds an extension used to search for library module files.
void addLibraryMaps(std::string_view pattern, const std::filesystem::path& basePath, const Bag& optionBag)
Adds library map files to the loader.
void addSeparateUnit(std::span<const std::string> filePatterns, const std::vector<std::string>& includePaths, std::vector<std::string> defines, const std::string& libraryName)
Adds a group of files as a separately compiled compilation unit.
auto getLibraryMaps() const -> const SyntaxTreeList&
Returns a list of all library map syntax trees that have been loaded and parsed.
auto hasFiles() const -> bool
Returns true if there is at least one source file to load, and false if none have been added to the loader.
auto loadSources() -> std::vector<SourceBuffer>
Loads all of the sources that have been added to the loader, but does not parse them.
auto loadAndParseSources(const Bag& optionBag) -> SyntaxTreeList
Loads and parses all of the source files that have been added to the loader.
auto getErrors() const -> std::span<const std::string>
Gets the list of errors that have occurred while loading files.
auto getOrAddLibrary(std::string_view name) -> SourceLibrary*
Gets a pointer to the source library with the given name, or adds it if it does not exist.

Function documentation

void slang::driver::SourceLoader::addFiles(std::string_view pattern)

Adds files to be loaded, specified via the given pattern.

All of the files that match the pattern will be added for loading. If no files match and the pattern is actually just a specific filename an error will be issued.

void slang::driver::SourceLoader::addLibraryFiles(std::string_view libraryName, std::string_view pattern)

Adds library files to be loaded, specified via the given pattern.

All of the files that match the pattern will be added for loading. If no files match and the pattern is actually just a specific filename an error will be issued.

Library files differ from regular source files in that they are only considered "used" if referenced in the main source and their modules are not automatically instantiated.

void slang::driver::SourceLoader::addSearchDirectories(std::string_view pattern)

Adds directories in which to search for library module files, specified via the given pattern.

A search for a library module occurs when there are instantiations found for unknown modules (or interfaces or programs). The given directories will be searched for files with the missing module's name plus any registered search extensions.

void slang::driver::SourceLoader::addSearchExtension(std::string_view extension)

Adds an extension used to search for library module files.

A search for a library module occurs when there are instantiations found for unknown modules (or interfaces or programs). The search will be for files with the given extensions.

Note that the extensions ".v" and ".sv" are always automatically included in the search set.

void slang::driver::SourceLoader::addLibraryMaps(std::string_view pattern, const std::filesystem::path& basePath, const Bag& optionBag)

Adds library map files to the loader.

All files that match the given pattern will be loaded and parsed as if they were library map files. The libraries within those maps will be created and any files they reference will be included in the list to load.

void slang::driver::SourceLoader::addSeparateUnit(std::span<const std::string> filePatterns, const std::vector<std::string>& includePaths, std::vector<std::string> defines, const std::string& libraryName)

Adds a group of files as a separately compiled compilation unit.

Unlike files added via the addFiles method, files added here are all guaranteed to be grouped into a single compilation unit and use the provided options for preprocessor defines and include paths.

If the library name is provided the compilation unit will be included in the library of that name; otherwise it will be included in the default library and be considered a non-library unit.

std::vector<SourceBuffer> slang::driver::SourceLoader::loadSources()

Loads all of the sources that have been added to the loader, but does not parse them.

Returns the loaded buffers.

SourceLibrary* slang::driver::SourceLoader::getOrAddLibrary(std::string_view name)

Gets a pointer to the source library with the given name, or adds it if it does not exist.

Returns nullptr if name is empty.