[llvm-branch-commits] [llvm-branch] r104361 - in /llvm/branches/Apple/whitney: include/llvm/Target/TargetRegistry.h lib/Target/X86/X86TargetMachine.cpp tools/llvm-mc/llvm-mc.cpp
Daniel Dunbar
daniel at zuster.org
Fri May 21 12:07:04 PDT 2010
Author: ddunbar
Date: Fri May 21 14:07:04 2010
New Revision: 104361
URL: http://llvm.org/viewvc/llvm-project?rev=104361&view=rev
Log:
Currently, createMachOStreamer() is invoked directly in llvm-mc which isn't ideal if we want to be able to use another object file format.
Add a createObjectStreamer() factory method so that the correct object
file streamer can be instantiated for a given target triple.
Modified:
llvm/branches/Apple/whitney/include/llvm/Target/TargetRegistry.h
llvm/branches/Apple/whitney/lib/Target/X86/X86TargetMachine.cpp
llvm/branches/Apple/whitney/tools/llvm-mc/llvm-mc.cpp
Modified: llvm/branches/Apple/whitney/include/llvm/Target/TargetRegistry.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/whitney/include/llvm/Target/TargetRegistry.h?rev=104361&r1=104360&r2=104361&view=diff
==============================================================================
--- llvm/branches/Apple/whitney/include/llvm/Target/TargetRegistry.h (original)
+++ llvm/branches/Apple/whitney/include/llvm/Target/TargetRegistry.h Fri May 21 14:07:04 2010
@@ -73,6 +73,13 @@
typedef MCCodeEmitter *(*CodeEmitterCtorTy)(const Target &T,
TargetMachine &TM,
MCContext &Ctx);
+ typedef MCStreamer *(*ObjectStreamerCtorTy)(const Target &T,
+ const std::string &TT,
+ MCContext &Ctx,
+ TargetAsmBackend &TAB,
+ raw_ostream &_OS,
+ MCCodeEmitter *_Emitter,
+ bool RelaxAll);
private:
/// Next - The next registered target in the linked list, maintained by the
@@ -126,6 +133,10 @@
/// if registered.
CodeEmitterCtorTy CodeEmitterCtorFn;
+ /// ObjectStreamerCtorFn - Construction function for this target's
+ /// ObjectStreamer, if registered.
+ ObjectStreamerCtorTy ObjectStreamerCtorFn;
+
public:
/// @name Target Information
/// @{
@@ -170,6 +181,9 @@
/// hasCodeEmitter - Check if this target supports instruction encoding.
bool hasCodeEmitter() const { return CodeEmitterCtorFn != 0; }
+ /// hasObjectStreamer - Check if this target supports streaming to files.
+ bool hasObjectStreamer() const { return ObjectStreamerCtorFn != 0; }
+
/// @}
/// @name Feature Constructors
/// @{
@@ -258,6 +272,24 @@
return CodeEmitterCtorFn(*this, TM, Ctx);
}
+ /// createObjectStreamer - Create a target specific MCStreamer.
+ ///
+ /// \arg TT - The target triple.
+ /// \arg Ctx - The target context.
+ /// \arg TAB - The target assembler backend object.
+ /// \arg _OS - The stream object.
+ /// \arg _Emitter - The target independent assembler object.
+ /// \arg RelaxAll - Relax all fixups?
+ MCStreamer *createObjectStreamer(const std::string &TT, MCContext &Ctx,
+ TargetAsmBackend &TAB,
+ raw_ostream &_OS,
+ MCCodeEmitter *_Emitter,
+ bool RelaxAll) const {
+ if (!ObjectStreamerCtorFn)
+ return 0;
+ return ObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter, RelaxAll);
+ }
+
/// @}
};
@@ -479,6 +511,20 @@
T.CodeEmitterCtorFn = Fn;
}
+ /// RegisterObjectStreamer - Register an 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 RegisterObjectStreamer(Target &T, Target::ObjectStreamerCtorTy Fn) {
+ if (!T.ObjectStreamerCtorFn)
+ T.ObjectStreamerCtorFn = Fn;
+ }
+
/// @}
};
Modified: llvm/branches/Apple/whitney/lib/Target/X86/X86TargetMachine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/whitney/lib/Target/X86/X86TargetMachine.cpp?rev=104361&r1=104360&r2=104361&view=diff
==============================================================================
--- llvm/branches/Apple/whitney/lib/Target/X86/X86TargetMachine.cpp (original)
+++ llvm/branches/Apple/whitney/lib/Target/X86/X86TargetMachine.cpp Fri May 21 14:07:04 2010
@@ -17,6 +17,8 @@
#include "llvm/PassManager.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/Passes.h"
+#include "llvm/MC/MCCodeEmitter.h"
+#include "llvm/MC/MCStreamer.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Target/TargetOptions.h"
#include "llvm/Target/TargetRegistry.h"
@@ -37,6 +39,18 @@
}
}
+static MCStreamer *createMCStreamer(const Target &T, const std::string &TT,
+ MCContext &Ctx, TargetAsmBackend &TAB,
+ raw_ostream &_OS,
+ MCCodeEmitter *_Emitter,
+ bool RelaxAll) {
+ Triple TheTriple(TT);
+ switch (TheTriple.getOS()) {
+ default:
+ return createMachOStreamer(Ctx, TAB, _OS, _Emitter, RelaxAll);
+ }
+}
+
extern "C" void LLVMInitializeX86Target() {
// Register the target.
RegisterTargetMachine<X86_32TargetMachine> X(TheX86_32Target);
@@ -57,6 +71,12 @@
createX86_32AsmBackend);
TargetRegistry::RegisterAsmBackend(TheX86_64Target,
createX86_64AsmBackend);
+
+ // Register the object streamer.
+ TargetRegistry::RegisterObjectStreamer(TheX86_32Target,
+ createMCStreamer);
+ TargetRegistry::RegisterObjectStreamer(TheX86_64Target,
+ createMCStreamer);
}
Modified: llvm/branches/Apple/whitney/tools/llvm-mc/llvm-mc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/whitney/tools/llvm-mc/llvm-mc.cpp?rev=104361&r1=104360&r2=104361&view=diff
==============================================================================
--- llvm/branches/Apple/whitney/tools/llvm-mc/llvm-mc.cpp (original)
+++ llvm/branches/Apple/whitney/tools/llvm-mc/llvm-mc.cpp Fri May 21 14:07:04 2010
@@ -301,7 +301,8 @@
assert(FileType == OFT_ObjectFile && "Invalid file type!");
CE.reset(TheTarget->createCodeEmitter(*TM, Ctx));
TAB.reset(TheTarget->createAsmBackend(TripleName));
- Str.reset(createMachOStreamer(Ctx, *TAB, *Out, CE.get(), RelaxAll));
+ Str.reset(TheTarget->createObjectStreamer(TripleName, Ctx, *TAB,
+ *Out, CE.get(), RelaxAll));
}
AsmParser Parser(SrcMgr, Ctx, *Str.get(), *MAI);
More information about the llvm-branch-commits
mailing list