aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-08-27 00:51:57 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-08-27 00:51:57 +0000
commit4a0abd80f18f9c2a10bf5b14cd6731d51972a426 (patch)
treeaa5e672bdfb25a08c7310a64502a34a753511554 /include
parent81e400092f55c2eba157172bfc0dd0df8317638d (diff)
Sketch TargetRegistry support for MCCodeEmitter abstract interface.
- Of course, nothing actually can provide this interface yet. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80188 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/MC/MCCodeEmitter.h32
-rw-r--r--include/llvm/MC/MCStreamer.h8
-rw-r--r--include/llvm/Target/TargetRegistry.h68
3 files changed, 105 insertions, 3 deletions
diff --git a/include/llvm/MC/MCCodeEmitter.h b/include/llvm/MC/MCCodeEmitter.h
new file mode 100644
index 0000000000..fdacb94282
--- /dev/null
+++ b/include/llvm/MC/MCCodeEmitter.h
@@ -0,0 +1,32 @@
+//===-- llvm/MC/MCCodeEmitter.h - Instruction Encoding ----------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_MC_MCCODEEMITTER_H
+#define LLVM_MC_MCCODEEMITTER_H
+
+namespace llvm {
+
+/// MCCodeEmitter - Generic instruction encoding interface.
+class MCCodeEmitter {
+ MCCodeEmitter(const MCCodeEmitter &); // DO NOT IMPLEMENT
+ void operator=(const MCCodeEmitter &); // DO NOT IMPLEMENT
+protected: // Can only create subclasses.
+ MCCodeEmitter();
+
+public:
+ virtual ~MCCodeEmitter();
+
+ /// EncodeInstruction - Encode the given \arg Inst to bytes on the output
+ /// stream \arg OS.
+ virtual void EncodeInstruction(const MCInst &Inst, raw_ostream &OS) = 0;
+};
+
+} // End llvm namespace
+
+#endif
diff --git a/include/llvm/MC/MCStreamer.h b/include/llvm/MC/MCStreamer.h
index e7741042e7..bc7f543322 100644
--- a/include/llvm/MC/MCStreamer.h
+++ b/include/llvm/MC/MCStreamer.h
@@ -18,14 +18,15 @@
namespace llvm {
class AsmPrinter;
+ class MCAsmInfo;
+ class MCCodeEmitter;
class MCContext;
- class MCValue;
class MCInst;
class MCSection;
class MCSymbol;
+ class MCValue;
class StringRef;
class raw_ostream;
- class MCAsmInfo;
/// MCStreamer - Streaming machine code generation interface. This interface
/// is intended to provide a programatic interface that is very similar to the
@@ -241,7 +242,8 @@ namespace llvm {
///
/// \arg AP - If given, an AsmPrinter to use for printing instructions.
MCStreamer *createAsmStreamer(MCContext &Ctx, raw_ostream &OS,
- const MCAsmInfo &MAI, AsmPrinter *AP = 0);
+ const MCAsmInfo &MAI, AsmPrinter *AP = 0,
+ MCCodeEmitter *CE = 0);
// FIXME: These two may end up getting rolled into a single
// createObjectStreamer interface, which implements the assembler backend, and
diff --git a/include/llvm/Target/TargetRegistry.h b/include/llvm/Target/TargetRegistry.h
index 6772d061ee..14fbd45e99 100644
--- a/include/llvm/Target/TargetRegistry.h
+++ b/include/llvm/Target/TargetRegistry.h
@@ -26,6 +26,7 @@
namespace llvm {
class AsmPrinter;
class MCAsmParser;
+ class MCCodeEmitter;
class Module;
class MCAsmInfo;
class TargetAsmParser;
@@ -57,6 +58,10 @@ namespace llvm {
bool VerboseAsm);
typedef TargetAsmParser *(*AsmParserCtorTy)(const Target &T,
MCAsmParser &P);
+ typedef MCCodeEmitter *(*CodeEmitterCtorTy)(const Target &T,
+ TargetMachine &TM,
+ const MCAsmInfo &MAI);
+
private:
/// Next - The next registered target in the linked list, maintained by the
/// TargetRegistry.
@@ -89,7 +94,14 @@ namespace llvm {
/// if registered.
AsmParserCtorTy AsmParserCtorFn;
+ /// CodeEmitterCtorFn - Construction function for this target's CodeEmitter,
+ /// if registered.
+ CodeEmitterCtorTy CodeEmitterCtorFn;
+
public:
+ /// @name Target Information
+ /// @{
+
// getNext - Return the next registered target.
const Target *getNext() const { return Next; }
@@ -99,6 +111,11 @@ namespace llvm {
/// getShortDescription - Get a short description of the target.
const char *getShortDescription() const { return ShortDesc; }
+ /// @}
+ /// @name Feature Predicates
+ /// @{
+
+ /// hasJIT - Check if this targets supports the just-in-time compilation.
bool hasJIT() const { return HasJIT; }
/// hasTargetMachine - Check if this target supports code generation.
@@ -110,6 +127,12 @@ namespace llvm {
/// hasAsmParser - Check if this target supports .s parsing.
bool hasAsmParser() const { return AsmParserCtorFn != 0; }
+ /// hasCodeEmitter - Check if this target supports instruction encoding.
+ bool hasCodeEmitter() const { return CodeEmitterCtorFn != 0; }
+
+ /// @}
+ /// @name Feature Constructors
+ /// @{
/// createAsmInfo - Create a MCAsmInfo implementation for the specified
/// target triple.
@@ -155,6 +178,16 @@ namespace llvm {
return 0;
return AsmParserCtorFn(*this, Parser);
}
+
+ /// createCodeEmitter - Create a target specific code emitter.
+ MCCodeEmitter *createCodeEmitter(TargetMachine &TM,
+ const MCAsmInfo *MAI) const {
+ if (!CodeEmitterCtorFn)
+ return 0;
+ return CodeEmitterCtorFn(*this, TM, *MAI);
+ }
+
+ /// @}
};
/// TargetRegistry - Generic interface to target specific features.
@@ -303,6 +336,20 @@ namespace llvm {
T.AsmParserCtorFn = Fn;
}
+ /// RegisterCodeEmitter - Register a MCCodeEmitter 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 AsmPrinter for the target.
+ static void RegisterCodeEmitter(Target &T, Target::CodeEmitterCtorTy Fn) {
+ if (!T.CodeEmitterCtorFn)
+ T.CodeEmitterCtorFn = Fn;
+ }
+
/// @}
};
@@ -431,6 +478,27 @@ namespace llvm {
}
};
+ /// RegisterCodeEmitter - Helper template for registering a target specific
+ /// machine code emitter, for use in the target initialization
+ /// function. Usage:
+ ///
+ /// extern "C" void LLVMInitializeFooCodeEmitter() {
+ /// extern Target TheFooTarget;
+ /// RegisterCodeEmitter<FooCodeEmitter> X(TheFooTarget);
+ /// }
+ template<class CodeEmitterImpl>
+ struct RegisterCodeEmitter {
+ RegisterCodeEmitter(Target &T) {
+ TargetRegistry::RegisterCodeEmitter(T, &Allocator);
+ }
+
+ private:
+ static MCCodeEmitter *Allocator(const Target &T, TargetMachine &TM,
+ const MCAsmInfo &MAI) {
+ return new CodeEmitterImpl(T, TM, MAI);
+ }
+ };
+
}
#endif