2009-07-15 04:24:58 +00:00
|
|
|
//===-- Target/TargetRegistry.h - Target Registration -----------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file exposes the TargetRegistry interface, which tools can use to access
|
|
|
|
// the appropriate target specific classes (TargetMachine, AsmPrinter, etc.)
|
|
|
|
// which have been registered.
|
|
|
|
//
|
|
|
|
// Target specific class implementations should register themselves using the
|
|
|
|
// appropriate TargetRegistry interfaces.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_TARGET_TARGETREGISTRY_H
|
|
|
|
#define LLVM_TARGET_TARGETREGISTRY_H
|
|
|
|
|
2009-07-26 05:03:33 +00:00
|
|
|
#include "llvm/ADT/Triple.h"
|
2009-07-15 04:24:58 +00:00
|
|
|
#include <string>
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
namespace llvm {
|
2009-08-13 23:48:47 +00:00
|
|
|
class AsmPrinter;
|
2009-07-15 04:24:58 +00:00
|
|
|
class Module;
|
2009-08-22 20:48:53 +00:00
|
|
|
class MCAsmInfo;
|
2010-02-02 23:37:42 +00:00
|
|
|
class MCAsmParser;
|
|
|
|
class MCCodeEmitter;
|
|
|
|
class MCContext;
|
2009-09-09 22:49:13 +00:00
|
|
|
class MCDisassembler;
|
2009-09-14 03:02:37 +00:00
|
|
|
class MCInstPrinter;
|
2010-02-02 23:37:42 +00:00
|
|
|
class MCStreamer;
|
2010-01-22 01:10:40 +00:00
|
|
|
class TargetAsmLexer;
|
2009-07-17 20:42:00 +00:00
|
|
|
class TargetAsmParser;
|
2009-07-15 04:24:58 +00:00
|
|
|
class TargetMachine;
|
|
|
|
class formatted_raw_ostream;
|
2009-09-14 03:02:37 +00:00
|
|
|
class raw_ostream;
|
2009-07-15 04:24:58 +00:00
|
|
|
|
|
|
|
/// Target - Wrapper for Target specific information.
|
|
|
|
///
|
|
|
|
/// For registration purposes, this is a POD type so that targets can be
|
|
|
|
/// registered without the use of static constructors.
|
2009-07-15 07:09:29 +00:00
|
|
|
///
|
|
|
|
/// Targets should implement a single global instance of this class (which
|
|
|
|
/// will be zero initialized), and pass that instance to the TargetRegistry as
|
|
|
|
/// part of their initialization.
|
|
|
|
class Target {
|
2009-08-12 07:22:17 +00:00
|
|
|
public:
|
|
|
|
friend struct TargetRegistry;
|
|
|
|
|
2009-07-15 04:24:58 +00:00
|
|
|
typedef unsigned (*TripleMatchQualityFnTy)(const std::string &TT);
|
|
|
|
|
2009-08-22 20:48:53 +00:00
|
|
|
typedef const MCAsmInfo *(*AsmInfoCtorFnTy)(const Target &T,
|
2009-11-06 10:58:06 +00:00
|
|
|
StringRef TT);
|
2009-08-12 07:22:17 +00:00
|
|
|
typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
|
|
|
|
const std::string &TT,
|
|
|
|
const std::string &Features);
|
2009-08-13 23:48:47 +00:00
|
|
|
typedef AsmPrinter *(*AsmPrinterCtorTy)(formatted_raw_ostream &OS,
|
|
|
|
TargetMachine &TM,
|
2010-02-02 23:37:42 +00:00
|
|
|
MCContext &Ctx,
|
|
|
|
MCStreamer &Streamer,
|
|
|
|
const MCAsmInfo *MAI);
|
2010-01-22 01:10:40 +00:00
|
|
|
typedef TargetAsmLexer *(*AsmLexerCtorTy)(const Target &T,
|
|
|
|
const MCAsmInfo &MAI);
|
|
|
|
typedef TargetAsmParser *(*AsmParserCtorTy)(const Target &T,MCAsmParser &P);
|
2009-09-09 22:49:13 +00:00
|
|
|
typedef const MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T);
|
2009-09-14 03:02:37 +00:00
|
|
|
typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
|
|
|
|
unsigned SyntaxVariant,
|
|
|
|
const MCAsmInfo &MAI,
|
|
|
|
raw_ostream &O);
|
2009-08-27 00:51:57 +00:00
|
|
|
typedef MCCodeEmitter *(*CodeEmitterCtorTy)(const Target &T,
|
2010-02-12 23:12:47 +00:00
|
|
|
TargetMachine &TM,
|
|
|
|
MCContext &Ctx);
|
2009-08-27 00:51:57 +00:00
|
|
|
|
2009-08-12 07:22:17 +00:00
|
|
|
private:
|
2009-07-15 04:24:58 +00:00
|
|
|
/// Next - The next registered target in the linked list, maintained by the
|
|
|
|
/// TargetRegistry.
|
|
|
|
Target *Next;
|
|
|
|
|
|
|
|
/// TripleMatchQualityFn - The target function for rating the match quality
|
|
|
|
/// of a triple.
|
|
|
|
TripleMatchQualityFnTy TripleMatchQualityFn;
|
|
|
|
|
|
|
|
/// Name - The target name.
|
|
|
|
const char *Name;
|
|
|
|
|
|
|
|
/// ShortDesc - A short description of the target.
|
|
|
|
const char *ShortDesc;
|
|
|
|
|
2009-07-25 10:09:50 +00:00
|
|
|
/// HasJIT - Whether this target supports the JIT.
|
|
|
|
bool HasJIT;
|
|
|
|
|
2009-08-12 07:22:17 +00:00
|
|
|
AsmInfoCtorFnTy AsmInfoCtorFn;
|
|
|
|
|
2009-07-15 04:24:58 +00:00
|
|
|
/// TargetMachineCtorFn - Construction function for this target's
|
|
|
|
/// TargetMachine, if registered.
|
|
|
|
TargetMachineCtorTy TargetMachineCtorFn;
|
|
|
|
|
|
|
|
/// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
|
|
|
|
/// if registered.
|
|
|
|
AsmPrinterCtorTy AsmPrinterCtorFn;
|
|
|
|
|
2010-01-22 01:10:40 +00:00
|
|
|
/// AsmLexerCtorFn - Construction function for this target's TargetAsmLexer,
|
2009-07-17 20:42:00 +00:00
|
|
|
/// if registered.
|
2010-01-22 01:10:40 +00:00
|
|
|
AsmLexerCtorTy AsmLexerCtorFn;
|
|
|
|
|
|
|
|
/// AsmParserCtorFn - Construction function for this target's
|
|
|
|
/// TargetAsmParser, if registered.
|
2009-07-17 20:42:00 +00:00
|
|
|
AsmParserCtorTy AsmParserCtorFn;
|
2009-09-09 22:49:13 +00:00
|
|
|
|
|
|
|
/// MCDisassemblerCtorFn - Construction function for this target's
|
|
|
|
/// MCDisassembler, if registered.
|
|
|
|
MCDisassemblerCtorTy MCDisassemblerCtorFn;
|
2009-07-17 20:42:00 +00:00
|
|
|
|
2009-09-14 03:02:37 +00:00
|
|
|
|
|
|
|
/// MCInstPrinterCtorFn - Construction function for this target's
|
|
|
|
/// MCInstPrinter, if registered.
|
|
|
|
MCInstPrinterCtorTy MCInstPrinterCtorFn;
|
|
|
|
|
2009-08-27 00:51:57 +00:00
|
|
|
/// CodeEmitterCtorFn - Construction function for this target's CodeEmitter,
|
|
|
|
/// if registered.
|
|
|
|
CodeEmitterCtorTy CodeEmitterCtorFn;
|
|
|
|
|
2009-07-15 04:24:58 +00:00
|
|
|
public:
|
2009-08-27 00:51:57 +00:00
|
|
|
/// @name Target Information
|
|
|
|
/// @{
|
|
|
|
|
2009-07-16 02:38:28 +00:00
|
|
|
// getNext - Return the next registered target.
|
|
|
|
const Target *getNext() const { return Next; }
|
|
|
|
|
2009-07-15 04:24:58 +00:00
|
|
|
/// getName - Get the target name.
|
|
|
|
const char *getName() const { return Name; }
|
|
|
|
|
|
|
|
/// getShortDescription - Get a short description of the target.
|
|
|
|
const char *getShortDescription() const { return ShortDesc; }
|
|
|
|
|
2009-08-27 00:51:57 +00:00
|
|
|
/// @}
|
|
|
|
/// @name Feature Predicates
|
|
|
|
/// @{
|
|
|
|
|
|
|
|
/// hasJIT - Check if this targets supports the just-in-time compilation.
|
2009-07-25 10:09:50 +00:00
|
|
|
bool hasJIT() const { return HasJIT; }
|
2009-07-15 20:24:03 +00:00
|
|
|
|
2009-07-16 02:06:09 +00:00
|
|
|
/// hasTargetMachine - Check if this target supports code generation.
|
|
|
|
bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
|
|
|
|
|
|
|
|
/// hasAsmPrinter - Check if this target supports .s printing.
|
|
|
|
bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; }
|
|
|
|
|
2009-07-17 20:42:00 +00:00
|
|
|
/// hasAsmParser - Check if this target supports .s parsing.
|
|
|
|
bool hasAsmParser() const { return AsmParserCtorFn != 0; }
|
2009-09-09 22:49:13 +00:00
|
|
|
|
|
|
|
/// hasMCDisassembler - Check if this target has a disassembler.
|
|
|
|
bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
|
2009-07-17 20:42:00 +00:00
|
|
|
|
2009-09-14 03:02:37 +00:00
|
|
|
/// hasMCInstPrinter - Check if this target has an instruction printer.
|
|
|
|
bool hasMCInstPrinter() const { return MCInstPrinterCtorFn != 0; }
|
|
|
|
|
2009-08-27 00:51:57 +00:00
|
|
|
/// hasCodeEmitter - Check if this target supports instruction encoding.
|
|
|
|
bool hasCodeEmitter() const { return CodeEmitterCtorFn != 0; }
|
|
|
|
|
|
|
|
/// @}
|
|
|
|
/// @name Feature Constructors
|
|
|
|
/// @{
|
2009-08-12 07:22:17 +00:00
|
|
|
|
2009-08-22 20:48:53 +00:00
|
|
|
/// createAsmInfo - Create a MCAsmInfo implementation for the specified
|
2009-08-12 07:22:17 +00:00
|
|
|
/// 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.
|
2009-11-06 10:58:06 +00:00
|
|
|
const MCAsmInfo *createAsmInfo(StringRef Triple) const {
|
2009-08-12 07:22:17 +00:00
|
|
|
if (!AsmInfoCtorFn)
|
|
|
|
return 0;
|
|
|
|
return AsmInfoCtorFn(*this, Triple);
|
|
|
|
}
|
|
|
|
|
2009-08-03 04:03:51 +00:00
|
|
|
/// createTargetMachine - Create a target specific machine implementation
|
2009-08-12 07:22:17 +00:00
|
|
|
/// for the specified \arg Triple.
|
2009-08-03 04:03:51 +00:00
|
|
|
///
|
|
|
|
/// \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.
|
2009-08-04 04:02:45 +00:00
|
|
|
TargetMachine *createTargetMachine(const std::string &Triple,
|
2009-07-15 20:24:03 +00:00
|
|
|
const std::string &Features) const {
|
2009-07-15 04:24:58 +00:00
|
|
|
if (!TargetMachineCtorFn)
|
|
|
|
return 0;
|
2009-08-04 04:02:45 +00:00
|
|
|
return TargetMachineCtorFn(*this, Triple, Features);
|
|
|
|
}
|
2009-07-15 04:24:58 +00:00
|
|
|
|
2010-02-02 23:37:42 +00:00
|
|
|
/// createAsmPrinter - Create a target specific assembly printer pass. This
|
|
|
|
/// takes ownership of the MCContext and MCStreamer objects but not the MAI.
|
2009-08-13 23:48:47 +00:00
|
|
|
AsmPrinter *createAsmPrinter(formatted_raw_ostream &OS, TargetMachine &TM,
|
2010-02-02 23:37:42 +00:00
|
|
|
MCContext &Ctx, MCStreamer &Streamer,
|
|
|
|
const MCAsmInfo *MAI) const {
|
2009-07-15 04:24:58 +00:00
|
|
|
if (!AsmPrinterCtorFn)
|
|
|
|
return 0;
|
2010-02-02 23:37:42 +00:00
|
|
|
return AsmPrinterCtorFn(OS, TM, Ctx, Streamer, MAI);
|
2009-07-15 04:24:58 +00:00
|
|
|
}
|
2009-07-17 20:42:00 +00:00
|
|
|
|
2010-01-22 01:10:40 +00:00
|
|
|
/// createAsmLexer - Create a target specific assembly lexer.
|
|
|
|
///
|
|
|
|
TargetAsmLexer *createAsmLexer(const MCAsmInfo &MAI) const {
|
|
|
|
if (!AsmLexerCtorFn)
|
|
|
|
return 0;
|
|
|
|
return AsmLexerCtorFn(*this, MAI);
|
|
|
|
}
|
|
|
|
|
2009-07-17 20:42:00 +00:00
|
|
|
/// createAsmParser - Create a target specific assembly parser.
|
2009-07-28 20:47:52 +00:00
|
|
|
///
|
|
|
|
/// \arg Parser - The target independent parser implementation to use for
|
|
|
|
/// parsing and lexing.
|
|
|
|
TargetAsmParser *createAsmParser(MCAsmParser &Parser) const {
|
2009-07-17 20:42:00 +00:00
|
|
|
if (!AsmParserCtorFn)
|
|
|
|
return 0;
|
2009-07-28 20:47:52 +00:00
|
|
|
return AsmParserCtorFn(*this, Parser);
|
2009-07-17 20:42:00 +00:00
|
|
|
}
|
2009-09-09 22:49:13 +00:00
|
|
|
|
|
|
|
const MCDisassembler *createMCDisassembler() const {
|
|
|
|
if (!MCDisassemblerCtorFn)
|
|
|
|
return 0;
|
|
|
|
return MCDisassemblerCtorFn(*this);
|
|
|
|
}
|
2009-08-27 00:51:57 +00:00
|
|
|
|
2009-09-14 03:02:37 +00:00
|
|
|
MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
|
|
|
|
const MCAsmInfo &MAI,
|
|
|
|
raw_ostream &O) const {
|
|
|
|
if (!MCInstPrinterCtorFn)
|
|
|
|
return 0;
|
|
|
|
return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, O);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-27 00:51:57 +00:00
|
|
|
/// createCodeEmitter - Create a target specific code emitter.
|
2010-02-12 23:12:47 +00:00
|
|
|
MCCodeEmitter *createCodeEmitter(TargetMachine &TM, MCContext &Ctx) const {
|
2009-08-27 00:51:57 +00:00
|
|
|
if (!CodeEmitterCtorFn)
|
|
|
|
return 0;
|
2010-02-12 23:12:47 +00:00
|
|
|
return CodeEmitterCtorFn(*this, TM, Ctx);
|
2009-08-27 00:51:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @}
|
2009-07-15 04:24:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// TargetRegistry - Generic interface to target specific features.
|
|
|
|
struct TargetRegistry {
|
2009-07-16 02:06:09 +00:00
|
|
|
class iterator {
|
|
|
|
const Target *Current;
|
|
|
|
explicit iterator(Target *T) : Current(T) {}
|
2009-07-18 23:22:46 +00:00
|
|
|
friend struct TargetRegistry;
|
2009-07-16 02:06:09 +00:00
|
|
|
public:
|
|
|
|
iterator(const iterator &I) : Current(I.Current) {}
|
|
|
|
iterator() : Current(0) {}
|
|
|
|
|
|
|
|
bool operator==(const iterator &x) const {
|
|
|
|
return Current == x.Current;
|
|
|
|
}
|
|
|
|
bool operator!=(const iterator &x) const {
|
|
|
|
return !operator==(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Iterator traversal: forward iteration only
|
|
|
|
iterator &operator++() { // Preincrement
|
|
|
|
assert(Current && "Cannot increment end iterator!");
|
2009-07-16 02:38:28 +00:00
|
|
|
Current = Current->getNext();
|
2009-07-16 02:06:09 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
iterator operator++(int) { // Postincrement
|
|
|
|
iterator tmp = *this;
|
|
|
|
++*this;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Target &operator*() const {
|
|
|
|
assert(Current && "Cannot dereference end iterator!");
|
|
|
|
return *Current;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Target *operator->() const {
|
|
|
|
return &operator*();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-07-15 04:24:58 +00:00
|
|
|
/// @name Registry Access
|
|
|
|
/// @{
|
|
|
|
|
2009-07-16 02:06:09 +00:00
|
|
|
static iterator begin();
|
|
|
|
|
|
|
|
static iterator end() { return iterator(); }
|
|
|
|
|
2009-07-26 02:12:58 +00:00
|
|
|
/// lookupTarget - Lookup a target based on a target triple.
|
|
|
|
///
|
|
|
|
/// \param Triple - The triple to use for finding a target.
|
|
|
|
/// \param Error - On failure, an error string describing why no target was
|
|
|
|
/// found.
|
|
|
|
static const Target *lookupTarget(const std::string &Triple,
|
|
|
|
std::string &Error);
|
2009-07-15 04:24:58 +00:00
|
|
|
|
|
|
|
/// getClosestTargetForJIT - Pick the best target that is compatible with
|
|
|
|
/// the current host. If no close target can be found, this returns null
|
|
|
|
/// and sets the Error string to a reason.
|
2009-07-26 02:12:58 +00:00
|
|
|
///
|
2009-08-13 23:36:34 +00:00
|
|
|
/// Maintained for compatibility through 2.6.
|
2009-08-03 04:20:57 +00:00
|
|
|
static const Target *getClosestTargetForJIT(std::string &Error);
|
2009-07-15 04:24:58 +00:00
|
|
|
|
|
|
|
/// @}
|
|
|
|
/// @name Target Registration
|
|
|
|
/// @{
|
|
|
|
|
2009-07-15 20:24:03 +00:00
|
|
|
/// RegisterTarget - Register the given target. Attempts to register a
|
|
|
|
/// target which has already been registered will be ignored.
|
2009-07-15 07:09:29 +00:00
|
|
|
///
|
|
|
|
/// 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.
|
2009-07-15 04:24:58 +00:00
|
|
|
///
|
|
|
|
/// @param T - The target being registered.
|
|
|
|
/// @param Name - The target name. This should be a static string.
|
|
|
|
/// @param ShortDesc - A short target description. This should be a static
|
|
|
|
/// string.
|
|
|
|
/// @param TQualityFn - The triple match quality computation function for
|
|
|
|
/// this target.
|
2009-07-25 10:09:50 +00:00
|
|
|
/// @param HasJIT - Whether the target supports JIT code
|
|
|
|
/// generation.
|
2009-07-15 04:24:58 +00:00
|
|
|
static void RegisterTarget(Target &T,
|
|
|
|
const char *Name,
|
|
|
|
const char *ShortDesc,
|
|
|
|
Target::TripleMatchQualityFnTy TQualityFn,
|
2009-07-25 10:09:50 +00:00
|
|
|
bool HasJIT = false);
|
2009-08-12 07:22:17 +00:00
|
|
|
|
2009-08-22 20:48:53 +00:00
|
|
|
/// RegisterAsmInfo - Register a MCAsmInfo implementation for the
|
2009-08-12 07:22:17 +00:00
|
|
|
/// 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.
|
2009-08-22 20:48:53 +00:00
|
|
|
/// @param Fn - A function to construct a MCAsmInfo for the target.
|
2009-08-12 07:22:17 +00:00
|
|
|
static void RegisterAsmInfo(Target &T, Target::AsmInfoCtorFnTy Fn) {
|
|
|
|
// Ignore duplicate registration.
|
|
|
|
if (!T.AsmInfoCtorFn)
|
|
|
|
T.AsmInfoCtorFn = Fn;
|
|
|
|
}
|
|
|
|
|
2009-07-15 04:24:58 +00:00
|
|
|
/// RegisterTargetMachine - Register a TargetMachine implementation for the
|
|
|
|
/// given target.
|
|
|
|
///
|
2009-07-15 07:09:29 +00:00
|
|
|
/// 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.
|
|
|
|
///
|
2009-07-15 04:24:58 +00:00
|
|
|
/// @param T - The target being registered.
|
|
|
|
/// @param Fn - A function to construct a TargetMachine for the target.
|
|
|
|
static void RegisterTargetMachine(Target &T,
|
|
|
|
Target::TargetMachineCtorTy Fn) {
|
2009-07-17 20:42:00 +00:00
|
|
|
// Ignore duplicate registration.
|
|
|
|
if (!T.TargetMachineCtorFn)
|
|
|
|
T.TargetMachineCtorFn = Fn;
|
2009-07-15 04:24:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
|
|
|
|
/// target.
|
|
|
|
///
|
2009-07-15 07:09:29 +00:00
|
|
|
/// 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.
|
|
|
|
///
|
2009-07-15 04:24:58 +00:00
|
|
|
/// @param T - The target being registered.
|
|
|
|
/// @param Fn - A function to construct an AsmPrinter for the target.
|
|
|
|
static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
|
2009-07-17 20:42:00 +00:00
|
|
|
// Ignore duplicate registration.
|
|
|
|
if (!T.AsmPrinterCtorFn)
|
|
|
|
T.AsmPrinterCtorFn = Fn;
|
|
|
|
}
|
|
|
|
|
2010-01-22 01:10:40 +00:00
|
|
|
/// RegisterAsmLexer - Register a TargetAsmLexer 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 RegisterAsmLexer(Target &T, Target::AsmLexerCtorTy Fn) {
|
|
|
|
if (!T.AsmLexerCtorFn)
|
|
|
|
T.AsmLexerCtorFn = Fn;
|
|
|
|
}
|
|
|
|
|
2009-07-17 20:42:00 +00:00
|
|
|
/// RegisterAsmParser - Register a TargetAsmParser 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 RegisterAsmParser(Target &T, Target::AsmParserCtorTy Fn) {
|
|
|
|
if (!T.AsmParserCtorFn)
|
|
|
|
T.AsmParserCtorFn = Fn;
|
2009-07-15 04:24:58 +00:00
|
|
|
}
|
2009-09-09 22:49:13 +00:00
|
|
|
|
|
|
|
/// 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;
|
|
|
|
}
|
2009-07-15 04:24:58 +00:00
|
|
|
|
2009-10-20 05:15:36 +00:00
|
|
|
/// RegisterMCInstPrinter - Register a MCInstPrinter 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 MCInstPrinter for the target.
|
2009-09-14 03:02:37 +00:00
|
|
|
static void RegisterMCInstPrinter(Target &T,
|
|
|
|
Target::MCInstPrinterCtorTy Fn) {
|
|
|
|
if (!T.MCInstPrinterCtorFn)
|
|
|
|
T.MCInstPrinterCtorFn = Fn;
|
|
|
|
}
|
|
|
|
|
2009-08-27 00:51:57 +00:00
|
|
|
/// RegisterCodeEmitter - Register a MCCodeEmitter implementation for the
|
|
|
|
/// given target.
|
2009-10-20 05:15:36 +00:00
|
|
|
///
|
2009-08-27 00:51:57 +00:00
|
|
|
/// 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;
|
|
|
|
}
|
|
|
|
|
2009-07-15 04:24:58 +00:00
|
|
|
/// @}
|
|
|
|
};
|
|
|
|
|
2009-07-25 06:49:55 +00:00
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// RegisterTarget - Helper template for registering a target, for use in the
|
|
|
|
/// target's initialization function. Usage:
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// Target TheFooTarget; // The global target instance.
|
|
|
|
///
|
|
|
|
/// extern "C" void LLVMInitializeFooTargetInfo() {
|
2009-07-26 05:03:33 +00:00
|
|
|
/// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
|
2009-07-25 06:49:55 +00:00
|
|
|
/// }
|
2009-07-26 05:03:33 +00:00
|
|
|
template<Triple::ArchType TargetArchType = Triple::InvalidArch,
|
|
|
|
bool HasJIT = false>
|
2009-07-25 06:49:55 +00:00
|
|
|
struct RegisterTarget {
|
|
|
|
RegisterTarget(Target &T, const char *Name, const char *Desc) {
|
|
|
|
TargetRegistry::RegisterTarget(T, Name, Desc,
|
2009-07-26 05:03:33 +00:00
|
|
|
&getTripleMatchQuality,
|
|
|
|
HasJIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned getTripleMatchQuality(const std::string &TT) {
|
2009-09-04 22:44:03 +00:00
|
|
|
if (Triple(TT).getArch() == TargetArchType)
|
2009-07-26 05:03:33 +00:00
|
|
|
return 20;
|
|
|
|
return 0;
|
2009-07-25 06:49:55 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-08-12 07:22:17 +00:00
|
|
|
/// RegisterAsmInfo - Helper template for registering a target assembly info
|
|
|
|
/// implementation. This invokes the static "Create" method on the class to
|
|
|
|
/// actually do the construction. Usage:
|
|
|
|
///
|
|
|
|
/// extern "C" void LLVMInitializeFooTarget() {
|
|
|
|
/// extern Target TheFooTarget;
|
2009-08-22 20:48:53 +00:00
|
|
|
/// RegisterAsmInfo<FooMCAsmInfo> X(TheFooTarget);
|
2009-08-12 07:22:17 +00:00
|
|
|
/// }
|
2009-08-22 20:48:53 +00:00
|
|
|
template<class MCAsmInfoImpl>
|
2009-08-12 07:22:17 +00:00
|
|
|
struct RegisterAsmInfo {
|
|
|
|
RegisterAsmInfo(Target &T) {
|
|
|
|
TargetRegistry::RegisterAsmInfo(T, &Allocator);
|
|
|
|
}
|
|
|
|
private:
|
2009-11-06 10:58:06 +00:00
|
|
|
static const MCAsmInfo *Allocator(const Target &T, StringRef TT) {
|
2009-08-22 20:48:53 +00:00
|
|
|
return new MCAsmInfoImpl(T, TT);
|
2009-08-12 07:22:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/// RegisterAsmInfoFn - Helper template for registering a target assembly info
|
|
|
|
/// implementation. This invokes the specified function to do the
|
|
|
|
/// construction. Usage:
|
|
|
|
///
|
|
|
|
/// extern "C" void LLVMInitializeFooTarget() {
|
|
|
|
/// extern Target TheFooTarget;
|
|
|
|
/// RegisterAsmInfoFn X(TheFooTarget, TheFunction);
|
|
|
|
/// }
|
|
|
|
struct RegisterAsmInfoFn {
|
|
|
|
RegisterAsmInfoFn(Target &T, Target::AsmInfoCtorFnTy Fn) {
|
|
|
|
TargetRegistry::RegisterAsmInfo(T, Fn);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-07-25 06:49:55 +00:00
|
|
|
/// RegisterTargetMachine - Helper template for registering a target machine
|
|
|
|
/// implementation, for use in the target machine initialization
|
|
|
|
/// function. Usage:
|
|
|
|
///
|
|
|
|
/// extern "C" void LLVMInitializeFooTarget() {
|
|
|
|
/// extern Target TheFooTarget;
|
|
|
|
/// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
|
|
|
|
/// }
|
|
|
|
template<class TargetMachineImpl>
|
|
|
|
struct RegisterTargetMachine {
|
|
|
|
RegisterTargetMachine(Target &T) {
|
|
|
|
TargetRegistry::RegisterTargetMachine(T, &Allocator);
|
|
|
|
}
|
|
|
|
|
2009-08-02 23:37:13 +00:00
|
|
|
private:
|
2009-08-04 04:02:45 +00:00
|
|
|
static TargetMachine *Allocator(const Target &T, const std::string &TT,
|
2009-08-02 23:37:13 +00:00
|
|
|
const std::string &FS) {
|
2009-08-03 04:03:51 +00:00
|
|
|
return new TargetMachineImpl(T, TT, FS);
|
2009-08-02 23:37:13 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-07-25 06:49:55 +00:00
|
|
|
/// RegisterAsmPrinter - Helper template for registering a target specific
|
|
|
|
/// assembly printer, for use in the target machine initialization
|
|
|
|
/// function. Usage:
|
|
|
|
///
|
|
|
|
/// extern "C" void LLVMInitializeFooAsmPrinter() {
|
|
|
|
/// extern Target TheFooTarget;
|
|
|
|
/// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
|
|
|
|
/// }
|
|
|
|
template<class AsmPrinterImpl>
|
|
|
|
struct RegisterAsmPrinter {
|
|
|
|
RegisterAsmPrinter(Target &T) {
|
|
|
|
TargetRegistry::RegisterAsmPrinter(T, &Allocator);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2009-08-13 23:48:47 +00:00
|
|
|
static AsmPrinter *Allocator(formatted_raw_ostream &OS, TargetMachine &TM,
|
2010-02-02 23:37:42 +00:00
|
|
|
MCContext &Ctx, MCStreamer &Streamer,
|
|
|
|
const MCAsmInfo *MAI) {
|
|
|
|
return new AsmPrinterImpl(OS, TM, Ctx, Streamer, MAI);
|
2009-07-25 06:49:55 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-01-22 01:10:40 +00:00
|
|
|
/// RegisterAsmLexer - Helper template for registering a target specific
|
|
|
|
/// assembly lexer, for use in the target machine initialization
|
|
|
|
/// function. Usage:
|
|
|
|
///
|
|
|
|
/// extern "C" void LLVMInitializeFooAsmLexer() {
|
|
|
|
/// extern Target TheFooTarget;
|
|
|
|
/// RegisterAsmLexer<FooAsmLexer> X(TheFooTarget);
|
|
|
|
/// }
|
|
|
|
template<class AsmLexerImpl>
|
|
|
|
struct RegisterAsmLexer {
|
|
|
|
RegisterAsmLexer(Target &T) {
|
|
|
|
TargetRegistry::RegisterAsmLexer(T, &Allocator);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static TargetAsmLexer *Allocator(const Target &T, const MCAsmInfo &MAI) {
|
|
|
|
return new AsmLexerImpl(T, MAI);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-07-28 20:47:52 +00:00
|
|
|
/// RegisterAsmParser - Helper template for registering a target specific
|
|
|
|
/// assembly parser, for use in the target machine initialization
|
|
|
|
/// function. Usage:
|
2009-07-25 06:49:55 +00:00
|
|
|
///
|
2009-07-28 20:47:52 +00:00
|
|
|
/// extern "C" void LLVMInitializeFooAsmParser() {
|
2009-07-25 06:49:55 +00:00
|
|
|
/// extern Target TheFooTarget;
|
2009-07-28 20:47:52 +00:00
|
|
|
/// RegisterAsmParser<FooAsmParser> X(TheFooTarget);
|
2009-07-25 06:49:55 +00:00
|
|
|
/// }
|
|
|
|
template<class AsmParserImpl>
|
|
|
|
struct RegisterAsmParser {
|
|
|
|
RegisterAsmParser(Target &T) {
|
|
|
|
TargetRegistry::RegisterAsmParser(T, &Allocator);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2009-07-28 20:47:52 +00:00
|
|
|
static TargetAsmParser *Allocator(const Target &T, MCAsmParser &P) {
|
|
|
|
return new AsmParserImpl(T, P);
|
2009-07-25 06:49:55 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-08-27 00:51:57 +00:00
|
|
|
/// 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:
|
2010-02-12 23:12:47 +00:00
|
|
|
static MCCodeEmitter *Allocator(const Target &T, TargetMachine &TM,
|
|
|
|
MCContext &Ctx) {
|
|
|
|
return new CodeEmitterImpl(T, TM, Ctx);
|
2009-08-27 00:51:57 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-07-15 04:24:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|