1 //===-- RecordStreamer.cpp - Record asm defined and used symbols ----------===// 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 #include "RecordStreamer.h" 11 #include "llvm/MC/MCSymbol.h" 12 13 using namespace llvm; 14 15 void RecordStreamer::markDefined(const MCSymbol &Symbol) { 16 State &S = Symbols[Symbol.getName()]; 17 switch (S) { 18 case DefinedGlobal: 19 case Global: 20 S = DefinedGlobal; 21 break; 22 case NeverSeen: 23 case Defined: 24 case Used: 25 S = Defined; 26 break; 27 case DefinedWeak: 28 break; 29 case UndefinedWeak: 30 S = DefinedWeak; 31 } 32 } 33 34 void RecordStreamer::markGlobal(const MCSymbol &Symbol, 35 MCSymbolAttr Attribute) { 36 State &S = Symbols[Symbol.getName()]; 37 switch (S) { 38 case DefinedGlobal: 39 case Defined: 40 S = (Attribute == MCSA_Weak) ? DefinedWeak : DefinedGlobal; 41 break; 42 43 case NeverSeen: 44 case Global: 45 case Used: 46 S = (Attribute == MCSA_Weak) ? UndefinedWeak : Global; 47 break; 48 case UndefinedWeak: 49 case DefinedWeak: 50 break; 51 } 52 } 53 54 void RecordStreamer::markUsed(const MCSymbol &Symbol) { 55 State &S = Symbols[Symbol.getName()]; 56 switch (S) { 57 case DefinedGlobal: 58 case Defined: 59 case Global: 60 case DefinedWeak: 61 case UndefinedWeak: 62 break; 63 64 case NeverSeen: 65 case Used: 66 S = Used; 67 break; 68 } 69 } 70 71 void RecordStreamer::visitUsedSymbol(const MCSymbol &Sym) { markUsed(Sym); } 72 73 RecordStreamer::RecordStreamer(MCContext &Context) : MCStreamer(Context) {} 74 75 RecordStreamer::const_iterator RecordStreamer::begin() { 76 return Symbols.begin(); 77 } 78 79 RecordStreamer::const_iterator RecordStreamer::end() { return Symbols.end(); } 80 81 void RecordStreamer::EmitInstruction(const MCInst &Inst, 82 const MCSubtargetInfo &STI, bool) { 83 MCStreamer::EmitInstruction(Inst, STI); 84 } 85 86 void RecordStreamer::EmitLabel(MCSymbol *Symbol, SMLoc Loc) { 87 MCStreamer::EmitLabel(Symbol); 88 markDefined(*Symbol); 89 } 90 91 void RecordStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) { 92 markDefined(*Symbol); 93 MCStreamer::EmitAssignment(Symbol, Value); 94 } 95 96 bool RecordStreamer::EmitSymbolAttribute(MCSymbol *Symbol, 97 MCSymbolAttr Attribute) { 98 if (Attribute == MCSA_Global || Attribute == MCSA_Weak) 99 markGlobal(*Symbol, Attribute); 100 if (Attribute == MCSA_LazyReference) 101 markUsed(*Symbol); 102 return true; 103 } 104 105 void RecordStreamer::EmitZerofill(MCSection *Section, MCSymbol *Symbol, 106 uint64_t Size, unsigned ByteAlignment) { 107 markDefined(*Symbol); 108 } 109 110 void RecordStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, 111 unsigned ByteAlignment) { 112 markDefined(*Symbol); 113 } 114 115 void RecordStreamer::emitELFSymverDirective(MCSymbol *Alias, 116 const MCSymbol *Aliasee) { 117 SymverAliasMap[Aliasee].push_back(Alias); 118 } 119