#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/ilist.h"
#include "llvm/ADT/ilist_node.h"
-#include "llvm/MC/MCValue.h"
#include "llvm/Support/Casting.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
#include <vector> // FIXME: Shouldn't be needed.
namespace llvm {
class raw_ostream;
class MCAssembler;
+class MCContext;
+class MCExpr;
class MCSection;
class MCSectionData;
+class MCSymbol;
class MCFragment : public ilist_node<MCFragment> {
MCFragment(const MCFragment&); // DO NOT IMPLEMENT
FT_Data,
FT_Align,
FT_Fill,
- FT_Org
+ FT_Org,
+ FT_ZeroFill
};
private:
class MCFillFragment : public MCFragment {
/// Value - Value to use for filling bytes.
- MCValue Value;
+ const MCExpr *Value;
/// ValueSize - The size (in bytes) of \arg Value to use when filling.
unsigned ValueSize;
uint64_t Count;
public:
- MCFillFragment(MCValue _Value, unsigned _ValueSize, uint64_t _Count,
+ MCFillFragment(const MCExpr &_Value, unsigned _ValueSize, uint64_t _Count,
MCSectionData *SD = 0)
: MCFragment(FT_Fill, SD),
- Value(_Value), ValueSize(_ValueSize), Count(_Count) {}
+ Value(&_Value), ValueSize(_ValueSize), Count(_Count) {}
/// @name Accessors
/// @{
return ValueSize * Count;
}
- MCValue getValue() const { return Value; }
+ const MCExpr &getValue() const { return *Value; }
unsigned getValueSize() const { return ValueSize; }
class MCOrgFragment : public MCFragment {
/// Offset - The offset this fragment should start at.
- MCValue Offset;
+ const MCExpr *Offset;
/// Value - Value to use for filling bytes.
int8_t Value;
public:
- MCOrgFragment(MCValue _Offset, int8_t _Value, MCSectionData *SD = 0)
+ MCOrgFragment(const MCExpr &_Offset, int8_t _Value, MCSectionData *SD = 0)
: MCFragment(FT_Org, SD),
- Offset(_Offset), Value(_Value) {}
+ Offset(&_Offset), Value(_Value) {}
+
/// @name Accessors
/// @{
return ~UINT64_C(0);
}
- MCValue getOffset() const { return Offset; }
+ const MCExpr &getOffset() const { return *Offset; }
uint8_t getValue() const { return Value; }
static bool classof(const MCOrgFragment *) { return true; }
};
+/// MCZeroFillFragment - Represent data which has a fixed size and alignment,
+/// but requires no physical space in the object file.
+class MCZeroFillFragment : public MCFragment {
+ /// Size - The size of this fragment.
+ uint64_t Size;
+
+ /// Alignment - The alignment for this fragment.
+ unsigned Alignment;
+
+public:
+ MCZeroFillFragment(uint64_t _Size, unsigned _Alignment, MCSectionData *SD = 0)
+ : MCFragment(FT_ZeroFill, SD),
+ Size(_Size), Alignment(_Alignment) {}
+
+ /// @name Accessors
+ /// @{
+
+ uint64_t getMaxFileSize() const {
+ // FIXME: This also doesn't make much sense, this method is misnamed.
+ return ~UINT64_C(0);
+ }
+
+ uint64_t getSize() const { return Size; }
+
+ unsigned getAlignment() const { return Alignment; }
+
+ /// @}
+
+ static bool classof(const MCFragment *F) {
+ return F->getKind() == MCFragment::FT_ZeroFill;
+ }
+ static bool classof(const MCZeroFillFragment *) { return true; }
+};
+
// FIXME: Should this be a separate class, or just merged into MCSection? Since
// we anticipate the fast path being through an MCAssembler, the only reason to
// keep it out is for API abstraction.
uint64_t Offset;
/// Value - The expression to eventually write into the fragment.
- //
- // FIXME: We could probably get away with requiring the client to pass in an
- // owned reference whose lifetime extends past that of the fixup.
- MCValue Value;
+ const MCExpr *Value;
/// Size - The fixup size.
unsigned Size;
uint64_t FixedValue;
public:
- Fixup(MCFragment &_Fragment, uint64_t _Offset, const MCValue &_Value,
+ Fixup(MCFragment &_Fragment, uint64_t _Offset, const MCExpr &_Value,
unsigned _Size)
- : Fragment(&_Fragment), Offset(_Offset), Value(_Value), Size(_Size),
+ : Fragment(&_Fragment), Offset(_Offset), Value(&_Value), Size(_Size),
FixedValue(0) {}
};
// FIXME: Same concerns as with SectionData.
class MCSymbolData : public ilist_node<MCSymbolData> {
public:
- MCSymbol &Symbol;
+ const MCSymbol *Symbol;
/// Fragment - The fragment this symbol's value is relative to, if any.
MCFragment *Fragment;
/// IsPrivateExtern - True if this symbol is private extern.
unsigned IsPrivateExtern : 1;
+ /// CommonSize - The size of the symbol, if it is 'common', or 0.
+ //
+ // FIXME: Pack this in with other fields? We could put it in offset, since a
+ // common symbol can never get a definition.
+ uint64_t CommonSize;
+
+ /// CommonAlign - The alignment of the symbol, if it is 'common'.
+ //
+ // FIXME: Pack this in with other fields?
+ unsigned CommonAlign;
+
/// Flags - The Flags field is used by object file implementations to store
/// additional per symbol information which is not easily classified.
uint32_t Flags;
public:
// Only for use as sentinel.
MCSymbolData();
- MCSymbolData(MCSymbol &_Symbol, MCFragment *_Fragment, uint64_t _Offset,
+ MCSymbolData(const MCSymbol &_Symbol, MCFragment *_Fragment, uint64_t _Offset,
MCAssembler *A = 0);
/// @name Accessors
/// @{
- MCSymbol &getSymbol() const { return Symbol; }
+ const MCSymbol &getSymbol() const { return *Symbol; }
MCFragment *getFragment() const { return Fragment; }
void setFragment(MCFragment *Value) { Fragment = Value; }
bool isPrivateExtern() const { return IsPrivateExtern; }
void setPrivateExtern(bool Value) { IsPrivateExtern = Value; }
-
+
+ /// isCommon - Is this a 'common' symbol.
+ bool isCommon() const { return CommonSize != 0; }
+
+ /// setCommon - Mark this symbol as being 'common'.
+ ///
+ /// \param Size - The size of the symbol.
+ /// \param Align - The alignment of the symbol.
+ void setCommon(uint64_t Size, unsigned Align) {
+ CommonSize = Size;
+ CommonAlign = Align;
+ }
+
+ /// getCommonSize - Return the size of a 'common' symbol.
+ uint64_t getCommonSize() const {
+ assert(isCommon() && "Not a 'common' symbol!");
+ return CommonSize;
+ }
+
+ /// getCommonAlignment - Return the alignment of a 'common' symbol.
+ unsigned getCommonAlignment() const {
+ assert(isCommon() && "Not a 'common' symbol!");
+ return CommonAlign;
+ }
+
/// getFlags - Get the (implementation defined) symbol flags.
uint32_t getFlags() const { return Flags; }
MCAssembler(const MCAssembler&); // DO NOT IMPLEMENT
void operator=(const MCAssembler&); // DO NOT IMPLEMENT
+ MCContext &Context;
+
raw_ostream &OS;
iplist<MCSectionData> Sections;
/// LayoutSection - Assign offsets and sizes to the fragments in the section
/// \arg SD, and update the section size. The section file offset should
/// already have been computed.
- ///
- /// \param NextAlign - The alignment for the section end address, which may
- /// add padding bytes to the section (these are included in the section "file"
- /// size, but not its regular size).
- void LayoutSection(MCSectionData &SD, unsigned NextAlign);
+ void LayoutSection(MCSectionData &SD);
public:
/// Construct a new assembler instance.
// concrete and require clients to pass in a target like object. The other
// option is to make this abstract, and have targets provide concrete
// implementations as we do with AsmParser.
- MCAssembler(raw_ostream &OS);
+ MCAssembler(MCContext &_Context, raw_ostream &OS);
~MCAssembler();
+ MCContext &getContext() const { return Context; }
+
/// Finish - Do final processing and write the object to the output stream.
void Finish();