xref: /freebsd/contrib/llvm-project/llvm/lib/MC/MCSectionXCOFF.cpp (revision 8bcb0991864975618c09697b1aca10683346d9f0)
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*8bcb0991SDimitry Andric static StringRef getMappingClassString(XCOFF::StorageMappingClass SMC) {
19*8bcb0991SDimitry Andric   switch (SMC) {
20*8bcb0991SDimitry Andric   case XCOFF::XMC_DS:
21*8bcb0991SDimitry Andric     return "DS";
22*8bcb0991SDimitry Andric   case XCOFF::XMC_RW:
23*8bcb0991SDimitry Andric     return "RW";
24*8bcb0991SDimitry Andric   case XCOFF::XMC_PR:
25*8bcb0991SDimitry Andric     return "PR";
26*8bcb0991SDimitry Andric   default:
27*8bcb0991SDimitry Andric     report_fatal_error("Unhandled storage-mapping class.");
28*8bcb0991SDimitry Andric   }
29*8bcb0991SDimitry Andric }
30*8bcb0991SDimitry Andric 
310b57cec5SDimitry Andric void MCSectionXCOFF::PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
320b57cec5SDimitry Andric                                           raw_ostream &OS,
330b57cec5SDimitry Andric                                           const MCExpr *Subsection) const {
340b57cec5SDimitry Andric   if (getKind().isText()) {
35*8bcb0991SDimitry Andric     if (getMappingClass() != XCOFF::XMC_PR)
36*8bcb0991SDimitry Andric       report_fatal_error("Unhandled storage-mapping class for .text csect");
37*8bcb0991SDimitry Andric 
380b57cec5SDimitry Andric     OS << "\t.csect " << getSectionName() << "["
39*8bcb0991SDimitry Andric        << getMappingClassString(getMappingClass())
400b57cec5SDimitry Andric        << "]" << '\n';
410b57cec5SDimitry Andric     return;
420b57cec5SDimitry Andric   }
430b57cec5SDimitry Andric 
44*8bcb0991SDimitry Andric   if (getKind().isData()) {
45*8bcb0991SDimitry Andric     switch (getMappingClass()) {
46*8bcb0991SDimitry Andric     case XCOFF::XMC_RW:
47*8bcb0991SDimitry Andric     case XCOFF::XMC_DS:
48*8bcb0991SDimitry Andric       OS << "\t.csect " << getSectionName() << "["
49*8bcb0991SDimitry Andric          << getMappingClassString(getMappingClass()) << "]" << '\n';
50*8bcb0991SDimitry Andric       break;
51*8bcb0991SDimitry Andric     case XCOFF::XMC_TC0:
52*8bcb0991SDimitry Andric       OS << "\t.toc\n";
53*8bcb0991SDimitry Andric       break;
54*8bcb0991SDimitry Andric     default:
55*8bcb0991SDimitry Andric       report_fatal_error(
56*8bcb0991SDimitry Andric           "Unhandled storage-mapping class for .data csect.");
57*8bcb0991SDimitry Andric     }
58*8bcb0991SDimitry Andric     return;
59*8bcb0991SDimitry Andric   }
60*8bcb0991SDimitry Andric 
61*8bcb0991SDimitry Andric   if (getKind().isBSSLocal() || getKind().isCommon()) {
62*8bcb0991SDimitry Andric     assert((getMappingClass() == XCOFF::XMC_RW ||
63*8bcb0991SDimitry Andric             getMappingClass() == XCOFF::XMC_BS) &&
64*8bcb0991SDimitry Andric            "Generated a storage-mapping class for a common/bss csect we don't "
65*8bcb0991SDimitry Andric            "understand how to switch to.");
66*8bcb0991SDimitry Andric     assert(getCSectType() == XCOFF::XTY_CM &&
67*8bcb0991SDimitry Andric            "wrong csect type for .bss csect");
68*8bcb0991SDimitry Andric     // Don't have to print a directive for switching to section for commons.
69*8bcb0991SDimitry Andric     // '.comm' and '.lcomm' directives for the variable will create the needed
70*8bcb0991SDimitry Andric     // csect.
71*8bcb0991SDimitry Andric     return;
72*8bcb0991SDimitry Andric   }
73*8bcb0991SDimitry Andric 
740b57cec5SDimitry Andric   report_fatal_error("Printing for this SectionKind is unimplemented.");
750b57cec5SDimitry Andric }
760b57cec5SDimitry Andric 
770b57cec5SDimitry Andric bool MCSectionXCOFF::UseCodeAlign() const { return getKind().isText(); }
780b57cec5SDimitry Andric 
79*8bcb0991SDimitry Andric bool MCSectionXCOFF::isVirtualSection() const { return XCOFF::XTY_CM == Type; }
80