blob: 9fe719a7fa7d8de43dafd100ac508d7a708cbc94 [file] [log] [blame]
Daniel Dunbar9faf2732009-06-24 01:03:06 +00001//===- lib/MC/MCStreamer.cpp - Streaming Machine Code 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
Rafael Espindolac653a892010-11-16 21:20:32 +000010#include "llvm/MC/MCContext.h"
Daniel Dunbar9faf2732009-06-24 01:03:06 +000011#include "llvm/MC/MCStreamer.h"
Chris Lattner0c65fd42010-01-19 18:45:47 +000012#include "llvm/MC/MCExpr.h"
Kevin Enderbye46564a2010-09-30 16:52:03 +000013#include "llvm/MC/MCObjectWriter.h"
Rafael Espindola16145972010-11-01 14:28:48 +000014#include "llvm/Support/ErrorHandling.h"
Chris Lattner8fa0e352010-01-22 19:17:48 +000015#include "llvm/Support/raw_ostream.h"
Chris Lattner17167212010-04-03 22:12:35 +000016#include "llvm/ADT/SmallString.h"
17#include "llvm/ADT/Twine.h"
Chris Lattner6ec72d22010-04-03 21:48:59 +000018#include <cstdlib>
Daniel Dunbar9faf2732009-06-24 01:03:06 +000019using namespace llvm;
20
Benjamin Kramere39017c2010-09-02 18:53:37 +000021MCStreamer::MCStreamer(MCContext &Ctx) : Context(Ctx), CurSection(0),
22 PrevSection(0) {
Daniel Dunbar9faf2732009-06-24 01:03:06 +000023}
24
25MCStreamer::~MCStreamer() {
26}
Chris Lattner0c65fd42010-01-19 18:45:47 +000027
Chris Lattner8fa0e352010-01-22 19:17:48 +000028raw_ostream &MCStreamer::GetCommentOS() {
29 // By default, discard comments.
30 return nulls();
31}
32
Rafael Espindola57ab7082010-12-03 00:55:40 +000033void MCStreamer::EmitDwarfSetLineAddr(int64_t LineDelta,
34 const MCSymbol *Label, int PointerSize) {
35 // emit the sequence to set the address
36 EmitIntValue(dwarf::DW_LNS_extended_op, 1);
37 EmitULEB128IntValue(PointerSize + 1);
38 EmitIntValue(dwarf::DW_LNE_set_address, 1);
39 EmitSymbolValue(Label, PointerSize);
40
41 // emit the sequence for the LineDelta (from 1) and a zero address delta.
42 MCDwarfLineAddr::Emit(this, LineDelta, 0);
43}
Chris Lattner8fa0e352010-01-22 19:17:48 +000044
Chris Lattnerdc50e5d2010-01-19 22:03:38 +000045/// EmitIntValue - Special case of EmitValue that avoids the client having to
46/// pass in a MCExpr for constant integers.
47void MCStreamer::EmitIntValue(uint64_t Value, unsigned Size,
48 unsigned AddrSpace) {
49 EmitValue(MCConstantExpr::Create(Value, getContext()), Size, AddrSpace);
50}
51
Rafael Espindola5e874982010-11-02 17:22:24 +000052/// EmitULEB128Value - Special case of EmitULEB128Value that avoids the
53/// client having to pass in a MCExpr for constant integers.
54void MCStreamer::EmitULEB128IntValue(uint64_t Value, unsigned AddrSpace) {
55 EmitULEB128Value(MCConstantExpr::Create(Value, getContext()), AddrSpace);
Kevin Enderbye46564a2010-09-30 16:52:03 +000056}
57
Rafael Espindola5e874982010-11-02 17:22:24 +000058/// EmitSLEB128Value - Special case of EmitSLEB128Value that avoids the
59/// client having to pass in a MCExpr for constant integers.
60void MCStreamer::EmitSLEB128IntValue(int64_t Value, unsigned AddrSpace) {
61 EmitSLEB128Value(MCConstantExpr::Create(Value, getContext()), AddrSpace);
Kevin Enderbye46564a2010-09-30 16:52:03 +000062}
63
Chris Lattnerb14490d2010-03-09 00:39:24 +000064void MCStreamer::EmitSymbolValue(const MCSymbol *Sym, unsigned Size,
65 unsigned AddrSpace) {
66 EmitValue(MCSymbolRefExpr::Create(Sym, getContext()), Size, AddrSpace);
67}
68
Rafael Espindolab7465312010-11-28 15:09:24 +000069void MCStreamer::EmitGPRel32Value(const MCExpr *Value) {
70 report_fatal_error("unsupported directive in streamer");
71}
72
Chris Lattner0c65fd42010-01-19 18:45:47 +000073/// EmitFill - Emit NumBytes bytes worth of the value specified by
74/// FillValue. This implements directives such as '.space'.
Chris Lattnerc35681b2010-01-19 19:46:13 +000075void MCStreamer::EmitFill(uint64_t NumBytes, uint8_t FillValue,
76 unsigned AddrSpace) {
Chris Lattner0c65fd42010-01-19 18:45:47 +000077 const MCExpr *E = MCConstantExpr::Create(FillValue, getContext());
78 for (uint64_t i = 0, e = NumBytes; i != e; ++i)
Chris Lattnerc35681b2010-01-19 19:46:13 +000079 EmitValue(E, 1, AddrSpace);
Chris Lattner0c65fd42010-01-19 18:45:47 +000080}
Chris Lattner8a87fb72010-04-03 21:35:55 +000081
Rafael Espindolac653a892010-11-16 21:20:32 +000082bool MCStreamer::EmitDwarfFileDirective(unsigned FileNo,
83 StringRef Filename) {
84 return getContext().GetDwarfFile(Filename, FileNo) == 0;
85}
86
87void MCStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
88 unsigned Column, unsigned Flags,
89 unsigned Isa,
90 unsigned Discriminator) {
91 getContext().setCurrentDwarfLoc(FileNo, Line, Column, Flags, Isa,
92 Discriminator);
93}
94
Rafael Espindola3c227b02010-11-22 14:27:24 +000095bool MCStreamer::EmitCFIStartProc() {
96 return false;
97}
98
99bool MCStreamer::EmitCFIEndProc() {
100 return false;
101}
102
103bool MCStreamer::EmitCFIDefCfaOffset(int64_t Offset) {
104 return false;
105}
106
107bool MCStreamer::EmitCFIDefCfaRegister(int64_t Register) {
108 return false;
109}
110
111bool MCStreamer::EmitCFIOffset(int64_t Register, int64_t Offset) {
112 return false;
113}
114
115bool MCStreamer::EmitCFIPersonality(const MCSymbol *Sym) {
116 return false;
117}
118
119bool MCStreamer::EmitCFILsda(const MCSymbol *Sym) {
120 return false;
121}
122
Matt Fleming141791c2010-05-20 19:45:09 +0000123/// EmitRawText - If this file is backed by an assembly streamer, this dumps
Chris Lattner8a87fb72010-04-03 21:35:55 +0000124/// the specified string in the output .s file. This capability is
125/// indicated by the hasRawTextSupport() predicate.
126void MCStreamer::EmitRawText(StringRef String) {
127 errs() << "EmitRawText called on an MCStreamer that doesn't support it, "
128 " something must not be fully mc'ized\n";
129 abort();
130}
Chris Lattner17167212010-04-03 22:12:35 +0000131
132void MCStreamer::EmitRawText(const Twine &T) {
133 SmallString<128> Str;
134 T.toVector(Str);
135 EmitRawText(Str.str());
136}