LLVM  5.0.0
RecordStreamer.h
Go to the documentation of this file.
1 //===- RecordStreamer.h - Record asm defined and used symbols ---*- C++ -*-===//
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 #ifndef LLVM_LIB_OBJECT_RECORDSTREAMER_H
11 #define LLVM_LIB_OBJECT_RECORDSTREAMER_H
12 
13 #include "llvm/ADT/DenseMap.h"
14 #include "llvm/ADT/StringMap.h"
15 #include "llvm/MC/MCDirectives.h"
16 #include "llvm/MC/MCStreamer.h"
17 #include "llvm/MC/MCSymbol.h"
18 #include "llvm/Support/SMLoc.h"
19 #include <vector>
20 
21 namespace llvm {
22 
23 class RecordStreamer : public MCStreamer {
24 public:
27 
28 private:
29  StringMap<State> Symbols;
30  // Map of aliases created by .symver directives, saved so we can update
31  // their symbol binding after parsing complete. This maps from each
32  // aliasee to its list of aliases.
34 
35  void markDefined(const MCSymbol &Symbol);
36  void markGlobal(const MCSymbol &Symbol, MCSymbolAttr Attribute);
37  void markUsed(const MCSymbol &Symbol);
38  void visitUsedSymbol(const MCSymbol &Sym) override;
39 
40 public:
41  RecordStreamer(MCContext &Context);
42 
44 
47  void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI,
48  bool) override;
49  void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
50  void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
51  bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
52  void EmitZerofill(MCSection *Section, MCSymbol *Symbol, uint64_t Size,
53  unsigned ByteAlignment) override;
54  void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
55  unsigned ByteAlignment) override;
56  /// Record .symver aliases for later processing.
57  void emitELFSymverDirective(MCSymbol *Alias,
58  const MCSymbol *Aliasee) override;
59  /// Return the map of .symver aliasee to associated aliases.
61  return SymverAliasMap;
62  }
63 
64  /// Get the state recorded for the given symbol.
66  auto SI = Symbols.find(Sym->getName());
67  if (SI == Symbols.end())
68  return NeverSeen;
69  return SI->second;
70  }
71 };
72 
73 } // end namespace llvm
74 
75 #endif // LLVM_LIB_OBJECT_RECORDSTREAMER_H
void emitELFSymverDirective(MCSymbol *Alias, const MCSymbol *Aliasee) override
Record .symver aliases for later processing.
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
void EmitZerofill(MCSection *Section, MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) override
Emit the zerofill section and an optional symbol.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override
Add the given Attribute to Symbol.
void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) override
Emit an assignment of Value to Symbol.
iterator find(StringRef Key)
Definition: StringMap.h:333
StringMap< State >::const_iterator const_iterator
const_iterator end()
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:36
Context object for machine code objects.
Definition: MCContext.h:59
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:159
Streaming machine code generation interface.
Definition: MCStreamer.h:167
RecordStreamer(MCContext &Context)
void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI, bool) override
Emit the given Instruction into the current section.
State getSymbolState(const MCSymbol *Sym)
Get the state recorded for the given symbol.
MCSymbolAttr
Definition: MCDirectives.h:19
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
DenseMap< const MCSymbol *, std::vector< MCSymbol * > > & symverAliases()
Return the map of .symver aliasee to associated aliases.
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:203
MCSubtargetInfo - Generic base class for all target subtargets.
void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) override
Emit a common symbol.
void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
LLVM Value Representation.
Definition: Value.h:73
Represents a location in source code.
Definition: SMLoc.h:24
const_iterator begin()
iterator end()
Definition: StringMap.h:318