~satchmo/libvmm

b94dee0badb2356954c5f71c66ddb7660f3be1d5 — Jason Phan 4 months ago d9f9f5c
memory: Add & and | operators for Address
3 files changed, 15 insertions(+), 5 deletions(-)

M vmm/memory/detail/address.hpp
M vmm/memory/detail/guest.cpp
M vmm/memory/detail/guest.hpp
M vmm/memory/detail/address.hpp => vmm/memory/detail/address.hpp +5 -2
@@ 26,8 26,11 @@ class Address
        // Returns the raw value of the address.
        virtual auto data() const noexcept -> Size = 0;

        // Returns a bitwise AND of the address and a mask.
        virtual auto mask(const Size) const noexcept -> Size = 0;
        // Returns the bitwise AND of the address and a mask.
        virtual auto operator&(const Size) const noexcept -> Size = 0;

        // Returns the bitwise OR of the address and a mask.
        virtual auto operator|(const Size) const noexcept -> Size = 0;

        // Adds `other` to the address' value.
        virtual auto operator+(const Size) const noexcept -> Concrete = 0;

M vmm/memory/detail/guest.cpp => vmm/memory/detail/guest.cpp +6 -1
@@ 10,11 10,16 @@ auto GuestAddress::data() const noexcept -> size_type
    return m_addr;
}

auto GuestAddress::mask(const size_type mask) const noexcept -> size_type
auto GuestAddress::operator&(const size_type mask) const noexcept -> size_type
{
    return m_addr & mask;
}

auto GuestAddress::operator|(const size_type mask) const noexcept -> size_type
{
    return m_addr | mask;
}

auto GuestAddress::operator+(const size_type val) const noexcept -> value_type
{
    return GuestAddress{m_addr + val};

M vmm/memory/detail/guest.hpp => vmm/memory/detail/guest.hpp +4 -2
@@ 34,11 34,13 @@ class GuestAddress : public Address<GuestAddress, uint64_t>
    public:
        explicit GuestAddress(size_type addr=0) noexcept : m_addr{addr} {}

        // Returns the raw value of the address.
        auto data() const noexcept -> size_type override;

        // Returns the bitwise AND of the address and a mask.
        auto mask(const size_type mask) const noexcept -> size_type override;
        auto operator&(const size_type mask) const noexcept -> size_type override;

        // Returns the bitwise OR of the address and a mask.
        auto operator|(const size_type mask) const noexcept -> size_type override;

        // Returns the address plus some value (sum is wrapped).
        auto operator+(const size_type val) const noexcept -> value_type override;