blob: f646168d3a4a7de8b0d22535acfb0bb111a0a3a0 [file] [log] [blame]
Sean Fertilef09d54e2019-07-09 19:21:01 +00001//===- 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
14using namespace llvm;
15
16MCSectionXCOFF::~MCSectionXCOFF() = default;
17
Xiangling Liao3b808fb2019-09-26 19:38:32 +000018
Sean Fertilef09d54e2019-07-09 19:21:01 +000019void MCSectionXCOFF::PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
20 raw_ostream &OS,
21 const MCExpr *Subsection) const {
22 if (getKind().isText()) {
Sean Fertile942537d2019-07-22 19:15:29 +000023 if (getMappingClass() != XCOFF::XMC_PR)
Xiangling Liao3b808fb2019-09-26 19:38:32 +000024 report_fatal_error("Unhandled storage-mapping class for .text csect");
Sean Fertile942537d2019-07-22 19:15:29 +000025
Jason Liu0dc05722019-11-08 09:26:28 -050026 OS << "\t.csect " << QualName->getName() << '\n';
Sean Fertilef09d54e2019-07-09 19:21:01 +000027 return;
28 }
29
diggerlin3dfa9752019-11-15 11:30:19 -050030 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
Xing Xueef039a32019-08-25 15:17:25 +000037 if (getKind().isData()) {
Xiangling Liao3b808fb2019-09-26 19:38:32 +000038 switch (getMappingClass()) {
39 case XCOFF::XMC_RW:
40 case XCOFF::XMC_DS:
Jason Liu0dc05722019-11-08 09:26:28 -050041 OS << "\t.csect " << QualName->getName() << '\n';
Xiangling Liao3b808fb2019-09-26 19:38:32 +000042 break;
43 case XCOFF::XMC_TC0:
44 OS << "\t.toc\n";
45 break;
46 default:
47 report_fatal_error(
48 "Unhandled storage-mapping class for .data csect.");
49 }
Xing Xueef039a32019-08-25 15:17:25 +000050 return;
51 }
52
David Tenty8558aac2019-08-08 15:40:35 +000053 if (getKind().isBSSLocal() || getKind().isCommon()) {
David Tenty9bf01e52019-08-13 17:04:51 +000054 assert((getMappingClass() == XCOFF::XMC_RW ||
55 getMappingClass() == XCOFF::XMC_BS) &&
56 "Generated a storage-mapping class for a common/bss csect we don't "
57 "understand how to switch to.");
58 assert(getCSectType() == XCOFF::XTY_CM &&
59 "wrong csect type for .bss csect");
Sean Fertile942537d2019-07-22 19:15:29 +000060 // Don't have to print a directive for switching to section for commons.
61 // '.comm' and '.lcomm' directives for the variable will create the needed
62 // csect.
63 return;
64 }
65
Sean Fertilef09d54e2019-07-09 19:21:01 +000066 report_fatal_error("Printing for this SectionKind is unimplemented.");
67}
68
69bool MCSectionXCOFF::UseCodeAlign() const { return getKind().isText(); }
70
Sean Fertile942537d2019-07-22 19:15:29 +000071bool MCSectionXCOFF::isVirtualSection() const { return XCOFF::XTY_CM == Type; }