[PM] Add an enum for describing the desired output strategy, and run
[oota-llvm.git] / tools / opt / NewPMDriver.cpp
1 //===- NewPMDriver.cpp - Driver for opt with new PM -----------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 /// \file
10 ///
11 /// This file is just a split of the code that logically belongs in opt.cpp but
12 /// that includes the new pass manager headers.
13 ///
14 //===----------------------------------------------------------------------===//
15
16 #include "NewPMDriver.h"
17 #include "Passes.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/IR/LLVMContext.h"
20 #include "llvm/IR/Module.h"
21 #include "llvm/IR/PassManager.h"
22 #include "llvm/Support/CommandLine.h"
23 #include "llvm/Support/ToolOutputFile.h"
24
25 using namespace llvm;
26 using namespace opt_tool;
27
28 bool llvm::runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M,
29                            tool_output_file *Out, StringRef PassPipeline,
30                            OutputKind OK) {
31   // Before executing passes, print the final values of the LLVM options.
32   cl::PrintOptionValues();
33
34   ModulePassManager MPM;
35   if (!parsePassPipeline(MPM, PassPipeline)) {
36     errs() << Arg0 << ": unable to parse pass pipeline description.\n";
37     return false;
38   }
39
40   // Now that we have all of the passes ready, run them.
41   MPM.run(&M);
42
43   // Declare success.
44   if (OK != OK_NoOutput)
45     Out->keep();
46   return true;
47 }