diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/llvmc2/Action.h | 3 | ||||
-rw-r--r-- | tools/llvmc2/Common.td | 1 | ||||
-rw-r--r-- | tools/llvmc2/CompilationGraph.cpp | 4 | ||||
-rw-r--r-- | tools/llvmc2/CompilationGraph.h | 16 | ||||
-rw-r--r-- | tools/llvmc2/StringSet.h | 40 | ||||
-rw-r--r-- | tools/llvmc2/Tool.h | 13 | ||||
-rw-r--r-- | tools/llvmc2/Tools.td | 15 |
7 files changed, 68 insertions, 24 deletions
diff --git a/tools/llvmc2/Action.h b/tools/llvmc2/Action.h index 32d1855..0f3f0bd 100644 --- a/tools/llvmc2/Action.h +++ b/tools/llvmc2/Action.h @@ -25,9 +25,10 @@ namespace llvmc { class Action { /// Command_ - The actual command (for example, 'ls'). std::string Command_; - /// Args_ - Command arguments. Stdout redirection is allowed. + /// Args_ - Command arguments. Stdout redirection ("> file") is allowed. std::vector<std::string> Args_; public: + Action() {} Action (const std::string& C, const StringVector& A) : Command_(C), Args_(A) diff --git a/tools/llvmc2/Common.td b/tools/llvmc2/Common.td index 2a6b54e..364cac3 100644 --- a/tools/llvmc2/Common.td +++ b/tools/llvmc2/Common.td @@ -56,6 +56,7 @@ def switch_on; def parameter_equals; def element_in_list; def input_languages_contain; +def default; // Boolean operators. def and; diff --git a/tools/llvmc2/CompilationGraph.cpp b/tools/llvmc2/CompilationGraph.cpp index e06a168..7ce4313 100644 --- a/tools/llvmc2/CompilationGraph.cpp +++ b/tools/llvmc2/CompilationGraph.cpp @@ -177,7 +177,7 @@ void CompilationGraph::PassThroughGraph (const sys::Path& InFile, Out = MakeTempFile(TempDir, In.getBasename(), CurTool->OutputSuffix()); } - if (int ret = CurTool->GenerateAction(In, Out).Execute()) + if (int ret = CurTool->GenerateAction(In, Out, InLangs).Execute()) throw error_code(ret); if (Last) @@ -343,7 +343,7 @@ int CompilationGraph::Build (const sys::Path& TempDir) { Out = MakeTempFile(TempDir, "tmp", JT->OutputSuffix()); } - if (int ret = JT->GenerateAction(Out).Execute()) + if (int ret = JT->GenerateAction(Out, InLangs).Execute()) throw error_code(ret); if (!IsLast) { diff --git a/tools/llvmc2/CompilationGraph.h b/tools/llvmc2/CompilationGraph.h index 91a9c77..6b2b290 100644 --- a/tools/llvmc2/CompilationGraph.h +++ b/tools/llvmc2/CompilationGraph.h @@ -16,6 +16,7 @@ #include "AutoGenerated.h" #include "Tool.h" +#include "StringSet.h" #include "llvm/ADT/GraphTraits.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" @@ -29,21 +30,6 @@ namespace llvmc { - /// StringSet - A wrapper for StringMap that provides set-like - /// functionality. Only insert() and count() methods are used by my - /// code. - template <class AllocatorTy = llvm::MallocAllocator> - class StringSet : public llvm::StringMap<char, AllocatorTy> { - typedef llvm::StringMap<char, AllocatorTy> base; - public: - void insert (const std::string& InLang) { - assert(!InLang.empty()); - const char* KeyStart = &InLang[0]; - const char* KeyEnd = KeyStart + InLang.size(); - base::insert(llvm::StringMapEntry<char>:: - Create(KeyStart, KeyEnd, base::getAllocator(), '+')); - } - }; typedef StringSet<> InputLanguagesSet; /// Edge - Represents an edge of the compilation graph. diff --git a/tools/llvmc2/StringSet.h b/tools/llvmc2/StringSet.h new file mode 100644 index 0000000..d9556cc --- /dev/null +++ b/tools/llvmc2/StringSet.h @@ -0,0 +1,40 @@ +//===--- StringSet.h - 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. +// +//===----------------------------------------------------------------------===// +// +// StringSet - A set-like wrapper for the StringMap. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_TOOLS_LLVMC2_STRINGSET_H +#define LLVM_TOOLS_LLVMC2_STRINGSET_H + +#include "llvm/ADT/StringMap.h" + +#include <cassert> + +namespace llvmc { + + /// StringSet - A wrapper for StringMap that provides set-like + /// functionality. Only insert() and count() methods are used by my + /// code. + template <class AllocatorTy = llvm::MallocAllocator> + class StringSet : public llvm::StringMap<char, AllocatorTy> { + typedef llvm::StringMap<char, AllocatorTy> base; + public: + void insert (const std::string& InLang) { + assert(!InLang.empty()); + const char* KeyStart = &InLang[0]; + const char* KeyEnd = KeyStart + InLang.size(); + base::insert(llvm::StringMapEntry<char>:: + Create(KeyStart, KeyEnd, base::getAllocator(), '+')); + } + }; +} + +#endif //LLVM_TOOLS_LLVMC2_STRINGSET_H diff --git a/tools/llvmc2/Tool.h b/tools/llvmc2/Tool.h index bfa7e46..3527817 100644 --- a/tools/llvmc2/Tool.h +++ b/tools/llvmc2/Tool.h @@ -15,6 +15,7 @@ #define LLVM_TOOLS_LLVMC2_TOOL_H #include "Action.h" +#include "StringSet.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" #include "llvm/System/Path.h" @@ -33,10 +34,12 @@ namespace llvmc { virtual ~Tool() {} virtual Action GenerateAction (const PathVector& inFiles, - const llvm::sys::Path& outFile) const = 0; + const llvm::sys::Path& outFile, + const StringSet<>& InLangs) const = 0; virtual Action GenerateAction (const llvm::sys::Path& inFile, - const llvm::sys::Path& outFile) const = 0; + const llvm::sys::Path& outFile, + const StringSet<>& InLangs) const = 0; virtual const char* Name() const = 0; virtual const char* InputLanguage() const = 0; @@ -54,8 +57,10 @@ namespace llvmc { void ClearJoinList() { JoinList_.clear(); } bool JoinListEmpty() const { return JoinList_.empty(); } - Action GenerateAction(const llvm::sys::Path& outFile) const - { return GenerateAction(JoinList_, outFile); } + Action GenerateAction(const llvm::sys::Path& outFile, + const StringSet<>& InLangs) const { + return GenerateAction(JoinList_, outFile, InLangs); + } // We shouldn't shadow base class's version of GenerateAction. using Tool::GenerateAction; diff --git a/tools/llvmc2/Tools.td b/tools/llvmc2/Tools.td index 5a614cf..63b713f 100644 --- a/tools/llvmc2/Tools.td +++ b/tools/llvmc2/Tools.td @@ -25,8 +25,15 @@ def llvm_gcc_c : Tool< [(in_language "c"), (out_language "llvm-bitcode"), (output_suffix "bc"), - (cmd_line "llvm-gcc -c -x c $INFILE -o $OUTFILE -emit-llvm"), + (cmd_line (case + (switch_on "E"), + "llvm-g++ -E -x c $INFILE -o $OUTFILE -emit-llvm", + (default), + "llvm-g++ -c -x c $INFILE -o $OUTFILE -emit-llvm")), + // TOFIX: Preprocessed files currently have suffix ".bc". (switch_option "E", (stop_compilation), + // Make this possible: + // (output_suffix "i"), (help "Stop after the preprocessing stage, do not run the compiler")), (sink) ]>; @@ -35,7 +42,11 @@ def llvm_gcc_cpp : Tool< [(in_language "c++"), (out_language "llvm-bitcode"), (output_suffix "bc"), - (cmd_line "llvm-g++ -c -x c++ $INFILE -o $OUTFILE -emit-llvm"), + (cmd_line (case + (switch_on "E"), + "llvm-g++ -E -x c++ $INFILE -o $OUTFILE -emit-llvm", + (default), + "llvm-g++ -c -x c++ $INFILE -o $OUTFILE -emit-llvm")), (switch_option "E", (stop_compilation)), (sink) ]>; |