OutputSectDesc.h revision 87f34658dec9097d987d254a990ea7f311bfc95f
1//===- OutputSectDesc.h ---------------------------------------------------===// 2// 3// The MCLinker Project 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9#ifndef MCLD_SCRIPT_OUTPUTSECTDESC_H 10#define MCLD_SCRIPT_OUTPUTSECTDESC_H 11#ifdef ENABLE_UNITTEST 12#include <gtest.h> 13#endif 14 15#include <mcld/Script/ScriptCommand.h> 16#include <vector> 17#include <string> 18#include <cassert> 19 20namespace mcld 21{ 22 23class RpnExpr; 24class StringList; 25 26/** \class OutputSectDesc 27 * \brief This class defines the interfaces to output section description. 28 */ 29 30class OutputSectDesc : public ScriptCommand 31{ 32public: 33 enum Type { 34 LOAD, // ALLOC 35 NOLOAD, 36 DSECT, 37 COPY, 38 INFO, 39 OVERLAY 40 }; 41 42 enum Constraint { 43 NO_CONSTRAINT, 44 ONLY_IF_RO, 45 ONLY_IF_RW 46 }; 47 48 struct Prolog { 49 bool hasVMA() const { return m_pVMA != NULL; } 50 const RpnExpr& vma() const { 51 assert(hasVMA()); 52 return *m_pVMA; 53 } 54 RpnExpr& vma() { 55 assert(hasVMA()); 56 return *m_pVMA; 57 } 58 59 void setType(Type pType) { 60 m_Type = pType; 61 } 62 63 Type type() const { return m_Type; } 64 65 bool hasLMA() const { return m_pLMA != NULL; } 66 const RpnExpr& lma() const { 67 assert(hasLMA()); 68 return *m_pLMA; 69 } 70 RpnExpr& lma() { 71 assert(hasLMA()); 72 return *m_pLMA; 73 } 74 75 bool hasAlign() const { return m_pAlign != NULL; } 76 const RpnExpr& align() const { 77 assert(hasAlign()); 78 return *m_pAlign; 79 } 80 81 bool hasSubAlign() const { return m_pSubAlign != NULL; } 82 const RpnExpr& subAlign() const { 83 assert(hasSubAlign()); 84 return *m_pSubAlign; 85 } 86 87 Constraint constraint() const { return m_Constraint; } 88 89 bool operator==(const Prolog& pRHS) const { 90 /* FIXME: currently I don't check the real content */ 91 if (this == &pRHS) 92 return true; 93 if (m_pVMA != pRHS.m_pVMA) 94 return false; 95 if (m_Type != pRHS.m_Type) 96 return false; 97 if (m_pLMA!= pRHS.m_pLMA) 98 return false; 99 if (m_pAlign != pRHS.m_pAlign) 100 return false; 101 if (m_pSubAlign != pRHS.m_pSubAlign) 102 return false; 103 if (m_Constraint != pRHS.m_Constraint) 104 return false; 105 return true; 106 } 107 108 RpnExpr* m_pVMA; 109 Type m_Type; 110 RpnExpr* m_pLMA; 111 RpnExpr* m_pAlign; 112 RpnExpr* m_pSubAlign; 113 Constraint m_Constraint; 114 }; 115 116 struct Epilog { 117 bool hasRegion() const { return m_pRegion != NULL; } 118 const std::string& region() const { 119 assert(hasRegion()); 120 return *m_pRegion; 121 } 122 123 bool hasLMARegion() const { return m_pLMARegion != NULL; } 124 const std::string& lmaRegion() const { 125 assert(hasLMARegion()); 126 return *m_pLMARegion; 127 } 128 129 bool hasPhdrs() const { return m_pPhdrs != NULL; } 130 const StringList& phdrs() const { 131 assert(hasPhdrs()); 132 return *m_pPhdrs; 133 } 134 135 bool hasFillExp() const { return m_pFillExp != NULL; } 136 const RpnExpr& fillExp() const { 137 assert(hasFillExp()); 138 return *m_pFillExp; 139 } 140 141 bool operator==(const Epilog& pRHS) const { 142 /* FIXME: currently I don't check the real content */ 143 if (this == &pRHS) 144 return true; 145 if (m_pRegion != pRHS.m_pRegion) 146 return false; 147 if (m_pLMARegion != pRHS.m_pLMARegion) 148 return false; 149 if (m_pPhdrs != pRHS.m_pPhdrs) 150 return false; 151 if (m_pFillExp != pRHS.m_pFillExp) 152 return false; 153 return true; 154 } 155 156 const std::string* m_pRegion; 157 const std::string* m_pLMARegion; 158 StringList* m_pPhdrs; 159 RpnExpr* m_pFillExp; 160 }; 161 162 typedef std::vector<ScriptCommand*> OutputSectCmds; 163 typedef OutputSectCmds::const_iterator const_iterator; 164 typedef OutputSectCmds::iterator iterator; 165 typedef OutputSectCmds::const_reference const_reference; 166 typedef OutputSectCmds::reference reference; 167 168public: 169 OutputSectDesc(const std::string& pName, const Prolog& pProlog); 170 ~OutputSectDesc(); 171 172 const_iterator begin() const { return m_OutputSectCmds.begin(); } 173 iterator begin() { return m_OutputSectCmds.begin(); } 174 const_iterator end() const { return m_OutputSectCmds.end(); } 175 iterator end() { return m_OutputSectCmds.end(); } 176 177 const_reference front() const { return m_OutputSectCmds.front(); } 178 reference front() { return m_OutputSectCmds.front(); } 179 const_reference back() const { return m_OutputSectCmds.back(); } 180 reference back() { return m_OutputSectCmds.back(); } 181 182 const std::string& name() const { return m_Name; } 183 184 size_t size() const { return m_OutputSectCmds.size(); } 185 186 bool empty() const { return m_OutputSectCmds.empty(); } 187 188 void dump() const; 189 190 static bool classof(const ScriptCommand* pCmd) 191 { 192 return pCmd->getKind() == ScriptCommand::OUTPUT_SECT_DESC; 193 } 194 195 void activate(Module& pModule); 196 197 void push_back(ScriptCommand* pCommand); 198 199 void setEpilog(const Epilog& pEpilog); 200 201 const Prolog& prolog() const { return m_Prolog; } 202 203 const Epilog& epilog() const { return m_Epilog; } 204 205private: 206 OutputSectCmds m_OutputSectCmds; 207 std::string m_Name; 208 Prolog m_Prolog; 209 Epilog m_Epilog; 210}; 211 212} // namespace of mcld 213 214#endif 215