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 18*5ffd83dbSDimitry Andric void MCSectionXCOFF::printCsectDirective(raw_ostream &OS) const { 19*5ffd83dbSDimitry Andric OS << "\t.csect " << QualName->getName() << "," << Log2_32(getAlignment()) 20*5ffd83dbSDimitry Andric << '\n'; 21*5ffd83dbSDimitry 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 30*5ffd83dbSDimitry 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."); 37*5ffd83dbSDimitry 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: 45*5ffd83dbSDimitry Andric printCsectDirective(OS); 46480093f4SDimitry Andric break; 47480093f4SDimitry Andric case XCOFF::XMC_TC: 488bcb0991SDimitry Andric break; 498bcb0991SDimitry Andric case XCOFF::XMC_TC0: 508bcb0991SDimitry Andric OS << "\t.toc\n"; 518bcb0991SDimitry Andric break; 528bcb0991SDimitry Andric default: 538bcb0991SDimitry Andric report_fatal_error( 548bcb0991SDimitry Andric "Unhandled storage-mapping class for .data csect."); 558bcb0991SDimitry Andric } 568bcb0991SDimitry Andric return; 578bcb0991SDimitry Andric } 588bcb0991SDimitry Andric 598bcb0991SDimitry Andric if (getKind().isBSSLocal() || getKind().isCommon()) { 608bcb0991SDimitry Andric assert((getMappingClass() == XCOFF::XMC_RW || 618bcb0991SDimitry Andric getMappingClass() == XCOFF::XMC_BS) && 628bcb0991SDimitry Andric "Generated a storage-mapping class for a common/bss csect we don't " 638bcb0991SDimitry Andric "understand how to switch to."); 648bcb0991SDimitry Andric assert(getCSectType() == XCOFF::XTY_CM && 658bcb0991SDimitry Andric "wrong csect type for .bss csect"); 668bcb0991SDimitry Andric // Don't have to print a directive for switching to section for commons. 678bcb0991SDimitry Andric // '.comm' and '.lcomm' directives for the variable will create the needed 688bcb0991SDimitry Andric // csect. 698bcb0991SDimitry Andric return; 708bcb0991SDimitry Andric } 718bcb0991SDimitry Andric 720b57cec5SDimitry Andric report_fatal_error("Printing for this SectionKind is unimplemented."); 730b57cec5SDimitry Andric } 740b57cec5SDimitry Andric 750b57cec5SDimitry Andric bool MCSectionXCOFF::UseCodeAlign() const { return getKind().isText(); } 760b57cec5SDimitry Andric 778bcb0991SDimitry Andric bool MCSectionXCOFF::isVirtualSection() const { return XCOFF::XTY_CM == Type; } 78