aboutsummaryrefslogtreecommitdiffstats
path: root/include/llvm
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-07-17 20:42:00 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-07-17 20:42:00 +0000
commit092a9dda2d13918a6410db26f41c7b5aa97ff989 (patch)
tree2dcdd3c50dd465a3e1068c713ed64e39781dea35 /include/llvm
parent234f6893a2bb752479e51c943e1eb604f2f48429 (diff)
downloadexternal_llvm-092a9dda2d13918a6410db26f41c7b5aa97ff989.zip
external_llvm-092a9dda2d13918a6410db26f41c7b5aa97ff989.tar.gz
external_llvm-092a9dda2d13918a6410db26f41c7b5aa97ff989.tar.bz2
Sketch support for target specific assembly parser.
- Not fully enabled yet, need a configure regeneration. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76230 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm')
-rw-r--r--include/llvm/Config/AsmParsers.def.in29
-rw-r--r--include/llvm/Target/TargetAsmParser.h34
-rw-r--r--include/llvm/Target/TargetRegistry.h40
3 files changed, 99 insertions, 4 deletions
diff --git a/include/llvm/Config/AsmParsers.def.in b/include/llvm/Config/AsmParsers.def.in
new file mode 100644
index 0000000..041af83
--- /dev/null
+++ b/include/llvm/Config/AsmParsers.def.in
@@ -0,0 +1,29 @@
+//===- llvm/Config/AsmParsers.def - LLVM Assembly Parsers -------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file enumerates all of the assembly-language parsers
+// supported by this build of LLVM. Clients of this file should define
+// the LLVM_ASM_PARSER macro to be a function-like macro with a
+// single parameter (the name of the target whose assembly can be
+// generated); including this file will then enumerate all of the
+// targets with assembly parsers.
+//
+// The set of targets supported by LLVM is generated at configuration
+// time, at which point this header is generated. Do not modify this
+// header directly.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_ASM_PARSER
+# error Please define the macro LLVM_ASM_PARSER(TargetName)
+#endif
+
+@LLVM_ENUM_ASM_PARSERS@
+
+#undef LLVM_ASM_PARSER
diff --git a/include/llvm/Target/TargetAsmParser.h b/include/llvm/Target/TargetAsmParser.h
new file mode 100644
index 0000000..bf96bf7
--- /dev/null
+++ b/include/llvm/Target/TargetAsmParser.h
@@ -0,0 +1,34 @@
+//===-- llvm/Target/TargetAsmParser.h - Target Assembly Parser --*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_TARGET_TARGETPARSER_H
+#define LLVM_TARGET_TARGETPARSER_H
+
+namespace llvm {
+class Target;
+
+/// TargetAsmParser - Generic interface to target specific assembly parsers.
+class TargetAsmParser {
+ TargetAsmParser(const TargetAsmParser &); // DO NOT IMPLEMENT
+ void operator=(const TargetAsmParser &); // DO NOT IMPLEMENT
+protected: // Can only create subclasses.
+ TargetAsmParser(const Target &);
+
+ /// TheTarget - The Target that this machine was created for.
+ const Target &TheTarget;
+
+public:
+ virtual ~TargetAsmParser();
+
+ const Target &getTarget() const { return TheTarget; }
+};
+
+} // End llvm namespace
+
+#endif
diff --git a/include/llvm/Target/TargetRegistry.h b/include/llvm/Target/TargetRegistry.h
index 63ff5f0..026338e 100644
--- a/include/llvm/Target/TargetRegistry.h
+++ b/include/llvm/Target/TargetRegistry.h
@@ -25,6 +25,7 @@
namespace llvm {
class FunctionPass;
class Module;
+ class TargetAsmParser;
class TargetMachine;
class formatted_raw_ostream;
@@ -48,6 +49,7 @@ namespace llvm {
typedef FunctionPass *(*AsmPrinterCtorTy)(formatted_raw_ostream &,
TargetMachine &,
bool);
+ typedef TargetAsmParser *(*AsmParserCtorTy)(const Target &);
friend struct TargetRegistry;
@@ -81,6 +83,10 @@ namespace llvm {
/// if registered.
AsmPrinterCtorTy AsmPrinterCtorFn;
+ /// AsmParserCtorFn - Construction function for this target's AsmParser,
+ /// if registered.
+ AsmParserCtorTy AsmParserCtorFn;
+
public:
// getNext - Return the next registered target.
const Target *getNext() const { return Next; }
@@ -101,6 +107,9 @@ namespace llvm {
/// hasAsmPrinter - Check if this target supports .s printing.
bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; }
+ /// hasAsmParser - Check if this target supports .s parsing.
+ bool hasAsmParser() const { return AsmParserCtorFn != 0; }
+
/// createTargetMachine - Create a target specific machine implementation.
TargetMachine *createTargetMachine(const Module &M,
const std::string &Features) const {
@@ -117,6 +126,13 @@ namespace llvm {
return 0;
return AsmPrinterCtorFn(OS, M, Verbose);
}
+
+ /// createAsmParser - Create a target specific assembly parser.
+ TargetAsmParser *createAsmParser() const {
+ if (!AsmParserCtorFn)
+ return 0;
+ return AsmParserCtorFn(*this);
+ }
};
/// TargetRegistry - Generic interface to target specific features.
@@ -225,8 +241,9 @@ namespace llvm {
/// @param Fn - A function to construct a TargetMachine for the target.
static void RegisterTargetMachine(Target &T,
Target::TargetMachineCtorTy Fn) {
- assert(!T.TargetMachineCtorFn && "Constructor already registered!");
- T.TargetMachineCtorFn = Fn;
+ // Ignore duplicate registration.
+ if (!T.TargetMachineCtorFn)
+ T.TargetMachineCtorFn = Fn;
}
/// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
@@ -239,8 +256,23 @@ namespace llvm {
/// @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) {
- assert(!T.AsmPrinterCtorFn && "Constructor already registered!");
- T.AsmPrinterCtorFn = Fn;
+ // Ignore duplicate registration.
+ if (!T.AsmPrinterCtorFn)
+ T.AsmPrinterCtorFn = Fn;
+ }
+
+ /// 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;
}
/// @}