MCSection.h revision f1d0f7781e766df878bec4e7977fa3204374f394
1//===- MCSection.h - Machine Code Sections ----------------------*- 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// This file declares the MCSection class.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_MC_MCSECTION_H
15#define LLVM_MC_MCSECTION_H
16
17#include "llvm/MC/SectionKind.h"
18#include "llvm/Support/Casting.h"
19
20namespace llvm {
21  class MCAsmInfo;
22  class raw_ostream;
23
24  /// MCSection - Instances of this class represent a uniqued identifier for a
25  /// section in the current translation unit.  The MCContext class uniques and
26  /// creates these.
27  class MCSection {
28  public:
29    enum SectionVariant {
30      SV_COFF = 0,
31      SV_ELF,
32      SV_MachO
33    };
34
35  private:
36    MCSection(const MCSection&);      // DO NOT IMPLEMENT
37    void operator=(const MCSection&); // DO NOT IMPLEMENT
38  protected:
39    MCSection(SectionVariant V, SectionKind K) : Variant(V), Kind(K) {}
40    SectionVariant Variant;
41    SectionKind Kind;
42  public:
43    virtual ~MCSection();
44
45    SectionKind getKind() const { return Kind; }
46
47    SectionVariant getVariant() const { return Variant; }
48
49    virtual void PrintSwitchToSection(const MCAsmInfo &MAI,
50                                      raw_ostream &OS) const = 0;
51
52    /// isBaseAddressKnownZero - Return true if we know that this section will
53    /// get a base address of zero.  In cases where we know that this is true we
54    /// can emit section offsets as direct references to avoid a subtraction
55    /// from the base of the section, saving a relocation.
56    virtual bool isBaseAddressKnownZero() const {
57      return false;
58    }
59
60    // UseCodeAlign - Return true if a .align directive should use
61    // "optimized nops" to fill instead of 0s.
62    virtual bool UseCodeAlign() const = 0;
63
64    /// isVirtualSection - Check whether this section is "virtual", that is
65    /// has no actual object file contents.
66    virtual bool isVirtualSection() const = 0;
67
68    static bool classof(const MCSection *) { return true; }
69  };
70
71} // end namespace llvm
72
73#endif
74