Auto merge of #66952 - 0dvictor:print, r=rkruppe
Use Module::print() instead of a PrintModulePass llvm::Module has a print() method. It is unnecessary to create a pass just for the purpose of printing LLVM IR.
This commit is contained in:
commit
1e2a73867d
3 changed files with 9 additions and 50 deletions
|
@ -588,14 +588,11 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext<LlvmCodegenBackend>,
|
||||||
cursor.position() as size_t
|
cursor.position() as size_t
|
||||||
}
|
}
|
||||||
|
|
||||||
with_codegen(tm, llmod, config.no_builtins, |cpm| {
|
|
||||||
let result =
|
let result =
|
||||||
llvm::LLVMRustPrintModule(cpm, llmod, out_c.as_ptr(), demangle_callback);
|
llvm::LLVMRustPrintModule(llmod, out_c.as_ptr(), demangle_callback);
|
||||||
llvm::LLVMDisposePassManager(cpm);
|
|
||||||
result.into_result().map_err(|()| {
|
result.into_result().map_err(|()| {
|
||||||
let msg = format!("failed to write LLVM IR to {}", out.display());
|
let msg = format!("failed to write LLVM IR to {}", out.display());
|
||||||
llvm_err(diag_handler, &msg)
|
llvm_err(diag_handler, &msg)
|
||||||
})
|
|
||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1727,8 +1727,7 @@ extern "C" {
|
||||||
Output: *const c_char,
|
Output: *const c_char,
|
||||||
FileType: FileType)
|
FileType: FileType)
|
||||||
-> LLVMRustResult;
|
-> LLVMRustResult;
|
||||||
pub fn LLVMRustPrintModule(PM: &PassManager<'a>,
|
pub fn LLVMRustPrintModule(M: &'a Module,
|
||||||
M: &'a Module,
|
|
||||||
Output: *const c_char,
|
Output: *const c_char,
|
||||||
Demangle: extern fn(*const c_char,
|
Demangle: extern fn(*const c_char,
|
||||||
size_t,
|
size_t,
|
||||||
|
|
|
@ -658,46 +658,11 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class RustPrintModulePass : public ModulePass {
|
|
||||||
raw_ostream* OS;
|
|
||||||
DemangleFn Demangle;
|
|
||||||
public:
|
|
||||||
static char ID;
|
|
||||||
RustPrintModulePass() : ModulePass(ID), OS(nullptr), Demangle(nullptr) {}
|
|
||||||
RustPrintModulePass(raw_ostream &OS, DemangleFn Demangle)
|
|
||||||
: ModulePass(ID), OS(&OS), Demangle(Demangle) {}
|
|
||||||
|
|
||||||
bool runOnModule(Module &M) override {
|
|
||||||
RustAssemblyAnnotationWriter AW(Demangle);
|
|
||||||
|
|
||||||
M.print(*OS, &AW, false);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
|
||||||
AU.setPreservesAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
static StringRef name() { return "RustPrintModulePass"; }
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace llvm {
|
|
||||||
void initializeRustPrintModulePassPass(PassRegistry&);
|
|
||||||
}
|
|
||||||
|
|
||||||
char RustPrintModulePass::ID = 0;
|
|
||||||
INITIALIZE_PASS(RustPrintModulePass, "print-rust-module",
|
|
||||||
"Print rust module to stderr", false, false)
|
|
||||||
|
|
||||||
extern "C" LLVMRustResult
|
extern "C" LLVMRustResult
|
||||||
LLVMRustPrintModule(LLVMPassManagerRef PMR, LLVMModuleRef M,
|
LLVMRustPrintModule(LLVMModuleRef M, const char *Path, DemangleFn Demangle) {
|
||||||
const char *Path, DemangleFn Demangle) {
|
|
||||||
llvm::legacy::PassManager *PM = unwrap<llvm::legacy::PassManager>(PMR);
|
|
||||||
std::string ErrorInfo;
|
std::string ErrorInfo;
|
||||||
|
|
||||||
std::error_code EC;
|
std::error_code EC;
|
||||||
raw_fd_ostream OS(Path, EC, sys::fs::F_None);
|
raw_fd_ostream OS(Path, EC, sys::fs::F_None);
|
||||||
if (EC)
|
if (EC)
|
||||||
|
@ -707,11 +672,9 @@ LLVMRustPrintModule(LLVMPassManagerRef PMR, LLVMModuleRef M,
|
||||||
return LLVMRustResult::Failure;
|
return LLVMRustResult::Failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RustAssemblyAnnotationWriter AAW(Demangle);
|
||||||
formatted_raw_ostream FOS(OS);
|
formatted_raw_ostream FOS(OS);
|
||||||
|
unwrap(M)->print(FOS, &AAW);
|
||||||
PM->add(new RustPrintModulePass(FOS, Demangle));
|
|
||||||
|
|
||||||
PM->run(*unwrap(M));
|
|
||||||
|
|
||||||
return LLVMRustResult::Success;
|
return LLVMRustResult::Success;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue