Daniel Dunbar | 7760fbe | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 1 | //===- MCAssembler.h - Object File Generation -------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef LLVM_MC_MCASSEMBLER_H |
| 11 | #define LLVM_MC_MCASSEMBLER_H |
| 12 | |
Daniel Dunbar | bd0b61d | 2010-03-10 20:58:29 +0000 | [diff] [blame] | 13 | #include "llvm/ADT/DenseMap.h" |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 14 | #include "llvm/ADT/SmallString.h" |
Daniel Dunbar | 7760fbe | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/ilist.h" |
| 16 | #include "llvm/ADT/ilist_node.h" |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 17 | #include "llvm/Support/Casting.h" |
Daniel Dunbar | ec3736d | 2010-02-13 09:28:54 +0000 | [diff] [blame] | 18 | #include "llvm/MC/MCFixup.h" |
Chandler Carruth | 1ec7df1 | 2009-10-26 01:35:46 +0000 | [diff] [blame] | 19 | #include "llvm/System/DataTypes.h" |
Daniel Dunbar | a0151d0 | 2009-08-24 11:56:58 +0000 | [diff] [blame] | 20 | #include <vector> // FIXME: Shouldn't be needed. |
Daniel Dunbar | 7760fbe | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 21 | |
| 22 | namespace llvm { |
| 23 | class raw_ostream; |
| 24 | class MCAssembler; |
Daniel Dunbar | 29efe7e | 2009-08-31 08:07:55 +0000 | [diff] [blame] | 25 | class MCContext; |
Daniel Dunbar | 4e5c1b6 | 2009-10-16 01:58:03 +0000 | [diff] [blame] | 26 | class MCExpr; |
Daniel Dunbar | 5e65c6f | 2010-02-11 21:29:29 +0000 | [diff] [blame] | 27 | class MCFragment; |
Daniel Dunbar | 7760fbe | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 28 | class MCSection; |
| 29 | class MCSectionData; |
Daniel Dunbar | 4e5c1b6 | 2009-10-16 01:58:03 +0000 | [diff] [blame] | 30 | class MCSymbol; |
Daniel Dunbar | d155a23 | 2010-03-11 01:34:27 +0000 | [diff] [blame] | 31 | class TargetAsmBackend; |
Daniel Dunbar | 7760fbe | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 32 | |
Daniel Dunbar | 5e65c6f | 2010-02-11 21:29:29 +0000 | [diff] [blame] | 33 | /// MCAsmFixup - Represent a fixed size region of bytes inside some fragment |
| 34 | /// which needs to be rewritten. This region will either be rewritten by the |
| 35 | /// assembler or cause a relocation entry to be generated. |
| 36 | struct MCAsmFixup { |
Daniel Dunbar | 5e65c6f | 2010-02-11 21:29:29 +0000 | [diff] [blame] | 37 | /// Offset - The offset inside the fragment which needs to be rewritten. |
| 38 | uint64_t Offset; |
| 39 | |
| 40 | /// Value - The expression to eventually write into the fragment. |
| 41 | const MCExpr *Value; |
| 42 | |
Daniel Dunbar | ec3736d | 2010-02-13 09:28:54 +0000 | [diff] [blame] | 43 | /// Kind - The fixup kind. |
| 44 | MCFixupKind Kind; |
Daniel Dunbar | 5e65c6f | 2010-02-11 21:29:29 +0000 | [diff] [blame] | 45 | |
| 46 | /// FixedValue - The value to replace the fix up by. |
| 47 | // |
| 48 | // FIXME: This should not be here. |
| 49 | uint64_t FixedValue; |
| 50 | |
| 51 | public: |
Daniel Dunbar | ec3736d | 2010-02-13 09:28:54 +0000 | [diff] [blame] | 52 | MCAsmFixup(uint64_t _Offset, const MCExpr &_Value, MCFixupKind _Kind) |
| 53 | : Offset(_Offset), Value(&_Value), Kind(_Kind), FixedValue(0) {} |
Daniel Dunbar | 5e65c6f | 2010-02-11 21:29:29 +0000 | [diff] [blame] | 54 | }; |
| 55 | |
Daniel Dunbar | 7760fbe | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 56 | class MCFragment : public ilist_node<MCFragment> { |
| 57 | MCFragment(const MCFragment&); // DO NOT IMPLEMENT |
| 58 | void operator=(const MCFragment&); // DO NOT IMPLEMENT |
| 59 | |
| 60 | public: |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 61 | enum FragmentType { |
| 62 | FT_Data, |
| 63 | FT_Align, |
| 64 | FT_Fill, |
Daniel Dunbar | df98a14 | 2009-08-28 05:49:21 +0000 | [diff] [blame] | 65 | FT_Org, |
| 66 | FT_ZeroFill |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | private: |
| 70 | FragmentType Kind; |
| 71 | |
Daniel Dunbar | b3730b1 | 2009-08-26 02:48:04 +0000 | [diff] [blame] | 72 | /// Parent - The data for the section this fragment is in. |
| 73 | MCSectionData *Parent; |
| 74 | |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 75 | /// @name Assembler Backend Data |
| 76 | /// @{ |
| 77 | // |
| 78 | // FIXME: This could all be kept private to the assembler implementation. |
| 79 | |
Daniel Dunbar | 1f022e2 | 2009-08-22 08:27:54 +0000 | [diff] [blame] | 80 | /// Offset - The offset of this fragment in its section. This is ~0 until |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 81 | /// initialized. |
Daniel Dunbar | 1f022e2 | 2009-08-22 08:27:54 +0000 | [diff] [blame] | 82 | uint64_t Offset; |
| 83 | |
| 84 | /// FileSize - The file size of this section. This is ~0 until initialized. |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 85 | uint64_t FileSize; |
| 86 | |
| 87 | /// @} |
| 88 | |
| 89 | protected: |
Daniel Dunbar | b3730b1 | 2009-08-26 02:48:04 +0000 | [diff] [blame] | 90 | MCFragment(FragmentType _Kind, MCSectionData *_Parent = 0); |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 91 | |
| 92 | public: |
| 93 | // Only for sentinel. |
| 94 | MCFragment(); |
| 95 | virtual ~MCFragment(); |
| 96 | |
| 97 | FragmentType getKind() const { return Kind; } |
| 98 | |
Daniel Dunbar | b3730b1 | 2009-08-26 02:48:04 +0000 | [diff] [blame] | 99 | MCSectionData *getParent() const { return Parent; } |
| 100 | void setParent(MCSectionData *Value) { Parent = Value; } |
| 101 | |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 102 | // FIXME: This should be abstract, fix sentinel. |
Daniel Dunbar | 3d153ff | 2009-08-21 23:07:38 +0000 | [diff] [blame] | 103 | virtual uint64_t getMaxFileSize() const { |
Daniel Dunbar | 197f563 | 2009-08-22 10:13:24 +0000 | [diff] [blame] | 104 | assert(0 && "Invalid getMaxFileSize call!"); |
Daniel Dunbar | 33bf7c2 | 2009-08-21 23:11:36 +0000 | [diff] [blame] | 105 | return 0; |
Douglas Gregor | 8cb4138 | 2009-12-19 07:05:23 +0000 | [diff] [blame] | 106 | } |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 107 | |
| 108 | /// @name Assembler Backend Support |
| 109 | /// @{ |
| 110 | // |
| 111 | // FIXME: This could all be kept private to the assembler implementation. |
| 112 | |
Daniel Dunbar | b3730b1 | 2009-08-26 02:48:04 +0000 | [diff] [blame] | 113 | uint64_t getAddress() const; |
| 114 | |
Daniel Dunbar | 6ad454a | 2010-02-13 09:28:03 +0000 | [diff] [blame] | 115 | uint64_t getFileSize() const { |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 116 | assert(FileSize != ~UINT64_C(0) && "File size not set!"); |
| 117 | return FileSize; |
| 118 | } |
| 119 | void setFileSize(uint64_t Value) { |
| 120 | assert(Value <= getMaxFileSize() && "Invalid file size!"); |
| 121 | FileSize = Value; |
| 122 | } |
| 123 | |
Daniel Dunbar | 1f022e2 | 2009-08-22 08:27:54 +0000 | [diff] [blame] | 124 | uint64_t getOffset() const { |
| 125 | assert(Offset != ~UINT64_C(0) && "File offset not set!"); |
| 126 | return Offset; |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 127 | } |
Daniel Dunbar | 1f022e2 | 2009-08-22 08:27:54 +0000 | [diff] [blame] | 128 | void setOffset(uint64_t Value) { Offset = Value; } |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 129 | |
| 130 | /// @} |
| 131 | |
| 132 | static bool classof(const MCFragment *O) { return true; } |
Daniel Dunbar | 6ad454a | 2010-02-13 09:28:03 +0000 | [diff] [blame] | 133 | |
| 134 | virtual void dump(); |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 135 | }; |
| 136 | |
| 137 | class MCDataFragment : public MCFragment { |
| 138 | SmallString<32> Contents; |
| 139 | |
Daniel Dunbar | 8685fa0 | 2010-02-13 09:28:43 +0000 | [diff] [blame] | 140 | /// Fixups - The list of fixups in this fragment. |
| 141 | std::vector<MCAsmFixup> Fixups; |
| 142 | |
| 143 | public: |
| 144 | typedef std::vector<MCAsmFixup>::const_iterator const_fixup_iterator; |
| 145 | typedef std::vector<MCAsmFixup>::iterator fixup_iterator; |
| 146 | |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 147 | public: |
| 148 | MCDataFragment(MCSectionData *SD = 0) : MCFragment(FT_Data, SD) {} |
| 149 | |
| 150 | /// @name Accessors |
| 151 | /// @{ |
| 152 | |
Daniel Dunbar | 3d153ff | 2009-08-21 23:07:38 +0000 | [diff] [blame] | 153 | uint64_t getMaxFileSize() const { |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 154 | return Contents.size(); |
| 155 | } |
| 156 | |
| 157 | SmallString<32> &getContents() { return Contents; } |
| 158 | const SmallString<32> &getContents() const { return Contents; } |
| 159 | |
| 160 | /// @} |
| 161 | |
Daniel Dunbar | 8685fa0 | 2010-02-13 09:28:43 +0000 | [diff] [blame] | 162 | /// @name Fixup Access |
| 163 | /// @{ |
| 164 | |
Daniel Dunbar | 03e0640 | 2010-03-12 21:00:38 +0000 | [diff] [blame^] | 165 | void addFixup(MCAsmFixup Fixup) { |
| 166 | // Enforce invariant that fixups are in offset order. |
| 167 | assert(Fixups.empty() || Fixup.Offset > Fixups.back().Offset && |
| 168 | "Fixups must be added in order!"); |
| 169 | Fixups.push_back(Fixup); |
| 170 | } |
| 171 | |
Daniel Dunbar | 8685fa0 | 2010-02-13 09:28:43 +0000 | [diff] [blame] | 172 | std::vector<MCAsmFixup> &getFixups() { return Fixups; } |
| 173 | const std::vector<MCAsmFixup> &getFixups() const { return Fixups; } |
| 174 | |
| 175 | fixup_iterator fixup_begin() { return Fixups.begin(); } |
| 176 | const_fixup_iterator fixup_begin() const { return Fixups.begin(); } |
| 177 | |
| 178 | fixup_iterator fixup_end() {return Fixups.end();} |
| 179 | const_fixup_iterator fixup_end() const {return Fixups.end();} |
| 180 | |
| 181 | size_t fixup_size() const { return Fixups.size(); } |
| 182 | |
| 183 | /// @} |
| 184 | |
Daniel Dunbar | 6ad454a | 2010-02-13 09:28:03 +0000 | [diff] [blame] | 185 | static bool classof(const MCFragment *F) { |
| 186 | return F->getKind() == MCFragment::FT_Data; |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 187 | } |
| 188 | static bool classof(const MCDataFragment *) { return true; } |
Daniel Dunbar | 6ad454a | 2010-02-13 09:28:03 +0000 | [diff] [blame] | 189 | |
| 190 | virtual void dump(); |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 191 | }; |
| 192 | |
| 193 | class MCAlignFragment : public MCFragment { |
| 194 | /// Alignment - The alignment to ensure, in bytes. |
| 195 | unsigned Alignment; |
| 196 | |
| 197 | /// Value - Value to use for filling padding bytes. |
| 198 | int64_t Value; |
| 199 | |
| 200 | /// ValueSize - The size of the integer (in bytes) of \arg Value. |
| 201 | unsigned ValueSize; |
| 202 | |
| 203 | /// MaxBytesToEmit - The maximum number of bytes to emit; if the alignment |
| 204 | /// cannot be satisfied in this width then this fragment is ignored. |
| 205 | unsigned MaxBytesToEmit; |
| 206 | |
Kevin Enderby | d767d4e | 2010-02-23 18:26:34 +0000 | [diff] [blame] | 207 | /// EmitNops - true when aligning code and optimal nops to be used for filling |
| 208 | bool EmitNops; |
| 209 | |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 210 | public: |
| 211 | MCAlignFragment(unsigned _Alignment, int64_t _Value, unsigned _ValueSize, |
Kevin Enderby | d767d4e | 2010-02-23 18:26:34 +0000 | [diff] [blame] | 212 | unsigned _MaxBytesToEmit, bool _EmitNops, |
| 213 | MCSectionData *SD = 0) |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 214 | : MCFragment(FT_Align, SD), Alignment(_Alignment), |
| 215 | Value(_Value),ValueSize(_ValueSize), |
Kevin Enderby | d767d4e | 2010-02-23 18:26:34 +0000 | [diff] [blame] | 216 | MaxBytesToEmit(_MaxBytesToEmit), EmitNops(_EmitNops) {} |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 217 | |
| 218 | /// @name Accessors |
| 219 | /// @{ |
| 220 | |
Daniel Dunbar | 3d153ff | 2009-08-21 23:07:38 +0000 | [diff] [blame] | 221 | uint64_t getMaxFileSize() const { |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 222 | return std::max(Alignment - 1, MaxBytesToEmit); |
| 223 | } |
| 224 | |
| 225 | unsigned getAlignment() const { return Alignment; } |
Daniel Dunbar | 6ad454a | 2010-02-13 09:28:03 +0000 | [diff] [blame] | 226 | |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 227 | int64_t getValue() const { return Value; } |
| 228 | |
| 229 | unsigned getValueSize() const { return ValueSize; } |
| 230 | |
| 231 | unsigned getMaxBytesToEmit() const { return MaxBytesToEmit; } |
| 232 | |
Kevin Enderby | d767d4e | 2010-02-23 18:26:34 +0000 | [diff] [blame] | 233 | unsigned getEmitNops() const { return EmitNops; } |
| 234 | |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 235 | /// @} |
| 236 | |
Daniel Dunbar | 6ad454a | 2010-02-13 09:28:03 +0000 | [diff] [blame] | 237 | static bool classof(const MCFragment *F) { |
| 238 | return F->getKind() == MCFragment::FT_Align; |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 239 | } |
| 240 | static bool classof(const MCAlignFragment *) { return true; } |
Daniel Dunbar | 6ad454a | 2010-02-13 09:28:03 +0000 | [diff] [blame] | 241 | |
| 242 | virtual void dump(); |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 243 | }; |
| 244 | |
| 245 | class MCFillFragment : public MCFragment { |
| 246 | /// Value - Value to use for filling bytes. |
Daniel Dunbar | b591b73 | 2010-02-13 09:28:32 +0000 | [diff] [blame] | 247 | int64_t Value; |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 248 | |
| 249 | /// ValueSize - The size (in bytes) of \arg Value to use when filling. |
| 250 | unsigned ValueSize; |
| 251 | |
| 252 | /// Count - The number of copies of \arg Value to insert. |
| 253 | uint64_t Count; |
| 254 | |
| 255 | public: |
Daniel Dunbar | b591b73 | 2010-02-13 09:28:32 +0000 | [diff] [blame] | 256 | MCFillFragment(int64_t _Value, unsigned _ValueSize, uint64_t _Count, |
Daniel Dunbar | 6ad454a | 2010-02-13 09:28:03 +0000 | [diff] [blame] | 257 | MCSectionData *SD = 0) |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 258 | : MCFragment(FT_Fill, SD), |
Daniel Dunbar | b591b73 | 2010-02-13 09:28:32 +0000 | [diff] [blame] | 259 | Value(_Value), ValueSize(_ValueSize), Count(_Count) {} |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 260 | |
| 261 | /// @name Accessors |
| 262 | /// @{ |
| 263 | |
Daniel Dunbar | 3d153ff | 2009-08-21 23:07:38 +0000 | [diff] [blame] | 264 | uint64_t getMaxFileSize() const { |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 265 | return ValueSize * Count; |
| 266 | } |
| 267 | |
Daniel Dunbar | b591b73 | 2010-02-13 09:28:32 +0000 | [diff] [blame] | 268 | int64_t getValue() const { return Value; } |
Daniel Dunbar | 6ad454a | 2010-02-13 09:28:03 +0000 | [diff] [blame] | 269 | |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 270 | unsigned getValueSize() const { return ValueSize; } |
| 271 | |
| 272 | uint64_t getCount() const { return Count; } |
| 273 | |
| 274 | /// @} |
| 275 | |
Daniel Dunbar | 6ad454a | 2010-02-13 09:28:03 +0000 | [diff] [blame] | 276 | static bool classof(const MCFragment *F) { |
| 277 | return F->getKind() == MCFragment::FT_Fill; |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 278 | } |
| 279 | static bool classof(const MCFillFragment *) { return true; } |
Daniel Dunbar | 6ad454a | 2010-02-13 09:28:03 +0000 | [diff] [blame] | 280 | |
| 281 | virtual void dump(); |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 282 | }; |
| 283 | |
| 284 | class MCOrgFragment : public MCFragment { |
| 285 | /// Offset - The offset this fragment should start at. |
Daniel Dunbar | 4e5c1b6 | 2009-10-16 01:58:03 +0000 | [diff] [blame] | 286 | const MCExpr *Offset; |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 287 | |
Daniel Dunbar | 6ad454a | 2010-02-13 09:28:03 +0000 | [diff] [blame] | 288 | /// Value - Value to use for filling bytes. |
Daniel Dunbar | 3d153ff | 2009-08-21 23:07:38 +0000 | [diff] [blame] | 289 | int8_t Value; |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 290 | |
| 291 | public: |
Daniel Dunbar | 4e5c1b6 | 2009-10-16 01:58:03 +0000 | [diff] [blame] | 292 | MCOrgFragment(const MCExpr &_Offset, int8_t _Value, MCSectionData *SD = 0) |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 293 | : MCFragment(FT_Org, SD), |
Daniel Dunbar | 4e5c1b6 | 2009-10-16 01:58:03 +0000 | [diff] [blame] | 294 | Offset(&_Offset), Value(_Value) {} |
Daniel Dunbar | df98a14 | 2009-08-28 05:49:21 +0000 | [diff] [blame] | 295 | |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 296 | /// @name Accessors |
| 297 | /// @{ |
| 298 | |
Daniel Dunbar | 3d153ff | 2009-08-21 23:07:38 +0000 | [diff] [blame] | 299 | uint64_t getMaxFileSize() const { |
| 300 | // FIXME: This doesn't make much sense. |
| 301 | return ~UINT64_C(0); |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 302 | } |
| 303 | |
Daniel Dunbar | 4e5c1b6 | 2009-10-16 01:58:03 +0000 | [diff] [blame] | 304 | const MCExpr &getOffset() const { return *Offset; } |
Daniel Dunbar | 6ad454a | 2010-02-13 09:28:03 +0000 | [diff] [blame] | 305 | |
Daniel Dunbar | 3d153ff | 2009-08-21 23:07:38 +0000 | [diff] [blame] | 306 | uint8_t getValue() const { return Value; } |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 307 | |
| 308 | /// @} |
| 309 | |
Daniel Dunbar | 6ad454a | 2010-02-13 09:28:03 +0000 | [diff] [blame] | 310 | static bool classof(const MCFragment *F) { |
| 311 | return F->getKind() == MCFragment::FT_Org; |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 312 | } |
| 313 | static bool classof(const MCOrgFragment *) { return true; } |
Daniel Dunbar | 6ad454a | 2010-02-13 09:28:03 +0000 | [diff] [blame] | 314 | |
| 315 | virtual void dump(); |
Daniel Dunbar | 7760fbe | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 316 | }; |
| 317 | |
Daniel Dunbar | df98a14 | 2009-08-28 05:49:21 +0000 | [diff] [blame] | 318 | /// MCZeroFillFragment - Represent data which has a fixed size and alignment, |
| 319 | /// but requires no physical space in the object file. |
| 320 | class MCZeroFillFragment : public MCFragment { |
| 321 | /// Size - The size of this fragment. |
| 322 | uint64_t Size; |
| 323 | |
| 324 | /// Alignment - The alignment for this fragment. |
| 325 | unsigned Alignment; |
| 326 | |
| 327 | public: |
| 328 | MCZeroFillFragment(uint64_t _Size, unsigned _Alignment, MCSectionData *SD = 0) |
| 329 | : MCFragment(FT_ZeroFill, SD), |
| 330 | Size(_Size), Alignment(_Alignment) {} |
| 331 | |
| 332 | /// @name Accessors |
| 333 | /// @{ |
| 334 | |
| 335 | uint64_t getMaxFileSize() const { |
| 336 | // FIXME: This also doesn't make much sense, this method is misnamed. |
| 337 | return ~UINT64_C(0); |
| 338 | } |
| 339 | |
| 340 | uint64_t getSize() const { return Size; } |
Daniel Dunbar | 6ad454a | 2010-02-13 09:28:03 +0000 | [diff] [blame] | 341 | |
Daniel Dunbar | df98a14 | 2009-08-28 05:49:21 +0000 | [diff] [blame] | 342 | unsigned getAlignment() const { return Alignment; } |
| 343 | |
| 344 | /// @} |
| 345 | |
Daniel Dunbar | 6ad454a | 2010-02-13 09:28:03 +0000 | [diff] [blame] | 346 | static bool classof(const MCFragment *F) { |
| 347 | return F->getKind() == MCFragment::FT_ZeroFill; |
Daniel Dunbar | df98a14 | 2009-08-28 05:49:21 +0000 | [diff] [blame] | 348 | } |
| 349 | static bool classof(const MCZeroFillFragment *) { return true; } |
Daniel Dunbar | 6ad454a | 2010-02-13 09:28:03 +0000 | [diff] [blame] | 350 | |
| 351 | virtual void dump(); |
Daniel Dunbar | df98a14 | 2009-08-28 05:49:21 +0000 | [diff] [blame] | 352 | }; |
| 353 | |
Daniel Dunbar | 7760fbe | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 354 | // FIXME: Should this be a separate class, or just merged into MCSection? Since |
| 355 | // we anticipate the fast path being through an MCAssembler, the only reason to |
| 356 | // keep it out is for API abstraction. |
| 357 | class MCSectionData : public ilist_node<MCSectionData> { |
| 358 | MCSectionData(const MCSectionData&); // DO NOT IMPLEMENT |
| 359 | void operator=(const MCSectionData&); // DO NOT IMPLEMENT |
| 360 | |
| 361 | public: |
| 362 | typedef iplist<MCFragment> FragmentListType; |
| 363 | |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 364 | typedef FragmentListType::const_iterator const_iterator; |
| 365 | typedef FragmentListType::iterator iterator; |
| 366 | |
Daniel Dunbar | bd91fed | 2010-02-11 21:29:46 +0000 | [diff] [blame] | 367 | typedef FragmentListType::const_reverse_iterator const_reverse_iterator; |
| 368 | typedef FragmentListType::reverse_iterator reverse_iterator; |
Daniel Dunbar | 8fa9da2 | 2009-08-26 13:58:10 +0000 | [diff] [blame] | 369 | |
Daniel Dunbar | 7760fbe | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 370 | private: |
| 371 | iplist<MCFragment> Fragments; |
Daniel Dunbar | adb77e4 | 2009-08-27 00:38:04 +0000 | [diff] [blame] | 372 | const MCSection *Section; |
Daniel Dunbar | 7760fbe | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 373 | |
| 374 | /// Alignment - The maximum alignment seen in this section. |
| 375 | unsigned Alignment; |
| 376 | |
| 377 | /// @name Assembler Backend Data |
| 378 | /// @{ |
| 379 | // |
| 380 | // FIXME: This could all be kept private to the assembler implementation. |
| 381 | |
Daniel Dunbar | b3730b1 | 2009-08-26 02:48:04 +0000 | [diff] [blame] | 382 | /// Address - The computed address of this section. This is ~0 until |
| 383 | /// initialized. |
| 384 | uint64_t Address; |
| 385 | |
Daniel Dunbar | 0f56d41 | 2009-08-26 04:13:32 +0000 | [diff] [blame] | 386 | /// Size - The content size of this section. This is ~0 until initialized. |
| 387 | uint64_t Size; |
| 388 | |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 389 | /// FileSize - The size of this section in the object file. This is ~0 until |
| 390 | /// initialized. |
Daniel Dunbar | 7760fbe | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 391 | uint64_t FileSize; |
| 392 | |
Daniel Dunbar | 8253f50 | 2010-02-02 21:44:01 +0000 | [diff] [blame] | 393 | /// HasInstructions - Whether this section has had instructions emitted into |
| 394 | /// it. |
| 395 | unsigned HasInstructions : 1; |
| 396 | |
Daniel Dunbar | 7760fbe | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 397 | /// @} |
| 398 | |
Daniel Dunbar | 6ad454a | 2010-02-13 09:28:03 +0000 | [diff] [blame] | 399 | public: |
Daniel Dunbar | 7760fbe | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 400 | // Only for use as sentinel. |
| 401 | MCSectionData(); |
| 402 | MCSectionData(const MCSection &Section, MCAssembler *A = 0); |
| 403 | |
Daniel Dunbar | adb77e4 | 2009-08-27 00:38:04 +0000 | [diff] [blame] | 404 | const MCSection &getSection() const { return *Section; } |
Daniel Dunbar | 7760fbe | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 405 | |
| 406 | unsigned getAlignment() const { return Alignment; } |
| 407 | void setAlignment(unsigned Value) { Alignment = Value; } |
| 408 | |
Daniel Dunbar | c3c1992 | 2009-08-26 13:57:54 +0000 | [diff] [blame] | 409 | /// @name Fragment Access |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 410 | /// @{ |
| 411 | |
| 412 | const FragmentListType &getFragmentList() const { return Fragments; } |
| 413 | FragmentListType &getFragmentList() { return Fragments; } |
| 414 | |
| 415 | iterator begin() { return Fragments.begin(); } |
| 416 | const_iterator begin() const { return Fragments.begin(); } |
| 417 | |
| 418 | iterator end() { return Fragments.end(); } |
| 419 | const_iterator end() const { return Fragments.end(); } |
| 420 | |
Daniel Dunbar | bd91fed | 2010-02-11 21:29:46 +0000 | [diff] [blame] | 421 | reverse_iterator rbegin() { return Fragments.rbegin(); } |
| 422 | const_reverse_iterator rbegin() const { return Fragments.rbegin(); } |
| 423 | |
| 424 | reverse_iterator rend() { return Fragments.rend(); } |
| 425 | const_reverse_iterator rend() const { return Fragments.rend(); } |
| 426 | |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 427 | size_t size() const { return Fragments.size(); } |
| 428 | |
Daniel Dunbar | 197f563 | 2009-08-22 10:13:24 +0000 | [diff] [blame] | 429 | bool empty() const { return Fragments.empty(); } |
| 430 | |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 431 | /// @} |
Daniel Dunbar | 7760fbe | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 432 | /// @name Assembler Backend Support |
| 433 | /// @{ |
| 434 | // |
| 435 | // FIXME: This could all be kept private to the assembler implementation. |
| 436 | |
Daniel Dunbar | 6ad454a | 2010-02-13 09:28:03 +0000 | [diff] [blame] | 437 | uint64_t getAddress() const { |
Daniel Dunbar | b3730b1 | 2009-08-26 02:48:04 +0000 | [diff] [blame] | 438 | assert(Address != ~UINT64_C(0) && "Address not set!"); |
| 439 | return Address; |
| 440 | } |
| 441 | void setAddress(uint64_t Value) { Address = Value; } |
| 442 | |
Daniel Dunbar | 6ad454a | 2010-02-13 09:28:03 +0000 | [diff] [blame] | 443 | uint64_t getSize() const { |
Daniel Dunbar | 0f56d41 | 2009-08-26 04:13:32 +0000 | [diff] [blame] | 444 | assert(Size != ~UINT64_C(0) && "File size not set!"); |
| 445 | return Size; |
| 446 | } |
| 447 | void setSize(uint64_t Value) { Size = Value; } |
| 448 | |
Daniel Dunbar | 6ad454a | 2010-02-13 09:28:03 +0000 | [diff] [blame] | 449 | uint64_t getFileSize() const { |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 450 | assert(FileSize != ~UINT64_C(0) && "File size not set!"); |
| 451 | return FileSize; |
| 452 | } |
Daniel Dunbar | 6ad454a | 2010-02-13 09:28:03 +0000 | [diff] [blame] | 453 | void setFileSize(uint64_t Value) { FileSize = Value; } |
Daniel Dunbar | 7760fbe | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 454 | |
Daniel Dunbar | 8253f50 | 2010-02-02 21:44:01 +0000 | [diff] [blame] | 455 | bool hasInstructions() const { return HasInstructions; } |
| 456 | void setHasInstructions(bool Value) { HasInstructions = Value; } |
| 457 | |
Daniel Dunbar | 7760fbe | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 458 | /// @} |
Daniel Dunbar | 6ad454a | 2010-02-13 09:28:03 +0000 | [diff] [blame] | 459 | |
| 460 | void dump(); |
Daniel Dunbar | 7760fbe | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 461 | }; |
| 462 | |
Daniel Dunbar | 197f563 | 2009-08-22 10:13:24 +0000 | [diff] [blame] | 463 | // FIXME: Same concerns as with SectionData. |
| 464 | class MCSymbolData : public ilist_node<MCSymbolData> { |
| 465 | public: |
Daniel Dunbar | ef0f637 | 2009-09-01 04:09:03 +0000 | [diff] [blame] | 466 | const MCSymbol *Symbol; |
Daniel Dunbar | 197f563 | 2009-08-22 10:13:24 +0000 | [diff] [blame] | 467 | |
| 468 | /// Fragment - The fragment this symbol's value is relative to, if any. |
| 469 | MCFragment *Fragment; |
| 470 | |
| 471 | /// Offset - The offset to apply to the fragment address to form this symbol's |
| 472 | /// value. |
| 473 | uint64_t Offset; |
Daniel Dunbar | 6ad454a | 2010-02-13 09:28:03 +0000 | [diff] [blame] | 474 | |
Daniel Dunbar | 6fae16d | 2009-08-22 11:41:10 +0000 | [diff] [blame] | 475 | /// IsExternal - True if this symbol is visible outside this translation |
| 476 | /// unit. |
| 477 | unsigned IsExternal : 1; |
Daniel Dunbar | 197f563 | 2009-08-22 10:13:24 +0000 | [diff] [blame] | 478 | |
Daniel Dunbar | 30b0942 | 2009-08-24 08:40:12 +0000 | [diff] [blame] | 479 | /// IsPrivateExtern - True if this symbol is private extern. |
| 480 | unsigned IsPrivateExtern : 1; |
| 481 | |
Daniel Dunbar | 8388a8f | 2009-08-28 07:08:35 +0000 | [diff] [blame] | 482 | /// CommonSize - The size of the symbol, if it is 'common', or 0. |
| 483 | // |
| 484 | // FIXME: Pack this in with other fields? We could put it in offset, since a |
| 485 | // common symbol can never get a definition. |
| 486 | uint64_t CommonSize; |
| 487 | |
| 488 | /// CommonAlign - The alignment of the symbol, if it is 'common'. |
| 489 | // |
| 490 | // FIXME: Pack this in with other fields? |
| 491 | unsigned CommonAlign; |
| 492 | |
Daniel Dunbar | 30b0942 | 2009-08-24 08:40:12 +0000 | [diff] [blame] | 493 | /// Flags - The Flags field is used by object file implementations to store |
| 494 | /// additional per symbol information which is not easily classified. |
| 495 | uint32_t Flags; |
| 496 | |
Daniel Dunbar | c3c1992 | 2009-08-26 13:57:54 +0000 | [diff] [blame] | 497 | /// Index - Index field, for use by the object file implementation. |
| 498 | uint64_t Index; |
| 499 | |
Daniel Dunbar | 197f563 | 2009-08-22 10:13:24 +0000 | [diff] [blame] | 500 | public: |
| 501 | // Only for use as sentinel. |
| 502 | MCSymbolData(); |
Daniel Dunbar | 22ad5f8 | 2009-08-31 08:08:06 +0000 | [diff] [blame] | 503 | MCSymbolData(const MCSymbol &_Symbol, MCFragment *_Fragment, uint64_t _Offset, |
Daniel Dunbar | 197f563 | 2009-08-22 10:13:24 +0000 | [diff] [blame] | 504 | MCAssembler *A = 0); |
| 505 | |
| 506 | /// @name Accessors |
| 507 | /// @{ |
| 508 | |
Daniel Dunbar | ef0f637 | 2009-09-01 04:09:03 +0000 | [diff] [blame] | 509 | const MCSymbol &getSymbol() const { return *Symbol; } |
Daniel Dunbar | 197f563 | 2009-08-22 10:13:24 +0000 | [diff] [blame] | 510 | |
| 511 | MCFragment *getFragment() const { return Fragment; } |
| 512 | void setFragment(MCFragment *Value) { Fragment = Value; } |
| 513 | |
| 514 | uint64_t getOffset() const { return Offset; } |
| 515 | void setOffset(uint64_t Value) { Offset = Value; } |
| 516 | |
Daniel Dunbar | f97aee1 | 2010-03-11 18:22:51 +0000 | [diff] [blame] | 517 | uint64_t getAddress() const { |
| 518 | assert(getFragment() && "Invalid getAddress() on undefined symbol!"); |
| 519 | return getFragment()->getAddress() + getOffset(); |
| 520 | } |
| 521 | |
Daniel Dunbar | 30b0942 | 2009-08-24 08:40:12 +0000 | [diff] [blame] | 522 | /// @} |
| 523 | /// @name Symbol Attributes |
| 524 | /// @{ |
Daniel Dunbar | 6ad454a | 2010-02-13 09:28:03 +0000 | [diff] [blame] | 525 | |
Daniel Dunbar | 30b0942 | 2009-08-24 08:40:12 +0000 | [diff] [blame] | 526 | bool isExternal() const { return IsExternal; } |
| 527 | void setExternal(bool Value) { IsExternal = Value; } |
Daniel Dunbar | 6ad454a | 2010-02-13 09:28:03 +0000 | [diff] [blame] | 528 | |
Daniel Dunbar | 30b0942 | 2009-08-24 08:40:12 +0000 | [diff] [blame] | 529 | bool isPrivateExtern() const { return IsPrivateExtern; } |
| 530 | void setPrivateExtern(bool Value) { IsPrivateExtern = Value; } |
Daniel Dunbar | 8388a8f | 2009-08-28 07:08:35 +0000 | [diff] [blame] | 531 | |
| 532 | /// isCommon - Is this a 'common' symbol. |
| 533 | bool isCommon() const { return CommonSize != 0; } |
| 534 | |
| 535 | /// setCommon - Mark this symbol as being 'common'. |
| 536 | /// |
| 537 | /// \param Size - The size of the symbol. |
| 538 | /// \param Align - The alignment of the symbol. |
| 539 | void setCommon(uint64_t Size, unsigned Align) { |
| 540 | CommonSize = Size; |
| 541 | CommonAlign = Align; |
| 542 | } |
| 543 | |
| 544 | /// getCommonSize - Return the size of a 'common' symbol. |
| 545 | uint64_t getCommonSize() const { |
| 546 | assert(isCommon() && "Not a 'common' symbol!"); |
| 547 | return CommonSize; |
| 548 | } |
| 549 | |
| 550 | /// getCommonAlignment - Return the alignment of a 'common' symbol. |
| 551 | unsigned getCommonAlignment() const { |
| 552 | assert(isCommon() && "Not a 'common' symbol!"); |
| 553 | return CommonAlign; |
| 554 | } |
| 555 | |
Daniel Dunbar | 30b0942 | 2009-08-24 08:40:12 +0000 | [diff] [blame] | 556 | /// getFlags - Get the (implementation defined) symbol flags. |
| 557 | uint32_t getFlags() const { return Flags; } |
Daniel Dunbar | 6fae16d | 2009-08-22 11:41:10 +0000 | [diff] [blame] | 558 | |
Daniel Dunbar | 30b0942 | 2009-08-24 08:40:12 +0000 | [diff] [blame] | 559 | /// setFlags - Set the (implementation defined) symbol flags. |
| 560 | void setFlags(uint32_t Value) { Flags = Value; } |
Daniel Dunbar | 6ad454a | 2010-02-13 09:28:03 +0000 | [diff] [blame] | 561 | |
Daniel Dunbar | c3c1992 | 2009-08-26 13:57:54 +0000 | [diff] [blame] | 562 | /// getIndex - Get the (implementation defined) index. |
| 563 | uint64_t getIndex() const { return Index; } |
| 564 | |
| 565 | /// setIndex - Set the (implementation defined) index. |
| 566 | void setIndex(uint64_t Value) { Index = Value; } |
Daniel Dunbar | 6ad454a | 2010-02-13 09:28:03 +0000 | [diff] [blame] | 567 | |
| 568 | /// @} |
| 569 | |
| 570 | void dump(); |
Daniel Dunbar | 197f563 | 2009-08-22 10:13:24 +0000 | [diff] [blame] | 571 | }; |
| 572 | |
Daniel Dunbar | a0151d0 | 2009-08-24 11:56:58 +0000 | [diff] [blame] | 573 | // FIXME: This really doesn't belong here. See comments below. |
| 574 | struct IndirectSymbolData { |
| 575 | MCSymbol *Symbol; |
| 576 | MCSectionData *SectionData; |
| 577 | }; |
| 578 | |
Daniel Dunbar | 7760fbe | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 579 | class MCAssembler { |
| 580 | public: |
| 581 | typedef iplist<MCSectionData> SectionDataListType; |
Daniel Dunbar | 197f563 | 2009-08-22 10:13:24 +0000 | [diff] [blame] | 582 | typedef iplist<MCSymbolData> SymbolDataListType; |
Daniel Dunbar | 7760fbe | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 583 | |
| 584 | typedef SectionDataListType::const_iterator const_iterator; |
| 585 | typedef SectionDataListType::iterator iterator; |
| 586 | |
Daniel Dunbar | 197f563 | 2009-08-22 10:13:24 +0000 | [diff] [blame] | 587 | typedef SymbolDataListType::const_iterator const_symbol_iterator; |
| 588 | typedef SymbolDataListType::iterator symbol_iterator; |
| 589 | |
Daniel Dunbar | a0151d0 | 2009-08-24 11:56:58 +0000 | [diff] [blame] | 590 | typedef std::vector<IndirectSymbolData>::iterator indirect_symbol_iterator; |
| 591 | |
Daniel Dunbar | 7760fbe | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 592 | private: |
| 593 | MCAssembler(const MCAssembler&); // DO NOT IMPLEMENT |
| 594 | void operator=(const MCAssembler&); // DO NOT IMPLEMENT |
| 595 | |
Daniel Dunbar | 29efe7e | 2009-08-31 08:07:55 +0000 | [diff] [blame] | 596 | MCContext &Context; |
| 597 | |
Daniel Dunbar | d155a23 | 2010-03-11 01:34:27 +0000 | [diff] [blame] | 598 | TargetAsmBackend &Backend; |
| 599 | |
Daniel Dunbar | 7760fbe | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 600 | raw_ostream &OS; |
Daniel Dunbar | 6ad454a | 2010-02-13 09:28:03 +0000 | [diff] [blame] | 601 | |
Daniel Dunbar | 7760fbe | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 602 | iplist<MCSectionData> Sections; |
| 603 | |
Daniel Dunbar | 197f563 | 2009-08-22 10:13:24 +0000 | [diff] [blame] | 604 | iplist<MCSymbolData> Symbols; |
| 605 | |
Daniel Dunbar | bd0b61d | 2010-03-10 20:58:29 +0000 | [diff] [blame] | 606 | /// The map of sections to their associated assembler backend data. |
| 607 | // |
| 608 | // FIXME: Avoid this indirection? |
| 609 | DenseMap<const MCSection*, MCSectionData*> SectionMap; |
| 610 | |
| 611 | /// The map of symbols to their associated assembler backend data. |
| 612 | // |
| 613 | // FIXME: Avoid this indirection? |
| 614 | DenseMap<const MCSymbol*, MCSymbolData*> SymbolMap; |
| 615 | |
Daniel Dunbar | a0151d0 | 2009-08-24 11:56:58 +0000 | [diff] [blame] | 616 | std::vector<IndirectSymbolData> IndirectSymbols; |
| 617 | |
Daniel Dunbar | f8c4bb7 | 2009-08-26 21:22:22 +0000 | [diff] [blame] | 618 | unsigned SubsectionsViaSymbols : 1; |
| 619 | |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 620 | private: |
| 621 | /// LayoutSection - Assign offsets and sizes to the fragments in the section |
| 622 | /// \arg SD, and update the section size. The section file offset should |
| 623 | /// already have been computed. |
Daniel Dunbar | 1c215be | 2009-08-28 05:49:04 +0000 | [diff] [blame] | 624 | void LayoutSection(MCSectionData &SD); |
Daniel Dunbar | 8fcefbe | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 625 | |
Daniel Dunbar | 7760fbe | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 626 | public: |
| 627 | /// Construct a new assembler instance. |
| 628 | /// |
| 629 | /// \arg OS - The stream to output to. |
| 630 | // |
| 631 | // FIXME: How are we going to parameterize this? Two obvious options are stay |
| 632 | // concrete and require clients to pass in a target like object. The other |
| 633 | // option is to make this abstract, and have targets provide concrete |
| 634 | // implementations as we do with AsmParser. |
Daniel Dunbar | d155a23 | 2010-03-11 01:34:27 +0000 | [diff] [blame] | 635 | MCAssembler(MCContext &_Context, TargetAsmBackend &_Backend, raw_ostream &OS); |
Daniel Dunbar | 7760fbe | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 636 | ~MCAssembler(); |
| 637 | |
Daniel Dunbar | 29efe7e | 2009-08-31 08:07:55 +0000 | [diff] [blame] | 638 | MCContext &getContext() const { return Context; } |
| 639 | |
Daniel Dunbar | fe3eef5 | 2010-03-11 02:28:59 +0000 | [diff] [blame] | 640 | TargetAsmBackend &getBackend() const { return Backend; } |
| 641 | |
Daniel Dunbar | 7760fbe | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 642 | /// Finish - Do final processing and write the object to the output stream. |
| 643 | void Finish(); |
| 644 | |
Daniel Dunbar | f8c4bb7 | 2009-08-26 21:22:22 +0000 | [diff] [blame] | 645 | // FIXME: This does not belong here. |
| 646 | bool getSubsectionsViaSymbols() const { |
| 647 | return SubsectionsViaSymbols; |
| 648 | } |
| 649 | void setSubsectionsViaSymbols(bool Value) { |
| 650 | SubsectionsViaSymbols = Value; |
| 651 | } |
| 652 | |
Daniel Dunbar | 7760fbe | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 653 | /// @name Section List Access |
| 654 | /// @{ |
| 655 | |
| 656 | const SectionDataListType &getSectionList() const { return Sections; } |
Daniel Dunbar | 6ad454a | 2010-02-13 09:28:03 +0000 | [diff] [blame] | 657 | SectionDataListType &getSectionList() { return Sections; } |
Daniel Dunbar | 7760fbe | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 658 | |
| 659 | iterator begin() { return Sections.begin(); } |
| 660 | const_iterator begin() const { return Sections.begin(); } |
| 661 | |
| 662 | iterator end() { return Sections.end(); } |
| 663 | const_iterator end() const { return Sections.end(); } |
| 664 | |
| 665 | size_t size() const { return Sections.size(); } |
| 666 | |
| 667 | /// @} |
Daniel Dunbar | 197f563 | 2009-08-22 10:13:24 +0000 | [diff] [blame] | 668 | /// @name Symbol List Access |
| 669 | /// @{ |
| 670 | |
| 671 | const SymbolDataListType &getSymbolList() const { return Symbols; } |
| 672 | SymbolDataListType &getSymbolList() { return Symbols; } |
| 673 | |
| 674 | symbol_iterator symbol_begin() { return Symbols.begin(); } |
| 675 | const_symbol_iterator symbol_begin() const { return Symbols.begin(); } |
| 676 | |
| 677 | symbol_iterator symbol_end() { return Symbols.end(); } |
| 678 | const_symbol_iterator symbol_end() const { return Symbols.end(); } |
| 679 | |
| 680 | size_t symbol_size() const { return Symbols.size(); } |
| 681 | |
| 682 | /// @} |
Daniel Dunbar | a0151d0 | 2009-08-24 11:56:58 +0000 | [diff] [blame] | 683 | /// @name Indirect Symbol List Access |
| 684 | /// @{ |
| 685 | |
| 686 | // FIXME: This is a total hack, this should not be here. Once things are |
| 687 | // factored so that the streamer has direct access to the .o writer, it can |
| 688 | // disappear. |
| 689 | std::vector<IndirectSymbolData> &getIndirectSymbols() { |
| 690 | return IndirectSymbols; |
| 691 | } |
| 692 | |
| 693 | indirect_symbol_iterator indirect_symbol_begin() { |
| 694 | return IndirectSymbols.begin(); |
| 695 | } |
| 696 | |
| 697 | indirect_symbol_iterator indirect_symbol_end() { |
| 698 | return IndirectSymbols.end(); |
| 699 | } |
| 700 | |
| 701 | size_t indirect_symbol_size() const { return IndirectSymbols.size(); } |
| 702 | |
| 703 | /// @} |
Daniel Dunbar | bd0b61d | 2010-03-10 20:58:29 +0000 | [diff] [blame] | 704 | /// @name Backend Data Access |
| 705 | /// @{ |
| 706 | |
| 707 | MCSectionData &getSectionData(const MCSection &Section) { |
| 708 | MCSectionData *&Entry = SectionMap[&Section]; |
| 709 | assert(Entry && "Missing section data!"); |
| 710 | return *Entry; |
| 711 | } |
| 712 | |
| 713 | MCSectionData &getOrCreateSectionData(const MCSection &Section, |
| 714 | bool *Created = 0) { |
| 715 | MCSectionData *&Entry = SectionMap[&Section]; |
| 716 | |
| 717 | if (Created) *Created = !Entry; |
| 718 | if (!Entry) |
| 719 | Entry = new MCSectionData(Section, this); |
| 720 | |
| 721 | return *Entry; |
| 722 | } |
| 723 | |
| 724 | MCSymbolData &getSymbolData(const MCSymbol &Symbol) { |
| 725 | MCSymbolData *&Entry = SymbolMap[&Symbol]; |
| 726 | assert(Entry && "Missing symbol data!"); |
| 727 | return *Entry; |
| 728 | } |
| 729 | |
| 730 | MCSymbolData &getOrCreateSymbolData(const MCSymbol &Symbol, |
| 731 | bool *Created = 0) { |
| 732 | MCSymbolData *&Entry = SymbolMap[&Symbol]; |
| 733 | |
| 734 | if (Created) *Created = !Entry; |
| 735 | if (!Entry) |
| 736 | Entry = new MCSymbolData(Symbol, 0, 0, this); |
| 737 | |
| 738 | return *Entry; |
| 739 | } |
| 740 | |
| 741 | /// @} |
Daniel Dunbar | 6ad454a | 2010-02-13 09:28:03 +0000 | [diff] [blame] | 742 | |
| 743 | void dump(); |
Daniel Dunbar | 7760fbe | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 744 | }; |
| 745 | |
| 746 | } // end namespace llvm |
| 747 | |
| 748 | #endif |