Skip to content

Commit

Permalink
Merge pull request #44 from zyantific/update-api
Browse files Browse the repository at this point in the history
#36: Better abstraction
  • Loading branch information
ZehMatt authored Jun 25, 2022
2 parents c807239 + 24379df commit 5663f1b
Show file tree
Hide file tree
Showing 48 changed files with 29,450 additions and 35,244 deletions.
14 changes: 11 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,23 @@ set(CMKR_TARGET zasm)
set(zasm_SOURCES "")

list(APPEND zasm_SOURCES
"src/zasm/src/assembler/assembler.cpp"
"src/zasm/src/assembler/assembler.instructions.cpp"
"src/zasm/src/decoder/decoder.cpp"
"src/zasm/src/encoder/encoder.cpp"
"src/zasm/src/encoder/generator.cpp"
"src/zasm/src/program/data.cpp"
"src/zasm/src/program/formatter.cpp"
"src/zasm/src/program/instruction.cpp"
"src/zasm/src/program/program.cpp"
"src/zasm/src/program/register.cpp"
"src/zasm/src/serialization/serializer.cpp"
"src/zasm/src/x86/x86.assembler.cpp"
"src/zasm/src/x86/x86.register.cpp"
"src/zasm/src/zasm.cpp"
"src/zasm/src/encoder/encoder.context.hpp"
"src/zasm/src/encoder/generator.hpp"
"src/zasm/src/program/program.node.hpp"
"src/zasm/src/program/program.state.hpp"
"include/zasm/assembler/assembler.hpp"
"include/zasm/base/mode.hpp"
"include/zasm/core/bitsize.hpp"
"include/zasm/core/enumflags.hpp"
"include/zasm/core/errors.hpp"
Expand All @@ -111,6 +113,12 @@ list(APPEND zasm_SOURCES
"include/zasm/program/register.hpp"
"include/zasm/program/section.hpp"
"include/zasm/serialization/serializer.hpp"
"include/zasm/x86/assembler.hpp"
"include/zasm/x86/emitter.hpp"
"include/zasm/x86/instruction.hpp"
"include/zasm/x86/memory.hpp"
"include/zasm/x86/register.hpp"
"include/zasm/x86/x86.hpp"
"include/zasm/zasm.hpp"
)

Expand Down
7,057 changes: 0 additions & 7,057 deletions include/zasm/assembler/assembler.hpp

This file was deleted.

13 changes: 13 additions & 0 deletions include/zasm/base/mode.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <cstdint>

namespace zasm
{
enum class MachineMode : uint8_t
{
I386,
AMD64,
};

} // namespace zasm
3 changes: 2 additions & 1 deletion include/zasm/decoder/decoder.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <Zydis/Zydis.h>
#include <zasm/base/mode.hpp>
#include <zasm/core/errors.hpp>
#include <zasm/core/expected.hpp>
#include <zasm/program/instruction.hpp>
Expand All @@ -15,7 +16,7 @@ namespace zasm
public:
using Result = zasm::Expected<Instruction, Error>;

Decoder(ZydisMachineMode mode) noexcept;
Decoder(MachineMode mode) noexcept;

Result decode(const void* data, const size_t len, uint64_t va) noexcept;
};
Expand Down
5 changes: 3 additions & 2 deletions include/zasm/encoder/encoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <array>
#include <cstdint>
#include <zasm/base/mode.hpp>
#include <zasm/core/errors.hpp>
#include <zasm/program/instruction.hpp>

Expand Down Expand Up @@ -42,12 +43,12 @@ namespace zasm
// full serialization. This allows to query instruction meta data such as operand access
// and CPU flags, this can be also used to estimate the size.
Error encodeEstimated(
EncoderResult& buf, ZydisMachineMode mode, Instruction::Attribs attribs, ZydisMnemonic id, size_t numOps,
EncoderResult& buf, MachineMode mode, Instruction::Attribs attribs, Instruction::Mnemonic id, size_t numOps,
const EncoderOperands& operands) noexcept;

// Encodes with full context. This function still allows labels to be unbound and will not error
// instead a temporary value be usually encoded. It is expected for the serialization to handle this
// with multiple passes.
Error encodeFull(EncoderResult& buf, EncoderContext& ctx, ZydisMachineMode mode, const Instruction& instr) noexcept;
Error encodeFull(EncoderResult& buf, EncoderContext& ctx, MachineMode mode, const Instruction& instr) noexcept;

} // namespace zasm
9 changes: 5 additions & 4 deletions include/zasm/program/immediate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <cstdint>

namespace zasm::operands
namespace zasm
{
class Imm
{
Expand Down Expand Up @@ -40,7 +40,8 @@ namespace zasm::operands
}
};

namespace detail {
namespace detail
{
template<typename T> class ImmT : public Imm
{
public:
Expand All @@ -50,7 +51,7 @@ namespace zasm::operands
{
}
};
}
} // namespace detail

/// <summary>
/// Helpers to avoid casts.
Expand All @@ -60,4 +61,4 @@ namespace zasm::operands
using Imm16 = detail::ImmT<int16_t>;
using Imm8 = detail::ImmT<int8_t>;

} // namespace zasm::operands
} // namespace zasm
Loading

0 comments on commit 5663f1b

Please sign in to comment.