Move LayoutOrder to MCSection.
[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 = 0;
44   /// The index of this section in the layout order.
45   unsigned LayoutOrder;
46
47 protected:
48   MCSection(SectionVariant V, SectionKind K, MCSymbol *Begin)
49       : Begin(Begin), Variant(V), Kind(K) {}
50   SectionVariant Variant;
51   SectionKind Kind;
52
53 public:
54   virtual ~MCSection();
55
56   SectionKind getKind() const { return Kind; }
57
58   SectionVariant getVariant() const { return Variant; }
59
60   MCSymbol *getBeginSymbol() { return Begin; }
61   const MCSymbol *getBeginSymbol() const {
62     return const_cast<MCSection *>(this)->getBeginSymbol();
63   }
64   void setBeginSymbol(MCSymbol *Sym) {
65     assert(!Begin);
66     Begin = Sym;
67   }
68   MCSymbol *getEndSymbol(MCContext &Ctx);
69   bool hasEnded() const;
70
71   unsigned getAlignment() const { return Alignment; }
72   void setAlignment(unsigned Value) { Alignment = Value; }
73
74   unsigned getOrdinal() const { return Ordinal; }
75   void setOrdinal(unsigned Value) { Ordinal = Value; }
76
77   unsigned getLayoutOrder() const { return LayoutOrder; }
78   void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
79
80   virtual void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS,
81                                     const MCExpr *Subsection) const = 0;
82
83   /// Return true if a .align directive should use "optimized nops" to fill
84   /// instead of 0s.
85   virtual bool UseCodeAlign() const = 0;
86
87   /// Check whether this section is "virtual", that is has no actual object
88   /// file contents.
89   virtual bool isVirtualSection() const = 0;
90 };
91
92 } // end namespace llvm
93
94 #endif