From b7276fb63ca185cd2e18aea8f0edfeb03c6627ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Wed, 27 Dec 2023 23:05:36 +0200 Subject: [PATCH 1/6] Move register base type to base folder --- CMakeLists.txt | 2 +- include/zasm/{program => base}/register.hpp | 0 include/zasm/program/memory.hpp | 2 +- include/zasm/program/operand.hpp | 8 ++++---- include/zasm/x86/register.hpp | 2 +- src/zasm/src/formatter/formatter.cpp | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) rename include/zasm/{program => base}/register.hpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index bc331e2..a191ca5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,6 +91,7 @@ set(zasm_SOURCES "include/zasm/base/instruction.hpp" "include/zasm/base/meta.hpp" "include/zasm/base/mode.hpp" + "include/zasm/base/register.hpp" "include/zasm/core/bitsize.hpp" "include/zasm/core/enumflags.hpp" "include/zasm/core/errors.hpp" @@ -118,7 +119,6 @@ set(zasm_SOURCES "include/zasm/program/observer.hpp" "include/zasm/program/operand.hpp" "include/zasm/program/program.hpp" - "include/zasm/program/register.hpp" "include/zasm/program/saverestore.hpp" "include/zasm/program/section.hpp" "include/zasm/program/sentinel.hpp" diff --git a/include/zasm/program/register.hpp b/include/zasm/base/register.hpp similarity index 100% rename from include/zasm/program/register.hpp rename to include/zasm/base/register.hpp diff --git a/include/zasm/program/memory.hpp b/include/zasm/program/memory.hpp index 6de116f..77f5cfc 100644 --- a/include/zasm/program/memory.hpp +++ b/include/zasm/program/memory.hpp @@ -2,11 +2,11 @@ #include "immediate.hpp" #include "label.hpp" -#include "register.hpp" #include #include #include +#include #include #include diff --git a/include/zasm/program/operand.hpp b/include/zasm/program/operand.hpp index 3a0893d..88338b3 100644 --- a/include/zasm/program/operand.hpp +++ b/include/zasm/program/operand.hpp @@ -3,10 +3,10 @@ #include "immediate.hpp" #include "label.hpp" #include "memory.hpp" -#include "register.hpp" #include #include +#include #include namespace zasm @@ -232,7 +232,7 @@ namespace zasm { return std::holds_alternative(_data); } - + /// /// Returns a reference with given type, throws if type mismatches. /// @@ -284,7 +284,7 @@ namespace zasm } return nullptr; } - + /// /// Returns a pointer with the type specified if the type matches. /// @@ -358,7 +358,7 @@ namespace zasm } /// - /// Returns the size of the operand, some operands can have different sizes + /// Returns the size of the operand, some operands can have different sizes /// depending on the machine mode. /// /// Machine mode diff --git a/include/zasm/x86/register.hpp b/include/zasm/x86/register.hpp index 1dbc09b..d228ed2 100644 --- a/include/zasm/x86/register.hpp +++ b/include/zasm/x86/register.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include +#include namespace zasm::x86 { diff --git a/src/zasm/src/formatter/formatter.cpp b/src/zasm/src/formatter/formatter.cpp index f68fd77..ca916d2 100644 --- a/src/zasm/src/formatter/formatter.cpp +++ b/src/zasm/src/formatter/formatter.cpp @@ -5,11 +5,11 @@ #include #include #include +#include #include #include #include #include -#include #include #include #include @@ -225,7 +225,7 @@ namespace zasm::formatter || base.getPhysicalIndex() == x86::bp.getPhysicalIndex()) { return x86::ss; - } + } } return x86::ds; } From 7874cf05e35e7a8323cefdc3934fa73918df0953 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Wed, 27 Dec 2023 23:10:28 +0200 Subject: [PATCH 2/6] Move immediate type to base folder --- CMakeLists.txt | 2 +- include/zasm/{program => base}/immediate.hpp | 0 include/zasm/program/memory.hpp | 1 - include/zasm/program/operand.hpp | 2 +- 4 files changed, 2 insertions(+), 3 deletions(-) rename include/zasm/{program => base}/immediate.hpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index a191ca5..366960b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,6 +88,7 @@ set(zasm_SOURCES "src/zasm/src/program/program.state.hpp" "src/zasm/src/program/saverestorehelper.hpp" "src/zasm/src/program/saverestoretypes.hpp" + "include/zasm/base/immediate.hpp" "include/zasm/base/instruction.hpp" "include/zasm/base/meta.hpp" "include/zasm/base/mode.hpp" @@ -110,7 +111,6 @@ set(zasm_SOURCES "include/zasm/program/align.hpp" "include/zasm/program/data.hpp" "include/zasm/program/embeddedlabel.hpp" - "include/zasm/program/immediate.hpp" "include/zasm/program/instruction.hpp" "include/zasm/program/label.hpp" "include/zasm/program/labeldata.hpp" diff --git a/include/zasm/program/immediate.hpp b/include/zasm/base/immediate.hpp similarity index 100% rename from include/zasm/program/immediate.hpp rename to include/zasm/base/immediate.hpp diff --git a/include/zasm/program/memory.hpp b/include/zasm/program/memory.hpp index 77f5cfc..fdd915b 100644 --- a/include/zasm/program/memory.hpp +++ b/include/zasm/program/memory.hpp @@ -1,6 +1,5 @@ #pragma once -#include "immediate.hpp" #include "label.hpp" #include diff --git a/include/zasm/program/operand.hpp b/include/zasm/program/operand.hpp index 88338b3..d4db535 100644 --- a/include/zasm/program/operand.hpp +++ b/include/zasm/program/operand.hpp @@ -1,11 +1,11 @@ #pragma once -#include "immediate.hpp" #include "label.hpp" #include "memory.hpp" #include #include +#include #include #include From fc95dc3f4f7350bcb14bfac155944475024d689b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Wed, 27 Dec 2023 23:14:56 +0200 Subject: [PATCH 3/6] Safe guard Packed with static_assert --- include/zasm/core/packed.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/zasm/core/packed.hpp b/include/zasm/core/packed.hpp index 448ed61..d5ea0fb 100644 --- a/include/zasm/core/packed.hpp +++ b/include/zasm/core/packed.hpp @@ -11,6 +11,7 @@ namespace zasm /// /// Container to tightly pack multiple elements with a given bit size to store /// in the provided underlying type. + /// Example: Specifying the underlying type as uint32_t and element bit size of 10 allows you to store 3 elements. /// /// The underlying storage type /// Value type of each element packed @@ -23,6 +24,8 @@ namespace zasm static constexpr std::size_t kStorageBitSize = std::numeric_limits::digits; static constexpr std::size_t kCapacity = kStorageBitSize / TElementBitSize; + static_assert(kCapacity * TElementBitSize <= kStorageBitSize, "Storage type is too small to store all elements"); + TUnderlying _data{}; public: @@ -42,7 +45,7 @@ namespace zasm { return _data == other._data; } - + constexpr bool operator!=(const Packed& other) const noexcept { return _data == other._data; From 028bd1d4b8b57f2b878a519f7d9a5f67c13b8136 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Wed, 27 Dec 2023 23:18:24 +0200 Subject: [PATCH 4/6] Move Label to base folder --- CMakeLists.txt | 2 +- include/zasm/{program => base}/label.hpp | 0 include/zasm/program/embeddedlabel.hpp | 3 +-- include/zasm/program/labeldata.hpp | 2 +- include/zasm/program/memory.hpp | 3 +-- include/zasm/program/node.hpp | 2 +- include/zasm/program/operand.hpp | 2 +- include/zasm/program/program.hpp | 2 +- src/zasm/src/encoder/encoder.context.hpp | 2 +- src/zasm/src/program/program.state.hpp | 4 ++-- 10 files changed, 10 insertions(+), 12 deletions(-) rename include/zasm/{program => base}/label.hpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 366960b..58f739d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,6 +90,7 @@ set(zasm_SOURCES "src/zasm/src/program/saverestoretypes.hpp" "include/zasm/base/immediate.hpp" "include/zasm/base/instruction.hpp" + "include/zasm/base/label.hpp" "include/zasm/base/meta.hpp" "include/zasm/base/mode.hpp" "include/zasm/base/register.hpp" @@ -112,7 +113,6 @@ set(zasm_SOURCES "include/zasm/program/data.hpp" "include/zasm/program/embeddedlabel.hpp" "include/zasm/program/instruction.hpp" - "include/zasm/program/label.hpp" "include/zasm/program/labeldata.hpp" "include/zasm/program/memory.hpp" "include/zasm/program/node.hpp" diff --git a/include/zasm/program/label.hpp b/include/zasm/base/label.hpp similarity index 100% rename from include/zasm/program/label.hpp rename to include/zasm/base/label.hpp diff --git a/include/zasm/program/embeddedlabel.hpp b/include/zasm/program/embeddedlabel.hpp index 7d314a5..d7791b1 100644 --- a/include/zasm/program/embeddedlabel.hpp +++ b/include/zasm/program/embeddedlabel.hpp @@ -1,9 +1,8 @@ #pragma once -#include "label.hpp" - #include #include +#include #include namespace zasm diff --git a/include/zasm/program/labeldata.hpp b/include/zasm/program/labeldata.hpp index f9b0575..4371fe2 100644 --- a/include/zasm/program/labeldata.hpp +++ b/include/zasm/program/labeldata.hpp @@ -1,8 +1,8 @@ #pragma once #include +#include #include -#include namespace zasm { diff --git a/include/zasm/program/memory.hpp b/include/zasm/program/memory.hpp index fdd915b..0cfb2eb 100644 --- a/include/zasm/program/memory.hpp +++ b/include/zasm/program/memory.hpp @@ -1,9 +1,8 @@ #pragma once -#include "label.hpp" - #include #include +#include #include #include #include diff --git a/include/zasm/program/node.hpp b/include/zasm/program/node.hpp index 0f39acb..3f16c77 100644 --- a/include/zasm/program/node.hpp +++ b/include/zasm/program/node.hpp @@ -4,13 +4,13 @@ #include "data.hpp" #include "embeddedlabel.hpp" #include "instruction.hpp" -#include "label.hpp" #include "section.hpp" #include "sentinel.hpp" #include #include #include +#include #include namespace zasm diff --git a/include/zasm/program/operand.hpp b/include/zasm/program/operand.hpp index d4db535..362af4b 100644 --- a/include/zasm/program/operand.hpp +++ b/include/zasm/program/operand.hpp @@ -1,11 +1,11 @@ #pragma once -#include "label.hpp" #include "memory.hpp" #include #include #include +#include #include #include diff --git a/include/zasm/program/program.hpp b/include/zasm/program/program.hpp index 8f9a816..4ec3acc 100644 --- a/include/zasm/program/program.hpp +++ b/include/zasm/program/program.hpp @@ -2,13 +2,13 @@ #include "data.hpp" #include "embeddedlabel.hpp" -#include "label.hpp" #include "node.hpp" #include "section.hpp" #include #include #include +#include #include #include #include diff --git a/src/zasm/src/encoder/encoder.context.hpp b/src/zasm/src/encoder/encoder.context.hpp index 008dd1e..7370030 100644 --- a/src/zasm/src/encoder/encoder.context.hpp +++ b/src/zasm/src/encoder/encoder.context.hpp @@ -5,8 +5,8 @@ #include #include #include +#include #include -#include #include namespace zasm diff --git a/src/zasm/src/program/program.state.hpp b/src/zasm/src/program/program.state.hpp index 73ce688..3740289 100644 --- a/src/zasm/src/program/program.state.hpp +++ b/src/zasm/src/program/program.state.hpp @@ -1,12 +1,10 @@ #pragma once -#include "zasm/base/mode.hpp" #include "zasm/core/enumflags.hpp" #include "zasm/core/objectpool.hpp" #include "zasm/core/stringpool.hpp" #include "zasm/encoder/encoder.hpp" #include "zasm/program/data.hpp" -#include "zasm/program/label.hpp" #include "zasm/program/labeldata.hpp" #include "zasm/program/node.hpp" #include "zasm/program/section.hpp" @@ -14,6 +12,8 @@ #include #include #include +#include +#include namespace zasm { From e41cd1ca10e779559fcfb5c555f57c199f852fbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Wed, 27 Dec 2023 23:20:33 +0200 Subject: [PATCH 5/6] Move Mem type to base folder --- CMakeLists.txt | 2 +- include/zasm/{program => base}/memory.hpp | 0 include/zasm/program/operand.hpp | 3 +-- include/zasm/x86/memory.hpp | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) rename include/zasm/{program => base}/memory.hpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 58f739d..92ea61f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,6 +91,7 @@ set(zasm_SOURCES "include/zasm/base/immediate.hpp" "include/zasm/base/instruction.hpp" "include/zasm/base/label.hpp" + "include/zasm/base/memory.hpp" "include/zasm/base/meta.hpp" "include/zasm/base/mode.hpp" "include/zasm/base/register.hpp" @@ -114,7 +115,6 @@ set(zasm_SOURCES "include/zasm/program/embeddedlabel.hpp" "include/zasm/program/instruction.hpp" "include/zasm/program/labeldata.hpp" - "include/zasm/program/memory.hpp" "include/zasm/program/node.hpp" "include/zasm/program/observer.hpp" "include/zasm/program/operand.hpp" diff --git a/include/zasm/program/memory.hpp b/include/zasm/base/memory.hpp similarity index 100% rename from include/zasm/program/memory.hpp rename to include/zasm/base/memory.hpp diff --git a/include/zasm/program/operand.hpp b/include/zasm/program/operand.hpp index 362af4b..f016886 100644 --- a/include/zasm/program/operand.hpp +++ b/include/zasm/program/operand.hpp @@ -1,11 +1,10 @@ #pragma once -#include "memory.hpp" - #include #include #include #include +#include #include #include diff --git a/include/zasm/x86/memory.hpp b/include/zasm/x86/memory.hpp index 2fca2d3..eb16d68 100644 --- a/include/zasm/x86/memory.hpp +++ b/include/zasm/x86/memory.hpp @@ -2,7 +2,7 @@ #include "register.hpp" -#include +#include namespace zasm::x86 { From e0f57004f3f5f166008c2ebac64a39104997cdd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Wed, 27 Dec 2023 23:29:06 +0200 Subject: [PATCH 6/6] Move Operand type to base folder --- CMakeLists.txt | 2 +- include/zasm/base/instruction.hpp | 1 + include/zasm/{program => base}/operand.hpp | 0 include/zasm/program/instruction.hpp | 5 ++--- include/zasm/x86/emitter.hpp | 2 +- src/tests/tests/tests.packed.cpp | 2 +- src/zasm/src/decoder/decoder.cpp | 2 +- src/zasm/src/program/instruction.cpp | 4 ++-- src/zasm/src/program/register.cpp | 10 +++++----- 9 files changed, 14 insertions(+), 14 deletions(-) rename include/zasm/{program => base}/operand.hpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 92ea61f..72b29b8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,6 +94,7 @@ set(zasm_SOURCES "include/zasm/base/memory.hpp" "include/zasm/base/meta.hpp" "include/zasm/base/mode.hpp" + "include/zasm/base/operand.hpp" "include/zasm/base/register.hpp" "include/zasm/core/bitsize.hpp" "include/zasm/core/enumflags.hpp" @@ -117,7 +118,6 @@ set(zasm_SOURCES "include/zasm/program/labeldata.hpp" "include/zasm/program/node.hpp" "include/zasm/program/observer.hpp" - "include/zasm/program/operand.hpp" "include/zasm/program/program.hpp" "include/zasm/program/saverestore.hpp" "include/zasm/program/section.hpp" diff --git a/include/zasm/base/instruction.hpp b/include/zasm/base/instruction.hpp index a12c803..fd8032e 100644 --- a/include/zasm/base/instruction.hpp +++ b/include/zasm/base/instruction.hpp @@ -6,6 +6,7 @@ #include #include #include +#include namespace zasm { diff --git a/include/zasm/program/operand.hpp b/include/zasm/base/operand.hpp similarity index 100% rename from include/zasm/program/operand.hpp rename to include/zasm/base/operand.hpp diff --git a/include/zasm/program/instruction.hpp b/include/zasm/program/instruction.hpp index c66c33c..854edcb 100644 --- a/include/zasm/program/instruction.hpp +++ b/include/zasm/program/instruction.hpp @@ -1,7 +1,5 @@ #pragma once -#include "operand.hpp" - #include #include #include @@ -9,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -77,7 +76,7 @@ namespace zasm return set1 == other.set1 && set0 == other.set0 && modified == other.modified && tested == other.tested && undefined == other.undefined; } - + constexpr bool operator!=(const CPUFlags& other) const { return !(*this == other); diff --git a/include/zasm/x86/emitter.hpp b/include/zasm/x86/emitter.hpp index 1651d33..d796ec0 100644 --- a/include/zasm/x86/emitter.hpp +++ b/include/zasm/x86/emitter.hpp @@ -3,9 +3,9 @@ #include "mnemonic.hpp" #include "register.hpp" +#include #include #include -#include namespace zasm::x86 { diff --git a/src/tests/tests/tests.packed.cpp b/src/tests/tests/tests.packed.cpp index a5409b7..46d4424 100644 --- a/src/tests/tests/tests.packed.cpp +++ b/src/tests/tests/tests.packed.cpp @@ -1,6 +1,6 @@ #include +#include #include -#include #include namespace zasm::tests diff --git a/src/zasm/src/decoder/decoder.cpp b/src/zasm/src/decoder/decoder.cpp index b0ad150..980a500 100644 --- a/src/zasm/src/decoder/decoder.cpp +++ b/src/zasm/src/decoder/decoder.cpp @@ -1,12 +1,12 @@ #include "zasm/decoder/decoder.hpp" #include "zasm/program/instruction.hpp" -#include "zasm/program/operand.hpp" #include "zasm/x86/meta.hpp" #include "zasm/x86/mnemonic.hpp" #include #include +#include namespace zasm { diff --git a/src/zasm/src/program/instruction.cpp b/src/zasm/src/program/instruction.cpp index 2e2766f..11a6a6f 100644 --- a/src/zasm/src/program/instruction.cpp +++ b/src/zasm/src/program/instruction.cpp @@ -2,9 +2,9 @@ #include #include +#include #include #include -#include namespace zasm { @@ -77,4 +77,4 @@ namespace zasm return getDetail(mode, *this); } -} // namespace zasm::x86 +} // namespace zasm diff --git a/src/zasm/src/program/register.cpp b/src/zasm/src/program/register.cpp index a1443dd..eda365c 100644 --- a/src/zasm/src/program/register.cpp +++ b/src/zasm/src/program/register.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include namespace zasm { @@ -143,7 +143,7 @@ namespace zasm { return static_cast(getClass()) == ZydisRegisterClass::ZYDIS_REGCLASS_GPR64; } - + bool Reg::isGp() const noexcept { return isGp8() || isGp16() || isGp32() || isGp64(); @@ -173,7 +173,7 @@ namespace zasm { return static_cast(getClass()) == ZydisRegisterClass::ZYDIS_REGCLASS_BOUND; } - + bool Reg::isControl() const noexcept { return static_cast(getClass()) == ZydisRegisterClass::ZYDIS_REGCLASS_CONTROL; @@ -188,12 +188,12 @@ namespace zasm { return static_cast(getClass()) == ZydisRegisterClass::ZYDIS_REGCLASS_MASK; } - + bool Reg::isMmx() const noexcept { return static_cast(getClass()) == ZydisRegisterClass::ZYDIS_REGCLASS_MMX; } - + bool Reg::isTmm() const noexcept { return static_cast(getClass()) == ZydisRegisterClass::ZYDIS_REGCLASS_TMM;