about summary refs log tree commit diff
path: root/src/rustllvm/PassWrapper.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/rustllvm/PassWrapper.cpp')
-rw-r--r--src/rustllvm/PassWrapper.cpp36
1 files changed, 30 insertions, 6 deletions
diff --git a/src/rustllvm/PassWrapper.cpp b/src/rustllvm/PassWrapper.cpp
index 30096677aa4..d6985719acb 100644
--- a/src/rustllvm/PassWrapper.cpp
+++ b/src/rustllvm/PassWrapper.cpp
@@ -58,19 +58,43 @@ LLVMInitializePasses() {
   initializeTarget(Registry);
 }
 
-extern "C" bool
-LLVMRustAddPass(LLVMPassManagerRef PM, const char *PassName) {
-    PassManagerBase *pm = unwrap(PM);
 
+enum class SupportedPassKind {
+  Function,
+  Module,
+  Unsupported
+};
+
+extern "C" Pass*
+LLVMRustFindAndCreatePass(const char *PassName) {
     StringRef SR(PassName);
     PassRegistry *PR = PassRegistry::getPassRegistry();
 
     const PassInfo *PI = PR->getPassInfo(SR);
     if (PI) {
-        pm->add(PI->createPass());
-        return true;
+        return PI->createPass();
     }
-    return false;
+    return NULL;
+}
+
+extern "C" SupportedPassKind
+LLVMRustPassKind(Pass *pass) {
+    assert(pass);
+    PassKind passKind = pass->getPassKind();
+    if (passKind == PT_Module) {
+        return SupportedPassKind::Module;
+    } else if (passKind == PT_Function) {
+        return SupportedPassKind::Function;
+    } else {
+        return SupportedPassKind::Unsupported;
+    }
+}
+
+extern "C" void
+LLVMRustAddPass(LLVMPassManagerRef PM, Pass *pass) {
+    assert(pass);
+    PassManagerBase *pm = unwrap(PM);
+    pm->add(pass);
 }
 
 extern "C" LLVMTargetMachineRef