1 //=====- NVPTXTargetStreamer.cpp - NVPTXTargetStreamer class ------------=====//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the NVPTXTargetStreamer class.
12 //===----------------------------------------------------------------------===//
14 #include "NVPTXTargetStreamer.h"
15 #include "llvm/MC/MCAsmInfo.h"
16 #include "llvm/MC/MCContext.h"
17 #include "llvm/MC/MCObjectFileInfo.h"
22 // NVPTXTargetStreamer Implemenation
24 NVPTXTargetStreamer::NVPTXTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {}
26 NVPTXTargetStreamer::~NVPTXTargetStreamer() = default;
28 void NVPTXTargetStreamer::outputDwarfFileDirectives() {
29 for (const std::string &S : DwarfFiles)
30 getStreamer().EmitRawText(S.data());
34 void NVPTXTargetStreamer::emitDwarfFileDirective(StringRef Directive) {
35 DwarfFiles.emplace_back(Directive);
38 static bool isDwarfSection(const MCObjectFileInfo *FI,
39 const MCSection *Section) {
40 // FIXME: the checks for the DWARF sections are very fragile and should be
41 // fixed up in a followup patch.
42 if (!Section || Section->getKind().isText() ||
43 Section->getKind().isWriteable())
45 return Section == FI->getDwarfAbbrevSection() ||
46 Section == FI->getDwarfInfoSection() ||
47 Section == FI->getDwarfMacinfoSection() ||
48 Section == FI->getDwarfFrameSection() ||
49 Section == FI->getDwarfAddrSection() ||
50 Section == FI->getDwarfRangesSection() ||
51 Section == FI->getDwarfARangesSection() ||
52 Section == FI->getDwarfLocSection() ||
53 Section == FI->getDwarfStrSection() ||
54 Section == FI->getDwarfLineSection() ||
55 Section == FI->getDwarfStrOffSection() ||
56 Section == FI->getDwarfLineStrSection() ||
57 Section == FI->getDwarfPubNamesSection() ||
58 Section == FI->getDwarfPubTypesSection() ||
59 Section == FI->getDwarfSwiftASTSection() ||
60 Section == FI->getDwarfTypesDWOSection() ||
61 Section == FI->getDwarfAbbrevDWOSection() ||
62 Section == FI->getDwarfAccelObjCSection() ||
63 Section == FI->getDwarfAccelNamesSection() ||
64 Section == FI->getDwarfAccelTypesSection() ||
65 Section == FI->getDwarfAccelNamespaceSection() ||
66 Section == FI->getDwarfLocDWOSection() ||
67 Section == FI->getDwarfStrDWOSection() ||
68 Section == FI->getDwarfCUIndexSection() ||
69 Section == FI->getDwarfInfoDWOSection() ||
70 Section == FI->getDwarfLineDWOSection() ||
71 Section == FI->getDwarfTUIndexSection() ||
72 Section == FI->getDwarfStrOffDWOSection() ||
73 Section == FI->getDwarfDebugNamesSection() ||
74 Section == FI->getDwarfDebugInlineSection() ||
75 Section == FI->getDwarfGnuPubNamesSection() ||
76 Section == FI->getDwarfGnuPubTypesSection();
79 void NVPTXTargetStreamer::changeSection(const MCSection *CurSection,
81 const MCExpr *SubSection,
83 assert(!SubSection && "SubSection is not null!");
84 const MCObjectFileInfo *FI = getStreamer().getContext().getObjectFileInfo();
85 // FIXME: remove comment once debug info is properly supported.
86 // Emit closing brace for DWARF sections only.
87 if (isDwarfSection(FI, CurSection))
89 if (isDwarfSection(FI, Section)) {
90 // Emit DWARF .file directives in the outermost scope.
91 outputDwarfFileDirectives();
93 Section->PrintSwitchToSection(*getStreamer().getContext().getAsmInfo(),
94 FI->getTargetTriple(), OS, SubSection);
95 // DWARF sections are enclosed into braces - emit the open one.
100 void NVPTXTargetStreamer::emitRawBytes(StringRef Data) {
101 const MCAsmInfo *MAI = Streamer.getContext().getAsmInfo();
102 const char *Directive = MAI->getData8bitsDirective();
103 unsigned NumElements = Data.size();
104 const unsigned MaxLen = 40;
105 unsigned NumChunks = 1 + ((NumElements - 1) / MaxLen);
106 // Split the very long directives into several parts if the limit is
108 for (unsigned I = 0; I < NumChunks; ++I) {
109 SmallString<128> Str;
110 raw_svector_ostream OS(Str);
112 const char *Label = Directive;
113 for (auto It = std::next(Data.bytes_begin(), I * MaxLen),
114 End = (I == NumChunks - 1)
116 : std::next(Data.bytes_begin(), (I + 1) * MaxLen);
118 OS << Label << (unsigned)*It;
119 if (Label == Directive)
122 Streamer.EmitRawText(OS.str());