]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Object/RecordStreamer.h
Merge libc++ trunk r300890, and update build glue.
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Object / RecordStreamer.h
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/MC/MCStreamer.h"
14
15 namespace llvm {
16 class RecordStreamer : public MCStreamer {
17 public:
18   enum State { NeverSeen, Global, Defined, DefinedGlobal, DefinedWeak, Used,
19                UndefinedWeak};
20
21 private:
22   StringMap<State> Symbols;
23   // Map of aliases created by .symver directives, saved so we can update
24   // their symbol binding after parsing complete. This maps from each
25   // aliasee to its list of aliases.
26   DenseMap<const MCSymbol *, std::vector<MCSymbol *>> SymverAliasMap;
27   void markDefined(const MCSymbol &Symbol);
28   void markGlobal(const MCSymbol &Symbol, MCSymbolAttr Attribute);
29   void markUsed(const MCSymbol &Symbol);
30   void visitUsedSymbol(const MCSymbol &Sym) override;
31
32 public:
33   typedef StringMap<State>::const_iterator const_iterator;
34   const_iterator begin();
35   const_iterator end();
36   RecordStreamer(MCContext &Context);
37   void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI,
38                        bool) override;
39   void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
40   void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
41   bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
42   void EmitZerofill(MCSection *Section, MCSymbol *Symbol, uint64_t Size,
43                     unsigned ByteAlignment) override;
44   void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
45                         unsigned ByteAlignment) override;
46   /// Record .symver aliases for later processing.
47   void emitELFSymverDirective(MCSymbol *Alias,
48                               const MCSymbol *Aliasee) override;
49   /// Return the map of .symver aliasee to associated aliases.
50   DenseMap<const MCSymbol *, std::vector<MCSymbol *>> &symverAliases() {
51     return SymverAliasMap;
52   }
53   /// Get the state recorded for the given symbol.
54   State getSymbolState(const MCSymbol *Sym) {
55     auto SI = Symbols.find(Sym->getName());
56     if (SI == Symbols.end())
57       return NeverSeen;
58     return SI->second;
59   }
60 };
61 }
62 #endif