blob: c53578ad44bbe65e56bc58f8678a34447a776608 [file] [log] [blame]
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +00001//===--- Utility.cpp - The LLVM Compiler Driver -----------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open
6// Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// Various helper and utility functions - implementation.
11//
12//===----------------------------------------------------------------------===//
13
14#include "Utility.h"
15
16#include "llvm/System/Program.h"
17
18#include <stdexcept>
19
20using namespace llvm;
21
22int llvmcc::ExecuteProgram(const std::string& name,
23 const std::vector<std::string>& args) {
24 sys::Path prog = sys::Program::FindProgramByName(name);
25
26 if (prog.isEmpty())
27 throw std::runtime_error("Can't find program '" + name + "'");
28 if (!prog.canExecute())
29 throw std::runtime_error("Program '" + name + "' is not executable.");
30
31 // Invoke the program
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.
37
38 return sys::Program::ExecuteAndWait(prog, &argv[0]);
39}