1 //===--- Utility.cpp - 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 // Various helper and utility functions - implementation.
12 //===----------------------------------------------------------------------===//
16 #include "llvm/System/Program.h"
22 int llvmcc::ExecuteProgram(const std::string& name,
23 const std::vector<std::string>& args) {
24 sys::Path prog = sys::Program::FindProgramByName(name);
27 throw std::runtime_error("Can't find program '" + name + "'");
28 if (!prog.canExecute())
29 throw std::runtime_error("Program '" + name + "' is not executable.");
32 std::vector<const char*> argv((args.size()+2));
33 argv[0] = name.c_str();
34 for (unsigned i = 1; i <= args.size(); ++i)
35 argv[i] = args[i-1].c_str();
36 argv[args.size()+1] = 0; // null terminate list.
38 return sys::Program::ExecuteAndWait(prog, &argv[0]);