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"
26 class RecordStreamer
: public MCStreamer
{
28 enum State
{ NeverSeen
, Global
, Defined
, DefinedGlobal
, DefinedWeak
, Used
,
33 StringMap
<State
> Symbols
;
34 // Map of aliases created by .symver directives, saved so we can update
35 // their symbol binding after parsing complete. This maps from each
36 // aliasee to its list of aliases.
37 DenseMap
<const MCSymbol
*, std::vector
<StringRef
>> SymverAliasMap
;
39 /// Get the state recorded for the given symbol.
40 State
getSymbolState(const MCSymbol
*Sym
);
42 void markDefined(const MCSymbol
&Symbol
);
43 void markGlobal(const MCSymbol
&Symbol
, MCSymbolAttr Attribute
);
44 void markUsed(const MCSymbol
&Symbol
);
45 void visitUsedSymbol(const MCSymbol
&Sym
) override
;
48 RecordStreamer(MCContext
&Context
, const Module
&M
);
50 void EmitInstruction(const MCInst
&Inst
, const MCSubtargetInfo
&STI
,
52 void EmitLabel(MCSymbol
*Symbol
, SMLoc Loc
= SMLoc()) override
;
53 void EmitAssignment(MCSymbol
*Symbol
, const MCExpr
*Value
) override
;
54 bool EmitSymbolAttribute(MCSymbol
*Symbol
, MCSymbolAttr Attribute
) override
;
55 void EmitZerofill(MCSection
*Section
, MCSymbol
*Symbol
, uint64_t Size
,
56 unsigned ByteAlignment
, SMLoc Loc
= SMLoc()) override
;
57 void EmitCommonSymbol(MCSymbol
*Symbol
, uint64_t Size
,
58 unsigned ByteAlignment
) override
;
59 /// Record .symver aliases for later processing.
60 void emitELFSymverDirective(StringRef AliasName
,
61 const MCSymbol
*Aliasee
) override
;
63 // Emit ELF .symver aliases and ensure they have the same binding as the
64 // defined symbol they alias with.
65 void flushSymverDirectives();
68 using const_iterator
= StringMap
<State
>::const_iterator
;
69 const_iterator
begin();
72 // SymverAliasMap iterators
73 using const_symver_iterator
= decltype(SymverAliasMap
)::const_iterator
;
74 iterator_range
<const_symver_iterator
> symverAliases();
77 } // end namespace llvm
79 #endif // LLVM_LIB_OBJECT_RECORDSTREAMER_H