Struct inkwell::targets::TargetMachine
source · pub struct TargetMachine { /* private fields */ }
Implementations§
source§impl TargetMachine
impl TargetMachine
pub unsafe fn new(target_machine: LLVMTargetMachineRef) -> Self
sourcepub fn as_mut_ptr(&self) -> LLVMTargetMachineRef
pub fn as_mut_ptr(&self) -> LLVMTargetMachineRef
Acquires the underlying raw pointer belonging to this TargetMachine
type.
pub fn get_target(&self) -> Target
pub fn get_triple(&self) -> TargetTriple
sourcepub fn get_default_triple() -> TargetTriple
pub fn get_default_triple() -> TargetTriple
Gets the default triple for the current system.
§Example
use inkwell::targets::TargetMachine;
let default_triple = TargetMachine::get_default_triple();
assert_eq!(default_triple.as_str().to_str(), Ok("x86_64-pc-linux-gnu"));
pub fn normalize_triple(triple: &TargetTriple) -> TargetTriple
sourcepub fn get_host_cpu_name() -> LLVMString
pub fn get_host_cpu_name() -> LLVMString
sourcepub fn get_host_cpu_features() -> LLVMString
pub fn get_host_cpu_features() -> LLVMString
Gets a comma separated list of supported features by the host CPU.
§Example Output
+sse2,+cx16,+sahf,-tbm
pub fn get_cpu(&self) -> LLVMString
pub fn get_feature_string(&self) -> &CStr
sourcepub fn get_target_data(&self) -> TargetData
pub fn get_target_data(&self) -> TargetData
Create TargetData from this target machine
pub fn set_asm_verbosity(&self, verbosity: bool)
pub fn add_analysis_passes<T>(&self, pass_manager: &PassManager<T>)
sourcepub fn write_to_memory_buffer(
&self,
module: &Module<'_>,
file_type: FileType
) -> Result<MemoryBuffer, LLVMString>
pub fn write_to_memory_buffer( &self, module: &Module<'_>, file_type: FileType ) -> Result<MemoryBuffer, LLVMString>
Writes a TargetMachine
to a MemoryBuffer
.
§Example
use inkwell::OptimizationLevel;
use inkwell::context::Context;
use inkwell::targets::{CodeModel, RelocMode, FileType, Target, TargetMachine, TargetTriple, InitializationConfig};
Target::initialize_x86(&InitializationConfig::default());
let opt = OptimizationLevel::Default;
let reloc = RelocMode::Default;
let model = CodeModel::Default;
let target = Target::from_name("x86-64").unwrap();
let target_machine = target.create_target_machine(
&TargetTriple::create("x86_64-pc-linux-gnu"),
"x86-64",
"+avx2",
opt,
reloc,
model
)
.unwrap();
let context = Context::create();
let module = context.create_module("my_module");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
module.add_function("my_fn", fn_type, None);
let buffer = target_machine.write_to_memory_buffer(&module, FileType::Assembly).unwrap();
sourcepub fn write_to_file(
&self,
module: &Module<'_>,
file_type: FileType,
path: &Path
) -> Result<(), LLVMString>
pub fn write_to_file( &self, module: &Module<'_>, file_type: FileType, path: &Path ) -> Result<(), LLVMString>
Saves a TargetMachine
to a file.
§Example
use inkwell::OptimizationLevel;
use inkwell::context::Context;
use inkwell::targets::{CodeModel, RelocMode, FileType, Target, TargetMachine, TargetTriple, InitializationConfig};
use std::path::Path;
Target::initialize_x86(&InitializationConfig::default());
let opt = OptimizationLevel::Default;
let reloc = RelocMode::Default;
let model = CodeModel::Default;
let path = Path::new("/tmp/some/path/main.asm");
let target = Target::from_name("x86-64").unwrap();
let target_machine = target.create_target_machine(
&TargetTriple::create("x86_64-pc-linux-gnu"),
"x86-64",
"+avx2",
opt,
reloc,
model
)
.unwrap();
let context = Context::create();
let module = context.create_module("my_module");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
module.add_function("my_fn", fn_type, None);
assert!(target_machine.write_to_file(&module, FileType::Object, &path).is_ok());
Trait Implementations§
source§impl Debug for TargetMachine
impl Debug for TargetMachine
Auto Trait Implementations§
impl Freeze for TargetMachine
impl RefUnwindSafe for TargetMachine
impl !Send for TargetMachine
impl !Sync for TargetMachine
impl Unpin for TargetMachine
impl UnwindSafe for TargetMachine
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more