]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/llvm/lib/MC/MCSectionXCOFF.cpp
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm-project / llvm / lib / MC / MCSectionXCOFF.cpp
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().isReadOnly()) {
31     if (getMappingClass() != XCOFF::XMC_RO)
32       report_fatal_error("Unhandled storage-mapping class for .rodata csect.");
33     OS << "\t.csect " << QualName->getName() << '\n';
34     return;
35   }
36
37   if (getKind().isData()) {
38     switch (getMappingClass()) {
39     case XCOFF::XMC_RW:
40     case XCOFF::XMC_DS:
41       OS << "\t.csect " << QualName->getName() << '\n';
42       break;
43     case XCOFF::XMC_TC:
44       break;
45     case XCOFF::XMC_TC0:
46       OS << "\t.toc\n";
47       break;
48     default:
49       report_fatal_error(
50           "Unhandled storage-mapping class for .data csect.");
51     }
52     return;
53   }
54
55   if (getKind().isBSSLocal() || getKind().isCommon()) {
56     assert((getMappingClass() == XCOFF::XMC_RW ||
57             getMappingClass() == XCOFF::XMC_BS) &&
58            "Generated a storage-mapping class for a common/bss csect we don't "
59            "understand how to switch to.");
60     assert(getCSectType() == XCOFF::XTY_CM &&
61            "wrong csect type for .bss csect");
62     // Don't have to print a directive for switching to section for commons.
63     // '.comm' and '.lcomm' directives for the variable will create the needed
64     // csect.
65     return;
66   }
67
68   report_fatal_error("Printing for this SectionKind is unimplemented.");
69 }
70
71 bool MCSectionXCOFF::UseCodeAlign() const { return getKind().isText(); }
72
73 bool MCSectionXCOFF::isVirtualSection() const { return XCOFF::XTY_CM == Type; }