xref: /freebsd/contrib/llvm-project/llvm/lib/MC/MCSectionXCOFF.cpp (revision 480093f4440d54b30b3025afeac24b48f2ba7a2e)
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 
188bcb0991SDimitry Andric 
190b57cec5SDimitry Andric void MCSectionXCOFF::PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
200b57cec5SDimitry Andric                                           raw_ostream &OS,
210b57cec5SDimitry Andric                                           const MCExpr *Subsection) const {
220b57cec5SDimitry Andric   if (getKind().isText()) {
238bcb0991SDimitry Andric     if (getMappingClass() != XCOFF::XMC_PR)
248bcb0991SDimitry Andric       report_fatal_error("Unhandled storage-mapping class for .text csect");
258bcb0991SDimitry Andric 
26*480093f4SDimitry Andric     OS << "\t.csect " << QualName->getName() << '\n';
27*480093f4SDimitry Andric     return;
28*480093f4SDimitry Andric   }
29*480093f4SDimitry Andric 
30*480093f4SDimitry Andric   if (getKind().isReadOnly()) {
31*480093f4SDimitry Andric     if (getMappingClass() != XCOFF::XMC_RO)
32*480093f4SDimitry Andric       report_fatal_error("Unhandled storage-mapping class for .rodata csect.");
33*480093f4SDimitry Andric     OS << "\t.csect " << QualName->getName() << '\n';
340b57cec5SDimitry Andric     return;
350b57cec5SDimitry Andric   }
360b57cec5SDimitry Andric 
378bcb0991SDimitry Andric   if (getKind().isData()) {
388bcb0991SDimitry Andric     switch (getMappingClass()) {
398bcb0991SDimitry Andric     case XCOFF::XMC_RW:
408bcb0991SDimitry Andric     case XCOFF::XMC_DS:
41*480093f4SDimitry Andric       OS << "\t.csect " << QualName->getName() << '\n';
42*480093f4SDimitry Andric       break;
43*480093f4SDimitry Andric     case XCOFF::XMC_TC:
448bcb0991SDimitry Andric       break;
458bcb0991SDimitry Andric     case XCOFF::XMC_TC0:
468bcb0991SDimitry Andric       OS << "\t.toc\n";
478bcb0991SDimitry Andric       break;
488bcb0991SDimitry Andric     default:
498bcb0991SDimitry Andric       report_fatal_error(
508bcb0991SDimitry Andric           "Unhandled storage-mapping class for .data csect.");
518bcb0991SDimitry Andric     }
528bcb0991SDimitry Andric     return;
538bcb0991SDimitry Andric   }
548bcb0991SDimitry Andric 
558bcb0991SDimitry Andric   if (getKind().isBSSLocal() || getKind().isCommon()) {
568bcb0991SDimitry Andric     assert((getMappingClass() == XCOFF::XMC_RW ||
578bcb0991SDimitry Andric             getMappingClass() == XCOFF::XMC_BS) &&
588bcb0991SDimitry Andric            "Generated a storage-mapping class for a common/bss csect we don't "
598bcb0991SDimitry Andric            "understand how to switch to.");
608bcb0991SDimitry Andric     assert(getCSectType() == XCOFF::XTY_CM &&
618bcb0991SDimitry Andric            "wrong csect type for .bss csect");
628bcb0991SDimitry Andric     // Don't have to print a directive for switching to section for commons.
638bcb0991SDimitry Andric     // '.comm' and '.lcomm' directives for the variable will create the needed
648bcb0991SDimitry Andric     // csect.
658bcb0991SDimitry Andric     return;
668bcb0991SDimitry Andric   }
678bcb0991SDimitry Andric 
680b57cec5SDimitry Andric   report_fatal_error("Printing for this SectionKind is unimplemented.");
690b57cec5SDimitry Andric }
700b57cec5SDimitry Andric 
710b57cec5SDimitry Andric bool MCSectionXCOFF::UseCodeAlign() const { return getKind().isText(); }
720b57cec5SDimitry Andric 
738bcb0991SDimitry Andric bool MCSectionXCOFF::isVirtualSection() const { return XCOFF::XTY_CM == Type; }
74