Struct inkwell::targets::TargetMachine

source ·
pub struct TargetMachine { /* private fields */ }

Implementations§

source§

impl TargetMachine

source

pub unsafe fn new(target_machine: LLVMTargetMachineRef) -> Self

source

pub fn as_mut_ptr(&self) -> LLVMTargetMachineRef

Acquires the underlying raw pointer belonging to this TargetMachine type.

source

pub fn get_target(&self) -> Target

source

pub fn get_triple(&self) -> TargetTriple

source

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"));
source

pub fn normalize_triple(triple: &TargetTriple) -> TargetTriple

source

pub fn get_host_cpu_name() -> LLVMString

Gets a string containing the host CPU’s name (triple).

§Example Output

x86_64-pc-linux-gnu

source

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

source

pub fn get_cpu(&self) -> LLVMString

source

pub fn get_feature_string(&self) -> &CStr

source

pub fn get_target_data(&self) -> TargetData

Create TargetData from this target machine

source

pub fn set_asm_verbosity(&self, verbosity: bool)

source

pub fn add_analysis_passes<T>(&self, pass_manager: &PassManager<T>)

source

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();
source

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

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for TargetMachine

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.