mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-05-02 00:19:35 +00:00
refactor(zcg): use wordsize instead of architecture
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// Game: Modern Warfare (IW3)
|
||||
game IW3;
|
||||
architecture x86;
|
||||
wordsize 32;
|
||||
|
||||
// Game Assets
|
||||
asset PhysPreset AssetPhysPreset;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Game: Modern Warfare 2 (IW4)
|
||||
game IW4;
|
||||
architecture x86;
|
||||
wordsize 32;
|
||||
|
||||
// Game Assets
|
||||
asset PhysPreset AssetPhysPreset;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Game: Modern Warfare 3 (IW5)
|
||||
game IW5;
|
||||
architecture x86;
|
||||
wordsize 32;
|
||||
|
||||
// Game Assets
|
||||
asset PhysPreset AssetPhysPreset;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Game: Black Ops (T5)
|
||||
game T5;
|
||||
architecture x86;
|
||||
wordsize 32;
|
||||
|
||||
// Game Assets
|
||||
asset PhysPreset AssetPhysPreset;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Game: Black Ops 2 (T6)
|
||||
game T6;
|
||||
architecture x86;
|
||||
wordsize 32;
|
||||
|
||||
// Game Assets
|
||||
asset PhysPreset AssetPhysPreset;
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
#include "Architecture.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
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);
|
||||
@@ -0,0 +1,19 @@
|
||||
#include "WordSize.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
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);
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "BaseRenderingContext.h"
|
||||
|
||||
BaseRenderingContext::BaseRenderingContext(std::string game, const Architecture gameArchitecture, std::vector<const FastFileBlock*> fastFileBlocks)
|
||||
BaseRenderingContext::BaseRenderingContext(std::string game, const WordSize gameWordSize, std::vector<const FastFileBlock*> 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)
|
||||
|
||||
@@ -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<const FastFileBlock*> m_blocks;
|
||||
|
||||
@@ -17,5 +17,5 @@ public:
|
||||
const FastFileBlock* m_default_temp_block;
|
||||
|
||||
protected:
|
||||
BaseRenderingContext(std::string game, Architecture gameArchitecture, std::vector<const FastFileBlock*> fastFileBlocks);
|
||||
BaseRenderingContext(std::string game, WordSize gameWordSize, std::vector<const FastFileBlock*> fastFileBlocks);
|
||||
};
|
||||
|
||||
@@ -18,10 +18,8 @@ RenderingUsedType::RenderingUsedType(const DataDefinition* type, StructureInform
|
||||
{
|
||||
}
|
||||
|
||||
OncePerAssetRenderingContext::OncePerAssetRenderingContext(std::string game,
|
||||
const Architecture gameArchitecture,
|
||||
std::vector<const FastFileBlock*> fastFileBlocks)
|
||||
: BaseRenderingContext(std::move(game), gameArchitecture, std::move(fastFileBlocks)),
|
||||
OncePerAssetRenderingContext::OncePerAssetRenderingContext(std::string game, const WordSize gameWordSize, std::vector<const FastFileBlock*> 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> OncePerAssetRenderingContext::BuildContext(const IDataRepository* repository, StructureInformation* asset)
|
||||
{
|
||||
auto context = std::make_unique<OncePerAssetRenderingContext>(
|
||||
OncePerAssetRenderingContext(repository->GetGameName(), repository->GetArchitecture(), repository->GetAllFastFileBlocks()));
|
||||
OncePerAssetRenderingContext(repository->GetGameName(), repository->GetWordSize(), repository->GetAllFastFileBlocks()));
|
||||
|
||||
context->MakeAsset(repository, asset);
|
||||
context->CreateUsedTypeCollections();
|
||||
|
||||
@@ -38,7 +38,7 @@ public:
|
||||
bool m_has_actions;
|
||||
|
||||
private:
|
||||
OncePerAssetRenderingContext(std::string game, Architecture gameArchitecture, std::vector<const FastFileBlock*> fastFileBlocks);
|
||||
OncePerAssetRenderingContext(std::string game, WordSize gameWordSize, std::vector<const FastFileBlock*> fastFileBlocks);
|
||||
|
||||
RenderingUsedType* AddUsedType(std::unique_ptr<RenderingUsedType> usedType);
|
||||
RenderingUsedType* GetBaseType(const IDataRepository* repository, MemberComputations* computations, RenderingUsedType* usedType);
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
#include <algorithm>
|
||||
|
||||
OncePerTemplateRenderingContext::OncePerTemplateRenderingContext(std::string game,
|
||||
const Architecture gameArchitecture,
|
||||
const WordSize gameWordSize,
|
||||
std::vector<const FastFileBlock*> fastFileBlocks,
|
||||
std::vector<StructureInformation*> 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> OncePerTemplateRenderingContext
|
||||
}
|
||||
|
||||
return std::make_unique<OncePerTemplateRenderingContext>(
|
||||
OncePerTemplateRenderingContext(repository->GetGameName(), repository->GetArchitecture(), repository->GetAllFastFileBlocks(), assetInformation));
|
||||
OncePerTemplateRenderingContext(repository->GetGameName(), repository->GetWordSize(), repository->GetAllFastFileBlocks(), assetInformation));
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ public:
|
||||
|
||||
private:
|
||||
OncePerTemplateRenderingContext(std::string game,
|
||||
Architecture gameArchitecture,
|
||||
WordSize gameWordSize,
|
||||
std::vector<const FastFileBlock*> fastFileBlocks,
|
||||
std::vector<StructureInformation*> assets);
|
||||
};
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<CommandsParserState>(targetRepository)),
|
||||
@@ -29,7 +29,6 @@ const std::vector<CommandsParser::sequence_t*>& CommandsParser::GetTestsForState
|
||||
static std::vector<sequence_t*> tests({
|
||||
new SequenceAction(),
|
||||
new SequenceAllocAlign(),
|
||||
new SequenceArchitecture(),
|
||||
new SequenceArrayCount(),
|
||||
new SequenceArraySize(),
|
||||
new SequenceAsset(),
|
||||
@@ -44,6 +43,7 @@ const std::vector<CommandsParser::sequence_t*>& CommandsParser::GetTestsForState
|
||||
new SequenceSetBlock(),
|
||||
new SequenceString(),
|
||||
new SequenceUse(),
|
||||
new SequenceWordSize(),
|
||||
});
|
||||
|
||||
return tests;
|
||||
|
||||
@@ -74,9 +74,9 @@ void CommandsParserState::AddBlock(std::unique_ptr<FastFileBlock> 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
|
||||
|
||||
@@ -13,7 +13,7 @@ public:
|
||||
[[nodiscard]] const IDataRepository* GetRepository() const;
|
||||
|
||||
void AddBlock(std::unique_ptr<FastFileBlock> block) const;
|
||||
void SetArchitecture(Architecture architecture) const;
|
||||
void SetWordSize(WordSize wordSize) const;
|
||||
void SetGame(std::string gameName) const;
|
||||
|
||||
[[nodiscard]] StructureInformation* GetInUse() const;
|
||||
|
||||
@@ -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<CommandsParserValue>& 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);
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Parsing/Commands/Impl/CommandsParser.h"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
class SequenceArchitecture final : public CommandsParser::sequence_t
|
||||
{
|
||||
public:
|
||||
SequenceArchitecture();
|
||||
|
||||
protected:
|
||||
void ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const override;
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, Architecture> m_architecture_mapping;
|
||||
};
|
||||
@@ -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<CommandsParserValue>& 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");
|
||||
}
|
||||
}
|
||||
@@ -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<CommandsParserValue>& result) const override;
|
||||
};
|
||||
+4
-4
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
@@ -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<EnumDefinition*>& GetAllEnums() const = 0;
|
||||
[[nodiscard]] virtual const std::vector<StructDefinition*>& GetAllStructs() const = 0;
|
||||
|
||||
@@ -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<EnumDefinition*>& InMemoryRepository::GetAllEnums() const
|
||||
|
||||
@@ -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<EnumDefinition*>& GetAllEnums() const override;
|
||||
[[nodiscard]] const std::vector<StructDefinition*>& GetAllStructs() const override;
|
||||
@@ -54,5 +54,5 @@ private:
|
||||
std::unordered_map<const DefinitionWithMembers*, StructureInformation*> m_structure_information_by_definition;
|
||||
std::unordered_map<const DataDefinition*, TypeInformation*> m_type_information_by_definition;
|
||||
std::string m_game_name;
|
||||
Architecture m_architecture;
|
||||
WordSize m_word_size;
|
||||
};
|
||||
|
||||
+16
-16
@@ -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 <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/generators/catch_generators.hpp>
|
||||
|
||||
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<SequenceArchitecture>();
|
||||
const auto sequence = std::make_unique<SequenceWordSize>();
|
||||
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
|
||||
Reference in New Issue
Block a user