MC: Add dyn_cast support to MCSection.
[oota-llvm.git] / include / llvm / MC / MCSectionCOFF.h
1 //===- MCSectionCOFF.h - COFF 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 MCSectionCOFF class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_MC_MCSECTIONCOFF_H
15 #define LLVM_MC_MCSECTIONCOFF_H
16
17 #include "llvm/MC/MCSection.h"
18
19 namespace llvm {
20   
21 /// MCSectionCOFF - This represents a section on Windows
22   class MCSectionCOFF : public MCSection {
23     // The memory for this string is stored in the same MCContext as *this.
24     StringRef SectionName;
25     
26     /// Characteristics - This is the Characteristics field of a section,
27     //  drawn from the enums below.
28     unsigned Characteristics;
29
30     /// Selection - This is the Selection field for the section symbol, if
31     /// it is a COMDAT section (Characteristics & IMAGE_SCN_LNK_COMDAT) != 0
32     int Selection;
33
34   private:
35     friend class MCContext;
36     MCSectionCOFF(StringRef Section, unsigned Characteristics,
37                   int Selection, SectionKind K)
38       : MCSection(SV_COFF, K), SectionName(Section),
39         Characteristics(Characteristics), Selection (Selection) {
40       assert ((Characteristics & 0x00F00000) == 0 &&
41         "alignment must not be set upon section creation");
42     }
43     ~MCSectionCOFF();
44
45   public:
46     /// ShouldOmitSectionDirective - Decides whether a '.section' directive
47     /// should be printed before the section name
48     bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
49
50     //FIXME: all COFF enumerations/flags should be standardized into one place...
51     // Target/X86COFF.h doesn't seem right as COFF can be used for other targets,
52     // MC/WinCOFF.h maybe right as it isn't target or entity specific, and it is
53     //   pretty low on the dependancy graph (is there any need to support non
54     //   windows COFF?)
55     // here is good for section stuff, but others should go elsewhere
56
57     /// Valid section flags.
58     enum {
59       IMAGE_SCN_TYPE_NO_PAD                     = 0x00000008,
60       IMAGE_SCN_CNT_CODE                        = 0x00000020,
61       IMAGE_SCN_CNT_INITIALIZED_DATA            = 0x00000040,
62       IMAGE_SCN_CNT_UNINITIALIZED_DATA          = 0x00000080,
63       IMAGE_SCN_LNK_OTHER                       = 0x00000100,
64       IMAGE_SCN_LNK_INFO                        = 0x00000200,
65       IMAGE_SCN_LNK_REMOVE                      = 0x00000800,
66       IMAGE_SCN_LNK_COMDAT                      = 0x00001000,
67       IMAGE_SCN_MEM_FARDATA                     = 0x00008000,
68       IMAGE_SCN_MEM_PURGEABLE                   = 0x00020000,
69       IMAGE_SCN_MEM_16BIT                       = 0x00020000,
70       IMAGE_SCN_MEM_LOCKED                      = 0x00040000,
71       IMAGE_SCN_MEM_PRELOAD                     = 0x00080000,
72       /* these are handled elsewhere
73       IMAGE_SCN_ALIGN_1BYTES                    = 0x00100000,
74       IMAGE_SCN_ALIGN_2BYTES                    = 0x00200000,
75       IMAGE_SCN_ALIGN_4BYTES                    = 0x00300000,
76       IMAGE_SCN_ALIGN_8BYTES                    = 0x00400000,
77       IMAGE_SCN_ALIGN_16BYTES                   = 0x00500000,
78       IMAGE_SCN_ALIGN_32BYTES                   = 0x00600000,
79       IMAGE_SCN_ALIGN_64BYTES                   = 0x00700000,
80       */
81       IMAGE_SCN_LNK_NRELOC_OVFL                 = 0x01000000,
82       IMAGE_SCN_MEM_DISCARDABLE                 = 0x02000000,
83       IMAGE_SCN_MEM_NOT_CACHED                  = 0x04000000,
84       IMAGE_SCN_MEM_NOT_PAGED                   = 0x08000000,
85       IMAGE_SCN_MEM_SHARED                      = 0x10000000,
86       IMAGE_SCN_MEM_EXECUTE                     = 0x20000000,
87       IMAGE_SCN_MEM_READ                        = 0x40000000,
88       IMAGE_SCN_MEM_WRITE                       = 0x80000000
89     };
90
91     enum {
92       IMAGE_COMDAT_SELECT_NODUPLICATES = 1,
93       IMAGE_COMDAT_SELECT_ANY,
94       IMAGE_COMDAT_SELECT_SAME_SIZE,
95       IMAGE_COMDAT_SELECT_EXACT_MATCH,
96       IMAGE_COMDAT_SELECT_ASSOCIATIVE,
97       IMAGE_COMDAT_SELECT_LARGEST
98     };
99
100     StringRef getSectionName() const { return SectionName; }
101     unsigned getCharacteristics() const { return Characteristics; }
102     int getSelection () const { return Selection; }
103     
104     virtual void PrintSwitchToSection(const MCAsmInfo &MAI,
105                                       raw_ostream &OS) const;
106
107     static bool classof(const MCSection *S) {
108       return S->getVariant() == SV_COFF;
109     }
110     static bool classof(const MCSectionCOFF *) { return true; }
111   };
112
113 } // end namespace llvm
114
115 #endif