• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- lib/MC/MCLoggingStreamer.cpp - API Logging Streamer ----------------===//
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 #include "llvm/MC/MCStreamer.h"
11 #include "llvm/ADT/OwningPtr.h"
12 #include "llvm/ADT/Twine.h"
13 #include "llvm/Support/raw_ostream.h"
14 using namespace llvm;
15 
16 namespace {
17 
18 class MCLoggingStreamer : public MCStreamer {
19   llvm::OwningPtr<MCStreamer> Child;
20 
21   raw_ostream &OS;
22 
23 public:
MCLoggingStreamer(MCStreamer * _Child,raw_ostream & _OS)24   MCLoggingStreamer(MCStreamer *_Child, raw_ostream &_OS)
25     : MCStreamer(_Child->getContext()), Child(_Child), OS(_OS) {}
26 
LogCall(const char * Function)27   void LogCall(const char *Function) {
28     OS << Function << "\n";
29   }
30 
LogCall(const char * Function,const Twine & Message)31   void LogCall(const char *Function, const Twine &Message) {
32     OS << Function << ": " << Message << "\n";
33   }
34 
isVerboseAsm() const35   virtual bool isVerboseAsm() const { return Child->isVerboseAsm(); }
36 
hasRawTextSupport() const37   virtual bool hasRawTextSupport() const { return Child->hasRawTextSupport(); }
38 
GetCommentOS()39   virtual raw_ostream &GetCommentOS() { return Child->GetCommentOS(); }
40 
AddComment(const Twine & T)41   virtual void AddComment(const Twine &T) {
42     LogCall("AddComment", T);
43     return Child->AddComment(T);
44   }
45 
AddBlankLine()46   virtual void AddBlankLine() {
47     LogCall("AddBlankLine");
48     return Child->AddBlankLine();
49   }
50 
ChangeSection(const MCSection * Section)51   virtual void ChangeSection(const MCSection *Section) {
52     LogCall("ChangeSection");
53     return Child->ChangeSection(Section);
54   }
55 
InitSections()56   virtual void InitSections() {
57     LogCall("InitSections");
58     return Child->InitSections();
59   }
60 
EmitLabel(MCSymbol * Symbol)61   virtual void EmitLabel(MCSymbol *Symbol) {
62     LogCall("EmitLabel");
63     return Child->EmitLabel(Symbol);
64   }
65 
EmitAssemblerFlag(MCAssemblerFlag Flag)66   virtual void EmitAssemblerFlag(MCAssemblerFlag Flag) {
67     LogCall("EmitAssemblerFlag");
68     return Child->EmitAssemblerFlag(Flag);
69   }
70 
EmitThumbFunc(MCSymbol * Func)71   virtual void EmitThumbFunc(MCSymbol *Func) {
72     LogCall("EmitThumbFunc");
73     return Child->EmitThumbFunc(Func);
74   }
75 
EmitAssignment(MCSymbol * Symbol,const MCExpr * Value)76   virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
77     LogCall("EmitAssignment");
78     return Child->EmitAssignment(Symbol, Value);
79   }
80 
EmitWeakReference(MCSymbol * Alias,const MCSymbol * Symbol)81   virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {
82     LogCall("EmitWeakReference");
83     return Child->EmitWeakReference(Alias, Symbol);
84   }
85 
EmitDwarfAdvanceLineAddr(int64_t LineDelta,const MCSymbol * LastLabel,const MCSymbol * Label,unsigned PointerSize)86   virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta,
87                                         const MCSymbol *LastLabel,
88                                         const MCSymbol *Label,
89                                         unsigned PointerSize) {
90     LogCall("EmitDwarfAdvanceLineAddr");
91     return Child->EmitDwarfAdvanceLineAddr(LineDelta, LastLabel, Label,
92                                            PointerSize);
93   }
94 
EmitSymbolAttribute(MCSymbol * Symbol,MCSymbolAttr Attribute)95   virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) {
96     LogCall("EmitSymbolAttribute");
97     return Child->EmitSymbolAttribute(Symbol, Attribute);
98   }
99 
EmitSymbolDesc(MCSymbol * Symbol,unsigned DescValue)100   virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
101     LogCall("EmitSymbolDesc");
102     return Child->EmitSymbolDesc(Symbol, DescValue);
103   }
104 
BeginCOFFSymbolDef(const MCSymbol * Symbol)105   virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol) {
106     LogCall("BeginCOFFSymbolDef");
107     return Child->BeginCOFFSymbolDef(Symbol);
108   }
109 
EmitCOFFSymbolStorageClass(int StorageClass)110   virtual void EmitCOFFSymbolStorageClass(int StorageClass) {
111     LogCall("EmitCOFFSymbolStorageClass");
112     return Child->EmitCOFFSymbolStorageClass(StorageClass);
113   }
114 
EmitCOFFSymbolType(int Type)115   virtual void EmitCOFFSymbolType(int Type) {
116     LogCall("EmitCOFFSymbolType");
117     return Child->EmitCOFFSymbolType(Type);
118   }
119 
EndCOFFSymbolDef()120   virtual void EndCOFFSymbolDef() {
121     LogCall("EndCOFFSymbolDef");
122     return Child->EndCOFFSymbolDef();
123   }
124 
EmitELFSize(MCSymbol * Symbol,const MCExpr * Value)125   virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
126     LogCall("EmitELFSize");
127     return Child->EmitELFSize(Symbol, Value);
128   }
129 
EmitCommonSymbol(MCSymbol * Symbol,uint64_t Size,unsigned ByteAlignment)130   virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
131                                 unsigned ByteAlignment) {
132     LogCall("EmitCommonSymbol");
133     return Child->EmitCommonSymbol(Symbol, Size, ByteAlignment);
134   }
135 
EmitLocalCommonSymbol(MCSymbol * Symbol,uint64_t Size,unsigned ByteAlignment)136   virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
137                                      unsigned ByteAlignment) {
138     LogCall("EmitLocalCommonSymbol");
139     return Child->EmitLocalCommonSymbol(Symbol, Size, ByteAlignment);
140   }
141 
EmitZerofill(const MCSection * Section,MCSymbol * Symbol=0,unsigned Size=0,unsigned ByteAlignment=0)142   virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
143                             unsigned Size = 0, unsigned ByteAlignment = 0) {
144     LogCall("EmitZerofill");
145     return Child->EmitZerofill(Section, Symbol, Size, ByteAlignment);
146   }
147 
EmitTBSSSymbol(const MCSection * Section,MCSymbol * Symbol,uint64_t Size,unsigned ByteAlignment=0)148   virtual void EmitTBSSSymbol (const MCSection *Section, MCSymbol *Symbol,
149                                uint64_t Size, unsigned ByteAlignment = 0) {
150     LogCall("EmitTBSSSymbol");
151     return Child->EmitTBSSSymbol(Section, Symbol, Size, ByteAlignment);
152   }
153 
EmitBytes(StringRef Data,unsigned AddrSpace)154   virtual void EmitBytes(StringRef Data, unsigned AddrSpace) {
155     LogCall("EmitBytes");
156     return Child->EmitBytes(Data, AddrSpace);
157   }
158 
EmitValueImpl(const MCExpr * Value,unsigned Size,unsigned AddrSpace)159   virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
160                              unsigned AddrSpace){
161     LogCall("EmitValue");
162     return Child->EmitValueImpl(Value, Size, AddrSpace);
163   }
164 
EmitULEB128Value(const MCExpr * Value)165   virtual void EmitULEB128Value(const MCExpr *Value) {
166     LogCall("EmitULEB128Value");
167     return Child->EmitULEB128Value(Value);
168   }
169 
EmitSLEB128Value(const MCExpr * Value)170   virtual void EmitSLEB128Value(const MCExpr *Value) {
171     LogCall("EmitSLEB128Value");
172     return Child->EmitSLEB128Value(Value);
173   }
174 
EmitGPRel32Value(const MCExpr * Value)175   virtual void EmitGPRel32Value(const MCExpr *Value) {
176     LogCall("EmitGPRel32Value");
177     return Child->EmitGPRel32Value(Value);
178   }
179 
EmitFill(uint64_t NumBytes,uint8_t FillValue,unsigned AddrSpace)180   virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue,
181                         unsigned AddrSpace) {
182     LogCall("EmitFill");
183     return Child->EmitFill(NumBytes, FillValue, AddrSpace);
184   }
185 
EmitValueToAlignment(unsigned ByteAlignment,int64_t Value=0,unsigned ValueSize=1,unsigned MaxBytesToEmit=0)186   virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
187                                     unsigned ValueSize = 1,
188                                     unsigned MaxBytesToEmit = 0) {
189     LogCall("EmitValueToAlignment");
190     return Child->EmitValueToAlignment(ByteAlignment, Value,
191                                        ValueSize, MaxBytesToEmit);
192   }
193 
EmitCodeAlignment(unsigned ByteAlignment,unsigned MaxBytesToEmit=0)194   virtual void EmitCodeAlignment(unsigned ByteAlignment,
195                                  unsigned MaxBytesToEmit = 0) {
196     LogCall("EmitCodeAlignment");
197     return Child->EmitCodeAlignment(ByteAlignment, MaxBytesToEmit);
198   }
199 
EmitValueToOffset(const MCExpr * Offset,unsigned char Value=0)200   virtual void EmitValueToOffset(const MCExpr *Offset,
201                                  unsigned char Value = 0) {
202     LogCall("EmitValueToOffset");
203     return Child->EmitValueToOffset(Offset, Value);
204   }
205 
EmitFileDirective(StringRef Filename)206   virtual void EmitFileDirective(StringRef Filename) {
207     LogCall("EmitFileDirective", "FileName:" + Filename);
208     return Child->EmitFileDirective(Filename);
209   }
210 
EmitDwarfFileDirective(unsigned FileNo,StringRef Filename)211   virtual bool EmitDwarfFileDirective(unsigned FileNo, StringRef Filename) {
212     LogCall("EmitDwarfFileDirective",
213             "FileNo:" + Twine(FileNo) + " Filename:" + Filename);
214     return Child->EmitDwarfFileDirective(FileNo, Filename);
215   }
216 
EmitDwarfLocDirective(unsigned FileNo,unsigned Line,unsigned Column,unsigned Flags,unsigned Isa,unsigned Discriminator,StringRef FileName)217   virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
218                                      unsigned Column, unsigned Flags,
219                                      unsigned Isa, unsigned Discriminator,
220                                      StringRef FileName) {
221     LogCall("EmitDwarfLocDirective",
222             "FileNo:" + Twine(FileNo) + " Line:" + Twine(Line) +
223             " Column:" + Twine(Column) + " Flags:" + Twine(Flags) +
224             " Isa:" + Twine(Isa) + " Discriminator:" + Twine(Discriminator));
225             return Child->EmitDwarfLocDirective(FileNo, Line, Column, Flags,
226                                                 Isa, Discriminator, FileName);
227   }
228 
EmitInstruction(const MCInst & Inst)229   virtual void EmitInstruction(const MCInst &Inst) {
230     LogCall("EmitInstruction");
231     return Child->EmitInstruction(Inst);
232   }
233 
EmitRawText(StringRef String)234   virtual void EmitRawText(StringRef String) {
235     LogCall("EmitRawText", "\"" + String + "\"");
236     return Child->EmitRawText(String);
237   }
238 
Finish()239   virtual void Finish() {
240     LogCall("Finish");
241     return Child->Finish();
242   }
243 
244 };
245 
246 } // end anonymous namespace.
247 
createLoggingStreamer(MCStreamer * Child,raw_ostream & OS)248 MCStreamer *llvm::createLoggingStreamer(MCStreamer *Child, raw_ostream &OS) {
249   return new MCLoggingStreamer(Child, OS);
250 }
251