pub struct TargetMachine { /* private fields */ }

Implementations

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

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

Example Output

x86_64-pc-linux-gnu

Gets a comma separated list of supported features by the host CPU.

Example Output

+sse2,+cx16,+sahf,-tbm

Create TargetData from this target machine

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

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

Formats the value using the given formatter. Read more

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.