Skip to content

Commit

Permalink
Merge pull request #109 from zyantific/arch-structure
Browse files Browse the repository at this point in the history
Refactor architecture a bit
  • Loading branch information
ZehMatt authored Jan 12, 2024
2 parents 54b74cc + e0f5700 commit 3c31923
Show file tree
Hide file tree
Showing 23 changed files with 42 additions and 43 deletions.
10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,14 @@ 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/label.hpp"
"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"
"include/zasm/core/errors.hpp"
Expand All @@ -109,16 +114,11 @@ 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"
"include/zasm/program/memory.hpp"
"include/zasm/program/node.hpp"
"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"
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions include/zasm/base/instruction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <cstdint>
#include <zasm/base/meta.hpp>
#include <zasm/base/mode.hpp>
#include <zasm/base/operand.hpp>

namespace zasm
{
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#pragma once

#include "immediate.hpp"
#include "label.hpp"
#include "register.hpp"

#include <cstdint>
#include <limits>
#include <zasm/base/label.hpp>
#include <zasm/base/mode.hpp>
#include <zasm/base/register.hpp>
#include <zasm/core/bitsize.hpp>
#include <zasm/core/packed.hpp>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#pragma once

#include "immediate.hpp"
#include "label.hpp"
#include "memory.hpp"
#include "register.hpp"

#include <cstdint>
#include <variant>
#include <zasm/base/immediate.hpp>
#include <zasm/base/label.hpp>
#include <zasm/base/memory.hpp>
#include <zasm/base/register.hpp>
#include <zasm/core/enumflags.hpp>

namespace zasm
Expand Down Expand Up @@ -232,7 +231,7 @@ namespace zasm
{
return std::holds_alternative<Operand::None>(_data);
}

/// <summary>
/// Returns a reference with given type, throws if type mismatches.
/// </summary>
Expand Down Expand Up @@ -284,7 +283,7 @@ namespace zasm
}
return nullptr;
}

/// <summary>
/// Returns a pointer with the type specified if the type matches.
/// </summary>
Expand Down Expand Up @@ -358,7 +357,7 @@ namespace zasm
}

/// <summary>
/// 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.
/// </summary>
/// <param name="mode">Machine mode</param>
Expand Down
File renamed without changes.
5 changes: 4 additions & 1 deletion include/zasm/core/packed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace zasm
/// <summary>
/// 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.
/// </summary>
/// <typeparam name="TUnderlying">The underlying storage type</typeparam>
/// <typeparam name="TElement">Value type of each element packed</typeparam>
Expand All @@ -23,6 +24,8 @@ namespace zasm
static constexpr std::size_t kStorageBitSize = std::numeric_limits<TUnderlying>::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:
Expand All @@ -42,7 +45,7 @@ namespace zasm
{
return _data == other._data;
}

constexpr bool operator!=(const Packed& other) const noexcept
{
return _data == other._data;
Expand Down
3 changes: 1 addition & 2 deletions include/zasm/program/embeddedlabel.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#pragma once

#include "label.hpp"

#include <cstddef>
#include <cstdint>
#include <zasm/base/label.hpp>
#include <zasm/core/bitsize.hpp>

namespace zasm
Expand Down
5 changes: 2 additions & 3 deletions include/zasm/program/instruction.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#pragma once

#include "operand.hpp"

#include <array>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <zasm/base/instruction.hpp>
#include <zasm/base/meta.hpp>
#include <zasm/base/mode.hpp>
#include <zasm/base/operand.hpp>
#include <zasm/core/errors.hpp>
#include <zasm/core/expected.hpp>
#include <zasm/core/packed.hpp>
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion include/zasm/program/labeldata.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include <cstdint>
#include <zasm/base/label.hpp>
#include <zasm/core/enumflags.hpp>
#include <zasm/program/label.hpp>

namespace zasm
{
Expand Down
2 changes: 1 addition & 1 deletion include/zasm/program/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
#include "data.hpp"
#include "embeddedlabel.hpp"
#include "instruction.hpp"
#include "label.hpp"
#include "section.hpp"
#include "sentinel.hpp"

#include <climits>
#include <cstddef>
#include <variant>
#include <zasm/base/label.hpp>
#include <zasm/core/enumflags.hpp>

namespace zasm
Expand Down
2 changes: 1 addition & 1 deletion include/zasm/program/program.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

#include "data.hpp"
#include "embeddedlabel.hpp"
#include "label.hpp"
#include "node.hpp"
#include "section.hpp"

#include <cstddef>
#include <cstdint>
#include <memory>
#include <zasm/base/label.hpp>
#include <zasm/base/mode.hpp>
#include <zasm/core/errors.hpp>
#include <zasm/core/expected.hpp>
Expand Down
2 changes: 1 addition & 1 deletion include/zasm/x86/emitter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#include "mnemonic.hpp"
#include "register.hpp"

#include <zasm/base/operand.hpp>
#include <zasm/core/errors.hpp>
#include <zasm/program/instruction.hpp>
#include <zasm/program/operand.hpp>

namespace zasm::x86
{
Expand Down
2 changes: 1 addition & 1 deletion include/zasm/x86/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "register.hpp"

#include <zasm/program/memory.hpp>
#include <zasm/base/memory.hpp>

namespace zasm::x86
{
Expand Down
2 changes: 1 addition & 1 deletion include/zasm/x86/register.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <Zydis/Zydis.h>
#include <zasm/program/register.hpp>
#include <zasm/base/register.hpp>

namespace zasm::x86
{
Expand Down
2 changes: 1 addition & 1 deletion src/tests/tests/tests.packed.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <gtest/gtest.h>
#include <zasm/base/operand.hpp>
#include <zasm/core/packed.hpp>
#include <zasm/program/operand.hpp>
#include <zasm/x86/register.hpp>

namespace zasm::tests
Expand Down
2 changes: 1 addition & 1 deletion src/zasm/src/decoder/decoder.cpp
Original file line number Diff line number Diff line change
@@ -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 <Zydis/Decoder.h>
#include <cassert>
#include <zasm/base/operand.hpp>

namespace zasm
{
Expand Down
2 changes: 1 addition & 1 deletion src/zasm/src/encoder/encoder.context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include <cstdint>
#include <optional>
#include <vector>
#include <zasm/base/label.hpp>
#include <zasm/core/stringpool.hpp>
#include <zasm/program/label.hpp>
#include <zasm/program/section.hpp>

namespace zasm
Expand Down
4 changes: 2 additions & 2 deletions src/zasm/src/formatter/formatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
#include <cmath>
#include <cstddef>
#include <cstring>
#include <zasm/base/register.hpp>
#include <zasm/formatter/formatter.hpp>
#include <zasm/program/instruction.hpp>
#include <zasm/program/node.hpp>
#include <zasm/program/program.hpp>
#include <zasm/program/register.hpp>
#include <zasm/x86/meta.hpp>
#include <zasm/x86/mnemonic.hpp>
#include <zasm/x86/register.hpp>
Expand Down Expand Up @@ -225,7 +225,7 @@ namespace zasm::formatter
|| base.getPhysicalIndex() == x86::bp.getPhysicalIndex())
{
return x86::ss;
}
}
}
return x86::ds;
}
Expand Down
4 changes: 2 additions & 2 deletions src/zasm/src/program/instruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

#include <cassert>
#include <zasm/base/mode.hpp>
#include <zasm/base/operand.hpp>
#include <zasm/decoder/decoder.hpp>
#include <zasm/encoder/encoder.hpp>
#include <zasm/program/operand.hpp>

namespace zasm
{
Expand Down Expand Up @@ -77,4 +77,4 @@ namespace zasm
return getDetail(mode, *this);
}

} // namespace zasm::x86
} // namespace zasm
4 changes: 2 additions & 2 deletions src/zasm/src/program/program.state.hpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#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"

#include <Zydis/Zydis.h>
#include <cstddef>
#include <vector>
#include <zasm/base/label.hpp>
#include <zasm/base/mode.hpp>

namespace zasm
{
Expand Down
10 changes: 5 additions & 5 deletions src/zasm/src/program/register.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <Zydis/Zydis.h>
#include <cstddef>
#include <zasm/program/register.hpp>
#include <zasm/base/register.hpp>

namespace zasm
{
Expand Down Expand Up @@ -143,7 +143,7 @@ namespace zasm
{
return static_cast<ZydisRegisterClass>(getClass()) == ZydisRegisterClass::ZYDIS_REGCLASS_GPR64;
}

bool Reg::isGp() const noexcept
{
return isGp8() || isGp16() || isGp32() || isGp64();
Expand Down Expand Up @@ -173,7 +173,7 @@ namespace zasm
{
return static_cast<ZydisRegisterClass>(getClass()) == ZydisRegisterClass::ZYDIS_REGCLASS_BOUND;
}

bool Reg::isControl() const noexcept
{
return static_cast<ZydisRegisterClass>(getClass()) == ZydisRegisterClass::ZYDIS_REGCLASS_CONTROL;
Expand All @@ -188,12 +188,12 @@ namespace zasm
{
return static_cast<ZydisRegisterClass>(getClass()) == ZydisRegisterClass::ZYDIS_REGCLASS_MASK;
}

bool Reg::isMmx() const noexcept
{
return static_cast<ZydisRegisterClass>(getClass()) == ZydisRegisterClass::ZYDIS_REGCLASS_MMX;
}

bool Reg::isTmm() const noexcept
{
return static_cast<ZydisRegisterClass>(getClass()) == ZydisRegisterClass::ZYDIS_REGCLASS_TMM;
Expand Down

0 comments on commit 3c31923

Please sign in to comment.