~ubuntu-branches/ubuntu/feisty/clamav/feisty

« back to all changes in this revision

Viewing changes to libclamav/c++/llvm/lib/MC/MCObjectStreamer.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2007-02-20 10:33:44 UTC
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: james.westby@ubuntu.com-20070220103344-zgcu2psnx9d98fpa
Tags: upstream-0.90
ImportĀ upstreamĀ versionĀ 0.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
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/Support/ErrorHandling.h"
13
 
#include "llvm/MC/MCAssembler.h"
14
 
#include "llvm/MC/MCCodeEmitter.h"
15
 
#include "llvm/MC/MCExpr.h"
16
 
#include "llvm/Target/TargetAsmBackend.h"
17
 
using namespace llvm;
18
 
 
19
 
MCObjectStreamer::MCObjectStreamer(MCContext &Context, TargetAsmBackend &TAB,
20
 
                                   raw_ostream &_OS, MCCodeEmitter *_Emitter)
21
 
  : MCStreamer(Context), Assembler(new MCAssembler(Context, TAB,
22
 
                                                   *_Emitter, _OS)),
23
 
    CurSectionData(0)
24
 
{
25
 
}
26
 
 
27
 
MCObjectStreamer::~MCObjectStreamer() {
28
 
  delete &Assembler->getBackend();
29
 
  delete &Assembler->getEmitter();
30
 
  delete Assembler;
31
 
}
32
 
 
33
 
MCFragment *MCObjectStreamer::getCurrentFragment() const {
34
 
  assert(getCurrentSectionData() && "No current section!");
35
 
 
36
 
  if (!getCurrentSectionData()->empty())
37
 
    return &getCurrentSectionData()->getFragmentList().back();
38
 
 
39
 
  return 0;
40
 
}
41
 
 
42
 
MCDataFragment *MCObjectStreamer::getOrCreateDataFragment() const {
43
 
  MCDataFragment *F = dyn_cast_or_null<MCDataFragment>(getCurrentFragment());
44
 
  if (!F)
45
 
    F = new MCDataFragment(getCurrentSectionData());
46
 
  return F;
47
 
}
48
 
 
49
 
const MCExpr *MCObjectStreamer::AddValueSymbols(const MCExpr *Value) {
50
 
  switch (Value->getKind()) {
51
 
  case MCExpr::Target: llvm_unreachable("Can't handle target exprs yet!");
52
 
  case MCExpr::Constant:
53
 
    break;
54
 
 
55
 
  case MCExpr::Binary: {
56
 
    const MCBinaryExpr *BE = cast<MCBinaryExpr>(Value);
57
 
    AddValueSymbols(BE->getLHS());
58
 
    AddValueSymbols(BE->getRHS());
59
 
    break;
60
 
  }
61
 
 
62
 
  case MCExpr::SymbolRef:
63
 
    Assembler->getOrCreateSymbolData(cast<MCSymbolRefExpr>(Value)->getSymbol());
64
 
    break;
65
 
 
66
 
  case MCExpr::Unary:
67
 
    AddValueSymbols(cast<MCUnaryExpr>(Value)->getSubExpr());
68
 
    break;
69
 
  }
70
 
 
71
 
  return Value;
72
 
}
73
 
 
74
 
void MCObjectStreamer::SwitchSection(const MCSection *Section) {
75
 
  assert(Section && "Cannot switch to a null section!");
76
 
 
77
 
  // If already in this section, then this is a noop.
78
 
  if (Section == CurSection) return;
79
 
 
80
 
  PrevSection = CurSection;
81
 
  CurSection = Section;
82
 
  CurSectionData = &getAssembler().getOrCreateSectionData(*Section);
83
 
}
84
 
 
85
 
void MCObjectStreamer::Finish() {
86
 
  getAssembler().Finish();
87
 
}