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