#include <cassert>
namespace llvm {
- class FunctionPass;
+ class AsmPrinter;
class MCAsmParser;
+ class MCCodeEmitter;
class Module;
- class TargetAsmInfo;
+ class MCAsmInfo;
+ class MCDisassembler;
+ class MCInstPrinter;
class TargetAsmParser;
class TargetMachine;
class formatted_raw_ostream;
+ class raw_ostream;
/// Target - Wrapper for Target specific information.
///
typedef unsigned (*TripleMatchQualityFnTy)(const std::string &TT);
- typedef const TargetAsmInfo *(*AsmInfoCtorFnTy)(const Target &T,
- const StringRef &TT);
+ typedef const MCAsmInfo *(*AsmInfoCtorFnTy)(const Target &T,
+ const StringRef &TT);
typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
const std::string &TT,
const std::string &Features);
- typedef FunctionPass *(*AsmPrinterCtorTy)(formatted_raw_ostream &OS,
- TargetMachine &TM,
- const TargetAsmInfo *TAI,
- bool VerboseAsm);
+ typedef AsmPrinter *(*AsmPrinterCtorTy)(formatted_raw_ostream &OS,
+ TargetMachine &TM,
+ const MCAsmInfo *MAI,
+ bool VerboseAsm);
typedef TargetAsmParser *(*AsmParserCtorTy)(const Target &T,
MCAsmParser &P);
+ typedef const MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T);
+ typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
+ unsigned SyntaxVariant,
+ const MCAsmInfo &MAI,
+ raw_ostream &O);
+ typedef MCCodeEmitter *(*CodeEmitterCtorTy)(const Target &T,
+ TargetMachine &TM);
+
private:
/// Next - The next registered target in the linked list, maintained by the
/// TargetRegistry.
/// AsmParserCtorFn - Construction function for this target's AsmParser,
/// if registered.
AsmParserCtorTy AsmParserCtorFn;
+
+ /// MCDisassemblerCtorFn - Construction function for this target's
+ /// MCDisassembler, if registered.
+ MCDisassemblerCtorTy MCDisassemblerCtorFn;
+
+
+ /// MCInstPrinterCtorFn - Construction function for this target's
+ /// MCInstPrinter, if registered.
+ MCInstPrinterCtorTy MCInstPrinterCtorFn;
+
+ /// 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; }
/// 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.
/// hasAsmParser - Check if this target supports .s parsing.
bool hasAsmParser() const { return AsmParserCtorFn != 0; }
+
+ /// hasMCDisassembler - Check if this target has a disassembler.
+ bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
+ /// hasMCInstPrinter - Check if this target has an instruction printer.
+ bool hasMCInstPrinter() const { return MCInstPrinterCtorFn != 0; }
+
+ /// hasCodeEmitter - Check if this target supports instruction encoding.
+ bool hasCodeEmitter() const { return CodeEmitterCtorFn != 0; }
+
+ /// @}
+ /// @name Feature Constructors
+ /// @{
- /// createAsmInfo - Create a TargetAsmInfo implementation for the specified
+ /// createAsmInfo - Create a MCAsmInfo implementation for the specified
/// target triple.
///
/// \arg Triple - This argument is used to determine the target machine
/// feature set; it should always be provided. Generally this should be
/// either the target triple from the module, or the target triple of the
/// host if that does not exist.
- const TargetAsmInfo *createAsmInfo(const StringRef &Triple) const {
+ const MCAsmInfo *createAsmInfo(const StringRef &Triple) const {
if (!AsmInfoCtorFn)
return 0;
return AsmInfoCtorFn(*this, Triple);
}
/// createAsmPrinter - Create a target specific assembly printer pass.
- FunctionPass *createAsmPrinter(formatted_raw_ostream &OS,
- TargetMachine &TM,
- const TargetAsmInfo *TAI,
- bool Verbose) const {
+ AsmPrinter *createAsmPrinter(formatted_raw_ostream &OS, TargetMachine &TM,
+ const MCAsmInfo *MAI, bool Verbose) const {
if (!AsmPrinterCtorFn)
return 0;
- return AsmPrinterCtorFn(OS, TM, TAI, Verbose);
+ return AsmPrinterCtorFn(OS, TM, MAI, Verbose);
}
/// createAsmParser - Create a target specific assembly parser.
return 0;
return AsmParserCtorFn(*this, Parser);
}
+
+ const MCDisassembler *createMCDisassembler() const {
+ if (!MCDisassemblerCtorFn)
+ return 0;
+ return MCDisassemblerCtorFn(*this);
+ }
+
+ MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
+ const MCAsmInfo &MAI,
+ raw_ostream &O) const {
+ if (!MCInstPrinterCtorFn)
+ return 0;
+ return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, O);
+ }
+
+
+ /// createCodeEmitter - Create a target specific code emitter.
+ MCCodeEmitter *createCodeEmitter(TargetMachine &TM) const {
+ if (!CodeEmitterCtorFn)
+ return 0;
+ return CodeEmitterCtorFn(*this, TM);
+ }
+
+ /// @}
};
/// TargetRegistry - Generic interface to target specific features.
Target::TripleMatchQualityFnTy TQualityFn,
bool HasJIT = false);
- /// RegisterAsmInfo - Register a TargetAsmInfo implementation for the
+ /// RegisterAsmInfo - Register a MCAsmInfo implementation for the
/// given target.
///
/// Clients are responsible for ensuring that registration doesn't occur
/// this is done by initializing all targets at program startup.
///
/// @param T - The target being registered.
- /// @param Fn - A function to construct a TargetAsmInfo for the target.
+ /// @param Fn - A function to construct a MCAsmInfo for the target.
static void RegisterAsmInfo(Target &T, Target::AsmInfoCtorFnTy Fn) {
// Ignore duplicate registration.
if (!T.AsmInfoCtorFn)
if (!T.AsmParserCtorFn)
T.AsmParserCtorFn = Fn;
}
+
+ /// RegisterMCDisassembler - Register a MCDisassembler 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 MCDisassembler for the target.
+ static void RegisterMCDisassembler(Target &T,
+ Target::MCDisassemblerCtorTy Fn) {
+ if (!T.MCDisassemblerCtorFn)
+ T.MCDisassemblerCtorFn = Fn;
+ }
+
+ static void RegisterMCInstPrinter(Target &T,
+ Target::MCInstPrinterCtorTy Fn) {
+ if (!T.MCInstPrinterCtorFn)
+ T.MCInstPrinterCtorFn = 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;
+ }
/// @}
};
}
static unsigned getTripleMatchQuality(const std::string &TT) {
- if (Triple(TT.c_str()).getArch() == TargetArchType)
+ if (Triple(TT).getArch() == TargetArchType)
return 20;
return 0;
}
///
/// extern "C" void LLVMInitializeFooTarget() {
/// extern Target TheFooTarget;
- /// RegisterAsmInfo<FooTargetAsmInfo> X(TheFooTarget);
+ /// RegisterAsmInfo<FooMCAsmInfo> X(TheFooTarget);
/// }
- template<class TargetAsmInfoImpl>
+ template<class MCAsmInfoImpl>
struct RegisterAsmInfo {
RegisterAsmInfo(Target &T) {
TargetRegistry::RegisterAsmInfo(T, &Allocator);
}
private:
- static const TargetAsmInfo *Allocator(const Target &T, const StringRef &TT){
- return new TargetAsmInfoImpl(T, TT);
+ static const MCAsmInfo *Allocator(const Target &T, const StringRef &TT) {
+ return new MCAsmInfoImpl(T, TT);
}
};
}
private:
- static FunctionPass *Allocator(formatted_raw_ostream &OS,
- TargetMachine &TM,
- const TargetAsmInfo *TAI,
- bool Verbose) {
- return new AsmPrinterImpl(OS, TM, TAI, Verbose);
+ static AsmPrinter *Allocator(formatted_raw_ostream &OS, TargetMachine &TM,
+ const MCAsmInfo *MAI, bool Verbose) {
+ return new AsmPrinterImpl(OS, TM, MAI, Verbose);
}
};
}
};
+ /// 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) {
+ return new CodeEmitterImpl(T, TM);
+ }
+ };
+
}
#endif