1 //=====- NVPTXTargetStreamer.cpp - NVPTXTargetStreamer class ------------=====//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the NVPTXTargetStreamer class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "NVPTXTargetStreamer.h"
15 #include "llvm/MC/MCAsmInfo.h"
16 #include "llvm/MC/MCContext.h"
17 #include "llvm/MC/MCObjectFileInfo.h"
18
19 using namespace llvm;
20
21 //
22 // NVPTXTargetStreamer Implemenation
23 //
NVPTXTargetStreamer(MCStreamer & S)24 NVPTXTargetStreamer::NVPTXTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {}
25
26 NVPTXTargetStreamer::~NVPTXTargetStreamer() = default;
27
emitDwarfFileDirective(StringRef Directive)28 void NVPTXTargetStreamer::emitDwarfFileDirective(StringRef Directive) {
29 DwarfFiles.emplace_back(Directive);
30 }
31
isDwarfSection(const MCObjectFileInfo * FI,const MCSection * Section)32 static bool isDwarfSection(const MCObjectFileInfo *FI,
33 const MCSection *Section) {
34 // FIXME: the checks for the DWARF sections are very fragile and should be
35 // fixed up in a followup patch.
36 if (!Section || Section->getKind().isText() ||
37 Section->getKind().isWriteable())
38 return false;
39 return Section == FI->getDwarfAbbrevSection() ||
40 Section == FI->getDwarfInfoSection() ||
41 Section == FI->getDwarfMacinfoSection() ||
42 Section == FI->getDwarfFrameSection() ||
43 Section == FI->getDwarfAddrSection() ||
44 Section == FI->getDwarfRangesSection() ||
45 Section == FI->getDwarfARangesSection() ||
46 Section == FI->getDwarfLocSection() ||
47 Section == FI->getDwarfStrSection() ||
48 Section == FI->getDwarfLineSection() ||
49 Section == FI->getDwarfStrOffSection() ||
50 Section == FI->getDwarfLineStrSection() ||
51 Section == FI->getDwarfPubNamesSection() ||
52 Section == FI->getDwarfPubTypesSection() ||
53 Section == FI->getDwarfSwiftASTSection() ||
54 Section == FI->getDwarfTypesDWOSection() ||
55 Section == FI->getDwarfAbbrevDWOSection() ||
56 Section == FI->getDwarfAccelObjCSection() ||
57 Section == FI->getDwarfAccelNamesSection() ||
58 Section == FI->getDwarfAccelTypesSection() ||
59 Section == FI->getDwarfAccelNamespaceSection() ||
60 Section == FI->getDwarfLocDWOSection() ||
61 Section == FI->getDwarfStrDWOSection() ||
62 Section == FI->getDwarfCUIndexSection() ||
63 Section == FI->getDwarfInfoDWOSection() ||
64 Section == FI->getDwarfLineDWOSection() ||
65 Section == FI->getDwarfTUIndexSection() ||
66 Section == FI->getDwarfStrOffDWOSection() ||
67 Section == FI->getDwarfDebugNamesSection() ||
68 Section == FI->getDwarfDebugInlineSection() ||
69 Section == FI->getDwarfGnuPubNamesSection() ||
70 Section == FI->getDwarfGnuPubTypesSection();
71 }
72
changeSection(const MCSection * CurSection,MCSection * Section,const MCExpr * SubSection,raw_ostream & OS)73 void NVPTXTargetStreamer::changeSection(const MCSection *CurSection,
74 MCSection *Section,
75 const MCExpr *SubSection,
76 raw_ostream &OS) {
77 assert(!SubSection && "SubSection is not null!");
78 const MCObjectFileInfo *FI = getStreamer().getContext().getObjectFileInfo();
79 // FIXME: remove comment once debug info is properly supported.
80 // Emit closing brace for DWARF sections only.
81 if (isDwarfSection(FI, CurSection))
82 OS << "//\t}\n";
83 if (isDwarfSection(FI, Section)) {
84 // Emit DWARF .file directives in the outermost scope.
85 for (const std::string &S : DwarfFiles)
86 getStreamer().EmitRawText(S.data());
87 DwarfFiles.clear();
88 OS << "//\t.section";
89 Section->PrintSwitchToSection(*getStreamer().getContext().getAsmInfo(),
90 FI->getTargetTriple(), OS, SubSection);
91 // DWARF sections are enclosed into braces - emit the open one.
92 OS << "//\t{\n";
93 }
94 }
95