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"
|
2011-07-26 20:57:44 +00:00
|
|
|
#include "llvm/MC/MCObjectFileInfo.h"
|
2011-07-18 20:57:22 +00:00
|
|
|
#include "llvm/MC/MCRegisterInfo.h"
|
2011-07-20 05:58:47 +00:00
|
|
|
#include "llvm/MC/MCSectionCOFF.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"
|
2011-07-25 23:24:55 +00:00
|
|
|
#include "llvm/MC/MCAsmBackend.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"
|
2011-06-17 20:35:21 +00:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2010-01-22 07:29:22 +00:00
|
|
|
#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"
|
2011-10-17 23:05:28 +00:00
|
|
|
#include "llvm/Support/PathV2.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 {
|
2011-06-17 20:35:21 +00:00
|
|
|
protected:
|
2010-01-22 07:29:22 +00:00
|
|
|
formatted_raw_ostream &OS;
|
2009-08-22 21:43:10 +00:00
|
|
|
const MCAsmInfo &MAI;
|
2011-06-17 20:35:21 +00:00
|
|
|
private:
|
2010-03-19 05:48:53 +00:00
|
|
|
OwningPtr<MCInstPrinter> InstPrinter;
|
2010-07-29 17:48:06 +00:00
|
|
|
OwningPtr<MCCodeEmitter> Emitter;
|
2011-07-25 23:24:55 +00:00
|
|
|
OwningPtr<MCAsmBackend> 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;
|
2011-04-30 03:44:37 +00:00
|
|
|
unsigned UseCFI : 1;
|
2011-10-17 23:05:28 +00:00
|
|
|
unsigned UseDwarfDirectory : 1;
|
2010-02-03 18:18:30 +00:00
|
|
|
|
2011-04-30 16:34:57 +00:00
|
|
|
enum EHSymbolFlags { EHGlobal = 1,
|
|
|
|
EHWeakDefinition = 1 << 1,
|
|
|
|
EHPrivateExtern = 1 << 2 };
|
|
|
|
DenseMap<const MCSymbol*, unsigned> FlagMap;
|
|
|
|
|
2010-12-04 03:21:47 +00:00
|
|
|
bool needsSet(const MCExpr *Value);
|
|
|
|
|
2011-05-30 20:20:15 +00:00
|
|
|
void EmitRegisterName(int64_t Register);
|
2012-01-07 22:42:19 +00:00
|
|
|
virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
|
2012-01-09 00:17:29 +00:00
|
|
|
virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame);
|
2011-05-30 20:20:15 +00:00
|
|
|
|
2009-08-17 04:17:34 +00:00
|
|
|
public:
|
2010-01-22 07:29:22 +00:00
|
|
|
MCAsmStreamer(MCContext &Context, formatted_raw_ostream &os,
|
2011-04-30 03:44:37 +00:00
|
|
|
bool isVerboseAsm, bool useLoc, bool useCFI,
|
2011-10-17 23:05:28 +00:00
|
|
|
bool useDwarfDirectory,
|
2010-12-16 03:05:59 +00:00
|
|
|
MCInstPrinter *printer, MCCodeEmitter *emitter,
|
2011-07-25 23:24:55 +00:00
|
|
|
MCAsmBackend *asmbackend,
|
2010-12-16 03:05:59 +00:00
|
|
|
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),
|
2011-10-17 23:05:28 +00:00
|
|
|
ShowInst(showInst), UseLoc(useLoc), UseCFI(useCFI),
|
|
|
|
UseDwarfDirectory(useDwarfDirectory) {
|
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
|
|
|
|
2011-02-16 01:08:29 +00:00
|
|
|
virtual void ChangeSection(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);
|
2011-04-30 16:34:57 +00:00
|
|
|
virtual void EmitEHSymAttributes(const MCSymbol *Symbol,
|
|
|
|
MCSymbol *EHSymbol);
|
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,
|
2011-07-14 05:43:07 +00:00
|
|
|
const MCSymbol *Label,
|
|
|
|
unsigned PointerSize);
|
2011-04-30 03:21:04 +00:00
|
|
|
virtual void EmitDwarfAdvanceFrameAddr(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();
|
2011-12-17 01:14:52 +00:00
|
|
|
virtual void EmitCOFFSecRel32(MCSymbol const *Symbol);
|
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.
|
2011-09-01 23:04:27 +00:00
|
|
|
/// @param Size - The alignment of the common symbol in bytes.
|
|
|
|
virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
|
|
|
|
unsigned ByteAlignment);
|
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,
|
2011-05-01 03:50:49 +00:00
|
|
|
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
|
|
|
|
2011-04-21 23:39:26 +00:00
|
|
|
virtual void EmitULEB128Value(const MCExpr *Value);
|
2010-11-02 17:22:24 +00:00
|
|
|
|
2011-04-21 23:39:26 +00:00
|
|
|
virtual void EmitSLEB128Value(const MCExpr *Value);
|
2010-11-02 17:22:24 +00:00
|
|
|
|
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);
|
2011-10-17 23:05:28 +00:00
|
|
|
virtual bool EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
|
|
|
|
StringRef Filename);
|
2010-11-16 21:20:32 +00:00
|
|
|
virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
|
|
|
|
unsigned Column, unsigned Flags,
|
2011-04-18 20:26:49 +00:00
|
|
|
unsigned Isa, unsigned Discriminator,
|
|
|
|
StringRef FileName);
|
2010-01-25 18:58:59 +00:00
|
|
|
|
2011-05-10 13:39:48 +00:00
|
|
|
virtual void EmitCFISections(bool EH, bool Debug);
|
2011-04-12 23:59:07 +00:00
|
|
|
virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset);
|
|
|
|
virtual void EmitCFIDefCfaOffset(int64_t Offset);
|
|
|
|
virtual void EmitCFIDefCfaRegister(int64_t Register);
|
|
|
|
virtual void EmitCFIOffset(int64_t Register, int64_t Offset);
|
|
|
|
virtual void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding);
|
|
|
|
virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding);
|
|
|
|
virtual void EmitCFIRememberState();
|
|
|
|
virtual void EmitCFIRestoreState();
|
|
|
|
virtual void EmitCFISameValue(int64_t Register);
|
|
|
|
virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset);
|
|
|
|
virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment);
|
2012-01-23 21:51:52 +00:00
|
|
|
virtual void EmitCFISignalFrame();
|
2010-11-22 14:27:24 +00:00
|
|
|
|
2011-05-22 21:12:15 +00:00
|
|
|
virtual void EmitWin64EHStartProc(const MCSymbol *Symbol);
|
2011-05-18 04:58:05 +00:00
|
|
|
virtual void EmitWin64EHEndProc();
|
2011-05-18 20:54:10 +00:00
|
|
|
virtual void EmitWin64EHStartChained();
|
|
|
|
virtual void EmitWin64EHEndChained();
|
2011-05-19 17:46:39 +00:00
|
|
|
virtual void EmitWin64EHHandler(const MCSymbol *Sym, bool Unwind,
|
|
|
|
bool Except);
|
|
|
|
virtual void EmitWin64EHHandlerData();
|
2011-05-19 19:35:55 +00:00
|
|
|
virtual void EmitWin64EHPushReg(unsigned Register);
|
|
|
|
virtual void EmitWin64EHSetFrame(unsigned Register, unsigned Offset);
|
|
|
|
virtual void EmitWin64EHAllocStack(unsigned Size);
|
|
|
|
virtual void EmitWin64EHSaveReg(unsigned Register, unsigned Offset);
|
|
|
|
virtual void EmitWin64EHSaveXMM(unsigned Register, unsigned Offset);
|
2011-05-18 04:58:05 +00:00
|
|
|
virtual void EmitWin64EHPushFrame(bool Code);
|
|
|
|
virtual void EmitWin64EHEndProlog();
|
|
|
|
|
2011-03-05 18:43:15 +00:00
|
|
|
virtual void EmitFnStart();
|
|
|
|
virtual void EmitFnEnd();
|
|
|
|
virtual void EmitCantUnwind();
|
|
|
|
virtual void EmitPersonality(const MCSymbol *Personality);
|
|
|
|
virtual void EmitHandlerData();
|
2011-03-05 18:43:32 +00:00
|
|
|
virtual void EmitSetFP(unsigned FpReg, unsigned SpReg, int64_t Offset = 0);
|
|
|
|
virtual void EmitPad(int64_t Offset);
|
|
|
|
virtual void EmitRegSave(const SmallVectorImpl<unsigned> &RegList, bool);
|
|
|
|
|
2011-03-05 18:43:15 +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
|
|
|
|
2012-01-07 03:13:18 +00:00
|
|
|
virtual void FinishImpl();
|
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));
|
|
|
|
}
|
|
|
|
|
2011-02-16 01:08:29 +00:00
|
|
|
void MCAsmStreamer::ChangeSection(const MCSection *Section) {
|
2009-08-19 05:49:37 +00:00
|
|
|
assert(Section && "Cannot switch to a null section!");
|
2011-02-16 01:08:29 +00:00
|
|
|
Section->PrintSwitchToSection(MAI, OS);
|
2009-06-24 01:03:06 +00:00
|
|
|
}
|
|
|
|
|
2011-04-30 16:34:57 +00:00
|
|
|
void MCAsmStreamer::EmitEHSymAttributes(const MCSymbol *Symbol,
|
|
|
|
MCSymbol *EHSymbol) {
|
|
|
|
if (UseCFI)
|
|
|
|
return;
|
|
|
|
|
|
|
|
unsigned Flags = FlagMap.lookup(Symbol);
|
|
|
|
|
|
|
|
if (Flags & EHGlobal)
|
|
|
|
EmitSymbolAttribute(EHSymbol, MCSA_Global);
|
|
|
|
if (Flags & EHWeakDefinition)
|
|
|
|
EmitSymbolAttribute(EHSymbol, MCSA_WeakDefinition);
|
|
|
|
if (Flags & EHPrivateExtern)
|
|
|
|
EmitSymbolAttribute(EHSymbol, MCSA_PrivateExtern);
|
|
|
|
}
|
|
|
|
|
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!");
|
2011-04-27 15:21:19 +00:00
|
|
|
MCStreamer::EmitLabel(Symbol);
|
2009-06-24 17:00:42 +00:00
|
|
|
|
2010-09-22 22:19:53 +00:00
|
|
|
OS << *Symbol << MAI.getLabelSuffix();
|
2010-01-22 07:36:39 +00:00
|
|
|
EmitEOL();
|
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) {
|
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;
|
2011-07-27 00:38:12 +00: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-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";
|
2011-05-16 16:17:21 +00:00
|
|
|
// Only Mach-O hasSubsectionsViaSymbols()
|
|
|
|
if (MAI.hasSubsectionsViaSymbols())
|
2010-11-05 22:08:08 +00:00
|
|
|
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,
|
2011-07-14 05:43:07 +00:00
|
|
|
const MCSymbol *Label,
|
|
|
|
unsigned PointerSize) {
|
|
|
|
EmitDwarfSetLineAddr(LineDelta, Label, PointerSize);
|
2010-12-03 00:55:40 +00:00
|
|
|
}
|
|
|
|
|
2011-04-30 03:21:04 +00:00
|
|
|
void MCAsmStreamer::EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
|
|
|
|
const MCSymbol *Label) {
|
|
|
|
EmitIntValue(dwarf::DW_CFA_advance_loc4, 1);
|
|
|
|
const MCExpr *AddrDelta = BuildSymbolDiff(getContext(), Label, LastLabel);
|
2011-05-19 21:40:34 +00:00
|
|
|
AddrDelta = ForceExpAbs(AddrDelta);
|
2011-04-30 03:21:04 +00:00
|
|
|
EmitValue(AddrDelta, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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();
|
2011-04-30 16:34:57 +00:00
|
|
|
FlagMap[Symbol] |= EHGlobal;
|
2010-01-25 18:30:45 +00:00
|
|
|
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;
|
2011-04-30 16:34:57 +00:00
|
|
|
case MCSA_PrivateExtern:
|
|
|
|
OS << "\t.private_extern\t";
|
|
|
|
FlagMap[Symbol] |= EHPrivateExtern;
|
|
|
|
break;
|
2010-06-21 20:35:01 +00:00
|
|
|
case MCSA_Protected: OS << "\t.protected\t"; break;
|
|
|
|
case MCSA_Reference: OS << "\t.reference\t"; break;
|
|
|
|
case MCSA_Weak: OS << "\t.weak\t"; break;
|
2011-04-30 16:34:57 +00:00
|
|
|
case MCSA_WeakDefinition:
|
|
|
|
OS << "\t.weak_definition\t";
|
|
|
|
FlagMap[Symbol] |= EHWeakDefinition;
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2011-12-17 01:14:52 +00:00
|
|
|
void MCAsmStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol) {
|
|
|
|
OS << "\t.secrel32\t" << *Symbol << '\n';
|
|
|
|
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.
|
2011-09-01 23:04:27 +00:00
|
|
|
void MCAsmStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
|
|
|
|
unsigned ByteAlign) {
|
|
|
|
assert(MAI.getLCOMMDirectiveType() != LCOMM::None &&
|
|
|
|
"Doesn't have .lcomm, can't emit it!");
|
2010-01-23 07:47:02 +00:00
|
|
|
OS << "\t.lcomm\t" << *Symbol << ',' << Size;
|
2011-09-01 23:04:27 +00:00
|
|
|
if (ByteAlign > 1) {
|
|
|
|
assert(MAI.getLCOMMDirectiveType() == LCOMM::ByteAlignment &&
|
|
|
|
"Alignment not supported on .lcomm!");
|
|
|
|
OS << ',' << ByteAlign;
|
|
|
|
}
|
2010-01-23 07:47:02 +00:00
|
|
|
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) {
|
2011-02-16 01:08:29 +00:00
|
|
|
assert(getCurrentSection() && "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,
|
2011-05-01 03:50:49 +00:00
|
|
|
unsigned AddrSpace) {
|
2011-02-16 01:08:29 +00:00
|
|
|
assert(getCurrentSection() && "Cannot emit contents before setting section!");
|
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.");
|
2011-07-15 02:09:41 +00:00
|
|
|
if (getContext().getAsmInfo().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
|
|
|
}
|
|
|
|
|
2011-04-21 23:39:26 +00:00
|
|
|
void MCAsmStreamer::EmitULEB128Value(const MCExpr *Value) {
|
2010-11-19 04:10:13 +00:00
|
|
|
int64_t IntValue;
|
|
|
|
if (Value->EvaluateAsAbsolute(IntValue)) {
|
2011-04-21 23:39:26 +00:00
|
|
|
EmitULEB128IntValue(IntValue);
|
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();
|
|
|
|
}
|
|
|
|
|
2011-04-21 23:39:26 +00:00
|
|
|
void MCAsmStreamer::EmitSLEB128Value(const MCExpr *Value) {
|
2010-11-19 04:10:13 +00:00
|
|
|
int64_t IntValue;
|
|
|
|
if (Value->EvaluateAsAbsolute(IntValue)) {
|
2011-04-21 23:39:26 +00:00
|
|
|
EmitSLEB128IntValue(IntValue);
|
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();
|
|
|
|
}
|
|
|
|
|
2011-10-17 23:05:28 +00:00
|
|
|
bool MCAsmStreamer::EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
|
|
|
|
StringRef Filename) {
|
|
|
|
if (!UseDwarfDirectory && !Directory.empty()) {
|
|
|
|
if (sys::path::is_absolute(Filename))
|
|
|
|
return EmitDwarfFileDirective(FileNo, "", Filename);
|
|
|
|
|
|
|
|
SmallString<128> FullPathName = Directory;
|
|
|
|
sys::path::append(FullPathName, Filename);
|
|
|
|
return EmitDwarfFileDirective(FileNo, "", FullPathName);
|
|
|
|
}
|
|
|
|
|
2010-12-10 07:39:47 +00:00
|
|
|
if (UseLoc) {
|
2010-11-19 02:26:16 +00:00
|
|
|
OS << "\t.file\t" << FileNo << ' ';
|
2011-10-17 23:05:28 +00:00
|
|
|
if (!Directory.empty()) {
|
|
|
|
PrintQuotedString(Directory, OS);
|
|
|
|
OS << ' ';
|
|
|
|
}
|
2010-11-19 02:26:16 +00:00
|
|
|
PrintQuotedString(Filename, OS);
|
|
|
|
EmitEOL();
|
|
|
|
}
|
2011-10-17 23:05:28 +00:00
|
|
|
return this->MCStreamer::EmitDwarfFileDirective(FileNo, Directory, Filename);
|
2010-11-16 21:20:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MCAsmStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
|
|
|
|
unsigned Column, unsigned Flags,
|
|
|
|
unsigned Isa,
|
2011-04-18 20:26:49 +00:00
|
|
|
unsigned Discriminator,
|
|
|
|
StringRef FileName) {
|
2010-11-19 02:26:16 +00:00
|
|
|
this->MCStreamer::EmitDwarfLocDirective(FileNo, Line, Column, Flags,
|
2011-04-18 20:26:49 +00:00
|
|
|
Isa, Discriminator, FileName);
|
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;
|
2011-04-18 20:26:49 +00:00
|
|
|
|
|
|
|
if (IsVerboseAsm) {
|
|
|
|
OS.PadToColumn(MAI.getCommentColumn());
|
|
|
|
OS << MAI.getCommentString() << ' ' << FileName << ':'
|
|
|
|
<< Line << ':' << Column;
|
|
|
|
}
|
2010-11-16 21:20:32 +00:00
|
|
|
EmitEOL();
|
2010-01-25 18:58:59 +00:00
|
|
|
}
|
|
|
|
|
2011-05-10 13:39:48 +00:00
|
|
|
void MCAsmStreamer::EmitCFISections(bool EH, bool Debug) {
|
|
|
|
MCStreamer::EmitCFISections(EH, Debug);
|
|
|
|
|
|
|
|
if (!UseCFI)
|
|
|
|
return;
|
|
|
|
|
|
|
|
OS << "\t.cfi_sections ";
|
|
|
|
if (EH) {
|
|
|
|
OS << ".eh_frame";
|
|
|
|
if (Debug)
|
|
|
|
OS << ", .debug_frame";
|
|
|
|
} else if (Debug) {
|
|
|
|
OS << ".debug_frame";
|
|
|
|
}
|
|
|
|
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2012-01-07 22:42:19 +00:00
|
|
|
void MCAsmStreamer::EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame) {
|
|
|
|
if (!UseCFI) {
|
|
|
|
RecordProcStart(Frame);
|
2011-04-30 03:44:37 +00:00
|
|
|
return;
|
2012-01-07 22:42:19 +00:00
|
|
|
}
|
2011-04-30 03:44:37 +00:00
|
|
|
|
2011-01-14 21:57:39 +00:00
|
|
|
OS << "\t.cfi_startproc";
|
2010-11-22 14:27:24 +00:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2012-01-09 00:17:29 +00:00
|
|
|
void MCAsmStreamer::EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) {
|
|
|
|
if (!UseCFI) {
|
|
|
|
RecordProcEnd(Frame);
|
2011-04-30 03:44:37 +00:00
|
|
|
return;
|
2012-01-09 00:17:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Put a dummy non-null value in Frame.End to mark that this frame has been
|
|
|
|
// closed.
|
|
|
|
Frame.End = (MCSymbol *) 1;
|
2011-04-30 03:44:37 +00:00
|
|
|
|
2011-01-14 21:57:39 +00:00
|
|
|
OS << "\t.cfi_endproc";
|
2010-11-22 14:27:24 +00:00
|
|
|
EmitEOL();
|
2011-04-12 23:59:07 +00:00
|
|
|
}
|
2010-11-22 14:27:24 +00:00
|
|
|
|
2011-05-30 20:20:15 +00:00
|
|
|
void MCAsmStreamer::EmitRegisterName(int64_t Register) {
|
2011-07-07 20:30:33 +00:00
|
|
|
if (InstPrinter && !MAI.useDwarfRegNumForCFI()) {
|
2011-07-18 20:57:22 +00:00
|
|
|
const MCRegisterInfo &MRI = getContext().getRegisterInfo();
|
|
|
|
unsigned LLVMRegister = MRI.getLLVMRegNum(Register, true);
|
2011-06-02 02:34:55 +00:00
|
|
|
InstPrinter->printRegName(OS, LLVMRegister);
|
2011-05-30 20:20:15 +00:00
|
|
|
} else {
|
|
|
|
OS << Register;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-12 23:59:07 +00:00
|
|
|
void MCAsmStreamer::EmitCFIDefCfa(int64_t Register, int64_t Offset) {
|
2011-04-29 21:41:06 +00:00
|
|
|
MCStreamer::EmitCFIDefCfa(Register, Offset);
|
|
|
|
|
2011-04-30 03:44:37 +00:00
|
|
|
if (!UseCFI)
|
|
|
|
return;
|
|
|
|
|
2011-05-30 20:20:15 +00:00
|
|
|
OS << "\t.cfi_def_cfa ";
|
|
|
|
EmitRegisterName(Register);
|
|
|
|
OS << ", " << Offset;
|
2011-04-29 21:41:06 +00:00
|
|
|
EmitEOL();
|
2010-11-22 14:27:24 +00:00
|
|
|
}
|
|
|
|
|
2011-04-12 23:59:07 +00:00
|
|
|
void MCAsmStreamer::EmitCFIDefCfaOffset(int64_t Offset) {
|
|
|
|
MCStreamer::EmitCFIDefCfaOffset(Offset);
|
2010-11-22 14:27:24 +00:00
|
|
|
|
2011-04-30 03:44:37 +00:00
|
|
|
if (!UseCFI)
|
|
|
|
return;
|
|
|
|
|
2011-01-14 21:57:39 +00:00
|
|
|
OS << "\t.cfi_def_cfa_offset " << Offset;
|
2010-11-22 14:27:24 +00:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2011-04-12 23:59:07 +00:00
|
|
|
void MCAsmStreamer::EmitCFIDefCfaRegister(int64_t Register) {
|
|
|
|
MCStreamer::EmitCFIDefCfaRegister(Register);
|
2010-11-22 14:27:24 +00:00
|
|
|
|
2011-04-30 03:44:37 +00:00
|
|
|
if (!UseCFI)
|
|
|
|
return;
|
|
|
|
|
2011-05-30 20:20:15 +00:00
|
|
|
OS << "\t.cfi_def_cfa_register ";
|
|
|
|
EmitRegisterName(Register);
|
2010-11-22 14:27:24 +00:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2011-04-12 23:59:07 +00:00
|
|
|
void MCAsmStreamer::EmitCFIOffset(int64_t Register, int64_t Offset) {
|
|
|
|
this->MCStreamer::EmitCFIOffset(Register, Offset);
|
2010-11-22 14:27:24 +00:00
|
|
|
|
2011-04-30 03:44:37 +00:00
|
|
|
if (!UseCFI)
|
|
|
|
return;
|
|
|
|
|
2011-05-30 20:20:15 +00:00
|
|
|
OS << "\t.cfi_offset ";
|
|
|
|
EmitRegisterName(Register);
|
|
|
|
OS << ", " << Offset;
|
2010-11-22 14:27:24 +00:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2011-04-12 23:59:07 +00:00
|
|
|
void MCAsmStreamer::EmitCFIPersonality(const MCSymbol *Sym,
|
2010-12-27 00:36:05 +00:00
|
|
|
unsigned Encoding) {
|
2011-04-12 23:59:07 +00:00
|
|
|
MCStreamer::EmitCFIPersonality(Sym, Encoding);
|
2010-11-22 14:27:24 +00:00
|
|
|
|
2011-04-30 03:44:37 +00:00
|
|
|
if (!UseCFI)
|
|
|
|
return;
|
|
|
|
|
2011-01-14 21:57:39 +00:00
|
|
|
OS << "\t.cfi_personality " << Encoding << ", " << *Sym;
|
2010-11-22 14:27:24 +00:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2011-04-12 23:59:07 +00:00
|
|
|
void MCAsmStreamer::EmitCFILsda(const MCSymbol *Sym, unsigned Encoding) {
|
|
|
|
MCStreamer::EmitCFILsda(Sym, Encoding);
|
2010-11-22 14:27:24 +00:00
|
|
|
|
2011-04-30 03:44:37 +00:00
|
|
|
if (!UseCFI)
|
|
|
|
return;
|
|
|
|
|
2011-01-14 21:57:39 +00:00
|
|
|
OS << "\t.cfi_lsda " << Encoding << ", " << *Sym;
|
2010-11-22 14:27:24 +00:00
|
|
|
EmitEOL();
|
2011-04-12 23:59:07 +00:00
|
|
|
}
|
2010-11-22 14:27:24 +00:00
|
|
|
|
2011-04-12 23:59:07 +00:00
|
|
|
void MCAsmStreamer::EmitCFIRememberState() {
|
|
|
|
MCStreamer::EmitCFIRememberState();
|
|
|
|
|
2011-04-30 03:44:37 +00:00
|
|
|
if (!UseCFI)
|
|
|
|
return;
|
|
|
|
|
2011-04-12 23:59:07 +00:00
|
|
|
OS << "\t.cfi_remember_state";
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MCAsmStreamer::EmitCFIRestoreState() {
|
|
|
|
MCStreamer::EmitCFIRestoreState();
|
|
|
|
|
2011-04-30 03:44:37 +00:00
|
|
|
if (!UseCFI)
|
|
|
|
return;
|
|
|
|
|
2011-04-12 23:59:07 +00:00
|
|
|
OS << "\t.cfi_restore_state";
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MCAsmStreamer::EmitCFISameValue(int64_t Register) {
|
|
|
|
MCStreamer::EmitCFISameValue(Register);
|
|
|
|
|
2011-04-30 03:44:37 +00:00
|
|
|
if (!UseCFI)
|
|
|
|
return;
|
|
|
|
|
2011-05-30 20:20:15 +00:00
|
|
|
OS << "\t.cfi_same_value ";
|
|
|
|
EmitRegisterName(Register);
|
2011-04-12 23:59:07 +00:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MCAsmStreamer::EmitCFIRelOffset(int64_t Register, int64_t Offset) {
|
|
|
|
MCStreamer::EmitCFIRelOffset(Register, Offset);
|
|
|
|
|
2011-04-30 03:44:37 +00:00
|
|
|
if (!UseCFI)
|
|
|
|
return;
|
|
|
|
|
2011-05-30 20:20:15 +00:00
|
|
|
OS << "\t.cfi_rel_offset ";
|
|
|
|
EmitRegisterName(Register);
|
|
|
|
OS << ", " << Offset;
|
2011-04-12 23:59:07 +00:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MCAsmStreamer::EmitCFIAdjustCfaOffset(int64_t Adjustment) {
|
|
|
|
MCStreamer::EmitCFIAdjustCfaOffset(Adjustment);
|
|
|
|
|
2011-04-30 03:44:37 +00:00
|
|
|
if (!UseCFI)
|
|
|
|
return;
|
|
|
|
|
2011-04-12 23:59:07 +00:00
|
|
|
OS << "\t.cfi_adjust_cfa_offset " << Adjustment;
|
|
|
|
EmitEOL();
|
2010-11-22 14:27:24 +00:00
|
|
|
}
|
|
|
|
|
2012-01-23 21:51:52 +00:00
|
|
|
void MCAsmStreamer::EmitCFISignalFrame() {
|
|
|
|
MCStreamer::EmitCFISignalFrame();
|
|
|
|
|
|
|
|
if (!UseCFI)
|
|
|
|
return;
|
|
|
|
|
|
|
|
OS << "\t.cif_signal_frame";
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2011-05-22 21:12:15 +00:00
|
|
|
void MCAsmStreamer::EmitWin64EHStartProc(const MCSymbol *Symbol) {
|
2011-05-20 18:19:22 +00:00
|
|
|
MCStreamer::EmitWin64EHStartProc(Symbol);
|
|
|
|
|
2011-05-19 17:46:39 +00:00
|
|
|
OS << ".seh_proc " << *Symbol;
|
2011-05-18 04:58:05 +00:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2011-05-18 22:13:51 +00:00
|
|
|
void MCAsmStreamer::EmitWin64EHEndProc() {
|
2011-05-20 18:19:22 +00:00
|
|
|
MCStreamer::EmitWin64EHEndProc();
|
|
|
|
|
2011-05-19 17:46:39 +00:00
|
|
|
OS << "\t.seh_endproc";
|
2011-05-18 04:58:05 +00:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2011-05-18 22:13:51 +00:00
|
|
|
void MCAsmStreamer::EmitWin64EHStartChained() {
|
2011-05-20 18:19:22 +00:00
|
|
|
MCStreamer::EmitWin64EHStartChained();
|
|
|
|
|
2011-05-19 17:46:39 +00:00
|
|
|
OS << "\t.seh_startchained";
|
2011-05-18 20:54:10 +00:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2011-05-18 22:13:51 +00:00
|
|
|
void MCAsmStreamer::EmitWin64EHEndChained() {
|
2011-05-20 18:19:22 +00:00
|
|
|
MCStreamer::EmitWin64EHEndChained();
|
|
|
|
|
2011-05-19 17:46:39 +00:00
|
|
|
OS << "\t.seh_endchained";
|
2011-05-18 20:54:10 +00:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2011-05-19 17:46:39 +00:00
|
|
|
void MCAsmStreamer::EmitWin64EHHandler(const MCSymbol *Sym, bool Unwind,
|
|
|
|
bool Except) {
|
2011-05-20 18:19:22 +00:00
|
|
|
MCStreamer::EmitWin64EHHandler(Sym, Unwind, Except);
|
|
|
|
|
2011-05-19 17:46:39 +00:00
|
|
|
OS << "\t.seh_handler " << *Sym;
|
|
|
|
if (Unwind)
|
|
|
|
OS << ", @unwind";
|
|
|
|
if (Except)
|
|
|
|
OS << ", @except";
|
2011-05-18 20:54:10 +00:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2011-07-20 05:58:47 +00:00
|
|
|
static const MCSection *getWin64EHTableSection(StringRef suffix,
|
|
|
|
MCContext &context) {
|
|
|
|
// FIXME: This doesn't belong in MCObjectFileInfo. However,
|
|
|
|
/// this duplicate code in MCWin64EH.cpp.
|
|
|
|
if (suffix == "")
|
|
|
|
return context.getObjectFileInfo()->getXDataSection();
|
|
|
|
return context.getCOFFSection((".xdata"+suffix).str(),
|
|
|
|
COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
|
|
|
|
COFF::IMAGE_SCN_MEM_READ |
|
|
|
|
COFF::IMAGE_SCN_MEM_WRITE,
|
|
|
|
SectionKind::getDataRel());
|
|
|
|
}
|
|
|
|
|
2011-05-19 17:46:39 +00:00
|
|
|
void MCAsmStreamer::EmitWin64EHHandlerData() {
|
2011-05-20 18:19:22 +00:00
|
|
|
MCStreamer::EmitWin64EHHandlerData();
|
|
|
|
|
2011-05-25 21:43:45 +00: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.
|
2011-05-27 19:09:24 +00:00
|
|
|
MCWin64EHUnwindInfo *CurFrame = getCurrentW64UnwindInfo();
|
|
|
|
StringRef suffix=MCWin64EHUnwindEmitter::GetSectionSuffix(CurFrame->Function);
|
2011-07-20 05:58:47 +00:00
|
|
|
const MCSection *xdataSect = getWin64EHTableSection(suffix, getContext());
|
2011-05-25 21:43:45 +00:00
|
|
|
if (xdataSect)
|
|
|
|
SwitchSectionNoChange(xdataSect);
|
|
|
|
|
2011-05-19 17:46:39 +00:00
|
|
|
OS << "\t.seh_handlerdata";
|
2011-05-18 20:54:10 +00:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2011-05-19 19:35:55 +00:00
|
|
|
void MCAsmStreamer::EmitWin64EHPushReg(unsigned Register) {
|
2011-05-20 18:19:22 +00:00
|
|
|
MCStreamer::EmitWin64EHPushReg(Register);
|
|
|
|
|
2011-05-19 17:46:39 +00:00
|
|
|
OS << "\t.seh_pushreg " << Register;
|
2011-05-18 04:58:05 +00:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2011-05-19 19:35:55 +00:00
|
|
|
void MCAsmStreamer::EmitWin64EHSetFrame(unsigned Register, unsigned Offset) {
|
2011-05-20 18:19:22 +00:00
|
|
|
MCStreamer::EmitWin64EHSetFrame(Register, Offset);
|
|
|
|
|
2011-05-19 17:46:39 +00:00
|
|
|
OS << "\t.seh_setframe " << Register << ", " << Offset;
|
2011-05-18 04:58:05 +00:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2011-05-19 19:35:55 +00:00
|
|
|
void MCAsmStreamer::EmitWin64EHAllocStack(unsigned Size) {
|
2011-05-20 18:19:22 +00:00
|
|
|
MCStreamer::EmitWin64EHAllocStack(Size);
|
|
|
|
|
2011-05-19 17:46:39 +00:00
|
|
|
OS << "\t.seh_stackalloc " << Size;
|
2011-05-18 04:58:05 +00:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2011-05-19 19:35:55 +00:00
|
|
|
void MCAsmStreamer::EmitWin64EHSaveReg(unsigned Register, unsigned Offset) {
|
2011-05-20 18:19:22 +00:00
|
|
|
MCStreamer::EmitWin64EHSaveReg(Register, Offset);
|
|
|
|
|
2011-05-19 17:46:39 +00:00
|
|
|
OS << "\t.seh_savereg " << Register << ", " << Offset;
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2011-05-19 19:35:55 +00:00
|
|
|
void MCAsmStreamer::EmitWin64EHSaveXMM(unsigned Register, unsigned Offset) {
|
2011-05-20 18:19:22 +00:00
|
|
|
MCStreamer::EmitWin64EHSaveXMM(Register, Offset);
|
|
|
|
|
2011-05-19 17:46:39 +00:00
|
|
|
OS << "\t.seh_savexmm " << Register << ", " << Offset;
|
2011-05-18 04:58:05 +00:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2011-05-18 22:13:51 +00:00
|
|
|
void MCAsmStreamer::EmitWin64EHPushFrame(bool Code) {
|
2011-05-20 18:19:22 +00:00
|
|
|
MCStreamer::EmitWin64EHPushFrame(Code);
|
|
|
|
|
2011-05-19 17:46:39 +00:00
|
|
|
OS << "\t.seh_pushframe";
|
2011-05-18 04:58:05 +00:00
|
|
|
if (Code)
|
2011-05-19 17:46:39 +00:00
|
|
|
OS << " @code";
|
2011-05-18 04:58:05 +00:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2011-05-18 22:13:51 +00:00
|
|
|
void MCAsmStreamer::EmitWin64EHEndProlog(void) {
|
2011-05-20 18:19:22 +00:00
|
|
|
MCStreamer::EmitWin64EHEndProlog();
|
|
|
|
|
2011-05-19 17:46:39 +00:00
|
|
|
OS << "\t.seh_endprologue";
|
2011-05-18 04:58:05 +00:00
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-08 22:49:42 +00:00
|
|
|
// FIXME: Note the fixup comments for Thumb2 are completely bogus since the
|
2011-01-13 23:27:39 +00:00
|
|
|
// high order halfword of a 32-bit Thumb2 instruction is emitted first.
|
2010-02-09 23:00:14 +00: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-13 21:45:26 +00:00
|
|
|
if (Code[i]) {
|
2011-01-13 23:27:39 +00:00
|
|
|
// FIXME: Some of the 8 bits require fix up.
|
2011-01-13 21:45:26 +00:00
|
|
|
OS << format("0x%02x", uint8_t(Code[i])) << '\''
|
|
|
|
<< char('A' + MapEntry - 1) << '\'';
|
|
|
|
} else
|
|
|
|
OS << char('A' + MapEntry - 1);
|
2010-02-09 23:00:14 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Otherwise, write out in binary.
|
|
|
|
OS << "0b";
|
2011-06-23 09:09:15 +00:00
|
|
|
for (unsigned j = 8; j--;) {
|
2010-02-09 23:00:14 +00:00
|
|
|
unsigned Bit = (Code[i] >> j) & 1;
|
2011-03-27 01:44:40 +00:00
|
|
|
|
2010-11-15 05:56:19 +00:00
|
|
|
unsigned FixupBit;
|
2011-07-15 02:09:41 +00:00
|
|
|
if (getContext().getAsmInfo().isLittleEndian())
|
2010-11-15 05:56:19 +00:00
|
|
|
FixupBit = i * 8 + j;
|
|
|
|
else
|
|
|
|
FixupBit = i * 8 + (7-j);
|
2011-03-27 01:44:40 +00:00
|
|
|
|
2011-06-23 09:09:15 +00:00
|
|
|
if (uint8_t MapEntry = FixupMap[FixupBit]) {
|
|
|
|
assert(Bit == 0 && "Encoder wrote into fixed up bit!");
|
|
|
|
OS << char('A' + MapEntry - 1);
|
2010-02-09 23:00:14 +00:00
|
|
|
} 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-05 18:43:15 +00:00
|
|
|
void MCAsmStreamer::EmitFnStart() {
|
|
|
|
OS << "\t.fnstart";
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MCAsmStreamer::EmitFnEnd() {
|
|
|
|
OS << "\t.fnend";
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MCAsmStreamer::EmitCantUnwind() {
|
|
|
|
OS << "\t.cantunwind";
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MCAsmStreamer::EmitHandlerData() {
|
|
|
|
OS << "\t.handlerdata";
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MCAsmStreamer::EmitPersonality(const MCSymbol *Personality) {
|
|
|
|
OS << "\t.personality " << Personality->getName();
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2011-03-05 18:43:32 +00:00
|
|
|
void MCAsmStreamer::EmitSetFP(unsigned FpReg, unsigned SpReg, int64_t Offset) {
|
2011-06-02 02:34:55 +00:00
|
|
|
OS << "\t.setfp\t";
|
|
|
|
InstPrinter->printRegName(OS, FpReg);
|
|
|
|
OS << ", ";
|
|
|
|
InstPrinter->printRegName(OS, SpReg);
|
2011-03-05 18:43:32 +00:00
|
|
|
if (Offset)
|
|
|
|
OS << ", #" << Offset;
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MCAsmStreamer::EmitPad(int64_t Offset) {
|
|
|
|
OS << "\t.pad\t#" << Offset;
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MCAsmStreamer::EmitRegSave(const SmallVectorImpl<unsigned> &RegList,
|
|
|
|
bool isVector) {
|
|
|
|
assert(RegList.size() && "RegList should not be empty");
|
|
|
|
if (isVector)
|
|
|
|
OS << "\t.vsave\t{";
|
|
|
|
else
|
|
|
|
OS << "\t.save\t{";
|
|
|
|
|
2011-06-02 02:34:55 +00:00
|
|
|
InstPrinter->printRegName(OS, RegList[0]);
|
2011-03-05 18:43:32 +00:00
|
|
|
|
2011-06-02 02:34:55 +00:00
|
|
|
for (unsigned i = 1, e = RegList.size(); i != e; ++i) {
|
|
|
|
OS << ", ";
|
|
|
|
InstPrinter->printRegName(OS, RegList[i]);
|
|
|
|
}
|
2011-03-05 18:43:32 +00:00
|
|
|
|
|
|
|
OS << "}";
|
|
|
|
EmitEOL();
|
|
|
|
}
|
|
|
|
|
2010-02-09 23:00:14 +00:00
|
|
|
void MCAsmStreamer::EmitInstruction(const MCInst &Inst) {
|
2011-02-16 01:08:29 +00:00
|
|
|
assert(getCurrentSection() && "Cannot emit contents before setting section!");
|
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)
|
2011-09-15 23:38:46 +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
|
|
|
}
|
|
|
|
|
2012-01-07 03:13:18 +00:00
|
|
|
void MCAsmStreamer::FinishImpl() {
|
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);
|
2011-05-01 04:49:54 +00:00
|
|
|
|
2011-12-09 18:09:40 +00:00
|
|
|
// If we are generating dwarf for assembly source files dump out the sections.
|
|
|
|
if (getContext().getGenDwarfForAssembly())
|
|
|
|
MCGenDwarfInfo::Emit(this);
|
|
|
|
|
2011-05-10 03:14:15 +00:00
|
|
|
if (!UseCFI)
|
|
|
|
EmitFrames(false);
|
2009-06-24 01:03:06 +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,
|
2011-10-17 23:05:28 +00:00
|
|
|
bool useCFI, bool useDwarfDirectory,
|
|
|
|
MCInstPrinter *IP, MCCodeEmitter *CE,
|
|
|
|
MCAsmBackend *MAB, bool ShowInst) {
|
2011-04-30 03:44:37 +00:00
|
|
|
return new MCAsmStreamer(Context, OS, isVerboseAsm, useLoc, useCFI,
|
2011-10-17 23:05:28 +00:00
|
|
|
useDwarfDirectory, IP, CE, MAB, ShowInst);
|
2009-06-24 01:03:06 +00:00
|
|
|
}
|