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