From 931d4521c33df446cf4f5a8ae168a8001556693f Mon Sep 17 00:00:00 2001 From: Mikhail Glushenkov Date: Mon, 2 Mar 2009 09:01:14 +0000 Subject: [PATCH] Reorganize llvmc code. Move the code from 'llvmc/driver' into a new CompilerDriver library, and change the build system accordingly. Makes it easier for projects using LLVM to build their own llvmc-based drivers. Tested with objdir != srcdir. llvm-svn: 65821 --- .../llvm/CompilerDriver}/Error.h | 0 .../driver => lib/CompilerDriver}/Action.cpp | 0 .../CompilerDriver}/CMakeLists.txt | 0 .../CompilerDriver}/CompilationGraph.cpp | 2 +- llvm/lib/CompilerDriver/Makefile | 19 +++++++ .../driver => lib/CompilerDriver}/Plugin.cpp | 0 .../driver => lib/CompilerDriver}/Tool.cpp | 0 llvm/lib/Makefile | 2 +- llvm/tools/llvmc/CMakeLists.txt | 2 +- llvm/tools/llvmc/Makefile | 11 +++-- llvm/tools/llvmc/Makefile.llvmc | 49 +++++++++++++++++++ .../llvmc/driver/{llvmc.cpp => Main.cpp} | 5 +- llvm/tools/llvmc/driver/Makefile | 13 +++-- llvm/tools/llvmc/plugins/Base/Makefile | 4 +- llvm/tools/llvmc/plugins/Clang/Makefile | 4 +- llvm/tools/llvmc/plugins/Hello/Makefile | 4 +- llvm/tools/llvmc/plugins/Makefile | 45 ++--------------- llvm/tools/llvmc/plugins/Simple/Makefile | 4 +- 18 files changed, 103 insertions(+), 61 deletions(-) rename llvm/{tools/llvmc/driver => include/llvm/CompilerDriver}/Error.h (100%) rename llvm/{tools/llvmc/driver => lib/CompilerDriver}/Action.cpp (100%) rename llvm/{tools/llvmc/driver => lib/CompilerDriver}/CMakeLists.txt (100%) rename llvm/{tools/llvmc/driver => lib/CompilerDriver}/CompilationGraph.cpp (99%) create mode 100644 llvm/lib/CompilerDriver/Makefile rename llvm/{tools/llvmc/driver => lib/CompilerDriver}/Plugin.cpp (100%) rename llvm/{tools/llvmc/driver => lib/CompilerDriver}/Tool.cpp (100%) create mode 100644 llvm/tools/llvmc/Makefile.llvmc rename llvm/tools/llvmc/driver/{llvmc.cpp => Main.cpp} (96%) diff --git a/llvm/tools/llvmc/driver/Error.h b/llvm/include/llvm/CompilerDriver/Error.h similarity index 100% rename from llvm/tools/llvmc/driver/Error.h rename to llvm/include/llvm/CompilerDriver/Error.h diff --git a/llvm/tools/llvmc/driver/Action.cpp b/llvm/lib/CompilerDriver/Action.cpp similarity index 100% rename from llvm/tools/llvmc/driver/Action.cpp rename to llvm/lib/CompilerDriver/Action.cpp diff --git a/llvm/tools/llvmc/driver/CMakeLists.txt b/llvm/lib/CompilerDriver/CMakeLists.txt similarity index 100% rename from llvm/tools/llvmc/driver/CMakeLists.txt rename to llvm/lib/CompilerDriver/CMakeLists.txt diff --git a/llvm/tools/llvmc/driver/CompilationGraph.cpp b/llvm/lib/CompilerDriver/CompilationGraph.cpp similarity index 99% rename from llvm/tools/llvmc/driver/CompilationGraph.cpp rename to llvm/lib/CompilerDriver/CompilationGraph.cpp index 238ef6f42a78..b8a66e17f53b 100644 --- a/llvm/tools/llvmc/driver/CompilationGraph.cpp +++ b/llvm/lib/CompilerDriver/CompilationGraph.cpp @@ -11,8 +11,8 @@ // //===----------------------------------------------------------------------===// -#include "Error.h" #include "llvm/CompilerDriver/CompilationGraph.h" +#include "llvm/CompilerDriver/Error.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/CommandLine.h" diff --git a/llvm/lib/CompilerDriver/Makefile b/llvm/lib/CompilerDriver/Makefile new file mode 100644 index 000000000000..e5bf3e10a79e --- /dev/null +++ b/llvm/lib/CompilerDriver/Makefile @@ -0,0 +1,19 @@ +##===- lib/CompilerDriver/Makefile -------------------------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open +# Source License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## + +LEVEL = ../.. + +# We don't want this library to appear in `llvm-config --libs` output, so its +# name doesn't start with "LLVM". + +LIBRARYNAME = CompilerDriver +LINK_COMPONENTS = support system +REQUIRES_EH := 1 + +include $(LEVEL)/Makefile.common diff --git a/llvm/tools/llvmc/driver/Plugin.cpp b/llvm/lib/CompilerDriver/Plugin.cpp similarity index 100% rename from llvm/tools/llvmc/driver/Plugin.cpp rename to llvm/lib/CompilerDriver/Plugin.cpp diff --git a/llvm/tools/llvmc/driver/Tool.cpp b/llvm/lib/CompilerDriver/Tool.cpp similarity index 100% rename from llvm/tools/llvmc/driver/Tool.cpp rename to llvm/lib/CompilerDriver/Tool.cpp diff --git a/llvm/lib/Makefile b/llvm/lib/Makefile index 4ad0763f97aa..8dd67d9957de 100644 --- a/llvm/lib/Makefile +++ b/llvm/lib/Makefile @@ -9,7 +9,7 @@ LEVEL = .. PARALLEL_DIRS = VMCore AsmParser Bitcode Archive Analysis Transforms CodeGen \ - Target ExecutionEngine Debugger Linker + Target ExecutionEngine Debugger Linker CompilerDriver include $(LEVEL)/Makefile.common diff --git a/llvm/tools/llvmc/CMakeLists.txt b/llvm/tools/llvmc/CMakeLists.txt index f8204199041f..bebaaebca8d6 100644 --- a/llvm/tools/llvmc/CMakeLists.txt +++ b/llvm/tools/llvmc/CMakeLists.txt @@ -1,4 +1,4 @@ -add_subdirectory(driver) +# add_subdirectory(driver) # TODO: support plugins and user-configured builds. # See ./doc/LLVMC-Reference.rst "Customizing LLVMC: the compilation graph" diff --git a/llvm/tools/llvmc/Makefile b/llvm/tools/llvmc/Makefile index 4354c387d40a..60961769d197 100644 --- a/llvm/tools/llvmc/Makefile +++ b/llvm/tools/llvmc/Makefile @@ -9,11 +9,12 @@ LEVEL = ../.. -BUILTIN_PLUGINS = Base Clang -DRIVER_NAME = llvmc +# The current plan is to make the user copy the skeleton project and change only +# this file (and plugins/UserPlugin, of course). + +export LLVMC_BASED_DRIVER_NAME = llvmc +export LLVMC_BUILTIN_PLUGINS = Base Clang + DIRS = plugins driver -export BUILTIN_PLUGINS -export DRIVER_NAME - include $(LEVEL)/Makefile.common diff --git a/llvm/tools/llvmc/Makefile.llvmc b/llvm/tools/llvmc/Makefile.llvmc new file mode 100644 index 000000000000..79ec6426e8d7 --- /dev/null +++ b/llvm/tools/llvmc/Makefile.llvmc @@ -0,0 +1,49 @@ +##===- tools/llvmc/Makefile.llvmc --------------------------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open +# Source License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## + +# TODO: This must be eventually merged into Makefile.rules. + +ifdef LLVMC_PLUGIN + +# We are included from plugins/PluginName/Makefile... + +LEVEL = ../../../.. + +LIBRARYNAME := $(patsubst %,plugin_llvmc_%,$(LLVMC_PLUGIN)) +REQUIRES_EH := 1 + +# Build a dynamic library if the user runs `make` from plugins/PluginName +ifndef LLVMC_BUILTIN_PLUGIN +LOADABLE_MODULE = 1 +endif + +# TableGen stuff... +ifneq ($(BUILT_SOURCES),) +BUILD_AUTOGENERATED_INC=1 +endif + +include $(LEVEL)/Makefile.common + +ifdef BUILD_AUTOGENERATED_INC + +TOOLS_SOURCE := $(strip $(wildcard $(PROJ_SRC_DIR)/*.td)) + +TD_COMMON :=$(strip $(wildcard \ + $(LLVM_SRC_ROOT)/include/llvm/CompilerDriver/*.td)) + +$(ObjDir)/AutoGenerated.inc.tmp: $(TOOLS_SOURCE) $(ObjDir)/.dir \ + $(TBLGEN) $(TD_COMMON) + $(Echo) "Building LLVMC configuration library with tblgen" + $(Verb) $(TableGen) -gen-llvmc -o $(call SYSPATH, $@) $< + +AutoGenerated.inc : $(ObjDir)/AutoGenerated.inc.tmp + $(Verb) $(CMP) -s $@ $< || $(CP) $< $@ +endif # BUILD_AUTOGENERATED_INC + +endif # LLVMC_PLUGIN diff --git a/llvm/tools/llvmc/driver/llvmc.cpp b/llvm/tools/llvmc/driver/Main.cpp similarity index 96% rename from llvm/tools/llvmc/driver/llvmc.cpp rename to llvm/tools/llvmc/driver/Main.cpp index 059e840eeb6f..16b91a87c91b 100644 --- a/llvm/tools/llvmc/driver/llvmc.cpp +++ b/llvm/tools/llvmc/driver/Main.cpp @@ -1,4 +1,4 @@ -//===--- llvmc.cpp - The LLVM Compiler Driver -------------------*- C++ -*-===// +//===--- Main.cpp - The LLVM Compiler Driver -------------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -14,9 +14,8 @@ // //===----------------------------------------------------------------------===// -#include "Error.h" - #include "llvm/CompilerDriver/CompilationGraph.h" +#include "llvm/CompilerDriver/Error.h" #include "llvm/CompilerDriver/Plugin.h" #include "llvm/System/Path.h" diff --git a/llvm/tools/llvmc/driver/Makefile b/llvm/tools/llvmc/driver/Makefile index 107f0dea385a..0e32726fec25 100644 --- a/llvm/tools/llvmc/driver/Makefile +++ b/llvm/tools/llvmc/driver/Makefile @@ -8,12 +8,15 @@ ##===----------------------------------------------------------------------===## LEVEL = ../../.. -TOOLNAME = $(DRIVER_NAME) + +TOOLNAME = $(LLVMC_BASED_DRIVER_NAME) +USEDLIBS = CompilerDriver + +ifneq ($(LLVMC_BUILTIN_PLUGINS),) +USEDLIBS += $(patsubst %,plugin_llvmc_%,$(LLVMC_BUILTIN_PLUGINS)) +endif + LINK_COMPONENTS = support system REQUIRES_EH := 1 -ifneq ($(BUILTIN_PLUGINS),) -USEDLIBS = $(patsubst %,plugin_llvmc_%,$(BUILTIN_PLUGINS)) -endif - include $(LEVEL)/Makefile.common diff --git a/llvm/tools/llvmc/plugins/Base/Makefile b/llvm/tools/llvmc/plugins/Base/Makefile index 5ca6048508a1..eb6ed010c6f6 100644 --- a/llvm/tools/llvmc/plugins/Base/Makefile +++ b/llvm/tools/llvmc/plugins/Base/Makefile @@ -7,7 +7,9 @@ # ##===----------------------------------------------------------------------===## +LEVEL = ../.. + LLVMC_PLUGIN = Base BUILT_SOURCES = AutoGenerated.inc -include ../Makefile +include $(LEVEL)/Makefile.llvmc diff --git a/llvm/tools/llvmc/plugins/Clang/Makefile b/llvm/tools/llvmc/plugins/Clang/Makefile index 32060138c233..a1b011e90db4 100644 --- a/llvm/tools/llvmc/plugins/Clang/Makefile +++ b/llvm/tools/llvmc/plugins/Clang/Makefile @@ -7,7 +7,9 @@ # ##===----------------------------------------------------------------------===## +LEVEL = ../.. + LLVMC_PLUGIN = Clang BUILT_SOURCES = AutoGenerated.inc -include ../Makefile +include $(LEVEL)/Makefile.llvmc diff --git a/llvm/tools/llvmc/plugins/Hello/Makefile b/llvm/tools/llvmc/plugins/Hello/Makefile index 181dd0c60508..8e9fa6f31351 100644 --- a/llvm/tools/llvmc/plugins/Hello/Makefile +++ b/llvm/tools/llvmc/plugins/Hello/Makefile @@ -7,6 +7,8 @@ # ##===----------------------------------------------------------------------===## +LEVEL = ../.. + LLVMC_PLUGIN = Hello -include ../Makefile +include $(LEVEL)/Makefile.llvmc diff --git a/llvm/tools/llvmc/plugins/Makefile b/llvm/tools/llvmc/plugins/Makefile index 734323f50d78..37dac6f0ac05 100644 --- a/llvm/tools/llvmc/plugins/Makefile +++ b/llvm/tools/llvmc/plugins/Makefile @@ -1,4 +1,4 @@ -##===- tools/llvmc/plugins/Makefile.plugins ----------------*- Makefile -*-===## +##===- tools/llvmc/plugins/Makefile ------------------------*- Makefile -*-===## # # The LLVM Compiler Infrastructure # @@ -7,49 +7,12 @@ # ##===----------------------------------------------------------------------===## -ifndef LLVMC_PLUGIN - LEVEL = ../../.. -DIRS = $(BUILTIN_PLUGINS) -# TOFIX: Should we also build DSO versions of plugins? -export BUILTIN_LLVMC_PLUGIN=1 - -include $(LEVEL)/Makefile.common - -else # LLVMC_PLUGIN - -LEVEL = ../../../.. - -LIBRARYNAME := $(patsubst %,plugin_llvmc_%,$(LLVMC_PLUGIN)) -REQUIRES_EH = 1 - -ifndef BUILTIN_LLVMC_PLUGIN -LOADABLE_MODULE = 1 +ifneq ($(LLVMC_BUILTIN_PLUGINS),) +DIRS = $(LLVMC_BUILTIN_PLUGINS) endif -ifneq ($(BUILT_SOURCES),) -BUILD_AUTOGENERATED_INC=1 -endif +export LLVMC_BUILTIN_PLUGIN=1 include $(LEVEL)/Makefile.common - -# TOFIX: This probably should go into Makefile.rules - -ifdef BUILD_AUTOGENERATED_INC - -TOOLS_SOURCE := $(strip $(wildcard $(PROJ_SRC_DIR)/*.td)) - -TD_COMMON :=$(strip $(wildcard \ - $(LLVM_SRC_ROOT)/include/llvm/CompilerDriver/*.td)) - -$(ObjDir)/AutoGenerated.inc.tmp: $(TOOLS_SOURCE) $(ObjDir)/.dir \ - $(TBLGEN) $(TD_COMMON) - $(Echo) "Building LLVMC configuration library with tblgen" - $(Verb) $(TableGen) -gen-llvmc -o $(call SYSPATH, $@) $< - -AutoGenerated.inc : $(ObjDir)/AutoGenerated.inc.tmp - $(Verb) $(CMP) -s $@ $< || $(CP) $< $@ -endif # BUILD_AUTOGENERATED_INC - -endif # LLVMC_PLUGIN diff --git a/llvm/tools/llvmc/plugins/Simple/Makefile b/llvm/tools/llvmc/plugins/Simple/Makefile index 1cd5af7a15e6..c38cda51719f 100644 --- a/llvm/tools/llvmc/plugins/Simple/Makefile +++ b/llvm/tools/llvmc/plugins/Simple/Makefile @@ -7,7 +7,9 @@ # ##===----------------------------------------------------------------------===## +LEVEL = ../.. + LLVMC_PLUGIN = Simple BUILT_SOURCES = AutoGenerated.inc -include ../Makefile +include $(LEVEL)/Makefile.llvmc