llvm.org GIT mirror llvm / 092a9dd
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 Daniel Dunbar 10 years ago
11 changed file(s) with 190 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
256256 add_subdirectory(lib/MC)
257257
258258 set(LLVM_ENUM_ASM_PRINTERS "")
259 set(LLVM_ENUM_ASM_PARSERS "")
259260 foreach(t ${LLVM_TARGETS_TO_BUILD})
260261 message(STATUS "Targeting ${t}")
261262 add_subdirectory(lib/Target/${t})
265266 set(LLVM_ENUM_ASM_PRINTERS
266267 "${LLVM_ENUM_ASM_PRINTERS}LLVM_ASM_PRINTER(${t})\n")
267268 endif( EXISTS ${LLVM_MAIN_SRC_DIR}/lib/Target/${t}/AsmPrinter/CMakeLists.txt )
269 if( EXISTS ${LLVM_MAIN_SRC_DIR}/lib/Target/${t}/AsmParser/CMakeLists.txt )
270 add_subdirectory(lib/Target/${t}/AsmParser)
271 set(LLVM_ENUM_ASM_PARSERS
272 "${LLVM_ENUM_ASM_PARSERS}LLVM_ASM_PARSER(${t})\n")
273 endif( EXISTS ${LLVM_MAIN_SRC_DIR}/lib/Target/${t}/AsmParser/CMakeLists.txt )
268274 endforeach(t)
269275
270276 # Produce llvm/Config/AsmPrinters.def
271277 configure_file(
272278 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmPrinters.def.in
273279 ${LLVM_BINARY_DIR}/include/llvm/Config/AsmPrinters.def
280 )
281
282 # Produce llvm/Config/AsmParsers.def
283 configure_file(
284 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmParsers.def.in
285 ${LLVM_BINARY_DIR}/include/llvm/Config/AsmParsers.def
274286 )
275287
276288 add_subdirectory(lib/ExecutionEngine)
457457 done
458458
459459 # Build the LLVM_TARGET and LLVM_ASM_PRINTER macro uses for
460 # Targets.def and AsmPrinters.def.
460 # Targets.def, AsmPrinters.def, and AsmParsers.def.
461461 LLVM_ENUM_TARGETS=""
462462 LLVM_ENUM_ASM_PRINTERS=""
463 LLVM_ENUM_ASM_PARSERS=""
463464 for target_to_build in $TARGETS_TO_BUILD; do
464465 LLVM_ENUM_TARGETS="LLVM_TARGET($target_to_build) $LLVM_ENUM_TARGETS"
465466 if test -f ${srcdir}/lib/Target/${target_to_build}/AsmPrinter/Makefile ; then
466467 LLVM_ENUM_ASM_PRINTERS="LLVM_ASM_PRINTER($target_to_build) $LLVM_ENUM_ASM_PRINTERS";
467468 fi
469 if test -f ${srcdir}/lib/Target/${target_to_build}/AsmParser/Makefile ; then
470 LLVM_ENUM_ASM_PARSERS="LLVM_ASM_PARSER($target_to_build) $LLVM_ENUM_ASM_PARSERS";
471 fi
468472 done
469473 AC_SUBST(LLVM_ENUM_TARGETS)
470474 AC_SUBST(LLVM_ENUM_ASM_PRINTERS)
475 AC_SUBST(LLVM_ENUM_ASM_PARSERS)
471476
472477 dnl Prevent the CBackend from using printf("%a") for floating point so older
473478 dnl C compilers that cannot deal with the 0x0p+0 hex floating point format
12561261 AC_CONFIG_HEADERS([include/llvm/Config/config.h])
12571262 AC_CONFIG_FILES([include/llvm/Config/Targets.def])
12581263 AC_CONFIG_FILES([include/llvm/Config/AsmPrinters.def])
1264 AC_CONFIG_FILES([include/llvm/Config/AsmParser.def])
12591265 AC_CONFIG_HEADERS([include/llvm/Support/DataTypes.h])
12601266 AC_CONFIG_HEADERS([include/llvm/ADT/iterator.h])
12611267
3434 function(explicit_map_components_to_libraries out_libs)
3535 set( link_components ${ARGN} )
3636 foreach(c ${link_components})
37 # add codegen/asmprinter
37 # add codegen, asmprinter, asmparser
3838 list(FIND LLVM_TARGETS_TO_BUILD ${c} idx)
3939 if( NOT idx LESS 0 )
4040 list(FIND llvm_libs "LLVM${c}CodeGen" idx)
5151 list(FIND llvm_libs "LLVM${c}AsmPrinter" asmidx)
5252 if( NOT asmidx LESS 0 )
5353 list(APPEND expanded_components "LLVM${c}AsmPrinter")
54 endif()
55 list(FIND llvm_libs "LLVM${c}AsmParser" asmidx)
56 if( NOT asmidx LESS 0 )
57 list(APPEND expanded_components "LLVM${c}AsmParser")
5458 endif()
5559 list(FIND llvm_libs "LLVM${c}Info" asmidx)
5660 if( NOT asmidx LESS 0 )
0 //===- llvm/Config/AsmParsers.def - LLVM Assembly Parsers -------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file enumerates all of the assembly-language parsers
10 // supported by this build of LLVM. Clients of this file should define
11 // the LLVM_ASM_PARSER macro to be a function-like macro with a
12 // single parameter (the name of the target whose assembly can be
13 // generated); including this file will then enumerate all of the
14 // targets with assembly parsers.
15 //
16 // The set of targets supported by LLVM is generated at configuration
17 // time, at which point this header is generated. Do not modify this
18 // header directly.
19 //
20 //===----------------------------------------------------------------------===//
21
22 #ifndef LLVM_ASM_PARSER
23 # error Please define the macro LLVM_ASM_PARSER(TargetName)
24 #endif
25
26 @LLVM_ENUM_ASM_PARSERS@
27
28 #undef LLVM_ASM_PARSER
0 //===-- llvm/Target/TargetAsmParser.h - Target Assembly Parser --*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_TARGET_TARGETPARSER_H
10 #define LLVM_TARGET_TARGETPARSER_H
11
12 namespace llvm {
13 class Target;
14
15 /// TargetAsmParser - Generic interface to target specific assembly parsers.
16 class TargetAsmParser {
17 TargetAsmParser(const TargetAsmParser &); // DO NOT IMPLEMENT
18 void operator=(const TargetAsmParser &); // DO NOT IMPLEMENT
19 protected: // Can only create subclasses.
20 TargetAsmParser(const Target &);
21
22 /// TheTarget - The Target that this machine was created for.
23 const Target &TheTarget;
24
25 public:
26 virtual ~TargetAsmParser();
27
28 const Target &getTarget() const { return TheTarget; }
29 };
30
31 } // End llvm namespace
32
33 #endif
2424 namespace llvm {
2525 class FunctionPass;
2626 class Module;
27 class TargetAsmParser;
2728 class TargetMachine;
2829 class formatted_raw_ostream;
2930
4748 typedef FunctionPass *(*AsmPrinterCtorTy)(formatted_raw_ostream &,
4849 TargetMachine &,
4950 bool);
51 typedef TargetAsmParser *(*AsmParserCtorTy)(const Target &);
5052
5153 friend struct TargetRegistry;
5254
8082 /// if registered.
8183 AsmPrinterCtorTy AsmPrinterCtorFn;
8284
85 /// AsmParserCtorFn - Construction function for this target's AsmParser,
86 /// if registered.
87 AsmParserCtorTy AsmParserCtorFn;
88
8389 public:
8490 // getNext - Return the next registered target.
8591 const Target *getNext() const { return Next; }
99105
100106 /// hasAsmPrinter - Check if this target supports .s printing.
101107 bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; }
108
109 /// hasAsmParser - Check if this target supports .s parsing.
110 bool hasAsmParser() const { return AsmParserCtorFn != 0; }
102111
103112 /// createTargetMachine - Create a target specific machine implementation.
104113 TargetMachine *createTargetMachine(const Module &M,
115124 if (!AsmPrinterCtorFn)
116125 return 0;
117126 return AsmPrinterCtorFn(OS, M, Verbose);
127 }
128
129 /// createAsmParser - Create a target specific assembly parser.
130 TargetAsmParser *createAsmParser() const {
131 if (!AsmParserCtorFn)
132 return 0;
133 return AsmParserCtorFn(*this);
118134 }
119135 };
120136
224240 /// @param Fn - A function to construct a TargetMachine for the target.
225241 static void RegisterTargetMachine(Target &T,
226242 Target::TargetMachineCtorTy Fn) {
227 assert(!T.TargetMachineCtorFn && "Constructor already registered!");
228 T.TargetMachineCtorFn = Fn;
243 // Ignore duplicate registration.
244 if (!T.TargetMachineCtorFn)
245 T.TargetMachineCtorFn = Fn;
229246 }
230247
231248 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
238255 /// @param T - The target being registered.
239256 /// @param Fn - A function to construct an AsmPrinter for the target.
240257 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
241 assert(!T.AsmPrinterCtorFn && "Constructor already registered!");
242 T.AsmPrinterCtorFn = Fn;
258 // Ignore duplicate registration.
259 if (!T.AsmPrinterCtorFn)
260 T.AsmPrinterCtorFn = Fn;
261 }
262
263 /// RegisterAsmParser - Register a TargetAsmParser implementation for the
264 /// given target.
265 ///
266 /// Clients are responsible for ensuring that registration doesn't occur
267 /// while another thread is attempting to access the registry. Typically
268 /// this is done by initializing all targets at program startup.
269 ///
270 /// @param T - The target being registered.
271 /// @param Fn - A function to construct an AsmPrinter for the target.
272 static void RegisterAsmParser(Target &T, Target::AsmParserCtorTy Fn) {
273 if (!T.AsmParserCtorFn)
274 T.AsmParserCtorFn = Fn;
243275 }
244276
245277 /// @}
0 include_directories( ${CMAKE_CURRENT_BINARY_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/.. )
1
2 add_llvm_library(LLVMX86AsmParser
3 X86AsmParser.cpp
4 )
5 add_dependencies(LLVMX86AsmParser X86CodeGenTable_gen)
0 ##===- lib/Target/X86/AsmParser/Makefile -------------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open Source
5 # License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8 LEVEL = ../../../..
9 LIBRARYNAME = LLVMX86AsmParser
10
11 # Hack: we need to include 'main' x86 target directory to grab private headers
12 CPPFLAGS = -I$(PROJ_OBJ_DIR)/.. -I$(PROJ_SRC_DIR)/..
13
14 include $(LEVEL)/Makefile.common
0 //===-- X86AsmParser.cpp - Parse X86 assembly to MCInst instructions ------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "llvm/Target/TargetRegistry.h"
10 #include "llvm/Target/TargetAsmParser.h"
11 using namespace llvm;
12
13 namespace {
14
15 class X86ATTAsmParser : public TargetAsmParser {
16 public:
17 explicit X86ATTAsmParser(const Target &);
18 };
19
20 }
21
22 X86ATTAsmParser::X86ATTAsmParser(const Target &T)
23 : TargetAsmParser(T)
24 {
25 }
26
27 namespace {
28 TargetAsmParser *createAsmParser(const Target &T) {
29 return new X86ATTAsmParser(T);
30 }
31 }
32
33 // Force static initialization.
34 extern "C" void LLVMInitializeX86AsmParser() {
35 extern Target TheX86_32Target;
36 TargetRegistry::RegisterAsmParser(TheX86_32Target, &createAsmParser);
37 extern Target TheX86_64Target;
38 TargetRegistry::RegisterAsmParser(TheX86_64Target, &createAsmParser);
39 }
1717 X86GenFastISel.inc \
1818 X86GenCallingConv.inc X86GenSubtarget.inc
1919
20 DIRS = AsmPrinter TargetInfo
20 DIRS = AsmPrinter AsmParser TargetInfo
2121
2222 include $(LEVEL)/Makefile.common
339339 $NAME_MAP{$target} = [$target.'info',
340340 $NAME_MAP{$target}[0]]
341341 }
342
343 if (defined $NAME_MAP{$target.'asmparser'}) {
344 $NAME_MAP{$target} = [$target.'asmparser',
345 $NAME_MAP{$target}[0]]
346 }
342347 }
343348
344349 # Add virtual entries.