5#include <llvm/MC/MCAsmInfo.h>
6#include <llvm/MC/MCInstPrinter.h>
7#include <llvm/MC/MCInstrInfo.h>
8#include <llvm/MC/MCRegisterInfo.h>
9#include <llvm/MC/MCSubtargetInfo.h>
10#include <llvm/MC/TargetRegistry.h>
54 Nyxstone(llvm::Triple&& triple,
const llvm::Target& target, llvm::MCTargetOptions&& target_options,
55 std::unique_ptr<llvm::MCRegisterInfo>&& register_info, std::unique_ptr<llvm::MCAsmInfo>&& assembler_info,
56 std::unique_ptr<llvm::MCInstrInfo>&& instruction_info, std::unique_ptr<llvm::MCSubtargetInfo>&& subtarget_info,
57 std::unique_ptr<llvm::MCInstPrinter>&& instruction_printer) noexcept
58 : triple(std::move(triple))
60 , target_options(std::move(target_options))
61 , register_info(std::move(register_info))
62 , assembler_info(std::move(assembler_info))
63 , instruction_info(std::move(instruction_info))
64 , subtarget_info(std::move(subtarget_info))
65 , instruction_printer(std::move(instruction_printer))
79 tl::expected<std::vector<u8>, std::string>
assemble(
80 const std::string& assembly, uint64_t address,
const std::vector<LabelDefinition>& labels)
const;
93 const std::string& assembly, uint64_t address,
const std::vector<LabelDefinition>& labels)
const;
102 tl::expected<std::string, std::string>
disassemble(
103 const std::vector<uint8_t>& bytes, uint64_t address,
size_t count)
const;
113 const std::vector<uint8_t>& bytes, uint64_t address,
size_t count)
const;
118 tl::expected<void, std::string> assemble_impl(
const std::string& assembly, uint64_t address,
119 const std::vector<LabelDefinition>& labels, std::vector<uint8_t>& bytes,
120 std::vector<Instruction>* instructions)
const;
123 tl::expected<void, std::string> disassemble_impl(
const std::vector<uint8_t>& bytes, uint64_t address,
size_t count,
124 std::string* disassembly, std::vector<Instruction>* instructions)
const;
130 const llvm::Target& target;
132 llvm::MCTargetOptions target_options;
134 std::unique_ptr<llvm::MCRegisterInfo> register_info;
135 std::unique_ptr<llvm::MCAsmInfo> assembler_info;
136 std::unique_ptr<llvm::MCInstrInfo> instruction_info;
137 std::unique_ptr<llvm::MCSubtargetInfo> subtarget_info;
138 std::unique_ptr<llvm::MCInstPrinter> instruction_printer;
170 : m_triple(std::move(triple)) {};
195 tl::expected<std::unique_ptr<Nyxstone>, std::string>
build();
199 std::string m_triple;
203 std::string m_features;
209bool is_ArmT16_or_ArmT32(
const llvm::Triple& triple);
Builder for Nyxstone instances.
Definition nyxstone.h:144
tl::expected< std::unique_ptr< Nyxstone >, std::string > build()
Builds a nyxstone instance from the builder.
Definition nyxstone.cpp:41
NyxstoneBuilder(std::string &&triple)
Creates a NyxstoneBuilder instance.
Definition nyxstone.h:169
NyxstoneBuilder & with_immediate_style(IntegerBase style) noexcept
Specify the style in which immediates should be represented.
Definition nyxstone.cpp:35
NyxstoneBuilder & with_cpu(std::string &&cpu) noexcept
Specifies the cpu for which to assemble/disassemble in nyxstone.
Definition nyxstone.cpp:23
IntegerBase
Configuration options for the immediate representation in disassembly.
Definition nyxstone.h:148
@ HexSuffix
Immediates are represented in hex format, suffixed with h, for example: 0ffh.
@ HexPrefix
Immediates are represented in hex format, prepended with 0x, for example: 0xff.
@ Dec
Immediates are represented in decimal format.
NyxstoneBuilder & with_features(std::string &&features) noexcept
Specify cpu features to en-/disable in nyxstone.
Definition nyxstone.cpp:29
Nyxstone class for assembling and disassembling for a given architecture.
Definition nyxstone.h:18
tl::expected< std::vector< u8 >, std::string > assemble(const std::string &assembly, uint64_t address, const std::vector< LabelDefinition > &labels) const
Translates assembly instructions at a given start address to bytes.
Definition nyxstone.cpp:124
Nyxstone(llvm::Triple &&triple, const llvm::Target &target, llvm::MCTargetOptions &&target_options, std::unique_ptr< llvm::MCRegisterInfo > &®ister_info, std::unique_ptr< llvm::MCAsmInfo > &&assembler_info, std::unique_ptr< llvm::MCInstrInfo > &&instruction_info, std::unique_ptr< llvm::MCSubtargetInfo > &&subtarget_info, std::unique_ptr< llvm::MCInstPrinter > &&instruction_printer) noexcept
Nyxstone constructor called by NyxstoneBuilder::build.
Definition nyxstone.h:54
tl::expected< std::string, std::string > disassemble(const std::vector< uint8_t > &bytes, uint64_t address, size_t count) const
Translates bytes to disassembly text at given start address.
Definition nyxstone.cpp:154
tl::expected< std::vector< Instruction >, std::string > assemble_to_instructions(const std::string &assembly, uint64_t address, const std::vector< LabelDefinition > &labels) const
Translates assembly instructions at given start address to instruction details containing bytes.
Definition nyxstone.cpp:131
tl::expected< std::vector< Instruction >, std::string > disassemble_to_instructions(const std::vector< uint8_t > &bytes, uint64_t address, size_t count) const
Translates bytes to instruction details containing disassembly text at given start address.
Definition nyxstone.cpp:163
Complete instruction information.
Definition nyxstone.h:29
std::string assembly
The assembly string of the instruction.
Definition nyxstone.h:33
uint64_t address
The absolute address of the instruction.
Definition nyxstone.h:31
std::vector< uint8_t > bytes
The byte code of the instruction.
Definition nyxstone.h:35
Defines the location of a label by absolute address.
Definition nyxstone.h:21
uint64_t address
The absolute address of the label.
Definition nyxstone.h:25
std::string name
The label name.
Definition nyxstone.h:23