| Sean Fertile | f09d54e | 2019-07-09 19:21:01 +0000 | [diff] [blame] | 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 | void MCSectionXCOFF::PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T, |
| 19 | raw_ostream &OS, |
| 20 | const MCExpr *Subsection) const { |
| 21 | if (getKind().isText()) { |
| Sean Fertile | 942537d | 2019-07-22 19:15:29 +0000 | [diff] [blame] | 22 | if (getMappingClass() != XCOFF::XMC_PR) |
| 23 | llvm_unreachable("Unsupported storage-mapping class for .text csect"); |
| 24 | |
| Sean Fertile | f09d54e | 2019-07-09 19:21:01 +0000 | [diff] [blame] | 25 | OS << "\t.csect " << getSectionName() << "[" |
| 26 | << "PR" |
| 27 | << "]" << '\n'; |
| 28 | return; |
| 29 | } |
| 30 | |
| Xing Xue | ef039a3 | 2019-08-25 15:17:25 +0000 | [diff] [blame] | 31 | if (getKind().isData()) { |
| 32 | assert(getMappingClass() == XCOFF::XMC_RW && |
| 33 | "Unhandled storage-mapping class for data section."); |
| 34 | |
| 35 | OS << "\t.csect " << getSectionName() << "[" |
| 36 | << "RW" |
| 37 | << "]" << '\n'; |
| 38 | return; |
| 39 | } |
| 40 | |
| David Tenty | 8558aac | 2019-08-08 15:40:35 +0000 | [diff] [blame] | 41 | if (getKind().isBSSLocal() || getKind().isCommon()) { |
| David Tenty | 9bf01e5 | 2019-08-13 17:04:51 +0000 | [diff] [blame] | 42 | assert((getMappingClass() == XCOFF::XMC_RW || |
| 43 | getMappingClass() == XCOFF::XMC_BS) && |
| 44 | "Generated a storage-mapping class for a common/bss csect we don't " |
| 45 | "understand how to switch to."); |
| 46 | assert(getCSectType() == XCOFF::XTY_CM && |
| 47 | "wrong csect type for .bss csect"); |
| Sean Fertile | 942537d | 2019-07-22 19:15:29 +0000 | [diff] [blame] | 48 | // Don't have to print a directive for switching to section for commons. |
| 49 | // '.comm' and '.lcomm' directives for the variable will create the needed |
| 50 | // csect. |
| 51 | return; |
| 52 | } |
| 53 | |
| Sean Fertile | f09d54e | 2019-07-09 19:21:01 +0000 | [diff] [blame] | 54 | report_fatal_error("Printing for this SectionKind is unimplemented."); |
| 55 | } |
| 56 | |
| 57 | bool MCSectionXCOFF::UseCodeAlign() const { return getKind().isText(); } |
| 58 | |
| Sean Fertile | 942537d | 2019-07-22 19:15:29 +0000 | [diff] [blame] | 59 | bool MCSectionXCOFF::isVirtualSection() const { return XCOFF::XTY_CM == Type; } |