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