mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-05-02 00:19:35 +00:00
Merge pull request #769 from michaeloliverx/refactor-arch-wordsize
refactor(zcg): use wordsize instead of architecture
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
// Game: Modern Warfare (IW3)
|
// Game: Modern Warfare (IW3)
|
||||||
game IW3;
|
game IW3;
|
||||||
architecture x86;
|
wordsize 32;
|
||||||
|
|
||||||
// Game Assets
|
// Game Assets
|
||||||
asset PhysPreset AssetPhysPreset;
|
asset PhysPreset AssetPhysPreset;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// Game: Modern Warfare 2 (IW4)
|
// Game: Modern Warfare 2 (IW4)
|
||||||
game IW4;
|
game IW4;
|
||||||
architecture x86;
|
wordsize 32;
|
||||||
|
|
||||||
// Game Assets
|
// Game Assets
|
||||||
asset PhysPreset AssetPhysPreset;
|
asset PhysPreset AssetPhysPreset;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// Game: Modern Warfare 3 (IW5)
|
// Game: Modern Warfare 3 (IW5)
|
||||||
game IW5;
|
game IW5;
|
||||||
architecture x86;
|
wordsize 32;
|
||||||
|
|
||||||
// Game Assets
|
// Game Assets
|
||||||
asset PhysPreset AssetPhysPreset;
|
asset PhysPreset AssetPhysPreset;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// Game: Black Ops (T5)
|
// Game: Black Ops (T5)
|
||||||
game T5;
|
game T5;
|
||||||
architecture x86;
|
wordsize 32;
|
||||||
|
|
||||||
// Game Assets
|
// Game Assets
|
||||||
asset PhysPreset AssetPhysPreset;
|
asset PhysPreset AssetPhysPreset;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// Game: Black Ops 2 (T6)
|
// Game: Black Ops 2 (T6)
|
||||||
game T6;
|
game T6;
|
||||||
architecture x86;
|
wordsize 32;
|
||||||
|
|
||||||
// Game Assets
|
// Game Assets
|
||||||
asset PhysPreset AssetPhysPreset;
|
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"
|
#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_game(std::move(game)),
|
||||||
m_architecture_mismatch(gameArchitecture != OWN_ARCHITECTURE),
|
m_word_size_mismatch(gameWordSize != OWN_WORD_SIZE),
|
||||||
m_pointer_size(GetPointerSizeForArchitecture(gameArchitecture)),
|
m_pointer_size(GetPointerSizeForWordSize(gameWordSize)),
|
||||||
m_blocks(std::move(fastFileBlocks)),
|
m_blocks(std::move(fastFileBlocks)),
|
||||||
m_default_normal_block(nullptr),
|
m_default_normal_block(nullptr),
|
||||||
m_default_temp_block(nullptr)
|
m_default_temp_block(nullptr)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class BaseRenderingContext
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::string m_game;
|
std::string m_game;
|
||||||
bool m_architecture_mismatch;
|
bool m_word_size_mismatch;
|
||||||
unsigned m_pointer_size;
|
unsigned m_pointer_size;
|
||||||
std::vector<const FastFileBlock*> m_blocks;
|
std::vector<const FastFileBlock*> m_blocks;
|
||||||
|
|
||||||
@@ -17,5 +17,5 @@ public:
|
|||||||
const FastFileBlock* m_default_temp_block;
|
const FastFileBlock* m_default_temp_block;
|
||||||
|
|
||||||
protected:
|
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,
|
OncePerAssetRenderingContext::OncePerAssetRenderingContext(std::string game, const WordSize gameWordSize, std::vector<const FastFileBlock*> fastFileBlocks)
|
||||||
const Architecture gameArchitecture,
|
: BaseRenderingContext(std::move(game), gameWordSize, std::move(fastFileBlocks)),
|
||||||
std::vector<const FastFileBlock*> fastFileBlocks)
|
|
||||||
: BaseRenderingContext(std::move(game), gameArchitecture, std::move(fastFileBlocks)),
|
|
||||||
m_asset(nullptr),
|
m_asset(nullptr),
|
||||||
m_has_actions(false)
|
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)
|
std::unique_ptr<OncePerAssetRenderingContext> OncePerAssetRenderingContext::BuildContext(const IDataRepository* repository, StructureInformation* asset)
|
||||||
{
|
{
|
||||||
auto context = std::make_unique<OncePerAssetRenderingContext>(
|
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->MakeAsset(repository, asset);
|
||||||
context->CreateUsedTypeCollections();
|
context->CreateUsedTypeCollections();
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public:
|
|||||||
bool m_has_actions;
|
bool m_has_actions;
|
||||||
|
|
||||||
private:
|
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* AddUsedType(std::unique_ptr<RenderingUsedType> usedType);
|
||||||
RenderingUsedType* GetBaseType(const IDataRepository* repository, MemberComputations* computations, RenderingUsedType* usedType);
|
RenderingUsedType* GetBaseType(const IDataRepository* repository, MemberComputations* computations, RenderingUsedType* usedType);
|
||||||
|
|||||||
@@ -5,10 +5,10 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
OncePerTemplateRenderingContext::OncePerTemplateRenderingContext(std::string game,
|
OncePerTemplateRenderingContext::OncePerTemplateRenderingContext(std::string game,
|
||||||
const Architecture gameArchitecture,
|
const WordSize gameWordSize,
|
||||||
std::vector<const FastFileBlock*> fastFileBlocks,
|
std::vector<const FastFileBlock*> fastFileBlocks,
|
||||||
std::vector<StructureInformation*> assets)
|
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))
|
m_assets(std::move(assets))
|
||||||
{
|
{
|
||||||
for (const auto* block : m_blocks)
|
for (const auto* block : m_blocks)
|
||||||
@@ -35,5 +35,5 @@ std::unique_ptr<OncePerTemplateRenderingContext> OncePerTemplateRenderingContext
|
|||||||
}
|
}
|
||||||
|
|
||||||
return std::make_unique<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:
|
private:
|
||||||
OncePerTemplateRenderingContext(std::string game,
|
OncePerTemplateRenderingContext(std::string game,
|
||||||
Architecture gameArchitecture,
|
WordSize gameWordSize,
|
||||||
std::vector<const FastFileBlock*> fastFileBlocks,
|
std::vector<const FastFileBlock*> fastFileBlocks,
|
||||||
std::vector<StructureInformation*> assets);
|
std::vector<StructureInformation*> assets);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ namespace
|
|||||||
m_intendation++;
|
m_intendation++;
|
||||||
|
|
||||||
// Method Declarations
|
// Method Declarations
|
||||||
if (m_env.m_architecture_mismatch)
|
if (m_env.m_word_size_mismatch)
|
||||||
{
|
{
|
||||||
for (const auto* type : m_env.m_used_types)
|
for (const auto* type : m_env.m_used_types)
|
||||||
{
|
{
|
||||||
@@ -190,7 +190,7 @@ namespace
|
|||||||
LINE("")
|
LINE("")
|
||||||
PrintMainLoadMethod();
|
PrintMainLoadMethod();
|
||||||
|
|
||||||
if (m_env.m_architecture_mismatch)
|
if (m_env.m_word_size_mismatch)
|
||||||
{
|
{
|
||||||
for (const auto* type : m_env.m_used_types)
|
for (const auto* type : m_env.m_used_types)
|
||||||
{
|
{
|
||||||
@@ -899,7 +899,7 @@ namespace
|
|||||||
{
|
{
|
||||||
LINEF("*{0} = m_stream.{1}<{2}>({3});",
|
LINEF("*{0} = m_stream.{1}<{2}>({3});",
|
||||||
MakeTypePtrVarName(def),
|
MakeTypePtrVarName(def),
|
||||||
m_env.m_architecture_mismatch ? "AllocOutOfBlock" : "Alloc",
|
m_env.m_word_size_mismatch ? "AllocOutOfBlock" : "Alloc",
|
||||||
def->GetFullName(),
|
def->GetFullName(),
|
||||||
def->GetAlignment())
|
def->GetAlignment())
|
||||||
}
|
}
|
||||||
@@ -976,7 +976,7 @@ namespace
|
|||||||
|
|
||||||
LINE("if (atStreamStart)")
|
LINE("if (atStreamStart)")
|
||||||
|
|
||||||
if (m_env.m_architecture_mismatch)
|
if (m_env.m_word_size_mismatch)
|
||||||
{
|
{
|
||||||
LINE("{")
|
LINE("{")
|
||||||
m_intendation++;
|
m_intendation++;
|
||||||
@@ -1210,7 +1210,7 @@ namespace
|
|||||||
{
|
{
|
||||||
LINEF("{0} = {1};", MakeTypeVarName(member->m_member->m_type_declaration->m_type), MakeMemberAccess(info, member, modifier))
|
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)
|
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()))
|
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});",
|
LINEF("m_stream.Load<{0}{1}>({2}, {3});",
|
||||||
MakeTypeDecl(member->m_member->m_type_declaration.get()),
|
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("{0} = {1};", MakeTypeVarName(member->m_member->m_type_declaration->m_type), MakeMemberAccess(info, member, modifier))
|
||||||
LINEF("LoadArray_{0}({1}, {2});",
|
LINEF("LoadArray_{0}({1}, {2});",
|
||||||
MakeSafeTypeName(member->m_member->m_type_declaration->m_type),
|
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()))
|
MakeEvaluation(modifier.GetDynamicArraySizeEvaluation()))
|
||||||
}
|
}
|
||||||
else if (info->m_has_matching_cross_platform_structure)
|
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)")
|
LINE("if (atStreamStart)")
|
||||||
m_intendation++;
|
m_intendation++;
|
||||||
@@ -1265,7 +1265,7 @@ namespace
|
|||||||
MakeMemberAccess(info, member, modifier),
|
MakeMemberAccess(info, member, modifier),
|
||||||
MakeEvaluation(modifier.GetDynamicArraySizeEvaluation()))
|
MakeEvaluation(modifier.GetDynamicArraySizeEvaluation()))
|
||||||
|
|
||||||
if (m_env.m_architecture_mismatch)
|
if (m_env.m_word_size_mismatch)
|
||||||
{
|
{
|
||||||
m_intendation--;
|
m_intendation--;
|
||||||
}
|
}
|
||||||
@@ -1279,7 +1279,7 @@ namespace
|
|||||||
{
|
{
|
||||||
LINEF("{0} = &{1};", MakeTypeVarName(member->m_member->m_type_declaration->m_type), MakeMemberAccess(info, member, modifier))
|
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))
|
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()))
|
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});",
|
LINEF("m_stream.Load<{0}{1}>(&{2});",
|
||||||
MakeTypeDecl(member->m_member->m_type_declaration.get()),
|
MakeTypeDecl(member->m_member->m_type_declaration.get()),
|
||||||
@@ -1421,7 +1421,7 @@ namespace
|
|||||||
|
|
||||||
[[nodiscard]] bool ShouldAllocOutOfBlock(const MemberInformation& member, const MemberLoadType loadType) const
|
[[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);
|
&& ((member.m_type && !member.m_type->m_has_matching_cross_platform_structure) || loadType == MemberLoadType::POINTER_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1505,7 +1505,7 @@ namespace
|
|||||||
{
|
{
|
||||||
LINE("")
|
LINE("")
|
||||||
|
|
||||||
if (m_env.m_architecture_mismatch)
|
if (m_env.m_word_size_mismatch)
|
||||||
LINE("uintptr_t toInsertLookupEntry = 0;")
|
LINE("uintptr_t toInsertLookupEntry = 0;")
|
||||||
else
|
else
|
||||||
LINEF("{0}** toInsert = nullptr;", member->m_member->m_type_declaration->m_type->GetFullName())
|
LINEF("{0}** toInsert = nullptr;", member->m_member->m_type_declaration->m_type->GetFullName())
|
||||||
@@ -1513,7 +1513,7 @@ namespace
|
|||||||
LINE("if (zonePtrType == ZonePointerType::INSERT)")
|
LINE("if (zonePtrType == ZonePointerType::INSERT)")
|
||||||
m_intendation++;
|
m_intendation++;
|
||||||
|
|
||||||
if (m_env.m_architecture_mismatch)
|
if (m_env.m_word_size_mismatch)
|
||||||
LINE("toInsertLookupEntry = m_stream.InsertPointerAliasLookup();")
|
LINE("toInsertLookupEntry = m_stream.InsertPointerAliasLookup();")
|
||||||
else
|
else
|
||||||
LINEF("toInsert = m_stream.InsertPointerNative<{0}>();", member->m_member->m_type_declaration->m_type->GetFullName())
|
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)")
|
LINE("if (zonePtrType == ZonePointerType::INSERT)")
|
||||||
m_intendation++;
|
m_intendation++;
|
||||||
|
|
||||||
if (m_env.m_architecture_mismatch)
|
if (m_env.m_word_size_mismatch)
|
||||||
LINEF(
|
LINEF(
|
||||||
"m_stream.SetInsertedPointerAliasLookup(toInsertLookupEntry, {0}->{1});", MakeTypeVarName(info->m_definition), member->m_member->m_name)
|
"m_stream.SetInsertedPointerAliasLookup(toInsertLookupEntry, {0}->{1});", MakeTypeVarName(info->m_definition), member->m_member->m_name)
|
||||||
else
|
else
|
||||||
@@ -1909,7 +1909,7 @@ namespace
|
|||||||
}
|
}
|
||||||
m_intendation--;
|
m_intendation--;
|
||||||
}
|
}
|
||||||
else if (!m_env.m_architecture_mismatch)
|
else if (!m_env.m_word_size_mismatch)
|
||||||
{
|
{
|
||||||
LINE("assert(atStreamStart);")
|
LINE("assert(atStreamStart);")
|
||||||
}
|
}
|
||||||
@@ -1950,7 +1950,7 @@ namespace
|
|||||||
LINEF("assert({0} != nullptr);", MakeTypePtrVarName(info->m_definition))
|
LINEF("assert({0} != nullptr);", MakeTypePtrVarName(info->m_definition))
|
||||||
LINE("")
|
LINE("")
|
||||||
|
|
||||||
if (!m_env.m_architecture_mismatch)
|
if (!m_env.m_word_size_mismatch)
|
||||||
{
|
{
|
||||||
LINE("if (atStreamStart)")
|
LINE("if (atStreamStart)")
|
||||||
m_intendation++;
|
m_intendation++;
|
||||||
@@ -1987,7 +1987,7 @@ namespace
|
|||||||
|
|
||||||
LINEF("*{0} = m_stream.{1}<{2}>({3});",
|
LINEF("*{0} = m_stream.{1}<{2}>({3});",
|
||||||
MakeTypePtrVarName(info->m_definition),
|
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->GetFullName(),
|
||||||
info->m_definition->GetAlignment())
|
info->m_definition->GetAlignment())
|
||||||
|
|
||||||
@@ -1995,7 +1995,7 @@ namespace
|
|||||||
{
|
{
|
||||||
LINE("")
|
LINE("")
|
||||||
|
|
||||||
if (m_env.m_architecture_mismatch)
|
if (m_env.m_word_size_mismatch)
|
||||||
LINE("uintptr_t toInsertLookupEntry = 0;")
|
LINE("uintptr_t toInsertLookupEntry = 0;")
|
||||||
else
|
else
|
||||||
LINEF("{0}** toInsert = nullptr;", info->m_definition->GetFullName())
|
LINEF("{0}** toInsert = nullptr;", info->m_definition->GetFullName())
|
||||||
@@ -2003,7 +2003,7 @@ namespace
|
|||||||
LINE("if (zonePtrType == ZonePointerType::INSERT)")
|
LINE("if (zonePtrType == ZonePointerType::INSERT)")
|
||||||
m_intendation++;
|
m_intendation++;
|
||||||
|
|
||||||
if (m_env.m_architecture_mismatch)
|
if (m_env.m_word_size_mismatch)
|
||||||
LINE("toInsertLookupEntry = m_stream.InsertPointerAliasLookup();")
|
LINE("toInsertLookupEntry = m_stream.InsertPointerAliasLookup();")
|
||||||
else
|
else
|
||||||
LINEF("toInsert = m_stream.InsertPointerNative<{0}>();", info->m_definition->GetFullName())
|
LINEF("toInsert = m_stream.InsertPointerNative<{0}>();", info->m_definition->GetFullName())
|
||||||
@@ -2050,7 +2050,7 @@ namespace
|
|||||||
LINE("if (zonePtrType == ZonePointerType::INSERT)")
|
LINE("if (zonePtrType == ZonePointerType::INSERT)")
|
||||||
m_intendation++;
|
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))
|
LINEF("m_stream.SetInsertedPointerAliasLookup(toInsertLookupEntry, *{0});", MakeTypePtrVarName(info->m_definition))
|
||||||
else
|
else
|
||||||
LINEF("*toInsert = *{0};", MakeTypePtrVarName(info->m_definition))
|
LINEF("*toInsert = *{0};", MakeTypePtrVarName(info->m_definition))
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ namespace
|
|||||||
m_intendation++;
|
m_intendation++;
|
||||||
|
|
||||||
// Method Declarations
|
// Method Declarations
|
||||||
if (m_env.m_architecture_mismatch)
|
if (m_env.m_word_size_mismatch)
|
||||||
{
|
{
|
||||||
for (const auto* type : m_env.m_used_types)
|
for (const auto* type : m_env.m_used_types)
|
||||||
{
|
{
|
||||||
@@ -178,7 +178,7 @@ namespace
|
|||||||
LINE("")
|
LINE("")
|
||||||
PrintMainWriteMethod();
|
PrintMainWriteMethod();
|
||||||
|
|
||||||
if (m_env.m_architecture_mismatch)
|
if (m_env.m_word_size_mismatch)
|
||||||
{
|
{
|
||||||
for (const auto* type : m_env.m_used_types)
|
for (const auto* type : m_env.m_used_types)
|
||||||
{
|
{
|
||||||
@@ -335,7 +335,7 @@ namespace
|
|||||||
MakeTypeWrittenVarNameInternal(info->m_definition, str);
|
MakeTypeWrittenVarNameInternal(info->m_definition, str);
|
||||||
str << ".AtOffset(";
|
str << ".AtOffset(";
|
||||||
|
|
||||||
if (m_env.m_architecture_mismatch)
|
if (m_env.m_word_size_mismatch)
|
||||||
{
|
{
|
||||||
str << OffsetForMemberModifier(*member, modifier, 0);
|
str << OffsetForMemberModifier(*member, modifier, 0);
|
||||||
}
|
}
|
||||||
@@ -837,7 +837,7 @@ namespace
|
|||||||
|
|
||||||
std::string MakeReusableInnerOffset(const DataDefinition* dataDefinition, const Variable* member) const
|
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::to_string(member->m_offset);
|
||||||
|
|
||||||
return std::format("offsetof({0}, {1})", dataDefinition->GetFullName(), member->m_name);
|
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/SequenceAction.h"
|
||||||
#include "Parsing/Commands/Sequence/SequenceAllocAlign.h"
|
#include "Parsing/Commands/Sequence/SequenceAllocAlign.h"
|
||||||
#include "Parsing/Commands/Sequence/SequenceArchitecture.h"
|
|
||||||
#include "Parsing/Commands/Sequence/SequenceArrayCount.h"
|
#include "Parsing/Commands/Sequence/SequenceArrayCount.h"
|
||||||
#include "Parsing/Commands/Sequence/SequenceArraySize.h"
|
#include "Parsing/Commands/Sequence/SequenceArraySize.h"
|
||||||
#include "Parsing/Commands/Sequence/SequenceAsset.h"
|
#include "Parsing/Commands/Sequence/SequenceAsset.h"
|
||||||
@@ -17,6 +16,7 @@
|
|||||||
#include "Parsing/Commands/Sequence/SequenceSetBlock.h"
|
#include "Parsing/Commands/Sequence/SequenceSetBlock.h"
|
||||||
#include "Parsing/Commands/Sequence/SequenceString.h"
|
#include "Parsing/Commands/Sequence/SequenceString.h"
|
||||||
#include "Parsing/Commands/Sequence/SequenceUse.h"
|
#include "Parsing/Commands/Sequence/SequenceUse.h"
|
||||||
|
#include "Parsing/Commands/Sequence/SequenceWordSize.h"
|
||||||
|
|
||||||
CommandsParser::CommandsParser(CommandsLexer* lexer, IDataRepository* targetRepository)
|
CommandsParser::CommandsParser(CommandsLexer* lexer, IDataRepository* targetRepository)
|
||||||
: AbstractParser(lexer, std::make_unique<CommandsParserState>(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({
|
static std::vector<sequence_t*> tests({
|
||||||
new SequenceAction(),
|
new SequenceAction(),
|
||||||
new SequenceAllocAlign(),
|
new SequenceAllocAlign(),
|
||||||
new SequenceArchitecture(),
|
|
||||||
new SequenceArrayCount(),
|
new SequenceArrayCount(),
|
||||||
new SequenceArraySize(),
|
new SequenceArraySize(),
|
||||||
new SequenceAsset(),
|
new SequenceAsset(),
|
||||||
@@ -44,6 +43,7 @@ const std::vector<CommandsParser::sequence_t*>& CommandsParser::GetTestsForState
|
|||||||
new SequenceSetBlock(),
|
new SequenceSetBlock(),
|
||||||
new SequenceString(),
|
new SequenceString(),
|
||||||
new SequenceUse(),
|
new SequenceUse(),
|
||||||
|
new SequenceWordSize(),
|
||||||
});
|
});
|
||||||
|
|
||||||
return tests;
|
return tests;
|
||||||
|
|||||||
@@ -74,9 +74,9 @@ void CommandsParserState::AddBlock(std::unique_ptr<FastFileBlock> block) const
|
|||||||
m_repository->Add(std::move(block));
|
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
|
void CommandsParserState::SetGame(std::string gameName) const
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ public:
|
|||||||
[[nodiscard]] const IDataRepository* GetRepository() const;
|
[[nodiscard]] const IDataRepository* GetRepository() const;
|
||||||
|
|
||||||
void AddBlock(std::unique_ptr<FastFileBlock> block) 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;
|
void SetGame(std::string gameName) const;
|
||||||
|
|
||||||
[[nodiscard]] StructureInformation* GetInUse() 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)
|
if (hasPointerModifier)
|
||||||
{
|
{
|
||||||
declaration->m_alignment = GetPointerSizeForArchitecture(repository->GetArchitecture());
|
declaration->m_alignment = GetPointerSizeForWordSize(repository->GetWordSize());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -92,7 +92,7 @@ namespace
|
|||||||
switch (declarationModifier->GetType())
|
switch (declarationModifier->GetType())
|
||||||
{
|
{
|
||||||
case DeclarationModifierType::POINTER:
|
case DeclarationModifierType::POINTER:
|
||||||
currentSize = GetPointerSizeForArchitecture(repository->GetArchitecture());
|
currentSize = GetPointerSizeForWordSize(repository->GetWordSize());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DeclarationModifierType::ARRAY:
|
case DeclarationModifierType::ARRAY:
|
||||||
@@ -256,9 +256,9 @@ namespace
|
|||||||
|
|
||||||
bool CalculateSizeAndAlignPostProcessor::PostProcess(IDataRepository* repository)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -40,7 +40,7 @@ bool CrossPlatformStructurePostProcessor::PostProcess(IDataRepository* repositor
|
|||||||
{
|
{
|
||||||
const auto& allInfos = repository->GetAllStructureInformation();
|
const auto& allInfos = repository->GetAllStructureInformation();
|
||||||
|
|
||||||
if (repository->GetArchitecture() == OWN_ARCHITECTURE)
|
if (repository->GetWordSize() == OWN_WORD_SIZE)
|
||||||
{
|
{
|
||||||
for (const auto& info : allInfos)
|
for (const auto& info : allInfos)
|
||||||
info->m_has_matching_cross_platform_structure = true;
|
info->m_has_matching_cross_platform_structure = true;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include "Domain/Definition/StructDefinition.h"
|
#include "Domain/Definition/StructDefinition.h"
|
||||||
#include "Domain/Definition/TypedefDefinition.h"
|
#include "Domain/Definition/TypedefDefinition.h"
|
||||||
#include "Domain/Definition/UnionDefinition.h"
|
#include "Domain/Definition/UnionDefinition.h"
|
||||||
#include "Domain/Environment/Architecture.h"
|
#include "Domain/Environment/WordSize.h"
|
||||||
#include "Domain/FastFile/FastFileBlock.h"
|
#include "Domain/FastFile/FastFileBlock.h"
|
||||||
#include "Domain/Information/StructureInformation.h"
|
#include "Domain/Information/StructureInformation.h"
|
||||||
|
|
||||||
@@ -30,8 +30,8 @@ public:
|
|||||||
|
|
||||||
[[nodiscard]] virtual const std::string& GetGameName() const = 0;
|
[[nodiscard]] virtual const std::string& GetGameName() const = 0;
|
||||||
virtual void SetGame(std::string gameName) = 0;
|
virtual void SetGame(std::string gameName) = 0;
|
||||||
[[nodiscard]] virtual Architecture GetArchitecture() const = 0;
|
[[nodiscard]] virtual WordSize GetWordSize() const = 0;
|
||||||
virtual void SetArchitecture(Architecture architecture) = 0;
|
virtual void SetWordSize(WordSize wordSize) = 0;
|
||||||
|
|
||||||
[[nodiscard]] virtual const std::vector<EnumDefinition*>& GetAllEnums() const = 0;
|
[[nodiscard]] virtual const std::vector<EnumDefinition*>& GetAllEnums() const = 0;
|
||||||
[[nodiscard]] virtual const std::vector<StructDefinition*>& GetAllStructs() const = 0;
|
[[nodiscard]] virtual const std::vector<StructDefinition*>& GetAllStructs() const = 0;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "InMemoryRepository.h"
|
#include "InMemoryRepository.h"
|
||||||
|
|
||||||
InMemoryRepository::InMemoryRepository()
|
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);
|
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
|
const std::vector<EnumDefinition*>& InMemoryRepository::GetAllEnums() const
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ public:
|
|||||||
|
|
||||||
[[nodiscard]] const std::string& GetGameName() const override;
|
[[nodiscard]] const std::string& GetGameName() const override;
|
||||||
void SetGame(std::string gameName) override;
|
void SetGame(std::string gameName) override;
|
||||||
[[nodiscard]] Architecture GetArchitecture() const override;
|
[[nodiscard]] WordSize GetWordSize() const override;
|
||||||
void SetArchitecture(Architecture architecture) override;
|
void SetWordSize(WordSize wordSize) override;
|
||||||
|
|
||||||
[[nodiscard]] const std::vector<EnumDefinition*>& GetAllEnums() const override;
|
[[nodiscard]] const std::vector<EnumDefinition*>& GetAllEnums() const override;
|
||||||
[[nodiscard]] const std::vector<StructDefinition*>& GetAllStructs() 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 DefinitionWithMembers*, StructureInformation*> m_structure_information_by_definition;
|
||||||
std::unordered_map<const DataDefinition*, TypeInformation*> m_type_information_by_definition;
|
std::unordered_map<const DataDefinition*, TypeInformation*> m_type_information_by_definition;
|
||||||
std::string m_game_name;
|
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 "Parsing/Mock/MockLexer.h"
|
||||||
#include "Persistence/InMemory/InMemoryRepository.h"
|
#include "Persistence/InMemory/InMemoryRepository.h"
|
||||||
|
|
||||||
#include <catch2/catch_test_macros.hpp>
|
#include <catch2/catch_test_macros.hpp>
|
||||||
#include <catch2/generators/catch_generators.hpp>
|
#include <catch2/generators/catch_generators.hpp>
|
||||||
|
|
||||||
namespace test::parsing::commands::sequence::sequence_architecture
|
namespace test::parsing::commands::sequence::sequence_word_size
|
||||||
{
|
{
|
||||||
class CommandsSequenceTestsHelper
|
class CommandsSequenceTestsHelper
|
||||||
{
|
{
|
||||||
@@ -31,18 +31,18 @@ namespace test::parsing::commands::sequence::sequence_architecture
|
|||||||
bool PerformTest()
|
bool PerformTest()
|
||||||
{
|
{
|
||||||
REQUIRE(m_lexer);
|
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);
|
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;
|
CommandsSequenceTestsHelper helper;
|
||||||
const TokenPos pos;
|
const TokenPos pos;
|
||||||
helper.Tokens({
|
helper.Tokens({
|
||||||
CommandsParserValue::Identifier(pos, new std::string("architecture")),
|
CommandsParserValue::Identifier(pos, new std::string("wordsize")),
|
||||||
CommandsParserValue::Identifier(pos, new std::string("x86")),
|
CommandsParserValue::Integer(pos, 32),
|
||||||
CommandsParserValue::Character(pos, ';'),
|
CommandsParserValue::Character(pos, ';'),
|
||||||
CommandsParserValue::EndOfFile(pos),
|
CommandsParserValue::EndOfFile(pos),
|
||||||
});
|
});
|
||||||
@@ -51,16 +51,16 @@ namespace test::parsing::commands::sequence::sequence_architecture
|
|||||||
|
|
||||||
REQUIRE(result);
|
REQUIRE(result);
|
||||||
REQUIRE(helper.m_consumed_token_count == 3);
|
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;
|
CommandsSequenceTestsHelper helper;
|
||||||
const TokenPos pos;
|
const TokenPos pos;
|
||||||
helper.Tokens({
|
helper.Tokens({
|
||||||
CommandsParserValue::Identifier(pos, new std::string("architecture")),
|
CommandsParserValue::Identifier(pos, new std::string("wordsize")),
|
||||||
CommandsParserValue::Identifier(pos, new std::string("x86")),
|
CommandsParserValue::Integer(pos, 64),
|
||||||
CommandsParserValue::Character(pos, ';'),
|
CommandsParserValue::Character(pos, ';'),
|
||||||
CommandsParserValue::EndOfFile(pos),
|
CommandsParserValue::EndOfFile(pos),
|
||||||
});
|
});
|
||||||
@@ -69,21 +69,21 @@ namespace test::parsing::commands::sequence::sequence_architecture
|
|||||||
|
|
||||||
REQUIRE(result);
|
REQUIRE(result);
|
||||||
REQUIRE(helper.m_consumed_token_count == 3);
|
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;
|
CommandsSequenceTestsHelper helper;
|
||||||
const TokenPos pos;
|
const TokenPos pos;
|
||||||
helper.Tokens({
|
helper.Tokens({
|
||||||
CommandsParserValue::Identifier(pos, new std::string("architecture")),
|
CommandsParserValue::Identifier(pos, new std::string("wordsize")),
|
||||||
CommandsParserValue::Identifier(pos, new std::string("x1337")),
|
CommandsParserValue::Integer(pos, 1337),
|
||||||
CommandsParserValue::Character(pos, ';'),
|
CommandsParserValue::Character(pos, ';'),
|
||||||
CommandsParserValue::EndOfFile(pos),
|
CommandsParserValue::EndOfFile(pos),
|
||||||
});
|
});
|
||||||
|
|
||||||
REQUIRE_THROWS_AS(helper.PerformTest(), ParsingException);
|
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