/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/lib/Object/RecordStreamer.h
Line | Count | Source (jump to first uncovered line) |
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: |
25 | | enum State { NeverSeen, Global, Defined, DefinedGlobal, DefinedWeak, Used, |
26 | | UndefinedWeak}; |
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. |
33 | | DenseMap<const MCSymbol *, std::vector<MCSymbol *>> SymverAliasMap; |
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 | | |
43 | | using const_iterator = StringMap<State>::const_iterator; |
44 | | |
45 | | const_iterator begin(); |
46 | | const_iterator end(); |
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. |
60 | 74 | DenseMap<const MCSymbol *, std::vector<MCSymbol *>> &symverAliases() { |
61 | 74 | return SymverAliasMap; |
62 | 74 | } |
63 | | |
64 | | /// Get the state recorded for the given symbol. |
65 | 49 | State getSymbolState(const MCSymbol *Sym) { |
66 | 49 | auto SI = Symbols.find(Sym->getName()); |
67 | 49 | if (SI == Symbols.end()) |
68 | 0 | return NeverSeen; |
69 | 49 | return SI->second; |
70 | 49 | } |
71 | | }; |
72 | | |
73 | | } // end namespace llvm |
74 | | |
75 | | #endif // LLVM_LIB_OBJECT_RECORDSTREAMER_H |