Skip to content

Commit

Permalink
Merge pull request #3219 from hs-apotell/pathid
Browse files Browse the repository at this point in the history
IO Abstraction: Introducing PathId & FileSystem (Phase 1)
  • Loading branch information
alaindargelas authored Sep 9, 2022
2 parents 79057e8 + 54896f5 commit 40766f4
Show file tree
Hide file tree
Showing 116 changed files with 2,482 additions and 2,009 deletions.
6 changes: 3 additions & 3 deletions .github/bin/run-clang-tidy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,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
Expand Down Expand Up @@ -698,7 +701,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
Expand Down
13 changes: 8 additions & 5 deletions include/Surelog/API/PythonAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#define SURELOG_PYTHONAPI_H
#pragma once

#include <filesystem>
#include <string>
#include <vector>

Expand Down Expand Up @@ -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<std::string>& args,
Expand All @@ -66,17 +67,19 @@ 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:
PythonAPI(const PythonAPI& orig) = delete;

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;
Expand Down
33 changes: 14 additions & 19 deletions include/Surelog/Cache/Cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
#pragma once

#include <Surelog/Cache/header_generated.h>
#include <Surelog/Common/SymbolId.h>
#include <Surelog/Design/VObject.h>
#include <Surelog/Common/PathId.h>
#include <flatbuffers/flatbuffers.h>

#include <filesystem>
Expand All @@ -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.
Expand All @@ -64,37 +64,32 @@ class Cache {
const std::string& getExecutableTimeStamp();

// Open file and read contents into a buffer.
std::unique_ptr<uint8_t[]> openFlatBuffers(
const std::filesystem::path& cacheFileName);
std::unique_ptr<uint8_t[]> 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<SURELOG::CACHE::Header> 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<VectorOffsetError> 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<Cache::VectorOffsetString> 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);

Expand All @@ -105,20 +100,20 @@ class Cache {
std::vector<CACHE::VObject> 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<const SURELOG::CACHE::VObject*>* objects,
const SymbolTable& cacheSymbols, SymbolTable* localSymbols,
SymbolId fileId, FileContent* fileContent);
const SymbolTable& cacheSymbols, SymbolTable* localSymbols, PathId fileId,
FileContent* fileContent);

void restoreVObjects(
const flatbuffers::Vector<const SURELOG::CACHE::VObject*>* objects,
const SymbolTable& cacheSymbols, SymbolTable* localSymbols,
SymbolId fileId, std::vector<SURELOG::VObject>* result);
const SymbolTable& cacheSymbols, SymbolTable* localSymbols, PathId fileId,
std::vector<SURELOG::VObject>* result);

private:
Cache(const Cache& orig) = delete;
Expand Down
17 changes: 6 additions & 11 deletions include/Surelog/Cache/PPCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

#include <Surelog/Cache/Cache.h>

#include <filesystem>

namespace SURELOG {

class PreprocessFile;
Expand All @@ -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<uint8_t[]>& 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<uint8_t[]>& buffer,
bool errorsOnly, int recursionDepth);
bool checkCacheIsValid_(PathId cacheFileId);
bool checkCacheIsValid_(PathId cacheFileId,
const std::unique_ptr<uint8_t[]>& buffer);

PreprocessFile* m_pp;
Expand Down
11 changes: 3 additions & 8 deletions include/Surelog/Cache/ParseCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

#include <Surelog/Cache/Cache.h>

#include <memory>

namespace SURELOG {

class ParseFile;
Expand All @@ -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<uint8_t[]>& buffer);
bool checkCacheIsValid_(const std::filesystem::path& cacheFileName,
const std::unique_ptr<uint8_t[]>& buffer);
PathId getCacheFileName_(PathId svFileNameId);
bool restore_(PathId cacheFileId, const std::unique_ptr<uint8_t[]>& buffer);
bool checkCacheIsValid_(PathId cacheFileId, const std::unique_ptr<uint8_t[]>& buffer);

ParseFile* m_parse;
bool m_isPrecompiled;
Expand Down
7 changes: 3 additions & 4 deletions include/Surelog/Cache/PythonAPICache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
Loading

0 comments on commit 40766f4

Please sign in to comment.