aboutsummaryrefslogtreecommitdiffstats
path: root/lib/MC/MCLoggingStreamer.cpp
blob: 3fe8ac72c8ec5a9ed34a4da816c6c896f8a025b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
//===- lib/MC/MCLoggingStreamer.cpp - API Logging Streamer ----------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "llvm/MC/MCStreamer.h"
#include "llvm/ADT/OwningPtr.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;

namespace {

class MCLoggingStreamer : public MCStreamer {
  llvm::OwningPtr<MCStreamer> Child;
  
  raw_ostream &OS;

public:
  MCLoggingStreamer(MCStreamer *_Child, raw_ostream &_OS)
    : MCStreamer(_Child->getContext()), Child(_Child), OS(_OS) {}

  void LogCall(const char *Function) {
    OS << Function << "\n";
  }

  void LogCall(const char *Function, const Twine &Message) {
    OS << Function << ": " << Message << "\n";
  }

  virtual bool isVerboseAsm() const { return Child->isVerboseAsm(); }
  
  virtual bool hasRawTextSupport() const { return Child->hasRawTextSupport(); }

  virtual raw_ostream &GetCommentOS() { return Child->GetCommentOS(); }

  virtual void AddComment(const Twine &T) {
    LogCall("AddComment", T);
    return Child->AddComment(T);
  }

  virtual void AddBlankLine() {
    LogCall("AddBlankLine");
    return Child->AddBlankLine();
  }

  virtual void ChangeSection(const MCSection *Section) {
    LogCall("ChangeSection");
    return Child->ChangeSection(Section);
  }

  virtual void InitSections() {
    LogCall("InitSections");
    return Child->InitSections();
  }

  virtual void EmitLabel(MCSymbol *Symbol) {
    LogCall("EmitLabel");
    return Child->EmitLabel(Symbol);
  }

  virtual void EmitAssemblerFlag(MCAssemblerFlag Flag) {
    LogCall("EmitAssemblerFlag");
    return Child->EmitAssemblerFlag(Flag);
  }

  virtual void EmitThumbFunc(MCSymbol *Func) {
    LogCall("EmitThumbFunc");
    return Child->EmitThumbFunc(Func);
  }

  virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
    LogCall("EmitAssignment");
    return Child->EmitAssignment(Symbol, Value);
  }

  virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {
    LogCall("EmitWeakReference");
    return Child->EmitWeakReference(Alias, Symbol);
  }

  virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta,
                                        const MCSymbol *LastLabel,
                                        const MCSymbol *Label,
                                        unsigned PointerSize) {
    LogCall("EmitDwarfAdvanceLineAddr");
    return Child->EmitDwarfAdvanceLineAddr(LineDelta, LastLabel, Label,
                                           PointerSize);
  }

  virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) {
    LogCall("EmitSymbolAttribute");
    return Child->EmitSymbolAttribute(Symbol, Attribute);
  }

  virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
    LogCall("EmitSymbolDesc");
    return Child->EmitSymbolDesc(Symbol, DescValue);
  }

  virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol) {
    LogCall("BeginCOFFSymbolDef");
    return Child->BeginCOFFSymbolDef(Symbol);
  }

  virtual void EmitCOFFSymbolStorageClass(int StorageClass) {
    LogCall("EmitCOFFSymbolStorageClass");
    return Child->EmitCOFFSymbolStorageClass(StorageClass);
  }

  virtual void EmitCOFFSymbolType(int Type) {
    LogCall("EmitCOFFSymbolType");
    return Child->EmitCOFFSymbolType(Type);
  }

  virtual void EndCOFFSymbolDef() {
    LogCall("EndCOFFSymbolDef");
    return Child->EndCOFFSymbolDef();
  }

  virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
    LogCall("EmitELFSize");
    return Child->EmitELFSize(Symbol, Value);
  }

  virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
                                unsigned ByteAlignment) {
    LogCall("EmitCommonSymbol");
    return Child->EmitCommonSymbol(Symbol, Size, ByteAlignment);
  }

  virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
                                     unsigned ByteAlignment) {
    LogCall("EmitLocalCommonSymbol");
    return Child->EmitLocalCommonSymbol(Symbol, Size, ByteAlignment);
  }
  
  virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
                            unsigned Size = 0, unsigned ByteAlignment = 0) {
    LogCall("EmitZerofill");
    return Child->EmitZerofill(Section, Symbol, Size, ByteAlignment);
  }

  virtual void EmitTBSSSymbol (const MCSection *Section, MCSymbol *Symbol,
                               uint64_t Size, unsigned ByteAlignment = 0) {
    LogCall("EmitTBSSSymbol");
    return Child->EmitTBSSSymbol(Section, Symbol, Size, ByteAlignment);
  }

  virtual void EmitBytes(StringRef Data, unsigned AddrSpace) {
    LogCall("EmitBytes");
    return Child->EmitBytes(Data, AddrSpace);
  }

  virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
                             unsigned AddrSpace){
    LogCall("EmitValue");
    return Child->EmitValueImpl(Value, Size, AddrSpace);
  }

  virtual void EmitULEB128Value(const MCExpr *Value) {
    LogCall("EmitULEB128Value");
    return Child->EmitULEB128Value(Value);
  }

  virtual void EmitSLEB128Value(const MCExpr *Value) {
    LogCall("EmitSLEB128Value");
    return Child->EmitSLEB128Value(Value);
  }

  virtual void EmitGPRel32Value(const MCExpr *Value) {
    LogCall("EmitGPRel32Value");
    return Child->EmitGPRel32Value(Value);
  }

  virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue,
                        unsigned AddrSpace) {
    LogCall("EmitFill");
    return Child->EmitFill(NumBytes, FillValue, AddrSpace);
  }

  virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
                                    unsigned ValueSize = 1,
                                    unsigned MaxBytesToEmit = 0) {
    LogCall("EmitValueToAlignment");
    return Child->EmitValueToAlignment(ByteAlignment, Value,
                                       ValueSize, MaxBytesToEmit);
  }

  virtual void EmitCodeAlignment(unsigned ByteAlignment,
                                 unsigned MaxBytesToEmit = 0) {
    LogCall("EmitCodeAlignment");
    return Child->EmitCodeAlignment(ByteAlignment, MaxBytesToEmit);
  }

  virtual void EmitValueToOffset(const MCExpr *Offset,
                                 unsigned char Value = 0) {
    LogCall("EmitValueToOffset");
    return Child->EmitValueToOffset(Offset, Value);
  }

  virtual void EmitFileDirective(StringRef Filename) {
    LogCall("EmitFileDirective", "FileName:" + Filename);
    return Child->EmitFileDirective(Filename);
  }

  virtual bool EmitDwarfFileDirective(unsigned FileNo, StringRef Filename) {
    LogCall("EmitDwarfFileDirective",
            "FileNo:" + Twine(FileNo) + " Filename:" + Filename);
    return Child->EmitDwarfFileDirective(FileNo, Filename);
  }

  virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
                                     unsigned Column, unsigned Flags,
                                     unsigned Isa, unsigned Discriminator,
                                     StringRef FileName) {
    LogCall("EmitDwarfLocDirective",
            "FileNo:" + Twine(FileNo) + " Line:" + Twine(Line) +
            " Column:" + Twine(Column) + " Flags:" + Twine(Flags) +
            " Isa:" + Twine(Isa) + " Discriminator:" + Twine(Discriminator));
            return Child->EmitDwarfLocDirective(FileNo, Line, Column, Flags,
                                                Isa, Discriminator, FileName);
  }

  virtual void EmitInstruction(const MCInst &Inst) {
    LogCall("EmitInstruction");
    return Child->EmitInstruction(Inst);
  }

  virtual void EmitRawText(StringRef String) {
    LogCall("EmitRawText", "\"" + String + "\"");
    return Child->EmitRawText(String);
  }

  virtual void Finish() {
    LogCall("Finish");
    return Child->Finish();
  }

};

} // end anonymous namespace.

MCStreamer *llvm::createLoggingStreamer(MCStreamer *Child, raw_ostream &OS) {
  return new MCLoggingStreamer(Child, OS);
}