diff --git a/examples/opcode_counter.rs b/examples/opcode_counter.rs index 221ba3c..e5e7936 100644 --- a/examples/opcode_counter.rs +++ b/examples/opcode_counter.rs @@ -4,7 +4,6 @@ use std::collections::HashMap; use llvm_plugin::inkwell::values::{FunctionValue, InstructionOpcode}; -use llvm_plugin::utils::InstructionIterator; use llvm_plugin::{ AnalysisKey, FunctionAnalysisManager, LlvmFunctionAnalysis, LlvmFunctionPass, PassBuilder, PipelineParsing, PreservedAnalyses, @@ -57,7 +56,7 @@ impl LlvmFunctionAnalysis for OpcodeCounterAnalysis { let mut opcode_map = HashMap::new(); for bb in function.get_basic_blocks() { - for instr in InstructionIterator::new(&bb) { + for instr in bb.get_instructions() { opcode_map .entry(instr.get_opcode()) .and_modify(|e| *e += 1) diff --git a/examples/static_call_counter.rs b/examples/static_call_counter.rs index 4b8209a..f0a4333 100644 --- a/examples/static_call_counter.rs +++ b/examples/static_call_counter.rs @@ -7,7 +7,6 @@ use either::Either; use llvm_plugin::inkwell::module::Module; use llvm_plugin::inkwell::values::{BasicValueEnum, InstructionOpcode}; -use llvm_plugin::utils::InstructionIterator; use llvm_plugin::{ AnalysisKey, LlvmModuleAnalysis, LlvmModulePass, ModuleAnalysisManager, PassBuilder, PipelineParsing, PreservedAnalyses, @@ -47,7 +46,7 @@ impl LlvmModuleAnalysis for StaticCallCounterAnalysis { for func in module.get_functions() { for bb in func.get_basic_blocks() { - for instr in InstructionIterator::new(&bb) { + for instr in bb.get_instructions() { if !matches!(instr.get_opcode(), InstructionOpcode::Call) { continue; } diff --git a/examples/strings.rs b/examples/strings.rs index 7d760b2..a880467 100644 --- a/examples/strings.rs +++ b/examples/strings.rs @@ -7,7 +7,6 @@ use llvm_plugin::inkwell::basic_block::BasicBlock; use llvm_plugin::inkwell::module::{Linkage, Module}; use llvm_plugin::inkwell::values::{BasicValueEnum, FunctionValue, GlobalValue}; use llvm_plugin::inkwell::{AddressSpace, IntPredicate}; -use llvm_plugin::utils::GlobalIterator; use llvm_plugin::{ LlvmModulePass, ModuleAnalysisManager, PassBuilder, PipelineParsing, PreservedAnalyses, }; @@ -59,7 +58,7 @@ fn encode_global_strings<'a>(module: &mut Module<'a>) -> Vec> { let mut global_strings = Vec::new(); let cx = module.get_context(); - for global in GlobalIterator::new(module) { + for global in module.get_globals() { // ignore external globals if matches!(global.get_linkage(), Linkage::External) { continue; diff --git a/llvm-plugin/build.rs b/llvm-plugin/build.rs index 0f6b776..49ac5bb 100644 --- a/llvm-plugin/build.rs +++ b/llvm-plugin/build.rs @@ -98,7 +98,7 @@ mod llvm_sys { fn locate_llvm_config() -> Option { let prefix = env::var_os(&*ENV_LLVM_PREFIX) .map(|p| PathBuf::from(p).join("bin")) - .unwrap_or_else(PathBuf::new); + .unwrap_or_default(); for binary_name in llvm_config_binary_names() { let binary_name = prefix.join(binary_name); match llvm_version(&binary_name) { diff --git a/llvm-plugin/src/analysis.rs b/llvm-plugin/src/analysis.rs index 1521104..e439479 100644 --- a/llvm-plugin/src/analysis.rs +++ b/llvm-plugin/src/analysis.rs @@ -125,7 +125,7 @@ impl FunctionAnalysisManager { } Box::into_raw(pass); - #[allow(clippy::forget_copy)] + #[allow(forgetting_copy_types)] std::mem::forget(function); } diff --git a/llvm-plugin/src/lib.rs b/llvm-plugin/src/lib.rs index 4dd5a4d..1fcc7ca 100644 --- a/llvm-plugin/src/lib.rs +++ b/llvm-plugin/src/lib.rs @@ -117,9 +117,6 @@ pub use pass_manager::*; mod pass_builder; pub use pass_builder::*; -/// Utilities. -pub mod utils; - /// Enum specifying whether analyses on an IR unit are not preserved due /// to the modification of such unit by a transformation pass. #[repr(C)] diff --git a/llvm-plugin/src/pass_manager.rs b/llvm-plugin/src/pass_manager.rs index d1ed688..a6adc7f 100644 --- a/llvm-plugin/src/pass_manager.rs +++ b/llvm-plugin/src/pass_manager.rs @@ -111,7 +111,7 @@ impl FunctionPassManager { let preserve = pass.run_pass(&mut function, &manager); Box::into_raw(pass); - #[allow(clippy::forget_copy)] + #[allow(forgetting_copy_types)] std::mem::forget(function); preserve diff --git a/llvm-plugin/src/utils.rs b/llvm-plugin/src/utils.rs deleted file mode 100644 index a09dbe0..0000000 --- a/llvm-plugin/src/utils.rs +++ /dev/null @@ -1,87 +0,0 @@ -use inkwell::basic_block::BasicBlock; -use inkwell::module::Module; -use inkwell::values::{FunctionValue, GlobalValue, InstructionValue}; - -/// Convenient iterator for enumerating functions. -pub struct FunctionIterator<'a, 'ctx> { - module: &'a Module<'ctx>, - func: Option>, -} - -impl<'a, 'ctx> FunctionIterator<'a, 'ctx> { - /// Create a new [`FunctionIterator`] from a [`Module`]. - pub fn new(module: &'a Module<'ctx>) -> Self { - Self { module, func: None } - } -} - -impl<'a, 'ctx> Iterator for FunctionIterator<'a, 'ctx> { - type Item = FunctionValue<'ctx>; - - fn next(&mut self) -> Option { - if let Some(func) = self.func { - self.func = func.get_next_function(); - return self.func; - } - - self.func = Some(self.module.get_first_function()?); - self.func - } -} - -/// Convenient iterator for enumerating globals. -pub struct GlobalIterator<'a, 'ctx> { - module: &'a Module<'ctx>, - global: Option>, -} - -impl<'a, 'ctx> GlobalIterator<'a, 'ctx> { - /// Create a new [`GlobalIterator`] from a [`Module`]. - pub fn new(module: &'a Module<'ctx>) -> Self { - Self { - module, - global: None, - } - } -} - -impl<'a, 'ctx> Iterator for GlobalIterator<'a, 'ctx> { - type Item = GlobalValue<'ctx>; - - fn next(&mut self) -> Option { - if let Some(global) = self.global { - self.global = global.get_next_global(); - return self.global; - } - - self.global = Some(self.module.get_first_global()?); - self.global - } -} - -/// Convenient iterator for enumerating globals. -pub struct InstructionIterator<'a, 'ctx> { - bb: &'a BasicBlock<'ctx>, - instr: Option>, -} - -impl<'a, 'ctx> InstructionIterator<'a, 'ctx> { - /// Create a new [`InstructionIterator`] from a [`BasicBlock`]. - pub fn new(bb: &'a BasicBlock<'ctx>) -> Self { - Self { bb, instr: None } - } -} - -impl<'a, 'ctx> Iterator for InstructionIterator<'a, 'ctx> { - type Item = InstructionValue<'ctx>; - - fn next(&mut self) -> Option { - if let Some(instr) = self.instr { - self.instr = instr.get_next_instruction(); - return self.instr; - } - - self.instr = Some(self.bb.get_first_instruction()?); - self.instr - } -} diff --git a/tests/plugins/plugin5/src/lib.rs b/tests/plugins/plugin5/src/lib.rs index d670578..4d86e89 100644 --- a/tests/plugins/plugin5/src/lib.rs +++ b/tests/plugins/plugin5/src/lib.rs @@ -1,7 +1,6 @@ use llvm_plugin::inkwell::basic_block::BasicBlock; use llvm_plugin::inkwell::module::Module; use llvm_plugin::inkwell::values::{FunctionValue, InstructionOpcode, InstructionValue}; -use llvm_plugin::utils::FunctionIterator; use llvm_plugin::{ AnalysisKey, FunctionAnalysisManager, LlvmFunctionAnalysis, LlvmFunctionPass, LlvmModulePass, ModuleAnalysisManager, PassBuilder, PipelineParsing, PreservedAnalyses, @@ -39,7 +38,7 @@ impl LlvmModulePass for Pass1 { .get_function_analysis_manager_proxy(&module) .get_manager(); - for function in FunctionIterator::new(module) { + for function in module.get_functions() { let result = manager.get_cached_result::(&function); assert!(result.is_none());