[llvm-commits] [llvm] r94127 - in /llvm/trunk/include/llvm/Target: TargetAsmParser.h TargetRegistry.h

Chris Lattner sabre at nondot.org
Thu Jan 21 17:10:41 PST 2010


Author: lattner
Date: Thu Jan 21 19:10:40 2010
New Revision: 94127

URL: http://llvm.org/viewvc/llvm-project?rev=94127&view=rev
Log:
allow registering target lexers.

Modified:
    llvm/trunk/include/llvm/Target/TargetAsmParser.h
    llvm/trunk/include/llvm/Target/TargetRegistry.h

Modified: llvm/trunk/include/llvm/Target/TargetAsmParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetAsmParser.h?rev=94127&r1=94126&r2=94127&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Target/TargetAsmParser.h (original)
+++ llvm/trunk/include/llvm/Target/TargetAsmParser.h Thu Jan 21 19:10:40 2010
@@ -11,7 +11,6 @@
 #define LLVM_TARGET_TARGETPARSER_H
 
 namespace llvm {
-class MCAsmParser;
 class MCInst;
 class StringRef;
 class Target;

Modified: llvm/trunk/include/llvm/Target/TargetRegistry.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetRegistry.h?rev=94127&r1=94126&r2=94127&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Target/TargetRegistry.h (original)
+++ llvm/trunk/include/llvm/Target/TargetRegistry.h Thu Jan 21 19:10:40 2010
@@ -31,6 +31,7 @@
   class MCAsmInfo;
   class MCDisassembler;
   class MCInstPrinter;
+  class TargetAsmLexer;
   class TargetAsmParser;
   class TargetMachine;
   class formatted_raw_ostream;
@@ -59,8 +60,9 @@
                                             TargetMachine &TM,
                                             const MCAsmInfo *MAI,
                                             bool VerboseAsm);
-    typedef TargetAsmParser *(*AsmParserCtorTy)(const Target &T,
-                                                MCAsmParser &P);
+    typedef TargetAsmLexer *(*AsmLexerCtorTy)(const Target &T,
+                                              const MCAsmInfo &MAI);
+    typedef TargetAsmParser *(*AsmParserCtorTy)(const Target &T,MCAsmParser &P);
     typedef const MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T);
     typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
                                                   unsigned SyntaxVariant,
@@ -97,8 +99,12 @@
     /// if registered.
     AsmPrinterCtorTy AsmPrinterCtorFn;
 
-    /// AsmParserCtorFn - Construction function for this target's AsmParser,
+    /// AsmLexerCtorFn - Construction function for this target's TargetAsmLexer,
     /// if registered.
+    AsmLexerCtorTy AsmLexerCtorFn;
+    
+    /// AsmParserCtorFn - Construction function for this target's
+    /// TargetAsmParser, if registered.
     AsmParserCtorTy AsmParserCtorFn;
     
     /// MCDisassemblerCtorFn - Construction function for this target's
@@ -191,6 +197,14 @@
       return AsmPrinterCtorFn(OS, TM, MAI, Verbose);
     }
 
+    /// createAsmLexer - Create a target specific assembly lexer.
+    ///
+    TargetAsmLexer *createAsmLexer(const MCAsmInfo &MAI) const {
+      if (!AsmLexerCtorFn)
+        return 0;
+      return AsmLexerCtorFn(*this, MAI);
+    }
+    
     /// createAsmParser - Create a target specific assembly parser.
     ///
     /// \arg Parser - The target independent parser implementation to use for
@@ -358,6 +372,20 @@
         T.AsmPrinterCtorFn = Fn;
     }
 
+    /// 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;
+    }
+    
     /// RegisterAsmParser - Register a TargetAsmParser implementation for the
     /// given target.
     /// 
@@ -524,6 +552,26 @@
     }
   };
 
+  /// 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);
+    }
+  };
+
   /// RegisterAsmParser - Helper template for registering a target specific
   /// assembly parser, for use in the target machine initialization
   /// function. Usage:





More information about the llvm-commits mailing list