ca902f6594435d1644f1e398ce7f61717ac5d116
[oota-llvm.git] / include / llvm / MC / MCSection.h
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/ADT/StringRef.h"
18 #include "llvm/MC/SectionKind.h"
19 #include "llvm/Support/Compiler.h"
20
21 namespace llvm {
22 class MCAsmInfo;
23 class MCContext;
24 class MCExpr;
25 class MCSymbol;
26 class raw_ostream;
27
28 /// Instances of this class represent a uniqued identifier for a section in the
29 /// current translation unit.  The MCContext class uniques and creates these.
30 class MCSection {
31 public:
32   enum SectionVariant { SV_COFF = 0, SV_ELF, SV_MachO };
33
34 private:
35   MCSection(const MCSection &) = delete;
36   void operator=(const MCSection &) = delete;
37
38   MCSymbol *Begin;
39   MCSymbol *End = nullptr;
40   /// The alignment requirement of this section.
41   unsigned Alignment = 1;
42   /// The section index in the assemblers section list.
43   unsigned Ordinal = ~UINT32_C(0);
44
45 protected:
46   MCSection(SectionVariant V, SectionKind K, MCSymbol *Begin)
47       : Begin(Begin), Variant(V), Kind(K) {}
48   SectionVariant Variant;
49   SectionKind Kind;
50
51 public:
52   virtual ~MCSection();
53
54   SectionKind getKind() const { return Kind; }
55
56   SectionVariant getVariant() const { return Variant; }
57
58   MCSymbol *getBeginSymbol() { return Begin; }
59   const MCSymbol *getBeginSymbol() const {
60     return const_cast<MCSection *>(this)->getBeginSymbol();
61   }
62   void setBeginSymbol(MCSymbol *Sym) {
63     assert(!Begin);
64     Begin = Sym;
65   }
66   MCSymbol *getEndSymbol(MCContext &Ctx);
67   bool hasEnded() const;
68
69   unsigned getAlignment() const { return Alignment; }
70   void setAlignment(unsigned Value) { Alignment = Value; }
71
72   unsigned getOrdinal() const { return Ordinal; }
73   void setOrdinal(unsigned Value) { Ordinal = Value; }
74
75   virtual void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS,
76                                     const MCExpr *Subsection) const = 0;
77
78   /// Return true if a .align directive should use "optimized nops" to fill
79   /// instead of 0s.
80   virtual bool UseCodeAlign() const = 0;
81
82   /// Check whether this section is "virtual", that is has no actual object
83   /// file contents.
84   virtual bool isVirtualSection() const = 0;
85 };
86
87 } // end namespace llvm
88
89 #endif