Attribute Macro llvm_plugin_macros::plugin
source · [−]#[plugin]
Expand description
Macro for defining a new LLVM plugin.
This macro must be used at the module level, and must define a name
and version
parameters.
It will look for the #[pass(name = ..)]
and #[analysis]
attributes inside the module,
to generate code that, once executed by the opt tool, will register passes to the LLVM
pass manager.
Examples
Using the outer attribute syntax:
#[llvm_plugin::plugin(name = "some_name", version = "0.1")]
mod plugin {
#[derive(Default)]
struct Pass1;
#[pass(name = "some_other_name")]
impl LlvmModulePass for Pass1 {
fn run_pass(
&self,
module: &mut Module,
manager: &ModuleAnalysisManager,
) -> PreservedAnalyses {
todo!()
}
}
#[derive(Default)]
struct Analysis1;
#[analysis]
impl LlvmModuleAnalysis for Analysis1 {
fn run_analysis(
&self,
module: &Module,
manager: &ModuleAnalysisManager,
) -> String {
todo!()
}
}
}
Using the inner attribute syntax (requires nightly
):
#![feature(prelude_import)]
#![feature(custom_inner_attributes)]
#![llvm_plugin::plugin(name = "some_name", version = "0.1")]
#[derive(Default)]
struct Pass1;
#[pass(name = "some_other_name")]
impl LlvmModulePass for Pass1 {
fn run_pass(
&self,
module: &mut Module,
manager: &ModuleAnalysisManager,
) -> PreservedAnalyses {
todo!()
}
}
#[derive(Default)]
struct Analysis1;
#[analysis]
impl LlvmModuleAnalysis for Analysis1 {
fn run_analysis(
&self,
module: &Module,
manager: &ModuleAnalysisManager,
) -> String {
todo!()
}
}