4 * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5 * See included license file for license details.
7 #if !defined(_DataTarget_h_)
11 #include "DataSource.h"
16 // Forward declaration
20 * \brief Abstract base class for the target address or range of data.
22 * Targets at the most basic level have a single address, and potentially
23 * an address range. Unbounded targets have a beginning address but no
24 * specific end address, while bounded targets do have an end address.
26 * Users of a data target can access the begin and end addresses directly.
27 * However, the most powerful way to use a target is with the
28 * getRangeForSegment() method. This method returns the target address range
29 * for a segment of a data source. The value of the resulting range can be
30 * completely dependent upon the segment's properties, those of its data
31 * source, and the type of data target.
33 * \see elftosb::DataSource
38 //! \brief Simple structure that describes an addressed region of memory.
39 //! \todo Decide if the end address is inclusive or not.
47 //! \brief Default constructor.
48 DataTarget() : m_source(0) {}
50 //! \brief Destructor.
51 virtual ~DataTarget() {}
53 //! \brief Whether the target is just a single address or has an end to it.
54 virtual bool isBounded() { return false; }
56 virtual uint32_t getBeginAddress() { return 0; }
57 virtual uint32_t getEndAddress() { return 0; }
59 //! \brief Return the address range for a segment of a data source.
60 virtual DataTarget::AddressRange getRangeForSegment(DataSource & source, DataSource::Segment & segment)=0;
62 inline void setSource(DataSource * source) { m_source = source; }
63 inline DataSource * getSource() const { return m_source; }
66 DataSource * m_source; //!< Corresponding data source for this target.
70 * \brief Target with a constant values for the addresses.
72 * This target type supports can be both bounded and unbounded. It always has
73 * at least one address, the beginning address. The end address is optional,
74 * and if not provided makes the target unbounded.
76 class ConstantDataTarget : public DataTarget
79 //! \brief Constructor taking only a begin address.
80 ConstantDataTarget(uint32_t start) : DataTarget(), m_begin(start), m_end(0), m_hasEnd(false) {}
82 //! \brief Constructor taking both begin and end addresses.
83 ConstantDataTarget(uint32_t start, uint32_t end) : DataTarget(), m_begin(start), m_end(end), m_hasEnd(true) {}
85 //! \brief The target is bounded if an end address was specified.
86 virtual bool isBounded() { return m_hasEnd; }
88 virtual uint32_t getBeginAddress() { return m_begin; }
89 virtual uint32_t getEndAddress() { return m_end; }
91 //! \brief Return the address range for a segment of a data source.
92 virtual DataTarget::AddressRange getRangeForSegment(DataSource & source, DataSource::Segment & segment);
95 uint32_t m_begin; //!< Start address.
96 uint32_t m_end; //!< End address.
97 bool m_hasEnd; //!< Was an end address specified?
101 * \brief Target address that is the "natural" location of whatever the source data is.
103 * The data source used with the target must have a natural location. If
104 * getRangeForSegment() is called with a segment that does not have a natural
105 * location, a semantic_error will be thrown.
107 class NaturalDataTarget : public DataTarget
110 //! \brief Default constructor.
111 NaturalDataTarget() : DataTarget() {}
113 //! \brief Natural data targets are bounded by their source's segment lengths.
114 virtual bool isBounded() { return true; }
116 //! \brief Return the address range for a segment of a data source.
117 virtual DataTarget::AddressRange getRangeForSegment(DataSource & source, DataSource::Segment & segment);
120 }; // namespace elftosb
122 #endif // _DataTarget_h_