2009-06-24 01:03:06 +00:00
|
|
|
//===- lib/MC/MCAsmStreamer.cpp - Text Assembly Output --------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2009-08-31 08:08:38 +00:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2009-08-27 00:51:57 +00:00
|
|
|
#include "llvm/MC/MCCodeEmitter.h"
|
2009-06-24 01:03:06 +00:00
|
|
|
#include "llvm/MC/MCContext.h"
|
2009-08-31 08:08:38 +00:00
|
|
|
#include "llvm/MC/MCExpr.h"
|
2010-12-16 03:20:06 +00:00
|
|
|
#include "llvm/MC/MCFixupKindInfo.h"
|
2009-07-01 06:35:03 +00:00
|
|
|
#include "llvm/MC/MCInst.h"
|
2009-09-14 03:02:37 +00:00
|
|
|
#include "llvm/MC/MCInstPrinter.h"
|
2009-08-10 18:15:01 +00:00
|
|
|
#include "llvm/MC/MCSectionMachO.h"
|
2009-06-24 01:03:06 +00:00
|
|
|
#include "llvm/MC/MCSymbol.h"
|
2010-03-19 05:48:53 +00:00
|
|
|
#include "llvm/ADT/OwningPtr.h"
|
2010-01-22 07:29:22 +00:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
|
|
|
#include "llvm/ADT/Twine.h"
|
2009-07-11 20:10:48 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2009-08-19 06:12:02 +00:00
|
|
|
#include "llvm/Support/MathExtras.h"
|
2009-08-27 00:51:57 +00:00
|
|
|
#include "llvm/Support/Format.h"
|
2010-01-22 07:29:22 +00:00
|
|
|
#include "llvm/Support/FormattedStream.h"
|
2010-12-16 03:05:59 +00:00
|
|
|
#include "llvm/Target/TargetAsmBackend.h"
|
2010-12-10 07:39:47 +00:00
|
|
|
#include "llvm/Target/TargetAsmInfo.h"
|
2010-12-16 03:05:59 +00:00
|
|
|
#include "llvm/Target/TargetLoweringObjectFile.h"
|
2010-12-19 20:43:38 +00:00
|
|
|
#include <cctype>
|
2009-06-24 01:03:06 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2009-08-17 04:17:34 +00:00
|
|
|
class MCAsmStreamer : public MCStreamer {
|
2010-01-22 07:29:22 +00:00
|
|
|
formatted_raw_ostream &OS;
|
2009-08-22 21:43:10 +00:00
|
|
|
const MCAsmInfo &MAI;
|
2010-03-19 05:48:53 +00:00
|
|
|
OwningPtr<MCInstPrinter> InstPrinter;
|
2010-07-29 17:48:06 +00:00
|
|
|
OwningPtr<MCCodeEmitter> Emitter;
|
2010-12-16 03:05:59 +00:00
|
|
|
OwningPtr<TargetAsmBackend> AsmBackend;
|
2010-09-22 18:16:55 +00:00
|
|
|
|
2010-01-22 07:29:22 +00:00
|
|
|
SmallString<128> CommentToEmit;
|
2010-01-22 19:17:48 +00:00
|
|
|
raw_svector_ostream CommentStream;
|
2010-02-03 18:18:30 +00:00
|
|
|
|
|
|
|
unsigned IsVerboseAsm : 1;
|
|
|
|
unsigned ShowInst : 1;
|
2010-12-10 07:39:47 +00:00
|
|
|
unsigned UseLoc : 1;
|
2010-02-03 18:18:30 +00:00
|
|
|
|
2010-12-04 03:21:47 +00:00
|
|
|
bool needsSet(const MCExpr *Value);
|
|
|
|
|
2009-08-17 04:17:34 +00:00
|
|
|
public:
|
2010-01-22 07:29:22 +00:00
|
|
|
MCAsmStreamer(MCContext &Context, formatted_raw_ostream &os,
|
2010-12-10 07:39:47 +00:00
|
|
|
bool isVerboseAsm,
|
|
|
|
bool useLoc,
|
2010-12-16 03:05:59 +00:00
|
|
|
MCInstPrinter *printer, MCCodeEmitter *emitter,
|
|
|
|
TargetAsmBackend *asmbackend,
|
|
|
|
bool showInst)
|
2010-03-12 18:28:53 +00:00
|
|
|
: MCStreamer(Context), OS(os), MAI(Context.getAsmInfo()),
|
2010-12-16 03:05:59 +00:00
|
|
|
InstPrinter(printer), Emitter(emitter), AsmBackend(asmbackend),
|
|
|
|
CommentStream(CommentToEmit), IsVerboseAsm(isVerboseAsm),
|
2010-12-10 07:39:47 +00:00
|
|
|
ShowInst(showInst), UseLoc(useLoc) {
|
2010-02-10 00:10:18 +00:00
|
|
|
if (InstPrinter && IsVerboseAsm)
|
|
|
|
InstPrinter->setCommentStream(CommentStream);
|
|
|
|
}
|
2009-08-17 04:17:34 +00:00
|
|
|
~MCAsmStreamer() {}
|
2009-06-24 01:03:06 +00:00
|
|
|
|
2010-01-22 07:29:22 +00:00
|
|
|
inline void EmitEOL() {
|
2010-01-22 19:17:48 +00:00
|
|
|
// If we don't have any comments, just emit a \n.
|
|
|
|
if (!IsVerboseAsm) {
|
2010-01-22 07:29:22 +00:00
|
|
|
OS << '\n';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
EmitCommentsAndEOL();
|
|
|
|
}
|
|
|
|
void EmitCommentsAndEOL();
|
2010-02-02 23:37:42 +00:00
|
|
|
|
|
|
|
/// isVerboseAsm - Return true if this streamer supports verbose assembly at
|
|
|
|
/// all.
|
|
|
|
virtual bool isVerboseAsm() const { return IsVerboseAsm; }
|
2010-09-22 18:16:55 +00:00
|
|
|
|
2010-04-03 21:35:55 +00:00
|
|
|
/// hasRawTextSupport - We support EmitRawText.
|
|
|
|
virtual bool hasRawTextSupport() const { return true; }
|
2010-02-09 23:00:14 +00:00
|
|
|
|
2010-01-22 18:21:35 +00:00
|
|
|
/// AddComment - Add a comment that can be emitted to the generated .s
|
2010-01-22 07:29:22 +00:00
|
|
|
/// file if applicable as a QoI issue to make the output of the compiler
|
|
|
|
/// more readable. This only affects the MCAsmStreamer, and only when
|
|
|
|
/// verbose assembly output is enabled.
|
2010-01-22 18:21:35 +00:00
|
|
|
virtual void AddComment(const Twine &T);
|
2010-02-09 23:00:14 +00:00
|
|
|
|
|
|
|
/// AddEncodingComment - Add a comment showing the encoding of an instruction.
|
|
|
|
virtual void AddEncodingComment(const MCInst &Inst);
|
|
|
|
|
2010-01-22 19:17:48 +00:00
|
|
|
/// GetCommentOS - Return a raw_ostream that comments can be written to.
|
|
|
|
/// Unlike AddComment, you are required to terminate comments with \n if you
|
|
|
|
/// use this method.
|
|
|
|
virtual raw_ostream &GetCommentOS() {
|
|
|
|
if (!IsVerboseAsm)
|
|
|
|
return nulls(); // Discard comments unless in verbose asm mode.
|
|
|
|
return CommentStream;
|
|
|
|
}
|
2010-02-09 23:00:14 +00:00
|
|
|
|
2010-01-22 19:52:01 +00:00
|
|
|
/// AddBlankLine - Emit a blank line to a .s file to pretty it up.
|
|
|
|
virtual void AddBlankLine() {
|
|
|
|
EmitEOL();
|
|
|
|
}
|
2010-02-09 23:00:14 +00:00
|
|
|
|
2009-08-17 04:17:34 +00:00
|
|
|
/// @name MCStreamer Interface
|
|
|
|
/// @{
|
2009-06-24 01:03:06 +00:00
|
|
|
|
2009-08-17 05:49:08 +00:00
|
|
|
virtual void SwitchSection(const MCSection *Section);
|
2009-06-24 01:03:06 +00:00
|
|
|
|
2010-09-15 21:48:40 +00:00
|
|
|
virtual void InitSections() {
|
|
|
|
// FIXME, this is MachO specific, but the testsuite
|
|
|
|
// expects this.
|
|
|
|
SwitchSection(getContext().getMachOSection("__TEXT", "__text",
|
|
|
|
MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
|
|
|
|
0, SectionKind::getText()));
|
|
|
|
}
|
|
|
|
|
2009-08-17 04:17:34 +00:00
|
|
|
virtual void EmitLabel(MCSymbol *Symbol);
|
2009-06-24 01:03:06 +00:00
|
|
|
|
2010-01-23 06:39:22 +00:00
|
|
|
virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
|
2010-11-05 22:08:08 +00:00
|
|
|
virtual void EmitThumbFunc(MCSymbol *Func);
|
2009-06-24 01:03:06 +00:00
|
|
|
|
2009-08-31 08:09:28 +00:00
|
|
|
virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
|
2010-11-01 14:28:48 +00:00
|
|
|
virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol);
|
2010-12-03 00:55:40 +00:00
|
|
|
virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta,
|
|
|
|
const MCSymbol *LastLabel,
|
|
|
|
const MCSymbol *Label);
|
2009-06-24 01:03:06 +00:00
|
|
|
|
2010-01-23 06:39:22 +00:00
|
|
|
virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute);
|
2009-07-13 21:03:15 +00:00
|
|
|
|
2009-08-17 04:17:34 +00:00
|
|
|
virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
|
2010-05-08 19:54:22 +00:00
|
|
|
virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol);
|
|
|
|
virtual void EmitCOFFSymbolStorageClass(int StorageClass);
|
|
|
|
virtual void EmitCOFFSymbolType(int Type);
|
|
|
|
virtual void EndCOFFSymbolDef();
|
2010-01-25 07:52:13 +00:00
|
|
|
virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value);
|
2010-01-23 07:47:02 +00:00
|
|
|
virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
|
2009-08-30 06:17:16 +00:00
|
|
|
unsigned ByteAlignment);
|
2009-07-14 18:17:10 +00:00
|
|
|
|
2010-01-23 07:47:02 +00:00
|
|
|
/// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol.
|
|
|
|
///
|
|
|
|
/// @param Symbol - The common symbol to emit.
|
|
|
|
/// @param Size - The size of the common symbol.
|
|
|
|
virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size);
|
2010-09-22 18:16:55 +00:00
|
|
|
|
2009-08-28 05:48:22 +00:00
|
|
|
virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
|
2009-08-30 06:17:16 +00:00
|
|
|
unsigned Size = 0, unsigned ByteAlignment = 0);
|
2009-07-14 21:35:03 +00:00
|
|
|
|
2010-05-18 21:16:04 +00:00
|
|
|
virtual void EmitTBSSSymbol (const MCSection *Section, MCSymbol *Symbol,
|
|
|
|
uint64_t Size, unsigned ByteAlignment = 0);
|
2010-09-22 18:16:55 +00:00
|
|
|
|
2010-01-19 19:46:13 +00:00
|
|
|
virtual void EmitBytes(StringRef Data, unsigned AddrSpace);
|
2009-07-07 20:30:46 +00:00
|
|
|
|
2010-12-10 07:39:47 +00:00
|
|
|
virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
|
|
|
|
bool isPCRel, unsigned AddrSpace);
|
2010-12-03 02:54:21 +00:00
|
|
|
virtual void EmitIntValue(uint64_t Value, unsigned Size,
|
|
|
|
unsigned AddrSpace = 0);
|
2010-11-02 17:22:24 +00:00
|
|
|
|
|
|
|
virtual void EmitULEB128Value(const MCExpr *Value, unsigned AddrSpace = 0);
|
|
|
|
|
|
|
|
virtual void EmitSLEB128Value(const MCExpr *Value, unsigned AddrSpace = 0);
|
|
|
|
|
2010-01-25 21:28:50 +00:00
|
|
|
virtual void EmitGPRel32Value(const MCExpr *Value);
|
2010-09-22 18:16:55 +00:00
|
|
|
|
2010-01-19 22:03:38 +00:00
|
|
|
|
2010-01-19 19:46:13 +00:00
|
|
|
virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue,
|
|
|
|
unsigned AddrSpace);
|
2009-07-10 22:20:30 +00:00
|
|
|
|
2009-08-17 04:17:34 +00:00
|
|
|
virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
|
|
|
|
unsigned ValueSize = 1,
|
|
|
|
unsigned MaxBytesToEmit = 0);
|
2009-06-24 01:03:06 +00:00
|
|
|
|
2010-02-23 18:26:34 +00:00
|
|
|
virtual void EmitCodeAlignment(unsigned ByteAlignment,
|
|
|
|
unsigned MaxBytesToEmit = 0);
|
|
|
|
|
2009-08-31 08:09:28 +00:00
|
|
|
virtual void EmitValueToOffset(const MCExpr *Offset,
|
2009-08-17 04:17:34 +00:00
|
|
|
unsigned char Value = 0);
|
2009-06-24 01:03:06 +00:00
|
|
|
|
2010-01-25 18:58:59 +00:00
|
|
|
virtual void EmitFileDirective(StringRef Filename);
|
2010-11-16 21:20:32 +00:00
|
|
|
virtual bool EmitDwarfFileDirective(unsigned FileNo, StringRef Filename);
|
|
|
|
virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
|
|
|
|
unsigned Column, unsigned Flags,
|
|
|
|
unsigned Isa, unsigned Discriminator);
|
2010-01-25 18:58:59 +00:00
|
|
|
|
2010-11-22 14:27:24 +00:00
|
|
|
virtual bool EmitCFIStartProc();
|
|
|
|
virtual bool EmitCFIEndProc();
|
|
|
|
virtual bool EmitCFIDefCfaOffset(int64_t Offset);
|
|
|
|
virtual bool EmitCFIDefCfaRegister(int64_t Register);
|
|
|
|
virtual bool EmitCFIOffset(int64_t Register, int64_t Offset);
|
2010-12-27 00:36:05 +00:00
|
|
|
virtual bool EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding);
|
2010-12-27 15:56:22 +00:00
|
|
|
virtual bool EmitCFILsda(const MCSymbol *Sym, unsigned Encoding);
|
2010-11-22 14:27:24 +00:00
|
|
|
|
2010-01-25 18:58:59 +00:00
|
|
|
virtual void EmitInstruction(const MCInst &Inst);
|
2010-09-22 18:16:55 +00:00
|
|
|
|
2010-09-22 18:18:30 +00:00
|
|
|
/// EmitRawText - If this file is backed by an assembly streamer, this dumps
|
2010-04-03 21:35:55 +00:00
|
|
|
/// the specified string in the output .s file. This capability is
|
|
|
|
/// indicated by the hasRawTextSupport() predicate.
|
|
|
|
virtual void EmitRawText(StringRef String);
|
2010-09-22 18:16:55 +00:00
|
|
|
|
2009-08-17 04:17:34 +00:00
|
|
|
virtual void Finish();
|
2010-09-22 18:16:55 +00:00
|
|
|
|
2009-08-17 04:17:34 +00:00
|
|
|
/// @}
|
|
|
|
};
|
2009-06-24 19:25:34 +00:00
|
|
|
|
2009-08-17 04:17:34 +00:00
|
|
|
} // end anonymous namespace.
|
2009-06-24 01:03:06 +00:00
|
|
|
|
2010-01-22 18:21:35 +00:00
|
|
|
/// AddComment - Add a comment that can be emitted to the generated .s
|
2010-01-22 07:29:22 +00:00
|
|
|
/// file if applicable as a QoI issue to make the output of the compiler
|
|
|
|
/// more readable. This only affects the MCAsmStreamer, and only when
|
|
|
|
/// verbose assembly output is enabled.
|
2010-01-22 18:21:35 +00:00
|
|
|
void MCAsmStreamer::AddComment(const Twine &T) {
|
2010-01-22 07:29:22 +00:00
|
|
|
if (!IsVerboseAsm) return;
|
2010-09-22 18:16:55 +00:00
|
|
|
|
2010-01-22 19:17:48 +00:00
|
|
|
// Make sure that CommentStream is flushed.
|
|
|
|
CommentStream.flush();
|
2010-09-22 18:16:55 +00:00
|
|
|
|
2010-01-22 07:29:22 +00:00
|
|
|
T.toVector(CommentToEmit);
|
2010-01-22 19:17:48 +00:00
|
|
|
// Each comment goes on its own line.
|
|
|
|
CommentToEmit.push_back('\n');
|
2010-09-22 18:16:55 +00:00
|
|
|
|
2010-01-22 21:16:10 +00:00
|
|
|
// Tell the comment stream that the vector changed underneath it.
|
|
|
|
CommentStream.resync();
|
2010-01-22 07:29:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MCAsmStreamer::EmitCommentsAndEOL() {
|
2010-01-22 19:17:48 +00:00
|
|
|
if (CommentToEmit.empty() && CommentStream.GetNumBytesInBuffer() == 0) {
|
|
|
|
OS << '\n';
|
|
|
|
return;
|
|
|
|
}
|
2010-09-22 18:16:55 +00:00
|
|
|
|
2010-01-22 19:17:48 +00:00
|
|
|
CommentStream.flush();
|
2010-01-22 07:29:22 +00:00
|
|
|
StringRef Comments = CommentToEmit.str();
|
2010-09-22 18:16:55 +00:00
|
|
|
|
2010-01-22 19:17:48 +00:00
|
|
|
assert(Comments.back() == '\n' &&
|
|
|
|
"Comment array not newline terminated");
|
|
|
|
do {
|
2010-01-22 07:29:22 +00:00
|
|
|
// Emit a line of comments.
|
|
|
|
OS.PadToColumn(MAI.getCommentColumn());
|
|
|
|
size_t Position = Comments.find('\n');
|
|
|
|
OS << MAI.getCommentString() << ' ' << Comments.substr(0, Position) << '\n';
|
2010-09-22 18:16:55 +00:00
|
|
|
|
2010-01-22 07:29:22 +00:00
|
|
|
Comments = Comments.substr(Position+1);
|
2010-01-22 19:17:48 +00:00
|
|
|
} while (!Comments.empty());
|
2010-09-22 18:16:55 +00:00
|
|
|
|
2010-01-22 21:16:10 +00:00
|
|
|
CommentToEmit.clear();
|
|
|
|
// Tell the comment stream that the vector changed underneath it.
|
|
|
|
CommentStream.resync();
|
2010-01-22 07:29:22 +00:00
|
|
|
}
|
|
|
|
|
2009-06-25 21:03:18 +00:00
|
|
|
static inline int64_t truncateToSize(int64_t Value, unsigned Bytes) {
|
|
|
|
assert(Bytes && "Invalid size!");
|
|
|
|
return Value & ((uint64_t) (int64_t) -1 >> (64 - Bytes * 8));
|
|
|
|
}
|
|
|
|
|
2009-08-17 05:49:08 +00:00
|
|
|
void MCAsmStreamer::SwitchSection(const MCSection *Section) {
|
2009-08-19 05:49:37 +00:00
|
|
|
assert(Section && "Cannot switch to a null section!");
|
2009-06-24 01:03:06 +00:00
|
|
|
if (Section != CurSection) {
|
2010-09-02 18:53:37 +00:00
|
|
|
PrevSection = CurSection;
|
2009-06-24 01:03:06 +00:00
|
|
|
CurSection = Section;
|
2009-08-22 21:43:10 +00:00
|
|
|
Section->PrintSwitchToSection(MAI, OS);
|
2009-06-24 01:03:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MCAsmStreamer::EmitLabel(MCSymbol *Symbol) {
|
2009-08-22 07:22:36 +00:00
|
|
|
assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
|
2010-05-05 19:01:00 +00:00
|
|
|
assert(!Symbol->isVariable() && "Cannot emit a variable symbol!");
|
2009-06-24 17:00:42 +00:00
|
|
|
assert(CurSection && "Cannot emit before setting section!");
|
|
|
|
|
2010-09-22 22:19:53 +00:00
|
|
|
OS << *Symbol << MAI.getLabelSuffix();
|
2010-01-22 07:36:39 +00:00
|
|
|
EmitEOL();
|
2009-08-22 07:22:36 +00:00
|
|
|
Symbol->setSection(*CurSection);
|
2009-06-24 01:03:06 +00:00
|
|
|
}
|
|
|
|
|
2010-01-23 06:39:22 +00:00
|
|
|
void MCAsmStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {
|
2009-07-16 17:56:39 +00:00
|
|
|
switch (Flag) {
|
2009-08-13 23:36:34 +00:00
|
|
|
default: assert(0 && "Invalid flag!");
|
2010-09-30 02:45:56 +00:00
|
|
|
case MCAF_SyntaxUnified: OS << "\t.syntax unified"; break;
|
2010-01-23 06:39:22 +00:00
|
|
|
case MCAF_SubsectionsViaSymbols: OS << ".subsections_via_symbols"; break;
|
2010-11-05 22:08:08 +00:00
|
|
|
case MCAF_Code16: OS << "\t.code\t16"; break;
|
2010-11-05 22:40:09 +00:00
|
|
|
case MCAF_Code32: OS << "\t.code\t32"; break;
|
2009-07-16 17:56:39 +00:00
|
|
|
}
|
2010-01-22 07:36:39 +00:00
|
|
|
EmitEOL();
|
2009-07-13 21:03:15 +00:00
|
|
|
}
|
|
|
|
|
2010-11-05 22:08:08 +00:00
|
|
|
void MCAsmStreamer::EmitThumbFunc(MCSymbol *Func) {
|
|
|
|
// This needs to emit to a temporary string to get properly quoted
|
|
|
|
// MCSymbols when they have spaces in them.
|
|
|
|
OS << "\t.thumb_func";
|
|
|
|
if (Func)
|
|
|
|
OS << '\t' << *Func;
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2009-08-31 08:09:28 +00:00
|
|
|
void MCAsmStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
|
2010-01-22 07:36:39 +00:00
|
|
|
OS << *Symbol << " = " << *Value;
|
|
|
|
EmitEOL();
|
2009-10-16 01:34:54 +00:00
|
|
|
|
|
|
|
// FIXME: Lift context changes into super class.
|
2010-05-05 17:41:00 +00:00
|
|
|
Symbol->setVariableValue(Value);
|
2009-06-24 01:03:06 +00:00
|
|
|
}
|
|
|
|
|
2010-11-01 14:28:48 +00:00
|
|
|
void MCAsmStreamer::EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {
|
|
|
|
OS << ".weakref " << *Alias << ", " << *Symbol;
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2010-12-03 00:55:40 +00:00
|
|
|
void MCAsmStreamer::EmitDwarfAdvanceLineAddr(int64_t LineDelta,
|
|
|
|
const MCSymbol *LastLabel,
|
|
|
|
const MCSymbol *Label) {
|
2010-12-10 07:39:47 +00:00
|
|
|
EmitDwarfSetLineAddr(LineDelta, Label,
|
|
|
|
getContext().getTargetAsmInfo().getPointerSize());
|
2010-12-03 00:55:40 +00:00
|
|
|
}
|
|
|
|
|
2009-10-16 01:34:54 +00:00
|
|
|
void MCAsmStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
|
2010-01-23 06:39:22 +00:00
|
|
|
MCSymbolAttr Attribute) {
|
2009-06-24 01:03:06 +00:00
|
|
|
switch (Attribute) {
|
2010-01-23 06:39:22 +00:00
|
|
|
case MCSA_Invalid: assert(0 && "Invalid symbol attribute");
|
2010-01-25 18:30:45 +00:00
|
|
|
case MCSA_ELF_TypeFunction: /// .type _foo, STT_FUNC # aka @function
|
|
|
|
case MCSA_ELF_TypeIndFunction: /// .type _foo, STT_GNU_IFUNC
|
|
|
|
case MCSA_ELF_TypeObject: /// .type _foo, STT_OBJECT # aka @object
|
|
|
|
case MCSA_ELF_TypeTLS: /// .type _foo, STT_TLS # aka @tls_object
|
|
|
|
case MCSA_ELF_TypeCommon: /// .type _foo, STT_COMMON # aka @common
|
|
|
|
case MCSA_ELF_TypeNoType: /// .type _foo, STT_NOTYPE # aka @notype
|
2010-11-13 04:55:06 +00:00
|
|
|
case MCSA_ELF_TypeGnuUniqueObject: /// .type _foo, @gnu_unique_object
|
2010-01-25 18:30:45 +00:00
|
|
|
assert(MAI.hasDotTypeDotSizeDirective() && "Symbol Attr not supported");
|
2010-02-04 01:42:13 +00:00
|
|
|
OS << "\t.type\t" << *Symbol << ','
|
2010-01-25 18:30:45 +00:00
|
|
|
<< ((MAI.getCommentString()[0] != '@') ? '@' : '%');
|
|
|
|
switch (Attribute) {
|
|
|
|
default: assert(0 && "Unknown ELF .type");
|
|
|
|
case MCSA_ELF_TypeFunction: OS << "function"; break;
|
|
|
|
case MCSA_ELF_TypeIndFunction: OS << "gnu_indirect_function"; break;
|
|
|
|
case MCSA_ELF_TypeObject: OS << "object"; break;
|
|
|
|
case MCSA_ELF_TypeTLS: OS << "tls_object"; break;
|
|
|
|
case MCSA_ELF_TypeCommon: OS << "common"; break;
|
|
|
|
case MCSA_ELF_TypeNoType: OS << "no_type"; break;
|
2010-11-13 04:55:06 +00:00
|
|
|
case MCSA_ELF_TypeGnuUniqueObject: OS << "gnu_unique_object"; break;
|
2010-01-25 18:30:45 +00:00
|
|
|
}
|
|
|
|
EmitEOL();
|
|
|
|
return;
|
|
|
|
case MCSA_Global: // .globl/.global
|
|
|
|
OS << MAI.getGlobalDirective();
|
|
|
|
break;
|
2010-06-21 20:35:01 +00:00
|
|
|
case MCSA_Hidden: OS << "\t.hidden\t"; break;
|
|
|
|
case MCSA_IndirectSymbol: OS << "\t.indirect_symbol\t"; break;
|
|
|
|
case MCSA_Internal: OS << "\t.internal\t"; break;
|
|
|
|
case MCSA_LazyReference: OS << "\t.lazy_reference\t"; break;
|
|
|
|
case MCSA_Local: OS << "\t.local\t"; break;
|
|
|
|
case MCSA_NoDeadStrip: OS << "\t.no_dead_strip\t"; break;
|
2010-11-19 18:39:33 +00:00
|
|
|
case MCSA_SymbolResolver: OS << "\t.symbol_resolver\t"; break;
|
2010-06-21 20:35:01 +00:00
|
|
|
case MCSA_PrivateExtern: OS << "\t.private_extern\t"; break;
|
|
|
|
case MCSA_Protected: OS << "\t.protected\t"; break;
|
|
|
|
case MCSA_Reference: OS << "\t.reference\t"; break;
|
|
|
|
case MCSA_Weak: OS << "\t.weak\t"; break;
|
|
|
|
case MCSA_WeakDefinition: OS << "\t.weak_definition\t"; break;
|
2010-01-23 06:39:22 +00:00
|
|
|
// .weak_reference
|
|
|
|
case MCSA_WeakReference: OS << MAI.getWeakRefDirective(); break;
|
2010-07-08 17:22:42 +00:00
|
|
|
case MCSA_WeakDefAutoPrivate: OS << "\t.weak_def_can_be_hidden\t"; break;
|
2009-06-24 01:03:06 +00:00
|
|
|
}
|
|
|
|
|
2010-01-22 07:36:39 +00:00
|
|
|
OS << *Symbol;
|
|
|
|
EmitEOL();
|
2009-06-24 01:03:06 +00:00
|
|
|
}
|
|
|
|
|
2009-07-14 18:17:10 +00:00
|
|
|
void MCAsmStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
|
2010-01-22 07:36:39 +00:00
|
|
|
OS << ".desc" << ' ' << *Symbol << ',' << DescValue;
|
|
|
|
EmitEOL();
|
2009-07-14 18:17:10 +00:00
|
|
|
}
|
|
|
|
|
2010-05-08 19:54:22 +00:00
|
|
|
void MCAsmStreamer::BeginCOFFSymbolDef(const MCSymbol *Symbol) {
|
|
|
|
OS << "\t.def\t " << *Symbol << ';';
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MCAsmStreamer::EmitCOFFSymbolStorageClass (int StorageClass) {
|
|
|
|
OS << "\t.scl\t" << StorageClass << ';';
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MCAsmStreamer::EmitCOFFSymbolType (int Type) {
|
|
|
|
OS << "\t.type\t" << Type << ';';
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MCAsmStreamer::EndCOFFSymbolDef() {
|
|
|
|
OS << "\t.endef";
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2010-01-25 07:52:13 +00:00
|
|
|
void MCAsmStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
|
|
|
|
assert(MAI.hasDotTypeDotSizeDirective());
|
|
|
|
OS << "\t.size\t" << *Symbol << ", " << *Value << '\n';
|
|
|
|
}
|
|
|
|
|
2010-01-23 07:47:02 +00:00
|
|
|
void MCAsmStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
|
2009-08-30 06:17:16 +00:00
|
|
|
unsigned ByteAlignment) {
|
2010-01-23 07:47:02 +00:00
|
|
|
OS << "\t.comm\t" << *Symbol << ',' << Size;
|
2010-01-25 07:29:13 +00:00
|
|
|
if (ByteAlignment != 0) {
|
2010-01-26 20:21:43 +00:00
|
|
|
if (MAI.getCOMMDirectiveAlignmentIsInBytes())
|
2010-01-19 06:01:04 +00:00
|
|
|
OS << ',' << ByteAlignment;
|
|
|
|
else
|
|
|
|
OS << ',' << Log2_32(ByteAlignment);
|
|
|
|
}
|
2010-01-22 07:36:39 +00:00
|
|
|
EmitEOL();
|
2009-07-07 20:30:46 +00:00
|
|
|
}
|
|
|
|
|
2010-01-23 07:47:02 +00:00
|
|
|
/// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol.
|
|
|
|
///
|
|
|
|
/// @param Symbol - The common symbol to emit.
|
|
|
|
/// @param Size - The size of the common symbol.
|
|
|
|
void MCAsmStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size) {
|
|
|
|
assert(MAI.hasLCOMMDirective() && "Doesn't have .lcomm, can't emit it!");
|
|
|
|
OS << "\t.lcomm\t" << *Symbol << ',' << Size;
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2009-08-28 05:48:22 +00:00
|
|
|
void MCAsmStreamer::EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
|
2009-08-30 06:17:16 +00:00
|
|
|
unsigned Size, unsigned ByteAlignment) {
|
2009-08-13 23:36:34 +00:00
|
|
|
// Note: a .zerofill directive does not switch sections.
|
2009-08-08 23:39:42 +00:00
|
|
|
OS << ".zerofill ";
|
2010-09-22 18:16:55 +00:00
|
|
|
|
2009-08-08 23:39:42 +00:00
|
|
|
// This is a mach-o specific directive.
|
2009-08-10 01:39:42 +00:00
|
|
|
const MCSectionMachO *MOSection = ((const MCSectionMachO*)Section);
|
2009-08-14 18:51:45 +00:00
|
|
|
OS << MOSection->getSegmentName() << "," << MOSection->getSectionName();
|
2010-09-22 18:16:55 +00:00
|
|
|
|
2009-07-10 22:20:30 +00:00
|
|
|
if (Symbol != NULL) {
|
2010-01-17 21:43:43 +00:00
|
|
|
OS << ',' << *Symbol << ',' << Size;
|
2009-08-30 06:17:16 +00:00
|
|
|
if (ByteAlignment != 0)
|
|
|
|
OS << ',' << Log2_32(ByteAlignment);
|
2009-07-10 22:20:30 +00:00
|
|
|
}
|
2010-01-22 07:36:39 +00:00
|
|
|
EmitEOL();
|
2009-07-10 22:20:30 +00:00
|
|
|
}
|
|
|
|
|
2010-05-17 02:13:02 +00:00
|
|
|
// .tbss sym, size, align
|
|
|
|
// This depends that the symbol has already been mangled from the original,
|
|
|
|
// e.g. _a.
|
2010-05-18 21:16:04 +00:00
|
|
|
void MCAsmStreamer::EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
|
|
|
|
uint64_t Size, unsigned ByteAlignment) {
|
2010-05-14 01:50:28 +00:00
|
|
|
assert(Symbol != NULL && "Symbol shouldn't be NULL!");
|
2010-05-18 21:16:04 +00:00
|
|
|
// Instead of using the Section we'll just use the shortcut.
|
|
|
|
// This is a mach-o specific directive and section.
|
2010-05-17 02:13:02 +00:00
|
|
|
OS << ".tbss " << *Symbol << ", " << Size;
|
2010-09-22 18:16:55 +00:00
|
|
|
|
2010-05-18 21:16:04 +00:00
|
|
|
// Output align if we have it. We default to 1 so don't bother printing
|
|
|
|
// that.
|
|
|
|
if (ByteAlignment > 1) OS << ", " << Log2_32(ByteAlignment);
|
2010-09-22 18:16:55 +00:00
|
|
|
|
2010-05-14 01:50:28 +00:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2010-01-23 00:15:00 +00:00
|
|
|
static inline char toOctal(int X) { return (X&7)+'0'; }
|
|
|
|
|
2010-01-25 18:58:59 +00:00
|
|
|
static void PrintQuotedString(StringRef Data, raw_ostream &OS) {
|
|
|
|
OS << '"';
|
2010-09-22 18:16:55 +00:00
|
|
|
|
2010-01-25 18:58:59 +00:00
|
|
|
for (unsigned i = 0, e = Data.size(); i != e; ++i) {
|
|
|
|
unsigned char C = Data[i];
|
|
|
|
if (C == '"' || C == '\\') {
|
|
|
|
OS << '\\' << (char)C;
|
|
|
|
continue;
|
|
|
|
}
|
2010-09-22 18:16:55 +00:00
|
|
|
|
2010-01-25 18:58:59 +00:00
|
|
|
if (isprint((unsigned char)C)) {
|
|
|
|
OS << (char)C;
|
|
|
|
continue;
|
|
|
|
}
|
2010-09-22 18:16:55 +00:00
|
|
|
|
2010-01-25 18:58:59 +00:00
|
|
|
switch (C) {
|
|
|
|
case '\b': OS << "\\b"; break;
|
|
|
|
case '\f': OS << "\\f"; break;
|
|
|
|
case '\n': OS << "\\n"; break;
|
|
|
|
case '\r': OS << "\\r"; break;
|
|
|
|
case '\t': OS << "\\t"; break;
|
|
|
|
default:
|
|
|
|
OS << '\\';
|
|
|
|
OS << toOctal(C >> 6);
|
|
|
|
OS << toOctal(C >> 3);
|
|
|
|
OS << toOctal(C >> 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-09-22 18:16:55 +00:00
|
|
|
|
2010-01-25 18:58:59 +00:00
|
|
|
OS << '"';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-19 19:46:13 +00:00
|
|
|
void MCAsmStreamer::EmitBytes(StringRef Data, unsigned AddrSpace) {
|
2009-06-24 17:00:42 +00:00
|
|
|
assert(CurSection && "Cannot emit contents before setting section!");
|
2010-01-23 00:15:00 +00:00
|
|
|
if (Data.empty()) return;
|
2010-09-22 18:16:55 +00:00
|
|
|
|
2010-01-23 00:15:00 +00:00
|
|
|
if (Data.size() == 1) {
|
|
|
|
OS << MAI.getData8bitsDirective(AddrSpace);
|
|
|
|
OS << (unsigned)(unsigned char)Data[0];
|
2010-01-22 07:36:39 +00:00
|
|
|
EmitEOL();
|
2010-01-23 00:15:00 +00:00
|
|
|
return;
|
2010-01-22 07:36:39 +00:00
|
|
|
}
|
2010-01-23 00:15:00 +00:00
|
|
|
|
|
|
|
// If the data ends with 0 and the target supports .asciz, use it, otherwise
|
|
|
|
// use .ascii
|
|
|
|
if (MAI.getAscizDirective() && Data.back() == 0) {
|
|
|
|
OS << MAI.getAscizDirective();
|
|
|
|
Data = Data.substr(0, Data.size()-1);
|
|
|
|
} else {
|
|
|
|
OS << MAI.getAsciiDirective();
|
|
|
|
}
|
|
|
|
|
2010-01-25 18:58:59 +00:00
|
|
|
OS << ' ';
|
|
|
|
PrintQuotedString(Data, OS);
|
2010-01-23 00:15:00 +00:00
|
|
|
EmitEOL();
|
2009-06-24 01:03:06 +00:00
|
|
|
}
|
|
|
|
|
2010-12-03 02:54:21 +00:00
|
|
|
void MCAsmStreamer::EmitIntValue(uint64_t Value, unsigned Size,
|
|
|
|
unsigned AddrSpace) {
|
|
|
|
EmitValue(MCConstantExpr::Create(Value, getContext()), Size, AddrSpace);
|
|
|
|
}
|
|
|
|
|
2010-12-10 07:39:47 +00:00
|
|
|
void MCAsmStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
|
|
|
|
bool isPCRel, unsigned AddrSpace) {
|
2010-01-19 22:03:38 +00:00
|
|
|
assert(CurSection && "Cannot emit contents before setting section!");
|
2010-12-10 07:39:47 +00:00
|
|
|
assert(!isPCRel && "Cannot emit pc relative relocations!");
|
2010-01-19 22:03:38 +00:00
|
|
|
const char *Directive = 0;
|
|
|
|
switch (Size) {
|
|
|
|
default: break;
|
|
|
|
case 1: Directive = MAI.getData8bitsDirective(AddrSpace); break;
|
|
|
|
case 2: Directive = MAI.getData16bitsDirective(AddrSpace); break;
|
|
|
|
case 4: Directive = MAI.getData32bitsDirective(AddrSpace); break;
|
2010-01-20 06:45:39 +00:00
|
|
|
case 8:
|
|
|
|
Directive = MAI.getData64bitsDirective(AddrSpace);
|
|
|
|
// If the target doesn't support 64-bit data, emit as two 32-bit halves.
|
|
|
|
if (Directive) break;
|
2010-11-28 23:22:44 +00:00
|
|
|
int64_t IntValue;
|
|
|
|
if (!Value->EvaluateAsAbsolute(IntValue))
|
|
|
|
report_fatal_error("Don't know how to emit this value.");
|
2010-12-10 07:39:47 +00:00
|
|
|
if (getContext().getTargetAsmInfo().isLittleEndian()) {
|
2010-11-28 23:22:44 +00:00
|
|
|
EmitIntValue((uint32_t)(IntValue >> 0 ), 4, AddrSpace);
|
|
|
|
EmitIntValue((uint32_t)(IntValue >> 32), 4, AddrSpace);
|
2010-01-20 06:45:39 +00:00
|
|
|
} else {
|
2010-11-28 23:22:44 +00:00
|
|
|
EmitIntValue((uint32_t)(IntValue >> 32), 4, AddrSpace);
|
|
|
|
EmitIntValue((uint32_t)(IntValue >> 0 ), 4, AddrSpace);
|
2010-01-20 06:45:39 +00:00
|
|
|
}
|
|
|
|
return;
|
2010-01-19 22:03:38 +00:00
|
|
|
}
|
2010-09-22 18:16:55 +00:00
|
|
|
|
2010-01-19 22:03:38 +00:00
|
|
|
assert(Directive && "Invalid size for machine code value!");
|
2010-01-25 21:28:50 +00:00
|
|
|
OS << Directive << *Value;
|
2010-01-22 07:29:22 +00:00
|
|
|
EmitEOL();
|
2009-06-24 01:03:06 +00:00
|
|
|
}
|
|
|
|
|
2010-11-02 17:22:24 +00:00
|
|
|
void MCAsmStreamer::EmitULEB128Value(const MCExpr *Value, unsigned AddrSpace) {
|
2010-11-19 04:10:13 +00:00
|
|
|
int64_t IntValue;
|
|
|
|
if (Value->EvaluateAsAbsolute(IntValue)) {
|
2010-12-03 01:19:49 +00:00
|
|
|
EmitULEB128IntValue(IntValue, AddrSpace);
|
2010-11-19 04:10:13 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-11-04 18:17:08 +00:00
|
|
|
assert(MAI.hasLEB128() && "Cannot print a .uleb");
|
|
|
|
OS << ".uleb128 " << *Value;
|
2010-11-02 17:22:24 +00:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MCAsmStreamer::EmitSLEB128Value(const MCExpr *Value, unsigned AddrSpace) {
|
2010-11-19 04:10:13 +00:00
|
|
|
int64_t IntValue;
|
|
|
|
if (Value->EvaluateAsAbsolute(IntValue)) {
|
2010-12-03 01:19:49 +00:00
|
|
|
EmitSLEB128IntValue(IntValue, AddrSpace);
|
2010-11-19 04:10:13 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-11-04 18:17:08 +00:00
|
|
|
assert(MAI.hasLEB128() && "Cannot print a .sleb");
|
|
|
|
OS << ".sleb128 " << *Value;
|
2010-11-02 17:22:24 +00:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2010-01-25 21:28:50 +00:00
|
|
|
void MCAsmStreamer::EmitGPRel32Value(const MCExpr *Value) {
|
|
|
|
assert(MAI.getGPRel32Directive() != 0);
|
|
|
|
OS << MAI.getGPRel32Directive() << *Value;
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-19 18:52:28 +00:00
|
|
|
/// EmitFill - Emit NumBytes bytes worth of the value specified by
|
|
|
|
/// FillValue. This implements directives such as '.space'.
|
2010-01-19 19:46:13 +00:00
|
|
|
void MCAsmStreamer::EmitFill(uint64_t NumBytes, uint8_t FillValue,
|
|
|
|
unsigned AddrSpace) {
|
2010-01-19 18:58:52 +00:00
|
|
|
if (NumBytes == 0) return;
|
2010-09-22 18:16:55 +00:00
|
|
|
|
2010-01-19 19:46:13 +00:00
|
|
|
if (AddrSpace == 0)
|
|
|
|
if (const char *ZeroDirective = MAI.getZeroDirective()) {
|
|
|
|
OS << ZeroDirective << NumBytes;
|
|
|
|
if (FillValue != 0)
|
|
|
|
OS << ',' << (int)FillValue;
|
2010-01-22 07:29:22 +00:00
|
|
|
EmitEOL();
|
2010-01-19 19:46:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Emit a byte at a time.
|
|
|
|
MCStreamer::EmitFill(NumBytes, FillValue, AddrSpace);
|
2010-01-19 18:52:28 +00:00
|
|
|
}
|
|
|
|
|
2009-06-24 19:25:34 +00:00
|
|
|
void MCAsmStreamer::EmitValueToAlignment(unsigned ByteAlignment, int64_t Value,
|
|
|
|
unsigned ValueSize,
|
|
|
|
unsigned MaxBytesToEmit) {
|
2009-08-19 06:12:02 +00:00
|
|
|
// Some assemblers don't support non-power of two alignments, so we always
|
|
|
|
// emit alignments as a power of two if possible.
|
|
|
|
if (isPowerOf2_32(ByteAlignment)) {
|
2009-08-19 06:35:36 +00:00
|
|
|
switch (ValueSize) {
|
|
|
|
default: llvm_unreachable("Invalid size for machine code value!");
|
2009-08-22 21:43:10 +00:00
|
|
|
case 1: OS << MAI.getAlignDirective(); break;
|
|
|
|
// FIXME: use MAI for this!
|
2009-08-19 06:35:36 +00:00
|
|
|
case 2: OS << ".p2alignw "; break;
|
|
|
|
case 4: OS << ".p2alignl "; break;
|
|
|
|
case 8: llvm_unreachable("Unsupported alignment size!");
|
|
|
|
}
|
2010-09-22 18:16:55 +00:00
|
|
|
|
2009-08-22 21:43:10 +00:00
|
|
|
if (MAI.getAlignmentIsInBytes())
|
2009-08-19 06:12:02 +00:00
|
|
|
OS << ByteAlignment;
|
|
|
|
else
|
|
|
|
OS << Log2_32(ByteAlignment);
|
|
|
|
|
|
|
|
if (Value || MaxBytesToEmit) {
|
2009-09-03 04:01:10 +00:00
|
|
|
OS << ", 0x";
|
|
|
|
OS.write_hex(truncateToSize(Value, ValueSize));
|
2009-06-24 19:25:34 +00:00
|
|
|
|
2010-09-22 18:16:55 +00:00
|
|
|
if (MaxBytesToEmit)
|
2009-08-19 06:12:02 +00:00
|
|
|
OS << ", " << MaxBytesToEmit;
|
|
|
|
}
|
2010-01-22 07:36:39 +00:00
|
|
|
EmitEOL();
|
2009-08-19 06:12:02 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-09-22 18:16:55 +00:00
|
|
|
|
2009-08-19 06:12:02 +00:00
|
|
|
// Non-power of two alignment. This is not widely supported by assemblers.
|
2009-08-22 21:43:10 +00:00
|
|
|
// FIXME: Parameterize this based on MAI.
|
2009-06-24 19:25:34 +00:00
|
|
|
switch (ValueSize) {
|
2009-08-19 06:12:02 +00:00
|
|
|
default: llvm_unreachable("Invalid size for machine code value!");
|
|
|
|
case 1: OS << ".balign"; break;
|
|
|
|
case 2: OS << ".balignw"; break;
|
|
|
|
case 4: OS << ".balignl"; break;
|
|
|
|
case 8: llvm_unreachable("Unsupported alignment size!");
|
2009-06-24 19:25:34 +00:00
|
|
|
}
|
|
|
|
|
2009-08-19 06:12:02 +00:00
|
|
|
OS << ' ' << ByteAlignment;
|
2009-06-25 21:03:18 +00:00
|
|
|
OS << ", " << truncateToSize(Value, ValueSize);
|
2010-09-22 18:16:55 +00:00
|
|
|
if (MaxBytesToEmit)
|
2009-06-24 19:25:34 +00:00
|
|
|
OS << ", " << MaxBytesToEmit;
|
2010-01-22 07:36:39 +00:00
|
|
|
EmitEOL();
|
2009-06-24 19:25:34 +00:00
|
|
|
}
|
|
|
|
|
2010-02-23 18:26:34 +00:00
|
|
|
void MCAsmStreamer::EmitCodeAlignment(unsigned ByteAlignment,
|
|
|
|
unsigned MaxBytesToEmit) {
|
2010-02-23 18:44:31 +00:00
|
|
|
// Emit with a text fill value.
|
|
|
|
EmitValueToAlignment(ByteAlignment, MAI.getTextAlignFillValue(),
|
|
|
|
1, MaxBytesToEmit);
|
2010-02-23 18:26:34 +00:00
|
|
|
}
|
|
|
|
|
2009-08-31 08:09:28 +00:00
|
|
|
void MCAsmStreamer::EmitValueToOffset(const MCExpr *Offset,
|
2009-06-24 19:25:34 +00:00
|
|
|
unsigned char Value) {
|
|
|
|
// FIXME: Verify that Offset is associated with the current section.
|
2010-01-22 07:36:39 +00:00
|
|
|
OS << ".org " << *Offset << ", " << (unsigned) Value;
|
|
|
|
EmitEOL();
|
2009-06-24 19:25:34 +00:00
|
|
|
}
|
|
|
|
|
2010-01-25 18:58:59 +00:00
|
|
|
|
|
|
|
void MCAsmStreamer::EmitFileDirective(StringRef Filename) {
|
|
|
|
assert(MAI.hasSingleParameterDotFile());
|
|
|
|
OS << "\t.file\t";
|
|
|
|
PrintQuotedString(Filename, OS);
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2010-11-16 21:20:32 +00:00
|
|
|
bool MCAsmStreamer::EmitDwarfFileDirective(unsigned FileNo, StringRef Filename){
|
2010-12-10 07:39:47 +00:00
|
|
|
if (UseLoc) {
|
2010-11-19 02:26:16 +00:00
|
|
|
OS << "\t.file\t" << FileNo << ' ';
|
|
|
|
PrintQuotedString(Filename, OS);
|
|
|
|
EmitEOL();
|
|
|
|
}
|
2010-11-16 21:20:32 +00:00
|
|
|
return this->MCStreamer::EmitDwarfFileDirective(FileNo, Filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MCAsmStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
|
|
|
|
unsigned Column, unsigned Flags,
|
|
|
|
unsigned Isa,
|
|
|
|
unsigned Discriminator) {
|
2010-11-19 02:26:16 +00:00
|
|
|
this->MCStreamer::EmitDwarfLocDirective(FileNo, Line, Column, Flags,
|
|
|
|
Isa, Discriminator);
|
2010-12-10 07:39:47 +00:00
|
|
|
if (!UseLoc)
|
2010-11-19 02:26:16 +00:00
|
|
|
return;
|
|
|
|
|
2010-11-16 21:20:32 +00:00
|
|
|
OS << "\t.loc\t" << FileNo << " " << Line << " " << Column;
|
|
|
|
if (Flags & DWARF2_FLAG_BASIC_BLOCK)
|
|
|
|
OS << " basic_block";
|
|
|
|
if (Flags & DWARF2_FLAG_PROLOGUE_END)
|
|
|
|
OS << " prologue_end";
|
|
|
|
if (Flags & DWARF2_FLAG_EPILOGUE_BEGIN)
|
|
|
|
OS << " epilogue_begin";
|
|
|
|
|
|
|
|
unsigned OldFlags = getContext().getCurrentDwarfLoc().getFlags();
|
|
|
|
if ((Flags & DWARF2_FLAG_IS_STMT) != (OldFlags & DWARF2_FLAG_IS_STMT)) {
|
|
|
|
OS << " is_stmt ";
|
|
|
|
|
|
|
|
if (Flags & DWARF2_FLAG_IS_STMT)
|
|
|
|
OS << "1";
|
|
|
|
else
|
|
|
|
OS << "0";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Isa)
|
|
|
|
OS << "isa " << Isa;
|
|
|
|
if (Discriminator)
|
|
|
|
OS << "discriminator " << Discriminator;
|
|
|
|
EmitEOL();
|
2010-01-25 18:58:59 +00:00
|
|
|
}
|
|
|
|
|
2010-11-22 14:27:24 +00:00
|
|
|
bool MCAsmStreamer::EmitCFIStartProc() {
|
|
|
|
if (this->MCStreamer::EmitCFIStartProc())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
OS << ".cfi_startproc";
|
|
|
|
EmitEOL();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MCAsmStreamer::EmitCFIEndProc() {
|
|
|
|
if (this->MCStreamer::EmitCFIEndProc())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
OS << ".cfi_endproc";
|
|
|
|
EmitEOL();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MCAsmStreamer::EmitCFIDefCfaOffset(int64_t Offset) {
|
|
|
|
if (this->MCStreamer::EmitCFIDefCfaOffset(Offset))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
OS << ".cfi_def_cfa_offset " << Offset;
|
|
|
|
EmitEOL();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MCAsmStreamer::EmitCFIDefCfaRegister(int64_t Register) {
|
|
|
|
if (this->MCStreamer::EmitCFIDefCfaRegister(Register))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
OS << ".cfi_def_cfa_register " << Register;
|
|
|
|
EmitEOL();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MCAsmStreamer::EmitCFIOffset(int64_t Register, int64_t Offset) {
|
|
|
|
if (this->MCStreamer::EmitCFIOffset(Register, Offset))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
OS << ".cfi_offset " << Register << ", " << Offset;
|
|
|
|
EmitEOL();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-12-27 00:36:05 +00:00
|
|
|
bool MCAsmStreamer::EmitCFIPersonality(const MCSymbol *Sym,
|
|
|
|
unsigned Encoding) {
|
|
|
|
if (this->MCStreamer::EmitCFIPersonality(Sym, Encoding))
|
2010-11-22 14:27:24 +00:00
|
|
|
return true;
|
|
|
|
|
2010-12-27 00:36:05 +00:00
|
|
|
OS << ".cfi_personality " << Encoding << ", " << *Sym;
|
2010-11-22 14:27:24 +00:00
|
|
|
EmitEOL();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-12-27 15:56:22 +00:00
|
|
|
bool MCAsmStreamer::EmitCFILsda(const MCSymbol *Sym, unsigned Encoding) {
|
|
|
|
if (this->MCStreamer::EmitCFILsda(Sym, Encoding))
|
2010-11-22 14:27:24 +00:00
|
|
|
return true;
|
|
|
|
|
2010-12-27 15:56:22 +00:00
|
|
|
OS << ".cfi_lsda " << Encoding << ", " << *Sym;
|
2010-11-22 14:27:24 +00:00
|
|
|
EmitEOL();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-02-09 23:00:14 +00:00
|
|
|
void MCAsmStreamer::AddEncodingComment(const MCInst &Inst) {
|
|
|
|
raw_ostream &OS = GetCommentOS();
|
|
|
|
SmallString<256> Code;
|
|
|
|
SmallVector<MCFixup, 4> Fixups;
|
|
|
|
raw_svector_ostream VecOS(Code);
|
|
|
|
Emitter->EncodeInstruction(Inst, VecOS, Fixups);
|
|
|
|
VecOS.flush();
|
2010-01-25 18:58:59 +00:00
|
|
|
|
2010-02-09 23:00:14 +00:00
|
|
|
// If we are showing fixups, create symbolic markers in the encoded
|
|
|
|
// representation. We do this by making a per-bit map to the fixup item index,
|
|
|
|
// then trying to display it as nicely as possible.
|
2010-02-10 01:41:14 +00:00
|
|
|
SmallVector<uint8_t, 64> FixupMap;
|
|
|
|
FixupMap.resize(Code.size() * 8);
|
2010-02-09 23:00:14 +00:00
|
|
|
for (unsigned i = 0, e = Code.size() * 8; i != e; ++i)
|
|
|
|
FixupMap[i] = 0;
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
|
|
|
|
MCFixup &F = Fixups[i];
|
2010-12-16 03:20:06 +00:00
|
|
|
const MCFixupKindInfo &Info = AsmBackend->getFixupKindInfo(F.getKind());
|
2010-02-09 23:00:14 +00:00
|
|
|
for (unsigned j = 0; j != Info.TargetSize; ++j) {
|
|
|
|
unsigned Index = F.getOffset() * 8 + Info.TargetOffset + j;
|
|
|
|
assert(Index < Code.size() * 8 && "Invalid offset in fixup!");
|
|
|
|
FixupMap[Index] = 1 + i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OS << "encoding: [";
|
|
|
|
for (unsigned i = 0, e = Code.size(); i != e; ++i) {
|
|
|
|
if (i)
|
|
|
|
OS << ',';
|
|
|
|
|
|
|
|
// See if all bits are the same map entry.
|
|
|
|
uint8_t MapEntry = FixupMap[i * 8 + 0];
|
|
|
|
for (unsigned j = 1; j != 8; ++j) {
|
|
|
|
if (FixupMap[i * 8 + j] == MapEntry)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
MapEntry = uint8_t(~0U);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MapEntry != uint8_t(~0U)) {
|
|
|
|
if (MapEntry == 0) {
|
|
|
|
OS << format("0x%02x", uint8_t(Code[i]));
|
|
|
|
} else {
|
|
|
|
assert(Code[i] == 0 && "Encoder wrote into fixed up bit!");
|
|
|
|
OS << char('A' + MapEntry - 1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Otherwise, write out in binary.
|
|
|
|
OS << "0b";
|
|
|
|
for (unsigned j = 8; j--;) {
|
|
|
|
unsigned Bit = (Code[i] >> j) & 1;
|
2010-11-15 05:56:19 +00:00
|
|
|
|
|
|
|
unsigned FixupBit;
|
2010-12-10 07:39:47 +00:00
|
|
|
if (getContext().getTargetAsmInfo().isLittleEndian())
|
2010-11-15 05:56:19 +00:00
|
|
|
FixupBit = i * 8 + j;
|
|
|
|
else
|
|
|
|
FixupBit = i * 8 + (7-j);
|
|
|
|
|
|
|
|
if (uint8_t MapEntry = FixupMap[FixupBit]) {
|
2010-02-09 23:00:14 +00:00
|
|
|
assert(Bit == 0 && "Encoder wrote into fixed up bit!");
|
|
|
|
OS << char('A' + MapEntry - 1);
|
|
|
|
} else
|
|
|
|
OS << Bit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OS << "]\n";
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
|
|
|
|
MCFixup &F = Fixups[i];
|
2010-12-16 03:20:06 +00:00
|
|
|
const MCFixupKindInfo &Info = AsmBackend->getFixupKindInfo(F.getKind());
|
2010-02-09 23:00:14 +00:00
|
|
|
OS << " fixup " << char('A' + i) << " - " << "offset: " << F.getOffset()
|
2010-02-10 04:47:08 +00:00
|
|
|
<< ", value: " << *F.getValue() << ", kind: " << Info.Name << "\n";
|
2010-02-09 23:00:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MCAsmStreamer::EmitInstruction(const MCInst &Inst) {
|
|
|
|
assert(CurSection && "Cannot emit contents before setting section!");
|
|
|
|
|
2010-12-10 07:39:47 +00:00
|
|
|
if (!UseLoc)
|
2010-11-19 02:26:16 +00:00
|
|
|
MCLineEntry::Make(this, getCurrentSection());
|
|
|
|
|
2010-02-09 23:00:14 +00:00
|
|
|
// Show the encoding in a comment if we have a code emitter.
|
|
|
|
if (Emitter)
|
|
|
|
AddEncodingComment(Inst);
|
|
|
|
|
2010-02-09 00:54:51 +00:00
|
|
|
// Show the MCInst if enabled.
|
2010-05-26 15:18:13 +00:00
|
|
|
if (ShowInst) {
|
2010-03-22 21:49:34 +00:00
|
|
|
Inst.dump_pretty(GetCommentOS(), &MAI, InstPrinter.get(), "\n ");
|
2010-05-26 15:18:13 +00:00
|
|
|
GetCommentOS() << "\n";
|
|
|
|
}
|
|
|
|
|
2010-03-22 21:49:34 +00:00
|
|
|
// If we have an AsmPrinter, use that to print, otherwise print the MCInst.
|
2010-02-03 18:18:30 +00:00
|
|
|
if (InstPrinter)
|
2010-04-04 05:04:31 +00:00
|
|
|
InstPrinter->printInst(&Inst, OS);
|
2010-02-03 18:18:30 +00:00
|
|
|
else
|
|
|
|
Inst.print(OS, &MAI);
|
2010-01-22 07:36:39 +00:00
|
|
|
EmitEOL();
|
2009-06-24 01:03:06 +00:00
|
|
|
}
|
|
|
|
|
2010-09-22 18:18:30 +00:00
|
|
|
/// EmitRawText - If this file is backed by an assembly streamer, this dumps
|
2010-04-03 21:35:55 +00:00
|
|
|
/// the specified string in the output .s file. This capability is
|
|
|
|
/// indicated by the hasRawTextSupport() predicate.
|
|
|
|
void MCAsmStreamer::EmitRawText(StringRef String) {
|
2010-04-03 22:06:56 +00:00
|
|
|
if (!String.empty() && String.back() == '\n')
|
|
|
|
String = String.substr(0, String.size()-1);
|
2010-04-03 21:35:55 +00:00
|
|
|
OS << String;
|
2010-04-03 22:06:56 +00:00
|
|
|
EmitEOL();
|
2010-04-03 21:35:55 +00:00
|
|
|
}
|
|
|
|
|
2009-06-24 01:03:06 +00:00
|
|
|
void MCAsmStreamer::Finish() {
|
2010-11-19 02:26:16 +00:00
|
|
|
// Dump out the dwarf file & directory tables and line tables.
|
2010-12-10 07:39:47 +00:00
|
|
|
if (getContext().hasDwarfFiles() && !UseLoc)
|
|
|
|
MCDwarfFileTable::Emit(this);
|
2009-06-24 01:03:06 +00:00
|
|
|
}
|
2010-02-03 18:18:30 +00:00
|
|
|
|
2010-01-22 07:29:22 +00:00
|
|
|
MCStreamer *llvm::createAsmStreamer(MCContext &Context,
|
|
|
|
formatted_raw_ostream &OS,
|
2010-12-10 07:39:47 +00:00
|
|
|
bool isVerboseAsm, bool useLoc,
|
2010-12-16 03:05:59 +00:00
|
|
|
MCInstPrinter *IP, MCCodeEmitter *CE,
|
|
|
|
TargetAsmBackend *TAB, bool ShowInst) {
|
2010-12-10 07:39:47 +00:00
|
|
|
return new MCAsmStreamer(Context, OS, isVerboseAsm, useLoc,
|
2010-12-16 03:05:59 +00:00
|
|
|
IP, CE, TAB, ShowInst);
|
2009-06-24 01:03:06 +00:00
|
|
|
}
|