Change allowsUnalignedMemoryAccesses to take type argument since some targets
[llvm/avr.git] / lib / CompilerDriver / Action.cpp
blob5fd63eefc523ebb3c0d7e0a2a8048b91d7c960e0
1 //===--- Action.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 // Action class - implementation and auxiliary functions.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/CompilerDriver/Action.h"
15 #include "llvm/CompilerDriver/BuiltinOptions.h"
16 #include "llvm/Support/raw_ostream.h"
17 #include "llvm/System/Program.h"
18 #include <stdexcept>
20 using namespace llvm;
21 using namespace llvmc;
23 namespace {
24 int ExecuteProgram(const std::string& name,
25 const StrVector& args) {
26 sys::Path prog = sys::Program::FindProgramByName(name);
28 if (prog.isEmpty())
29 throw std::runtime_error("Can't find program '" + name + "'");
30 if (!prog.canExecute())
31 throw std::runtime_error("Program '" + name + "' is not executable.");
33 // Build the command line vector and the redirects array.
34 const sys::Path* redirects[3] = {0,0,0};
35 sys::Path stdout_redirect;
37 std::vector<const char*> argv;
38 argv.reserve((args.size()+2));
39 argv.push_back(name.c_str());
41 for (StrVector::const_iterator B = args.begin(), E = args.end();
42 B!=E; ++B) {
43 if (*B == ">") {
44 ++B;
45 stdout_redirect.set(*B);
46 redirects[1] = &stdout_redirect;
48 else {
49 argv.push_back((*B).c_str());
52 argv.push_back(0); // null terminate list.
54 // Invoke the program.
55 return sys::Program::ExecuteAndWait(prog, &argv[0], 0, &redirects[0]);
58 void print_string (const std::string& str) {
59 errs() << str << ' ';
63 int llvmc::Action::Execute() const {
64 if (DryRun || VerboseMode) {
65 errs() << Command_ << " ";
66 std::for_each(Args_.begin(), Args_.end(), print_string);
67 errs() << '\n';
69 if (DryRun)
70 return 0;
71 else
72 return ExecuteProgram(Command_, Args_);