]> git.proxmox.com Git - rustc.git/blob - src/rustllvm/PassWrapper.cpp
Merge tag 'debian/0.7-0_exp1'
[rustc.git] / src / rustllvm / PassWrapper.cpp
1 // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #include "rustllvm.h"
12
13 using namespace llvm;
14
15 // Pass conversion fns
16 typedef struct LLVMOpaquePass *LLVMPassRef;
17
18 inline Pass *unwrap(LLVMPassRef P) {
19 return reinterpret_cast<Pass*>(P);
20 }
21
22 inline LLVMPassRef wrap(const Pass *P) {
23 return reinterpret_cast<LLVMPassRef>(const_cast<Pass*>(P));
24 }
25
26 template<typename T>
27 inline T *unwrap(LLVMPassRef P) {
28 T *Q = (T*)unwrap(P);
29 assert(Q && "Invalid cast!");
30 return Q;
31 }
32
33 extern "C" void LLVMInitializePasses() {
34 PassRegistry &Registry = *PassRegistry::getPassRegistry();
35 initializeCore(Registry);
36 initializeCodeGen(Registry);
37 initializeScalarOpts(Registry);
38 initializeVectorization(Registry);
39 initializeIPO(Registry);
40 initializeAnalysis(Registry);
41 initializeIPA(Registry);
42 initializeTransformUtils(Registry);
43 initializeInstCombine(Registry);
44 initializeInstrumentation(Registry);
45 initializeTarget(Registry);
46 }
47
48 extern "C" void LLVMAddPass(LLVMPassManagerRef PM, LLVMPassRef P) {
49 PassManagerBase * pm = unwrap(PM);
50 Pass * p = unwrap(P);
51
52 pm->add(p);
53 }
54
55 extern "C" LLVMPassRef LLVMCreatePass(const char * PassName) {
56 StringRef SR(PassName);
57 PassRegistry * PR = PassRegistry::getPassRegistry();
58
59 const PassInfo * PI = PR->getPassInfo(SR);
60 if (PI) {
61 return wrap(PI->createPass());
62 } else {
63 return (LLVMPassRef)0;
64 }
65 }
66
67 extern "C" void LLVMDestroyPass(LLVMPassRef PassRef) {
68 Pass *p = unwrap(PassRef);
69 delete p;
70 }