llvm.org GIT mirror llvm / be9d9a1
Add output redirection, rename namespace llvmcc to namespace llvmc. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50746 91177308-0d34-0410-b5e6-96231b3b80d8 Mikhail Glushenkov 11 years ago
10 changed file(s) with 52 addition(s) and 32 deletion(s). Raw diff Collapse all Expand all
1919 #include
2020
2121 using namespace llvm;
22 using namespace llvmc;
2223
2324 extern cl::opt VerboseMode;
2425
2526 namespace {
2627 int ExecuteProgram(const std::string& name,
27 const std::vector& args) {
28 const StringVector& args) {
2829 sys::Path prog = sys::Program::FindProgramByName(name);
2930
3031 if (prog.isEmpty())
3233 if (!prog.canExecute())
3334 throw std::runtime_error("Program '" + name + "' is not executable.");
3435
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.
36 const sys::Path* redirects[3] = {0,0,0};
37 sys::Path stdout_redirect;
4138
42 return sys::Program::ExecuteAndWait(prog, &argv[0]);
39 std::vector argv;
40 argv.reserve((args.size()+2));
41 argv.push_back(name.c_str());
42
43 for (StringVector::const_iterator B = args.begin(), E = args.end();
44 B!=E; ++B) {
45 if (*B == ">") {
46 ++B;
47 stdout_redirect.set(*B);
48 redirects[1] = &stdout_redirect;
49 }
50 else {
51 argv.push_back((*B).c_str());
52 }
53 }
54 argv.push_back(0); // null terminate list.
55
56 return sys::Program::ExecuteAndWait(prog, &argv[0], 0, &redirects[0]);
4357 }
4458
4559 void print_string (const std::string& str) {
4761 }
4862 }
4963
50 int llvmcc::Action::Execute() const {
64 int llvmc::Action::Execute() const {
5165 if (VerboseMode) {
5266 std::cerr << Command_ << " ";
5367 std::for_each(Args_.begin(), Args_.end(), print_string);
1616 #include
1717 #include
1818
19 namespace llvmcc {
19 namespace llvmc {
20
21 typedef std::vector StringVector;
2022
2123 class Action {
2224 std::string Command_;
2325 std::vector Args_;
2426 public:
25 Action (std::string const& C,
26 std::vector const& A)
27 Action (const std::string& C,
28 const StringVector& A)
2729 : Command_(C), Args_(A)
2830 {}
2931
1919 #include
2020
2121 using namespace llvm;
22 using namespace llvmcc;
22 using namespace llvmc;
2323
2424 // The auto-generated file
2525 #include "AutoGenerated.inc"
1717
1818 #include
1919
20 namespace llvmcc {
20 namespace llvmc {
2121
2222 typedef llvm::StringMap LanguageMap;
2323 class CompilationGraph;
2323 #include
2424
2525 using namespace llvm;
26 using namespace llvmcc;
26 using namespace llvmc;
2727
2828 extern cl::list InputFilenames;
2929 extern cl::opt OutputFilename;
214214 return &getNode(ChooseEdge(TV)->ToolName());
215215 }
216216
217 // TOFIX: merge some parts with PassThroughGraph.
218 // Build the targets. Command-line options are passed through
219 // temporary variables.
217220 int CompilationGraph::Build (const sys::Path& TempDir) {
218221
219222 // For each input file:
233236 // For all join nodes in topological order:
234237 for (std::vector::iterator B = JTV.begin(), E = JTV.end();
235238 B != E; ++B) {
236 // TOFIX: more testing, merge some parts with PassThroughGraph.
239
237240 sys::Path Out;
238241 const Node* CurNode = *B;
239242 JoinTool* JT = &dynamic_cast(*CurNode->ToolPtr.getPtr());
240243 bool IsLast = false;
241244
245 // Has files pending?
242246 if (JT->JoinListEmpty())
243247 continue;
244248
276280
277281 namespace llvm {
278282 template <>
279 struct DOTGraphTraitsc::CompilationGraph*>
283 struct DOTGraphTraits::CompilationGraph*>
280284 : public DefaultDOTGraphTraits
281285 {
282286
2525
2626 #include
2727
28 namespace llvmcc {
28 namespace llvmc {
2929
3030 // An edge in the graph.
3131 class Edge : public llvm::RefCountedBaseVPTR {
254254
255255 namespace llvm {
256256 template <>
257 struct GraphTraits {
258 typedef llvmcc::CompilationGraph GraphType;
259 typedef llvmcc::Node NodeType;
260 typedef llvmcc::NodeChildIterator ChildIteratorType;
257 struct GraphTraits {
258 typedef llvmc::CompilationGraph GraphType;
259 typedef llvmc::Node NodeType;
260 typedef llvmc::NodeChildIterator ChildIteratorType;
261261
262262 static NodeType* getEntryNode(GraphType* G) {
263263 return &G->getNode("root");
270270 return ChildIteratorType(N, N->OutEdges.end());
271271 }
272272
273 typedef llvmcc::NodesIterator nodes_iterator;
273 typedef llvmc::NodesIterator nodes_iterator;
274274 static nodes_iterator nodes_begin(GraphType *G) {
275275 return GraphBegin(G);
276276 }
1414
1515 #include "llvm/ADT/StringExtras.h"
1616
17 void llvmcc::Tool::UnpackValues (const std::string& from,
17 void llvmc::Tool::UnpackValues (const std::string& from,
1818 std::vector& to) {
1919 llvm::SplitString(from, to, ",");
2020 }
2121 #include
2222 #include
2323
24 namespace llvmcc {
24 namespace llvmc {
2525
2626 typedef std::vector PathVector;
2727
None //===--- llvmcc.cpp - The LLVM Compiler Driver ------------------*- C++ -*-===//
0 //===--- llvmc.cpp - The LLVM Compiler Driver ------------------*- C++ -*-===//
11 //
22 // The LLVM Compiler Infrastructure
33 //
2525
2626 namespace cl = llvm::cl;
2727 namespace sys = llvm::sys;
28 using namespace llvmcc;
28 using namespace llvmc;
2929
3030 // Built-in command-line options.
3131 // External linkage here is intentional.
None //===- LLVMCConfigurationEmitter.cpp - Generate LLVMCC config -------------===//
0 //===- LLVMCConfigurationEmitter.cpp - Generate LLVMC config --------------===//
11 //
22 // The LLVM Compiler Infrastructure
33 //
66 //
77 //===----------------------------------------------------------------------===//
88 //
9 // This tablegen backend is responsible for emitting LLVMCC configuration code.
9 // This tablegen backend is responsible for emitting LLVMC configuration code.
1010 //
1111 //===----------------------------------------------------------------------===//
1212
847847 throw std::string("Error in the language map definition!");
848848
849849 // Generate code
850 O << "void llvmcc::PopulateLanguageMap(LanguageMap& language_map) {\n";
850 O << "void llvmc::PopulateLanguageMap(LanguageMap& language_map) {\n";
851851
852852 for (unsigned i = 0; i < LangsToSuffixesList->size(); ++i) {
853853 Record* LangToSuffixes = LangsToSuffixesList->getElementAsRecord(i);
10391039 ListInit* edges = CompilationGraph->getValueAsListInit("edges");
10401040
10411041 // Generate code
1042 O << "void llvmcc::PopulateCompilationGraph(CompilationGraph& G) {\n"
1042 O << "void llvmc::PopulateCompilationGraph(CompilationGraph& G) {\n"
10431043 << Indent1 << "PopulateLanguageMap(G.ExtsToLangs);\n\n";
10441044
10451045 // Insert vertices
10841084 // Back-end entry point
10851085 void LLVMCCConfigurationEmitter::run (std::ostream &O) {
10861086 // Emit file header
1087 EmitSourceFileHeader("LLVMCC Configuration Library", O);
1087 EmitSourceFileHeader("LLVMC Configuration Library", O);
10881088
10891089 // Get a list of all defined Tools
10901090 RecordVector Tools = Records.getAllDerivedDefinitions("Tool");