diff options
author | rtk0c <[email protected]> | 2022-06-11 11:37:45 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2022-06-11 11:37:45 -0700 |
commit | f29a141ab4c4308aed66f930a6f3a42cd20a482d (patch) | |
tree | 482cb3698e45ddc22cc39977dac3e49071554eb1 /source/20-codegen-compiler/CodegenInput.cpp | |
parent | 123bea4fc8d828cec7b41949bab1db443387728e (diff) |
Changeset: 70 Fix cmake and codegen infra
- Invoke codegen.exe once with a list of changed files, instead of individually for each changed file (this gives the codegen global access to all the code, allowing more things)
- Initial support for outputting an archive SQLite database that contains all the code info
Diffstat (limited to 'source/20-codegen-compiler/CodegenInput.cpp')
-rw-r--r-- | source/20-codegen-compiler/CodegenInput.cpp | 99 |
1 files changed, 0 insertions, 99 deletions
diff --git a/source/20-codegen-compiler/CodegenInput.cpp b/source/20-codegen-compiler/CodegenInput.cpp deleted file mode 100644 index 0dced0e..0000000 --- a/source/20-codegen-compiler/CodegenInput.cpp +++ /dev/null @@ -1,99 +0,0 @@ -#include "CodegenInput.hpp" - -#include <Macros.hpp> -#include <Utils.hpp> - -#include <robin_hood.h> -#include <variant> - -struct SomeDecl { - std::variant<DeclStruct, DeclFunction, DeclEnum> v; -}; - -class CodegenInput::Private { -public: - // We want address stability for everything - robin_hood::unordered_node_map<std::string, SomeDecl, StringHash, StringEqual> decls; - robin_hood::unordered_node_map<std::string, DeclNamespace, StringHash, StringEqual> namespaces; -}; - -CodegenInput::CodegenInput() - : m{ new Private() } // -{ -} - -CodegenInput::~CodegenInput() { - delete m; -} - -#define STORE_DECL_OF_TYPE(DeclType, fullname, decl) \ - auto [iter, success] = m->decls.try_emplace(std::move(fullname), SomeDecl{ .v = std::move(decl) }); \ - auto& key = iter->first; \ - auto& val = iter->second; \ - auto& declRef = std::get<DeclType>(val.v); \ - declRef.fullname = key; \ - return &declRef - -DeclEnum* CodegenInput::AddEnum(std::string fullname, DeclEnum decl) { -#if CODEGEN_DEBUG_PRINT - printf("Committed enum '%s'\n", decl.name.c_str()); - for (auto& elm : decl.elements) { - printf(" - element %s = %" PRId64 "\n", elm.name.c_str(), elm.value); - } -#endif - - STORE_DECL_OF_TYPE(DeclEnum, fullname, decl); -} - -DeclStruct* CodegenInput::AddStruct(std::string fullname, DeclStruct decl) { -#if CODEGEN_DEBUG_PRINT - printf("Committed struct '%s'\n", decl.name.c_str()); - printf(" Base classes:\n"); - for (auto& base : decl.baseClasses) { - printf(" - %.*s\n", PRINTF_STRING_VIEW(base->name)); - } -#endif - - STORE_DECL_OF_TYPE(DeclStruct, fullname, decl); -} - -#define FIND_DECL_OF_TYPE(DeclType) \ - auto iter = m->decls.find(name); \ - if (iter != m->decls.end()) { \ - auto& some = iter->second.v; \ - if (auto decl = std::get_if<DeclType>(&some)) { \ - return decl; \ - } \ - } \ - return nullptr - -const DeclEnum* CodegenInput::FindEnum(std::string_view name) const { - FIND_DECL_OF_TYPE(DeclEnum); -} - -const DeclStruct* CodegenInput::FindStruct(std::string_view name) const { - FIND_DECL_OF_TYPE(DeclStruct); -} - -DeclNamespace* CodegenInput::AddNamespace(DeclNamespace ns) { - auto path = Utils::MakeFullName(""sv, &ns); - auto [iter, success] = m->namespaces.try_emplace(std::move(path), std::move(ns)); - auto& nsRef = iter->second; - if (success) { - nsRef.fullname = iter->first; - } - return &nsRef; -} - -const DeclNamespace* CodegenInput::FindNamespace(std::string_view fullname) const { - auto iter = m->namespaces.find(fullname); - if (iter != m->namespaces.end()) { - return &iter->second; - } else { - return nullptr; - } -} - -DeclNamespace* CodegenInput::FindNamespace(std::string_view name) { - return const_cast<DeclNamespace*>(const_cast<const CodegenInput*>(this)->FindNamespace(name)); -} |