mirror of
https://github.com/edg-l/edlang.git
synced 2024-11-23 00:18:24 +00:00
1351 lines
209 KiB
HTML
1351 lines
209 KiB
HTML
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="All `build_*` methods return a `Result<_, BuilderError>` type containing either the returned value or some error. Those methods all may return `BuilderError::UnsetPosition` if a `position_*` method has not yet been called, in addition to any other possibility."><title>Builder in inkwell::builder - Rust</title><script> if (window.location.protocol !== "file:") document.write(`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2">`)</script><link rel="stylesheet" href="../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../static.files/rustdoc-e935ef01ae1c1829.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="inkwell" data-themes="" data-resource-suffix="" data-rustdoc-version="1.78.0 (9b00956e5 2024-04-29)" data-channel="1.78.0" data-search-js="search-42d8da7a6b9792c2.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../../static.files/storage-4c98445ec4002617.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-12cf3b4f4f9dc36d.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-04d5337699b92874.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc struct"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../inkwell/index.html">inkwell</a><span class="version">0.4.0</span></h2></div><h2 class="location"><a href="#">Builder</a></h2><div class="sidebar-elems"><section><h3><a href="#implementations">Methods</a></h3><ul class="block method"><li><a href="#method.as_mut_ptr">as_mut_ptr</a></li><li><a href="#method.build_address_space_cast">build_address_space_cast</a></li><li><a href="#method.build_aggregate_return">build_aggregate_return</a></li><li><a href="#method.build_alloca">build_alloca</a></li><li><a href="#method.build_and">build_and</a></li><li><a href="#method.build_array_alloca">build_array_alloca</a></li><li><a href="#method.build_array_malloc">build_array_malloc</a></li><li><a href="#method.build_atomicrmw">build_atomicrmw</a></li><li><a href="#method.build_bit_cast">build_bit_cast</a></li><li><a href="#method.build_call">build_call</a></li><li><a href="#method.build_cast">build_cast</a></li><li><a href="#method.build_cmpxchg">build_cmpxchg</a></li><li><a href="#method.build_conditional_branch">build_conditional_branch</a></li><li><a href="#method.build_direct_call">build_direct_call</a></li><li><a href="#method.build_direct_invoke">build_direct_invoke</a></li><li><a href="#method.build_extract_element">build_extract_element</a></li><li><a href="#method.build_extract_value">build_extract_value</a></li><li><a href="#method.build_fence">build_fence</a></li><li><a href="#method.build_float_add">build_float_add</a></li><li><a href="#method.build_float_cast">build_float_cast</a></li><li><a href="#method.build_float_compare">build_float_compare</a></li><li><a href="#method.build_float_div">build_float_div</a></li><li><a href="#method.build_float_ext">build_float_ext</a></li><li><a href="#method.build_float_mul">build_float_mul</a></li><li><a href="#method.build_float_neg">build_float_neg</a></li><li><a href="#method.build_float_rem">build_float_rem</a></li><li><a href="#method.build_float_sub">build_float_sub</a></li><li><a href="#method.build_float_to_signed_int">build_float_to_signed_int</a></li><li><a href="#method.build_float_to_unsigned_int">build_float_to_unsigned_int</a></li><li><a href="#method.build_float_trunc">build_float_trunc</a></li><li><a href="#method.build_free">build_free</a></li><li><a href="#method.build_gep">build_gep</a></li><li><a href="#method.build_global_string">build_global_string</a></li><li><a href="#method.build_global_string_ptr">build_global_string_ptr</a></li><li><a href="#method.build_in_bounds_gep">build_in_bounds_gep</a></li><li><a href="#method.build_indirect_branch">build_indirect_branch</a></li><li><a href="#method.build_indirect_call">build_indirect_call</a></li><li><a href="#method.build_indirect_invoke">build_indirect_invoke</a></li><li><a href="#method.build_insert_element">build_insert_element</a></li><li><a href="#method.build_insert_value">build_insert_value</a></li><li><a href="#method.build_int_add">build_int_add</a></li><li><a href="#method.build_int_cast">build_int_cast</a></li><li><a href="#method.build_int_cast_sign_flag">build_int_cast_sign_flag</a></li><li><a href="#method.build_int_compare">build_int_compare</a></li><li><a href="#method.build_int_exact_signed_div">build_int_exact_signed_div</a></li><li><a href="#method.build_int_mul">build_int_mul</a></li><li><a href="#method.build_int_neg">build_int_neg</a></li><li><a href="#method.build_int_nsw_add">build_int_nsw_add</a></li><li><a href="#method.build_int_nsw_mul">build_int_nsw_mul</a></li><li><a href="#method.build_int_nsw_neg">build_int_nsw_neg</a></li><li><a href="#method.build_int_nsw_sub">build_int_nsw_sub</a></li><li><a href="#method.build_int_nuw_add">build_int_nuw_add</a></li><li><a href="#method.build_int_nuw_mul">build_int_nuw_mul</a></li><li><a href="#method.build_int_nuw_neg">build_int_nuw_neg</a></li><li><a href="#method.build_int_nuw_sub">build_int_nuw_sub</a></li><li><a href="#method.build_int_s_extend">build_int_s_extend</a></li><li><a href="#method.build_int_s_extend_or_bit_cast">build_int_s_extend_or_bit_cast</a></li><li><a href="#method.build_int_signed_div">build_int_signed_div</a></li><li><a href="#method.build_int_signed_rem">build_int_signed_rem</a></li><li><a href="#method.build_int_sub">build_int_sub</a></li><li><a href="#method.build_int_to_ptr">build_int_to_ptr</a></li><li><a href="#method.build_int_truncate">build_int_truncate</a></li><li><a href="#method.build_int_truncate_or_bit_cast">build_int_truncate_or_bit_cast</a></li><li><a href="#method.build_int_unsigned_div">build_int_unsigned_div</a></li><li><a href="#method.build_int_unsigned_rem">build_int_unsigned_rem</a></li><li><a href="#method.build_int_z_extend">build_int_z_extend</a></li><li><a href="#method.build_int_z_extend_or_bit_cast">build_int_z_extend_or_bit_cast</a></li><li><a href="#method.build_invoke">build_invoke</a></li><li><a href="#method.build_is_not_null">build_is_not_null</a></li><li><a href="#method.build_is_null">build_is_null</a></li><li><a href="#method.build_landing_pad">build_landing_pad</a></li><li><a href="#method.build_left_shift">build_left_shift</a></li><li><a href="#method.build_load">build_load</a></li><li><a href="#method.build_malloc">build_malloc</a></li><li><a href="#method.build_memcpy">build_memcpy</a></li><li><a href="#method.build_memmove">build_memmove</a></li><li><a href="#method.build_memset">build_memset</a></li><li><a href="#method.build_not">build_not</a></li><li><a href="#method.build_or">build_or</a></li><li><a href="#method.build_phi">build_phi</a></li><li><a href="#method.build_pointer_cast">build_pointer_cast</a></li><li><a href="#method.build_ptr_diff">build_ptr_diff</a></li><li><a href="#method.build_ptr_to_int">build_ptr_to_int</a></li><li><a href="#method.build_resume">build_resume</a></li><li><a href="#method.build_return">build_return</a></li><li><a href="#method.build_right_shift">build_right_shift</a></li><li><a href="#method.build_select">build_select</a></li><li><a href="#method.build_shuffle_vector">build_shuffle_vector</a></li><li><a href="#method.build_signed_int_to_float">build_signed_int_to_float</a></li><li><a href="#method.build_store">build_store</a></li><li><a href="#method.build_struct_gep">build_struct_gep</a></li><li><a href="#method.build_switch">build_switch</a></li><li><a href="#method.build_unconditional_branch">build_unconditional_branch</a></li><li><a href="#method.build_unreachable">build_unreachable</a></li><li><a href="#method.build_unsigned_int_to_float">build_unsigned_int_to_float</a></li><li><a href="#method.build_va_arg">build_va_arg</a></li><li><a href="#method.build_xor">build_xor</a></li><li><a href="#method.clear_insertion_position">clear_insertion_position</a></li><li><a href="#method.get_current_debug_location">get_current_debug_location</a></li><li><a href="#method.get_insert_block">get_insert_block</a></li><li><a href="#method.insert_instruction">insert_instruction</a></li><li><a href="#method.new">new</a></li><li><a href="#method.position_at">position_at</a></li><li><a href="#method.position_at_end">position_at_end</a></li><li><a href="#method.position_before">position_before</a></li><li><a href="#method.set_current_debug_location">set_current_debug_location</a></li><li><a href="#method.unset_current_debug_location">unset_current_debug_location</a></li></ul><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block trait-implementation"><li><a href="#impl-Debug-for-Builder%3C'ctx%3E">Debug</a></li><li><a href="#impl-Drop-for-Builder%3C'_%3E">Drop</a></li></ul><h3><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul class="block synthetic-implementation"><li><a href="#impl-Freeze-for-Builder%3C'ctx%3E">!Freeze</a></li><li><a href="#impl-RefUnwindSafe-for-Builder%3C'ctx%3E">!RefUnwindSafe</a></li><li><a href="#impl-Send-for-Builder%3C'ctx%3E">!Send</a></li><li><a href="#impl-Sync-for-Builder%3C'ctx%3E">!Sync</a></li><li><a href="#impl-Unpin-for-Builder%3C'ctx%3E">Unpin</a></li><li><a href="#impl-UnwindSafe-for-Builder%3C'ctx%3E">UnwindSafe</a></li></ul><h3><a href="#blanket-implementations">Blanket Implementations</a></h3><ul class="block blanket-implementation"><li><a href="#impl-Any-for-T">Any</a></li><li><a href="#impl-Borrow%3CT%3E-for-T">Borrow<T></a></li><li><a href="#impl-BorrowMut%3CT%3E-for-T">BorrowMut<T></a></li><li><a href="#impl-From%3CT%3E-for-T">From<T></a></li><li><a href="#impl-Into%3CU%3E-for-T">Into<U></a></li><li><a href="#impl-IntoEither-for-T">IntoEither</a></li><li><a href="#impl-TryFrom%3CU%3E-for-T">TryFrom<U></a></li><li><a href="#impl-TryInto%3CU%3E-for-T">TryInto<U></a></li></ul></section><h2><a href="index.html">In inkwell::builder</a></h2></div></nav><div class="sidebar-resizer"></div>
|
||
<main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><div id="sidebar-button" tabindex="-1"><a href="../../inkwell/all.html" title="show sidebar"></a></div><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" tabindex="-1"><a href="../../help.html" title="help">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1>Struct <a href="../index.html">inkwell</a>::<wbr><a href="index.html">builder</a>::<wbr><a class="struct" href="#">Builder</a><button id="copy-path" title="Copy item path to clipboard"><img src="../../static.files/clipboard-7571035ce49a181d.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="src" href="../../src/inkwell/builder.rs.html#91-95">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></span></div><pre class="rust item-decl"><code>pub struct Builder<'ctx> { <span class="comment">/* private fields */</span> }</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>All <code>build_*</code> methods return a <code>Result<_, BuilderError></code> type containing either the returned value or some error.
|
||
Those methods all may return <code>BuilderError::UnsetPosition</code> if a <code>position_*</code> method has not yet been called, in addition
|
||
to any other possibility.</p>
|
||
</div></details><h2 id="implementations" class="section-header">Implementations<a href="#implementations" class="anchor">§</a></h2><div id="implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-Builder%3C'ctx%3E" class="impl"><a class="src rightside" href="../../src/inkwell/builder.rs.html#100-3488">source</a><a href="#impl-Builder%3C'ctx%3E" class="anchor">§</a><h3 class="code-header">impl<'ctx> <a class="struct" href="struct.Builder.html" title="struct inkwell::builder::Builder">Builder</a><'ctx></h3></section></summary><div class="impl-items"><section id="method.new" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#101-109">source</a><h4 class="code-header">pub unsafe fn <a href="#method.new" class="fn">new</a>(builder: <a class="type" href="../../llvm_sys/prelude/type.LLVMBuilderRef.html" title="type llvm_sys::prelude::LLVMBuilderRef">LLVMBuilderRef</a>) -> Self</h4></section><details class="toggle method-toggle" open><summary><section id="method.as_mut_ptr" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#112-114">source</a><h4 class="code-header">pub fn <a href="#method.as_mut_ptr" class="fn">as_mut_ptr</a>(&self) -> <a class="type" href="../../llvm_sys/prelude/type.LLVMBuilderRef.html" title="type llvm_sys::prelude::LLVMBuilderRef">LLVMBuilderRef</a></h4></section></summary><div class="docblock"><p>Acquires the underlying raw pointer belonging to this <code>Builder</code> type.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.build_return" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#140-152">source</a><h4 class="code-header">pub fn <a href="#method.build_return" class="fn">build_return</a>(
|
||
&self,
|
||
value: <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><&dyn <a class="trait" href="../values/trait.BasicValue.html" title="trait inkwell::values::BasicValue">BasicValue</a><'ctx>>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../values/struct.InstructionValue.html" title="struct inkwell::values::InstructionValue">InstructionValue</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section></summary><div class="docblock"><p>Builds a function return instruction. It should be provided with <code>None</code> if the return type
|
||
is void otherwise <code>Some(&value)</code> should be provided.</p>
|
||
<h5 id="example"><a class="doc-anchor" href="#example">§</a>Example</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>inkwell::context::Context;
|
||
|
||
<span class="comment">// A simple function which returns its argument:
|
||
</span><span class="kw">let </span>context = Context::create();
|
||
<span class="kw">let </span>module = context.create_module(<span class="string">"ret"</span>);
|
||
<span class="kw">let </span>builder = context.create_builder();
|
||
<span class="kw">let </span>i32_type = context.i32_type();
|
||
<span class="kw">let </span>arg_types = [i32_type.into()];
|
||
<span class="kw">let </span>fn_type = i32_type.fn_type(<span class="kw-2">&</span>arg_types, <span class="bool-val">false</span>);
|
||
<span class="kw">let </span>fn_value = module.add_function(<span class="string">"ret"</span>, fn_type, <span class="prelude-val">None</span>);
|
||
<span class="kw">let </span>entry = context.append_basic_block(fn_value, <span class="string">"entry"</span>);
|
||
<span class="kw">let </span>i32_arg = fn_value.get_first_param().unwrap();
|
||
|
||
builder.position_at_end(entry);
|
||
builder.build_return(<span class="prelude-val">Some</span>(<span class="kw-2">&</span>i32_arg)).unwrap();</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.build_aggregate_return" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#177-188">source</a><h4 class="code-header">pub fn <a href="#method.build_aggregate_return" class="fn">build_aggregate_return</a>(
|
||
&self,
|
||
values: &[<a class="enum" href="../values/enum.BasicValueEnum.html" title="enum inkwell::values::BasicValueEnum">BasicValueEnum</a><'ctx>]
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../values/struct.InstructionValue.html" title="struct inkwell::values::InstructionValue">InstructionValue</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section></summary><div class="docblock"><p>Builds a function return instruction for a return type which is an aggregate type (ie structs and arrays).
|
||
It is not necessary to use this over <code>build_return</code> but may be more convenient to use.</p>
|
||
<h5 id="example-1"><a class="doc-anchor" href="#example-1">§</a>Example</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>inkwell::context::Context;
|
||
|
||
<span class="comment">// This builds a simple function which returns a struct (tuple) of two ints.
|
||
</span><span class="kw">let </span>context = Context::create();
|
||
<span class="kw">let </span>module = context.create_module(<span class="string">"ret"</span>);
|
||
<span class="kw">let </span>builder = context.create_builder();
|
||
<span class="kw">let </span>i32_type = context.i32_type();
|
||
<span class="kw">let </span>i32_three = i32_type.const_int(<span class="number">3</span>, <span class="bool-val">false</span>);
|
||
<span class="kw">let </span>i32_seven = i32_type.const_int(<span class="number">7</span>, <span class="bool-val">false</span>);
|
||
<span class="kw">let </span>struct_type = context.struct_type(<span class="kw-2">&</span>[i32_type.into(), i32_type.into()], <span class="bool-val">false</span>);
|
||
<span class="kw">let </span>fn_type = struct_type.fn_type(<span class="kw-2">&</span>[], <span class="bool-val">false</span>);
|
||
<span class="kw">let </span>fn_value = module.add_function(<span class="string">"ret"</span>, fn_type, <span class="prelude-val">None</span>);
|
||
<span class="kw">let </span>entry = context.append_basic_block(fn_value, <span class="string">"entry"</span>);
|
||
|
||
builder.position_at_end(entry);
|
||
builder.build_aggregate_return(<span class="kw-2">&</span>[i32_three.into(), i32_seven.into()]).unwrap();</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.build_call" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#258-268">source</a><h4 class="code-header">pub fn <a href="#method.build_call" class="fn">build_call</a>(
|
||
&self,
|
||
function: <a class="struct" href="../values/struct.FunctionValue.html" title="struct inkwell::values::FunctionValue">FunctionValue</a><'ctx>,
|
||
args: &[<a class="enum" href="../values/enum.BasicMetadataValueEnum.html" title="enum inkwell::values::BasicMetadataValueEnum">BasicMetadataValueEnum</a><'ctx>],
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../values/struct.CallSiteValue.html" title="struct inkwell::values::CallSiteValue">CallSiteValue</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section></summary><div class="docblock"><p>Builds a function call instruction. Alias for <a href="struct.Builder.html#method.build_direct_call" title="method inkwell::builder::Builder::build_direct_call">Builder::build_direct_call</a>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.build_direct_call" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#299-309">source</a><h4 class="code-header">pub fn <a href="#method.build_direct_call" class="fn">build_direct_call</a>(
|
||
&self,
|
||
function: <a class="struct" href="../values/struct.FunctionValue.html" title="struct inkwell::values::FunctionValue">FunctionValue</a><'ctx>,
|
||
args: &[<a class="enum" href="../values/enum.BasicMetadataValueEnum.html" title="enum inkwell::values::BasicMetadataValueEnum">BasicMetadataValueEnum</a><'ctx>],
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../values/struct.CallSiteValue.html" title="struct inkwell::values::CallSiteValue">CallSiteValue</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section></summary><div class="docblock"><p>Builds a function call instruction. The function being called is known at compile time. If
|
||
you want to call a function pointer, see <a href="struct.Builder.html#method.build_indirect_call" title="method inkwell::builder::Builder::build_indirect_call">Builder::build_indirect_call</a>.</p>
|
||
<h5 id="example-2"><a class="doc-anchor" href="#example-2">§</a>Example</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>inkwell::context::Context;
|
||
|
||
<span class="comment">// A simple function which calls itself:
|
||
</span><span class="kw">let </span>context = Context::create();
|
||
<span class="kw">let </span>module = context.create_module(<span class="string">"ret"</span>);
|
||
<span class="kw">let </span>builder = context.create_builder();
|
||
<span class="kw">let </span>i32_type = context.i32_type();
|
||
<span class="kw">let </span>fn_type = i32_type.fn_type(<span class="kw-2">&</span>[i32_type.into()], <span class="bool-val">false</span>);
|
||
<span class="kw">let </span>fn_value = module.add_function(<span class="string">"ret"</span>, fn_type, <span class="prelude-val">None</span>);
|
||
<span class="kw">let </span>entry = context.append_basic_block(fn_value, <span class="string">"entry"</span>);
|
||
<span class="kw">let </span>i32_arg = fn_value.get_first_param().unwrap();
|
||
<span class="kw">let </span>md_string = context.metadata_string(<span class="string">"a metadata"</span>);
|
||
|
||
builder.position_at_end(entry);
|
||
|
||
<span class="kw">let </span>ret_val = builder.build_call(fn_value, <span class="kw-2">&</span>[i32_arg.into(), md_string.into()], <span class="string">"call"</span>).unwrap()
|
||
.try_as_basic_value()
|
||
.left()
|
||
.unwrap();
|
||
|
||
builder.build_return(<span class="prelude-val">Some</span>(<span class="kw-2">&</span>ret_val)).unwrap();</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.build_indirect_call" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#342-353">source</a><h4 class="code-header">pub fn <a href="#method.build_indirect_call" class="fn">build_indirect_call</a>(
|
||
&self,
|
||
function_type: <a class="struct" href="../types/struct.FunctionType.html" title="struct inkwell::types::FunctionType">FunctionType</a><'ctx>,
|
||
function_pointer: <a class="struct" href="../values/struct.PointerValue.html" title="struct inkwell::values::PointerValue">PointerValue</a><'ctx>,
|
||
args: &[<a class="enum" href="../values/enum.BasicMetadataValueEnum.html" title="enum inkwell::values::BasicMetadataValueEnum">BasicMetadataValueEnum</a><'ctx>],
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../values/struct.CallSiteValue.html" title="struct inkwell::values::CallSiteValue">CallSiteValue</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section></summary><div class="docblock"><p>Call a function pointer. Because a pointer does not carry a type, the type of the function
|
||
must be specified explicitly.</p>
|
||
<p>See <a href="../context/struct.Context.html#method.create_inline_asm" title="method inkwell::context::Context::create_inline_asm">Context::create_inline_asm</a> for a practical example. Basic usage looks like this:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>inkwell::context::Context;
|
||
|
||
<span class="comment">// A simple function which calls itself:
|
||
</span><span class="kw">let </span>context = Context::create();
|
||
<span class="kw">let </span>module = context.create_module(<span class="string">"ret"</span>);
|
||
<span class="kw">let </span>builder = context.create_builder();
|
||
<span class="kw">let </span>i32_type = context.i32_type();
|
||
<span class="kw">let </span>fn_type = i32_type.fn_type(<span class="kw-2">&</span>[i32_type.into()], <span class="bool-val">false</span>);
|
||
<span class="kw">let </span>fn_value = module.add_function(<span class="string">"ret"</span>, fn_type, <span class="prelude-val">None</span>);
|
||
<span class="kw">let </span>entry = context.append_basic_block(fn_value, <span class="string">"entry"</span>);
|
||
<span class="kw">let </span>i32_arg = fn_value.get_first_param().unwrap();
|
||
<span class="kw">let </span>md_string = context.metadata_string(<span class="string">"a metadata"</span>);
|
||
|
||
builder.position_at_end(entry);
|
||
|
||
<span class="kw">let </span>function_pointer = fn_value.as_global_value().as_pointer_value();
|
||
<span class="kw">let </span>ret_val = builder.build_indirect_call(fn_value.get_type(), function_pointer, <span class="kw-2">&</span>[i32_arg.into(), md_string.into()], <span class="string">"call"</span>).unwrap()
|
||
.try_as_basic_value()
|
||
.left()
|
||
.unwrap();
|
||
|
||
builder.build_return(<span class="prelude-val">Some</span>(<span class="kw-2">&</span>ret_val)).unwrap();</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.build_invoke" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#592-604">source</a><h4 class="code-header">pub fn <a href="#method.build_invoke" class="fn">build_invoke</a>(
|
||
&self,
|
||
function: <a class="struct" href="../values/struct.FunctionValue.html" title="struct inkwell::values::FunctionValue">FunctionValue</a><'ctx>,
|
||
args: &[<a class="enum" href="../values/enum.BasicValueEnum.html" title="enum inkwell::values::BasicValueEnum">BasicValueEnum</a><'ctx>],
|
||
then_block: <a class="struct" href="../basic_block/struct.BasicBlock.html" title="struct inkwell::basic_block::BasicBlock">BasicBlock</a><'ctx>,
|
||
catch_block: <a class="struct" href="../basic_block/struct.BasicBlock.html" title="struct inkwell::basic_block::BasicBlock">BasicBlock</a><'ctx>,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../values/struct.CallSiteValue.html" title="struct inkwell::values::CallSiteValue">CallSiteValue</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section></summary><div class="docblock"><p>An invoke is similar to a normal function call, but used to
|
||
call functions that may throw an exception, and then respond to the exception.</p>
|
||
<p>When the called function returns normally, the <code>then</code> block is evaluated next. If instead
|
||
the function threw an exception, the <code>catch</code> block is entered. The first non-phi
|
||
instruction of the catch block must be a <code>landingpad</code> instruction. See also
|
||
<a href="struct.Builder.html#method.build_landing_pad" title="method inkwell::builder::Builder::build_landing_pad"><code>Builder::build_landing_pad</code></a>.</p>
|
||
<p>The <a href="crate::passes::PassManager::add_prune_eh_pass"><code>add_prune_eh_pass</code></a> turns an invoke into a call when the called function is
|
||
guaranteed to never throw an exception.</p>
|
||
<p>This example catches C++ exceptions of type <code>int</code>, and returns <code>0</code> if an exceptions is thrown.
|
||
For usage of a cleanup landing pad and the <code>resume</code> instruction, see <a href="struct.Builder.html#method.build_resume" title="method inkwell::builder::Builder::build_resume"><code>Builder::build_resume</code></a></p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>inkwell::context::Context;
|
||
<span class="kw">use </span>inkwell::AddressSpace;
|
||
<span class="kw">use </span>inkwell::module::Linkage;
|
||
|
||
<span class="kw">let </span>context = Context::create();
|
||
<span class="kw">let </span>module = context.create_module(<span class="string">"sum"</span>);
|
||
<span class="kw">let </span>builder = context.create_builder();
|
||
|
||
<span class="kw">let </span>f32_type = context.f32_type();
|
||
<span class="kw">let </span>fn_type = f32_type.fn_type(<span class="kw-2">&</span>[], <span class="bool-val">false</span>);
|
||
|
||
<span class="comment">// we will pretend this function can throw an exception
|
||
</span><span class="kw">let </span>function = module.add_function(<span class="string">"bomb"</span>, fn_type, <span class="prelude-val">None</span>);
|
||
<span class="kw">let </span>basic_block = context.append_basic_block(function, <span class="string">"entry"</span>);
|
||
|
||
builder.position_at_end(basic_block);
|
||
|
||
<span class="kw">let </span>pi = f32_type.const_float(::std::f64::consts::PI);
|
||
|
||
builder.build_return(<span class="prelude-val">Some</span>(<span class="kw-2">&</span>pi)).unwrap();
|
||
|
||
<span class="kw">let </span>function2 = module.add_function(<span class="string">"wrapper"</span>, fn_type, <span class="prelude-val">None</span>);
|
||
<span class="kw">let </span>basic_block2 = context.append_basic_block(function2, <span class="string">"entry"</span>);
|
||
|
||
builder.position_at_end(basic_block2);
|
||
|
||
<span class="kw">let </span>then_block = context.append_basic_block(function2, <span class="string">"then_block"</span>);
|
||
<span class="kw">let </span>catch_block = context.append_basic_block(function2, <span class="string">"catch_block"</span>);
|
||
|
||
<span class="kw">let </span>call_site = builder.build_invoke(function, <span class="kw-2">&</span>[], then_block, catch_block, <span class="string">"get_pi"</span>).unwrap();
|
||
|
||
{
|
||
builder.position_at_end(then_block);
|
||
|
||
<span class="comment">// in the then_block, the `call_site` value is defined and can be used
|
||
</span><span class="kw">let </span>result = call_site.try_as_basic_value().left().unwrap();
|
||
|
||
builder.build_return(<span class="prelude-val">Some</span>(<span class="kw-2">&</span>result)).unwrap();
|
||
}
|
||
|
||
{
|
||
builder.position_at_end(catch_block);
|
||
|
||
<span class="comment">// the personality function used by C++
|
||
</span><span class="kw">let </span>personality_function = {
|
||
<span class="kw">let </span>name = <span class="string">"__gxx_personality_v0"</span>;
|
||
<span class="kw">let </span>linkage = <span class="prelude-val">Some</span>(Linkage::External);
|
||
|
||
module.add_function(name, context.i64_type().fn_type(<span class="kw-2">&</span>[], <span class="bool-val">false</span>), linkage)
|
||
};
|
||
|
||
<span class="comment">// type of an exception in C++
|
||
</span><span class="kw">let </span>ptr_type = context.ptr_type(AddressSpace::default());
|
||
<span class="kw">let </span>i32_type = context.i32_type();
|
||
<span class="kw">let </span>exception_type = context.struct_type(<span class="kw-2">&</span>[ptr_type.into(), i32_type.into()], <span class="bool-val">false</span>);
|
||
|
||
<span class="kw">let </span>null = ptr_type.const_zero();
|
||
<span class="kw">let </span>res = builder.build_landing_pad(exception_type, personality_function, <span class="kw-2">&</span>[null.into()], <span class="bool-val">false</span>, <span class="string">"res"</span>).unwrap();
|
||
|
||
<span class="comment">// we handle the exception by returning a default value
|
||
</span>builder.build_return(<span class="prelude-val">Some</span>(<span class="kw-2">&</span>f32_type.const_zero())).unwrap();
|
||
}</code></pre></div>
|
||
</div></details><section id="method.build_direct_invoke" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#607-626">source</a><h4 class="code-header">pub fn <a href="#method.build_direct_invoke" class="fn">build_direct_invoke</a>(
|
||
&self,
|
||
function: <a class="struct" href="../values/struct.FunctionValue.html" title="struct inkwell::values::FunctionValue">FunctionValue</a><'ctx>,
|
||
args: &[<a class="enum" href="../values/enum.BasicValueEnum.html" title="enum inkwell::values::BasicValueEnum">BasicValueEnum</a><'ctx>],
|
||
then_block: <a class="struct" href="../basic_block/struct.BasicBlock.html" title="struct inkwell::basic_block::BasicBlock">BasicBlock</a><'ctx>,
|
||
catch_block: <a class="struct" href="../basic_block/struct.BasicBlock.html" title="struct inkwell::basic_block::BasicBlock">BasicBlock</a><'ctx>,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../values/struct.CallSiteValue.html" title="struct inkwell::values::CallSiteValue">CallSiteValue</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_indirect_invoke" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#629-649">source</a><h4 class="code-header">pub fn <a href="#method.build_indirect_invoke" class="fn">build_indirect_invoke</a>(
|
||
&self,
|
||
function_type: <a class="struct" href="../types/struct.FunctionType.html" title="struct inkwell::types::FunctionType">FunctionType</a><'ctx>,
|
||
function_pointer: <a class="struct" href="../values/struct.PointerValue.html" title="struct inkwell::values::PointerValue">PointerValue</a><'ctx>,
|
||
args: &[<a class="enum" href="../values/enum.BasicValueEnum.html" title="enum inkwell::values::BasicValueEnum">BasicValueEnum</a><'ctx>],
|
||
then_block: <a class="struct" href="../basic_block/struct.BasicBlock.html" title="struct inkwell::basic_block::BasicBlock">BasicBlock</a><'ctx>,
|
||
catch_block: <a class="struct" href="../basic_block/struct.BasicBlock.html" title="struct inkwell::basic_block::BasicBlock">BasicBlock</a><'ctx>,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../values/struct.CallSiteValue.html" title="struct inkwell::values::CallSiteValue">CallSiteValue</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><details class="toggle method-toggle" open><summary><section id="method.build_landing_pad" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#839-877">source</a><h4 class="code-header">pub fn <a href="#method.build_landing_pad" class="fn">build_landing_pad</a><T>(
|
||
&self,
|
||
exception_type: T,
|
||
personality_function: <a class="struct" href="../values/struct.FunctionValue.html" title="struct inkwell::values::FunctionValue">FunctionValue</a><'ctx>,
|
||
clauses: &[<a class="enum" href="../values/enum.BasicValueEnum.html" title="enum inkwell::values::BasicValueEnum">BasicValueEnum</a><'ctx>],
|
||
is_cleanup: <a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.bool.html">bool</a>,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="enum" href="../values/enum.BasicValueEnum.html" title="enum inkwell::values::BasicValueEnum">BasicValueEnum</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>><div class="where">where
|
||
T: <a class="trait" href="../types/trait.BasicType.html" title="trait inkwell::types::BasicType">BasicType</a><'ctx>,</div></h4></section></summary><div class="docblock"><p>Landing pads are places where control flow jumps to if a <a href="struct.Builder.html#method.build_invoke" title="method inkwell::builder::Builder::build_invoke"><code>Builder::build_invoke</code></a> triggered an exception.
|
||
The landing pad will match the exception against its <em>clauses</em>. Depending on the clause
|
||
that is matched, the exception can then be handled, or resumed after some optional cleanup,
|
||
causing the exception to bubble up.</p>
|
||
<p>Exceptions in LLVM are designed based on the needs of a C++ compiler, but can be used more generally.
|
||
Here are some specific examples of landing pads. For a full example of handling an exception, see <a href="struct.Builder.html#method.build_invoke" title="method inkwell::builder::Builder::build_invoke"><code>Builder::build_invoke</code></a>.</p>
|
||
<ul>
|
||
<li><strong>cleanup</strong>: a cleanup landing pad is always visited when unwinding the stack.
|
||
A cleanup is extra code that needs to be run when unwinding a scope. C++ destructors are a typical example.
|
||
In a language with reference counting, the cleanup block can decrement the refcount of values in scope.
|
||
The <a href="struct.Builder.html#method.build_resume" title="method inkwell::builder::Builder::build_resume"><code>Builder::build_resume</code></a> function has a full example using a cleanup lading pad.</li>
|
||
</ul>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>inkwell::context::Context;
|
||
<span class="kw">use </span>inkwell::AddressSpace;
|
||
<span class="kw">use </span>inkwell::module::Linkage;
|
||
|
||
<span class="kw">let </span>context = Context::create();
|
||
<span class="kw">let </span>module = context.create_module(<span class="string">"sum"</span>);
|
||
<span class="kw">let </span>builder = context.create_builder();
|
||
|
||
<span class="comment">// type of an exception in C++
|
||
</span><span class="attr">#[cfg(not(any(feature = <span class="string">"llvm15-0"</span>, feature = <span class="string">"llvm16-0"</span>, feature = <span class="string">"llvm17-0"</span>, feature = <span class="string">"llvm18-0"</span>)))]
|
||
</span><span class="kw">let </span>i8_ptr_type = context.i8_type().ptr_type(AddressSpace::default());
|
||
<span class="attr">#[cfg(any(feature = <span class="string">"llvm15-0"</span>, feature = <span class="string">"llvm16-0"</span>, feature = <span class="string">"llvm17-0"</span>, feature = <span class="string">"llvm18-0"</span>))]
|
||
</span><span class="kw">let </span>i8_ptr_type = context.ptr_type(AddressSpace::default());
|
||
<span class="kw">let </span>i32_type = context.i32_type();
|
||
<span class="kw">let </span>exception_type = context.struct_type(<span class="kw-2">&</span>[i8_ptr_type.into(), i32_type.into()], <span class="bool-val">false</span>);
|
||
|
||
<span class="comment">// the personality function used by C++
|
||
</span><span class="kw">let </span>personality_function = {
|
||
<span class="kw">let </span>name = <span class="string">"__gxx_personality_v0"</span>;
|
||
<span class="kw">let </span>linkage = <span class="prelude-val">Some</span>(Linkage::External);
|
||
|
||
module.add_function(name, context.i64_type().fn_type(<span class="kw-2">&</span>[], <span class="bool-val">false</span>), linkage)
|
||
};
|
||
|
||
<span class="comment">// make the cleanup landing pad
|
||
</span><span class="kw">let </span>res = builder.build_landing_pad( exception_type, personality_function, <span class="kw-2">&</span>[], <span class="bool-val">true</span>, <span class="string">"res"</span>).unwrap();</code></pre></div>
|
||
<ul>
|
||
<li><strong>catch all</strong>: An implementation of the C++ <code>catch(...)</code>, which catches all exceptions.
|
||
A catch clause with a NULL pointer value will match anything.</li>
|
||
</ul>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>inkwell::context::Context;
|
||
<span class="kw">use </span>inkwell::AddressSpace;
|
||
<span class="kw">use </span>inkwell::module::Linkage;
|
||
|
||
<span class="kw">let </span>context = Context::create();
|
||
<span class="kw">let </span>module = context.create_module(<span class="string">"sum"</span>);
|
||
<span class="kw">let </span>builder = context.create_builder();
|
||
|
||
<span class="comment">// type of an exception in C++
|
||
</span><span class="attr">#[cfg(not(any(feature = <span class="string">"llvm15-0"</span>, feature = <span class="string">"llvm16-0"</span>, feature = <span class="string">"llvm17-0"</span>, feature = <span class="string">"llvm18-0"</span>)))]
|
||
</span><span class="kw">let </span>i8_ptr_type = context.i8_type().ptr_type(AddressSpace::default());
|
||
<span class="attr">#[cfg(any(feature = <span class="string">"llvm15-0"</span>, feature = <span class="string">"llvm16-0"</span>, feature = <span class="string">"llvm17-0"</span>, feature = <span class="string">"llvm18-0"</span>))]
|
||
</span><span class="kw">let </span>i8_ptr_type = context.ptr_type(AddressSpace::default());
|
||
<span class="kw">let </span>i32_type = context.i32_type();
|
||
<span class="kw">let </span>exception_type = context.struct_type(<span class="kw-2">&</span>[i8_ptr_type.into(), i32_type.into()], <span class="bool-val">false</span>);
|
||
|
||
<span class="comment">// the personality function used by C++
|
||
</span><span class="kw">let </span>personality_function = {
|
||
<span class="kw">let </span>name = <span class="string">"__gxx_personality_v0"</span>;
|
||
<span class="kw">let </span>linkage = <span class="prelude-val">Some</span>(Linkage::External);
|
||
|
||
module.add_function(name, context.i64_type().fn_type(<span class="kw-2">&</span>[], <span class="bool-val">false</span>), linkage)
|
||
};
|
||
|
||
<span class="comment">// make a null pointer of type i8
|
||
</span><span class="kw">let </span>null = i8_ptr_type.const_zero();
|
||
|
||
<span class="comment">// make the catch all landing pad
|
||
</span><span class="kw">let </span>res = builder.build_landing_pad(exception_type, personality_function, <span class="kw-2">&</span>[null.into()], <span class="bool-val">false</span>, <span class="string">"res"</span>).unwrap();</code></pre></div>
|
||
<ul>
|
||
<li><strong>catch a type of exception</strong>: Catch a specific type of exception. The example uses C++’s type info.</li>
|
||
</ul>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>inkwell::context::Context;
|
||
<span class="kw">use </span>inkwell::module::Linkage;
|
||
<span class="kw">use </span>inkwell::AddressSpace;
|
||
<span class="kw">use </span>inkwell::values::BasicValue;
|
||
|
||
<span class="kw">let </span>context = Context::create();
|
||
<span class="kw">let </span>module = context.create_module(<span class="string">"sum"</span>);
|
||
<span class="kw">let </span>builder = context.create_builder();
|
||
|
||
<span class="comment">// type of an exception in C++
|
||
</span><span class="attr">#[cfg(not(any(feature = <span class="string">"llvm15-0"</span>, feature = <span class="string">"llvm16-0"</span>, feature = <span class="string">"llvm17-0"</span>, feature = <span class="string">"llvm18-0"</span>)))]
|
||
</span><span class="kw">let </span>i8_ptr_type = context.i8_type().ptr_type(AddressSpace::default());
|
||
<span class="attr">#[cfg(any(feature = <span class="string">"llvm15-0"</span>, feature = <span class="string">"llvm16-0"</span>, feature = <span class="string">"llvm17-0"</span>, feature = <span class="string">"llvm18-0"</span>))]
|
||
</span><span class="kw">let </span>i8_ptr_type = context.ptr_type(AddressSpace::default());
|
||
<span class="kw">let </span>i32_type = context.i32_type();
|
||
<span class="kw">let </span>exception_type = context.struct_type(<span class="kw-2">&</span>[i8_ptr_type.into(), i32_type.into()], <span class="bool-val">false</span>);
|
||
|
||
<span class="comment">// the personality function used by C++
|
||
</span><span class="kw">let </span>personality_function = {
|
||
<span class="kw">let </span>name = <span class="string">"__gxx_personality_v0"</span>;
|
||
<span class="kw">let </span>linkage = <span class="prelude-val">Some</span>(Linkage::External);
|
||
|
||
module.add_function(name, context.i64_type().fn_type(<span class="kw-2">&</span>[], <span class="bool-val">false</span>), linkage)
|
||
};
|
||
|
||
<span class="comment">// link in the C++ type info for the `int` type
|
||
</span><span class="kw">let </span>type_info_int = module.add_global(i8_ptr_type, <span class="prelude-val">Some</span>(AddressSpace::default()), <span class="string">"_ZTIi"</span>);
|
||
type_info_int.set_linkage(Linkage::External);
|
||
|
||
<span class="comment">// make the catch landing pad
|
||
</span><span class="kw">let </span>clause = type_info_int.as_basic_value_enum();
|
||
<span class="kw">let </span>res = builder.build_landing_pad(exception_type, personality_function, <span class="kw-2">&</span>[clause], <span class="bool-val">false</span>, <span class="string">"res"</span>).unwrap();</code></pre></div>
|
||
<ul>
|
||
<li><strong>filter</strong>: A filter clause encodes that only some types of exceptions are valid at this
|
||
point. A filter clause is made by constructing a clause from a constant array.</li>
|
||
</ul>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>inkwell::context::Context;
|
||
<span class="kw">use </span>inkwell::module::Linkage;
|
||
<span class="kw">use </span>inkwell::values::AnyValue;
|
||
<span class="kw">use </span>inkwell::AddressSpace;
|
||
|
||
<span class="kw">let </span>context = Context::create();
|
||
<span class="kw">let </span>module = context.create_module(<span class="string">"sum"</span>);
|
||
<span class="kw">let </span>builder = context.create_builder();
|
||
|
||
<span class="comment">// type of an exception in C++
|
||
</span><span class="attr">#[cfg(not(any(feature = <span class="string">"llvm15-0"</span>, feature = <span class="string">"llvm16-0"</span>, feature = <span class="string">"llvm17-0"</span>, feature = <span class="string">"llvm18-0"</span>)))]
|
||
</span><span class="kw">let </span>i8_ptr_type = context.i8_type().ptr_type(AddressSpace::default());
|
||
<span class="attr">#[cfg(any(feature = <span class="string">"llvm15-0"</span>, feature = <span class="string">"llvm16-0"</span>, feature = <span class="string">"llvm17-0"</span>, feature = <span class="string">"llvm18-0"</span>))]
|
||
</span><span class="kw">let </span>i8_ptr_type = context.ptr_type(AddressSpace::default());
|
||
<span class="kw">let </span>i32_type = context.i32_type();
|
||
<span class="kw">let </span>exception_type = context.struct_type(<span class="kw-2">&</span>[i8_ptr_type.into(), i32_type.into()], <span class="bool-val">false</span>);
|
||
|
||
<span class="comment">// the personality function used by C++
|
||
</span><span class="kw">let </span>personality_function = {
|
||
<span class="kw">let </span>name = <span class="string">"__gxx_personality_v0"</span>;
|
||
<span class="kw">let </span>linkage = <span class="prelude-val">Some</span>(Linkage::External);
|
||
|
||
module.add_function(name, context.i64_type().fn_type(<span class="kw-2">&</span>[], <span class="bool-val">false</span>), linkage)
|
||
};
|
||
|
||
<span class="comment">// link in the C++ type info for the `int` type
|
||
</span><span class="kw">let </span>type_info_int = module.add_global(i8_ptr_type, <span class="prelude-val">Some</span>(AddressSpace::default()), <span class="string">"_ZTIi"</span>);
|
||
type_info_int.set_linkage(Linkage::External);
|
||
|
||
<span class="comment">// make the filter landing pad
|
||
</span><span class="kw">let </span>filter_pattern = i8_ptr_type.const_array(<span class="kw-2">&</span>[type_info_int.as_any_value_enum().into_pointer_value()]);
|
||
<span class="kw">let </span>res = builder.build_landing_pad(exception_type, personality_function, <span class="kw-2">&</span>[filter_pattern.into()], <span class="bool-val">false</span>, <span class="string">"res"</span>).unwrap();</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.build_resume" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#953-960">source</a><h4 class="code-header">pub fn <a href="#method.build_resume" class="fn">build_resume</a><V: <a class="trait" href="../values/trait.BasicValue.html" title="trait inkwell::values::BasicValue">BasicValue</a><'ctx>>(
|
||
&self,
|
||
value: V
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../values/struct.InstructionValue.html" title="struct inkwell::values::InstructionValue">InstructionValue</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section></summary><div class="docblock"><p>Resume propagation of an existing (in-flight) exception whose unwinding was interrupted with a landingpad instruction.</p>
|
||
<p>This example uses a cleanup landing pad. A cleanup is extra code that needs to be run when
|
||
unwinding a scope. C++ destructors are a typical example. In a language with reference counting,
|
||
the cleanup block can decrement the refcount of values in scope.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>inkwell::context::Context;
|
||
<span class="kw">use </span>inkwell::AddressSpace;
|
||
<span class="kw">use </span>inkwell::module::Linkage;
|
||
|
||
<span class="kw">let </span>context = Context::create();
|
||
<span class="kw">let </span>module = context.create_module(<span class="string">"sum"</span>);
|
||
<span class="kw">let </span>builder = context.create_builder();
|
||
|
||
<span class="kw">let </span>f32_type = context.f32_type();
|
||
<span class="kw">let </span>fn_type = f32_type.fn_type(<span class="kw-2">&</span>[], <span class="bool-val">false</span>);
|
||
|
||
<span class="comment">// we will pretend this function can throw an exception
|
||
</span><span class="kw">let </span>function = module.add_function(<span class="string">"bomb"</span>, fn_type, <span class="prelude-val">None</span>);
|
||
<span class="kw">let </span>basic_block = context.append_basic_block(function, <span class="string">"entry"</span>);
|
||
|
||
builder.position_at_end(basic_block);
|
||
|
||
<span class="kw">let </span>pi = f32_type.const_float(::std::f64::consts::PI);
|
||
|
||
builder.build_return(<span class="prelude-val">Some</span>(<span class="kw-2">&</span>pi)).unwrap();
|
||
|
||
<span class="kw">let </span>function2 = module.add_function(<span class="string">"wrapper"</span>, fn_type, <span class="prelude-val">None</span>);
|
||
<span class="kw">let </span>basic_block2 = context.append_basic_block(function2, <span class="string">"entry"</span>);
|
||
|
||
builder.position_at_end(basic_block2);
|
||
|
||
<span class="kw">let </span>then_block = context.append_basic_block(function2, <span class="string">"then_block"</span>);
|
||
<span class="kw">let </span>catch_block = context.append_basic_block(function2, <span class="string">"catch_block"</span>);
|
||
|
||
<span class="kw">let </span>call_site = builder.build_invoke(function, <span class="kw-2">&</span>[], then_block, catch_block, <span class="string">"get_pi"</span>).unwrap();
|
||
|
||
{
|
||
builder.position_at_end(then_block);
|
||
|
||
<span class="comment">// in the then_block, the `call_site` value is defined and can be used
|
||
</span><span class="kw">let </span>result = call_site.try_as_basic_value().left().unwrap();
|
||
|
||
builder.build_return(<span class="prelude-val">Some</span>(<span class="kw-2">&</span>result)).unwrap();
|
||
}
|
||
|
||
{
|
||
builder.position_at_end(catch_block);
|
||
|
||
<span class="comment">// the personality function used by C++
|
||
</span><span class="kw">let </span>personality_function = {
|
||
<span class="kw">let </span>name = <span class="string">"__gxx_personality_v0"</span>;
|
||
<span class="kw">let </span>linkage = <span class="prelude-val">Some</span>(Linkage::External);
|
||
|
||
module.add_function(name, context.i64_type().fn_type(<span class="kw-2">&</span>[], <span class="bool-val">false</span>), linkage)
|
||
};
|
||
|
||
<span class="comment">// type of an exception in C++
|
||
</span><span class="attr">#[cfg(not(any(feature = <span class="string">"llvm15-0"</span>, feature = <span class="string">"llvm16-0"</span>, feature = <span class="string">"llvm17-0"</span>, feature = <span class="string">"llvm18-0"</span>)))]
|
||
</span><span class="kw">let </span>i8_ptr_type = context.i8_type().ptr_type(AddressSpace::default());
|
||
<span class="attr">#[cfg(any(feature = <span class="string">"llvm15-0"</span>, feature = <span class="string">"llvm16-0"</span>, feature = <span class="string">"llvm17-0"</span>, feature = <span class="string">"llvm18-0"</span>))]
|
||
</span><span class="kw">let </span>i8_ptr_type = context.ptr_type(AddressSpace::default());
|
||
<span class="kw">let </span>i32_type = context.i32_type();
|
||
<span class="kw">let </span>exception_type = context.struct_type(<span class="kw-2">&</span>[i8_ptr_type.into(), i32_type.into()], <span class="bool-val">false</span>);
|
||
|
||
<span class="comment">// make the landing pad; must give a concrete type to the slice
|
||
</span><span class="kw">let </span>res = builder.build_landing_pad( exception_type, personality_function, <span class="kw-2">&</span>[], <span class="bool-val">true</span>, <span class="string">"res"</span>).unwrap();
|
||
|
||
<span class="comment">// do cleanup ...
|
||
|
||
</span>builder.build_resume(res).unwrap();
|
||
}</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.build_gep" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#992-1016">source</a><h4 class="code-header">pub unsafe fn <a href="#method.build_gep" class="fn">build_gep</a><T: <a class="trait" href="../types/trait.BasicType.html" title="trait inkwell::types::BasicType">BasicType</a><'ctx>>(
|
||
&self,
|
||
pointee_ty: T,
|
||
ptr: <a class="struct" href="../values/struct.PointerValue.html" title="struct inkwell::values::PointerValue">PointerValue</a><'ctx>,
|
||
ordered_indexes: &[<a class="struct" href="../values/struct.IntValue.html" title="struct inkwell::values::IntValue">IntValue</a><'ctx>],
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../values/struct.PointerValue.html" title="struct inkwell::values::PointerValue">PointerValue</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section></summary><div class="docblock"><p>GEP is very likely to segfault if indexes are used incorrectly, and is therefore an unsafe function. Maybe we can change this in the future.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.build_in_bounds_gep" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#1050-1074">source</a><h4 class="code-header">pub unsafe fn <a href="#method.build_in_bounds_gep" class="fn">build_in_bounds_gep</a><T: <a class="trait" href="../types/trait.BasicType.html" title="trait inkwell::types::BasicType">BasicType</a><'ctx>>(
|
||
&self,
|
||
pointee_ty: T,
|
||
ptr: <a class="struct" href="../values/struct.PointerValue.html" title="struct inkwell::values::PointerValue">PointerValue</a><'ctx>,
|
||
ordered_indexes: &[<a class="struct" href="../values/struct.IntValue.html" title="struct inkwell::values::IntValue">IntValue</a><'ctx>],
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../values/struct.PointerValue.html" title="struct inkwell::values::PointerValue">PointerValue</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section></summary><div class="docblock"><p>GEP is very likely to segfault if indexes are used incorrectly, and is therefore an unsafe function. Maybe we can change this in the future.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.build_struct_gep" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#1179-1214">source</a><h4 class="code-header">pub fn <a href="#method.build_struct_gep" class="fn">build_struct_gep</a><T: <a class="trait" href="../types/trait.BasicType.html" title="trait inkwell::types::BasicType">BasicType</a><'ctx>>(
|
||
&self,
|
||
pointee_ty: T,
|
||
ptr: <a class="struct" href="../values/struct.PointerValue.html" title="struct inkwell::values::PointerValue">PointerValue</a><'ctx>,
|
||
index: <a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.u32.html">u32</a>,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../values/struct.PointerValue.html" title="struct inkwell::values::PointerValue">PointerValue</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section></summary><div class="docblock"><p>Builds a GEP instruction on a struct pointer. Returns <code>Err</code> <code>BuilderError::GEPPointee</code> or <code>BuilderError::GEPIndex</code> if input <code>PointerValue</code> doesn’t
|
||
point to a struct or if index is out of bounds.</p>
|
||
<h5 id="example-3"><a class="doc-anchor" href="#example-3">§</a>Example</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>inkwell::AddressSpace;
|
||
<span class="kw">use </span>inkwell::context::Context;
|
||
|
||
<span class="kw">let </span>context = Context::create();
|
||
<span class="kw">let </span>builder = context.create_builder();
|
||
<span class="kw">let </span>module = context.create_module(<span class="string">"struct_gep"</span>);
|
||
<span class="kw">let </span>void_type = context.void_type();
|
||
<span class="kw">let </span>i32_ty = context.i32_type();
|
||
<span class="attr">#[cfg(not(any(feature = <span class="string">"llvm15-0"</span>, feature = <span class="string">"llvm16-0"</span>, feature = <span class="string">"llvm17-0"</span>, feature = <span class="string">"llvm18-0"</span>)))]
|
||
</span><span class="kw">let </span>i32_ptr_ty = i32_ty.ptr_type(AddressSpace::default());
|
||
<span class="attr">#[cfg(any(feature = <span class="string">"llvm15-0"</span>, feature = <span class="string">"llvm16-0"</span>, feature = <span class="string">"llvm17-0"</span>, feature = <span class="string">"llvm18-0"</span>))]
|
||
</span><span class="kw">let </span>i32_ptr_ty = context.ptr_type(AddressSpace::default());
|
||
<span class="kw">let </span>field_types = <span class="kw-2">&</span>[i32_ty.into(), i32_ty.into()];
|
||
<span class="kw">let </span>struct_ty = context.struct_type(field_types, <span class="bool-val">false</span>);
|
||
<span class="kw">let </span>struct_ptr_ty = struct_ty.ptr_type(AddressSpace::default());
|
||
<span class="kw">let </span>fn_type = void_type.fn_type(<span class="kw-2">&</span>[i32_ptr_ty.into(), struct_ptr_ty.into()], <span class="bool-val">false</span>);
|
||
<span class="kw">let </span>fn_value = module.add_function(<span class="string">""</span>, fn_type, <span class="prelude-val">None</span>);
|
||
<span class="kw">let </span>entry = context.append_basic_block(fn_value, <span class="string">"entry"</span>);
|
||
|
||
builder.position_at_end(entry);
|
||
|
||
<span class="kw">let </span>i32_ptr = fn_value.get_first_param().unwrap().into_pointer_value();
|
||
<span class="kw">let </span>struct_ptr = fn_value.get_last_param().unwrap().into_pointer_value();
|
||
|
||
<span class="macro">assert!</span>(builder.build_struct_gep(i32_ty, i32_ptr, <span class="number">0</span>, <span class="string">"struct_gep"</span>).is_err());
|
||
<span class="macro">assert!</span>(builder.build_struct_gep(i32_ty, i32_ptr, <span class="number">10</span>, <span class="string">"struct_gep"</span>).is_err());
|
||
<span class="macro">assert!</span>(builder.build_struct_gep(struct_ty, struct_ptr, <span class="number">0</span>, <span class="string">"struct_gep"</span>).is_ok());
|
||
<span class="macro">assert!</span>(builder.build_struct_gep(struct_ty, struct_ptr, <span class="number">1</span>, <span class="string">"struct_gep"</span>).is_ok());
|
||
<span class="macro">assert!</span>(builder.build_struct_gep(struct_ty, struct_ptr, <span class="number">2</span>, <span class="string">"struct_gep"</span>).is_err());</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.build_ptr_diff" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#1296-1319">source</a><h4 class="code-header">pub fn <a href="#method.build_ptr_diff" class="fn">build_ptr_diff</a><T: <a class="trait" href="../types/trait.BasicType.html" title="trait inkwell::types::BasicType">BasicType</a><'ctx>>(
|
||
&self,
|
||
pointee_ty: T,
|
||
lhs_ptr: <a class="struct" href="../values/struct.PointerValue.html" title="struct inkwell::values::PointerValue">PointerValue</a><'ctx>,
|
||
rhs_ptr: <a class="struct" href="../values/struct.PointerValue.html" title="struct inkwell::values::PointerValue">PointerValue</a><'ctx>,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../values/struct.IntValue.html" title="struct inkwell::values::IntValue">IntValue</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section></summary><div class="docblock"><p>Builds an instruction which calculates the difference of two pointers.</p>
|
||
<h5 id="example-4"><a class="doc-anchor" href="#example-4">§</a>Example</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>inkwell::context::Context;
|
||
<span class="kw">use </span>inkwell::AddressSpace;
|
||
|
||
<span class="comment">// Builds a function which diffs two pointers
|
||
</span><span class="kw">let </span>context = Context::create();
|
||
<span class="kw">let </span>module = context.create_module(<span class="string">"ret"</span>);
|
||
<span class="kw">let </span>builder = context.create_builder();
|
||
<span class="kw">let </span>void_type = context.void_type();
|
||
<span class="kw">let </span>i32_type = context.i32_type();
|
||
<span class="attr">#[cfg(not(any(feature = <span class="string">"llvm15-0"</span>, feature = <span class="string">"llvm16-0"</span>, feature = <span class="string">"llvm17-0"</span>, feature = <span class="string">"llvm18-0"</span>)))]
|
||
</span><span class="kw">let </span>i32_ptr_type = i32_type.ptr_type(AddressSpace::default());
|
||
<span class="attr">#[cfg(any(feature = <span class="string">"llvm15-0"</span>, feature = <span class="string">"llvm16-0"</span>, feature = <span class="string">"llvm17-0"</span>, feature = <span class="string">"llvm18-0"</span>))]
|
||
</span><span class="kw">let </span>i32_ptr_type = context.ptr_type(AddressSpace::default());
|
||
<span class="kw">let </span>fn_type = void_type.fn_type(<span class="kw-2">&</span>[i32_ptr_type.into(), i32_ptr_type.into()], <span class="bool-val">false</span>);
|
||
<span class="kw">let </span>fn_value = module.add_function(<span class="string">"ret"</span>, fn_type, <span class="prelude-val">None</span>);
|
||
<span class="kw">let </span>entry = context.append_basic_block(fn_value, <span class="string">"entry"</span>);
|
||
<span class="kw">let </span>i32_ptr_param1 = fn_value.get_first_param().unwrap().into_pointer_value();
|
||
<span class="kw">let </span>i32_ptr_param2 = fn_value.get_nth_param(<span class="number">1</span>).unwrap().into_pointer_value();
|
||
|
||
builder.position_at_end(entry);
|
||
builder.build_ptr_diff(i32_ptr_type, i32_ptr_param1, i32_ptr_param2, <span class="string">"diff"</span>).unwrap();
|
||
builder.build_return(<span class="prelude-val">None</span>).unwrap();</code></pre></div>
|
||
</div></details><section id="method.build_phi" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#1326-1334">source</a><h4 class="code-header">pub fn <a href="#method.build_phi" class="fn">build_phi</a><T: <a class="trait" href="../types/trait.BasicType.html" title="trait inkwell::types::BasicType">BasicType</a><'ctx>>(
|
||
&self,
|
||
type_: T,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../values/struct.PhiValue.html" title="struct inkwell::values::PhiValue">PhiValue</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><details class="toggle method-toggle" open><summary><section id="method.build_store" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#1364-1375">source</a><h4 class="code-header">pub fn <a href="#method.build_store" class="fn">build_store</a><V: <a class="trait" href="../values/trait.BasicValue.html" title="trait inkwell::values::BasicValue">BasicValue</a><'ctx>>(
|
||
&self,
|
||
ptr: <a class="struct" href="../values/struct.PointerValue.html" title="struct inkwell::values::PointerValue">PointerValue</a><'ctx>,
|
||
value: V
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../values/struct.InstructionValue.html" title="struct inkwell::values::InstructionValue">InstructionValue</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section></summary><div class="docblock"><p>Builds a store instruction. It allows you to store a value of type <code>T</code> in a pointer to a type <code>T</code>.</p>
|
||
<h5 id="example-5"><a class="doc-anchor" href="#example-5">§</a>Example</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>inkwell::context::Context;
|
||
<span class="kw">use </span>inkwell::AddressSpace;
|
||
|
||
<span class="comment">// Builds a function which takes an i32 pointer and stores a 7 in it.
|
||
</span><span class="kw">let </span>context = Context::create();
|
||
<span class="kw">let </span>module = context.create_module(<span class="string">"ret"</span>);
|
||
<span class="kw">let </span>builder = context.create_builder();
|
||
<span class="kw">let </span>void_type = context.void_type();
|
||
<span class="kw">let </span>i32_type = context.i32_type();
|
||
<span class="attr">#[cfg(not(any(feature = <span class="string">"llvm15-0"</span>, feature = <span class="string">"llvm16-0"</span>, feature = <span class="string">"llvm17-0"</span>, feature = <span class="string">"llvm18-0"</span>)))]
|
||
</span><span class="kw">let </span>i32_ptr_type = i32_type.ptr_type(AddressSpace::default());
|
||
<span class="attr">#[cfg(any(feature = <span class="string">"llvm15-0"</span>, feature = <span class="string">"llvm16-0"</span>, feature = <span class="string">"llvm17-0"</span>, feature = <span class="string">"llvm18-0"</span>))]
|
||
</span><span class="kw">let </span>i32_ptr_type = context.ptr_type(AddressSpace::default());
|
||
<span class="kw">let </span>i32_seven = i32_type.const_int(<span class="number">7</span>, <span class="bool-val">false</span>);
|
||
<span class="kw">let </span>fn_type = void_type.fn_type(<span class="kw-2">&</span>[i32_ptr_type.into()], <span class="bool-val">false</span>);
|
||
<span class="kw">let </span>fn_value = module.add_function(<span class="string">"ret"</span>, fn_type, <span class="prelude-val">None</span>);
|
||
<span class="kw">let </span>entry = context.append_basic_block(fn_value, <span class="string">"entry"</span>);
|
||
<span class="kw">let </span>i32_ptr_param = fn_value.get_first_param().unwrap().into_pointer_value();
|
||
|
||
builder.position_at_end(entry);
|
||
builder.build_store(i32_ptr_param, i32_seven).unwrap();
|
||
builder.build_return(<span class="prelude-val">None</span>).unwrap();</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.build_load" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#1446-1467">source</a><h4 class="code-header">pub fn <a href="#method.build_load" class="fn">build_load</a><T: <a class="trait" href="../types/trait.BasicType.html" title="trait inkwell::types::BasicType">BasicType</a><'ctx>>(
|
||
&self,
|
||
pointee_ty: T,
|
||
ptr: <a class="struct" href="../values/struct.PointerValue.html" title="struct inkwell::values::PointerValue">PointerValue</a><'ctx>,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="enum" href="../values/enum.BasicValueEnum.html" title="enum inkwell::values::BasicValueEnum">BasicValueEnum</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section></summary><div class="docblock"><p>Builds a load2 instruction. It allows you to retrieve a value of type <code>T</code> from a pointer to a type <code>T</code>.</p>
|
||
<h5 id="example-6"><a class="doc-anchor" href="#example-6">§</a>Example</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>inkwell::context::Context;
|
||
<span class="kw">use </span>inkwell::AddressSpace;
|
||
|
||
<span class="comment">// Builds a function which takes an i32 pointer and returns the pointed at i32.
|
||
</span><span class="kw">let </span>context = Context::create();
|
||
<span class="kw">let </span>module = context.create_module(<span class="string">"ret"</span>);
|
||
<span class="kw">let </span>builder = context.create_builder();
|
||
<span class="kw">let </span>i32_type = context.i32_type();
|
||
<span class="attr">#[cfg(not(any(feature = <span class="string">"llvm15-0"</span>, feature = <span class="string">"llvm16-0"</span>, feature = <span class="string">"llvm17-0"</span>, feature = <span class="string">"llvm18-0"</span>)))]
|
||
</span><span class="kw">let </span>i32_ptr_type = i32_type.ptr_type(AddressSpace::default());
|
||
<span class="attr">#[cfg(any(feature = <span class="string">"llvm15-0"</span>, feature = <span class="string">"llvm16-0"</span>, feature = <span class="string">"llvm17-0"</span>, feature = <span class="string">"llvm18-0"</span>))]
|
||
</span><span class="kw">let </span>i32_ptr_type = context.ptr_type(AddressSpace::default());
|
||
<span class="kw">let </span>fn_type = i32_type.fn_type(<span class="kw-2">&</span>[i32_ptr_type.into()], <span class="bool-val">false</span>);
|
||
<span class="kw">let </span>fn_value = module.add_function(<span class="string">"ret"</span>, fn_type, <span class="prelude-val">None</span>);
|
||
<span class="kw">let </span>entry = context.append_basic_block(fn_value, <span class="string">"entry"</span>);
|
||
<span class="kw">let </span>i32_ptr_param = fn_value.get_first_param().unwrap().into_pointer_value();
|
||
|
||
builder.position_at_end(entry);
|
||
|
||
<span class="kw">let </span>pointee = builder.build_load(i32_type, i32_ptr_param, <span class="string">"load2"</span>).unwrap();
|
||
|
||
builder.build_return(<span class="prelude-val">Some</span>(<span class="kw-2">&</span>pointee)).unwrap();</code></pre></div>
|
||
</div></details><section id="method.build_alloca" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#1470-1478">source</a><h4 class="code-header">pub fn <a href="#method.build_alloca" class="fn">build_alloca</a><T: <a class="trait" href="../types/trait.BasicType.html" title="trait inkwell::types::BasicType">BasicType</a><'ctx>>(
|
||
&self,
|
||
ty: T,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../values/struct.PointerValue.html" title="struct inkwell::values::PointerValue">PointerValue</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_array_alloca" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#1481-1495">source</a><h4 class="code-header">pub fn <a href="#method.build_array_alloca" class="fn">build_array_alloca</a><T: <a class="trait" href="../types/trait.BasicType.html" title="trait inkwell::types::BasicType">BasicType</a><'ctx>>(
|
||
&self,
|
||
ty: T,
|
||
size: <a class="struct" href="../values/struct.IntValue.html" title="struct inkwell::values::IntValue">IntValue</a><'ctx>,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../values/struct.PointerValue.html" title="struct inkwell::values::PointerValue">PointerValue</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><details class="toggle method-toggle" open><summary><section id="method.build_memcpy" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#1508-1543">source</a><h4 class="code-header">pub fn <a href="#method.build_memcpy" class="fn">build_memcpy</a>(
|
||
&self,
|
||
dest: <a class="struct" href="../values/struct.PointerValue.html" title="struct inkwell::values::PointerValue">PointerValue</a><'ctx>,
|
||
dest_align_bytes: <a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.u32.html">u32</a>,
|
||
src: <a class="struct" href="../values/struct.PointerValue.html" title="struct inkwell::values::PointerValue">PointerValue</a><'ctx>,
|
||
src_align_bytes: <a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.u32.html">u32</a>,
|
||
size: <a class="struct" href="../values/struct.IntValue.html" title="struct inkwell::values::IntValue">IntValue</a><'ctx>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../values/struct.PointerValue.html" title="struct inkwell::values::PointerValue">PointerValue</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section></summary><div class="docblock"><p>Build a <a href="https://llvm.org/docs/LangRef.html#llvm-memcpy-intrinsic">memcpy</a> instruction.</p>
|
||
<p>Alignment arguments are specified in bytes, and should always be
|
||
both a power of 2 and under 2^64.</p>
|
||
<p>The final argument should be a pointer-sized integer.</p>
|
||
<p>Returns an <code>Err(BuilderError::AlignmentError)</code> if the source or destination alignments are not a power of 2.</p>
|
||
<p><a href="https://thedan64.github.io/inkwell/inkwell/targets/struct.TargetData.html#method.ptr_sized_int_type_in_context"><code>TargetData::ptr_sized_int_type_in_context</code></a> will get you one of those.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.build_memmove" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#1556-1591">source</a><h4 class="code-header">pub fn <a href="#method.build_memmove" class="fn">build_memmove</a>(
|
||
&self,
|
||
dest: <a class="struct" href="../values/struct.PointerValue.html" title="struct inkwell::values::PointerValue">PointerValue</a><'ctx>,
|
||
dest_align_bytes: <a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.u32.html">u32</a>,
|
||
src: <a class="struct" href="../values/struct.PointerValue.html" title="struct inkwell::values::PointerValue">PointerValue</a><'ctx>,
|
||
src_align_bytes: <a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.u32.html">u32</a>,
|
||
size: <a class="struct" href="../values/struct.IntValue.html" title="struct inkwell::values::IntValue">IntValue</a><'ctx>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../values/struct.PointerValue.html" title="struct inkwell::values::PointerValue">PointerValue</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section></summary><div class="docblock"><p>Build a <a href="http://llvm.org/docs/LangRef.html#llvm-memmove-intrinsic">memmove</a> instruction.</p>
|
||
<p>Alignment arguments are specified in bytes, and should always be
|
||
both a power of 2 and under 2^64.</p>
|
||
<p>The final argument should be a pointer-sized integer.</p>
|
||
<p>Returns an <code>Err(BuilderError::AlignmentError)</code> if the source or destination alignments are not a power of 2 under 2^64.</p>
|
||
<p><a href="https://thedan64.github.io/inkwell/inkwell/targets/struct.TargetData.html#method.ptr_sized_int_type_in_context"><code>TargetData::ptr_sized_int_type_in_context</code></a> will get you one of those.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.build_memset" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#1604-1631">source</a><h4 class="code-header">pub fn <a href="#method.build_memset" class="fn">build_memset</a>(
|
||
&self,
|
||
dest: <a class="struct" href="../values/struct.PointerValue.html" title="struct inkwell::values::PointerValue">PointerValue</a><'ctx>,
|
||
dest_align_bytes: <a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.u32.html">u32</a>,
|
||
val: <a class="struct" href="../values/struct.IntValue.html" title="struct inkwell::values::IntValue">IntValue</a><'ctx>,
|
||
size: <a class="struct" href="../values/struct.IntValue.html" title="struct inkwell::values::IntValue">IntValue</a><'ctx>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../values/struct.PointerValue.html" title="struct inkwell::values::PointerValue">PointerValue</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section></summary><div class="docblock"><p>Build a <a href="http://llvm.org/docs/LangRef.html#llvm-memset-intrinsics">memset</a> instruction.</p>
|
||
<p>Alignment arguments are specified in bytes, and should always be
|
||
both a power of 2 and under 2^64.</p>
|
||
<p>The final argument should be a pointer-sized integer.</p>
|
||
<p>Returns an <code>Err(BuilderError::AlignmentError)</code> if the source alignment is not a power of 2 under 2^64.</p>
|
||
<p><a href="https://thedan64.github.io/inkwell/inkwell/targets/struct.TargetData.html#method.ptr_sized_int_type_in_context"><code>TargetData::ptr_sized_int_type_in_context</code></a> will get you one of those.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.build_malloc" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#1635-1651">source</a><h4 class="code-header">pub fn <a href="#method.build_malloc" class="fn">build_malloc</a><T: <a class="trait" href="../types/trait.BasicType.html" title="trait inkwell::types::BasicType">BasicType</a><'ctx>>(
|
||
&self,
|
||
ty: T,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../values/struct.PointerValue.html" title="struct inkwell::values::PointerValue">PointerValue</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section></summary><div class="docblock"><p>Returns <code>Err(BuilderError::AlignmentError)</code> if the type is unsized.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.build_array_malloc" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#1655-1677">source</a><h4 class="code-header">pub fn <a href="#method.build_array_malloc" class="fn">build_array_malloc</a><T: <a class="trait" href="../types/trait.BasicType.html" title="trait inkwell::types::BasicType">BasicType</a><'ctx>>(
|
||
&self,
|
||
ty: T,
|
||
size: <a class="struct" href="../values/struct.IntValue.html" title="struct inkwell::values::IntValue">IntValue</a><'ctx>,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../values/struct.PointerValue.html" title="struct inkwell::values::PointerValue">PointerValue</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section></summary><div class="docblock"><p>Returns <code>Err(BuilderError::AlignmentError)</code> if the type is unsized.</p>
|
||
</div></details><section id="method.build_free" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#1680-1685">source</a><h4 class="code-header">pub fn <a href="#method.build_free" class="fn">build_free</a>(
|
||
&self,
|
||
ptr: <a class="struct" href="../values/struct.PointerValue.html" title="struct inkwell::values::PointerValue">PointerValue</a><'ctx>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../values/struct.InstructionValue.html" title="struct inkwell::values::InstructionValue">InstructionValue</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.insert_instruction" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#1687-1698">source</a><h4 class="code-header">pub fn <a href="#method.insert_instruction" class="fn">insert_instruction</a>(
|
||
&self,
|
||
instruction: &<a class="struct" href="../values/struct.InstructionValue.html" title="struct inkwell::values::InstructionValue">InstructionValue</a><'ctx>,
|
||
name: <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><&<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>>
|
||
)</h4></section><section id="method.get_insert_block" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#1700-1702">source</a><h4 class="code-header">pub fn <a href="#method.get_insert_block" class="fn">get_insert_block</a>(&self) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="../basic_block/struct.BasicBlock.html" title="struct inkwell::basic_block::BasicBlock">BasicBlock</a><'ctx>></h4></section><section id="method.build_int_unsigned_div" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#1707-1715">source</a><h4 class="code-header">pub fn <a href="#method.build_int_unsigned_div" class="fn">build_int_unsigned_div</a><T: <a class="trait" href="../values/trait.IntMathValue.html" title="trait inkwell::values::IntMathValue">IntMathValue</a><'ctx>>(
|
||
&self,
|
||
lhs: T,
|
||
rhs: T,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_int_signed_div" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#1719-1727">source</a><h4 class="code-header">pub fn <a href="#method.build_int_signed_div" class="fn">build_int_signed_div</a><T: <a class="trait" href="../values/trait.IntMathValue.html" title="trait inkwell::values::IntMathValue">IntMathValue</a><'ctx>>(
|
||
&self,
|
||
lhs: T,
|
||
rhs: T,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_int_exact_signed_div" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#1731-1745">source</a><h4 class="code-header">pub fn <a href="#method.build_int_exact_signed_div" class="fn">build_int_exact_signed_div</a><T: <a class="trait" href="../values/trait.IntMathValue.html" title="trait inkwell::values::IntMathValue">IntMathValue</a><'ctx>>(
|
||
&self,
|
||
lhs: T,
|
||
rhs: T,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_int_unsigned_rem" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#1749-1757">source</a><h4 class="code-header">pub fn <a href="#method.build_int_unsigned_rem" class="fn">build_int_unsigned_rem</a><T: <a class="trait" href="../values/trait.IntMathValue.html" title="trait inkwell::values::IntMathValue">IntMathValue</a><'ctx>>(
|
||
&self,
|
||
lhs: T,
|
||
rhs: T,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_int_signed_rem" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#1761-1769">source</a><h4 class="code-header">pub fn <a href="#method.build_int_signed_rem" class="fn">build_int_signed_rem</a><T: <a class="trait" href="../values/trait.IntMathValue.html" title="trait inkwell::values::IntMathValue">IntMathValue</a><'ctx>>(
|
||
&self,
|
||
lhs: T,
|
||
rhs: T,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_int_s_extend" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#1771-1791">source</a><h4 class="code-header">pub fn <a href="#method.build_int_s_extend" class="fn">build_int_s_extend</a><T: <a class="trait" href="../values/trait.IntMathValue.html" title="trait inkwell::values::IntMathValue">IntMathValue</a><'ctx>>(
|
||
&self,
|
||
int_value: T,
|
||
int_type: T::<a class="associatedtype" href="../values/trait.IntMathValue.html#associatedtype.BaseType" title="type inkwell::values::IntMathValue::BaseType">BaseType</a>,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_address_space_cast" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#1794-1814">source</a><h4 class="code-header">pub fn <a href="#method.build_address_space_cast" class="fn">build_address_space_cast</a>(
|
||
&self,
|
||
ptr_val: <a class="struct" href="../values/struct.PointerValue.html" title="struct inkwell::values::PointerValue">PointerValue</a><'ctx>,
|
||
ptr_type: <a class="struct" href="../types/struct.PointerType.html" title="struct inkwell::types::PointerType">PointerType</a><'ctx>,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../values/struct.PointerValue.html" title="struct inkwell::values::PointerValue">PointerValue</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><details class="toggle method-toggle" open><summary><section id="method.build_bit_cast" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#1844-1856">source</a><h4 class="code-header">pub fn <a href="#method.build_bit_cast" class="fn">build_bit_cast</a><T, V>(
|
||
&self,
|
||
val: V,
|
||
ty: T,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="enum" href="../values/enum.BasicValueEnum.html" title="enum inkwell::values::BasicValueEnum">BasicValueEnum</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>><div class="where">where
|
||
T: <a class="trait" href="../types/trait.BasicType.html" title="trait inkwell::types::BasicType">BasicType</a><'ctx>,
|
||
V: <a class="trait" href="../values/trait.BasicValue.html" title="trait inkwell::values::BasicValue">BasicValue</a><'ctx>,</div></h4></section></summary><div class="docblock"><p>Builds a bitcast instruction. A bitcast reinterprets the bits of one value
|
||
into a value of another type which has the same bit width.</p>
|
||
<h5 id="example-7"><a class="doc-anchor" href="#example-7">§</a>Example</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>inkwell::AddressSpace;
|
||
<span class="kw">use </span>inkwell::context::Context;
|
||
|
||
<span class="kw">let </span>context = Context::create();
|
||
<span class="kw">let </span>module = context.create_module(<span class="string">"bc"</span>);
|
||
<span class="kw">let </span>void_type = context.void_type();
|
||
<span class="kw">let </span>f32_type = context.f32_type();
|
||
<span class="kw">let </span>i32_type = context.i32_type();
|
||
<span class="kw">let </span>arg_types = [i32_type.into()];
|
||
<span class="kw">let </span>fn_type = void_type.fn_type(<span class="kw-2">&</span>arg_types, <span class="bool-val">false</span>);
|
||
<span class="kw">let </span>fn_value = module.add_function(<span class="string">"bc"</span>, fn_type, <span class="prelude-val">None</span>);
|
||
<span class="kw">let </span>builder = context.create_builder();
|
||
<span class="kw">let </span>entry = context.append_basic_block(fn_value, <span class="string">"entry"</span>);
|
||
<span class="kw">let </span>i32_arg = fn_value.get_first_param().unwrap();
|
||
|
||
builder.position_at_end(entry);
|
||
|
||
builder.build_bit_cast(i32_arg, f32_type, <span class="string">"i32tof32"</span>).unwrap();
|
||
builder.build_return(<span class="prelude-val">None</span>).unwrap();
|
||
|
||
<span class="macro">assert!</span>(module.verify().is_ok());</code></pre></div>
|
||
</div></details><section id="method.build_int_s_extend_or_bit_cast" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#1858-1878">source</a><h4 class="code-header">pub fn <a href="#method.build_int_s_extend_or_bit_cast" class="fn">build_int_s_extend_or_bit_cast</a><T: <a class="trait" href="../values/trait.IntMathValue.html" title="trait inkwell::values::IntMathValue">IntMathValue</a><'ctx>>(
|
||
&self,
|
||
int_value: T,
|
||
int_type: T::<a class="associatedtype" href="../values/trait.IntMathValue.html#associatedtype.BaseType" title="type inkwell::values::IntMathValue::BaseType">BaseType</a>,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_int_z_extend" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#1880-1900">source</a><h4 class="code-header">pub fn <a href="#method.build_int_z_extend" class="fn">build_int_z_extend</a><T: <a class="trait" href="../values/trait.IntMathValue.html" title="trait inkwell::values::IntMathValue">IntMathValue</a><'ctx>>(
|
||
&self,
|
||
int_value: T,
|
||
int_type: T::<a class="associatedtype" href="../values/trait.IntMathValue.html#associatedtype.BaseType" title="type inkwell::values::IntMathValue::BaseType">BaseType</a>,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_int_z_extend_or_bit_cast" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#1902-1922">source</a><h4 class="code-header">pub fn <a href="#method.build_int_z_extend_or_bit_cast" class="fn">build_int_z_extend_or_bit_cast</a><T: <a class="trait" href="../values/trait.IntMathValue.html" title="trait inkwell::values::IntMathValue">IntMathValue</a><'ctx>>(
|
||
&self,
|
||
int_value: T,
|
||
int_type: T::<a class="associatedtype" href="../values/trait.IntMathValue.html#associatedtype.BaseType" title="type inkwell::values::IntMathValue::BaseType">BaseType</a>,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_int_truncate" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#1924-1945">source</a><h4 class="code-header">pub fn <a href="#method.build_int_truncate" class="fn">build_int_truncate</a><T: <a class="trait" href="../values/trait.IntMathValue.html" title="trait inkwell::values::IntMathValue">IntMathValue</a><'ctx>>(
|
||
&self,
|
||
int_value: T,
|
||
int_type: T::<a class="associatedtype" href="../values/trait.IntMathValue.html#associatedtype.BaseType" title="type inkwell::values::IntMathValue::BaseType">BaseType</a>,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_int_truncate_or_bit_cast" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#1947-1968">source</a><h4 class="code-header">pub fn <a href="#method.build_int_truncate_or_bit_cast" class="fn">build_int_truncate_or_bit_cast</a><T: <a class="trait" href="../values/trait.IntMathValue.html" title="trait inkwell::values::IntMathValue">IntMathValue</a><'ctx>>(
|
||
&self,
|
||
int_value: T,
|
||
int_type: T::<a class="associatedtype" href="../values/trait.IntMathValue.html#associatedtype.BaseType" title="type inkwell::values::IntMathValue::BaseType">BaseType</a>,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_float_rem" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#1970-1978">source</a><h4 class="code-header">pub fn <a href="#method.build_float_rem" class="fn">build_float_rem</a><T: <a class="trait" href="../values/trait.FloatMathValue.html" title="trait inkwell::values::FloatMathValue">FloatMathValue</a><'ctx>>(
|
||
&self,
|
||
lhs: T,
|
||
rhs: T,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_float_to_unsigned_int" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#1981-2002">source</a><h4 class="code-header">pub fn <a href="#method.build_float_to_unsigned_int" class="fn">build_float_to_unsigned_int</a><T: <a class="trait" href="../values/trait.FloatMathValue.html" title="trait inkwell::values::FloatMathValue">FloatMathValue</a><'ctx>>(
|
||
&self,
|
||
float: T,
|
||
int_type: <T::<a class="associatedtype" href="../values/trait.FloatMathValue.html#associatedtype.BaseType" title="type inkwell::values::FloatMathValue::BaseType">BaseType</a> as <a class="trait" href="../types/trait.FloatMathType.html" title="trait inkwell::types::FloatMathType">FloatMathType</a><'ctx>>::<a class="associatedtype" href="../types/trait.FloatMathType.html#associatedtype.MathConvType" title="type inkwell::types::FloatMathType::MathConvType">MathConvType</a>,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<<T::<a class="associatedtype" href="../values/trait.FloatMathValue.html#associatedtype.BaseType" title="type inkwell::values::FloatMathValue::BaseType">BaseType</a> as <a class="trait" href="../types/trait.FloatMathType.html" title="trait inkwell::types::FloatMathType">FloatMathType</a><'ctx>>::<a class="associatedtype" href="../types/trait.FloatMathType.html#associatedtype.MathConvType" title="type inkwell::types::FloatMathType::MathConvType">MathConvType</a> as <a class="trait" href="../types/trait.IntMathType.html" title="trait inkwell::types::IntMathType">IntMathType</a><'ctx>>::<a class="associatedtype" href="../types/trait.IntMathType.html#associatedtype.ValueType" title="type inkwell::types::IntMathType::ValueType">ValueType</a>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_float_to_signed_int" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2004-2025">source</a><h4 class="code-header">pub fn <a href="#method.build_float_to_signed_int" class="fn">build_float_to_signed_int</a><T: <a class="trait" href="../values/trait.FloatMathValue.html" title="trait inkwell::values::FloatMathValue">FloatMathValue</a><'ctx>>(
|
||
&self,
|
||
float: T,
|
||
int_type: <T::<a class="associatedtype" href="../values/trait.FloatMathValue.html#associatedtype.BaseType" title="type inkwell::values::FloatMathValue::BaseType">BaseType</a> as <a class="trait" href="../types/trait.FloatMathType.html" title="trait inkwell::types::FloatMathType">FloatMathType</a><'ctx>>::<a class="associatedtype" href="../types/trait.FloatMathType.html#associatedtype.MathConvType" title="type inkwell::types::FloatMathType::MathConvType">MathConvType</a>,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<<T::<a class="associatedtype" href="../values/trait.FloatMathValue.html#associatedtype.BaseType" title="type inkwell::values::FloatMathValue::BaseType">BaseType</a> as <a class="trait" href="../types/trait.FloatMathType.html" title="trait inkwell::types::FloatMathType">FloatMathType</a><'ctx>>::<a class="associatedtype" href="../types/trait.FloatMathType.html#associatedtype.MathConvType" title="type inkwell::types::FloatMathType::MathConvType">MathConvType</a> as <a class="trait" href="../types/trait.IntMathType.html" title="trait inkwell::types::IntMathType">IntMathType</a><'ctx>>::<a class="associatedtype" href="../types/trait.IntMathType.html#associatedtype.ValueType" title="type inkwell::types::IntMathType::ValueType">ValueType</a>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_unsigned_int_to_float" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2028-2049">source</a><h4 class="code-header">pub fn <a href="#method.build_unsigned_int_to_float" class="fn">build_unsigned_int_to_float</a><T: <a class="trait" href="../values/trait.IntMathValue.html" title="trait inkwell::values::IntMathValue">IntMathValue</a><'ctx>>(
|
||
&self,
|
||
int: T,
|
||
float_type: <T::<a class="associatedtype" href="../values/trait.IntMathValue.html#associatedtype.BaseType" title="type inkwell::values::IntMathValue::BaseType">BaseType</a> as <a class="trait" href="../types/trait.IntMathType.html" title="trait inkwell::types::IntMathType">IntMathType</a><'ctx>>::<a class="associatedtype" href="../types/trait.IntMathType.html#associatedtype.MathConvType" title="type inkwell::types::IntMathType::MathConvType">MathConvType</a>,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<<T::<a class="associatedtype" href="../values/trait.IntMathValue.html#associatedtype.BaseType" title="type inkwell::values::IntMathValue::BaseType">BaseType</a> as <a class="trait" href="../types/trait.IntMathType.html" title="trait inkwell::types::IntMathType">IntMathType</a><'ctx>>::<a class="associatedtype" href="../types/trait.IntMathType.html#associatedtype.MathConvType" title="type inkwell::types::IntMathType::MathConvType">MathConvType</a> as <a class="trait" href="../types/trait.FloatMathType.html" title="trait inkwell::types::FloatMathType">FloatMathType</a><'ctx>>::<a class="associatedtype" href="../types/trait.FloatMathType.html#associatedtype.ValueType" title="type inkwell::types::FloatMathType::ValueType">ValueType</a>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_signed_int_to_float" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2051-2072">source</a><h4 class="code-header">pub fn <a href="#method.build_signed_int_to_float" class="fn">build_signed_int_to_float</a><T: <a class="trait" href="../values/trait.IntMathValue.html" title="trait inkwell::values::IntMathValue">IntMathValue</a><'ctx>>(
|
||
&self,
|
||
int: T,
|
||
float_type: <T::<a class="associatedtype" href="../values/trait.IntMathValue.html#associatedtype.BaseType" title="type inkwell::values::IntMathValue::BaseType">BaseType</a> as <a class="trait" href="../types/trait.IntMathType.html" title="trait inkwell::types::IntMathType">IntMathType</a><'ctx>>::<a class="associatedtype" href="../types/trait.IntMathType.html#associatedtype.MathConvType" title="type inkwell::types::IntMathType::MathConvType">MathConvType</a>,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<<T::<a class="associatedtype" href="../values/trait.IntMathValue.html#associatedtype.BaseType" title="type inkwell::values::IntMathValue::BaseType">BaseType</a> as <a class="trait" href="../types/trait.IntMathType.html" title="trait inkwell::types::IntMathType">IntMathType</a><'ctx>>::<a class="associatedtype" href="../types/trait.IntMathType.html#associatedtype.MathConvType" title="type inkwell::types::IntMathType::MathConvType">MathConvType</a> as <a class="trait" href="../types/trait.FloatMathType.html" title="trait inkwell::types::FloatMathType">FloatMathType</a><'ctx>>::<a class="associatedtype" href="../types/trait.FloatMathType.html#associatedtype.ValueType" title="type inkwell::types::FloatMathType::ValueType">ValueType</a>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_float_trunc" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2074-2094">source</a><h4 class="code-header">pub fn <a href="#method.build_float_trunc" class="fn">build_float_trunc</a><T: <a class="trait" href="../values/trait.FloatMathValue.html" title="trait inkwell::values::FloatMathValue">FloatMathValue</a><'ctx>>(
|
||
&self,
|
||
float: T,
|
||
float_type: T::<a class="associatedtype" href="../values/trait.FloatMathValue.html#associatedtype.BaseType" title="type inkwell::values::FloatMathValue::BaseType">BaseType</a>,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_float_ext" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2096-2116">source</a><h4 class="code-header">pub fn <a href="#method.build_float_ext" class="fn">build_float_ext</a><T: <a class="trait" href="../values/trait.FloatMathValue.html" title="trait inkwell::values::FloatMathValue">FloatMathValue</a><'ctx>>(
|
||
&self,
|
||
float: T,
|
||
float_type: T::<a class="associatedtype" href="../values/trait.FloatMathValue.html#associatedtype.BaseType" title="type inkwell::values::FloatMathValue::BaseType">BaseType</a>,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_float_cast" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2118-2138">source</a><h4 class="code-header">pub fn <a href="#method.build_float_cast" class="fn">build_float_cast</a><T: <a class="trait" href="../values/trait.FloatMathValue.html" title="trait inkwell::values::FloatMathValue">FloatMathValue</a><'ctx>>(
|
||
&self,
|
||
float: T,
|
||
float_type: T::<a class="associatedtype" href="../values/trait.FloatMathValue.html#associatedtype.BaseType" title="type inkwell::values::FloatMathValue::BaseType">BaseType</a>,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_int_cast" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2141-2161">source</a><h4 class="code-header">pub fn <a href="#method.build_int_cast" class="fn">build_int_cast</a><T: <a class="trait" href="../values/trait.IntMathValue.html" title="trait inkwell::values::IntMathValue">IntMathValue</a><'ctx>>(
|
||
&self,
|
||
int: T,
|
||
int_type: T::<a class="associatedtype" href="../values/trait.IntMathValue.html#associatedtype.BaseType" title="type inkwell::values::IntMathValue::BaseType">BaseType</a>,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><details class="toggle method-toggle" open><summary><section id="method.build_int_cast_sign_flag" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2165-2187">source</a><h4 class="code-header">pub fn <a href="#method.build_int_cast_sign_flag" class="fn">build_int_cast_sign_flag</a><T: <a class="trait" href="../values/trait.IntMathValue.html" title="trait inkwell::values::IntMathValue">IntMathValue</a><'ctx>>(
|
||
&self,
|
||
int: T,
|
||
int_type: T::<a class="associatedtype" href="../values/trait.IntMathValue.html#associatedtype.BaseType" title="type inkwell::values::IntMathValue::BaseType">BaseType</a>,
|
||
is_signed: <a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.bool.html">bool</a>,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section></summary><div class="docblock"><p>Like <code>build_int_cast</code>, but respects the signedness of the type being cast to.</p>
|
||
</div></details><section id="method.build_float_div" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2189-2197">source</a><h4 class="code-header">pub fn <a href="#method.build_float_div" class="fn">build_float_div</a><T: <a class="trait" href="../values/trait.FloatMathValue.html" title="trait inkwell::values::FloatMathValue">FloatMathValue</a><'ctx>>(
|
||
&self,
|
||
lhs: T,
|
||
rhs: T,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_int_add" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2200-2208">source</a><h4 class="code-header">pub fn <a href="#method.build_int_add" class="fn">build_int_add</a><T: <a class="trait" href="../values/trait.IntMathValue.html" title="trait inkwell::values::IntMathValue">IntMathValue</a><'ctx>>(
|
||
&self,
|
||
lhs: T,
|
||
rhs: T,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_int_nsw_add" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2212-2217">source</a><h4 class="code-header">pub fn <a href="#method.build_int_nsw_add" class="fn">build_int_nsw_add</a><T: <a class="trait" href="../values/trait.IntMathValue.html" title="trait inkwell::values::IntMathValue">IntMathValue</a><'ctx>>(
|
||
&self,
|
||
lhs: T,
|
||
rhs: T,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_int_nuw_add" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2221-2229">source</a><h4 class="code-header">pub fn <a href="#method.build_int_nuw_add" class="fn">build_int_nuw_add</a><T: <a class="trait" href="../values/trait.IntMathValue.html" title="trait inkwell::values::IntMathValue">IntMathValue</a><'ctx>>(
|
||
&self,
|
||
lhs: T,
|
||
rhs: T,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_float_add" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2232-2240">source</a><h4 class="code-header">pub fn <a href="#method.build_float_add" class="fn">build_float_add</a><T: <a class="trait" href="../values/trait.FloatMathValue.html" title="trait inkwell::values::FloatMathValue">FloatMathValue</a><'ctx>>(
|
||
&self,
|
||
lhs: T,
|
||
rhs: T,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_xor" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2243-2251">source</a><h4 class="code-header">pub fn <a href="#method.build_xor" class="fn">build_xor</a><T: <a class="trait" href="../values/trait.IntMathValue.html" title="trait inkwell::values::IntMathValue">IntMathValue</a><'ctx>>(
|
||
&self,
|
||
lhs: T,
|
||
rhs: T,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_and" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2254-2262">source</a><h4 class="code-header">pub fn <a href="#method.build_and" class="fn">build_and</a><T: <a class="trait" href="../values/trait.IntMathValue.html" title="trait inkwell::values::IntMathValue">IntMathValue</a><'ctx>>(
|
||
&self,
|
||
lhs: T,
|
||
rhs: T,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_or" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2265-2273">source</a><h4 class="code-header">pub fn <a href="#method.build_or" class="fn">build_or</a><T: <a class="trait" href="../values/trait.IntMathValue.html" title="trait inkwell::values::IntMathValue">IntMathValue</a><'ctx>>(
|
||
&self,
|
||
lhs: T,
|
||
rhs: T,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><details class="toggle method-toggle" open><summary><section id="method.build_left_shift" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2318-2326">source</a><h4 class="code-header">pub fn <a href="#method.build_left_shift" class="fn">build_left_shift</a><T: <a class="trait" href="../values/trait.IntMathValue.html" title="trait inkwell::values::IntMathValue">IntMathValue</a><'ctx>>(
|
||
&self,
|
||
lhs: T,
|
||
rhs: T,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section></summary><div class="docblock"><p>Builds an <code>IntValue</code> containing the result of a logical left shift instruction.</p>
|
||
<h5 id="example-8"><a class="doc-anchor" href="#example-8">§</a>Example</h5>
|
||
<p>A logical left shift is an operation in which an integer value’s bits are shifted left by N number of positions.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">assert_eq!</span>(<span class="number">0b0000_0001 </span><< <span class="number">0</span>, <span class="number">0b0000_0001</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="number">0b0000_0001 </span><< <span class="number">1</span>, <span class="number">0b0000_0010</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="number">0b0000_0011 </span><< <span class="number">2</span>, <span class="number">0b0000_1100</span>);</code></pre></div>
|
||
<p>In Rust, a function that could do this for 8bit values looks like:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">fn </span>left_shift(value: u8, n: u8) -> u8 {
|
||
value << n
|
||
}</code></pre></div>
|
||
<p>And in Inkwell, the corresponding function would look roughly like:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>inkwell::context::Context;
|
||
|
||
<span class="comment">// Setup
|
||
</span><span class="kw">let </span>context = Context::create();
|
||
<span class="kw">let </span>module = context.create_module(<span class="string">"my_module"</span>);
|
||
<span class="kw">let </span>builder = context.create_builder();
|
||
<span class="kw">let </span>i8_type = context.i8_type();
|
||
<span class="kw">let </span>fn_type = i8_type.fn_type(<span class="kw-2">&</span>[i8_type.into(), i8_type.into()], <span class="bool-val">false</span>);
|
||
|
||
<span class="comment">// Function Definition
|
||
</span><span class="kw">let </span>function = module.add_function(<span class="string">"left_shift"</span>, fn_type, <span class="prelude-val">None</span>);
|
||
<span class="kw">let </span>value = function.get_first_param().unwrap().into_int_value();
|
||
<span class="kw">let </span>n = function.get_nth_param(<span class="number">1</span>).unwrap().into_int_value();
|
||
<span class="kw">let </span>entry_block = context.append_basic_block(function, <span class="string">"entry"</span>);
|
||
|
||
builder.position_at_end(entry_block);
|
||
|
||
<span class="kw">let </span>shift = builder.build_left_shift(value, n, <span class="string">"left_shift"</span>).unwrap(); <span class="comment">// value << n
|
||
|
||
</span>builder.build_return(<span class="prelude-val">Some</span>(<span class="kw-2">&</span>shift)).unwrap();</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.build_right_shift" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2392-2412">source</a><h4 class="code-header">pub fn <a href="#method.build_right_shift" class="fn">build_right_shift</a><T: <a class="trait" href="../values/trait.IntMathValue.html" title="trait inkwell::values::IntMathValue">IntMathValue</a><'ctx>>(
|
||
&self,
|
||
lhs: T,
|
||
rhs: T,
|
||
sign_extend: <a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.bool.html">bool</a>,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section></summary><div class="docblock"><p>Builds an <code>IntValue</code> containing the result of a right shift instruction.</p>
|
||
<h5 id="example-9"><a class="doc-anchor" href="#example-9">§</a>Example</h5>
|
||
<p>A right shift is an operation in which an integer value’s bits are shifted right by N number of positions.
|
||
It may either be logical and have its leftmost N bit(s) filled with zeros or sign extended and filled with ones
|
||
if the leftmost bit was one.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="comment">//fix doc error about overflowing_literals
|
||
//rendered rfc: https://github.com/rust-lang/rfcs/blob/master/text/2438-deny-integer-literal-overflow-lint.md
|
||
//tracking issue: https://github.com/rust-lang/rust/issues/54502
|
||
</span><span class="attr">#![allow(overflowing_literals)]
|
||
|
||
</span><span class="comment">// Logical Right Shift
|
||
</span><span class="macro">assert_eq!</span>(<span class="number">0b1100_0000u8 </span>>> <span class="number">2</span>, <span class="number">0b0011_0000</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="number">0b0000_0010u8 </span>>> <span class="number">1</span>, <span class="number">0b0000_0001</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="number">0b0000_1100u8 </span>>> <span class="number">2</span>, <span class="number">0b0000_0011</span>);
|
||
|
||
<span class="comment">// Sign Extended Right Shift
|
||
</span><span class="macro">assert_eq!</span>(<span class="number">0b0100_0000i8 </span>>> <span class="number">2</span>, <span class="number">0b0001_0000</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="number">0b1110_0000u8 </span><span class="kw">as </span>i8 >> <span class="number">1</span>, <span class="number">0b1111_0000u8 </span><span class="kw">as </span>i8);
|
||
<span class="macro">assert_eq!</span>(<span class="number">0b1100_0000u8 </span><span class="kw">as </span>i8 >> <span class="number">2</span>, <span class="number">0b1111_0000u8 </span><span class="kw">as </span>i8);</code></pre></div>
|
||
<p>In Rust, functions that could do this for 8bit values look like:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">fn </span>logical_right_shift(value: u8, n: u8) -> u8 {
|
||
value >> n
|
||
}
|
||
|
||
<span class="kw">fn </span>sign_extended_right_shift(value: i8, n: u8) -> i8 {
|
||
value >> n
|
||
}</code></pre></div>
|
||
<p>Notice that, in Rust (and most other languages), whether or not a value is sign extended depends wholly on whether
|
||
or not the type is signed (ie an i8 is a signed 8 bit value). LLVM does not make this distinction for you.</p>
|
||
<p>In Inkwell, the corresponding functions would look roughly like:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>inkwell::context::Context;
|
||
|
||
<span class="comment">// Setup
|
||
</span><span class="kw">let </span>context = Context::create();
|
||
<span class="kw">let </span>module = context.create_module(<span class="string">"my_module"</span>);
|
||
<span class="kw">let </span>builder = context.create_builder();
|
||
<span class="kw">let </span>i8_type = context.i8_type();
|
||
<span class="kw">let </span>fn_type = i8_type.fn_type(<span class="kw-2">&</span>[i8_type.into(), i8_type.into()], <span class="bool-val">false</span>);
|
||
|
||
<span class="comment">// Function Definition
|
||
</span><span class="kw">let </span>function = module.add_function(<span class="string">"right_shift"</span>, fn_type, <span class="prelude-val">None</span>);
|
||
<span class="kw">let </span>value = function.get_first_param().unwrap().into_int_value();
|
||
<span class="kw">let </span>n = function.get_nth_param(<span class="number">1</span>).unwrap().into_int_value();
|
||
<span class="kw">let </span>entry_block = context.append_basic_block(function, <span class="string">"entry"</span>);
|
||
|
||
builder.position_at_end(entry_block);
|
||
|
||
<span class="comment">// Whether or not your right shift is sign extended (true) or logical (false) depends
|
||
// on the boolean input parameter:
|
||
</span><span class="kw">let </span>shift = builder.build_right_shift(value, n, <span class="bool-val">false</span>, <span class="string">"right_shift"</span>).unwrap(); <span class="comment">// value >> n
|
||
|
||
</span>builder.build_return(<span class="prelude-val">Some</span>(<span class="kw-2">&</span>shift)).unwrap();</code></pre></div>
|
||
</div></details><section id="method.build_int_sub" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2415-2423">source</a><h4 class="code-header">pub fn <a href="#method.build_int_sub" class="fn">build_int_sub</a><T: <a class="trait" href="../values/trait.IntMathValue.html" title="trait inkwell::values::IntMathValue">IntMathValue</a><'ctx>>(
|
||
&self,
|
||
lhs: T,
|
||
rhs: T,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_int_nsw_sub" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2426-2434">source</a><h4 class="code-header">pub fn <a href="#method.build_int_nsw_sub" class="fn">build_int_nsw_sub</a><T: <a class="trait" href="../values/trait.IntMathValue.html" title="trait inkwell::values::IntMathValue">IntMathValue</a><'ctx>>(
|
||
&self,
|
||
lhs: T,
|
||
rhs: T,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_int_nuw_sub" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2438-2446">source</a><h4 class="code-header">pub fn <a href="#method.build_int_nuw_sub" class="fn">build_int_nuw_sub</a><T: <a class="trait" href="../values/trait.IntMathValue.html" title="trait inkwell::values::IntMathValue">IntMathValue</a><'ctx>>(
|
||
&self,
|
||
lhs: T,
|
||
rhs: T,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_float_sub" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2449-2457">source</a><h4 class="code-header">pub fn <a href="#method.build_float_sub" class="fn">build_float_sub</a><T: <a class="trait" href="../values/trait.FloatMathValue.html" title="trait inkwell::values::FloatMathValue">FloatMathValue</a><'ctx>>(
|
||
&self,
|
||
lhs: T,
|
||
rhs: T,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_int_mul" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2460-2468">source</a><h4 class="code-header">pub fn <a href="#method.build_int_mul" class="fn">build_int_mul</a><T: <a class="trait" href="../values/trait.IntMathValue.html" title="trait inkwell::values::IntMathValue">IntMathValue</a><'ctx>>(
|
||
&self,
|
||
lhs: T,
|
||
rhs: T,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_int_nsw_mul" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2472-2480">source</a><h4 class="code-header">pub fn <a href="#method.build_int_nsw_mul" class="fn">build_int_nsw_mul</a><T: <a class="trait" href="../values/trait.IntMathValue.html" title="trait inkwell::values::IntMathValue">IntMathValue</a><'ctx>>(
|
||
&self,
|
||
lhs: T,
|
||
rhs: T,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_int_nuw_mul" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2484-2492">source</a><h4 class="code-header">pub fn <a href="#method.build_int_nuw_mul" class="fn">build_int_nuw_mul</a><T: <a class="trait" href="../values/trait.IntMathValue.html" title="trait inkwell::values::IntMathValue">IntMathValue</a><'ctx>>(
|
||
&self,
|
||
lhs: T,
|
||
rhs: T,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_float_mul" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2495-2503">source</a><h4 class="code-header">pub fn <a href="#method.build_float_mul" class="fn">build_float_mul</a><T: <a class="trait" href="../values/trait.FloatMathValue.html" title="trait inkwell::values::FloatMathValue">FloatMathValue</a><'ctx>>(
|
||
&self,
|
||
lhs: T,
|
||
rhs: T,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_cast" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2505-2527">source</a><h4 class="code-header">pub fn <a href="#method.build_cast" class="fn">build_cast</a><T: <a class="trait" href="../types/trait.BasicType.html" title="trait inkwell::types::BasicType">BasicType</a><'ctx>, V: <a class="trait" href="../values/trait.BasicValue.html" title="trait inkwell::values::BasicValue">BasicValue</a><'ctx>>(
|
||
&self,
|
||
op: <a class="enum" href="../values/enum.InstructionOpcode.html" title="enum inkwell::values::InstructionOpcode">InstructionOpcode</a>,
|
||
from_value: V,
|
||
to_type: T,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="enum" href="../values/enum.BasicValueEnum.html" title="enum inkwell::values::BasicValueEnum">BasicValueEnum</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_pointer_cast" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2530-2544">source</a><h4 class="code-header">pub fn <a href="#method.build_pointer_cast" class="fn">build_pointer_cast</a><T: <a class="trait" href="../values/trait.PointerMathValue.html" title="trait inkwell::values::PointerMathValue">PointerMathValue</a><'ctx>>(
|
||
&self,
|
||
from: T,
|
||
to: T::<a class="associatedtype" href="../values/trait.PointerMathValue.html#associatedtype.BaseType" title="type inkwell::values::PointerMathValue::BaseType">BaseType</a>,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_int_compare" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2550-2572">source</a><h4 class="code-header">pub fn <a href="#method.build_int_compare" class="fn">build_int_compare</a><T: <a class="trait" href="../values/trait.IntMathValue.html" title="trait inkwell::values::IntMathValue">IntMathValue</a><'ctx>>(
|
||
&self,
|
||
op: <a class="enum" href="../enum.IntPredicate.html" title="enum inkwell::IntPredicate">IntPredicate</a>,
|
||
lhs: T,
|
||
rhs: T,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<T::<a class="associatedtype" href="../values/trait.IntMathValue.html#associatedtype.BaseType" title="type inkwell::values::IntMathValue::BaseType">BaseType</a> as <a class="trait" href="../types/trait.IntMathType.html" title="trait inkwell::types::IntMathType">IntMathType</a><'ctx>>::<a class="associatedtype" href="../types/trait.IntMathType.html#associatedtype.ValueType" title="type inkwell::types::IntMathType::ValueType">ValueType</a>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_float_compare" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2576-2600">source</a><h4 class="code-header">pub fn <a href="#method.build_float_compare" class="fn">build_float_compare</a><T: <a class="trait" href="../values/trait.FloatMathValue.html" title="trait inkwell::values::FloatMathValue">FloatMathValue</a><'ctx>>(
|
||
&self,
|
||
op: <a class="enum" href="../enum.FloatPredicate.html" title="enum inkwell::FloatPredicate">FloatPredicate</a>,
|
||
lhs: T,
|
||
rhs: T,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<<T::<a class="associatedtype" href="../values/trait.FloatMathValue.html#associatedtype.BaseType" title="type inkwell::values::FloatMathValue::BaseType">BaseType</a> as <a class="trait" href="../types/trait.FloatMathType.html" title="trait inkwell::types::FloatMathType">FloatMathType</a><'ctx>>::<a class="associatedtype" href="../types/trait.FloatMathType.html#associatedtype.MathConvType" title="type inkwell::types::FloatMathType::MathConvType">MathConvType</a> as <a class="trait" href="../types/trait.IntMathType.html" title="trait inkwell::types::IntMathType">IntMathType</a><'ctx>>::<a class="associatedtype" href="../types/trait.IntMathType.html#associatedtype.ValueType" title="type inkwell::types::IntMathType::ValueType">ValueType</a>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_unconditional_branch" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2602-2612">source</a><h4 class="code-header">pub fn <a href="#method.build_unconditional_branch" class="fn">build_unconditional_branch</a>(
|
||
&self,
|
||
destination_block: <a class="struct" href="../basic_block/struct.BasicBlock.html" title="struct inkwell::basic_block::BasicBlock">BasicBlock</a><'ctx>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../values/struct.InstructionValue.html" title="struct inkwell::values::InstructionValue">InstructionValue</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_conditional_branch" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2614-2633">source</a><h4 class="code-header">pub fn <a href="#method.build_conditional_branch" class="fn">build_conditional_branch</a>(
|
||
&self,
|
||
comparison: <a class="struct" href="../values/struct.IntValue.html" title="struct inkwell::values::IntValue">IntValue</a><'ctx>,
|
||
then_block: <a class="struct" href="../basic_block/struct.BasicBlock.html" title="struct inkwell::basic_block::BasicBlock">BasicBlock</a><'ctx>,
|
||
else_block: <a class="struct" href="../basic_block/struct.BasicBlock.html" title="struct inkwell::basic_block::BasicBlock">BasicBlock</a><'ctx>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../values/struct.InstructionValue.html" title="struct inkwell::values::InstructionValue">InstructionValue</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_indirect_branch" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2635-2650">source</a><h4 class="code-header">pub fn <a href="#method.build_indirect_branch" class="fn">build_indirect_branch</a><BV: <a class="trait" href="../values/trait.BasicValue.html" title="trait inkwell::values::BasicValue">BasicValue</a><'ctx>>(
|
||
&self,
|
||
address: BV,
|
||
destinations: &[<a class="struct" href="../basic_block/struct.BasicBlock.html" title="struct inkwell::basic_block::BasicBlock">BasicBlock</a><'ctx>]
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../values/struct.InstructionValue.html" title="struct inkwell::values::InstructionValue">InstructionValue</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_int_neg" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2653-2661">source</a><h4 class="code-header">pub fn <a href="#method.build_int_neg" class="fn">build_int_neg</a><T: <a class="trait" href="../values/trait.IntMathValue.html" title="trait inkwell::values::IntMathValue">IntMathValue</a><'ctx>>(
|
||
&self,
|
||
value: T,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_int_nsw_neg" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2665-2673">source</a><h4 class="code-header">pub fn <a href="#method.build_int_nsw_neg" class="fn">build_int_nsw_neg</a><T: <a class="trait" href="../values/trait.IntMathValue.html" title="trait inkwell::values::IntMathValue">IntMathValue</a><'ctx>>(
|
||
&self,
|
||
value: T,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_int_nuw_neg" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2676-2684">source</a><h4 class="code-header">pub fn <a href="#method.build_int_nuw_neg" class="fn">build_int_nuw_neg</a><T: <a class="trait" href="../values/trait.IntMathValue.html" title="trait inkwell::values::IntMathValue">IntMathValue</a><'ctx>>(
|
||
&self,
|
||
value: T,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_float_neg" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2687-2695">source</a><h4 class="code-header">pub fn <a href="#method.build_float_neg" class="fn">build_float_neg</a><T: <a class="trait" href="../values/trait.FloatMathValue.html" title="trait inkwell::values::FloatMathValue">FloatMathValue</a><'ctx>>(
|
||
&self,
|
||
value: T,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_not" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2698-2706">source</a><h4 class="code-header">pub fn <a href="#method.build_not" class="fn">build_not</a><T: <a class="trait" href="../values/trait.IntMathValue.html" title="trait inkwell::values::IntMathValue">IntMathValue</a><'ctx>>(
|
||
&self,
|
||
value: T,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><details class="toggle method-toggle" open><summary><section id="method.position_at" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2713-2717">source</a><h4 class="code-header">pub fn <a href="#method.position_at" class="fn">position_at</a>(
|
||
&self,
|
||
basic_block: <a class="struct" href="../basic_block/struct.BasicBlock.html" title="struct inkwell::basic_block::BasicBlock">BasicBlock</a><'ctx>,
|
||
instruction: &<a class="struct" href="../values/struct.InstructionValue.html" title="struct inkwell::values::InstructionValue">InstructionValue</a><'ctx>
|
||
)</h4></section></summary><div class="docblock"><p>Set the position of the builder to after an instruction.</p>
|
||
<p>Be sure to call one of the <code>position_*</code> methods or all <code>build_*</code> methods will return <code>Err(BuilderError::UnsetPosition)</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.position_before" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2722-2726">source</a><h4 class="code-header">pub fn <a href="#method.position_before" class="fn">position_before</a>(&self, instruction: &<a class="struct" href="../values/struct.InstructionValue.html" title="struct inkwell::values::InstructionValue">InstructionValue</a><'ctx>)</h4></section></summary><div class="docblock"><p>Set the position of the builder to before an instruction.</p>
|
||
<p>Be sure to call one of the <code>position_*</code> methods or all <code>build_*</code> methods will return <code>Err(BuilderError::UnsetPosition)</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.position_at_end" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2731-2737">source</a><h4 class="code-header">pub fn <a href="#method.position_at_end" class="fn">position_at_end</a>(&self, basic_block: <a class="struct" href="../basic_block/struct.BasicBlock.html" title="struct inkwell::basic_block::BasicBlock">BasicBlock</a><'ctx>)</h4></section></summary><div class="docblock"><p>Set the position of the builder to the end of a basic block.</p>
|
||
<p>Be sure to call one of the <code>position_*</code> methods or all <code>build_*</code> methods will return <code>Err(BuilderError::UnsetPosition)</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.build_extract_value" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2797-2820">source</a><h4 class="code-header">pub fn <a href="#method.build_extract_value" class="fn">build_extract_value</a><AV: <a class="trait" href="../values/trait.AggregateValue.html" title="trait inkwell::values::AggregateValue">AggregateValue</a><'ctx>>(
|
||
&self,
|
||
agg: AV,
|
||
index: <a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.u32.html">u32</a>,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="enum" href="../values/enum.BasicValueEnum.html" title="enum inkwell::values::BasicValueEnum">BasicValueEnum</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section></summary><div class="docblock"><p>Builds an extract value instruction which extracts a <code>BasicValueEnum</code>
|
||
from a struct or array.</p>
|
||
<p>Returns <code>Err(BuilderError::ExtractOutOfRange)</code> if the provided index is out of bounds of the aggregate value length.</p>
|
||
<h5 id="example-10"><a class="doc-anchor" href="#example-10">§</a>Example</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>inkwell::context::Context;
|
||
<span class="kw">use </span>inkwell::builder::BuilderError;
|
||
|
||
<span class="kw">let </span>context = Context::create();
|
||
<span class="kw">let </span>module = context.create_module(<span class="string">"av"</span>);
|
||
<span class="kw">let </span>void_type = context.void_type();
|
||
<span class="kw">let </span>f32_type = context.f32_type();
|
||
<span class="kw">let </span>i32_type = context.i32_type();
|
||
<span class="kw">let </span>struct_type = context.struct_type(<span class="kw-2">&</span>[i32_type.into(), f32_type.into()], <span class="bool-val">false</span>);
|
||
<span class="kw">let </span>array_type = i32_type.array_type(<span class="number">3</span>);
|
||
<span class="kw">let </span>fn_type = void_type.fn_type(<span class="kw-2">&</span>[], <span class="bool-val">false</span>);
|
||
<span class="kw">let </span>fn_value = module.add_function(<span class="string">"av_fn"</span>, fn_type, <span class="prelude-val">None</span>);
|
||
<span class="kw">let </span>builder = context.create_builder();
|
||
<span class="kw">let </span>entry = context.append_basic_block(fn_value, <span class="string">"entry"</span>);
|
||
|
||
builder.position_at_end(entry);
|
||
|
||
<span class="kw">let </span>array_alloca = builder.build_alloca(array_type, <span class="string">"array_alloca"</span>).unwrap();
|
||
|
||
<span class="attr">#[cfg(any(
|
||
feature = <span class="string">"llvm4-0"</span>,
|
||
feature = <span class="string">"llvm5-0"</span>,
|
||
feature = <span class="string">"llvm6-0"</span>,
|
||
feature = <span class="string">"llvm7-0"</span>,
|
||
feature = <span class="string">"llvm8-0"</span>,
|
||
feature = <span class="string">"llvm9-0"</span>,
|
||
feature = <span class="string">"llvm10-0"</span>,
|
||
feature = <span class="string">"llvm11-0"</span>,
|
||
feature = <span class="string">"llvm12-0"</span>,
|
||
feature = <span class="string">"llvm13-0"</span>,
|
||
feature = <span class="string">"llvm14-0"
|
||
</span>))]
|
||
</span><span class="kw">let </span>array = builder.build_load(array_alloca, <span class="string">"array_load"</span>).unwrap().into_array_value();
|
||
<span class="attr">#[cfg(any(feature = <span class="string">"llvm15-0"</span>, feature = <span class="string">"llvm16-0"</span>, feature = <span class="string">"llvm17-0"</span>, feature = <span class="string">"llvm18-0"</span>))]
|
||
</span><span class="kw">let </span>array = builder.build_load(i32_type, array_alloca, <span class="string">"array_load"</span>).unwrap().into_array_value();
|
||
|
||
<span class="kw">let </span>const_int1 = i32_type.const_int(<span class="number">2</span>, <span class="bool-val">false</span>);
|
||
<span class="kw">let </span>const_int2 = i32_type.const_int(<span class="number">5</span>, <span class="bool-val">false</span>);
|
||
<span class="kw">let </span>const_int3 = i32_type.const_int(<span class="number">6</span>, <span class="bool-val">false</span>);
|
||
|
||
<span class="macro">assert!</span>(builder.build_insert_value(array, const_int1, <span class="number">0</span>, <span class="string">"insert"</span>).is_ok());
|
||
<span class="macro">assert!</span>(builder.build_insert_value(array, const_int2, <span class="number">1</span>, <span class="string">"insert"</span>).is_ok());
|
||
<span class="macro">assert!</span>(builder.build_insert_value(array, const_int3, <span class="number">2</span>, <span class="string">"insert"</span>).is_ok());
|
||
<span class="macro">assert!</span>(builder.build_insert_value(array, const_int3, <span class="number">3</span>, <span class="string">"insert"</span>).is_err_and(|e| e == BuilderError::ExtractOutOfRange));
|
||
|
||
<span class="macro">assert!</span>(builder.build_extract_value(array, <span class="number">0</span>, <span class="string">"extract"</span>).unwrap().is_int_value());
|
||
<span class="macro">assert!</span>(builder.build_extract_value(array, <span class="number">1</span>, <span class="string">"extract"</span>).unwrap().is_int_value());
|
||
<span class="macro">assert!</span>(builder.build_extract_value(array, <span class="number">2</span>, <span class="string">"extract"</span>).unwrap().is_int_value());
|
||
<span class="macro">assert!</span>(builder.build_extract_value(array, <span class="number">3</span>, <span class="string">"extract"</span>).is_err_and(|e| e == BuilderError::ExtractOutOfRange));</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.build_insert_value" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2875-2911">source</a><h4 class="code-header">pub fn <a href="#method.build_insert_value" class="fn">build_insert_value</a><AV, BV>(
|
||
&self,
|
||
agg: AV,
|
||
value: BV,
|
||
index: <a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.u32.html">u32</a>,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="enum" href="../values/enum.AggregateValueEnum.html" title="enum inkwell::values::AggregateValueEnum">AggregateValueEnum</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>><div class="where">where
|
||
AV: <a class="trait" href="../values/trait.AggregateValue.html" title="trait inkwell::values::AggregateValue">AggregateValue</a><'ctx>,
|
||
BV: <a class="trait" href="../values/trait.BasicValue.html" title="trait inkwell::values::BasicValue">BasicValue</a><'ctx>,</div></h4></section></summary><div class="docblock"><p>Builds an insert value instruction which inserts a <code>BasicValue</code> into a struct
|
||
or array and returns the resulting aggregate value.</p>
|
||
<p>Returns <code>Err(BuilderError::ExtractOutOfRange)</code> if the provided index is out of bounds of the aggregate value length.</p>
|
||
<h5 id="example-11"><a class="doc-anchor" href="#example-11">§</a>Example</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>inkwell::context::Context;
|
||
<span class="kw">use </span>inkwell::builder::BuilderError;
|
||
|
||
<span class="kw">let </span>context = Context::create();
|
||
<span class="kw">let </span>module = context.create_module(<span class="string">"av"</span>);
|
||
<span class="kw">let </span>void_type = context.void_type();
|
||
<span class="kw">let </span>f32_type = context.f32_type();
|
||
<span class="kw">let </span>i32_type = context.i32_type();
|
||
<span class="kw">let </span>struct_type = context.struct_type(<span class="kw-2">&</span>[i32_type.into(), f32_type.into()], <span class="bool-val">false</span>);
|
||
<span class="kw">let </span>array_type = i32_type.array_type(<span class="number">3</span>);
|
||
<span class="kw">let </span>fn_type = void_type.fn_type(<span class="kw-2">&</span>[], <span class="bool-val">false</span>);
|
||
<span class="kw">let </span>fn_value = module.add_function(<span class="string">"av_fn"</span>, fn_type, <span class="prelude-val">None</span>);
|
||
<span class="kw">let </span>builder = context.create_builder();
|
||
<span class="kw">let </span>entry = context.append_basic_block(fn_value, <span class="string">"entry"</span>);
|
||
|
||
builder.position_at_end(entry);
|
||
|
||
<span class="kw">let </span>array_alloca = builder.build_alloca(array_type, <span class="string">"array_alloca"</span>).unwrap();
|
||
|
||
<span class="attr">#[cfg(any(
|
||
feature = <span class="string">"llvm4-0"</span>,
|
||
feature = <span class="string">"llvm5-0"</span>,
|
||
feature = <span class="string">"llvm6-0"</span>,
|
||
feature = <span class="string">"llvm7-0"</span>,
|
||
feature = <span class="string">"llvm8-0"</span>,
|
||
feature = <span class="string">"llvm9-0"</span>,
|
||
feature = <span class="string">"llvm10-0"</span>,
|
||
feature = <span class="string">"llvm11-0"</span>,
|
||
feature = <span class="string">"llvm12-0"</span>,
|
||
feature = <span class="string">"llvm13-0"</span>,
|
||
feature = <span class="string">"llvm14-0"
|
||
</span>))]
|
||
</span><span class="kw">let </span>array = builder.build_load(array_alloca, <span class="string">"array_load"</span>).unwrap().into_array_value();
|
||
<span class="attr">#[cfg(any(feature = <span class="string">"llvm15-0"</span>, feature = <span class="string">"llvm16-0"</span>, feature = <span class="string">"llvm17-0"</span>, feature = <span class="string">"llvm18-0"</span>))]
|
||
</span><span class="kw">let </span>array = builder.build_load(i32_type, array_alloca, <span class="string">"array_load"</span>).unwrap().into_array_value();
|
||
|
||
<span class="kw">let </span>const_int1 = i32_type.const_int(<span class="number">2</span>, <span class="bool-val">false</span>);
|
||
<span class="kw">let </span>const_int2 = i32_type.const_int(<span class="number">5</span>, <span class="bool-val">false</span>);
|
||
<span class="kw">let </span>const_int3 = i32_type.const_int(<span class="number">6</span>, <span class="bool-val">false</span>);
|
||
|
||
<span class="macro">assert!</span>(builder.build_insert_value(array, const_int1, <span class="number">0</span>, <span class="string">"insert"</span>).is_ok());
|
||
<span class="macro">assert!</span>(builder.build_insert_value(array, const_int2, <span class="number">1</span>, <span class="string">"insert"</span>).is_ok());
|
||
<span class="macro">assert!</span>(builder.build_insert_value(array, const_int3, <span class="number">2</span>, <span class="string">"insert"</span>).is_ok());
|
||
<span class="macro">assert!</span>(builder.build_insert_value(array, const_int3, <span class="number">3</span>, <span class="string">"insert"</span>).is_err_and(|e| e == BuilderError::ExtractOutOfRange));</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.build_extract_element" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2937-2958">source</a><h4 class="code-header">pub fn <a href="#method.build_extract_element" class="fn">build_extract_element</a>(
|
||
&self,
|
||
vector: <a class="struct" href="../values/struct.VectorValue.html" title="struct inkwell::values::VectorValue">VectorValue</a><'ctx>,
|
||
index: <a class="struct" href="../values/struct.IntValue.html" title="struct inkwell::values::IntValue">IntValue</a><'ctx>,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="enum" href="../values/enum.BasicValueEnum.html" title="enum inkwell::values::BasicValueEnum">BasicValueEnum</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section></summary><div class="docblock"><p>Builds an extract element instruction which extracts a <code>BasicValueEnum</code>
|
||
from a vector.</p>
|
||
<h5 id="example-12"><a class="doc-anchor" href="#example-12">§</a>Example</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>inkwell::context::Context;
|
||
|
||
<span class="kw">let </span>context = Context::create();
|
||
<span class="kw">let </span>module = context.create_module(<span class="string">"av"</span>);
|
||
<span class="kw">let </span>i32_type = context.i32_type();
|
||
<span class="kw">let </span>i32_zero = i32_type.const_int(<span class="number">0</span>, <span class="bool-val">false</span>);
|
||
<span class="kw">let </span>vec_type = i32_type.vec_type(<span class="number">2</span>);
|
||
<span class="kw">let </span>fn_type = i32_type.fn_type(<span class="kw-2">&</span>[vec_type.into()], <span class="bool-val">false</span>);
|
||
<span class="kw">let </span>fn_value = module.add_function(<span class="string">"vec_fn"</span>, fn_type, <span class="prelude-val">None</span>);
|
||
<span class="kw">let </span>builder = context.create_builder();
|
||
<span class="kw">let </span>entry = context.append_basic_block(fn_value, <span class="string">"entry"</span>);
|
||
<span class="kw">let </span>vector_param = fn_value.get_first_param().unwrap().into_vector_value();
|
||
|
||
builder.position_at_end(entry);
|
||
|
||
<span class="kw">let </span>extracted = builder.build_extract_element(vector_param, i32_zero, <span class="string">"insert"</span>).unwrap();
|
||
|
||
builder.build_return(<span class="prelude-val">Some</span>(<span class="kw-2">&</span>extracted)).unwrap();</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.build_insert_element" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#2985-3008">source</a><h4 class="code-header">pub fn <a href="#method.build_insert_element" class="fn">build_insert_element</a><V: <a class="trait" href="../values/trait.BasicValue.html" title="trait inkwell::values::BasicValue">BasicValue</a><'ctx>>(
|
||
&self,
|
||
vector: <a class="struct" href="../values/struct.VectorValue.html" title="struct inkwell::values::VectorValue">VectorValue</a><'ctx>,
|
||
element: V,
|
||
index: <a class="struct" href="../values/struct.IntValue.html" title="struct inkwell::values::IntValue">IntValue</a><'ctx>,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../values/struct.VectorValue.html" title="struct inkwell::values::VectorValue">VectorValue</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section></summary><div class="docblock"><p>Builds an insert element instruction which inserts a <code>BasicValue</code> into a vector
|
||
and returns the resulting vector.</p>
|
||
<h5 id="example-13"><a class="doc-anchor" href="#example-13">§</a>Example</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>inkwell::context::Context;
|
||
|
||
<span class="kw">let </span>context = Context::create();
|
||
<span class="kw">let </span>module = context.create_module(<span class="string">"av"</span>);
|
||
<span class="kw">let </span>void_type = context.void_type();
|
||
<span class="kw">let </span>i32_type = context.i32_type();
|
||
<span class="kw">let </span>i32_zero = i32_type.const_int(<span class="number">0</span>, <span class="bool-val">false</span>);
|
||
<span class="kw">let </span>i32_seven = i32_type.const_int(<span class="number">7</span>, <span class="bool-val">false</span>);
|
||
<span class="kw">let </span>vec_type = i32_type.vec_type(<span class="number">2</span>);
|
||
<span class="kw">let </span>fn_type = void_type.fn_type(<span class="kw-2">&</span>[vec_type.into()], <span class="bool-val">false</span>);
|
||
<span class="kw">let </span>fn_value = module.add_function(<span class="string">"vec_fn"</span>, fn_type, <span class="prelude-val">None</span>);
|
||
<span class="kw">let </span>builder = context.create_builder();
|
||
<span class="kw">let </span>entry = context.append_basic_block(fn_value, <span class="string">"entry"</span>);
|
||
<span class="kw">let </span>vector_param = fn_value.get_first_param().unwrap().into_vector_value();
|
||
|
||
builder.position_at_end(entry);
|
||
builder.build_insert_element(vector_param, i32_seven, i32_zero, <span class="string">"insert"</span>).unwrap();
|
||
builder.build_return(<span class="prelude-val">None</span>).unwrap();</code></pre></div>
|
||
</div></details><section id="method.build_unreachable" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#3010-3017">source</a><h4 class="code-header">pub fn <a href="#method.build_unreachable" class="fn">build_unreachable</a>(&self) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../values/struct.InstructionValue.html" title="struct inkwell::values::InstructionValue">InstructionValue</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_fence" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#3021-3035">source</a><h4 class="code-header">pub fn <a href="#method.build_fence" class="fn">build_fence</a>(
|
||
&self,
|
||
atomic_ordering: <a class="enum" href="../enum.AtomicOrdering.html" title="enum inkwell::AtomicOrdering">AtomicOrdering</a>,
|
||
num: <a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.i32.html">i32</a>,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../values/struct.InstructionValue.html" title="struct inkwell::values::InstructionValue">InstructionValue</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_is_null" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#3038-3051">source</a><h4 class="code-header">pub fn <a href="#method.build_is_null" class="fn">build_is_null</a><T: <a class="trait" href="../values/trait.PointerMathValue.html" title="trait inkwell::values::PointerMathValue">PointerMathValue</a><'ctx>>(
|
||
&self,
|
||
ptr: T,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<<T::<a class="associatedtype" href="../values/trait.PointerMathValue.html#associatedtype.BaseType" title="type inkwell::values::PointerMathValue::BaseType">BaseType</a> as <a class="trait" href="../types/trait.PointerMathType.html" title="trait inkwell::types::PointerMathType">PointerMathType</a><'ctx>>::<a class="associatedtype" href="../types/trait.PointerMathType.html#associatedtype.PtrConvType" title="type inkwell::types::PointerMathType::PtrConvType">PtrConvType</a> as <a class="trait" href="../types/trait.IntMathType.html" title="trait inkwell::types::IntMathType">IntMathType</a><'ctx>>::<a class="associatedtype" href="../types/trait.IntMathType.html#associatedtype.ValueType" title="type inkwell::types::IntMathType::ValueType">ValueType</a>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_is_not_null" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#3054-3067">source</a><h4 class="code-header">pub fn <a href="#method.build_is_not_null" class="fn">build_is_not_null</a><T: <a class="trait" href="../values/trait.PointerMathValue.html" title="trait inkwell::values::PointerMathValue">PointerMathValue</a><'ctx>>(
|
||
&self,
|
||
ptr: T,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<<T::<a class="associatedtype" href="../values/trait.PointerMathValue.html#associatedtype.BaseType" title="type inkwell::values::PointerMathValue::BaseType">BaseType</a> as <a class="trait" href="../types/trait.PointerMathType.html" title="trait inkwell::types::PointerMathType">PointerMathType</a><'ctx>>::<a class="associatedtype" href="../types/trait.PointerMathType.html#associatedtype.PtrConvType" title="type inkwell::types::PointerMathType::PtrConvType">PtrConvType</a> as <a class="trait" href="../types/trait.IntMathType.html" title="trait inkwell::types::IntMathType">IntMathType</a><'ctx>>::<a class="associatedtype" href="../types/trait.IntMathType.html#associatedtype.ValueType" title="type inkwell::types::IntMathType::ValueType">ValueType</a>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_int_to_ptr" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#3070-3092">source</a><h4 class="code-header">pub fn <a href="#method.build_int_to_ptr" class="fn">build_int_to_ptr</a><T: <a class="trait" href="../values/trait.IntMathValue.html" title="trait inkwell::values::IntMathValue">IntMathValue</a><'ctx>>(
|
||
&self,
|
||
int: T,
|
||
ptr_type: <T::<a class="associatedtype" href="../values/trait.IntMathValue.html#associatedtype.BaseType" title="type inkwell::values::IntMathValue::BaseType">BaseType</a> as <a class="trait" href="../types/trait.IntMathType.html" title="trait inkwell::types::IntMathType">IntMathType</a><'ctx>>::<a class="associatedtype" href="../types/trait.IntMathType.html#associatedtype.PtrConvType" title="type inkwell::types::IntMathType::PtrConvType">PtrConvType</a>,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<<T::<a class="associatedtype" href="../values/trait.IntMathValue.html#associatedtype.BaseType" title="type inkwell::values::IntMathValue::BaseType">BaseType</a> as <a class="trait" href="../types/trait.IntMathType.html" title="trait inkwell::types::IntMathType">IntMathType</a><'ctx>>::<a class="associatedtype" href="../types/trait.IntMathType.html#associatedtype.PtrConvType" title="type inkwell::types::IntMathType::PtrConvType">PtrConvType</a> as <a class="trait" href="../types/trait.PointerMathType.html" title="trait inkwell::types::PointerMathType">PointerMathType</a><'ctx>>::<a class="associatedtype" href="../types/trait.PointerMathType.html#associatedtype.ValueType" title="type inkwell::types::PointerMathType::ValueType">ValueType</a>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_ptr_to_int" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#3095-3117">source</a><h4 class="code-header">pub fn <a href="#method.build_ptr_to_int" class="fn">build_ptr_to_int</a><T: <a class="trait" href="../values/trait.PointerMathValue.html" title="trait inkwell::values::PointerMathValue">PointerMathValue</a><'ctx>>(
|
||
&self,
|
||
ptr: T,
|
||
int_type: <T::<a class="associatedtype" href="../values/trait.PointerMathValue.html#associatedtype.BaseType" title="type inkwell::values::PointerMathValue::BaseType">BaseType</a> as <a class="trait" href="../types/trait.PointerMathType.html" title="trait inkwell::types::PointerMathType">PointerMathType</a><'ctx>>::<a class="associatedtype" href="../types/trait.PointerMathType.html#associatedtype.PtrConvType" title="type inkwell::types::PointerMathType::PtrConvType">PtrConvType</a>,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<<T::<a class="associatedtype" href="../values/trait.PointerMathValue.html#associatedtype.BaseType" title="type inkwell::values::PointerMathValue::BaseType">BaseType</a> as <a class="trait" href="../types/trait.PointerMathType.html" title="trait inkwell::types::PointerMathType">PointerMathType</a><'ctx>>::<a class="associatedtype" href="../types/trait.PointerMathType.html#associatedtype.PtrConvType" title="type inkwell::types::PointerMathType::PtrConvType">PtrConvType</a> as <a class="trait" href="../types/trait.IntMathType.html" title="trait inkwell::types::IntMathType">IntMathType</a><'ctx>>::<a class="associatedtype" href="../types/trait.IntMathType.html#associatedtype.ValueType" title="type inkwell::types::IntMathType::ValueType">ValueType</a>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.clear_insertion_position" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#3119-3121">source</a><h4 class="code-header">pub fn <a href="#method.clear_insertion_position" class="fn">clear_insertion_position</a>(&self)</h4></section><section id="method.build_switch" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#3126-3149">source</a><h4 class="code-header">pub fn <a href="#method.build_switch" class="fn">build_switch</a>(
|
||
&self,
|
||
value: <a class="struct" href="../values/struct.IntValue.html" title="struct inkwell::values::IntValue">IntValue</a><'ctx>,
|
||
else_block: <a class="struct" href="../basic_block/struct.BasicBlock.html" title="struct inkwell::basic_block::BasicBlock">BasicBlock</a><'ctx>,
|
||
cases: &[(<a class="struct" href="../values/struct.IntValue.html" title="struct inkwell::values::IntValue">IntValue</a><'ctx>, <a class="struct" href="../basic_block/struct.BasicBlock.html" title="struct inkwell::basic_block::BasicBlock">BasicBlock</a><'ctx>)]
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../values/struct.InstructionValue.html" title="struct inkwell::values::InstructionValue">InstructionValue</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_select" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#3152-3174">source</a><h4 class="code-header">pub fn <a href="#method.build_select" class="fn">build_select</a><BV: <a class="trait" href="../values/trait.BasicValue.html" title="trait inkwell::values::BasicValue">BasicValue</a><'ctx>, IMV: <a class="trait" href="../values/trait.IntMathValue.html" title="trait inkwell::values::IntMathValue">IntMathValue</a><'ctx>>(
|
||
&self,
|
||
condition: IMV,
|
||
then: BV,
|
||
else_: BV,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="enum" href="../values/enum.BasicValueEnum.html" title="enum inkwell::values::BasicValueEnum">BasicValueEnum</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_global_string" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#3177-3186">source</a><h4 class="code-header">pub unsafe fn <a href="#method.build_global_string" class="fn">build_global_string</a>(
|
||
&self,
|
||
value: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../values/struct.GlobalValue.html" title="struct inkwell::values::GlobalValue">GlobalValue</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_global_string_ptr" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#3190-3199">source</a><h4 class="code-header">pub fn <a href="#method.build_global_string_ptr" class="fn">build_global_string_ptr</a>(
|
||
&self,
|
||
value: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../values/struct.GlobalValue.html" title="struct inkwell::values::GlobalValue">GlobalValue</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_shuffle_vector" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#3202-3224">source</a><h4 class="code-header">pub fn <a href="#method.build_shuffle_vector" class="fn">build_shuffle_vector</a>(
|
||
&self,
|
||
left: <a class="struct" href="../values/struct.VectorValue.html" title="struct inkwell::values::VectorValue">VectorValue</a><'ctx>,
|
||
right: <a class="struct" href="../values/struct.VectorValue.html" title="struct inkwell::values::VectorValue">VectorValue</a><'ctx>,
|
||
mask: <a class="struct" href="../values/struct.VectorValue.html" title="struct inkwell::values::VectorValue">VectorValue</a><'ctx>,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../values/struct.VectorValue.html" title="struct inkwell::values::VectorValue">VectorValue</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><section id="method.build_va_arg" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#3229-3250">source</a><h4 class="code-header">pub fn <a href="#method.build_va_arg" class="fn">build_va_arg</a><BT: <a class="trait" href="../types/trait.BasicType.html" title="trait inkwell::types::BasicType">BasicType</a><'ctx>>(
|
||
&self,
|
||
list: <a class="struct" href="../values/struct.PointerValue.html" title="struct inkwell::values::PointerValue">PointerValue</a><'ctx>,
|
||
type_: BT,
|
||
name: &<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.str.html">str</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="enum" href="../values/enum.BasicValueEnum.html" title="enum inkwell::values::BasicValueEnum">BasicValueEnum</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section><details class="toggle method-toggle" open><summary><section id="method.build_atomicrmw" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#3282-3325">source</a><h4 class="code-header">pub fn <a href="#method.build_atomicrmw" class="fn">build_atomicrmw</a>(
|
||
&self,
|
||
op: <a class="enum" href="../enum.AtomicRMWBinOp.html" title="enum inkwell::AtomicRMWBinOp">AtomicRMWBinOp</a>,
|
||
ptr: <a class="struct" href="../values/struct.PointerValue.html" title="struct inkwell::values::PointerValue">PointerValue</a><'ctx>,
|
||
value: <a class="struct" href="../values/struct.IntValue.html" title="struct inkwell::values::IntValue">IntValue</a><'ctx>,
|
||
ordering: <a class="enum" href="../enum.AtomicOrdering.html" title="enum inkwell::AtomicOrdering">AtomicOrdering</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../values/struct.IntValue.html" title="struct inkwell::values::IntValue">IntValue</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section></summary><div class="docblock"><p>Builds an atomicrmw instruction. It allows you to atomically modify memory.</p>
|
||
<p>May return of the following errors:</p>
|
||
<ul>
|
||
<li><code>Err(BuilderError::BitwidthError)</code> if the bitwidth of the value is not a power of 2 and less than 8</li>
|
||
<li><code>Err(BuilderError:PointeeTypeMismatch)</code> if the pointee type does not match the value’s type</li>
|
||
</ul>
|
||
<h5 id="example-14"><a class="doc-anchor" href="#example-14">§</a>Example</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>inkwell::context::Context;
|
||
<span class="kw">use </span>inkwell::{AddressSpace, AtomicOrdering, AtomicRMWBinOp};
|
||
<span class="kw">let </span>context = Context::create();
|
||
<span class="kw">let </span>module = context.create_module(<span class="string">"rmw"</span>);
|
||
<span class="kw">let </span>void_type = context.void_type();
|
||
<span class="kw">let </span>i32_type = context.i32_type();
|
||
<span class="kw">let </span>i32_seven = i32_type.const_int(<span class="number">7</span>, <span class="bool-val">false</span>);
|
||
<span class="attr">#[cfg(not(any(feature = <span class="string">"llvm15-0"</span>, feature = <span class="string">"llvm16-0"</span>, feature = <span class="string">"llvm17-0"</span>, feature = <span class="string">"llvm18-0"</span>)))]
|
||
</span><span class="kw">let </span>i32_ptr_type = i32_type.ptr_type(AddressSpace::default());
|
||
<span class="attr">#[cfg(any(feature = <span class="string">"llvm15-0"</span>, feature = <span class="string">"llvm16-0"</span>, feature = <span class="string">"llvm17-0"</span>, feature = <span class="string">"llvm18-0"</span>))]
|
||
</span><span class="kw">let </span>i32_ptr_type = context.ptr_type(AddressSpace::default());
|
||
<span class="kw">let </span>fn_type = void_type.fn_type(<span class="kw-2">&</span>[i32_ptr_type.into()], <span class="bool-val">false</span>);
|
||
<span class="kw">let </span>fn_value = module.add_function(<span class="string">"rmw"</span>, fn_type, <span class="prelude-val">None</span>);
|
||
<span class="kw">let </span>entry = context.append_basic_block(fn_value, <span class="string">"entry"</span>);
|
||
<span class="kw">let </span>i32_ptr_param = fn_value.get_first_param().unwrap().into_pointer_value();
|
||
<span class="kw">let </span>builder = context.create_builder();
|
||
builder.position_at_end(entry);
|
||
builder.build_atomicrmw(AtomicRMWBinOp::Add, i32_ptr_param, i32_seven, AtomicOrdering::Unordered).unwrap();
|
||
builder.build_return(<span class="prelude-val">None</span>).unwrap();</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.build_cmpxchg" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#3363-3429">source</a><h4 class="code-header">pub fn <a href="#method.build_cmpxchg" class="fn">build_cmpxchg</a><V: <a class="trait" href="../values/trait.BasicValue.html" title="trait inkwell::values::BasicValue">BasicValue</a><'ctx>>(
|
||
&self,
|
||
ptr: <a class="struct" href="../values/struct.PointerValue.html" title="struct inkwell::values::PointerValue">PointerValue</a><'ctx>,
|
||
cmp: V,
|
||
new: V,
|
||
success: <a class="enum" href="../enum.AtomicOrdering.html" title="enum inkwell::AtomicOrdering">AtomicOrdering</a>,
|
||
failure: <a class="enum" href="../enum.AtomicOrdering.html" title="enum inkwell::AtomicOrdering">AtomicOrdering</a>
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../values/struct.StructValue.html" title="struct inkwell::values::StructValue">StructValue</a><'ctx>, <a class="enum" href="enum.BuilderError.html" title="enum inkwell::builder::BuilderError">BuilderError</a>></h4></section></summary><div class="docblock"><p>Builds a cmpxchg instruction. It allows you to atomically compare and replace memory.</p>
|
||
<p>May return one of the following errors:</p>
|
||
<ul>
|
||
<li><code>Err(BuilderError::PointeeTypeMismatch)</code> if the pointer does not point to an element of the value type</li>
|
||
<li><code>Err(BuilderError::ValueTypeMismatch)</code> if the value to compare and the new values are not of the same type, or if
|
||
the value does not have a pointer or integer type</li>
|
||
<li><code>Err(BuilderError::OrderingError)</code> if the following conditions are not satisfied:
|
||
<ul>
|
||
<li>Both success and failure orderings are not Monotonic or stronger</li>
|
||
<li>The failure ordering is stronger than the success ordering</li>
|
||
<li>The failure ordering is release or acquire release</li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
<h5 id="example-15"><a class="doc-anchor" href="#example-15">§</a>Example</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>inkwell::context::Context;
|
||
<span class="kw">use </span>inkwell::{AddressSpace, AtomicOrdering};
|
||
<span class="kw">let </span>context = Context::create();
|
||
<span class="kw">let </span>module = context.create_module(<span class="string">"cmpxchg"</span>);
|
||
<span class="kw">let </span>void_type = context.void_type();
|
||
<span class="kw">let </span>i32_type = context.i32_type();
|
||
<span class="attr">#[cfg(not(any(feature = <span class="string">"llvm15-0"</span>, feature = <span class="string">"llvm16-0"</span>, feature = <span class="string">"llvm17-0"</span>, feature = <span class="string">"llvm18-0"</span>)))]
|
||
</span><span class="kw">let </span>i32_ptr_type = i32_type.ptr_type(AddressSpace::default());
|
||
<span class="attr">#[cfg(any(feature = <span class="string">"llvm15-0"</span>, feature = <span class="string">"llvm16-0"</span>, feature = <span class="string">"llvm17-0"</span>, feature = <span class="string">"llvm18-0"</span>))]
|
||
</span><span class="kw">let </span>i32_ptr_type = context.ptr_type(AddressSpace::default());
|
||
<span class="kw">let </span>fn_type = void_type.fn_type(<span class="kw-2">&</span>[i32_ptr_type.into()], <span class="bool-val">false</span>);
|
||
<span class="kw">let </span>fn_value = module.add_function(<span class="string">""</span>, fn_type, <span class="prelude-val">None</span>);
|
||
<span class="kw">let </span>i32_ptr_param = fn_value.get_first_param().unwrap().into_pointer_value();
|
||
<span class="kw">let </span>i32_seven = i32_type.const_int(<span class="number">7</span>, <span class="bool-val">false</span>);
|
||
<span class="kw">let </span>i32_eight = i32_type.const_int(<span class="number">8</span>, <span class="bool-val">false</span>);
|
||
<span class="kw">let </span>entry = context.append_basic_block(fn_value, <span class="string">"entry"</span>);
|
||
<span class="kw">let </span>builder = context.create_builder();
|
||
builder.position_at_end(entry);
|
||
builder.build_cmpxchg(i32_ptr_param, i32_seven, i32_eight, AtomicOrdering::AcquireRelease, AtomicOrdering::Monotonic).unwrap();
|
||
builder.build_return(<span class="prelude-val">None</span>).unwrap();</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.set_current_debug_location" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#3446-3451">source</a><h4 class="code-header">pub fn <a href="#method.set_current_debug_location" class="fn">set_current_debug_location</a>(&self, location: <a class="struct" href="../debug_info/struct.DILocation.html" title="struct inkwell::debug_info::DILocation">DILocation</a><'ctx>)</h4></section></summary><div class="docblock"><p>Set the debug info source location of the instruction currently pointed at by the builder</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.get_current_debug_location" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#3456-3467">source</a><h4 class="code-header">pub fn <a href="#method.get_current_debug_location" class="fn">get_current_debug_location</a>(&self) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="../debug_info/struct.DILocation.html" title="struct inkwell::debug_info::DILocation">DILocation</a><'ctx>></h4></section></summary><div class="docblock"><p>Get the debug info source location of the instruction currently pointed at by the builder,
|
||
if available.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.unset_current_debug_location" class="method"><a class="src rightside" href="../../src/inkwell/builder.rs.html#3482-3487">source</a><h4 class="code-header">pub fn <a href="#method.unset_current_debug_location" class="fn">unset_current_debug_location</a>(&self)</h4></section></summary><div class="docblock"><p>Unset the debug info source location of the instruction currently pointed at by the
|
||
builder. If there isn’t any debug info, this is a no-op.</p>
|
||
</div></details></div></details></div><h2 id="trait-implementations" class="section-header">Trait Implementations<a href="#trait-implementations" class="anchor">§</a></h2><div id="trait-implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-Debug-for-Builder%3C'ctx%3E" class="impl"><a class="src rightside" href="../../src/inkwell/builder.rs.html#87">source</a><a href="#impl-Debug-for-Builder%3C'ctx%3E" class="anchor">§</a><h3 class="code-header">impl<'ctx> <a class="trait" href="https://doc.rust-lang.org/1.78.0/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="struct.Builder.html" title="struct inkwell::builder::Builder">Builder</a><'ctx></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.fmt" class="method trait-impl"><a class="src rightside" href="../../src/inkwell/builder.rs.html#87">source</a><a href="#method.fmt" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.78.0/core/fmt/trait.Debug.html#tymethod.fmt" class="fn">fmt</a>(&self, f: &mut <a class="struct" href="https://doc.rust-lang.org/1.78.0/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a><'_>) -> <a class="type" href="https://doc.rust-lang.org/1.78.0/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></h4></section></summary><div class='docblock'>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/1.78.0/core/fmt/trait.Debug.html#tymethod.fmt">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-Drop-for-Builder%3C'_%3E" class="impl"><a class="src rightside" href="../../src/inkwell/builder.rs.html#3499-3505">source</a><a href="#impl-Drop-for-Builder%3C'_%3E" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.78.0/core/ops/drop/trait.Drop.html" title="trait core::ops::drop::Drop">Drop</a> for <a class="struct" href="struct.Builder.html" title="struct inkwell::builder::Builder">Builder</a><'_></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.drop" class="method trait-impl"><a class="src rightside" href="../../src/inkwell/builder.rs.html#3500-3504">source</a><a href="#method.drop" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.78.0/core/ops/drop/trait.Drop.html#tymethod.drop" class="fn">drop</a>(&mut self)</h4></section></summary><div class='docblock'>Executes the destructor for this type. <a href="https://doc.rust-lang.org/1.78.0/core/ops/drop/trait.Drop.html#tymethod.drop">Read more</a></div></details></div></details></div><h2 id="synthetic-implementations" class="section-header">Auto Trait Implementations<a href="#synthetic-implementations" class="anchor">§</a></h2><div id="synthetic-implementations-list"><section id="impl-Freeze-for-Builder%3C'ctx%3E" class="impl"><a href="#impl-Freeze-for-Builder%3C'ctx%3E" class="anchor">§</a><h3 class="code-header">impl<'ctx> !<a class="trait" href="https://doc.rust-lang.org/1.78.0/core/marker/trait.Freeze.html" title="trait core::marker::Freeze">Freeze</a> for <a class="struct" href="struct.Builder.html" title="struct inkwell::builder::Builder">Builder</a><'ctx></h3></section><section id="impl-RefUnwindSafe-for-Builder%3C'ctx%3E" class="impl"><a href="#impl-RefUnwindSafe-for-Builder%3C'ctx%3E" class="anchor">§</a><h3 class="code-header">impl<'ctx> !<a class="trait" href="https://doc.rust-lang.org/1.78.0/core/panic/unwind_safe/trait.RefUnwindSafe.html" title="trait core::panic::unwind_safe::RefUnwindSafe">RefUnwindSafe</a> for <a class="struct" href="struct.Builder.html" title="struct inkwell::builder::Builder">Builder</a><'ctx></h3></section><section id="impl-Send-for-Builder%3C'ctx%3E" class="impl"><a href="#impl-Send-for-Builder%3C'ctx%3E" class="anchor">§</a><h3 class="code-header">impl<'ctx> !<a class="trait" href="https://doc.rust-lang.org/1.78.0/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="struct.Builder.html" title="struct inkwell::builder::Builder">Builder</a><'ctx></h3></section><section id="impl-Sync-for-Builder%3C'ctx%3E" class="impl"><a href="#impl-Sync-for-Builder%3C'ctx%3E" class="anchor">§</a><h3 class="code-header">impl<'ctx> !<a class="trait" href="https://doc.rust-lang.org/1.78.0/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="struct.Builder.html" title="struct inkwell::builder::Builder">Builder</a><'ctx></h3></section><section id="impl-Unpin-for-Builder%3C'ctx%3E" class="impl"><a href="#impl-Unpin-for-Builder%3C'ctx%3E" class="anchor">§</a><h3 class="code-header">impl<'ctx> <a class="trait" href="https://doc.rust-lang.org/1.78.0/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> for <a class="struct" href="struct.Builder.html" title="struct inkwell::builder::Builder">Builder</a><'ctx></h3></section><section id="impl-UnwindSafe-for-Builder%3C'ctx%3E" class="impl"><a href="#impl-UnwindSafe-for-Builder%3C'ctx%3E" class="anchor">§</a><h3 class="code-header">impl<'ctx> <a class="trait" href="https://doc.rust-lang.org/1.78.0/core/panic/unwind_safe/trait.UnwindSafe.html" title="trait core::panic::unwind_safe::UnwindSafe">UnwindSafe</a> for <a class="struct" href="struct.Builder.html" title="struct inkwell::builder::Builder">Builder</a><'ctx></h3></section></div><h2 id="blanket-implementations" class="section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor">§</a></h2><div id="blanket-implementations-list"><details class="toggle implementors-toggle"><summary><section id="impl-Any-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.78.0/src/core/any.rs.html#140">source</a><a href="#impl-Any-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.78.0/core/any/trait.Any.html" title="trait core::any::Any">Any</a> for T<div class="where">where
|
||
T: 'static + ?<a class="trait" href="https://doc.rust-lang.org/1.78.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.type_id" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.78.0/src/core/any.rs.html#141">source</a><a href="#method.type_id" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.78.0/core/any/trait.Any.html#tymethod.type_id" class="fn">type_id</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/1.78.0/core/any/struct.TypeId.html" title="struct core::any::TypeId">TypeId</a></h4></section></summary><div class='docblock'>Gets the <code>TypeId</code> of <code>self</code>. <a href="https://doc.rust-lang.org/1.78.0/core/any/trait.Any.html#tymethod.type_id">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Borrow%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.78.0/src/core/borrow.rs.html#208">source</a><a href="#impl-Borrow%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.78.0/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><T> for T<div class="where">where
|
||
T: ?<a class="trait" href="https://doc.rust-lang.org/1.78.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.borrow" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.78.0/src/core/borrow.rs.html#210">source</a><a href="#method.borrow" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.78.0/core/borrow/trait.Borrow.html#tymethod.borrow" class="fn">borrow</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.reference.html">&T</a></h4></section></summary><div class='docblock'>Immutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.78.0/core/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-BorrowMut%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.78.0/src/core/borrow.rs.html#216">source</a><a href="#impl-BorrowMut%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.78.0/core/borrow/trait.BorrowMut.html" title="trait core::borrow::BorrowMut">BorrowMut</a><T> for T<div class="where">where
|
||
T: ?<a class="trait" href="https://doc.rust-lang.org/1.78.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.borrow_mut" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.78.0/src/core/borrow.rs.html#217">source</a><a href="#method.borrow_mut" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.78.0/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut" class="fn">borrow_mut</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.reference.html">&mut T</a></h4></section></summary><div class='docblock'>Mutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.78.0/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-From%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.78.0/src/core/convert/mod.rs.html#765">source</a><a href="#impl-From%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.78.0/core/convert/trait.From.html" title="trait core::convert::From">From</a><T> for T</h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.from" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.78.0/src/core/convert/mod.rs.html#768">source</a><a href="#method.from" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.78.0/core/convert/trait.From.html#tymethod.from" class="fn">from</a>(t: T) -> T</h4></section></summary><div class="docblock"><p>Returns the argument unchanged.</p>
|
||
</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Into%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.78.0/src/core/convert/mod.rs.html#748-750">source</a><a href="#impl-Into%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/1.78.0/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><U> for T<div class="where">where
|
||
U: <a class="trait" href="https://doc.rust-lang.org/1.78.0/core/convert/trait.From.html" title="trait core::convert::From">From</a><T>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.into" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.78.0/src/core/convert/mod.rs.html#758">source</a><a href="#method.into" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.78.0/core/convert/trait.Into.html#tymethod.into" class="fn">into</a>(self) -> U</h4></section></summary><div class="docblock"><p>Calls <code>U::from(self)</code>.</p>
|
||
<p>That is, this conversion is whatever the implementation of
|
||
<code><a href="https://doc.rust-lang.org/1.78.0/core/convert/trait.From.html" title="trait core::convert::From">From</a><T> for U</code> chooses to do.</p>
|
||
</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-IntoEither-for-T" class="impl"><a class="src rightside" href="../../src/either/into_either.rs.html#64">source</a><a href="#impl-IntoEither-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="../../either/into_either/trait.IntoEither.html" title="trait either::into_either::IntoEither">IntoEither</a> for T</h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.into_either" class="method trait-impl"><a class="src rightside" href="../../src/either/into_either.rs.html#29">source</a><a href="#method.into_either" class="anchor">§</a><h4 class="code-header">fn <a href="../../either/into_either/trait.IntoEither.html#method.into_either" class="fn">into_either</a>(self, into_left: <a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.bool.html">bool</a>) -> <a class="enum" href="../../either/enum.Either.html" title="enum either::Either">Either</a><Self, Self></h4></section></summary><div class='docblock'>Converts <code>self</code> into a <a href="../../either/enum.Either.html#variant.Left" title="variant either::Either::Left"><code>Left</code></a> variant of <a href="../../either/enum.Either.html" title="enum either::Either"><code>Either<Self, Self></code></a>
|
||
if <code>into_left</code> is <code>true</code>.
|
||
Converts <code>self</code> into a <a href="../../either/enum.Either.html#variant.Right" title="variant either::Either::Right"><code>Right</code></a> variant of <a href="../../either/enum.Either.html" title="enum either::Either"><code>Either<Self, Self></code></a>
|
||
otherwise. <a href="../../either/into_either/trait.IntoEither.html#method.into_either">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.into_either_with" class="method trait-impl"><a class="src rightside" href="../../src/either/into_either.rs.html#55-57">source</a><a href="#method.into_either_with" class="anchor">§</a><h4 class="code-header">fn <a href="../../either/into_either/trait.IntoEither.html#method.into_either_with" class="fn">into_either_with</a><F>(self, into_left: F) -> <a class="enum" href="../../either/enum.Either.html" title="enum either::Either">Either</a><Self, Self><div class="where">where
|
||
F: <a class="trait" href="https://doc.rust-lang.org/1.78.0/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(<a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.reference.html">&Self</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.78.0/std/primitive.bool.html">bool</a>,</div></h4></section></summary><div class='docblock'>Converts <code>self</code> into a <a href="../../either/enum.Either.html#variant.Left" title="variant either::Either::Left"><code>Left</code></a> variant of <a href="../../either/enum.Either.html" title="enum either::Either"><code>Either<Self, Self></code></a>
|
||
if <code>into_left(&self)</code> returns <code>true</code>.
|
||
Converts <code>self</code> into a <a href="../../either/enum.Either.html#variant.Right" title="variant either::Either::Right"><code>Right</code></a> variant of <a href="../../either/enum.Either.html" title="enum either::Either"><code>Either<Self, Self></code></a>
|
||
otherwise. <a href="../../either/into_either/trait.IntoEither.html#method.into_either_with">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-TryFrom%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.78.0/src/core/convert/mod.rs.html#805-807">source</a><a href="#impl-TryFrom%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/1.78.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U> for T<div class="where">where
|
||
U: <a class="trait" href="https://doc.rust-lang.org/1.78.0/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><T>,</div></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Error-1" class="associatedtype trait-impl"><a href="#associatedtype.Error-1" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.78.0/core/convert/trait.TryFrom.html#associatedtype.Error" class="associatedtype">Error</a> = <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/convert/enum.Infallible.html" title="enum core::convert::Infallible">Infallible</a></h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="toggle method-toggle" open><summary><section id="method.try_from" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.78.0/src/core/convert/mod.rs.html#812">source</a><a href="#method.try_from" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.78.0/core/convert/trait.TryFrom.html#tymethod.try_from" class="fn">try_from</a>(value: U) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <T as <a class="trait" href="https://doc.rust-lang.org/1.78.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.78.0/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>></h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-TryInto%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.78.0/src/core/convert/mod.rs.html#790-792">source</a><a href="#impl-TryInto%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/1.78.0/core/convert/trait.TryInto.html" title="trait core::convert::TryInto">TryInto</a><U> for T<div class="where">where
|
||
U: <a class="trait" href="https://doc.rust-lang.org/1.78.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>,</div></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Error" class="associatedtype trait-impl"><a href="#associatedtype.Error" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.78.0/core/convert/trait.TryInto.html#associatedtype.Error" class="associatedtype">Error</a> = <U as <a class="trait" href="https://doc.rust-lang.org/1.78.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.78.0/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a></h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="toggle method-toggle" open><summary><section id="method.try_into" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.78.0/src/core/convert/mod.rs.html#797">source</a><a href="#method.try_into" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.78.0/core/convert/trait.TryInto.html#tymethod.try_into" class="fn">try_into</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.78.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><U, <U as <a class="trait" href="https://doc.rust-lang.org/1.78.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.78.0/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>></h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details></div></section></div></main></body></html> |