libmicroemu 0.2.0
ARM Microcontroller Emulator Library
Loading...
Searching...
No Matches
relative_adr_builder.h
1#pragma once
2
3#include "libmicroemu/internal/logic/alu.h"
4
5#include <cstdint>
6
7namespace libmicroemu::internal {
8
9class RelativeAdrBuilder {
10public:
22 template <typename TMnemonicBuilder, typename TRegOps, typename TArg0>
23 static void Build(TMnemonicBuilder &builder, const bool &is_add, const bool &is_index,
24 const bool &is_wback, const TArg0 &rn, const u32 &imm) {
25 using Reg = TRegOps;
26 assert(((is_index != false) || (is_wback != false))); // no viable option
27
28 if ((is_index == true) && (is_wback == false)) { // Offset: index=TRUE, wback=FALSE
29 builder.AddChar('[').AddString(Reg::GetRegisterName(rn.Get())).AddString(", ");
30 AddImm(builder, is_add, imm);
31 builder.AddChar(']');
32 } else if ((is_index == false) && (is_wback == true)) { // Post indexed: index=FALSE, wback=TRUE
33 builder.AddChar('[').AddString(Reg::GetRegisterName(rn.Get())).AddString("], ");
34 AddImm(builder, is_add, imm);
35 } else { // Pre indexed: index=TRUE, wback=TRUE
36 builder.AddChar('[').AddString(Reg::GetRegisterName(rn.Get())).AddString(", ");
37 AddImm(builder, is_add, imm);
38 builder.AddString("]!");
39 }
40 }
41
42private:
43 template <typename TMnemonicBuilder>
44 static void AddImm(TMnemonicBuilder &builder, const bool &is_add, const u32 &imm) {
45 builder.AddChar('#');
46 if (is_add == false) {
47 builder.AddChar('-');
48 }
49 builder.AddUInt(imm);
50 }
51
55 RelativeAdrBuilder() = delete;
56
60 ~RelativeAdrBuilder() = delete;
61
66 RelativeAdrBuilder &operator=(const RelativeAdrBuilder &r_src) = delete;
67
72 RelativeAdrBuilder(RelativeAdrBuilder &&r_src) = delete;
73
78 RelativeAdrBuilder &operator=(RelativeAdrBuilder &&r_src) = delete;
79};
80
81} // namespace libmicroemu::internal
static void Build(TMnemonicBuilder &builder, const bool &is_add, const bool &is_index, const bool &is_wback, const TArg0 &rn, const u32 &imm)
Uses the given str builder to build a string representing the different addressing modes of instructi...
Definition relative_adr_builder.h:23
The libmicroemu::internal namespace contains all classes and functions of libmicroemu which are priva...
Definition bkpt_flags.h:6