llvm.org GIT mirror llvm / b90cd83
Code reorg git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50722 91177308-0d34-0410-b5e6-96231b3b80d8 Mikhail Glushenkov 11 years ago
18 changed file(s) with 429 addition(s) and 396 deletion(s). Raw diff Collapse all Expand all
0 //===--- Tools.h - The LLVM Compiler Driver ---------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open
5 // Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Action class - implementation and auxiliary functions.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "Action.h"
14
15 #include "llvm/Support/CommandLine.h"
16 #include "llvm/System/Program.h"
17
18 #include
19 #include
20
21 using namespace llvm;
22
23 extern cl::opt VerboseMode;
24
25 namespace {
26 int ExecuteProgram(const std::string& name,
27 const std::vector& args) {
28 sys::Path prog = sys::Program::FindProgramByName(name);
29
30 if (prog.isEmpty())
31 throw std::runtime_error("Can't find program '" + name + "'");
32 if (!prog.canExecute())
33 throw std::runtime_error("Program '" + name + "' is not executable.");
34
35 // Invoke the program
36 std::vector argv((args.size()+2));
37 argv[0] = name.c_str();
38 for (unsigned i = 1; i <= args.size(); ++i)
39 argv[i] = args[i-1].c_str();
40 argv[args.size()+1] = 0; // null terminate list.
41
42 return sys::Program::ExecuteAndWait(prog, &argv[0]);
43 }
44
45 void print_string (const std::string& str) {
46 std::cerr << str << ' ';
47 }
48 }
49
50 int llvmcc::Action::Execute() {
51 if (VerboseMode) {
52 std::cerr << Command_ << " ";
53 std::for_each(Args_.begin(), Args_.end(), print_string);
54 std::cerr << '\n';
55 }
56 return ExecuteProgram(Command_, Args_);
57 }
0 //===--- Tools.h - The LLVM Compiler Driver ---------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open
5 // Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Action - encapsulates a single shell command.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_TOOLS_LLVMC2_ACTION_H
14 #define LLVM_TOOLS_LLVMC2_ACTION_H
15
16 #include
17 #include
18
19 namespace llvmcc {
20
21 class Action {
22 std::string Command_;
23 std::vector Args_;
24 public:
25 Action (std::string const& C,
26 std::vector const& A)
27 : Command_(C), Args_(A)
28 {}
29
30 int Execute();
31 };
32
33 }
34
35 #endif // LLVM_TOOLS_LLVMC2_ACTION_H
0 //===--- Tools.cpp - The LLVM Compiler Driver -------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open
5 // Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Auto-generated tool descriptions - implementation.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "AutoGenerated.h"
14 #include "CompilationGraph.h"
15 #include "Tool.h"
16
17 #include "llvm/Support/CommandLine.h"
18
19 #include
20
21 using namespace llvm;
22 using namespace llvmcc;
23
24 // The auto-generated file
25 #include "AutoGenerated.inc"
0 //===--- Tools.cpp - The LLVM Compiler Driver -------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open
5 // Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Auto-generated tool descriptions - public interface.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_TOOLS_LLVMC2_AUTOGENERATED_H
14 #define LLVM_TOOLS_LLVMC2_AUTOGENERATED_H
15
16 #include "llvm/ADT/StringMap.h"
17
18 #include
19
20 namespace llvmcc {
21
22 typedef llvm::StringMap LanguageMap;
23 class CompilationGraph;
24
25 void PopulateLanguageMap(LanguageMap& language_map);
26 void PopulateCompilationGraph(CompilationGraph& tools);
27 }
28
29 #endif // LLVM_TOOLS_LLVMC2_AUTOGENERATED_H
0 //===--- CompilationGraph.cpp - The LLVM Compiler Driver --------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open
5 // Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Compilation graph - implementation.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "CompilationGraph.h"
14
15 #include "llvm/Support/CommandLine.h"
16 #include "llvm/ADT/STLExtras.h"
17
18 #include
19
20 using namespace llvm;
21
22 extern cl::list InputFilenames;
23 extern cl::opt OutputFilename;
24
25 int llvmcc::CompilationGraph::Build (const sys::Path& tempDir) const {
26 sys::Path In(InputFilenames.at(0)), Out;
27
28 // Find out which language corresponds to the suffix of the first input file
29 LanguageMap::const_iterator Lang = ExtsToLangs.find(In.getSuffix());
30 if (Lang == ExtsToLangs.end())
31 throw std::runtime_error("Unknown suffix!");
32
33 // Find the toolchain corresponding to this language
34 ToolChainMap::const_iterator ToolsIt = ToolChains.find(Lang->second);
35 if (ToolsIt == ToolChains.end())
36 throw std::runtime_error("Unknown language!");
37 ToolChain Tools = ToolsIt->second;
38
39 PathVector JoinList;
40
41 for (cl::list::const_iterator B = InputFilenames.begin(),
42 E = InputFilenames.end(); B != E; ++B) {
43 In = sys::Path(*B);
44
45 // Pass input file through the toolchain
46 for (ToolChain::const_iterator B = Tools.begin(), E = Tools.end();
47 B != E; ++B) {
48
49 const Tool* CurTool = B->getPtr();
50
51 // Is this the last step in the chain?
52 if (llvm::next(B) == E || CurTool->IsLast()) {
53 JoinList.push_back(In);
54 break;
55 }
56 else {
57 Out = tempDir;
58 Out.appendComponent(In.getBasename());
59 Out.appendSuffix(CurTool->OutputSuffix());
60 Out.makeUnique(true, NULL);
61 Out.eraseFromDisk();
62 }
63
64 if (CurTool->GenerateAction(In, Out).Execute() != 0)
65 throw std::runtime_error("Tool returned error code!");
66
67 In = Out; Out.clear();
68 }
69 }
70
71 // Pass .o files to linker
72 const Tool* JoinNode = (--Tools.end())->getPtr();
73
74 // If the final output name is empty, set it to "a.out"
75 if (!OutputFilename.empty()) {
76 Out = sys::Path(OutputFilename);
77 }
78 else {
79 Out = sys::Path("a");
80 Out.appendSuffix(JoinNode->OutputSuffix());
81 }
82
83 if (JoinNode->GenerateAction(JoinList, Out).Execute() != 0)
84 throw std::runtime_error("Tool returned error code!");
85
86 return 0;
87 }
0 //===--- CompilationGraph.h - The LLVM Compiler Driver ----------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open
5 // Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Compilation graph - definition.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_TOOLS_LLVMC2_COMPILATION_GRAPH_H
14 #define LLVM_TOOLS_LLVMC2_COMPILATION_GRAPH_H
15
16 #include "AutoGenerated.h"
17 #include "Tool.h"
18
19 #include "llvm/ADT/StringMap.h"
20 #include "llvm/System/Path.h"
21
22 namespace llvmcc {
23
24 typedef std::vector > ToolChain;
25 typedef llvm::StringMap ToolChainMap;
26
27 struct CompilationGraph {
28 ToolChainMap ToolChains;
29 LanguageMap ExtsToLangs;
30
31 int Build(llvm::sys::Path const& tempDir) const;
32 };
33 }
34
35 #endif // LLVM_TOOLS_LLVMC2_COMPILATION_GRAPH_H
+0
-115
tools/llvmc2/Core.cpp less more
None //===--- Core.cpp - The LLVM Compiler Driver --------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open
5 // Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Core driver abstractions.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "Core.h"
14 #include "Utility.h"
15
16 #include "llvm/ADT/STLExtras.h"
17 #include "llvm/ADT/StringExtras.h"
18 #include "llvm/Support/CommandLine.h"
19
20 #include
21 #include
22 #include
23
24 using namespace llvm;
25 using namespace llvmcc;
26
27 extern cl::list InputFilenames;
28 extern cl::opt OutputFilename;
29 extern cl::opt VerboseMode;
30
31 namespace {
32 void print_string (const std::string& str) {
33 std::cerr << str << ' ';
34 }
35 }
36
37 int llvmcc::Action::Execute() {
38 if (VerboseMode) {
39 std::cerr << Command_ << " ";
40 std::for_each(Args_.begin(), Args_.end(), print_string);
41 std::cerr << '\n';
42 }
43 return ExecuteProgram(Command_, Args_);
44 }
45
46 int llvmcc::CompilationGraph::Build (const sys::Path& tempDir) const {
47 sys::Path In(InputFilenames.at(0)), Out;
48
49 // Find out which language corresponds to the suffix of the first input file
50 LanguageMap::const_iterator Lang = ExtsToLangs.find(In.getSuffix());
51 if (Lang == ExtsToLangs.end())
52 throw std::runtime_error("Unknown suffix!");
53
54 // Find the toolchain corresponding to this language
55 ToolChainMap::const_iterator ToolsIt = ToolChains.find(Lang->second);
56 if (ToolsIt == ToolChains.end())
57 throw std::runtime_error("Unknown language!");
58 ToolChain Tools = ToolsIt->second;
59
60 PathVector JoinList;
61
62 for (cl::list::const_iterator B = InputFilenames.begin(),
63 E = InputFilenames.end(); B != E; ++B) {
64 In = sys::Path(*B);
65
66 // Pass input file through the toolchain
67 for (ToolChain::const_iterator B = Tools.begin(), E = Tools.end();
68 B != E; ++B) {
69
70 const Tool* CurTool = B->getPtr();
71
72 // Is this the last step in the chain?
73 if (llvm::next(B) == E || CurTool->IsLast()) {
74 JoinList.push_back(In);
75 break;
76 }
77 else {
78 Out = tempDir;
79 Out.appendComponent(In.getBasename());
80 Out.appendSuffix(CurTool->OutputSuffix());
81 Out.makeUnique(true, NULL);
82 Out.eraseFromDisk();
83 }
84
85 if (CurTool->GenerateAction(In, Out).Execute() != 0)
86 throw std::runtime_error("Tool returned error code!");
87
88 In = Out; Out.clear();
89 }
90 }
91
92 // Pass .o files to linker
93 const Tool* JoinNode = (--Tools.end())->getPtr();
94
95 // If the final output name is empty, set it to "a.out"
96 if (!OutputFilename.empty()) {
97 Out = sys::Path(OutputFilename);
98 }
99 else {
100 Out = sys::Path("a");
101 Out.appendSuffix(JoinNode->OutputSuffix());
102 }
103
104 if (JoinNode->GenerateAction(JoinList, Out).Execute() != 0)
105 throw std::runtime_error("Tool returned error code!");
106
107 return 0;
108 }
109
110 void llvmcc::Tool::UnpackValues (const std::string& from,
111 std::vector& to) const {
112 SplitString(from, to, ",");
113 }
114
+0
-83
tools/llvmc2/Core.h less more
None //===--- Core.h - The LLVM Compiler Driver ----------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open
5 // Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Core driver abstractions.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_TOOLS_LLVMCC_CORE_H
14 #define LLVM_TOOLS_LLVMCC_CORE_H
15
16 #include "Utility.h"
17
18 #include "llvm/ADT/IntrusiveRefCntPtr.h"
19 #include "llvm/ADT/StringMap.h"
20 #include "llvm/System/Path.h"
21
22 #include
23 #include
24 #include
25
26 // Core functionality
27
28 namespace llvmcc {
29
30 typedef std::vector PathVector;
31 typedef llvm::StringMap LanguageMap;
32
33 class Action {
34 std::string Command_;
35 std::vector Args_;
36 public:
37 Action (std::string const& C,
38 std::vector const& A)
39 : Command_(C), Args_(A)
40 {}
41
42 int Execute();
43 };
44
45 class Tool : public llvm::RefCountedBaseVPTR {
46 public:
47 virtual Action GenerateAction (PathVector const& inFiles,
48 llvm::sys::Path const& outFile) const = 0;
49
50 virtual Action GenerateAction (llvm::sys::Path const& inFile,
51 llvm::sys::Path const& outFile) const = 0;
52
53 virtual std::string Name() const = 0;
54 virtual std::string InputLanguage() const = 0;
55 virtual std::string OutputLanguage() const = 0;
56 virtual std::string OutputSuffix() const = 0;
57
58 virtual bool IsLast() const = 0;
59 virtual bool IsJoin() const = 0;
60
61 // Helper function that is called by the auto-generated code
62 // Splits strings of the form ",-foo,-bar,-baz"
63 // TOFIX: find a better name
64 void UnpackValues (std::string const& from,
65 std::vector& to) const;
66
67 virtual ~Tool()
68 {}
69 };
70
71 typedef std::vector > ToolChain;
72 typedef llvm::StringMap ToolChainMap;
73
74 struct CompilationGraph {
75 ToolChainMap ToolChains;
76 LanguageMap ExtsToLangs;
77
78 int Build(llvm::sys::Path const& tempDir) const;
79 };
80 }
81
82 #endif // LLVM_TOOLS_LLVMCC_CORE_H
77 ##===----------------------------------------------------------------------===##
88 LEVEL = ../..
99 TOOLNAME = llvmc2
10 BUILT_SOURCES = Tools.inc
10 BUILT_SOURCES = AutoGenerated.inc
1111 LINK_COMPONENTS = support system
1212 REQUIRES_EH := 1
1313
2222
2323 # TOFIX: integrate this part into Makefile.rules?
2424 # The degree of horrorshowness in that file is too much for me atm.
25 $(ObjDir)/Tools.inc.tmp: $(TOOLS_SOURCE) $(ObjDir)/.dir
25 $(ObjDir)/AutoGenerated.inc.tmp: $(TOOLS_SOURCE) $(ObjDir)/.dir
2626 $(Echo) "Building LLVMCC configuration library with tblgen"
2727 $(Verb) $(TableGen) -gen-llvmcc -o $(call SYSPATH, $@) $<
2828
29 Tools.inc : $(ObjDir)/Tools.inc.tmp
29 AutoGenerated.inc : $(ObjDir)/AutoGenerated.inc.tmp
3030 $(Verb) $(CMP) -s $@ $< || $(CP) $< $@
3131
0 //===--- Tools.cpp - The LLVM Compiler Driver -------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open
5 // Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Tool abstract base class - implementation of the auxiliary functions.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "Tool.h"
14
15 #include "llvm/ADT/StringExtras.h"
16
17 void llvmcc::Tool::UnpackValues (const std::string& from,
18 std::vector& to) {
19 llvm::SplitString(from, to, ",");
20 }
0 //===--- Tools.h - The LLVM Compiler Driver ---------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open
5 // Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Tool abstract base class - an interface to tool descriptions.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_TOOLS_LLVMC2_TOOL_H
14 #define LLVM_TOOLS_LLVMC2_TOOL_H
15
16 #include "Action.h"
17
18 #include "llvm/ADT/IntrusiveRefCntPtr.h"
19 #include "llvm/System/Path.h"
20
21 #include
22 #include
23
24 namespace llvmcc {
25
26 typedef std::vector PathVector;
27
28 class Tool : public llvm::RefCountedBaseVPTR {
29 public:
30 virtual Action GenerateAction (PathVector const& inFiles,
31 llvm::sys::Path const& outFile) const = 0;
32
33 virtual Action GenerateAction (llvm::sys::Path const& inFile,
34 llvm::sys::Path const& outFile) const = 0;
35
36 virtual std::string Name() const = 0;
37 virtual std::string InputLanguage() const = 0;
38 virtual std::string OutputLanguage() const = 0;
39 virtual std::string OutputSuffix() const = 0;
40
41 virtual bool IsLast() const = 0;
42 virtual bool IsJoin() const = 0;
43
44 // Helper function that is called by the auto-generated code
45 // Splits strings of the form ",-foo,-bar,-baz"
46 // TOFIX: find a better name
47 static void UnpackValues (std::string const& from,
48 std::vector& to);
49
50 virtual ~Tool()
51 {}
52 };
53
54 }
55
56 #endif //LLVM_TOOLS_LLVMC2_TOOL_H
+0
-28
tools/llvmc2/Tools.cpp less more
None //===--- Tools.cpp - The LLVM Compiler Driver -------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open
5 // Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Auto-generated tool descriptions.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "Tools.h"
14 #include "Core.h"
15
16 #include "llvm/ADT/IntrusiveRefCntPtr.h"
17 #include "llvm/Support/CommandLine.h"
18
19 #include
20 #include
21 #include
22
23 using namespace llvm;
24 using namespace llvmcc;
25
26 // Include the auto-generated file
27 #include "Tools.inc"
+0
-26
tools/llvmc2/Tools.h less more
None //===--- Tools.h - The LLVM Compiler Driver ---------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open
5 // Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Auto-generated tool descriptions.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_TOOLS_LLVMCC_TOOLS_H
14 #define LLVM_TOOLS_LLVMCC_TOOLS_H
15
16 #include "Core.h"
17
18 namespace llvmcc {
19
20 void PopulateLanguageMap(LanguageMap& language_map);
21 void PopulateCompilationGraph(CompilationGraph& tools);
22
23 }
24
25 #endif //LLVM_TOOLS_LLVMCC_TOOLS_H
+0
-39
tools/llvmc2/Utility.cpp less more
None //===--- Utility.cpp - The LLVM Compiler Driver -----------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open
5 // Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Various helper and utility functions - implementation.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "Utility.h"
14
15 #include "llvm/System/Program.h"
16
17 #include
18
19 using namespace llvm;
20
21 int llvmcc::ExecuteProgram(const std::string& name,
22 const std::vector& args) {
23 sys::Path prog = sys::Program::FindProgramByName(name);
24
25 if (prog.isEmpty())
26 throw std::runtime_error("Can't find program '" + name + "'");
27 if (!prog.canExecute())
28 throw std::runtime_error("Program '" + name + "' is not executable.");
29
30 // Invoke the program
31 std::vector argv((args.size()+2));
32 argv[0] = name.c_str();
33 for (unsigned i = 1; i <= args.size(); ++i)
34 argv[i] = args[i-1].c_str();
35 argv[args.size()+1] = 0; // null terminate list.
36
37 return sys::Program::ExecuteAndWait(prog, &argv[0]);
38 }
+0
-27
tools/llvmc2/Utility.h less more
None //===--- Utility.h - The LLVM Compiler Driver -------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open
5 // Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Various helper and utility functions.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_TOOLS_LLVMCC_UTILITY_H
14 #define LLVM_TOOLS_LLVMCC_UTILITY_H
15
16 #include
17 #include
18
19 namespace llvmcc {
20
21 int ExecuteProgram (const std::string& name,
22 const std::vector& arguments);
23
24 }
25
26 #endif // LLVM_TOOLS_LLVMCC_UTILITY_H
0 //===--- llvmcc.cpp - The LLVM Compiler Driver ------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open
5 // Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This tool provides a single point of access to the LLVM
10 // compilation tools. It has many options. To discover the options
11 // supported please refer to the tools' manual page or run the tool
12 // with the --help option.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #include "CompilationGraph.h"
17 #include "Tool.h"
18
19 #include "llvm/System/Path.h"
20 #include "llvm/Support/CommandLine.h"
21
22 #include
23 #include
24 #include
25
26 namespace cl = llvm::cl;
27 namespace sys = llvm::sys;
28 using namespace llvmcc;
29
30 // External linkage here is intentional.
31 cl::list InputFilenames(cl::Positional,
32 cl::desc(""), cl::OneOrMore);
33 cl::opt OutputFilename("o", cl::desc("Output file name"),
34 cl::value_desc("file"));
35 cl::opt VerboseMode("v", cl::desc("Enable verbose mode"));
36
37
38 namespace {
39 int BuildTargets(const CompilationGraph& graph) {
40 int ret;
41 sys::Path tempDir(sys::Path::GetTemporaryDirectory());
42
43 try {
44 ret = graph.Build(tempDir);
45 }
46 catch(...) {
47 tempDir.eraseFromDisk(true);
48 throw;
49 }
50
51 tempDir.eraseFromDisk(true);
52 return ret;
53 }
54 }
55
56 int main(int argc, char** argv) {
57 try {
58 CompilationGraph graph;
59
60 cl::ParseCommandLineOptions(argc, argv,
61 "LLVM Compiler Driver(Work In Progress)");
62 PopulateCompilationGraph(graph);
63 return BuildTargets(graph);
64 }
65 catch(const std::exception& ex) {
66 std::cerr << ex.what() << '\n';
67 }
68 catch(...) {
69 std::cerr << "Unknown error!\n";
70 }
71 }
+0
-73
tools/llvmc2/llvmcc.cpp less more
None //===--- llvmcc.cpp - The LLVM Compiler Driver ------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open
5 // Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This tool provides a single point of access to the LLVM
10 // compilation tools. It has many options. To discover the options
11 // supported please refer to the tools' manual page or run the tool
12 // with the --help option.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #include "Core.h"
17 #include "Utility.h"
18 #include "Tools.h"
19
20 #include "llvm/System/Path.h"
21 #include "llvm/Support/CommandLine.h"
22
23 #include
24 #include
25 #include
26
27 using namespace llvm;
28 using namespace llvmcc;
29
30 // These variables are also used in Core.cpp,
31 // so they should have external linkage.
32 cl::list InputFilenames(cl::Positional,
33 cl::desc(""), cl::OneOrMore);
34 cl::opt OutputFilename("o", cl::desc("Output file name"),
35 cl::value_desc("file"));
36 cl::opt VerboseMode("v", cl::desc("Enable verbose mode"));
37
38
39 namespace {
40 int BuildTargets(const CompilationGraph& graph) {
41 int ret;
42 sys::Path tempDir(sys::Path::GetTemporaryDirectory());
43
44 try {
45 ret = graph.Build(tempDir);
46 }
47 catch(...) {
48 tempDir.eraseFromDisk(true);
49 throw;
50 }
51
52 tempDir.eraseFromDisk(true);
53 return ret;
54 }
55 }
56
57 int main(int argc, char** argv) {
58 try {
59 CompilationGraph graph;
60
61 cl::ParseCommandLineOptions(argc, argv,
62 "LLVM Compiler Driver(Work In Progress)");
63 PopulateCompilationGraph(graph);
64 return BuildTargets(graph);
65 }
66 catch(const std::exception& ex) {
67 std::cerr << ex.what() << '\n';
68 }
69 catch(...) {
70 std::cerr << "Unknown error!\n";
71 }
72 }
622622 << "::iterator B = " << D.GenVariableName() << ".begin(),\n"
623623 << Indent3 << "E = " << D.GenVariableName()
624624 << ".end(); B != E; ++B)\n"
625 << Indent4 << "UnpackValues(*B, vec);\n";
625 << Indent4 << "Tool::UnpackValues(*B, vec);\n";
626626 }
627627 else if (D.Type == OptionType::Prefix || D.Type == OptionType::Parameter){
628 O << Indent3 << "UnpackValues("
628 O << Indent3 << "Tool::UnpackValues("
629629 << D.GenVariableName() << ", vec);\n";
630630 }
631631 else {