15460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//===- ELFSegmentFactory.h ------------------------------------------------===//
25460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//
35460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//                     The MCLinker Project
45460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//
55460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// This file is distributed under the University of Illinois Open Source
65460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// License. See LICENSE.TXT for details.
75460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//
85460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//===----------------------------------------------------------------------===//
937b74a387bb3993387029859c2d9d051c41c724eStephen Hines#ifndef MCLD_LD_ELFSEGMENTFACTORY_H_
1037b74a387bb3993387029859c2d9d051c41c724eStephen Hines#define MCLD_LD_ELFSEGMENTFACTORY_H_
1187f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
1287f34658dec9097d987d254a990ea7f311bfc95fStephen Hines#include <llvm/Support/DataTypes.h>
1387f34658dec9097d987d254a990ea7f311bfc95fStephen Hines#include <llvm/Support/ELF.h>
1437b74a387bb3993387029859c2d9d051c41c724eStephen Hines
1587f34658dec9097d987d254a990ea7f311bfc95fStephen Hines#include <vector>
165460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
1737b74a387bb3993387029859c2d9d051c41c724eStephen Hinesnamespace mcld {
185460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
1987f34658dec9097d987d254a990ea7f311bfc95fStephen Hinesclass ELFSegment;
2087f34658dec9097d987d254a990ea7f311bfc95fStephen Hinesclass LDSection;
2187f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
225460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao/** \class ELFSegmentFactory
235460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *  \brief provide the interface to create and delete an ELFSegment
245460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao */
2537b74a387bb3993387029859c2d9d051c41c724eStephen Hinesclass ELFSegmentFactory {
2637b74a387bb3993387029859c2d9d051c41c724eStephen Hines public:
2787f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  typedef std::vector<ELFSegment*> Segments;
2887f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  typedef Segments::const_iterator const_iterator;
2987f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  typedef Segments::iterator iterator;
3087f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
3187f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  const_iterator begin() const { return m_Segments.begin(); }
3237b74a387bb3993387029859c2d9d051c41c724eStephen Hines  iterator begin() { return m_Segments.begin(); }
3337b74a387bb3993387029859c2d9d051c41c724eStephen Hines  const_iterator end() const { return m_Segments.end(); }
3437b74a387bb3993387029859c2d9d051c41c724eStephen Hines  iterator end() { return m_Segments.end(); }
3587f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
3687f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  const ELFSegment* front() const { return m_Segments.front(); }
3737b74a387bb3993387029859c2d9d051c41c724eStephen Hines  ELFSegment* front() { return m_Segments.front(); }
3837b74a387bb3993387029859c2d9d051c41c724eStephen Hines  const ELFSegment* back() const { return m_Segments.back(); }
3937b74a387bb3993387029859c2d9d051c41c724eStephen Hines  ELFSegment* back() { return m_Segments.back(); }
4087f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
4187f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  size_t size() const { return m_Segments.size(); }
4287f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
4387f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  bool empty() const { return m_Segments.empty(); }
4487f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
4587f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  iterator find(uint32_t pType, uint32_t pFlagSet, uint32_t pFlagClear);
4687f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
4737b74a387bb3993387029859c2d9d051c41c724eStephen Hines  const_iterator find(uint32_t pType,
4837b74a387bb3993387029859c2d9d051c41c724eStephen Hines                      uint32_t pFlagSet,
4937b74a387bb3993387029859c2d9d051c41c724eStephen Hines                      uint32_t pFlagClear) const;
5087f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
5137b74a387bb3993387029859c2d9d051c41c724eStephen Hines  iterator find(uint32_t pType, const LDSection* pSection);
5287f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
5387f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  const_iterator find(uint32_t pType, const LDSection* pSection) const;
545460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
555460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// produce - produce an empty ELF segment information.
565460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// this function will create an ELF segment
575460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// @param pType - p_type in ELF program header
58affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  ELFSegment* produce(uint32_t pType, uint32_t pFlag = llvm::ELF::PF_R);
595460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
60cfcb22478ca64c308df58f9abe6fa2dedb213c16Stephen Hines  ELFSegment* insert(iterator pPosition,
61cfcb22478ca64c308df58f9abe6fa2dedb213c16Stephen Hines                     uint32_t pType,
62cfcb22478ca64c308df58f9abe6fa2dedb213c16Stephen Hines                     uint32_t pFlag = llvm::ELF::PF_R);
63cfcb22478ca64c308df58f9abe6fa2dedb213c16Stephen Hines
6487f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  void erase(iterator pSegment);
65affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
6637b74a387bb3993387029859c2d9d051c41c724eStephen Hines private:
6787f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  Segments m_Segments;
685460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao};
695460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
7037b74a387bb3993387029859c2d9d051c41c724eStephen Hines}  // namespace mcld
71affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
7237b74a387bb3993387029859c2d9d051c41c724eStephen Hines#endif  // MCLD_LD_ELFSEGMENTFACTORY_H_
73