2009-06-24 09:03:06 +08: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"
|
2014-04-24 22:33:36 +08:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2015-01-14 19:23:27 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
|
|
|
#include "llvm/ADT/Twine.h"
|
|
|
|
#include "llvm/MC/MCAsmBackend.h"
|
2009-08-31 16:08:38 +08:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2009-08-27 08:51:57 +08:00
|
|
|
#include "llvm/MC/MCCodeEmitter.h"
|
2009-06-24 09:03:06 +08:00
|
|
|
#include "llvm/MC/MCContext.h"
|
2009-08-31 16:08:38 +08:00
|
|
|
#include "llvm/MC/MCExpr.h"
|
2010-12-16 11:20:06 +08:00
|
|
|
#include "llvm/MC/MCFixupKindInfo.h"
|
2009-07-01 14:35:03 +08:00
|
|
|
#include "llvm/MC/MCInst.h"
|
2009-09-14 11:02:37 +08:00
|
|
|
#include "llvm/MC/MCInstPrinter.h"
|
2011-07-27 04:57:44 +08:00
|
|
|
#include "llvm/MC/MCObjectFileInfo.h"
|
2011-07-19 04:57:22 +08:00
|
|
|
#include "llvm/MC/MCRegisterInfo.h"
|
2011-07-20 13:58:47 +08:00
|
|
|
#include "llvm/MC/MCSectionCOFF.h"
|
2009-08-11 02:15:01 +08:00
|
|
|
#include "llvm/MC/MCSectionMachO.h"
|
2009-06-24 09:03:06 +08:00
|
|
|
#include "llvm/MC/MCSymbol.h"
|
2013-10-06 00:42:21 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2009-07-12 04:10:48 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2009-08-27 08:51:57 +08:00
|
|
|
#include "llvm/Support/Format.h"
|
2010-01-22 15:29:22 +08:00
|
|
|
#include "llvm/Support/FormattedStream.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Support/MathExtras.h"
|
2013-06-12 06:21:28 +08:00
|
|
|
#include "llvm/Support/Path.h"
|
2010-12-20 04:43:38 +08:00
|
|
|
#include <cctype>
|
2009-06-24 09:03:06 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2015-04-09 21:04:20 +08:00
|
|
|
class MCAsmStreamer final : public MCStreamer {
|
2015-04-10 05:06:08 +08:00
|
|
|
std::unique_ptr<formatted_raw_ostream> OSOwner;
|
2010-01-22 15:29:22 +08:00
|
|
|
formatted_raw_ostream &OS;
|
2013-06-18 15:20:20 +08:00
|
|
|
const MCAsmInfo *MAI;
|
2014-03-06 13:51:42 +08:00
|
|
|
std::unique_ptr<MCInstPrinter> InstPrinter;
|
|
|
|
std::unique_ptr<MCCodeEmitter> Emitter;
|
|
|
|
std::unique_ptr<MCAsmBackend> AsmBackend;
|
2010-09-23 02:16:55 +08:00
|
|
|
|
2010-01-22 15:29:22 +08:00
|
|
|
SmallString<128> CommentToEmit;
|
2010-01-23 03:17:48 +08:00
|
|
|
raw_svector_ostream CommentStream;
|
2010-02-04 02:18:30 +08:00
|
|
|
|
|
|
|
unsigned IsVerboseAsm : 1;
|
|
|
|
unsigned ShowInst : 1;
|
2011-10-18 07:05:28 +08:00
|
|
|
unsigned UseDwarfDirectory : 1;
|
2010-02-04 02:18:30 +08:00
|
|
|
|
2011-05-31 04:20:15 +08:00
|
|
|
void EmitRegisterName(int64_t Register);
|
2014-11-03 20:19:03 +08:00
|
|
|
void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame) override;
|
2014-03-08 15:02:02 +08:00
|
|
|
void EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) override;
|
2011-05-31 04:20:15 +08:00
|
|
|
|
2009-08-17 12:17:34 +08:00
|
|
|
public:
|
2015-04-10 05:06:08 +08:00
|
|
|
MCAsmStreamer(MCContext &Context, std::unique_ptr<formatted_raw_ostream> os,
|
2014-05-12 21:07:11 +08:00
|
|
|
bool isVerboseAsm, bool useDwarfDirectory,
|
2014-02-06 02:00:21 +08:00
|
|
|
MCInstPrinter *printer, MCCodeEmitter *emitter,
|
|
|
|
MCAsmBackend *asmbackend, bool showInst)
|
2015-04-10 05:06:08 +08:00
|
|
|
: MCStreamer(Context), OSOwner(std::move(os)), OS(*OSOwner),
|
|
|
|
MAI(Context.getAsmInfo()), InstPrinter(printer), Emitter(emitter),
|
|
|
|
AsmBackend(asmbackend), CommentStream(CommentToEmit),
|
|
|
|
IsVerboseAsm(isVerboseAsm), ShowInst(showInst),
|
|
|
|
UseDwarfDirectory(useDwarfDirectory) {
|
2010-02-10 08:10:18 +08:00
|
|
|
if (InstPrinter && IsVerboseAsm)
|
|
|
|
InstPrinter->setCommentStream(CommentStream);
|
|
|
|
}
|
2009-06-24 09:03:06 +08:00
|
|
|
|
2010-01-22 15:29:22 +08:00
|
|
|
inline void EmitEOL() {
|
2010-01-23 03:17:48 +08:00
|
|
|
// If we don't have any comments, just emit a \n.
|
|
|
|
if (!IsVerboseAsm) {
|
2010-01-22 15:29:22 +08:00
|
|
|
OS << '\n';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
EmitCommentsAndEOL();
|
|
|
|
}
|
|
|
|
void EmitCommentsAndEOL();
|
2010-02-03 07:37:42 +08:00
|
|
|
|
|
|
|
/// isVerboseAsm - Return true if this streamer supports verbose assembly at
|
|
|
|
/// all.
|
2014-03-08 15:02:02 +08:00
|
|
|
bool isVerboseAsm() const override { return IsVerboseAsm; }
|
2010-09-23 02:16:55 +08:00
|
|
|
|
2010-04-04 05:35:55 +08:00
|
|
|
/// hasRawTextSupport - We support EmitRawText.
|
2014-03-08 15:02:02 +08:00
|
|
|
bool hasRawTextSupport() const override { return true; }
|
2010-02-10 07:00:14 +08:00
|
|
|
|
2010-01-23 02:21:35 +08:00
|
|
|
/// AddComment - Add a comment that can be emitted to the generated .s
|
2010-01-22 15:29:22 +08: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.
|
2014-03-08 15:02:02 +08:00
|
|
|
void AddComment(const Twine &T) override;
|
2010-02-10 07:00:14 +08:00
|
|
|
|
|
|
|
/// AddEncodingComment - Add a comment showing the encoding of an instruction.
|
2014-03-08 15:07:08 +08:00
|
|
|
void AddEncodingComment(const MCInst &Inst, const MCSubtargetInfo &);
|
2010-02-10 07:00:14 +08:00
|
|
|
|
2010-01-23 03:17:48 +08: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.
|
2014-03-08 15:02:02 +08:00
|
|
|
raw_ostream &GetCommentOS() override {
|
2010-01-23 03:17:48 +08:00
|
|
|
if (!IsVerboseAsm)
|
|
|
|
return nulls(); // Discard comments unless in verbose asm mode.
|
|
|
|
return CommentStream;
|
|
|
|
}
|
2010-02-10 07:00:14 +08:00
|
|
|
|
2014-03-02 17:09:27 +08:00
|
|
|
void emitRawComment(const Twine &T, bool TabPrefix = true) override;
|
2014-01-17 00:28:37 +08:00
|
|
|
|
2010-01-23 03:52:01 +08:00
|
|
|
/// AddBlankLine - Emit a blank line to a .s file to pretty it up.
|
2014-03-08 15:02:02 +08:00
|
|
|
void AddBlankLine() override {
|
2010-01-23 03:52:01 +08:00
|
|
|
EmitEOL();
|
|
|
|
}
|
2010-02-10 07:00:14 +08:00
|
|
|
|
2009-08-17 12:17:34 +08:00
|
|
|
/// @name MCStreamer Interface
|
|
|
|
/// @{
|
2009-06-24 09:03:06 +08:00
|
|
|
|
2015-05-22 03:20:38 +08:00
|
|
|
void ChangeSection(MCSection *Section, const MCExpr *Subsection) override;
|
2014-03-08 15:02:02 +08:00
|
|
|
|
2014-03-29 15:34:53 +08:00
|
|
|
void EmitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) override;
|
2014-03-08 15:02:02 +08:00
|
|
|
void EmitLabel(MCSymbol *Symbol) override;
|
|
|
|
|
|
|
|
void EmitAssemblerFlag(MCAssemblerFlag Flag) override;
|
|
|
|
void EmitLinkerOptions(ArrayRef<std::string> Options) override;
|
|
|
|
void EmitDataRegion(MCDataRegionType Kind) override;
|
2014-03-19 06:09:05 +08:00
|
|
|
void EmitVersionMin(MCVersionMinType Kind, unsigned Major, unsigned Minor,
|
|
|
|
unsigned Update) override;
|
2014-03-08 15:02:02 +08:00
|
|
|
void EmitThumbFunc(MCSymbol *Func) override;
|
|
|
|
|
|
|
|
void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
|
|
|
|
void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;
|
|
|
|
bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
|
|
|
|
|
|
|
|
void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override;
|
|
|
|
void BeginCOFFSymbolDef(const MCSymbol *Symbol) override;
|
|
|
|
void EmitCOFFSymbolStorageClass(int StorageClass) override;
|
|
|
|
void EmitCOFFSymbolType(int Type) override;
|
|
|
|
void EndCOFFSymbolDef() override;
|
|
|
|
void EmitCOFFSectionIndex(MCSymbol const *Symbol) override;
|
|
|
|
void EmitCOFFSecRel32(MCSymbol const *Symbol) override;
|
|
|
|
void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) override;
|
|
|
|
void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
|
|
|
|
unsigned ByteAlignment) override;
|
2009-07-15 02:17:10 +08:00
|
|
|
|
2010-01-23 15:47:02 +08:00
|
|
|
/// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol.
|
|
|
|
///
|
|
|
|
/// @param Symbol - The common symbol to emit.
|
|
|
|
/// @param Size - The size of the common symbol.
|
2012-08-24 00:54:08 +08:00
|
|
|
/// @param ByteAlignment - The alignment of the common symbol in bytes.
|
2014-03-08 15:02:02 +08:00
|
|
|
void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
|
|
|
|
unsigned ByteAlignment) override;
|
|
|
|
|
2015-05-22 03:20:38 +08:00
|
|
|
void EmitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
|
2014-03-08 15:02:02 +08:00
|
|
|
uint64_t Size = 0, unsigned ByteAlignment = 0) override;
|
|
|
|
|
2015-05-22 03:20:38 +08:00
|
|
|
void EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size,
|
|
|
|
unsigned ByteAlignment = 0) override;
|
2014-03-08 15:02:02 +08:00
|
|
|
|
|
|
|
void EmitBytes(StringRef Data) override;
|
|
|
|
|
2014-04-23 01:27:29 +08:00
|
|
|
void EmitValueImpl(const MCExpr *Value, unsigned Size,
|
|
|
|
const SMLoc &Loc = SMLoc()) override;
|
2014-03-08 15:02:02 +08:00
|
|
|
void EmitIntValue(uint64_t Value, unsigned Size) override;
|
|
|
|
|
|
|
|
void EmitULEB128Value(const MCExpr *Value) override;
|
|
|
|
|
|
|
|
void EmitSLEB128Value(const MCExpr *Value) override;
|
|
|
|
|
|
|
|
void EmitGPRel64Value(const MCExpr *Value) override;
|
|
|
|
|
|
|
|
void EmitGPRel32Value(const MCExpr *Value) override;
|
|
|
|
|
|
|
|
|
|
|
|
void EmitFill(uint64_t NumBytes, uint8_t FillValue) override;
|
|
|
|
|
|
|
|
void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
|
|
|
|
unsigned ValueSize = 1,
|
|
|
|
unsigned MaxBytesToEmit = 0) override;
|
|
|
|
|
|
|
|
void EmitCodeAlignment(unsigned ByteAlignment,
|
|
|
|
unsigned MaxBytesToEmit = 0) override;
|
|
|
|
|
|
|
|
bool EmitValueToOffset(const MCExpr *Offset,
|
|
|
|
unsigned char Value = 0) override;
|
|
|
|
|
|
|
|
void EmitFileDirective(StringRef Filename) override;
|
2014-03-17 09:52:11 +08:00
|
|
|
unsigned EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
|
|
|
|
StringRef Filename,
|
|
|
|
unsigned CUID = 0) override;
|
2014-03-08 15:02:02 +08:00
|
|
|
void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
|
|
|
|
unsigned Column, unsigned Flags,
|
|
|
|
unsigned Isa, unsigned Discriminator,
|
|
|
|
StringRef FileName) override;
|
2014-04-01 16:07:52 +08:00
|
|
|
MCSymbol *getDwarfLineTableSymbol(unsigned CUID) override;
|
2014-03-08 15:02:02 +08:00
|
|
|
|
|
|
|
void EmitIdent(StringRef IdentString) override;
|
|
|
|
void EmitCFISections(bool EH, bool Debug) override;
|
|
|
|
void EmitCFIDefCfa(int64_t Register, int64_t Offset) override;
|
|
|
|
void EmitCFIDefCfaOffset(int64_t Offset) override;
|
|
|
|
void EmitCFIDefCfaRegister(int64_t Register) override;
|
|
|
|
void EmitCFIOffset(int64_t Register, int64_t Offset) override;
|
|
|
|
void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding) override;
|
|
|
|
void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding) override;
|
|
|
|
void EmitCFIRememberState() override;
|
|
|
|
void EmitCFIRestoreState() override;
|
|
|
|
void EmitCFISameValue(int64_t Register) override;
|
|
|
|
void EmitCFIRelOffset(int64_t Register, int64_t Offset) override;
|
|
|
|
void EmitCFIAdjustCfaOffset(int64_t Adjustment) override;
|
|
|
|
void EmitCFISignalFrame() override;
|
|
|
|
void EmitCFIUndefined(int64_t Register) override;
|
|
|
|
void EmitCFIRegister(int64_t Register1, int64_t Register2) override;
|
|
|
|
void EmitCFIWindowSave() override;
|
|
|
|
|
2014-06-29 09:52:01 +08:00
|
|
|
void EmitWinCFIStartProc(const MCSymbol *Symbol) override;
|
|
|
|
void EmitWinCFIEndProc() override;
|
|
|
|
void EmitWinCFIStartChained() override;
|
|
|
|
void EmitWinCFIEndChained() override;
|
|
|
|
void EmitWinCFIPushReg(unsigned Register) override;
|
|
|
|
void EmitWinCFISetFrame(unsigned Register, unsigned Offset) override;
|
|
|
|
void EmitWinCFIAllocStack(unsigned Size) override;
|
|
|
|
void EmitWinCFISaveReg(unsigned Register, unsigned Offset) override;
|
|
|
|
void EmitWinCFISaveXMM(unsigned Register, unsigned Offset) override;
|
|
|
|
void EmitWinCFIPushFrame(bool Code) override;
|
|
|
|
void EmitWinCFIEndProlog() override;
|
|
|
|
|
|
|
|
void EmitWinEHHandler(const MCSymbol *Sym, bool Unwind, bool Except) override;
|
|
|
|
void EmitWinEHHandlerData() override;
|
2014-03-08 15:02:02 +08:00
|
|
|
|
|
|
|
void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override;
|
|
|
|
|
|
|
|
void EmitBundleAlignMode(unsigned AlignPow2) override;
|
|
|
|
void EmitBundleLock(bool AlignToEnd) override;
|
|
|
|
void EmitBundleUnlock() override;
|
2012-12-21 03:05:53 +08:00
|
|
|
|
2010-09-23 02:18:30 +08:00
|
|
|
/// EmitRawText - If this file is backed by an assembly streamer, this dumps
|
2010-04-04 05:35:55 +08:00
|
|
|
/// the specified string in the output .s file. This capability is
|
|
|
|
/// indicated by the hasRawTextSupport() predicate.
|
2014-03-08 15:02:02 +08:00
|
|
|
void EmitRawTextImpl(StringRef String) override;
|
2010-09-23 02:16:55 +08:00
|
|
|
|
2014-03-08 15:02:02 +08:00
|
|
|
void FinishImpl() override;
|
2009-08-17 12:17:34 +08:00
|
|
|
};
|
2009-06-25 03:25:34 +08:00
|
|
|
|
2009-08-17 12:17:34 +08:00
|
|
|
} // end anonymous namespace.
|
2009-06-24 09:03:06 +08:00
|
|
|
|
2010-01-23 02:21:35 +08:00
|
|
|
/// AddComment - Add a comment that can be emitted to the generated .s
|
2010-01-22 15:29:22 +08: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-23 02:21:35 +08:00
|
|
|
void MCAsmStreamer::AddComment(const Twine &T) {
|
2010-01-22 15:29:22 +08:00
|
|
|
if (!IsVerboseAsm) return;
|
2010-09-23 02:16:55 +08:00
|
|
|
|
2010-01-23 03:17:48 +08:00
|
|
|
// Make sure that CommentStream is flushed.
|
|
|
|
CommentStream.flush();
|
2010-09-23 02:16:55 +08:00
|
|
|
|
2010-01-22 15:29:22 +08:00
|
|
|
T.toVector(CommentToEmit);
|
2010-01-23 03:17:48 +08:00
|
|
|
// Each comment goes on its own line.
|
|
|
|
CommentToEmit.push_back('\n');
|
2010-09-23 02:16:55 +08:00
|
|
|
|
2010-01-23 05:16:10 +08:00
|
|
|
// Tell the comment stream that the vector changed underneath it.
|
|
|
|
CommentStream.resync();
|
2010-01-22 15:29:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MCAsmStreamer::EmitCommentsAndEOL() {
|
2010-01-23 03:17:48 +08:00
|
|
|
if (CommentToEmit.empty() && CommentStream.GetNumBytesInBuffer() == 0) {
|
|
|
|
OS << '\n';
|
|
|
|
return;
|
|
|
|
}
|
2010-09-23 02:16:55 +08:00
|
|
|
|
2010-01-23 03:17:48 +08:00
|
|
|
CommentStream.flush();
|
2015-03-18 18:17:07 +08:00
|
|
|
StringRef Comments = CommentToEmit;
|
2010-09-23 02:16:55 +08:00
|
|
|
|
2010-01-23 03:17:48 +08:00
|
|
|
assert(Comments.back() == '\n' &&
|
|
|
|
"Comment array not newline terminated");
|
|
|
|
do {
|
2010-01-22 15:29:22 +08:00
|
|
|
// Emit a line of comments.
|
2013-06-18 15:20:20 +08:00
|
|
|
OS.PadToColumn(MAI->getCommentColumn());
|
2010-01-22 15:29:22 +08:00
|
|
|
size_t Position = Comments.find('\n');
|
2013-06-18 15:20:20 +08:00
|
|
|
OS << MAI->getCommentString() << ' ' << Comments.substr(0, Position) <<'\n';
|
2010-09-23 02:16:55 +08:00
|
|
|
|
2010-01-22 15:29:22 +08:00
|
|
|
Comments = Comments.substr(Position+1);
|
2010-01-23 03:17:48 +08:00
|
|
|
} while (!Comments.empty());
|
2010-09-23 02:16:55 +08:00
|
|
|
|
2010-01-23 05:16:10 +08:00
|
|
|
CommentToEmit.clear();
|
|
|
|
// Tell the comment stream that the vector changed underneath it.
|
|
|
|
CommentStream.resync();
|
2010-01-22 15:29:22 +08:00
|
|
|
}
|
|
|
|
|
2009-06-26 05:03:18 +08: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));
|
|
|
|
}
|
|
|
|
|
2014-01-17 00:28:37 +08:00
|
|
|
void MCAsmStreamer::emitRawComment(const Twine &T, bool TabPrefix) {
|
|
|
|
if (TabPrefix)
|
|
|
|
OS << '\t';
|
|
|
|
OS << MAI->getCommentString() << T;
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2015-05-22 03:20:38 +08:00
|
|
|
void MCAsmStreamer::ChangeSection(MCSection *Section,
|
2013-04-18 05:18:16 +08:00
|
|
|
const MCExpr *Subsection) {
|
2009-08-19 13:49:37 +08:00
|
|
|
assert(Section && "Cannot switch to a null section!");
|
2013-06-18 15:20:20 +08:00
|
|
|
Section->PrintSwitchToSection(*MAI, OS, Subsection);
|
2009-06-24 09:03:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MCAsmStreamer::EmitLabel(MCSymbol *Symbol) {
|
2009-08-22 15:22:36 +08:00
|
|
|
assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
|
2011-04-27 23:21:19 +08:00
|
|
|
MCStreamer::EmitLabel(Symbol);
|
2009-06-25 01:00:42 +08:00
|
|
|
|
2013-06-18 15:20:20 +08:00
|
|
|
OS << *Symbol << MAI->getLabelSuffix();
|
2010-01-22 15:36:39 +08:00
|
|
|
EmitEOL();
|
2009-06-24 09:03:06 +08:00
|
|
|
}
|
|
|
|
|
2014-03-29 15:34:53 +08:00
|
|
|
void MCAsmStreamer::EmitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) {
|
|
|
|
StringRef str = MCLOHIdToName(Kind);
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
int NbArgs = MCLOHIdToNbArgs(Kind);
|
|
|
|
assert(NbArgs != -1 && ((size_t)NbArgs) == Args.size() && "Malformed LOH!");
|
|
|
|
assert(str != "" && "Invalid LOH name");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
OS << "\t" << MCLOHDirectiveName() << " " << str << "\t";
|
|
|
|
bool IsFirst = true;
|
|
|
|
for (MCLOHArgs::const_iterator It = Args.begin(), EndIt = Args.end();
|
|
|
|
It != EndIt; ++It) {
|
|
|
|
if (!IsFirst)
|
|
|
|
OS << ", ";
|
|
|
|
IsFirst = false;
|
|
|
|
OS << **It;
|
|
|
|
}
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2010-01-23 14:39:22 +08:00
|
|
|
void MCAsmStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {
|
2009-07-17 01:56:39 +08:00
|
|
|
switch (Flag) {
|
2010-09-30 10:45:56 +08:00
|
|
|
case MCAF_SyntaxUnified: OS << "\t.syntax unified"; break;
|
2010-01-23 14:39:22 +08:00
|
|
|
case MCAF_SubsectionsViaSymbols: OS << ".subsections_via_symbols"; break;
|
2013-06-18 15:20:20 +08:00
|
|
|
case MCAF_Code16: OS << '\t'<< MAI->getCode16Directive();break;
|
|
|
|
case MCAF_Code32: OS << '\t'<< MAI->getCode32Directive();break;
|
|
|
|
case MCAF_Code64: OS << '\t'<< MAI->getCode64Directive();break;
|
2009-07-17 01:56:39 +08:00
|
|
|
}
|
2010-01-22 15:36:39 +08:00
|
|
|
EmitEOL();
|
2009-07-14 05:03:15 +08:00
|
|
|
}
|
|
|
|
|
2013-01-18 09:25:48 +08:00
|
|
|
void MCAsmStreamer::EmitLinkerOptions(ArrayRef<std::string> Options) {
|
|
|
|
assert(!Options.empty() && "At least one option is required!");
|
|
|
|
OS << "\t.linker_option \"" << Options[0] << '"';
|
|
|
|
for (ArrayRef<std::string>::iterator it = Options.begin() + 1,
|
|
|
|
ie = Options.end(); it != ie; ++it) {
|
|
|
|
OS << ", " << '"' << *it << '"';
|
|
|
|
}
|
2013-01-19 03:37:00 +08:00
|
|
|
OS << "\n";
|
2013-01-18 09:25:48 +08:00
|
|
|
}
|
|
|
|
|
2012-05-19 03:12:01 +08:00
|
|
|
void MCAsmStreamer::EmitDataRegion(MCDataRegionType Kind) {
|
2013-06-18 15:20:20 +08:00
|
|
|
if (!MAI->doesSupportDataRegionDirectives())
|
2012-05-19 03:12:01 +08:00
|
|
|
return;
|
|
|
|
switch (Kind) {
|
|
|
|
case MCDR_DataRegion: OS << "\t.data_region"; break;
|
|
|
|
case MCDR_DataRegionJT8: OS << "\t.data_region jt8"; break;
|
|
|
|
case MCDR_DataRegionJT16: OS << "\t.data_region jt16"; break;
|
|
|
|
case MCDR_DataRegionJT32: OS << "\t.data_region jt32"; break;
|
|
|
|
case MCDR_DataRegionEnd: OS << "\t.end_data_region"; break;
|
|
|
|
}
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2014-03-19 06:09:05 +08:00
|
|
|
void MCAsmStreamer::EmitVersionMin(MCVersionMinType Kind, unsigned Major,
|
|
|
|
unsigned Minor, unsigned Update) {
|
|
|
|
switch (Kind) {
|
|
|
|
case MCVM_IOSVersionMin: OS << "\t.ios_version_min"; break;
|
|
|
|
case MCVM_OSXVersionMin: OS << "\t.macosx_version_min"; break;
|
|
|
|
}
|
|
|
|
OS << " " << Major << ", " << Minor;
|
|
|
|
if (Update)
|
|
|
|
OS << ", " << Update;
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2010-11-06 06:08:08 +08: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";
|
2011-05-17 00:17:21 +08:00
|
|
|
// Only Mach-O hasSubsectionsViaSymbols()
|
2013-06-18 15:20:20 +08:00
|
|
|
if (MAI->hasSubsectionsViaSymbols())
|
2010-11-06 06:08:08 +08:00
|
|
|
OS << '\t' << *Func;
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2009-08-31 16:09:28 +08:00
|
|
|
void MCAsmStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
|
2010-01-22 15:36:39 +08:00
|
|
|
OS << *Symbol << " = " << *Value;
|
|
|
|
EmitEOL();
|
2009-10-16 09:34:54 +08:00
|
|
|
|
2014-03-20 17:44:49 +08:00
|
|
|
MCStreamer::EmitAssignment(Symbol, Value);
|
2009-06-24 09:03:06 +08:00
|
|
|
}
|
|
|
|
|
2010-11-01 22:28:48 +08:00
|
|
|
void MCAsmStreamer::EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {
|
|
|
|
OS << ".weakref " << *Alias << ", " << *Symbol;
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2013-08-09 09:52:03 +08:00
|
|
|
bool MCAsmStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
|
2010-01-23 14:39:22 +08:00
|
|
|
MCSymbolAttr Attribute) {
|
2009-06-24 09:03:06 +08:00
|
|
|
switch (Attribute) {
|
2012-02-07 13:05:23 +08:00
|
|
|
case MCSA_Invalid: llvm_unreachable("Invalid symbol attribute");
|
2010-01-26 02:30:45 +08: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 12:55:06 +08:00
|
|
|
case MCSA_ELF_TypeGnuUniqueObject: /// .type _foo, @gnu_unique_object
|
2013-08-09 09:52:03 +08:00
|
|
|
if (!MAI->hasDotTypeDotSizeDirective())
|
|
|
|
return false; // Symbol attribute not supported
|
2010-02-04 09:42:13 +08:00
|
|
|
OS << "\t.type\t" << *Symbol << ','
|
2013-06-18 15:20:20 +08:00
|
|
|
<< ((MAI->getCommentString()[0] != '@') ? '@' : '%');
|
2010-01-26 02:30:45 +08:00
|
|
|
switch (Attribute) {
|
2013-08-09 09:52:03 +08:00
|
|
|
default: return false;
|
2010-01-26 02:30:45 +08:00
|
|
|
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 12:55:06 +08:00
|
|
|
case MCSA_ELF_TypeGnuUniqueObject: OS << "gnu_unique_object"; break;
|
2010-01-26 02:30:45 +08:00
|
|
|
}
|
|
|
|
EmitEOL();
|
2013-08-09 09:52:03 +08:00
|
|
|
return true;
|
2010-01-26 02:30:45 +08:00
|
|
|
case MCSA_Global: // .globl/.global
|
2013-06-18 15:20:20 +08:00
|
|
|
OS << MAI->getGlobalDirective();
|
2010-01-26 02:30:45 +08:00
|
|
|
break;
|
2010-06-22 04:35:01 +08: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;
|
2014-12-24 12:11:42 +08:00
|
|
|
case MCSA_NoDeadStrip:
|
|
|
|
if (!MAI->hasNoDeadStrip())
|
|
|
|
return false;
|
|
|
|
OS << "\t.no_dead_strip\t";
|
|
|
|
break;
|
2010-11-20 02:39:33 +08:00
|
|
|
case MCSA_SymbolResolver: OS << "\t.symbol_resolver\t"; break;
|
2011-05-01 00:34:57 +08:00
|
|
|
case MCSA_PrivateExtern:
|
|
|
|
OS << "\t.private_extern\t";
|
|
|
|
break;
|
2010-06-22 04:35:01 +08:00
|
|
|
case MCSA_Protected: OS << "\t.protected\t"; break;
|
|
|
|
case MCSA_Reference: OS << "\t.reference\t"; break;
|
2014-12-02 05:16:17 +08:00
|
|
|
case MCSA_Weak: OS << MAI->getWeakDirective(); break;
|
2011-05-01 00:34:57 +08:00
|
|
|
case MCSA_WeakDefinition:
|
|
|
|
OS << "\t.weak_definition\t";
|
|
|
|
break;
|
2010-01-23 14:39:22 +08:00
|
|
|
// .weak_reference
|
2013-06-18 15:20:20 +08:00
|
|
|
case MCSA_WeakReference: OS << MAI->getWeakRefDirective(); break;
|
2010-07-09 01:22:42 +08:00
|
|
|
case MCSA_WeakDefAutoPrivate: OS << "\t.weak_def_can_be_hidden\t"; break;
|
2009-06-24 09:03:06 +08:00
|
|
|
}
|
|
|
|
|
2010-01-22 15:36:39 +08:00
|
|
|
OS << *Symbol;
|
|
|
|
EmitEOL();
|
2013-08-09 09:52:03 +08:00
|
|
|
|
|
|
|
return true;
|
2009-06-24 09:03:06 +08:00
|
|
|
}
|
|
|
|
|
2009-07-15 02:17:10 +08:00
|
|
|
void MCAsmStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
|
2010-01-22 15:36:39 +08:00
|
|
|
OS << ".desc" << ' ' << *Symbol << ',' << DescValue;
|
|
|
|
EmitEOL();
|
2009-07-15 02:17:10 +08:00
|
|
|
}
|
|
|
|
|
2010-05-09 03:54:22 +08: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();
|
|
|
|
}
|
|
|
|
|
2013-12-21 02:15:00 +08:00
|
|
|
void MCAsmStreamer::EmitCOFFSectionIndex(MCSymbol const *Symbol) {
|
|
|
|
OS << "\t.secidx\t" << *Symbol;
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2011-12-17 09:14:52 +08:00
|
|
|
void MCAsmStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol) {
|
2013-12-21 02:15:00 +08:00
|
|
|
OS << "\t.secrel32\t" << *Symbol;
|
2011-12-17 09:14:52 +08:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2010-01-25 15:52:13 +08:00
|
|
|
void MCAsmStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
|
2013-06-18 15:20:20 +08:00
|
|
|
assert(MAI->hasDotTypeDotSizeDirective());
|
2010-01-25 15:52:13 +08:00
|
|
|
OS << "\t.size\t" << *Symbol << ", " << *Value << '\n';
|
|
|
|
}
|
|
|
|
|
2010-01-23 15:47:02 +08:00
|
|
|
void MCAsmStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
|
2009-08-30 14:17:16 +08:00
|
|
|
unsigned ByteAlignment) {
|
2013-09-24 01:56:20 +08:00
|
|
|
// Common symbols do not belong to any actual section.
|
2014-04-13 12:57:38 +08:00
|
|
|
AssignSection(Symbol, nullptr);
|
2013-09-20 07:21:01 +08:00
|
|
|
|
2010-01-23 15:47:02 +08:00
|
|
|
OS << "\t.comm\t" << *Symbol << ',' << Size;
|
2010-01-25 15:29:13 +08:00
|
|
|
if (ByteAlignment != 0) {
|
2013-06-18 15:20:20 +08:00
|
|
|
if (MAI->getCOMMDirectiveAlignmentIsInBytes())
|
2010-01-19 14:01:04 +08:00
|
|
|
OS << ',' << ByteAlignment;
|
|
|
|
else
|
|
|
|
OS << ',' << Log2_32(ByteAlignment);
|
|
|
|
}
|
2010-01-22 15:36:39 +08:00
|
|
|
EmitEOL();
|
2009-07-08 04:30:46 +08:00
|
|
|
}
|
|
|
|
|
2010-01-23 15:47:02 +08:00
|
|
|
/// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol.
|
|
|
|
///
|
|
|
|
/// @param Symbol - The common symbol to emit.
|
|
|
|
/// @param Size - The size of the common symbol.
|
2011-09-02 07:04:27 +08:00
|
|
|
void MCAsmStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
|
|
|
|
unsigned ByteAlign) {
|
2013-09-24 01:56:20 +08:00
|
|
|
// Common symbols do not belong to any actual section.
|
2014-04-13 12:57:38 +08:00
|
|
|
AssignSection(Symbol, nullptr);
|
2013-09-20 07:21:01 +08:00
|
|
|
|
2010-01-23 15:47:02 +08:00
|
|
|
OS << "\t.lcomm\t" << *Symbol << ',' << Size;
|
2011-09-02 07:04:27 +08:00
|
|
|
if (ByteAlign > 1) {
|
2013-06-18 15:20:20 +08:00
|
|
|
switch (MAI->getLCOMMDirectiveAlignmentType()) {
|
2012-09-08 05:08:01 +08:00
|
|
|
case LCOMM::NoAlignment:
|
|
|
|
llvm_unreachable("alignment not supported on .lcomm!");
|
|
|
|
case LCOMM::ByteAlignment:
|
2012-09-08 01:25:13 +08:00
|
|
|
OS << ',' << ByteAlign;
|
2012-09-08 05:08:01 +08:00
|
|
|
break;
|
|
|
|
case LCOMM::Log2Alignment:
|
2012-09-08 01:25:13 +08:00
|
|
|
assert(isPowerOf2_32(ByteAlign) && "alignment must be a power of 2");
|
|
|
|
OS << ',' << Log2_32(ByteAlign);
|
2012-09-08 05:08:01 +08:00
|
|
|
break;
|
2012-09-08 01:25:13 +08:00
|
|
|
}
|
2011-09-02 07:04:27 +08:00
|
|
|
}
|
2010-01-23 15:47:02 +08:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2015-05-22 03:20:38 +08:00
|
|
|
void MCAsmStreamer::EmitZerofill(MCSection *Section, MCSymbol *Symbol,
|
2012-06-23 04:14:46 +08:00
|
|
|
uint64_t Size, unsigned ByteAlignment) {
|
2013-09-20 07:21:01 +08:00
|
|
|
if (Symbol)
|
|
|
|
AssignSection(Symbol, Section);
|
|
|
|
|
2009-08-14 07:36:34 +08:00
|
|
|
// Note: a .zerofill directive does not switch sections.
|
2009-08-09 07:39:42 +08:00
|
|
|
OS << ".zerofill ";
|
2010-09-23 02:16:55 +08:00
|
|
|
|
2009-08-09 07:39:42 +08:00
|
|
|
// This is a mach-o specific directive.
|
2009-08-10 09:39:42 +08:00
|
|
|
const MCSectionMachO *MOSection = ((const MCSectionMachO*)Section);
|
2009-08-15 02:51:45 +08:00
|
|
|
OS << MOSection->getSegmentName() << "," << MOSection->getSectionName();
|
2010-09-23 02:16:55 +08:00
|
|
|
|
2014-04-13 12:57:38 +08:00
|
|
|
if (Symbol) {
|
2010-01-18 05:43:43 +08:00
|
|
|
OS << ',' << *Symbol << ',' << Size;
|
2009-08-30 14:17:16 +08:00
|
|
|
if (ByteAlignment != 0)
|
|
|
|
OS << ',' << Log2_32(ByteAlignment);
|
2009-07-11 06:20:30 +08:00
|
|
|
}
|
2010-01-22 15:36:39 +08:00
|
|
|
EmitEOL();
|
2009-07-11 06:20:30 +08:00
|
|
|
}
|
|
|
|
|
2010-05-17 10:13:02 +08:00
|
|
|
// .tbss sym, size, align
|
|
|
|
// This depends that the symbol has already been mangled from the original,
|
|
|
|
// e.g. _a.
|
2015-05-22 03:20:38 +08:00
|
|
|
void MCAsmStreamer::EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
|
2010-05-19 05:16:04 +08:00
|
|
|
uint64_t Size, unsigned ByteAlignment) {
|
2013-09-20 07:21:01 +08:00
|
|
|
AssignSection(Symbol, Section);
|
|
|
|
|
2014-04-13 12:57:38 +08:00
|
|
|
assert(Symbol && "Symbol shouldn't be NULL!");
|
2010-05-19 05:16:04 +08:00
|
|
|
// Instead of using the Section we'll just use the shortcut.
|
|
|
|
// This is a mach-o specific directive and section.
|
2010-05-17 10:13:02 +08:00
|
|
|
OS << ".tbss " << *Symbol << ", " << Size;
|
2010-09-23 02:16:55 +08:00
|
|
|
|
2010-05-19 05:16:04 +08: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-23 02:16:55 +08:00
|
|
|
|
2010-05-14 09:50:28 +08:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2010-01-23 08:15:00 +08:00
|
|
|
static inline char toOctal(int X) { return (X&7)+'0'; }
|
|
|
|
|
2010-01-26 02:58:59 +08:00
|
|
|
static void PrintQuotedString(StringRef Data, raw_ostream &OS) {
|
|
|
|
OS << '"';
|
2010-09-23 02:16:55 +08:00
|
|
|
|
2010-01-26 02:58:59 +08: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-23 02:16:55 +08:00
|
|
|
|
2010-01-26 02:58:59 +08:00
|
|
|
if (isprint((unsigned char)C)) {
|
|
|
|
OS << (char)C;
|
|
|
|
continue;
|
|
|
|
}
|
2010-09-23 02:16:55 +08:00
|
|
|
|
2010-01-26 02:58:59 +08: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-23 02:16:55 +08:00
|
|
|
|
2010-01-26 02:58:59 +08:00
|
|
|
OS << '"';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-02 23:49:13 +08:00
|
|
|
void MCAsmStreamer::EmitBytes(StringRef Data) {
|
2013-04-18 05:18:16 +08:00
|
|
|
assert(getCurrentSection().first &&
|
|
|
|
"Cannot emit contents before setting section!");
|
2010-01-23 08:15:00 +08:00
|
|
|
if (Data.empty()) return;
|
2010-09-23 02:16:55 +08:00
|
|
|
|
2010-01-23 08:15:00 +08:00
|
|
|
if (Data.size() == 1) {
|
2013-07-02 23:49:13 +08:00
|
|
|
OS << MAI->getData8bitsDirective();
|
2010-01-23 08:15:00 +08:00
|
|
|
OS << (unsigned)(unsigned char)Data[0];
|
2010-01-22 15:36:39 +08:00
|
|
|
EmitEOL();
|
2010-01-23 08:15:00 +08:00
|
|
|
return;
|
2010-01-22 15:36:39 +08:00
|
|
|
}
|
2010-01-23 08:15:00 +08:00
|
|
|
|
|
|
|
// If the data ends with 0 and the target supports .asciz, use it, otherwise
|
|
|
|
// use .ascii
|
2013-06-18 15:20:20 +08:00
|
|
|
if (MAI->getAscizDirective() && Data.back() == 0) {
|
|
|
|
OS << MAI->getAscizDirective();
|
2010-01-23 08:15:00 +08:00
|
|
|
Data = Data.substr(0, Data.size()-1);
|
|
|
|
} else {
|
2013-06-18 15:20:20 +08:00
|
|
|
OS << MAI->getAsciiDirective();
|
2010-01-23 08:15:00 +08:00
|
|
|
}
|
|
|
|
|
2010-01-26 02:58:59 +08:00
|
|
|
PrintQuotedString(Data, OS);
|
2010-01-23 08:15:00 +08:00
|
|
|
EmitEOL();
|
2009-06-24 09:03:06 +08:00
|
|
|
}
|
|
|
|
|
2013-07-02 23:49:13 +08:00
|
|
|
void MCAsmStreamer::EmitIntValue(uint64_t Value, unsigned Size) {
|
|
|
|
EmitValue(MCConstantExpr::Create(Value, getContext()), Size);
|
2010-12-03 10:54:21 +08:00
|
|
|
}
|
|
|
|
|
2014-04-23 01:27:29 +08:00
|
|
|
void MCAsmStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
|
|
|
|
const SMLoc &Loc) {
|
2014-02-01 15:19:38 +08:00
|
|
|
assert(Size <= 8 && "Invalid size");
|
2013-04-18 05:18:16 +08:00
|
|
|
assert(getCurrentSection().first &&
|
|
|
|
"Cannot emit contents before setting section!");
|
2014-04-13 12:57:38 +08:00
|
|
|
const char *Directive = nullptr;
|
2010-01-20 06:03:38 +08:00
|
|
|
switch (Size) {
|
|
|
|
default: break;
|
2013-07-02 23:49:13 +08:00
|
|
|
case 1: Directive = MAI->getData8bitsDirective(); break;
|
|
|
|
case 2: Directive = MAI->getData16bitsDirective(); break;
|
|
|
|
case 4: Directive = MAI->getData32bitsDirective(); break;
|
2014-02-01 15:19:38 +08:00
|
|
|
case 8: Directive = MAI->getData64bitsDirective(); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Directive) {
|
2010-11-29 07:22:44 +08:00
|
|
|
int64_t IntValue;
|
|
|
|
if (!Value->EvaluateAsAbsolute(IntValue))
|
|
|
|
report_fatal_error("Don't know how to emit this value.");
|
2014-02-01 15:19:38 +08:00
|
|
|
|
|
|
|
// We couldn't handle the requested integer size so we fallback by breaking
|
|
|
|
// the request down into several, smaller, integers. Since sizes greater
|
|
|
|
// than eight are invalid and size equivalent to eight should have been
|
|
|
|
// handled earlier, we use four bytes as our largest piece of granularity.
|
|
|
|
bool IsLittleEndian = MAI->isLittleEndian();
|
|
|
|
for (unsigned Emitted = 0; Emitted != Size;) {
|
|
|
|
unsigned Remaining = Size - Emitted;
|
|
|
|
// The size of our partial emission must be a power of two less than
|
|
|
|
// eight.
|
|
|
|
unsigned EmissionSize = PowerOf2Floor(Remaining);
|
|
|
|
if (EmissionSize > 4)
|
|
|
|
EmissionSize = 4;
|
|
|
|
// Calculate the byte offset of our partial emission taking into account
|
|
|
|
// the endianness of the target.
|
|
|
|
unsigned ByteOffset =
|
|
|
|
IsLittleEndian ? Emitted : (Remaining - EmissionSize);
|
|
|
|
uint64_t ValueToEmit = IntValue >> (ByteOffset * 8);
|
|
|
|
// We truncate our partial emission to fit within the bounds of the
|
|
|
|
// emission domain. This produces nicer output and silences potential
|
|
|
|
// truncation warnings when round tripping through another assembler.
|
2014-12-13 05:48:03 +08:00
|
|
|
uint64_t Shift = 64 - EmissionSize * 8;
|
2014-12-15 22:25:12 +08:00
|
|
|
assert(Shift < static_cast<uint64_t>(
|
2014-12-14 00:55:02 +08:00
|
|
|
std::numeric_limits<unsigned long long>::digits) &&
|
2014-12-13 05:48:03 +08:00
|
|
|
"undefined behavior");
|
|
|
|
ValueToEmit &= ~0ULL >> Shift;
|
2014-02-01 15:19:38 +08:00
|
|
|
EmitIntValue(ValueToEmit, EmissionSize);
|
|
|
|
Emitted += EmissionSize;
|
2010-01-20 14:45:39 +08:00
|
|
|
}
|
|
|
|
return;
|
2010-01-20 06:03:38 +08:00
|
|
|
}
|
2010-09-23 02:16:55 +08:00
|
|
|
|
2010-01-20 06:03:38 +08:00
|
|
|
assert(Directive && "Invalid size for machine code value!");
|
2010-01-26 05:28:50 +08:00
|
|
|
OS << Directive << *Value;
|
2010-01-22 15:29:22 +08:00
|
|
|
EmitEOL();
|
2009-06-24 09:03:06 +08:00
|
|
|
}
|
|
|
|
|
2011-04-22 07:39:26 +08:00
|
|
|
void MCAsmStreamer::EmitULEB128Value(const MCExpr *Value) {
|
2010-11-19 12:10:13 +08:00
|
|
|
int64_t IntValue;
|
|
|
|
if (Value->EvaluateAsAbsolute(IntValue)) {
|
2011-04-22 07:39:26 +08:00
|
|
|
EmitULEB128IntValue(IntValue);
|
2010-11-19 12:10:13 +08:00
|
|
|
return;
|
|
|
|
}
|
2010-11-05 02:17:08 +08:00
|
|
|
OS << ".uleb128 " << *Value;
|
2010-11-03 01:22:24 +08:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2011-04-22 07:39:26 +08:00
|
|
|
void MCAsmStreamer::EmitSLEB128Value(const MCExpr *Value) {
|
2010-11-19 12:10:13 +08:00
|
|
|
int64_t IntValue;
|
|
|
|
if (Value->EvaluateAsAbsolute(IntValue)) {
|
2011-04-22 07:39:26 +08:00
|
|
|
EmitSLEB128IntValue(IntValue);
|
2010-11-19 12:10:13 +08:00
|
|
|
return;
|
|
|
|
}
|
2010-11-05 02:17:08 +08:00
|
|
|
OS << ".sleb128 " << *Value;
|
2010-11-03 01:22:24 +08:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2012-02-03 12:33:00 +08:00
|
|
|
void MCAsmStreamer::EmitGPRel64Value(const MCExpr *Value) {
|
2014-04-13 12:57:38 +08:00
|
|
|
assert(MAI->getGPRel64Directive() != nullptr);
|
2013-06-18 15:20:20 +08:00
|
|
|
OS << MAI->getGPRel64Directive() << *Value;
|
2012-02-03 12:33:00 +08:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2010-01-26 05:28:50 +08:00
|
|
|
void MCAsmStreamer::EmitGPRel32Value(const MCExpr *Value) {
|
2014-04-13 12:57:38 +08:00
|
|
|
assert(MAI->getGPRel32Directive() != nullptr);
|
2013-06-18 15:20:20 +08:00
|
|
|
OS << MAI->getGPRel32Directive() << *Value;
|
2010-01-26 05:28:50 +08:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-20 02:52:28 +08:00
|
|
|
/// EmitFill - Emit NumBytes bytes worth of the value specified by
|
|
|
|
/// FillValue. This implements directives such as '.space'.
|
2013-07-02 23:49:13 +08:00
|
|
|
void MCAsmStreamer::EmitFill(uint64_t NumBytes, uint8_t FillValue) {
|
2010-01-20 02:58:52 +08:00
|
|
|
if (NumBytes == 0) return;
|
2010-09-23 02:16:55 +08:00
|
|
|
|
2013-07-02 23:49:13 +08:00
|
|
|
if (const char *ZeroDirective = MAI->getZeroDirective()) {
|
|
|
|
OS << ZeroDirective << NumBytes;
|
|
|
|
if (FillValue != 0)
|
|
|
|
OS << ',' << (int)FillValue;
|
|
|
|
EmitEOL();
|
|
|
|
return;
|
|
|
|
}
|
2010-01-20 03:46:13 +08:00
|
|
|
|
|
|
|
// Emit a byte at a time.
|
2013-07-02 23:49:13 +08:00
|
|
|
MCStreamer::EmitFill(NumBytes, FillValue);
|
2010-01-20 02:52:28 +08:00
|
|
|
}
|
|
|
|
|
2009-06-25 03:25:34 +08:00
|
|
|
void MCAsmStreamer::EmitValueToAlignment(unsigned ByteAlignment, int64_t Value,
|
|
|
|
unsigned ValueSize,
|
|
|
|
unsigned MaxBytesToEmit) {
|
2009-08-19 14:12:02 +08: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 14:35:36 +08:00
|
|
|
switch (ValueSize) {
|
2014-02-05 02:39:51 +08:00
|
|
|
default:
|
|
|
|
llvm_unreachable("Invalid size for machine code value!");
|
|
|
|
case 1:
|
|
|
|
OS << "\t.align\t";
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
OS << ".p2alignw ";
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
OS << ".p2alignl ";
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
llvm_unreachable("Unsupported alignment size!");
|
2009-08-19 14:35:36 +08:00
|
|
|
}
|
2010-09-23 02:16:55 +08:00
|
|
|
|
2013-06-18 15:20:20 +08:00
|
|
|
if (MAI->getAlignmentIsInBytes())
|
2009-08-19 14:12:02 +08:00
|
|
|
OS << ByteAlignment;
|
|
|
|
else
|
|
|
|
OS << Log2_32(ByteAlignment);
|
|
|
|
|
|
|
|
if (Value || MaxBytesToEmit) {
|
2009-09-03 12:01:10 +08:00
|
|
|
OS << ", 0x";
|
|
|
|
OS.write_hex(truncateToSize(Value, ValueSize));
|
2009-06-25 03:25:34 +08:00
|
|
|
|
2010-09-23 02:16:55 +08:00
|
|
|
if (MaxBytesToEmit)
|
2009-08-19 14:12:02 +08:00
|
|
|
OS << ", " << MaxBytesToEmit;
|
|
|
|
}
|
2010-01-22 15:36:39 +08:00
|
|
|
EmitEOL();
|
2009-08-19 14:12:02 +08:00
|
|
|
return;
|
|
|
|
}
|
2010-09-23 02:16:55 +08:00
|
|
|
|
2009-08-19 14:12:02 +08:00
|
|
|
// Non-power of two alignment. This is not widely supported by assemblers.
|
2009-08-23 05:43:10 +08:00
|
|
|
// FIXME: Parameterize this based on MAI.
|
2009-06-25 03:25:34 +08:00
|
|
|
switch (ValueSize) {
|
2009-08-19 14:12:02 +08: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-25 03:25:34 +08:00
|
|
|
}
|
|
|
|
|
2009-08-19 14:12:02 +08:00
|
|
|
OS << ' ' << ByteAlignment;
|
2009-06-26 05:03:18 +08:00
|
|
|
OS << ", " << truncateToSize(Value, ValueSize);
|
2010-09-23 02:16:55 +08:00
|
|
|
if (MaxBytesToEmit)
|
2009-06-25 03:25:34 +08:00
|
|
|
OS << ", " << MaxBytesToEmit;
|
2010-01-22 15:36:39 +08:00
|
|
|
EmitEOL();
|
2009-06-25 03:25:34 +08:00
|
|
|
}
|
|
|
|
|
2010-02-24 02:26:34 +08:00
|
|
|
void MCAsmStreamer::EmitCodeAlignment(unsigned ByteAlignment,
|
|
|
|
unsigned MaxBytesToEmit) {
|
2010-02-24 02:44:31 +08:00
|
|
|
// Emit with a text fill value.
|
2013-06-18 15:20:20 +08:00
|
|
|
EmitValueToAlignment(ByteAlignment, MAI->getTextAlignFillValue(),
|
2010-02-24 02:44:31 +08:00
|
|
|
1, MaxBytesToEmit);
|
2010-02-24 02:26:34 +08:00
|
|
|
}
|
|
|
|
|
2012-01-27 08:37:08 +08:00
|
|
|
bool MCAsmStreamer::EmitValueToOffset(const MCExpr *Offset,
|
2009-06-25 03:25:34 +08:00
|
|
|
unsigned char Value) {
|
|
|
|
// FIXME: Verify that Offset is associated with the current section.
|
2010-01-22 15:36:39 +08:00
|
|
|
OS << ".org " << *Offset << ", " << (unsigned) Value;
|
|
|
|
EmitEOL();
|
2012-01-27 08:37:08 +08:00
|
|
|
return false;
|
2009-06-25 03:25:34 +08:00
|
|
|
}
|
|
|
|
|
2010-01-26 02:58:59 +08:00
|
|
|
|
|
|
|
void MCAsmStreamer::EmitFileDirective(StringRef Filename) {
|
2013-06-18 15:20:20 +08:00
|
|
|
assert(MAI->hasSingleParameterDotFile());
|
2010-01-26 02:58:59 +08:00
|
|
|
OS << "\t.file\t";
|
|
|
|
PrintQuotedString(Filename, OS);
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2014-03-17 09:52:11 +08:00
|
|
|
unsigned MCAsmStreamer::EmitDwarfFileDirective(unsigned FileNo,
|
|
|
|
StringRef Directory,
|
|
|
|
StringRef Filename,
|
|
|
|
unsigned CUID) {
|
2014-03-18 02:13:58 +08:00
|
|
|
assert(CUID == 0);
|
|
|
|
|
|
|
|
MCDwarfLineTable &Table = getContext().getMCDwarfLineTable(CUID);
|
|
|
|
unsigned NumFiles = Table.getMCDwarfFiles().size();
|
|
|
|
FileNo = Table.getFile(Directory, Filename, FileNo);
|
|
|
|
if (FileNo == 0)
|
|
|
|
return 0;
|
|
|
|
if (NumFiles == Table.getMCDwarfFiles().size())
|
|
|
|
return FileNo;
|
|
|
|
|
|
|
|
SmallString<128> FullPathName;
|
|
|
|
|
2011-10-18 07:05:28 +08:00
|
|
|
if (!UseDwarfDirectory && !Directory.empty()) {
|
|
|
|
if (sys::path::is_absolute(Filename))
|
2014-03-18 02:13:58 +08:00
|
|
|
Directory = "";
|
|
|
|
else {
|
|
|
|
FullPathName = Directory;
|
|
|
|
sys::path::append(FullPathName, Filename);
|
|
|
|
Directory = "";
|
|
|
|
Filename = FullPathName;
|
|
|
|
}
|
2011-10-18 07:05:28 +08:00
|
|
|
}
|
|
|
|
|
2014-02-06 02:00:21 +08:00
|
|
|
OS << "\t.file\t" << FileNo << ' ';
|
|
|
|
if (!Directory.empty()) {
|
|
|
|
PrintQuotedString(Directory, OS);
|
|
|
|
OS << ' ';
|
2010-11-19 10:26:16 +08:00
|
|
|
}
|
2014-02-06 02:00:21 +08:00
|
|
|
PrintQuotedString(Filename, OS);
|
|
|
|
EmitEOL();
|
|
|
|
|
2014-03-18 02:13:58 +08:00
|
|
|
return FileNo;
|
2010-11-17 05:20:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MCAsmStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
|
|
|
|
unsigned Column, unsigned Flags,
|
|
|
|
unsigned Isa,
|
2011-04-19 04:26:49 +08:00
|
|
|
unsigned Discriminator,
|
|
|
|
StringRef FileName) {
|
2010-11-17 05:20:32 +08: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)
|
2014-02-14 04:05:03 +08:00
|
|
|
OS << " isa " << Isa;
|
2010-11-17 05:20:32 +08:00
|
|
|
if (Discriminator)
|
2014-02-14 04:05:03 +08:00
|
|
|
OS << " discriminator " << Discriminator;
|
2011-04-19 04:26:49 +08:00
|
|
|
|
|
|
|
if (IsVerboseAsm) {
|
2013-06-18 15:20:20 +08:00
|
|
|
OS.PadToColumn(MAI->getCommentColumn());
|
|
|
|
OS << MAI->getCommentString() << ' ' << FileName << ':'
|
2011-04-19 04:26:49 +08:00
|
|
|
<< Line << ':' << Column;
|
|
|
|
}
|
2010-11-17 05:20:32 +08:00
|
|
|
EmitEOL();
|
2014-12-31 06:47:13 +08:00
|
|
|
this->MCStreamer::EmitDwarfLocDirective(FileNo, Line, Column, Flags,
|
|
|
|
Isa, Discriminator, FileName);
|
2010-01-26 02:58:59 +08:00
|
|
|
}
|
|
|
|
|
2014-04-01 16:07:52 +08:00
|
|
|
MCSymbol *MCAsmStreamer::getDwarfLineTableSymbol(unsigned CUID) {
|
|
|
|
// Always use the zeroth line table, since asm syntax only supports one line
|
|
|
|
// table for now.
|
|
|
|
return MCStreamer::getDwarfLineTableSymbol(0);
|
|
|
|
}
|
|
|
|
|
2013-10-16 09:05:45 +08:00
|
|
|
void MCAsmStreamer::EmitIdent(StringRef IdentString) {
|
|
|
|
assert(MAI->hasIdentDirective() && ".ident directive not supported");
|
|
|
|
OS << "\t.ident\t";
|
|
|
|
PrintQuotedString(IdentString, OS);
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2011-05-10 21:39:48 +08:00
|
|
|
void MCAsmStreamer::EmitCFISections(bool EH, bool Debug) {
|
|
|
|
MCStreamer::EmitCFISections(EH, Debug);
|
|
|
|
OS << "\t.cfi_sections ";
|
|
|
|
if (EH) {
|
|
|
|
OS << ".eh_frame";
|
|
|
|
if (Debug)
|
|
|
|
OS << ", .debug_frame";
|
|
|
|
} else if (Debug) {
|
|
|
|
OS << ".debug_frame";
|
|
|
|
}
|
|
|
|
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2014-11-03 20:19:03 +08:00
|
|
|
void MCAsmStreamer::EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame) {
|
2011-01-15 05:57:39 +08:00
|
|
|
OS << "\t.cfi_startproc";
|
2014-01-28 01:20:25 +08:00
|
|
|
if (Frame.IsSimple)
|
|
|
|
OS << " simple";
|
2010-11-22 22:27:24 +08:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2012-01-09 08:17:29 +08:00
|
|
|
void MCAsmStreamer::EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) {
|
2014-06-25 08:13:59 +08:00
|
|
|
MCStreamer::EmitCFIEndProcImpl(Frame);
|
2011-01-15 05:57:39 +08:00
|
|
|
OS << "\t.cfi_endproc";
|
2010-11-22 22:27:24 +08:00
|
|
|
EmitEOL();
|
2011-04-13 07:59:07 +08:00
|
|
|
}
|
2010-11-22 22:27:24 +08:00
|
|
|
|
2011-05-31 04:20:15 +08:00
|
|
|
void MCAsmStreamer::EmitRegisterName(int64_t Register) {
|
2013-06-18 15:20:20 +08:00
|
|
|
if (InstPrinter && !MAI->useDwarfRegNumForCFI()) {
|
|
|
|
const MCRegisterInfo *MRI = getContext().getRegisterInfo();
|
|
|
|
unsigned LLVMRegister = MRI->getLLVMRegNum(Register, true);
|
2011-06-02 10:34:55 +08:00
|
|
|
InstPrinter->printRegName(OS, LLVMRegister);
|
2011-05-31 04:20:15 +08:00
|
|
|
} else {
|
|
|
|
OS << Register;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-13 07:59:07 +08:00
|
|
|
void MCAsmStreamer::EmitCFIDefCfa(int64_t Register, int64_t Offset) {
|
2011-04-30 05:41:06 +08:00
|
|
|
MCStreamer::EmitCFIDefCfa(Register, Offset);
|
2011-05-31 04:20:15 +08:00
|
|
|
OS << "\t.cfi_def_cfa ";
|
|
|
|
EmitRegisterName(Register);
|
|
|
|
OS << ", " << Offset;
|
2011-04-30 05:41:06 +08:00
|
|
|
EmitEOL();
|
2010-11-22 22:27:24 +08:00
|
|
|
}
|
|
|
|
|
2011-04-13 07:59:07 +08:00
|
|
|
void MCAsmStreamer::EmitCFIDefCfaOffset(int64_t Offset) {
|
|
|
|
MCStreamer::EmitCFIDefCfaOffset(Offset);
|
2011-01-15 05:57:39 +08:00
|
|
|
OS << "\t.cfi_def_cfa_offset " << Offset;
|
2010-11-22 22:27:24 +08:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2011-04-13 07:59:07 +08:00
|
|
|
void MCAsmStreamer::EmitCFIDefCfaRegister(int64_t Register) {
|
|
|
|
MCStreamer::EmitCFIDefCfaRegister(Register);
|
2011-05-31 04:20:15 +08:00
|
|
|
OS << "\t.cfi_def_cfa_register ";
|
|
|
|
EmitRegisterName(Register);
|
2010-11-22 22:27:24 +08:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2011-04-13 07:59:07 +08:00
|
|
|
void MCAsmStreamer::EmitCFIOffset(int64_t Register, int64_t Offset) {
|
|
|
|
this->MCStreamer::EmitCFIOffset(Register, Offset);
|
2011-05-31 04:20:15 +08:00
|
|
|
OS << "\t.cfi_offset ";
|
|
|
|
EmitRegisterName(Register);
|
|
|
|
OS << ", " << Offset;
|
2010-11-22 22:27:24 +08:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2011-04-13 07:59:07 +08:00
|
|
|
void MCAsmStreamer::EmitCFIPersonality(const MCSymbol *Sym,
|
2010-12-27 08:36:05 +08:00
|
|
|
unsigned Encoding) {
|
2011-04-13 07:59:07 +08:00
|
|
|
MCStreamer::EmitCFIPersonality(Sym, Encoding);
|
2011-01-15 05:57:39 +08:00
|
|
|
OS << "\t.cfi_personality " << Encoding << ", " << *Sym;
|
2010-11-22 22:27:24 +08:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2011-04-13 07:59:07 +08:00
|
|
|
void MCAsmStreamer::EmitCFILsda(const MCSymbol *Sym, unsigned Encoding) {
|
|
|
|
MCStreamer::EmitCFILsda(Sym, Encoding);
|
2011-01-15 05:57:39 +08:00
|
|
|
OS << "\t.cfi_lsda " << Encoding << ", " << *Sym;
|
2010-11-22 22:27:24 +08:00
|
|
|
EmitEOL();
|
2011-04-13 07:59:07 +08:00
|
|
|
}
|
2010-11-22 22:27:24 +08:00
|
|
|
|
2011-04-13 07:59:07 +08:00
|
|
|
void MCAsmStreamer::EmitCFIRememberState() {
|
|
|
|
MCStreamer::EmitCFIRememberState();
|
|
|
|
OS << "\t.cfi_remember_state";
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MCAsmStreamer::EmitCFIRestoreState() {
|
|
|
|
MCStreamer::EmitCFIRestoreState();
|
|
|
|
OS << "\t.cfi_restore_state";
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MCAsmStreamer::EmitCFISameValue(int64_t Register) {
|
|
|
|
MCStreamer::EmitCFISameValue(Register);
|
2011-05-31 04:20:15 +08:00
|
|
|
OS << "\t.cfi_same_value ";
|
|
|
|
EmitRegisterName(Register);
|
2011-04-13 07:59:07 +08:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MCAsmStreamer::EmitCFIRelOffset(int64_t Register, int64_t Offset) {
|
|
|
|
MCStreamer::EmitCFIRelOffset(Register, Offset);
|
2011-05-31 04:20:15 +08:00
|
|
|
OS << "\t.cfi_rel_offset ";
|
|
|
|
EmitRegisterName(Register);
|
|
|
|
OS << ", " << Offset;
|
2011-04-13 07:59:07 +08:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MCAsmStreamer::EmitCFIAdjustCfaOffset(int64_t Adjustment) {
|
|
|
|
MCStreamer::EmitCFIAdjustCfaOffset(Adjustment);
|
|
|
|
OS << "\t.cfi_adjust_cfa_offset " << Adjustment;
|
|
|
|
EmitEOL();
|
2010-11-22 22:27:24 +08:00
|
|
|
}
|
|
|
|
|
2012-01-24 05:51:52 +08:00
|
|
|
void MCAsmStreamer::EmitCFISignalFrame() {
|
|
|
|
MCStreamer::EmitCFISignalFrame();
|
2012-05-31 08:53:18 +08:00
|
|
|
OS << "\t.cfi_signal_frame";
|
2012-01-24 05:51:52 +08:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2012-11-24 00:59:41 +08:00
|
|
|
void MCAsmStreamer::EmitCFIUndefined(int64_t Register) {
|
|
|
|
MCStreamer::EmitCFIUndefined(Register);
|
|
|
|
OS << "\t.cfi_undefined " << Register;
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2012-11-25 23:14:49 +08:00
|
|
|
void MCAsmStreamer::EmitCFIRegister(int64_t Register1, int64_t Register2) {
|
|
|
|
MCStreamer::EmitCFIRegister(Register1, Register2);
|
|
|
|
OS << "\t.cfi_register " << Register1 << ", " << Register2;
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2013-09-26 22:49:40 +08:00
|
|
|
void MCAsmStreamer::EmitCFIWindowSave() {
|
|
|
|
MCStreamer::EmitCFIWindowSave();
|
|
|
|
OS << "\t.cfi_window_save";
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2014-06-29 09:52:01 +08:00
|
|
|
void MCAsmStreamer::EmitWinCFIStartProc(const MCSymbol *Symbol) {
|
|
|
|
MCStreamer::EmitWinCFIStartProc(Symbol);
|
2011-05-21 02:19:22 +08:00
|
|
|
|
2011-05-20 01:46:39 +08:00
|
|
|
OS << ".seh_proc " << *Symbol;
|
2011-05-18 12:58:05 +08:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2014-06-29 09:52:01 +08:00
|
|
|
void MCAsmStreamer::EmitWinCFIEndProc() {
|
|
|
|
MCStreamer::EmitWinCFIEndProc();
|
2011-05-21 02:19:22 +08:00
|
|
|
|
2011-05-20 01:46:39 +08:00
|
|
|
OS << "\t.seh_endproc";
|
2011-05-18 12:58:05 +08:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2014-06-29 09:52:01 +08:00
|
|
|
void MCAsmStreamer::EmitWinCFIStartChained() {
|
|
|
|
MCStreamer::EmitWinCFIStartChained();
|
2011-05-21 02:19:22 +08:00
|
|
|
|
2011-05-20 01:46:39 +08:00
|
|
|
OS << "\t.seh_startchained";
|
2011-05-19 04:54:10 +08:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2014-06-29 09:52:01 +08:00
|
|
|
void MCAsmStreamer::EmitWinCFIEndChained() {
|
|
|
|
MCStreamer::EmitWinCFIEndChained();
|
2011-05-21 02:19:22 +08:00
|
|
|
|
2011-05-20 01:46:39 +08:00
|
|
|
OS << "\t.seh_endchained";
|
2011-05-19 04:54:10 +08:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2014-06-29 09:52:01 +08:00
|
|
|
void MCAsmStreamer::EmitWinEHHandler(const MCSymbol *Sym, bool Unwind,
|
|
|
|
bool Except) {
|
|
|
|
MCStreamer::EmitWinEHHandler(Sym, Unwind, Except);
|
2011-05-21 02:19:22 +08:00
|
|
|
|
2011-05-20 01:46:39 +08:00
|
|
|
OS << "\t.seh_handler " << *Sym;
|
|
|
|
if (Unwind)
|
|
|
|
OS << ", @unwind";
|
|
|
|
if (Except)
|
|
|
|
OS << ", @except";
|
2011-05-19 04:54:10 +08:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2014-06-29 09:52:01 +08:00
|
|
|
void MCAsmStreamer::EmitWinEHHandlerData() {
|
|
|
|
MCStreamer::EmitWinEHHandlerData();
|
2011-05-21 02:19:22 +08:00
|
|
|
|
2011-05-26 05:43:45 +08:00
|
|
|
// Switch sections. Don't call SwitchSection directly, because that will
|
|
|
|
// cause the section switch to be visible in the emitted assembly.
|
|
|
|
// We only do this so the section switch that terminates the handler
|
|
|
|
// data block is visible.
|
2014-08-04 02:51:17 +08:00
|
|
|
WinEH::FrameInfo *CurFrame = getCurrentWinFrameInfo();
|
2015-05-22 03:20:38 +08:00
|
|
|
if (MCSection *XData = WinEH::UnwindEmitter::getXDataSection(
|
2014-09-05 01:42:03 +08:00
|
|
|
CurFrame->Function, getContext()))
|
2014-08-07 10:59:41 +08:00
|
|
|
SwitchSectionNoChange(XData);
|
2011-05-26 05:43:45 +08:00
|
|
|
|
2011-05-20 01:46:39 +08:00
|
|
|
OS << "\t.seh_handlerdata";
|
2011-05-19 04:54:10 +08:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2014-06-29 09:52:01 +08:00
|
|
|
void MCAsmStreamer::EmitWinCFIPushReg(unsigned Register) {
|
|
|
|
MCStreamer::EmitWinCFIPushReg(Register);
|
2011-05-21 02:19:22 +08:00
|
|
|
|
2014-06-11 04:16:36 +08:00
|
|
|
OS << "\t.seh_pushreg " << Register;
|
2011-05-18 12:58:05 +08:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2014-06-29 09:52:01 +08:00
|
|
|
void MCAsmStreamer::EmitWinCFISetFrame(unsigned Register, unsigned Offset) {
|
|
|
|
MCStreamer::EmitWinCFISetFrame(Register, Offset);
|
2011-05-21 02:19:22 +08:00
|
|
|
|
2014-06-11 04:16:36 +08:00
|
|
|
OS << "\t.seh_setframe " << Register << ", " << Offset;
|
2011-05-18 12:58:05 +08:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2014-06-29 09:52:01 +08:00
|
|
|
void MCAsmStreamer::EmitWinCFIAllocStack(unsigned Size) {
|
|
|
|
MCStreamer::EmitWinCFIAllocStack(Size);
|
2011-05-21 02:19:22 +08:00
|
|
|
|
2011-05-20 01:46:39 +08:00
|
|
|
OS << "\t.seh_stackalloc " << Size;
|
2011-05-18 12:58:05 +08:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2014-06-29 09:52:01 +08:00
|
|
|
void MCAsmStreamer::EmitWinCFISaveReg(unsigned Register, unsigned Offset) {
|
|
|
|
MCStreamer::EmitWinCFISaveReg(Register, Offset);
|
2011-05-21 02:19:22 +08:00
|
|
|
|
2014-06-11 04:16:36 +08:00
|
|
|
OS << "\t.seh_savereg " << Register << ", " << Offset;
|
2011-05-20 01:46:39 +08:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2014-06-29 09:52:01 +08:00
|
|
|
void MCAsmStreamer::EmitWinCFISaveXMM(unsigned Register, unsigned Offset) {
|
|
|
|
MCStreamer::EmitWinCFISaveXMM(Register, Offset);
|
2011-05-21 02:19:22 +08:00
|
|
|
|
2014-06-11 04:16:36 +08:00
|
|
|
OS << "\t.seh_savexmm " << Register << ", " << Offset;
|
2011-05-18 12:58:05 +08:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2014-06-29 09:52:01 +08:00
|
|
|
void MCAsmStreamer::EmitWinCFIPushFrame(bool Code) {
|
|
|
|
MCStreamer::EmitWinCFIPushFrame(Code);
|
2011-05-21 02:19:22 +08:00
|
|
|
|
2011-05-20 01:46:39 +08:00
|
|
|
OS << "\t.seh_pushframe";
|
2011-05-18 12:58:05 +08:00
|
|
|
if (Code)
|
2011-05-20 01:46:39 +08:00
|
|
|
OS << " @code";
|
2011-05-18 12:58:05 +08:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2014-06-29 09:52:01 +08:00
|
|
|
void MCAsmStreamer::EmitWinCFIEndProlog(void) {
|
|
|
|
MCStreamer::EmitWinCFIEndProlog();
|
2011-05-21 02:19:22 +08:00
|
|
|
|
2011-05-20 01:46:39 +08:00
|
|
|
OS << "\t.seh_endprologue";
|
2011-05-18 12:58:05 +08:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2014-01-29 07:13:07 +08:00
|
|
|
void MCAsmStreamer::AddEncodingComment(const MCInst &Inst,
|
|
|
|
const MCSubtargetInfo &STI) {
|
2010-02-10 07:00:14 +08:00
|
|
|
raw_ostream &OS = GetCommentOS();
|
|
|
|
SmallString<256> Code;
|
|
|
|
SmallVector<MCFixup, 4> Fixups;
|
2014-06-27 06:52:05 +08:00
|
|
|
raw_svector_ostream VecOS(Code);
|
2015-05-16 03:13:16 +08:00
|
|
|
Emitter->encodeInstruction(Inst, VecOS, Fixups, STI);
|
2014-06-27 06:52:05 +08:00
|
|
|
VecOS.flush();
|
2010-01-26 02:58:59 +08:00
|
|
|
|
2010-02-10 07:00:14 +08: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 09:41:14 +08:00
|
|
|
SmallVector<uint8_t, 64> FixupMap;
|
|
|
|
FixupMap.resize(Code.size() * 8);
|
2010-02-10 07:00:14 +08: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 11:20:06 +08:00
|
|
|
const MCFixupKindInfo &Info = AsmBackend->getFixupKindInfo(F.getKind());
|
2010-02-10 07:00:14 +08: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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-09 06:49:42 +08:00
|
|
|
// FIXME: Note the fixup comments for Thumb2 are completely bogus since the
|
2011-01-14 07:27:39 +08:00
|
|
|
// high order halfword of a 32-bit Thumb2 instruction is emitted first.
|
2010-02-10 07:00:14 +08:00
|
|
|
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 {
|
2011-01-14 05:45:26 +08:00
|
|
|
if (Code[i]) {
|
2011-01-14 07:27:39 +08:00
|
|
|
// FIXME: Some of the 8 bits require fix up.
|
2011-01-14 05:45:26 +08:00
|
|
|
OS << format("0x%02x", uint8_t(Code[i])) << '\''
|
|
|
|
<< char('A' + MapEntry - 1) << '\'';
|
|
|
|
} else
|
|
|
|
OS << char('A' + MapEntry - 1);
|
2010-02-10 07:00:14 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Otherwise, write out in binary.
|
|
|
|
OS << "0b";
|
2011-06-23 17:09:15 +08:00
|
|
|
for (unsigned j = 8; j--;) {
|
2010-02-10 07:00:14 +08:00
|
|
|
unsigned Bit = (Code[i] >> j) & 1;
|
2011-03-27 09:44:40 +08:00
|
|
|
|
2010-11-15 13:56:19 +08:00
|
|
|
unsigned FixupBit;
|
2013-06-18 15:20:20 +08:00
|
|
|
if (MAI->isLittleEndian())
|
2010-11-15 13:56:19 +08:00
|
|
|
FixupBit = i * 8 + j;
|
|
|
|
else
|
|
|
|
FixupBit = i * 8 + (7-j);
|
2011-03-27 09:44:40 +08:00
|
|
|
|
2011-06-23 17:09:15 +08:00
|
|
|
if (uint8_t MapEntry = FixupMap[FixupBit]) {
|
|
|
|
assert(Bit == 0 && "Encoder wrote into fixed up bit!");
|
|
|
|
OS << char('A' + MapEntry - 1);
|
2010-02-10 07:00:14 +08:00
|
|
|
} else
|
|
|
|
OS << Bit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OS << "]\n";
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
|
|
|
|
MCFixup &F = Fixups[i];
|
2010-12-16 11:20:06 +08:00
|
|
|
const MCFixupKindInfo &Info = AsmBackend->getFixupKindInfo(F.getKind());
|
2010-02-10 07:00:14 +08:00
|
|
|
OS << " fixup " << char('A' + i) << " - " << "offset: " << F.getOffset()
|
2010-02-10 12:47:08 +08:00
|
|
|
<< ", value: " << *F.getValue() << ", kind: " << Info.Name << "\n";
|
2010-02-10 07:00:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-29 07:12:42 +08:00
|
|
|
void MCAsmStreamer::EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) {
|
2013-04-18 05:18:16 +08:00
|
|
|
assert(getCurrentSection().first &&
|
|
|
|
"Cannot emit contents before setting section!");
|
2010-02-10 07:00:14 +08:00
|
|
|
|
|
|
|
// Show the encoding in a comment if we have a code emitter.
|
|
|
|
if (Emitter)
|
2014-01-29 07:13:07 +08:00
|
|
|
AddEncodingComment(Inst, STI);
|
2010-02-10 07:00:14 +08:00
|
|
|
|
2010-02-09 08:54:51 +08:00
|
|
|
// Show the MCInst if enabled.
|
2010-05-26 23:18:13 +08:00
|
|
|
if (ShowInst) {
|
2015-02-05 08:58:51 +08:00
|
|
|
Inst.dump_pretty(GetCommentOS(), InstPrinter.get(), "\n ");
|
2010-05-26 23:18:13 +08:00
|
|
|
GetCommentOS() << "\n";
|
|
|
|
}
|
|
|
|
|
2010-03-23 05:49:34 +08:00
|
|
|
// If we have an AsmPrinter, use that to print, otherwise print the MCInst.
|
2010-02-04 02:18:30 +08:00
|
|
|
if (InstPrinter)
|
2015-03-28 04:36:02 +08:00
|
|
|
InstPrinter->printInst(&Inst, OS, "", STI);
|
2010-02-04 02:18:30 +08:00
|
|
|
else
|
2015-02-05 08:58:51 +08:00
|
|
|
Inst.print(OS);
|
2010-01-22 15:36:39 +08:00
|
|
|
EmitEOL();
|
2009-06-24 09:03:06 +08:00
|
|
|
}
|
|
|
|
|
2012-12-21 03:05:53 +08:00
|
|
|
void MCAsmStreamer::EmitBundleAlignMode(unsigned AlignPow2) {
|
|
|
|
OS << "\t.bundle_align_mode " << AlignPow2;
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2013-01-08 05:51:08 +08:00
|
|
|
void MCAsmStreamer::EmitBundleLock(bool AlignToEnd) {
|
2012-12-21 03:05:53 +08:00
|
|
|
OS << "\t.bundle_lock";
|
2013-01-08 05:51:08 +08:00
|
|
|
if (AlignToEnd)
|
|
|
|
OS << " align_to_end";
|
2012-12-21 03:05:53 +08:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MCAsmStreamer::EmitBundleUnlock() {
|
|
|
|
OS << "\t.bundle_unlock";
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2010-09-23 02:18:30 +08:00
|
|
|
/// EmitRawText - If this file is backed by an assembly streamer, this dumps
|
2010-04-04 05:35:55 +08:00
|
|
|
/// the specified string in the output .s file. This capability is
|
|
|
|
/// indicated by the hasRawTextSupport() predicate.
|
2013-10-25 06:43:10 +08:00
|
|
|
void MCAsmStreamer::EmitRawTextImpl(StringRef String) {
|
2010-04-04 06:06:56 +08:00
|
|
|
if (!String.empty() && String.back() == '\n')
|
|
|
|
String = String.substr(0, String.size()-1);
|
2010-04-04 05:35:55 +08:00
|
|
|
OS << String;
|
2010-04-04 06:06:56 +08:00
|
|
|
EmitEOL();
|
2010-04-04 05:35:55 +08:00
|
|
|
}
|
|
|
|
|
2012-01-07 11:13:18 +08:00
|
|
|
void MCAsmStreamer::FinishImpl() {
|
2011-12-10 02:09:40 +08:00
|
|
|
// If we are generating dwarf for assembly source files dump out the sections.
|
|
|
|
if (getContext().getGenDwarfForAssembly())
|
2014-04-01 15:35:52 +08:00
|
|
|
MCGenDwarfInfo::Emit(this);
|
|
|
|
|
|
|
|
// Emit the label for the line table, if requested - since the rest of the
|
|
|
|
// line table will be defined by .loc/.file directives, and not emitted
|
|
|
|
// directly, the label is the only work required here.
|
|
|
|
auto &Tables = getContext().getMCDwarfLineTables();
|
|
|
|
if (!Tables.empty()) {
|
2014-04-01 16:07:52 +08:00
|
|
|
assert(Tables.size() == 1 && "asm output only supports one line table");
|
2014-04-01 15:35:52 +08:00
|
|
|
if (auto *Label = Tables.begin()->second.getLabel()) {
|
|
|
|
SwitchSection(getContext().getObjectFileInfo()->getDwarfLineSection());
|
|
|
|
EmitLabel(Label);
|
|
|
|
}
|
|
|
|
}
|
2009-06-24 09:03:06 +08:00
|
|
|
}
|
2013-09-10 03:48:37 +08:00
|
|
|
|
2010-01-22 15:29:22 +08:00
|
|
|
MCStreamer *llvm::createAsmStreamer(MCContext &Context,
|
2015-04-10 05:06:08 +08:00
|
|
|
std::unique_ptr<formatted_raw_ostream> OS,
|
2014-05-07 21:00:43 +08:00
|
|
|
bool isVerboseAsm, bool useDwarfDirectory,
|
|
|
|
MCInstPrinter *IP, MCCodeEmitter *CE,
|
|
|
|
MCAsmBackend *MAB, bool ShowInst) {
|
2015-04-10 05:06:08 +08:00
|
|
|
return new MCAsmStreamer(Context, std::move(OS), isVerboseAsm,
|
|
|
|
useDwarfDirectory, IP, CE, MAB, ShowInst);
|
2009-06-24 09:03:06 +08:00
|
|
|
}
|