1 //===--- Tools.h - The LLVM Compiler Driver ---------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open
6 // Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Action class - implementation and auxiliary functions.
12 //===----------------------------------------------------------------------===//
16 #include "llvm/Support/CommandLine.h"
17 #include "llvm/System/Program.h"
24 extern cl::opt<bool> VerboseMode;
27 int ExecuteProgram(const std::string& name,
28 const std::vector<std::string>& args) {
29 sys::Path prog = sys::Program::FindProgramByName(name);
32 throw std::runtime_error("Can't find program '" + name + "'");
33 if (!prog.canExecute())
34 throw std::runtime_error("Program '" + name + "' is not executable.");
37 std::vector<const char*> argv((args.size()+2));
38 argv[0] = name.c_str();
39 for (unsigned i = 1; i <= args.size(); ++i)
40 argv[i] = args[i-1].c_str();
41 argv[args.size()+1] = 0; // null terminate list.
43 return sys::Program::ExecuteAndWait(prog, &argv[0]);
46 void print_string (const std::string& str) {
47 std::cerr << str << ' ';
51 int llvmcc::Action::Execute() const {
53 std::cerr << Command_ << " ";
54 std::for_each(Args_.begin(), Args_.end(), print_string);
57 return ExecuteProgram(Command_, Args_);