pub struct Project { /* private fields */ }
Expand description
A Project
is a collection of LLVM code to be explored,
consisting of one or more LLVM modules.
Implementations§
source§impl Project
impl Project
sourcepub fn from_bc_path(path: impl AsRef<Path>) -> Result<Self, String>
pub fn from_bc_path(path: impl AsRef<Path>) -> Result<Self, String>
Construct a new Project
from a path to an LLVM bitcode file
sourcepub fn from_bc_paths<P>(
paths: impl IntoIterator<Item = P>
) -> Result<Self, String>where
P: AsRef<Path>,
pub fn from_bc_paths<P>( paths: impl IntoIterator<Item = P> ) -> Result<Self, String>where P: AsRef<Path>,
Construct a new Project
from multiple LLVM bitcode files
sourcepub fn from_bc_dir(path: impl AsRef<Path>, extn: &str) -> Result<Self, Error>
pub fn from_bc_dir(path: impl AsRef<Path>, extn: &str) -> Result<Self, Error>
Construct a new Project
from a path to a directory containing
LLVM bitcode files.
All files in the directory which have the extension extn
will
be parsed and added to the Project
.
Panics if there are no files in the directory with that extension.
sourcepub fn from_bc_dir_with_blacklist(
path: impl AsRef<Path>,
extn: &str,
exclude: impl Fn(&Path) -> bool
) -> Result<Self, Error>
pub fn from_bc_dir_with_blacklist( path: impl AsRef<Path>, extn: &str, exclude: impl Fn(&Path) -> bool ) -> Result<Self, Error>
Construct a new Project
from a path to a directory containing LLVM
bitcode files.
All files in the directory which have the extension extn
, except those
for which the provided exclude
closure returns true
, will be parsed
and added to the Project
.
Panics if there are no files in the directory with that extension, or if they were all excluded.
sourcepub fn add_bc_path(&mut self, path: impl AsRef<Path>) -> Result<(), String>
pub fn add_bc_path(&mut self, path: impl AsRef<Path>) -> Result<(), String>
Add the code in the given LLVM bitcode file to the Project
sourcepub fn add_bc_dir(
&mut self,
path: impl AsRef<Path>,
extn: &str
) -> Result<(), Error>
pub fn add_bc_dir( &mut self, path: impl AsRef<Path>, extn: &str ) -> Result<(), Error>
Add the code in the given directory to the Project
.
See Project::from_bc_dir()
.
sourcepub fn add_bc_dir_with_blacklist(
&mut self,
path: impl AsRef<Path>,
extn: &str,
exclude: impl Fn(&Path) -> bool
) -> Result<(), Error>
pub fn add_bc_dir_with_blacklist( &mut self, path: impl AsRef<Path>, extn: &str, exclude: impl Fn(&Path) -> bool ) -> Result<(), Error>
Add the code in the given directory, except for blacklisted files, to the Project
.
See Project::from_bc_dir_with_blacklist()
.
sourcepub fn pointer_size_bits(&self) -> u32
pub fn pointer_size_bits(&self) -> u32
Get the pointer size used by the Project
, in bits.
E.g., this will be 64
if the LLVM bitcode was compiled for a 64-bit platform.
sourcepub fn all_functions(&self) -> impl Iterator<Item = (&Function, &Module)>
pub fn all_functions(&self) -> impl Iterator<Item = (&Function, &Module)>
Iterate over all Function
s in the Project
.
Gives pairs which also indicate the Module
the Function
is defined in.
sourcepub fn all_global_vars(
&self
) -> impl Iterator<Item = (&GlobalVariable, &Module)>
pub fn all_global_vars( &self ) -> impl Iterator<Item = (&GlobalVariable, &Module)>
Iterate over all GlobalVariable
s in the Project
.
Gives pairs which also indicate the Module
the GlobalVariable
comes from.
sourcepub fn all_global_aliases(
&self
) -> impl Iterator<Item = (&GlobalAlias, &Module)>
pub fn all_global_aliases( &self ) -> impl Iterator<Item = (&GlobalAlias, &Module)>
Iterate over all GlobalAlias
es in the Project
.
Gives pairs which also indicate the Module
the GlobalAlias
comes from.
sourcepub fn all_named_struct_types(
&self
) -> impl Iterator<Item = (&String, &NamedStructDef, &Module)>
pub fn all_named_struct_types( &self ) -> impl Iterator<Item = (&String, &NamedStructDef, &Module)>
Iterate over all named struct types in the Project
.
Gives triplets (name, NamedStructDef, Module)
which indicate the struct’s name,
definition, and which module the definition comes from.
sourcepub fn active_module_names(&self) -> impl Iterator<Item = &String>
pub fn active_module_names(&self) -> impl Iterator<Item = &String>
Get the names of the LLVM modules which have been parsed and loaded into
the Project
sourcepub fn get_func_by_name<'p>(
&'p self,
name: &str
) -> Option<(&'p Function, &'p Module)>
pub fn get_func_by_name<'p>( &'p self, name: &str ) -> Option<(&'p Function, &'p Module)>
Search the project for a function with the given name. If a matching function is found, return both it and the module it was found in.
For projects containing C++ or Rust code, you can pass either the mangled or demangled function name (fully qualified with namespaces/modules).
If you have a State
handy, you may want to use
state.get_func_by_name()
instead, which will get the appropriate
(potentially module-private) definition based on the current LLVM module.
sourcepub fn get_named_struct_def<'p>(
&'p self,
name: &str
) -> Result<(&'p NamedStructDef, &'p Module)>
pub fn get_named_struct_def<'p>( &'p self, name: &str ) -> Result<(&'p NamedStructDef, &'p Module)>
Get the definition of the named struct with the given name. Returns both the definition, and the module that definition was found in.
Returns Err
if neither a definition nor declaration for a named struct
type with the given name was found anywhere in the Project
.
If the named struct type is defined in multiple modules in the Project
,
this returns one of them arbitrarily. However, it will only return
NamedStructDef::Opaque
if all definitions are opaque; that is, it will
attempt to return some non-opaque definition if one exists, before
returning an opaque definition.
sourcepub fn size_in_bits(&self, ty: &Type) -> Option<u32>
pub fn size_in_bits(&self, ty: &Type) -> Option<u32>
Get the size of the Type
, in bits.
Accounts for the Project
’s pointer size and named struct definitions.
Note that some types have size 0 bits, and this may return Some(0)
.
Returns None
for structs which have no definition in the entire Project
,
or for structs/arrays/vectors where one of the elements is a struct with no
definition in the entire Project
.
sourcepub fn fp_size_in_bits(fpt: FPType) -> u32
pub fn fp_size_in_bits(fpt: FPType) -> u32
Get the size of the FPType
, in bits