aboutsummaryrefslogtreecommitdiff
path: root/buildtools/codegen/CodegenInput.inl
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2022-05-28 20:52:42 -0700
committerrtk0c <[email protected]>2022-05-28 20:52:42 -0700
commit1a6f1ea3b76c3ed4cad5aba5502af390ce50a2c0 (patch)
tree40627f5cdfd931b8c28f0b3a5ec78ef0d0f2b9f0 /buildtools/codegen/CodegenInput.inl
parent6c3007295a6a8c6803933392834c974ec5f56aa0 (diff)
Changeset: 42 Change codegen input parsing to lookahead based; lookup table infra; input/output decl infra
Diffstat (limited to 'buildtools/codegen/CodegenInput.inl')
-rw-r--r--buildtools/codegen/CodegenInput.inl40
1 files changed, 40 insertions, 0 deletions
diff --git a/buildtools/codegen/CodegenInput.inl b/buildtools/codegen/CodegenInput.inl
new file mode 100644
index 0000000..9fae43c
--- /dev/null
+++ b/buildtools/codegen/CodegenInput.inl
@@ -0,0 +1,40 @@
+#pragma once
+
+#include "CodegenConfig.hpp"
+#include "CodegenDecl.hpp"
+
+#include <Utils.hpp>
+
+#include <robin_hood.h>
+#include <cinttypes>
+#include <string>
+#include <vector>
+
+class CodegenInput {
+private:
+ std::vector<DeclEnum> mEnums;
+ robin_hood::unordered_map<std::string_view, size_t> mDeclByName;
+
+public:
+ void AddEnum(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
+
+ mDeclByName.try_emplace(decl.name, mEnums.size());
+ mEnums.push_back(std::move(decl));
+ }
+
+ const DeclEnum* FindEnumByName(std::string_view name) const {
+ // TODO handle multiple kinds of decl
+ auto iter = mDeclByName.find(name);
+ if (iter != mDeclByName.end()) {
+ return &mEnums[iter->second];
+ } else {
+ return nullptr;
+ }
+ }
+};