diff options
author | rtk0c <[email protected]> | 2022-05-30 15:56:29 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2022-05-30 15:56:29 -0700 |
commit | 80afa67d2b9f1c0605696a3fd69058544fe12fe4 (patch) | |
tree | 3dfe2a6f45e4f5ca8ad534baf06d76d9c558333b /buildtools/codegen/CodegenDecl.cpp | |
parent | 0d92ecfdbfc875a099d9e83714b3a2209668fca5 (diff) | |
parent | 7d8bca09b3c4bf1418e758bd3bd0d6f85672153e (diff) |
Changeset: 53
Diffstat (limited to 'buildtools/codegen/CodegenDecl.cpp')
-rw-r--r-- | buildtools/codegen/CodegenDecl.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/buildtools/codegen/CodegenDecl.cpp b/buildtools/codegen/CodegenDecl.cpp new file mode 100644 index 0000000..7cf21ce --- /dev/null +++ b/buildtools/codegen/CodegenDecl.cpp @@ -0,0 +1,49 @@ +#include "CodegenDecl.hpp" + +#include <Utils.hpp> + +static EnumValuePattern NextPattern(EnumValuePattern val) { + return (EnumValuePattern)(val + 1); +} + +EnumValuePattern DeclEnum::CalcPattern() const { + if (elements.empty()) return EVP_Continuous; + + auto pattern = EVP_Continuous; +restart: + auto lastVal = elements[0].value; + for (size_t i = 1; i < elements.size(); ++i) { + auto currVal = elements[i].value; + switch (pattern) { + case EVP_Continuous: { + bool satisfy = lastVal + 1 == currVal; + if (!satisfy) { + pattern = NextPattern(pattern); + goto restart; + } + } break; + + case EVP_Bits: { + bool satisfy = (lastVal << 1) == currVal; + if (!satisfy) { + pattern = NextPattern(pattern); + goto restart; + } + } break; + + // A random pattern can match anything + case EVP_Random: + case EVP_COUNT: break; + } + lastVal = currVal; + } + + return pattern; +} + +EnumValuePattern DeclEnum::GetPattern() const { + if (pattern == EVP_COUNT) { + pattern = CalcPattern(); + } + return pattern; +} |