#ifndef LLVM_MC_MCASSEMBLER_H
#define LLVM_MC_MCASSEMBLER_H
+#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/ilist.h"
#include "llvm/ADT/ilist_node.h"
#include "llvm/Support/Casting.h"
+#include "llvm/MC/MCFixup.h"
#include "llvm/System/DataTypes.h"
#include <vector> // FIXME: Shouldn't be needed.
/// Value - The expression to eventually write into the fragment.
const MCExpr *Value;
- /// Size - The fixup size.
- unsigned Size;
+ /// Kind - The fixup kind.
+ MCFixupKind Kind;
/// FixedValue - The value to replace the fix up by.
//
uint64_t FixedValue;
public:
- MCAsmFixup(uint64_t _Offset, const MCExpr &_Value, unsigned _Size)
- : Offset(_Offset), Value(&_Value), Size(_Size), FixedValue(0) {}
+ MCAsmFixup(uint64_t _Offset, const MCExpr &_Value, MCFixupKind _Kind)
+ : Offset(_Offset), Value(&_Value), Kind(_Kind), FixedValue(0) {}
};
class MCFragment : public ilist_node<MCFragment> {
MCFragment(const MCFragment&); // DO NOT IMPLEMENT
void operator=(const MCFragment&); // DO NOT IMPLEMENT
-public:
- typedef std::vector<MCAsmFixup>::const_iterator const_fixup_iterator;
- typedef std::vector<MCAsmFixup>::iterator fixup_iterator;
-
public:
enum FragmentType {
FT_Data,
/// FileSize - The file size of this section. This is ~0 until initialized.
uint64_t FileSize;
- /// Fixups - The list of fixups in this fragment.
- //
- // FIXME: This should be sunk into MCDataFragment.
- std::vector<MCAsmFixup> Fixups;
-
/// @}
protected:
return 0;
}
- /// @name Fixup Access
- /// @{
-
- /// LookupFixup - Look up the fixup for the given \arg Fragment and \arg
- /// Offset.
- ///
- /// If multiple fixups exist for the same fragment and offset it is undefined
- /// which one is returned.
- //
- // FIXME: This isn't horribly slow in practice, but there are much nicer
- // solutions to applying the fixups. This will be fixed by sinking fixups into
- // data fragments exclusively.
- const MCAsmFixup *LookupFixup(uint64_t Offset) const {
- for (unsigned i = 0, e = Fixups.size(); i != e; ++i)
- if (Fixups[i].Offset == Offset)
- return &Fixups[i];
- return 0;
- }
-
- std::vector<MCAsmFixup> &getFixups() { return Fixups; }
- const std::vector<MCAsmFixup> &getFixups() const { return Fixups; }
-
- fixup_iterator fixup_begin() { return Fixups.begin(); }
- const_fixup_iterator fixup_begin() const { return Fixups.begin(); }
-
- fixup_iterator fixup_end() {return Fixups.end();}
- const_fixup_iterator fixup_end() const {return Fixups.end();}
-
- size_t fixup_size() const { return Fixups.size(); }
-
/// @name Assembler Backend Support
/// @{
//
class MCDataFragment : public MCFragment {
SmallString<32> Contents;
+ /// Fixups - The list of fixups in this fragment.
+ std::vector<MCAsmFixup> Fixups;
+
+public:
+ typedef std::vector<MCAsmFixup>::const_iterator const_fixup_iterator;
+ typedef std::vector<MCAsmFixup>::iterator fixup_iterator;
+
public:
MCDataFragment(MCSectionData *SD = 0) : MCFragment(FT_Data, SD) {}
/// @}
+ /// @name Fixup Access
+ /// @{
+
+ std::vector<MCAsmFixup> &getFixups() { return Fixups; }
+ const std::vector<MCAsmFixup> &getFixups() const { return Fixups; }
+
+ fixup_iterator fixup_begin() { return Fixups.begin(); }
+ const_fixup_iterator fixup_begin() const { return Fixups.begin(); }
+
+ fixup_iterator fixup_end() {return Fixups.end();}
+ const_fixup_iterator fixup_end() const {return Fixups.end();}
+
+ size_t fixup_size() const { return Fixups.size(); }
+
+ /// @}
+
static bool classof(const MCFragment *F) {
return F->getKind() == MCFragment::FT_Data;
}
/// cannot be satisfied in this width then this fragment is ignored.
unsigned MaxBytesToEmit;
+ /// EmitNops - true when aligning code and optimal nops to be used for filling
+ bool EmitNops;
+
public:
MCAlignFragment(unsigned _Alignment, int64_t _Value, unsigned _ValueSize,
- unsigned _MaxBytesToEmit, MCSectionData *SD = 0)
+ unsigned _MaxBytesToEmit, bool _EmitNops,
+ MCSectionData *SD = 0)
: MCFragment(FT_Align, SD), Alignment(_Alignment),
Value(_Value),ValueSize(_ValueSize),
- MaxBytesToEmit(_MaxBytesToEmit) {}
+ MaxBytesToEmit(_MaxBytesToEmit), EmitNops(_EmitNops) {}
/// @name Accessors
/// @{
unsigned getMaxBytesToEmit() const { return MaxBytesToEmit; }
+ unsigned getEmitNops() const { return EmitNops; }
+
/// @}
static bool classof(const MCFragment *F) {
iplist<MCSymbolData> Symbols;
+ /// The map of sections to their associated assembler backend data.
+ //
+ // FIXME: Avoid this indirection?
+ DenseMap<const MCSection*, MCSectionData*> SectionMap;
+
+ /// The map of symbols to their associated assembler backend data.
+ //
+ // FIXME: Avoid this indirection?
+ DenseMap<const MCSymbol*, MCSymbolData*> SymbolMap;
+
std::vector<IndirectSymbolData> IndirectSymbols;
unsigned SubsectionsViaSymbols : 1;
size_t indirect_symbol_size() const { return IndirectSymbols.size(); }
+ /// @}
+ /// @name Backend Data Access
+ /// @{
+
+ MCSectionData &getSectionData(const MCSection &Section) {
+ MCSectionData *&Entry = SectionMap[&Section];
+ assert(Entry && "Missing section data!");
+ return *Entry;
+ }
+
+ MCSectionData &getOrCreateSectionData(const MCSection &Section,
+ bool *Created = 0) {
+ MCSectionData *&Entry = SectionMap[&Section];
+
+ if (Created) *Created = !Entry;
+ if (!Entry)
+ Entry = new MCSectionData(Section, this);
+
+ return *Entry;
+ }
+
+ MCSymbolData &getSymbolData(const MCSymbol &Symbol) {
+ MCSymbolData *&Entry = SymbolMap[&Symbol];
+ assert(Entry && "Missing symbol data!");
+ return *Entry;
+ }
+
+ MCSymbolData &getOrCreateSymbolData(const MCSymbol &Symbol,
+ bool *Created = 0) {
+ MCSymbolData *&Entry = SymbolMap[&Symbol];
+
+ if (Created) *Created = !Entry;
+ if (!Entry)
+ Entry = new MCSymbolData(Symbol, 0, 0, this);
+
+ return *Entry;
+ }
+
/// @}
void dump();