LLVM  4.0.0
RecordStreamer.cpp
Go to the documentation of this file.
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 DefinedWeak:
27  break;
28  case UndefinedWeak:
29  S = DefinedWeak;
30  }
31 }
32 
33 void RecordStreamer::markGlobal(const MCSymbol &Symbol,
35  State &S = Symbols[Symbol.getName()];
36  switch (S) {
37  case DefinedGlobal:
38  case Defined:
39  S = (Attribute == MCSA_Weak) ? DefinedWeak : DefinedGlobal;
40  break;
41 
42  case NeverSeen:
43  case Global:
44  case Used:
45  S = (Attribute == MCSA_Weak) ? UndefinedWeak : Global;
46  break;
47  case UndefinedWeak:
48  case DefinedWeak:
49  break;
50  }
51 }
52 
53 void RecordStreamer::markUsed(const MCSymbol &Symbol) {
54  State &S = Symbols[Symbol.getName()];
55  switch (S) {
56  case DefinedGlobal:
57  case Defined:
58  case Global:
59  case DefinedWeak:
60  case UndefinedWeak:
61  break;
62 
63  case NeverSeen:
64  case Used:
65  S = Used;
66  break;
67  }
68 }
69 
70 void RecordStreamer::visitUsedSymbol(const MCSymbol &Sym) { markUsed(Sym); }
71 
73  return Symbols.begin();
74 }
75 
77 
79 
81  const MCSubtargetInfo &STI) {
82  MCStreamer::EmitInstruction(Inst, STI);
83 }
84 
86  MCStreamer::EmitLabel(Symbol);
87  markDefined(*Symbol);
88 }
89 
91  markDefined(*Symbol);
92  MCStreamer::EmitAssignment(Symbol, Value);
93 }
94 
96  MCSymbolAttr Attribute) {
97  if (Attribute == MCSA_Global || Attribute == MCSA_Weak)
98  markGlobal(*Symbol, Attribute);
99  if (Attribute == MCSA_LazyReference)
100  markUsed(*Symbol);
101  return true;
102 }
103 
105  uint64_t Size, unsigned ByteAlignment) {
106  markDefined(*Symbol);
107 }
108 
109 void RecordStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
110  unsigned ByteAlignment) {
111  markDefined(*Symbol);
112 }
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:40
LLVMContext & Context
void EmitZerofill(MCSection *Section, MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) override
Emit the zerofill section and an optional symbol.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:39
bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override
Add the given Attribute to Symbol.
void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) override
Emit an assignment of Value to Symbol.
const_iterator end()
virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI)
Emit the given Instruction into the current section.
Definition: MCStreamer.cpp:765
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol.
Definition: MCStreamer.cpp:722
Context object for machine code objects.
Definition: MCContext.h:51
.lazy_reference (MachO)
Definition: MCDirectives.h:34
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:150
Streaming machine code generation interface.
Definition: MCStreamer.h:161
RecordStreamer(MCContext &Context)
void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override
Emit the given Instruction into the current section.
virtual void EmitLabel(MCSymbol *Symbol)
Emit a label for Symbol into the current section.
Definition: MCStreamer.cpp:293
MCSymbolAttr
Definition: MCDirectives.h:19
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:199
StringMap< State >::const_iterator const_iterator
iterator begin()
Definition: StringMap.h:302
.type _foo,
Definition: MCDirectives.h:30
MCSubtargetInfo - Generic base class for all target subtargets.
void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) override
Emit a common symbol.
void EmitLabel(MCSymbol *Symbol) override
Emit a label for Symbol into the current section.
LLVM Value Representation.
Definition: Value.h:71
const_iterator begin()
iterator end()
Definition: StringMap.h:305