Most of the time, the type pointed to by a PCState pointer or reference will be the same as all the others, if not nullptr. This change adds a set of "set" functions which assume that the underlying type of each pointer or reference are the same, and handles casting, copying things over, creating a new copy, etc, for you. It uses a new "update" virtual method on PCState subclasses which casts the source to the same type as the destination and copies values over. Note that the "set" function doesn't actually verify that the two types are the same, just like the overloaded ==, != and << operators. In the future, those checks can be added for debugging purposes, probably guarded by a configuration variable which can be toggled on or off to get better performance or more thorough error checking. The main advantage of these wrappers are that they allows consistent semantics whether your moving a value from a pointer, or from a yet unconverted PCState subclass, or vice versa, which will be particularly helpful while transitioning between using raw PCState instances and using primarily pointers and references. This change also adds wrappers which handle std::unique_ptr, which makes it easier to use them as arguments to these functions. Otherwise, if the std::unique_ptr is a temporary value, using the return value of .get() will let the std::unique_ptr go out of scope, making it delete the data pointed to by the returned pointed. By keeping the std::unique_ptr around on the stack, that prevents it from going out of scope. Change-Id: I2c737b08e0590a2c46e212a7b9efa543bdb81ad3 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/52041 Tested-by: kokoro <noreply+kokoro@google.com> Maintainer: Gabe Black <gabe.black@gmail.com> Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br>
83 lines
2.6 KiB
C++
83 lines
2.6 KiB
C++
/*
|
|
* Copyright (c) 2009 The University of Edinburgh
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions are
|
|
* met: redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer;
|
|
* redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution;
|
|
* neither the name of the copyright holders nor the names of its
|
|
* contributors may be used to endorse or promote products derived from
|
|
* this software without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
#ifndef __ARCH_POWER_PCSTATE_HH__
|
|
#define __ARCH_POWER_PCSTATE_HH__
|
|
|
|
#include "arch/generic/pcstate.hh"
|
|
#include "arch/power/types.hh"
|
|
#include "enums/ByteOrder.hh"
|
|
|
|
namespace gem5
|
|
{
|
|
|
|
namespace PowerISA
|
|
{
|
|
|
|
class PCState : public GenericISA::SimplePCState<4>
|
|
{
|
|
private:
|
|
ByteOrder guestByteOrder = ByteOrder::big;
|
|
|
|
public:
|
|
using GenericISA::SimplePCState<4>::SimplePCState;
|
|
|
|
PCState(const PCState &other) :
|
|
GenericISA::SimplePCState<4>(other),
|
|
guestByteOrder(other.guestByteOrder)
|
|
{}
|
|
PCState &operator=(const PCState &other) = default;
|
|
|
|
PCStateBase *clone() const override { return new PCState(*this); }
|
|
|
|
void
|
|
update(const PCStateBase &other) override
|
|
{
|
|
GenericISA::SimplePCState<4>::update(other);
|
|
auto &pcstate = other.as<PCState>();
|
|
guestByteOrder = pcstate.guestByteOrder;
|
|
}
|
|
|
|
ByteOrder
|
|
byteOrder() const
|
|
{
|
|
return guestByteOrder;
|
|
}
|
|
|
|
void
|
|
byteOrder(ByteOrder order)
|
|
{
|
|
guestByteOrder = order;
|
|
}
|
|
};
|
|
|
|
} // namespace PowerISA
|
|
} // namespace gem5
|
|
|
|
#endif // __ARCH_POWER_PCSTATE_HH__
|