
As with all libraries, the assembly parser library needs declaring within the build system so that when compiled, the functionality this library provides is added.
This consists of a Makefile for when make is used
for the build, a CMakeLists.txt file for when
cmake is used instead and a LLVMBuild.txt file
for the rest of build system.
These files declare which libraries are required and need to be compiled first. In this case the TableGen output for the architecture needs to be generated first so that function generated can be used within the library.
For example, the build files for the OpenRISC 1000 implementation are as follows.
;===- ./lib/Target/OR1K/AsmParser/LLVMBuild.txt ----------------*- Conf -*--===;
;
; The LLVM Compiler Infrastructure
;
; This file is distributed under the University of Illinois Open Source
; License. See LICENSE.TXT for details.
;
;===------------------------------------------------------------------------===;
;
; This is an LLVMBuild description file for the components in this subdirectory.
;
; For more information on the LLVMBuild system, please see:
;
; http://llvm.org/docs/LLVMBuild.html
;
;===------------------------------------------------------------------------===;
[component_0]
type = Library
name = OR1KAsmParser
parent = OR1K
required_libraries = MC MCParser Support OR1KDesc OR1KInfo
add_to_library_groups = OR1K
Figure 3.1. LLVMBuild.txt
add_llvm_library(LLVMOR1KASMParser
OR1KAsmParser.cpp
)
add_dependencies(LLVMOR1KAsmParser OR1KCommonTableGen)
Figure 3.2. CMakeLists.txt
##===- lib/Target/OR1K/AsmParser/Makefile ------------------*- Makefile -*-===##
#
# The LLVM Compiler Infrastructure
#
# This file is distributed under the University of Illinois Open Source
# License. See LICENSE.TXT for details.
#
##===----------------------------------------------------------------------===##
LEVEL = ../../../..
LIBRARYNAME = LLVMOR1KAsmParser
# Hack: we need to include 'main' or1k target directory to grab private headers
CPP.Flags += -I$(PROJ_OBJ_DIR)/.. -I$(PROJ_SRC_DIR)/..
include $(LEVEL)/Makefile.common
Figure 3.3. Makefile
The final parts of the build system that need modifying is adding the new library to its parent.
In the CMakeLists.txt file for the target, the
TableGen assembly matcher needs to be generated and the AsmParser
directory added. The equivalent variables also need changing in the
Makefile. For OpenRISC 1000 this would be as follows.
tablegen(LLVM OR1KGenAsmMatcher.inc -gen-asm-matcher)
add_subdirectory(AsmParser)
Figure 3.4. CMakeLists.txt
# Make sure that tblgen is run, first thing.
BUILT_SOURCES = OR1KGenRegisterInfo.inc OR1KGenInstrInfo.inc \
- OR1KGenAsmWriter.inc OR1KGenDAGISel.inc \
+ OR1KGenAsmWriter.inc OR1KGenAsmMatcher.inc OR1KGenDAGISel.inc \
OR1KGenSubtargetInfo.inc OR1KGenCallingConv.inc
-DIRS = InstPrinter TargetInfo MCTargetDesc
+DIRS = AsmParser InstPrinter TargetInfo MCTargetDesc
Figure 3.5. Makefile
Finally, in the LLVMBuild.txt file for the target
library, the parameter has_parser is defined
as 1.
