1 //===- RecordStreamer.h - Record asm defined and used symbols ---*- C++ -*-===//
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 #ifndef LLVM_LIB_OBJECT_RECORDSTREAMER_H
11 #define LLVM_LIB_OBJECT_RECORDSTREAMER_H
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"
23 class RecordStreamer : public MCStreamer {
25 enum State { NeverSeen, Global, Defined, DefinedGlobal, DefinedWeak, Used,
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.
33 DenseMap<const MCSymbol *, std::vector<MCSymbol *>> SymverAliasMap;
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;
41 RecordStreamer(MCContext &Context);
43 using const_iterator = StringMap<State>::const_iterator;
45 const_iterator begin();
47 void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI,
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.
60 DenseMap<const MCSymbol *, std::vector<MCSymbol *>> &symverAliases() {
61 return SymverAliasMap;
64 /// Get the state recorded for the given symbol.
65 State getSymbolState(const MCSymbol *Sym) {
66 auto SI = Symbols.find(Sym->getName());
67 if (SI == Symbols.end())
73 } // end namespace llvm
75 #endif // LLVM_LIB_OBJECT_RECORDSTREAMER_H