From f138311d2d2e0cc9ba0496d523bb46f2c1c9fb73 Mon Sep 17 00:00:00 2001 From: rtk0c Date: Wed, 20 Sep 2023 23:58:58 -0700 Subject: Copy from the PlasticSCM repo, replace vendored glm wtih conan --- source/20-codegen-compiler/CodegenDecl.cpp | 74 ++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 source/20-codegen-compiler/CodegenDecl.cpp (limited to 'source/20-codegen-compiler/CodegenDecl.cpp') diff --git a/source/20-codegen-compiler/CodegenDecl.cpp b/source/20-codegen-compiler/CodegenDecl.cpp new file mode 100644 index 0000000..11e1bb5 --- /dev/null +++ b/source/20-codegen-compiler/CodegenDecl.cpp @@ -0,0 +1,74 @@ +#include "CodegenDecl.hpp" + +#include "CodegenUtils.hpp" + +#include +#include + +const std::string& DeclStruct::GetMangledName() const { + if (mangledName.empty()) { + mangledName = Utils::MakeMangledName(name, container); + } + return mangledName; +} + +std::string DeclXGlobalVar::MangleCtorName(std::string_view targetName) { + return fmt::format("{}_MANGLED_ctor", targetName); +} + +std::string DeclXGlobalVar::MangleDtorName(std::string_view targetName) { + return fmt::format("{}_MANGLED_dtor", targetName); +} + +const std::string& DeclEnum::GetMangledName() const { + if (mangledName.empty()) { + mangledName = Utils::MakeMangledName(name, container); + } + return mangledName; +} + +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; +} -- cgit v1.2.3-70-g09d2