diff options
author | Eli Bendersky <eliben@google.com> | 2012-12-07 19:13:57 +0000 |
---|---|---|
committer | Eli Bendersky <eliben@google.com> | 2012-12-07 19:13:57 +0000 |
commit | 64d9a3233476553fc950f0f2fc6a2cdd2a4c05cf (patch) | |
tree | 42e99ad39f9203c0caf206319b45449bf7723230 /include/llvm/MC | |
parent | e4ccfef809a1a47f1386bb2767b8c77e64644435 (diff) | |
download | external_llvm-64d9a3233476553fc950f0f2fc6a2cdd2a4c05cf.zip external_llvm-64d9a3233476553fc950f0f2fc6a2cdd2a4c05cf.tar.gz external_llvm-64d9a3233476553fc950f0f2fc6a2cdd2a4c05cf.tar.bz2 |
Refactor MCInstFragment and MCDataFragment to adhere to a common interface,
which removes code duplication and prepares the ground for future additions.
Full discussion:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20121203/158233.html
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169626 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/MC')
-rw-r--r-- | include/llvm/MC/MCAssembler.h | 95 |
1 files changed, 50 insertions, 45 deletions
diff --git a/include/llvm/MC/MCAssembler.h b/include/llvm/MC/MCAssembler.h index 266e0c7..a308030 100644 --- a/include/llvm/MC/MCAssembler.h +++ b/include/llvm/MC/MCAssembler.h @@ -102,7 +102,35 @@ public: void dump(); }; -class MCDataFragment : public MCFragment { +class MCEncodedFragment : public MCFragment { + virtual void anchor(); +public: + MCEncodedFragment(MCFragment::FragmentType FType, MCSectionData *SD = 0) + : MCFragment(FType, SD) { + } + virtual ~MCEncodedFragment(); + + typedef SmallVectorImpl<MCFixup>::const_iterator const_fixup_iterator; + typedef SmallVectorImpl<MCFixup>::iterator fixup_iterator; + + virtual SmallString<32> &getContents() = 0; + virtual const SmallString<32> &getContents() const = 0; + + virtual SmallVectorImpl<MCFixup> &getFixups() = 0; + virtual const SmallVectorImpl<MCFixup> &getFixups() const = 0; + + virtual fixup_iterator fixup_begin() = 0; + virtual const_fixup_iterator fixup_begin() const = 0; + virtual fixup_iterator fixup_end() = 0; + virtual const_fixup_iterator fixup_end() const = 0; + + static bool classof(const MCFragment *F) { + MCFragment::FragmentType Kind = F->getKind(); + return Kind == MCFragment::FT_Inst || Kind == MCFragment::FT_Data; + } +}; + +class MCDataFragment : public MCEncodedFragment { virtual void anchor(); SmallString<32> Contents; @@ -110,27 +138,19 @@ class MCDataFragment : public MCFragment { SmallVector<MCFixup, 4> Fixups; public: - typedef SmallVectorImpl<MCFixup>::const_iterator const_fixup_iterator; - typedef SmallVectorImpl<MCFixup>::iterator fixup_iterator; - -public: - MCDataFragment(MCSectionData *SD = 0) : MCFragment(FT_Data, SD) {} - - /// @name Accessors - /// @{ + MCDataFragment(MCSectionData *SD = 0) + : MCEncodedFragment(FT_Data, SD) { + } SmallString<32> &getContents() { return Contents; } const SmallString<32> &getContents() const { return Contents; } - /// @} - /// @name Fixup Access - /// @{ + SmallVectorImpl<MCFixup> &getFixups() { + return Fixups; + } - void addFixup(MCFixup Fixup) { - // Enforce invariant that fixups are in offset order. - assert((Fixups.empty() || Fixup.getOffset() >= Fixups.back().getOffset()) && - "Fixups must be added in order!"); - Fixups.push_back(Fixup); + const SmallVectorImpl<MCFixup> &getFixups() const { + return Fixups; } fixup_iterator fixup_begin() { return Fixups.begin(); } @@ -139,55 +159,42 @@ public: fixup_iterator fixup_end() {return Fixups.end();} const_fixup_iterator fixup_end() const {return Fixups.end();} - /// @} - static bool classof(const MCFragment *F) { return F->getKind() == MCFragment::FT_Data; } }; -// FIXME: This current incarnation of MCInstFragment doesn't make much sense, as -// it is almost entirely a duplicate of MCDataFragment. If we decide to stick -// with this approach (as opposed to making MCInstFragment a very light weight -// object with just the MCInst and a code size, then we should just change -// MCDataFragment to have an optional MCInst at its end. -class MCInstFragment : public MCFragment { +class MCInstFragment : public MCEncodedFragment { virtual void anchor(); /// Inst - The instruction this is a fragment for. MCInst Inst; - /// Code - Binary data for the currently encoded instruction. - SmallString<8> Code; + /// Contents - Binary data for the currently encoded instruction. + SmallString<32> Contents; /// Fixups - The list of fixups in this fragment. SmallVector<MCFixup, 1> Fixups; public: - typedef SmallVectorImpl<MCFixup>::const_iterator const_fixup_iterator; - typedef SmallVectorImpl<MCFixup>::iterator fixup_iterator; - -public: MCInstFragment(const MCInst &_Inst, MCSectionData *SD = 0) - : MCFragment(FT_Inst, SD), Inst(_Inst) { + : MCEncodedFragment(FT_Inst, SD), Inst(_Inst) { } - /// @name Accessors - /// @{ - - SmallVectorImpl<char> &getCode() { return Code; } - const SmallVectorImpl<char> &getCode() const { return Code; } + SmallString<32> &getContents() { return Contents; } + const SmallString<32> &getContents() const { return Contents; } - unsigned getInstSize() const { return Code.size(); } + unsigned getInstSize() const { return Contents.size(); } const MCInst &getInst() const { return Inst; } void setInst(const MCInst& Value) { Inst = Value; } - /// @} - /// @name Fixup Access - /// @{ + SmallVectorImpl<MCFixup> &getFixups() { + return Fixups; + } - SmallVectorImpl<MCFixup> &getFixups() { return Fixups; } - const SmallVectorImpl<MCFixup> &getFixups() const { return Fixups; } + const SmallVectorImpl<MCFixup> &getFixups() const { + return Fixups; + } fixup_iterator fixup_begin() { return Fixups.begin(); } const_fixup_iterator fixup_begin() const { return Fixups.begin(); } @@ -195,8 +202,6 @@ public: fixup_iterator fixup_end() {return Fixups.end();} const_fixup_iterator fixup_end() const {return Fixups.end();} - /// @} - static bool classof(const MCFragment *F) { return F->getKind() == MCFragment::FT_Inst; } |