LLVM API Documentation
00001 //===- lib/MC/MCSectionCOFF.cpp - COFF Code Section Representation --------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 00010 #include "llvm/MC/MCSectionCOFF.h" 00011 #include "llvm/MC/MCAsmInfo.h" 00012 #include "llvm/MC/MCContext.h" 00013 #include "llvm/MC/MCSymbol.h" 00014 #include "llvm/Support/raw_ostream.h" 00015 using namespace llvm; 00016 00017 MCSectionCOFF::~MCSectionCOFF() {} // anchor. 00018 00019 // ShouldOmitSectionDirective - Decides whether a '.section' directive 00020 // should be printed before the section name 00021 bool MCSectionCOFF::ShouldOmitSectionDirective(StringRef Name, 00022 const MCAsmInfo &MAI) const { 00023 if (COMDATSymbol) 00024 return false; 00025 00026 // FIXME: Does .section .bss/.data/.text work everywhere?? 00027 if (Name == ".text" || Name == ".data" || Name == ".bss") 00028 return true; 00029 00030 return false; 00031 } 00032 00033 void MCSectionCOFF::setSelection(int Selection) const { 00034 assert(Selection != 0 && "invalid COMDAT selection type"); 00035 this->Selection = Selection; 00036 Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT; 00037 } 00038 00039 void MCSectionCOFF::PrintSwitchToSection(const MCAsmInfo &MAI, 00040 raw_ostream &OS, 00041 const MCExpr *Subsection) const { 00042 00043 // standard sections don't require the '.section' 00044 if (ShouldOmitSectionDirective(SectionName, MAI)) { 00045 OS << '\t' << getSectionName() << '\n'; 00046 return; 00047 } 00048 00049 OS << "\t.section\t" << getSectionName() << ",\""; 00050 if (getKind().isText()) 00051 OS << 'x'; 00052 else if (getKind().isBSS()) 00053 OS << 'b'; 00054 if (getKind().isWriteable()) 00055 OS << 'w'; 00056 else 00057 OS << 'r'; 00058 if (getCharacteristics() & COFF::IMAGE_SCN_MEM_DISCARDABLE) 00059 OS << 'n'; 00060 if (getCharacteristics() & COFF::IMAGE_SCN_CNT_INITIALIZED_DATA) 00061 OS << 'd'; 00062 OS << '"'; 00063 00064 if (getCharacteristics() & COFF::IMAGE_SCN_LNK_COMDAT) { 00065 OS << ","; 00066 switch (Selection) { 00067 case COFF::IMAGE_COMDAT_SELECT_NODUPLICATES: 00068 OS << "one_only,"; 00069 break; 00070 case COFF::IMAGE_COMDAT_SELECT_ANY: 00071 OS << "discard,"; 00072 break; 00073 case COFF::IMAGE_COMDAT_SELECT_SAME_SIZE: 00074 OS << "same_size,"; 00075 break; 00076 case COFF::IMAGE_COMDAT_SELECT_EXACT_MATCH: 00077 OS << "same_contents,"; 00078 break; 00079 case COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE: 00080 OS << "associative,"; 00081 break; 00082 case COFF::IMAGE_COMDAT_SELECT_LARGEST: 00083 OS << "largest,"; 00084 break; 00085 case COFF::IMAGE_COMDAT_SELECT_NEWEST: 00086 OS << "newest,"; 00087 break; 00088 default: 00089 assert (0 && "unsupported COFF selection type"); 00090 break; 00091 } 00092 assert(COMDATSymbol); 00093 OS << *COMDATSymbol; 00094 } 00095 OS << '\n'; 00096 } 00097 00098 bool MCSectionCOFF::UseCodeAlign() const { 00099 return getKind().isText(); 00100 } 00101 00102 bool MCSectionCOFF::isVirtualSection() const { 00103 return getCharacteristics() & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA; 00104 }