2009-06-23 20:24:17 +00:00
|
|
|
//===- MCStreamer.h - High-level Streaming Machine Code Output --*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2009-07-01 06:08:37 +00:00
|
|
|
//
|
|
|
|
// This file declares the MCStreamer class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2009-06-23 20:24:17 +00:00
|
|
|
|
|
|
|
#ifndef LLVM_MC_MCSTREAMER_H
|
|
|
|
#define LLVM_MC_MCSTREAMER_H
|
|
|
|
|
2010-11-29 18:16:10 +00:00
|
|
|
#include "llvm/Support/DataTypes.h"
|
2010-01-23 06:39:22 +00:00
|
|
|
#include "llvm/MC/MCDirectives.h"
|
2010-12-10 07:39:47 +00:00
|
|
|
#include "llvm/MC/MCDwarf.h"
|
2011-05-19 02:49:00 +00:00
|
|
|
#include "llvm/MC/MCWin64EH.h"
|
2011-07-22 21:16:32 +00:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2009-06-24 19:25:34 +00:00
|
|
|
|
2009-06-23 20:24:17 +00:00
|
|
|
namespace llvm {
|
2011-07-25 23:24:55 +00:00
|
|
|
class MCAsmBackend;
|
2009-08-27 00:51:57 +00:00
|
|
|
class MCAsmInfo;
|
|
|
|
class MCCodeEmitter;
|
2009-06-23 20:24:17 +00:00
|
|
|
class MCContext;
|
2009-08-31 08:09:28 +00:00
|
|
|
class MCExpr;
|
2009-06-23 20:24:17 +00:00
|
|
|
class MCInst;
|
2009-09-14 03:02:37 +00:00
|
|
|
class MCInstPrinter;
|
2009-06-23 20:24:17 +00:00
|
|
|
class MCSection;
|
|
|
|
class MCSymbol;
|
2009-07-27 21:49:56 +00:00
|
|
|
class StringRef;
|
2010-11-19 02:26:16 +00:00
|
|
|
class TargetLoweringObjectFile;
|
2010-01-22 07:29:22 +00:00
|
|
|
class Twine;
|
2009-06-23 20:24:17 +00:00
|
|
|
class raw_ostream;
|
2010-01-22 07:29:22 +00:00
|
|
|
class formatted_raw_ostream;
|
2009-06-23 20:24:17 +00:00
|
|
|
|
2009-07-01 06:08:37 +00:00
|
|
|
/// MCStreamer - Streaming machine code generation interface. This interface
|
|
|
|
/// is intended to provide a programatic interface that is very similar to the
|
|
|
|
/// level that an assembler .s file provides. It has callbacks to emit bytes,
|
2009-08-30 06:17:16 +00:00
|
|
|
/// handle directives, etc. The implementation of this interface retains
|
2009-07-01 06:08:37 +00:00
|
|
|
/// state to know what the current section is etc.
|
|
|
|
///
|
|
|
|
/// There are multiple implementations of this interface: one for writing out
|
|
|
|
/// a .s file, and implementations that write out .o files of various formats.
|
|
|
|
///
|
2009-06-23 20:24:17 +00:00
|
|
|
class MCStreamer {
|
|
|
|
MCContext &Context;
|
|
|
|
|
|
|
|
MCStreamer(const MCStreamer&); // DO NOT IMPLEMENT
|
|
|
|
MCStreamer &operator=(const MCStreamer&); // DO NOT IMPLEMENT
|
|
|
|
|
2011-05-10 01:10:18 +00:00
|
|
|
bool EmitEHFrame;
|
|
|
|
bool EmitDebugFrame;
|
|
|
|
|
2010-12-26 20:20:31 +00:00
|
|
|
std::vector<MCDwarfFrameInfo> FrameInfos;
|
|
|
|
MCDwarfFrameInfo *getCurrentFrameInfo();
|
|
|
|
void EnsureValidFrame();
|
|
|
|
|
2011-05-26 02:45:47 +00:00
|
|
|
std::vector<MCWin64EHUnwindInfo *> W64UnwindInfos;
|
2011-05-19 04:04:13 +00:00
|
|
|
MCWin64EHUnwindInfo *CurrentW64UnwindInfo;
|
|
|
|
void setCurrentW64UnwindInfo(MCWin64EHUnwindInfo *Frame);
|
2011-05-19 02:49:00 +00:00
|
|
|
void EnsureValidW64UnwindInfo();
|
|
|
|
|
2011-08-02 20:24:22 +00:00
|
|
|
MCSymbol* LastSymbol;
|
2011-04-27 15:21:19 +00:00
|
|
|
|
2011-02-21 01:07:42 +00:00
|
|
|
/// SectionStack - This is stack of current and previous section
|
|
|
|
/// values saved by PushSection.
|
|
|
|
SmallVector<std::pair<const MCSection *,
|
|
|
|
const MCSection *>, 4> SectionStack;
|
2009-08-30 06:17:16 +00:00
|
|
|
|
2011-10-04 23:26:17 +00:00
|
|
|
unsigned UniqueCodeBeginSuffix;
|
|
|
|
unsigned UniqueDataBeginSuffix;
|
|
|
|
|
2011-02-16 01:08:29 +00:00
|
|
|
protected:
|
2011-10-04 23:26:17 +00:00
|
|
|
/// Indicator of whether the previous data-or-code indicator was for
|
|
|
|
/// code or not. Used to determine when we need to emit a new indicator.
|
|
|
|
enum DataType {
|
|
|
|
Data,
|
|
|
|
Code,
|
|
|
|
JumpTable8,
|
|
|
|
JumpTable16,
|
|
|
|
JumpTable32
|
|
|
|
};
|
|
|
|
DataType RegionIndicator;
|
|
|
|
|
|
|
|
|
2011-02-16 01:08:29 +00:00
|
|
|
MCStreamer(MCContext &Ctx);
|
2011-04-30 03:21:04 +00:00
|
|
|
|
|
|
|
const MCExpr *BuildSymbolDiff(MCContext &Context, const MCSymbol *A,
|
|
|
|
const MCSymbol *B);
|
|
|
|
|
2011-05-19 21:40:34 +00:00
|
|
|
const MCExpr *ForceExpAbs(const MCExpr* Expr);
|
2010-09-02 18:53:37 +00:00
|
|
|
|
2011-05-10 03:14:15 +00:00
|
|
|
void EmitFrames(bool usingCFI);
|
|
|
|
|
2011-05-22 03:01:05 +00:00
|
|
|
MCWin64EHUnwindInfo *getCurrentW64UnwindInfo(){return CurrentW64UnwindInfo;}
|
2011-05-22 04:15:07 +00:00
|
|
|
void EmitW64Tables();
|
2011-05-22 03:01:05 +00:00
|
|
|
|
2009-06-23 23:02:31 +00:00
|
|
|
public:
|
2009-06-23 20:24:17 +00:00
|
|
|
virtual ~MCStreamer();
|
|
|
|
|
|
|
|
MCContext &getContext() const { return Context; }
|
|
|
|
|
2010-12-10 07:39:47 +00:00
|
|
|
unsigned getNumFrameInfos() {
|
|
|
|
return FrameInfos.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
const MCDwarfFrameInfo &getFrameInfo(unsigned i) {
|
|
|
|
return FrameInfos[i];
|
|
|
|
}
|
|
|
|
|
2011-07-22 21:16:32 +00:00
|
|
|
ArrayRef<MCDwarfFrameInfo> getFrameInfos() {
|
|
|
|
return FrameInfos;
|
|
|
|
}
|
|
|
|
|
2011-05-22 04:15:07 +00:00
|
|
|
unsigned getNumW64UnwindInfos() {
|
|
|
|
return W64UnwindInfos.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
MCWin64EHUnwindInfo &getW64UnwindInfo(unsigned i) {
|
2011-05-26 02:45:47 +00:00
|
|
|
return *W64UnwindInfos[i];
|
2011-05-22 04:15:07 +00:00
|
|
|
}
|
|
|
|
|
2010-01-22 19:52:01 +00:00
|
|
|
/// @name Assembly File Formatting.
|
|
|
|
/// @{
|
2010-09-15 16:24:01 +00:00
|
|
|
|
2010-04-03 21:35:55 +00:00
|
|
|
/// isVerboseAsm - Return true if this streamer supports verbose assembly
|
|
|
|
/// and if it is enabled.
|
2010-02-02 23:37:42 +00:00
|
|
|
virtual bool isVerboseAsm() const { return false; }
|
2010-09-15 16:24:01 +00:00
|
|
|
|
2010-04-03 21:35:55 +00:00
|
|
|
/// hasRawTextSupport - Return true if this asm streamer supports emitting
|
|
|
|
/// unformatted text to the .s file with EmitRawText.
|
|
|
|
virtual bool hasRawTextSupport() const { return false; }
|
2010-01-22 19:52:01 +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.
|
|
|
|
///
|
|
|
|
/// If the comment includes embedded \n's, they will each get the comment
|
|
|
|
/// prefix as appropriate. The added comment should not end with a \n.
|
2010-01-22 18:21:35 +00:00
|
|
|
virtual void AddComment(const Twine &T) {}
|
2010-09-15 16:24:01 +00:00
|
|
|
|
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();
|
2010-09-15 16:24:01 +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() {}
|
2010-09-15 16:24:01 +00:00
|
|
|
|
2010-01-22 19:52:01 +00:00
|
|
|
/// @}
|
2010-09-15 16:24:01 +00:00
|
|
|
|
2009-06-24 19:25:34 +00:00
|
|
|
/// @name Symbol & Section Management
|
|
|
|
/// @{
|
2010-09-15 16:24:01 +00:00
|
|
|
|
2010-03-25 00:03:04 +00:00
|
|
|
/// getCurrentSection - Return the current section that the streamer is
|
2009-08-30 06:17:16 +00:00
|
|
|
/// emitting code to.
|
2011-02-16 01:08:29 +00:00
|
|
|
const MCSection *getCurrentSection() const {
|
2011-02-21 01:07:42 +00:00
|
|
|
if (!SectionStack.empty())
|
|
|
|
return SectionStack.back().first;
|
2011-02-16 01:08:29 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2009-06-24 19:25:34 +00:00
|
|
|
|
2010-09-02 18:53:37 +00:00
|
|
|
/// getPreviousSection - Return the previous section that the streamer is
|
|
|
|
/// emitting code to.
|
2011-02-16 01:08:29 +00:00
|
|
|
const MCSection *getPreviousSection() const {
|
2011-02-21 01:07:42 +00:00
|
|
|
if (!SectionStack.empty())
|
|
|
|
return SectionStack.back().second;
|
2011-02-16 01:08:29 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ChangeSection - Update streamer for a new active section.
|
|
|
|
///
|
|
|
|
/// This is called by PopSection and SwitchSection, if the current
|
|
|
|
/// section changes.
|
|
|
|
virtual void ChangeSection(const MCSection *) = 0;
|
|
|
|
|
|
|
|
/// pushSection - Save the current and previous section on the
|
|
|
|
/// section stack.
|
|
|
|
void PushSection() {
|
2011-02-21 01:07:42 +00:00
|
|
|
SectionStack.push_back(std::make_pair(getCurrentSection(),
|
|
|
|
getPreviousSection()));
|
2011-02-16 01:08:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// popSection - Restore the current and previous section from
|
|
|
|
/// the section stack. Calls ChangeSection as needed.
|
|
|
|
///
|
|
|
|
/// Returns false if the stack was empty.
|
|
|
|
bool PopSection() {
|
2011-02-21 01:07:42 +00:00
|
|
|
if (SectionStack.size() <= 1)
|
2011-02-16 01:08:29 +00:00
|
|
|
return false;
|
2011-02-21 01:07:42 +00:00
|
|
|
const MCSection *oldSection = SectionStack.pop_back_val().first;
|
|
|
|
const MCSection *curSection = SectionStack.back().first;
|
2011-02-16 01:08:29 +00:00
|
|
|
|
|
|
|
if (oldSection != curSection)
|
|
|
|
ChangeSection(curSection);
|
|
|
|
return true;
|
|
|
|
}
|
2010-09-02 18:53:37 +00:00
|
|
|
|
2009-06-23 23:02:31 +00:00
|
|
|
/// SwitchSection - Set the current section where code is being emitted to
|
2010-02-22 04:10:52 +00:00
|
|
|
/// @p Section. This is required to update CurSection.
|
2009-06-23 23:02:31 +00:00
|
|
|
///
|
|
|
|
/// This corresponds to assembler directives like .section, .text, etc.
|
2011-02-16 01:08:29 +00:00
|
|
|
void SwitchSection(const MCSection *Section) {
|
|
|
|
assert(Section && "Cannot switch to a null section!");
|
2011-02-21 01:07:42 +00:00
|
|
|
const MCSection *curSection = SectionStack.back().first;
|
|
|
|
SectionStack.back().second = curSection;
|
2011-02-16 01:08:29 +00:00
|
|
|
if (Section != curSection) {
|
2011-02-21 01:07:42 +00:00
|
|
|
SectionStack.back().first = Section;
|
2011-02-16 01:08:29 +00:00
|
|
|
ChangeSection(Section);
|
|
|
|
}
|
|
|
|
}
|
2010-09-15 16:24:01 +00:00
|
|
|
|
2011-05-25 21:43:45 +00:00
|
|
|
/// SwitchSectionNoChange - Set the current section where code is being
|
|
|
|
/// emitted to @p Section. This is required to update CurSection. This
|
|
|
|
/// version does not call ChangeSection.
|
|
|
|
void SwitchSectionNoChange(const MCSection *Section) {
|
|
|
|
assert(Section && "Cannot switch to a null section!");
|
|
|
|
const MCSection *curSection = SectionStack.back().first;
|
|
|
|
SectionStack.back().second = curSection;
|
|
|
|
if (Section != curSection)
|
|
|
|
SectionStack.back().first = Section;
|
|
|
|
}
|
|
|
|
|
2010-09-15 21:48:40 +00:00
|
|
|
/// InitSections - Create the default sections and set the initial one.
|
|
|
|
virtual void InitSections() = 0;
|
|
|
|
|
2010-02-22 04:10:52 +00:00
|
|
|
/// EmitLabel - Emit a label for @p Symbol into the current section.
|
2009-06-23 23:02:31 +00:00
|
|
|
///
|
|
|
|
/// This corresponds to an assembler statement such as:
|
|
|
|
/// foo:
|
|
|
|
///
|
|
|
|
/// @param Symbol - The symbol to emit. A given symbol should only be
|
|
|
|
/// emitted as a label once, and symbols emitted as a label should never be
|
|
|
|
/// used in an assignment.
|
2011-04-27 15:21:19 +00:00
|
|
|
virtual void EmitLabel(MCSymbol *Symbol);
|
2009-06-23 23:02:31 +00:00
|
|
|
|
2011-10-04 23:26:17 +00:00
|
|
|
/// EmitDataRegion - Emit a label that marks the beginning of a data
|
|
|
|
/// region.
|
|
|
|
/// On ELF targets, this corresponds to an assembler statement such as:
|
|
|
|
/// $d.1:
|
|
|
|
virtual void EmitDataRegion();
|
|
|
|
|
|
|
|
/// EmitJumpTable8Region - Emit a label that marks the beginning of a
|
|
|
|
/// jump table composed of 8-bit offsets.
|
|
|
|
/// On ELF targets, this corresponds to an assembler statement such as:
|
|
|
|
/// $d.1:
|
|
|
|
virtual void EmitJumpTable8Region();
|
|
|
|
|
|
|
|
/// EmitJumpTable16Region - Emit a label that marks the beginning of a
|
|
|
|
/// jump table composed of 16-bit offsets.
|
|
|
|
/// On ELF targets, this corresponds to an assembler statement such as:
|
|
|
|
/// $d.1:
|
|
|
|
virtual void EmitJumpTable16Region();
|
|
|
|
|
|
|
|
/// EmitJumpTable32Region - Emit a label that marks the beginning of a
|
|
|
|
/// jump table composed of 32-bit offsets.
|
|
|
|
/// On ELF targets, this corresponds to an assembler statement such as:
|
|
|
|
/// $d.1:
|
|
|
|
virtual void EmitJumpTable32Region();
|
|
|
|
|
|
|
|
/// EmitCodeRegion - Emit a label that marks the beginning of a code
|
|
|
|
/// region.
|
|
|
|
/// On ELF targets, this corresponds to an assembler statement such as:
|
|
|
|
/// $a.1:
|
|
|
|
virtual void EmitCodeRegion();
|
|
|
|
|
|
|
|
/// ForceCodeRegion - Forcibly sets the current region mode to code. Used
|
|
|
|
/// at function entry points.
|
|
|
|
void ForceCodeRegion() { RegionIndicator = Code; }
|
|
|
|
|
|
|
|
|
2011-04-28 12:50:37 +00:00
|
|
|
virtual void EmitEHSymAttributes(const MCSymbol *Symbol,
|
|
|
|
MCSymbol *EHSymbol);
|
|
|
|
|
2010-02-22 04:10:52 +00:00
|
|
|
/// EmitAssemblerFlag - Note in the output the specified @p Flag
|
2010-01-23 06:39:22 +00:00
|
|
|
virtual void EmitAssemblerFlag(MCAssemblerFlag Flag) = 0;
|
2009-07-13 21:03:15 +00:00
|
|
|
|
2010-11-05 22:08:08 +00:00
|
|
|
/// EmitThumbFunc - Note in the output that the specified @p Func is
|
|
|
|
/// a Thumb mode function (ARM target only).
|
|
|
|
virtual void EmitThumbFunc(MCSymbol *Func) = 0;
|
|
|
|
|
2010-02-22 04:10:52 +00:00
|
|
|
/// EmitAssignment - Emit an assignment of @p Value to @p Symbol.
|
2009-06-23 23:02:31 +00:00
|
|
|
///
|
|
|
|
/// This corresponds to an assembler statement such as:
|
|
|
|
/// symbol = value
|
|
|
|
///
|
|
|
|
/// The assignment generates no code, but has the side effect of binding the
|
|
|
|
/// value in the current context. For the assembly streamer, this prints the
|
|
|
|
/// binding into the .s file.
|
|
|
|
///
|
|
|
|
/// @param Symbol - The symbol being assigned to.
|
|
|
|
/// @param Value - The value for the symbol.
|
2009-08-31 08:09:28 +00:00
|
|
|
virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) = 0;
|
2009-06-23 20:24:17 +00:00
|
|
|
|
2010-11-01 14:28:48 +00:00
|
|
|
/// EmitWeakReference - Emit an weak reference from @p Alias to @p Symbol.
|
|
|
|
///
|
|
|
|
/// This corresponds to an assembler statement such as:
|
|
|
|
/// .weakref alias, symbol
|
|
|
|
///
|
|
|
|
/// @param Alias - The alias that is being created.
|
|
|
|
/// @param Symbol - The symbol being aliased.
|
|
|
|
virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) = 0;
|
|
|
|
|
2010-02-22 04:10:52 +00:00
|
|
|
/// EmitSymbolAttribute - Add the given @p Attribute to @p Symbol.
|
2009-06-24 01:03:06 +00:00
|
|
|
virtual void EmitSymbolAttribute(MCSymbol *Symbol,
|
2010-01-23 06:39:22 +00:00
|
|
|
MCSymbolAttr Attribute) = 0;
|
2009-06-23 20:24:17 +00:00
|
|
|
|
2010-02-22 04:10:52 +00:00
|
|
|
/// EmitSymbolDesc - Set the @p DescValue for the @p Symbol.
|
2009-07-14 18:17:10 +00:00
|
|
|
///
|
|
|
|
/// @param Symbol - The symbol to have its n_desc field set.
|
|
|
|
/// @param DescValue - The value to set into the n_desc field.
|
|
|
|
virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) = 0;
|
|
|
|
|
2010-05-08 19:54:22 +00:00
|
|
|
/// BeginCOFFSymbolDef - Start emitting COFF symbol definition
|
|
|
|
///
|
|
|
|
/// @param Symbol - The symbol to have its External & Type fields set.
|
|
|
|
virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol) = 0;
|
|
|
|
|
|
|
|
/// EmitCOFFSymbolStorageClass - Emit the storage class of the symbol.
|
|
|
|
///
|
|
|
|
/// @param StorageClass - The storage class the symbol should have.
|
|
|
|
virtual void EmitCOFFSymbolStorageClass(int StorageClass) = 0;
|
|
|
|
|
|
|
|
/// EmitCOFFSymbolType - Emit the type of the symbol.
|
|
|
|
///
|
|
|
|
/// @param Type - A COFF type identifier (see COFF::SymbolType in X86COFF.h)
|
|
|
|
virtual void EmitCOFFSymbolType(int Type) = 0;
|
|
|
|
|
|
|
|
/// EndCOFFSymbolDef - Marks the end of the symbol definition.
|
|
|
|
virtual void EndCOFFSymbolDef() = 0;
|
|
|
|
|
2010-01-25 07:52:13 +00:00
|
|
|
/// EmitELFSize - Emit an ELF .size directive.
|
|
|
|
///
|
|
|
|
/// This corresponds to an assembler statement such as:
|
|
|
|
/// .size symbol, expression
|
|
|
|
///
|
|
|
|
virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) = 0;
|
2010-09-15 16:24:01 +00:00
|
|
|
|
2010-01-23 07:47:02 +00:00
|
|
|
/// EmitCommonSymbol - Emit a common symbol.
|
2009-07-07 20:30:46 +00:00
|
|
|
///
|
|
|
|
/// @param Symbol - The common symbol to emit.
|
|
|
|
/// @param Size - The size of the common symbol.
|
2009-08-30 06:17:16 +00:00
|
|
|
/// @param ByteAlignment - The alignment of the symbol if
|
2010-01-23 07:47:02 +00:00
|
|
|
/// non-zero. This must be a power of 2.
|
|
|
|
virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
|
2009-08-30 06:17:16 +00:00
|
|
|
unsigned ByteAlignment) = 0;
|
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
|
|
|
/// @param ByteAlignment - The alignment of the common symbol in bytes.
|
|
|
|
virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
|
|
|
|
unsigned ByteAlignment) = 0;
|
2010-09-15 16:24:01 +00:00
|
|
|
|
2010-05-21 22:39:11 +00:00
|
|
|
/// EmitZerofill - Emit the zerofill section and an optional symbol.
|
2009-07-10 22:20:30 +00:00
|
|
|
///
|
|
|
|
/// @param Section - The zerofill section to create and or to put the symbol
|
|
|
|
/// @param Symbol - The zerofill symbol to emit, if non-NULL.
|
|
|
|
/// @param Size - The size of the zerofill symbol.
|
2009-08-30 06:17:16 +00:00
|
|
|
/// @param ByteAlignment - The alignment of the zerofill symbol if
|
|
|
|
/// non-zero. This must be a power of 2 on some targets.
|
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) = 0;
|
2009-07-10 22:20:30 +00:00
|
|
|
|
2010-05-14 01:50:28 +00:00
|
|
|
/// EmitTBSSSymbol - Emit a thread local bss (.tbss) symbol.
|
|
|
|
///
|
2010-05-18 21:16:04 +00:00
|
|
|
/// @param Section - The thread local common section.
|
2010-05-14 01:50:28 +00:00
|
|
|
/// @param Symbol - The thread local common symbol to emit.
|
|
|
|
/// @param Size - The size of the symbol.
|
|
|
|
/// @param ByteAlignment - The alignment of the thread local common symbol
|
|
|
|
/// if non-zero. This must be a power of 2 on some targets.
|
2010-05-18 21:16:04 +00:00
|
|
|
virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
|
2010-09-15 16:24:01 +00:00
|
|
|
uint64_t Size, unsigned ByteAlignment = 0) = 0;
|
2011-05-15 17:20:01 +00:00
|
|
|
|
2009-06-24 19:25:34 +00:00
|
|
|
/// @}
|
|
|
|
/// @name Generating Data
|
|
|
|
/// @{
|
|
|
|
|
2009-08-30 06:17:16 +00:00
|
|
|
/// EmitBytes - Emit the bytes in \arg Data into the output.
|
2009-06-23 23:02:31 +00:00
|
|
|
///
|
|
|
|
/// This is used to implement assembler directives such as .byte, .ascii,
|
|
|
|
/// etc.
|
2010-01-19 19:46:13 +00:00
|
|
|
virtual void EmitBytes(StringRef Data, unsigned AddrSpace) = 0;
|
2009-06-23 23:02:31 +00:00
|
|
|
|
2010-02-22 04:10:52 +00:00
|
|
|
/// EmitValue - Emit the expression @p Value into the output as a native
|
|
|
|
/// integer of the given @p Size bytes.
|
2009-06-23 23:02:31 +00:00
|
|
|
///
|
|
|
|
/// This is used to implement assembler directives such as .word, .quad,
|
|
|
|
/// etc.
|
|
|
|
///
|
|
|
|
/// @param Value - The value to emit.
|
|
|
|
/// @param Size - The size of the integer (in bytes) to emit. This must
|
|
|
|
/// match a native machine width.
|
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) = 0;
|
2010-12-10 07:39:47 +00:00
|
|
|
|
|
|
|
void EmitValue(const MCExpr *Value, unsigned Size, unsigned AddrSpace = 0);
|
|
|
|
|
2010-01-19 22:03:38 +00:00
|
|
|
/// EmitIntValue - Special case of EmitValue that avoids the client having
|
|
|
|
/// to pass in a MCExpr for constant integers.
|
2010-12-03 02:54:21 +00:00
|
|
|
virtual void EmitIntValue(uint64_t Value, unsigned Size,
|
|
|
|
unsigned AddrSpace = 0);
|
2010-09-15 16:24:01 +00:00
|
|
|
|
2010-12-06 17:27:56 +00:00
|
|
|
/// EmitAbsValue - Emit the Value, but try to avoid relocations. On MachO
|
|
|
|
/// this is done by producing
|
|
|
|
/// foo = value
|
|
|
|
/// .long foo
|
|
|
|
void EmitAbsValue(const MCExpr *Value, unsigned Size,
|
|
|
|
unsigned AddrSpace = 0);
|
2010-09-30 17:16:09 +00:00
|
|
|
|
2011-04-21 23:39:26 +00:00
|
|
|
virtual void EmitULEB128Value(const MCExpr *Value) = 0;
|
2010-11-02 17:22:24 +00:00
|
|
|
|
2011-04-21 23:39:26 +00:00
|
|
|
virtual void EmitSLEB128Value(const MCExpr *Value) = 0;
|
2010-11-02 17:22:24 +00:00
|
|
|
|
|
|
|
/// EmitULEB128Value - Special case of EmitULEB128Value that avoids the
|
|
|
|
/// client having to pass in a MCExpr for constant integers.
|
2011-11-05 11:52:44 +00:00
|
|
|
void EmitULEB128IntValue(uint64_t Value, unsigned AddrSpace = 0,
|
|
|
|
unsigned Padding = 0);
|
2010-11-02 17:22:24 +00:00
|
|
|
|
|
|
|
/// EmitSLEB128Value - Special case of EmitSLEB128Value that avoids the
|
|
|
|
/// client having to pass in a MCExpr for constant integers.
|
2010-11-28 14:56:52 +00:00
|
|
|
void EmitSLEB128IntValue(int64_t Value, unsigned AddrSpace = 0);
|
2010-09-30 17:16:09 +00:00
|
|
|
|
2010-03-09 00:39:24 +00:00
|
|
|
/// EmitSymbolValue - Special case of EmitValue that avoids the client
|
|
|
|
/// having to pass in a MCExpr for MCSymbols.
|
2010-11-28 15:12:55 +00:00
|
|
|
void EmitSymbolValue(const MCSymbol *Sym, unsigned Size,
|
|
|
|
unsigned AddrSpace = 0);
|
2010-09-15 16:24:01 +00:00
|
|
|
|
2010-02-22 04:10:52 +00:00
|
|
|
/// EmitGPRel32Value - Emit the expression @p Value into the output as a
|
2010-01-25 21:28:50 +00:00
|
|
|
/// gprel32 (32-bit GP relative) value.
|
|
|
|
///
|
|
|
|
/// This is used to implement assembler directives such as .gprel32 on
|
|
|
|
/// targets that support them.
|
2010-11-28 15:09:24 +00:00
|
|
|
virtual void EmitGPRel32Value(const MCExpr *Value);
|
2010-09-15 16:24:01 +00:00
|
|
|
|
2010-01-19 18:45:47 +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
|
|
|
virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue,
|
|
|
|
unsigned AddrSpace);
|
2010-09-15 16:24:01 +00:00
|
|
|
|
2010-01-19 21:51:22 +00:00
|
|
|
/// EmitZeros - Emit NumBytes worth of zeros. This is a convenience
|
|
|
|
/// function that just wraps EmitFill.
|
|
|
|
void EmitZeros(uint64_t NumBytes, unsigned AddrSpace) {
|
|
|
|
EmitFill(NumBytes, 0, AddrSpace);
|
|
|
|
}
|
|
|
|
|
2010-09-15 16:24:01 +00:00
|
|
|
|
2010-02-22 04:10:52 +00:00
|
|
|
/// EmitValueToAlignment - Emit some number of copies of @p Value until
|
|
|
|
/// the byte alignment @p ByteAlignment is reached.
|
2009-06-24 19:25:34 +00:00
|
|
|
///
|
|
|
|
/// If the number of bytes need to emit for the alignment is not a multiple
|
2010-02-22 04:10:52 +00:00
|
|
|
/// of @p ValueSize, then the contents of the emitted fill bytes is
|
2009-06-24 19:25:34 +00:00
|
|
|
/// undefined.
|
|
|
|
///
|
|
|
|
/// This used to implement the .align assembler directive.
|
|
|
|
///
|
|
|
|
/// @param ByteAlignment - The alignment to reach. This must be a power of
|
2009-06-29 23:46:59 +00:00
|
|
|
/// two on some targets.
|
2009-06-24 19:25:34 +00:00
|
|
|
/// @param Value - The value to use when filling bytes.
|
2010-02-22 04:10:52 +00:00
|
|
|
/// @param ValueSize - The size of the integer (in bytes) to emit for
|
|
|
|
/// @p Value. This must match a native machine width.
|
2009-06-24 19:25:34 +00:00
|
|
|
/// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
|
|
|
|
/// the alignment cannot be reached in this many bytes, no bytes are
|
|
|
|
/// emitted.
|
|
|
|
virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
|
|
|
|
unsigned ValueSize = 1,
|
|
|
|
unsigned MaxBytesToEmit = 0) = 0;
|
2010-02-23 18:26:34 +00:00
|
|
|
|
|
|
|
/// EmitCodeAlignment - Emit nops until the byte alignment @p ByteAlignment
|
|
|
|
/// is reached.
|
|
|
|
///
|
|
|
|
/// This used to align code where the alignment bytes may be executed. This
|
|
|
|
/// can emit different bytes for different sizes to optimize execution.
|
|
|
|
///
|
|
|
|
/// @param ByteAlignment - The alignment to reach. This must be a power of
|
|
|
|
/// two on some targets.
|
|
|
|
/// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
|
|
|
|
/// the alignment cannot be reached in this many bytes, no bytes are
|
|
|
|
/// emitted.
|
|
|
|
virtual void EmitCodeAlignment(unsigned ByteAlignment,
|
|
|
|
unsigned MaxBytesToEmit = 0) = 0;
|
2009-06-24 19:25:34 +00:00
|
|
|
|
2010-02-22 04:10:52 +00:00
|
|
|
/// EmitValueToOffset - Emit some number of copies of @p Value until the
|
|
|
|
/// byte offset @p Offset is reached.
|
2009-06-24 19:25:34 +00:00
|
|
|
///
|
|
|
|
/// This is used to implement assembler directives such as .org.
|
|
|
|
///
|
2009-08-30 21:14:05 +00:00
|
|
|
/// @param Offset - The offset to reach. This may be an expression, but the
|
2009-06-24 19:25:34 +00:00
|
|
|
/// expression must be associated with the current section.
|
|
|
|
/// @param Value - The value to use when filling bytes.
|
2009-08-31 08:09:28 +00:00
|
|
|
virtual void EmitValueToOffset(const MCExpr *Offset,
|
2009-06-24 19:25:34 +00:00
|
|
|
unsigned char Value = 0) = 0;
|
2010-09-15 16:24:01 +00:00
|
|
|
|
2009-06-24 19:25:34 +00:00
|
|
|
/// @}
|
2010-09-15 16:24:01 +00:00
|
|
|
|
2010-01-25 18:58:59 +00:00
|
|
|
/// EmitFileDirective - Switch to a new logical file. This is used to
|
|
|
|
/// implement the '.file "foo.c"' assembler directive.
|
|
|
|
virtual void EmitFileDirective(StringRef Filename) = 0;
|
2010-09-15 16:24:01 +00:00
|
|
|
|
2010-01-25 18:58:59 +00:00
|
|
|
/// EmitDwarfFileDirective - Associate a filename with a specified logical
|
|
|
|
/// file number. This implements the DWARF2 '.file 4 "foo.c"' assembler
|
|
|
|
/// directive.
|
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
|
|
|
|
|
|
|
/// EmitDwarfLocDirective - This implements the DWARF2
|
|
|
|
// '.loc fileno lineno ...' assembler directive.
|
|
|
|
virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
|
|
|
|
unsigned Column, unsigned Flags,
|
|
|
|
unsigned Isa,
|
2011-04-18 20:26:49 +00:00
|
|
|
unsigned Discriminator,
|
|
|
|
StringRef FileName);
|
2009-06-24 19:25:34 +00:00
|
|
|
|
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) = 0;
|
2010-12-03 00:55:40 +00:00
|
|
|
|
2010-12-28 05:39:27 +00:00
|
|
|
virtual void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
|
|
|
|
const MCSymbol *Label) {
|
|
|
|
}
|
|
|
|
|
2010-12-03 00:55:40 +00:00
|
|
|
void EmitDwarfSetLineAddr(int64_t LineDelta, const MCSymbol *Label,
|
|
|
|
int PointerSize);
|
|
|
|
|
2011-07-19 00:01:42 +00:00
|
|
|
virtual void EmitCompactUnwindEncoding(uint32_t CompactUnwindEncoding);
|
2011-05-10 01:10:18 +00:00
|
|
|
virtual void EmitCFISections(bool EH, bool Debug);
|
2011-04-12 23:59:07 +00:00
|
|
|
virtual void EmitCFIStartProc();
|
|
|
|
virtual void EmitCFIEndProc();
|
|
|
|
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);
|
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:47:22 +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-15 17:20:01 +00:00
|
|
|
virtual void EmitWin64EHPushFrame(bool Code);
|
2011-05-18 04:47:22 +00:00
|
|
|
virtual void EmitWin64EHEndProlog();
|
2011-05-15 17:20:01 +00:00
|
|
|
|
2010-02-22 04:10:52 +00:00
|
|
|
/// EmitInstruction - Emit the given @p Instruction into the current
|
2009-06-23 23:02:31 +00:00
|
|
|
/// section.
|
2009-06-23 20:24:17 +00:00
|
|
|
virtual void EmitInstruction(const MCInst &Inst) = 0;
|
2009-06-23 23:39:15 +00:00
|
|
|
|
2010-04-03 21:35:55 +00:00
|
|
|
/// EmitRawText - If this file is backed by a assembly streamer, this dumps
|
|
|
|
/// the specified string in the output .s file. This capability is
|
|
|
|
/// indicated by the hasRawTextSupport() predicate. By default this aborts.
|
|
|
|
virtual void EmitRawText(StringRef String);
|
2010-04-03 22:12:35 +00:00
|
|
|
void EmitRawText(const Twine &String);
|
2010-09-15 16:24:01 +00:00
|
|
|
|
2011-03-05 18:43:15 +00:00
|
|
|
/// ARM-related methods.
|
|
|
|
/// FIXME: Eventually we should have some "target MC streamer" and move
|
|
|
|
/// these methods there.
|
|
|
|
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 isVector);
|
2011-03-05 18:43:15 +00:00
|
|
|
|
2010-06-01 16:31:34 +00:00
|
|
|
/// Finish - Finish emission of machine code.
|
2009-06-23 23:39:15 +00:00
|
|
|
virtual void Finish() = 0;
|
2009-06-23 20:24:17 +00:00
|
|
|
};
|
|
|
|
|
2009-08-13 23:36:34 +00:00
|
|
|
/// createNullStreamer - Create a dummy machine code streamer, which does
|
|
|
|
/// nothing. This is useful for timing the assembler front end.
|
|
|
|
MCStreamer *createNullStreamer(MCContext &Ctx);
|
|
|
|
|
2009-06-23 23:02:31 +00:00
|
|
|
/// createAsmStreamer - Create a machine code streamer which will print out
|
|
|
|
/// assembly for the native target, suitable for compiling with a native
|
|
|
|
/// assembler.
|
2010-02-03 18:18:30 +00:00
|
|
|
///
|
|
|
|
/// \param InstPrint - If given, the instruction printer to use. If not given
|
2010-03-19 05:48:53 +00:00
|
|
|
/// the MCInst representation will be printed. This method takes ownership of
|
|
|
|
/// InstPrint.
|
2010-02-03 18:18:30 +00:00
|
|
|
///
|
|
|
|
/// \param CE - If given, a code emitter to use to show the instruction
|
2010-07-29 17:48:06 +00:00
|
|
|
/// encoding inline with the assembly. This method takes ownership of \arg CE.
|
2010-02-03 18:18:30 +00:00
|
|
|
///
|
2010-12-16 03:05:59 +00:00
|
|
|
/// \param TAB - If given, a target asm backend to use to show the fixup
|
|
|
|
/// information in conjunction with encoding information. This method takes
|
|
|
|
/// ownership of \arg TAB.
|
|
|
|
///
|
2010-02-03 18:18:30 +00:00
|
|
|
/// \param ShowInst - Whether to show the MCInst representation inline with
|
|
|
|
/// the assembly.
|
2011-06-17 20:35:21 +00:00
|
|
|
///
|
|
|
|
/// \param DecodeLSDA - If true, emit comments that translates the LSDA into a
|
|
|
|
/// human readable format. Only usable with CFI.
|
2010-01-22 07:29:22 +00:00
|
|
|
MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
|
2010-12-10 07:39:47 +00:00
|
|
|
bool isVerboseAsm,
|
|
|
|
bool useLoc,
|
2011-04-30 03:44:37 +00:00
|
|
|
bool useCFI,
|
2011-10-17 23:05:28 +00:00
|
|
|
bool useDwarfDirectory,
|
2009-09-14 03:02:37 +00:00
|
|
|
MCInstPrinter *InstPrint = 0,
|
2010-02-03 18:18:30 +00:00
|
|
|
MCCodeEmitter *CE = 0,
|
2011-07-25 23:24:55 +00:00
|
|
|
MCAsmBackend *TAB = 0,
|
2011-06-17 20:55:01 +00:00
|
|
|
bool ShowInst = false);
|
2009-06-23 23:02:31 +00:00
|
|
|
|
2010-06-01 16:10:08 +00:00
|
|
|
/// createMachOStreamer - Create a machine code streamer which will generate
|
2009-06-23 23:02:31 +00:00
|
|
|
/// Mach-O format object files.
|
2010-07-29 17:48:06 +00:00
|
|
|
///
|
|
|
|
/// Takes ownership of \arg TAB and \arg CE.
|
2011-07-25 23:24:55 +00:00
|
|
|
MCStreamer *createMachOStreamer(MCContext &Ctx, MCAsmBackend &TAB,
|
2010-03-25 22:49:09 +00:00
|
|
|
raw_ostream &OS, MCCodeEmitter *CE,
|
|
|
|
bool RelaxAll = false);
|
2009-06-23 20:24:17 +00:00
|
|
|
|
2010-07-11 22:05:00 +00:00
|
|
|
/// createWinCOFFStreamer - Create a machine code streamer which will
|
|
|
|
/// generate Microsoft COFF format object files.
|
2010-07-29 17:48:06 +00:00
|
|
|
///
|
|
|
|
/// Takes ownership of \arg TAB and \arg CE.
|
2010-07-11 22:05:00 +00:00
|
|
|
MCStreamer *createWinCOFFStreamer(MCContext &Ctx,
|
2011-07-25 23:24:55 +00:00
|
|
|
MCAsmBackend &TAB,
|
2010-07-31 06:22:29 +00:00
|
|
|
MCCodeEmitter &CE, raw_ostream &OS,
|
|
|
|
bool RelaxAll = false);
|
2010-07-11 22:05:00 +00:00
|
|
|
|
2010-08-16 18:35:43 +00:00
|
|
|
/// createELFStreamer - Create a machine code streamer which will generate
|
|
|
|
/// ELF format object files.
|
2011-07-25 23:24:55 +00:00
|
|
|
MCStreamer *createELFStreamer(MCContext &Ctx, MCAsmBackend &TAB,
|
2010-08-16 18:35:43 +00:00
|
|
|
raw_ostream &OS, MCCodeEmitter *CE,
|
2011-01-23 17:55:27 +00:00
|
|
|
bool RelaxAll, bool NoExecStack);
|
2010-08-16 18:35:43 +00:00
|
|
|
|
2010-05-23 17:44:06 +00:00
|
|
|
/// createLoggingStreamer - Create a machine code streamer which just logs the
|
|
|
|
/// API calls and then dispatches to another streamer.
|
|
|
|
///
|
|
|
|
/// The new streamer takes ownership of the \arg Child.
|
|
|
|
MCStreamer *createLoggingStreamer(MCStreamer *Child, raw_ostream &OS);
|
|
|
|
|
2010-11-17 16:06:47 +00:00
|
|
|
/// createPureStreamer - Create a machine code streamer which will generate
|
|
|
|
/// "pure" MC object files, for use with MC-JIT and testing tools.
|
|
|
|
///
|
|
|
|
/// Takes ownership of \arg TAB and \arg CE.
|
2011-07-25 23:24:55 +00:00
|
|
|
MCStreamer *createPureStreamer(MCContext &Ctx, MCAsmBackend &TAB,
|
2010-11-17 16:06:47 +00:00
|
|
|
raw_ostream &OS, MCCodeEmitter *CE);
|
|
|
|
|
2009-06-23 20:24:17 +00:00
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|