1 //===- lib/MC/MCSectionXCOFF.cpp - XCOFF Code Section Representation ------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "llvm/MC/MCSectionXCOFF.h" 10 #include "llvm/MC/MCAsmInfo.h" 11 #include "llvm/MC/MCExpr.h" 12 #include "llvm/Support/raw_ostream.h" 13 14 using namespace llvm; 15 16 MCSectionXCOFF::~MCSectionXCOFF() = default; 17 printCsectDirective(raw_ostream & OS) const18void MCSectionXCOFF::printCsectDirective(raw_ostream &OS) const { 19 OS << "\t.csect " << QualName->getName() << "," << Log2_32(getAlignment()) 20 << '\n'; 21 } 22 PrintSwitchToSection(const MCAsmInfo & MAI,const Triple & T,raw_ostream & OS,const MCExpr * Subsection) const23void MCSectionXCOFF::PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T, 24 raw_ostream &OS, 25 const MCExpr *Subsection) const { 26 if (getKind().isText()) { 27 if (getMappingClass() != XCOFF::XMC_PR) 28 report_fatal_error("Unhandled storage-mapping class for .text csect"); 29 30 printCsectDirective(OS); 31 return; 32 } 33 34 if (getKind().isReadOnly()) { 35 if (getMappingClass() != XCOFF::XMC_RO) 36 report_fatal_error("Unhandled storage-mapping class for .rodata csect."); 37 printCsectDirective(OS); 38 return; 39 } 40 41 if (getKind().isData()) { 42 switch (getMappingClass()) { 43 case XCOFF::XMC_RW: 44 case XCOFF::XMC_DS: 45 printCsectDirective(OS); 46 break; 47 case XCOFF::XMC_TC: 48 case XCOFF::XMC_TE: 49 break; 50 case XCOFF::XMC_TC0: 51 OS << "\t.toc\n"; 52 break; 53 default: 54 report_fatal_error( 55 "Unhandled storage-mapping class for .data csect."); 56 } 57 return; 58 } 59 60 if (getKind().isBSSLocal() || getKind().isCommon()) { 61 assert((getMappingClass() == XCOFF::XMC_RW || 62 getMappingClass() == XCOFF::XMC_BS) && 63 "Generated a storage-mapping class for a common/bss csect we don't " 64 "understand how to switch to."); 65 assert(getCSectType() == XCOFF::XTY_CM && 66 "wrong csect type for .bss csect"); 67 // Don't have to print a directive for switching to section for commons. 68 // '.comm' and '.lcomm' directives for the variable will create the needed 69 // csect. 70 return; 71 } 72 73 report_fatal_error("Printing for this SectionKind is unimplemented."); 74 } 75 UseCodeAlign() const76bool MCSectionXCOFF::UseCodeAlign() const { return getKind().isText(); } 77 isVirtualSection() const78bool MCSectionXCOFF::isVirtualSection() const { return XCOFF::XTY_CM == Type; } 79