From 0c6b629853553e33985b631a8289388b70445e5f Mon Sep 17 00:00:00 2001 From: HS Date: Wed, 7 Sep 2022 16:37:57 -0700 Subject: [PATCH] IO Abstraction: Introducing PathId & FileSystem (Phase 1) NOTE: This is only the first phase of the large goal of IO abstraction. Big picture goal is to abstract IO operations out of Surelog and into a class implementation that can be overriden by client application. This facilitates implementation of other more extensive features (like support for UNC paths, portale cache, multi-source root directories, cache archives, etc). Adding those directly to Surelog is not ideal since in many cases this features pull in other thrid-party dependecnies that might not have the same licensing terms as Surelog (and so leave it to the client/application to decide). Introducing two new classes - PathId & FileSystem PathId - New class parallel to SymbolId that represent path-like objects for IO operations. Each instance can represent a directory or a file but the internal representation doesn't necessarily have to be a _path_. For instance, in case of compressed archive of sources, it can be a string representation of the archive + the offset. The only enforcement is that the representation needs to be *printable* i.e. should be convertible to a string (since thee representation is stored in SymbolTable). For the advanced users. this limitation can very easily be overcome and is left as an exercise. FileSystem - This reroutes access to native file system or in special advanced cases can restrict access to the file system. All operations of PathId are meant to be routed thru' this class. This commit contains only the bare-bones of the implementation (to keep the rest of the change review-able). Follow up commit will add the real meat to this implementation. Most of this change is about switching from SymbolId to use of PathId where applicable. Some specific ones that may be of interest to the reviewer. * Restrict use of std::filesystem to minimal scope (functions where possible). Do NOT pass std::filesystem::path across function boundaries. Use PathId instead. * Do NOT cache unpinned strings, especially the ones that represent paths. Add them to the SymbolTable and resolve it on restore. * PreprocessFile::m_fileId used to represent both a file path (when processing a file) or a macro name (when processing a macro). This was a problem since now the path needs to be represented using PathId but the macro name is represented using SymbolId. So, added two independent variables PreprocessFile::m_macroId & PreprocessFile::m_fileId. --- .github/bin/run-clang-tidy.sh | 6 +- CMakeLists.txt | 5 + include/Surelog/API/PythonAPI.h | 13 +- include/Surelog/Cache/Cache.h | 33 +-- include/Surelog/Cache/PPCache.h | 17 +- include/Surelog/Cache/ParseCache.h | 11 +- include/Surelog/Cache/PythonAPICache.h | 7 +- .../Surelog/CommandLine/CommandLineParser.h | 148 +++++----- include/Surelog/Common/FileSystem.h | 70 +++++ include/Surelog/Common/NodeId.h | 2 +- include/Surelog/Common/PathId.h | 140 +++++++++ include/Surelog/Common/SymbolId.h | 36 ++- include/Surelog/Design/Design.h | 9 +- include/Surelog/Design/DesignComponent.h | 27 +- include/Surelog/Design/DesignElement.h | 5 +- include/Surelog/Design/FileContent.h | 31 +- include/Surelog/Design/LetStmt.h | 7 +- include/Surelog/Design/ModuleDefinition.h | 2 +- include/Surelog/Design/ModuleInstance.h | 4 +- include/Surelog/Design/TimeInfo.h | 6 +- include/Surelog/Design/VObject.h | 9 +- include/Surelog/Design/ValuedComponentI.h | 15 +- include/Surelog/DesignCompile/CompileDesign.h | 2 +- .../DesignCompile/CompileFileContent.h | 3 +- include/Surelog/DesignCompile/CompileHelper.h | 41 ++- .../DesignCompile/NetlistElaboration.h | 19 +- include/Surelog/DesignCompile/UhdmChecker.h | 18 +- include/Surelog/DesignCompile/UhdmWriter.h | 29 +- include/Surelog/ErrorReporting/Location.h | 15 +- include/Surelog/Library/Library.h | 12 +- include/Surelog/Library/LibrarySet.h | 2 +- include/Surelog/Library/ParseLibraryDef.h | 6 +- include/Surelog/Library/SVLibShapeListener.h | 9 +- include/Surelog/Package/Package.h | 7 +- include/Surelog/Package/Precompiled.h | 30 +- include/Surelog/SourceCompile/AnalyzeFile.h | 35 ++- .../SourceCompile/AntlrParserErrorListener.h | 9 +- .../SourceCompile/CommonListenerHelper.h | 2 +- .../Surelog/SourceCompile/CompilationUnit.h | 6 +- .../Surelog/SourceCompile/CompileSourceFile.h | 23 +- include/Surelog/SourceCompile/Compiler.h | 16 +- .../Surelog/SourceCompile/IncludeFileInfo.h | 6 +- include/Surelog/SourceCompile/MacroInfo.h | 17 +- include/Surelog/SourceCompile/ParseFile.h | 31 +- .../Surelog/SourceCompile/PreprocessFile.h | 47 ++- .../Surelog/SourceCompile/PreprocessHarness.h | 7 +- .../SV3_1aPpTreeListenerHelper.h | 2 +- .../SourceCompile/SV3_1aTreeShapeHelper.h | 8 +- include/Surelog/Testbench/ClassDefinition.h | 2 +- include/Surelog/Testbench/Program.h | 2 +- include/Surelog/Utils/FileUtils.h | 16 +- src/API/PythonAPI.cpp | 17 +- src/API/SLAPI.cpp | 51 ++-- src/API/Surelog.cpp | 2 +- src/Cache/Cache.cpp | 89 +++--- src/Cache/PPCache.cpp | 225 +++++++------- src/Cache/ParseCache.cpp | 127 ++++---- src/Cache/PythonAPICache.cpp | 74 ++--- src/Cache/preproc.fbs | 10 +- src/CommandLine/CommandLineParser.cpp | 261 +++++++++-------- src/Common/FileSystem.cpp | 91 ++++++ src/Common/PathId.cpp | 42 +++ src/Common/SymbolId.cpp | 31 ++ src/Design/Design.cpp | 7 +- src/Design/DesignElement.cpp | 2 +- src/Design/FileContent.cpp | 53 ++-- src/Design/ModuleInstance.cpp | 6 +- src/Design/VObject.cpp | 3 +- src/DesignCompile/Builtin.cpp | 3 +- src/DesignCompile/CompileClass.cpp | 124 ++++---- src/DesignCompile/CompileDesign.cpp | 47 +-- src/DesignCompile/CompileExpression.cpp | 155 +++++----- src/DesignCompile/CompileHelper.cpp | 80 ++--- src/DesignCompile/CompileModule.cpp | 92 +++--- src/DesignCompile/CompilePackage.cpp | 24 +- src/DesignCompile/CompileProgram.cpp | 24 +- src/DesignCompile/CompileStmt.cpp | 32 +- src/DesignCompile/CompileType.cpp | 100 ++++--- src/DesignCompile/DesignElaboration.cpp | 161 +++++----- src/DesignCompile/ElaborationStep.cpp | 24 +- src/DesignCompile/EvalFunc.cpp | 9 +- src/DesignCompile/NetlistElaboration.cpp | 81 +++-- src/DesignCompile/ResolveSymbols.cpp | 2 +- src/DesignCompile/TestbenchElaboration.cpp | 39 ++- src/DesignCompile/UhdmChecker.cpp | 68 +++-- src/DesignCompile/UhdmWriter.cpp | 66 +++-- src/ErrorReporting/ErrorContainer.cpp | 42 ++- src/ErrorReporting/Location.cpp | 19 +- src/ErrorReporting/Report.cpp | 8 +- src/Library/Library.cpp | 6 +- src/Library/LibrarySet.cpp | 8 +- src/Library/ParseLibraryDef.cpp | 45 ++- src/Library/SVLibShapeListener.cpp | 30 +- src/Package/Precompiled.cpp | 40 +-- src/SourceCompile/AnalyzeFile.cpp | 109 ++++--- .../AntlrParserErrorListener.cpp | 9 +- src/SourceCompile/CheckCompile.cpp | 28 +- src/SourceCompile/CommonListenerHelper.cpp | 2 +- src/SourceCompile/CompilationUnit.cpp | 6 +- src/SourceCompile/CompileSourceFile.cpp | 95 +++--- src/SourceCompile/Compiler.cpp | 202 +++++++------ src/SourceCompile/MacroInfo.cpp | 17 ++ src/SourceCompile/ParseFile.cpp | 58 ++-- src/SourceCompile/ParserHarness.cpp | 15 +- src/SourceCompile/PreprocessFile.cpp | 277 +++++++++--------- src/SourceCompile/PreprocessHarness.cpp | 8 +- .../SV3_1aPpTreeListenerHelper.cpp | 8 +- .../SV3_1aPpTreeShapeListener.cpp | 92 +++--- src/SourceCompile/SV3_1aTreeShapeHelper.cpp | 6 +- src/SourceCompile/SV3_1aTreeShapeListener.cpp | 25 +- src/Utils/FileUtils.cpp | 46 +-- src/Utils/FileUtils_test.cpp | 29 +- src/hellosureworld.cpp | 6 +- src/main.cpp | 4 +- src/roundtrip.cpp | 4 +- third_party/UHDM | 2 +- 116 files changed, 2483 insertions(+), 2010 deletions(-) create mode 100644 include/Surelog/Common/FileSystem.h create mode 100644 include/Surelog/Common/PathId.h create mode 100644 src/Common/FileSystem.cpp create mode 100644 src/Common/PathId.cpp create mode 100644 src/Common/SymbolId.cpp diff --git a/.github/bin/run-clang-tidy.sh b/.github/bin/run-clang-tidy.sh index f544431fc6..6d53d83a35 100755 --- a/.github/bin/run-clang-tidy.sh +++ b/.github/bin/run-clang-tidy.sh @@ -73,11 +73,11 @@ Checks: > CheckOptions: - key: performance-unnecessary-value-param.AllowedTypes - value: ::SURELOG::SymbolId;SURELOG::SymbolId;SymbolId;::SURELOG::NodeId;SURELOG::NodeId;NodeId + value: ::SURELOG::SymbolId;SURELOG::SymbolId;SymbolId;::SURELOG::NodeId;SURELOG::NodeId;NodeId;::SURELOG::PathId;SURELOG::PathId;PathId - key: performance-for-range-copy.AllowedTypes - value: ::SURELOG::SymbolId;SURELOG::SymbolId;SymbolId;::SURELOG::NodeId;SURELOG::NodeId;NodeId + value: ::SURELOG::SymbolId;SURELOG::SymbolId;SymbolId;::SURELOG::NodeId;SURELOG::NodeId;NodeId;::SURELOG::PathId;SURELOG::PathId;PathId - key: performance-unnecessary-copy-initialization.AllowedTypes - value: ::SURELOG::SymbolId;SURELOG::SymbolId;SymbolId;::SURELOG::NodeId;SURELOG::NodeId;NodeId + value: ::SURELOG::SymbolId;SURELOG::SymbolId;SymbolId;::SURELOG::NodeId;SURELOG::NodeId;NodeId;::SURELOG::PathId;SURELOG::PathId;PathId EOF CLANG_TIDY_OPTS="--config-file=${LOCAL_TMP}/clang-tidy" fi diff --git a/CMakeLists.txt b/CMakeLists.txt index 0889065d34..3859f2cab3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -274,6 +274,9 @@ set(surelog_SRC ${PROJECT_SOURCE_DIR}/src/Cache/ParseCache.cpp ${PROJECT_SOURCE_DIR}/src/CommandLine/CommandLineParser.cpp ${PROJECT_SOURCE_DIR}/src/Common/ClockingBlockHolder.cpp + ${PROJECT_SOURCE_DIR}/src/Common/FileSystem.cpp + ${PROJECT_SOURCE_DIR}/src/Common/PathId.cpp + ${PROJECT_SOURCE_DIR}/src/Common/SymbolId.cpp ${PROJECT_SOURCE_DIR}/src/Config/Config.cpp ${PROJECT_SOURCE_DIR}/src/Config/ConfigSet.cpp ${PROJECT_SOURCE_DIR}/src/Design/DataType.cpp @@ -697,7 +700,9 @@ install( install( FILES ${PROJECT_SOURCE_DIR}/include/Surelog/Common/ClockingBlockHolder.h ${PROJECT_SOURCE_DIR}/include/Surelog/Common/Containers.h + ${PROJECT_SOURCE_DIR}/include/Surelog/Common/FileSystem.h ${PROJECT_SOURCE_DIR}/include/Surelog/Common/NodeId.h + ${PROJECT_SOURCE_DIR}/include/Surelog/Common/PathId.h ${PROJECT_SOURCE_DIR}/include/Surelog/Common/PortNetHolder.h ${PROJECT_SOURCE_DIR}/include/Surelog/Common/RTTI.h ${PROJECT_SOURCE_DIR}/include/Surelog/Common/SymbolId.h diff --git a/include/Surelog/API/PythonAPI.h b/include/Surelog/API/PythonAPI.h index 09ab312084..e55c49cf7b 100644 --- a/include/Surelog/API/PythonAPI.h +++ b/include/Surelog/API/PythonAPI.h @@ -25,6 +25,7 @@ #define SURELOG_PYTHONAPI_H #pragma once +#include #include #include @@ -53,7 +54,7 @@ class PythonAPI { static void shutdown(PyThreadState* interp); static void loadScripts(); - static bool loadScript(const std::string& name, bool check = false); + static bool loadScript(const std::filesystem::path& name, bool check = false); static std::string evalScript(const std::string& module, const std::string& function, const std::vector& args, @@ -66,9 +67,10 @@ class PythonAPI { static void setListenerScript(std::string script) { m_listenerScript = script; } - static bool evalScriptPerFile(std::string script, ErrorContainer* errors, - FileContent* fC, PyThreadState* interp); - static bool evalScript(std::string script, Design* design); + static bool evalScriptPerFile(const std::filesystem::path& script, + ErrorContainer* errors, FileContent* fC, + PyThreadState* interp); + static bool evalScript(const std::filesystem::path& script, Design* design); static void setStrictMode(bool mode) { m_strictMode = mode; } private: @@ -76,7 +78,8 @@ class PythonAPI { static void initInterp_(); static void loadScriptsInInterp_(); - static bool loadScript_(const std::string& name, bool check = false); + static bool loadScript_(const std::filesystem::path& name, + bool check = false); static std::string m_invalidScriptResult; static PyThreadState* m_mainThreadState; static std::string m_programPath; diff --git a/include/Surelog/Cache/Cache.h b/include/Surelog/Cache/Cache.h index 36f80c8016..84c2f295ec 100644 --- a/include/Surelog/Cache/Cache.h +++ b/include/Surelog/Cache/Cache.h @@ -26,8 +26,7 @@ #pragma once #include -#include -#include +#include #include #include @@ -38,6 +37,7 @@ namespace SURELOG { class ErrorContainer; class FileContent; class SymbolTable; +class VObject; // A cache class used as a base for various other cashes persisting // things in flatbuffers. @@ -64,37 +64,32 @@ class Cache { const std::string& getExecutableTimeStamp(); // Open file and read contents into a buffer. - std::unique_ptr openFlatBuffers( - const std::filesystem::path& cacheFileName); + std::unique_ptr openFlatBuffers(PathId cacheFileId); bool saveFlatbuffers(flatbuffers::FlatBufferBuilder& builder, - const std::filesystem::path& cacheFileName); + PathId cacheFileId); bool checkIfCacheIsValid(const SURELOG::CACHE::Header* header, - std::string_view schemaVersion, - const std::filesystem::path& cacheFileName); + std::string_view schemaVersion, PathId cacheFileId); flatbuffers::Offset createHeader( flatbuffers::FlatBufferBuilder& builder, std::string_view schemaVersion, - const std::filesystem::path& origFileName); + PathId origFileId); // Store errors in cache. Canonicalize strings and store in "cacheSymbols". flatbuffers::Offset cacheErrors( flatbuffers::FlatBufferBuilder& builder, SymbolTable* cacheSymbols, const ErrorContainer* errorContainer, const SymbolTable& localSymbols, - SymbolId subjectId); + PathId subjectId); - // Given the symbol table (that we've accumulated while emitting cached - // items), convert it to a flatbuffer cache vector. - flatbuffers::Offset createSymbolCache( - flatbuffers::FlatBufferBuilder& builder, const SymbolTable& cacheSymbols); + void restoreSymbols(const VectorOffsetString* symbolBuf, + SymbolTable* cacheSymbols); // Restores errors and the cache symbol table (to be used in other restore // operations). // References in the error container to local symbols will be entered into // the local symbol table. void restoreErrors(const VectorOffsetError* errorsBuf, - const VectorOffsetString* symbolBuf, SymbolTable* cacheSymbols, ErrorContainer* errorContainer, SymbolTable* localSymbols); @@ -105,20 +100,20 @@ class Cache { std::vector cacheVObjects(const FileContent* fcontent, SymbolTable* cacheSymbols, const SymbolTable& localSymbols, - SymbolId fileId); + PathId fileId); // Restore objects coming from the flatbuffer cache and with the corresponding // "cacheSymbols" into "fileContent", with IDs relevant in the local // symbol table "localSymbols" (which is updated). void restoreVObjects( const flatbuffers::Vector* objects, - const SymbolTable& cacheSymbols, SymbolTable* localSymbols, - SymbolId fileId, FileContent* fileContent); + const SymbolTable& cacheSymbols, SymbolTable* localSymbols, PathId fileId, + FileContent* fileContent); void restoreVObjects( const flatbuffers::Vector* objects, - const SymbolTable& cacheSymbols, SymbolTable* localSymbols, - SymbolId fileId, std::vector* result); + const SymbolTable& cacheSymbols, SymbolTable* localSymbols, PathId fileId, + std::vector* result); private: Cache(const Cache& orig) = delete; diff --git a/include/Surelog/Cache/PPCache.h b/include/Surelog/Cache/PPCache.h index 83ab9eb097..1b95763fd5 100644 --- a/include/Surelog/Cache/PPCache.h +++ b/include/Surelog/Cache/PPCache.h @@ -27,8 +27,6 @@ #include -#include - namespace SURELOG { class PreprocessFile; @@ -43,15 +41,12 @@ class PPCache : Cache { private: PPCache(const PPCache& orig) = delete; - std::filesystem::path getCacheFileName_( - const std::filesystem::path& fileName = ""); - bool restore_(const std::filesystem::path& cacheFileName, bool errorsOnly, - int recursionDepth); - bool restore_(const std::filesystem::path& cacheFileName, - const std::unique_ptr& buffer, bool errorsOnly, - int recursionDepth); - bool checkCacheIsValid_(const std::filesystem::path& cacheFileName); - bool checkCacheIsValid_(const std::filesystem::path& cacheFileName, + PathId getCacheFileId_(PathId requestedFileId); + bool restore_(PathId cacheFileId, bool errorsOnly, int recursionDepth); + bool restore_(PathId cacheFileId, const std::unique_ptr& buffer, + bool errorsOnly, int recursionDepth); + bool checkCacheIsValid_(PathId cacheFileId); + bool checkCacheIsValid_(PathId cacheFileId, const std::unique_ptr& buffer); PreprocessFile* m_pp; diff --git a/include/Surelog/Cache/ParseCache.h b/include/Surelog/Cache/ParseCache.h index 6d3ec952d5..1e72e1c570 100644 --- a/include/Surelog/Cache/ParseCache.h +++ b/include/Surelog/Cache/ParseCache.h @@ -27,8 +27,6 @@ #include -#include - namespace SURELOG { class ParseFile; @@ -44,12 +42,9 @@ class ParseCache : Cache { private: ParseCache(const ParseCache& orig) = delete; - std::filesystem::path getCacheFileName_( - const std::filesystem::path& fileName = ""); - bool restore_(const std::filesystem::path& cacheFileName, - const std::unique_ptr& buffer); - bool checkCacheIsValid_(const std::filesystem::path& cacheFileName, - const std::unique_ptr& buffer); + PathId getCacheFileName_(PathId svFileNameId); + bool restore_(PathId cacheFileId, const std::unique_ptr& buffer); + bool checkCacheIsValid_(PathId cacheFileId, const std::unique_ptr& buffer); ParseFile* m_parse; bool m_isPrecompiled; diff --git a/include/Surelog/Cache/PythonAPICache.h b/include/Surelog/Cache/PythonAPICache.h index 16875f0601..e599dfe454 100644 --- a/include/Surelog/Cache/PythonAPICache.h +++ b/include/Surelog/Cache/PythonAPICache.h @@ -44,10 +44,9 @@ class PythonAPICache final : Cache { private: PythonAPICache(const PythonAPICache& orig) = delete; - std::filesystem::path getCacheFileName_( - const std::filesystem::path& fileName = "") const; - bool restore_(const std::filesystem::path& cacheFileName); - bool checkCacheIsValid_(const std::filesystem::path& cacheFileName); + PathId getCacheFileId_(PathId svFileNameId) const; + bool restore_(PathId cacheFileId); + bool checkCacheIsValid_(PathId cacheFileId); PythonListen* m_listener; }; diff --git a/include/Surelog/CommandLine/CommandLineParser.h b/include/Surelog/CommandLine/CommandLineParser.h index a829a03a76..d9d20f0333 100644 --- a/include/Surelog/CommandLine/CommandLineParser.h +++ b/include/Surelog/CommandLine/CommandLineParser.h @@ -25,9 +25,9 @@ #define SURELOG_COMMANDLINEPARSER_H #pragma once +#include #include -#include #include #include #include @@ -41,31 +41,21 @@ class SymbolTable; class CommandLineParser final { public: CommandLineParser(ErrorContainer* errors, SymbolTable* symbolTable, - bool diff_comp_mode = false, bool fileUnit = false); + bool diffCompMode = false, bool fileUnit = false); bool parseCommandLine(int argc, const char** argv); /* Verilog command line content */ - const std::vector& getLibraryPaths() const { - return m_libraryPaths; - } - const std::vector& getSourceFiles() const { return m_sourceFiles; } - const std::vector& getLibraryFiles() const { - return m_libraryFiles; - } - const std::vector& getLibraryExtensions() const { + const PathIdVector& getLibraryPaths() const { return m_libraryPaths; } + const PathIdVector& getSourceFiles() const { return m_sourceFiles; } + const PathIdVector& getLibraryFiles() const { return m_libraryFiles; } + const SymbolIdVector& getLibraryExtensions() const { return m_libraryExtensions; } - const std::vector& getIncludePaths() const { - return m_includePaths; - } - const std::vector& getOrdredLibraries() const { - return m_orderedLibraries; - } - const std::vector& getLibraryMapFiles() const { - return m_libraryMapFiles; - } - const std::vector& getConfigFiles() const { return m_configFiles; } - const std::vector& getUseConfigs() const { return m_useConfigs; } + const PathIdVector& getIncludePaths() const { return m_includePaths; } + const PathIdVector& getOrdredLibraries() const { return m_orderedLibraries; } + const PathIdVector& getLibraryMapFiles() const { return m_libraryMapFiles; } + const PathIdVector& getConfigFiles() const { return m_configFiles; } + const SymbolIdVector& getUseConfigs() const { return m_useConfigs; } const std::map& getDefineList() const { return m_defineList; @@ -75,19 +65,19 @@ class CommandLineParser final { return m_paramList; } bool fileunit() const { - return m_fileunit; + return m_fileUnit; } // File or all compilation semantic - void setFileUnit() { m_fileunit = true; } + void setFileUnit() { m_fileUnit = true; } /* PP Output file/dir options */ - SymbolId writePpOutputFileId() const { return m_writePpOutputFileId; } - SymbolId getOutputDir() const { return m_outputDir; } - SymbolId getCompileAllDir() const { return m_compileAllDirectory; } - SymbolId getCompileUnitDir() const { return m_compileUnitDirectory; } - SymbolId getCompileDir() const { - return fileunit() ? m_compileUnitDirectory : m_compileAllDirectory; + PathId writePpOutputFileId() const { return m_writePpOutputFileId; } + PathId getOutputDirId() const { return m_outputDirId; } + PathId getCompileAllDirId() const { return m_compileAllDirId; } + PathId getCompileUnitDirId() const { return m_compileUnitDirId; } + PathId getCompileDirId() const { + return fileunit() ? m_compileUnitDirId : m_compileAllDirId; } - SymbolId getFullCompileDir() const { return m_fullCompileDir; } - SymbolId getLogFileId() const { return m_logFileId; } + PathId getFullCompileDirId() const { return m_fullCompileDirId; } + PathId getLogFileId() const { return m_logFileId; } SymbolId getDefaultLogFileId() const { return m_defaultLogFileId; } bool writePpOutput() const { return m_writePpOutput; } void setwritePpOutput(bool value) { m_writePpOutput = value; } @@ -98,8 +88,8 @@ class CommandLineParser final { bool noCacheHash() const { return m_noCacheHash; } void setCacheAllowed(bool val) { m_cacheAllowed = val; } bool lineOffsetsAsComments() const { return m_lineOffsetsAsComments; } - SymbolId getCacheDir() const { return m_cacheDirId; } - SymbolId getPrecompiledDir() const { return m_precompiledDirId; } + PathId getCacheDirId() const { return m_cacheDirId; } + PathId getPrecompiledDirId() const { return m_precompiledDirId; } bool usePPOutputFileLocation() const { return m_ppOutputFileLocation; } /* PP Output content generation options */ bool filterFileLine() const { return m_filterFileLine; } @@ -146,7 +136,7 @@ class CommandLineParser final { bool elaborate() const { return m_elaborate; } bool writeUhdm() const { return m_writeUhdm; } bool sepComp() const { return m_sepComp; } - bool link() const { return m_link; } + bool link() const { return m_link; } void setParse(bool val) { m_parse = val; } void setParseOnly(bool val) { m_parseOnly = val; } void setLowMem(bool val) { m_lowMem = val; } @@ -190,15 +180,15 @@ class CommandLineParser final { bool pythonEvalScript() const { return m_pythonEvalScript && m_pythonAllowed; } - SymbolId pythonEvalScriptPerFileId() const { + PathId pythonEvalScriptPerFileId() const { return m_pythonEvalScriptPerFileId; } - SymbolId pythonEvalScriptId() const { return m_pythonEvalScriptId; } - SymbolId pythonListenerId() const { return m_pythonListenerFileId; } - const SymbolTable& getSymbolTable() const { return *m_symbolTable; } + PathId pythonEvalScriptId() const { return m_pythonEvalScriptId; } + PathId pythonListenerId() const { return m_pythonListenerFileId; } // There are some places that modify the command-line symbol table. - SymbolTable* mutableSymbolTable() const { return m_symbolTable; } + SymbolTable* getSymbolTable() { return m_symbolTable; } + const SymbolTable* getSymbolTable() const { return m_symbolTable; } /* Internal */ ErrorContainer* getErrorContainer() const { return m_errors; } @@ -213,20 +203,25 @@ class CommandLineParser final { std::string getTimeScale() const { return m_timescale; } bool createCache() const { return m_createCache; } std::string currentDateTime(); - bool parseBuiltIn(); - std::filesystem::path getBuiltInPath() const { return m_builtinPath; } - std::filesystem::path getExePath() const { return m_exePath; } + bool parseBuiltIn() const { return m_parseBuiltIn; } + PathId getProgramId() const { return m_programId; } std::string getExeCommand() const { return m_exeCommand; } std::set& getTopLevelModules() { return m_topLevelModules; } std::set& getBlackBoxModules() { return m_blackboxModules; } std::set& getBlackBoxInstances() { return m_blackboxInstances; } - void setTopLevelModule(const std::string& module) { m_topLevelModules.insert(module); } - void setBlackBoxModule(const std::string& module) { m_blackboxModules.insert(module); } - void setBlackBoxInstance(const std::string& instance) { m_blackboxInstances.insert(instance); } + void setTopLevelModule(const std::string& module) { + m_topLevelModules.insert(module); + } + void setBlackBoxModule(const std::string& module) { + m_blackboxModules.insert(module); + } + void setBlackBoxInstance(const std::string& instance) { + m_blackboxInstances.insert(instance); + } bool fullSVMode() const { return m_sverilog; } void fullSVMode(bool sverilog) { m_sverilog = sverilog; } - bool isSVFile(const std::filesystem::path& fileName) const; + bool isSVFile(PathId fileId) const; bool cleanCache(); private: @@ -237,7 +232,9 @@ class CommandLineParser final { void processArgs_(const std::vector& args, std::vector& container); void splitPlusArg_(const std::string& s, const std::string& prefix, - std::vector& container); + SymbolIdVector& container); + void splitPlusArg_(const std::string& s, const std::string& prefix, + PathIdVector& container); void splitPlusArg_( const std::string& s, const std::string& prefix, std::map& container); @@ -248,28 +245,28 @@ class CommandLineParser final { bool prepareCompilation_(int argc, const char** argv); bool setupCache_(); - std::vector m_libraryPaths; // -y - std::vector m_sourceFiles; // .v .sv - std::set m_svSourceFiles; // user forced sv files - std::vector m_libraryFiles; // -v - std::vector m_includePaths; // +incdir+ - SymbolIdSet m_includePathSet; - std::vector m_libraryExtensions; // +libext+ - std::vector m_orderedLibraries; // -L - std::vector m_libraryMapFiles; // -map - std::vector m_configFiles; // -cfgFile - std::vector m_useConfigs; // -cfg + PathIdVector m_libraryPaths; // -y + PathIdVector m_sourceFiles; // .v .sv + PathIdSet m_svSourceFiles; // user forced sv files + PathIdVector m_libraryFiles; // -v + PathIdVector m_includePaths; // +incdir+ + PathIdSet m_includePathSet; + SymbolIdVector m_libraryExtensions; // +libext+ + PathIdVector m_orderedLibraries; // -L + PathIdVector m_libraryMapFiles; // -map + PathIdVector m_configFiles; // -cfgFile + SymbolIdVector m_useConfigs; // -cfg std::map m_defineList; // +define+ std::map m_paramList; // -Pparameter=value - SymbolId m_writePpOutputFileId; + PathId m_writePpOutputFileId; bool m_writePpOutput; bool m_filterFileLine; int m_debugLevel; - ErrorContainer* m_errors; - SymbolTable* m_symbolTable; - SymbolId m_logFileId; + ErrorContainer* m_errors = nullptr; + SymbolTable* m_symbolTable = nullptr; + PathId m_logFileId; bool m_lineOffsetsAsComments; bool m_liborder; bool m_librescan; @@ -277,7 +274,7 @@ class CommandLineParser final { bool m_nolibcell; bool m_muteStdout; bool m_verbose; - bool m_fileunit; + bool m_fileUnit; bool m_filterSimpleDirectives; bool m_filterProtectedRegions; bool m_filterComments; @@ -287,20 +284,20 @@ class CommandLineParser final { bool m_elaborate; bool m_parametersubstitution; bool m_letexprsubstitution; - bool m_diff_comp_mode; + bool m_diffCompMode; bool m_help; bool m_cacheAllowed; bool m_debugCache; unsigned short int m_nbMaxTreads; unsigned short int m_nbMaxProcesses; - SymbolId m_compileUnitDirectory; - SymbolId m_compileAllDirectory; - SymbolId m_outputDir; - SymbolId m_fullCompileDir; + PathId m_compileUnitDirId; + PathId m_compileAllDirId; + PathId m_outputDirId; + PathId m_fullCompileDirId; SymbolId m_defaultLogFileId; - SymbolId m_defaultCacheDirId; - SymbolId m_cacheDirId; - SymbolId m_precompiledDirId; + PathId m_defaultCacheDirId; + PathId m_cacheDirId; + PathId m_precompiledDirId; bool m_note; bool m_info; bool m_warning; @@ -314,16 +311,15 @@ class CommandLineParser final { std::string m_timescale; bool m_pythonEvalScriptPerFile; bool m_pythonEvalScript; - SymbolId m_pythonEvalScriptPerFileId; - SymbolId m_pythonEvalScriptId; - SymbolId m_pythonListenerFileId; + PathId m_pythonEvalScriptPerFileId; + PathId m_pythonEvalScriptId; + PathId m_pythonListenerFileId; bool m_debugIncludeFileInfo; bool m_createCache; bool m_profile; bool m_parseBuiltIn; bool m_ppOutputFileLocation; - std::filesystem::path m_builtinPath; - std::filesystem::path m_exePath; + PathId m_programId; std::string m_exeCommand; std::set m_topLevelModules; std::set m_blackboxModules; diff --git a/include/Surelog/Common/FileSystem.h b/include/Surelog/Common/FileSystem.h new file mode 100644 index 0000000000..37114315a8 --- /dev/null +++ b/include/Surelog/Common/FileSystem.h @@ -0,0 +1,70 @@ +/* + Copyright 2022 chipsalliance + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +/* + * File: FileSystem.cpp + * Author: hs + * + * Created on June 1, 2022, 3:00 AM + */ + +#ifndef SURELOG_FILESYSTEM_H +#define SURELOG_FILESYSTEM_H +#pragma once + +#include +#include +#include + +namespace SURELOG { +class PathId; +class SymbolId; +class SymbolTable; + +class FileSystem { + public: + static FileSystem *getInstance(); + static FileSystem *setInstance(FileSystem *const fileSystem); + + public: + virtual PathId toPathId(const std::filesystem::path &path, + SymbolTable *const symbolTable); + virtual const std::string &toSymbol(PathId id); + virtual std::filesystem::path toPath(PathId id); + + virtual const std::filesystem::path &getCwd(); + virtual PathId getCwd(SymbolTable *const symbolTable); + + virtual PathId copy(PathId id, SymbolTable *const toSymbolTable); + + virtual ~FileSystem(); + + protected: + const std::filesystem::path m_cwd; + + private: + static FileSystem *sInstance; + + protected: + FileSystem(const std::filesystem::path &cwd); + + private: + FileSystem(const FileSystem &rhs) = delete; + FileSystem &operator=(const FileSystem &rhs) = delete; +}; +} // namespace SURELOG + +#endif // SURELOG_FILESYSTEM_H diff --git a/include/Surelog/Common/NodeId.h b/include/Surelog/Common/NodeId.h index 81d8851f6a..02e91b9cd6 100644 --- a/include/Surelog/Common/NodeId.h +++ b/include/Surelog/Common/NodeId.h @@ -117,4 +117,4 @@ typedef std::unordered_set } // namespace SURELOG -#endif // SURELOG_NODEID_H +#endif // SURELOG_NODEID_H \ No newline at end of file diff --git a/include/Surelog/Common/PathId.h b/include/Surelog/Common/PathId.h new file mode 100644 index 0000000000..9800c4b992 --- /dev/null +++ b/include/Surelog/Common/PathId.h @@ -0,0 +1,140 @@ +#ifndef SURELOG_PATHID_H +#define SURELOG_PATHID_H +#pragma once + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#if !defined(PATHID_DEBUG_ENABLED) +#if defined(DEBUG) || defined(_DEBUG) +#define PATHID_DEBUG_ENABLED 1 +#else +#define PATHID_DEBUG_ENABLED 0 +#endif +#endif + +namespace SURELOG { +typedef uint32_t RawPathId; +inline static constexpr RawPathId BadRawPathId = 0; +inline static constexpr std::string_view BadRawPath = BadRawSymbol; + +class SymbolTable; + +class PathId final { + public: +#if PATHID_DEBUG_ENABLED + PathId() + : m_symbolTable(nullptr), m_id(BadRawPathId), m_value(BadRawPath) {} + PathId(const SymbolTable *const symbolTable, RawPathId id, + std::string_view value) + : m_symbolTable(symbolTable), m_id(id), m_value(value) {} + PathId(const PathId &rhs) + : PathId(rhs.m_symbolTable, rhs.m_id, rhs.m_value) {} + PathId(const SymbolTable *const symbolTable, SymbolId id) + : PathId(symbolTable, id.id, id.value) {} +#else + PathId() : m_symbolTable(nullptr), m_id(BadRawPathId) {} + PathId(const SymbolTable *const symbolTable, RawPathId id, + std::string_view value) + : m_symbolTable(symbolTable), m_id(id) {} + PathId(const PathId &rhs) + : PathId(rhs.m_symbolTable, rhs.m_id, BadRawPath) {} + PathId(const SymbolTable *const symbolTable, SymbolId id) + : PathId(symbolTable, id.id, BadRawPath) {} +#endif + + PathId &operator=(const PathId &rhs) { + if (this != &rhs) { + m_symbolTable = rhs.m_symbolTable; + m_id = rhs.m_id; +#if PATHID_DEBUG_ENABLED + m_value = rhs.m_value; +#endif + } + return *this; + } + + const SymbolTable *getSymbolTable() const { return m_symbolTable; } + + explicit operator RawPathId() const { return m_id; } + explicit operator bool() const { return m_id != BadRawPathId; } +#if PATHID_DEBUG_ENABLED + explicit operator SymbolId() const { return SymbolId(m_id, m_value); } +#else + explicit operator SymbolId() const { return SymbolId(m_id, BadRawPath); } +#endif + + bool operator==(const PathId &rhs) const; + bool operator!=(const PathId &rhs) const { return !operator==(rhs); } + + private: + const SymbolTable *m_symbolTable = nullptr; + RawPathId m_id = BadRawPathId; +#if PATHID_DEBUG_ENABLED + std::string_view m_value; +#endif + + friend class SymbolId; + friend std::istream &operator>>(std::istream &strm, PathId &pathId); + friend std::ostream &operator<<(std::ostream &strm, const PathId &pathId); +}; + +inline static const PathId BadPathId(nullptr, BadRawPathId, BadRawPath); + +inline SymbolId::SymbolId(const PathId &rhs) +#if SYMBOLID_DEBUG_ENABLED + : id(rhs.m_id), value(rhs.m_value) {} +#else + : id(rhs.m_id) {} +#endif + +inline std::istream &operator>>(std::istream &strm, PathId &pathId) { + return strm >> pathId.m_id; +} + +inline std::ostream &operator<<(std::ostream &strm, const PathId &pathId) { + return strm << pathId.m_id; +} + +struct PathIdPP final { // Pretty Printer + const PathId &m_id; + + PathIdPP(const PathId &id) : m_id(id) {} +}; + +std::ostream &operator<<(std::ostream &strm, const PathIdPP &id); + +struct PathIdHasher final { + inline size_t operator()(const PathId &value) const { + return std::hash()((RawPathId)value); + } +}; + +struct PathIdEqualityComparer final { + inline bool operator()(const PathId &lhs, const PathId &rhs) const { + return (lhs == rhs); + } +}; + +struct PathIdLessThanComparer final { + inline bool operator()(const PathId &lhs, const PathId &rhs) const { + return ((RawPathId)lhs < (RawPathId)rhs); + } +}; + +typedef std::set PathIdSet; +typedef std::unordered_set + PathIdUnorderedSet; +typedef std::vector PathIdVector; + +} // namespace SURELOG + +#endif // SURELOG_PATHID_H diff --git a/include/Surelog/Common/SymbolId.h b/include/Surelog/Common/SymbolId.h index e9ef5476a6..626771c40c 100644 --- a/include/Surelog/Common/SymbolId.h +++ b/include/Surelog/Common/SymbolId.h @@ -7,6 +7,7 @@ #include #include #include +#include #if !defined(SYMBOLID_DEBUG_ENABLED) #if defined(DEBUG) || defined(_DEBUG) @@ -22,33 +23,28 @@ namespace SURELOG { * * Used to uniquely represent a string in SymbolTable. SymbolId can (and * should) be resolved only with the SymbolTable that it was generated with. - * + * */ typedef uint32_t RawSymbolId; inline static constexpr RawSymbolId BadRawSymbolId = 0; inline static constexpr std::string_view BadRawSymbol = "@@BAD_SYMBOL@@"; + +class PathId; +class SymbolTable; + class SymbolId final { public: #if SYMBOLID_DEBUG_ENABLED SymbolId() : id(BadRawSymbolId), value(BadRawSymbol) {} - SymbolId(RawSymbolId id, std::string_view value) - : id(id) - , value(value) - { - } + SymbolId(RawSymbolId id, std::string_view value) : id(id) , value(value) {} + SymbolId(const SymbolId &rhs) : id(rhs.id), value(rhs.value) {} #else SymbolId() : id(BadRawSymbolId) {} - explicit SymbolId(RawSymbolId id) : id(id) {} SymbolId(RawSymbolId id, std::string_view value) : id(id) {} + SymbolId(const SymbolId &rhs) : id(rhs.id) {} #endif - SymbolId(const SymbolId &rhs) - : id(rhs.id) -#if SYMBOLID_DEBUG_ENABLED - , value(rhs.value) -#endif - { - } + explicit SymbolId(const PathId &rhs); // Implementation in Path.h SymbolId &operator=(const SymbolId &rhs) { if (this != &rhs) { @@ -72,6 +68,7 @@ class SymbolId final { std::string_view value; #endif + friend class PathId; friend std::ostream &operator<<(std::ostream &strm, const SymbolId &symbolId); }; @@ -86,6 +83,16 @@ inline std::ostream &operator<<(std::ostream &strm, const SymbolId &symbolId) { return strm; } +struct SymbolIdPP final { // Pretty Printer + const SymbolId &id; + const SymbolTable *const symbolTable; + + SymbolIdPP(const SymbolId &id, const SymbolTable *const symbolTable) + : id(id), symbolTable(symbolTable) {} +}; + +std::ostream &operator<<(std::ostream &strm, const SymbolIdPP &id); + struct SymbolIdHasher final { inline size_t operator()(const SymbolId &value) const { return std::hash()((RawSymbolId)value); @@ -107,6 +114,7 @@ struct SymbolIdLessThanComparer final { typedef std::set SymbolIdSet; typedef std::unordered_set SymbolIdUnorderedSet; +typedef std::vector SymbolIdVector; } // namespace SURELOG diff --git a/include/Surelog/Design/Design.h b/include/Surelog/Design/Design.h index 42ca8d2e2f..5b924b5bbf 100644 --- a/include/Surelog/Design/Design.h +++ b/include/Surelog/Design/Design.h @@ -27,7 +27,7 @@ #include #include -#include +#include #include #include @@ -52,7 +52,6 @@ class ParseCache; class ParseFile; class PPCache; class PreprocessFile; -class SymbolId; class SV3_1aPpTreeShapeListener; class SV3_1aTreeShapeListener; class SVLibShapeListener; @@ -80,7 +79,7 @@ class Design final { ~Design(); - typedef std::vector> FileIdDesignContentMap; + typedef std::vector> FileIdDesignContentMap; // TODO: Unfortunately, all these need to be non-const, as there is code // on the receiving end is not using const stringently enough. @@ -167,10 +166,10 @@ class Design final { protected: // Thread-safe - void addFileContent(SymbolId fileId, FileContent* content); + void addFileContent(PathId fileId, FileContent* content); // Thread-safe - void addPPFileContent(SymbolId fileId, FileContent* content); + void addPPFileContent(PathId fileId, FileContent* content); void addOrderedPackage(const std::string& packageName) { m_orderedPackageNames.push_back(packageName); diff --git a/include/Surelog/Design/DesignComponent.h b/include/Surelog/Design/DesignComponent.h index 9d48d3ce3d..2df83c7259 100644 --- a/include/Surelog/Design/DesignComponent.h +++ b/include/Surelog/Design/DesignComponent.h @@ -26,6 +26,7 @@ #pragma once #include +#include #include #include #include @@ -36,8 +37,6 @@ // UHDM #include -#include - namespace SURELOG { class DataType; @@ -53,17 +52,16 @@ class Variable; class ExprEval { public: - ExprEval(UHDM::expr* expr, ValuedComponentI* instance, - const std::filesystem::path& fileName, int lineNumber, - UHDM::any* pexpr) + ExprEval(UHDM::expr* expr, ValuedComponentI* instance, PathId fileId, + int lineNumber, UHDM::any* pexpr) : m_expr(expr), m_instance(instance), - m_fileName(fileName), + m_fileId(fileId), m_lineNumber(lineNumber), m_pexpr(pexpr) {} UHDM::expr* m_expr; ValuedComponentI* m_instance; - std::filesystem::path m_fileName; + PathId m_fileId; int m_lineNumber; UHDM::any* m_pexpr; }; @@ -78,7 +76,7 @@ class DesignComponent : public ValuedComponentI, public PortNetHolder { virtual unsigned int getSize() const = 0; virtual VObjectType getType() const = 0; virtual bool isInstance() const = 0; - virtual const std::string& getName() const = 0; + virtual std::string getName() const = 0; void append(DesignComponent*); typedef std::map DataTypeMap; @@ -92,7 +90,9 @@ class DesignComponent : public ValuedComponentI, public PortNetHolder { typedef std::vector ParameterVec; typedef std::vector ParamAssignVec; typedef std::map LetStmtMap; - typedef std::map, StringViewCompare> NamedObjectMap; + typedef std::map, + StringViewCompare> + NamedObjectMap; void addFileContent(const FileContent* fileContent, NodeId nodeId); const std::vector& getFileContents() const { @@ -106,9 +106,7 @@ class DesignComponent : public ValuedComponentI, public PortNetHolder { void addNamedObject(std::string_view name, FileCNodeId object, DesignComponent* def = nullptr); - const NamedObjectMap& getNamedObjects() const { - return m_namedObjects; - } + const NamedObjectMap& getNamedObjects() const { return m_namedObjects; } const std::pair* getNamedObject( std::string_view name) const; @@ -149,7 +147,9 @@ class DesignComponent : public ValuedComponentI, public PortNetHolder { void addParamAssign(ParamAssign* assign) { m_paramAssigns.push_back(assign); } const ParamAssignVec& getParamAssignVec() const { return m_paramAssigns; } - void addImportedSymbol(UHDM::import_typespec* i) { m_imported_symbols.push_back(i); } + void addImportedSymbol(UHDM::import_typespec* i) { + m_imported_symbols.push_back(i); + } const std::vector& getImportedSymbols() const { return m_imported_symbols; } @@ -182,6 +182,7 @@ class DesignComponent : public ValuedComponentI, public PortNetHolder { LetStmt* getLetStmt(std::string_view name); const LetStmtMap& getLetStmts() const { return m_letDecls; } + protected: std::vector m_fileContents; std::vector m_nodeIds; diff --git a/include/Surelog/Design/DesignElement.h b/include/Surelog/Design/DesignElement.h index 5997a8d928..48798e2185 100644 --- a/include/Surelog/Design/DesignElement.h +++ b/include/Surelog/Design/DesignElement.h @@ -26,6 +26,7 @@ #pragma once #include +#include #include #include @@ -51,12 +52,12 @@ class DesignElement final { SLline // Used to split files with correct file info }; - DesignElement(SymbolId name, SymbolId fileId, ElemType type, NodeId uniqueId, + DesignElement(SymbolId name, PathId fileId, ElemType type, NodeId uniqueId, unsigned int line, unsigned short column, unsigned int endLine, unsigned short endColumn, NodeId parent); SymbolId m_name; - SymbolId m_fileId; + PathId m_fileId; const ElemType m_type; const NodeId m_uniqueId; const unsigned int m_line; diff --git a/include/Surelog/Design/FileContent.h b/include/Surelog/Design/FileContent.h index f2522e5825..a0191c961e 100644 --- a/include/Surelog/Design/FileContent.h +++ b/include/Surelog/Design/FileContent.h @@ -47,9 +47,8 @@ class Program; class FileContent : public DesignComponent { SURELOG_IMPLEMENT_RTTI(FileContent, DesignComponent) public: - FileContent(SymbolId fileId, Library* library, SymbolTable* symbolTable, - ErrorContainer* errors, FileContent* parent, - SymbolId fileChunkId); + FileContent(PathId fileId, Library* library, SymbolTable* symbolTable, + ErrorContainer* errors, FileContent* parent, PathId fileChunkId); ~FileContent() override = default; void setLibrary(Library* lib) { m_library = lib; } @@ -98,7 +97,7 @@ class FileContent : public DesignComponent { unsigned int getSize() const override { return m_objects.size(); } VObjectType getType() const override { return VObjectType::slNoType; } bool isInstance() const override { return false; } - const std::string& getName() const override; + std::string getName() const override; NodeId getRootNode() const; std::string printObjects() const; // The whole file content std::string printSubTree( @@ -106,18 +105,16 @@ class FileContent : public DesignComponent { std::string printObject(NodeId noedId) const; // Only print that object std::vector collectSubTree( NodeId uniqueId) const; // Helper function - std::filesystem::path getFileName(NodeId id) const; - std::filesystem::path getChunkFileName() const; SymbolTable* getSymbolTable() const { return m_symbolTable; } void setSymbolTable(SymbolTable* table) { m_symbolTable = table; } - SymbolId getFileId(NodeId id) const; - SymbolId* getMutableFileId(NodeId id); + PathId getFileId(NodeId id) const; + PathId* getMutableFileId(NodeId id); Library* getLibrary() const { return m_library; } std::vector& getDesignElements() { return m_elements; } void addDesignElement(const std::string& name, DesignElement* elem); const DesignElement* getDesignElement(std::string_view name) const; using DesignComponent::addObject; - NodeId addObject(SymbolId name, SymbolId fileId, VObjectType type, + NodeId addObject(SymbolId name, PathId fileId, VObjectType type, unsigned int line, unsigned short column, unsigned int endLine, unsigned short endColumn, NodeId parent = InvalidNodeId, @@ -146,8 +143,8 @@ class FileContent : public DesignComponent { NodeId Definition(NodeId index) const; - void SetDefinitionFile(NodeId index, SymbolId def); - SymbolId GetDefinitionFile(NodeId index) const; + void SetDefinitionFile(NodeId index, PathId def); + PathId GetDefinitionFile(NodeId index) const; NodeId Parent(NodeId index) const; @@ -205,12 +202,12 @@ class FileContent : public DesignComponent { const FileContent* getParent() const { return m_parentFile; } void setParent(FileContent* parent) { m_parentFile = parent; } - std::filesystem::path getFileName() const; - bool diffTree(NodeId id, const FileContent* oFc, NodeId oId, std::string* diff_out) const; - SymbolId getSymbolId() const { return m_fileId; } + PathId getFileId() const { return m_fileId; } + PathId getChunkFileId() const { return m_fileChunkId; } + bool isLibraryCellFile() const { return m_isLibraryCellFile; } void setLibraryCellFile() { m_isLibraryCellFile = true; } @@ -221,7 +218,7 @@ class FileContent : public DesignComponent { std::vector m_elements; std::map m_elementMap; std::vector m_objects; - std::unordered_map + std::unordered_map m_definitionFiles; NameIdMap m_objectLookup; // Populated at ResolveSymbol stage @@ -235,8 +232,8 @@ class FileContent : public DesignComponent { ClassNameClassDefinitionMultiMap m_classDefinitions; - const SymbolId m_fileId; - const SymbolId m_fileChunkId; + const PathId m_fileId; + const PathId m_fileChunkId; ErrorContainer* const m_errors; Library* m_library; // TODO: should be set in constructor and *const diff --git a/include/Surelog/Design/LetStmt.h b/include/Surelog/Design/LetStmt.h index 0cfeb51354..a543bc14ee 100644 --- a/include/Surelog/Design/LetStmt.h +++ b/include/Surelog/Design/LetStmt.h @@ -28,8 +28,8 @@ #include // UHDM -#include #include +#include #include #include @@ -40,11 +40,14 @@ class FileContent; class LetStmt final { public: - LetStmt(UHDM::let_decl* decl, UHDM::VectorOfseq_formal_decl* ios, UHDM::expr* expr) : m_decl(decl), m_ios(ios), m_expr(expr) {} + LetStmt(UHDM::let_decl* decl, UHDM::VectorOfseq_formal_decl* ios, + UHDM::expr* expr) + : m_decl(decl), m_ios(ios), m_expr(expr) {} ~LetStmt() = default; const UHDM::let_decl* Decl() { return m_decl; } const UHDM::VectorOfseq_formal_decl* Ios() { return m_ios; } const UHDM::expr* Expr() { return m_expr; } + private: UHDM::let_decl* m_decl; UHDM::VectorOfseq_formal_decl* m_ios; diff --git a/include/Surelog/Design/ModuleDefinition.h b/include/Surelog/Design/ModuleDefinition.h index ed3c24542c..659a2dd9f8 100644 --- a/include/Surelog/Design/ModuleDefinition.h +++ b/include/Surelog/Design/ModuleDefinition.h @@ -52,7 +52,7 @@ class ModuleDefinition : public DesignComponent, public ClockingBlockHolder { ~ModuleDefinition() override = default; - const std::string& getName() const override { return m_name; } + std::string getName() const override { return m_name; } VObjectType getType() const override; bool isInstance() const override; unsigned int getSize() const override; diff --git a/include/Surelog/Design/ModuleInstance.h b/include/Surelog/Design/ModuleInstance.h index c6d257d8d2..8b6340d065 100644 --- a/include/Surelog/Design/ModuleInstance.h +++ b/include/Surelog/Design/ModuleInstance.h @@ -39,6 +39,7 @@ class FileContent; class ModuleInstance; class Netlist; class Parameter; +class PathId; class SymbolId; class SymbolTable; @@ -74,8 +75,7 @@ class ModuleInstance : public ValuedComponentI { } ModuleInstance* getParent() const { return m_parent; } const FileContent* getFileContent() const { return m_fileContent; } - SymbolId getFileId() const; - std::filesystem::path getFileName() const; + PathId getFileId() const; NodeId getNodeId() const { return m_nodeId; } unsigned int getLineNb() const; unsigned short getColumnNb() const; diff --git a/include/Surelog/Design/TimeInfo.h b/include/Surelog/Design/TimeInfo.h index 64915492f4..911c5d0c05 100644 --- a/include/Surelog/Design/TimeInfo.h +++ b/include/Surelog/Design/TimeInfo.h @@ -25,7 +25,7 @@ #define SURELOG_TIMEINFO_H #pragma once -#include +#include #include #include @@ -45,7 +45,7 @@ class TimeInfo final { }; Type m_type = Type::None; - SymbolId m_fileId = BadSymbolId; + PathId m_fileId; unsigned int m_line = 0; Unit m_timeUnit = Unit::Second; double m_timeUnitValue = 0.0; @@ -59,7 +59,7 @@ class TimeInfo final { class NetTypeInfo final { public: VObjectType m_type = slNoType; - SymbolId m_fileId = BadSymbolId; + PathId m_fileId; unsigned int m_line = 0; }; diff --git a/include/Surelog/Design/VObject.h b/include/Surelog/Design/VObject.h index 3a30071759..61b24d6b52 100644 --- a/include/Surelog/Design/VObject.h +++ b/include/Surelog/Design/VObject.h @@ -26,6 +26,7 @@ #pragma once #include +#include #include #include @@ -38,14 +39,14 @@ class SymbolTable; class VObject final { public: - VObject(SymbolId name, SymbolId fileId, VObjectType type, unsigned int line, + VObject(SymbolId name, PathId fileId, VObjectType type, unsigned int line, unsigned short column, unsigned int endLine, unsigned short endColumn, NodeId parent = InvalidNodeId) : VObject(name, fileId, type, line, column, endLine, endColumn, parent, InvalidNodeId /* definition */, InvalidNodeId /* child */, InvalidNodeId /* sibling */) {} - VObject(SymbolId name, SymbolId fileId, VObjectType type, unsigned int line, + VObject(SymbolId name, PathId fileId, VObjectType type, unsigned int line, unsigned short column, unsigned int endLine, unsigned short endColumn, NodeId parent, NodeId definition, NodeId child, NodeId sibling) : m_name(name), @@ -63,10 +64,10 @@ class VObject final { static std::string_view getTypeName(VObjectType type); std::string print(SymbolTable* symbols, NodeId uniqueId, - SymbolId definitionFile, SymbolId printedFile) const; + PathId definitionFile, PathId printedFile) const; SymbolId m_name; - SymbolId m_fileId; + PathId m_fileId; VObjectType m_type; unsigned short m_column = 0; unsigned short m_endColumn = 0; diff --git a/include/Surelog/Design/ValuedComponentI.h b/include/Surelog/Design/ValuedComponentI.h index 66f0f43b6e..8f818be854 100644 --- a/include/Surelog/Design/ValuedComponentI.h +++ b/include/Surelog/Design/ValuedComponentI.h @@ -25,8 +25,8 @@ #define SURELOG_VALUEDCOMPONENTI_H #pragma once -#include #include +#include // UHDM #include @@ -43,7 +43,8 @@ class Value; class ValuedComponentI : public RTTI { SURELOG_IMPLEMENT_RTTI(ValuedComponentI, RTTI) public: - using ParamMap = std::map, StringViewCompare>; + using ParamMap = + std::map, StringViewCompare>; using ComplexValueMap = std::map; ValuedComponentI(const ValuedComponentI* parentScope, @@ -55,22 +56,18 @@ class ValuedComponentI : public RTTI { virtual Value* getValue(std::string_view name) const; virtual Value* getValue(std::string_view name, ExprBuilder& exprBuilder) const; - virtual void setValue(std::string_view name, Value* val, // NOLINT + virtual void setValue(std::string_view name, Value* val, // NOLINT ExprBuilder& exprBuilder, int lineNb = 0); virtual void deleteValue(std::string_view name, ExprBuilder& exprBuilder); virtual void forgetValue(std::string_view name); - const ParamMap& getMappedValues() const { - return m_paramMap; - } + const ParamMap& getMappedValues() const { return m_paramMap; } const ValuedComponentI* getParentScope() const { return m_parentScope; } void setParentScope(ValuedComponentI* parent) { m_parentScope = parent; } virtual void setComplexValue(std::string_view name, UHDM::expr* val); virtual UHDM::expr* getComplexValue(std::string_view name) const; virtual void forgetComplexValue(std::string_view name); - const ComplexValueMap& getComplexValues() const { - return m_complexValues; - } + const ComplexValueMap& getComplexValues() const { return m_complexValues; } // Do not change the signature of this method, it's use in gdb for debug. virtual std::string decompile(char* valueName) { return "Undefined"; } diff --git a/include/Surelog/DesignCompile/CompileDesign.h b/include/Surelog/DesignCompile/CompileDesign.h index 2258a1f1b7..7d2b1a9f6f 100644 --- a/include/Surelog/DesignCompile/CompileDesign.h +++ b/include/Surelog/DesignCompile/CompileDesign.h @@ -49,7 +49,7 @@ class CompileDesign { bool compile(); bool elaborate(); - vpiHandle writeUHDM(const std::string& fileName); + vpiHandle writeUHDM(PathId fileId); Compiler* getCompiler() const { return m_compiler; } virtual UHDM::Serializer& getSerializer() { return m_serializer; } diff --git a/include/Surelog/DesignCompile/CompileFileContent.h b/include/Surelog/DesignCompile/CompileFileContent.h index b7e6013455..718600a447 100644 --- a/include/Surelog/DesignCompile/CompileFileContent.h +++ b/include/Surelog/DesignCompile/CompileFileContent.h @@ -60,8 +60,7 @@ class CompileFileContent final { [[maybe_unused]] Design* design, [[maybe_unused]] SymbolTable* symbols, [[maybe_unused]] ErrorContainer* errors) - : m_compileDesign(compiler), - m_fileContent(file) { + : m_compileDesign(compiler), m_fileContent(file) { m_helper.seterrorReporting(errors, symbols); } diff --git a/include/Surelog/DesignCompile/CompileHelper.h b/include/Surelog/DesignCompile/CompileHelper.h index 404dee12be..5bc5ea5e01 100644 --- a/include/Surelog/DesignCompile/CompileHelper.h +++ b/include/Surelog/DesignCompile/CompileHelper.h @@ -25,6 +25,7 @@ #define SURELOG_COMPILEHELPER_H #pragma once +#include #include #include #include @@ -446,9 +447,9 @@ class CompileHelper final { UHDM::expr* reduceExpr(UHDM::any* expr, bool& invalidValue, DesignComponent* component, CompileDesign* compileDesign, - ValuedComponentI* instance, - const std::filesystem::path& fileName, int lineNumber, - UHDM::any* pexpr, bool muteErrors = false); + ValuedComponentI* instance, PathId fileId, + int lineNumber, UHDM::any* pexpr, + bool muteErrors = false); UHDM::expr* expandPatternAssignment(const UHDM::typespec* tps, UHDM::expr* rhs, @@ -458,8 +459,7 @@ class CompileHelper final { uint64_t Bits(const UHDM::any* typespec, bool& invalidValue, DesignComponent* component, CompileDesign* compileDesign, - ValuedComponentI* instance, - const std::filesystem::path& fileName, int lineNumber, + ValuedComponentI* instance, PathId fileId, int lineNumber, bool reduce, bool sizeMode); UHDM::variables* getSimpleVarFromTypespec( @@ -474,20 +474,19 @@ class CompileHelper final { UHDM::expr* EvalFunc(UHDM::function* func, std::vector* args, bool& invalidValue, DesignComponent* component, CompileDesign* compileDesign, ValuedComponentI* instance, - const std::filesystem::path& fileName, int lineNumber, - UHDM::any* pexpr); + PathId fileId, int lineNumber, UHDM::any* pexpr); void evalScheduledExprs(DesignComponent* component, CompileDesign* compileDesign); void checkForLoops(bool on); - bool loopDetected(const std::filesystem::path& fileName, int lineNumber, + bool loopDetected(PathId fileId, int lineNumber, CompileDesign* compileDesign, ValuedComponentI* instance); UHDM::any* getValue(const std::string& name, DesignComponent* component, CompileDesign* compileDesign, ValuedComponentI* instance, - const std::filesystem::path& fileName, int lineNumber, - UHDM::any* pexpr, bool reduce, bool muteErrors = false); + PathId fileId, int lineNumber, UHDM::any* pexpr, + bool reduce, bool muteErrors = false); // Parse numeric UHDM constant into int64_t. Returns if successful. bool parseConstant(const UHDM::constant& constant, int64_t* value); @@ -523,15 +522,13 @@ class CompileHelper final { bool errorOnNegativeConstant(DesignComponent* component, const std::string& value, CompileDesign* compileDesign, - ValuedComponentI* instance, - const std::filesystem::path& fileName, + ValuedComponentI* instance, PathId fileId, unsigned int lineNo, unsigned short columnNo); UHDM::any* decodeHierPath(UHDM::hier_path* path, bool& invalidValue, DesignComponent* component, CompileDesign* compileDesign, - ValuedComponentI* instance, - const std::filesystem::path& fileName, + ValuedComponentI* instance, PathId fileName, int lineNumber, UHDM::any* pexpr, bool reduce, bool muteErrors, bool returnTypespec); @@ -564,14 +561,16 @@ class CompileHelper final { ExprBuilder m_exprBuilder; UHDM::module* m_exprEvalPlaceHolder = nullptr; // Caches - UHDM::int_typespec* buildIntTypespec( - CompileDesign* compileDesign, const std::filesystem::path& fileName, - const std::string& name, const std::string& value, unsigned int line, - unsigned short column, unsigned int eline, unsigned short ecolumn); + UHDM::int_typespec* buildIntTypespec(CompileDesign* compileDesign, + PathId fileId, const std::string& name, + const std::string& value, + unsigned int line, unsigned short column, + unsigned int eline, + unsigned short ecolumn); UHDM::typespec_member* buildTypespecMember( - CompileDesign* compileDesign, const std::filesystem::path& fileName, - const std::string& name, const std::string& value, unsigned int line, - unsigned short column, unsigned int eline, unsigned short ecolumn); + CompileDesign* compileDesign, PathId fileId, const std::string& name, + const std::string& value, unsigned int line, unsigned short column, + unsigned int eline, unsigned short ecolumn); std::unordered_map m_cache_int_typespec; std::unordered_map m_cache_typespec_member; diff --git a/include/Surelog/DesignCompile/NetlistElaboration.h b/include/Surelog/DesignCompile/NetlistElaboration.h index 6aa6544de3..73c9d58c74 100644 --- a/include/Surelog/DesignCompile/NetlistElaboration.h +++ b/include/Surelog/DesignCompile/NetlistElaboration.h @@ -62,21 +62,24 @@ class NetlistElaboration : public TestbenchElaboration { UHDM::interface* elab_interface_( ModuleInstance* instance, ModuleInstance* interf_instance, const std::string& instName, const std::string& defName, - ModuleDefinition* mod, const std::filesystem::path& fileName, int lineNb, + ModuleDefinition* mod, PathId fileId, int lineNb, UHDM::interface_array* interf_array, const std::string& modPortName); - UHDM::modport* elab_modport_( - ModuleInstance* instance, ModuleInstance* interfInstance, - const std::string& instName, const std::string& defName, - ModuleDefinition* mod, const std::filesystem::path& fileName, int lineNb, - const std::string& modPortName, UHDM::interface_array* interf_array); + UHDM::modport* elab_modport_(ModuleInstance* instance, + ModuleInstance* interfInstance, + const std::string& instName, + const std::string& defName, + ModuleDefinition* mod, PathId fileId, int lineNb, + const std::string& modPortName, + UHDM::interface_array* interf_array); bool elab_ports_nets_(ModuleInstance* instance, bool ports); bool elab_ports_nets_(ModuleInstance* instance, ModuleInstance* child, Netlist* parentNetlist, Netlist* netlist, DesignComponent* comp, const std::string& prefix, bool ports); - UHDM::any* bind_net_(const FileContent* idfC, NodeId id, ModuleInstance* instance, - ModuleInstance* boundInstance, const std::string& name); + UHDM::any* bind_net_(const FileContent* idfC, NodeId id, + ModuleInstance* instance, ModuleInstance* boundInstance, + const std::string& name); UHDM::any* bind_net_(ModuleInstance* instance, const std::string& name); ModuleInstance* getInterfaceInstance_(ModuleInstance* instance, const std::string& sigName); diff --git a/include/Surelog/DesignCompile/UhdmChecker.h b/include/Surelog/DesignCompile/UhdmChecker.h index 9c61d38af4..c7b0107336 100644 --- a/include/Surelog/DesignCompile/UhdmChecker.h +++ b/include/Surelog/DesignCompile/UhdmChecker.h @@ -25,7 +25,6 @@ #define SURELOG_UHDMCHECKER_H #pragma once -#include #include #include #include @@ -42,16 +41,15 @@ class UhdmChecker final { : m_compileDesign(compiler), m_design(design) {} // Technically not a const method as it modifies some static values. - bool check(const std::string& reportFile); + bool check(PathId reportFileId); private: bool registerFile(const FileContent* fC, std::set& moduleNames); - bool reportHtml(CompileDesign* compileDesign, - const std::filesystem::path& reportFile, - float overallCoverage); - float reportCoverage(const std::filesystem::path& reportFile); - void annotate(CompileDesign* m_compileDesign); + bool reportHtml(PathId reportFileId, float overallCoverage); + float reportCoverage(PathId reportFileId); + void annotate(); void mergeColumnCoverage(); + CompileDesign* const m_compileDesign; Design* const m_design; typedef unsigned int LineNb; @@ -66,9 +64,9 @@ class UhdmChecker final { typedef std::map RangesMap; typedef std::map FileNodeCoverMap; FileNodeCoverMap fileNodeCoverMap; - std::map fileMap; - std::multimap> coverageMap; - std::map fileCoverageMap; + std::map fileMap; + std::multimap> coverageMap; + std::map fileCoverageMap; }; } // namespace SURELOG diff --git a/include/Surelog/DesignCompile/UhdmWriter.h b/include/Surelog/DesignCompile/UhdmWriter.h index ae39edc814..1e039e0070 100644 --- a/include/Surelog/DesignCompile/UhdmWriter.h +++ b/include/Surelog/DesignCompile/UhdmWriter.h @@ -55,7 +55,7 @@ class UhdmWriter final { UhdmWriter(CompileDesign* compiler, Design* design); - vpiHandle write(const std::string& uhdmFile); + vpiHandle write(PathId uhdmFileId); static unsigned int getVpiDirection(VObjectType type); @@ -95,21 +95,26 @@ class UhdmWriter final { bool writeElabGenScope(UHDM::Serializer& s, ModuleInstance* instance, UHDM::gen_scope* m, ExprBuilder& exprBuilder); void writePackage(Package* pack, UHDM::package* p, UHDM::Serializer& s, - UhdmWriter::ComponentMap& componentMap, bool elaborated); + UhdmWriter::ComponentMap& componentMap, bool elaborated); void writeClasses(ClassNameClassDefinitionMultiMap& orig_classes, + UHDM::VectorOfclass_defn* dest_classes, UHDM::Serializer& s, + UhdmWriter::ComponentMap& componentMap, + UHDM::BaseClass* parent); + void writeClass(ClassDefinition* classDef, UHDM::VectorOfclass_defn* dest_classes, UHDM::Serializer& s, - UhdmWriter::ComponentMap& componentMap, UHDM::BaseClass* parent); - void writeClass(ClassDefinition* classDef, UHDM::VectorOfclass_defn* dest_classes, - UHDM::Serializer& s, UhdmWriter::ComponentMap& componentMap, - UHDM::BaseClass* parent); - void writeProgram(Program* mod, UHDM::program* m, UHDM::Serializer& s, UhdmWriter::ComponentMap& componentMap, - UhdmWriter::ModPortMap& modPortMap, - ModuleInstance* instance = nullptr); - - void lateBinding(UHDM::Serializer& s, DesignComponent* mod, UHDM::scope* m, UhdmWriter::ComponentMap& componentMap); - void lateTypedefBinding(UHDM::Serializer& s, DesignComponent* mod, UHDM::scope* m, UhdmWriter::ComponentMap& componentMap); + UHDM::BaseClass* parent); + void writeProgram(Program* mod, UHDM::program* m, UHDM::Serializer& s, + UhdmWriter::ComponentMap& componentMap, + UhdmWriter::ModPortMap& modPortMap, + ModuleInstance* instance = nullptr); + + void lateBinding(UHDM::Serializer& s, DesignComponent* mod, UHDM::scope* m, + UhdmWriter::ComponentMap& componentMap); + void lateTypedefBinding(UHDM::Serializer& s, DesignComponent* mod, + UHDM::scope* m, + UhdmWriter::ComponentMap& componentMap); CompileDesign* const m_compileDesign; Design* const m_design; diff --git a/include/Surelog/ErrorReporting/Location.h b/include/Surelog/ErrorReporting/Location.h index 19cf6caf02..f4443fef47 100644 --- a/include/Surelog/ErrorReporting/Location.h +++ b/include/Surelog/ErrorReporting/Location.h @@ -25,25 +25,30 @@ #define SURELOG_LOCATION_H #pragma once +#include #include +#include + namespace SURELOG { class Location final { public: - Location(SymbolId object) - : m_fileId(BadSymbolId), m_line(0), m_column(0), m_object(object) {} - Location(SymbolId fileId, unsigned int line, unsigned short int column, + explicit Location(SymbolId object) + : m_fileId(BadPathId), m_line(0), m_column(0), m_object(object) {} + explicit Location(PathId fileId) : Location((SymbolId)fileId) {} + Location(PathId fileId, unsigned int line, unsigned short int column, SymbolId object = BadSymbolId) : m_fileId(fileId), m_line(line), m_column(column), m_object(object) {} - /* Do not create a copy constructor, use default*/ + /* Do not create a copy constructor, use default */ // Location(const Location& orig); bool operator==(const Location& rhs) const; bool operator<(const Location& rhs) const; + friend std::ostream& operator<<(std::ostream& strm, const Location& location); - SymbolId m_fileId; + PathId m_fileId; unsigned int m_line; unsigned short int m_column; SymbolId m_object; diff --git a/include/Surelog/Library/Library.h b/include/Surelog/Library/Library.h index c08cda11f6..8aa1707490 100644 --- a/include/Surelog/Library/Library.h +++ b/include/Surelog/Library/Library.h @@ -25,7 +25,7 @@ #define SURELOG_LIBRARY_H #pragma once -#include +#include #include #include @@ -42,14 +42,14 @@ class Library final { Library(std::string_view name, SymbolTable* symbols) : m_name(name), m_symbols(symbols) {} - void addFileId(SymbolId fid) { + void addFileId(PathId fid) { m_fileIds.push_back(fid); m_fileIdsSet.insert(fid); } const std::string& getName() const { return m_name; } - const std::vector& getFiles() const { return m_fileIds; } - bool isMember(SymbolId fid) const { + const PathIdVector& getFiles() const { return m_fileIds; } + bool isMember(PathId fid) const { return m_fileIdsSet.find(fid) != m_fileIdsSet.end(); } std::string report(SymbolTable* symbols) const; @@ -60,8 +60,8 @@ class Library final { private: std::string m_name; - std::vector m_fileIds; - SymbolIdSet m_fileIdsSet; + PathIdVector m_fileIds; + PathIdSet m_fileIdsSet; std::map m_modules; SymbolTable* const m_symbols; }; diff --git a/include/Surelog/Library/LibrarySet.h b/include/Surelog/Library/LibrarySet.h index d96a379405..f2b344eff9 100644 --- a/include/Surelog/Library/LibrarySet.h +++ b/include/Surelog/Library/LibrarySet.h @@ -43,7 +43,7 @@ class LibrarySet final { void addLibrary(const Library& lib); std::vector& getLibraries() { return m_libraries; } Library* getLibrary(std::string_view libName); - Library* getLibrary(SymbolId fileId); + Library* getLibrary(PathId fileId); void checkErrors(SymbolTable* symbols, ErrorContainer* errors) const; std::string report(SymbolTable* symbols) const; diff --git a/include/Surelog/Library/ParseLibraryDef.h b/include/Surelog/Library/ParseLibraryDef.h index 4f476353f5..87099686e7 100644 --- a/include/Surelog/Library/ParseLibraryDef.h +++ b/include/Surelog/Library/ParseLibraryDef.h @@ -44,10 +44,10 @@ class ParseLibraryDef final { ConfigSet* configSet); bool parseLibrariesDefinition(); - bool parseLibraryDefinition(SymbolId file, Library* lib = nullptr); + bool parseLibraryDefinition(PathId file, Library* lib = nullptr); bool parseConfigDefinition(); - SymbolId getFileId() const { return m_fileId; } + PathId getFileId() const { return m_fileId; } CommandLineParser* getCommandLineParser() const { return m_commandLineParser; } @@ -63,7 +63,7 @@ class ParseLibraryDef final { private: ParseLibraryDef(const ParseLibraryDef& orig) = delete; - SymbolId m_fileId; + PathId m_fileId; CommandLineParser* const m_commandLineParser; ErrorContainer* const m_errors; SymbolTable* const m_symbolTable; diff --git a/include/Surelog/Library/SVLibShapeListener.h b/include/Surelog/Library/SVLibShapeListener.h index 77f88da847..1ac883e155 100644 --- a/include/Surelog/Library/SVLibShapeListener.h +++ b/include/Surelog/Library/SVLibShapeListener.h @@ -25,11 +25,10 @@ #define SURELOG_SVLIBSHAPELISTENER_H #pragma once +#include #include #include -#include - namespace SURELOG { class Config; @@ -38,13 +37,12 @@ class ParseLibraryDef; class SVLibShapeListener : public SV3_1aParserBaseListener, public SV3_1aTreeShapeHelper { public: - SVLibShapeListener(ParseLibraryDef* parser, antlr4::CommonTokenStream* tokens, - const std::filesystem::path& relativePath); + SVLibShapeListener(ParseLibraryDef* parser, antlr4::CommonTokenStream* tokens); SymbolId registerSymbol(std::string_view symbol) final; antlr4::CommonTokenStream* getTokenStream() const { return m_tokens; } - ~SVLibShapeListener() override; + ~SVLibShapeListener() override = default; // *** LIBRARY DEFINITION PARSING *** @@ -174,7 +172,6 @@ class SVLibShapeListener : public SV3_1aParserBaseListener, private: ParseLibraryDef* m_parser; antlr4::CommonTokenStream* m_tokens; - const std::filesystem::path m_relativePath; }; }; // namespace SURELOG diff --git a/include/Surelog/Package/Package.h b/include/Surelog/Package/Package.h index d38d9390f1..6ffd7064c2 100644 --- a/include/Surelog/Package/Package.h +++ b/include/Surelog/Package/Package.h @@ -25,12 +25,12 @@ #define SURELOG_PACKAGE_H #pragma once -#include - #include #include #include +#include + // UHDM #include @@ -59,7 +59,7 @@ class Package : public DesignComponent { return VObjectType::slPackage_declaration; } bool isInstance() const override { return false; } - const std::string& getName() const override { return m_name; } + std::string getName() const override { return m_name; } ClassNameClassDefinitionMultiMap& getClassDefinitions() { return m_classDefinitions; @@ -82,6 +82,7 @@ class Package : public DesignComponent { void setNetlist(Netlist* netlist) { m_netlist = netlist; } Package* getUnElabPackage() { return m_unElabPackage; } + private: std::string m_name; Library* m_library; diff --git a/include/Surelog/Package/Precompiled.h b/include/Surelog/Package/Precompiled.h index 1c10ac2b5c..6d7eaa53c8 100644 --- a/include/Surelog/Package/Precompiled.h +++ b/include/Surelog/Package/Precompiled.h @@ -25,36 +25,32 @@ #define SURELOG_PRECOMPILED_H #pragma once -#include +#include +#include #include -#include -#include +#include namespace SURELOG { - +class PathId; class Precompiled final { public: static Precompiled* getSingleton(); - void addPrecompiled(const std::string& package_name, - const std::string& fileName); + void addPrecompiled(std::string_view package_name, std::string_view fileName); + + std::string getFileName(std::string_view packageName) const; - std::string getFileName(const std::string& packageName) const; - bool isFilePrecompiled(const std::filesystem::path& fileName) const; - bool isPackagePrecompiled(const std::string& package) const; + bool isFilePrecompiled(PathId fileId) const; + bool isFilePrecompiled(std::string_view fileName) const; + + bool isPackagePrecompiled(std::string_view packageName) const; private: Precompiled(); // Only accessed via singleton. Precompiled(const Precompiled&) = delete; - struct fs_path_hash final { - std::size_t operator()(const std::filesystem::path& path) const { - return std::filesystem::hash_value(path); - } - }; - - std::unordered_map m_packageMap; - std::unordered_set m_packageFileSet; + std::map> m_packageMap; + std::set> m_packageFileSet; }; } // namespace SURELOG diff --git a/include/Surelog/SourceCompile/AnalyzeFile.h b/include/Surelog/SourceCompile/AnalyzeFile.h index 0be07445b6..8560103983 100644 --- a/include/Surelog/SourceCompile/AnalyzeFile.h +++ b/include/Surelog/SourceCompile/AnalyzeFile.h @@ -25,14 +25,13 @@ #define SURELOG_ANALYZEFILE_H #pragma once -#include -#include -#include - -#include +#include #include #include +#include +#include + namespace SURELOG { class CommandLineParser; @@ -61,35 +60,35 @@ class AnalyzeFile { unsigned long m_endChar; }; - AnalyzeFile(CommandLineParser* clp, Design* design, - const std::filesystem::path& ppFileName, - const std::filesystem::path& fileName, int nbChunks, - const std::string& text = "") + AnalyzeFile(CommandLineParser* clp, Design* design, PathId ppFileId, + PathId fileId, int nbChunks, const std::string& text = "") : m_clp(clp), m_design(design), - m_ppFileName(ppFileName), - m_fileName(fileName), + m_ppFileId(ppFileId), + m_fileId(fileId), m_nbChunks(nbChunks), m_text(text) {} void analyze(); - std::vector& getSplitFiles() { return m_splitFiles; } - std::vector& getLineOffsets() { return m_lineOffsets; } + const std::vector& getSplitFiles() const { return m_splitFiles; } + const std::vector& getLineOffsets() const { + return m_lineOffsets; + } AnalyzeFile(const AnalyzeFile& orig) = delete; - virtual ~AnalyzeFile() {} + virtual ~AnalyzeFile() = default; private: void checkSLlineDirective_(const std::string& line, unsigned int lineNb); std::string setSLlineDirective_(unsigned int lineNb, unsigned int& origFromLine, - std::filesystem::path& origFile); + PathId& origFileId); CommandLineParser* m_clp; Design* m_design; - std::filesystem::path m_ppFileName; - std::filesystem::path m_fileName; + PathId m_ppFileId; + PathId m_fileId; std::vector m_fileChunks; - std::vector m_splitFiles; + std::vector m_splitFiles; std::vector m_lineOffsets; int m_nbChunks; std::stack m_includeFileInfo; diff --git a/include/Surelog/SourceCompile/AntlrParserErrorListener.h b/include/Surelog/SourceCompile/AntlrParserErrorListener.h index 99743510e6..d60ef7d20a 100644 --- a/include/Surelog/SourceCompile/AntlrParserErrorListener.h +++ b/include/Surelog/SourceCompile/AntlrParserErrorListener.h @@ -25,8 +25,10 @@ #define SURELOG_ANTLRPARSERERRORLISTENER_H #pragma once +#include #include + namespace SURELOG { class ParseFile; @@ -34,13 +36,14 @@ class ParseFile; class AntlrParserErrorListener : public antlr4::ANTLRErrorListener { public: AntlrParserErrorListener(ParseFile *parser, bool watchDogOn, - unsigned int lineOffset, const std::string &fileName) + unsigned int lineOffset, + PathId fileId) : m_parser(parser), m_reportedSyntaxError(false), m_watchDogOn(watchDogOn), m_barked(false), m_lineOffset(lineOffset), - m_fileName(fileName) {} + m_fileId(fileId) {} ~AntlrParserErrorListener() override{}; @@ -70,7 +73,7 @@ class AntlrParserErrorListener : public antlr4::ANTLRErrorListener { bool m_watchDogOn; bool m_barked; unsigned int m_lineOffset; - std::string m_fileName; + PathId m_fileId; std::string m_fileContent; }; diff --git a/include/Surelog/SourceCompile/CommonListenerHelper.h b/include/Surelog/SourceCompile/CommonListenerHelper.h index 612cb77a2c..053696775f 100644 --- a/include/Surelog/SourceCompile/CommonListenerHelper.h +++ b/include/Surelog/SourceCompile/CommonListenerHelper.h @@ -81,7 +81,7 @@ class CommonListenerHelper { FileContent* getFileContent() { return m_fileContent; } virtual std::tuple - getFileLine(antlr4::ParserRuleContext* ctx, SymbolId& fileId) = 0; + getFileLine(antlr4::ParserRuleContext* ctx, PathId& fileId) = 0; private: NodeId& MutableChild(NodeId index); diff --git a/include/Surelog/SourceCompile/CompilationUnit.h b/include/Surelog/SourceCompile/CompilationUnit.h index da241221e3..0224d62250 100644 --- a/include/Surelog/SourceCompile/CompilationUnit.h +++ b/include/Surelog/SourceCompile/CompilationUnit.h @@ -53,15 +53,15 @@ class CompilationUnit { void deleteAllMacros() { m_macros.clear(); } /* Following methods deal with `timescale */ - void setCurrentTimeInfo(SymbolId fileId); + void setCurrentTimeInfo(PathId fileId); std::vector& getTimeInfo() { return m_timeInfo; } void recordTimeInfo(TimeInfo& info); - TimeInfo& getTimeInfo(SymbolId fileId, unsigned int line); + TimeInfo& getTimeInfo(PathId fileId, unsigned int line); /* Following methods deal with `default_nettype */ std::vector& getDefaultNetType() { return m_defaultNetTypes; } void recordDefaultNetType(NetTypeInfo& info); - VObjectType getDefaultNetType(SymbolId fileId, unsigned int line); + VObjectType getDefaultNetType(PathId fileId, unsigned int line); NodeId generateUniqueDesignElemId() { m_uniqueIdGenerator++; diff --git a/include/Surelog/SourceCompile/CompileSourceFile.h b/include/Surelog/SourceCompile/CompileSourceFile.h index 9ce93116dd..bb54a43a27 100644 --- a/include/Surelog/SourceCompile/CompileSourceFile.h +++ b/include/Surelog/SourceCompile/CompileSourceFile.h @@ -50,18 +50,18 @@ class PreprocessFile; class PythonListen; class SymbolTable; -class CompileSourceFile { +class CompileSourceFile final { public: friend PreprocessFile; enum Action { Preprocess, PostPreprocess, Parse, PythonAPI }; - CompileSourceFile(SymbolId fileId, CommandLineParser* clp, + CompileSourceFile(PathId fileId, CommandLineParser* clp, ErrorContainer* errors, Compiler* compiler, SymbolTable* symbols, CompilationUnit* comp_unit, Library* library, const std::string& = ""); // Chunk File: - CompileSourceFile(CompileSourceFile* parent, SymbolId ppResultFileId, + CompileSourceFile(CompileSourceFile* parent, PathId ppResultFileId, unsigned int lineOffset); bool compile(Action action); @@ -80,11 +80,14 @@ class CompileSourceFile { const std::map& getPpAntlrHandlerMap() const { - return m_antlrPpMap; + return m_antlrPpMacroMap; } void registerAntlrPpHandlerForId(SymbolId id, PreprocessFile::AntlrParserHandler* pp); + void registerAntlrPpHandlerForId(PathId id, + PreprocessFile::AntlrParserHandler* pp); PreprocessFile::AntlrParserHandler* getAntlrPpHandlerForId(SymbolId); + PreprocessFile::AntlrParserHandler* getAntlrPpHandlerForId(PathId); #ifdef SURELOG_WITH_PYTHON void setPythonInterp(PyThreadState* interpState); @@ -98,8 +101,8 @@ class CompileSourceFile { // Get size of job approximated by size of file to process. uint64_t getJobSize(Action action) const; - SymbolId getFileId() const { return m_fileId; } - SymbolId getPpOutputFileId() const { return m_ppResultFileId; } + PathId getFileId() const { return m_fileId; } + PathId getPpOutputFileId() const { return m_ppResultFileId; } void setFileAnalyzer(AnalyzeFile* analyzer) { m_fileAnalyzer = analyzer; } AnalyzeFile* getFileAnalyzer() const { return m_fileAnalyzer; } @@ -115,7 +118,7 @@ class CompileSourceFile { bool pythonAPI_(); - SymbolId m_fileId; + PathId m_fileId; CommandLineParser* m_commandLineParser = nullptr; ErrorContainer* m_errors = nullptr; Compiler* m_compiler = nullptr; @@ -125,10 +128,12 @@ class CompileSourceFile { ParseFile* m_parser = nullptr; CompilationUnit* m_compilationUnit = nullptr; Action m_action = Action::Preprocess; - SymbolId m_ppResultFileId; + PathId m_ppResultFileId; std::map - m_antlrPpMap; // Preprocessor Antlr Handlers (One per included file) + m_antlrPpMacroMap; // Preprocessor Antlr Handlers (One per macro) + std::map + m_antlrPpFileMap; // Preprocessor Antlr Handlers (One per included file) #ifdef SURELOG_WITH_PYTHON PyThreadState* m_interpState = nullptr; PythonListen* m_pythonListener = nullptr; diff --git a/include/Surelog/SourceCompile/Compiler.h b/include/Surelog/SourceCompile/Compiler.h index 8da4708d57..993f5620f1 100644 --- a/include/Surelog/SourceCompile/Compiler.h +++ b/include/Surelog/SourceCompile/Compiler.h @@ -25,6 +25,7 @@ limitations under the License. #define SURELOG_COMPILER_H #pragma once +#include #include #include #include @@ -56,6 +57,8 @@ class SymbolTable; class Compiler { public: + typedef std::map, PathIdLessThanComparer> + PPFileMap; Compiler(CommandLineParser* commandLineParser, ErrorContainer* errors, SymbolTable* symbolTable); Compiler(CommandLineParser* commandLineParser, ErrorContainer* errors, @@ -91,11 +94,8 @@ class Compiler { vpiHandle getUhdmDesign() const { return m_uhdmDesign; } CompileDesign* getCompileDesign() const { return m_compileDesign; } ErrorContainer::Stats getErrorStats() const; - bool isLibraryFile(SymbolId id) const; - const std::map>& - getPPFileMap() { - return ppFileMap; - } + bool isLibraryFile(PathId id) const; + const PPFileMap& getPPFileMap() { return m_ppFileMap; } #ifdef USETBB tbb::task_group& getTaskGroup() { return m_taskGroup; } #endif @@ -133,10 +133,10 @@ class Compiler { ConfigSet* const m_configSet; Design* const m_design; vpiHandle m_uhdmDesign; - SymbolIdSet m_libraryFiles; // -v - std::string m_text; // unit tests + PathIdSet m_libraryFiles; // -v + std::string m_text; // unit tests CompileDesign* m_compileDesign; - std::map> ppFileMap; + PPFileMap m_ppFileMap; #ifdef USETBB tbb::task_group m_taskGroup; #endif diff --git a/include/Surelog/SourceCompile/IncludeFileInfo.h b/include/Surelog/SourceCompile/IncludeFileInfo.h index 07d2fa86bf..d6f1e67d2c 100644 --- a/include/Surelog/SourceCompile/IncludeFileInfo.h +++ b/include/Surelog/SourceCompile/IncludeFileInfo.h @@ -35,7 +35,7 @@ class IncludeFileInfo { enum class Action : unsigned int { NONE = 0, PUSH = 1, POP = 2 }; IncludeFileInfo(Context context, unsigned int sectionStartLine, - SymbolId sectionFile, unsigned int originalStartLine, + PathId sectionFile, unsigned int originalStartLine, unsigned int originalStartColumn, unsigned int originalEndLine, unsigned int originalEndColumn, Action action) @@ -61,7 +61,7 @@ class IncludeFileInfo { m_indexOpening(i.m_indexOpening), m_indexClosing(i.m_indexClosing) {} IncludeFileInfo(Context context, unsigned int sectionStartLine, - SymbolId sectionFile, unsigned int originalStartLine, + PathId sectionFile, unsigned int originalStartLine, unsigned int originalStartColumn, unsigned int originalEndLine, unsigned int originalEndColumn, Action type, int indexOpening, int indexClosing) @@ -78,7 +78,7 @@ class IncludeFileInfo { const Context m_context; unsigned int m_sectionStartLine = 0; - SymbolId m_sectionFile = BadSymbolId; + PathId m_sectionFile; unsigned int m_originalStartLine = 0; unsigned int m_originalStartColumn = 0; const unsigned int m_originalEndLine = 0; diff --git a/include/Surelog/SourceCompile/MacroInfo.h b/include/Surelog/SourceCompile/MacroInfo.h index 2920a113c3..7a6ca1023e 100644 --- a/include/Surelog/SourceCompile/MacroInfo.h +++ b/include/Surelog/SourceCompile/MacroInfo.h @@ -25,7 +25,7 @@ #define SURELOG_MACROINFO_H #pragma once -#include +#include #include #include @@ -35,20 +35,11 @@ namespace SURELOG { class MacroInfo { public: - MacroInfo(std::string_view name, int type, SymbolId file, + MacroInfo(std::string_view name, int type, PathId fileId, unsigned int startLine, unsigned short int startColumn, unsigned int endLine, unsigned short int endColumn, const std::vector& arguments, - const std::vector& tokens) - : m_name(name), - m_type(type), - m_file(file), - m_startLine(startLine), - m_startColumn(startColumn), - m_endLine(endLine), - m_endColumn(endColumn), - m_arguments(arguments), - m_tokens(tokens) {} + const std::vector& tokens); enum Type { NO_ARGS, WITH_ARGS, @@ -56,7 +47,7 @@ class MacroInfo { const std::string m_name; const int m_type; - const SymbolId m_file; + const PathId m_fileId; const unsigned int m_startLine; const unsigned short int m_startColumn; const unsigned int m_endLine; diff --git a/include/Surelog/SourceCompile/ParseFile.h b/include/Surelog/SourceCompile/ParseFile.h index 286df41a72..dc90debe58 100644 --- a/include/Surelog/SourceCompile/ParseFile.h +++ b/include/Surelog/SourceCompile/ParseFile.h @@ -27,7 +27,6 @@ #include -#include #include namespace SURELOG { @@ -48,16 +47,16 @@ class ParseFile final { friend class PythonListen; // Helper constructor used by SVLibShapeListener - ParseFile(SymbolId fileId, SymbolTable* symbolTable, ErrorContainer* errors); + ParseFile(PathId fileId, SymbolTable* symbolTable, ErrorContainer* errors); // Regular file - ParseFile(SymbolId fileId, CompileSourceFile* csf, - CompilationUnit* compilationUnit, Library* library, - SymbolId ppFileId, bool keepParserHandler); + ParseFile(PathId fileId, CompileSourceFile* csf, + CompilationUnit* compilationUnit, Library* library, PathId ppFileId, + bool keepParserHandler); // File chunk ParseFile(CompileSourceFile* compileSourceFile, ParseFile* parent, - SymbolId chunkFileId, unsigned int offsetLine); + PathId chunkFileId, unsigned int offsetLine); // Unit test constructor ParseFile(const std::string& text, CompileSourceFile* csf, @@ -72,23 +71,21 @@ class ParseFile final { } CompilationUnit* getCompilationUnit() const { return m_compilationUnit; } Library* getLibrary() const { return m_library; } - std::filesystem::path getFileName(unsigned int line); - std::filesystem::path getPpFileName() const { return getSymbol(m_ppFileId); } SymbolTable* getSymbolTable(); ErrorContainer* getErrorContainer(); - SymbolId getFileId(unsigned int line); - SymbolId getRawFileId() const { return m_fileId; } - SymbolId getPpFileId() const { return m_ppFileId; } + PathId getFileId(unsigned int line); + PathId getRawFileId() const { return m_fileId; } + PathId getPpFileId() const { return m_ppFileId; } unsigned int getLineNb(unsigned int line); class LineTranslationInfo { public: - LineTranslationInfo(SymbolId pretendFileId, unsigned int originalLine, + LineTranslationInfo(PathId pretendFileId, unsigned int originalLine, unsigned int pretendLine) : m_pretendFileId(pretendFileId), m_originalLine(originalLine), m_pretendLine(pretendLine) {} - SymbolId m_pretendFileId; + PathId m_pretendFileId; unsigned int m_originalLine; unsigned int m_pretendLine; }; @@ -113,8 +110,8 @@ class ParseFile final { void profileParser(); private: - SymbolId m_fileId; - SymbolId m_ppFileId; + PathId m_fileId; + PathId m_ppFileId; CompileSourceFile* const m_compileSourceFile; CompilationUnit* const m_compilationUnit; Library* m_library = nullptr; @@ -126,7 +123,7 @@ class ParseFile final { FileContent* m_fileContent = nullptr; bool debug_AstModel; - bool parseOneFile_(const std::string& fileName, unsigned int lineOffset); + bool parseOneFile_(PathId fileId, unsigned int lineOffset); void buildLineInfoCache_(); // For file chunk: std::vector m_children; @@ -137,7 +134,7 @@ class ParseFile final { std::string m_profileInfo; std::string m_sourceText; // For Unit tests std::vector lineInfoCache; - std::vector fileInfoCache; + std::vector fileInfoCache; }; }; // namespace SURELOG diff --git a/include/Surelog/SourceCompile/PreprocessFile.h b/include/Surelog/SourceCompile/PreprocessFile.h index 1590a288e0..4e61f77a75 100644 --- a/include/Surelog/SourceCompile/PreprocessFile.h +++ b/include/Surelog/SourceCompile/PreprocessFile.h @@ -30,7 +30,6 @@ #include #include -#include #include #include @@ -67,24 +66,25 @@ enum VerilogVersion { }; /* Can be either an include file or a macro definition being evaluated */ -class PreprocessFile { +class PreprocessFile final { public: class SpecialInstructions; class DescriptiveErrorListener; /* Constructors */ - PreprocessFile(SymbolId fileId, CompileSourceFile* csf, + PreprocessFile(PathId fileId, CompileSourceFile* csf, SpecialInstructions& instructions, - CompilationUnit* compilationUnit, Library* library); - PreprocessFile(SymbolId fileId, PreprocessFile* includedIn, - unsigned int includerLine, CompileSourceFile* csf, + CompilationUnit* compilationUnit, Library* library, + PreprocessFile* includer = nullptr, + unsigned int includerLine = 0); + PreprocessFile(SymbolId macroId, CompileSourceFile* csf, SpecialInstructions& instructions, CompilationUnit* compilationUnit, Library* library, + PreprocessFile* includer, unsigned int includerLine, std::string_view macroBody = "", MacroInfo* = nullptr, unsigned int embeddedMacroCallLine = 0, - SymbolId embeddedMacroCallFile = BadSymbolId); - PreprocessFile(const PreprocessFile& orig); - virtual ~PreprocessFile(); + PathId embeddedMacroCallFile = BadPathId); + ~PreprocessFile(); /* Main function */ bool preprocess(); @@ -96,7 +96,7 @@ class PreprocessFile { unsigned short int endColumn, const std::string& formal_arguments, const std::vector& body); - void recordMacro(const std::string& name, SymbolId fileId, + void recordMacro(const std::string& name, PathId fileId, unsigned int startLine, unsigned short int startColumn, unsigned int endLine, unsigned short int endColumn, const std::vector& formal_arguments, @@ -107,18 +107,16 @@ class PreprocessFile { LoopCheck& loopChecker, SpecialInstructions& instructions, unsigned int embeddedMacroCallLine = 0, - SymbolId embeddedMacroCallFile = BadSymbolId); + PathId embeddedMacroCallFile = BadPathId); bool deleteMacro(const std::string& name, std::set& visited); void undefineAllMacros(std::set& visited); bool isMacroBody() const { return !m_macroBody.empty(); } const std::string& getMacroBody() const { return m_macroBody; } MacroInfo* getMacroInfo() { return m_macroInfo; } SymbolId getMacroSignature(); - const MacroStorage& getMacros() { return m_macros; } + const MacroStorage& getMacros() const { return m_macros; } MacroInfo* getMacro(const std::string& name); - std::filesystem::path getFileName(unsigned int line); - std::string reportIncludeInfo() const; CompileSourceFile* getCompileSourceFile() const { @@ -130,9 +128,9 @@ class PreprocessFile { return m_antlrParserHandler ? m_antlrParserHandler->m_pptokens : nullptr; } - SymbolId getFileId(unsigned int line) const; - SymbolId getIncluderFileId(unsigned int line) const; - SymbolId getRawFileId() const { return m_fileId; } + PathId getFileId(unsigned int line) const; + PathId getIncluderFileId(unsigned int line) const; + PathId getRawFileId() const { return m_fileId; } unsigned int getLineNb(unsigned int line); PreprocessFile* getIncluder() const { return m_includer; } unsigned int getIncluderLine() const { return m_includerLine; } @@ -143,7 +141,7 @@ class PreprocessFile { return m_includeFileInfo; } int addIncludeFileInfo(IncludeFileInfo::Context context, - unsigned int sectionStartLine, SymbolId sectionFile, + unsigned int sectionStartLine, PathId sectionFile, unsigned int originalStartLine, unsigned int originalStartColumn, unsigned int originalEndLine, @@ -161,7 +159,7 @@ class PreprocessFile { unsigned int getEmbeddedMacroCallLine() const { return m_embeddedMacroCallLine; } - SymbolId getEmbeddedMacroCallFile() const { return m_embeddedMacroCallFile; } + PathId getEmbeddedMacroCallFile() const { return m_embeddedMacroCallFile; } /* Markings */ static const char* const MacroNotDefined; @@ -169,7 +167,8 @@ class PreprocessFile { static const char* const PP__File__Marking; private: - SymbolId m_fileId; + PathId m_fileId; + SymbolId m_macroId; Library* m_library = nullptr; std::string m_result; std::string m_macroBody; @@ -241,12 +240,12 @@ class PreprocessFile { /* Incoming `line handling */ struct LineTranslationInfo final { - LineTranslationInfo(SymbolId pretendFileId, unsigned int originalLine, + LineTranslationInfo(PathId pretendFileId, unsigned int originalLine, unsigned int pretendLine) : m_pretendFileId(pretendFileId), m_originalLine(originalLine), m_pretendLine(pretendLine) {} - const SymbolId m_pretendFileId; + const PathId m_pretendFileId; const unsigned int m_originalLine = 0; const unsigned int m_pretendLine = 0; }; @@ -330,7 +329,7 @@ class PreprocessFile { PreprocessFile* callingFile, unsigned int callingLine, LoopCheck& loopChecker, MacroInfo* macroInfo, SpecialInstructions& instructions, unsigned int embeddedMacroCallLine, - SymbolId embeddedMacroCallFile); + PathId embeddedMacroCallFile); void checkMacroArguments_(const std::string& name, unsigned int line, unsigned short column, @@ -349,7 +348,7 @@ class PreprocessFile { bool m_usingCachedVersion = false; std::vector m_includeFileInfo; unsigned int m_embeddedMacroCallLine = 0; - SymbolId m_embeddedMacroCallFile; + PathId m_embeddedMacroCallFile; std::string m_profileInfo; FileContent* m_fileContent = nullptr; VerilogVersion m_verilogVersion = VerilogVersion::NoVersion; diff --git a/include/Surelog/SourceCompile/PreprocessHarness.h b/include/Surelog/SourceCompile/PreprocessHarness.h index dce9079d58..f4000ba282 100644 --- a/include/Surelog/SourceCompile/PreprocessHarness.h +++ b/include/Surelog/SourceCompile/PreprocessHarness.h @@ -26,17 +26,18 @@ #pragma once #include -#include #include +#include namespace SURELOG { class PreprocessHarness { public: PreprocessHarness(); - std::string preprocess(std::string_view content, CompilationUnit* compUnit = nullptr); + std::string preprocess(std::string_view content, + CompilationUnit* compUnit = nullptr); - const ErrorContainer &collected_errors() const { return m_errors; } + const ErrorContainer& collected_errors() const { return m_errors; } private: SymbolTable m_symbols; diff --git a/include/Surelog/SourceCompile/SV3_1aPpTreeListenerHelper.h b/include/Surelog/SourceCompile/SV3_1aPpTreeListenerHelper.h index 2ede705154..86568b2118 100644 --- a/include/Surelog/SourceCompile/SV3_1aPpTreeListenerHelper.h +++ b/include/Surelog/SourceCompile/SV3_1aPpTreeListenerHelper.h @@ -86,7 +86,7 @@ class SV3_1aPpTreeListenerHelper : public CommonListenerHelper { SymbolId registerSymbol(std::string_view symbol) final; std::tuple - getFileLine(antlr4::ParserRuleContext* ctx, SymbolId& fileId) override; + getFileLine(antlr4::ParserRuleContext* ctx, PathId& fileId) override; ~SV3_1aPpTreeListenerHelper() override = default; }; diff --git a/include/Surelog/SourceCompile/SV3_1aTreeShapeHelper.h b/include/Surelog/SourceCompile/SV3_1aTreeShapeHelper.h index 1ed942431a..ab2e6c814a 100644 --- a/include/Surelog/SourceCompile/SV3_1aTreeShapeHelper.h +++ b/include/Surelog/SourceCompile/SV3_1aTreeShapeHelper.h @@ -25,9 +25,6 @@ #define SURELOG_SV3_1ATREESHAPEHELPER_H #pragma once -#include -#include - #include #include #include @@ -35,6 +32,9 @@ #include #include +#include +#include + namespace antlr4 { class CommonTokenStream; } @@ -83,7 +83,7 @@ class SV3_1aTreeShapeHelper : public CommonListenerHelper { SV3_1aParser::Time_literalContext* ctx); std::tuple - getFileLine(antlr4::ParserRuleContext* ctx, SymbolId& fileId) override; + getFileLine(antlr4::ParserRuleContext* ctx, PathId& fileId) override; protected: ParseFile* m_pf; diff --git a/include/Surelog/Testbench/ClassDefinition.h b/include/Surelog/Testbench/ClassDefinition.h index 818ea87cdc..a957369d9a 100644 --- a/include/Surelog/Testbench/ClassDefinition.h +++ b/include/Surelog/Testbench/ClassDefinition.h @@ -63,7 +63,7 @@ class ClassDefinition : public DesignComponent, public DataType { return VObjectType::slClass_declaration; } bool isInstance() const override { return false; } - const std::string& getName() const override { return m_name; } + std::string getName() const override { return m_name; } Library* getLibrary() { return m_library; } DesignComponent* getContainer() const { return m_container; } void setContainer(DesignComponent* container) { m_container = container; } diff --git a/include/Surelog/Testbench/Program.h b/include/Surelog/Testbench/Program.h index ec151208ae..d5d9645c57 100644 --- a/include/Surelog/Testbench/Program.h +++ b/include/Surelog/Testbench/Program.h @@ -51,7 +51,7 @@ class Program : public DesignComponent, public ClockingBlockHolder { unsigned int getSize() const override; VObjectType getType() const override; bool isInstance() const override { return true; } - const std::string& getName() const override { return m_name; } + std::string getName() const override { return m_name; } ClassNameClassDefinitionMultiMap& getClassDefinitions() { return m_classDefinitions; diff --git a/include/Surelog/Utils/FileUtils.h b/include/Surelog/Utils/FileUtils.h index 5692e3414d..e0abd918ff 100644 --- a/include/Surelog/Utils/FileUtils.h +++ b/include/Surelog/Utils/FileUtils.h @@ -25,6 +25,7 @@ #define SURELOG_FILEUTILS_H #pragma once +#include #include #include @@ -46,8 +47,8 @@ class FileUtils final { // Find file whose name is available in the SymbolTable either in // the current directory or under each of the paths. // If found, return the symbolID representing that file. - static SymbolId locateFile(SymbolId file, SymbolTable* symbols, - const std::vector& paths); + static PathId locateFile(PathId file, SymbolTable* symbols, + const std::vector& paths); static bool mkDirs(const std::filesystem::path& path); static bool rmDirRecursively(const std::filesystem::path& path); static std::filesystem::path getFullPath(const std::filesystem::path& path); @@ -57,14 +58,13 @@ class FileUtils final { static std::filesystem::path basename(const std::filesystem::path& str); static uint64_t fileSize(const std::filesystem::path& name); static std::string hashPath(const std::filesystem::path& path); - static std::vector collectFiles( + static std::vector collectFiles( const std::filesystem::path& dirPath, const std::filesystem::path& extension, SymbolTable* symbols); - static std::vector collectFiles(SymbolId dirPath, - SymbolId extension, - SymbolTable* symbols); - static std::vector collectFiles( - const std::filesystem::path& pathSpec, SymbolTable* symbols); + static std::vector collectFiles(PathId dirPath, SymbolId extension, + SymbolTable* symbols); + static std::vector collectFiles(const std::filesystem::path& pathSpec, + SymbolTable* symbols); static std::string getFileContent(const std::filesystem::path& name); static std::filesystem::path makeRelativePath( const std::filesystem::path& path); diff --git a/src/API/PythonAPI.cpp b/src/API/PythonAPI.cpp index f12f5dc838..d86b1ea2e9 100644 --- a/src/API/PythonAPI.cpp +++ b/src/API/PythonAPI.cpp @@ -79,7 +79,7 @@ void PythonAPI::shutdown() { #endif } -bool PythonAPI::loadScript(const std::string& name, bool check) { +bool PythonAPI::loadScript(const std::filesystem::path& name, bool check) { #ifdef SURELOG_WITH_PYTHON PyEval_AcquireThread(m_mainThreadState); bool status = loadScript_(name, check); @@ -90,11 +90,12 @@ bool PythonAPI::loadScript(const std::string& name, bool check) { #endif } -bool PythonAPI::loadScript_(const std::string& name, bool check) { +bool PythonAPI::loadScript_(const std::filesystem::path& name, bool check) { #ifdef SURELOG_WITH_PYTHON if (FileUtils::fileExists(name)) { - FILE* fp = fopen(name.c_str(), "r"); - PyRun_SimpleFile(fp, name.c_str()); + std::string fname = name.string(); + FILE* fp = fopen(fname.c_str(), "r"); + PyRun_SimpleFile(fp, fname.c_str()); PyErr_Print(); fclose(fp); return true; @@ -353,8 +354,9 @@ std::string PythonAPI::evalScript(const std::string& module, #endif } -bool PythonAPI::evalScriptPerFile(std::string script, ErrorContainer* errors, - FileContent* fC, PyThreadState* interp) { +bool PythonAPI::evalScriptPerFile(const std::filesystem::path& script, + ErrorContainer* errors, FileContent* fC, + PyThreadState* interp) { #ifdef SURELOG_WITH_PYTHON PyEval_AcquireThread(interp); loadScript_(script); @@ -392,7 +394,8 @@ bool PythonAPI::evalScriptPerFile(std::string script, ErrorContainer* errors, #endif } -bool PythonAPI::evalScript(std::string script, Design* design) { +bool PythonAPI::evalScript(const std::filesystem::path& script, + Design* design) { #ifdef SURELOG_WITH_PYTHON PyEval_AcquireThread(m_mainThreadState); loadScript_(script); diff --git a/src/API/SLAPI.cpp b/src/API/SLAPI.cpp index a1edda1eb0..428c96fdd2 100644 --- a/src/API/SLAPI.cpp +++ b/src/API/SLAPI.cpp @@ -29,6 +29,7 @@ #include #endif +#include #include #include #include @@ -85,9 +86,11 @@ void SLaddError(ErrorContainer* errors, const char* messageId, const char* fileName, unsigned int line, unsigned int col, const char* objectName) { if (errors == nullptr) return; + FileSystem* const fileSystem = FileSystem::getInstance(); SymbolTable* symbolTable = errors->getSymbolTable(); - const SymbolId fileId = - IsEmpty(fileName) ? BadSymbolId : symbolTable->registerSymbol(fileName); + const PathId fileId = IsEmpty(fileName) + ? BadPathId + : fileSystem->toPathId(fileName, symbolTable); const SymbolId objectId = IsEmpty(objectName) ? BadSymbolId : symbolTable->registerSymbol(objectName); @@ -104,19 +107,22 @@ void SLaddMLError(ErrorContainer* errors, const char* messageId, unsigned int line2, unsigned int col2, const char* objectName2) { if (errors == nullptr) return; + FileSystem* const fileSystem = FileSystem::getInstance(); SymbolTable* symbolTable = errors->getSymbolTable(); - const SymbolId fileId1 = - IsEmpty(fileName1) ? BadSymbolId : symbolTable->registerSymbol(fileName1); + const PathId fileId1 = IsEmpty(fileName1) + ? BadPathId + : fileSystem->toPathId(fileName1, symbolTable); const SymbolId objectId1 = IsEmpty(objectName1) ? BadSymbolId : symbolTable->registerSymbol(objectName1); Location loc1(fileId1, line1, col1, objectId1); - SymbolId fileId2; - if (!IsEmpty(fileName2)) fileId2 = symbolTable->registerSymbol(fileName2); - SymbolId objectId2; - if (!IsEmpty(objectName2)) - objectId2 = symbolTable->registerSymbol(objectName2); + PathId fileId2 = IsEmpty(fileName2) + ? BadPathId + : fileSystem->toPathId(fileName2, symbolTable); + SymbolId objectId2 = IsEmpty(objectName2) + ? BadSymbolId + : symbolTable->registerSymbol(objectName2); Location loc2(fileId2, line2, col2, objectId2); ErrorDefinition::ErrorType type = ErrorDefinition::getErrorType(messageId); @@ -196,9 +202,10 @@ void SLaddMLErrorContext(SV3_1aPythonListener* prog, std::string SLgetFile(SV3_1aPythonListener* prog, antlr4::ParserRuleContext* context) { #ifdef SURELOG_WITH_PYTHON + FileSystem* const fileSystem = FileSystem::getInstance(); SV3_1aPythonListener* listener = (SV3_1aPythonListener*)prog; - std::string file = - listener->getPythonListen()->getParseFile()->getFileName(0).string(); + ParseFile* parseFile = listener->getPythonListen()->getParseFile(); + std::string file = fileSystem->toPath(parseFile->getFileId(0)).string(); return file; #else std::cerr << "SLgetFile(): Python support not compiled in\n"; @@ -288,7 +295,7 @@ RawNodeId SLgetRootNode(FileContent* fC) { std::string SLgetFile(FileContent* fC, RawNodeId id) { if (!fC) return ""; - return fC->getSymbolTable()->getSymbol(fC->getFileId(NodeId(id))); + return FileSystem::getInstance()->toPath(fC->getFileId(NodeId(id))).string(); } unsigned int SLgetType(FileContent* fC, RawNodeId id) { @@ -468,8 +475,8 @@ static bool ModuleHasFirstFileContent(const ClassOrPackageOrProgram* module) { std::string SLgetModuleFile(ModuleDefinition* module) { if (!ModuleHasFirstFileContent(module)) return ""; - return module->getFileContents()[0] - ->getFileName(module->getNodeIds()[0]) + return FileSystem::getInstance() + ->toPath(module->getFileContents()[0]->getFileId(module->getNodeIds()[0])) .string(); } @@ -501,8 +508,8 @@ std::string SLgetClassName(ClassDefinition* module) { std::string SLgetClassFile(ClassDefinition* module) { if (!ModuleHasFirstFileContent(module)) return ""; - return module->getFileContents()[0] - ->getFileName(module->getNodeIds()[0]) + return FileSystem::getInstance() + ->toPath(module->getFileContents()[0]->getFileId(module->getNodeIds()[0])) .string(); } @@ -534,8 +541,8 @@ std::string SLgetPackageName(Package* module) { std::string SLgetPackageFile(Package* module) { if (!ModuleHasFirstFileContent(module)) return ""; - return module->getFileContents()[0] - ->getFileName(module->getNodeIds()[0]) + return FileSystem::getInstance() + ->toPath(module->getFileContents()[0]->getFileId(module->getNodeIds()[0])) .string(); } @@ -566,8 +573,8 @@ std::string SLgetProgramName(Program* module) { std::string SLgetProgramFile(Program* module) { if (!ModuleHasFirstFileContent(module)) return ""; - return module->getFileContents()[0] - ->getFileName(module->getNodeIds()[0]) + return FileSystem::getInstance() + ->toPath(module->getFileContents()[0]->getFileId(module->getNodeIds()[0])) .string(); } @@ -623,8 +630,8 @@ DesignComponent* SLgetInstanceDefinition(ModuleInstance* instance) { std::string SLgetInstanceFileName(ModuleInstance* instance) { if (!instance) return ""; - return instance->getFileContent() - ->getFileName(instance->getNodeId()) + return FileSystem::getInstance() + ->toPath(instance->getFileContent()->getFileId(instance->getNodeId())) .string(); } diff --git a/src/API/Surelog.cpp b/src/API/Surelog.cpp index f73279edcd..c93b287fac 100644 --- a/src/API/Surelog.cpp +++ b/src/API/Surelog.cpp @@ -24,7 +24,7 @@ namespace SURELOG { scompiler* start_compiler(CommandLineParser* clp) { Compiler* the_compiler = - new Compiler(clp, clp->getErrorContainer(), clp->mutableSymbolTable()); + new Compiler(clp, clp->getErrorContainer(), clp->getSymbolTable()); bool status = the_compiler->compile(); if (!status) return nullptr; return (scompiler*)the_compiler; diff --git a/src/Cache/Cache.cpp b/src/Cache/Cache.cpp index 3755a15035..7723289e72 100644 --- a/src/Cache/Cache.cpp +++ b/src/Cache/Cache.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -50,8 +51,9 @@ time_t Cache::get_mtime(const fs::path& path) { return statbuf.st_mtime; } -std::unique_ptr Cache::openFlatBuffers( - const fs::path& cacheFileName) { +std::unique_ptr Cache::openFlatBuffers(PathId cacheFileId) { + FileSystem* const fileSystem = FileSystem::getInstance(); + fs::path cacheFileName = fileSystem->toPath(cacheFileId); const std::string filename = cacheFileName.string(); FILE* file = fopen(filename.c_str(), "rb"); if (file == nullptr) return nullptr; @@ -69,7 +71,9 @@ std::unique_ptr Cache::openFlatBuffers( bool Cache::checkIfCacheIsValid(const SURELOG::CACHE::Header* header, std::string_view schemaVersion, - const fs::path& cacheFileName) { + PathId cacheFileId) { + FileSystem* const fileSystem = FileSystem::getInstance(); + fs::path cacheFileName = fileSystem->toPath(cacheFileId); /* Schema version */ if (schemaVersion != header->flb_version()->c_str()) { return false; @@ -105,7 +109,9 @@ bool Cache::checkIfCacheIsValid(const SURELOG::CACHE::Header* header, flatbuffers::Offset Cache::createHeader( flatbuffers::FlatBufferBuilder& builder, std::string_view schemaVersion, - const fs::path& origFileName) { + PathId origFileId) { + FileSystem* const fileSystem = FileSystem::getInstance(); + fs::path origFileName = fileSystem->toPath(origFileId); auto fName = builder.CreateString(origFileName.string()); auto sl_version = builder.CreateString(CommandLineParser::getVersionNumber()); auto sl_build_date = builder.CreateString(getExecutableTimeStamp()); @@ -116,16 +122,18 @@ flatbuffers::Offset Cache::createHeader( } bool Cache::saveFlatbuffers(flatbuffers::FlatBufferBuilder& builder, - const fs::path& cacheFileName) { + PathId cacheFileId) { + FileSystem* const fileSystem = FileSystem::getInstance(); + fs::path cacheFileName = fileSystem->toPath(cacheFileId); const std::string tmp_name = cacheFileName.string() + ".tmp"; const unsigned char* buf = builder.GetBufferPointer(); const int size = builder.GetSize(); bool success = flatbuffers::SaveFile(tmp_name.c_str(), (const char*)buf, size, true); if (success) { - std::filesystem::rename(tmp_name, cacheFileName); + fs::rename(tmp_name, cacheFileName); } else { - std::filesystem::remove(tmp_name); + fs::remove(tmp_name); } return success; } @@ -133,7 +141,8 @@ bool Cache::saveFlatbuffers(flatbuffers::FlatBufferBuilder& builder, flatbuffers::Offset Cache::cacheErrors( flatbuffers::FlatBufferBuilder& builder, SymbolTable* cacheSymbols, const ErrorContainer* errorContainer, const SymbolTable& localSymbols, - SymbolId subjectId) { + PathId subjectId) { + FileSystem* const fileSystem = FileSystem::getInstance(); const std::vector& errors = errorContainer->getErrors(); std::vector> error_vec; for (const Error& error : errors) { @@ -149,12 +158,11 @@ flatbuffers::Offset Cache::cacheErrors( if (matchSubject) { std::vector> location_vec; for (const Location& loc : locs) { - SymbolId canonicalFileId = cacheSymbols->registerSymbol( - localSymbols.getSymbol(loc.m_fileId)); + PathId canonicalFileId = fileSystem->copy(loc.m_fileId, cacheSymbols); SymbolId canonicalObjectId = cacheSymbols->registerSymbol( localSymbols.getSymbol(loc.m_object)); auto locflb = CACHE::CreateLocation( - builder, (RawSymbolId)canonicalFileId, loc.m_line, loc.m_column, + builder, (RawPathId)canonicalFileId, loc.m_line, loc.m_column, (RawSymbolId)canonicalObjectId); location_vec.push_back(locflb); } @@ -168,32 +176,30 @@ flatbuffers::Offset Cache::cacheErrors( return builder.CreateVector(error_vec); } -flatbuffers::Offset Cache::createSymbolCache( - flatbuffers::FlatBufferBuilder& builder, const SymbolTable& cacheSymbols) { - return builder.CreateVectorOfStrings(cacheSymbols.getSymbols()); +void Cache::restoreSymbols(const VectorOffsetString* symbolsBuf, + SymbolTable* cacheSymbols) { + for (unsigned int i = 0; i < symbolsBuf->size(); i++) { + std::string_view symbol = symbolsBuf->Get(i)->string_view(); + cacheSymbols->registerSymbol(symbol); + } } void Cache::restoreErrors(const VectorOffsetError* errorsBuf, - const VectorOffsetString* symbolsBuf, SymbolTable* cacheSymbols, ErrorContainer* errorContainer, SymbolTable* localSymbols) { - for (unsigned int i = 0; i < symbolsBuf->size(); i++) { - const std::string symbol = symbolsBuf->Get(i)->c_str(); - cacheSymbols->registerSymbol(symbol); - } + FileSystem* const fileSystem = FileSystem::getInstance(); for (unsigned int i = 0; i < errorsBuf->size(); i++) { auto errorFlb = errorsBuf->Get(i); std::vector locs; for (unsigned int j = 0; j < errorFlb->locations()->size(); j++) { auto locFlb = errorFlb->locations()->Get(j); - SymbolId translFileId = localSymbols->registerSymbol( - cacheSymbols->getSymbol(SymbolId(locFlb->file_id(), ""))); + PathId translFileId = fileSystem->copy( + PathId(cacheSymbols, locFlb->file_id(), ""), localSymbols); SymbolId translObjectId = localSymbols->registerSymbol( cacheSymbols->getSymbol(SymbolId(locFlb->object(), ""))); - Location loc(translFileId, locFlb->line(), locFlb->column(), - translObjectId); - locs.push_back(loc); + locs.emplace_back(translFileId, locFlb->line(), locFlb->column(), + translObjectId); } Error err((ErrorDefinition::ErrorType)errorFlb->error_id(), locs); errorContainer->addError(err, false); @@ -202,7 +208,7 @@ void Cache::restoreErrors(const VectorOffsetError* errorsBuf, std::vector Cache::cacheVObjects( const FileContent* fcontent, SymbolTable* cacheSymbols, - const SymbolTable& localSymbols, SymbolId fileId) { + const SymbolTable& localSymbols, PathId fileId) { /* Cache the design objects */ // std::vector> object_vec; std::vector object_vec; @@ -217,19 +223,23 @@ std::vector Cache::cacheVObjects( return (RawSymbolId)cacheSymbols->registerSymbol( localSymbols.getSymbol(id)); }; + std::function toCachePath = [cacheSymbols](PathId id) { + FileSystem* const fileSystem = FileSystem::getInstance(); + return (RawPathId)fileSystem->copy(id, cacheSymbols); + }; for (const VObject& object : fcontent->getVObjects()) { // Lets compress this struct into 20 and 16 bits fields: // object_vec.push_back(PARSECACHE::CreateVObject(builder, - // toCacheSym(object.m_name), - // object.m_uniqueId, - // object.m_type, - // object.m_column, - // object.m_line, - // object.m_parent, - // object.m_definition, - // object.m_child, - // object.m_sibling)); + // toCacheSym(object.m_name), + // object.m_uniqueId, + // object.m_type, + // object.m_column, + // object.m_line, + // object.m_parent, + // object.m_definition, + // object.m_child, + // object.m_sibling)); uint64_t field1 = 0; uint64_t field2 = 0; @@ -246,7 +256,7 @@ std::vector Cache::cacheVObjects( field2 |= 0xFFFFFF0000000000 & (((uint64_t)(RawNodeId)object.m_child) << (12 + 28)); field3 |= 0x000000000000000F & (((uint64_t)(RawNodeId)object.m_child) >> (24)); field3 |= 0x00000000FFFFFFF0 & (((uint64_t)(RawNodeId)object.m_sibling) << (4)); - field3 |= 0x00FFFFFF00000000 & (toCacheSym(object.m_fileId) << (4 + 28)); + field3 |= 0x00FFFFFF00000000 & (toCachePath(object.m_fileId) << (4 + 28)); field3 |= 0xFF00000000000000 & (((uint64_t)object.m_line) << (4 + 28 + 24)); field4 |= 0x000000000000FFFF & (((uint64_t)object.m_line) >> (8)); field4 |= 0x000000FFFFFF0000 & (((uint64_t)object.m_endLine) << (16)); @@ -261,7 +271,7 @@ std::vector Cache::cacheVObjects( void Cache::restoreVObjects( const flatbuffers::Vector* objects, - const SymbolTable& cacheSymbols, SymbolTable* localSymbols, SymbolId fileId, + const SymbolTable& cacheSymbols, SymbolTable* localSymbols, PathId fileId, FileContent* fileContent) { restoreVObjects(objects, cacheSymbols, localSymbols, fileId, fileContent->mutableVObjects()); @@ -269,8 +279,9 @@ void Cache::restoreVObjects( void Cache::restoreVObjects( const flatbuffers::Vector* objects, - const SymbolTable& cacheSymbols, SymbolTable* localSymbols, SymbolId fileId, + const SymbolTable& cacheSymbols, SymbolTable* localSymbols, PathId fileId, std::vector* result) { + FileSystem* const fileSystem = FileSystem::getInstance(); /* Restore design objects */ result->clear(); result->reserve(objects->size()); @@ -307,8 +318,8 @@ void Cache::restoreVObjects( result->emplace_back( localSymbols->registerSymbol( cacheSymbols.getSymbol(SymbolId(name, ""))), - localSymbols->registerSymbol( - cacheSymbols.getSymbol(SymbolId(fileId, ""))), + fileSystem->copy(PathId(&cacheSymbols, fileId, ""), + localSymbols), (VObjectType)type, line, column, endLine, endColumn, NodeId(parent), NodeId(definition), NodeId(child), NodeId(sibling)); } diff --git a/src/Cache/PPCache.cpp b/src/Cache/PPCache.cpp index 89fb981f81..2871494e5e 100644 --- a/src/Cache/PPCache.cpp +++ b/src/Cache/PPCache.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -48,14 +49,13 @@ static const char FlbSchemaVersion[] = "1.3"; // TODO(hzeller): this should come from a function cacheFileResolver() or // something that can be passed to the cache. That way, we can leave the // somewhat hard-coded notion of where cache files are. -fs::path PPCache::getCacheFileName_(const fs::path& requested_file) { +PathId PPCache::getCacheFileId_(PathId requestedFileId) { + FileSystem* const fileSystem = FileSystem::getInstance(); Precompiled* prec = Precompiled::getSingleton(); CommandLineParser* clp = m_pp->getCompileSourceFile()->getCommandLineParser(); - SymbolId cacheDirId = clp->getCacheDir(); - - const fs::path svFileName = - requested_file.empty() ? m_pp->getFileName(LINE1) : requested_file; + if (!requestedFileId) requestedFileId = m_pp->getFileId(LINE1); + const fs::path svFileName = fileSystem->toPath(requestedFileId); const fs::path baseFileName = FileUtils::basename(svFileName); const fs::path filePath = FileUtils::getPathName(svFileName); fs::path hashedPath = @@ -64,30 +64,28 @@ fs::path PPCache::getCacheFileName_(const fs::path& requested_file) { if (clp->parseOnly()) { fileName = filePath / baseFileName; } - if (prec->isFilePrecompiled(baseFileName)) { - fs::path packageRepDir = m_pp->getSymbol(m_pp->getCompileSourceFile() - ->getCommandLineParser() - ->getPrecompiledDir()); - cacheDirId = m_pp->getCompileSourceFile() - ->getCommandLineParser() - ->mutableSymbolTable() - ->registerSymbol(packageRepDir.string()); + + PathId cacheDirId = clp->getCacheDirId(); + if (prec->isFilePrecompiled(baseFileName.string())) { + cacheDirId = fileSystem->copy( + m_pp->getCompileSourceFile() + ->getCommandLineParser() + ->getPrecompiledDirId(), + m_pp->getCompileSourceFile()->getCommandLineParser()->getSymbolTable()); m_isPrecompiled = true; fileName = baseFileName; - hashedPath = ""; + hashedPath.clear(); } - fs::path cacheDirName = m_pp->getSymbol(cacheDirId); - + fs::path cacheDirName = fileSystem->toPath(cacheDirId); Library* lib = m_pp->getLibrary(); std::string libName = lib->getName(); - if (clp->parseOnly()) { - libName = ""; - } + if (clp->parseOnly()) libName.clear(); fs::path cacheFileName = cacheDirName / libName / (fileName.string() + ".slpp"); FileUtils::mkDirs(cacheDirName / libName / hashedPath); - return cacheFileName; + return fileSystem->toPathId(cacheFileName, + m_pp->getCompileSourceFile()->getSymbolTable()); } template @@ -97,15 +95,18 @@ static bool compareVectors(std::vector a, std::vector b) { return (a == b); } -bool PPCache::restore_(const fs::path& cacheFileName, +bool PPCache::restore_(PathId cacheFileId, const std::unique_ptr& buffer, bool errorsOnly, int recursionDepth) { if (buffer == nullptr) return false; + FileSystem* const fileSystem = FileSystem::getInstance(); const MACROCACHE::PPCache* ppcache = MACROCACHE::GetPPCache(buffer.get()); // std::cout << "RESTORING FILE: " << cacheFileName << std::endl; SymbolTable cacheSymbols; - restoreErrors(ppcache->errors(), ppcache->symbols(), &cacheSymbols, + restoreSymbols(ppcache->symbols(), &cacheSymbols); + + restoreErrors(ppcache->errors(), &cacheSymbols, m_pp->getCompileSourceFile()->getErrorContainer(), m_pp->getCompileSourceFile()->getSymbolTable()); @@ -116,30 +117,30 @@ bool PPCache::restore_(const fs::path& cacheFileName, // std::cout << "RESTORING MACRO: " << macro->name()->str() << std::endl; std::vector args; for (const auto* macro_arg : *macro->arguments()) { - args.push_back(macro_arg->str()); + args.emplace_back(macro_arg->string_view()); } std::vector tokens; tokens.reserve(macro->tokens()->size()); for (const auto* macro_token : *macro->tokens()) { - tokens.push_back(macro_token->str()); + tokens.emplace_back(macro_token->string_view()); } m_pp->recordMacro( - macro->name()->str(), - m_pp->getCompileSourceFile()->getSymbolTable()->registerSymbol( - cacheSymbols.getSymbol(SymbolId(macro->file_id(), ""))), + cacheSymbols.getSymbol(SymbolId(macro->name_id(), "")), + fileSystem->copy(PathId(&cacheSymbols, macro->file_id(), ""), + m_pp->getCompileSourceFile()->getSymbolTable()), macro->start_line(), macro->start_column(), macro->end_line(), macro->end_column(), args, tokens); } /* Restore `timescale directives */ if (!errorsOnly) { + SymbolTable* localSymbols = m_pp->getCompileSourceFile()->getSymbolTable(); for (const CACHE::TimeInfo* fbtimeinfo : *ppcache->time_info()) { TimeInfo timeInfo; timeInfo.m_type = (TimeInfo::Type)fbtimeinfo->type(); - timeInfo.m_fileId = - m_pp->getCompileSourceFile()->getSymbolTable()->registerSymbol( - cacheSymbols.getSymbol( - SymbolId(fbtimeinfo->file_id(), ""))); + timeInfo.m_fileId = fileSystem->copy( + PathId(&cacheSymbols, fbtimeinfo->file_id(), BadRawPath), + m_pp->getCompileSourceFile()->getSymbolTable()); timeInfo.m_line = fbtimeinfo->line(); timeInfo.m_timeUnit = (TimeInfo::Unit)fbtimeinfo->time_unit(); timeInfo.m_timeUnitValue = fbtimeinfo->time_unit_value(); @@ -153,11 +154,11 @@ bool PPCache::restore_(const fs::path& cacheFileName, if (recursionDepth == 0) { const auto* lineinfos = ppcache->line_translation_vec(); for (const MACROCACHE::LineTranslationInfo* lineinfo : *lineinfos) { - const fs::path pretendFileName = lineinfo->pretend_file()->str(); + PathId pretendFileId = fileSystem->copy( + PathId(&cacheSymbols, lineinfo->pretend_file_id(), ""), + m_pp->getCompileSourceFile()->getSymbolTable()); PreprocessFile::LineTranslationInfo lineFileInfo( - m_pp->getCompileSourceFile()->getSymbolTable()->registerSymbol( - pretendFileName.string()), - lineinfo->original_line(), lineinfo->pretend_line()); + pretendFileId, lineinfo->original_line(), lineinfo->pretend_line()); m_pp->addLineTranslationInfo(lineFileInfo); } } @@ -165,15 +166,15 @@ bool PPCache::restore_(const fs::path& cacheFileName, /* Restore include file info */ if (recursionDepth == 0) m_pp->clearIncludeFileInfo(); for (const auto* incinfo : *ppcache->include_file_info()) { - const fs::path sectionFileName = incinfo->section_file()->str(); + PathId sectionFileId = fileSystem->copy( + PathId(&cacheSymbols, incinfo->section_file_id(), ""), + m_pp->getCompileSourceFile()->getSymbolTable()); // std::cout << "read sectionFile: " << sectionFileName << " s:" << // incinfo->m_sectionStartLine() << " o:" << incinfo->m_originalLine() << // " t:" << incinfo->m_type() << "\n"; m_pp->addIncludeFileInfo( static_cast(incinfo->context()), - incinfo->section_start_line(), - m_pp->getCompileSourceFile()->getSymbolTable()->registerSymbol( - sectionFileName.string()), + incinfo->section_start_line(), sectionFileId, incinfo->original_start_line(), incinfo->original_start_column(), incinfo->original_end_line(), incinfo->original_end_column(), static_cast(incinfo->action()), @@ -182,9 +183,11 @@ bool PPCache::restore_(const fs::path& cacheFileName, // Includes if (auto includes = ppcache->includes()) { - for (const auto* include : *includes) { - restore_(getCacheFileName_(include->str()), errorsOnly, - recursionDepth + 1); + for (auto include : *includes) { + PathId includeFileId = + fileSystem->copy(PathId(&cacheSymbols, include, ""), + m_pp->getCompileSourceFile()->getSymbolTable()); + restore_(getCacheFileId_(includeFileId), errorsOnly, recursionDepth + 1); } } // File Body @@ -196,11 +199,10 @@ bool PPCache::restore_(const fs::path& cacheFileName, // FileContent FileContent* fileContent = m_pp->getFileContent(); if (fileContent == nullptr) { - fileContent = - new FileContent(m_pp->getFileId(0), m_pp->getLibrary(), - m_pp->getCompileSourceFile()->getSymbolTable(), - m_pp->getCompileSourceFile()->getErrorContainer(), - nullptr, BadSymbolId); + fileContent = new FileContent( + m_pp->getFileId(0), m_pp->getLibrary(), + m_pp->getCompileSourceFile()->getSymbolTable(), + m_pp->getCompileSourceFile()->getErrorContainer(), nullptr, BadPathId); m_pp->setFileContent(fileContent); m_pp->getCompileSourceFile()->getCompiler()->getDesign()->addPPFileContent( m_pp->getFileId(0), fileContent); @@ -215,13 +217,13 @@ bool PPCache::restore_(const fs::path& cacheFileName, return true; } -bool PPCache::restore_(const fs::path& cacheFileName, bool errorsOnly, +bool PPCache::restore_(PathId cacheFileId, bool errorsOnly, int recursionDepth) { - return restore_(cacheFileName, openFlatBuffers(cacheFileName), errorsOnly, + return restore_(cacheFileId, openFlatBuffers(cacheFileId), errorsOnly, recursionDepth); } -bool PPCache::checkCacheIsValid_(const fs::path& cacheFileName, +bool PPCache::checkCacheIsValid_(PathId cacheFileId, const std::unique_ptr& buffer) { if (buffer == nullptr) return false; @@ -236,11 +238,14 @@ bool PPCache::checkCacheIsValid_(const fs::path& cacheFileName, if (clp->noCacheHash()) { return true; } + FileSystem* const fileSystem = FileSystem::getInstance(); const MACROCACHE::PPCache* ppcache = MACROCACHE::GetPPCache(buffer.get()); auto header = ppcache->header(); + const auto cacheSymbols = ppcache->symbols(); + if (!m_isPrecompiled) { - if (!checkIfCacheIsValid(header, FlbSchemaVersion, cacheFileName)) { + if (!checkIfCacheIsValid(header, FlbSchemaVersion, cacheFileId)) { return false; } @@ -250,15 +255,14 @@ bool PPCache::checkCacheIsValid_(const fs::path& cacheFileName, std::vector include_path_vec; include_path_vec.reserve(includePathList.size()); for (const auto& path : includePathList) { - fs::path spath = m_pp->getSymbol(path); - include_path_vec.push_back(spath); + include_path_vec.emplace_back(fileSystem->toPath(path)); } std::vector cache_include_path_vec; cache_include_path_vec.reserve(ppcache->cmd_include_paths()->size()); - for (const auto* include_path : *ppcache->cmd_include_paths()) { - const fs::path path = include_path->str(); - cache_include_path_vec.push_back(path); + for (auto include : *ppcache->cmd_include_paths()) { + cache_include_path_vec.emplace_back( + cacheSymbols->Get(include)->string_view()); } if (!compareVectors(include_path_vec, cache_include_path_vec)) { return false; @@ -272,14 +276,13 @@ bool PPCache::checkCacheIsValid_(const fs::path& cacheFileName, for (const auto& definePair : defineList) { std::string spath = m_pp->getSymbol(definePair.first) + "=" + definePair.second; - define_vec.push_back(spath); + define_vec.emplace_back(std::move(spath)); } std::vector cache_define_vec; cache_define_vec.reserve(ppcache->cmd_define_options()->size()); for (const auto* cmd_define_option : *ppcache->cmd_define_options()) { - const std::string path = cmd_define_option->str(); - cache_define_vec.push_back(path); + cache_define_vec.emplace_back(cmd_define_option->string_view()); } if (!compareVectors(define_vec, cache_define_vec)) { return false; @@ -287,8 +290,11 @@ bool PPCache::checkCacheIsValid_(const fs::path& cacheFileName, /* All includes*/ if (auto includes = ppcache->includes()) { - for (const auto* include : *includes) { - if (!checkCacheIsValid_(getCacheFileName_(include->str()))) { + for (auto include : *includes) { + PathId includeFileId = fileSystem->toPathId( + cacheSymbols->Get(include)->string_view(), + m_pp->getCompileSourceFile()->getSymbolTable()); + if (!checkCacheIsValid_(getCacheFileId_(includeFileId))) { return false; } } @@ -298,13 +304,13 @@ bool PPCache::checkCacheIsValid_(const fs::path& cacheFileName, return true; } -bool PPCache::checkCacheIsValid_(const fs::path& cacheFileName) { +bool PPCache::checkCacheIsValid_(PathId cacheFileId) { CommandLineParser* clp = m_pp->getCompileSourceFile()->getCommandLineParser(); if (clp->parseOnly() || clp->lowMem()) { return true; } - return checkCacheIsValid_(cacheFileName, openFlatBuffers(cacheFileName)); + return checkCacheIsValid_(cacheFileId, openFlatBuffers(cacheFileId)); } bool PPCache::restore(bool errorsOnly) { @@ -313,15 +319,16 @@ bool PPCache::restore(bool errorsOnly) { if (!cacheAllowed) return false; if (m_pp->isMacroBody()) return false; - fs::path cacheFileName = getCacheFileName_(); - auto buffer = openFlatBuffers(cacheFileName); + PathId cacheFileId = getCacheFileId_(BadPathId); + auto buffer = openFlatBuffers(cacheFileId); if (buffer == nullptr) return false; - return checkCacheIsValid_(cacheFileName, buffer) && - restore_(cacheFileName, buffer, errorsOnly, 0); + return checkCacheIsValid_(cacheFileId, buffer) && + restore_(cacheFileId, buffer, errorsOnly, 0); } bool PPCache::save() { + FileSystem* const fileSystem = FileSystem::getInstance(); bool cacheAllowed = m_pp->getCompileSourceFile()->getCommandLineParser()->cacheAllowed(); if (!cacheAllowed) return false; @@ -336,16 +343,16 @@ bool PPCache::save() { return false; } } - const fs::path& svFileName = m_pp->getFileName(LINE1); - const fs::path& origFileName = svFileName; - const fs::path& cacheFileName = getCacheFileName_(); + + PathId origFileId = m_pp->getFileId(LINE1); + PathId cacheFileId = getCacheFileId_(BadPathId); // std::cout << "SAVING FILE: " << cacheFileName << std::endl; if (m_pp->isMacroBody()) return false; flatbuffers::FlatBufferBuilder builder(1024); SymbolTable cacheSymbols; /* Create header section */ - auto header = createHeader(builder, FlbSchemaVersion, origFileName); + auto header = createHeader(builder, FlbSchemaVersion, origFileId); /* Cache the macro definitions */ const MacroStorage& macros = m_pp->getMacros(); @@ -353,7 +360,6 @@ bool PPCache::save() { for (const auto& [macroName, infoVec] : macros) { for (const auto& info : infoVec) { // std::cout << "SAVING MACRO: " << macroName << std::endl; - auto name = builder.CreateString(macroName); MACROCACHE::MacroType type = (info->m_type == MacroInfo::WITH_ARGS) ? MACROCACHE::MacroType_WITH_ARGS : MACROCACHE::MacroType_NO_ARGS; @@ -370,11 +376,9 @@ bool PPCache::save() { } */ auto tokens = builder.CreateVectorOfStrings(info->m_tokens); - macro_vec.push_back(MACROCACHE::CreateMacro( - builder, name, type, - (RawSymbolId)cacheSymbols.registerSymbol( - m_pp->getCompileSourceFile()->getSymbolTable()->getSymbol( - info->m_file)), + macro_vec.emplace_back(MACROCACHE::CreateMacro( + builder, (RawSymbolId)cacheSymbols.registerSymbol(macroName), type, + (RawPathId)fileSystem->copy(info->m_fileId, &cacheSymbols), info->m_startLine, info->m_startColumn, info->m_endLine, info->m_endColumn, args, tokens)); } @@ -382,14 +386,14 @@ bool PPCache::save() { auto macroList = builder.CreateVector(macro_vec); /* Cache Included files */ - std::vector include_vec; + std::vector include_vec; std::set included; m_pp->collectIncludedFiles(included); for (PreprocessFile* pp : included) { - fs::path svFileName = m_pp->getSymbol(pp->getRawFileId()); - include_vec.push_back(svFileName.string()); + PathId fileId = fileSystem->copy(pp->getRawFileId(), &cacheSymbols); + include_vec.emplace_back((RawPathId)fileId); } - auto includeList = builder.CreateVectorOfStrings(include_vec); + auto includeList = builder.CreateVector(include_vec); /* Cache the body of the file */ auto body = builder.CreateString(m_pp->getPreProcessedFileContent()); @@ -397,7 +401,7 @@ bool PPCache::save() { /* Cache the errors and canonical symbols */ ErrorContainer* errorContainer = m_pp->getCompileSourceFile()->getErrorContainer(); - SymbolId subjectFileId = m_pp->getFileId(LINE1); + PathId subjectFileId = m_pp->getFileId(LINE1); auto errorCache = cacheErrors(builder, &cacheSymbols, errorContainer, *m_pp->getCompileSourceFile()->getSymbolTable(), subjectFileId); @@ -405,12 +409,12 @@ bool PPCache::save() { /* Cache the include paths list */ auto includePathList = m_pp->getCompileSourceFile()->getCommandLineParser()->getIncludePaths(); - std::vector include_path_vec; - for (const auto& path : includePathList) { - std::string spath = m_pp->getSymbol(path); - include_path_vec.push_back(spath); + std::vector include_path_vec; + for (const auto& pathId : includePathList) { + PathId includePathId = fileSystem->copy(pathId, &cacheSymbols); + include_path_vec.emplace_back((RawPathId)includePathId); } - auto incPaths = builder.CreateVectorOfStrings(include_path_vec); + auto incPaths = builder.CreateVector(include_path_vec); /* Cache the defines on the command line */ auto defineList = @@ -419,7 +423,7 @@ bool PPCache::save() { for (auto& definePair : defineList) { std::string spath = m_pp->getSymbol(definePair.first) + "=" + definePair.second; - define_vec.push_back(spath); + define_vec.emplace_back(std::move(spath)); } auto defines = builder.CreateVectorOfStrings(define_vec); @@ -428,15 +432,12 @@ bool PPCache::save() { std::vector> timeinfo_vec; for (auto& info : timeinfoList) { if (info.m_fileId != m_pp->getFileId(0)) continue; - auto timeInfo = CACHE::CreateTimeInfo( + timeinfo_vec.emplace_back(CACHE::CreateTimeInfo( builder, static_cast(info.m_type), - (RawSymbolId)cacheSymbols.registerSymbol( - m_pp->getCompileSourceFile()->getSymbolTable()->getSymbol( - info.m_fileId)), - info.m_line, static_cast(info.m_timeUnit), - info.m_timeUnitValue, static_cast(info.m_timePrecision), - info.m_timePrecisionValue); - timeinfo_vec.push_back(timeInfo); + (RawPathId)fileSystem->copy(info.m_fileId, &cacheSymbols), info.m_line, + static_cast(info.m_timeUnit), info.m_timeUnitValue, + static_cast(info.m_timePrecision), + info.m_timePrecisionValue)); } auto timeinfoFBList = builder.CreateVector(timeinfo_vec); @@ -445,13 +446,11 @@ bool PPCache::save() { std::vector> linetrans_vec; for (const auto& info : lineTranslationVec) { - fs::path pretendFileName = - m_pp->getCompileSourceFile()->getSymbolTable()->getSymbol( - info.m_pretendFileId); - auto lineInfo = MACROCACHE::CreateLineTranslationInfo( - builder, builder.CreateString(pretendFileName.string()), - info.m_originalLine, info.m_pretendLine); - linetrans_vec.push_back(lineInfo); + PathId pretendFileId = + fileSystem->copy(info.m_pretendFileId, &cacheSymbols); + linetrans_vec.emplace_back(MACROCACHE::CreateLineTranslationInfo( + builder, (RawPathId)pretendFileId, info.m_originalLine, + info.m_pretendLine)); } auto lineinfoFBList = builder.CreateVector(linetrans_vec); @@ -459,20 +458,16 @@ bool PPCache::save() { auto includeInfo = m_pp->getIncludeFileInfo(); std::vector> lineinfo_vec; for (IncludeFileInfo& info : includeInfo) { - fs::path sectionFileName = - m_pp->getCompileSourceFile()->getSymbolTable()->getSymbol( - info.m_sectionFile); - auto incInfo = MACROCACHE::CreateIncludeFileInfo( + PathId sectionFileId = fileSystem->copy(info.m_sectionFile, &cacheSymbols); + lineinfo_vec.emplace_back(MACROCACHE::CreateIncludeFileInfo( builder, static_cast(info.m_context), info.m_sectionStartLine, - builder.CreateString(sectionFileName.string()), - info.m_originalStartLine, info.m_originalStartColumn, - info.m_originalEndLine, info.m_originalEndColumn, - static_cast(info.m_action), info.m_indexOpening, - info.m_indexClosing); + (RawPathId)sectionFileId, info.m_originalStartLine, + info.m_originalStartColumn, info.m_originalEndLine, + info.m_originalEndColumn, static_cast(info.m_action), + info.m_indexOpening, info.m_indexClosing)); // std::cout << "save sectionFile: " << sectionFileName << " s:" << // info.m_sectionStartLine << " o:" << info.m_originalLine << " t:" << // info.m_type << "\n"; - lineinfo_vec.push_back(incInfo); } auto incinfoFBList = builder.CreateVector(lineinfo_vec); @@ -482,7 +477,7 @@ bool PPCache::save() { m_pp->getFileId(0)); auto objectList = builder.CreateVectorOfStructs(object_vec); - auto symbolVec = createSymbolCache(builder, cacheSymbols); + auto symbolVec = builder.CreateVectorOfStrings(cacheSymbols.getSymbols()); /* Create Flatbuffers */ auto ppcache = MACROCACHE::CreatePPCache( builder, header, macroList, includeList, body, errorCache, symbolVec, @@ -491,7 +486,7 @@ bool PPCache::save() { FinishPPCacheBuffer(builder, ppcache); /* Save Flatbuffer */ - bool status = saveFlatbuffers(builder, cacheFileName); + bool status = saveFlatbuffers(builder, cacheFileId); return status; } diff --git a/src/Cache/ParseCache.cpp b/src/Cache/ParseCache.cpp index a9bfc2cf20..e7081a0ba9 100644 --- a/src/Cache/ParseCache.cpp +++ b/src/Cache/ParseCache.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -46,43 +47,41 @@ static constexpr char FlbSchemaVersion[] = "1.2"; // TODO(hzeller): this should come from a function cacheFileResolver() or // something that can be passed to the cache. That way, we can leave the // somewhat hard-coded notion of where cache files are. -fs::path ParseCache::getCacheFileName_(const fs::path& svFileNameIn) { - fs::path svFileName = svFileNameIn; +PathId ParseCache::getCacheFileName_(PathId svFileNameId) { + FileSystem* const fileSystem = FileSystem::getInstance(); CommandLineParser* clp = m_parse->getCompileSourceFile()->getCommandLineParser(); Precompiled* prec = Precompiled::getSingleton(); - SymbolId cacheDirId = clp->getCacheDir(); - if (svFileName.empty()) svFileName = m_parse->getPpFileName(); + if (!svFileNameId) svFileNameId = m_parse->getPpFileId(); + fs::path svFileName = fileSystem->toPath(svFileNameId); fs::path baseFileName = FileUtils::basename(svFileName); fs::path cacheFileName; - if (prec->isFilePrecompiled(baseFileName)) { - fs::path packageRepDir = m_parse->getSymbol(clp->getPrecompiledDir()); + PathId cacheDirId = clp->getCacheDirId(); + if (prec->isFilePrecompiled(baseFileName.string())) { cacheDirId = - clp->mutableSymbolTable()->registerSymbol(packageRepDir.string()); + fileSystem->copy(clp->getPrecompiledDirId(), clp->getSymbolTable()); m_isPrecompiled = true; svFileName = baseFileName; - } else { - if (clp->noCacheHash()) { - fs::path cacheDirName = m_parse->getSymbol(cacheDirId); - const std::string& svFileTemp = svFileName.string(); - std::string svFile; - int nbSlash = 0; - // Bring back the .slpa file in the cache dir instead of alongside the - // writepp source file - for (char c : svFileTemp) { - if (nbSlash >= 2) { - svFile += c; - } - if (c == '/') { - nbSlash++; - } + } else if (clp->noCacheHash()) { + fs::path cacheDirName = fileSystem->toPath(cacheDirId); + const std::string& svFileTemp = svFileName.string(); + std::string svFile; + int nbSlash = 0; + // Bring back the .slpa file in the cache dir instead of alongside the + // writepp source file + for (char c : svFileTemp) { + if (nbSlash >= 2) { + svFile += c; + } + if (c == '/') { + nbSlash++; } - cacheFileName = cacheDirName / (svFile + ".slpa"); - } else { - svFileName = svFileName.parent_path().filename() / baseFileName; } + cacheFileName = cacheDirName / (svFile + ".slpa"); + } else { + svFileName = svFileName.parent_path().filename() / baseFileName; } - fs::path cacheDirName = m_parse->getSymbol(cacheDirId); + fs::path cacheDirName = fileSystem->toPath(cacheDirId); Library* lib = m_parse->getLibrary(); std::string libName = lib->getName(); if (cacheFileName.empty()) { @@ -90,19 +89,23 @@ fs::path ParseCache::getCacheFileName_(const fs::path& svFileNameIn) { } FileUtils::mkDirs(cacheDirName / libName); - return cacheFileName; + return fileSystem->toPathId( + cacheFileName, m_parse->getCompileSourceFile()->getSymbolTable()); } -bool ParseCache::restore_(const fs::path& cacheFileName, +bool ParseCache::restore_(PathId cacheFileId, const std::unique_ptr& buffer) { if (buffer == nullptr) return false; + FileSystem* const fileSystem = FileSystem::getInstance(); /* Restore Errors */ const PARSECACHE::ParseCache* ppcache = PARSECACHE::GetParseCache(buffer.get()); SymbolTable cacheSymbols; - restoreErrors(ppcache->errors(), ppcache->symbols(), &cacheSymbols, + restoreSymbols(ppcache->symbols(), &cacheSymbols); + + restoreErrors(ppcache->errors(), &cacheSymbols, m_parse->getCompileSourceFile()->getErrorContainer(), m_parse->getCompileSourceFile()->getSymbolTable()); @@ -113,7 +116,7 @@ bool ParseCache::restore_(const fs::path& cacheFileName, new FileContent(m_parse->getFileId(0), m_parse->getLibrary(), m_parse->getCompileSourceFile()->getSymbolTable(), m_parse->getCompileSourceFile()->getErrorContainer(), - nullptr, BadSymbolId); + nullptr, BadPathId); m_parse->setFileContent(fileContent); m_parse->getCompileSourceFile()->getCompiler()->getDesign()->addFileContent( m_parse->getFileId(0), fileContent); @@ -124,18 +127,17 @@ bool ParseCache::restore_(const fs::path& cacheFileName, DesignElement* elem = new DesignElement( m_parse->getCompileSourceFile()->getSymbolTable()->registerSymbol( elemName), - m_parse->getCompileSourceFile()->getSymbolTable()->registerSymbol( - cacheSymbols.getSymbol(SymbolId(elemc->file_id(), ""))), + fileSystem->copy(PathId(&cacheSymbols, elemc->file_id(), BadRawPath), + m_parse->getCompileSourceFile()->getSymbolTable()), (DesignElement::ElemType)elemc->type(), NodeId(elemc->unique_id()), elemc->line(), elemc->column(), elemc->end_line(), elemc->end_column(), NodeId(elemc->parent())); elem->m_node = NodeId(elemc->node()); elem->m_defaultNetType = (VObjectType)elemc->default_net_type(); elem->m_timeInfo.m_type = (TimeInfo::Type)elemc->time_info()->type(); - elem->m_timeInfo.m_fileId = - m_parse->getCompileSourceFile()->getSymbolTable()->registerSymbol( - cacheSymbols.getSymbol( - SymbolId(elemc->time_info()->file_id(), ""))); + elem->m_timeInfo.m_fileId = fileSystem->copy( + PathId(&cacheSymbols, elemc->time_info()->file_id(), BadRawPath), + m_parse->getCompileSourceFile()->getSymbolTable()); elem->m_timeInfo.m_line = elemc->time_info()->line(); elem->m_timeInfo.m_timeUnit = (TimeInfo::Unit)elemc->time_info()->time_unit(); @@ -158,7 +160,7 @@ bool ParseCache::restore_(const fs::path& cacheFileName, return true; } -bool ParseCache::checkCacheIsValid_(const fs::path& cacheFileName, +bool ParseCache::checkCacheIsValid_(PathId cacheFileId, const std::unique_ptr& buffer) { if (buffer == nullptr) return false; @@ -177,7 +179,7 @@ bool ParseCache::checkCacheIsValid_(const fs::path& cacheFileName, PARSECACHE::GetParseCache(buffer.get()); auto header = ppcache->header(); if (!m_isPrecompiled && - !checkIfCacheIsValid(header, FlbSchemaVersion, cacheFileName)) { + !checkIfCacheIsValid(header, FlbSchemaVersion, cacheFileId)) { return false; } @@ -185,8 +187,8 @@ bool ParseCache::checkCacheIsValid_(const fs::path& cacheFileName, } bool ParseCache::isValid() { - fs::path cacheFileName = getCacheFileName_(); - return checkCacheIsValid_(cacheFileName, openFlatBuffers(cacheFileName)); + PathId cacheFileId = getCacheFileName_(BadPathId); + return checkCacheIsValid_(cacheFileId, openFlatBuffers(cacheFileId)); } bool ParseCache::restore() { @@ -195,9 +197,9 @@ bool ParseCache::restore() { bool cacheAllowed = clp->cacheAllowed(); if (!cacheAllowed) return false; - fs::path cacheFileName = getCacheFileName_(); - auto buffer = openFlatBuffers(cacheFileName); - if (!checkCacheIsValid_(cacheFileName, buffer)) { + PathId cacheFileId = getCacheFileName_(BadPathId); + auto buffer = openFlatBuffers(cacheFileId); + if (!checkCacheIsValid_(cacheFileId, buffer)) { // char path [10000]; // char* p = getcwd(path, 9999); // if (!clp->parseOnly()) @@ -206,10 +208,11 @@ bool ParseCache::restore() { return false; } - return restore_(cacheFileName, buffer); + return restore_(cacheFileId, buffer); } bool ParseCache::save() { + FileSystem* const fileSystem = FileSystem::getInstance(); CommandLineParser* clp = m_parse->getCompileSourceFile()->getCommandLineParser(); bool cacheAllowed = clp->cacheAllowed(); @@ -226,29 +229,27 @@ bool ParseCache::save() { return false; } } - fs::path svFileName = m_parse->getPpFileName(); - fs::path origFileName = svFileName; + PathId origFileId = m_parse->getPpFileId(); + fs::path origFileName = fileSystem->toPath(origFileId); if (parseOnly) { - SymbolId cacheDirId = clp->getCacheDir(); - fs::path cacheDirName = m_parse->getSymbol(cacheDirId); - origFileName = cacheDirName / ".." / origFileName; + origFileName = + fileSystem->toPath(clp->getCacheDirId()) / ".." / origFileName; } - fs::path cacheFileName = getCacheFileName_(); - if (strstr(cacheFileName.string().c_str(), "@@BAD_SYMBOL@@")) { + PathId cacheFileId = getCacheFileName_(BadPathId); + if (!cacheFileId) { // Any fake(virtual) file like builtin.sv return true; } flatbuffers::FlatBufferBuilder builder(1024); /* Create header section */ - auto header = createHeader(builder, FlbSchemaVersion, origFileName); + auto header = createHeader(builder, FlbSchemaVersion, origFileId); /* Cache the errors and canonical symbols */ ErrorContainer* errorContainer = m_parse->getCompileSourceFile()->getErrorContainer(); - fs::path subjectFile = m_parse->getFileName(LINE1); - SymbolId subjectFileId = - m_parse->getCompileSourceFile()->getSymbolTable()->registerSymbol( - subjectFile.string()); + PathId subjectFileId = + fileSystem->copy(m_parse->getFileId(LINE1), + m_parse->getCompileSourceFile()->getSymbolTable()); SymbolTable cacheSymbols; auto errorCache = cacheErrors( builder, &cacheSymbols, errorContainer, @@ -264,17 +265,13 @@ bool ParseCache::save() { elem->m_name); auto timeInfo = CACHE::CreateTimeInfo( builder, static_cast(info.m_type), - (RawSymbolId)cacheSymbols.registerSymbol( - m_parse->getCompileSourceFile()->getSymbolTable()->getSymbol( - info.m_fileId)), + (RawPathId)fileSystem->copy(info.m_fileId, &cacheSymbols), info.m_line, static_cast(info.m_timeUnit), info.m_timeUnitValue, static_cast(info.m_timePrecision), info.m_timePrecisionValue); - element_vec.push_back(PARSECACHE::CreateDesignElement( + element_vec.emplace_back(PARSECACHE::CreateDesignElement( builder, (RawSymbolId)cacheSymbols.registerSymbol(elemName), - (RawSymbolId)cacheSymbols.registerSymbol( - m_parse->getCompileSourceFile()->getSymbolTable()->getSymbol( - elem->m_fileId)), + (RawPathId)fileSystem->copy(elem->m_fileId, &cacheSymbols), elem->m_type, (RawNodeId)elem->m_uniqueId, elem->m_line, elem->m_column, elem->m_endLine, elem->m_endColumn, timeInfo, (RawNodeId)elem->m_parent, (RawNodeId)elem->m_node, @@ -289,14 +286,14 @@ bool ParseCache::save() { m_parse->getFileId(0)); auto objectList = builder.CreateVectorOfStructs(object_vec); - auto symbolVec = createSymbolCache(builder, cacheSymbols); + auto symbolVec = builder.CreateVectorOfStrings(cacheSymbols.getSymbols()); /* Create Flatbuffers */ auto ppcache = PARSECACHE::CreateParseCache( builder, header, errorCache, symbolVec, elementList, objectList); FinishParseCacheBuffer(builder, ppcache); /* Save Flatbuffer */ - bool status = saveFlatbuffers(builder, cacheFileName); + bool status = saveFlatbuffers(builder, cacheFileId); return status; } diff --git a/src/Cache/PythonAPICache.cpp b/src/Cache/PythonAPICache.cpp index 847aba0bda..dcd3eec792 100644 --- a/src/Cache/PythonAPICache.cpp +++ b/src/Cache/PythonAPICache.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -53,50 +54,54 @@ static std::string FlbSchemaVersion = "1.0"; PythonAPICache::PythonAPICache(PythonListen* listener) : m_listener(listener) {} -std::filesystem::path PythonAPICache::getCacheFileName_( - const std::filesystem::path& svFileName) const { - std::filesystem::path svFileNamePriv = svFileName; - SymbolId cacheDirId = - m_listener->getCompileSourceFile()->getCommandLineParser()->getCacheDir(); - fs::path cacheDirName = m_listener->getParseFile()->getSymbol(cacheDirId); - if (svFileNamePriv.empty()) - svFileNamePriv = m_listener->getParseFile()->getFileName(LINE1); - svFileNamePriv = FileUtils::basename(svFileNamePriv); +PathId PythonAPICache::getCacheFileId_(PathId svFileNameId) const { + FileSystem* const fileSystem = FileSystem::getInstance(); + PathId cacheDirId = m_listener->getCompileSourceFile() + ->getCommandLineParser() + ->getCacheDirId(); + ParseFile* parseFile = m_listener->getParseFile(); + fs::path cacheDirName = fileSystem->toPath(cacheDirId); + if (!svFileNameId) svFileNameId = parseFile->getFileId(LINE1); + std::filesystem::path svFileName = fileSystem->toPath(svFileNameId); + svFileName = FileUtils::basename(svFileName); Library* lib = m_listener->getCompileSourceFile()->getLibrary(); std::string libName = lib->getName(); fs::path cacheFileName = - cacheDirName / libName / (svFileNamePriv.string() + ".slpy"); - return cacheFileName; + cacheDirName / libName / (svFileName.string() + ".slpy"); + return fileSystem->toPathId( + cacheFileName, m_listener->getCompileSourceFile()->getSymbolTable()); } -bool PythonAPICache::restore_(const std::filesystem::path& cacheFileName) { - auto buffer = openFlatBuffers(cacheFileName); +bool PythonAPICache::restore_(PathId cacheFileId) { + auto buffer = openFlatBuffers(cacheFileId); if (buffer == nullptr) return false; const PYTHONAPICACHE::PythonAPICache* ppcache = PYTHONAPICACHE::GetPythonAPICache(buffer.get()); SymbolTable canonicalSymbols; - restoreErrors(ppcache->m_errors(), ppcache->m_symbols(), &canonicalSymbols, + restoreSymbols(ppcache->m_symbols(), &canonicalSymbols); + restoreErrors(ppcache->m_errors(), &canonicalSymbols, m_listener->getCompileSourceFile()->getErrorContainer(), m_listener->getCompileSourceFile()->getSymbolTable()); return true; } -bool PythonAPICache::checkCacheIsValid_( - const std::filesystem::path& cacheFileName) { - auto buffer = openFlatBuffers(cacheFileName); +bool PythonAPICache::checkCacheIsValid_(PathId cacheFileId) { + auto buffer = openFlatBuffers(cacheFileId); if (buffer == nullptr) return false; if (!PYTHONAPICACHE::PythonAPICacheBufferHasIdentifier(buffer.get())) { return false; } + FileSystem* const fileSystem = FileSystem::getInstance(); const PYTHONAPICACHE::PythonAPICache* ppcache = PYTHONAPICACHE::GetPythonAPICache(buffer.get()); auto header = ppcache->m_header(); - auto scriptFile = ppcache->m_python_script_file()->c_str(); - if (scriptFile) { - time_t ct = get_mtime(cacheFileName.c_str()); + fs::path cacheFileName = fileSystem->toPath(cacheFileId); + auto scriptFile = ppcache->m_python_script_file()->string_view(); + if (!scriptFile.empty()) { + time_t ct = get_mtime(cacheFileName); time_t ft = get_mtime(scriptFile); if (ft == -1) { return false; @@ -109,7 +114,7 @@ bool PythonAPICache::checkCacheIsValid_( } } - if (!checkIfCacheIsValid(header, FlbSchemaVersion, cacheFileName)) { + if (!checkIfCacheIsValid(header, FlbSchemaVersion, cacheFileId)) { return false; } @@ -117,7 +122,7 @@ bool PythonAPICache::checkCacheIsValid_( } bool PythonAPICache::isValid() { - return checkCacheIsValid_(getCacheFileName_()); + return checkCacheIsValid_(getCacheFileId_(BadPathId)); } bool PythonAPICache::restore() { @@ -126,27 +131,30 @@ bool PythonAPICache::restore() { ->cacheAllowed(); if (!cacheAllowed) return false; - fs::path cacheFileName = getCacheFileName_(); - if (!checkCacheIsValid_(cacheFileName)) { + PathId cacheFileId = getCacheFileId_(BadPathId); + if (!checkCacheIsValid_(cacheFileId)) { return false; } - return restore_(cacheFileName); + return restore_(cacheFileId); } bool PythonAPICache::save() { + FileSystem* const fileSystem = FileSystem::getInstance(); bool cacheAllowed = m_listener->getCompileSourceFile() ->getCommandLineParser() ->cacheAllowed(); if (!cacheAllowed) return false; - fs::path svFileName = m_listener->getParseFile()->getPpFileName(); + ParseFile* parseFile = m_listener->getParseFile(); + SymbolTable* symbolTable = parseFile->getSymbolTable(); + fs::path svFileName = fileSystem->toPath(parseFile->getPpFileId()); fs::path origFileName = svFileName; - - fs::path cacheFileName = getCacheFileName_(); + PathId cacheFileId = getCacheFileId_(BadPathId); flatbuffers::FlatBufferBuilder builder(1024); /* Create header section */ - auto header = createHeader(builder, FlbSchemaVersion, origFileName.string()); + auto header = + createHeader(builder, FlbSchemaVersion, parseFile->getPpFileId()); std::string pythonScriptFile = PythonAPI::getListenerScript(); auto scriptFile = builder.CreateString(pythonScriptFile); @@ -154,21 +162,21 @@ bool PythonAPICache::save() { /* Cache the errors and canonical symbols */ ErrorContainer* errorContainer = m_listener->getCompileSourceFile()->getErrorContainer(); - SymbolId subjectFileId = m_listener->getParseFile()->getFileId(LINE1); + PathId subjectFileId = m_listener->getParseFile()->getFileId(LINE1); SymbolTable canonicalSymbols; auto errorCache = cacheErrors( builder, &canonicalSymbols, errorContainer, *m_listener->getCompileSourceFile()->getSymbolTable(), subjectFileId); - auto symbolVec = createSymbolCache(builder, canonicalSymbols); - ; + auto symbolVec = builder.CreateVectorOfStrings(canonicalSymbols.getSymbols()); + /* Create Flatbuffers */ auto ppcache = PYTHONAPICACHE::CreatePythonAPICache( builder, header, scriptFile, errorCache, symbolVec); FinishPythonAPICacheBuffer(builder, ppcache); /* Save Flatbuffer */ - bool status = saveFlatbuffers(builder, cacheFileName.string()); + bool status = saveFlatbuffers(builder, cacheFileId); return status; } diff --git a/src/Cache/preproc.fbs b/src/Cache/preproc.fbs index e737ad2680..df40b63866 100644 --- a/src/Cache/preproc.fbs +++ b/src/Cache/preproc.fbs @@ -27,7 +27,7 @@ namespace SURELOG.MACROCACHE; enum MacroType :byte { NO_ARGS = 0, WITH_ARGS = 1 } table Macro { - name:string; + name_id:ulong; type:MacroType; file_id:uint; start_line:uint; @@ -41,7 +41,7 @@ table Macro { table IncludeFileInfo { context:uint; section_start_line:uint; - section_file:string; + section_file_id:ulong; original_start_line:uint; original_start_column:uint; original_end_line:uint; @@ -52,7 +52,7 @@ table IncludeFileInfo { } table LineTranslationInfo { - pretend_file:string; + pretend_file_id:ulong; original_line:uint; pretend_line:uint; } @@ -60,11 +60,11 @@ table LineTranslationInfo { table PPCache { header:CACHE.Header; macros:[Macro]; - includes:[string]; + includes:[ulong]; body:string; errors:[CACHE.Error]; symbols:[string]; - cmd_include_paths:[string]; + cmd_include_paths:[ulong]; cmd_define_options:[string]; time_info:[CACHE.TimeInfo]; line_translation_vec:[LineTranslationInfo]; diff --git a/src/CommandLine/CommandLineParser.cpp b/src/CommandLine/CommandLineParser.cpp index 541ca32bea..8c7dbbda36 100644 --- a/src/CommandLine/CommandLineParser.cpp +++ b/src/CommandLine/CommandLineParser.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -313,9 +314,8 @@ void CommandLineParser::logFooter() { CommandLineParser::CommandLineParser(ErrorContainer* errors, SymbolTable* symbolTable, - bool diff_comp_mode, bool fileUnit) - : m_writePpOutputFileId(BadSymbolId), - m_writePpOutput(false), + bool diffCompMode, bool fileUnit) + : m_writePpOutput(false), m_filterFileLine(true), m_debugLevel(0), m_errors(errors), @@ -327,7 +327,7 @@ CommandLineParser::CommandLineParser(ErrorContainer* errors, m_nolibcell(false), m_muteStdout(false), m_verbose(false), - m_fileunit(fileUnit), + m_fileUnit(fileUnit), m_filterSimpleDirectives(false), m_filterProtectedRegions(false), m_filterComments(false), @@ -337,14 +337,12 @@ CommandLineParser::CommandLineParser(ErrorContainer* errors, m_elaborate(false), m_parametersubstitution(true), m_letexprsubstitution(true), - m_diff_comp_mode(diff_comp_mode), + m_diffCompMode(diffCompMode), m_help(false), m_cacheAllowed(true), m_debugCache(false), m_nbMaxTreads(0), m_nbMaxProcesses(0), - m_fullCompileDir(BadSymbolId), - m_cacheDirId(BadSymbolId), m_note(true), m_info(true), m_warning(true), @@ -361,9 +359,6 @@ CommandLineParser::CommandLineParser(ErrorContainer* errors, m_nbLinesForFileSplitting(10000000), m_pythonEvalScriptPerFile(false), m_pythonEvalScript(false), - m_pythonEvalScriptPerFileId(BadSymbolId), - m_pythonEvalScriptId(BadSymbolId), - m_pythonListenerFileId(BadSymbolId), m_debugIncludeFileInfo(false), m_createCache(false), m_profile(false), @@ -382,17 +377,20 @@ CommandLineParser::CommandLineParser(ErrorContainer* errors, m_noCacheHash(false), m_sepComp(false), m_link(false) { + FileSystem* const fileSystem = FileSystem::getInstance(); m_errors->registerCmdLine(this); - m_logFileId = m_symbolTable->registerSymbol(defaultLogFileName); - m_compileUnitDirectory = - m_symbolTable->registerSymbol(defaultCompileUnitDirName); - m_compileAllDirectory = - m_symbolTable->registerSymbol(defaultCompileAllDirName); - m_outputDir = m_symbolTable->registerSymbol("."); + m_logFileId = fileSystem->toPathId(defaultLogFileName, m_symbolTable); + m_compileUnitDirId = + fileSystem->toPathId(defaultCompileUnitDirName, m_symbolTable); + m_compileAllDirId = + fileSystem->toPathId(defaultCompileAllDirName, m_symbolTable); + m_outputDirId = fileSystem->toPathId(".", m_symbolTable); m_defaultLogFileId = m_symbolTable->registerSymbol(defaultLogFileName); - m_defaultCacheDirId = m_symbolTable->registerSymbol(defaultCacheDirName); - m_precompiledDirId = m_symbolTable->registerSymbol(defaultPrecompiledDirName); - if (m_diff_comp_mode) { + m_defaultCacheDirId = + fileSystem->toPathId(defaultCacheDirName, m_symbolTable); + m_precompiledDirId = + fileSystem->toPathId(defaultPrecompiledDirName, m_symbolTable); + if (m_diffCompMode) { m_muteStdout = true; m_verbose = false; } @@ -423,7 +421,7 @@ static std::string_view undecorateArg(std::string_view arg) { void CommandLineParser::splitPlusArg_(const std::string& s, const std::string& prefix, - std::vector& container) { + SymbolIdVector& container) { std::istringstream f(s); std::string tmp; while (getline(f, tmp, '+')) { @@ -452,6 +450,20 @@ void CommandLineParser::splitEqArg_( } } +void CommandLineParser::splitPlusArg_(const std::string& s, + const std::string& prefix, + PathIdVector& container) { + FileSystem* const fileSystem = FileSystem::getInstance(); + std::istringstream f(s); + std::string tmp; + while (getline(f, tmp, '+')) { + if (!tmp.empty() && (tmp != prefix)) { + PathId id = fileSystem->toPathId(tmp, m_symbolTable); + container.emplace_back(id); + } + } +} + void CommandLineParser::splitPlusArg_( const std::string& s, const std::string& prefix, std::map& container) { @@ -489,6 +501,7 @@ bool CommandLineParser::plus_arguments_(const std::string& s) { void CommandLineParser::processArgs_(const std::vector& args, std::vector& container) { + FileSystem* const fileSystem = FileSystem::getInstance(); for (unsigned int i = 0; i < args.size(); i++) { std::string arg(undecorateArg(args[i])); if (arg == "-cmd_ign") { @@ -579,9 +592,9 @@ void CommandLineParser::processArgs_(const std::vector& args, m_elaborate = true; m_writePpOutput = true; m_link = true; - fs::path odir = m_symbolTable->getSymbol(m_outputDir); - odir /= m_symbolTable->getSymbol( - (fileunit() ? m_compileUnitDirectory : m_compileAllDirectory)); + fs::path odir = fileSystem->toPath(m_outputDirId); + odir /= fileSystem->toPath( + (fileunit() ? m_compileUnitDirId : m_compileAllDirId)); odir = FileUtils::getPreferredPath(odir); if (FileUtils::fileExists(odir)) { for (const auto& entry : fs::directory_iterator(odir)) { @@ -615,17 +628,18 @@ void CommandLineParser::processArgs_(const std::vector& args, void CommandLineParser::processOutputDirectory_( const std::vector& args) { + FileSystem* const fileSystem = FileSystem::getInstance(); for (unsigned int i = 0; i < args.size(); i++) { std::string arg(undecorateArg(args[i])); if (arg == "-odir" || arg == "-o" || arg == "--Mdir") { if (i == args.size() - 1) { - Location loc(mutableSymbolTable()->registerSymbol(args[i])); + Location loc(m_symbolTable->registerSymbol(args[i])); Error err(ErrorDefinition::CMD_PP_FILE_MISSING_ODIR, loc); m_errors->addError(err); break; } fs::path path = FileUtils::getPreferredPath(undecorateArg(args[++i])); - m_outputDir = m_symbolTable->registerSymbol(path.string()); + m_outputDirId = fileSystem->toPathId(path, m_symbolTable); } } } @@ -666,17 +680,20 @@ static fs::path GetProgramNameAbsolutePath(const char* progname) { } bool CommandLineParser::parseCommandLine(int argc, const char** argv) { - m_exePath = GetProgramNameAbsolutePath(argv[0]); - const fs::path exe_dir = FileUtils::getPathName(m_exePath); + FileSystem* const fileSystem = FileSystem::getInstance(); + std::filesystem::path programPath = GetProgramNameAbsolutePath(argv[0]); + m_programId = fileSystem->toPathId(programPath, m_symbolTable); + + const fs::path programDir = FileUtils::getPathName(programPath); const std::vector search_path = { - exe_dir, exe_dir / ".." / "lib" / "surelog"}; + programDir, programDir / ".." / "lib" / "surelog"}; - m_precompiledDirId = m_symbolTable->registerSymbol( - FileUtils::getPreferredPath(exe_dir / "pkg").string()); + m_precompiledDirId = fileSystem->toPathId( + FileUtils::getPreferredPath(programDir / "pkg"), m_symbolTable); for (const fs::path& dir : search_path) { const fs::path pkg_dir = FileUtils::getPreferredPath(dir / "pkg"); if (FileUtils::fileIsDirectory(pkg_dir)) { - m_precompiledDirId = m_symbolTable->registerSymbol(pkg_dir.string()); + m_precompiledDirId = fileSystem->toPathId(pkg_dir, m_symbolTable); break; } } @@ -707,12 +724,11 @@ bool CommandLineParser::parseCommandLine(int argc, const char** argv) { } } } else if (arg == "-builtin") { - if (i < argc - 1) { - m_builtinPath = undecorateArg(argv[i + 1]); - } + ++i; // Deprecated and ignored! } else if (arg == "-l") { if (i < argc - 1) { - m_logFileId = m_symbolTable->registerSymbol(undecorateArg(argv[i + 1])); + m_logFileId = + fileSystem->toPathId(undecorateArg(argv[i + 1]), m_symbolTable); } } else if (arg.find("-D") == 0) { std::string def; @@ -749,8 +765,8 @@ bool CommandLineParser::parseCommandLine(int argc, const char** argv) { if (argument == "-nobuiltin") { m_parseBuiltIn = false; } else if (argument == "-fileunit") { - if (m_diff_comp_mode == false) // Controlled by constructor - m_fileunit = true; + if (m_diffCompMode == false) // Controlled by constructor + m_fileUnit = true; } else if (argument == "-mutestdout") { m_muteStdout = true; } else if (argument == "-nopython") { @@ -767,7 +783,7 @@ bool CommandLineParser::parseCommandLine(int argc, const char** argv) { // handled by plus_arguments } else if (all_arguments[i] == "-d") { if (i == all_arguments.size() - 1) { - Location loc(mutableSymbolTable()->registerSymbol(all_arguments[i])); + Location loc(m_symbolTable->registerSymbol(all_arguments[i])); Error err(ErrorDefinition::CMD_DEBUG_MISSING_LEVEL, loc); m_errors->addError(err); break; @@ -796,7 +812,7 @@ bool CommandLineParser::parseCommandLine(int argc, const char** argv) { } else if (is_number(all_arguments[i])) { int debugLevel = std::stoi(all_arguments[i]); if (debugLevel < 0 || debugLevel > 4) { - Location loc(mutableSymbolTable()->registerSymbol(all_arguments[i])); + Location loc(m_symbolTable->registerSymbol(all_arguments[i])); Error err(ErrorDefinition::CMD_DEBUG_INCORRECT_LEVEL, loc); m_errors->addError(err); } else { @@ -834,7 +850,7 @@ bool CommandLineParser::parseCommandLine(int argc, const char** argv) { } else if (all_arguments[i].find("-timescale=") == 0) { std::string timescale = all_arguments[i].substr(11); if (timescale.empty()) { - Location loc(mutableSymbolTable()->registerSymbol(all_arguments[i])); + Location loc(m_symbolTable->registerSymbol(all_arguments[i])); Error err(ErrorDefinition::CMD_TIMESCALE_MISSING_SETTING, loc); m_errors->addError(err); break; @@ -886,16 +902,16 @@ bool CommandLineParser::parseCommandLine(int argc, const char** argv) { } else if (all_arguments[i].find("-I") == 0) { fs::path include = all_arguments[i].substr(2); if (include.empty()) { - Location loc(mutableSymbolTable()->registerSymbol(all_arguments[i])); + Location loc(m_symbolTable->registerSymbol(all_arguments[i])); Error err(ErrorDefinition::CMD_INCLUDE_PATH_DOES_NOT_EXIST, loc); m_errors->addError(err); break; } - m_includePaths.push_back(mutableSymbolTable()->registerSymbol( - FileUtils::getPreferredPath(include).string())); + m_includePaths.push_back(fileSystem->toPathId( + FileUtils::getPreferredPath(include), m_symbolTable)); } else if (all_arguments[i] == "-split") { if (i == all_arguments.size() - 1) { - Location loc(mutableSymbolTable()->registerSymbol(all_arguments[i])); + Location loc(m_symbolTable->registerSymbol(all_arguments[i])); Error err(ErrorDefinition::CMD_SPLIT_FILE_MISSING_SIZE, loc); m_errors->addError(err); break; @@ -930,7 +946,7 @@ bool CommandLineParser::parseCommandLine(int argc, const char** argv) { bool mt = ((all_arguments[i] == "-mt") || (all_arguments[i] == "--threads")); if (i == all_arguments.size() - 1) { - Location loc(mutableSymbolTable()->registerSymbol(all_arguments[i])); + Location loc(m_symbolTable->registerSymbol(all_arguments[i])); Error err(ErrorDefinition::CMD_MT_MISSING_LEVEL, loc); m_errors->addError(err); break; @@ -945,11 +961,11 @@ bool CommandLineParser::parseCommandLine(int argc, const char** argv) { maxMT = std::stoi(all_arguments[i]); } if (maxMT > 512) { - Location loc(mutableSymbolTable()->registerSymbol(all_arguments[i])); + Location loc(m_symbolTable->registerSymbol(all_arguments[i])); Error err(ErrorDefinition::CMD_MT_INCORRECT_LEVEL, loc); m_errors->addError(err); } else { - if (m_diff_comp_mode) { + if (m_diffCompMode) { unsigned int concurentThreadsSupported = std::thread::hardware_concurrency(); if (maxMT > (concurentThreadsSupported / 2)) @@ -978,7 +994,7 @@ bool CommandLineParser::parseCommandLine(int argc, const char** argv) { } if (profile()) { - Location loc(mutableSymbolTable()->registerSymbol( + Location loc(m_symbolTable->registerSymbol( StrCat(m_nbMaxProcesses, " processes and ", m_nbMaxTreads))); Error err(ErrorDefinition::CMD_NUMBER_THREADS, loc); m_errors->addError(err); @@ -1005,70 +1021,70 @@ bool CommandLineParser::parseCommandLine(int argc, const char** argv) { m_lineOffsetsAsComments = true; } else if (all_arguments[i] == "-v") { if (i == all_arguments.size() - 1) { - Location loc(mutableSymbolTable()->registerSymbol(all_arguments[i])); + Location loc(m_symbolTable->registerSymbol(all_arguments[i])); Error err(ErrorDefinition::CMD_LIBRARY_FILE_MISSING_FILE, loc); m_errors->addError(err); break; } i++; - m_libraryFiles.push_back(m_symbolTable->registerSymbol( - FileUtils::getPreferredPath(all_arguments[i]).string())); + m_libraryFiles.emplace_back(fileSystem->toPathId( + FileUtils::getPreferredPath(all_arguments[i]), m_symbolTable)); } else if (all_arguments[i] == "-y") { if (i == all_arguments.size() - 1) { - Location loc(mutableSymbolTable()->registerSymbol(all_arguments[i])); + Location loc(m_symbolTable->registerSymbol(all_arguments[i])); Error err(ErrorDefinition::CMD_LIBRARY_PATH_MISSING_PATH, loc); m_errors->addError(err); break; } i++; - m_libraryPaths.push_back(m_symbolTable->registerSymbol( - FileUtils::getPreferredPath(all_arguments[i]).string())); + m_libraryPaths.emplace_back(fileSystem->toPathId( + FileUtils::getPreferredPath(all_arguments[i]), m_symbolTable)); } else if (all_arguments[i] == "-l") { if (i == all_arguments.size() - 1) { - Location loc(mutableSymbolTable()->registerSymbol(all_arguments[i])); + Location loc(m_symbolTable->registerSymbol(all_arguments[i])); Error err(ErrorDefinition::CMD_LOG_FILE_MISSING_FILE, loc); m_errors->addError(err); break; } i++; - m_logFileId = m_symbolTable->registerSymbol(all_arguments[i]); + m_logFileId = fileSystem->toPathId(all_arguments[i], m_symbolTable); } else if (all_arguments[i] == "-L") { i++; - m_orderedLibraries.push_back(m_symbolTable->registerSymbol( - FileUtils::getPreferredPath(all_arguments[i]).string())); + m_orderedLibraries.emplace_back(fileSystem->toPathId( + FileUtils::getPreferredPath(all_arguments[i]), m_symbolTable)); } else if (all_arguments[i] == "-map") { i++; - m_libraryMapFiles.push_back(m_symbolTable->registerSymbol( - FileUtils::getPreferredPath(all_arguments[i]).string())); + m_libraryMapFiles.emplace_back(fileSystem->toPathId( + FileUtils::getPreferredPath(all_arguments[i]), m_symbolTable)); } else if (all_arguments[i] == "-cfgfile") { i++; - m_configFiles.push_back(m_symbolTable->registerSymbol( - FileUtils::getPreferredPath(all_arguments[i]).string())); + m_configFiles.emplace_back(fileSystem->toPathId( + FileUtils::getPreferredPath(all_arguments[i]), m_symbolTable)); } else if (all_arguments[i] == "-cfg") { i++; m_useConfigs.push_back(m_symbolTable->registerSymbol(all_arguments[i])); } else if (all_arguments[i] == "-writeppfile") { if (i == all_arguments.size() - 1) { - Location loc(mutableSymbolTable()->registerSymbol(all_arguments[i])); + Location loc(m_symbolTable->registerSymbol(all_arguments[i])); Error err(ErrorDefinition::CMD_PP_FILE_MISSING_FILE, loc); m_errors->addError(err); break; } i++; - m_writePpOutputFileId = m_symbolTable->registerSymbol( - FileUtils::getPreferredPath(all_arguments[i]).string()); + m_writePpOutputFileId = fileSystem->toPathId( + FileUtils::getPreferredPath(all_arguments[i]), m_symbolTable); } else if (all_arguments[i] == "-nohash") { m_noCacheHash = true; } else if (all_arguments[i] == "-cache") { if (i == all_arguments.size() - 1) { - Location loc(mutableSymbolTable()->registerSymbol(all_arguments[i])); + Location loc(m_symbolTable->registerSymbol(all_arguments[i])); Error err(ErrorDefinition::CMD_PP_FILE_MISSING_FILE, loc); m_errors->addError(err); break; } i++; - m_cacheDirId = m_symbolTable->registerSymbol( - FileUtils::getPreferredPath(all_arguments[i]).string()); + m_cacheDirId = fileSystem->toPathId( + FileUtils::getPreferredPath(all_arguments[i]), m_symbolTable); } else if (all_arguments[i] == "-replay") { m_replay = true; } else if (all_arguments[i] == "-writepp") { @@ -1098,12 +1114,12 @@ bool CommandLineParser::parseCommandLine(int argc, const char** argv) { } else if (all_arguments[i] == "-sverilog") { m_sverilog = true; } else if (all_arguments[i] == "-fileunit") { - Location loc(mutableSymbolTable()->registerSymbol(all_arguments[i])); + Location loc(m_symbolTable->registerSymbol(all_arguments[i])); Error err(ErrorDefinition::CMD_SEPARATE_COMPILATION_UNIT_ON, loc); m_errors->addError(err); } else if (all_arguments[i] == "-diffcompunit") { - if (m_fileunit) { - Location loc(mutableSymbolTable()->registerSymbol(all_arguments[i])); + if (m_fileUnit) { + Location loc(m_symbolTable->registerSymbol(all_arguments[i])); Error err(ErrorDefinition::CMD_SEPARATE_COMPILATION_UNIT_ON, loc); m_errors->addError(err); } @@ -1176,7 +1192,7 @@ bool CommandLineParser::parseCommandLine(int argc, const char** argv) { withPython(); } else if (all_arguments[i] == "-pythonevalscriptperfile") { if (i == all_arguments.size() - 1) { - Location loc(mutableSymbolTable()->registerSymbol(all_arguments[i])); + Location loc(m_symbolTable->registerSymbol(all_arguments[i])); Error err(ErrorDefinition::CMD_PP_FILE_MISSING_FILE, loc); m_errors->addError(err); break; @@ -1188,14 +1204,14 @@ bool CommandLineParser::parseCommandLine(int argc, const char** argv) { m_elaborate = true; m_pythonEvalScriptPerFile = true; m_pythonEvalScriptPerFileId = - m_symbolTable->registerSymbol(all_arguments[i]); + fileSystem->toPathId(all_arguments[i], m_symbolTable); if (m_pythonAllowed) PythonAPI::loadScript(all_arguments[i], true); else std::cerr << "ERROR: No Python allowed, check your arguments!\n"; } else if (all_arguments[i] == "-pythonlistenerfile") { if (i == all_arguments.size() - 1) { - Location loc(mutableSymbolTable()->registerSymbol(all_arguments[i])); + Location loc(m_symbolTable->registerSymbol(all_arguments[i])); Error err(ErrorDefinition::CMD_PP_FILE_MISSING_FILE, loc); m_errors->addError(err); break; @@ -1206,12 +1222,12 @@ bool CommandLineParser::parseCommandLine(int argc, const char** argv) { m_compile = true; m_elaborate = true; m_pythonListener = true; - m_pythonListenerFileId = m_symbolTable->registerSymbol( - FileUtils::getPreferredPath(all_arguments[i]).string()); + m_pythonListenerFileId = fileSystem->toPathId( + FileUtils::getPreferredPath(all_arguments[i]), m_symbolTable); PythonAPI::setListenerScript(all_arguments[i]); } else if (all_arguments[i] == "-pythonevalscript") { if (i == all_arguments.size() - 1) { - Location loc(mutableSymbolTable()->registerSymbol(all_arguments[i])); + Location loc(m_symbolTable->registerSymbol(all_arguments[i])); Error err(ErrorDefinition::CMD_PP_FILE_MISSING_FILE, loc); m_errors->addError(err); break; @@ -1222,8 +1238,8 @@ bool CommandLineParser::parseCommandLine(int argc, const char** argv) { m_compile = true; m_elaborate = true; m_pythonEvalScript = true; - m_pythonEvalScriptId = m_symbolTable->registerSymbol( - FileUtils::getPreferredPath(all_arguments[i]).string()); + m_pythonEvalScriptId = fileSystem->toPathId( + FileUtils::getPreferredPath(all_arguments[i]), m_symbolTable); if (m_pythonAllowed) PythonAPI::loadScript(all_arguments[i], true); else @@ -1233,16 +1249,15 @@ bool CommandLineParser::parseCommandLine(int argc, const char** argv) { } else if (all_arguments[i] == "-sv") { if (((i + 1) < all_arguments.size()) && (all_arguments[i + 1][0] != '-')) { - ++i; - fs::path svpath = FileUtils::getPreferredPath(all_arguments[i]); + fs::path svpath = FileUtils::getPreferredPath(all_arguments[++i]); if (FileUtils::fileExists(svpath)) { - SymbolId id = m_symbolTable->registerSymbol(svpath.string()); + PathId id = fileSystem->toPathId(svpath, m_symbolTable); m_sourceFiles.push_back(id); fs::path fileName = FileUtils::basename(svpath); - m_svSourceFiles.insert(fileName); + m_svSourceFiles.insert(id); fs::path path = FileUtils::getPathName(svpath); if (!path.empty()) { - SymbolId pathId = m_symbolTable->registerSymbol(path.string()); + PathId pathId = fileSystem->toPathId(path, m_symbolTable); if (m_includePathSet.find(pathId) == m_includePathSet.end()) { m_includePathSet.insert(pathId); m_includePaths.push_back(pathId); @@ -1253,35 +1268,35 @@ bool CommandLineParser::parseCommandLine(int argc, const char** argv) { m_sverilog = true; } } else if (all_arguments[i] == "--x-assign") { - Location loc(mutableSymbolTable()->registerSymbol(all_arguments[i])); + Location loc(m_symbolTable->registerSymbol(all_arguments[i])); Error err(ErrorDefinition::CMD_PLUS_ARG_IGNORED, loc); m_errors->addError(err); i++; } else if (all_arguments[i] == "--x-initial") { - Location loc(mutableSymbolTable()->registerSymbol(all_arguments[i])); + Location loc(m_symbolTable->registerSymbol(all_arguments[i])); Error err(ErrorDefinition::CMD_PLUS_ARG_IGNORED, loc); m_errors->addError(err); i++; } else if (all_arguments[i].at(0) == '+') { - Location loc(mutableSymbolTable()->registerSymbol(all_arguments[i])); + Location loc(m_symbolTable->registerSymbol(all_arguments[i])); Error err(ErrorDefinition::CMD_PLUS_ARG_IGNORED, loc); m_errors->addError(err); } else if (all_arguments[i].at(0) == '-') { - Location loc(mutableSymbolTable()->registerSymbol(all_arguments[i])); + Location loc(m_symbolTable->registerSymbol(all_arguments[i])); Error err(ErrorDefinition::CMD_MINUS_ARG_IGNORED, loc); m_errors->addError(err); } else if ((all_arguments[i][0] == '-') || is_number(all_arguments[i]) || is_c_file(all_arguments[i]) || (all_arguments[i].rfind(".vlt") != std::string::npos)) { - Location loc(mutableSymbolTable()->registerSymbol(all_arguments[i])); + Location loc(m_symbolTable->registerSymbol(all_arguments[i])); Error err(ErrorDefinition::CMD_PLUS_ARG_IGNORED, loc); m_errors->addError(err); } else { fs::path path = FileUtils::getPreferredPath(all_arguments[i]); - m_sourceFiles.push_back(m_symbolTable->registerSymbol(path.string())); + m_sourceFiles.push_back(fileSystem->toPathId(path, m_symbolTable)); fs::path name = FileUtils::getPathName(path); if (!name.empty()) { - SymbolId pathId = m_symbolTable->registerSymbol(name.string()); + PathId pathId = fileSystem->toPathId(name, m_symbolTable); if (m_includePathSet.find(pathId) == m_includePathSet.end()) { m_includePathSet.insert(pathId); m_includePaths.push_back(pathId); @@ -1297,9 +1312,10 @@ bool CommandLineParser::parseCommandLine(int argc, const char** argv) { } bool CommandLineParser::checkCommandLine_() { + FileSystem* const fileSystem = FileSystem::getInstance(); bool noError = true; for (const auto& fid : m_sourceFiles) { - if (!FileUtils::fileExists(m_symbolTable->getSymbol(fid))) { + if (!FileUtils::fileExists(fileSystem->toPath(fid))) { Location loc(fid); Error err(ErrorDefinition::CMD_VERILOG_FILE_DOES_NOT_EXIST, loc); m_errors->addError(err); @@ -1307,14 +1323,14 @@ bool CommandLineParser::checkCommandLine_() { } } for (const auto& fid : m_libraryPaths) { - if (!FileUtils::fileExists(m_symbolTable->getSymbol(fid))) { + if (!FileUtils::fileExists(fileSystem->toPath(fid))) { Location loc(fid); Error err(ErrorDefinition::CMD_LIBRARY_PATH_DOES_NOT_EXIST, loc); m_errors->addError(err); } } for (const auto& fid : m_libraryFiles) { - if (!FileUtils::fileExists(m_symbolTable->getSymbol(fid))) { + if (!FileUtils::fileExists(fileSystem->toPath(fid))) { Location loc(fid); Error err(ErrorDefinition::CMD_LIBRARY_FILE_DOES_NOT_EXIST, loc); m_errors->addError(err); @@ -1322,7 +1338,7 @@ bool CommandLineParser::checkCommandLine_() { } } for (const auto& fid : m_includePaths) { - if (!FileUtils::fileExists(m_symbolTable->getSymbol(fid))) { + if (!FileUtils::fileExists(fileSystem->toPath(fid))) { Location loc(fid); Error err(ErrorDefinition::CMD_INCLUDE_PATH_DOES_NOT_EXIST, loc); m_errors->addError(err); @@ -1335,25 +1351,26 @@ bool CommandLineParser::checkCommandLine_() { return noError; } -bool CommandLineParser::isSVFile(const fs::path& name) const { - return m_svSourceFiles.find(name) != m_svSourceFiles.end(); +bool CommandLineParser::isSVFile(PathId fileId) const { + return m_svSourceFiles.find(fileId) != m_svSourceFiles.end(); } bool CommandLineParser::prepareCompilation_(int argc, const char** argv) { + FileSystem* const fileSystem = FileSystem::getInstance(); bool noError = true; - fs::path odir = m_symbolTable->getSymbol(m_outputDir); + fs::path odir = fileSystem->toPath(m_outputDirId); - odir /= m_symbolTable->getSymbol( - (fileunit() ? m_compileUnitDirectory : m_compileAllDirectory)); - m_fullCompileDir = - m_symbolTable->registerSymbol(FileUtils::getPreferredPath(odir).string()); + odir /= + fileSystem->toPath((fileunit() ? m_compileUnitDirId : m_compileAllDirId)); + m_fullCompileDirId = + fileSystem->toPathId(FileUtils::getPreferredPath(odir), m_symbolTable); - fs::path full_path = odir / m_symbolTable->getSymbol(m_logFileId); - m_logFileId = m_symbolTable->registerSymbol( - FileUtils::getPreferredPath(full_path).string()); + fs::path full_path = odir / fileSystem->toPath(m_logFileId); + m_logFileId = fileSystem->toPathId(FileUtils::getPreferredPath(full_path), + m_symbolTable); if (!FileUtils::mkDirs(odir)) { - Location loc(m_fullCompileDir); + Location loc(m_fullCompileDirId); Error err(ErrorDefinition::CMD_PP_CANNOT_CREATE_OUTPUT_DIR, loc); m_errors->addError(err); noError = false; @@ -1372,20 +1389,19 @@ bool CommandLineParser::prepareCompilation_(int argc, const char** argv) { return noError; } -bool CommandLineParser::parseBuiltIn() { return m_parseBuiltIn; } - bool CommandLineParser::setupCache_() { + FileSystem* const fileSystem = FileSystem::getInstance(); bool noError = true; fs::path cachedir; - fs::path odir = m_symbolTable->getSymbol(m_outputDir); - odir /= m_symbolTable->getSymbol( - (fileunit() ? m_compileUnitDirectory : m_compileAllDirectory)); + fs::path odir = fileSystem->toPath(m_outputDirId); + odir /= + fileSystem->toPath((fileunit() ? m_compileUnitDirId : m_compileAllDirId)); if (m_cacheDirId) { - cachedir = m_symbolTable->getSymbol(m_cacheDirId); + cachedir = fileSystem->toPath(m_cacheDirId); } else { - cachedir = odir / m_symbolTable->getSymbol(m_defaultCacheDirId); - m_cacheDirId = m_symbolTable->registerSymbol( - FileUtils::getPreferredPath(cachedir).string()); + cachedir = odir / fileSystem->toPath(m_defaultCacheDirId); + m_cacheDirId = fileSystem->toPathId(FileUtils::getPreferredPath(cachedir), + m_symbolTable); } if (m_cacheAllowed) { @@ -1403,17 +1419,18 @@ bool CommandLineParser::setupCache_() { } bool CommandLineParser::cleanCache() { + FileSystem* const fileSystem = FileSystem::getInstance(); bool noError = true; fs::path cachedir; - fs::path odir = m_symbolTable->getSymbol(m_outputDir); - odir /= m_symbolTable->getSymbol( - (fileunit() ? m_compileUnitDirectory : m_compileAllDirectory)); + fs::path odir = fileSystem->toPath(m_outputDirId); + odir /= + fileSystem->toPath((fileunit() ? m_compileUnitDirId : m_compileAllDirId)); if (m_cacheDirId) { - cachedir = m_symbolTable->getSymbol(m_cacheDirId); + cachedir = fileSystem->toPath(m_cacheDirId); } else { - cachedir = odir / m_symbolTable->getSymbol(m_defaultCacheDirId); - m_cacheDirId = m_symbolTable->registerSymbol( - FileUtils::getPreferredPath(cachedir).string()); + cachedir = odir / fileSystem->toPath(m_defaultCacheDirId); + m_cacheDirId = fileSystem->toPathId(FileUtils::getPreferredPath(cachedir), + m_symbolTable); } if (!m_cacheAllowed) { diff --git a/src/Common/FileSystem.cpp b/src/Common/FileSystem.cpp new file mode 100644 index 0000000000..4d752d7b22 --- /dev/null +++ b/src/Common/FileSystem.cpp @@ -0,0 +1,91 @@ +/* + Copyright 2022 chipsalliance + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +/* + * File: FileSystem.cpp + * Author: hs + * + * Created on June 1, 2022, 3:00 AM + */ + +#include +#include +#include + +#if defined(_MSC_VER) +#define NOMINMAX +#include +#else +#include +#include +#endif + +namespace SURELOG { +FileSystem *FileSystem::sInstance = nullptr; + +FileSystem *FileSystem::getInstance() { + if (sInstance == nullptr) { + sInstance = new FileSystem(std::filesystem::current_path()); + } + return sInstance; +} + +FileSystem *FileSystem::setInstance(FileSystem *const fileSystem) { + FileSystem *const instance = sInstance; + sInstance = fileSystem; + return instance; +} + +FileSystem::FileSystem(const std::filesystem::path &cwd) : m_cwd(cwd) {} + +FileSystem::~FileSystem() { + if (sInstance == this) setInstance(nullptr); +} + +PathId FileSystem::toPathId(const std::filesystem::path &path, + SymbolTable *const symbolTable) { + if (path.empty()) return BadPathId; + + auto [symbolId, symbol] = symbolTable->add(path.string()); + return PathId(symbolTable, (RawSymbolId)symbolId, symbol); +} + +const std::string &FileSystem::toSymbol(PathId id) { + return id ? id.getSymbolTable()->getSymbol((SymbolId)id) + : SymbolTable::getBadSymbol(); +} + +std::filesystem::path FileSystem::toPath(PathId id) { + if (!id) return std::filesystem::path(); + + const std::string &symbol = toSymbol(id); + return (symbol == BadRawSymbol) ? std::filesystem::path() + : std::filesystem::path(symbol); +} + +const std::filesystem::path &FileSystem::getCwd() { return m_cwd; } + +PathId FileSystem::getCwd(SymbolTable *const symbolTable) { + return toPathId(m_cwd, symbolTable); +} + +PathId FileSystem::copy(PathId id, SymbolTable *const toSymbolTable) { + if (!id) return BadPathId; + + const std::string &symbol = toSymbol(id); + return (symbol == BadRawSymbol) ? BadPathId : toPathId(symbol, toSymbolTable); +} +} // namespace SURELOG diff --git a/src/Common/PathId.cpp b/src/Common/PathId.cpp new file mode 100644 index 0000000000..e4d1661b35 --- /dev/null +++ b/src/Common/PathId.cpp @@ -0,0 +1,42 @@ +/* + Copyright 2019 Alain Dargelas + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +/* + * File: PathId.cpp + * Author: HS + * + * Created on July 4, 2022, 1:30 AM + */ + +#include +#include +#include + +namespace SURELOG { +std::ostream &operator<<(std::ostream &strm, const PathIdPP &id) { + return strm << FileSystem::getInstance()->toPath(id.m_id); +} + +bool PathId::operator==(const PathId &rhs) const { + FileSystem *const fileSystem = FileSystem::getInstance(); + return ((m_symbolTable != nullptr) && (rhs.m_symbolTable != nullptr) && + (m_id != BadRawPathId) && (rhs.m_id != BadRawPathId)) + ? ((m_symbolTable == rhs.m_symbolTable) && (m_id == rhs.m_id)) || + (fileSystem->toPath(*this) == fileSystem->toPath(rhs)) + : (m_symbolTable == nullptr) && (rhs.m_symbolTable == nullptr) && + (m_id == BadRawPathId) && (rhs.m_id == BadRawPathId); +} +} // namespace SURELOG diff --git a/src/Common/SymbolId.cpp b/src/Common/SymbolId.cpp new file mode 100644 index 0000000000..9f4fffedec --- /dev/null +++ b/src/Common/SymbolId.cpp @@ -0,0 +1,31 @@ +/* + Copyright 2019 Alain Dargelas + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +/* + * File: SymbolId.cpp + * Author: HS + * + * Created on July 4, 2022, 1:30 AM + */ + +#include +#include + +namespace SURELOG { +inline std::ostream &operator<<(std::ostream &strm, const SymbolIdPP &id) { + return strm << id.symbolTable->getSymbol(id.id); +} +} // namespace SURELOG diff --git a/src/Design/Design.cpp b/src/Design/Design.cpp index e62f77dd99..2715ce3641 100644 --- a/src/Design/Design.cpp +++ b/src/Design/Design.cpp @@ -63,13 +63,13 @@ Design::~Design() { } } -void Design::addFileContent(SymbolId fileId, FileContent* content) { +void Design::addFileContent(PathId fileId, FileContent* content) { m_mutex.lock(); m_fileContents.push_back(std::make_pair(fileId, content)); m_mutex.unlock(); } -void Design::addPPFileContent(SymbolId fileId, FileContent* content) { +void Design::addPPFileContent(PathId fileId, FileContent* content) { m_mutex.lock(); m_ppFileContents.push_back(std::make_pair(fileId, content)); m_mutex.unlock(); @@ -120,8 +120,7 @@ std::string Design::reportInstanceTree() const { undef = " [U]"; } std::string type_s; - Location loc(symbols->registerSymbol(tmp->getFileName().string()), - tmp->getLineNb(), tmp->getColumnNb(), + Location loc(tmp->getFileId(), tmp->getLineNb(), tmp->getColumnNb(), tmp->getFullPathId(symbols)); if (type == slUdp_instantiation) { type_s = "[UDP]"; diff --git a/src/Design/DesignElement.cpp b/src/Design/DesignElement.cpp index 57ecf7cc25..bc92c476b1 100644 --- a/src/Design/DesignElement.cpp +++ b/src/Design/DesignElement.cpp @@ -24,7 +24,7 @@ #include namespace SURELOG { -DesignElement::DesignElement(SymbolId name, SymbolId fileId, ElemType type, +DesignElement::DesignElement(SymbolId name, PathId fileId, ElemType type, NodeId uniqueId, unsigned int line, unsigned short column, unsigned int endLine, unsigned short endColumn, NodeId parent) diff --git a/src/Design/FileContent.cpp b/src/Design/FileContent.cpp index a2b5498939..2a044e2fcc 100644 --- a/src/Design/FileContent.cpp +++ b/src/Design/FileContent.cpp @@ -21,6 +21,7 @@ * Created on June 8, 2017, 8:22 PM */ +#include #include #include #include @@ -30,9 +31,9 @@ #include namespace SURELOG { -FileContent::FileContent(SymbolId fileId, Library* library, +FileContent::FileContent(PathId fileId, Library* library, SymbolTable* symbolTable, ErrorContainer* errors, - FileContent* parent, SymbolId fileChunkId) + FileContent* parent, PathId fileChunkId) : DesignComponent(nullptr, nullptr), m_fileId(fileId), m_fileChunkId(fileChunkId), @@ -40,16 +41,12 @@ FileContent::FileContent(SymbolId fileId, Library* library, m_library(library), m_symbolTable(symbolTable), m_parentFile(parent) { - addObject(BadSymbolId, BadSymbolId, sl_INVALID_, 0, 0, 0, 0, InvalidNodeId, + addObject(BadSymbolId, BadPathId, sl_INVALID_, 0, 0, 0, 0, InvalidNodeId, InvalidNodeId, InvalidNodeId, InvalidNodeId); } -const std::string& FileContent::getName() const { - return m_symbolTable->getSymbol(m_fileId); -} - -std::filesystem::path FileContent::getChunkFileName() const { - return m_symbolTable->getSymbol(m_fileChunkId); +std::string FileContent::getName() const { + return FileSystem::getInstance()->toPath(m_fileId).string(); } const std::string& FileContent::SymName(NodeId index) const { @@ -63,33 +60,25 @@ const std::string& FileContent::SymName(NodeId index) const { return m_symbolTable->getSymbol(Name(index)); } -std::filesystem::path FileContent::getFileName() const { - return m_symbolTable->getSymbol(m_fileId); -} - NodeId FileContent::getRootNode() const { return m_objects.empty() ? InvalidNodeId : m_objects[1].m_sibling; } -SymbolId FileContent::getFileId(NodeId id) const { +PathId FileContent::getFileId(NodeId id) const { return m_objects[id].m_fileId; } -SymbolId* FileContent::getMutableFileId(NodeId id) { +PathId* FileContent::getMutableFileId(NodeId id) { return &m_objects[id].m_fileId; } -std::filesystem::path FileContent::getFileName(NodeId id) const { - SymbolId fileId = m_objects[id].m_fileId; - return m_symbolTable->getSymbol(fileId); -} - std::string FileContent::printObjects() const { std::string text; NodeId index(0); if (m_library) text += "LIB: " + m_library->getName() + "\n"; - const std::filesystem::path fileName = m_symbolTable->getSymbol(m_fileId); + const std::filesystem::path fileName = + FileSystem::getInstance()->toPath(m_fileId); text += "FILE: " + fileName.string() + "\n"; for (auto& object : m_objects) { text += @@ -121,12 +110,10 @@ void FileContent::insertObjectLookup(const std::string& name, NodeId id, if (itr == m_objectLookup.end()) { m_objectLookup.insert(std::make_pair(name, id)); } else { - Location loc( - errors->getSymbolTable()->registerSymbol(getFileName(id).string()), - Line(id), Column(id), errors->getSymbolTable()->registerSymbol(name)); - Location loc2(errors->getSymbolTable()->registerSymbol( - getFileName(itr->second).string()), - Line(itr->second), Column(itr->second)); + Location loc(getFileId(id), Line(id), Column(id), + errors->getSymbolTable()->registerSymbol(name)); + Location loc2(getFileId(itr->second), Line(itr->second), + Column(itr->second)); Error err(ErrorDefinition::COMP_MULTIPLY_DEFINED_DESIGN_UNIT, loc, loc2); errors->addError(err); } @@ -205,16 +192,16 @@ std::vector FileContent::collectSubTree(NodeId index) const { return text; } -void FileContent::SetDefinitionFile(NodeId index, SymbolId def) { +void FileContent::SetDefinitionFile(NodeId index, PathId def) { m_definitionFiles.insert(std::make_pair(index, def)); } -SymbolId FileContent::GetDefinitionFile(NodeId index) const { +PathId FileContent::GetDefinitionFile(NodeId index) const { auto itr = m_definitionFiles.find(index); - return (itr == m_definitionFiles.end()) ? BadSymbolId : (*itr).second; + return (itr == m_definitionFiles.end()) ? BadPathId : itr->second; } -NodeId FileContent::addObject(SymbolId name, SymbolId fileId, VObjectType type, +NodeId FileContent::addObject(SymbolId name, PathId fileId, VObjectType type, unsigned int line, unsigned short column, unsigned int endLine, unsigned short endColumn, NodeId parent /* = InvalidNodeId */, @@ -689,7 +676,7 @@ void FileContent::populateCoreMembers(NodeId startIndex, NodeId endIndex, } } - SymbolId fileId; + PathId fileId; if (startIndex && endIndex) { const VObject& startObject = m_objects[startIndex]; const VObject& endObject = m_objects[endIndex]; @@ -716,7 +703,7 @@ void FileContent::populateCoreMembers(NodeId startIndex, NodeId endIndex, } if (fileId) { - instance->VpiFile(m_symbolTable->getSymbol(fileId)); + instance->VpiFile(FileSystem::getInstance()->toPath(fileId).string()); } } } // namespace SURELOG diff --git a/src/Design/ModuleInstance.cpp b/src/Design/ModuleInstance.cpp index be31524f1d..3cbc690664 100644 --- a/src/Design/ModuleInstance.cpp +++ b/src/Design/ModuleInstance.cpp @@ -202,14 +202,10 @@ VObjectType ModuleInstance::getModuleType() const { return type; } -SymbolId ModuleInstance::getFileId() const { +PathId ModuleInstance::getFileId() const { return m_fileContent->getFileId(m_nodeId); } -std::filesystem::path ModuleInstance::getFileName() const { - return m_fileContent->getFileName(m_nodeId); -} - unsigned int ModuleInstance::getLineNb() const { return m_fileContent->Line(m_nodeId); } diff --git a/src/Design/VObject.cpp b/src/Design/VObject.cpp index b81c822ea2..711618c453 100644 --- a/src/Design/VObject.cpp +++ b/src/Design/VObject.cpp @@ -28,8 +28,7 @@ namespace SURELOG { std::string VObject::print(SymbolTable* symbols, NodeId uniqueId, - SymbolId definitionFile, - SymbolId printedFile) const { + PathId definitionFile, PathId printedFile) const { std::string text; const std::string& symbol = symbols->getSymbol(m_name); if (symbol == SymbolTable::getBadSymbol()) { diff --git a/src/DesignCompile/Builtin.cpp b/src/DesignCompile/Builtin.cpp index 7473df194f..8ad3136b9a 100644 --- a/src/DesignCompile/Builtin.cpp +++ b/src/DesignCompile/Builtin.cpp @@ -350,8 +350,7 @@ void Builtin::addBuiltinClasses() { std::vector classes = fC1->sl_collect_all(fC1->getRootNode(), slClass_declaration); - m_compiler->getCompiler()->getDesign()->addFileContent( - fC1->getFileId(NodeId(0)), fC1); + m_compiler->getCompiler()->getDesign()->addFileContent(fC1->getFileId(), fC1); for (auto classId : classes) { NodeId stId = fC1->sl_collect(classId, VObjectType::slStringConst, VObjectType::slAttr_spec); diff --git a/src/DesignCompile/CompileClass.cpp b/src/DesignCompile/CompileClass.cpp index 28508727a1..22ea3326f9 100644 --- a/src/DesignCompile/CompileClass.cpp +++ b/src/DesignCompile/CompileClass.cpp @@ -22,6 +22,7 @@ */ #include +#include #include #include #include @@ -54,11 +55,13 @@ int FunctorCompileClass::operator()() const { bool CompileClass::compile() { if (m_class->m_fileContents.empty()) return true; + + FileSystem* const fileSystem = FileSystem::getInstance(); const FileContent* fC = m_class->m_fileContents[0]; if (fC == nullptr) return true; NodeId nodeId = m_class->m_nodeIds[0]; - fs::path fileName = fC->getFileName(nodeId); + fs::path fileName = fileSystem->toPath(fC->getFileId(nodeId)); std::string fullName; std::vector names; @@ -84,7 +87,7 @@ bool CompileClass::compile() { if (m_class->m_uhdm_definition->VpiFullName().empty()) m_class->m_uhdm_definition->VpiFullName(fullName); - Location loc(m_symbols->registerSymbol(fileName.string()), fC->Line(nodeId), + Location loc(fileSystem->toPathId(fileName, m_symbols), fC->Line(nodeId), fC->Column(nodeId), m_symbols->registerSymbol(fullName)); Error err1(ErrorDefinition::COMP_COMPILE_CLASS, loc); @@ -229,20 +232,13 @@ bool CompileClass::compile() { std::string moduleName = m_class->getName(); moduleName = StringUtils::ltrim(moduleName, '@'); if (endLabel != moduleName) { - Location loc( - m_compileDesign->getCompiler() - ->getSymbolTable() - ->registerSymbol( - fC->getFileName(m_class->getNodeIds()[0]).string()), - fC->Line(m_class->getNodeIds()[0]), - fC->Column(m_class->getNodeIds()[0]), - m_compileDesign->getCompiler() - ->getSymbolTable() - ->registerSymbol(moduleName)); - Location loc2(m_compileDesign->getCompiler() - ->getSymbolTable() - ->registerSymbol(fC->getFileName(id).string()), - fC->Line(id), fC->Column(id), + Location loc(fC->getFileId(m_class->getNodeIds()[0]), + fC->Line(m_class->getNodeIds()[0]), + fC->Column(m_class->getNodeIds()[0]), + m_compileDesign->getCompiler() + ->getSymbolTable() + ->registerSymbol(moduleName)); + Location loc2(fC->getFileId(id), fC->Line(id), fC->Column(id), m_compileDesign->getCompiler() ->getSymbolTable() ->registerSymbol(endLabel)); @@ -353,15 +349,12 @@ bool CompileClass::compile_class_property_(const FileContent* fC, NodeId id) { Property* previous = m_class->getProperty(varName); if (previous) { - Location loc1( - m_symbols->registerSymbol(fC->getFileName(var).string()), - fC->Line(var), fC->Column(var), - m_symbols->registerSymbol(varName)); + Location loc1(fC->getFileId(var), fC->Line(var), fC->Column(var), + m_symbols->registerSymbol(varName)); const FileContent* prevFile = previous->getFileContent(); NodeId prevNode = previous->getNodeId(); - Location loc2(m_symbols->registerSymbol( - prevFile->getFileName(prevNode).string()), - prevFile->Line(prevNode), prevFile->Column(prevNode), + Location loc2(prevFile->getFileId(prevNode), prevFile->Line(prevNode), + prevFile->Column(prevNode), m_symbols->registerSymbol(varName)); Error err(ErrorDefinition::COMP_MULTIPLY_DEFINED_PROPERTY, loc1, loc2); @@ -464,8 +457,8 @@ bool CompileClass::compile_class_method_(const FileContent* fC, NodeId id) { if (function_name) { funcName = fC->SymName(function_name); if (builtins_.find(funcName) != builtins_.end()) { - Location loc(m_symbols->registerSymbol(fC->getFileName().string()), - fC->Line(function_name), fC->Column(function_name), + Location loc(fC->getFileId(), fC->Line(function_name), + fC->Column(function_name), m_symbols->registerSymbol(funcName)); Error err(ErrorDefinition::COMP_CANNOT_REDEFINE_BUILTIN_METHOD, loc); m_errors->addError(err); @@ -584,15 +577,13 @@ bool CompileClass::compile_class_method_(const FileContent* fC, NodeId id) { method->compile(m_helper); TaskMethod* prevDef = m_class->getTask(taskName); if (prevDef) { - Location loc1(m_symbols->registerSymbol(fC->getFileName(id).string()), - fC->Line(id), fC->Column(id), + Location loc1(fC->getFileId(id), fC->Line(id), fC->Column(id), m_symbols->registerSymbol(taskName)); const FileContent* prevFile = prevDef->getFileContent(); NodeId prevNode = prevDef->getNodeId(); - Location loc2( - m_symbols->registerSymbol(prevFile->getFileName(prevNode).string()), - prevFile->Line(prevNode), prevFile->Column(prevNode), - m_symbols->registerSymbol(taskName)); + Location loc2(prevFile->getFileId(prevNode), prevFile->Line(prevNode), + prevFile->Column(prevNode), + m_symbols->registerSymbol(taskName)); Error err(ErrorDefinition::COMP_MULTIPLY_DEFINED_TASK, loc1, loc2); m_errors->addError(err); } @@ -608,13 +599,12 @@ bool CompileClass::compile_class_method_(const FileContent* fC, NodeId id) { Function* prevDef = m_class->getFunction(funcName); if (prevDef) { SymbolId funcSymbol = m_symbols->registerSymbol(funcName); - Location loc1(m_symbols->registerSymbol(fC->getFileName(id).string()), - fC->Line(id), fC->Column(id), funcSymbol); + Location loc1(fC->getFileId(id), fC->Line(id), fC->Column(id), + funcSymbol); const FileContent* prevFile = prevDef->getFileContent(); NodeId prevNode = prevDef->getNodeId(); - Location loc2( - m_symbols->registerSymbol(prevFile->getFileName(prevNode).string()), - prevFile->Line(prevNode), prevFile->Column(prevNode), funcSymbol); + Location loc2(prevFile->getFileId(prevNode), prevFile->Line(prevNode), + prevFile->Column(prevNode), funcSymbol); if (funcSymbol) { Error err(ErrorDefinition::COMP_MULTIPLY_DEFINED_FUNCTION, loc1, loc2); m_errors->addError(err); @@ -632,16 +622,14 @@ bool CompileClass::compile_class_constraint_(const FileContent* fC, std::string constName = fC->SymName(constraint_name); Constraint* prevDef = m_class->getConstraint(constName); if (prevDef) { - Location loc1( - m_symbols->registerSymbol(fC->getFileName(class_constraint).string()), - fC->Line(class_constraint), fC->Column(class_constraint), - m_symbols->registerSymbol(constName)); + Location loc1(fC->getFileId(class_constraint), fC->Line(class_constraint), + fC->Column(class_constraint), + m_symbols->registerSymbol(constName)); const FileContent* prevFile = prevDef->getFileContent(); NodeId prevNode = prevDef->getNodeId(); - Location loc2( - m_symbols->registerSymbol(prevFile->getFileName(prevNode).string()), - prevFile->Line(prevNode), prevFile->Column(prevNode), - m_symbols->registerSymbol(constName)); + Location loc2(prevFile->getFileId(prevNode), prevFile->Line(prevNode), + prevFile->Column(prevNode), + m_symbols->registerSymbol(constName)); Error err(ErrorDefinition::COMP_MULTIPLY_DEFINED_CONSTRAINT, loc1, loc2); m_errors->addError(err); } @@ -661,17 +649,15 @@ bool CompileClass::compile_class_declaration_(const FileContent* fC, m_class->m_uhdm_definition->VpiFullName() + "::" + class_name; ClassDefinition* prevDef = m_class->getClass(class_name); if (prevDef) { - Location loc1( - m_symbols->registerSymbol(fC->getFileName(class_name_id).string()), - fC->Line(class_name_id), fC->Column(class_name_id), - m_symbols->registerSymbol(class_name)); + Location loc1(fC->getFileId(class_name_id), fC->Line(class_name_id), + fC->Column(class_name_id), + m_symbols->registerSymbol(class_name)); const FileContent* prevFile = prevDef->getFileContent(); NodeId prevNode = prevFile->sl_collect(prevDef->getNodeId(), VObjectType::slStringConst); - Location loc2( - m_symbols->registerSymbol(prevFile->getFileName(prevNode).string()), - prevFile->Line(prevNode), prevFile->Column(prevNode), - m_symbols->registerSymbol(class_name)); + Location loc2(prevFile->getFileId(prevNode), prevFile->Line(prevNode), + prevFile->Column(prevNode), + m_symbols->registerSymbol(class_name)); Error err(ErrorDefinition::COMP_MULTIPLY_DEFINED_INNER_CLASS, loc1, loc2); m_errors->addError(err); } @@ -706,16 +692,14 @@ bool CompileClass::compile_covergroup_declaration_(const FileContent* fC, std::string covergroupName = fC->SymName(covergroup_name); CoverGroupDefinition* prevDef = m_class->getCoverGroup(covergroupName); if (prevDef) { - Location loc1( - m_symbols->registerSymbol(fC->getFileName(covergroup_name).string()), - fC->Line(covergroup_name), fC->Column(covergroup_name), - m_symbols->registerSymbol(covergroupName)); + Location loc1(fC->getFileId(covergroup_name), fC->Line(covergroup_name), + fC->Column(covergroup_name), + m_symbols->registerSymbol(covergroupName)); const FileContent* prevFile = prevDef->getFileContent(); NodeId prevNode = prevDef->getNodeId(); - Location loc2( - m_symbols->registerSymbol(prevFile->getFileName(prevNode).string()), - prevFile->Line(prevNode), prevFile->Column(prevNode), - m_symbols->registerSymbol(covergroupName)); + Location loc2(prevFile->getFileId(prevNode), prevFile->Line(prevNode), + prevFile->Column(prevNode), + m_symbols->registerSymbol(covergroupName)); Error err(ErrorDefinition::COMP_MULTIPLY_DEFINED_COVERGROUP, loc1, loc2); m_errors->addError(err); } @@ -764,15 +748,13 @@ bool CompileClass::compile_local_parameter_declaration_(const FileContent* fC, const std::pair* prevDef = m_class->getNamedObject(name); if (prevDef) { - Location loc1(m_symbols->registerSymbol(fC->getFileName(var).string()), - fC->Line(var), fC->Column(var), + Location loc1(fC->getFileId(var), fC->Line(var), fC->Column(var), m_symbols->registerSymbol(name)); const FileContent* prevFile = prevDef->first.fC; NodeId prevNode = prevDef->first.nodeId; - Location loc2( - m_symbols->registerSymbol(prevFile->getFileName(prevNode).string()), - prevFile->Line(prevNode), prevFile->Column(prevNode), - m_symbols->registerSymbol(name)); + Location loc2(prevFile->getFileId(prevNode), prevFile->Line(prevNode), + prevFile->Column(prevNode), + m_symbols->registerSymbol(name)); Error err(ErrorDefinition::COMP_MULTIPLY_DEFINED_PARAMETER, loc1, loc2); m_errors->addError(err); } @@ -810,15 +792,13 @@ bool CompileClass::compile_parameter_declaration_(const FileContent* fC, const std::pair* prevDef = m_class->getNamedObject(name); if (prevDef) { - Location loc1(m_symbols->registerSymbol(fC->getFileName(var).string()), - fC->Line(var), fC->Column(var), + Location loc1(fC->getFileId(var), fC->Line(var), fC->Column(var), m_symbols->registerSymbol(name)); const FileContent* prevFile = prevDef->first.fC; NodeId prevNode = prevDef->first.nodeId; - Location loc2( - m_symbols->registerSymbol(prevFile->getFileName(prevNode).string()), - prevFile->Line(prevNode), prevFile->Column(prevNode), - m_symbols->registerSymbol(name)); + Location loc2(prevFile->getFileId(prevNode), prevFile->Line(prevNode), + prevFile->Column(prevNode), + m_symbols->registerSymbol(name)); Error err(ErrorDefinition::COMP_MULTIPLY_DEFINED_PARAMETER, loc1, loc2); m_errors->addError(err); } diff --git a/src/DesignCompile/CompileDesign.cpp b/src/DesignCompile/CompileDesign.cpp index e6546f9f59..11ef44980c 100644 --- a/src/DesignCompile/CompileDesign.cpp +++ b/src/DesignCompile/CompileDesign.cpp @@ -22,6 +22,7 @@ */ #include +#include #include #include #include @@ -76,14 +77,15 @@ bool CompileDesign::compile() { UHDM::ErrorHandler errHandler = [=](UHDM::ErrorType errType, const std::string& msg, const UHDM::any* object1, const UHDM::any* object2) { + FileSystem* const fileSystem = FileSystem::getInstance(); ErrorContainer* errors = m_compiler->getErrorContainer(); SymbolTable* symbols = m_compiler->getSymbolTable(); if (object1) { - Location loc1(symbols->registerSymbol(object1->VpiFile().string()), + Location loc1(fileSystem->toPathId(object1->VpiFile(), symbols), object1->VpiLineNo(), object1->VpiColumnNo(), symbols->registerSymbol(msg)); if (object2) { - Location loc2(symbols->registerSymbol(object2->VpiFile().string()), + Location loc2(fileSystem->toPathId(object2->VpiFile(), symbols), object2->VpiLineNo(), object2->VpiColumnNo()); Error err((ErrorDefinition::ErrorType)errType, loc1, loc2); errors->addError(err); @@ -174,6 +176,7 @@ void CompileDesign::compileMT_(ObjectMapType& objects, int maxThreadCount) { void CompileDesign::collectObjects_(Design::FileIdDesignContentMap& all_files, Design* design, bool finalCollection) { + FileSystem* const fileSystem = FileSystem::getInstance(); typedef std::map> FileNamePackageMap; FileNamePackageMap fileNamePackageMap; SymbolTable* symbols = m_compiler->getSymbolTable(); @@ -181,7 +184,6 @@ void CompileDesign::collectObjects_(Design::FileIdDesignContentMap& all_files, // Collect all packages and module definitions for (const auto& file : all_files) { const FileContent* fC = file.second; - const fs::path fileName = fC->getFileName(); Library* lib = fC->getLibrary(); for (const auto& mod : fC->getModuleDefinitions()) { ModuleDefinition* existing = design->getModuleDefinition(mod.first); @@ -218,24 +220,24 @@ void CompileDesign::collectObjects_(Design::FileIdDesignContentMap& all_files, if (existing) { const FileContent* oldFC = existing->getFileContents()[0]; const FileContent* oldParentFile = oldFC->getParent(); - NodeId oldNodeId = existing->getNodeIds()[0]; - fs::path oldFileName = oldFC->getFileName(); - unsigned int oldLine = oldFC->Line(oldNodeId); Package* newP = pack.second; const FileContent* newFC = newP->getFileContents()[0]; const FileContent* newParentFile = newFC->getParent(); NodeId newNodeId = newP->getNodeIds()[0]; - fs::path newFileName = newFC->getFileName(); - unsigned int newLine = newFC->Line(newNodeId); - if (!finalCollection) { - if (((oldParentFile != newParentFile) || - (oldParentFile == nullptr && newParentFile == nullptr)) && - ((oldFileName != newFileName) || (oldLine != newLine))) { - Location loc1(symbols->registerSymbol(oldFileName.string()), - oldLine, oldFC->Column(oldNodeId), + if (!finalCollection && + ((oldParentFile != newParentFile) || + ((oldParentFile == nullptr) && (newParentFile == nullptr)))) { + NodeId oldNodeId = existing->getNodeIds()[0]; + fs::path oldFileName = fileSystem->toPath(oldFC->getFileId()); + unsigned int oldLine = oldFC->Line(oldNodeId); + fs::path newFileName = fileSystem->toPath(newFC->getFileId()); + unsigned int newLine = newFC->Line(newNodeId); + if ((oldFileName != newFileName) || (oldLine != newLine)) { + Location loc1(fileSystem->toPathId(oldFileName, symbols), oldLine, + oldFC->Column(oldNodeId), symbols->registerSymbol(pack.first)); - Location loc2(symbols->registerSymbol(newFileName.string()), - newLine, newFC->Column(newNodeId), + Location loc2(fileSystem->toPathId(newFileName, symbols), newLine, + newFC->Column(newNodeId), symbols->registerSymbol(pack.first)); Error err(ErrorDefinition::COMP_MULTIPLY_DEFINED_PACKAGE, loc1, loc2); @@ -293,7 +295,7 @@ bool CompileDesign::compilation_() { int index = 0; do { SymbolTable* symbols = - m_compiler->getCommandLineParser()->getSymbolTable().CreateSnapshot(); + m_compiler->getCommandLineParser()->getSymbolTable()->CreateSnapshot(); m_symbolTables.push_back(symbols); ErrorContainer* errors = new ErrorContainer(symbols); errors->registerCmdLine(m_compiler->getCommandLineParser()); @@ -378,23 +380,26 @@ bool CompileDesign::elaboration_() { return true; } -vpiHandle CompileDesign::writeUHDM(const std::string& fileName) { +vpiHandle CompileDesign::writeUHDM(PathId fileId) { UhdmWriter* uhdmwriter = new UhdmWriter(this, m_compiler->getDesign()); - vpiHandle h = uhdmwriter->write(fileName); + vpiHandle h = uhdmwriter->write(fileId); delete uhdmwriter; return h; } void decompile(ValuedComponentI* instance) { + FileSystem* const fileSystem = FileSystem::getInstance(); if (instance) { ModuleInstance* inst = valuedcomponenti_cast(instance); if (inst) { DesignComponent* component = inst->getDefinition(); while (inst) { std::cout << "Instance:" << inst->getFullPathName() << " " - << inst->getFileName() << "\n"; + << fileSystem->toPath(inst->getFileId()) << "\n"; std::cout << "Mod: " << inst->getModuleName() << " " - << component->getFileContents()[0]->getFileName() << "\n"; + << fileSystem->toPath( + component->getFileContents()[0]->getFileId()) + << "\n"; for (const auto& ps : inst->getMappedValues()) { const std::string& name = ps.first; diff --git a/src/DesignCompile/CompileExpression.cpp b/src/DesignCompile/CompileExpression.cpp index cef6094674..71ca6b2fa8 100644 --- a/src/DesignCompile/CompileExpression.cpp +++ b/src/DesignCompile/CompileExpression.cpp @@ -22,6 +22,7 @@ */ #include +#include #include #include #include @@ -687,10 +688,9 @@ constant *compileConst(const FileContent *fC, NodeId child, Serializer &s) { any *CompileHelper::decodeHierPath(hier_path *path, bool &invalidValue, DesignComponent *component, CompileDesign *compileDesign, - ValuedComponentI *instance, - const fs::path &fileName, int lineNumber, - any *pexpr, bool reduce, bool muteErrors, - bool returnTypespec) { + ValuedComponentI *instance, PathId fileId, + int lineNumber, any *pexpr, bool reduce, + bool muteErrors, bool returnTypespec) { UHDM::GetObjectFunctor getObjectFunctor = [&](const std::string &name, const any *inst, const any *pexpr) -> UHDM::any * { @@ -699,7 +699,7 @@ any *CompileHelper::decodeHierPath(hier_path *path, bool &invalidValue, UHDM::GetObjectFunctor getValueFunctor = [&](const std::string &name, const any *inst, const any *pexpr) -> UHDM::any * { - return (expr *)getValue(name, component, compileDesign, instance, fileName, + return (expr *)getValue(name, component, compileDesign, instance, fileId, lineNumber, (any *)pexpr, true, false); }; UHDM::GetTaskFuncFunctor getTaskFuncFunctor = @@ -732,8 +732,7 @@ any *CompileHelper::decodeHierPath(hier_path *path, bool &invalidValue, // std::string_view lineText = // StringUtils::getLineInString(fileContent, lineNumber); std::string_view lineText = path->VpiFullName(); - Location loc(symbols->registerSymbol(fileName.string()), lineNumber, 0, - symbols->registerSymbol(lineText)); + Location loc(fileId, lineNumber, 0, symbols->registerSymbol(lineText)); Error err(ErrorDefinition::UHDM_UNRESOLVED_HIER_PATH, loc); errors->addError(err); } @@ -744,9 +743,8 @@ any *CompileHelper::decodeHierPath(hier_path *path, bool &invalidValue, expr *CompileHelper::reduceExpr(any *result, bool &invalidValue, DesignComponent *component, CompileDesign *compileDesign, - ValuedComponentI *instance, - const fs::path &fileName, int lineNumber, - any *pexpr, bool muteErrors) { + ValuedComponentI *instance, PathId fileId, + int lineNumber, any *pexpr, bool muteErrors) { UHDM::GetObjectFunctor getObjectFunctor = [&](const std::string &name, const any *inst, const any *pexpr) -> UHDM::any * { @@ -755,7 +753,7 @@ expr *CompileHelper::reduceExpr(any *result, bool &invalidValue, UHDM::GetObjectFunctor getValueFunctor = [&](const std::string &name, const any *inst, const any *pexpr) -> UHDM::any * { - return (expr *)getValue(name, component, compileDesign, instance, fileName, + return (expr *)getValue(name, component, compileDesign, instance, fileId, lineNumber, (any *)pexpr, true, muteErrors); }; UHDM::GetTaskFuncFunctor getTaskFuncFunctor = @@ -785,13 +783,13 @@ expr *CompileHelper::reduceExpr(any *result, bool &invalidValue, any *CompileHelper::getValue(const std::string &name, DesignComponent *component, CompileDesign *compileDesign, - ValuedComponentI *instance, - const fs::path &fileName, int lineNumber, - any *pexpr, bool reduce, bool muteErrors) { + ValuedComponentI *instance, PathId fileId, + int lineNumber, any *pexpr, bool reduce, + bool muteErrors) { Serializer &s = compileDesign->getSerializer(); Value *sval = nullptr; any *result = nullptr; - if (loopDetected(fileName, lineNumber, instance)) { + if (loopDetected(fileId, lineNumber, compileDesign, instance)) { return nullptr; } if (m_checkForLoops) { @@ -1021,7 +1019,7 @@ any *CompileHelper::getValue(const std::string &name, if (result->VpiName() != name) { any *tmp = getValue(result->VpiName(), component, compileDesign, instance, - fileName, lineNumber, pexpr, true, muteErrors); + fileId, lineNumber, pexpr, true, muteErrors); if (tmp) result = tmp; } } else if (resultType == uhdmoperation || resultType == uhdmhier_path || @@ -1029,9 +1027,8 @@ any *CompileHelper::getValue(const std::string &name, resultType == uhdmsys_func_call) { if (reduce) { bool invalidValue = false; - any *tmp = - reduceExpr(result, invalidValue, component, compileDesign, instance, - fileName, lineNumber, pexpr, muteErrors); + any *tmp = reduceExpr(result, invalidValue, component, compileDesign, + instance, fileId, lineNumber, pexpr, muteErrors); if (tmp) result = tmp; } } else { @@ -1262,6 +1259,7 @@ UHDM::any *CompileHelper::compileExpression( if (m_checkForLoops) { m_stackLevel++; } + FileSystem *const fileSystem = FileSystem::getInstance(); UHDM::Serializer &s = compileDesign->getSerializer(); UHDM::any *result = nullptr; VObjectType parentType = fC->Type(parent); @@ -2723,15 +2721,14 @@ UHDM::any *CompileHelper::compileExpression( component, fC, List_of_arguments, compileDesign, fcall, instance, reduce, muteErrors); if (reduce) { - const fs::path fileName = fC->getFileName(); + PathId fileId = fC->getFileId(); int lineNumber = fC->Line(nameId); if (func == nullptr) { ErrorContainer *errors = compileDesign->getCompiler()->getErrorContainer(); SymbolTable *symbols = compileDesign->getCompiler()->getSymbolTable(); - Location loc(symbols->registerSymbol(fileName.string()), - lineNumber, fC->Column(nameId), + Location loc(fileId, lineNumber, fC->Column(nameId), symbols->registerSymbol(name)); Error err(ErrorDefinition::COMP_UNDEFINED_USER_FUNCTION, loc); errors->addError(err); @@ -2739,7 +2736,7 @@ UHDM::any *CompileHelper::compileExpression( result = EvalFunc( any_cast(func), args, invalidValue, (instance) ? actual_comp : component, compileDesign, - instance, fileName, lineNumber, pexpr); + instance, fileId, lineNumber, pexpr); } if (result == nullptr || invalidValue == true) { fcall->Tf_call_args(args); @@ -3013,11 +3010,12 @@ UHDM::any *CompileHelper::compileExpression( compileDesign->getCompiler()->getErrorContainer(); SymbolTable *symbols = compileDesign->getCompiler()->getSymbolTable(); unsupported_expr *exp = s.MakeUnsupported_expr(); - std::string fileContent = FileUtils::getFileContent(fC->getFileName()); + std::string fileContent = + FileUtils::getFileContent(fileSystem->toPath(fC->getFileId())); std::string_view lineText = StringUtils::getLineInString(fileContent, fC->Line(the_node)); - Location loc(symbols->registerSymbol(fC->getFileName(the_node).string()), - fC->Line(the_node), fC->Column(the_node), + Location loc(fC->getFileId(the_node), fC->Line(the_node), + fC->Column(the_node), symbols->registerSymbol( StrCat("<", fC->printObject(the_node), "> ", lineText))); Error err(ErrorDefinition::UHDM_UNSUPPORTED_EXPR, loc); @@ -3033,8 +3031,8 @@ UHDM::any *CompileHelper::compileExpression( // Reduce bool invalidValue = false; any *tmp = reduceExpr(result, invalidValue, component, compileDesign, - instance, fC->getFileName(the_node), - fC->Line(the_node), pexpr, muteErrors); + instance, fC->getFileId(the_node), fC->Line(the_node), + pexpr, muteErrors); if (tmp && (invalidValue == false)) { result = tmp; } @@ -3059,6 +3057,7 @@ UHDM::any *CompileHelper::compileAssignmentPattern(DesignComponent *component, CompileDesign *compileDesign, UHDM::any *pexpr, ValuedComponentI *instance) { + FileSystem *const fileSystem = FileSystem::getInstance(); UHDM::Serializer &s = compileDesign->getSerializer(); UHDM::any *result = nullptr; UHDM::operation *operation = s.MakeOperation(); @@ -3145,9 +3144,10 @@ UHDM::any *CompileHelper::compileAssignmentPattern(DesignComponent *component, } if (reduceMore) { bool invalidValue = false; - any *tmp = reduceExpr(exp, invalidValue, component, compileDesign, - instance, op->VpiFile().string(), - op->VpiLineNo(), nullptr, true); + any *tmp = reduceExpr( + exp, invalidValue, component, compileDesign, instance, + fileSystem->toPathId(op->VpiFile(), fC->getSymbolTable()), + op->VpiLineNo(), nullptr, true); if (invalidValue == false) { exp = tmp; } @@ -3157,7 +3157,7 @@ UHDM::any *CompileHelper::compileAssignmentPattern(DesignComponent *component, ref_obj *ref = (ref_obj *)exp; const std::string &name = ref->VpiName(); any *tmp = getValue(name, component, compileDesign, instance, - fC->getFileName(), fC->Line(Expression), pexpr, + fC->getFileId(), fC->Line(Expression), pexpr, true, true); if (tmp) { exp = tmp; @@ -3204,26 +3204,32 @@ bool CompileHelper::errorOnNegativeConstant(DesignComponent *component, ValuedComponentI *instance) { if (value == nullptr) return false; const std::string &val = value->uhdmValue(); - return errorOnNegativeConstant(component, val, compileDesign, instance, "", 0, - 0); + return errorOnNegativeConstant(component, val, compileDesign, instance, + BadPathId, 0, 0); } bool CompileHelper::errorOnNegativeConstant(DesignComponent *component, expr *exp, CompileDesign *compileDesign, ValuedComponentI *instance) { + FileSystem *const fileSystem = FileSystem::getInstance(); if (exp == nullptr) return false; if (exp->UhdmType() != uhdmconstant) return false; const std::string &val = exp->VpiValue(); - return errorOnNegativeConstant(component, val, compileDesign, instance, - exp->VpiFile(), exp->VpiLineNo(), - exp->VpiColumnNo()); + return errorOnNegativeConstant( + component, val, compileDesign, instance, + fileSystem->toPathId(exp->VpiFile(), + compileDesign->getCompiler()->getSymbolTable()), + exp->VpiLineNo(), exp->VpiColumnNo()); } -bool CompileHelper::errorOnNegativeConstant( - DesignComponent *component, const std::string &val, - CompileDesign *compileDesign, ValuedComponentI *instance, - const fs::path &fileName, unsigned int lineNo, unsigned short columnNo) { +bool CompileHelper::errorOnNegativeConstant(DesignComponent *component, + const std::string &val, + CompileDesign *compileDesign, + ValuedComponentI *instance, + PathId fileId, unsigned int lineNo, + unsigned short columnNo) { + FileSystem *const fileSystem = FileSystem::getInstance(); if (val[4] == '-') { std::string instanceName; if (instance) { @@ -3236,14 +3242,14 @@ bool CompileHelper::errorOnNegativeConstant( } std::string message; StrAppend(&message, '"', instanceName, "\"\n"); + SymbolTable *symbols = compileDesign->getCompiler()->getSymbolTable(); + const std::filesystem::path fileName = fileSystem->toPath(fileId); const std::string &fileContent = FileUtils::getFileContent(fileName); auto lineText = StringUtils::getLineInString(fileContent, lineNo); StrAppend(&message, " text: ", lineText); StrAppend(&message, " value: ", val); ErrorContainer *errors = compileDesign->getCompiler()->getErrorContainer(); - SymbolTable *symbols = compileDesign->getCompiler()->getSymbolTable(); - Location loc(symbols->registerSymbol(fileName.string()), lineNo, columnNo, - symbols->registerSymbol(message)); + Location loc(fileId, lineNo, columnNo, symbols->registerSymbol(message)); Error err(ErrorDefinition::ELAB_NEGATIVE_VALUE, loc); bool replay = false; @@ -3254,9 +3260,11 @@ bool CompileHelper::errorOnNegativeConstant( valuedcomponenti_cast(instance); while (inst) { std::cout << "Instance:" << inst->getFullPathName() << " " - << inst->getFileName() << "\n"; + << inst->getFileId() << "\n"; std::cout << "Mod: " << inst->getModuleName() << " " - << component->getFileContents()[0]->getFileName() << "\n"; + << fileSystem->toPath( + component->getFileContents()[0]->getFileId()) + << "\n"; for (const auto &ps : inst->getMappedValues()) { const std::string &name = ps.first; @@ -3289,6 +3297,7 @@ std::vector *CompileHelper::compileRanges( DesignComponent *component, const FileContent *fC, NodeId Packed_dimension, CompileDesign *compileDesign, UHDM::any *pexpr, ValuedComponentI *instance, bool reduce, int &size, bool muteErrors) { + FileSystem *const fileSystem = FileSystem::getInstance(); UHDM::Serializer &s = compileDesign->getSerializer(); VectorOfrange *ranges = nullptr; size = 0; @@ -3414,14 +3423,13 @@ std::vector *CompileHelper::compileRanges( std::string message; StrAppend(&message, '"', instanceName, "\"\n"); std::string fileContent = - FileUtils::getFileContent(fC->getFileName().string()); + FileUtils::getFileContent(fileSystem->toPath(fC->getFileId())); std::string_view lineText = StringUtils::getLineInString(fileContent, fC->Line(rexpr)); StrAppend(&message, " text: ", lineText); StrAppend(&message, " value: ", val); - Location loc(symbols->registerSymbol(fC->getFileName().string()), - fC->Line(rexpr), fC->Column(rexpr), + Location loc(fC->getFileId(), fC->Line(rexpr), fC->Column(rexpr), symbols->registerSymbol(message)); Error err(ErrorDefinition::ELAB_ILLEGAL_ZERO_VALUE, loc); errors->addError(err); @@ -3602,9 +3610,9 @@ UHDM::any *CompileHelper::compilePartSelectRange( if (reduce && (lexp->UhdmType() == uhdmconstant) && (rexp->UhdmType() == uhdmconstant)) { if (!name.empty()) { - any *v = getValue(name, component, compileDesign, instance, - fC->getFileName(), fC->Line(Constant_expression), - pexpr, reduce, muteErrors); + any *v = + getValue(name, component, compileDesign, instance, fC->getFileId(), + fC->Line(Constant_expression), pexpr, reduce, muteErrors); if (v && (v->UhdmType() == uhdmconstant)) { constant *cv = (constant *)v; Value *cvv = @@ -3707,10 +3715,9 @@ UHDM::any *CompileHelper::compilePartSelectRange( uint64_t CompileHelper::Bits(const UHDM::any *typespec, bool &invalidValue, DesignComponent *component, CompileDesign *compileDesign, - ValuedComponentI *instance, - const fs::path &fileName, int lineNumber, - bool reduce, bool sizeMode) { - if (loopDetected(fileName, lineNumber, instance)) { + ValuedComponentI *instance, PathId fileId, + int lineNumber, bool reduce, bool sizeMode) { + if (loopDetected(fileId, lineNumber, compileDesign, instance)) { return 0; } if (m_checkForLoops) { @@ -3724,7 +3731,7 @@ uint64_t CompileHelper::Bits(const UHDM::any *typespec, bool &invalidValue, UHDM::GetObjectFunctor getValueFunctor = [&](const std::string &name, const any *inst, const any *pexpr) -> UHDM::any * { - return (expr *)getValue(name, component, compileDesign, instance, fileName, + return (expr *)getValue(name, component, compileDesign, instance, fileId, lineNumber, (any *)pexpr, true, false); }; UHDM::GetTaskFuncFunctor getTaskFuncFunctor = @@ -3780,7 +3787,7 @@ const typespec *CompileHelper::getTypespec(DesignComponent *component, CompileDesign *compileDesign, ValuedComponentI *instance, bool reduce) { - if (loopDetected(fC->getFileName(), fC->Line(id), instance)) { + if (loopDetected(fC->getFileId(), fC->Line(id), compileDesign, instance)) { return nullptr; } UHDM::Serializer &s = compileDesign->getSerializer(); @@ -3831,7 +3838,7 @@ const typespec *CompileHelper::getTypespec(DesignComponent *component, bool invalidValue = false; result = (typespec *)decodeHierPath( (hier_path *)exp, invalidValue, component, compileDesign, - instance, fC->getFileName(), fC->Line(id), nullptr, reduce, false, + instance, fC->getFileId(), fC->Line(id), nullptr, reduce, false, true); } else if (exp->UhdmType() == uhdmbit_select) { bit_select *select = (bit_select *)exp; @@ -4084,7 +4091,7 @@ UHDM::any *CompileHelper::compileBits( } if (reduce && tps) bits += Bits(tps, invalidValue, component, compileDesign, instance, - fC->getFileName(typeSpecId), fC->Line(typeSpecId), + fC->getFileId(typeSpecId), fC->Line(typeSpecId), reduce, sizeMode); ConcatExpression = fC->Sibling(ConcatExpression); } @@ -4108,7 +4115,7 @@ UHDM::any *CompileHelper::compileBits( } if (reduce && tps) bits = Bits(tps, invalidValue, component, compileDesign, instance, - fC->getFileName(typeSpecId), fC->Line(typeSpecId), reduce, + fC->getFileId(typeSpecId), fC->Line(typeSpecId), reduce, sizeMode); if (reduce && (!tps)) { @@ -4116,7 +4123,7 @@ UHDM::any *CompileHelper::compileBits( instance, true, true); if (exp && typeSpecId) { bits = Bits(exp, invalidValue, component, compileDesign, instance, - fC->getFileName(typeSpecId), fC->Line(typeSpecId), reduce, + fC->getFileId(typeSpecId), fC->Line(typeSpecId), reduce, sizeMode); } } @@ -4305,12 +4312,12 @@ UHDM::any *CompileHelper::compileBound( expr *lr = (expr *)r->Left_expr(); expr *rr = (expr *)r->Right_expr(); bool invalidValue = false; - lr = reduceExpr(lr, invalidValue, component, compileDesign, instance, "", - 0, nullptr, true); + lr = reduceExpr(lr, invalidValue, component, compileDesign, instance, + BadPathId, 0, nullptr, true); UHDM::ExprEval eval; int64_t lrv = eval.get_value(invalidValue, lr); - rr = reduceExpr(rr, invalidValue, component, compileDesign, instance, "", - 0, nullptr, true); + rr = reduceExpr(rr, invalidValue, component, compileDesign, instance, + BadPathId, 0, nullptr, true); int64_t rrv = eval.get_value(invalidValue, rr); if (name == "left") { return lr; @@ -4361,7 +4368,7 @@ UHDM::any *CompileHelper::compileClog2( val = eval.get_value( invalidValue, reduceExpr(operand, invalidValue, component, compileDesign, instance, - fC->getFileName(), fC->Line(Expression), pexpr, muteErrors)); + fC->getFileId(), fC->Line(Expression), pexpr, muteErrors)); } if (reduce && (invalidValue == false)) { val = val - 1; @@ -4966,7 +4973,7 @@ UHDM::any *CompileHelper::compileComplexFuncCall( result = ref; } } else if (UHDM::any *st = getValue( - sval, component, compileDesign, instance, fC->getFileName(), + sval, component, compileDesign, instance, fC->getFileId(), fC->Line(Bit_select), pexpr, reduce, muteErrors)) { UHDM_OBJECT_TYPE type = st->UhdmType(); NodeId Select = dotedName; @@ -5148,8 +5155,8 @@ void CompileHelper::reorderAssignmentPattern(DesignComponent *mod, int optype = op->VpiOpType(); if (optype == vpiConditionOp) { bool invalidValue = false; - expr *tmp = reduceExpr(op, invalidValue, mod, compileDesign, instance, "", - 0, nullptr, true); + expr *tmp = reduceExpr(op, invalidValue, mod, compileDesign, instance, + BadPathId, 0, nullptr, true); if (tmp && (tmp->UhdmType() == uhdmoperation) && (invalidValue == false)) { op = (operation *)tmp; optype = op->VpiOpType(); @@ -5190,11 +5197,11 @@ void CompileHelper::reorderAssignmentPattern(DesignComponent *mod, expr *rr = (expr *)r->Right_expr(); bool invalidValue = false; UHDM::ExprEval eval; - lr = reduceExpr(lr, invalidValue, mod, compileDesign, instance, "", 0, - nullptr, true); + lr = reduceExpr(lr, invalidValue, mod, compileDesign, instance, + BadPathId, 0, nullptr, true); int64_t lrv = eval.get_value(invalidValue, lr); - rr = reduceExpr(rr, invalidValue, mod, compileDesign, instance, "", 0, - nullptr, true); + rr = reduceExpr(rr, invalidValue, mod, compileDesign, instance, + BadPathId, 0, nullptr, true); int64_t rrv = eval.get_value(invalidValue, rr); if (lrv > rrv) { op->VpiReordered(true); diff --git a/src/DesignCompile/CompileHelper.cpp b/src/DesignCompile/CompileHelper.cpp index 2ea6637207..cd933f564e 100644 --- a/src/DesignCompile/CompileHelper.cpp +++ b/src/DesignCompile/CompileHelper.cpp @@ -22,6 +22,7 @@ */ #include +#include #include #include #include @@ -74,8 +75,10 @@ void CompileHelper::checkForLoops(bool on) { m_unwind = false; } -bool CompileHelper::loopDetected(const std::filesystem::path& fileName, - int lineNumber, ValuedComponentI* instance) { +bool CompileHelper::loopDetected(PathId fileId, int lineNumber, + CompileDesign* compileDesign, + ValuedComponentI* instance) { + FileSystem* const fileSystem = FileSystem::getInstance(); #if defined(_WIN32) constexpr int32_t kMaxAllowedStackDepth = 100; #else @@ -88,8 +91,7 @@ bool CompileHelper::loopDetected(const std::filesystem::path& fileName, valuedcomponenti_cast(instance)) { instName = inst->getFullPathName(); } - Location loc(m_symbols->registerSymbol(fileName.string()), lineNumber, 0, - m_symbols->registerSymbol(instName)); + Location loc(fileId, lineNumber, 0, m_symbols->registerSymbol(instName)); Error err(ErrorDefinition::ELAB_EXPRESSION_LOOP, loc); m_errors->addError(err); m_unwind = true; @@ -304,8 +306,7 @@ bool CompileHelper::importPackage(DesignComponent* scope, Design* design, scope->setTask_funcs(sfuncs); } } else { - Location loc(m_symbols->registerSymbol(fC->getFileName(id).string()), - fC->Line(id), fC->Column(id), + Location loc(fC->getFileId(id), fC->Line(id), fC->Column(id), m_symbols->registerSymbol(pack_name)); Error err(ErrorDefinition::COMP_UNDEFINED_PACKAGE, loc); m_errors->addError(err); @@ -578,16 +579,13 @@ const DataType* CompileHelper::compileTypeDef(DesignComponent* scope, if (scope) { const TypeDef* prevDef = scope->getTypeDef(name); if (prevDef && !prevDef->isForwardDeclaration()) { - Location loc1( - m_symbols->registerSymbol(fC->getFileName(data_type).string()), - fC->Line(data_type), fC->Column(data_type), - m_symbols->registerSymbol(name)); + Location loc1(fC->getFileId(data_type), fC->Line(data_type), + fC->Column(data_type), m_symbols->registerSymbol(name)); const FileContent* prevFile = prevDef->getFileContent(); NodeId prevNode = prevDef->getNodeId(); - Location loc2( - m_symbols->registerSymbol(prevFile->getFileName(prevNode).string()), - prevFile->Line(prevNode), prevFile->Column(prevNode), - m_symbols->registerSymbol(name)); + Location loc2(prevFile->getFileId(prevNode), prevFile->Line(prevNode), + prevFile->Column(prevNode), + m_symbols->registerSymbol(name)); Error err(ErrorDefinition::COMP_MULTIPLY_DEFINED_TYPEDEF, loc1, loc2); m_errors->addError(err); } @@ -731,7 +729,7 @@ const DataType* CompileHelper::compileTypeDef(DesignComponent* scope, if (const typespec* base = enum_t->Base_typespec()) { bool invalidValue = false; baseSize = Bits(base, invalidValue, scope, compileDesign, nullptr, - fC->getFileName(), base->VpiLineNo(), reduce, true); + fC->getFileId(), base->VpiLineNo(), reduce, true); } while (enum_name_declaration) { NodeId enumNameId = fC->Child(enum_name_declaration); @@ -1262,14 +1260,11 @@ bool CompileHelper::compileScopeVariable(Scope* parent, const FileContent* fC, Variable* previous = parent->getVariable(varName); if (previous) { - Location loc1( - m_symbols->registerSymbol(fC->getFileName(var).string()), - fC->Line(var), fC->Column(var), - m_symbols->registerSymbol(varName)); + Location loc1(fC->getFileId(var), fC->Line(var), fC->Column(var), + m_symbols->registerSymbol(varName)); const FileContent* prevFile = previous->getFileContent(); NodeId prevNode = previous->getNodeId(); - Location loc2(m_symbols->registerSymbol( - prevFile->getFileName(prevNode).string()), + Location loc2(prevFile->getFileId(prevNode), prevFile->Line(prevNode), prevFile->Column(prevNode), m_symbols->registerSymbol(varName)); Error err(ErrorDefinition::COMP_MULTIPLY_DEFINED_VARIABLE, loc1, @@ -2732,7 +2727,7 @@ bool CompileHelper::compileParameterDeclaration( bool invalidValue = false; int sizetmp = Bits(ts, invalidValue, component, compileDesign, instance, - fC->getFileName(), fC->Line(actual_value), true, false); + fC->getFileId(), fC->Line(actual_value), true, false); if (!invalidValue) size = sizetmp; } Value* val = m_exprBuilder.fromVpiValue(c->VpiValue(), size); @@ -2740,7 +2735,7 @@ bool CompileHelper::compileParameterDeclaration( } else if (reduce && (!isMultiDimension)) { UHDM::expr* the_expr = (UHDM::expr*)expr; if (the_expr->Typespec() == nullptr) the_expr->Typespec(ts); - ExprEval expr_eval(the_expr, instance, fC->getFileName(), + ExprEval expr_eval(the_expr, instance, fC->getFileId(), fC->Line(name), nullptr); component->scheduleParamExprEval(the_name, expr_eval); } else if (expr && ((exprtype == uhdmoperation) || @@ -2913,7 +2908,7 @@ bool CompileHelper::compileParameterDeclaration( bool invalidValue = false; int sizetmp = Bits(ts, invalidValue, component, compileDesign, instance, - fC->getFileName(), fC->Line(actual_value), true, false); + fC->getFileId(), fC->Line(actual_value), true, false); if (!invalidValue) size = sizetmp; } if (rhs->Typespec() == nullptr) rhs->Typespec(ts); @@ -2940,11 +2935,16 @@ void CompileHelper::adjustSize(const UHDM::typespec* ts, if (ts == nullptr) { return; } + + FileSystem* const fileSystem = FileSystem::getInstance(); int orig_size = c->VpiSize(); bool invalidValue = false; - int sizetmp = Bits(ts, invalidValue, component, compileDesign, instance, - c->VpiFile(), c->VpiLineNo(), true, true); + int sizetmp = + Bits(ts, invalidValue, component, compileDesign, instance, + fileSystem->toPathId(c->VpiFile(), + compileDesign->getCompiler()->getSymbolTable()), + c->VpiLineNo(), true, true); int size = orig_size; if (!invalidValue) size = sizetmp; @@ -3193,6 +3193,7 @@ VectorOfany* CompileHelper::compileTfCallArguments( DesignComponent* component, const FileContent* fC, NodeId Arg_list_node, CompileDesign* compileDesign, UHDM::any* call, ValuedComponentI* instance, bool reduce, bool muteErrors) { + FileSystem* const fileSystem = FileSystem::getInstance(); UHDM::Serializer& s = compileDesign->getSerializer(); if (fC->Type(Arg_list_node) == VObjectType::slSelect) { // Task or func call with no argument, not even () @@ -3286,7 +3287,7 @@ VectorOfany* CompileHelper::compileTfCallArguments( arguments->push_back((*itr).second); } else { constant* c = s.MakeConstant(); - c->VpiFile(fC->getFileName()); + c->VpiFile(fileSystem->toPath(fC->getFileId()).string()); c->VpiValue("INT:0"); c->VpiDecompile("0"); c->VpiSize(64); @@ -3766,6 +3767,7 @@ UHDM::expr* CompileHelper::expandPatternAssignment(const typespec* tps, DesignComponent* component, CompileDesign* compileDesign, ValuedComponentI* instance) { + FileSystem* const fileSystem = FileSystem::getInstance(); Serializer& s = compileDesign->getSerializer(); uint64_t size = 1; @@ -3782,12 +3784,18 @@ UHDM::expr* CompileHelper::expandPatternAssignment(const typespec* tps, uint64_t r1 = eval.get_value( invalidValue, reduceExpr((any*)range->Left_expr(), invalidValue, component, - compileDesign, instance, range->Left_expr()->VpiFile(), + compileDesign, instance, + fileSystem->toPathId( + range->Left_expr()->VpiFile(), + compileDesign->getCompiler()->getSymbolTable()), range->Left_expr()->VpiLineNo(), nullptr)); uint64_t r2 = eval.get_value( invalidValue, reduceExpr((any*)range->Right_expr(), invalidValue, component, - compileDesign, instance, range->Right_expr()->VpiFile(), + compileDesign, instance, + fileSystem->toPathId( + range->Right_expr()->VpiFile(), + compileDesign->getCompiler()->getSymbolTable()), range->Right_expr()->VpiLineNo(), nullptr)); size *= (r1 > r2) ? (r1 - r2 + 1) : (r2 - r1 + 1); } @@ -3824,9 +3832,13 @@ UHDM::expr* CompileHelper::expandPatternAssignment(const typespec* tps, UHDM::ExprEval eval; int val = eval.get_value( invalidValue, - reduceExpr((any*)tp->Pattern(), invalidValue, component, - compileDesign, instance, tp->Pattern()->VpiFile(), - tp->Pattern()->VpiLineNo(), nullptr)); + reduceExpr( + (any*)tp->Pattern(), invalidValue, component, + compileDesign, instance, + fileSystem->toPathId( + tp->Pattern()->VpiFile(), + compileDesign->getCompiler()->getSymbolTable()), + tp->Pattern()->VpiLineNo(), nullptr)); for (unsigned int i = 0; i < size; i++) { values[i] = val; } @@ -3887,9 +3899,9 @@ bool CompileHelper::valueRange(Value* val, UHDM::typespec* ts, if (r) { bool invalidValue = false; expr* lv = reduceExpr((any*)r->Left_expr(), invalidValue, component, - compileDesign, instance, "", 0, nullptr, true); + compileDesign, instance, BadPathId, 0, nullptr, true); expr* rv = reduceExpr((any*)r->Right_expr(), invalidValue, component, - compileDesign, instance, "", 0, nullptr, true); + compileDesign, instance, BadPathId, 0, nullptr, true); UHDM::ExprEval eval; int64_t lvv = eval.get_value(invalidValue, lv); int64_t rvv = eval.get_value(invalidValue, rv); diff --git a/src/DesignCompile/CompileModule.cpp b/src/DesignCompile/CompileModule.cpp index 341d4166d2..88c323527a 100644 --- a/src/DesignCompile/CompileModule.cpp +++ b/src/DesignCompile/CompileModule.cpp @@ -22,6 +22,7 @@ */ #include +#include #include #include #include @@ -58,8 +59,7 @@ int FunctorCompileModule::operator()() const { bool CompileModule::compile() { const FileContent* const fC = m_module->m_fileContents[0]; NodeId nodeId = m_module->m_nodeIds[0]; - Location loc(m_symbols->registerSymbol(fC->getFileName(nodeId).string()), - fC->Line(nodeId), fC->Column(nodeId), + Location loc(fC->getFileId(nodeId), fC->Line(nodeId), fC->Column(nodeId), m_symbols->registerSymbol(m_module->getName())); VObjectType moduleType = fC->Type(nodeId); ErrorDefinition::ErrorType errType = ErrorDefinition::COMP_COMPILE_MODULE; @@ -809,20 +809,13 @@ bool CompileModule::collectModuleObjects_(CollectType collectType) { moduleName = StringUtils::ltrim(moduleName, ':'); moduleName = StringUtils::ltrim(moduleName, ':'); if (endLabel != moduleName) { - Location loc( - m_compileDesign->getCompiler() - ->getSymbolTable() - ->registerSymbol( - fC->getFileName(m_module->getNodeIds()[0]).string()), - fC->Line(m_module->getNodeIds()[0]), - fC->Column(m_module->getNodeIds()[0]), - m_compileDesign->getCompiler() - ->getSymbolTable() - ->registerSymbol(moduleName)); - Location loc2(m_compileDesign->getCompiler() - ->getSymbolTable() - ->registerSymbol(fC->getFileName(id).string()), - fC->Line(id), fC->Column(id), + Location loc(fC->getFileId(m_module->getNodeIds()[0]), + fC->Line(m_module->getNodeIds()[0]), + fC->Column(m_module->getNodeIds()[0]), + m_compileDesign->getCompiler() + ->getSymbolTable() + ->registerSymbol(moduleName)); + Location loc2(fC->getFileId(id), fC->Line(id), fC->Column(id), m_compileDesign->getCompiler() ->getSymbolTable() ->registerSymbol(endLabel)); @@ -1015,9 +1008,8 @@ bool CompileModule::collectInterfaceObjects_(CollectType collectType) { VObjectTypeUnorderedSet types = {VObjectType::slModport_item}; std::vector items = fC->sl_collect_all(id, types); for (auto nodeId : items) { - Location loc( - m_symbols->registerSymbol(fC->getFileName(nodeId).string()), - fC->Line(nodeId), fC->Column(nodeId)); + Location loc(fC->getFileId(nodeId), fC->Line(nodeId), + fC->Column(nodeId)); Error err(ErrorDefinition::COMP_NO_MODPORT_IN_GENERATE, loc); m_errors->addError(err); } @@ -1067,13 +1059,11 @@ bool CompileModule::collectInterfaceObjects_(CollectType collectType) { if (!Expression) { // If expression is not null, we cannot conclude here if (!port_exists) { - Location loc( - m_symbols->registerSymbol( - fC->getFileName(simple_port_name).string()), - fC->Line(simple_port_name), - fC->Column(simple_port_name), - m_symbols->registerSymbol( - fC->SymName(simple_port_name))); + Location loc(fC->getFileId(simple_port_name), + fC->Line(simple_port_name), + fC->Column(simple_port_name), + m_symbols->registerSymbol( + fC->SymName(simple_port_name))); Error err(ErrorDefinition::COMP_MODPORT_UNDEFINED_PORT, loc); m_errors->addError(err); @@ -1098,11 +1088,10 @@ bool CompileModule::collectInterfaceObjects_(CollectType collectType) { ClockingBlock* cb = m_module->getClockingBlock(clocking_block_symbol); if (cb == nullptr) { - Location loc( - m_symbols->registerSymbol( - fC->getFileName(clocking_block_name).string()), - fC->Line(clocking_block_name), - fC->Column(clocking_block_name), clocking_block_symbol); + Location loc(fC->getFileId(clocking_block_name), + fC->Line(clocking_block_name), + fC->Column(clocking_block_name), + clocking_block_symbol); Error err( ErrorDefinition::COMP_MODPORT_UNDEFINED_CLOCKING_BLOCK, loc); @@ -1194,20 +1183,13 @@ bool CompileModule::collectInterfaceObjects_(CollectType collectType) { moduleName = StringUtils::ltrim(moduleName, ':'); moduleName = StringUtils::ltrim(moduleName, ':'); if (endLabel != moduleName) { - Location loc( - m_compileDesign->getCompiler() - ->getSymbolTable() - ->registerSymbol( - fC->getFileName(m_module->getNodeIds()[0]).string()), - fC->Line(m_module->getNodeIds()[0]), - fC->Column(m_module->getNodeIds()[0]), - m_compileDesign->getCompiler() - ->getSymbolTable() - ->registerSymbol(moduleName)); - Location loc2(m_compileDesign->getCompiler() - ->getSymbolTable() - ->registerSymbol(fC->getFileName(id).string()), - fC->Line(id), fC->Column(id), + Location loc(fC->getFileId(m_module->getNodeIds()[0]), + fC->Line(m_module->getNodeIds()[0]), + fC->Column(m_module->getNodeIds()[0]), + m_compileDesign->getCompiler() + ->getSymbolTable() + ->registerSymbol(moduleName)); + Location loc2(fC->getFileId(id), fC->Line(id), fC->Column(id), m_compileDesign->getCompiler() ->getSymbolTable() ->registerSymbol(endLabel)); @@ -1259,6 +1241,7 @@ bool CompileModule::collectInterfaceObjects_(CollectType collectType) { } bool CompileModule::checkModule_() { + FileSystem* const fileSystem = FileSystem::getInstance(); int countMissingType = 0; int countMissingDirection = 0; Location* missingTypeLoc = nullptr; @@ -1279,9 +1262,9 @@ bool CompileModule::checkModule_() { port->getDirection() == VObjectType::slPortDir_Inout) { if (countMissingType == 0) missingTypeLoc = new Location( - m_symbols->registerSymbol(port->getFileContent() - ->getFileName(port->getNodeId()) - .string()), + fileSystem->copy( + port->getFileContent()->getFileId(port->getNodeId()), + m_symbols), port->getFileContent()->Line(port->getNodeId()), port->getFileContent()->Column(port->getNodeId()), m_symbols->registerSymbol(port->getName())); @@ -1291,9 +1274,9 @@ bool CompileModule::checkModule_() { if (port->getDirection() == VObjectType::slNoType) { if (countMissingDirection == 0) missingDirectionLoc = new Location( - m_symbols->registerSymbol(port->getFileContent() - ->getFileName(port->getNodeId()) - .string()), + fileSystem->copy( + port->getFileContent()->getFileId(port->getNodeId()), + m_symbols), port->getFileContent()->Line(port->getNodeId()), port->getFileContent()->Column(port->getNodeId()), m_symbols->registerSymbol(port->getName())); @@ -1336,6 +1319,7 @@ bool CompileModule::checkModule_() { } bool CompileModule::checkInterface_() { + FileSystem* const fileSystem = FileSystem::getInstance(); int countMissingType = 0; Location* missingTypeLoc = nullptr; for (auto& port : m_module->m_ports) { @@ -1344,9 +1328,9 @@ bool CompileModule::checkInterface_() { port->getDirection() == VObjectType::slPortDir_Inout) { if (countMissingType == 0) missingTypeLoc = new Location( - m_symbols->registerSymbol(port->getFileContent() - ->getFileName(port->getNodeId()) - .string()), + fileSystem->copy( + port->getFileContent()->getFileId(port->getNodeId()), + m_symbols), port->getFileContent()->Line(port->getNodeId()), 0, m_symbols->registerSymbol(port->getName())); countMissingType++; diff --git a/src/DesignCompile/CompilePackage.cpp b/src/DesignCompile/CompilePackage.cpp index 43e384db25..7a6124bff7 100644 --- a/src/DesignCompile/CompilePackage.cpp +++ b/src/DesignCompile/CompilePackage.cpp @@ -70,8 +70,7 @@ bool CompilePackage::compile(bool reduce) { const FileContent* fC = m_package->m_fileContents[0]; NodeId packId = m_package->m_nodeIds[0]; if (reduce) { - Location loc(m_symbols->registerSymbol(fC->getFileName(packId).string()), - fC->Line(packId), fC->Column(packId), + Location loc(fC->getFileId(packId), fC->Line(packId), fC->Column(packId), m_symbols->getId(m_package->getName())); Error err(ErrorDefinition::COMP_COMPILE_PACKAGE, loc); @@ -282,20 +281,13 @@ bool CompilePackage::collectObjects_(CollectType collectType, bool reduce) { std::string moduleName = m_package->getName(); moduleName = StringUtils::ltrim(moduleName, '@'); if (endLabel != moduleName) { - Location loc( - m_compileDesign->getCompiler() - ->getSymbolTable() - ->registerSymbol( - fC->getFileName(m_package->getNodeIds()[0]).string()), - fC->Line(m_package->getNodeIds()[0]), - fC->Column(m_package->getNodeIds()[0]), - m_compileDesign->getCompiler() - ->getSymbolTable() - ->registerSymbol(moduleName)); - Location loc2(m_compileDesign->getCompiler() - ->getSymbolTable() - ->registerSymbol(fC->getFileName(id).string()), - fC->Line(id), fC->Column(id), + Location loc(fC->getFileId(m_package->getNodeIds()[0]), + fC->Line(m_package->getNodeIds()[0]), + fC->Column(m_package->getNodeIds()[0]), + m_compileDesign->getCompiler() + ->getSymbolTable() + ->registerSymbol(moduleName)); + Location loc2(fC->getFileId(id), fC->Line(id), fC->Column(id), m_compileDesign->getCompiler() ->getSymbolTable() ->registerSymbol(endLabel)); diff --git a/src/DesignCompile/CompileProgram.cpp b/src/DesignCompile/CompileProgram.cpp index e4c286ab80..85a2192149 100644 --- a/src/DesignCompile/CompileProgram.cpp +++ b/src/DesignCompile/CompileProgram.cpp @@ -50,8 +50,7 @@ bool CompileProgram::compile() { const FileContent* fC = m_program->m_fileContents[0]; NodeId nodeId = m_program->m_nodeIds[0]; - Location loc(m_symbols->registerSymbol(fC->getFileName(nodeId).string()), - fC->Line(nodeId), fC->Column(nodeId), + Location loc(fC->getFileId(nodeId), fC->Line(nodeId), fC->Column(nodeId), m_symbols->registerSymbol(m_program->getName())); Error err1(ErrorDefinition::COMP_COMPILE_PROGRAM, loc); @@ -313,20 +312,13 @@ bool CompileProgram::collectObjects_(CollectType collectType) { std::string moduleName = m_program->getName(); moduleName = StringUtils::ltrim(moduleName, '@'); if (endLabel != moduleName) { - Location loc( - m_compileDesign->getCompiler() - ->getSymbolTable() - ->registerSymbol( - fC->getFileName(m_program->getNodeIds()[0]).string()), - fC->Line(m_program->getNodeIds()[0]), - fC->Column(m_program->getNodeIds()[0]), - m_compileDesign->getCompiler() - ->getSymbolTable() - ->registerSymbol(moduleName)); - Location loc2(m_compileDesign->getCompiler() - ->getSymbolTable() - ->registerSymbol(fC->getFileName(id).string()), - fC->Line(id), fC->Column(id), + Location loc(fC->getFileId(m_program->getNodeIds()[0]), + fC->Line(m_program->getNodeIds()[0]), + fC->Column(m_program->getNodeIds()[0]), + m_compileDesign->getCompiler() + ->getSymbolTable() + ->registerSymbol(moduleName)); + Location loc2(fC->getFileId(id), fC->Line(id), fC->Column(id), m_compileDesign->getCompiler() ->getSymbolTable() ->registerSymbol(endLabel)); diff --git a/src/DesignCompile/CompileStmt.cpp b/src/DesignCompile/CompileStmt.cpp index 37c4269ac1..6141aa3c42 100644 --- a/src/DesignCompile/CompileStmt.cpp +++ b/src/DesignCompile/CompileStmt.cpp @@ -21,6 +21,7 @@ * Created on May 14, 2019, 8:03 PM */ +#include #include #include #include @@ -104,6 +105,7 @@ VectorOfany* CompileHelper::compileStmt(DesignComponent* component, UHDM::any* pstmt, ValuedComponentI* instance, bool reduce) { + FileSystem* const fileSystem = FileSystem::getInstance(); VectorOfany* results = nullptr; UHDM::Serializer& s = compileDesign->getSerializer(); VObjectType type = fC->Type(the_stmt); @@ -247,11 +249,10 @@ VectorOfany* CompileHelper::compileStmt(DesignComponent* component, compileDesign->getCompiler()->getErrorContainer(); SymbolTable* symbols = compileDesign->getCompiler()->getSymbolTable(); - Location loc(symbols->registerSymbol(fC->getFileName().string()), - fC->Line(labelId), fC->Column(labelId), - symbols->registerSymbol(label)); - Location loc2(symbols->registerSymbol(fC->getFileName().string()), - fC->Line(endLabel), fC->Column(endLabel), + Location loc(fC->getFileId(), fC->Line(labelId), + fC->Column(labelId), symbols->registerSymbol(label)); + Location loc2(fC->getFileId(), fC->Line(endLabel), + fC->Column(endLabel), symbols->registerSymbol(endlabel)); Error err(ErrorDefinition::COMP_UNMATCHED_LABEL, loc, loc2); errors->addError(err); @@ -361,14 +362,12 @@ VectorOfany* CompileHelper::compileStmt(DesignComponent* component, compileDesign->getCompiler()->getErrorContainer(); SymbolTable* symbols = compileDesign->getCompiler()->getSymbolTable(); - Location loc( - symbols->registerSymbol(fC->getFileName().string()), - fC->Line(labelId), fC->Column(labelId), - symbols->registerSymbol(label)); - Location loc2( - symbols->registerSymbol(fC->getFileName().string()), - fC->Line(endLabel), fC->Column(endLabel), - symbols->registerSymbol(endlabel)); + Location loc(fC->getFileId(), fC->Line(labelId), + fC->Column(labelId), + symbols->registerSymbol(label)); + Location loc2(fC->getFileId(), fC->Line(endLabel), + fC->Column(endLabel), + symbols->registerSymbol(endlabel)); Error err(ErrorDefinition::COMP_UNMATCHED_LABEL, loc, loc2); errors->addError(err); } @@ -859,11 +858,12 @@ VectorOfany* CompileHelper::compileStmt(DesignComponent* component, compileDesign->getCompiler()->getErrorContainer(); SymbolTable* symbols = compileDesign->getCompiler()->getSymbolTable(); unsupported_stmt* ustmt = s.MakeUnsupported_stmt(); - std::string fileContent = FileUtils::getFileContent(fC->getFileName()); + std::string fileContent = + FileUtils::getFileContent(fileSystem->toPath(fC->getFileId())); std::string_view lineText = StringUtils::getLineInString(fileContent, fC->Line(the_stmt)); - Location loc(symbols->registerSymbol(fC->getFileName(the_stmt).string()), - fC->Line(the_stmt), fC->Column(the_stmt), + Location loc(fC->getFileId(the_stmt), fC->Line(the_stmt), + fC->Column(the_stmt), symbols->registerSymbol( StrCat("<", fC->printObject(the_stmt), "> ", lineText))); Error err(ErrorDefinition::UHDM_UNSUPPORTED_STMT, loc); diff --git a/src/DesignCompile/CompileType.cpp b/src/DesignCompile/CompileType.cpp index a3af6b5a33..2ff5d4acfe 100644 --- a/src/DesignCompile/CompileType.cpp +++ b/src/DesignCompile/CompileType.cpp @@ -22,6 +22,7 @@ */ #include +#include #include #include #include @@ -587,10 +588,9 @@ typespec* CompileHelper::compileDatastructureTypespec( UHDM::parameter* lhs = (UHDM::parameter*)param_assign->Lhs(); result = (typespec*)lhs->Typespec(); if (result == nullptr) { - int_typespec* tps = - buildIntTypespec(compileDesign, fC->getFileName(), typeName, - "", fC->Line(type), fC->Column(type), - fC->EndLine(type), fC->EndColumn(type)); + int_typespec* tps = buildIntTypespec( + compileDesign, fC->getFileId(), typeName, "", fC->Line(type), + fC->Column(type), fC->EndLine(type), fC->EndColumn(type)); lhs->Typespec(tps); result = tps; } @@ -634,20 +634,18 @@ typespec* CompileHelper::compileDatastructureTypespec( compileDesign->getCompiler()->getErrorContainer(); SymbolTable* symbols = compileDesign->getCompiler()->getSymbolTable(); - Location loc1( - symbols->registerSymbol(fC->getFileName().string()), - fC->Line(suffixNode), fC->Column(suffixNode), - symbols->registerSymbol(suffixname)); + Location loc1(fC->getFileId(), fC->Line(suffixNode), + fC->Column(suffixNode), + symbols->registerSymbol(suffixname)); std::string libName = fC->getLibrary()->getName(); Design* design = compileDesign->getCompiler()->getDesign(); ModuleDefinition* def = design->getModuleDefinition(libName + "@" + typeName2); const FileContent* interF = def->getFileContents()[0]; - Location loc2( - symbols->registerSymbol(interF->getFileName().string()), - interF->Line(def->getNodeIds()[0]), - interF->Column(def->getNodeIds()[0]), - symbols->registerSymbol(typeName2)); + Location loc2(interF->getFileId(), + interF->Line(def->getNodeIds()[0]), + interF->Column(def->getNodeIds()[0]), + symbols->registerSymbol(typeName2)); Error err(ErrorDefinition::ELAB_UNKNOWN_INTERFACE_MEMBER, loc1, loc2); errors->addError(err); @@ -871,9 +869,10 @@ typespec* CompileHelper::compileDatastructureTypespec( } UHDM::typespec_member* CompileHelper::buildTypespecMember( - CompileDesign* compileDesign, const fs::path& fileName, - const std::string& name, const std::string& value, unsigned int line, - unsigned short column, unsigned int eline, unsigned short ecolumn) { + CompileDesign* compileDesign, PathId fileId, const std::string& name, + const std::string& value, unsigned int line, unsigned short column, + unsigned int eline, unsigned short ecolumn) { + FileSystem* const fileSystem = FileSystem::getInstance(); /* std::string hash = fileName + ":" + name + ":" + value + ":" + std::to_string(line) + ":" + std::to_string(column) + ":" + @@ -886,7 +885,7 @@ UHDM::typespec_member* CompileHelper::buildTypespecMember( Serializer& s = compileDesign->getSerializer(); var = s.MakeTypespec_member(); var->VpiName(name); - var->VpiFile(fileName); + var->VpiFile(fileSystem->toPath(fileId).string()); var->VpiLineNo(line); var->VpiColumnNo(column); var->VpiEndLineNo(eline); @@ -899,9 +898,10 @@ UHDM::typespec_member* CompileHelper::buildTypespecMember( } int_typespec* CompileHelper::buildIntTypespec( - CompileDesign* compileDesign, const fs::path& fileName, - const std::string& name, const std::string& value, unsigned int line, - unsigned short column, unsigned int eline, unsigned short ecolumn) { + CompileDesign* compileDesign, PathId fileId, const std::string& name, + const std::string& value, unsigned int line, unsigned short column, + unsigned int eline, unsigned short ecolumn) { + FileSystem* const fileSystem = FileSystem::getInstance(); /* std::string hash = fileName + ":" + name + ":" + value + ":" + std::to_string(line) + ":" + std::to_string(column) + ":" + @@ -915,7 +915,7 @@ int_typespec* CompileHelper::buildIntTypespec( var = s.MakeInt_typespec(); var->VpiValue(value); var->VpiName(name); - var->VpiFile(fileName); + var->VpiFile(fileSystem->toPath(fileId).string()); var->VpiLineNo(line); var->VpiColumnNo(column); var->VpiEndLineNo(eline); @@ -1026,6 +1026,7 @@ UHDM::typespec* CompileHelper::compileTypespec( DesignComponent* component, const FileContent* fC, NodeId type, CompileDesign* compileDesign, UHDM::any* pstmt, SURELOG::ValuedComponentI* instance, bool reduce, bool isVariable) { + FileSystem* const fileSystem = FileSystem::getInstance(); UHDM::Serializer& s = compileDesign->getSerializer(); UHDM::typespec* result = nullptr; VObjectType the_type = fC->Type(type); @@ -1106,7 +1107,7 @@ UHDM::typespec* CompileHelper::compileTypespec( bool invalidValue = false; baseSize = Bits(baseType, invalidValue, component, compileDesign, instance, - fC->getFileName(), baseType->VpiLineNo(), reduce, true); + fC->getFileId(), baseType->VpiLineNo(), reduce, true); } enum_typespec* en = s.MakeEnum_typespec(); en->Base_typespec(baseType); @@ -1413,12 +1414,12 @@ UHDM::typespec* CompileHelper::compileTypespec( NodeId Expression = fC->Sibling(member_name); const std::string& mem_name = fC->SymName(member_name); typespec_member* m = - buildTypespecMember(compileDesign, fC->getFileName(), mem_name, - "", fC->Line(Variable_decl_assignment), + buildTypespecMember(compileDesign, fC->getFileId(), mem_name, "", + fC->Line(Variable_decl_assignment), fC->Column(Variable_decl_assignment), fC->EndLine(Variable_decl_assignment), fC->EndColumn(Variable_decl_assignment)); - m->VpiRefFile(fC->getFileName().string()); + m->VpiRefFile(fileSystem->toPath(fC->getFileId()).string()); m->VpiRefLineNo(fC->Line(Data_type)); m->VpiRefColumnNo(fC->Column(Data_type)); m->VpiRefEndLineNo(fC->EndLine(Data_type)); @@ -1470,7 +1471,7 @@ UHDM::typespec* CompileHelper::compileTypespec( } else if (reduce) { if (any* cast_to = getValue(typeName, component, compileDesign, instance, - fC->getFileName(), fC->Line(type), nullptr, !reduce)) { + fC->getFileId(), fC->Line(type), nullptr, !reduce)) { constant* c = any_cast(cast_to); if (c) { integer_typespec* var = s.MakeInteger_typespec(); @@ -1498,8 +1499,11 @@ UHDM::typespec* CompileHelper::compileTypespec( const any* rhs = param->Rhs(); if (const constant* exp = any_cast(rhs)) { int_typespec* its = buildIntTypespec( - compileDesign, param->VpiFile(), typeName, - exp->VpiValue(), param->VpiLineNo(), + compileDesign, + fileSystem->toPathId( + param->VpiFile(), + compileDesign->getCompiler()->getSymbolTable()), + typeName, exp->VpiValue(), param->VpiLineNo(), param->VpiColumnNo(), param->VpiLineNo(), param->VpiColumnNo()); result = its; @@ -1522,7 +1526,7 @@ UHDM::typespec* CompileHelper::compileTypespec( bool invalidValue = false; result = (typespec*)decodeHierPath( path, invalidValue, component, compileDesign, - instance, fC->getFileName(), fC->Line(type), + instance, fC->getFileId(), fC->Line(type), nullptr, reduce, false, true); } } @@ -1547,9 +1551,13 @@ UHDM::typespec* CompileHelper::compileTypespec( const any* rhs = param->Rhs(); if (const constant* exp = any_cast(rhs)) { int_typespec* its = buildIntTypespec( - compileDesign, param->VpiFile(), typeName, - exp->VpiValue(), param->VpiLineNo(), param->VpiColumnNo(), - param->VpiLineNo(), param->VpiColumnNo()); + compileDesign, + fileSystem->toPathId( + param->VpiFile(), + compileDesign->getCompiler()->getSymbolTable()), + typeName, exp->VpiValue(), param->VpiLineNo(), + param->VpiColumnNo(), param->VpiLineNo(), + param->VpiColumnNo()); result = its; } else if (const operation* exp = any_cast(rhs)) { @@ -1723,11 +1731,10 @@ UHDM::typespec* CompileHelper::compileTypespec( compileDesign->getCompiler()->getErrorContainer(); SymbolTable* symbols = compileDesign->getCompiler()->getSymbolTable(); std::string fileContent = - FileUtils::getFileContent(fC->getFileName()); + FileUtils::getFileContent(fileSystem->toPath(fC->getFileId())); std::string_view lineText = StringUtils::getLineInString(fileContent, fC->Line(type)); - Location loc(symbols->registerSymbol(fC->getFileName(type).string()), - fC->Line(type), fC->Column(type), + Location loc(fC->getFileId(type), fC->Line(type), fC->Column(type), symbols->registerSymbol( StrCat("<", fC->printObject(type), "> ", lineText))); Error err(ErrorDefinition::UHDM_UNSUPPORTED_TYPE, loc); @@ -1754,11 +1761,11 @@ UHDM::typespec* CompileHelper::compileTypespec( ErrorContainer* errors = compileDesign->getCompiler()->getErrorContainer(); SymbolTable* symbols = compileDesign->getCompiler()->getSymbolTable(); - std::string fileContent = FileUtils::getFileContent(fC->getFileName()); + std::string fileContent = + FileUtils::getFileContent(fileSystem->toPath(fC->getFileId())); std::string_view lineText = StringUtils::getLineInString(fileContent, fC->Line(type)); - Location loc(symbols->registerSymbol(fC->getFileName(type).string()), - fC->Line(type), fC->Column(type), + Location loc(fC->getFileId(type), fC->Line(type), fC->Column(type), symbols->registerSymbol( StrCat("<", fC->printObject(type), "> ", lineText))); Error err(ErrorDefinition::UHDM_UNSUPPORTED_TYPE, loc); @@ -1779,6 +1786,7 @@ UHDM::typespec* CompileHelper::elabTypespec(DesignComponent* component, CompileDesign* compileDesign, UHDM::any* pexpr, ValuedComponentI* instance) { + FileSystem* const fileSystem = FileSystem::getInstance(); Serializer& s = compileDesign->getSerializer(); typespec* result = spec; UHDM_OBJECT_TYPE type = spec->UhdmType(); @@ -1840,12 +1848,16 @@ UHDM::typespec* CompileHelper::elabTypespec(DesignComponent* component, expr* oldLeft = (expr*)oldRange->Left_expr(); expr* oldRight = (expr*)oldRange->Right_expr(); bool invalidValue = false; - expr* newLeft = - reduceExpr(oldLeft, invalidValue, component, compileDesign, instance, - oldLeft->VpiFile(), oldLeft->VpiLineNo(), pexpr); - expr* newRight = - reduceExpr(oldRight, invalidValue, component, compileDesign, instance, - oldRight->VpiFile(), oldRight->VpiLineNo(), pexpr); + expr* newLeft = reduceExpr( + oldLeft, invalidValue, component, compileDesign, instance, + fileSystem->toPathId(oldLeft->VpiFile(), + compileDesign->getCompiler()->getSymbolTable()), + oldLeft->VpiLineNo(), pexpr); + expr* newRight = reduceExpr( + oldRight, invalidValue, component, compileDesign, instance, + fileSystem->toPathId(oldRight->VpiFile(), + compileDesign->getCompiler()->getSymbolTable()), + oldRight->VpiLineNo(), pexpr); if (!invalidValue) { oldRange->Left_expr(newLeft); oldRange->Right_expr(newRight); diff --git a/src/DesignCompile/DesignElaboration.cpp b/src/DesignCompile/DesignElaboration.cpp index ffd5e315f2..685823b45d 100644 --- a/src/DesignCompile/DesignElaboration.cpp +++ b/src/DesignCompile/DesignElaboration.cpp @@ -22,6 +22,7 @@ */ #include +#include #include #include #include @@ -87,9 +88,8 @@ bool DesignElaboration::elaborate() { bool DesignElaboration::setupConfigurations_() { ConfigSet* configSet = m_compileDesign->getCompiler()->getDesign()->getConfigSet(); - SymbolTable* st = m_compileDesign->getCompiler() - ->getCommandLineParser() - ->mutableSymbolTable(); + SymbolTable* st = + m_compileDesign->getCompiler()->getCommandLineParser()->getSymbolTable(); std::vector& allConfigs = configSet->getAllMutableConfigs(); std::vector selectedConfigIds = m_compileDesign->getCompiler()->getCommandLineParser()->getUseConfigs(); @@ -143,8 +143,7 @@ bool DesignElaboration::setupConfigurations_() { Config* conf = configSet->getMutableConfigByName(confName); if (!conf) { const FileContent* fC = usec.second.getFileContent(); - Location loc(st->registerSymbol( - fC->getFileName(usec.second.getNodeId()).string()), + Location loc(fC->getFileId(usec.second.getNodeId()), fC->Line(usec.second.getNodeId()), fC->Column(usec.second.getNodeId()), st->registerSymbol(confName)); @@ -160,10 +159,9 @@ bool DesignElaboration::setupConfigurations_() { for (const auto& config : allConfigs) { const std::string& name = config.getName(); const FileContent* fC = config.getFileContent(); - SymbolId fid = - st->registerSymbol(fC->getFileName(config.getNodeId()).string()); - Location loc(fid, fC->Line(config.getNodeId()), - fC->Column(config.getNodeId()), st->getId(config.getName())); + Location loc(fC->getFileId(config.getNodeId()), + fC->Line(config.getNodeId()), fC->Column(config.getNodeId()), + st->getId(config.getName())); if (!config.isUsed()) { Error err(ErrorDefinition::ELAB_CONFIGURATION_IGNORED, loc); m_compileDesign->getCompiler()->getErrorContainer()->addError(err); @@ -248,6 +246,7 @@ void DesignElaboration::recurseBuildInstanceClause_( } bool DesignElaboration::identifyTopModules_() { + FileSystem* const fileSystem = FileSystem::getInstance(); m_topLevelModules.clear(); bool modulePresent = false; bool toplevelModuleFound = false; @@ -307,10 +306,8 @@ bool DesignElaboration::identifyTopModules_() { if (isTop) { SymbolId topid = st->registerSymbol(topname); auto itr = m_uniqueTopLevelModules.find(topname); - Location loc( - st->registerSymbol( - (file.second->getFileName(element->m_node)).string()), - element->m_line, element->m_column, topid); + Location loc(file.second->getFileId(element->m_node), + element->m_line, element->m_column, topid); if (itr == m_uniqueTopLevelModules.end()) { bool okModule = true; if (!userTopList.empty()) { @@ -345,22 +342,22 @@ bool DesignElaboration::identifyTopModules_() { if (moduleName == prevModuleName) { const FileContent* fC1 = (*itr).second.second; NodeId nodeId1 = moduleDefinition->m_node; - fs::path fileName1 = fC1->getFileName(nodeId1); + PathId fileId1 = fileSystem->copy(fC1->getFileId(nodeId1), st); unsigned int line1 = fC1->Line(nodeId1); - Location loc1(st->registerSymbol(fileName1.string()), line1, - fC1->Column(nodeId1), st->registerSymbol(moduleName)); + Location loc1(fileId1, line1, fC1->Column(nodeId1), + st->registerSymbol(moduleName)); std::vector locations; while (1) { const FileContent* fC2 = prevFileContent; NodeId nodeId2 = prevModuleDefinition->m_node; - fs::path fileName2 = fC2->getFileName(nodeId2); + PathId fileId2 = fileSystem->copy(fC2->getFileId(nodeId2), st); unsigned int line2 = fC2->Line(nodeId2); - Location loc2(st->registerSymbol(fileName2.string()), line2, - fC2->Column(nodeId2), st->registerSymbol(moduleName)); + Location loc2(fileId2, line2, fC2->Column(nodeId2), + st->registerSymbol(moduleName)); - if ((fileName1 != fileName2) || (line1 != line2)) { + if ((fileId1 != fileId2) || (line1 != line2)) { locations.push_back(loc2); } @@ -432,10 +429,8 @@ bool DesignElaboration::identifyTopModules_() { m_topLevelModules.emplace_back(topname, file.second); toplevelModuleFound = true; SymbolId topid = st->registerSymbol(topname); - Location loc( - st->registerSymbol( - (file.second->getFileName(element->m_node)).string()), - element->m_line, element->m_column, topid); + Location loc(file.second->getFileId(element->m_node), + element->m_line, element->m_column, topid); Error err(ErrorDefinition::ELAB_TOP_LEVEL_MODULE, loc); m_compileDesign->getCompiler()->getErrorContainer()->addError(err); } @@ -640,10 +635,9 @@ ModuleInstance* DesignElaboration::createBindInstance_( } else { SymbolTable* st = m_compileDesign->getCompiler()->getErrorContainer()->getSymbolTable(); - Location loc( - st->registerSymbol(fC->getFileName(bind->getStmtId()).string()), - fC->Line(bind->getStmtId()), fC->Column(bind->getStmtId()), - st->registerSymbol(bindModName)); + Location loc(fC->getFileId(bind->getStmtId()), + fC->Line(bind->getStmtId()), fC->Column(bind->getStmtId()), + st->registerSymbol(bindModName)); Error err(ErrorDefinition::ELAB_NO_MODULE_DEFINITION, loc); m_compileDesign->getCompiler()->getErrorContainer()->addError(err, false, false); @@ -679,8 +673,7 @@ void DesignElaboration::elaborateInstance_( if (blackboxModules.find(modName) != blackboxModules.end()) { SymbolTable* st = m_compileDesign->getCompiler()->getErrorContainer()->getSymbolTable(); - Location loc(st->registerSymbol(fC->getFileName().string()), - fC->Line(nodeId), fC->Column(nodeId), + Location loc(fC->getFileId(), fC->Line(nodeId), fC->Column(nodeId), st->registerSymbol(modName)); Error err(ErrorDefinition::ELAB_SKIPPING_BLACKBOX_MODULE, loc); m_compileDesign->getCompiler()->getErrorContainer()->addError(err, false, @@ -695,8 +688,7 @@ void DesignElaboration::elaborateInstance_( if (blackboxInstances.find(modName) != blackboxInstances.end()) { SymbolTable* st = m_compileDesign->getCompiler()->getErrorContainer()->getSymbolTable(); - Location loc(st->registerSymbol(fC->getFileName().string()), - fC->Line(nodeId), fC->Column(nodeId), + Location loc(fC->getFileId(), fC->Line(nodeId), fC->Column(nodeId), st->registerSymbol(modName)); Error err(ErrorDefinition::ELAB_SKIPPING_BLACKBOX_INSTANCE, loc); m_compileDesign->getCompiler()->getErrorContainer()->addError(err, false, @@ -706,8 +698,7 @@ void DesignElaboration::elaborateInstance_( if (blackboxInstances.find(instanceName) != blackboxInstances.end()) { SymbolTable* st = m_compileDesign->getCompiler()->getErrorContainer()->getSymbolTable(); - Location loc(st->registerSymbol(fC->getFileName().string()), - fC->Line(nodeId), fC->Column(nodeId), + Location loc(fC->getFileId(), fC->Line(nodeId), fC->Column(nodeId), st->registerSymbol(instanceName)); Error err(ErrorDefinition::ELAB_SKIPPING_BLACKBOX_INSTANCE, loc); m_compileDesign->getCompiler()->getErrorContainer()->addError(err, false, @@ -764,15 +755,12 @@ void DesignElaboration::elaborateInstance_( if (loopDetected) { SymbolTable* st = m_compileDesign->getCompiler()->getErrorContainer()->getSymbolTable(); - Location loc( - st->registerSymbol(fC->getFileName(parent->getNodeId()).string()), - fC->Line(parent->getNodeId()), fC->Column(parent->getNodeId()), - st->registerSymbol(parent->getModuleName())); - Location loc2( - st->registerSymbol( - tmp->getFileContent()->getFileName(tmp->getNodeId()).string()), - tmp->getFileContent()->Line(tmp->getNodeId()), - tmp->getFileContent()->Column(tmp->getNodeId())); + Location loc(fC->getFileId(parent->getNodeId()), + fC->Line(parent->getNodeId()), fC->Column(parent->getNodeId()), + st->registerSymbol(parent->getModuleName())); + Location loc2(tmp->getFileContent()->getFileId(tmp->getNodeId()), + tmp->getFileContent()->Line(tmp->getNodeId()), + tmp->getFileContent()->Column(tmp->getNodeId())); Error err(ErrorDefinition::ELAB_INSTANTIATION_LOOP, loc, loc2); m_compileDesign->getCompiler()->getErrorContainer()->addError(err); return; @@ -1503,10 +1491,9 @@ void DesignElaboration::elaborateInstance_( SymbolTable* st = m_compileDesign->getCompiler() ->getErrorContainer() ->getSymbolTable(); - Location loc( - st->registerSymbol(fC->getFileName(subInstanceId).string()), - fC->Line(subInstanceId), fC->Column(subInstanceId), - st->registerSymbol(modName)); + Location loc(fC->getFileId(subInstanceId), fC->Line(subInstanceId), + fC->Column(subInstanceId), + st->registerSymbol(modName)); Error err(ErrorDefinition::ELAB_NO_MODULE_DEFINITION, loc); m_compileDesign->getCompiler()->getErrorContainer()->addError( err, false, false); @@ -1728,9 +1715,8 @@ void DesignElaboration::collectParams_(std::vector& params, } } else { Location loc( - st->registerSymbol(pack_import.fC->getFileName(pack_id).string()), - pack_import.fC->Line(pack_id), pack_import.fC->Column(pack_id), - st->registerSymbol(pack_name)); + pack_import.fC->getFileId(pack_id), pack_import.fC->Line(pack_id), + pack_import.fC->Column(pack_id), st->registerSymbol(pack_name)); Error err(ErrorDefinition::ELAB_UNDEFINED_PACKAGE, loc); errors->addError(err); } @@ -1788,9 +1774,8 @@ void DesignElaboration::collectParams_(std::vector& params, NodeId expr = parentFile->Sibling(child); if (!expr) { Location loc( - st->registerSymbol(parentFile->getFileName(paramAssign).string()), - parentFile->Line(paramAssign), parentFile->Column(paramAssign), - st->registerSymbol(name)); + parentFile->getFileId(paramAssign), parentFile->Line(paramAssign), + parentFile->Column(paramAssign), st->registerSymbol(name)); Error err(ErrorDefinition::ELAB_EMPTY_PARAM_OVERRIDE, loc); errors->addError(err); continue; @@ -1972,8 +1957,7 @@ void DesignElaboration::collectParams_(std::vector& params, overridenParams.insert(name); } else { if (parentFile->Type(expr) != slDelay2) { - Location loc(st->registerSymbol( - parentFile->getFileName(paramAssign).string()), + Location loc(parentFile->getFileId(paramAssign), parentFile->Line(paramAssign), parentFile->Column(paramAssign), st->registerSymbol(std::to_string(index))); @@ -2021,7 +2005,7 @@ void DesignElaboration::collectParams_(std::vector& params, m_compileDesign->getCompiler()->getCommandLineParser(); const auto& useroverrides = cmdLine->getParamList(); for (const auto& [nameId, value] : useroverrides) { - const std::string& name = cmdLine->getSymbolTable().getSymbol(nameId); + const std::string& name = cmdLine->getSymbolTable()->getSymbol(nameId); Value* val = m_exprBuilder.fromString(value); if (val) { instance->setValue(name, val, m_exprBuilder, 0); @@ -2199,7 +2183,7 @@ void DesignElaboration::checkElaboration_() { const auto& useroverrides = cmdLine->getParamList(); for (const auto& [nameId, value] : useroverrides) { bool found = false; - const std::string& name = cmdLine->getSymbolTable().getSymbol(nameId); + const std::string& name = cmdLine->getSymbolTable()->getSymbol(nameId); for (ModuleInstance* inst : design->getTopLevelModuleInstances()) { DesignComponent* module = inst->getDefinition(); Parameter* p = module->getParameter(name); @@ -2224,10 +2208,9 @@ void DesignElaboration::checkConfigurations_() { UseClause& useC = pathUseC.second; if (!useC.isUsed()) { const FileContent* fC = useC.getFileContent(); - Location loc( - st->registerSymbol(fC->getFileName(useC.getNodeId()).string()), - fC->Line(useC.getNodeId()), fC->Column(useC.getNodeId()), - st->registerSymbol(pathUseC.first)); + Location loc(fC->getFileId(useC.getNodeId()), fC->Line(useC.getNodeId()), + fC->Column(useC.getNodeId()), + st->registerSymbol(pathUseC.first)); Error err(ErrorDefinition::ELAB_USE_CLAUSE_IGNORED, loc); m_compileDesign->getCompiler()->getErrorContainer()->addError(err); } @@ -2236,10 +2219,9 @@ void DesignElaboration::checkConfigurations_() { UseClause& useC = pathUseC.second; if (!useC.isUsed()) { const FileContent* fC = useC.getFileContent(); - Location loc( - st->registerSymbol(fC->getFileName(useC.getNodeId()).string()), - fC->Line(useC.getNodeId()), fC->Column(useC.getNodeId()), - st->registerSymbol(pathUseC.first)); + Location loc(fC->getFileId(useC.getNodeId()), fC->Line(useC.getNodeId()), + fC->Column(useC.getNodeId()), + st->registerSymbol(pathUseC.first)); Error err(ErrorDefinition::ELAB_USE_CLAUSE_IGNORED, loc); m_compileDesign->getCompiler()->getErrorContainer()->addError(err); } @@ -2400,6 +2382,14 @@ bool DesignElaboration::bindDataTypes_() { } void DesignElaboration::createFileList_() { + CommandLineParser* cmdLine = + m_compileDesign->getCompiler()->getCommandLineParser(); + if (!(cmdLine->writePpOutput() || cmdLine->writePpOutputFileId())) { + return; + } + + FileSystem* const fileSystem = FileSystem::getInstance(); + Design* design = m_compileDesign->getCompiler()->getDesign(); std::queue queue; std::set files; @@ -2419,8 +2409,8 @@ void DesignElaboration::createFileList_() { DesignComponent* def = current->getDefinition(); queue.pop(); if (current == nullptr) continue; - for (unsigned int i = 0; i < current->getNbChildren(); i++) { - queue.push(current->getChildren(i)); + for (ModuleInstance* sub : current->getAllSubInstances()) { + queue.push(sub); } const FileContent* fC = current->getFileContent(); if (fC) { @@ -2434,30 +2424,27 @@ void DesignElaboration::createFileList_() { } } } - CommandLineParser* cmdLine = - m_compileDesign->getCompiler()->getCommandLineParser(); - if (cmdLine->writePpOutput() || cmdLine->writePpOutputFileId()) { - const fs::path directory = - cmdLine->getSymbolTable().getSymbol(cmdLine->getFullCompileDir()); - std::ofstream ofs; - fs::path fileList = directory / "file_elab.lst"; - ofs.open(fileList); - const std::map>& ppFileName = - m_compileDesign->getCompiler()->getPPFileMap(); - if (ofs.good()) { - for (auto fC : files) { - auto itr = ppFileName.find(fC->getFileName()); - if (itr != ppFileName.end()) { - for (const auto& f : itr->second) { - ofs << f << std::flush << std::endl; - } + const fs::path directory = fileSystem->toPath(cmdLine->getFullCompileDirId()); + std::ofstream ofs; + fs::path fileList = directory / "file_elab.lst"; + ofs.open(fileList); + const Compiler::PPFileMap& ppFileName = + m_compileDesign->getCompiler()->getPPFileMap(); + SymbolTable* symbolTable = m_compileDesign->getCompiler()->getSymbolTable(); + if (ofs.good()) { + for (const auto& fC : files) { + PathId fileId = fileSystem->copy(fC->getFileId(), symbolTable); + auto itr = ppFileName.find(fileId); + if (itr != ppFileName.end()) { + for (const auto& fId : itr->second) { + ofs << fileSystem->toPath(fId) << std::flush << std::endl; } } - ofs.close(); - } else { - std::cout << "Could not create filelist: " << fileList << std::endl; } + ofs.close(); + } else { + std::cerr << "Could not create filelist: " << fileList << std::endl; } } } // namespace SURELOG diff --git a/src/DesignCompile/ElaborationStep.cpp b/src/DesignCompile/ElaborationStep.cpp index 9489d2fbe6..971c9f21fa 100644 --- a/src/DesignCompile/ElaborationStep.cpp +++ b/src/DesignCompile/ElaborationStep.cpp @@ -22,6 +22,7 @@ */ #include +#include #include #include #include @@ -77,6 +78,7 @@ ElaborationStep::ElaborationStep(CompileDesign* compileDesign) ElaborationStep::~ElaborationStep() {} bool ElaborationStep::bindTypedefs_() { + FileSystem* const fileSystem = FileSystem::getInstance(); Compiler* compiler = m_compileDesign->getCompiler(); ErrorContainer* errors = compiler->getErrorContainer(); SymbolTable* symbols = compiler->getSymbolTable(); @@ -216,7 +218,7 @@ bool ElaborationStep::bindTypedefs_() { specs.insert(std::make_pair(name, ts)); } if (ts->UhdmType() == uhdmunsupported_typespec) { - Location loc1(symbols->registerSymbol(ts->VpiFile().string()), + Location loc1(fileSystem->toPathId(ts->VpiFile(), symbols), ts->VpiLineNo(), ts->VpiColumnNo(), symbols->registerSymbol(name)); Error err1(ErrorDefinition::COMP_UNDEFINED_TYPE, loc1); @@ -253,15 +255,13 @@ bool ElaborationStep::bindTypedefs_() { if (prevDef == nullptr) { const FileContent* fC = typd->getFileContent(); NodeId id = typd->getNodeId(); - fs::path fileName = fC->getFileName(id); std::string definition_string; NodeId defNode = typd->getDefinitionNode(); VObjectType defType = fC->Type(defNode); if (defType == VObjectType::slStringConst) { definition_string = fC->SymName(defNode); } - Location loc1(symbols->registerSymbol(fileName.string()), - fC->Line(id), fC->Column(id), + Location loc1(fC->getFileId(id), fC->Line(id), fC->Column(id), symbols->registerSymbol(definition_string)); Error err1(ErrorDefinition::COMP_UNDEFINED_TYPE, loc1); errors->addError(err1); @@ -716,9 +716,8 @@ const DataType* ElaborationStep::bindDataType_( } if ((found == false) && (errtype != ErrorDefinition::NO_ERROR_MESSAGE)) { - fs::path fileName = fC->getFileName(id); - Location loc1(symbols->registerSymbol(fileName.string()), fC->Line(id), - fC->Column(id), symbols->registerSymbol(type_name)); + Location loc1(fC->getFileId(id), fC->Line(id), fC->Column(id), + symbols->registerSymbol(type_name)); Location loc2(symbols->registerSymbol(parent->getName())); Error err1(errtype, loc1, loc2); errors->addError(err1); @@ -783,9 +782,8 @@ Variable* ElaborationStep::bindVariable_(const std::string& var_name, } if ((result == nullptr) && (errtype != ErrorDefinition::NO_ERROR_MESSAGE)) { - fs::path fileName = fC->getFileName(id); - Location loc1(symbols->registerSymbol(fileName.string()), fC->Line(id), - fC->Column(id), symbols->registerSymbol(var_name)); + Location loc1(fC->getFileId(id), fC->Line(id), fC->Column(id), + symbols->registerSymbol(var_name)); Location loc2(symbols->registerSymbol(parent->getName())); Error err1(errtype, loc1, loc2); errors->addError(err1); @@ -948,8 +946,7 @@ void checkIfBuiltInTypeOrErrorOut(DesignComponent* def, const FileContent* fC, (interfName != "unsigned") && (interfName != "do") && (interfName != "final") && (interfName != "global") && (interfName != "soft")) { - Location loc(symbols->registerSymbol(fC->getFileName(id).string()), - fC->Line(id), fC->Column(id), + Location loc(fC->getFileId(id), fC->Line(id), fC->Column(id), symbols->registerSymbol(interfName)); Error err(ErrorDefinition::COMP_UNDEFINED_TYPE, loc); errors->addError(err); @@ -1027,8 +1024,7 @@ bool ElaborationStep::bindPortType_(Signal* signal, const FileContent* fC, if (interface) { signal->setInterfaceDef(interface); } else { - Location loc(symbols->registerSymbol( - fC->getFileName(if_type_name_s).string()), + Location loc(fC->getFileId(if_type_name_s), fC->Line(if_type_name_s), fC->Column(if_type_name_s), symbols->registerSymbol(interfaceName)); diff --git a/src/DesignCompile/EvalFunc.cpp b/src/DesignCompile/EvalFunc.cpp index adc399db47..b64d288641 100644 --- a/src/DesignCompile/EvalFunc.cpp +++ b/src/DesignCompile/EvalFunc.cpp @@ -47,9 +47,8 @@ using namespace UHDM; // NOLINT (using a bunch of them) expr* CompileHelper::EvalFunc(UHDM::function* func, std::vector* args, bool& invalidValue, DesignComponent* component, CompileDesign* compileDesign, - ValuedComponentI* instance, - const fs::path& fileName, int lineNumber, - any* pexpr) { + ValuedComponentI* instance, PathId fileId, + int lineNumber, any* pexpr) { UHDM::GetObjectFunctor getObjectFunctor = [&](const std::string& name, const any* inst, const any* pexpr) -> UHDM::any* { @@ -58,7 +57,7 @@ expr* CompileHelper::EvalFunc(UHDM::function* func, std::vector* args, UHDM::GetObjectFunctor getValueFunctor = [&](const std::string& name, const any* inst, const any* pexpr) -> UHDM::any* { - return (expr*)getValue(name, component, compileDesign, instance, fileName, + return (expr*)getValue(name, component, compileDesign, instance, fileId, lineNumber, (any*)pexpr, true, false); }; UHDM::GetTaskFuncFunctor getTaskFuncFunctor = @@ -92,7 +91,7 @@ void CompileHelper::evalScheduledExprs(DesignComponent* component, bool invalidValue = false; expr* result = reduceExpr(expr_eval.m_expr, invalidValue, component, compileDesign, - expr_eval.m_instance, expr_eval.m_fileName, + expr_eval.m_instance, expr_eval.m_fileId, expr_eval.m_lineNumber, expr_eval.m_pexpr); if (result && result->UhdmType() == uhdmconstant) { UHDM::constant* c = (UHDM::constant*)result; diff --git a/src/DesignCompile/NetlistElaboration.cpp b/src/DesignCompile/NetlistElaboration.cpp index 691b29f799..9f87985ea5 100644 --- a/src/DesignCompile/NetlistElaboration.cpp +++ b/src/DesignCompile/NetlistElaboration.cpp @@ -22,6 +22,7 @@ */ #include +#include #include #include #include @@ -127,6 +128,7 @@ bool NetlistElaboration::elaborate() { bool NetlistElaboration::elab_parameters_(ModuleInstance* instance, bool param_port) { + FileSystem* const fileSystem = FileSystem::getInstance(); Serializer& s = m_compileDesign->getSerializer(); if (!instance) return true; Netlist* netlist = instance->getNetlist(); @@ -155,7 +157,7 @@ bool NetlistElaboration::elab_parameters_(ModuleInstance* instance, constant* c = s.MakeConstant(); c->VpiValue(value->uhdmValue()); c->VpiDecompile(value->decompiledValue()); - c->VpiFile(instfC->getFileName()); + c->VpiFile(fileSystem->toPath(instfC->getFileId()).string()); c->VpiSize(value->getSize()); c->VpiConstType(value->vpiValType()); c->VpiLineNo(line); @@ -359,7 +361,10 @@ bool NetlistElaboration::elab_parameters_(ModuleInstance* instance, bool invalidValue = false; m_helper.checkForLoops(true); expr* tmp = m_helper.reduceExpr( - exp, invalidValue, mod, m_compileDesign, instance, exp->VpiFile(), + exp, invalidValue, mod, m_compileDesign, instance, + fileSystem->toPathId( + exp->VpiFile(), + m_compileDesign->getCompiler()->getSymbolTable()), exp->VpiLineNo(), nullptr, true); m_helper.checkForLoops(false); if (tmp && (invalidValue == false)) exp = tmp; @@ -378,7 +383,10 @@ bool NetlistElaboration::elab_parameters_(ModuleInstance* instance, m_helper.checkForLoops(true); expr* tmp = m_helper.reduceExpr( exp, invalidValue, mod, m_compileDesign, instance, - exp->VpiFile(), exp->VpiLineNo(), nullptr, true); + fileSystem->toPathId( + exp->VpiFile(), + m_compileDesign->getCompiler()->getSymbolTable()), + exp->VpiLineNo(), nullptr, true); m_helper.checkForLoops(false); if (tmp && (invalidValue == false)) exp = tmp; } @@ -443,6 +451,7 @@ bool NetlistElaboration::elab_parameters_(ModuleInstance* instance, bool NetlistElaboration::elaborate_(ModuleInstance* instance, bool recurse) { if (instance->isElaborated()) return true; + FileSystem* const fileSystem = FileSystem::getInstance(); instance->setElaborated(); Netlist* netlist = instance->getNetlist(); bool elabPortsNets = false; @@ -482,10 +491,12 @@ bool NetlistElaboration::elaborate_(ModuleInstance* instance, bool recurse) { valuedcomponenti_cast(childDef)) { VObjectType insttype = instance->getType(); if (insttype == VObjectType::slInterface_instantiation) { - elab_interface_(instance->getParent(), instance, - instance->getInstanceName(), instance->getModuleName(), - mm, instance->getFileName(), instance->getLineNb(), - nullptr, ""); + elab_interface_( + instance->getParent(), instance, instance->getInstanceName(), + instance->getModuleName(), mm, + fileSystem->copy(instance->getFileId(), + m_compileDesign->getCompiler()->getSymbolTable()), + instance->getLineNb(), nullptr, ""); } } @@ -649,6 +660,7 @@ ModuleInstance* NetlistElaboration::getInterfaceInstance_( } bool NetlistElaboration::high_conn_(ModuleInstance* instance) { + FileSystem* const fileSystem = FileSystem::getInstance(); ModuleInstance* parent = instance->getParent(); DesignComponent* parent_comp = nullptr; if (parent) parent_comp = parent->getDefinition(); @@ -1078,10 +1090,13 @@ bool NetlistElaboration::high_conn_(ModuleInstance* instance) { Netlist* netlistInterf = new Netlist(interfaceInstance); interfaceInstance->setNetlist(netlistInterf); - mp = elab_modport_(instance, interfaceInstance, formalName, - orig_interf->getName(), orig_interf, - p->VpiFile(), p->VpiLineNo(), selectName, - nullptr); + mp = elab_modport_( + instance, interfaceInstance, formalName, + orig_interf->getName(), orig_interf, + fileSystem->toPathId( + p->VpiFile(), + m_compileDesign->getCompiler()->getSymbolTable()), + p->VpiLineNo(), selectName, nullptr); } } if (mp) { @@ -1111,10 +1126,13 @@ bool NetlistElaboration::high_conn_(ModuleInstance* instance) { ModuleInstance* orig_instance = (*itr).second.first; ModuleDefinition* orig_interf = (ModuleDefinition*)orig_instance->getDefinition(); - sm = elab_interface_(instance, orig_instance, formalName, - orig_interf->getName(), orig_interf, - instance->getFileName(), - instance->getLineNb(), nullptr, ""); + sm = elab_interface_( + instance, orig_instance, formalName, orig_interf->getName(), + orig_interf, + fileSystem->copy( + instance->getFileId(), + m_compileDesign->getCompiler()->getSymbolTable()), + instance->getLineNb(), nullptr, ""); } } if (sm) { @@ -1148,7 +1166,7 @@ bool NetlistElaboration::high_conn_(ModuleInstance* instance) { if (!found) { port* p = s.MakePort(); p->VpiName(sigName); - p->VpiFile(fC->getFileName()); + p->VpiFile(fileSystem->toPath(fC->getFileId()).string()); p->VpiLineNo(wildcardLineNumber); p->VpiColumnNo(wildcardColumnNumber); p->VpiEndLineNo(wildcardLineNumber); @@ -1158,7 +1176,7 @@ bool NetlistElaboration::high_conn_(ModuleInstance* instance) { } if (pp->High_conn() == nullptr) { ref_obj* ref = s.MakeRef_obj(); - ref->VpiFile(fC->getFileName()); + ref->VpiFile(fileSystem->toPath(fC->getFileId()).string()); ref->VpiLineNo(wildcardLineNumber); ref->VpiColumnNo(wildcardColumnNumber); ref->VpiEndLineNo(wildcardLineNumber); @@ -1185,8 +1203,9 @@ bool NetlistElaboration::high_conn_(ModuleInstance* instance) { interface* NetlistElaboration::elab_interface_( ModuleInstance* instance, ModuleInstance* interf_instance, const std::string& instName, const std::string& defName, - ModuleDefinition* mod, const fs::path& fileName, int lineNb, + ModuleDefinition* mod, PathId fileId, int lineNb, interface_array* interf_array, const std::string& modPortName) { + FileSystem* const fileSystem = FileSystem::getInstance(); Netlist* netlist = instance->getNetlist(); if (netlist == nullptr) { netlist = new Netlist(instance); @@ -1202,7 +1221,7 @@ interface* NetlistElaboration::elab_interface_( sm->VpiName(instName); sm->VpiDefName(defName); // sm->VpiFullName(??); - sm->VpiFile(fileName); + sm->VpiFile(fileSystem->toPath(fileId).string()); sm->VpiLineNo(lineNb); subInterfaces->push_back(sm); if (interf_array) { @@ -1277,14 +1296,14 @@ interface* NetlistElaboration::elab_interface_( modport* NetlistElaboration::elab_modport_( ModuleInstance* instance, ModuleInstance* interfaceInstance, const std::string& instName, const std::string& defName, - ModuleDefinition* mod, const fs::path& fileName, int lineNb, + ModuleDefinition* mod, PathId fileId, int lineNb, const std::string& modPortName, UHDM::interface_array* interf_array) { Netlist* netlist = instance->getNetlist(); std::string fullname = instName + "." + modPortName; Netlist::ModPortMap::iterator itr = netlist->getModPortMap().find(fullname); if (itr == netlist->getModPortMap().end()) { - elab_interface_(instance, interfaceInstance, instName, defName, mod, - fileName, lineNb, interf_array, fullname); + elab_interface_(instance, interfaceInstance, instName, defName, mod, fileId, + lineNb, interf_array, fullname); } itr = netlist->getModPortMap().find(fullname); if (itr != netlist->getModPortMap().end()) { @@ -1364,7 +1383,7 @@ bool NetlistElaboration::elab_interfaces_(ModuleInstance* instance) { VObjectType insttype = child->getType(); if (insttype == VObjectType::slInterface_instantiation) { elab_interface_(instance, child, child->getInstanceName(), - child->getModuleName(), mm, child->getFileName(), + child->getModuleName(), mm, child->getFileId(), child->getLineNb(), nullptr, ""); } } @@ -1490,8 +1509,7 @@ bool NetlistElaboration::elabSignal(Signal* sig, ModuleInstance* instance, SymbolTable* symbols = m_compileDesign->getCompiler()->getSymbolTable(); ErrorContainer* errors = m_compileDesign->getCompiler()->getErrorContainer(); - Location loc1(symbols->registerSymbol(fC->getFileName().string()), - fC->Line(id), fC->Column(id), + Location loc1(fC->getFileId(), fC->Line(id), fC->Column(id), symbols->registerSymbol(sig->getName())); Error err(ErrorDefinition::ELAB_USE_INTERFACE_AS_SIGNAL_TYPE, loc1); errors->addError(err); @@ -1895,8 +1913,7 @@ bool NetlistElaboration::elabSignal(Signal* sig, ModuleInstance* instance, ErrorContainer* errors = m_compileDesign->getCompiler()->getErrorContainer(); SymbolTable* symbols = m_compileDesign->getCompiler()->getSymbolTable(); - Location loc(symbols->registerSymbol(fC->getFileName().string()), - fC->Line(id), fC->Column(id), + Location loc(fC->getFileId(), fC->Line(id), fC->Column(id), symbols->registerSymbol(signame)); Error err(ErrorDefinition::UHDM_UNSUPPORTED_SIGNAL, loc); errors->addError(err); @@ -2054,7 +2071,7 @@ bool NetlistElaboration::elab_ports_nets_( instance->addSubInstance(interfaceInstance); elab_modport_(instance, interfaceInstance, sigName, orig_interf->getName(), orig_interf, - instance->getFileName(), instance->getLineNb(), + instance->getFileId(), instance->getLineNb(), orig_modport->getName(), array_int); } } else { @@ -2076,7 +2093,7 @@ bool NetlistElaboration::elab_ports_nets_( modport* mp = elab_modport_( instance, interfaceInstance, signame, orig_interf->getName(), - orig_interf, instance->getFileName(), instance->getLineNb(), + orig_interf, instance->getFileId(), instance->getLineNb(), orig_modport->getName(), array_int); instance->addSubInstance(interfaceInstance); ref->Actual_group(mp); @@ -2120,7 +2137,7 @@ bool NetlistElaboration::elab_ports_nets_( interface* sm = elab_interface_( instance, interfaceInstance, signame, orig_interf->getName(), - orig_interf, instance->getFileName(), instance->getLineNb(), + orig_interf, instance->getFileId(), instance->getLineNb(), array_int, ""); if (unpackedDimensions) { @@ -2260,7 +2277,7 @@ UHDM::any* NetlistElaboration::bind_net_(const FileContent* origfC, NodeId id, } m_helper.checkForLoops(true); result = m_helper.getValue(name, instance->getDefinition(), m_compileDesign, - instance, "", 0, nullptr, true, true); + instance, BadPathId, 0, nullptr, true, true); m_helper.checkForLoops(false); } if ((instance != nullptr) && (result == nullptr)) { @@ -2277,7 +2294,7 @@ UHDM::any* NetlistElaboration::bind_net_(const FileContent* origfC, NodeId id, ErrorContainer* errors = m_compileDesign->getCompiler()->getErrorContainer(); - Location loc(symbols->registerSymbol(origfC->getFileName().string()), + Location loc(origfC->getFileId(), id ? origfC->Line(id) : instance->getLineNb(), id ? origfC->Column(id) : instance->getColumnNb(), symbols->registerSymbol(name)); diff --git a/src/DesignCompile/ResolveSymbols.cpp b/src/DesignCompile/ResolveSymbols.cpp index d99cb4867c..0bb6ac842d 100644 --- a/src/DesignCompile/ResolveSymbols.cpp +++ b/src/DesignCompile/ResolveSymbols.cpp @@ -298,7 +298,7 @@ bool ResolveSymbols::bindDefinition_(NodeId objIndex, bool found = false; for (const auto& file : all_files) { - SymbolId fileId = file.first; + PathId fileId = file.first; FileContent* fcontent = file.second; auto itr = fcontent->getObjectLookup().find(modName); diff --git a/src/DesignCompile/TestbenchElaboration.cpp b/src/DesignCompile/TestbenchElaboration.cpp index aa8b961d52..12f4201a73 100644 --- a/src/DesignCompile/TestbenchElaboration.cpp +++ b/src/DesignCompile/TestbenchElaboration.cpp @@ -21,6 +21,7 @@ * Created on February 6, 2019, 9:01 PM */ +#include #include #include #include @@ -148,6 +149,7 @@ bool TestbenchElaboration::bindClasses_() { } bool TestbenchElaboration::checkForMultipleDefinition_() { + FileSystem* const fileSystem = FileSystem::getInstance(); Compiler* compiler = m_compileDesign->getCompiler(); ErrorContainer* errors = compiler->getErrorContainer(); SymbolTable* symbols = compiler->getSymbolTable(); @@ -165,22 +167,22 @@ bool TestbenchElaboration::checkForMultipleDefinition_() { if (className == prevClassName) { const FileContent* fC1 = classDefinition->getFileContents()[0]; NodeId nodeId1 = classDefinition->getNodeIds()[0]; - fs::path fileName1 = fC1->getFileName(nodeId1); + PathId fileId1 = fileSystem->copy(fC1->getFileId(nodeId1), symbols); unsigned int line1 = fC1->Line(nodeId1); - Location loc1(symbols->registerSymbol(fileName1.string()), line1, - fC1->Column(nodeId1), symbols->registerSymbol(className)); + Location loc1(fileId1, line1, fC1->Column(nodeId1), + symbols->registerSymbol(className)); std::vector locations; while (1) { const FileContent* fC2 = prevClassDefinition->getFileContents()[0]; NodeId nodeId2 = prevClassDefinition->getNodeIds()[0]; - fs::path fileName2 = fC2->getFileName(nodeId2); + PathId fileId2 = fileSystem->copy(fC2->getFileId(nodeId2), symbols); unsigned int line2 = fC2->Line(nodeId2); - Location loc2(symbols->registerSymbol(fileName2.string()), line2, - fC2->Column(nodeId2), symbols->registerSymbol(className)); + Location loc2(fileId2, line2, fC2->Column(nodeId2), + symbols->registerSymbol(className)); - if ((fileName1 != fileName2) || (line1 != line2)) { + if ((fileId1 != fileId2) || (line1 != line2)) { std::string diff; if (fC1->diffTree(nodeId1, fC2, nodeId2, &diff)) { locations.push_back(loc2); @@ -378,10 +380,8 @@ bool TestbenchElaboration::bindFunctionReturnTypesAndParamaters_() { const std::string& typeName = dtype->getName(); NodeId p = param->getNodeId(); const FileContent* fC = dtype->getFileContent(); - fs::path fileName = fC->getFileName(p); Location loc1( - symbols->registerSymbol(fileName.string()), fC->Line(p), - fC->Column(p), + fC->getFileId(p), fC->Line(p), fC->Column(p), symbols->registerSymbol(name + " of type " + typeName)); std::string exp; if (value->getType() == Value::Type::String) @@ -498,9 +498,8 @@ bool TestbenchElaboration::bindSubRoutineCall_(ClassDefinition* classDefinition, if (!validFunction) { const FileContent* fC = st->getFileContent(); NodeId p = st->getNodeId(); - fs::path fileName = fC->getFileName(p); - Location loc1(symbols->registerSymbol(fileName.string()), fC->Line(p), - fC->Column(p), symbols->registerSymbol(function)); + Location loc1(fC->getFileId(p), fC->Line(p), fC->Column(p), + symbols->registerSymbol(function)); Error err1(ErrorDefinition::COMP_UNDEFINED_SYSTEM_FUNCTION, loc1); errors->addError(err1); return true; @@ -540,16 +539,13 @@ bool TestbenchElaboration::bindSubRoutineCall_(ClassDefinition* classDefinition, if (!datatypeName.empty()) typeName = datatypeName; NodeId p = st->getNodeId(); const FileContent* fC = st->getFileContent(); - fs::path fileName = fC->getFileName(p); Location loc1( - symbols->registerSymbol(fileName.string()), fC->Line(p), fC->Column(p), + fC->getFileId(p), fC->Line(p), fC->Column(p), symbols->registerSymbol("\"" + name + "\"" + " of type " + typeName)); const FileContent* fC2 = dtype->getFileContent(); - fs::path fileName2 = fC2->getFileName(dtype->getNodeId()); - Location loc2(symbols->registerSymbol(fileName2.string()), - fC2->Line(dtype->getNodeId()), - fC2->Column(dtype->getNodeId()), - symbols->registerSymbol(function)); + Location loc2( + fC2->getFileId(dtype->getNodeId()), fC2->Line(dtype->getNodeId()), + fC2->Column(dtype->getNodeId()), symbols->registerSymbol(function)); Error err1(ErrorDefinition::COMP_NO_METHOD_FOR_TYPE, loc1, loc2); errors->addError(err1); } @@ -762,8 +758,7 @@ bool TestbenchElaboration::bindProperties_() { ErrorContainer* errors = m_compileDesign->getCompiler()->getErrorContainer(); SymbolTable* symbols = m_compileDesign->getCompiler()->getSymbolTable(); - Location loc(symbols->registerSymbol(fC->getFileName().string()), - fC->Line(id), fC->Column(id), + Location loc(fC->getFileId(), fC->Line(id), fC->Column(id), symbols->registerSymbol(signame)); Error err(ErrorDefinition::UHDM_UNSUPPORTED_SIGNAL, loc); errors->addError(err); diff --git a/src/DesignCompile/UhdmChecker.cpp b/src/DesignCompile/UhdmChecker.cpp index acc8a1ef6b..5c80da7fff 100644 --- a/src/DesignCompile/UhdmChecker.cpp +++ b/src/DesignCompile/UhdmChecker.cpp @@ -22,6 +22,7 @@ */ #include +#include #include #include #include @@ -60,7 +61,7 @@ bool UhdmChecker::registerFile(const FileContent* fC, std::set& moduleNames) { const VObject& current = fC->Object(NodeId(fC->getSize() - 2)); NodeId id = current.m_child; - SymbolId fileId = fC->getSymbolId(); + PathId fileId = fC->getFileId(); if (!id) id = current.m_sibling; if (!id) return false; std::stack stack; @@ -84,7 +85,7 @@ bool UhdmChecker::registerFile(const FileContent* fC, if (type == VObjectType::slEnd) skip = true; // Skip macro expansion which resides in another file (header) - SymbolId fid = fC->getFileId(id); + PathId fid = fC->getFileId(id); if (fid != fileId) { if (current.m_sibling) stack.push(current.m_sibling); continue; @@ -236,11 +237,11 @@ bool UhdmChecker::registerFile(const FileContent* fC, return true; } -bool UhdmChecker::reportHtml(CompileDesign* compileDesign, - const fs::path& reportFile, - float overallCoverage) { - ErrorContainer* errors = compileDesign->getCompiler()->getErrorContainer(); - SymbolTable* symbols = compileDesign->getCompiler()->getSymbolTable(); +bool UhdmChecker::reportHtml(PathId reportFileId, float overallCoverage) { + FileSystem* const fileSystem = FileSystem::getInstance(); + ErrorContainer* errors = m_compileDesign->getCompiler()->getErrorContainer(); + SymbolTable* symbols = m_compileDesign->getCompiler()->getSymbolTable(); + const std::filesystem::path reportFile = fileSystem->toPath(reportFileId); std::ofstream report; report.open(reportFile.string() + ".html"); if (report.bad()) return false; @@ -253,7 +254,8 @@ bool UhdmChecker::reportHtml(CompileDesign* compileDesign, std::string allUncovered; static std::multimap orderedCoverageMap; for (const auto& [fC, uhdmCover] : fileNodeCoverMap) { - std::string fileContent = FileUtils::getFileContent(fC->getFileName()); + const fs::path filepath = fileSystem->toPath(fC->getFileId()); + std::string fileContent = FileUtils::getFileContent(filepath); auto fileContentLines = StringUtils::splitLines(fileContent); std::ofstream reportF; std::string fname = "chk" + std::to_string(fileIndex) + ".html"; @@ -264,8 +266,7 @@ bool UhdmChecker::reportHtml(CompileDesign* compileDesign, "{\nfont-size: 14px;\n}\n"; float cov = 0.0f; - std::map::iterator itr = - fileCoverageMap.find(fC->getFileName()); + const auto& itr = fileCoverageMap.find(fC->getFileId()); cov = (*itr).second; std::stringstream strst; strst << std::setprecision(3) << cov; @@ -276,24 +277,24 @@ bool UhdmChecker::reportHtml(CompileDesign* compileDesign, "#82E0AA; margin:0; min-width: 110px; padding:10; float: left; \">" + coverage + "

" + fC->getFileName().string() + "

\n"; + fname + "> " + filepath.string() + "\n"; const std::string fileStatPink = "\n"; + fname + "> " + filepath.string() + "\n"; const std::string fileStatRed = "\n"; + fname + "> " + filepath.string() + "\n"; const std::string fileStatWhite = "

" + - fC->getFileName().string() + " " + coverage + "

\n"; + filepath.string() + " " + coverage + "\n"; - reportF << "

" << fC->getFileName() << coverage << "

\n"; + reportF << "

" << filepath << coverage << "

\n"; bool uncovered = false; std::string pinkCoverage; std::string redCoverage; @@ -329,8 +330,7 @@ bool UhdmChecker::reportHtml(CompileDesign* compileDesign, } if (lineText.empty()) { - Location loc(symbols->registerSymbol(fC->getFileName().string()), - line, 1); + Location loc(fileSystem->toPathId(filepath, symbols), line, 1); Error err(ErrorDefinition::UHDM_WRONG_COVERAGE_LINE, loc); errors->addError(err); } @@ -435,7 +435,9 @@ void UhdmChecker::mergeColumnCoverage() { } } -float UhdmChecker::reportCoverage(const fs::path& reportFile) { +float UhdmChecker::reportCoverage(PathId reportFileId) { + FileSystem* const fileSystem = FileSystem::getInstance(); + const std::filesystem::path reportFile = fileSystem->toPath(reportFileId); std::ofstream report; report.open(reportFile); if (report.bad()) return false; @@ -471,7 +473,8 @@ float UhdmChecker::reportCoverage(const fs::path& reportFile) { if (fileNamePrinted == false) { firstUncoveredLine = cItr.first; report << "\n\n" - << fC->getFileName() << ":" << cItr.first << ": " + << fileSystem->toPath(fC->getFileId()) << ":" << cItr.first + << ": " << " Missing models\n"; fileNamePrinted = true; } @@ -487,10 +490,10 @@ float UhdmChecker::reportCoverage(const fs::path& reportFile) { coverage = (lineNb - uncovered) * 100.0f / lineNb; if (uncovered) { report << "File coverage: " << std::setprecision(3) << coverage << "%\n"; - coverageMap.insert(std::make_pair( - coverage, std::make_pair(fC->getFileName(), firstUncoveredLine))); + coverageMap.emplace(coverage, + std::make_pair(fC->getFileId(), firstUncoveredLine)); } - fileCoverageMap.insert(std::make_pair(fC->getFileName(), coverage)); + fileCoverageMap.emplace(fC->getFileId(), coverage); } float overallCoverage = 0.0f; if (overallLineNb == 0) @@ -510,7 +513,8 @@ float UhdmChecker::reportCoverage(const fs::path& reportFile) { return overallCoverage; } -void UhdmChecker::annotate(CompileDesign* m_compileDesign) { +void UhdmChecker::annotate() { + FileSystem* const fileSystem = FileSystem::getInstance(); Serializer& s = m_compileDesign->getSerializer(); const auto& objects = s.AllObjects(); for (const auto& obj : objects) { @@ -521,8 +525,9 @@ void UhdmChecker::annotate(CompileDesign* m_compileDesign) { if ((ot == uhdmunsupported_expr) || (ot == uhdmunsupported_stmt) || (ot == uhdmunsupported_typespec)) unsupported = true; - const fs::path& fn = bc->VpiFile(); - const auto& fItr = fileMap.find(fn); + PathId fnId = fileSystem->toPathId( + bc->VpiFile(), m_compileDesign->getCompiler()->getSymbolTable()); + const auto& fItr = fileMap.find(fnId); if (fItr != fileMap.end()) { const FileContent* fC = (*fItr).second; FileNodeCoverMap::iterator fileItr = fileNodeCoverMap.find(fC); @@ -612,7 +617,8 @@ void collectUsedFileContents(std::set& files, } } -bool UhdmChecker::check(const std::string& reportFile) { +bool UhdmChecker::check(PathId reportFileId) { + FileSystem* const fileSystem = FileSystem::getInstance(); // Register all objects location in file content CommandLineParser* clp = m_compileDesign->getCompiler()->getCommandLineParser(); @@ -629,25 +635,25 @@ bool UhdmChecker::check(const std::string& reportFile) { } for (const FileContent* fC : files) { - const fs::path fileName = fC->getFileName(); + const fs::path fileName = fileSystem->toPath(fC->getFileId()); if (!clp->createCache()) { if ((fileName.filename().compare("uvm_pkg.sv") == 0) || (fileName.filename().compare("ovm_pkg.sv") == 0)) { continue; } } - fileMap.insert(std::make_pair(fileName, fC)); + fileMap.emplace(fC->getFileId(), fC); registerFile(fC, moduleNames); } // Annotate UHDM object coverage - annotate(m_compileDesign); + annotate(); mergeColumnCoverage(); // Report uncovered objects - float overallCoverage = reportCoverage(reportFile); - reportHtml(m_compileDesign, reportFile, overallCoverage); + float overallCoverage = reportCoverage(reportFileId); + reportHtml(reportFileId, overallCoverage); return true; } diff --git a/src/DesignCompile/UhdmWriter.cpp b/src/DesignCompile/UhdmWriter.cpp index f76d55a461..1374c82368 100644 --- a/src/DesignCompile/UhdmWriter.cpp +++ b/src/DesignCompile/UhdmWriter.cpp @@ -22,6 +22,7 @@ */ #include +#include #include #include #include @@ -1622,6 +1623,7 @@ bool UhdmWriter::writeElabProgram(Serializer& s, ModuleInstance* instance, bool UhdmWriter::writeElabGenScope(Serializer& s, ModuleInstance* instance, gen_scope* m, ExprBuilder& exprBuilder) { + FileSystem* const fileSystem = FileSystem::getInstance(); Netlist* netlist = instance->getNetlist(); ComponentMap componentMap; ModuleDefinition* mod = @@ -1691,7 +1693,7 @@ bool UhdmWriter::writeElabGenScope(Serializer& s, ModuleInstance* instance, parameter* p = s.MakeParameter(); p->VpiName(name); if (val && val->isValid()) p->VpiValue(val->uhdmValue()); - p->VpiFile(instance->getFileName()); + p->VpiFile(fileSystem->toPath(instance->getFileId()).string()); p->VpiLineNo(param.second.second); p->VpiParent(m); p->VpiLocalParam(true); @@ -1791,6 +1793,7 @@ bool UhdmWriter::writeElabGenScope(Serializer& s, ModuleInstance* instance, void UhdmWriter::lateTypedefBinding(UHDM::Serializer& s, DesignComponent* mod, scope* m, ComponentMap& componentMap) { + FileSystem* const fileSystem = FileSystem::getInstance(); for (UHDM::any* var : mod->getLateTypedefBinding()) { const typespec* orig = nullptr; if (expr* ex = any_cast(var)) { @@ -2193,20 +2196,26 @@ void UhdmWriter::lateTypedefBinding(UHDM::Serializer& s, DesignComponent* mod, if (for_stmt->Variables()) { for (auto var : *for_stmt->Variables()) { if (var->UhdmType() == uhdmhier_path) { + PathId parentFileId = fileSystem->toPathId( + parent->VpiFile(), + m_compileDesign->getCompiler()->getSymbolTable()); bool invalidValue = false; indexTypespec = (typespec*)m_helper.decodeHierPath( (hier_path*)var, invalidValue, mod, - m_compileDesign, nullptr, parent->VpiFile(), + m_compileDesign, nullptr, parentFileId, parent->VpiLineNo(), (any*)parent, true, true /*mute for now*/, true); } } } else if (const variables* var = for_stmt->Variable()) { if (var->UhdmType() == uhdmhier_path) { + PathId parentFileId = fileSystem->toPathId( + parent->VpiFile(), + m_compileDesign->getCompiler()->getSymbolTable()); bool invalidValue = false; indexTypespec = (typespec*)m_helper.decodeHierPath( (hier_path*)var, invalidValue, mod, m_compileDesign, - nullptr, parent->VpiFile(), parent->VpiLineNo(), + nullptr, parentFileId, parent->VpiLineNo(), (any*)parent, true, true /*mute for now*/, true); } else if (var->UhdmType() == uhdmref_var) { bool invalidValue = false; @@ -2217,10 +2226,13 @@ void UhdmWriter::lateTypedefBinding(UHDM::Serializer& s, DesignComponent* mod, elems->push_back(ref); ref->VpiName(var->VpiName()); path->VpiFullName(var->VpiName()); + PathId parentFileId = fileSystem->toPathId( + parent->VpiFile(), + m_compileDesign->getCompiler()->getSymbolTable()); indexTypespec = (typespec*)m_helper.decodeHierPath( path, invalidValue, mod, m_compileDesign, nullptr, - parent->VpiFile(), parent->VpiLineNo(), - (any*)parent, true, true /*mute for now*/, true); + parentFileId, parent->VpiLineNo(), (any*)parent, + true, true /*mute for now*/, true); } } variables* swapVar = nullptr; @@ -2250,7 +2262,7 @@ void UhdmWriter::lateTypedefBinding(UHDM::Serializer& s, DesignComponent* mod, } } - if ((name == "") && (found == false)) { + if (name.empty() && (found == false)) { // Port .op({\op[1] ,\op[0] }) if (operation* op = any_cast(var)) { const typespec* baseTypespec = nullptr; @@ -2305,6 +2317,7 @@ void UhdmWriter::lateTypedefBinding(UHDM::Serializer& s, DesignComponent* mod, void UhdmWriter::lateBinding(UHDM::Serializer& s, DesignComponent* mod, scope* m, ComponentMap& componentMap) { + FileSystem* const fileSystem = FileSystem::getInstance(); for (UHDM::ref_obj* ref : mod->getLateBinding()) { if (ref->Actual_group()) continue; std::string name = ref->VpiName(); @@ -2800,9 +2813,9 @@ void UhdmWriter::lateBinding(UHDM::Serializer& s, DesignComponent* mod, if (mod) { if (auto elem = mod->getDesignElement()) { if (elem->m_defaultNetType == slNoType) { - Location loc(m_compileDesign->getCompiler() - ->getSymbolTable() - ->registerSymbol(ref->VpiFile().string()), + Location loc(fileSystem->toPathId( + ref->VpiFile(), + m_compileDesign->getCompiler()->getSymbolTable()), ref->VpiLineNo(), ref->VpiColumnNo(), m_compileDesign->getCompiler() ->getSymbolTable() @@ -3217,6 +3230,7 @@ void UhdmWriter::writeInstance(ModuleDefinition* mod, ModuleInstance* instance, UhdmWriter::ModPortMap& modPortMap, UhdmWriter::InstanceMap& instanceMap, ExprBuilder& exprBuilder) { + FileSystem* const fileSystem = FileSystem::getInstance(); Serializer& s = compileDesign->getSerializer(); VectorOfmodule* subModules = nullptr; VectorOfprogram* subPrograms = nullptr; @@ -3287,14 +3301,14 @@ void UhdmWriter::writeInstance(ModuleDefinition* mod, ModuleInstance* instance, tempInstanceMap.emplace(child, sm); if (childDef && !childDef->getFileContents().empty() && compileDesign->getCompiler()->isLibraryFile( - childDef->getFileContents()[0]->getSymbolId())) { + childDef->getFileContents()[0]->getFileId())) { sm->VpiCellInstance(true); } sm->VpiName(child->getInstanceName()); sm->VpiDefName(child->getModuleName()); sm->VpiFullName(child->getFullPathName()); const FileContent* defFile = mm->getFileContents()[0]; - sm->VpiDefFile(defFile->getFileName()); + sm->VpiDefFile(fileSystem->toPath(defFile->getFileId()).string()); sm->VpiDefLineNo(defFile->Line(mm->getNodeIds()[0])); child->getFileContent()->populateCoreMembers(child->getNodeId(), child->getNodeId(), sm); @@ -3366,7 +3380,7 @@ void UhdmWriter::writeInstance(ModuleDefinition* mod, ModuleInstance* instance, child->getFileContent()->populateCoreMembers(child->getNodeId(), child->getNodeId(), sm); const FileContent* defFile = mm->getFileContents()[0]; - sm->VpiDefFile(defFile->getFileName()); + sm->VpiDefFile(fileSystem->toPath(defFile->getFileId()).string()); sm->VpiDefLineNo(defFile->Line(mm->getNodeIds()[0])); subInterfaces->push_back(sm); UHDM_OBJECT_TYPE utype = m->UhdmType(); @@ -3490,7 +3504,7 @@ void UhdmWriter::writeInstance(ModuleDefinition* mod, ModuleInstance* instance, child->getFileContent()->populateCoreMembers(child->getNodeId(), child->getNodeId(), sm); const FileContent* defFile = prog->getFileContents()[0]; - sm->VpiDefFile(defFile->getFileName()); + sm->VpiDefFile(fileSystem->toPath(defFile->getFileId()).string()); sm->VpiDefLineNo(defFile->Line(prog->getNodeIds()[0])); subPrograms->push_back(sm); UHDM_OBJECT_TYPE utype = m->UhdmType(); @@ -3550,7 +3564,9 @@ void UhdmWriter::writeInstance(ModuleDefinition* mod, ModuleInstance* instance, } } -vpiHandle UhdmWriter::write(const std::string& uhdmFile) { +vpiHandle UhdmWriter::write(PathId uhdmFileId) { + FileSystem* const fileSystem = FileSystem::getInstance(); + const std::filesystem::path uhdmFile = fileSystem->toPath(uhdmFileId); ComponentMap componentMap; ModPortMap modPortMap; InstanceMap instanceMap; @@ -3560,8 +3576,7 @@ vpiHandle UhdmWriter::write(const std::string& uhdmFile) { m_compileDesign->getCompiler()->getErrorContainer(), m_compileDesign->getCompiler()->getSymbolTable()); - Location loc(m_compileDesign->getCompiler()->getSymbolTable()->registerSymbol( - uhdmFile)); + Location loc((SymbolId)uhdmFileId); Error err(ErrorDefinition::UHDM_CREATING_MODEL, loc); m_compileDesign->getCompiler()->getErrorContainer()->addError(err); m_compileDesign->getCompiler()->getErrorContainer()->printMessages( @@ -3595,8 +3610,8 @@ vpiHandle UhdmWriter::write(const std::string& uhdmFile) { (ifi.m_action == IncludeFileInfo::Action::PUSH)) { const FileContent* const fC = pf->getFileContent(); include_file_info* const pifi = s.MakeInclude_file_info(); - pifi->VpiFile(fC->getSymbolTable()->getSymbol(pf->getRawFileId())); - pifi->VpiIncludedFile(pf->getSymbol(ifi.m_sectionFile)); + pifi->VpiFile(fileSystem->toPath(pf->getRawFileId()).string()); + pifi->VpiIncludedFile(fileSystem->toPath(ifi.m_sectionFile).string()); pifi->VpiLineNo(ifi.m_originalStartLine); pifi->VpiColumnNo(ifi.m_originalStartColumn); pifi->VpiEndLineNo(ifi.m_originalEndLine); @@ -3771,7 +3786,7 @@ vpiHandle UhdmWriter::write(const std::string& uhdmFile) { const FileContent* fC = mod->getFileContents()[0]; module* m = s.MakeModule(); if (m_compileDesign->getCompiler()->isLibraryFile( - mod->getFileContents()[0]->getSymbolId())) { + mod->getFileContents()[0]->getFileId())) { m->VpiCellInstance(true); } componentMap.insert(std::make_pair(mod, m)); @@ -3899,26 +3914,27 @@ vpiHandle UhdmWriter::write(const std::string& uhdmFile) { // Check before restore Location loc( m_compileDesign->getCompiler()->getSymbolTable()->registerSymbol( - std::string(uhdmFile) + ".chk.html")); + uhdmFile.string() + ".chk.html")); Error err(ErrorDefinition::UHDM_WRITE_HTML_COVERAGE, loc); m_compileDesign->getCompiler()->getErrorContainer()->addError(err); m_compileDesign->getCompiler()->getErrorContainer()->printMessages( m_compileDesign->getCompiler()->getCommandLineParser()->muteStdout()); UhdmChecker* uhdmchecker = new UhdmChecker(m_compileDesign, m_design); - uhdmchecker->check(std::string(uhdmFile) + ".chk"); + std::filesystem::path chkFile = uhdmFile; + uhdmchecker->check(fileSystem->toPathId( + chkFile += ".chk", m_compileDesign->getCompiler()->getSymbolTable())); delete uhdmchecker; } if (m_compileDesign->getCompiler()->getCommandLineParser()->getDebugUhdm()) { if (m_compileDesign->getCompiler()->getCommandLineParser()->writeUhdm()) { - Location loc( - m_compileDesign->getCompiler()->getSymbolTable()->registerSymbol( - uhdmFile)); + Location loc((SymbolId)uhdmFileId); Error err1(ErrorDefinition::UHDM_LOAD_DB, loc); m_compileDesign->getCompiler()->getErrorContainer()->addError(err1); m_compileDesign->getCompiler()->getErrorContainer()->printMessages( m_compileDesign->getCompiler()->getCommandLineParser()->muteStdout()); - const std::vector& restoredDesigns = s.Restore(uhdmFile); + const std::vector& restoredDesigns = + s.Restore(uhdmFile.string()); Error err2(ErrorDefinition::UHDM_VISITOR, loc); m_compileDesign->getCompiler()->getErrorContainer()->addError(err2); diff --git a/src/ErrorReporting/ErrorContainer.cpp b/src/ErrorReporting/ErrorContainer.cpp index 87619826dd..40ffcfacfc 100644 --- a/src/ErrorReporting/ErrorContainer.cpp +++ b/src/ErrorReporting/ErrorContainer.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -61,8 +62,8 @@ ErrorContainer::~ErrorContainer() { void ErrorContainer::init() { if (ErrorDefinition::init()) { - const fs::path logFileName = - m_clp->getSymbolTable().getSymbol(m_clp->getLogFileId()); + FileSystem* const fileSystem = FileSystem::getInstance(); + const fs::path logFileName = fileSystem->toPath(m_clp->getLogFileId()); if (LogListener::failed(m_logListener->initialize(logFileName.string()))) { std::cerr << "[FTL:LG0001] Cannot create log file \"" << logFileName << "\"" << std::endl; @@ -77,6 +78,7 @@ Error& ErrorContainer::addError(Error& error, bool showDuplicates, if (std::get<2>(textStatus)) // filter Message return error; + FileSystem* const fileSystem = FileSystem::getInstance(); std::multimap& waivers = Waiver::getWaivers(); std::pair< @@ -87,7 +89,7 @@ Error& ErrorContainer::addError(Error& error, bool showDuplicates, it = ret.first; it != ret.second; ++it) { if ((((*it).second.m_fileName.empty()) || - (m_symbolTable->getSymbol(error.m_locations[0].m_fileId) == + (fileSystem->toPath(error.m_locations[0].m_fileId) == (*it).second.m_fileName)) && (((*it).second.m_line == 0) || (error.m_locations[0].m_line == (*it).second.m_line)) && @@ -99,6 +101,13 @@ Error& ErrorContainer::addError(Error& error, bool showDuplicates, } } + // Copy the PathId into our local SymbolTable! + for (Location& loc : error.m_locations) { + if (loc.m_fileId) { + loc.m_fileId = fileSystem->copy(loc.m_fileId, m_symbolTable); + } + } + if (showDuplicates) { m_errors.emplace_back(error); } else { @@ -107,28 +116,31 @@ Error& ErrorContainer::addError(Error& error, bool showDuplicates, m_errorSet.insert(std::get<0>(textStatus)); } } - return m_errors[m_errors.size() - 1]; + return m_errors.back(); } void ErrorContainer::appendErrors(ErrorContainer& rhs) { + FileSystem* const fileSystem = FileSystem::getInstance(); for (unsigned int i = 0; i < rhs.m_errors.size(); i++) { Error err = rhs.m_errors[i]; - // Translate IDs to master symbol table - for (auto& loc : err.m_locations) { - if (loc.m_fileId) - loc.m_fileId = m_symbolTable->registerSymbol( - rhs.m_symbolTable->getSymbol(loc.m_fileId)); - if (loc.m_object) { - loc.m_object = m_symbolTable->registerSymbol( - rhs.m_symbolTable->getSymbol(loc.m_object)); + if (!err.m_reported) { + // Translate IDs to master symbol table + for (auto& loc : err.m_locations) { + if (loc.m_fileId) + loc.m_fileId = fileSystem->copy(loc.m_fileId, m_symbolTable); + if (loc.m_object) { + loc.m_object = m_symbolTable->registerSymbol( + rhs.m_symbolTable->getSymbol(loc.m_object)); + } } + addError(err); } - if (!err.m_reported) addError(err); } } std::tuple ErrorContainer::createErrorMessage( const Error& msg, bool reentrantPython) const { + FileSystem* const fileSystem = FileSystem::getInstance(); const std::map& infoMap = ErrorDefinition::getErrorInfoMap(); std::string tmp; @@ -184,7 +196,7 @@ std::tuple ErrorContainer::createErrorMessage( /* Location */ std::string location; if (loc.m_fileId) { - location = m_symbolTable->getSymbol(loc.m_fileId); + location = fileSystem->toPath(loc.m_fileId).string(); if (loc.m_line > 0) { location += ":" + std::to_string(loc.m_line) + ":"; if (loc.m_column > 0) location += std::to_string(loc.m_column) + ":"; @@ -199,7 +211,7 @@ std::tuple ErrorContainer::createErrorMessage( const Location& extraLoc = msg.m_locations[i]; if (extraLoc.m_fileId) { std::string extraLocation = - m_symbolTable->getSymbol(extraLoc.m_fileId); + fileSystem->toPath(extraLoc.m_fileId).string(); if (extraLoc.m_line > 0) { extraLocation += ":" + std::to_string(extraLoc.m_line) + ":"; if (extraLoc.m_column > 0) diff --git a/src/ErrorReporting/Location.cpp b/src/ErrorReporting/Location.cpp index be86fb752b..1897041f21 100644 --- a/src/ErrorReporting/Location.cpp +++ b/src/ErrorReporting/Location.cpp @@ -25,7 +25,7 @@ namespace SURELOG { -bool Location::operator==(const Location& rhs) const { +bool Location::operator==(const Location &rhs) const { if (m_fileId != rhs.m_fileId) return false; if (m_line != rhs.m_line) return false; if (m_column != rhs.m_column) return false; @@ -33,13 +33,22 @@ bool Location::operator==(const Location& rhs) const { return true; } -bool Location::operator<(const Location& rhs) const { - static SymbolIdLessThanComparer comparer; - if (comparer(m_fileId, rhs.m_fileId)) return true; +bool Location::operator<(const Location &rhs) const { + static PathIdLessThanComparer pathIdComparer; + static SymbolIdLessThanComparer symbolIdComparer; + if (pathIdComparer(m_fileId, rhs.m_fileId)) return true; if (m_line < rhs.m_line) return true; if (m_column < rhs.m_column) return true; - if (comparer(m_object, rhs.m_object)) return true; + if (symbolIdComparer(m_object, rhs.m_object)) return true; return false; } +std::ostream &operator<<(std::ostream &strm, const Location &location) { + strm << "file-id=" << location.m_fileId << ", " + << "line=" << location.m_line << ", " + << "column=" << location.m_column << ", " + << "object=" << location.m_object; + return strm; +} + } // namespace SURELOG diff --git a/src/ErrorReporting/Report.cpp b/src/ErrorReporting/Report.cpp index 47b53cbd63..917a88751c 100644 --- a/src/ErrorReporting/Report.cpp +++ b/src/ErrorReporting/Report.cpp @@ -22,6 +22,7 @@ */ #include +#include #include #include @@ -91,9 +92,10 @@ std::pair Report::makeDiffCompUnitReport(CommandLineParser* clp, SymbolTable* st) { // std::mutex m; // m.lock(); - fs::path odir = st->getSymbol(clp->getOutputDir()); - fs::path alldir = st->getSymbol(clp->getCompileAllDir()); - fs::path unitdir = st->getSymbol(clp->getCompileUnitDir()); + FileSystem* const fileSystem = FileSystem::getInstance(); + fs::path odir = fileSystem->toPath(clp->getOutputDirId()); + fs::path alldir = fileSystem->toPath(clp->getCompileAllDirId()); + fs::path unitdir = fileSystem->toPath(clp->getCompileUnitDirId()); fs::path log = st->getSymbol(clp->getDefaultLogFileId()); fs::path alllog = odir / alldir / log; fs::path unitlog = odir / unitdir / log; diff --git a/src/Library/Library.cpp b/src/Library/Library.cpp index ebdf2be789..ec97317f9f 100644 --- a/src/Library/Library.cpp +++ b/src/Library/Library.cpp @@ -21,6 +21,7 @@ * Created on January 27, 2018, 5:25 PM */ +#include #include #include #include @@ -42,10 +43,11 @@ ModuleDefinition* Library::getModule(const std::string& name) const { } std::string Library::report(SymbolTable* symbols) const { + FileSystem* const fileSystem = FileSystem::getInstance(); std::string report; report = "LIB: " + m_name + "\n"; - for (const auto& id : m_fileIds) { - report += " " + symbols->getSymbol(id) + "\n"; + for (auto id : m_fileIds) { + report += " " + fileSystem->toPath(id).string() + "\n"; } return report; } diff --git a/src/Library/LibrarySet.cpp b/src/Library/LibrarySet.cpp index 8bfa5ddd0f..a44f38a424 100644 --- a/src/Library/LibrarySet.cpp +++ b/src/Library/LibrarySet.cpp @@ -39,7 +39,7 @@ Library* LibrarySet::getLibrary(std::string_view libName) { return nullptr; } -Library* LibrarySet::getLibrary(SymbolId fileId) { +Library* LibrarySet::getLibrary(PathId fileId) { Library* lib = nullptr; for (auto& library : m_libraries) { if (library.isMember(fileId)) { @@ -64,15 +64,15 @@ std::string LibrarySet::report(SymbolTable* symbols) const { void LibrarySet::checkErrors(SymbolTable* symbols, ErrorContainer* errors) const { - std::map fileSet; + std::map fileSet; for (const auto& library : m_libraries) { for (const auto& file : library.getFiles()) { - std::map::iterator itr = fileSet.find(file); + auto itr = fileSet.find(file); if (itr == fileSet.end()) { fileSet.insert(std::make_pair(file, library.getName())); } else { Location loc1( - symbols->registerSymbol((*itr).second + ", " + library.getName())); + symbols->registerSymbol(itr->second + ", " + library.getName())); Location loc2(file); Error err(ErrorDefinition::LIB_FILE_MAPS_TO_MULTIPLE_LIBS, loc1, loc2); errors->addError(err); diff --git a/src/Library/ParseLibraryDef.cpp b/src/Library/ParseLibraryDef.cpp index 2b7224f1a4..802d08d0f7 100644 --- a/src/Library/ParseLibraryDef.cpp +++ b/src/Library/ParseLibraryDef.cpp @@ -22,6 +22,7 @@ */ #include +#include #include #include #include @@ -48,8 +49,7 @@ ParseLibraryDef::ParseLibraryDef(CommandLineParser* commandLineParser, ErrorContainer* errors, SymbolTable* symbolTable, LibrarySet* librarySet, ConfigSet* configSet) - : m_fileId(BadSymbolId), - m_commandLineParser(commandLineParser), + : m_commandLineParser(commandLineParser), m_errors(errors), m_symbolTable(symbolTable), m_librarySet(librarySet), @@ -57,8 +57,9 @@ ParseLibraryDef::ParseLibraryDef(CommandLineParser* commandLineParser, m_fileContent(nullptr) {} bool ParseLibraryDef::parseLibrariesDefinition() { + FileSystem* const fileSystem = FileSystem::getInstance(); // Get .map files from command line - std::vector libraryMapFiles = + std::vector libraryMapFiles = m_commandLineParser->getLibraryMapFiles(); if (libraryMapFiles.empty()) { // or scan local dir @@ -73,27 +74,27 @@ bool ParseLibraryDef::parseLibrariesDefinition() { } // Config files are parsed using the library top rule - std::vector cfgFiles = m_commandLineParser->getConfigFiles(); - for (const auto& file : cfgFiles) { - libraryMapFiles.push_back(file); - } + const std::vector& cfgFiles = m_commandLineParser->getConfigFiles(); + libraryMapFiles.insert(libraryMapFiles.end(), cfgFiles.begin(), + cfgFiles.end()); for (const auto& fileId : libraryMapFiles) { parseLibraryDefinition(fileId); } - for (const auto& file : cfgFiles) { - fs::path fullPath = FileUtils::getFullPath(m_symbolTable->getSymbol(file)); - m_librarySet->getLibrary(m_symbolTable->registerSymbol( - fullPath.string())); // Register configuration files in "work" library + for (auto file : cfgFiles) { + fs::path fullPath = FileUtils::getFullPath(fileSystem->toPath(file)); + m_librarySet->getLibrary(fileSystem->toPathId( + fullPath, + m_symbolTable)); // Register configuration files in "work" library } unsigned int size = m_commandLineParser->getSourceFiles().size(); for (unsigned int i = 0; i < size; i++) { - SymbolId id = m_commandLineParser->getSourceFiles()[i]; - fs::path fullPath = FileUtils::getFullPath(m_symbolTable->getSymbol(id)); - m_librarySet->getLibrary(m_symbolTable->registerSymbol( - fullPath.string())); // Register files in "work" library + PathId id = m_commandLineParser->getSourceFiles()[i]; + fs::path fullPath = FileUtils::getFullPath(fileSystem->toPath(id)); + m_librarySet->getLibrary(fileSystem->toPathId( + fullPath, m_symbolTable)); // Register files in "work" library } m_librarySet->checkErrors(m_symbolTable, m_errors); @@ -104,10 +105,10 @@ bool ParseLibraryDef::parseLibrariesDefinition() { return true; } -bool ParseLibraryDef::parseLibraryDefinition(SymbolId fileId, Library* lib) { +bool ParseLibraryDef::parseLibraryDefinition(PathId fileId, Library* lib) { + FileSystem* const fileSystem = FileSystem::getInstance(); m_fileId = fileId; - const fs::path fileName = m_symbolTable->getSymbol(fileId); - const fs::path relativePath = FileUtils::getPathName(fileName); + const fs::path fileName = fileSystem->toPath(fileId); std::ifstream stream; stream.open(fileName); @@ -136,8 +137,7 @@ bool ParseLibraryDef::parseLibraryDefinition(SymbolId fileId, Library* lib) { m_parser->addErrorListener(errorListener); antlr4::tree::ParseTree* m_tree = m_parser->top_level_library_rule(); - SVLibShapeListener* m_listener = - new SVLibShapeListener(this, m_tokens, relativePath); + SVLibShapeListener* m_listener = new SVLibShapeListener(this, m_tokens); m_fileContent = m_listener->getFileContent(); tree::ParseTreeWalker::DEFAULT.walk(m_listener, m_tree); @@ -146,10 +146,9 @@ bool ParseLibraryDef::parseLibraryDefinition(SymbolId fileId, Library* lib) { if (lib) { m_fileContent->setLibrary(lib); } else { - fs::path fullPath = - FileUtils::getFullPath(m_symbolTable->getSymbol(m_fileId)); + fs::path fullPath = FileUtils::getFullPath(fileSystem->toPath(m_fileId)); m_fileContent->setLibrary(m_librarySet->getLibrary( - m_symbolTable->registerSymbol(fullPath.string()))); + fileSystem->toPathId(fullPath, m_symbolTable))); } } diff --git a/src/Library/SVLibShapeListener.cpp b/src/Library/SVLibShapeListener.cpp index 1916b2e260..279bcee8c4 100644 --- a/src/Library/SVLibShapeListener.cpp +++ b/src/Library/SVLibShapeListener.cpp @@ -21,6 +21,7 @@ * Created on January 28, 2018, 10:17 PM */ +#include #include #include #include @@ -39,32 +40,29 @@ namespace SURELOG { namespace fs = std::filesystem; SVLibShapeListener::SVLibShapeListener(ParseLibraryDef *parser, - antlr4::CommonTokenStream *tokens, - const fs::path &relativePath) + antlr4::CommonTokenStream *tokens) : SV3_1aTreeShapeHelper( new ParseFile(parser->getFileId(), parser->getSymbolTable(), parser->getErrorContainer()), tokens, 0), m_parser(parser), - m_tokens(tokens), - m_relativePath(relativePath) { + m_tokens(tokens) { m_fileContent = new FileContent( m_parser->getFileId(), nullptr, m_parser->getSymbolTable(), - m_parser->getErrorContainer(), nullptr, BadSymbolId); + m_parser->getErrorContainer(), nullptr, BadPathId); m_pf->setFileContent(m_fileContent); m_includeFileInfo.emplace(IncludeFileInfo::Context::NONE, 1, m_pf->getFileId(0), 0, 0, 0, 0, IncludeFileInfo::Action::PUSH); } -SVLibShapeListener::~SVLibShapeListener() {} - SymbolId SVLibShapeListener::registerSymbol(std::string_view symbol) { return m_parser->getSymbolTable()->registerSymbol(symbol); } void SVLibShapeListener::enterLibrary_declaration( SV3_1aParser::Library_declarationContext *ctx) { + FileSystem *const fileSystem = FileSystem::getInstance(); std::string name = ctx->identifier()->getText(); Library *lib = m_parser->getLibrarySet()->getLibrary(name); if (lib == nullptr) { @@ -73,20 +71,21 @@ void SVLibShapeListener::enterLibrary_declaration( } lib = m_parser->getLibrarySet()->getLibrary(name); + SymbolTable *symbolTable = m_parser->getSymbolTable(); + const PathId fileId = m_parser->getFileId(); + const fs::path filepath = fileSystem->toPath(fileId); + const fs::path dirpath = FileUtils::getPathName(filepath); for (auto pathSpec : ctx->file_path_spec()) { for (const auto &id : - FileUtils::collectFiles(m_relativePath / pathSpec->getText(), - m_parser->getSymbolTable())) { + FileUtils::collectFiles(dirpath / pathSpec->getText(), symbolTable)) { lib->addFileId(id); - fs::path fileName = m_parser->getSymbolTable()->getSymbol(id); + fs::path fileName = fileSystem->toPath(id); if ((fileName.extension() == ".cfg") || (fileName.extension() == ".map")) { ParseLibraryDef parser( m_parser->getCommandLineParser(), m_parser->getErrorContainer(), - m_parser->getSymbolTable(), m_parser->getLibrarySet(), - m_parser->getConfigSet()); - parser.parseLibraryDefinition( - m_parser->getSymbolTable()->registerSymbol(fileName.string()), lib); + symbolTable, m_parser->getLibrarySet(), m_parser->getConfigSet()); + parser.parseLibraryDefinition(id, lib); } } } @@ -94,6 +93,7 @@ void SVLibShapeListener::enterLibrary_declaration( void SVLibShapeListener::enterInclude_statement( SV3_1aParser::Include_statementContext *ctx) { + FileSystem *const fileSystem = FileSystem::getInstance(); fs::path filePath = ctx->file_path_spec()->getText(); std::pair lineCol = ParseUtils::getLineColumn(m_tokens, ctx); @@ -110,7 +110,7 @@ void SVLibShapeListener::enterInclude_statement( m_parser->getSymbolTable(), m_parser->getLibrarySet(), m_parser->getConfigSet()); parser.parseLibraryDefinition( - m_parser->getSymbolTable()->registerSymbol(filePath.string())); + fileSystem->toPathId(filePath, m_parser->getSymbolTable())); } void SVLibShapeListener::enterUselib_directive( diff --git a/src/Package/Precompiled.cpp b/src/Package/Precompiled.cpp index c061a73222..fbe97c4311 100644 --- a/src/Package/Precompiled.cpp +++ b/src/Package/Precompiled.cpp @@ -21,40 +21,46 @@ * Created on April 28, 2018, 10:27 AM */ +#include +#include #include +#include +#include namespace SURELOG { +Precompiled* Precompiled::getSingleton() { + static Precompiled* const singleton = new Precompiled(); + return singleton; +} Precompiled::Precompiled() { addPrecompiled("uvm_pkg", "uvm_pkg.sv"); addPrecompiled("ovm_pkg", "ovm_pkg.sv"); } -Precompiled* Precompiled::getSingleton() { - static Precompiled* const singleton = new Precompiled(); - return singleton; -} - -void Precompiled::addPrecompiled(const std::string& packageName, - const std::string& fileName) { - m_packageMap.insert({packageName, fileName}); - m_packageFileSet.insert(fileName); +void Precompiled::addPrecompiled(std::string_view packageName, + std::string_view fileName) { + m_packageMap.emplace(packageName, fileName); + m_packageFileSet.emplace(fileName); } -std::string Precompiled::getFileName(const std::string& packageName) const { +std::string Precompiled::getFileName(std::string_view packageName) const { auto found = m_packageMap.find(packageName); return (found == m_packageMap.end()) ? "" : found->second; } -bool Precompiled::isFilePrecompiled( - const std::filesystem::path& fileName) const { - auto found = m_packageFileSet.find(fileName); - return (found != m_packageFileSet.end()); +bool Precompiled::isFilePrecompiled(std::string_view fileName) const { + return (m_packageFileSet.find(fileName) != m_packageFileSet.end()); } -bool Precompiled::isPackagePrecompiled(const std::string& packageName) const { - auto found = m_packageMap.find(packageName); - return (found != m_packageMap.end()); +bool Precompiled::isFilePrecompiled(PathId fileId) const { + std::filesystem::path filePath = FileSystem::getInstance()->toPath(fileId); + std::filesystem::path fileName = FileUtils::basename(filePath); + return (m_packageFileSet.find(fileName) != m_packageFileSet.end()); +} + +bool Precompiled::isPackagePrecompiled(std::string_view packageName) const { + return (m_packageMap.find(packageName) != m_packageMap.end()); } } // namespace SURELOG diff --git a/src/SourceCompile/AnalyzeFile.cpp b/src/SourceCompile/AnalyzeFile.cpp index 39c70bce38..11000d464c 100644 --- a/src/SourceCompile/AnalyzeFile.cpp +++ b/src/SourceCompile/AnalyzeFile.cpp @@ -22,6 +22,7 @@ */ #include +#include #include #include #include @@ -59,13 +60,14 @@ void AnalyzeFile::checkSLlineDirective_(const std::string& line, std::string keyword; ss >> keyword; if (keyword == "SLline") { - IncludeFileInfo info(IncludeFileInfo::Context::NONE, 0, BadSymbolId, 0, 0, - 0, 0, IncludeFileInfo::Action::NONE); + IncludeFileInfo info(IncludeFileInfo::Context::NONE, 0, BadPathId, 0, 0, 0, + 0, IncludeFileInfo::Action::NONE); ss >> info.m_sectionStartLine; std::string file; ss >> file; file = StringUtils::unquoted(file); - info.m_sectionFile = m_clp->mutableSymbolTable()->registerSymbol(file); + info.m_sectionFile = + FileSystem::getInstance()->toPathId(file, m_clp->getSymbolTable()); unsigned int action = 0; ss >> action; @@ -92,15 +94,15 @@ void AnalyzeFile::checkSLlineDirective_(const std::string& line, std::string AnalyzeFile::setSLlineDirective_(unsigned int lineNb, unsigned int& origFromLine, - fs::path& origFile) { + PathId& origFileId) { std::ostringstream result; if (!m_includeFileInfo.empty()) { - origFile = m_clp->mutableSymbolTable()->getSymbol( + origFileId = m_includeFileInfo.top().m_sectionFile; + fs::path origFile = FileSystem::getInstance()->toPath( m_includeFileInfo.top().m_sectionFile); const IncludeFileInfo& info = m_includeFileInfo.top(); origFromLine = lineNb - info.m_originalStartLine + info.m_sectionStartLine; - result << "SLline " << origFromLine << " \"" << origFile.string() << "\" " - << 1 << "\n"; + result << "SLline " << origFromLine << " " << origFile << " 1" << std::endl; } else { result << ""; // BUG or intentional ? } @@ -108,12 +110,16 @@ std::string AnalyzeFile::setSLlineDirective_(unsigned int lineNb, } void AnalyzeFile::analyze() { + FileSystem* const fileSystem = FileSystem::getInstance(); + SymbolTable* const symbolTable = m_clp->getSymbolTable(); + ErrorContainer* const errors = m_clp->getErrorContainer(); std::string line; std::vector allLines; allLines.emplace_back("FILLER LINE"); if (m_text.empty()) { + fs::path ppFileName = fileSystem->toPath(m_ppFileId); std::ifstream ifs; - ifs.open(m_ppFileName); + ifs.open(ppFileName); if (!ifs.good()) { return; } @@ -383,19 +389,9 @@ void AnalyzeFile::analyze() { unsigned int lineSize = lineNb; - if (m_clp->getNbMaxProcesses()) { - m_splitFiles.emplace_back(m_ppFileName); - m_lineOffsets.push_back(0); - return; - } - - if (lineSize < minNbLineForPartitioning) { - m_splitFiles.emplace_back(m_ppFileName); - m_lineOffsets.push_back(0); - return; - } - if (m_nbChunks < 2) { - m_splitFiles.emplace_back(m_ppFileName); + if (m_clp->getNbMaxProcesses() || (lineSize < minNbLineForPartitioning) || + (m_nbChunks < 2)) { + m_splitFiles.emplace_back(m_ppFileId); m_lineOffsets.push_back(0); return; } @@ -403,11 +399,10 @@ void AnalyzeFile::analyze() { if (inComment || inString) { m_splitFiles.clear(); m_lineOffsets.clear(); - Location loc( - m_clp->mutableSymbolTable()->registerSymbol(m_fileName.string())); + Location loc((SymbolId)m_fileId); Error err(ErrorDefinition::PA_CANNOT_SPLIT_FILE, loc); - m_clp->getErrorContainer()->addError(err); - m_clp->getErrorContainer()->printMessages(); + errors->addError(err); + errors->printMessages(); return; } @@ -418,11 +413,10 @@ void AnalyzeFile::analyze() { unsigned int fromLine = 1; unsigned int toIndex = 0; - m_includeFileInfo.emplace( - IncludeFileInfo::Context::INCLUDE, 1, - m_clp->mutableSymbolTable()->registerSymbol(m_fileName.string()), 1, 0, 1, - 0, IncludeFileInfo::Action::PUSH); + m_includeFileInfo.emplace(IncludeFileInfo::Context::INCLUDE, 1, m_fileId, 1, + 0, 1, 0, IncludeFileInfo::Action::PUSH); unsigned int linesWriten = 0; + PathId origFileId; for (unsigned int i = 0; i < fileChunks.size(); i++) { DesignElement::ElemType chunkType = fileChunks[i].m_chunkType; @@ -446,7 +440,6 @@ void AnalyzeFile::analyze() { bool endPackageDetected = false; std::string sllineInfo; unsigned int origFromLine = 0; - fs::path origFile; // unsigned int baseFromLine = fromLine; while (!endPackageDetected) { std::string content; @@ -488,7 +481,8 @@ void AnalyzeFile::analyze() { // content += "SLline " + std::to_string(fromLine - baseFromLine + // origFromLine + 1) + " \"" + origFile + "\" 1"; } else { - sllineInfo = setSLlineDirective_(fromLine, origFromLine, origFile); + sllineInfo = + setSLlineDirective_(fromLine, origFromLine, origFileId); content = sllineInfo; } @@ -552,22 +546,22 @@ void AnalyzeFile::analyze() { splitted = false; } - fs::path splitFileName = - m_ppFileName.string() + ".ck" + std::to_string(chunkNb); + fs::path splitFileName = fileSystem->toPath(m_ppFileId).string() + + ".ck" + std::to_string(chunkNb); if (chunkNb > 1000) { m_splitFiles.clear(); m_lineOffsets.clear(); - Location loc(m_clp->mutableSymbolTable()->registerSymbol( - m_fileName.string())); + Location loc((SymbolId)m_fileId); Error err(ErrorDefinition::PA_CANNOT_SPLIT_FILE, loc); - m_clp->getErrorContainer()->addError(err); - m_clp->getErrorContainer()->printMessages(); + errors->addError(err); + errors->printMessages(); return; } content += " " + fileLevelImportSection; saveContent(splitFileName, content); - m_splitFiles.emplace_back(splitFileName); + m_splitFiles.emplace_back( + fileSystem->toPathId(splitFileName, symbolTable)); // m_lineOffsets.push_back(fromLine - 1); @@ -594,11 +588,10 @@ void AnalyzeFile::analyze() { (allLines[toLine].find("*/") == std::string::npos)) { m_splitFiles.clear(); m_lineOffsets.clear(); - Location loc( - m_clp->mutableSymbolTable()->registerSymbol(m_fileName.string())); + Location loc((SymbolId)m_fileId); Error err(ErrorDefinition::PA_CANNOT_SPLIT_FILE, loc); - m_clp->getErrorContainer()->addError(err); - m_clp->getErrorContainer()->printMessages(); + errors->addError(err); + errors->printMessages(); return; } @@ -611,7 +604,7 @@ void AnalyzeFile::analyze() { m_lineOffsets.push_back(linesWriten); - content += setSLlineDirective_(fromLine, origFromLine, origFile); + content += setSLlineDirective_(fromLine, origFromLine, origFileId); for (unsigned int l = fromLine; l < toLine; l++) { checkSLlineDirective_(allLines[l], l); content += allLines[l]; @@ -621,21 +614,21 @@ void AnalyzeFile::analyze() { linesWriten++; } - fs::path splitFileName = - m_ppFileName.string() + ".ck" + std::to_string(chunkNb); + fs::path splitFileName = fileSystem->toPath(m_ppFileId).string() + + ".ck" + std::to_string(chunkNb); if (chunkNb > 1000) { m_splitFiles.clear(); m_lineOffsets.clear(); - Location loc( - m_clp->mutableSymbolTable()->registerSymbol(m_fileName.string())); + Location loc((SymbolId)m_fileId); Error err(ErrorDefinition::PA_CANNOT_SPLIT_FILE, loc); - m_clp->getErrorContainer()->addError(err); - m_clp->getErrorContainer()->printMessages(); + errors->addError(err); + errors->printMessages(); return; } saveContent(splitFileName, content); - m_splitFiles.emplace_back(splitFileName); + m_splitFiles.emplace_back( + fileSystem->toPathId(splitFileName, symbolTable)); // m_lineOffsets.push_back (fromLine-1); @@ -682,7 +675,7 @@ void AnalyzeFile::analyze() { m_lineOffsets.push_back(linesWriten); - content += setSLlineDirective_(fromLine, origFromLine, origFile); + content += setSLlineDirective_(fromLine, origFromLine, origFileId); content += " " + fileLevelImportSection; for (unsigned int l = fromLine; l < toLine; l++) { checkSLlineDirective_(allLines[l], l); @@ -693,21 +686,21 @@ void AnalyzeFile::analyze() { linesWriten++; } - fs::path splitFileName = - m_ppFileName.string() + ".ck" + std::to_string(chunkNb); + fs::path splitFileName = fileSystem->toPath(m_ppFileId).string() + ".ck" + + std::to_string(chunkNb); if (chunkNb > 1000) { m_splitFiles.clear(); m_lineOffsets.clear(); - Location loc( - m_clp->mutableSymbolTable()->registerSymbol(m_fileName.string())); + Location loc((SymbolId)m_fileId); Error err(ErrorDefinition::PA_CANNOT_SPLIT_FILE, loc); - m_clp->getErrorContainer()->addError(err); - m_clp->getErrorContainer()->printMessages(); + errors->addError(err); + errors->printMessages(); return; } saveContent(splitFileName, content); - m_splitFiles.emplace_back(splitFileName); + m_splitFiles.emplace_back( + fileSystem->toPathId(splitFileName, symbolTable)); chunkNb++; diff --git a/src/SourceCompile/AntlrParserErrorListener.cpp b/src/SourceCompile/AntlrParserErrorListener.cpp index 846b6bcfad..f161f83edc 100644 --- a/src/SourceCompile/AntlrParserErrorListener.cpp +++ b/src/SourceCompile/AntlrParserErrorListener.cpp @@ -21,6 +21,7 @@ * Created on July 29, 2017, 5:32 PM */ +#include #include #include #include @@ -38,8 +39,10 @@ void AntlrParserErrorListener::syntaxError( m_barked = true; return; } + FileSystem *const fileSystem = FileSystem::getInstance(); + const std::filesystem::path fileName = fileSystem->toPath(m_fileId); if (m_fileContent.empty()) { - m_fileContent = FileUtils::getFileContent(m_fileName); + m_fileContent = FileUtils::getFileContent(fileName); } std::string lineText; @@ -50,8 +53,8 @@ void AntlrParserErrorListener::syntaxError( lineText += "\n"; } for (unsigned int i = 0; i < charPositionInLine; i++) lineText += " "; - lineText += "^-- " + m_fileName + ":" + std::to_string(line) + ":" + - std::to_string(charPositionInLine) + ":"; + lineText += "^-- " + fileName.string() + ":" + std::to_string(line) + + ":" + std::to_string(charPositionInLine) + ":"; } } if (m_reportedSyntaxError == false) { diff --git a/src/SourceCompile/CheckCompile.cpp b/src/SourceCompile/CheckCompile.cpp index 5dc2b3fe7f..584c8654d5 100644 --- a/src/SourceCompile/CheckCompile.cpp +++ b/src/SourceCompile/CheckCompile.cpp @@ -22,6 +22,7 @@ */ #include +#include #include #include #include @@ -50,24 +51,21 @@ bool CheckCompile::checkSyntaxErrors_() { } bool CheckCompile::mergeSymbolTables_() { + FileSystem* const fileSystem = FileSystem::getInstance(); const Design::FileIdDesignContentMap& all_files = m_compiler->getDesign()->getAllFileContents(); for (const auto& sym_file : all_files) { const auto fileContent = sym_file.second; - m_compiler->getSymbolTable()->registerSymbol( - fileContent->getFileName().string()); + fileSystem->copy(fileContent->getFileId(), m_compiler->getSymbolTable()); for (NodeId id : fileContent->getNodeIds()) { - *fileContent->getMutableFileId(id) = - m_compiler->getSymbolTable()->registerSymbol( - fileContent->getSymbolTable()->getSymbol( - fileContent->getFileId(id))); + *fileContent->getMutableFileId(id) = fileSystem->copy( + fileContent->getFileId(id), m_compiler->getSymbolTable()); } for (DesignElement* elem : fileContent->getDesignElements()) { elem->m_name = m_compiler->getSymbolTable()->registerSymbol( fileContent->getSymbolTable()->getSymbol(elem->m_name)); - elem->m_fileId = m_compiler->getSymbolTable()->registerSymbol( - fileContent->getSymbolTable()->getSymbol( - fileContent->getFileId(elem->m_node))); + elem->m_fileId = fileSystem->copy(fileContent->getFileId(elem->m_node), + m_compiler->getSymbolTable()); } } return true; @@ -102,16 +100,12 @@ bool CheckCompile::checkTimescale_() { timeUnitUsed = true; } else if (elem->m_timeInfo.m_type == TimeInfo::Type::Timescale) { timeScaleUsed = true; - Location loc(m_compiler->getSymbolTable()->registerSymbol( - fileContent->getSymbolTable()->getSymbol( - fileContent->getFileId(elem->m_node))), - elem->m_line, elem->m_column, elem->m_name); + Location loc(fileContent->getFileId(elem->m_node), elem->m_line, + elem->m_column, elem->m_name); noTimeUnitLocs.push_back(loc); } else { - Location loc(m_compiler->getSymbolTable()->registerSymbol( - fileContent->getSymbolTable()->getSymbol( - fileContent->getFileId(elem->m_node))), - elem->m_line, elem->m_column, elem->m_name); + Location loc(fileContent->getFileId(elem->m_node), elem->m_line, + elem->m_column, elem->m_name); noTimeUnitLocs.push_back(loc); if (reportedMissingTimescale.find(elem->m_name) == reportedMissingTimescale.end()) { diff --git a/src/SourceCompile/CommonListenerHelper.cpp b/src/SourceCompile/CommonListenerHelper.cpp index ab48a4faf6..2926b20a9c 100644 --- a/src/SourceCompile/CommonListenerHelper.cpp +++ b/src/SourceCompile/CommonListenerHelper.cpp @@ -91,7 +91,7 @@ unsigned int CommonListenerHelper::Line(NodeId index) const { int CommonListenerHelper::addVObject(ParserRuleContext* ctx, SymbolId sym, VObjectType objtype) { - SymbolId fileId; + PathId fileId; auto [line, column, endLine, endColumn] = getFileLine(ctx, fileId); NodeId objectIndex = m_fileContent->addObject(sym, fileId, objtype, line, diff --git a/src/SourceCompile/CompilationUnit.cpp b/src/SourceCompile/CompilationUnit.cpp index 1705b0868a..772aaadd51 100644 --- a/src/SourceCompile/CompilationUnit.cpp +++ b/src/SourceCompile/CompilationUnit.cpp @@ -55,7 +55,7 @@ void CompilationUnit::recordTimeInfo(TimeInfo& info) { m_timeInfo.push_back(info); } -TimeInfo& CompilationUnit::getTimeInfo(SymbolId fileId, unsigned int line) { +TimeInfo& CompilationUnit::getTimeInfo(PathId fileId, unsigned int line) { if (m_timeInfo.empty()) { return m_noTimeInfo; } @@ -74,7 +74,7 @@ void CompilationUnit::recordDefaultNetType(NetTypeInfo& info) { m_defaultNetTypes.push_back(info); } -VObjectType CompilationUnit::getDefaultNetType(SymbolId fileId, +VObjectType CompilationUnit::getDefaultNetType(PathId fileId, unsigned int line) { if (m_defaultNetTypes.empty()) { return slNetType_Wire; @@ -90,7 +90,7 @@ VObjectType CompilationUnit::getDefaultNetType(SymbolId fileId, return slNetType_Wire; } -void CompilationUnit::setCurrentTimeInfo(SymbolId fileId) { +void CompilationUnit::setCurrentTimeInfo(PathId fileId) { if (m_timeInfo.empty()) { return; } diff --git a/src/SourceCompile/CompileSourceFile.cpp b/src/SourceCompile/CompileSourceFile.cpp index 5c05e31ad2..0bf15e9173 100644 --- a/src/SourceCompile/CompileSourceFile.cpp +++ b/src/SourceCompile/CompileSourceFile.cpp @@ -22,6 +22,7 @@ */ #include +#include #include #include #include @@ -45,7 +46,7 @@ namespace SURELOG { using namespace antlr4; namespace fs = std::filesystem; -CompileSourceFile::CompileSourceFile(SymbolId fileId, CommandLineParser* clp, +CompileSourceFile::CompileSourceFile(PathId fileId, CommandLineParser* clp, ErrorContainer* errors, Compiler* compiler, SymbolTable* symbols, CompilationUnit* compilationUnit, @@ -57,12 +58,11 @@ CompileSourceFile::CompileSourceFile(SymbolId fileId, CommandLineParser* clp, m_symbolTable(symbols), m_compilationUnit(compilationUnit), m_action(Preprocess), - m_ppResultFileId(BadSymbolId), m_library(library), m_text(text) {} CompileSourceFile::CompileSourceFile(CompileSourceFile* parent, - SymbolId ppResultFileId, + PathId ppResultFileId, unsigned int lineOffset) : m_fileId(parent->m_fileId), m_commandLineParser(parent->m_commandLineParser), @@ -83,7 +83,8 @@ CompileSourceFile::CompileSourceFile(CompileSourceFile* parent, bool CompileSourceFile::compile(Action action) { m_action = action; - fs::path fileName = m_symbolTable->getSymbol(m_fileId); + FileSystem* const fileSystem = FileSystem::getInstance(); + fs::path fileName = fileSystem->toPath(m_fileId); if (m_commandLineParser->verbose()) { Location loc(m_fileId); ErrorDefinition::ErrorType type = @@ -132,25 +133,30 @@ CompileSourceFile::~CompileSourceFile() { #ifdef SURELOG_WITH_PYTHON delete m_pythonListener; #endif - std::map::iterator itr2; - for (itr2 = m_antlrPpMap.begin(); itr2 != m_antlrPpMap.end(); itr2++) { - delete (*itr2).second; + for (auto& entry : m_antlrPpMacroMap) { + delete entry.second; } + for (auto& entry : m_antlrPpFileMap) { + delete entry.second; + } + m_antlrPpMacroMap.clear(); + m_antlrPpFileMap.clear(); } uint64_t CompileSourceFile::getJobSize(Action action) const { + FileSystem* const fileSystem = FileSystem::getInstance(); switch (action) { case Preprocess: case PostPreprocess: { - fs::path fileName = getSymbolTable()->getSymbol(m_fileId); + fs::path fileName = fileSystem->toPath(m_fileId); return FileUtils::fileSize(fileName); } case Parse: { - fs::path fileName = getSymbolTable()->getSymbol(m_ppResultFileId); + fs::path fileName = fileSystem->toPath(m_ppResultFileId); return FileUtils::fileSize(fileName); } case PythonAPI: { - fs::path fileName = getSymbolTable()->getSymbol(m_ppResultFileId); + fs::path fileName = fileSystem->toPath(m_ppResultFileId); return FileUtils::fileSize(fileName); } }; @@ -172,7 +178,7 @@ bool CompileSourceFile::pythonAPI_() { if (getCommandLineParser()->pythonEvalScriptPerFile()) { PythonAPI::evalScriptPerFile( - getCommandLineParser()->getSymbolTable().getSymbol( + FileSystem::getInstance()->toPath( getCommandLineParser()->pythonEvalScriptPerFileId()), m_errors, m_parser->getFileContent(), m_interpState); } @@ -203,10 +209,6 @@ bool CompileSourceFile::parse_() { } bool CompileSourceFile::preprocess_() { - Precompiled* prec = Precompiled::getSingleton(); - fs::path root = getSymbolTable()->getSymbol(m_fileId); - root = FileUtils::basename(root); - PreprocessFile::SpecialInstructions instructions( PreprocessFile::SpecialInstructions::DontMute, PreprocessFile::SpecialInstructions::DontMark, @@ -219,9 +221,10 @@ bool CompileSourceFile::preprocess_() { m_pp = new PreprocessFile(m_fileId, this, instructions, m_compilationUnit, m_library); } else { - m_pp = new PreprocessFile(BadSymbolId, nullptr, 0, this, instructions, - m_compilationUnit, m_library, m_text, nullptr, 0, - BadSymbolId); + m_pp = new PreprocessFile(BadSymbolId, this, instructions, + m_compilationUnit, m_library, + /* includer */ nullptr, /* includerLine */ 0, + m_text, nullptr, 0, BadPathId); } registerPP(m_pp); @@ -236,7 +239,9 @@ bool CompileSourceFile::preprocess_() { if (m_commandLineParser->getDebugIncludeFileInfo()) std::cerr << m_pp->reportIncludeInfo(); - if ((!m_commandLineParser->createCache()) && prec->isFilePrecompiled(root)) + Precompiled* prec = Precompiled::getSingleton(); + if ((!m_commandLineParser->createCache()) && + prec->isFilePrecompiled(m_fileId)) return true; m_pp->saveCache(); @@ -244,10 +249,10 @@ bool CompileSourceFile::preprocess_() { } bool CompileSourceFile::postPreprocess_() { + FileSystem* const fileSystem = FileSystem::getInstance(); SymbolTable* symbolTable = getCompiler()->getSymbolTable(); if (m_commandLineParser->parseOnly()) { - m_ppResultFileId = - m_symbolTable->registerSymbol(symbolTable->getSymbol(m_fileId)); + m_ppResultFileId = fileSystem->copy(m_fileId, m_symbolTable); return true; } std::string m_pp_result = m_pp->getPreProcessedFileContent(); @@ -258,8 +263,8 @@ bool CompileSourceFile::postPreprocess_() { if (m_commandLineParser->writePpOutput() || m_commandLineParser->writePpOutputFileId()) { const fs::path directory = - symbolTable->getSymbol(m_commandLineParser->getFullCompileDir()); - fs::path fullFileName = symbolTable->getSymbol(m_fileId); + fileSystem->toPath(m_commandLineParser->getFullCompileDirId()); + fs::path fullFileName = fileSystem->toPath(m_fileId); fs::path baseFileName = FileUtils::basename(fullFileName); fs::path filePath = FileUtils::getPathName(fullFileName); fs::path hashedPath = m_commandLineParser->noCacheHash() @@ -268,15 +273,15 @@ bool CompileSourceFile::postPreprocess_() { fs::path fileName = hashedPath / baseFileName; const fs::path writePpOutputFileName = - symbolTable->getSymbol(m_commandLineParser->writePpOutputFileId()); + fileSystem->toPath(m_commandLineParser->writePpOutputFileId()); std::string libName = m_library->getName(); fs::path ppFileName = m_commandLineParser->writePpOutput() ? directory / libName / fileName : writePpOutputFileName; fs::path dirPpFile = FileUtils::getPathName(ppFileName); - SymbolId ppOutId = symbolTable->registerSymbol(ppFileName.string()); - m_ppResultFileId = m_symbolTable->registerSymbol(ppFileName.string()); - SymbolId ppDirId = symbolTable->registerSymbol(dirPpFile.string()); + PathId ppOutId = fileSystem->toPathId(ppFileName, symbolTable); + m_ppResultFileId = fileSystem->toPathId(ppFileName, m_symbolTable); + PathId ppDirId = fileSystem->toPathId(dirPpFile, symbolTable); if (m_commandLineParser->lowMem() || m_commandLineParser->link()) { return true; } @@ -305,22 +310,38 @@ bool CompileSourceFile::postPreprocess_() { void CompileSourceFile::registerAntlrPpHandlerForId( SymbolId id, PreprocessFile::AntlrParserHandler* pp) { - std::map::iterator itr = - m_antlrPpMap.find(id); - if (itr != m_antlrPpMap.end()) { + auto itr = m_antlrPpMacroMap.find(id); + if (itr != m_antlrPpMacroMap.end()) { + delete (*itr).second; + m_antlrPpMacroMap.erase(itr); + } + m_antlrPpMacroMap.emplace(id, pp); +} + +void CompileSourceFile::registerAntlrPpHandlerForId( + PathId id, PreprocessFile::AntlrParserHandler* pp) { + auto itr = m_antlrPpFileMap.find(id); + if (itr != m_antlrPpFileMap.end()) { delete (*itr).second; - m_antlrPpMap.erase(itr); - m_antlrPpMap.insert(std::make_pair(id, pp)); - return; + m_antlrPpFileMap.erase(itr); } - m_antlrPpMap.insert(std::make_pair(id, pp)); + m_antlrPpFileMap.emplace(id, pp); } PreprocessFile::AntlrParserHandler* CompileSourceFile::getAntlrPpHandlerForId( SymbolId id) { - std::map::iterator itr = - m_antlrPpMap.find(id); - if (itr != m_antlrPpMap.end()) { + auto itr = m_antlrPpMacroMap.find(id); + if (itr != m_antlrPpMacroMap.end()) { + PreprocessFile::AntlrParserHandler* ptr = (*itr).second; + return ptr; + } + return nullptr; +} + +PreprocessFile::AntlrParserHandler* CompileSourceFile::getAntlrPpHandlerForId( + PathId id) { + auto itr = m_antlrPpFileMap.find(id); + if (itr != m_antlrPpFileMap.end()) { PreprocessFile::AntlrParserHandler* ptr = (*itr).second; return ptr; } diff --git a/src/SourceCompile/Compiler.cpp b/src/SourceCompile/Compiler.cpp index d860001b4f..96b34d4bef 100644 --- a/src/SourceCompile/Compiler.cpp +++ b/src/SourceCompile/Compiler.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -131,11 +132,12 @@ bool Compiler::compileOneFile_(CompileSourceFile* compiler, return status; } -bool Compiler::isLibraryFile(SymbolId id) const { +bool Compiler::isLibraryFile(PathId id) const { return (m_libraryFiles.find(id) != m_libraryFiles.end()); } bool Compiler::ppinit_() { + FileSystem* const fileSystem = FileSystem::getInstance(); if (!m_commandLineParser->fileunit()) { m_commonCompilationUnit = new CompilationUnit(false); if (m_commandLineParser->parseBuiltIn()) { @@ -147,9 +149,9 @@ bool Compiler::ppinit_() { CompilationUnit* comp_unit = m_commonCompilationUnit; // Source files (.v, .sv on the command line) - SymbolIdSet sourceFiles; + PathIdSet sourceFiles; std::set sourceFileNames; - for (const SymbolId& source_file_id : m_commandLineParser->getSourceFiles()) { + for (const PathId& source_file_id : m_commandLineParser->getSourceFiles()) { SymbolTable* symbols = m_symbolTable; if (m_commandLineParser->fileunit()) { comp_unit = new CompilationUnit(true); @@ -158,20 +160,18 @@ bool Compiler::ppinit_() { builtin->addBuiltinMacros(comp_unit); } m_compilationUnits.push_back(comp_unit); - symbols = m_commandLineParser->getSymbolTable().CreateSnapshot(); + symbols = m_commandLineParser->getSymbolTable()->CreateSnapshot(); m_symbolTables.push_back(symbols); } ErrorContainer* errors = new ErrorContainer(symbols); m_errorContainers.push_back(errors); errors->registerCmdLine(m_commandLineParser); - const fs::path fileName = - m_commandLineParser->getSymbolTable().getSymbol(source_file_id); + const fs::path fileName = fileSystem->toPath(source_file_id); const fs::path fullPath = FileUtils::getFullPath(fileName); sourceFileNames.insert(fullPath); - const SymbolId fullPathId = - m_commandLineParser->mutableSymbolTable()->registerSymbol( - fullPath.string()); + const PathId fullPathId = + fileSystem->toPathId(fullPath, m_commandLineParser->getSymbolTable()); Library* library = m_librarySet->getLibrary(fullPathId); sourceFiles.insert(fullPathId); @@ -184,17 +184,16 @@ bool Compiler::ppinit_() { if (!m_text.empty()) { Library* library = new Library("UnitTest", m_symbolTable); CompileSourceFile* compiler = - new CompileSourceFile(BadSymbolId, m_commandLineParser, m_errors, this, + new CompileSourceFile(BadPathId, m_commandLineParser, m_errors, this, m_symbolTable, comp_unit, library, m_text); m_compilers.push_back(compiler); } // Library files - SymbolIdSet libFiles; + PathIdSet libFiles; // (-v ) - for (const SymbolId& id : m_commandLineParser->getLibraryFiles()) { - const fs::path fileName = - m_commandLineParser->getSymbolTable().getSymbol(id); + for (PathId id : m_commandLineParser->getLibraryFiles()) { + const fs::path fileName = fileSystem->toPath(id); const fs::path fullPath = FileUtils::getFullPath(fileName); if (sourceFileNames.find(fullPath) == sourceFileNames.end()) { libFiles.insert(id); @@ -202,12 +201,11 @@ bool Compiler::ppinit_() { } // (-y +libext+) for (const auto& path : m_commandLineParser->getLibraryPaths()) { - for (const auto& ext : m_commandLineParser->getLibraryExtensions()) { + for (auto ext : m_commandLineParser->getLibraryExtensions()) { auto files = FileUtils::collectFiles( - path, ext, m_commandLineParser->mutableSymbolTable()); + path, ext, m_commandLineParser->getSymbolTable()); for (const auto& file : files) { - const fs::path fileName = - m_commandLineParser->getSymbolTable().getSymbol(file); + const fs::path fileName = fileSystem->toPath(file); const fs::path fullPath = FileUtils::getFullPath(fileName); if (sourceFileNames.find(fullPath) == sourceFileNames.end()) { libFiles.insert(file); @@ -220,20 +218,18 @@ bool Compiler::ppinit_() { if (m_commandLineParser->fileunit()) { comp_unit = new CompilationUnit(true); m_compilationUnits.push_back(comp_unit); - symbols = m_commandLineParser->getSymbolTable().CreateSnapshot(); + symbols = m_commandLineParser->getSymbolTable()->CreateSnapshot(); m_symbolTables.push_back(symbols); } ErrorContainer* errors = new ErrorContainer(symbols); m_errorContainers.push_back(errors); errors->registerCmdLine(m_commandLineParser); - fs::path fullPath = FileUtils::getFullPath( - m_commandLineParser->getSymbolTable().getSymbol(id)); + fs::path fullPath = FileUtils::getFullPath(fileSystem->toPath(id)); // This line registers the file in the "work" library: - SymbolId fullPathId = - m_commandLineParser->mutableSymbolTable()->registerSymbol( - fullPath.string()); + PathId fullPathId = + fileSystem->toPathId(fullPath, m_commandLineParser->getSymbolTable()); /*Library* library = */ m_librarySet->getLibrary(fullPathId); m_libraryFiles.insert(id); m_libraryFiles.insert(fullPathId); @@ -249,8 +245,8 @@ bool Compiler::ppinit_() { // Libraries (.map) for (auto& lib : m_librarySet->getLibraries()) { - for (const auto& id : lib.getFiles()) { - fs::path fileName = lib.getSymbols()->getSymbol(id); + for (auto id : lib.getFiles()) { + fs::path fileName = fileSystem->toPath(id); if (sourceFiles.find(id) != sourceFiles.end()) { // These files are already included in the command line continue; @@ -264,7 +260,7 @@ bool Compiler::ppinit_() { if (m_commandLineParser->fileunit()) { comp_unit = new CompilationUnit(true); m_compilationUnits.push_back(comp_unit); - symbols = m_commandLineParser->getSymbolTable().CreateSnapshot(); + symbols = m_commandLineParser->getSymbolTable()->CreateSnapshot(); m_symbolTables.push_back(symbols); } ErrorContainer* errors = new ErrorContainer(symbols); @@ -280,12 +276,13 @@ bool Compiler::ppinit_() { } bool Compiler::createFileList_() { + FileSystem* const fileSystem = FileSystem::getInstance(); if ((m_commandLineParser->writePpOutput() || m_commandLineParser->writePpOutputFileId()) && (!m_commandLineParser->parseOnly())) { SymbolTable* symbolTable = getSymbolTable(); const fs::path directory = - symbolTable->getSymbol(m_commandLineParser->getFullCompileDir()); + fileSystem->toPath(m_commandLineParser->getFullCompileDirId()); { std::ofstream ofs; fs::path fileList = directory / "file.lst"; @@ -293,12 +290,14 @@ bool Compiler::createFileList_() { if (ofs.good()) { unsigned int size = m_compilers.size(); for (unsigned int i = 0; i < size; i++) { - fs::path ppFileName = m_compilers[i]->getSymbolTable()->getSymbol( - m_compilers[i]->getPpOutputFileId()); - fs::path fileName = m_compilers[i]->getSymbolTable()->getSymbol( - m_compilers[i]->getFileId()); + PathId ppFileId = fileSystem->copy( + m_compilers[i]->getPpOutputFileId(), symbolTable); + PathId fileId = + fileSystem->copy(m_compilers[i]->getFileId(), symbolTable); + m_ppFileMap[fileId].push_back(ppFileId); + + fs::path ppFileName = fileSystem->toPath(ppFileId); ppFileName = FileUtils::getPreferredPath(ppFileName); - ppFileMap[fileName].push_back(ppFileName); ofs << ppFileName << std::flush << std::endl; } ofs.close(); @@ -313,10 +312,9 @@ bool Compiler::createFileList_() { if (ofs.good()) { unsigned int size = m_compilers.size(); for (unsigned int i = 0; i < size; i++) { - fs::path ppFileName = m_compilers[i]->getSymbolTable()->getSymbol( - m_compilers[i]->getPpOutputFileId()); - fs::path fileName = m_compilers[i]->getSymbolTable()->getSymbol( - m_compilers[i]->getFileId()); + fs::path ppFileName = + fileSystem->toPath(m_compilers[i]->getPpOutputFileId()); + fs::path fileName = fileSystem->toPath(m_compilers[i]->getFileId()); ppFileName = FileUtils::getPreferredPath(ppFileName); ppFileName = ppFileName.lexically_relative(directory); ofs << ppFileName << " " << fileName << std::flush << std::endl; @@ -331,8 +329,7 @@ bool Compiler::createFileList_() { std::string concatFiles; unsigned int size = m_compilers.size(); for (unsigned int i = 0; i < size; i++) { - fs::path fileName = m_compilers[i]->getSymbolTable()->getSymbol( - m_compilers[i]->getFileId()); + fs::path fileName = fileSystem->toPath(m_compilers[i]->getFileId()); concatFiles += fileName.string() + "|"; } std::size_t val = std::hash{}(concatFiles); @@ -344,8 +341,7 @@ bool Compiler::createFileList_() { if (ofs.good()) { unsigned int size = m_compilers.size(); for (unsigned int i = 0; i < size; i++) { - fs::path fileName = m_compilers[i]->getSymbolTable()->getSymbol( - m_compilers[i]->getFileId()); + fs::path fileName = fileSystem->toPath(m_compilers[i]->getFileId()); if (i > 0) ofs << " "; ofs << fileName.string(); } @@ -368,13 +364,15 @@ bool Compiler::createMultiProcessParser_() { return true; } + FileSystem* const fileSystem = FileSystem::getInstance(); + // Create CMakeLists.txt bool muted = m_commandLineParser->muteStdout(); SymbolTable* symbolTable = getSymbolTable(); const fs::path outputDir = - symbolTable->getSymbol(m_commandLineParser->getOutputDir()); + fileSystem->toPath(m_commandLineParser->getOutputDirId()); const fs::path directory = - symbolTable->getSymbol(m_commandLineParser->getFullCompileDir()); + fileSystem->toPath(m_commandLineParser->getFullCompileDirId()); std::ofstream ofs; fs::path fileList = directory / "CMakeLists.txt"; ofs.open(fileList); @@ -409,10 +407,7 @@ bool Compiler::createMultiProcessParser_() { fs::path cwd = fs::current_path(); for (const auto& compiler : m_compilers) { - fs::path root = - compiler->getSymbolTable()->getSymbol(compiler->getFileId()); - root = FileUtils::basename(root); - if (prec->isFilePrecompiled(root)) { + if (prec->isFilePrecompiled(compiler->getFileId())) { continue; } unsigned int size = @@ -433,7 +428,8 @@ bool Compiler::createMultiProcessParser_() { jobArray[newJobIndex].push_back(compiler); } - fs::path full_exe_path = m_commandLineParser->getExePath(); + fs::path full_exe_path = + fileSystem->toPath(m_commandLineParser->getProgramId()); if (m_commandLineParser->profile()) { full_exe_path += " -profile"; } @@ -444,15 +440,12 @@ bool Compiler::createMultiProcessParser_() { // Big jobs for (CompileSourceFile* compiler : bigJobs) { absoluteIndex++; - fs::path fileName = - compiler->getSymbolTable()->getSymbol(compiler->getPpOutputFileId()); - fileName = fileName.lexically_relative(directory); + fs::path fileName = fileSystem->toPath(compiler->getPpOutputFileId()); std::string targetname = std::to_string(absoluteIndex) + "_" + FileUtils::basename(fileName).string(); targets.push_back(targetname); - fs::path baseFileName = FileUtils::basename(fileName); std::string_view svFile = - m_commandLineParser->isSVFile(baseFileName) ? " -sv " : " "; + m_commandLineParser->isSVFile(compiler->getFileId()) ? " -sv " : " "; std::string batchCmd = StrCat( fileUnit, sverilog, synth, noHash, " -parseonly -nostdout -nobuiltin -mt 0 -mp 0 -l ", @@ -473,11 +466,10 @@ bool Compiler::createMultiProcessParser_() { fs::path lastFile; absoluteIndex++; for (const auto compiler : jobArray[i]) { - fs::path fileName = compiler->getSymbolTable()->getSymbol( - compiler->getPpOutputFileId()); - fs::path baseFileName = FileUtils::basename(fileName); + fs::path fileName = fileSystem->toPath(compiler->getPpOutputFileId()); std::string_view svFile = - m_commandLineParser->isSVFile(baseFileName) ? " -sv " : " "; + m_commandLineParser->isSVFile(compiler->getFileId()) ? " -sv " + : " "; fileName = fileName.lexically_relative(directory); StrAppend(&fileList, svFile, fileName); lastFile = fileName; @@ -555,13 +547,15 @@ bool Compiler::createMultiProcessPreProcessor_() { return true; } + FileSystem* const fileSystem = FileSystem::getInstance(); + // Create CMakeLists.txt bool muted = m_commandLineParser->muteStdout(); SymbolTable* symbolTable = getSymbolTable(); const fs::path outputDir = - symbolTable->getSymbol(m_commandLineParser->getOutputDir()); + fileSystem->toPath(m_commandLineParser->getOutputDirId()); const fs::path directory = - symbolTable->getSymbol(m_commandLineParser->getFullCompileDir()); + fileSystem->toPath(m_commandLineParser->getFullCompileDirId()); std::ofstream ofs; fs::path fileList = directory / "CMakeLists.txt"; ofs.open(fileList); @@ -571,7 +565,8 @@ bool Compiler::createMultiProcessPreProcessor_() { ofs << "project(SurelogPreprocessing NONE)" << std::endl; fs::path cwd = fs::current_path(); - fs::path full_exe_path = m_commandLineParser->getExePath(); + fs::path full_exe_path = + fileSystem->toPath(m_commandLineParser->getProgramId()); if (m_commandLineParser->profile()) { full_exe_path += " -profile"; } @@ -580,7 +575,7 @@ bool Compiler::createMultiProcessPreProcessor_() { // +define+ for (const auto& id_value : m_commandLineParser->getDefineList()) { const std::string defName = - m_commandLineParser->getSymbolTable().getSymbol(id_value.first); + m_commandLineParser->getSymbolTable()->getSymbol(id_value.first); std::string val; for (char c : id_value.second) { if (c == '#') { @@ -593,39 +588,33 @@ bool Compiler::createMultiProcessPreProcessor_() { } // Source files (.v, .sv on the command line) - for (const SymbolId& id : m_commandLineParser->getSourceFiles()) { - const fs::path fileName = - m_commandLineParser->getSymbolTable().getSymbol(id); - - fs::path baseFileName = FileUtils::basename(fileName); + for (const PathId& id : m_commandLineParser->getSourceFiles()) { + const fs::path fileName = fileSystem->toPath(id); std::string_view svFile = - m_commandLineParser->isSVFile(baseFileName) ? " -sv " : " "; + m_commandLineParser->isSVFile(id) ? " -sv " : " "; StrAppend(&fileList, svFile, fileName); } // Library files // (-v ) - for (const SymbolId& id : m_commandLineParser->getLibraryFiles()) { - const std::string& fileName = - m_commandLineParser->getSymbolTable().getSymbol(id); - fileList += " -v " + fileName; + for (const PathId& id : m_commandLineParser->getLibraryFiles()) { + const fs::path fileName = fileSystem->toPath(id); + fileList += " -v " + fileName.string(); } // (-y +libext+) for (const auto& id : m_commandLineParser->getLibraryPaths()) { - const std::string& fileName = - m_commandLineParser->getSymbolTable().getSymbol(id); - fileList += " -y " + fileName; + const fs::path fileName = fileSystem->toPath(id); + fileList += " -y " + fileName.string(); } // +libext+ for (const auto& id : m_commandLineParser->getLibraryExtensions()) { const std::string& extName = - m_commandLineParser->getSymbolTable().getSymbol(id); + m_commandLineParser->getSymbolTable()->getSymbol(id); fileList += " +libext+" + extName; } // Include dirs - for (const SymbolId& id : m_commandLineParser->getIncludePaths()) { - const std::string& fileName = - m_commandLineParser->getSymbolTable().getSymbol(id); - fileList += " -I" + fileName; + for (const PathId& id : m_commandLineParser->getIncludePaths()) { + const fs::path fileName = fileSystem->toPath(id); + fileList += " -I" + fileName.string(); } std::string_view sverilog = @@ -690,6 +679,7 @@ static int calculateEffectiveThreads(int nbThreads) { } bool Compiler::parseinit_() { + FileSystem* const fileSystem = FileSystem::getInstance(); Precompiled* const prec = Precompiled::getSingleton(); // Single out the large files. @@ -703,19 +693,21 @@ bool Compiler::parseinit_() { std::vector tmp_compilers; for (CompileSourceFile* const compiler : m_compilers) { - const fs::path fileName = - compiler->getSymbolTable()->getSymbol(compiler->getPpOutputFileId()); - const fs::path origFile = - compiler->getSymbolTable()->getSymbol(compiler->getFileId()); - const fs::path root = FileUtils::basename(fileName); - const unsigned int nbThreads = prec->isFilePrecompiled(root) - ? 0 - : m_commandLineParser->getNbMaxTreads(); + const fs::path fileName = fileSystem->toPath(compiler->getPpOutputFileId()); + const fs::path origFile = fileSystem->toPath(compiler->getFileId()); + const unsigned int nbThreads = + prec->isFilePrecompiled(compiler->getPpOutputFileId()) + ? 0 + : m_commandLineParser->getNbMaxTreads(); const int effectiveNbThreads = calculateEffectiveThreads(nbThreads); AnalyzeFile* const fileAnalyzer = - new AnalyzeFile(m_commandLineParser, m_design, fileName, origFile, + new AnalyzeFile(m_commandLineParser, m_design, + fileSystem->copy(compiler->getPpOutputFileId(), + m_commandLineParser->getSymbolTable()), + fileSystem->copy(compiler->getFileId(), + m_commandLineParser->getSymbolTable()), effectiveNbThreads, m_text); fileAnalyzer->analyze(); compiler->setFileAnalyzer(fileAnalyzer); @@ -726,7 +718,7 @@ bool Compiler::parseinit_() { if (!m_commandLineParser->fileunit()) { SymbolTable* symbols = - m_commandLineParser->getSymbolTable().CreateSnapshot(); + m_commandLineParser->getSymbolTable()->CreateSnapshot(); m_symbolTables.push_back(symbols); compiler->setSymbolTable(symbols); // fileContent->setSymbolTable(symbols); @@ -739,16 +731,14 @@ bool Compiler::parseinit_() { compiler->getParser()->setFileContent(new FileContent( compiler->getParser()->getFileId(0), compiler->getParser()->getLibrary(), compiler->getSymbolTable(), - compiler->getErrorContainer(), nullptr, BadSymbolId)); + compiler->getErrorContainer(), nullptr, BadPathId)); int j = 0; - for (auto& chunk : fileAnalyzer->getSplitFiles()) { + for (const auto& ppId : fileAnalyzer->getSplitFiles()) { SymbolTable* symbols = - m_commandLineParser->getSymbolTable().CreateSnapshot(); + m_commandLineParser->getSymbolTable()->CreateSnapshot(); m_symbolTables.push_back(symbols); - SymbolId ppId = symbols->registerSymbol(chunk.string()); - symbols->registerSymbol( - compiler->getParser()->getFileName(LINE1).string()); + fileSystem->copy(compiler->getParser()->getFileId(LINE1), symbols); CompileSourceFile* chunkCompiler = new CompileSourceFile( compiler, ppId, fileAnalyzer->getLineOffsets()[j]); // Schedule chunk @@ -774,7 +764,7 @@ bool Compiler::parseinit_() { } else { if ((!m_commandLineParser->fileunit()) && m_text.empty()) { SymbolTable* symbols = - m_commandLineParser->getSymbolTable().CreateSnapshot(); + m_commandLineParser->getSymbolTable()->CreateSnapshot(); m_symbolTables.push_back(symbols); compiler->setSymbolTable(symbols); ErrorContainer* errors = new ErrorContainer(symbols); @@ -813,6 +803,7 @@ bool Compiler::cleanup_() { bool Compiler::compileFileSet_(CompileSourceFile::Action action, bool allowMultithread, std::vector& container) { + FileSystem* const fileSystem = FileSystem::getInstance(); const unsigned short maxThreadCount = allowMultithread ? m_commandLineParser->getNbMaxTreads() : 0; @@ -897,8 +888,9 @@ bool Compiler::compileFileSet_(CompileSourceFile::Action action, for (const CompileSourceFile* job : jobArray[i]) { fs::path fileName; if (job->getPreprocessor()) - fileName = job->getPreprocessor()->getFileName(0); - if (job->getParser()) fileName = job->getParser()->getFileName(0); + fileName = fileSystem->toPath(job->getPreprocessor()->getFileId(0)); + if (job->getParser()) + fileName = fileSystem->toPath(job->getParser()->getFileId(0)); sum += job->getJobSize(action); std::cout << job->getJobSize(action) << " " << fileName << std::endl; } @@ -952,6 +944,7 @@ bool Compiler::compileFileSet_(CompileSourceFile::Action action, } bool Compiler::compile() { + FileSystem* const fileSystem = FileSystem::getInstance(); std::string profile; Timer tmr; Timer tmrTotal; @@ -1073,9 +1066,9 @@ bool Compiler::compile() { } if (m_commandLineParser->pythonEvalScript()) { - PythonAPI::evalScript(m_commandLineParser->getSymbolTable().getSymbol( - m_commandLineParser->pythonEvalScriptId()), - m_design); + PythonAPI::evalScript( + fileSystem->toPath(m_commandLineParser->pythonEvalScriptId()), + m_design); if (m_commandLineParser->profile()) { std::string msg = "Python design processing took " + StringUtils::to_string(tmr.elapsed_rounded()) + @@ -1088,11 +1081,12 @@ bool Compiler::compile() { m_errors->printMessages(m_commandLineParser->muteStdout()); } - fs::path directory = m_commandLineParser->getSymbolTable().getSymbol( - m_commandLineParser->getFullCompileDir()); + fs::path directory = + fileSystem->toPath(m_commandLineParser->getFullCompileDirId()); fs::path uhdmFile = directory / "surelog.uhdm"; - m_uhdmDesign = m_compileDesign->writeUHDM(uhdmFile.string()); + m_uhdmDesign = m_compileDesign->writeUHDM(fileSystem->toPathId( + uhdmFile, m_compileDesign->getCompiler()->getSymbolTable())); // Do not delete as now UHDM has to live past the compilation step // delete compileDesign; } diff --git a/src/SourceCompile/MacroInfo.cpp b/src/SourceCompile/MacroInfo.cpp index b00d7b0795..f160c25e4d 100644 --- a/src/SourceCompile/MacroInfo.cpp +++ b/src/SourceCompile/MacroInfo.cpp @@ -22,3 +22,20 @@ */ #include + +namespace SURELOG { +MacroInfo::MacroInfo(std::string_view name, int type, PathId fileId, + unsigned int startLine, unsigned short int startColumn, + unsigned int endLine, unsigned short int endColumn, + const std::vector& arguments, + const std::vector& tokens) + : m_name(name), + m_type(type), + m_fileId(fileId), + m_startLine(startLine), + m_startColumn(startColumn), + m_endLine(endLine), + m_endColumn(endColumn), + m_arguments(arguments), + m_tokens(tokens) {} +} // namespace SURELOG diff --git a/src/SourceCompile/ParseFile.cpp b/src/SourceCompile/ParseFile.cpp index 68492401f2..a120b34239 100644 --- a/src/SourceCompile/ParseFile.cpp +++ b/src/SourceCompile/ParseFile.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -46,10 +47,9 @@ namespace SURELOG { namespace fs = std::filesystem; -ParseFile::ParseFile(SymbolId fileId, SymbolTable* symbolTable, +ParseFile::ParseFile(PathId fileId, SymbolTable* symbolTable, ErrorContainer* errors) : m_fileId(fileId), - m_ppFileId(BadSymbolId), m_compileSourceFile(nullptr), m_compilationUnit(nullptr), m_library(nullptr), @@ -66,9 +66,9 @@ ParseFile::ParseFile(SymbolId fileId, SymbolTable* symbolTable, debug_AstModel = false; } -ParseFile::ParseFile(SymbolId fileId, CompileSourceFile* csf, +ParseFile::ParseFile(PathId fileId, CompileSourceFile* csf, CompilationUnit* compilationUnit, Library* library, - SymbolId ppFileId, bool keepParserHandler) + PathId ppFileId, bool keepParserHandler) : m_fileId(fileId), m_ppFileId(ppFileId), m_compileSourceFile(csf), @@ -89,7 +89,7 @@ ParseFile::ParseFile(SymbolId fileId, CompileSourceFile* csf, } ParseFile::ParseFile(CompileSourceFile* compileSourceFile, ParseFile* parent, - SymbolId chunkFileId, unsigned int offsetLine) + PathId chunkFileId, unsigned int offsetLine) : m_fileId(parent->m_fileId), m_ppFileId(chunkFileId), m_compileSourceFile(compileSourceFile), @@ -110,9 +110,7 @@ ParseFile::ParseFile(CompileSourceFile* compileSourceFile, ParseFile* parent, ParseFile::ParseFile(const std::string& text, CompileSourceFile* csf, CompilationUnit* compilationUnit, Library* library) - : m_fileId(BadSymbolId), - m_ppFileId(BadSymbolId), - m_compileSourceFile(csf), + : m_compileSourceFile(csf), m_compilationUnit(compilationUnit), m_library(library), m_antlrParserHandler(nullptr), @@ -155,10 +153,6 @@ std::string ParseFile::getSymbol(SymbolId id) const { return getCompileSourceFile()->getSymbolTable()->getSymbol(id); } -fs::path ParseFile::getFileName(unsigned int line) { - return getSymbol(getFileId(line)); -} - void ParseFile::addError(Error& error) { getCompileSourceFile()->getErrorContainer()->addError(error); } @@ -182,7 +176,7 @@ void ParseFile::buildLineInfoCache_() { while (1) { if ((lineItr >= infos[index].m_originalStartLine) && (infos[index].m_action == IncludeFileInfo::Action::POP)) { - SymbolId fileId = infos[index].m_sectionFile; + PathId fileId = infos[index].m_sectionFile; fileInfoCache[lineItr] = fileId; unsigned int l = infos[index].m_sectionStartLine + (lineItr - infos[index].m_originalStartLine); @@ -204,7 +198,7 @@ void ParseFile::buildLineInfoCache_() { (infos[index].m_indexClosing > -1) && (lineItr < infos[infos[index].m_indexClosing].m_originalStartLine)) { - SymbolId fileId = infos[index].m_sectionFile; + PathId fileId = infos[index].m_sectionFile; fileInfoCache[lineItr] = fileId; unsigned int l = infos[index].m_sectionStartLine + (lineItr - infos[index].m_originalStartLine); @@ -218,12 +212,12 @@ void ParseFile::buildLineInfoCache_() { } } -SymbolId ParseFile::getFileId(unsigned int line) { +PathId ParseFile::getFileId(unsigned int line) { if (!getCompileSourceFile()) { return m_fileId; } PreprocessFile* pp = getCompileSourceFile()->getPreprocessor(); - if (!pp) return BadSymbolId; + if (!pp) return BadPathId; auto& infos = pp->getIncludeFileInfo(); if (!infos.empty()) { if (!fileInfoCache.empty()) { @@ -276,8 +270,9 @@ unsigned int ParseFile::getLineNb(unsigned int line) { } } -bool ParseFile::parseOneFile_(const std::string& fileName, - unsigned int lineOffset) { +bool ParseFile::parseOneFile_(PathId fileId, unsigned int lineOffset) { + FileSystem* const fileSystem = FileSystem::getInstance(); + const std::filesystem::path fileName = fileSystem->toPath(fileId); CommandLineParser* clp = getCompileSourceFile()->getCommandLineParser(); PreprocessFile* pp = getCompileSourceFile()->getPreprocessor(); Timer tmr; @@ -288,7 +283,6 @@ bool ParseFile::parseOneFile_(const std::string& fileName, if (m_sourceText.empty()) { stream.open(fileName); if (!stream.good()) { - SymbolId fileId = registerSymbol(fileName); Location ppfile(fileId); Error err(ErrorDefinition::PA_CANNOT_OPEN_FILE, ppfile); addError(err); @@ -301,10 +295,9 @@ bool ParseFile::parseOneFile_(const std::string& fileName, } antlrParserHandler->m_errorListener = - new AntlrParserErrorListener(this, false, lineOffset, fileName); + new AntlrParserErrorListener(this, false, lineOffset, fileId); antlrParserHandler->m_lexer = new SV3_1aLexer(antlrParserHandler->m_inputStream); - const auto suffix = StringUtils::leaf(fileName); VerilogVersion version = VerilogVersion::SystemVerilog; if (pp) version = pp->getVerilogVersion(); if (version != VerilogVersion::NoVersion) { @@ -332,8 +325,8 @@ bool ParseFile::parseOneFile_(const std::string& fileName, } } else { fs::path baseFileName = FileUtils::basename(fileName); - if ((suffix == "sv") || (clp->fullSVMode()) || - (clp->isSVFile(baseFileName))) { + if ((fileName.extension() == ".sv") || (clp->fullSVMode()) || + (clp->isSVFile(fileId))) { antlrParserHandler->m_lexer->sverilog = true; } else { antlrParserHandler->m_lexer->sverilog = false; @@ -386,7 +379,7 @@ bool ParseFile::parseOneFile_(const std::string& fileName, if (getCompileSourceFile()->getCommandLineParser()->profile()) { m_profileInfo += "SLL Parsing: " + StringUtils::to_string(tmr.elapsed_rounded()) + - "s " + fileName + "\n"; + "s " + fileName.string() + "\n"; tmr.reset(); profileParser(); } @@ -409,7 +402,7 @@ bool ParseFile::parseOneFile_(const std::string& fileName, if (getCompileSourceFile()->getCommandLineParser()->profile()) { m_profileInfo += "LL Parsing: " + StringUtils::to_string(tmr.elapsed_rounded()) + - "s " + fileName + "\n"; + "s " + fileName.string() + "\n"; tmr.reset(); profileParser(); } @@ -466,11 +459,10 @@ std::string ParseFile::getProfileInfo() const { } bool ParseFile::parse() { + FileSystem* const fileSystem = FileSystem::getInstance(); CommandLineParser* clp = getCompileSourceFile()->getCommandLineParser(); Precompiled* prec = Precompiled::getSingleton(); - fs::path root = FileUtils::basename(this->getPpFileName()); - bool precompiled = false; - if (prec->isFilePrecompiled(root)) precompiled = true; + bool precompiled = prec->isFilePrecompiled(m_ppFileId); if (m_children.empty()) { ParseCache cache(this); @@ -480,8 +472,8 @@ bool ParseFile::parse() { if (debug_AstModel && !precompiled) std::cout << m_fileContent->printObjects(); if (clp->debugCache()) { - std::cout << "PARSER CACHE USED FOR: " << this->getFileName(0) - << std::endl; + std::cout << "PARSER CACHE USED FOR: " + << fileSystem->toPath(getFileId(0)) << std::endl; } return true; } @@ -501,8 +493,8 @@ bool ParseFile::parse() { } if (ok) { if (clp->debugCache()) { - std::cout << "PARSER CACHE USED FOR: " << this->getFileName(0) - << std::endl; + std::cout << "PARSER CACHE USED FOR: " + << fileSystem->toPath(getFileId(0)) << std::endl; } return true; } @@ -513,7 +505,7 @@ bool ParseFile::parse() { // std::cout << std::endl << "Parsing " << getSymbol(m_ppFileId) << " // Line: " << m_offsetLine << std::endl << std::flush; - parseOneFile_(getSymbol(m_ppFileId), m_offsetLine); + parseOneFile_(m_ppFileId, m_offsetLine); // m_listener = new SV3_1aTreeShapeListener (this, // m_antlrParserHandler->m_tokens, m_offsetLine); diff --git a/src/SourceCompile/ParserHarness.cpp b/src/SourceCompile/ParserHarness.cpp index dd159a4403..38903e8b68 100644 --- a/src/SourceCompile/ParserHarness.cpp +++ b/src/SourceCompile/ParserHarness.cpp @@ -22,6 +22,7 @@ */ #include +#include #include #include #include @@ -58,13 +59,13 @@ std::unique_ptr ParserHarness::parse(const std::string& content) { m_h->compiler = std::make_unique(m_h->clp.get(), m_h->errors.get(), m_h->symbols.get()); m_h->csf = std::make_unique( - BadSymbolId, m_h->clp.get(), m_h->errors.get(), m_h->compiler.get(), + BadPathId, m_h->clp.get(), m_h->errors.get(), m_h->compiler.get(), m_h->symbols.get(), m_h->unit.get(), m_h->lib.get()); m_h->pf.reset( new ParseFile(content, m_h->csf.get(), m_h->unit.get(), m_h->lib.get())); std::unique_ptr file_content_result( - new FileContent(BadSymbolId, m_h->lib.get(), m_h->symbols.get(), - m_h->errors.get(), nullptr, BadSymbolId)); + new FileContent(BadPathId, m_h->lib.get(), m_h->symbols.get(), + m_h->errors.get(), nullptr, BadPathId)); m_h->pf->setFileContent(file_content_result.get()); if (!m_h->pf->parse()) file_content_result.reset(nullptr); return file_content_result; @@ -78,15 +79,15 @@ FileContent* ParserHarness::parse(const std::string& content, ErrorContainer* errors = compiler->getErrorContainer(); CommandLineParser* clp = compiler->getCommandLineParser(); Library* lib = new Library("work", symbols); - CompileSourceFile* csf = new CompileSourceFile(BadSymbolId, clp, errors, + CompileSourceFile* csf = new CompileSourceFile(BadPathId, clp, errors, compiler, symbols, unit, lib); ParseFile* pf = new ParseFile(content, csf, unit, lib); - SymbolId fileId; + PathId fileId; if (!fileName.empty()) { - fileId = symbols->registerSymbol(fileName); + fileId = FileSystem::getInstance()->toPathId(fileName, symbols); } FileContent* file_content_result = - new FileContent(fileId, lib, symbols, errors, nullptr, BadSymbolId); + new FileContent(fileId, lib, symbols, errors, nullptr, BadPathId); pf->setFileContent(file_content_result); if (!pf->parse()) file_content_result = nullptr; return file_content_result; diff --git a/src/SourceCompile/PreprocessFile.cpp b/src/SourceCompile/PreprocessFile.cpp index 1df452648b..89948ea626 100644 --- a/src/SourceCompile/PreprocessFile.cpp +++ b/src/SourceCompile/PreprocessFile.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -54,7 +55,7 @@ const char* const PreprocessFile::MacroNotDefined = "SURELOG_MACRO_NOT_DEFINED"; const char* const PreprocessFile::PP__Line__Marking = "SURELOG__LINE__MARKING"; const char* const PreprocessFile::PP__File__Marking = "SURELOG__FILE__MARKING"; IncludeFileInfo PreprocessFile::s_badIncludeFileInfo( - IncludeFileInfo::Context::NONE, 0, BadSymbolId, 0, 0, 0, 0, + IncludeFileInfo::Context::NONE, 0, BadPathId, 0, 0, 0, 0, IncludeFileInfo::Action::NONE); void PreprocessFile::SpecialInstructions::print() { @@ -161,7 +162,7 @@ void PreprocessFile::DescriptiveErrorListener::syntaxError( lineText += "^-- " + m_fileName + ":" + std::to_string(line) + ":" + std::to_string(charPositionInLine) + ":"; msgId = m_pp->registerSymbol(msg + "," + lineText); - Location loc(m_pp->getMacroInfo()->m_file, + Location loc(m_pp->getMacroInfo()->m_fileId, m_pp->getMacroInfo()->m_startLine + line - 1, charPositionInLine, msgId); Location extraLoc(m_pp->getIncluderFileId(m_pp->getIncluderLine()), @@ -208,13 +209,15 @@ void PreprocessFile::DescriptiveErrorListener::reportContextSensitivity( Parser* recognizer, const dfa::DFA& dfa, size_t startIndex, size_t stopIndex, size_t prediction, atn::ATNConfigSet* configs) {} -PreprocessFile::PreprocessFile(SymbolId fileId, CompileSourceFile* csf, +PreprocessFile::PreprocessFile(PathId fileId, CompileSourceFile* csf, SpecialInstructions& instructions, - CompilationUnit* comp_unit, Library* library) + CompilationUnit* comp_unit, Library* library, + PreprocessFile* includer /* = nullptr */, + unsigned int includerLine /* = 0 */) : m_fileId(fileId), m_library(library), - m_includer(nullptr), - m_includerLine(0), + m_includer(includer), + m_includerLine(includerLine), m_compileSourceFile(csf), m_lineCount(0), m_listener(nullptr), @@ -225,24 +228,25 @@ PreprocessFile::PreprocessFile(SymbolId fileId, CompileSourceFile* csf, m_pauseAppend(false), m_usingCachedVersion(false), m_embeddedMacroCallLine(0), - m_embeddedMacroCallFile(BadSymbolId), m_fileContent(nullptr), m_verilogVersion(VerilogVersion::NoVersion) { setDebug(m_compileSourceFile->m_commandLineParser->getDebugLevel()); resetIncludeFileInfo(); + if (m_includer != nullptr) { + m_includer->m_includes.push_back(this); + } } -PreprocessFile::PreprocessFile(SymbolId fileId, PreprocessFile* includedIn, - unsigned int includerLine, - CompileSourceFile* csf, - SpecialInstructions& instructions, - CompilationUnit* comp_unit, Library* library, - std::string_view macroBody, MacroInfo* macroInfo, - unsigned int embeddedMacroCallLine, - SymbolId embeddedMacroCallFile) - : m_fileId(fileId), +PreprocessFile::PreprocessFile( + SymbolId macroId, CompileSourceFile* csf, SpecialInstructions& instructions, + CompilationUnit* comp_unit, Library* library, PreprocessFile* includer, + unsigned int includerLine, std::string_view macroBody, MacroInfo* macroInfo, + unsigned int embeddedMacroCallLine, PathId embeddedMacroCallFile) + : m_macroId(macroId), m_library(library), m_macroBody(macroBody), + m_includer(includer), + m_includerLine(includerLine), m_compileSourceFile(csf), m_lineCount(0), m_listener(nullptr), @@ -257,10 +261,8 @@ PreprocessFile::PreprocessFile(SymbolId fileId, PreprocessFile* includedIn, m_fileContent(nullptr), m_verilogVersion(VerilogVersion::NoVersion) { setDebug(m_compileSourceFile->m_commandLineParser->getDebugLevel()); - m_includer = includedIn; - m_includerLine = includerLine; - if (includedIn) { - includedIn->m_includes.push_back(this); + if (m_includer != nullptr) { + m_includer->m_includes.push_back(this); } } @@ -273,14 +275,11 @@ std::string PreprocessFile::getSymbol(SymbolId id) const { return getCompileSourceFile()->getSymbolTable()->getSymbol(id); } -fs::path PreprocessFile::getFileName(unsigned int line) { - return getSymbol(getFileId(line)); -} - SymbolId PreprocessFile::getMacroSignature() { - std::string macroSignature = getSymbol(m_fileId); + std::string macroSignature = getSymbol(m_macroId); if (m_macroInfo) { - macroSignature += "|" + getSymbol(m_macroInfo->m_file); + macroSignature += + "|" + FileSystem::getInstance()->toPath(m_macroInfo->m_fileId).string(); macroSignature += "|" + std::to_string(m_macroInfo->m_startLine); } macroSignature += "|" + m_macroBody; @@ -288,8 +287,6 @@ SymbolId PreprocessFile::getMacroSignature() { return sigId; } -PreprocessFile::PreprocessFile(const PreprocessFile& orig) {} - PreprocessFile::~PreprocessFile() { delete m_listener; if (!m_instructions.m_persist) { @@ -315,36 +312,45 @@ static size_t LinesCount(std::string_view s) { } bool PreprocessFile::preprocess() { - m_result = ""; - fs::path fileName = getSymbol(m_fileId); - Precompiled* prec = Precompiled::getSingleton(); - fs::path root = FileUtils::basename(fileName); + m_result.clear(); + Timer tmr; + fs::path fileName; + std::string macroName; bool precompiled = false; - if (prec->isFilePrecompiled(root)) precompiled = true; + SymbolId macroSignatureId; + FileSystem* const fileSystem = FileSystem::getInstance(); CommandLineParser* clp = getCompileSourceFile()->getCommandLineParser(); - Timer tmr; - PPCache cache(this); - if (cache.restore(clp->lowMem() || clp->noCacheHash())) { - if (clp->debugCache()) { - if (m_macroBody.empty()) { - std::cout << "PP CACHE USED FOR: " << fileName << std::endl; + if (m_macroBody.empty()) { + fileName = fileSystem->toPath(m_fileId); + Precompiled* prec = Precompiled::getSingleton(); + fs::path root = FileUtils::basename(fileName); + if (prec->isFilePrecompiled(root.string())) precompiled = true; + PPCache cache(this); + if (cache.restore(clp->lowMem() || clp->noCacheHash())) { + m_usingCachedVersion = true; + getCompilationUnit()->setCurrentTimeInfo(getFileId(0)); + if (m_debugAstModel && !precompiled) + std::cout << m_fileContent->printObjects(); + if (precompiled || clp->noCacheHash()) { + if (clp->debugCache()) { + std::cout << "PP CACHE USED FOR: " << fileName << std::endl; + } + return true; + } + if (!clp->parseOnly() && !clp->lowMem()) { + resetIncludeFileInfo(); } } - m_usingCachedVersion = true; - getCompilationUnit()->setCurrentTimeInfo(getFileId(0)); - if (m_debugAstModel && !precompiled) - std::cout << m_fileContent->printObjects(); - if (precompiled || clp->noCacheHash()) { - return true; - } - if (!clp->parseOnly() && !clp->lowMem()) { - resetIncludeFileInfo(); - } + } else { + macroName = getSymbol(m_macroId); + macroSignatureId = getMacroSignature(); } if (clp->parseOnly() || clp->lowMem() || clp->link()) return true; - m_antlrParserHandler = getCompileSourceFile()->getAntlrPpHandlerForId( - (m_macroBody.empty()) ? m_fileId : getMacroSignature()); + m_antlrParserHandler = + m_macroBody.empty() + ? getCompileSourceFile()->getAntlrPpHandlerForId(m_fileId) + : getCompileSourceFile()->getAntlrPpHandlerForId(macroSignatureId); if (m_antlrParserHandler == nullptr) { m_antlrParserHandler = new AntlrParserHandler(); @@ -365,7 +371,7 @@ bool PreprocessFile::preprocess() { addError(err); } else { Location includeFile(m_includer->m_fileId, m_includerLine, 0, - m_fileId); + (SymbolId)m_fileId); Error err(ErrorDefinition::PP_CANNOT_OPEN_INCLUDE_FILE, includeFile); addError(err); } @@ -426,7 +432,7 @@ bool PreprocessFile::preprocess() { loc = file; } else { Location includeFile(m_includer->m_fileId, m_includerLine, 0, - m_fileId); + (SymbolId)m_fileId); loc = includeFile; } Error err(ErrorDefinition::PP_CANNOT_READ_FILE_CONTENT, loc); @@ -437,7 +443,7 @@ bool PreprocessFile::preprocess() { m_antlrParserHandler->m_errorListener = new PreprocessFile::DescriptiveErrorListener( this, (m_macroBody.empty()) ? fileName.string() - : "in macro " + fileName.string()); + : "in macro " + macroName); m_antlrParserHandler->m_pplexer = new SV3_1aPpLexer(m_antlrParserHandler->m_inputStream); m_antlrParserHandler->m_pplexer->removeErrorListeners(); @@ -472,13 +478,13 @@ bool PreprocessFile::preprocess() { m_antlrParserHandler->m_pptree = m_antlrParserHandler->m_ppparser->top_level_rule(); - if (getCompileSourceFile()->getCommandLineParser()->profile()) { + if (m_macroBody.empty() && + getCompileSourceFile()->getCommandLineParser()->profile()) { m_profileInfo += "PP SSL Parsing: " + StringUtils::to_string(tmr.elapsed_rounded()) + "s " + fileName.string() + "\n"; tmr.reset(); } - } catch (ParseCancellationException& pex) { m_antlrParserHandler->m_pptokens->reset(); m_antlrParserHandler->m_ppparser->reset(); @@ -492,7 +498,8 @@ bool PreprocessFile::preprocess() { m_antlrParserHandler->m_pptree = m_antlrParserHandler->m_ppparser->top_level_rule(); - if (getCompileSourceFile()->getCommandLineParser()->profile()) { + if (m_macroBody.empty() && + getCompileSourceFile()->getCommandLineParser()->profile()) { m_profileInfo += "PP LL Parsing: " + StringUtils::to_string(tmr.elapsed_rounded()) + "s " + fileName.string() + "\n"; @@ -507,11 +514,15 @@ bool PreprocessFile::preprocess() { << std::endl << std::endl; - getCompileSourceFile()->registerAntlrPpHandlerForId( - (m_macroBody.empty()) ? m_fileId : getMacroSignature(), - m_antlrParserHandler); + if (m_macroBody.empty()) { + getCompileSourceFile()->registerAntlrPpHandlerForId(m_fileId, + m_antlrParserHandler); + } else { + getCompileSourceFile()->registerAntlrPpHandlerForId(macroSignatureId, + m_antlrParserHandler); + } } - m_result = ""; + m_result.clear(); m_lineCount = 0; delete m_listener; m_listener = new SV3_1aPpTreeShapeListener( @@ -533,7 +544,7 @@ unsigned int PreprocessFile::getSumLineCount() { int PreprocessFile::addIncludeFileInfo( IncludeFileInfo::Context context, unsigned int sectionStartLine, - SymbolId sectionFile, unsigned int originalStartLine, + PathId sectionFile, unsigned int originalStartLine, unsigned int originalStartColumn, unsigned int originalEndLine, unsigned int originalEndColumn, IncludeFileInfo::Action action, int indexOpening /* = 0 */, int indexClosing /* = 0 */) { @@ -612,6 +623,7 @@ void PreprocessFile::recordMacro(const std::string& name, } std::string PreprocessFile::reportIncludeInfo() const { + FileSystem* const fileSystem = FileSystem::getInstance(); std::ostringstream strm; for (auto const& info : m_includeFileInfo) { const char* const context = @@ -620,13 +632,14 @@ std::string PreprocessFile::reportIncludeInfo() const { (info.m_action == IncludeFileInfo::Action::PUSH) ? "in" : "out"; strm << context << " " << info.m_originalStartLine << "," << info.m_originalStartColumn << ":" << info.m_originalEndLine << "," - << info.m_originalEndColumn << " " << getSymbol(info.m_sectionFile) - << " " << info.m_sectionStartLine << " " << action << std::endl; + << info.m_originalEndColumn << " " + << fileSystem->toPath(info.m_sectionFile).string() << " " + << info.m_sectionStartLine << " " << action << std::endl; } return strm.str(); } -void PreprocessFile::recordMacro(const std::string& name, SymbolId fileId, +void PreprocessFile::recordMacro(const std::string& name, PathId fileId, unsigned int startLine, unsigned short int startColumn, unsigned int endLine, @@ -701,7 +714,7 @@ void PreprocessFile::checkMacroArguments_( } } -SymbolId PreprocessFile::getIncluderFileId(unsigned int line) const { +PathId PreprocessFile::getIncluderFileId(unsigned int line) const { const PreprocessFile* tmp = this; while (tmp->m_includer != nullptr) { tmp = tmp->m_includer; @@ -746,13 +759,12 @@ std::string PreprocessFile::evaluateMacroInstance( SpecialInstructions instructions( SpecialInstructions::Mute, SpecialInstructions::Mark, SpecialInstructions::Filter, checkMacroLoop, asisUndefMacro); - PreprocessFile* pp = new PreprocessFile( - BadSymbolId, /* macroArgs */ nullptr, - 0 /* m_includer ? m_includer : callingFile, callingLine */, - m_compileSourceFile, instructions, - m_includer ? m_includer->m_compilationUnit - : callingFile->m_compilationUnit, - callingFile->m_library, macro_instance); + PreprocessFile* pp = + new PreprocessFile(BadSymbolId, m_compileSourceFile, instructions, + m_includer ? m_includer->m_compilationUnit + : callingFile->m_compilationUnit, + callingFile->m_library, /* includer */ nullptr, + /* includerLine */ 0, macro_instance); if (!pp->preprocess()) { result = MacroNotDefined; } else { @@ -768,22 +780,23 @@ std::pair PreprocessFile::evaluateMacro_( PreprocessFile* callingFile, unsigned int callingLine, LoopCheck& loopChecker, MacroInfo* macroInfo, SpecialInstructions& instructions, unsigned int embeddedMacroCallLine, - SymbolId embeddedMacroCallFile) { + PathId embeddedMacroCallFile) { + FileSystem* const fileSystem = FileSystem::getInstance(); std::string result; bool found = false; const std::vector& formal_args = macroInfo->m_arguments; const std::vector& orig_body_tokens = macroInfo->m_tokens; if (instructions.m_check_macro_loop) { - bool loop = loopChecker.addEdge(callingFile->m_fileId, getId(name)); + bool loop = loopChecker.addEdge(callingFile->m_macroId, getId(name)); if (loop) { std::vector loop = loopChecker.reportLoop(); for (const auto& id : loop) { MacroInfo* macroInfo2 = m_compilationUnit->getMacroInfo(getSymbol(id)); if (macroInfo2) { - Location loc(macroInfo2->m_file, macroInfo2->m_startLine, + Location loc(macroInfo2->m_fileId, macroInfo2->m_startLine, macroInfo2->m_startColumn, id); - Location exloc(macroInfo->m_file, macroInfo->m_startLine, + Location exloc(macroInfo->m_fileId, macroInfo->m_startLine, macroInfo->m_startColumn, getId(name)); Error err(ErrorDefinition::PP_RECURSIVE_MACRO_DEFINITION, loc, exloc); addError(err); @@ -820,16 +833,16 @@ std::pair PreprocessFile::evaluateMacro_( if ((actual_args.size() > formal_args.size() && (!m_instructions.m_mute))) { if (formal_args.empty() && (StringUtils::getFirstNonEmptyToken(body_tokens) == "(")) { - Location loc(macroInfo->m_file, macroInfo->m_startLine, + Location loc(macroInfo->m_fileId, macroInfo->m_startLine, macroInfo->m_startColumn + name.size() + 1, getId(name)); Error err(ErrorDefinition::PP_MACRO_HAS_SPACE_BEFORE_ARGS, loc); addError(err); } else if ((!Waiver::macroArgCheck(name)) && !formal_args.empty()) { Location loc(callingFile->getFileId(callingLine), callingFile->getLineNb(callingLine), 0, getId(name)); - Location arg(BadSymbolId, 0, 0, + Location arg(BadPathId, 0, 0, registerSymbol(std::to_string(actual_args.size()))); - Location def(macroInfo->m_file, macroInfo->m_startLine, + Location def(macroInfo->m_fileId, macroInfo->m_startLine, macroInfo->m_startColumn, registerSymbol(std::to_string(formal_args.size()))); std::vector locs = {arg, def}; @@ -855,7 +868,7 @@ std::pair PreprocessFile::evaluateMacro_( } if (!empty_actual) { if (actual_args[i] == SymbolTable::getEmptyMacroMarker()) { - actual_args[i] = ""; + actual_args[i].clear(); } const std::string pattern = "`" + formal; @@ -874,49 +887,45 @@ std::pair PreprocessFile::evaluateMacro_( StringUtils::replaceInTokenVector(body_tokens, formal + "``", actual_args[i]); StringUtils::replaceInTokenVector(body_tokens, formal, actual_args[i]); + } else if (formal_arg_default.size() == 2) { + const std::string default_val = + std::regex_replace(formal_arg_default[1], ws_re, ""); + StringUtils::replaceInTokenVector(body_tokens, {"``", formal, "``"}, + default_val); + StringUtils::replaceInTokenVector(body_tokens, "``" + formal + "``", + default_val); + StringUtils::replaceInTokenVector(body_tokens, {formal, "``"}, + default_val); + StringUtils::replaceInTokenVector(body_tokens, {"``", formal}, + default_val); + StringUtils::replaceInTokenVector(body_tokens, {formal, " ", "``"}, + default_val); + StringUtils::replaceInTokenVector(body_tokens, formal + "``", + default_val); + StringUtils::replaceInTokenVector(body_tokens, formal, default_val); } else { - if (formal_arg_default.size() == 2) { - const std::string default_val = - std::regex_replace(formal_arg_default[1], ws_re, ""); - StringUtils::replaceInTokenVector(body_tokens, {"``", formal, "``"}, - default_val); - StringUtils::replaceInTokenVector(body_tokens, "``" + formal + "``", - default_val); - StringUtils::replaceInTokenVector(body_tokens, {formal, "``"}, - default_val); - StringUtils::replaceInTokenVector(body_tokens, {"``", formal}, - default_val); - StringUtils::replaceInTokenVector(body_tokens, {formal, " ", "``"}, - default_val); - StringUtils::replaceInTokenVector(body_tokens, formal + "``", - default_val); - StringUtils::replaceInTokenVector(body_tokens, formal, default_val); - } else { - StringUtils::replaceInTokenVector(body_tokens, {"``", formal, "``"}, - ""); - StringUtils::replaceInTokenVector(body_tokens, "``" + formal + "``", - ""); - StringUtils::replaceInTokenVector(body_tokens, {formal, "``"}, ""); - StringUtils::replaceInTokenVector(body_tokens, {"``", formal}, ""); - StringUtils::replaceInTokenVector(body_tokens, {formal, " ", "``"}, ""); - StringUtils::replaceInTokenVector(body_tokens, formal + "``", ""); - StringUtils::replaceInTokenVector(body_tokens, formal, ""); - - if ((int)i > (int)(((int)actual_args.size()) - 1)) { - if (!instructions.m_mute) { - Location loc(callingFile->getFileId(callingLine), - callingFile->getLineNb(callingLine), 0, getId(name)); - SymbolId id = - registerSymbol(std::to_string(i + 1) + " (" + formal + ")"); - Location arg(BadSymbolId, 0, 0, id); - Location def(macroInfo->m_file, macroInfo->m_startLine, - macroInfo->m_startColumn, id); - std::vector locs = {arg, def}; - Error err(ErrorDefinition::PP_MACRO_NO_DEFAULT_VALUE, loc, &locs); - addError(err); - } - incorrectArgNb = true; + StringUtils::replaceInTokenVector(body_tokens, {"``", formal, "``"}, ""); + StringUtils::replaceInTokenVector(body_tokens, "``" + formal + "``", ""); + StringUtils::replaceInTokenVector(body_tokens, {formal, "``"}, ""); + StringUtils::replaceInTokenVector(body_tokens, {"``", formal}, ""); + StringUtils::replaceInTokenVector(body_tokens, {formal, " ", "``"}, ""); + StringUtils::replaceInTokenVector(body_tokens, formal + "``", ""); + StringUtils::replaceInTokenVector(body_tokens, formal, ""); + + if ((int)i > (int)(((int)actual_args.size()) - 1)) { + if (!instructions.m_mute) { + Location loc(callingFile->getFileId(callingLine), + callingFile->getLineNb(callingLine), 0, getId(name)); + SymbolId id = + registerSymbol(std::to_string(i + 1) + " (" + formal + ")"); + Location arg(id); + Location def(macroInfo->m_fileId, macroInfo->m_startLine, + macroInfo->m_startColumn, id); + std::vector locs = {arg, def}; + Error err(ErrorDefinition::PP_MACRO_NO_DEFAULT_VALUE, loc, &locs); + addError(err); } + incorrectArgNb = true; } } } @@ -970,7 +979,7 @@ std::pair PreprocessFile::evaluateMacro_( if (body_short.find('`') != std::string::npos) { // Recursively resolve macro instantiation within the macro if (m_debugMacro) { - const fs::path fileName = getSymbol(m_fileId); + const fs::path fileName = fileSystem->toPath(m_fileId); std::cout << "PP BODY EXPANSION FOR " << name << " in : " << fileName << std::endl; for (const auto& arg : actual_args) { @@ -983,13 +992,12 @@ std::pair PreprocessFile::evaluateMacro_( SpecialInstructions::Filter, m_instructions.m_check_macro_loop, m_instructions.m_as_is_undefined_macro); PreprocessFile* pp = new PreprocessFile( - macroId, callingFile ? callingFile : m_includer, callingLine, - m_compileSourceFile, instructions, + macroId, m_compileSourceFile, instructions, callingFile ? callingFile->m_compilationUnit : m_includer->m_compilationUnit, callingFile ? callingFile->m_library : m_includer->m_library, - body_short, macroInfo, embeddedMacroCallLine - 1, - embeddedMacroCallFile); + callingFile ? callingFile : m_includer, callingLine, body_short, + macroInfo, embeddedMacroCallLine - 1, embeddedMacroCallFile); getCompileSourceFile()->registerPP(pp); if (!pp->preprocess()) { result = MacroNotDefined; @@ -1000,7 +1008,8 @@ std::pair PreprocessFile::evaluateMacro_( pp_result = std::regex_replace( pp_result, std::regex(PP__File__Marking), "\"" + - FileUtils::getFullPath(callingFile->getFileName(callingLine)) + FileUtils::getFullPath( + fileSystem->toPath(callingFile->getFileId(callingLine))) .string() + "\""); pp_result = std::regex_replace(pp_result, std::regex(PP__Line__Marking), @@ -1103,7 +1112,7 @@ std::string PreprocessFile::getMacro( const std::string& name, std::vector& arguments, PreprocessFile* callingFile, unsigned int callingLine, LoopCheck& loopChecker, SpecialInstructions& instructions, - unsigned int embeddedMacroCallLine, SymbolId embeddedMacroCallFile) { + unsigned int embeddedMacroCallLine, PathId embeddedMacroCallFile) { SymbolId macroId = registerSymbol(name); if (m_debugMacro) { std::cout << "PP CALL TO getMacro for " << name << "\n"; @@ -1138,7 +1147,7 @@ std::string PreprocessFile::getMacro( } else { if (info) { found = true; - result = ""; + result.clear(); } } } @@ -1154,10 +1163,10 @@ std::string PreprocessFile::getMacro( } } -SymbolId PreprocessFile::getFileId(unsigned int line) const { +PathId PreprocessFile::getFileId(unsigned int line) const { const unsigned int size = m_lineTranslationVec.size(); if (isMacroBody() && m_macroInfo) { - return m_macroInfo->m_file; + return m_macroInfo->m_fileId; } else { if (size) { if (size == 1) { @@ -1208,9 +1217,9 @@ std::string PreprocessFile::getPreProcessedFileContent() { break; } } - if (!nonEmpty) m_result = ""; + if (!nonEmpty) m_result.clear(); if (m_debugPPResult) { - const fs::path fileName = getSymbol(m_fileId); + const fs::path fileName = FileSystem::getInstance()->toPath(m_fileId); std::string objName = (!m_macroBody.empty()) ? "macro " + m_macroBody : "file " + fileName.string(); std::cout << "PP RESULT for " << objName diff --git a/src/SourceCompile/PreprocessHarness.cpp b/src/SourceCompile/PreprocessHarness.cpp index bebb47d3ae..fcc29099a0 100644 --- a/src/SourceCompile/PreprocessHarness.cpp +++ b/src/SourceCompile/PreprocessHarness.cpp @@ -48,11 +48,11 @@ std::string PreprocessHarness::preprocess(std::string_view content, CommandLineParser clp(&m_errors, &m_symbols, false, false); Library lib("work", &m_symbols); Compiler compiler(&clp, &m_errors, &m_symbols); - CompileSourceFile csf(BadSymbolId, &clp, &m_errors, &compiler, &m_symbols, + CompileSourceFile csf(BadPathId, &clp, &m_errors, &compiler, &m_symbols, compUnit ? compUnit : &unit, &lib); - PreprocessFile pp(BadSymbolId, nullptr, 0, &csf, instructions, - compUnit ? compUnit : &unit, &lib, content, nullptr, 0, - BadSymbolId); + PreprocessFile pp(BadSymbolId, &csf, instructions, + compUnit ? compUnit : &unit, &lib, nullptr, 0, content, + nullptr, 0, BadPathId); if (!pp.preprocess()) { result = "ERROR_PP"; diff --git a/src/SourceCompile/SV3_1aPpTreeListenerHelper.cpp b/src/SourceCompile/SV3_1aPpTreeListenerHelper.cpp index 9a852f812a..72f8faf098 100644 --- a/src/SourceCompile/SV3_1aPpTreeListenerHelper.cpp +++ b/src/SourceCompile/SV3_1aPpTreeListenerHelper.cpp @@ -41,7 +41,7 @@ SymbolId SV3_1aPpTreeListenerHelper::registerSymbol(std::string_view symbol) { std::tuple SV3_1aPpTreeListenerHelper::getFileLine(antlr4::ParserRuleContext* ctx, - SymbolId& fileId) { + PathId& fileId) { std::pair lineCol = ParseUtils::getLineColumn(m_tokens, ctx); std::pair endLineCol = ParseUtils::getEndLineColumn(m_tokens, ctx); unsigned int line = m_pp->getLineNb(lineCol.first); @@ -115,7 +115,7 @@ void SV3_1aPpTreeListenerHelper::logError(ErrorDefinition::ErrorType error, std::pair lineCol = ParseUtils::getLineColumn(m_pp->getTokenStream(), ctx); if (m_pp->getMacroInfo()) { - Location loc(m_pp->getMacroInfo()->m_file, + Location loc(m_pp->getMacroInfo()->m_fileId, m_pp->getMacroInfo()->m_startLine + lineCol.first - 1, lineCol.second, getSymbolTable()->registerSymbol(object)); Location extraLoc(m_pp->getIncluderFileId(m_pp->getIncluderLine()), @@ -177,12 +177,12 @@ void SV3_1aPpTreeListenerHelper::checkMultiplyDefinedMacro( if (macroInf) { std::pair lineCol = ParseUtils::getLineColumn(m_pp->getTokenStream(), ctx); - if ((macroInf->m_file == m_pp->getFileId(lineCol.first)) && + if ((macroInf->m_fileId == m_pp->getFileId(lineCol.first)) && (m_pp->getLineNb(lineCol.first) == macroInf->m_startLine)) return; Location loc(m_pp->getFileId(lineCol.first), m_pp->getLineNb(lineCol.first), lineCol.second, getSymbolTable()->getId(macroName)); - Location extraLoc(macroInf->m_file, macroInf->m_startLine, + Location extraLoc(macroInf->m_fileId, macroInf->m_startLine, macroInf->m_startColumn); logError(ErrorDefinition::PP_MULTIPLY_DEFINED_MACRO, loc, extraLoc); } diff --git a/src/SourceCompile/SV3_1aPpTreeShapeListener.cpp b/src/SourceCompile/SV3_1aPpTreeShapeListener.cpp index 6b1fa6c660..971aedc2f5 100644 --- a/src/SourceCompile/SV3_1aPpTreeShapeListener.cpp +++ b/src/SourceCompile/SV3_1aPpTreeShapeListener.cpp @@ -15,6 +15,7 @@ */ #include +#include #include #include #include @@ -43,11 +44,10 @@ void SV3_1aPpTreeShapeListener::enterTop_level_rule( // TODO: setting m_fileContent should happen at construction time. // This also makes it hard to know who the owner is. if (m_pp->getFileContent() == nullptr) { - m_fileContent = - new FileContent(m_pp->getFileId(0), m_pp->getLibrary(), - m_pp->getCompileSourceFile()->getSymbolTable(), - m_pp->getCompileSourceFile()->getErrorContainer(), - nullptr, BadSymbolId); + m_fileContent = new FileContent( + m_pp->getFileId(0), m_pp->getLibrary(), + m_pp->getCompileSourceFile()->getSymbolTable(), + m_pp->getCompileSourceFile()->getErrorContainer(), nullptr, BadPathId); m_pp->setFileContent(m_fileContent); m_pp->getCompileSourceFile()->getCompiler()->getDesign()->addPPFileContent( m_pp->getFileId(0), m_fileContent); @@ -215,6 +215,7 @@ void SV3_1aPpTreeShapeListener::enterUnterminated_string( void SV3_1aPpTreeShapeListener::enterInclude_directive( SV3_1aPpParser::Include_directiveContext *ctx) { + FileSystem *const fileSystem = FileSystem::getInstance(); if (m_inActiveBranch && (!m_inMacroDefinitionParsing)) { std::pair startLineCol = ParseUtils::getLineColumn(m_pp->getTokenStream(), ctx); @@ -246,14 +247,13 @@ void SV3_1aPpTreeShapeListener::enterInclude_directive( if (m_pp->m_debugPP) std::cout << "PP INCLUDE DIRECTIVE " << fileName << std::endl; - SymbolId fileId = getSymbolTable()->registerSymbol(fileName); - const SymbolId locfileId = - FileUtils::locateFile(fileId, getSymbolTable(), - m_pp->getCompileSourceFile() - ->getCommandLineParser() - ->getIncludePaths()); + PathId fileId = fileSystem->toPathId(fileName, getSymbolTable()); + const PathId locfileId = FileUtils::locateFile(fileId, getSymbolTable(), + m_pp->getCompileSourceFile() + ->getCommandLineParser() + ->getIncludePaths()); if (locfileId) { - fileName = getSymbolTable()->getSymbol(locfileId); + fileName = fileSystem->toPath(locfileId).string(); fileId = locfileId; } @@ -267,7 +267,7 @@ void SV3_1aPpTreeShapeListener::enterInclude_directive( while (tmp) { if (tmp->getFileId(0) == fileId) { Location loc(m_pp->getFileId(startLineCol.first), startLineCol.first, - startLineCol.second, fileId); + startLineCol.second, (SymbolId)fileId); logError(ErrorDefinition::PP_RECURSIVE_INCLUDE_DIRECTIVE, loc, true); return; } @@ -284,9 +284,10 @@ void SV3_1aPpTreeShapeListener::enterInclude_directive( /* originalEndColumn */ endLineCol.second, /* action */ IncludeFileInfo::Action::PUSH); - PreprocessFile *pp = new PreprocessFile( - fileId, m_pp, startLineCol.first, m_pp->getCompileSourceFile(), - m_instructions, m_pp->getCompilationUnit(), m_pp->getLibrary()); + PreprocessFile *pp = + new PreprocessFile(fileId, m_pp->getCompileSourceFile(), m_instructions, + m_pp->getCompilationUnit(), m_pp->getLibrary(), m_pp, + startLineCol.first); m_pp->getCompileSourceFile()->registerPP(pp); if (!pp->preprocess()) { return; @@ -310,23 +311,26 @@ void SV3_1aPpTreeShapeListener::enterInclude_directive( ->lineOffsetsAsComments()) { post = "\n/* SLline " + std::to_string(info->m_startLine + startLineCol.first) + - " \"" + getSymbolTable()->getSymbol(info->m_file) + + " \"" + fileSystem->toPath(info->m_fileId).string() + "\" 0 */\n"; } else { post = "\n`line " + std::to_string(info->m_startLine + startLineCol.first) + - " \"" + getSymbolTable()->getSymbol(info->m_file) + "\" 0\n"; + " \"" + fileSystem->toPath(info->m_fileId).string() + "\" 0\n"; } } else { if (m_pp->getCompileSourceFile() ->getCommandLineParser() ->lineOffsetsAsComments()) { - post = "\n/* SLline " + std::to_string(startLineCol.first + 1) + - " \"" + m_pp->getFileName(startLineCol.first).string() + - "\" 2 */\n"; + post = + "\n/* SLline " + std::to_string(startLineCol.first + 1) + " \"" + + fileSystem->toPath(m_pp->getFileId(startLineCol.first)).string() + + "\" 2 */\n"; } else { - post = "\n`line " + std::to_string(startLineCol.first + 1) + " \"" + - m_pp->getFileName(startLineCol.first).string() + "\" 2\n"; + post = + "\n`line " + std::to_string(startLineCol.first + 1) + " \"" + + fileSystem->toPath(m_pp->getFileId(startLineCol.first)).string() + + "\" 2\n"; } } } @@ -428,6 +432,7 @@ void SV3_1aPpTreeShapeListener::exitSimple_no_args_macro_definition( void SV3_1aPpTreeShapeListener::enterMacroInstanceWithArgs( SV3_1aPpParser::MacroInstanceWithArgsContext *ctx) { + FileSystem *const fileSystem = FileSystem::getInstance(); if (m_inActiveBranch && (!m_inMacroDefinitionParsing)) { std::pair startLineCol = ParseUtils::getLineColumn(m_pp->getTokenStream(), ctx); @@ -464,13 +469,13 @@ void SV3_1aPpTreeShapeListener::enterMacroInstanceWithArgs( unsigned int lineSum = m_pp->getSumLineCount() + 1; openingIndex = m_pp->getSourceFile()->addIncludeFileInfo( IncludeFileInfo::Context::MACRO, macroInf->m_startLine, - macroInf->m_file, lineSum, startLineCol.second, + macroInf->m_fileId, lineSum, startLineCol.second, lineSum + (endLineCol.first - startLineCol.first), endLineCol.second, IncludeFileInfo::Action::PUSH); macroBody = m_pp->getMacro( macroName, actualArgs, m_pp, startLineCol.first, m_pp->getSourceFile()->m_loopChecker, m_pp->m_instructions, - macroInf->m_startLine, macroInf->m_file); + macroInf->m_startLine, macroInf->m_fileId); } else { macroBody = m_pp->getMacro( macroName, actualArgs, m_pp, startLineCol.first, @@ -490,9 +495,11 @@ void SV3_1aPpTreeShapeListener::enterMacroInstanceWithArgs( if (!m_pp->m_instructions.m_filterFileLine) { if (startLineCol.second == 0) { pre = "`line " + std::to_string(macroInf->m_startLine) + " \"" + - getSymbolTable()->getSymbol(macroInf->m_file) + "\" 0"; - post = "`line " + std::to_string(startLineCol.first + 1) + " \"" + - m_pp->getFileName(startLineCol.first).string() + "\" 0"; + fileSystem->toPath(macroInf->m_fileId).string() + "\" 0"; + post = + "`line " + std::to_string(startLineCol.first + 1) + " \"" + + fileSystem->toPath(m_pp->getFileId(startLineCol.first)).string() + + "\" 0"; if (m_pp->getCompileSourceFile() ->getCommandLineParser() ->lineOffsetsAsComments()) { @@ -521,7 +528,7 @@ void SV3_1aPpTreeShapeListener::enterMacroInstanceWithArgs( } if (openingIndex >= 0) { - SymbolId fileId; + PathId fileId; unsigned int line = 0; if (m_pp->getEmbeddedMacroCallFile()) { fileId = m_pp->getEmbeddedMacroCallFile(); @@ -573,6 +580,7 @@ void SV3_1aPpTreeShapeListener::exitMacroInstanceWithArgs( void SV3_1aPpTreeShapeListener::enterMacroInstanceNoArgs( SV3_1aPpParser::MacroInstanceNoArgsContext *ctx) { + FileSystem *const fileSystem = FileSystem::getInstance(); if (m_inActiveBranch && (!m_inMacroDefinitionParsing)) { std::string macroName; std::pair startLineCol = @@ -605,7 +613,7 @@ void SV3_1aPpTreeShapeListener::enterMacroInstanceNoArgs( Location loc(m_pp->getFileId(startLineCol.first), m_pp->getLineNb(startLineCol.first), startLineCol.second, getSymbolTable()->getId(macroName)); - Location extraLoc(macroInf->m_file, macroInf->m_startLine, + Location extraLoc(macroInf->m_fileId, macroInf->m_startLine, macroInf->m_startColumn); logError(ErrorDefinition::PP_MACRO_PARENTHESIS_NEEDED, loc, extraLoc); } @@ -613,13 +621,13 @@ void SV3_1aPpTreeShapeListener::enterMacroInstanceNoArgs( unsigned int lineSum = m_pp->getSumLineCount() + 1; openingIndex = m_pp->getSourceFile()->addIncludeFileInfo( IncludeFileInfo::Context::MACRO, macroInf->m_startLine, - macroInf->m_file, lineSum, startLineCol.second, + macroInf->m_fileId, lineSum, startLineCol.second, lineSum + (endLineCol.first - startLineCol.first), endLineCol.second, IncludeFileInfo::Action::PUSH); macroBody = m_pp->getMacro(macroName, args, m_pp, startLineCol.first, m_pp->getSourceFile()->m_loopChecker, m_pp->m_instructions, macroInf->m_startLine, - macroInf->m_file); + macroInf->m_fileId); } else { macroBody = m_pp->getMacro(macroName, args, m_pp, startLineCol.first, m_pp->getSourceFile()->m_loopChecker, @@ -642,11 +650,13 @@ void SV3_1aPpTreeShapeListener::enterMacroInstanceNoArgs( if (macroInf) { if (!m_pp->m_instructions.m_filterFileLine) { if (startLineCol.second == 0) { - if (macroInf->m_file) + if (macroInf->m_fileId) pre = "`line " + std::to_string(macroInf->m_startLine) + " \"" + - getSymbolTable()->getSymbol(macroInf->m_file) + "\" 0"; - post = "`line " + std::to_string(startLineCol.first + 1) + " \"" + - m_pp->getFileName(startLineCol.first).string() + "\" 0"; + fileSystem->toPath(macroInf->m_fileId).string() + "\" 0"; + post = + "`line " + std::to_string(startLineCol.first + 1) + " \"" + + fileSystem->toPath(m_pp->getFileId(startLineCol.first)).string() + + "\" 0"; if (m_pp->getCompileSourceFile() ->getCommandLineParser() ->lineOffsetsAsComments()) { @@ -664,7 +674,7 @@ void SV3_1aPpTreeShapeListener::enterMacroInstanceNoArgs( m_pp->append(pre + macroBody + post); if (openingIndex >= 0) { - SymbolId fileId; + PathId fileId; unsigned int line = 0; if (m_pp->getEmbeddedMacroCallFile()) { fileId = m_pp->getEmbeddedMacroCallFile(); @@ -736,13 +746,16 @@ void SV3_1aPpTreeShapeListener::exitPragma_directive( void SV3_1aPpTreeShapeListener::enterSv_file_directive( SV3_1aPpParser::Sv_file_directiveContext *ctx) { + FileSystem *const fileSystem = FileSystem::getInstance(); if (m_inActiveBranch && (!m_inMacroDefinitionParsing)) { if (m_pp->getMacroInfo()) { m_pp->append(PreprocessFile::PP__File__Marking); } else { std::pair lineCol = ParseUtils::getLineColumn(m_pp->getTokenStream(), ctx); - m_pp->append("\"" + m_pp->getFileName(lineCol.first).string() + "\""); + m_pp->append("\"" + + fileSystem->toPath(m_pp->getFileId(lineCol.first)).string() + + "\""); } } m_pp->pauseAppend(); @@ -768,13 +781,14 @@ void SV3_1aPpTreeShapeListener::enterSv_line_directive( void SV3_1aPpTreeShapeListener::enterLine_directive( SV3_1aPpParser::Line_directiveContext *ctx) { + FileSystem *const fileSystem = FileSystem::getInstance(); std::pair lineCol = ParseUtils::getLineColumn(m_pp->getTokenStream(), ctx); std::string fileName; if (ctx->String()) fileName = StringUtils::unquoted(ctx->String()->getText()); std::string number; if (!ctx->number().empty()) number = ctx->number()[0]->getText(); - SymbolId newFileId = getSymbolTable()->registerSymbol(fileName); + PathId newFileId = fileSystem->toPathId(fileName, getSymbolTable()); if (ctx->number().size() > 1) { std::string type = ctx->number()[1]->getText(); int newType = atoi(type.c_str()); diff --git a/src/SourceCompile/SV3_1aTreeShapeHelper.cpp b/src/SourceCompile/SV3_1aTreeShapeHelper.cpp index ffb6e92b10..3ab6f4c230 100644 --- a/src/SourceCompile/SV3_1aTreeShapeHelper.cpp +++ b/src/SourceCompile/SV3_1aTreeShapeHelper.cpp @@ -108,7 +108,7 @@ SymbolId SV3_1aTreeShapeHelper::registerSymbol(std::string_view symbol) { void SV3_1aTreeShapeHelper::addNestedDesignElement( antlr4::ParserRuleContext* ctx, std::string_view name, DesignElement::ElemType elemtype, VObjectType objtype) { - SymbolId fileId; + PathId fileId; auto [line, column, endLine, endColumn] = getFileLine(ctx, fileId); std::string design_element = m_pf->getLibrary()->getName() + "@"; design_element.append(name); @@ -132,7 +132,7 @@ void SV3_1aTreeShapeHelper::addDesignElement(antlr4::ParserRuleContext* ctx, std::string_view name, DesignElement::ElemType elemtype, VObjectType objtype) { - SymbolId fileId; + PathId fileId; auto [line, column, endLine, endColumn] = getFileLine(ctx, fileId); std::string design_element = m_pf->getLibrary()->getName() + "@"; design_element.append(name); @@ -150,7 +150,7 @@ void SV3_1aTreeShapeHelper::addDesignElement(antlr4::ParserRuleContext* ctx, std::tuple SV3_1aTreeShapeHelper::getFileLine(antlr4::ParserRuleContext* ctx, - SymbolId& fileId) { + PathId& fileId) { std::pair lineCol = ParseUtils::getLineColumn(m_tokens, ctx); std::pair endLineCol = ParseUtils::getEndLineColumn(m_tokens, ctx); unsigned int line = 0; diff --git a/src/SourceCompile/SV3_1aTreeShapeListener.cpp b/src/SourceCompile/SV3_1aTreeShapeListener.cpp index e01562e5db..44a13365d8 100644 --- a/src/SourceCompile/SV3_1aTreeShapeListener.cpp +++ b/src/SourceCompile/SV3_1aTreeShapeListener.cpp @@ -22,6 +22,7 @@ */ #include +#include #include #include #include @@ -39,11 +40,10 @@ namespace SURELOG { void SV3_1aTreeShapeListener::enterTop_level_rule( SV3_1aParser::Top_level_ruleContext * /*ctx*/) { if (m_pf->getFileContent() == nullptr) { - m_fileContent = - new FileContent(m_pf->getFileId(0), m_pf->getLibrary(), - m_pf->getCompileSourceFile()->getSymbolTable(), - m_pf->getCompileSourceFile()->getErrorContainer(), - nullptr, BadSymbolId); + m_fileContent = new FileContent( + m_pf->getFileId(0), m_pf->getLibrary(), + m_pf->getCompileSourceFile()->getSymbolTable(), + m_pf->getCompileSourceFile()->getErrorContainer(), nullptr, BadPathId); m_pf->setFileContent(m_fileContent); m_pf->getCompileSourceFile()->getCompiler()->getDesign()->addFileContent( m_pf->getFileId(0), m_fileContent); @@ -63,7 +63,7 @@ void SV3_1aTreeShapeListener::enterTop_level_library_rule( // Visited from Library/SVLibShapeListener.h m_fileContent = new FileContent( m_pf->getFileId(0), m_pf->getLibrary(), m_pf->getSymbolTable(), - m_pf->getErrorContainer(), nullptr, BadSymbolId); + m_pf->getErrorContainer(), nullptr, BadPathId); m_pf->setFileContent(m_fileContent); } @@ -175,6 +175,7 @@ void SV3_1aTreeShapeListener::enterSlline( SV3_1aParser::SllineContext * /*ctx*/) {} void SV3_1aTreeShapeListener::exitSlline(SV3_1aParser::SllineContext *ctx) { + FileSystem *const fileSystem = FileSystem::getInstance(); unsigned int startLine = std::stoi(ctx->Integral_number()[0]->getText()); IncludeFileInfo::Action action = static_cast( std::stoi(ctx->Integral_number()[1]->getText())); @@ -184,17 +185,17 @@ void SV3_1aTreeShapeListener::exitSlline(SV3_1aParser::SllineContext *ctx) { std::pair endLineCol = ParseUtils::getEndLineColumn(m_tokens, ctx); if (action == IncludeFileInfo::Action::PUSH) { // Push - m_includeFileInfo.emplace(IncludeFileInfo::Context::INCLUDE, startLine, - m_pf->getSymbolTable()->registerSymbol(file), - startLineCol.first, startLineCol.second, - endLineCol.first, endLineCol.second, - IncludeFileInfo::Action::PUSH); + m_includeFileInfo.emplace( + IncludeFileInfo::Context::INCLUDE, startLine, + fileSystem->toPathId(file, m_pf->getSymbolTable()), startLineCol.first, + startLineCol.second, endLineCol.first, endLineCol.second, + IncludeFileInfo::Action::PUSH); } else if (action == IncludeFileInfo::Action::POP) { // Pop if (!m_includeFileInfo.empty()) m_includeFileInfo.pop(); if (!m_includeFileInfo.empty()) { IncludeFileInfo &info = m_includeFileInfo.top(); - info.m_sectionFile = m_pf->getSymbolTable()->registerSymbol(file); + info.m_sectionFile = fileSystem->toPathId(file, m_pf->getSymbolTable()); info.m_originalStartLine = startLineCol.first /*+ m_lineOffset */; info.m_originalStartColumn = startLineCol.second /*+ m_lineOffset */; info.m_sectionStartLine = startLine; diff --git a/src/Utils/FileUtils.cpp b/src/Utils/FileUtils.cpp index e622ad5116..31556ddf70 100644 --- a/src/Utils/FileUtils.cpp +++ b/src/Utils/FileUtils.cpp @@ -21,6 +21,7 @@ * Created on March 16, 2017, 11:02 PM */ +#include #include #include #include @@ -60,20 +61,20 @@ bool FileUtils::fileIsRegular(const fs::path& name) { return fs::is_regular_file(name); } -SymbolId FileUtils::locateFile(SymbolId file, SymbolTable* symbols, - const std::vector& paths) { - const fs::path fileName = symbols->getSymbol(file); +PathId FileUtils::locateFile(PathId file, SymbolTable* symbols, + const std::vector& paths) { + FileSystem* const fileSystem = FileSystem::getInstance(); + const fs::path fileName = fileSystem->toPath(file); if (fileExists(fileName)) { - return file; + return fileSystem->toPathId(fileName, symbols); } - for (const auto& id : paths) { - const fs::path path = symbols->getSymbol(id); - fs::path filePath = path / fileName; + for (auto id : paths) { + fs::path filePath = fileSystem->toPath(id) / fileName; if (fileExists(filePath)) { - return symbols->registerSymbol(filePath.string()); + return fileSystem->toPathId(filePath, symbols); } } - return BadSymbolId; + return BadPathId; } bool FileUtils::mkDirs(const fs::path& path) { @@ -107,29 +108,31 @@ bool FileUtils::getFullPath(const fs::path& path, fs::path* result) { return found; } -std::vector FileUtils::collectFiles(SymbolId dirPath, SymbolId ext, - SymbolTable* symbols) { - return collectFiles(symbols->getSymbol(dirPath), symbols->getSymbol(ext), +std::vector FileUtils::collectFiles(PathId dirPath, SymbolId ext, + SymbolTable* symbols) { + FileSystem* const fileSystem = FileSystem::getInstance(); + return collectFiles(fileSystem->toPath(dirPath), symbols->getSymbol(ext), symbols); } -std::vector FileUtils::collectFiles(const fs::path& dirPath, - const fs::path& ext, - SymbolTable* symbols) { - std::vector result; +std::vector FileUtils::collectFiles(const fs::path& dirPath, + const fs::path& ext, + SymbolTable* symbols) { + FileSystem* const fileSystem = FileSystem::getInstance(); + std::vector result; if (fileIsDirectory(dirPath)) { for (const fs::directory_entry& entry : fs::directory_iterator(dirPath)) { const fs::path& filepath = entry.path(); if (filepath.extension() == ext) { - result.push_back(symbols->registerSymbol(filepath.string())); + result.emplace_back(fileSystem->toPathId(filepath, symbols)); } } } return result; } -std::vector FileUtils::collectFiles(const fs::path& pathSpec, - SymbolTable* symbols) { +std::vector FileUtils::collectFiles(const fs::path& pathSpec, + SymbolTable* symbols) { // ? single character wildcard (matches any single character) // * multiple character wildcard (matches any number of characters in a // directory/file name) @@ -140,7 +143,7 @@ std::vector FileUtils::collectFiles(const fs::path& pathSpec, // Identical to / * Paths that do not begin with / are relative to the // directory in which the current lib.map file is located. - std::vector result; + std::vector result; std::error_code ec; fs::path path(pathSpec); @@ -191,6 +194,7 @@ std::vector FileUtils::collectFiles(const fs::path& pathSpec, fs::directory_options::skip_permission_denied | fs::directory_options::follow_directory_symlink; + FileSystem* const fileSystem = FileSystem::getInstance(); for (const fs::directory_entry& entry : fs::recursive_directory_iterator(prefix, options)) { if (fs::is_regular_file(entry.path())) { @@ -198,7 +202,7 @@ std::vector FileUtils::collectFiles(const fs::path& pathSpec, entry.path().string().substr(prefix.string().length() + 1); std::smatch match; if (!ec && std::regex_match(relative, match, regex)) { - result.push_back(symbols->registerSymbol(entry.path().string())); + result.emplace_back(fileSystem->toPathId(entry.path(), symbols)); } } } diff --git a/src/Utils/FileUtils_test.cpp b/src/Utils/FileUtils_test.cpp index 0fbedc92df..baaaada22b 100644 --- a/src/Utils/FileUtils_test.cpp +++ b/src/Utils/FileUtils_test.cpp @@ -14,6 +14,7 @@ limitations under the License. */ +#include #include #include #include @@ -28,6 +29,11 @@ namespace SURELOG { namespace fs = std::filesystem; namespace { +class TestFileSystem : public FileSystem { + public: + TestFileSystem() : FileSystem(fs::current_path()) {} +}; + TEST(FileUtilsTest, BasicFileOperations) { const std::string dirtest = testing::TempDir() + "/file-exist-dir"; const std::string basename = "file-exists-test.txt"; @@ -66,6 +72,7 @@ TEST(FileUtilsTest, BasicFileOperations) { } TEST(FileUtilsTest, LocateFile) { + TestFileSystem fileSystem; SymbolTable sym; const std::string search_file = "search-file.txt"; @@ -77,26 +84,26 @@ TEST(FileUtilsTest, LocateFile) { FileUtils::mkDirs(path1); FileUtils::mkDirs(actual_dir); - std::vector paths = { - sym.registerSymbol(path1.string()), - sym.registerSymbol(path2.string()), - sym.registerSymbol(actual_dir.string()), + std::vector paths = { + fileSystem.toPathId(path1, &sym), + fileSystem.toPathId(path2, &sym), + fileSystem.toPathId(actual_dir, &sym), }; - SymbolId search_file_id = sym.registerSymbol(search_file); + PathId search_file_id = fileSystem.toPathId(search_file, &sym); // At this point, the file does not exist yet. - SymbolId non_exist = FileUtils::locateFile(search_file_id, &sym, paths); - EXPECT_EQ(non_exist, BadSymbolId); + PathId non_exist = FileUtils::locateFile(search_file_id, &sym, paths); + EXPECT_EQ(non_exist, BadPathId); const fs::path actual_loc = actual_dir / search_file; std::ofstream(actual_loc).close(); - SymbolId now_exists = FileUtils::locateFile(search_file_id, &sym, paths); - EXPECT_NE(now_exists, BadSymbolId); - EXPECT_EQ(sym.getSymbol(now_exists), actual_loc); + PathId now_exists = FileUtils::locateFile(search_file_id, &sym, paths); + EXPECT_NE(now_exists, BadPathId); + EXPECT_EQ(fileSystem.toPath(now_exists), actual_loc); - SymbolId already_found = FileUtils::locateFile(now_exists, &sym, paths); + PathId already_found = FileUtils::locateFile(now_exists, &sym, paths); EXPECT_EQ(already_found, now_exists); FileUtils::rmDirRecursively(basedir); diff --git a/src/hellosureworld.cpp b/src/hellosureworld.cpp index 03664fbc9c..d3b9826d1c 100644 --- a/src/hellosureworld.cpp +++ b/src/hellosureworld.cpp @@ -25,6 +25,7 @@ // cd tests/UnitElabBlock // hellouhdm top.v -parse -mutestdout +#include #include #include @@ -57,8 +58,11 @@ int main(int argc, const char** argv) { for (auto& top : the_design->getTopLevelModuleInstances()) { std::function inst_visit = [&inst_visit](SURELOG::ModuleInstance* inst) { + SURELOG::FileSystem* const fileSystem = + SURELOG::FileSystem::getInstance(); std::cout << "Inst: " << inst->getFullPathName() << std::endl; - std::cout << "File: " << inst->getFileName() << std::endl; + std::cout << "File: " << fileSystem->toPath(inst->getFileId()) + << std::endl; for (unsigned int i = 0; i < inst->getNbChildren(); i++) { inst_visit(inst->getChildren(i)); } diff --git a/src/main.cpp b/src/main.cpp index 740c18a57a..ad6a35ccd7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,6 +30,7 @@ #endif #include +#include #include #include #include @@ -54,6 +55,7 @@ constexpr std::string_view output_folder_opt = "-o"; unsigned int executeCompilation( int argc, const char** argv, bool diff_comp_mode, bool fileunit, SURELOG::ErrorContainer::Stats* overallStats = nullptr) { + SURELOG::FileSystem* const fileSystem = SURELOG::FileSystem::getInstance(); bool success = true; bool noFatalErrors = true; unsigned int codedReturn = 0; @@ -98,7 +100,7 @@ unsigned int executeCompilation( std::string ext_command = clp->getExeCommand(); if (!ext_command.empty()) { - fs::path directory = symbolTable->getSymbol(clp->getFullCompileDir()); + fs::path directory = fileSystem->toPath(clp->getFullCompileDirId()); fs::path fileList = directory / "file.lst"; std::string command = ext_command + " " + fileList.string(); int result = system(command.c_str()); diff --git a/src/roundtrip.cpp b/src/roundtrip.cpp index 3a3f7e6e57..dbf8b662af 100644 --- a/src/roundtrip.cpp +++ b/src/roundtrip.cpp @@ -24,6 +24,7 @@ * Created on February 10, 2022, 12:00 PM */ +#include #include #include #include @@ -3447,6 +3448,7 @@ static int run(const std::vector &designHandles, static int run_in_surelog_mode(int argc, const char **argv) { // Read command line, compile a design, use -parse argument int code = 0; + SURELOG::FileSystem *const fileSystem = SURELOG::FileSystem::getInstance(); SURELOG::SymbolTable *const symbolTable = new SURELOG::SymbolTable(); SURELOG::ErrorContainer *const errors = new SURELOG::ErrorContainer(symbolTable); @@ -3475,7 +3477,7 @@ static int run_in_surelog_mode(int argc, const char **argv) { if (vpi_design == nullptr) return code; - std::filesystem::path logDir = symbolTable->getSymbol(clp->getOutputDir()); + std::filesystem::path logDir = fileSystem->toPath(clp->getOutputDirId()); if (logDir.is_relative()) { logDir = std::filesystem::current_path() / logDir; } diff --git a/third_party/UHDM b/third_party/UHDM index cfe60c31d1..2097a15228 160000 --- a/third_party/UHDM +++ b/third_party/UHDM @@ -1 +1 @@ -Subproject commit cfe60c31d133ffd53420fa5a80844bd2dc3dca6a +Subproject commit 2097a15228352f0ee04c3c7da208f042b49a0dc3