blob: a845ecd786a8e659bf1dd51aec47c086d7bb1019 [file] [log] [blame]
Rafael Espindola13b69d62014-07-03 18:59:23 +00001//===-- 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
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000010#ifndef LLVM_LIB_OBJECT_RECORDSTREAMER_H
11#define LLVM_LIB_OBJECT_RECORDSTREAMER_H
Rafael Espindola13b69d62014-07-03 18:59:23 +000012
13#include "llvm/MC/MCStreamer.h"
14
15namespace llvm {
16class RecordStreamer : public MCStreamer {
17public:
Davide Italianof7518492016-09-15 17:54:22 +000018 enum State { NeverSeen, Global, Defined, DefinedGlobal, DefinedWeak, Used,
19 UndefinedWeak};
Rafael Espindola13b69d62014-07-03 18:59:23 +000020
21private:
22 StringMap<State> Symbols;
Teresa Johnsond8204472017-03-09 00:19:49 +000023 // 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;
Rafael Espindola13b69d62014-07-03 18:59:23 +000027 void markDefined(const MCSymbol &Symbol);
Davide Italianoec7e29e2016-06-22 20:48:15 +000028 void markGlobal(const MCSymbol &Symbol, MCSymbolAttr Attribute);
Rafael Espindola13b69d62014-07-03 18:59:23 +000029 void markUsed(const MCSymbol &Symbol);
30 void visitUsedSymbol(const MCSymbol &Sym) override;
31
32public:
33 typedef StringMap<State>::const_iterator const_iterator;
34 const_iterator begin();
35 const_iterator end();
36 RecordStreamer(MCContext &Context);
Andrew V. Tischenko75745d02017-04-14 07:44:23 +000037 void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI,
38 bool) override;
Rafael Espindolabe991572017-02-10 15:13:12 +000039 void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
Rafael Espindola13b69d62014-07-03 18:59:23 +000040 void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
41 bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
Rafael Espindola0709a7b2015-05-21 19:20:38 +000042 void EmitZerofill(MCSection *Section, MCSymbol *Symbol, uint64_t Size,
Rafael Espindola13b69d62014-07-03 18:59:23 +000043 unsigned ByteAlignment) override;
44 void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
45 unsigned ByteAlignment) override;
Teresa Johnsond8204472017-03-09 00:19:49 +000046 /// 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 }
Rafael Espindola13b69d62014-07-03 18:59:23 +000060};
Alexander Kornienkof00654e2015-06-23 09:49:53 +000061}
Rafael Espindola13b69d62014-07-03 18:59:23 +000062#endif