10b57cec5SDimitry Andric //===- lib/MC/MCSectionXCOFF.cpp - XCOFF Code Section Representation ------===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric 90b57cec5SDimitry Andric #include "llvm/MC/MCSectionXCOFF.h" 100b57cec5SDimitry Andric #include "llvm/MC/MCAsmInfo.h" 110b57cec5SDimitry Andric #include "llvm/MC/MCExpr.h" 120b57cec5SDimitry Andric #include "llvm/Support/raw_ostream.h" 130b57cec5SDimitry Andric 140b57cec5SDimitry Andric using namespace llvm; 150b57cec5SDimitry Andric 160b57cec5SDimitry Andric MCSectionXCOFF::~MCSectionXCOFF() = default; 170b57cec5SDimitry Andric 185ffd83dbSDimitry Andric void MCSectionXCOFF::printCsectDirective(raw_ostream &OS) const { 195ffd83dbSDimitry Andric OS << "\t.csect " << QualName->getName() << "," << Log2_32(getAlignment()) 205ffd83dbSDimitry Andric << '\n'; 215ffd83dbSDimitry Andric } 228bcb0991SDimitry Andric 230b57cec5SDimitry Andric void MCSectionXCOFF::PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T, 240b57cec5SDimitry Andric raw_ostream &OS, 250b57cec5SDimitry Andric const MCExpr *Subsection) const { 260b57cec5SDimitry Andric if (getKind().isText()) { 278bcb0991SDimitry Andric if (getMappingClass() != XCOFF::XMC_PR) 288bcb0991SDimitry Andric report_fatal_error("Unhandled storage-mapping class for .text csect"); 298bcb0991SDimitry Andric 305ffd83dbSDimitry Andric printCsectDirective(OS); 31480093f4SDimitry Andric return; 32480093f4SDimitry Andric } 33480093f4SDimitry Andric 34480093f4SDimitry Andric if (getKind().isReadOnly()) { 35480093f4SDimitry Andric if (getMappingClass() != XCOFF::XMC_RO) 36480093f4SDimitry Andric report_fatal_error("Unhandled storage-mapping class for .rodata csect."); 375ffd83dbSDimitry Andric printCsectDirective(OS); 380b57cec5SDimitry Andric return; 390b57cec5SDimitry Andric } 400b57cec5SDimitry Andric 418bcb0991SDimitry Andric if (getKind().isData()) { 428bcb0991SDimitry Andric switch (getMappingClass()) { 438bcb0991SDimitry Andric case XCOFF::XMC_RW: 448bcb0991SDimitry Andric case XCOFF::XMC_DS: 455ffd83dbSDimitry Andric printCsectDirective(OS); 46480093f4SDimitry Andric break; 47480093f4SDimitry Andric case XCOFF::XMC_TC: 48*e8d8bef9SDimitry Andric case XCOFF::XMC_TE: 498bcb0991SDimitry Andric break; 508bcb0991SDimitry Andric case XCOFF::XMC_TC0: 518bcb0991SDimitry Andric OS << "\t.toc\n"; 528bcb0991SDimitry Andric break; 538bcb0991SDimitry Andric default: 548bcb0991SDimitry Andric report_fatal_error( 558bcb0991SDimitry Andric "Unhandled storage-mapping class for .data csect."); 568bcb0991SDimitry Andric } 578bcb0991SDimitry Andric return; 588bcb0991SDimitry Andric } 598bcb0991SDimitry Andric 608bcb0991SDimitry Andric if (getKind().isBSSLocal() || getKind().isCommon()) { 618bcb0991SDimitry Andric assert((getMappingClass() == XCOFF::XMC_RW || 628bcb0991SDimitry Andric getMappingClass() == XCOFF::XMC_BS) && 638bcb0991SDimitry Andric "Generated a storage-mapping class for a common/bss csect we don't " 648bcb0991SDimitry Andric "understand how to switch to."); 658bcb0991SDimitry Andric assert(getCSectType() == XCOFF::XTY_CM && 668bcb0991SDimitry Andric "wrong csect type for .bss csect"); 678bcb0991SDimitry Andric // Don't have to print a directive for switching to section for commons. 688bcb0991SDimitry Andric // '.comm' and '.lcomm' directives for the variable will create the needed 698bcb0991SDimitry Andric // csect. 708bcb0991SDimitry Andric return; 718bcb0991SDimitry Andric } 728bcb0991SDimitry Andric 730b57cec5SDimitry Andric report_fatal_error("Printing for this SectionKind is unimplemented."); 740b57cec5SDimitry Andric } 750b57cec5SDimitry Andric 760b57cec5SDimitry Andric bool MCSectionXCOFF::UseCodeAlign() const { return getKind().isText(); } 770b57cec5SDimitry Andric 788bcb0991SDimitry Andric bool MCSectionXCOFF::isVirtualSection() const { return XCOFF::XTY_CM == Type; } 79