MCSectionCOFF.h revision 263508
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/ADT/StringRef.h" 18#include "llvm/MC/MCSection.h" 19#include "llvm/Support/COFF.h" 20 21namespace llvm { 22class MCSymbol; 23 24/// MCSectionCOFF - This represents a section on Windows 25 class MCSectionCOFF : public MCSection { 26 // The memory for this string is stored in the same MCContext as *this. 27 StringRef SectionName; 28 29 // FIXME: The following fields should not be mutable, but are for now so 30 // the asm parser can honor the .linkonce directive. 31 32 /// Characteristics - This is the Characteristics field of a section, 33 /// drawn from the enums below. 34 mutable unsigned Characteristics; 35 36 /// The COMDAT symbol of this section. Only valid if this is a COMDAT 37 /// section. Two COMDAT sections are merged if they have the same 38 /// COMDAT symbol. 39 const MCSymbol *COMDATSymbol; 40 41 /// Selection - This is the Selection field for the section symbol, if 42 /// it is a COMDAT section (Characteristics & IMAGE_SCN_LNK_COMDAT) != 0 43 mutable int Selection; 44 45 /// Assoc - This is name of the associated section, if it is a COMDAT 46 /// section (Characteristics & IMAGE_SCN_LNK_COMDAT) != 0 with an 47 /// associative Selection (IMAGE_COMDAT_SELECT_ASSOCIATIVE). 48 mutable const MCSectionCOFF *Assoc; 49 50 private: 51 friend class MCContext; 52 MCSectionCOFF(StringRef Section, unsigned Characteristics, 53 const MCSymbol *COMDATSymbol, int Selection, 54 const MCSectionCOFF *Assoc, SectionKind K) 55 : MCSection(SV_COFF, K), SectionName(Section), 56 Characteristics(Characteristics), COMDATSymbol(COMDATSymbol), 57 Selection(Selection), Assoc(Assoc) { 58 assert ((Characteristics & 0x00F00000) == 0 && 59 "alignment must not be set upon section creation"); 60 assert ((Selection == COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE) == 61 (Assoc != 0) && 62 "associative COMDAT section must have an associated section"); 63 } 64 ~MCSectionCOFF(); 65 66 public: 67 /// ShouldOmitSectionDirective - Decides whether a '.section' directive 68 /// should be printed before the section name 69 bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const; 70 71 StringRef getSectionName() const { return SectionName; } 72 virtual std::string getLabelBeginName() const { 73 return SectionName.str() + "_begin"; 74 } 75 virtual std::string getLabelEndName() const { 76 return SectionName.str() + "_end"; 77 } 78 unsigned getCharacteristics() const { return Characteristics; } 79 int getSelection() const { return Selection; } 80 const MCSectionCOFF *getAssocSection() const { return Assoc; } 81 82 void setSelection(int Selection, const MCSectionCOFF *Assoc = 0) const; 83 84 virtual void PrintSwitchToSection(const MCAsmInfo &MAI, 85 raw_ostream &OS, 86 const MCExpr *Subsection) const; 87 virtual bool UseCodeAlign() const; 88 virtual bool isVirtualSection() const; 89 90 static bool classof(const MCSection *S) { 91 return S->getVariant() == SV_COFF; 92 } 93 }; 94 95} // end namespace llvm 96 97#endif 98