2010-03-11 03:28:59 +01:00
|
|
|
//===- MCAsmLayout.h - Assembly Layout Object -------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_MC_MCASMLAYOUT_H
|
|
|
|
#define LLVM_MC_MCASMLAYOUT_H
|
|
|
|
|
2011-11-14 18:45:03 +01:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2010-05-12 17:42:59 +02:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
|
2010-03-11 03:28:59 +01:00
|
|
|
namespace llvm {
|
|
|
|
class MCAssembler;
|
2010-03-24 04:43:40 +01:00
|
|
|
class MCFragment;
|
2015-05-26 04:00:36 +02:00
|
|
|
class MCSection;
|
2014-05-01 15:24:25 +02:00
|
|
|
class MCSymbol;
|
2010-03-11 03:28:59 +01:00
|
|
|
|
|
|
|
/// Encapsulates the layout of an assembly file at a particular point in time.
|
|
|
|
///
|
2012-12-10 21:13:43 +01:00
|
|
|
/// Assembly may require computing multiple layouts for a particular assembly
|
2010-03-11 03:28:59 +01:00
|
|
|
/// file as part of the relaxation process. This class encapsulates the layout
|
|
|
|
/// at a single point in time in such a way that it is always possible to
|
2012-12-10 21:13:43 +01:00
|
|
|
/// efficiently compute the exact address of any symbol in the assembly file,
|
2010-03-11 03:28:59 +01:00
|
|
|
/// even during the relaxation process.
|
|
|
|
class MCAsmLayout {
|
|
|
|
MCAssembler &Assembler;
|
|
|
|
|
2010-05-12 17:42:59 +02:00
|
|
|
/// List of sections in layout order.
|
2015-05-26 04:00:36 +02:00
|
|
|
llvm::SmallVector<MCSection *, 16> SectionOrder;
|
2010-05-12 17:42:59 +02:00
|
|
|
|
2011-04-15 07:18:47 +02:00
|
|
|
/// The last fragment which was laid out, or 0 if nothing has been laid
|
|
|
|
/// out. Fragments are always laid out in order, so all fragments with a
|
2012-12-12 20:54:05 +01:00
|
|
|
/// lower ordinal will be valid.
|
2015-05-26 04:00:36 +02:00
|
|
|
mutable DenseMap<const MCSection *, MCFragment *> LastValidFragment;
|
2010-05-14 02:37:21 +02:00
|
|
|
|
2010-05-14 02:51:14 +02:00
|
|
|
/// \brief Make sure that the layout for the given fragment is valid, lazily
|
|
|
|
/// computing it if necessary.
|
2012-12-12 20:54:05 +01:00
|
|
|
void ensureValid(const MCFragment *F) const;
|
2010-05-14 02:51:14 +02:00
|
|
|
|
2012-12-12 20:54:05 +01:00
|
|
|
/// \brief Is the layout for this fragment valid?
|
|
|
|
bool isFragmentValid(const MCFragment *F) const;
|
2010-05-14 02:37:21 +02:00
|
|
|
|
2010-03-11 03:28:59 +01:00
|
|
|
public:
|
2015-03-16 19:06:57 +01:00
|
|
|
MCAsmLayout(MCAssembler &Assembler);
|
2010-03-11 03:28:59 +01:00
|
|
|
|
|
|
|
/// Get the assembler object this is a layout for.
|
2010-03-12 22:00:45 +01:00
|
|
|
MCAssembler &getAssembler() const { return Assembler; }
|
2010-03-24 04:43:40 +01:00
|
|
|
|
2013-02-05 18:55:27 +01:00
|
|
|
/// \brief Invalidate the fragments starting with F because it has been
|
|
|
|
/// resized. The fragment's size should have already been updated, but
|
|
|
|
/// its bundle padding will be recomputed.
|
|
|
|
void invalidateFragmentsFrom(MCFragment *F);
|
2010-03-25 20:35:56 +01:00
|
|
|
|
2010-05-13 22:40:12 +02:00
|
|
|
/// \brief Perform layout for a single fragment, assuming that the previous
|
2011-04-15 07:18:47 +02:00
|
|
|
/// fragment has already been laid out correctly, and the parent section has
|
2010-05-13 22:40:12 +02:00
|
|
|
/// been initialized.
|
2012-12-12 20:54:05 +01:00
|
|
|
void layoutFragment(MCFragment *Fragment);
|
2010-05-13 22:40:12 +02:00
|
|
|
|
2015-05-02 02:44:14 +02:00
|
|
|
/// \name Section Access (in layout order)
|
2010-05-12 17:42:59 +02:00
|
|
|
/// @{
|
|
|
|
|
2015-05-26 04:00:36 +02:00
|
|
|
llvm::SmallVectorImpl<MCSection *> &getSectionOrder() { return SectionOrder; }
|
|
|
|
const llvm::SmallVectorImpl<MCSection *> &getSectionOrder() const {
|
2010-05-12 19:56:47 +02:00
|
|
|
return SectionOrder;
|
|
|
|
}
|
2010-05-12 17:42:59 +02:00
|
|
|
|
|
|
|
/// @}
|
2015-05-02 02:44:14 +02:00
|
|
|
/// \name Fragment Layout Data
|
2010-03-25 03:00:07 +01:00
|
|
|
/// @{
|
2010-03-24 04:43:40 +01:00
|
|
|
|
2010-03-25 03:00:07 +01:00
|
|
|
/// \brief Get the offset of the given fragment inside its containing section.
|
2010-03-25 03:00:02 +01:00
|
|
|
uint64_t getFragmentOffset(const MCFragment *F) const;
|
2010-03-25 03:00:07 +01:00
|
|
|
|
2010-05-13 05:19:50 +02:00
|
|
|
/// @}
|
2015-05-02 02:44:14 +02:00
|
|
|
/// \name Utility Functions
|
2010-05-13 05:19:50 +02:00
|
|
|
/// @{
|
2010-03-25 03:00:07 +01:00
|
|
|
|
2010-05-13 03:10:22 +02:00
|
|
|
/// \brief Get the address space size of the given section, as it effects
|
|
|
|
/// layout. This may differ from the size reported by \see getSectionSize() by
|
|
|
|
/// not including section tail padding.
|
2015-05-26 04:00:36 +02:00
|
|
|
uint64_t getSectionAddressSize(const MCSection *Sec) const;
|
2010-05-13 03:10:22 +02:00
|
|
|
|
2010-05-13 05:19:50 +02:00
|
|
|
/// \brief Get the data size of the given section, as emitted to the object
|
|
|
|
/// file. This may include additional padding, or be 0 for virtual sections.
|
2015-05-26 04:00:36 +02:00
|
|
|
uint64_t getSectionFileSize(const MCSection *Sec) const;
|
2010-05-13 03:10:22 +02:00
|
|
|
|
2010-12-06 03:57:26 +01:00
|
|
|
/// \brief Get the offset of the given symbol, as computed in the current
|
|
|
|
/// layout.
|
2015-05-02 02:44:14 +02:00
|
|
|
/// \return True on success.
|
2015-05-20 01:53:20 +02:00
|
|
|
bool getSymbolOffset(const MCSymbol &S, uint64_t &Val) const;
|
2014-04-30 23:51:13 +02:00
|
|
|
|
|
|
|
/// \brief Variant that reports a fatal error if the offset is not computable.
|
2015-05-20 01:53:20 +02:00
|
|
|
uint64_t getSymbolOffset(const MCSymbol &S) const;
|
2010-12-06 03:57:26 +01:00
|
|
|
|
2014-05-01 15:24:25 +02:00
|
|
|
/// \brief If this symbol is equivalent to A + Constant, return A.
|
|
|
|
const MCSymbol *getBaseSymbol(const MCSymbol &Symbol) const;
|
|
|
|
|
2010-03-25 03:00:07 +01:00
|
|
|
/// @}
|
2010-03-11 03:28:59 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|