~satchmo/libvmm

7cbc9db468f47905b8a2dc1da67e17778588a3d6 — Jason Phan 4 months ago 88368e8
memory: Remove unecessary methods from Address
3 files changed, 1 insertions(+), 85 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 +0 -17
@@ 40,25 40,8 @@ class Address
        virtual auto operator-(const Size) const noexcept -> Concrete = 0;
        virtual auto operator-(const Concrete&) const noexcept -> Concrete = 0;

        // Adds `other` to the address' value.
        //
        // Returns a pair consisting of the sum and a boolean indicating
        // whether an overflow would have occurred. If an overflow would have
        // occurred, the wrapped address is returned.
        virtual auto add(const Size) const -> Concrete = 0;
        virtual auto add(const Concrete&) const -> Concrete = 0;

        // Subtracts `other` from the address' value.
        //
        // Returns a pair containing the difference and a boolean indicating
        // whether an arithmetic underflow would have occurred. If an overflow
        // would have occurred, then the wrapped address is returned.
        virtual auto subtract(const Size) const -> Concrete = 0;
        virtual auto subtract(const Concrete&) const -> Concrete = 0;

        // Aligns the address to a power of 2.
        virtual auto align_up(const Size) noexcept -> void = 0;
        virtual auto checked_align_up(const Size) -> void = 0;
};

//template<typename Derived>

M vmm/memory/detail/guest.cpp => vmm/memory/detail/guest.cpp +1 -39
@@ 40,48 40,10 @@ auto GuestAddress::operator-(const_reference addr) const noexcept -> value_type
    return *this - addr.data();
}

auto GuestAddress::add(const size_type val) const -> value_type
{
    if (m_addr > std::numeric_limits<size_type>::max() - val) {
        VMM_THROW(std::overflow_error(std::to_string(m_addr) + " + " + std::to_string(val) + " results in overflow."));
    }

    return *this + val;
}

auto GuestAddress::add(const_reference addr) const -> value_type
{
    return add(addr.data());
}

auto GuestAddress::subtract(const size_type val) const -> value_type
{
    if (m_addr < std::numeric_limits<size_type>::min() + val) {
        VMM_THROW(std::underflow_error(std::to_string(m_addr) + " - " + std::to_string(val) + " results in underflow."));
    }

    return *this - val;
}

auto GuestAddress::subtract(const_reference addr) const -> value_type
{
    return subtract(addr.data());
}

auto GuestAddress::align_up(const size_type alignment) noexcept -> void
{
    const auto mask = alignment - 1;
    m_addr = (*this + mask).data() & !mask;
}

auto GuestAddress::checked_align_up(const size_type alignment) -> void
{
    const auto mask = alignment - 1;

    assert(alignment);
    assert(!(alignment & mask));

    m_addr = add(mask).data() & !mask;
    m_addr = (*this + mask) & !mask;
}

}  // vmm::memory::detail

M vmm/memory/detail/guest.hpp => vmm/memory/detail/guest.hpp +0 -29
@@ 55,37 55,8 @@ class GuestAddress : public Address<GuestAddress, uint64_t>
        // (difference is wrapped).
        auto operator-(const_reference addr) const noexcept -> value_type override;

        // Returns the address plus some value.
        //
        // If an "overflow" occurs, an exception is thrown.
        auto add(const size_type val) const -> value_type override;

        // Returns the sum of the address and another address.
        //
        // If an "overflow" occurs, an exception is thrown.
        auto add(const_reference addr) const -> value_type override;

        // Returns the address minus some value.
        //
        // If an "underflow" occurs, an exception is thrown.
        auto subtract(const size_type val) const -> value_type override;

        // Returns the difference between the address and another address.
        //
        // If an "underflow" occurs, an exception is thrown.
        auto subtract(const_reference addr) const -> value_type override;

        // Returns the offset between `m_addr` to `base`.
        //auto offset_from(const_reference base) const noexcept -> value_type;
        //auto checked_offset_from(const_reference base) const -> value_type;

        // Aligns the address to a power of 2.
        auto align_up(const size_type alignment) noexcept -> void override;

        // Aligns the address to a power of 2.
        //
        // If an "overflow" occurs, an exception is thrown.
        auto checked_align_up(const size_type alignment) -> void override;
};

}  // vmm::memory::detail