aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChe-Liang Chiou <clchiou@gmail.com>2010-11-08 02:21:17 +0000
committerChe-Liang Chiou <clchiou@gmail.com>2010-11-08 02:21:17 +0000
commit6da24ca51d0a0483b4ff1537a177bd172997f129 (patch)
treef15c39cfc64529d539480a4474902e6de8354fa9
parent5991487c10faa5f1c0cc815381d745150582a309 (diff)
downloadexternal_llvm-6da24ca51d0a0483b4ff1537a177bd172997f129.zip
external_llvm-6da24ca51d0a0483b4ff1537a177bd172997f129.tar.gz
external_llvm-6da24ca51d0a0483b4ff1537a177bd172997f129.tar.bz2
Add registry hook for assembly text output
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118394 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Target/TargetRegistry.h52
-rw-r--r--lib/CodeGen/LLVMTargetMachine.cpp9
-rw-r--r--tools/llvm-mc/llvm-mc.cpp6
3 files changed, 59 insertions, 8 deletions
diff --git a/include/llvm/Target/TargetRegistry.h b/include/llvm/Target/TargetRegistry.h
index 2817b0c..abffb58 100644
--- a/include/llvm/Target/TargetRegistry.h
+++ b/include/llvm/Target/TargetRegistry.h
@@ -39,6 +39,13 @@ namespace llvm {
class TargetAsmParser;
class TargetMachine;
class raw_ostream;
+ class formatted_raw_ostream;
+
+ MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
+ bool isLittleEndian, bool isVerboseAsm,
+ MCInstPrinter *InstPrint,
+ MCCodeEmitter *CE,
+ bool ShowInst);
/// Target - Wrapper for Target specific information.
///
@@ -81,6 +88,13 @@ namespace llvm {
raw_ostream &_OS,
MCCodeEmitter *_Emitter,
bool RelaxAll);
+ typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
+ formatted_raw_ostream &OS,
+ bool isLittleEndian,
+ bool isVerboseAsm,
+ MCInstPrinter *InstPrint,
+ MCCodeEmitter *CE,
+ bool ShowInst);
private:
/// Next - The next registered target in the linked list, maintained by the
@@ -138,7 +152,13 @@ namespace llvm {
/// ObjectStreamer, if registered.
ObjectStreamerCtorTy ObjectStreamerCtorFn;
+ /// AsmStreamerCtorFn - Construction function for this target's
+ /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
+ AsmStreamerCtorTy AsmStreamerCtorFn;
+
public:
+ Target() : AsmStreamerCtorFn(llvm::createAsmStreamer) {}
+
/// @name Target Information
/// @{
@@ -185,6 +205,9 @@ namespace llvm {
/// hasObjectStreamer - Check if this target supports streaming to files.
bool hasObjectStreamer() const { return ObjectStreamerCtorFn != 0; }
+ /// hasAsmStreamer - Check if this target supports streaming to files.
+ bool hasAsmStreamer() const { return AsmStreamerCtorFn != 0; }
+
/// @}
/// @name Feature Constructors
/// @{
@@ -292,6 +315,19 @@ namespace llvm {
return ObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter, RelaxAll);
}
+ /// createAsmStreamer - Create a target specific MCStreamer.
+ MCStreamer *createAsmStreamer(MCContext &Ctx,
+ formatted_raw_ostream &OS,
+ bool isLittleEndian,
+ bool isVerboseAsm,
+ MCInstPrinter *InstPrint,
+ MCCodeEmitter *CE,
+ bool ShowInst) const {
+ // AsmStreamerCtorFn is default to llvm::createAsmStreamer
+ return AsmStreamerCtorFn(Ctx, OS, isLittleEndian, isVerboseAsm,
+ InstPrint, CE, ShowInst);
+ }
+
/// @}
};
@@ -513,7 +549,7 @@ namespace llvm {
T.CodeEmitterCtorFn = Fn;
}
- /// RegisterObjectStreamer - Register an MCStreamer implementation
+ /// RegisterObjectStreamer - Register a object code MCStreamer implementation
/// for the given target.
///
/// Clients are responsible for ensuring that registration doesn't occur
@@ -527,6 +563,20 @@ namespace llvm {
T.ObjectStreamerCtorFn = Fn;
}
+ /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
+ /// for the given target.
+ ///
+ /// Clients are responsible for ensuring that registration doesn't occur
+ /// while another thread is attempting to access the registry. Typically
+ /// this is done by initializing all targets at program startup.
+ ///
+ /// @param T - The target being registered.
+ /// @param Fn - A function to construct an MCStreamer for the target.
+ static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
+ if (T.AsmStreamerCtorFn == createAsmStreamer)
+ T.AsmStreamerCtorFn = Fn;
+ }
+
/// @}
};
diff --git a/lib/CodeGen/LLVMTargetMachine.cpp b/lib/CodeGen/LLVMTargetMachine.cpp
index 60aa1e5..3ba1b89 100644
--- a/lib/CodeGen/LLVMTargetMachine.cpp
+++ b/lib/CodeGen/LLVMTargetMachine.cpp
@@ -144,10 +144,11 @@ bool LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
if (ShowMCEncoding)
MCE = getTarget().createCodeEmitter(*this, *Context);
- AsmStreamer.reset(createAsmStreamer(*Context, Out,
- getTargetData()->isLittleEndian(),
- getVerboseAsm(), InstPrinter,
- MCE, ShowMCInst));
+ AsmStreamer.reset(getTarget().createAsmStreamer(*Context, Out,
+ getTargetData()->isLittleEndian(),
+ getVerboseAsm(),
+ InstPrinter, MCE,
+ ShowMCInst));
break;
}
case CGFT_ObjectFile: {
diff --git a/tools/llvm-mc/llvm-mc.cpp b/tools/llvm-mc/llvm-mc.cpp
index 9710805..67bb06b 100644
--- a/tools/llvm-mc/llvm-mc.cpp
+++ b/tools/llvm-mc/llvm-mc.cpp
@@ -342,9 +342,9 @@ static int AssembleInput(const char *ProgName) {
MCCodeEmitter *CE = 0;
if (ShowEncoding)
CE = TheTarget->createCodeEmitter(*TM, Ctx);
- Str.reset(createAsmStreamer(Ctx, FOS,
- TM->getTargetData()->isLittleEndian(),
- /*asmverbose*/true, IP, CE, ShowInst));
+ Str.reset(TheTarget->createAsmStreamer(Ctx, FOS,
+ TM->getTargetData()->isLittleEndian(),
+ /*asmverbose*/true, IP, CE, ShowInst));
} else if (FileType == OFT_Null) {
Str.reset(createNullStreamer(Ctx));
} else {