diff --git a/src/ZoneCode/Game/IW3/IW3_Commands.txt b/src/ZoneCode/Game/IW3/IW3_Commands.txt index 4ac4a98f..22d212c6 100644 --- a/src/ZoneCode/Game/IW3/IW3_Commands.txt +++ b/src/ZoneCode/Game/IW3/IW3_Commands.txt @@ -1,6 +1,6 @@ // Game: Modern Warfare (IW3) game IW3; -architecture x86; +wordsize 32; // Game Assets asset PhysPreset AssetPhysPreset; diff --git a/src/ZoneCode/Game/IW4/IW4_Commands.txt b/src/ZoneCode/Game/IW4/IW4_Commands.txt index cf62d97c..7a3cfd25 100644 --- a/src/ZoneCode/Game/IW4/IW4_Commands.txt +++ b/src/ZoneCode/Game/IW4/IW4_Commands.txt @@ -1,6 +1,6 @@ // Game: Modern Warfare 2 (IW4) game IW4; -architecture x86; +wordsize 32; // Game Assets asset PhysPreset AssetPhysPreset; diff --git a/src/ZoneCode/Game/IW5/IW5_Commands.txt b/src/ZoneCode/Game/IW5/IW5_Commands.txt index e523ce91..e2faf2a4 100644 --- a/src/ZoneCode/Game/IW5/IW5_Commands.txt +++ b/src/ZoneCode/Game/IW5/IW5_Commands.txt @@ -1,6 +1,6 @@ // Game: Modern Warfare 3 (IW5) game IW5; -architecture x86; +wordsize 32; // Game Assets asset PhysPreset AssetPhysPreset; diff --git a/src/ZoneCode/Game/T5/T5_Commands.txt b/src/ZoneCode/Game/T5/T5_Commands.txt index 977e4b0b..6181a4fe 100644 --- a/src/ZoneCode/Game/T5/T5_Commands.txt +++ b/src/ZoneCode/Game/T5/T5_Commands.txt @@ -1,6 +1,6 @@ // Game: Black Ops (T5) game T5; -architecture x86; +wordsize 32; // Game Assets asset PhysPreset AssetPhysPreset; diff --git a/src/ZoneCode/Game/T6/T6_Commands.txt b/src/ZoneCode/Game/T6/T6_Commands.txt index 80edd659..8a3af04b 100644 --- a/src/ZoneCode/Game/T6/T6_Commands.txt +++ b/src/ZoneCode/Game/T6/T6_Commands.txt @@ -1,6 +1,6 @@ // Game: Black Ops 2 (T6) game T6; -architecture x86; +wordsize 32; // Game Assets asset PhysPreset AssetPhysPreset; diff --git a/src/ZoneCodeGeneratorLib/Domain/Environment/Architecture.cpp b/src/ZoneCodeGeneratorLib/Domain/Environment/Architecture.cpp deleted file mode 100644 index cc30f874..00000000 --- a/src/ZoneCodeGeneratorLib/Domain/Environment/Architecture.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "Architecture.h" - -#include - -unsigned GetPointerSizeForArchitecture(const Architecture architecture) -{ - switch (architecture) - { - case Architecture::X86: - return sizeof(uint32_t); - - case Architecture::X64: - return sizeof(uint64_t); - - default: - assert(false); - return sizeof(uint32_t); - } -} diff --git a/src/ZoneCodeGeneratorLib/Domain/Environment/Architecture.h b/src/ZoneCodeGeneratorLib/Domain/Environment/Architecture.h deleted file mode 100644 index ec02e787..00000000 --- a/src/ZoneCodeGeneratorLib/Domain/Environment/Architecture.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include - -enum class Architecture : std::uint8_t -{ - UNKNOWN, - X86, - X64 -}; - -static constexpr Architecture OWN_ARCHITECTURE = -#if defined(ARCH_x86) - Architecture::X86 -#elif defined(ARCH_x64) - Architecture::X64 -#endif - ; - -extern unsigned GetPointerSizeForArchitecture(Architecture architecture); diff --git a/src/ZoneCodeGeneratorLib/Domain/Environment/WordSize.cpp b/src/ZoneCodeGeneratorLib/Domain/Environment/WordSize.cpp new file mode 100644 index 00000000..84331547 --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Domain/Environment/WordSize.cpp @@ -0,0 +1,19 @@ +#include "WordSize.h" + +#include + +unsigned GetPointerSizeForWordSize(const WordSize wordSize) +{ + switch (wordSize) + { + case WordSize::BITS_32: + return sizeof(uint32_t); + + case WordSize::BITS_64: + return sizeof(uint64_t); + + default: + assert(false); + return sizeof(uint32_t); + } +} diff --git a/src/ZoneCodeGeneratorLib/Domain/Environment/WordSize.h b/src/ZoneCodeGeneratorLib/Domain/Environment/WordSize.h new file mode 100644 index 00000000..d7a80b58 --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Domain/Environment/WordSize.h @@ -0,0 +1,20 @@ +#pragma once + +#include + +enum class WordSize : std::uint8_t +{ + UNKNOWN, + BITS_32, + BITS_64 +}; + +static constexpr WordSize OWN_WORD_SIZE = +#if defined(ARCH_x86) + WordSize::BITS_32 +#elif defined(ARCH_x64) + WordSize::BITS_64 +#endif + ; + +extern unsigned GetPointerSizeForWordSize(WordSize wordSize); diff --git a/src/ZoneCodeGeneratorLib/Generating/BaseRenderingContext.cpp b/src/ZoneCodeGeneratorLib/Generating/BaseRenderingContext.cpp index 24a79bce..5182aa54 100644 --- a/src/ZoneCodeGeneratorLib/Generating/BaseRenderingContext.cpp +++ b/src/ZoneCodeGeneratorLib/Generating/BaseRenderingContext.cpp @@ -1,9 +1,9 @@ #include "BaseRenderingContext.h" -BaseRenderingContext::BaseRenderingContext(std::string game, const Architecture gameArchitecture, std::vector fastFileBlocks) +BaseRenderingContext::BaseRenderingContext(std::string game, const WordSize gameWordSize, std::vector fastFileBlocks) : m_game(std::move(game)), - m_architecture_mismatch(gameArchitecture != OWN_ARCHITECTURE), - m_pointer_size(GetPointerSizeForArchitecture(gameArchitecture)), + m_word_size_mismatch(gameWordSize != OWN_WORD_SIZE), + m_pointer_size(GetPointerSizeForWordSize(gameWordSize)), m_blocks(std::move(fastFileBlocks)), m_default_normal_block(nullptr), m_default_temp_block(nullptr) diff --git a/src/ZoneCodeGeneratorLib/Generating/BaseRenderingContext.h b/src/ZoneCodeGeneratorLib/Generating/BaseRenderingContext.h index 4d5949f3..89f690c4 100644 --- a/src/ZoneCodeGeneratorLib/Generating/BaseRenderingContext.h +++ b/src/ZoneCodeGeneratorLib/Generating/BaseRenderingContext.h @@ -9,7 +9,7 @@ class BaseRenderingContext { public: std::string m_game; - bool m_architecture_mismatch; + bool m_word_size_mismatch; unsigned m_pointer_size; std::vector m_blocks; @@ -17,5 +17,5 @@ public: const FastFileBlock* m_default_temp_block; protected: - BaseRenderingContext(std::string game, Architecture gameArchitecture, std::vector fastFileBlocks); + BaseRenderingContext(std::string game, WordSize gameWordSize, std::vector fastFileBlocks); }; diff --git a/src/ZoneCodeGeneratorLib/Generating/OncePerAssetRenderingContext.cpp b/src/ZoneCodeGeneratorLib/Generating/OncePerAssetRenderingContext.cpp index 0152888a..0c117c4f 100644 --- a/src/ZoneCodeGeneratorLib/Generating/OncePerAssetRenderingContext.cpp +++ b/src/ZoneCodeGeneratorLib/Generating/OncePerAssetRenderingContext.cpp @@ -18,10 +18,8 @@ RenderingUsedType::RenderingUsedType(const DataDefinition* type, StructureInform { } -OncePerAssetRenderingContext::OncePerAssetRenderingContext(std::string game, - const Architecture gameArchitecture, - std::vector fastFileBlocks) - : BaseRenderingContext(std::move(game), gameArchitecture, std::move(fastFileBlocks)), +OncePerAssetRenderingContext::OncePerAssetRenderingContext(std::string game, const WordSize gameWordSize, std::vector fastFileBlocks) + : BaseRenderingContext(std::move(game), gameWordSize, std::move(fastFileBlocks)), m_asset(nullptr), m_has_actions(false) { @@ -190,7 +188,7 @@ bool OncePerAssetRenderingContext::UsedTypeHasActions(const RenderingUsedType* u std::unique_ptr OncePerAssetRenderingContext::BuildContext(const IDataRepository* repository, StructureInformation* asset) { auto context = std::make_unique( - OncePerAssetRenderingContext(repository->GetGameName(), repository->GetArchitecture(), repository->GetAllFastFileBlocks())); + OncePerAssetRenderingContext(repository->GetGameName(), repository->GetWordSize(), repository->GetAllFastFileBlocks())); context->MakeAsset(repository, asset); context->CreateUsedTypeCollections(); diff --git a/src/ZoneCodeGeneratorLib/Generating/OncePerAssetRenderingContext.h b/src/ZoneCodeGeneratorLib/Generating/OncePerAssetRenderingContext.h index 2ffbb9bf..fc9d9201 100644 --- a/src/ZoneCodeGeneratorLib/Generating/OncePerAssetRenderingContext.h +++ b/src/ZoneCodeGeneratorLib/Generating/OncePerAssetRenderingContext.h @@ -38,7 +38,7 @@ public: bool m_has_actions; private: - OncePerAssetRenderingContext(std::string game, Architecture gameArchitecture, std::vector fastFileBlocks); + OncePerAssetRenderingContext(std::string game, WordSize gameWordSize, std::vector fastFileBlocks); RenderingUsedType* AddUsedType(std::unique_ptr usedType); RenderingUsedType* GetBaseType(const IDataRepository* repository, MemberComputations* computations, RenderingUsedType* usedType); diff --git a/src/ZoneCodeGeneratorLib/Generating/OncePerTemplateRenderingContext.cpp b/src/ZoneCodeGeneratorLib/Generating/OncePerTemplateRenderingContext.cpp index 3985e4a5..c36e131a 100644 --- a/src/ZoneCodeGeneratorLib/Generating/OncePerTemplateRenderingContext.cpp +++ b/src/ZoneCodeGeneratorLib/Generating/OncePerTemplateRenderingContext.cpp @@ -5,10 +5,10 @@ #include OncePerTemplateRenderingContext::OncePerTemplateRenderingContext(std::string game, - const Architecture gameArchitecture, + const WordSize gameWordSize, std::vector fastFileBlocks, std::vector assets) - : BaseRenderingContext(std::move(game), gameArchitecture, std::move(fastFileBlocks)), + : BaseRenderingContext(std::move(game), gameWordSize, std::move(fastFileBlocks)), m_assets(std::move(assets)) { for (const auto* block : m_blocks) @@ -35,5 +35,5 @@ std::unique_ptr OncePerTemplateRenderingContext } return std::make_unique( - OncePerTemplateRenderingContext(repository->GetGameName(), repository->GetArchitecture(), repository->GetAllFastFileBlocks(), assetInformation)); + OncePerTemplateRenderingContext(repository->GetGameName(), repository->GetWordSize(), repository->GetAllFastFileBlocks(), assetInformation)); } diff --git a/src/ZoneCodeGeneratorLib/Generating/OncePerTemplateRenderingContext.h b/src/ZoneCodeGeneratorLib/Generating/OncePerTemplateRenderingContext.h index 3b1adc04..bfa5cf56 100644 --- a/src/ZoneCodeGeneratorLib/Generating/OncePerTemplateRenderingContext.h +++ b/src/ZoneCodeGeneratorLib/Generating/OncePerTemplateRenderingContext.h @@ -15,7 +15,7 @@ public: private: OncePerTemplateRenderingContext(std::string game, - Architecture gameArchitecture, + WordSize gameWordSize, std::vector fastFileBlocks, std::vector assets); }; diff --git a/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneLoadTemplate.cpp b/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneLoadTemplate.cpp index 76b2a4b2..46a3bd27 100644 --- a/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneLoadTemplate.cpp +++ b/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneLoadTemplate.cpp @@ -83,7 +83,7 @@ namespace m_intendation++; // Method Declarations - if (m_env.m_architecture_mismatch) + if (m_env.m_word_size_mismatch) { for (const auto* type : m_env.m_used_types) { @@ -190,7 +190,7 @@ namespace LINE("") PrintMainLoadMethod(); - if (m_env.m_architecture_mismatch) + if (m_env.m_word_size_mismatch) { for (const auto* type : m_env.m_used_types) { @@ -899,7 +899,7 @@ namespace { LINEF("*{0} = m_stream.{1}<{2}>({3});", MakeTypePtrVarName(def), - m_env.m_architecture_mismatch ? "AllocOutOfBlock" : "Alloc", + m_env.m_word_size_mismatch ? "AllocOutOfBlock" : "Alloc", def->GetFullName(), def->GetAlignment()) } @@ -976,7 +976,7 @@ namespace LINE("if (atStreamStart)") - if (m_env.m_architecture_mismatch) + if (m_env.m_word_size_mismatch) { LINE("{") m_intendation++; @@ -1210,7 +1210,7 @@ namespace { LINEF("{0} = {1};", MakeTypeVarName(member->m_member->m_type_declaration->m_type), MakeMemberAccess(info, member, modifier)) - if (computations.IsAfterPartialLoad() && !m_env.m_architecture_mismatch) + if (computations.IsAfterPartialLoad() && !m_env.m_word_size_mismatch) { LINEF("LoadArray_{0}(true, {1});", MakeSafeTypeName(member->m_member->m_type_declaration->m_type), arraySizeStr) } @@ -1231,7 +1231,7 @@ namespace LINE(MakeCustomActionCall(member->m_post_load_action.get())) } } - else if (computations.IsAfterPartialLoad() && !m_env.m_architecture_mismatch) + else if (computations.IsAfterPartialLoad() && !m_env.m_word_size_mismatch) { LINEF("m_stream.Load<{0}{1}>({2}, {3});", MakeTypeDecl(member->m_member->m_type_declaration.get()), @@ -1248,12 +1248,12 @@ namespace LINEF("{0} = {1};", MakeTypeVarName(member->m_member->m_type_declaration->m_type), MakeMemberAccess(info, member, modifier)) LINEF("LoadArray_{0}({1}, {2});", MakeSafeTypeName(member->m_member->m_type_declaration->m_type), - m_env.m_architecture_mismatch ? "false" : "true", + m_env.m_word_size_mismatch ? "false" : "true", MakeEvaluation(modifier.GetDynamicArraySizeEvaluation())) } else if (info->m_has_matching_cross_platform_structure) { - if (m_env.m_architecture_mismatch) + if (m_env.m_word_size_mismatch) { LINE("if (atStreamStart)") m_intendation++; @@ -1265,7 +1265,7 @@ namespace MakeMemberAccess(info, member, modifier), MakeEvaluation(modifier.GetDynamicArraySizeEvaluation())) - if (m_env.m_architecture_mismatch) + if (m_env.m_word_size_mismatch) { m_intendation--; } @@ -1279,7 +1279,7 @@ namespace { LINEF("{0} = &{1};", MakeTypeVarName(member->m_member->m_type_declaration->m_type), MakeMemberAccess(info, member, modifier)) - if (computations.IsAfterPartialLoad() && !m_env.m_architecture_mismatch) + if (computations.IsAfterPartialLoad() && !m_env.m_word_size_mismatch) { LINEF("Load_{0}(true);", MakeSafeTypeName(member->m_member->m_type_declaration->m_type)) } @@ -1300,7 +1300,7 @@ namespace LINE(MakeCustomActionCall(member->m_post_load_action.get())) } } - else if (computations.IsAfterPartialLoad() && !m_env.m_architecture_mismatch) + else if (computations.IsAfterPartialLoad() && !m_env.m_word_size_mismatch) { LINEF("m_stream.Load<{0}{1}>(&{2});", MakeTypeDecl(member->m_member->m_type_declaration.get()), @@ -1421,7 +1421,7 @@ namespace [[nodiscard]] bool ShouldAllocOutOfBlock(const MemberInformation& member, const MemberLoadType loadType) const { - return m_env.m_architecture_mismatch + return m_env.m_word_size_mismatch && ((member.m_type && !member.m_type->m_has_matching_cross_platform_structure) || loadType == MemberLoadType::POINTER_ARRAY); } @@ -1505,7 +1505,7 @@ namespace { LINE("") - if (m_env.m_architecture_mismatch) + if (m_env.m_word_size_mismatch) LINE("uintptr_t toInsertLookupEntry = 0;") else LINEF("{0}** toInsert = nullptr;", member->m_member->m_type_declaration->m_type->GetFullName()) @@ -1513,7 +1513,7 @@ namespace LINE("if (zonePtrType == ZonePointerType::INSERT)") m_intendation++; - if (m_env.m_architecture_mismatch) + if (m_env.m_word_size_mismatch) LINE("toInsertLookupEntry = m_stream.InsertPointerAliasLookup();") else LINEF("toInsert = m_stream.InsertPointerNative<{0}>();", member->m_member->m_type_declaration->m_type->GetFullName()) @@ -1530,7 +1530,7 @@ namespace LINE("if (zonePtrType == ZonePointerType::INSERT)") m_intendation++; - if (m_env.m_architecture_mismatch) + if (m_env.m_word_size_mismatch) LINEF( "m_stream.SetInsertedPointerAliasLookup(toInsertLookupEntry, {0}->{1});", MakeTypeVarName(info->m_definition), member->m_member->m_name) else @@ -1909,7 +1909,7 @@ namespace } m_intendation--; } - else if (!m_env.m_architecture_mismatch) + else if (!m_env.m_word_size_mismatch) { LINE("assert(atStreamStart);") } @@ -1950,7 +1950,7 @@ namespace LINEF("assert({0} != nullptr);", MakeTypePtrVarName(info->m_definition)) LINE("") - if (!m_env.m_architecture_mismatch) + if (!m_env.m_word_size_mismatch) { LINE("if (atStreamStart)") m_intendation++; @@ -1987,7 +1987,7 @@ namespace LINEF("*{0} = m_stream.{1}<{2}>({3});", MakeTypePtrVarName(info->m_definition), - m_env.m_architecture_mismatch ? "AllocOutOfBlock" : "Alloc", + m_env.m_word_size_mismatch ? "AllocOutOfBlock" : "Alloc", info->m_definition->GetFullName(), info->m_definition->GetAlignment()) @@ -1995,7 +1995,7 @@ namespace { LINE("") - if (m_env.m_architecture_mismatch) + if (m_env.m_word_size_mismatch) LINE("uintptr_t toInsertLookupEntry = 0;") else LINEF("{0}** toInsert = nullptr;", info->m_definition->GetFullName()) @@ -2003,7 +2003,7 @@ namespace LINE("if (zonePtrType == ZonePointerType::INSERT)") m_intendation++; - if (m_env.m_architecture_mismatch) + if (m_env.m_word_size_mismatch) LINE("toInsertLookupEntry = m_stream.InsertPointerAliasLookup();") else LINEF("toInsert = m_stream.InsertPointerNative<{0}>();", info->m_definition->GetFullName()) @@ -2050,7 +2050,7 @@ namespace LINE("if (zonePtrType == ZonePointerType::INSERT)") m_intendation++; - if (m_env.m_architecture_mismatch) + if (m_env.m_word_size_mismatch) LINEF("m_stream.SetInsertedPointerAliasLookup(toInsertLookupEntry, *{0});", MakeTypePtrVarName(info->m_definition)) else LINEF("*toInsert = *{0};", MakeTypePtrVarName(info->m_definition)) diff --git a/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneWriteTemplate.cpp b/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneWriteTemplate.cpp index 96b41946..3a6d1c82 100644 --- a/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneWriteTemplate.cpp +++ b/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneWriteTemplate.cpp @@ -79,7 +79,7 @@ namespace m_intendation++; // Method Declarations - if (m_env.m_architecture_mismatch) + if (m_env.m_word_size_mismatch) { for (const auto* type : m_env.m_used_types) { @@ -178,7 +178,7 @@ namespace LINE("") PrintMainWriteMethod(); - if (m_env.m_architecture_mismatch) + if (m_env.m_word_size_mismatch) { for (const auto* type : m_env.m_used_types) { @@ -335,7 +335,7 @@ namespace MakeTypeWrittenVarNameInternal(info->m_definition, str); str << ".AtOffset("; - if (m_env.m_architecture_mismatch) + if (m_env.m_word_size_mismatch) { str << OffsetForMemberModifier(*member, modifier, 0); } @@ -837,7 +837,7 @@ namespace std::string MakeReusableInnerOffset(const DataDefinition* dataDefinition, const Variable* member) const { - if (m_env.m_architecture_mismatch) + if (m_env.m_word_size_mismatch) return std::to_string(member->m_offset); return std::format("offsetof({0}, {1})", dataDefinition->GetFullName(), member->m_name); diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParser.cpp b/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParser.cpp index 303e1d9e..80f93e37 100644 --- a/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParser.cpp +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParser.cpp @@ -2,7 +2,6 @@ #include "Parsing/Commands/Sequence/SequenceAction.h" #include "Parsing/Commands/Sequence/SequenceAllocAlign.h" -#include "Parsing/Commands/Sequence/SequenceArchitecture.h" #include "Parsing/Commands/Sequence/SequenceArrayCount.h" #include "Parsing/Commands/Sequence/SequenceArraySize.h" #include "Parsing/Commands/Sequence/SequenceAsset.h" @@ -17,6 +16,7 @@ #include "Parsing/Commands/Sequence/SequenceSetBlock.h" #include "Parsing/Commands/Sequence/SequenceString.h" #include "Parsing/Commands/Sequence/SequenceUse.h" +#include "Parsing/Commands/Sequence/SequenceWordSize.h" CommandsParser::CommandsParser(CommandsLexer* lexer, IDataRepository* targetRepository) : AbstractParser(lexer, std::make_unique(targetRepository)), @@ -29,7 +29,6 @@ const std::vector& CommandsParser::GetTestsForState static std::vector tests({ new SequenceAction(), new SequenceAllocAlign(), - new SequenceArchitecture(), new SequenceArrayCount(), new SequenceArraySize(), new SequenceAsset(), @@ -44,6 +43,7 @@ const std::vector& CommandsParser::GetTestsForState new SequenceSetBlock(), new SequenceString(), new SequenceUse(), + new SequenceWordSize(), }); return tests; diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParserState.cpp b/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParserState.cpp index 0169d5ed..44ae6602 100644 --- a/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParserState.cpp +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParserState.cpp @@ -74,9 +74,9 @@ void CommandsParserState::AddBlock(std::unique_ptr block) const m_repository->Add(std::move(block)); } -void CommandsParserState::SetArchitecture(const Architecture architecture) const +void CommandsParserState::SetWordSize(const WordSize wordSize) const { - m_repository->SetArchitecture(architecture); + m_repository->SetWordSize(wordSize); } void CommandsParserState::SetGame(std::string gameName) const diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParserState.h b/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParserState.h index a38b322f..fdef5737 100644 --- a/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParserState.h +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParserState.h @@ -13,7 +13,7 @@ public: [[nodiscard]] const IDataRepository* GetRepository() const; void AddBlock(std::unique_ptr block) const; - void SetArchitecture(Architecture architecture) const; + void SetWordSize(WordSize wordSize) const; void SetGame(std::string gameName) const; [[nodiscard]] StructureInformation* GetInUse() const; diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceArchitecture.cpp b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceArchitecture.cpp deleted file mode 100644 index 0e690139..00000000 --- a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceArchitecture.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include "SequenceArchitecture.h" - -#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h" -#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h" - -namespace -{ - static constexpr auto CAPTURE_ARCHITECTURE = 1; -} - -SequenceArchitecture::SequenceArchitecture() -{ - const CommandsMatcherFactory create(this); - - AddMatchers({ - create.Keyword("architecture"), - create.Identifier().Capture(CAPTURE_ARCHITECTURE), - create.Char(';'), - }); - - m_architecture_mapping["x86"] = Architecture::X86; - m_architecture_mapping["x64"] = Architecture::X64; -} - -void SequenceArchitecture::ProcessMatch(CommandsParserState* state, SequenceResult& result) const -{ - const auto& architectureToken = result.NextCapture(CAPTURE_ARCHITECTURE); - - const auto foundArchitecture = m_architecture_mapping.find(architectureToken.IdentifierValue()); - - if (foundArchitecture == m_architecture_mapping.end()) - throw ParsingException(architectureToken.GetPos(), "Unknown architecture"); - - state->SetArchitecture(foundArchitecture->second); -} diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceArchitecture.h b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceArchitecture.h deleted file mode 100644 index 5b609b6f..00000000 --- a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceArchitecture.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "Parsing/Commands/Impl/CommandsParser.h" - -#include - -class SequenceArchitecture final : public CommandsParser::sequence_t -{ -public: - SequenceArchitecture(); - -protected: - void ProcessMatch(CommandsParserState* state, SequenceResult& result) const override; - -private: - std::unordered_map m_architecture_mapping; -}; diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceWordSize.cpp b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceWordSize.cpp new file mode 100644 index 00000000..d6cfac60 --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceWordSize.cpp @@ -0,0 +1,39 @@ +#include "SequenceWordSize.h" + +#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h" +#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h" + +namespace +{ + static constexpr auto CAPTURE_WORD_SIZE = 1; +} + +SequenceWordSize::SequenceWordSize() +{ + const CommandsMatcherFactory create(this); + + AddMatchers({ + create.Keyword("wordsize"), + create.Integer().Capture(CAPTURE_WORD_SIZE), + create.Char(';'), + }); +} + +void SequenceWordSize::ProcessMatch(CommandsParserState* state, SequenceResult& result) const +{ + const auto& wordSizeToken = result.NextCapture(CAPTURE_WORD_SIZE); + + switch (wordSizeToken.IntegerValue()) + { + case 32: + state->SetWordSize(WordSize::BITS_32); + break; + + case 64: + state->SetWordSize(WordSize::BITS_64); + break; + + default: + throw ParsingException(wordSizeToken.GetPos(), "Unknown word size"); + } +} diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceWordSize.h b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceWordSize.h new file mode 100644 index 00000000..33cf8a3f --- /dev/null +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceWordSize.h @@ -0,0 +1,12 @@ +#pragma once + +#include "Parsing/Commands/Impl/CommandsParser.h" + +class SequenceWordSize final : public CommandsParser::sequence_t +{ +public: + SequenceWordSize(); + +protected: + void ProcessMatch(CommandsParserState* state, SequenceResult& result) const override; +}; diff --git a/src/ZoneCodeGeneratorLib/Parsing/PostProcessing/CalculateSizeAndAlignPostProcessor.cpp b/src/ZoneCodeGeneratorLib/Parsing/PostProcessing/CalculateSizeAndAlignPostProcessor.cpp index 65032723..f67fbf43 100644 --- a/src/ZoneCodeGeneratorLib/Parsing/PostProcessing/CalculateSizeAndAlignPostProcessor.cpp +++ b/src/ZoneCodeGeneratorLib/Parsing/PostProcessing/CalculateSizeAndAlignPostProcessor.cpp @@ -27,7 +27,7 @@ namespace if (hasPointerModifier) { - declaration->m_alignment = GetPointerSizeForArchitecture(repository->GetArchitecture()); + declaration->m_alignment = GetPointerSizeForWordSize(repository->GetWordSize()); } else { @@ -92,7 +92,7 @@ namespace switch (declarationModifier->GetType()) { case DeclarationModifierType::POINTER: - currentSize = GetPointerSizeForArchitecture(repository->GetArchitecture()); + currentSize = GetPointerSizeForWordSize(repository->GetWordSize()); break; case DeclarationModifierType::ARRAY: @@ -256,9 +256,9 @@ namespace bool CalculateSizeAndAlignPostProcessor::PostProcess(IDataRepository* repository) { - if (repository->GetArchitecture() == Architecture::UNKNOWN) + if (repository->GetWordSize() == WordSize::UNKNOWN) { - con::error("You must set an architecture!"); + con::error("You must set a word size!"); return false; } diff --git a/src/ZoneCodeGeneratorLib/Parsing/PostProcessing/CrossPlatformStructurePostProcessor.cpp b/src/ZoneCodeGeneratorLib/Parsing/PostProcessing/CrossPlatformStructurePostProcessor.cpp index 397e9844..299ec3b3 100644 --- a/src/ZoneCodeGeneratorLib/Parsing/PostProcessing/CrossPlatformStructurePostProcessor.cpp +++ b/src/ZoneCodeGeneratorLib/Parsing/PostProcessing/CrossPlatformStructurePostProcessor.cpp @@ -40,7 +40,7 @@ bool CrossPlatformStructurePostProcessor::PostProcess(IDataRepository* repositor { const auto& allInfos = repository->GetAllStructureInformation(); - if (repository->GetArchitecture() == OWN_ARCHITECTURE) + if (repository->GetWordSize() == OWN_WORD_SIZE) { for (const auto& info : allInfos) info->m_has_matching_cross_platform_structure = true; diff --git a/src/ZoneCodeGeneratorLib/Persistence/IDataRepository.h b/src/ZoneCodeGeneratorLib/Persistence/IDataRepository.h index 563b5ab9..0e82dd8b 100644 --- a/src/ZoneCodeGeneratorLib/Persistence/IDataRepository.h +++ b/src/ZoneCodeGeneratorLib/Persistence/IDataRepository.h @@ -4,7 +4,7 @@ #include "Domain/Definition/StructDefinition.h" #include "Domain/Definition/TypedefDefinition.h" #include "Domain/Definition/UnionDefinition.h" -#include "Domain/Environment/Architecture.h" +#include "Domain/Environment/WordSize.h" #include "Domain/FastFile/FastFileBlock.h" #include "Domain/Information/StructureInformation.h" @@ -30,8 +30,8 @@ public: [[nodiscard]] virtual const std::string& GetGameName() const = 0; virtual void SetGame(std::string gameName) = 0; - [[nodiscard]] virtual Architecture GetArchitecture() const = 0; - virtual void SetArchitecture(Architecture architecture) = 0; + [[nodiscard]] virtual WordSize GetWordSize() const = 0; + virtual void SetWordSize(WordSize wordSize) = 0; [[nodiscard]] virtual const std::vector& GetAllEnums() const = 0; [[nodiscard]] virtual const std::vector& GetAllStructs() const = 0; diff --git a/src/ZoneCodeGeneratorLib/Persistence/InMemory/InMemoryRepository.cpp b/src/ZoneCodeGeneratorLib/Persistence/InMemory/InMemoryRepository.cpp index 792e1d2b..44bcf1e4 100644 --- a/src/ZoneCodeGeneratorLib/Persistence/InMemory/InMemoryRepository.cpp +++ b/src/ZoneCodeGeneratorLib/Persistence/InMemory/InMemoryRepository.cpp @@ -1,7 +1,7 @@ #include "InMemoryRepository.h" InMemoryRepository::InMemoryRepository() - : m_architecture(Architecture::UNKNOWN) + : m_word_size(WordSize::UNKNOWN) { } @@ -83,14 +83,14 @@ void InMemoryRepository::SetGame(std::string gameName) m_game_name = std::move(gameName); } -Architecture InMemoryRepository::GetArchitecture() const +WordSize InMemoryRepository::GetWordSize() const { - return m_architecture; + return m_word_size; } -void InMemoryRepository::SetArchitecture(const Architecture architecture) +void InMemoryRepository::SetWordSize(const WordSize wordSize) { - m_architecture = architecture; + m_word_size = wordSize; } const std::vector& InMemoryRepository::GetAllEnums() const diff --git a/src/ZoneCodeGeneratorLib/Persistence/InMemory/InMemoryRepository.h b/src/ZoneCodeGeneratorLib/Persistence/InMemory/InMemoryRepository.h index 918d5620..7b7d7b7b 100644 --- a/src/ZoneCodeGeneratorLib/Persistence/InMemory/InMemoryRepository.h +++ b/src/ZoneCodeGeneratorLib/Persistence/InMemory/InMemoryRepository.h @@ -24,8 +24,8 @@ public: [[nodiscard]] const std::string& GetGameName() const override; void SetGame(std::string gameName) override; - [[nodiscard]] Architecture GetArchitecture() const override; - void SetArchitecture(Architecture architecture) override; + [[nodiscard]] WordSize GetWordSize() const override; + void SetWordSize(WordSize wordSize) override; [[nodiscard]] const std::vector& GetAllEnums() const override; [[nodiscard]] const std::vector& GetAllStructs() const override; @@ -54,5 +54,5 @@ private: std::unordered_map m_structure_information_by_definition; std::unordered_map m_type_information_by_definition; std::string m_game_name; - Architecture m_architecture; + WordSize m_word_size; }; diff --git a/test/ZoneCodeGeneratorLibTests/Parsing/Commands/Sequence/SequenceArchitectureTests.cpp b/test/ZoneCodeGeneratorLibTests/Parsing/Commands/Sequence/SequenceWordSizeTests.cpp similarity index 68% rename from test/ZoneCodeGeneratorLibTests/Parsing/Commands/Sequence/SequenceArchitectureTests.cpp rename to test/ZoneCodeGeneratorLibTests/Parsing/Commands/Sequence/SequenceWordSizeTests.cpp index 0b87f0e3..0615cbd8 100644 --- a/test/ZoneCodeGeneratorLibTests/Parsing/Commands/Sequence/SequenceArchitectureTests.cpp +++ b/test/ZoneCodeGeneratorLibTests/Parsing/Commands/Sequence/SequenceWordSizeTests.cpp @@ -1,11 +1,11 @@ -#include "Parsing/Commands/Sequence/SequenceArchitecture.h" +#include "Parsing/Commands/Sequence/SequenceWordSize.h" #include "Parsing/Mock/MockLexer.h" #include "Persistence/InMemory/InMemoryRepository.h" #include #include -namespace test::parsing::commands::sequence::sequence_architecture +namespace test::parsing::commands::sequence::sequence_word_size { class CommandsSequenceTestsHelper { @@ -31,18 +31,18 @@ namespace test::parsing::commands::sequence::sequence_architecture bool PerformTest() { REQUIRE(m_lexer); - const auto sequence = std::make_unique(); + const auto sequence = std::make_unique(); return sequence->MatchSequence(m_lexer.get(), m_state.get(), m_consumed_token_count); } }; - TEST_CASE("SequenceArchitecture: Ensure can set x86", "[parsing][sequence]") + TEST_CASE("SequenceWordSize: Ensure can set 32-bit", "[parsing][sequence]") { CommandsSequenceTestsHelper helper; const TokenPos pos; helper.Tokens({ - CommandsParserValue::Identifier(pos, new std::string("architecture")), - CommandsParserValue::Identifier(pos, new std::string("x86")), + CommandsParserValue::Identifier(pos, new std::string("wordsize")), + CommandsParserValue::Integer(pos, 32), CommandsParserValue::Character(pos, ';'), CommandsParserValue::EndOfFile(pos), }); @@ -51,16 +51,16 @@ namespace test::parsing::commands::sequence::sequence_architecture REQUIRE(result); REQUIRE(helper.m_consumed_token_count == 3); - REQUIRE(helper.m_repository->GetArchitecture() == Architecture::X86); + REQUIRE(helper.m_repository->GetWordSize() == WordSize::BITS_32); } - TEST_CASE("SequenceArchitecture: Ensure can set x64", "[parsing][sequence]") + TEST_CASE("SequenceWordSize: Ensure can set 64-bit", "[parsing][sequence]") { CommandsSequenceTestsHelper helper; const TokenPos pos; helper.Tokens({ - CommandsParserValue::Identifier(pos, new std::string("architecture")), - CommandsParserValue::Identifier(pos, new std::string("x86")), + CommandsParserValue::Identifier(pos, new std::string("wordsize")), + CommandsParserValue::Integer(pos, 64), CommandsParserValue::Character(pos, ';'), CommandsParserValue::EndOfFile(pos), }); @@ -69,21 +69,21 @@ namespace test::parsing::commands::sequence::sequence_architecture REQUIRE(result); REQUIRE(helper.m_consumed_token_count == 3); - REQUIRE(helper.m_repository->GetArchitecture() == Architecture::X86); + REQUIRE(helper.m_repository->GetWordSize() == WordSize::BITS_64); } - TEST_CASE("SequenceArchitecture: Ensure cannot match unknown value", "[parsing][sequence]") + TEST_CASE("SequenceWordSize: Ensure cannot match unknown value", "[parsing][sequence]") { CommandsSequenceTestsHelper helper; const TokenPos pos; helper.Tokens({ - CommandsParserValue::Identifier(pos, new std::string("architecture")), - CommandsParserValue::Identifier(pos, new std::string("x1337")), + CommandsParserValue::Identifier(pos, new std::string("wordsize")), + CommandsParserValue::Integer(pos, 1337), CommandsParserValue::Character(pos, ';'), CommandsParserValue::EndOfFile(pos), }); REQUIRE_THROWS_AS(helper.PerformTest(), ParsingException); - REQUIRE(helper.m_repository->GetArchitecture() == Architecture::UNKNOWN); + REQUIRE(helper.m_repository->GetWordSize() == WordSize::UNKNOWN); } -} // namespace test::parsing::commands::sequence::sequence_architecture +} // namespace test::parsing::commands::sequence::sequence_word_size