MCStreamer.cpp revision 208954
1109864Sjeff//===- lib/MC/MCStreamer.cpp - Streaming Machine Code Output --------------===//
2113357Sjeff//
3109864Sjeff//                     The LLVM Compiler Infrastructure
4109864Sjeff//
5109864Sjeff// This file is distributed under the University of Illinois Open Source
6109864Sjeff// License. See LICENSE.TXT for details.
7109864Sjeff//
8109864Sjeff//===----------------------------------------------------------------------===//
9109864Sjeff
10109864Sjeff#include "llvm/MC/MCStreamer.h"
11109864Sjeff#include "llvm/MC/MCExpr.h"
12109864Sjeff#include "llvm/Support/raw_ostream.h"
13109864Sjeff#include "llvm/ADT/SmallString.h"
14109864Sjeff#include "llvm/ADT/Twine.h"
15109864Sjeff#include <cstdlib>
16109864Sjeffusing namespace llvm;
17109864Sjeff
18109864SjeffMCStreamer::MCStreamer(MCContext &_Context) : Context(_Context), CurSection(0) {
19109864Sjeff}
20109864Sjeff
21109864SjeffMCStreamer::~MCStreamer() {
22109864Sjeff}
23109864Sjeff
24109864Sjeffraw_ostream &MCStreamer::GetCommentOS() {
25109864Sjeff  // By default, discard comments.
26109864Sjeff  return nulls();
27109864Sjeff}
28109864Sjeff
29109864Sjeff
30109864Sjeff/// EmitIntValue - Special case of EmitValue that avoids the client having to
31109864Sjeff/// pass in a MCExpr for constant integers.
32109864Sjeffvoid MCStreamer::EmitIntValue(uint64_t Value, unsigned Size,
33109864Sjeff                              unsigned AddrSpace) {
34109864Sjeff  EmitValue(MCConstantExpr::Create(Value, getContext()), Size, AddrSpace);
35109864Sjeff}
36112966Sjeff
37109864Sjeffvoid MCStreamer::EmitSymbolValue(const MCSymbol *Sym, unsigned Size,
38109864Sjeff                                 unsigned AddrSpace) {
39109864Sjeff  EmitValue(MCSymbolRefExpr::Create(Sym, getContext()), Size, AddrSpace);
40109864Sjeff}
41109864Sjeff
42109864Sjeff/// EmitFill - Emit NumBytes bytes worth of the value specified by
43109864Sjeff/// FillValue.  This implements directives such as '.space'.
44109864Sjeffvoid MCStreamer::EmitFill(uint64_t NumBytes, uint8_t FillValue,
45109864Sjeff                          unsigned AddrSpace) {
46109864Sjeff  const MCExpr *E = MCConstantExpr::Create(FillValue, getContext());
47109864Sjeff  for (uint64_t i = 0, e = NumBytes; i != e; ++i)
48109864Sjeff    EmitValue(E, 1, AddrSpace);
49109864Sjeff}
50109864Sjeff
51109864Sjeff/// EmitRawText - If this file is backed by an assembly streamer, this dumps
52109864Sjeff/// the specified string in the output .s file.  This capability is
53113357Sjeff/// indicated by the hasRawTextSupport() predicate.
54113357Sjeffvoid MCStreamer::EmitRawText(StringRef String) {
55109864Sjeff  errs() << "EmitRawText called on an MCStreamer that doesn't support it, "
56109864Sjeff  " something must not be fully mc'ized\n";
57109864Sjeff  abort();
58109864Sjeff}
59109864Sjeff
60109864Sjeffvoid MCStreamer::EmitRawText(const Twine &T) {
61109864Sjeff  SmallString<128> Str;
62109864Sjeff  T.toVector(Str);
63113357Sjeff  EmitRawText(Str.str());
64113357Sjeff}
65113357Sjeff