MC: Lift SwitchSection() and Finish() into MCObjectStreamer.
[oota-llvm.git] / lib / MC / MCObjectStreamer.cpp
1 //===- lib/MC/MCObjectStreamer.cpp - Object File MCStreamer Interface -----===//
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/MCObjectStreamer.h"
11
12 #include "llvm/MC/MCAssembler.h"
13 using namespace llvm;
14
15 MCObjectStreamer::MCObjectStreamer(MCContext &Context, TargetAsmBackend &TAB,
16                                    raw_ostream &_OS, MCCodeEmitter *_Emitter)
17   : MCStreamer(Context), Assembler(new MCAssembler(Context, TAB,
18                                                    *_Emitter, _OS)),
19     CurSectionData(0)
20 {
21 }
22
23 MCObjectStreamer::~MCObjectStreamer() {
24   delete Assembler;
25 }
26
27 void MCObjectStreamer::SwitchSection(const MCSection *Section) {
28   assert(Section && "Cannot switch to a null section!");
29
30   // If already in this section, then this is a noop.
31   if (Section == CurSection) return;
32
33   CurSection = Section;
34   CurSectionData = &getAssembler().getOrCreateSectionData(*Section);
35 }
36
37 void MCObjectStreamer::Finish() {
38   getAssembler().Finish();
39 }