blob: f34fcd9a61f7ba7d7baabb38ed2342355a3ca9c4 [file] [log] [blame]
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +00001//===- lib/MC/MCMachOStreamer.cpp - Mach-O Object Output ------------===//
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 "llvm/MC/MCStreamer.h"
11
12#include "llvm/ADT/DenseMap.h"
13#include "llvm/MC/MCAssembler.h"
14#include "llvm/MC/MCContext.h"
15#include "llvm/MC/MCSection.h"
16#include "llvm/MC/MCSymbol.h"
17#include "llvm/MC/MCValue.h"
18#include "llvm/Support/ErrorHandling.h"
19using namespace llvm;
20
21namespace {
22
23class MCMachOStreamer : public MCStreamer {
24 MCAssembler Assembler;
25
26 MCSectionData *CurSectionData;
27
28 DenseMap<const MCSection*, MCSectionData*> SectionMap;
29
30public:
31 MCMachOStreamer(MCContext &Context, raw_ostream &_OS)
32 : MCStreamer(Context), Assembler(_OS), CurSectionData(0) {}
33 ~MCMachOStreamer() {}
34
35 /// @name MCStreamer Interface
36 /// @{
37
38 virtual void SwitchSection(const MCSection *Section);
39
40 virtual void EmitLabel(MCSymbol *Symbol);
41
42 virtual void EmitAssemblerFlag(AssemblerFlag Flag);
43
44 virtual void EmitAssignment(MCSymbol *Symbol, const MCValue &Value,
45 bool MakeAbsolute = false);
46
47 virtual void EmitSymbolAttribute(MCSymbol *Symbol, SymbolAttr Attribute);
48
49 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
50
51 virtual void EmitLocalSymbol(MCSymbol *Symbol, const MCValue &Value);
52
53 virtual void EmitCommonSymbol(MCSymbol *Symbol, unsigned Size,
54 unsigned Pow2Alignment, bool IsLocal);
55
56 virtual void EmitZerofill(MCSection *Section, MCSymbol *Symbol = NULL,
57 unsigned Size = 0, unsigned Pow2Alignment = 0);
58
59 virtual void EmitBytes(const StringRef &Data);
60
61 virtual void EmitValue(const MCValue &Value, unsigned Size);
62
63 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
64 unsigned ValueSize = 1,
65 unsigned MaxBytesToEmit = 0);
66
67 virtual void EmitValueToOffset(const MCValue &Offset,
68 unsigned char Value = 0);
69
70 virtual void EmitInstruction(const MCInst &Inst);
71
72 virtual void Finish();
73
74 /// @}
75};
76
77} // end anonymous namespace.
78
79void MCMachOStreamer::SwitchSection(const MCSection *Section) {
80 assert(Section && "Cannot switch to a null section!");
81
82 if (Section != CurSection) {
83 CurSection = Section;
84 MCSectionData *&Entry = SectionMap[Section];
85
86 if (!Entry)
87 Entry = new MCSectionData(*Section, &Assembler);
88
89 CurSectionData = Entry;
90 }
91}
92
93void MCMachOStreamer::EmitLabel(MCSymbol *Symbol) {
94 assert(Symbol->getSection() == 0 && "Cannot emit a symbol twice!");
95 assert(CurSection && "Cannot emit before setting section!");
96 assert(!getContext().GetSymbolValue(Symbol) &&
97 "Cannot emit symbol which was directly assigned to!");
98
99 llvm_unreachable("FIXME: Not yet implemented!");
100
101 Symbol->setSection(CurSection);
102 Symbol->setExternal(false);
103}
104
105void MCMachOStreamer::EmitAssemblerFlag(AssemblerFlag Flag) {
106 llvm_unreachable("FIXME: Not yet implemented!");
107}
108
109void MCMachOStreamer::EmitAssignment(MCSymbol *Symbol,
110 const MCValue &Value,
111 bool MakeAbsolute) {
112 assert(!Symbol->getSection() && "Cannot assign to a label!");
113
114 llvm_unreachable("FIXME: Not yet implemented!");
115}
116
117void MCMachOStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
118 SymbolAttr Attribute) {
119 llvm_unreachable("FIXME: Not yet implemented!");
120}
121
122void MCMachOStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
123 llvm_unreachable("FIXME: Not yet implemented!");
124}
125
126void MCMachOStreamer::EmitLocalSymbol(MCSymbol *Symbol, const MCValue &Value) {
127 llvm_unreachable("FIXME: Not yet implemented!");
128}
129
130void MCMachOStreamer::EmitCommonSymbol(MCSymbol *Symbol, unsigned Size,
131 unsigned Pow2Alignment,
132 bool IsLocal) {
133 llvm_unreachable("FIXME: Not yet implemented!");
134}
135
136void MCMachOStreamer::EmitZerofill(MCSection *Section, MCSymbol *Symbol,
137 unsigned Size, unsigned Pow2Alignment) {
138 llvm_unreachable("FIXME: Not yet implemented!");
139}
140
141void MCMachOStreamer::EmitBytes(const StringRef &Data) {
142 llvm_unreachable("FIXME: Not yet implemented!");
143}
144
145void MCMachOStreamer::EmitValue(const MCValue &Value, unsigned Size) {
146 llvm_unreachable("FIXME: Not yet implemented!");
147}
148
149void MCMachOStreamer::EmitValueToAlignment(unsigned ByteAlignment,
150 int64_t Value, unsigned ValueSize,
151 unsigned MaxBytesToEmit) {
152 llvm_unreachable("FIXME: Not yet implemented!");
153}
154
155void MCMachOStreamer::EmitValueToOffset(const MCValue &Offset,
156 unsigned char Value) {
157 llvm_unreachable("FIXME: Not yet implemented!");
158}
159
160void MCMachOStreamer::EmitInstruction(const MCInst &Inst) {
161 llvm_unreachable("FIXME: Not yet implemented!");
162}
163
164void MCMachOStreamer::Finish() {
165 Assembler.Finish();
166}
167
168MCStreamer *llvm::createMachOStreamer(MCContext &Context, raw_ostream &OS) {
169 return new MCMachOStreamer(Context, OS);
170}