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 18 19 void MCSectionXCOFF::PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T, 20 raw_ostream &OS, 21 const MCExpr *Subsection) const { 22 if (getKind().isText()) { 23 if (getMappingClass() != XCOFF::XMC_PR) 24 report_fatal_error("Unhandled storage-mapping class for .text csect"); 25 26 OS << "\t.csect " << QualName->getName() << '\n'; 27 return; 28 } 29 30 if (getKind().isData()) { 31 switch (getMappingClass()) { 32 case XCOFF::XMC_RW: 33 case XCOFF::XMC_DS: 34 OS << "\t.csect " << QualName->getName() << '\n'; 35 break; 36 case XCOFF::XMC_TC0: 37 OS << "\t.toc\n"; 38 break; 39 default: 40 report_fatal_error( 41 "Unhandled storage-mapping class for .data csect."); 42 } 43 return; 44 } 45 46 if (getKind().isBSSLocal() || getKind().isCommon()) { 47 assert((getMappingClass() == XCOFF::XMC_RW || 48 getMappingClass() == XCOFF::XMC_BS) && 49 "Generated a storage-mapping class for a common/bss csect we don't " 50 "understand how to switch to."); 51 assert(getCSectType() == XCOFF::XTY_CM && 52 "wrong csect type for .bss csect"); 53 // Don't have to print a directive for switching to section for commons. 54 // '.comm' and '.lcomm' directives for the variable will create the needed 55 // csect. 56 return; 57 } 58 59 report_fatal_error("Printing for this SectionKind is unimplemented."); 60 } 61 62 bool MCSectionXCOFF::UseCodeAlign() const { return getKind().isText(); } 63 64 bool MCSectionXCOFF::isVirtualSection() const { return XCOFF::XTY_CM == Type; } 65