@@ -658,46 +658,11 @@ class RustAssemblyAnnotationWriter : public AssemblyAnnotationWriter {
658
658
}
659
659
};
660
660
661
- class RustPrintModulePass : public ModulePass {
662
- raw_ostream* OS;
663
- DemangleFn Demangle;
664
- public:
665
- static char ID;
666
- RustPrintModulePass () : ModulePass(ID), OS(nullptr ), Demangle(nullptr ) {}
667
- RustPrintModulePass (raw_ostream &OS, DemangleFn Demangle)
668
- : ModulePass(ID), OS(&OS), Demangle(Demangle) {}
669
-
670
- bool runOnModule (Module &M) override {
671
- RustAssemblyAnnotationWriter AW (Demangle);
672
-
673
- M.print (*OS, &AW, false );
674
-
675
- return false ;
676
- }
677
-
678
- void getAnalysisUsage (AnalysisUsage &AU) const override {
679
- AU.setPreservesAll ();
680
- }
681
-
682
- static StringRef name () { return " RustPrintModulePass" ; }
683
- };
684
-
685
661
} // namespace
686
662
687
- namespace llvm {
688
- void initializeRustPrintModulePassPass (PassRegistry&);
689
- }
690
-
691
- char RustPrintModulePass::ID = 0 ;
692
- INITIALIZE_PASS (RustPrintModulePass, " print-rust-module" ,
693
- " Print rust module to stderr" , false , false )
694
-
695
663
extern " C" LLVMRustResult
696
- LLVMRustPrintModule(LLVMPassManagerRef PMR, LLVMModuleRef M,
697
- const char *Path, DemangleFn Demangle) {
698
- llvm::legacy::PassManager *PM = unwrap<llvm::legacy::PassManager>(PMR);
664
+ LLVMRustPrintModule (LLVMModuleRef M, const char *Path, DemangleFn Demangle) {
699
665
std::string ErrorInfo;
700
-
701
666
std::error_code EC;
702
667
raw_fd_ostream OS (Path, EC, sys::fs::F_None);
703
668
if (EC)
@@ -707,11 +672,9 @@ LLVMRustPrintModule(LLVMPassManagerRef PMR, LLVMModuleRef M,
707
672
return LLVMRustResult::Failure;
708
673
}
709
674
675
+ RustAssemblyAnnotationWriter AAW (Demangle);
710
676
formatted_raw_ostream FOS (OS);
711
-
712
- PM->add (new RustPrintModulePass (FOS, Demangle));
713
-
714
- PM->run (*unwrap (M));
677
+ unwrap (M)->print (FOS, &AAW);
715
678
716
679
return LLVMRustResult::Success;
717
680
}
0 commit comments