From 95c1f5ba64e7ad505781235839b65a2a8f64a733 Mon Sep 17 00:00:00 2001 From: Mikhail Glushenkov Date: Mon, 29 Jun 2009 03:09:15 +0000 Subject: [PATCH] Make dynamic LLVMC plugins work on Windows (finally!). Implemented by making lib/CompilerDriver a shared library that holds all the global static data (CommandLine options, plugin registry) that we unfortunately have to live with. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74417 91177308-0d34-0410-b5e6-96231b3b80d8 --- Makefile.rules | 4 +-- include/llvm/CompilerDriver/Main.inc | 38 -------------------- lib/CompilerDriver/BuiltinOptions.cpp | 52 +++++++++++++++++++++++++++ lib/CompilerDriver/Makefile | 18 ++++++++-- lib/CompilerDriver/Tool.cpp | 6 ++++ 5 files changed, 76 insertions(+), 42 deletions(-) create mode 100644 lib/CompilerDriver/BuiltinOptions.cpp diff --git a/Makefile.rules b/Makefile.rules index a1a1924a990..9787d5fe0b5 100644 --- a/Makefile.rules +++ b/Makefile.rules @@ -200,6 +200,7 @@ ifdef LLVMC_PLUGIN LIBRARYNAME := $(patsubst %,plugin_llvmc_%,$(LLVMC_PLUGIN)) CPP.Flags += -DLLVMC_PLUGIN_NAME=$(LLVMC_PLUGIN) REQUIRES_EH := 1 +LD.Flags += -lCompilerDriver # Build a dynamic library if the user runs `make` directly from the plugin # directory. @@ -217,9 +218,8 @@ endif # LLVMC_PLUGIN ifdef LLVMC_BASED_DRIVER TOOLNAME = $(LLVMC_BASED_DRIVER) -LLVMLIBS = CompilerDriver.a -LINK_COMPONENTS = support system REQUIRES_EH := 1 +LD.Flags += -lCompilerDriver # Preprocessor magic that generates references to static variables in built-in # plugins. diff --git a/include/llvm/CompilerDriver/Main.inc b/include/llvm/CompilerDriver/Main.inc index 4a83d563000..5dce8793976 100644 --- a/include/llvm/CompilerDriver/Main.inc +++ b/include/llvm/CompilerDriver/Main.inc @@ -24,8 +24,6 @@ #include "llvm/CompilerDriver/Plugin.h" #include "llvm/System/Path.h" -#include "llvm/Support/CommandLine.h" -#include "llvm/Support/PluginLoader.h" #include #include @@ -35,42 +33,6 @@ namespace cl = llvm::cl; namespace sys = llvm::sys; using namespace llvmc; -// Built-in command-line options. -// External linkage here is intentional. - -cl::list InputFilenames(cl::Positional, cl::desc(""), - cl::ZeroOrMore); -cl::opt OutputFilename("o", cl::desc("Output file name"), - cl::value_desc("file"), cl::Prefix); -cl::list Languages("x", - cl::desc("Specify the language of the following input files"), - cl::ZeroOrMore); -cl::opt DryRun("dry-run", - cl::desc("Only pretend to run commands")); -cl::opt VerboseMode("v", - cl::desc("Enable verbose mode")); - -cl::opt CheckGraph("check-graph", - cl::desc("Check the compilation graph for errors"), - cl::Hidden); -cl::opt WriteGraph("write-graph", - cl::desc("Write compilation-graph.dot file"), - cl::Hidden); -cl::opt ViewGraph("view-graph", - cl::desc("Show compilation graph in GhostView"), - cl::Hidden); - -cl::opt SaveTemps -("save-temps", cl::desc("Keep temporary files"), - cl::init(SaveTempsEnum::Unset), - cl::values(clEnumValN(SaveTempsEnum::Obj, "obj", - "Save files in the directory specified with -o"), - clEnumValN(SaveTempsEnum::Cwd, "cwd", - "Use current working directory"), - clEnumValN(SaveTempsEnum::Obj, "", "Same as 'cwd'"), - clEnumValEnd), - cl::ValueOptional); - namespace { sys::Path getTempDir() { diff --git a/lib/CompilerDriver/BuiltinOptions.cpp b/lib/CompilerDriver/BuiltinOptions.cpp new file mode 100644 index 00000000000..c8b768219ab --- /dev/null +++ b/lib/CompilerDriver/BuiltinOptions.cpp @@ -0,0 +1,52 @@ +//===--- BuiltinOptions.cpp - The LLVM Compiler Driver ----------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open +// Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// Definitions of all global command-line option variables. +// +//===----------------------------------------------------------------------===// + +#include "llvm/CompilerDriver/BuiltinOptions.h" +#include "llvm/Support/PluginLoader.h" + +namespace cl = llvm::cl; + +// External linkage here is intentional. + +cl::list InputFilenames(cl::Positional, cl::desc(""), + cl::ZeroOrMore); +cl::opt OutputFilename("o", cl::desc("Output file name"), + cl::value_desc("file"), cl::Prefix); +cl::list Languages("x", + cl::desc("Specify the language of the following input files"), + cl::ZeroOrMore); +cl::opt DryRun("dry-run", + cl::desc("Only pretend to run commands")); +cl::opt VerboseMode("v", + cl::desc("Enable verbose mode")); + +cl::opt CheckGraph("check-graph", + cl::desc("Check the compilation graph for errors"), + cl::Hidden); +cl::opt WriteGraph("write-graph", + cl::desc("Write compilation-graph.dot file"), + cl::Hidden); +cl::opt ViewGraph("view-graph", + cl::desc("Show compilation graph in GhostView"), + cl::Hidden); + +cl::opt SaveTemps +("save-temps", cl::desc("Keep temporary files"), + cl::init(SaveTempsEnum::Unset), + cl::values(clEnumValN(SaveTempsEnum::Obj, "obj", + "Save files in the directory specified with -o"), + clEnumValN(SaveTempsEnum::Cwd, "cwd", + "Use current working directory"), + clEnumValN(SaveTempsEnum::Obj, "", "Same as 'cwd'"), + clEnumValEnd), + cl::ValueOptional); diff --git a/lib/CompilerDriver/Makefile b/lib/CompilerDriver/Makefile index e5bf3e10a79..bbef2e34a14 100644 --- a/lib/CompilerDriver/Makefile +++ b/lib/CompilerDriver/Makefile @@ -12,8 +12,22 @@ 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 +LIBRARYNAME = libCompilerDriver +LLVMLIBS = LLVMSupport.a LLVMSystem.a +LOADABLE_MODULE := 1 REQUIRES_EH := 1 include $(LEVEL)/Makefile.common + +FullLibName = $(LIBRARYNAME)$(SHLIBEXT) + +# Copy the library to the bin dir so that llvmc can find it. +all-local:: + $(Echo) Copying $(BuildMode) Shared Library $(FullLibName) \ + to $(ToolDir) + -$(Verb) $(CP) $(LibDir)/$(FullLibName) $(ToolDir)/ + +clean-local:: + $(Echo) Removing $(BuildMode) Shared Library $(FullLibName) \ + from $(ToolDir) + -$(Verb) $(RM) -f $(ToolDir)/$(FullLibName) diff --git a/lib/CompilerDriver/Tool.cpp b/lib/CompilerDriver/Tool.cpp index e704dd9544f..7953dd24934 100644 --- a/lib/CompilerDriver/Tool.cpp +++ b/lib/CompilerDriver/Tool.cpp @@ -14,11 +14,17 @@ #include "llvm/CompilerDriver/BuiltinOptions.h" #include "llvm/CompilerDriver/Tool.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/System/Path.h" using namespace llvm; using namespace llvmc; +// SplitString is used by derived Tool classes. +typedef void (*SplitStringFunPtr)(const std::string&, + std::vector&, const char*); +SplitStringFunPtr ForceLinkageSplitString = &llvm::SplitString; + namespace { sys::Path MakeTempFile(const sys::Path& TempDir, const std::string& BaseName, const std::string& Suffix) {