diff options
Diffstat (limited to 'src/llvm_kaleidoscope_rs/llvm')
-rw-r--r-- | src/llvm_kaleidoscope_rs/llvm/basic_block.rs.html | 69 | ||||
-rw-r--r-- | src/llvm_kaleidoscope_rs/llvm/builder.rs.html | 423 | ||||
-rw-r--r-- | src/llvm_kaleidoscope_rs/llvm/lljit.rs.html | 217 | ||||
-rw-r--r-- | src/llvm_kaleidoscope_rs/llvm/mod.rs.html | 115 | ||||
-rw-r--r-- | src/llvm_kaleidoscope_rs/llvm/module.rs.html | 325 | ||||
-rw-r--r-- | src/llvm_kaleidoscope_rs/llvm/pass_manager.rs.html | 115 | ||||
-rw-r--r-- | src/llvm_kaleidoscope_rs/llvm/type_.rs.html | 95 | ||||
-rw-r--r-- | src/llvm_kaleidoscope_rs/llvm/value.rs.html | 361 |
8 files changed, 832 insertions, 888 deletions
diff --git a/src/llvm_kaleidoscope_rs/llvm/basic_block.rs.html b/src/llvm_kaleidoscope_rs/llvm/basic_block.rs.html index 581b8e2..2370022 100644 --- a/src/llvm_kaleidoscope_rs/llvm/basic_block.rs.html +++ b/src/llvm_kaleidoscope_rs/llvm/basic_block.rs.html @@ -1,10 +1,4 @@ -<!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="Source of the Rust file `src/llvm/basic_block.rs`."><meta name="keywords" content="rust, rustlang, rust-lang"><title>basic_block.rs - source</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" type="text/css" href="../../../normalize.css"><link rel="stylesheet" type="text/css" href="../../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../../ayu.css" disabled><link rel="stylesheet" type="text/css" href="../../../dark.css" disabled><link rel="stylesheet" type="text/css" href="../../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../../storage.js"></script><script defer src="../../../source-script.js"></script><script defer src="../../../source-files.js"></script><script defer src="../../../main.js"></script><noscript><link rel="stylesheet" href="../../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../../favicon.svg"></head><body class="rustdoc source"><!--[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">☰</button><a class="sidebar-logo" href="../../../llvm_kaleidoscope_rs/index.html"><div class="logo-container"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></div> - </a><h2 class="location"></h2> - </nav> - <nav class="sidebar"><a class="sidebar-logo" href="../../../llvm_kaleidoscope_rs/index.html"><div class="logo-container"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></div> - </a></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../../../llvm_kaleidoscope_rs/index.html"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></a><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><button type="button" id="help-button" title="help">?</button><div id="settings-menu" tabindex="-1"> - <a href="../../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../../wheel.svg"></a></div> - </div></form></nav></div><section id="main-content" class="content"><div class="example-wrap"><pre class="line-numbers"><span id="1">1</span> +<!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="Source of the Rust file `src/llvm/basic_block.rs`."><meta name="keywords" content="rust, rustlang, rust-lang"><title>basic_block.rs - source</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../../../normalize.css"><link rel="stylesheet" href="../../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../../../ayu.css" disabled><link rel="stylesheet" href="../../../dark.css" disabled><link rel="stylesheet" href="../../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../../storage.js"></script><script defer src="../../../source-script.js"></script><script defer src="../../../source-files.js"></script><script defer src="../../../main.js"></script><noscript><link rel="stylesheet" href="../../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../../favicon.svg"></head><body class="rustdoc source"><!--[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">☰</button><a class="sidebar-logo" href="../../../llvm_kaleidoscope_rs/index.html"><div class="logo-container"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></div></a><h2 class="location"></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../../../llvm_kaleidoscope_rs/index.html"><div class="logo-container"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></div></a></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../../../llvm_kaleidoscope_rs/index.html"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></a><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><button type="button">?</button></div><div id="settings-menu" tabindex="-1"><a href="../../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../../wheel.svg"></a></div></div></form></nav></div><section id="main-content" class="content"><div class="example-wrap"><pre class="line-numbers"><span id="1">1</span> <span id="2">2</span> <span id="3">3</span> <span id="4">4</span> @@ -43,45 +37,44 @@ <span id="37">37</span> <span id="38">38</span> <span id="39">39</span> -</pre><pre class="rust"><code><span class="kw">use</span> <span class="ident">llvm_sys</span>::{<span class="ident">core::LLVMGetBasicBlockParent</span>, <span class="ident">prelude::LLVMBasicBlockRef</span>}; +</pre><pre class="rust"><code><span class="kw">use </span>llvm_sys::{core::LLVMGetBasicBlockParent, prelude::LLVMBasicBlockRef}; -<span class="kw">use</span> <span class="ident">std::marker::PhantomData</span>; +<span class="kw">use </span>std::marker::PhantomData; -<span class="kw">use</span> <span class="ident"><span class="kw">super</span>::FnValue</span>; +<span class="kw">use </span><span class="kw">super</span>::FnValue; -<span class="doccomment">/// Wrapper for a LLVM Basic Block.</span> -<span class="attribute">#[<span class="ident">derive</span>(<span class="ident">Copy</span>, <span class="ident">Clone</span>)]</span> -<span class="kw">pub</span> <span class="kw">struct</span> <span class="ident">BasicBlock</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>(<span class="ident">LLVMBasicBlockRef</span>, <span class="ident">PhantomData</span><span class="op"><</span><span class="kw-2">&</span><span class="lifetime">'llvm</span> ()<span class="op">></span>); +<span class="doccomment">/// Wrapper for a LLVM Basic Block. +</span><span class="attribute">#[derive(Copy, Clone)] +</span><span class="kw">pub struct </span>BasicBlock<<span class="lifetime">'llvm</span>>(LLVMBasicBlockRef, PhantomData<<span class="kw-2">&</span><span class="lifetime">'llvm </span>()>); -<span class="kw">impl</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> <span class="ident">BasicBlock</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> { - <span class="doccomment">/// Create a new BasicBlock instance.</span> - <span class="doccomment">///</span> - <span class="doccomment">/// # Panics</span> - <span class="doccomment">///</span> - <span class="doccomment">/// Panics if `bb_ref` is a null pointer.</span> - <span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn</span> <span class="ident">new</span>(<span class="ident">bb_ref</span>: <span class="ident">LLVMBasicBlockRef</span>) -> <span class="ident">BasicBlock</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> { - <span class="macro">assert!</span>(<span class="op">!</span><span class="ident">bb_ref</span>.<span class="ident">is_null</span>()); - <span class="ident">BasicBlock</span>(<span class="ident">bb_ref</span>, <span class="ident">PhantomData</span>) +<span class="kw">impl</span><<span class="lifetime">'llvm</span>> BasicBlock<<span class="lifetime">'llvm</span>> { + <span class="doccomment">/// Create a new BasicBlock instance. + /// + /// # Panics + /// + /// Panics if `bb_ref` is a null pointer. + </span><span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn </span>new(bb_ref: LLVMBasicBlockRef) -> BasicBlock<<span class="lifetime">'llvm</span>> { + <span class="macro">assert!</span>(!bb_ref.is_null()); + BasicBlock(bb_ref, PhantomData) } - <span class="doccomment">/// Get the raw LLVM value reference.</span> - <span class="attribute">#[<span class="ident">inline</span>]</span> - <span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn</span> <span class="ident">bb_ref</span>(<span class="kw-2">&</span><span class="self">self</span>) -> <span class="ident">LLVMBasicBlockRef</span> { - <span class="self">self</span>.<span class="number">0</span> - } + <span class="doccomment">/// Get the raw LLVM value reference. + </span><span class="attribute">#[inline] + </span><span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn </span>bb_ref(<span class="kw-2">&</span><span class="self">self</span>) -> LLVMBasicBlockRef { + <span class="self">self</span>.<span class="number">0 + </span>} - <span class="doccomment">/// Get the function to which the basic block belongs.</span> - <span class="doccomment">///</span> - <span class="doccomment">/// # Panics</span> - <span class="doccomment">///</span> - <span class="doccomment">/// Panics if LLVM API returns a `null` pointer.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">get_parent</span>(<span class="kw-2">&</span><span class="self">self</span>) -> <span class="ident">FnValue</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> { - <span class="kw">let</span> <span class="ident">value_ref</span> <span class="op">=</span> <span class="kw">unsafe</span> { <span class="ident">LLVMGetBasicBlockParent</span>(<span class="self">self</span>.<span class="ident">bb_ref</span>()) }; - <span class="macro">assert!</span>(<span class="op">!</span><span class="ident">value_ref</span>.<span class="ident">is_null</span>()); + <span class="doccomment">/// Get the function to which the basic block belongs. + /// + /// # Panics + /// + /// Panics if LLVM API returns a `null` pointer. + </span><span class="kw">pub fn </span>get_parent(<span class="kw-2">&</span><span class="self">self</span>) -> FnValue<<span class="lifetime">'llvm</span>> { + <span class="kw">let </span>value_ref = <span class="kw">unsafe </span>{ LLVMGetBasicBlockParent(<span class="self">self</span>.bb_ref()) }; + <span class="macro">assert!</span>(!value_ref.is_null()); - <span class="ident">FnValue::new</span>(<span class="ident">value_ref</span>) + FnValue::new(value_ref) } } </code></pre></div> -</section></div></main><div id="rustdoc-vars" data-root-path="../../../" data-current-crate="llvm_kaleidoscope_rs" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.63.0 (4b91a6ea7 2022-08-08)" ></div> -</body></html>
\ No newline at end of file +</section></div></main><div id="rustdoc-vars" data-root-path="../../../" data-current-crate="llvm_kaleidoscope_rs" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.65.0 (897e37553 2022-11-02)" ></div></body></html>
\ No newline at end of file diff --git a/src/llvm_kaleidoscope_rs/llvm/builder.rs.html b/src/llvm_kaleidoscope_rs/llvm/builder.rs.html index 934351a..fad1867 100644 --- a/src/llvm_kaleidoscope_rs/llvm/builder.rs.html +++ b/src/llvm_kaleidoscope_rs/llvm/builder.rs.html @@ -1,10 +1,4 @@ -<!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="Source of the Rust file `src/llvm/builder.rs`."><meta name="keywords" content="rust, rustlang, rust-lang"><title>builder.rs - source</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" type="text/css" href="../../../normalize.css"><link rel="stylesheet" type="text/css" href="../../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../../ayu.css" disabled><link rel="stylesheet" type="text/css" href="../../../dark.css" disabled><link rel="stylesheet" type="text/css" href="../../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../../storage.js"></script><script defer src="../../../source-script.js"></script><script defer src="../../../source-files.js"></script><script defer src="../../../main.js"></script><noscript><link rel="stylesheet" href="../../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../../favicon.svg"></head><body class="rustdoc source"><!--[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">☰</button><a class="sidebar-logo" href="../../../llvm_kaleidoscope_rs/index.html"><div class="logo-container"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></div> - </a><h2 class="location"></h2> - </nav> - <nav class="sidebar"><a class="sidebar-logo" href="../../../llvm_kaleidoscope_rs/index.html"><div class="logo-container"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></div> - </a></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../../../llvm_kaleidoscope_rs/index.html"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></a><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><button type="button" id="help-button" title="help">?</button><div id="settings-menu" tabindex="-1"> - <a href="../../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../../wheel.svg"></a></div> - </div></form></nav></div><section id="main-content" class="content"><div class="example-wrap"><pre class="line-numbers"><span id="1">1</span> +<!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="Source of the Rust file `src/llvm/builder.rs`."><meta name="keywords" content="rust, rustlang, rust-lang"><title>builder.rs - source</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../../../normalize.css"><link rel="stylesheet" href="../../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../../../ayu.css" disabled><link rel="stylesheet" href="../../../dark.css" disabled><link rel="stylesheet" href="../../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../../storage.js"></script><script defer src="../../../source-script.js"></script><script defer src="../../../source-files.js"></script><script defer src="../../../main.js"></script><noscript><link rel="stylesheet" href="../../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../../favicon.svg"></head><body class="rustdoc source"><!--[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">☰</button><a class="sidebar-logo" href="../../../llvm_kaleidoscope_rs/index.html"><div class="logo-container"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></div></a><h2 class="location"></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../../../llvm_kaleidoscope_rs/index.html"><div class="logo-container"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></div></a></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../../../llvm_kaleidoscope_rs/index.html"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></a><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><button type="button">?</button></div><div id="settings-menu" tabindex="-1"><a href="../../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../../wheel.svg"></a></div></div></form></nav></div><section id="main-content" class="content"><div class="example-wrap"><pre class="line-numbers"><span id="1">1</span> <span id="2">2</span> <span id="3">3</span> <span id="4">4</span> @@ -283,285 +277,284 @@ <span id="277">277</span> <span id="278">278</span> <span id="279">279</span> -</pre><pre class="rust"><code><span class="kw">use</span> <span class="ident">llvm_sys</span>::{ - <span class="ident">core</span>::{ - <span class="ident">LLVMAddIncoming</span>, <span class="ident">LLVMBuildBr</span>, <span class="ident">LLVMBuildCondBr</span>, <span class="ident">LLVMBuildFAdd</span>, <span class="ident">LLVMBuildFCmp</span>, <span class="ident">LLVMBuildFMul</span>, - <span class="ident">LLVMBuildFSub</span>, <span class="ident">LLVMBuildPhi</span>, <span class="ident">LLVMBuildRet</span>, <span class="ident">LLVMBuildUIToFP</span>, <span class="ident">LLVMCreateBuilderInContext</span>, - <span class="ident">LLVMDisposeBuilder</span>, <span class="ident">LLVMGetInsertBlock</span>, <span class="ident">LLVMPositionBuilderAtEnd</span>, +</pre><pre class="rust"><code><span class="kw">use </span>llvm_sys::{ + core::{ + LLVMAddIncoming, LLVMBuildBr, LLVMBuildCondBr, LLVMBuildFAdd, LLVMBuildFCmp, LLVMBuildFMul, + LLVMBuildFSub, LLVMBuildPhi, LLVMBuildRet, LLVMBuildUIToFP, LLVMCreateBuilderInContext, + LLVMDisposeBuilder, LLVMGetInsertBlock, LLVMPositionBuilderAtEnd, }, - <span class="ident">prelude</span>::{<span class="ident">LLVMBuilderRef</span>, <span class="ident">LLVMValueRef</span>}, - <span class="ident">LLVMRealPredicate</span>, + prelude::{LLVMBuilderRef, LLVMValueRef}, + LLVMRealPredicate, }; -<span class="kw">use</span> <span class="ident">std::marker::PhantomData</span>; +<span class="kw">use </span>std::marker::PhantomData; -<span class="kw">use</span> <span class="kw">super</span>::{<span class="ident">BasicBlock</span>, <span class="ident">FnValue</span>, <span class="ident">Module</span>, <span class="ident">PhiValue</span>, <span class="ident">Type</span>, <span class="ident">Value</span>}; +<span class="kw">use super</span>::{BasicBlock, FnValue, Module, PhiValue, Type, Value}; -<span class="comment">// Definition of LLVM C API functions using our `repr(transparent)` types.</span> -<span class="kw">extern</span> <span class="string">"C"</span> { - <span class="kw">fn</span> <span class="ident">LLVMBuildCall2</span>( - <span class="ident">arg1</span>: <span class="ident">LLVMBuilderRef</span>, - <span class="ident">arg2</span>: <span class="ident">Type</span><span class="op"><</span><span class="lifetime">'_</span><span class="op">></span>, - <span class="ident">Fn</span>: <span class="ident">FnValue</span><span class="op"><</span><span class="lifetime">'_</span><span class="op">></span>, - <span class="ident">Args</span>: <span class="kw-2">*mut</span> <span class="ident">Value</span><span class="op"><</span><span class="lifetime">'_</span><span class="op">></span>, - <span class="ident">NumArgs</span>: <span class="ident">::libc::c_uint</span>, - <span class="ident">Name</span>: <span class="kw-2">*const</span> <span class="ident">::libc::c_char</span>, - ) -> <span class="ident">LLVMValueRef</span>; +<span class="comment">// Definition of LLVM C API functions using our `repr(transparent)` types. +</span><span class="kw">extern </span><span class="string">"C" </span>{ + <span class="kw">fn </span>LLVMBuildCall2( + arg1: LLVMBuilderRef, + arg2: Type<<span class="lifetime">'_</span>>, + Fn: FnValue<<span class="lifetime">'_</span>>, + Args: <span class="kw-2">*mut </span>Value<<span class="lifetime">'_</span>>, + NumArgs: ::libc::c_uint, + Name: <span class="kw-2">*const </span>::libc::c_char, + ) -> LLVMValueRef; } -<span class="doccomment">/// Wrapper for a LLVM IR Builder.</span> -<span class="kw">pub</span> <span class="kw">struct</span> <span class="ident">IRBuilder</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> { - <span class="ident">builder</span>: <span class="ident">LLVMBuilderRef</span>, - <span class="ident">_ctx</span>: <span class="ident">PhantomData</span><span class="op"><</span><span class="kw-2">&</span><span class="lifetime">'llvm</span> ()<span class="op">></span>, +<span class="doccomment">/// Wrapper for a LLVM IR Builder. +</span><span class="kw">pub struct </span>IRBuilder<<span class="lifetime">'llvm</span>> { + builder: LLVMBuilderRef, + _ctx: PhantomData<<span class="kw-2">&</span><span class="lifetime">'llvm </span>()>, } -<span class="kw">impl</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> <span class="ident">IRBuilder</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> { - <span class="doccomment">/// Create a new LLVM IR Builder with the `module`s context.</span> - <span class="doccomment">///</span> - <span class="doccomment">/// # Panics</span> - <span class="doccomment">///</span> - <span class="doccomment">/// Panics if creating the IR Builder fails.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">with_ctx</span>(<span class="ident">module</span>: <span class="kw-2">&</span><span class="lifetime">'llvm</span> <span class="ident">Module</span>) -> <span class="ident">IRBuilder</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> { - <span class="kw">let</span> <span class="ident">builder</span> <span class="op">=</span> <span class="kw">unsafe</span> { <span class="ident">LLVMCreateBuilderInContext</span>(<span class="ident">module</span>.<span class="ident">ctx</span>()) }; - <span class="macro">assert!</span>(<span class="op">!</span><span class="ident">builder</span>.<span class="ident">is_null</span>()); +<span class="kw">impl</span><<span class="lifetime">'llvm</span>> IRBuilder<<span class="lifetime">'llvm</span>> { + <span class="doccomment">/// Create a new LLVM IR Builder with the `module`s context. + /// + /// # Panics + /// + /// Panics if creating the IR Builder fails. + </span><span class="kw">pub fn </span>with_ctx(module: <span class="kw-2">&</span><span class="lifetime">'llvm </span>Module) -> IRBuilder<<span class="lifetime">'llvm</span>> { + <span class="kw">let </span>builder = <span class="kw">unsafe </span>{ LLVMCreateBuilderInContext(module.ctx()) }; + <span class="macro">assert!</span>(!builder.is_null()); - <span class="ident">IRBuilder</span> { - <span class="ident">builder</span>, - <span class="ident">_ctx</span>: <span class="ident">PhantomData</span>, + IRBuilder { + builder, + _ctx: PhantomData, } } - <span class="doccomment">/// Position the IR Builder at the end of the given Basic Block.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">pos_at_end</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">bb</span>: <span class="ident">BasicBlock</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>) { - <span class="kw">unsafe</span> { - <span class="ident">LLVMPositionBuilderAtEnd</span>(<span class="self">self</span>.<span class="ident">builder</span>, <span class="ident">bb</span>.<span class="ident">bb_ref</span>()); + <span class="doccomment">/// Position the IR Builder at the end of the given Basic Block. + </span><span class="kw">pub fn </span>pos_at_end(<span class="kw-2">&</span><span class="self">self</span>, bb: BasicBlock<<span class="lifetime">'llvm</span>>) { + <span class="kw">unsafe </span>{ + LLVMPositionBuilderAtEnd(<span class="self">self</span>.builder, bb.bb_ref()); } } - <span class="doccomment">/// Get the BasicBlock the IRBuilder currently inputs into.</span> - <span class="doccomment">///</span> - <span class="doccomment">/// # Panics</span> - <span class="doccomment">///</span> - <span class="doccomment">/// Panics if LLVM API returns a `null` pointer.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">get_insert_block</span>(<span class="kw-2">&</span><span class="self">self</span>) -> <span class="ident">BasicBlock</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> { - <span class="kw">let</span> <span class="ident">bb_ref</span> <span class="op">=</span> <span class="kw">unsafe</span> { <span class="ident">LLVMGetInsertBlock</span>(<span class="self">self</span>.<span class="ident">builder</span>) }; - <span class="macro">assert!</span>(<span class="op">!</span><span class="ident">bb_ref</span>.<span class="ident">is_null</span>()); + <span class="doccomment">/// Get the BasicBlock the IRBuilder currently inputs into. + /// + /// # Panics + /// + /// Panics if LLVM API returns a `null` pointer. + </span><span class="kw">pub fn </span>get_insert_block(<span class="kw-2">&</span><span class="self">self</span>) -> BasicBlock<<span class="lifetime">'llvm</span>> { + <span class="kw">let </span>bb_ref = <span class="kw">unsafe </span>{ LLVMGetInsertBlock(<span class="self">self</span>.builder) }; + <span class="macro">assert!</span>(!bb_ref.is_null()); - <span class="ident">BasicBlock::new</span>(<span class="ident">bb_ref</span>) + BasicBlock::new(bb_ref) } - <span class="doccomment">/// Emit a [fadd](https://llvm.org/docs/LangRef.html#fadd-instruction) instruction.</span> - <span class="doccomment">///</span> - <span class="doccomment">/// # Panics</span> - <span class="doccomment">///</span> - <span class="doccomment">/// Panics if LLVM API returns a `null` pointer.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">fadd</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">lhs</span>: <span class="ident">Value</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>, <span class="ident">rhs</span>: <span class="ident">Value</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>) -> <span class="ident">Value</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> { - <span class="macro">debug_assert!</span>(<span class="ident">lhs</span>.<span class="ident">is_f64</span>(), <span class="string">"fadd: Expected f64 as lhs operand!"</span>); - <span class="macro">debug_assert!</span>(<span class="ident">rhs</span>.<span class="ident">is_f64</span>(), <span class="string">"fadd: Expected f64 as rhs operand!"</span>); + <span class="doccomment">/// Emit a [fadd](https://llvm.org/docs/LangRef.html#fadd-instruction) instruction. + /// + /// # Panics + /// + /// Panics if LLVM API returns a `null` pointer. + </span><span class="kw">pub fn </span>fadd(<span class="kw-2">&</span><span class="self">self</span>, lhs: Value<<span class="lifetime">'llvm</span>>, rhs: Value<<span class="lifetime">'llvm</span>>) -> Value<<span class="lifetime">'llvm</span>> { + <span class="macro">debug_assert!</span>(lhs.is_f64(), <span class="string">"fadd: Expected f64 as lhs operand!"</span>); + <span class="macro">debug_assert!</span>(rhs.is_f64(), <span class="string">"fadd: Expected f64 as rhs operand!"</span>); - <span class="kw">let</span> <span class="ident">value_ref</span> <span class="op">=</span> <span class="kw">unsafe</span> { - <span class="ident">LLVMBuildFAdd</span>( - <span class="self">self</span>.<span class="ident">builder</span>, - <span class="ident">lhs</span>.<span class="ident">value_ref</span>(), - <span class="ident">rhs</span>.<span class="ident">value_ref</span>(), - <span class="string">b"fadd\0"</span>.<span class="ident">as_ptr</span>().<span class="ident">cast</span>(), + <span class="kw">let </span>value_ref = <span class="kw">unsafe </span>{ + LLVMBuildFAdd( + <span class="self">self</span>.builder, + lhs.value_ref(), + rhs.value_ref(), + <span class="string">b"fadd\0"</span>.as_ptr().cast(), ) }; - <span class="ident">Value::new</span>(<span class="ident">value_ref</span>) + Value::new(value_ref) } - <span class="doccomment">/// Emit a [fsub](https://llvm.org/docs/LangRef.html#fsub-instruction) instruction.</span> - <span class="doccomment">///</span> - <span class="doccomment">/// # Panics</span> - <span class="doccomment">///</span> - <span class="doccomment">/// Panics if LLVM API returns a `null` pointer.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">fsub</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">lhs</span>: <span class="ident">Value</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>, <span class="ident">rhs</span>: <span class="ident">Value</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>) -> <span class="ident">Value</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> { - <span class="macro">debug_assert!</span>(<span class="ident">lhs</span>.<span class="ident">is_f64</span>(), <span class="string">"fsub: Expected f64 as lhs operand!"</span>); - <span class="macro">debug_assert!</span>(<span class="ident">rhs</span>.<span class="ident">is_f64</span>(), <span class="string">"fsub: Expected f64 as rhs operand!"</span>); + <span class="doccomment">/// Emit a [fsub](https://llvm.org/docs/LangRef.html#fsub-instruction) instruction. + /// + /// # Panics + /// + /// Panics if LLVM API returns a `null` pointer. + </span><span class="kw">pub fn </span>fsub(<span class="kw-2">&</span><span class="self">self</span>, lhs: Value<<span class="lifetime">'llvm</span>>, rhs: Value<<span class="lifetime">'llvm</span>>) -> Value<<span class="lifetime">'llvm</span>> { + <span class="macro">debug_assert!</span>(lhs.is_f64(), <span class="string">"fsub: Expected f64 as lhs operand!"</span>); + <span class="macro">debug_assert!</span>(rhs.is_f64(), <span class="string">"fsub: Expected f64 as rhs operand!"</span>); - <span class="kw">let</span> <span class="ident">value_ref</span> <span class="op">=</span> <span class="kw">unsafe</span> { - <span class="ident">LLVMBuildFSub</span>( - <span class="self">self</span>.<span class="ident">builder</span>, - <span class="ident">lhs</span>.<span class="ident">value_ref</span>(), - <span class="ident">rhs</span>.<span class="ident">value_ref</span>(), - <span class="string">b"fsub\0"</span>.<span class="ident">as_ptr</span>().<span class="ident">cast</span>(), + <span class="kw">let </span>value_ref = <span class="kw">unsafe </span>{ + LLVMBuildFSub( + <span class="self">self</span>.builder, + lhs.value_ref(), + rhs.value_ref(), + <span class="string">b"fsub\0"</span>.as_ptr().cast(), ) }; - <span class="ident">Value::new</span>(<span class="ident">value_ref</span>) + Value::new(value_ref) } - <span class="doccomment">/// Emit a [fmul](https://llvm.org/docs/LangRef.html#fmul-instruction) instruction.</span> - <span class="doccomment">///</span> - <span class="doccomment">/// # Panics</span> - <span class="doccomment">///</span> - <span class="doccomment">/// Panics if LLVM API returns a `null` pointer.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">fmul</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">lhs</span>: <span class="ident">Value</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>, <span class="ident">rhs</span>: <span class="ident">Value</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>) -> <span class="ident">Value</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> { - <span class="macro">debug_assert!</span>(<span class="ident">lhs</span>.<span class="ident">is_f64</span>(), <span class="string">"fmul: Expected f64 as lhs operand!"</span>); - <span class="macro">debug_assert!</span>(<span class="ident">rhs</span>.<span class="ident">is_f64</span>(), <span class="string">"fmul: Expected f64 as rhs operand!"</span>); + <span class="doccomment">/// Emit a [fmul](https://llvm.org/docs/LangRef.html#fmul-instruction) instruction. + /// + /// # Panics + /// + /// Panics if LLVM API returns a `null` pointer. + </span><span class="kw">pub fn </span>fmul(<span class="kw-2">&</span><span class="self">self</span>, lhs: Value<<span class="lifetime">'llvm</span>>, rhs: Value<<span class="lifetime">'llvm</span>>) -> Value<<span class="lifetime">'llvm</span>> { + <span class="macro">debug_assert!</span>(lhs.is_f64(), <span class="string">"fmul: Expected f64 as lhs operand!"</span>); + <span class="macro">debug_assert!</span>(rhs.is_f64(), <span class="string">"fmul: Expected f64 as rhs operand!"</span>); - <span class="kw">let</span> <span class="ident">value_ref</span> <span class="op">=</span> <span class="kw">unsafe</span> { - <span class="ident">LLVMBuildFMul</span>( - <span class="self">self</span>.<span class="ident">builder</span>, - <span class="ident">lhs</span>.<span class="ident">value_ref</span>(), - <span class="ident">rhs</span>.<span class="ident">value_ref</span>(), - <span class="string">b"fmul\0"</span>.<span class="ident">as_ptr</span>().<span class="ident">cast</span>(), + <span class="kw">let </span>value_ref = <span class="kw">unsafe </span>{ + LLVMBuildFMul( + <span class="self">self</span>.builder, + lhs.value_ref(), + rhs.value_ref(), + <span class="string">b"fmul\0"</span>.as_ptr().cast(), ) }; - <span class="ident">Value::new</span>(<span class="ident">value_ref</span>) + Value::new(value_ref) } - <span class="doccomment">/// Emit a [fcmpult](https://llvm.org/docs/LangRef.html#fcmp-instruction) instruction.</span> - <span class="doccomment">///</span> - <span class="doccomment">/// # Panics</span> - <span class="doccomment">///</span> - <span class="doccomment">/// Panics if LLVM API returns a `null` pointer.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">fcmpult</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">lhs</span>: <span class="ident">Value</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>, <span class="ident">rhs</span>: <span class="ident">Value</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>) -> <span class="ident">Value</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> { - <span class="macro">debug_assert!</span>(<span class="ident">lhs</span>.<span class="ident">is_f64</span>(), <span class="string">"fcmpult: Expected f64 as lhs operand!"</span>); - <span class="macro">debug_assert!</span>(<span class="ident">rhs</span>.<span class="ident">is_f64</span>(), <span class="string">"fcmpult: Expected f64 as rhs operand!"</span>); + <span class="doccomment">/// Emit a [fcmpult](https://llvm.org/docs/LangRef.html#fcmp-instruction) instruction. + /// + /// # Panics + /// + /// Panics if LLVM API returns a `null` pointer. + </span><span class="kw">pub fn </span>fcmpult(<span class="kw-2">&</span><span class="self">self</span>, lhs: Value<<span class="lifetime">'llvm</span>>, rhs: Value<<span class="lifetime">'llvm</span>>) -> Value<<span class="lifetime">'llvm</span>> { + <span class="macro">debug_assert!</span>(lhs.is_f64(), <span class="string">"fcmpult: Expected f64 as lhs operand!"</span>); + <span class="macro">debug_assert!</span>(rhs.is_f64(), <span class="string">"fcmpult: Expected f64 as rhs operand!"</span>); - <span class="kw">let</span> <span class="ident">value_ref</span> <span class="op">=</span> <span class="kw">unsafe</span> { - <span class="ident">LLVMBuildFCmp</span>( - <span class="self">self</span>.<span class="ident">builder</span>, - <span class="ident">LLVMRealPredicate::LLVMRealULT</span>, - <span class="ident">lhs</span>.<span class="ident">value_ref</span>(), - <span class="ident">rhs</span>.<span class="ident">value_ref</span>(), - <span class="string">b"fcmpult\0"</span>.<span class="ident">as_ptr</span>().<span class="ident">cast</span>(), + <span class="kw">let </span>value_ref = <span class="kw">unsafe </span>{ + LLVMBuildFCmp( + <span class="self">self</span>.builder, + LLVMRealPredicate::LLVMRealULT, + lhs.value_ref(), + rhs.value_ref(), + <span class="string">b"fcmpult\0"</span>.as_ptr().cast(), ) }; - <span class="ident">Value::new</span>(<span class="ident">value_ref</span>) + Value::new(value_ref) } - <span class="doccomment">/// Emit a [fcmpone](https://llvm.org/docs/LangRef.html#fcmp-instruction) instruction.</span> - <span class="doccomment">///</span> - <span class="doccomment">/// # Panics</span> - <span class="doccomment">///</span> - <span class="doccomment">/// Panics if LLVM API returns a `null` pointer.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">fcmpone</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">lhs</span>: <span class="ident">Value</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>, <span class="ident">rhs</span>: <span class="ident">Value</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>) -> <span class="ident">Value</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> { - <span class="macro">debug_assert!</span>(<span class="ident">lhs</span>.<span class="ident">is_f64</span>(), <span class="string">"fcmone: Expected f64 as lhs operand!"</span>); - <span class="macro">debug_assert!</span>(<span class="ident">rhs</span>.<span class="ident">is_f64</span>(), <span class="string">"fcmone: Expected f64 as rhs operand!"</span>); + <span class="doccomment">/// Emit a [fcmpone](https://llvm.org/docs/LangRef.html#fcmp-instruction) instruction. + /// + /// # Panics + /// + /// Panics if LLVM API returns a `null` pointer. + </span><span class="kw">pub fn </span>fcmpone(<span class="kw-2">&</span><span class="self">self</span>, lhs: Value<<span class="lifetime">'llvm</span>>, rhs: Value<<span class="lifetime">'llvm</span>>) -> Value<<span class="lifetime">'llvm</span>> { + <span class="macro">debug_assert!</span>(lhs.is_f64(), <span class="string">"fcmone: Expected f64 as lhs operand!"</span>); + <span class="macro">debug_assert!</span>(rhs.is_f64(), <span class="string">"fcmone: Expected f64 as rhs operand!"</span>); - <span class="kw">let</span> <span class="ident">value_ref</span> <span class="op">=</span> <span class="kw">unsafe</span> { - <span class="ident">LLVMBuildFCmp</span>( - <span class="self">self</span>.<span class="ident">builder</span>, - <span class="ident">LLVMRealPredicate::LLVMRealONE</span>, - <span class="ident">lhs</span>.<span class="ident">value_ref</span>(), - <span class="ident">rhs</span>.<span class="ident">value_ref</span>(), - <span class="string">b"fcmpone\0"</span>.<span class="ident">as_ptr</span>().<span class="ident">cast</span>(), + <span class="kw">let </span>value_ref = <span class="kw">unsafe </span>{ + LLVMBuildFCmp( + <span class="self">self</span>.builder, + LLVMRealPredicate::LLVMRealONE, + lhs.value_ref(), + rhs.value_ref(), + <span class="string">b"fcmpone\0"</span>.as_ptr().cast(), ) }; - <span class="ident">Value::new</span>(<span class="ident">value_ref</span>) + Value::new(value_ref) } - <span class="doccomment">/// Emit a [uitofp](https://llvm.org/docs/LangRef.html#uitofp-to-instruction) instruction.</span> - <span class="doccomment">///</span> - <span class="doccomment">/// # Panics</span> - <span class="doccomment">///</span> - <span class="doccomment">/// Panics if LLVM API returns a `null` pointer.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">uitofp</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">val</span>: <span class="ident">Value</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>, <span class="ident">dest_type</span>: <span class="ident">Type</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>) -> <span class="ident">Value</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> { - <span class="macro">debug_assert!</span>(<span class="ident">val</span>.<span class="ident">is_int</span>(), <span class="string">"uitofp: Expected integer operand!"</span>); + <span class="doccomment">/// Emit a [uitofp](https://llvm.org/docs/LangRef.html#uitofp-to-instruction) instruction. + /// + /// # Panics + /// + /// Panics if LLVM API returns a `null` pointer. + </span><span class="kw">pub fn </span>uitofp(<span class="kw-2">&</span><span class="self">self</span>, val: Value<<span class="lifetime">'llvm</span>>, dest_type: Type<<span class="lifetime">'llvm</span>>) -> Value<<span class="lifetime">'llvm</span>> { + <span class="macro">debug_assert!</span>(val.is_int(), <span class="string">"uitofp: Expected integer operand!"</span>); - <span class="kw">let</span> <span class="ident">value_ref</span> <span class="op">=</span> <span class="kw">unsafe</span> { - <span class="ident">LLVMBuildUIToFP</span>( - <span class="self">self</span>.<span class="ident">builder</span>, - <span class="ident">val</span>.<span class="ident">value_ref</span>(), - <span class="ident">dest_type</span>.<span class="ident">type_ref</span>(), - <span class="string">b"uitofp\0"</span>.<span class="ident">as_ptr</span>().<span class="ident">cast</span>(), + <span class="kw">let </span>value_ref = <span class="kw">unsafe </span>{ + LLVMBuildUIToFP( + <span class="self">self</span>.builder, + val.value_ref(), + dest_type.type_ref(), + <span class="string">b"uitofp\0"</span>.as_ptr().cast(), ) }; - <span class="ident">Value::new</span>(<span class="ident">value_ref</span>) + Value::new(value_ref) } - <span class="doccomment">/// Emit a [call](https://llvm.org/docs/LangRef.html#call-instruction) instruction.</span> - <span class="doccomment">///</span> - <span class="doccomment">/// # Panics</span> - <span class="doccomment">///</span> - <span class="doccomment">/// Panics if LLVM API returns a `null` pointer.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">call</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">fn_value</span>: <span class="ident">FnValue</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>, <span class="ident">args</span>: <span class="kw-2">&mut</span> [<span class="ident">Value</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>]) -> <span class="ident">Value</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> { - <span class="kw">let</span> <span class="ident">value_ref</span> <span class="op">=</span> <span class="kw">unsafe</span> { - <span class="ident">LLVMBuildCall2</span>( - <span class="self">self</span>.<span class="ident">builder</span>, - <span class="ident">fn_value</span>.<span class="ident">ret_type</span>(), - <span class="ident">fn_value</span>, - <span class="ident">args</span>.<span class="ident">as_mut_ptr</span>(), - <span class="ident">args</span>.<span class="ident">len</span>() <span class="kw">as</span> <span class="ident">libc::c_uint</span>, - <span class="string">b"call\0"</span>.<span class="ident">as_ptr</span>().<span class="ident">cast</span>(), + <span class="doccomment">/// Emit a [call](https://llvm.org/docs/LangRef.html#call-instruction) instruction. + /// + /// # Panics + /// + /// Panics if LLVM API returns a `null` pointer. + </span><span class="kw">pub fn </span>call(<span class="kw-2">&</span><span class="self">self</span>, fn_value: FnValue<<span class="lifetime">'llvm</span>>, args: <span class="kw-2">&mut </span>[Value<<span class="lifetime">'llvm</span>>]) -> Value<<span class="lifetime">'llvm</span>> { + <span class="kw">let </span>value_ref = <span class="kw">unsafe </span>{ + LLVMBuildCall2( + <span class="self">self</span>.builder, + fn_value.ret_type(), + fn_value, + args.as_mut_ptr(), + args.len() <span class="kw">as </span>libc::c_uint, + <span class="string">b"call\0"</span>.as_ptr().cast(), ) }; - <span class="ident">Value::new</span>(<span class="ident">value_ref</span>) + Value::new(value_ref) } - <span class="doccomment">/// Emit a [ret](https://llvm.org/docs/LangRef.html#ret-instruction) instruction.</span> - <span class="doccomment">///</span> - <span class="doccomment">/// # Panics</span> - <span class="doccomment">///</span> - <span class="doccomment">/// Panics if LLVM API returns a `null` pointer.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">ret</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">ret</span>: <span class="ident">Value</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>) { - <span class="kw">let</span> <span class="ident">ret</span> <span class="op">=</span> <span class="kw">unsafe</span> { <span class="ident">LLVMBuildRet</span>(<span class="self">self</span>.<span class="ident">builder</span>, <span class="ident">ret</span>.<span class="ident">value_ref</span>()) }; - <span class="macro">assert!</span>(<span class="op">!</span><span class="ident">ret</span>.<span class="ident">is_null</span>()); + <span class="doccomment">/// Emit a [ret](https://llvm.org/docs/LangRef.html#ret-instruction) instruction. + /// + /// # Panics + /// + /// Panics if LLVM API returns a `null` pointer. + </span><span class="kw">pub fn </span>ret(<span class="kw-2">&</span><span class="self">self</span>, ret: Value<<span class="lifetime">'llvm</span>>) { + <span class="kw">let </span>ret = <span class="kw">unsafe </span>{ LLVMBuildRet(<span class="self">self</span>.builder, ret.value_ref()) }; + <span class="macro">assert!</span>(!ret.is_null()); } - <span class="doccomment">/// Emit an unconditional [br](https://llvm.org/docs/LangRef.html#br-instruction) instruction.</span> - <span class="doccomment">///</span> - <span class="doccomment">/// # Panics</span> - <span class="doccomment">///</span> - <span class="doccomment">/// Panics if LLVM API returns a `null` pointer.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">br</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">dest</span>: <span class="ident">BasicBlock</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>) { - <span class="kw">let</span> <span class="ident">br_ref</span> <span class="op">=</span> <span class="kw">unsafe</span> { <span class="ident">LLVMBuildBr</span>(<span class="self">self</span>.<span class="ident">builder</span>, <span class="ident">dest</span>.<span class="ident">bb_ref</span>()) }; - <span class="macro">assert!</span>(<span class="op">!</span><span class="ident">br_ref</span>.<span class="ident">is_null</span>()); + <span class="doccomment">/// Emit an unconditional [br](https://llvm.org/docs/LangRef.html#br-instruction) instruction. + /// + /// # Panics + /// + /// Panics if LLVM API returns a `null` pointer. + </span><span class="kw">pub fn </span>br(<span class="kw-2">&</span><span class="self">self</span>, dest: BasicBlock<<span class="lifetime">'llvm</span>>) { + <span class="kw">let </span>br_ref = <span class="kw">unsafe </span>{ LLVMBuildBr(<span class="self">self</span>.builder, dest.bb_ref()) }; + <span class="macro">assert!</span>(!br_ref.is_null()); } - <span class="doccomment">/// Emit a conditional [br](https://llvm.org/docs/LangRef.html#br-instruction) instruction.</span> - <span class="doccomment">///</span> - <span class="doccomment">/// # Panics</span> - <span class="doccomment">///</span> - <span class="doccomment">/// Panics if LLVM API returns a `null` pointer.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">cond_br</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">cond</span>: <span class="ident">Value</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>, <span class="ident">then</span>: <span class="ident">BasicBlock</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>, <span class="ident">else_</span>: <span class="ident">BasicBlock</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>) { - <span class="kw">let</span> <span class="ident">br_ref</span> <span class="op">=</span> <span class="kw">unsafe</span> { - <span class="ident">LLVMBuildCondBr</span>( - <span class="self">self</span>.<span class="ident">builder</span>, - <span class="ident">cond</span>.<span class="ident">value_ref</span>(), - <span class="ident">then</span>.<span class="ident">bb_ref</span>(), - <span class="ident">else_</span>.<span class="ident">bb_ref</span>(), + <span class="doccomment">/// Emit a conditional [br](https://llvm.org/docs/LangRef.html#br-instruction) instruction. + /// + /// # Panics + /// + /// Panics if LLVM API returns a `null` pointer. + </span><span class="kw">pub fn </span>cond_br(<span class="kw-2">&</span><span class="self">self</span>, cond: Value<<span class="lifetime">'llvm</span>>, then: BasicBlock<<span class="lifetime">'llvm</span>>, else_: BasicBlock<<span class="lifetime">'llvm</span>>) { + <span class="kw">let </span>br_ref = <span class="kw">unsafe </span>{ + LLVMBuildCondBr( + <span class="self">self</span>.builder, + cond.value_ref(), + then.bb_ref(), + else_.bb_ref(), ) }; - <span class="macro">assert!</span>(<span class="op">!</span><span class="ident">br_ref</span>.<span class="ident">is_null</span>()); + <span class="macro">assert!</span>(!br_ref.is_null()); } - <span class="doccomment">/// Emit a [phi](https://llvm.org/docs/LangRef.html#phi-instruction) instruction.</span> - <span class="doccomment">///</span> - <span class="doccomment">/// # Panics</span> - <span class="doccomment">///</span> - <span class="doccomment">/// Panics if LLVM API returns a `null` pointer.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">phi</span>( + <span class="doccomment">/// Emit a [phi](https://llvm.org/docs/LangRef.html#phi-instruction) instruction. + /// + /// # Panics + /// + /// Panics if LLVM API returns a `null` pointer. + </span><span class="kw">pub fn </span>phi( <span class="kw-2">&</span><span class="self">self</span>, - <span class="ident">phi_type</span>: <span class="ident">Type</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>, - <span class="ident">incoming</span>: <span class="kw-2">&</span>[(<span class="ident">Value</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>, <span class="ident">BasicBlock</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>)], - ) -> <span class="ident">PhiValue</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> { - <span class="kw">let</span> <span class="ident">phi_ref</span> <span class="op">=</span> - <span class="kw">unsafe</span> { <span class="ident">LLVMBuildPhi</span>(<span class="self">self</span>.<span class="ident">builder</span>, <span class="ident">phi_type</span>.<span class="ident">type_ref</span>(), <span class="string">b"phi\0"</span>.<span class="ident">as_ptr</span>().<span class="ident">cast</span>()) }; - <span class="macro">assert!</span>(<span class="op">!</span><span class="ident">phi_ref</span>.<span class="ident">is_null</span>()); + phi_type: Type<<span class="lifetime">'llvm</span>>, + incoming: <span class="kw-2">&</span>[(Value<<span class="lifetime">'llvm</span>>, BasicBlock<<span class="lifetime">'llvm</span>>)], + ) -> PhiValue<<span class="lifetime">'llvm</span>> { + <span class="kw">let </span>phi_ref = + <span class="kw">unsafe </span>{ LLVMBuildPhi(<span class="self">self</span>.builder, phi_type.type_ref(), <span class="string">b"phi\0"</span>.as_ptr().cast()) }; + <span class="macro">assert!</span>(!phi_ref.is_null()); - <span class="kw">for</span> (<span class="ident">val</span>, <span class="ident">bb</span>) <span class="kw">in</span> <span class="ident">incoming</span> { + <span class="kw">for </span>(val, bb) <span class="kw">in </span>incoming { <span class="macro">debug_assert_eq!</span>( - <span class="ident">val</span>.<span class="ident">type_of</span>().<span class="ident">kind</span>(), - <span class="ident">phi_type</span>.<span class="ident">kind</span>(), - <span class="string">"Type of incoming phi value must be the same as the type used to build the phi node."</span> - ); + val.type_of().kind(), + phi_type.kind(), + <span class="string">"Type of incoming phi value must be the same as the type used to build the phi node." + </span>); - <span class="kw">unsafe</span> { - <span class="ident">LLVMAddIncoming</span>(<span class="ident">phi_ref</span>, <span class="kw-2">&mut</span> <span class="ident">val</span>.<span class="ident">value_ref</span>() <span class="kw">as</span> <span class="kw">_</span>, <span class="kw-2">&mut</span> <span class="ident">bb</span>.<span class="ident">bb_ref</span>() <span class="kw">as</span> <span class="kw">_</span>, <span class="number">1</span>); + <span class="kw">unsafe </span>{ + LLVMAddIncoming(phi_ref, <span class="kw-2">&mut </span>val.value_ref() <span class="kw">as _</span>, <span class="kw-2">&mut </span>bb.bb_ref() <span class="kw">as _</span>, <span class="number">1</span>); } } - <span class="ident">PhiValue::new</span>(<span class="ident">phi_ref</span>) + PhiValue::new(phi_ref) } } -<span class="kw">impl</span> <span class="ident">Drop</span> <span class="kw">for</span> <span class="ident">IRBuilder</span><span class="op"><</span><span class="lifetime">'_</span><span class="op">></span> { - <span class="kw">fn</span> <span class="ident">drop</span>(<span class="kw-2">&mut</span> <span class="self">self</span>) { - <span class="kw">unsafe</span> { <span class="ident">LLVMDisposeBuilder</span>(<span class="self">self</span>.<span class="ident">builder</span>) } +<span class="kw">impl </span>Drop <span class="kw">for </span>IRBuilder<<span class="lifetime">'_</span>> { + <span class="kw">fn </span>drop(<span class="kw-2">&mut </span><span class="self">self</span>) { + <span class="kw">unsafe </span>{ LLVMDisposeBuilder(<span class="self">self</span>.builder) } } } </code></pre></div> -</section></div></main><div id="rustdoc-vars" data-root-path="../../../" data-current-crate="llvm_kaleidoscope_rs" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.63.0 (4b91a6ea7 2022-08-08)" ></div> -</body></html>
\ No newline at end of file +</section></div></main><div id="rustdoc-vars" data-root-path="../../../" data-current-crate="llvm_kaleidoscope_rs" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.65.0 (897e37553 2022-11-02)" ></div></body></html>
\ No newline at end of file diff --git a/src/llvm_kaleidoscope_rs/llvm/lljit.rs.html b/src/llvm_kaleidoscope_rs/llvm/lljit.rs.html index 5a5a376..80be225 100644 --- a/src/llvm_kaleidoscope_rs/llvm/lljit.rs.html +++ b/src/llvm_kaleidoscope_rs/llvm/lljit.rs.html @@ -1,10 +1,4 @@ -<!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="Source of the Rust file `src/llvm/lljit.rs`."><meta name="keywords" content="rust, rustlang, rust-lang"><title>lljit.rs - source</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" type="text/css" href="../../../normalize.css"><link rel="stylesheet" type="text/css" href="../../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../../ayu.css" disabled><link rel="stylesheet" type="text/css" href="../../../dark.css" disabled><link rel="stylesheet" type="text/css" href="../../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../../storage.js"></script><script defer src="../../../source-script.js"></script><script defer src="../../../source-files.js"></script><script defer src="../../../main.js"></script><noscript><link rel="stylesheet" href="../../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../../favicon.svg"></head><body class="rustdoc source"><!--[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">☰</button><a class="sidebar-logo" href="../../../llvm_kaleidoscope_rs/index.html"><div class="logo-container"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></div> - </a><h2 class="location"></h2> - </nav> - <nav class="sidebar"><a class="sidebar-logo" href="../../../llvm_kaleidoscope_rs/index.html"><div class="logo-container"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></div> - </a></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../../../llvm_kaleidoscope_rs/index.html"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></a><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><button type="button" id="help-button" title="help">?</button><div id="settings-menu" tabindex="-1"> - <a href="../../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../../wheel.svg"></a></div> - </div></form></nav></div><section id="main-content" class="content"><div class="example-wrap"><pre class="line-numbers"><span id="1">1</span> +<!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="Source of the Rust file `src/llvm/lljit.rs`."><meta name="keywords" content="rust, rustlang, rust-lang"><title>lljit.rs - source</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../../../normalize.css"><link rel="stylesheet" href="../../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../../../ayu.css" disabled><link rel="stylesheet" href="../../../dark.css" disabled><link rel="stylesheet" href="../../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../../storage.js"></script><script defer src="../../../source-script.js"></script><script defer src="../../../source-files.js"></script><script defer src="../../../main.js"></script><noscript><link rel="stylesheet" href="../../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../../favicon.svg"></head><body class="rustdoc source"><!--[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">☰</button><a class="sidebar-logo" href="../../../llvm_kaleidoscope_rs/index.html"><div class="logo-container"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></div></a><h2 class="location"></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../../../llvm_kaleidoscope_rs/index.html"><div class="logo-container"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></div></a></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../../../llvm_kaleidoscope_rs/index.html"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></a><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><button type="button">?</button></div><div id="settings-menu" tabindex="-1"><a href="../../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../../wheel.svg"></a></div></div></form></nav></div><section id="main-content" class="content"><div class="example-wrap"><pre class="line-numbers"><span id="1">1</span> <span id="2">2</span> <span id="3">3</span> <span id="4">4</span> @@ -158,160 +152,159 @@ <span id="152">152</span> <span id="153">153</span> <span id="154">154</span> -</pre><pre class="rust"><code><span class="kw">use</span> <span class="ident">llvm_sys::orc2</span>::{ - <span class="ident">lljit</span>::{ - <span class="ident">LLVMOrcCreateLLJIT</span>, <span class="ident">LLVMOrcLLJITAddLLVMIRModuleWithRT</span>, <span class="ident">LLVMOrcLLJITGetGlobalPrefix</span>, - <span class="ident">LLVMOrcLLJITGetMainJITDylib</span>, <span class="ident">LLVMOrcLLJITLookup</span>, <span class="ident">LLVMOrcLLJITRef</span>, +</pre><pre class="rust"><code><span class="kw">use </span>llvm_sys::orc2::{ + lljit::{ + LLVMOrcCreateLLJIT, LLVMOrcLLJITAddLLVMIRModuleWithRT, LLVMOrcLLJITGetGlobalPrefix, + LLVMOrcLLJITGetMainJITDylib, LLVMOrcLLJITLookup, LLVMOrcLLJITRef, }, - <span class="ident">LLVMOrcCreateDynamicLibrarySearchGeneratorForProcess</span>, <span class="ident">LLVMOrcDefinitionGeneratorRef</span>, - <span class="ident">LLVMOrcJITDylibAddGenerator</span>, <span class="ident">LLVMOrcJITDylibCreateResourceTracker</span>, <span class="ident">LLVMOrcJITDylibRef</span>, - <span class="ident">LLVMOrcReleaseResourceTracker</span>, <span class="ident">LLVMOrcResourceTrackerRef</span>, <span class="ident">LLVMOrcResourceTrackerRemove</span>, + LLVMOrcCreateDynamicLibrarySearchGeneratorForProcess, LLVMOrcDefinitionGeneratorRef, + LLVMOrcJITDylibAddGenerator, LLVMOrcJITDylibCreateResourceTracker, LLVMOrcJITDylibRef, + LLVMOrcReleaseResourceTracker, LLVMOrcResourceTrackerRef, LLVMOrcResourceTrackerRemove, }; -<span class="kw">use</span> <span class="ident">std::convert::TryFrom</span>; -<span class="kw">use</span> <span class="ident">std::marker::PhantomData</span>; +<span class="kw">use </span>std::convert::TryFrom; +<span class="kw">use </span>std::marker::PhantomData; -<span class="kw">use</span> <span class="kw">super</span>::{<span class="ident">Error</span>, <span class="ident">Module</span>}; -<span class="kw">use</span> <span class="ident"><span class="kw">crate</span>::SmallCStr</span>; +<span class="kw">use super</span>::{Error, Module}; +<span class="kw">use </span><span class="kw">crate</span>::SmallCStr; -<span class="doccomment">/// Marker trait to constrain function signatures that can be looked up in the JIT.</span> -<span class="kw">pub</span> <span class="kw">trait</span> <span class="ident">JitFn</span> {} +<span class="doccomment">/// Marker trait to constrain function signatures that can be looked up in the JIT. +</span><span class="kw">pub trait </span>JitFn {} -<span class="kw">impl</span> <span class="ident">JitFn</span> <span class="kw">for</span> <span class="kw">unsafe</span> <span class="kw">extern</span> <span class="string">"C"</span> <span class="kw">fn</span>() -> <span class="ident">f64</span> {} +<span class="kw">impl </span>JitFn <span class="kw">for unsafe extern </span><span class="string">"C" </span><span class="kw">fn</span>() -> f64 {} -<span class="doccomment">/// Wrapper for a LLVM [LLJIT](https://www.llvm.org/docs/ORCv2.html#lljit-and-lllazyjit).</span> -<span class="kw">pub</span> <span class="kw">struct</span> <span class="ident">LLJit</span> { - <span class="ident">jit</span>: <span class="ident">LLVMOrcLLJITRef</span>, - <span class="ident">dylib</span>: <span class="ident">LLVMOrcJITDylibRef</span>, +<span class="doccomment">/// Wrapper for a LLVM [LLJIT](https://www.llvm.org/docs/ORCv2.html#lljit-and-lllazyjit). +</span><span class="kw">pub struct </span>LLJit { + jit: LLVMOrcLLJITRef, + dylib: LLVMOrcJITDylibRef, } -<span class="kw">impl</span> <span class="ident">LLJit</span> { - <span class="doccomment">/// Create a new LLJit instance.</span> - <span class="doccomment">///</span> - <span class="doccomment">/// # Panics</span> - <span class="doccomment">///</span> - <span class="doccomment">/// Panics if LLVM API returns a `null` pointer or an error.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">new</span>() -> <span class="ident">LLJit</span> { - <span class="kw">let</span> (<span class="ident">jit</span>, <span class="ident">dylib</span>) <span class="op">=</span> <span class="kw">unsafe</span> { - <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">jit</span> <span class="op">=</span> <span class="ident">std::ptr::null_mut</span>(); - <span class="kw">let</span> <span class="ident">err</span> <span class="op">=</span> <span class="ident">LLVMOrcCreateLLJIT</span>( - <span class="kw-2">&mut</span> <span class="ident">jit</span> <span class="kw">as</span> <span class="kw">_</span>, - <span class="ident">std::ptr::null_mut</span>(), <span class="comment">/* builder: nullptr -> default */</span> - ); +<span class="kw">impl </span>LLJit { + <span class="doccomment">/// Create a new LLJit instance. + /// + /// # Panics + /// + /// Panics if LLVM API returns a `null` pointer or an error. + </span><span class="kw">pub fn </span>new() -> LLJit { + <span class="kw">let </span>(jit, dylib) = <span class="kw">unsafe </span>{ + <span class="kw">let </span><span class="kw-2">mut </span>jit = std::ptr::null_mut(); + <span class="kw">let </span>err = LLVMOrcCreateLLJIT( + <span class="kw-2">&mut </span>jit <span class="kw">as _</span>, + std::ptr::null_mut(), <span class="comment">/* builder: nullptr -> default */ + </span>); - <span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="ident">err</span>) <span class="op">=</span> <span class="ident">Error::from</span>(<span class="ident">err</span>) { - <span class="macro">panic!</span>(<span class="string">"Error: {}"</span>, <span class="ident">err</span>.<span class="ident">as_str</span>()); + <span class="kw">if let </span><span class="prelude-val">Some</span>(err) = Error::from(err) { + <span class="macro">panic!</span>(<span class="string">"Error: {}"</span>, err.as_str()); } - <span class="kw">let</span> <span class="ident">dylib</span> <span class="op">=</span> <span class="ident">LLVMOrcLLJITGetMainJITDylib</span>(<span class="ident">jit</span>); - <span class="macro">assert!</span>(<span class="op">!</span><span class="ident">dylib</span>.<span class="ident">is_null</span>()); + <span class="kw">let </span>dylib = LLVMOrcLLJITGetMainJITDylib(jit); + <span class="macro">assert!</span>(!dylib.is_null()); - (<span class="ident">jit</span>, <span class="ident">dylib</span>) + (jit, dylib) }; - <span class="ident">LLJit</span> { <span class="ident">jit</span>, <span class="ident">dylib</span> } + LLJit { jit, dylib } } - <span class="doccomment">/// Add an LLVM IR module to the JIT. Return a [`ResourceTracker`], which when dropped, will</span> - <span class="doccomment">/// remove the code of the LLVM IR module from the JIT.</span> - <span class="doccomment">///</span> - <span class="doccomment">/// # Panics</span> - <span class="doccomment">///</span> - <span class="doccomment">/// Panics if LLVM API returns a `null` pointer or an error.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">add_module</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">module</span>: <span class="ident">Module</span>) -> <span class="ident">ResourceTracker</span><span class="op"><</span><span class="lifetime">'_</span><span class="op">></span> { - <span class="kw">let</span> <span class="ident">tsmod</span> <span class="op">=</span> <span class="ident">module</span>.<span class="ident">into_raw_thread_safe_module</span>(); + <span class="doccomment">/// Add an LLVM IR module to the JIT. Return a [`ResourceTracker`], which when dropped, will + /// remove the code of the LLVM IR module from the JIT. + /// + /// # Panics + /// + /// Panics if LLVM API returns a `null` pointer or an error. + </span><span class="kw">pub fn </span>add_module(<span class="kw-2">&</span><span class="self">self</span>, module: Module) -> ResourceTracker<<span class="lifetime">'_</span>> { + <span class="kw">let </span>tsmod = module.into_raw_thread_safe_module(); - <span class="kw">let</span> <span class="ident">rt</span> <span class="op">=</span> <span class="kw">unsafe</span> { - <span class="kw">let</span> <span class="ident">rt</span> <span class="op">=</span> <span class="ident">LLVMOrcJITDylibCreateResourceTracker</span>(<span class="self">self</span>.<span class="ident">dylib</span>); - <span class="kw">let</span> <span class="ident">err</span> <span class="op">=</span> <span class="ident">LLVMOrcLLJITAddLLVMIRModuleWithRT</span>(<span class="self">self</span>.<span class="ident">jit</span>, <span class="ident">rt</span>, <span class="ident">tsmod</span>); + <span class="kw">let </span>rt = <span class="kw">unsafe </span>{ + <span class="kw">let </span>rt = LLVMOrcJITDylibCreateResourceTracker(<span class="self">self</span>.dylib); + <span class="kw">let </span>err = LLVMOrcLLJITAddLLVMIRModuleWithRT(<span class="self">self</span>.jit, rt, tsmod); - <span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="ident">err</span>) <span class="op">=</span> <span class="ident">Error::from</span>(<span class="ident">err</span>) { - <span class="macro">panic!</span>(<span class="string">"Error: {}"</span>, <span class="ident">err</span>.<span class="ident">as_str</span>()); + <span class="kw">if let </span><span class="prelude-val">Some</span>(err) = Error::from(err) { + <span class="macro">panic!</span>(<span class="string">"Error: {}"</span>, err.as_str()); } - <span class="ident">rt</span> + rt }; - <span class="ident">ResourceTracker::new</span>(<span class="ident">rt</span>) + ResourceTracker::new(rt) } - <span class="doccomment">/// Find the symbol with the name `sym` in the JIT.</span> - <span class="doccomment">///</span> - <span class="doccomment">/// # Panics</span> - <span class="doccomment">///</span> - <span class="doccomment">/// Panics if the symbol is not found in the JIT.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">find_symbol</span><span class="op"><</span><span class="ident">F</span>: <span class="ident">JitFn</span><span class="op">></span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">sym</span>: <span class="kw-2">&</span><span class="ident">str</span>) -> <span class="ident">F</span> { - <span class="kw">let</span> <span class="ident">sym</span> <span class="op">=</span> - <span class="ident">SmallCStr::try_from</span>(<span class="ident">sym</span>).<span class="ident">expect</span>(<span class="string">"Failed to convert 'sym' argument to small C string!"</span>); + <span class="doccomment">/// Find the symbol with the name `sym` in the JIT. + /// + /// # Panics + /// + /// Panics if the symbol is not found in the JIT. + </span><span class="kw">pub fn </span>find_symbol<F: JitFn>(<span class="kw-2">&</span><span class="self">self</span>, sym: <span class="kw-2">&</span>str) -> F { + <span class="kw">let </span>sym = + SmallCStr::try_from(sym).expect(<span class="string">"Failed to convert 'sym' argument to small C string!"</span>); - <span class="kw">unsafe</span> { - <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">addr</span> <span class="op">=</span> <span class="number">0u64</span>; - <span class="kw">let</span> <span class="ident">err</span> <span class="op">=</span> <span class="ident">LLVMOrcLLJITLookup</span>(<span class="self">self</span>.<span class="ident">jit</span>, <span class="kw-2">&mut</span> <span class="ident">addr</span> <span class="kw">as</span> <span class="kw">_</span>, <span class="ident">sym</span>.<span class="ident">as_ptr</span>()); + <span class="kw">unsafe </span>{ + <span class="kw">let </span><span class="kw-2">mut </span>addr = <span class="number">0u64</span>; + <span class="kw">let </span>err = LLVMOrcLLJITLookup(<span class="self">self</span>.jit, <span class="kw-2">&mut </span>addr <span class="kw">as _</span>, sym.as_ptr()); - <span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="ident">err</span>) <span class="op">=</span> <span class="ident">Error::from</span>(<span class="ident">err</span>) { - <span class="macro">panic!</span>(<span class="string">"Error: {}"</span>, <span class="ident">err</span>.<span class="ident">as_str</span>()); + <span class="kw">if let </span><span class="prelude-val">Some</span>(err) = Error::from(err) { + <span class="macro">panic!</span>(<span class="string">"Error: {}"</span>, err.as_str()); } - <span class="macro">debug_assert_eq!</span>(<span class="ident">core::mem::size_of_val</span>(<span class="kw-2">&</span><span class="ident">addr</span>), <span class="ident">core::mem::size_of</span>::<span class="op"><</span><span class="ident">F</span><span class="op">></span>()); - <span class="ident">std::mem::transmute_copy</span>(<span class="kw-2">&</span><span class="ident">addr</span>) + <span class="macro">debug_assert_eq!</span>(core::mem::size_of_val(<span class="kw-2">&</span>addr), core::mem::size_of::<F>()); + std::mem::transmute_copy(<span class="kw-2">&</span>addr) } } - <span class="doccomment">/// Enable lookup of dynamic symbols available in the current process from the JIT.</span> - <span class="doccomment">///</span> - <span class="doccomment">/// # Panics</span> - <span class="doccomment">///</span> - <span class="doccomment">/// Panics if LLVM API returns an error.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">enable_process_symbols</span>(<span class="kw-2">&</span><span class="self">self</span>) { - <span class="kw">unsafe</span> { - <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">proc_syms_gen</span>: <span class="ident">LLVMOrcDefinitionGeneratorRef</span> <span class="op">=</span> <span class="ident">std::ptr::null_mut</span>(); - <span class="kw">let</span> <span class="ident">err</span> <span class="op">=</span> <span class="ident">LLVMOrcCreateDynamicLibrarySearchGeneratorForProcess</span>( - <span class="kw-2">&mut</span> <span class="ident">proc_syms_gen</span> <span class="kw">as</span> <span class="kw">_</span>, - <span class="self">self</span>.<span class="ident">global_prefix</span>(), - <span class="prelude-val">None</span>, <span class="comment">/* filter */</span> - <span class="ident">std::ptr::null_mut</span>(), <span class="comment">/* filter ctx */</span> - ); + <span class="doccomment">/// Enable lookup of dynamic symbols available in the current process from the JIT. + /// + /// # Panics + /// + /// Panics if LLVM API returns an error. + </span><span class="kw">pub fn </span>enable_process_symbols(<span class="kw-2">&</span><span class="self">self</span>) { + <span class="kw">unsafe </span>{ + <span class="kw">let </span><span class="kw-2">mut </span>proc_syms_gen: LLVMOrcDefinitionGeneratorRef = std::ptr::null_mut(); + <span class="kw">let </span>err = LLVMOrcCreateDynamicLibrarySearchGeneratorForProcess( + <span class="kw-2">&mut </span>proc_syms_gen <span class="kw">as _</span>, + <span class="self">self</span>.global_prefix(), + <span class="prelude-val">None</span>, <span class="comment">/* filter */ + </span>std::ptr::null_mut(), <span class="comment">/* filter ctx */ + </span>); - <span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="ident">err</span>) <span class="op">=</span> <span class="ident">Error::from</span>(<span class="ident">err</span>) { - <span class="macro">panic!</span>(<span class="string">"Error: {}"</span>, <span class="ident">err</span>.<span class="ident">as_str</span>()); + <span class="kw">if let </span><span class="prelude-val">Some</span>(err) = Error::from(err) { + <span class="macro">panic!</span>(<span class="string">"Error: {}"</span>, err.as_str()); } - <span class="ident">LLVMOrcJITDylibAddGenerator</span>(<span class="self">self</span>.<span class="ident">dylib</span>, <span class="ident">proc_syms_gen</span>); + LLVMOrcJITDylibAddGenerator(<span class="self">self</span>.dylib, proc_syms_gen); } } - <span class="doccomment">/// Return the global prefix character according to the LLJITs data layout.</span> - <span class="kw">fn</span> <span class="ident">global_prefix</span>(<span class="kw-2">&</span><span class="self">self</span>) -> <span class="ident">libc::c_char</span> { - <span class="kw">unsafe</span> { <span class="ident">LLVMOrcLLJITGetGlobalPrefix</span>(<span class="self">self</span>.<span class="ident">jit</span>) } + <span class="doccomment">/// Return the global prefix character according to the LLJITs data layout. + </span><span class="kw">fn </span>global_prefix(<span class="kw-2">&</span><span class="self">self</span>) -> libc::c_char { + <span class="kw">unsafe </span>{ LLVMOrcLLJITGetGlobalPrefix(<span class="self">self</span>.jit) } } } -<span class="doccomment">/// A resource handle for code added to an [`LLJit`] instance.</span> -<span class="doccomment">///</span> -<span class="doccomment">/// When a `ResourceTracker` handle is dropped, the code corresponding to the handle will be</span> -<span class="doccomment">/// removed from the JIT.</span> -<span class="kw">pub</span> <span class="kw">struct</span> <span class="ident">ResourceTracker</span><span class="op"><</span><span class="lifetime">'jit</span><span class="op">></span>(<span class="ident">LLVMOrcResourceTrackerRef</span>, <span class="ident">PhantomData</span><span class="op"><</span><span class="kw-2">&</span><span class="lifetime">'jit</span> ()<span class="op">></span>); +<span class="doccomment">/// A resource handle for code added to an [`LLJit`] instance. +/// +/// When a `ResourceTracker` handle is dropped, the code corresponding to the handle will be +/// removed from the JIT. +</span><span class="kw">pub struct </span>ResourceTracker<<span class="lifetime">'jit</span>>(LLVMOrcResourceTrackerRef, PhantomData<<span class="kw-2">&</span><span class="lifetime">'jit </span>()>); -<span class="kw">impl</span><span class="op"><</span><span class="lifetime">'jit</span><span class="op">></span> <span class="ident">ResourceTracker</span><span class="op"><</span><span class="lifetime">'jit</span><span class="op">></span> { - <span class="kw">fn</span> <span class="ident">new</span>(<span class="ident">rt</span>: <span class="ident">LLVMOrcResourceTrackerRef</span>) -> <span class="ident">ResourceTracker</span><span class="op"><</span><span class="lifetime">'jit</span><span class="op">></span> { - <span class="macro">assert!</span>(<span class="op">!</span><span class="ident">rt</span>.<span class="ident">is_null</span>()); - <span class="ident">ResourceTracker</span>(<span class="ident">rt</span>, <span class="ident">PhantomData</span>) +<span class="kw">impl</span><<span class="lifetime">'jit</span>> ResourceTracker<<span class="lifetime">'jit</span>> { + <span class="kw">fn </span>new(rt: LLVMOrcResourceTrackerRef) -> ResourceTracker<<span class="lifetime">'jit</span>> { + <span class="macro">assert!</span>(!rt.is_null()); + ResourceTracker(rt, PhantomData) } } -<span class="kw">impl</span> <span class="ident">Drop</span> <span class="kw">for</span> <span class="ident">ResourceTracker</span><span class="op"><</span><span class="lifetime">'_</span><span class="op">></span> { - <span class="kw">fn</span> <span class="ident">drop</span>(<span class="kw-2">&mut</span> <span class="self">self</span>) { - <span class="kw">unsafe</span> { - <span class="kw">let</span> <span class="ident">err</span> <span class="op">=</span> <span class="ident">LLVMOrcResourceTrackerRemove</span>(<span class="self">self</span>.<span class="number">0</span>); +<span class="kw">impl </span>Drop <span class="kw">for </span>ResourceTracker<<span class="lifetime">'_</span>> { + <span class="kw">fn </span>drop(<span class="kw-2">&mut </span><span class="self">self</span>) { + <span class="kw">unsafe </span>{ + <span class="kw">let </span>err = LLVMOrcResourceTrackerRemove(<span class="self">self</span>.<span class="number">0</span>); - <span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="ident">err</span>) <span class="op">=</span> <span class="ident">Error::from</span>(<span class="ident">err</span>) { - <span class="macro">panic!</span>(<span class="string">"Error: {}"</span>, <span class="ident">err</span>.<span class="ident">as_str</span>()); + <span class="kw">if let </span><span class="prelude-val">Some</span>(err) = Error::from(err) { + <span class="macro">panic!</span>(<span class="string">"Error: {}"</span>, err.as_str()); } - <span class="ident">LLVMOrcReleaseResourceTracker</span>(<span class="self">self</span>.<span class="number">0</span>); + LLVMOrcReleaseResourceTracker(<span class="self">self</span>.<span class="number">0</span>); }; } } </code></pre></div> -</section></div></main><div id="rustdoc-vars" data-root-path="../../../" data-current-crate="llvm_kaleidoscope_rs" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.63.0 (4b91a6ea7 2022-08-08)" ></div> -</body></html>
\ No newline at end of file +</section></div></main><div id="rustdoc-vars" data-root-path="../../../" data-current-crate="llvm_kaleidoscope_rs" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.65.0 (897e37553 2022-11-02)" ></div></body></html>
\ No newline at end of file diff --git a/src/llvm_kaleidoscope_rs/llvm/mod.rs.html b/src/llvm_kaleidoscope_rs/llvm/mod.rs.html index 3dca9c7..87756d4 100644 --- a/src/llvm_kaleidoscope_rs/llvm/mod.rs.html +++ b/src/llvm_kaleidoscope_rs/llvm/mod.rs.html @@ -1,10 +1,4 @@ -<!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="Source of the Rust file `src/llvm/mod.rs`."><meta name="keywords" content="rust, rustlang, rust-lang"><title>mod.rs - source</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" type="text/css" href="../../../normalize.css"><link rel="stylesheet" type="text/css" href="../../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../../ayu.css" disabled><link rel="stylesheet" type="text/css" href="../../../dark.css" disabled><link rel="stylesheet" type="text/css" href="../../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../../storage.js"></script><script defer src="../../../source-script.js"></script><script defer src="../../../source-files.js"></script><script defer src="../../../main.js"></script><noscript><link rel="stylesheet" href="../../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../../favicon.svg"></head><body class="rustdoc source"><!--[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">☰</button><a class="sidebar-logo" href="../../../llvm_kaleidoscope_rs/index.html"><div class="logo-container"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></div> - </a><h2 class="location"></h2> - </nav> - <nav class="sidebar"><a class="sidebar-logo" href="../../../llvm_kaleidoscope_rs/index.html"><div class="logo-container"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></div> - </a></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../../../llvm_kaleidoscope_rs/index.html"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></a><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><button type="button" id="help-button" title="help">?</button><div id="settings-menu" tabindex="-1"> - <a href="../../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../../wheel.svg"></a></div> - </div></form></nav></div><section id="main-content" class="content"><div class="example-wrap"><pre class="line-numbers"><span id="1">1</span> +<!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="Source of the Rust file `src/llvm/mod.rs`."><meta name="keywords" content="rust, rustlang, rust-lang"><title>mod.rs - source</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../../../normalize.css"><link rel="stylesheet" href="../../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../../../ayu.css" disabled><link rel="stylesheet" href="../../../dark.css" disabled><link rel="stylesheet" href="../../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../../storage.js"></script><script defer src="../../../source-script.js"></script><script defer src="../../../source-files.js"></script><script defer src="../../../main.js"></script><noscript><link rel="stylesheet" href="../../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../../favicon.svg"></head><body class="rustdoc source"><!--[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">☰</button><a class="sidebar-logo" href="../../../llvm_kaleidoscope_rs/index.html"><div class="logo-container"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></div></a><h2 class="location"></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../../../llvm_kaleidoscope_rs/index.html"><div class="logo-container"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></div></a></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../../../llvm_kaleidoscope_rs/index.html"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></a><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><button type="button">?</button></div><div id="settings-menu" tabindex="-1"><a href="../../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../../wheel.svg"></a></div></div></form></nav></div><section id="main-content" class="content"><div class="example-wrap"><pre class="line-numbers"><span id="1">1</span> <span id="2">2</span> <span id="3">3</span> <span id="4">4</span> @@ -78,80 +72,79 @@ <span id="72">72</span> <span id="73">73</span> <span id="74">74</span> -</pre><pre class="rust"><code><span class="doccomment">//! Safe wrapper around the LLVM C API.</span> -<span class="doccomment">//!</span> -<span class="doccomment">//! References returned from the LLVM API are tied to the `'llvm` lifetime which is bound to the</span> -<span class="doccomment">//! context where the objects are created in.</span> -<span class="doccomment">//! We do not offer wrappers to remove or delete any objects in the context and therefore all the</span> -<span class="doccomment">//! references will be valid for the liftime of the context.</span> -<span class="doccomment">//!</span> -<span class="doccomment">//! For the scope of this tutorial we mainly use assertions to validate the results from the LLVM</span> -<span class="doccomment">//! API calls.</span> +</pre><pre class="rust"><code><span class="doccomment">//! Safe wrapper around the LLVM C API. +//! +//! References returned from the LLVM API are tied to the `'llvm` lifetime which is bound to the +//! context where the objects are created in. +//! We do not offer wrappers to remove or delete any objects in the context and therefore all the +//! references will be valid for the liftime of the context. +//! +//! For the scope of this tutorial we mainly use assertions to validate the results from the LLVM +//! API calls. -<span class="kw">use</span> <span class="ident">llvm_sys</span>::{ - <span class="ident">core::LLVMShutdown</span>, - <span class="ident">error</span>::{<span class="ident">LLVMDisposeErrorMessage</span>, <span class="ident">LLVMErrorRef</span>, <span class="ident">LLVMGetErrorMessage</span>}, - <span class="ident">target</span>::{ - <span class="ident">LLVM_InitializeNativeAsmParser</span>, <span class="ident">LLVM_InitializeNativeAsmPrinter</span>, - <span class="ident">LLVM_InitializeNativeTarget</span>, +</span><span class="kw">use </span>llvm_sys::{ + core::LLVMShutdown, + error::{LLVMDisposeErrorMessage, LLVMErrorRef, LLVMGetErrorMessage}, + target::{ + LLVM_InitializeNativeAsmParser, LLVM_InitializeNativeAsmPrinter, + LLVM_InitializeNativeTarget, }, }; -<span class="kw">use</span> <span class="ident">std::ffi::CStr</span>; +<span class="kw">use </span>std::ffi::CStr; -<span class="kw">mod</span> <span class="ident">basic_block</span>; -<span class="kw">mod</span> <span class="ident">builder</span>; -<span class="kw">mod</span> <span class="ident">lljit</span>; -<span class="kw">mod</span> <span class="ident">module</span>; -<span class="kw">mod</span> <span class="ident">pass_manager</span>; -<span class="kw">mod</span> <span class="ident">type_</span>; -<span class="kw">mod</span> <span class="ident">value</span>; +<span class="kw">mod </span>basic_block; +<span class="kw">mod </span>builder; +<span class="kw">mod </span>lljit; +<span class="kw">mod </span>module; +<span class="kw">mod </span>pass_manager; +<span class="kw">mod </span>type_; +<span class="kw">mod </span>value; -<span class="kw">pub</span> <span class="kw">use</span> <span class="ident">basic_block::BasicBlock</span>; -<span class="kw">pub</span> <span class="kw">use</span> <span class="ident">builder::IRBuilder</span>; -<span class="kw">pub</span> <span class="kw">use</span> <span class="ident">lljit</span>::{<span class="ident">LLJit</span>, <span class="ident">ResourceTracker</span>}; -<span class="kw">pub</span> <span class="kw">use</span> <span class="ident">module::Module</span>; -<span class="kw">pub</span> <span class="kw">use</span> <span class="ident">pass_manager::FunctionPassManager</span>; -<span class="kw">pub</span> <span class="kw">use</span> <span class="ident">type_::Type</span>; -<span class="kw">pub</span> <span class="kw">use</span> <span class="ident">value</span>::{<span class="ident">FnValue</span>, <span class="ident">PhiValue</span>, <span class="ident">Value</span>}; +<span class="kw">pub use </span>basic_block::BasicBlock; +<span class="kw">pub use </span>builder::IRBuilder; +<span class="kw">pub use </span>lljit::{LLJit, ResourceTracker}; +<span class="kw">pub use </span>module::Module; +<span class="kw">pub use </span>pass_manager::FunctionPassManager; +<span class="kw">pub use </span>type_::Type; +<span class="kw">pub use </span>value::{FnValue, PhiValue, Value}; -<span class="kw">struct</span> <span class="ident">Error</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>(<span class="kw-2">&</span><span class="lifetime">'llvm</span> <span class="kw-2">mut</span> <span class="ident">libc::c_char</span>); +<span class="kw">struct </span>Error<<span class="lifetime">'llvm</span>>(<span class="kw-2">&</span><span class="lifetime">'llvm </span><span class="kw-2">mut </span>libc::c_char); -<span class="kw">impl</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> <span class="ident">Error</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> { - <span class="kw">fn</span> <span class="ident">from</span>(<span class="ident">err</span>: <span class="ident">LLVMErrorRef</span>) -> <span class="prelude-ty">Option</span><span class="op"><</span><span class="ident">Error</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span><span class="op">></span> { - (<span class="op">!</span><span class="ident">err</span>.<span class="ident">is_null</span>()).<span class="ident">then</span>(<span class="op">|</span><span class="op">|</span> <span class="ident">Error</span>(<span class="kw">unsafe</span> { <span class="kw-2">&mut</span> <span class="kw-2">*</span><span class="ident">LLVMGetErrorMessage</span>(<span class="ident">err</span>) })) +<span class="kw">impl</span><<span class="lifetime">'llvm</span>> Error<<span class="lifetime">'llvm</span>> { + <span class="kw">fn </span>from(err: LLVMErrorRef) -> <span class="prelude-ty">Option</span><Error<<span class="lifetime">'llvm</span>>> { + (!err.is_null()).then(|| Error(<span class="kw">unsafe </span>{ <span class="kw-2">&mut *</span>LLVMGetErrorMessage(err) })) } - <span class="kw">fn</span> <span class="ident">as_str</span>(<span class="kw-2">&</span><span class="self">self</span>) -> <span class="kw-2">&</span><span class="ident">str</span> { - <span class="kw">unsafe</span> { <span class="ident">CStr::from_ptr</span>(<span class="self">self</span>.<span class="number">0</span>) } - .<span class="ident">to_str</span>() - .<span class="ident">expect</span>(<span class="string">"Expected valid UTF8 string from LLVM API"</span>) + <span class="kw">fn </span>as_str(<span class="kw-2">&</span><span class="self">self</span>) -> <span class="kw-2">&</span>str { + <span class="kw">unsafe </span>{ CStr::from_ptr(<span class="self">self</span>.<span class="number">0</span>) } + .to_str() + .expect(<span class="string">"Expected valid UTF8 string from LLVM API"</span>) } } -<span class="kw">impl</span> <span class="ident">Drop</span> <span class="kw">for</span> <span class="ident">Error</span><span class="op"><</span><span class="lifetime">'_</span><span class="op">></span> { - <span class="kw">fn</span> <span class="ident">drop</span>(<span class="kw-2">&mut</span> <span class="self">self</span>) { - <span class="kw">unsafe</span> { - <span class="ident">LLVMDisposeErrorMessage</span>(<span class="self">self</span>.<span class="number">0</span> <span class="kw">as</span> <span class="kw-2">*mut</span> <span class="ident">libc::c_char</span>); +<span class="kw">impl </span>Drop <span class="kw">for </span>Error<<span class="lifetime">'_</span>> { + <span class="kw">fn </span>drop(<span class="kw-2">&mut </span><span class="self">self</span>) { + <span class="kw">unsafe </span>{ + LLVMDisposeErrorMessage(<span class="self">self</span>.<span class="number">0 </span><span class="kw">as </span><span class="kw-2">*mut </span>libc::c_char); } } } -<span class="doccomment">/// Initialize native target for corresponding to host (useful for jitting).</span> -<span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">initialize_native_taget</span>() { - <span class="kw">unsafe</span> { - <span class="macro">assert_eq!</span>(<span class="ident">LLVM_InitializeNativeTarget</span>(), <span class="number">0</span>); - <span class="macro">assert_eq!</span>(<span class="ident">LLVM_InitializeNativeAsmParser</span>(), <span class="number">0</span>); - <span class="macro">assert_eq!</span>(<span class="ident">LLVM_InitializeNativeAsmPrinter</span>(), <span class="number">0</span>); +<span class="doccomment">/// Initialize native target for corresponding to host (useful for jitting). +</span><span class="kw">pub fn </span>initialize_native_taget() { + <span class="kw">unsafe </span>{ + <span class="macro">assert_eq!</span>(LLVM_InitializeNativeTarget(), <span class="number">0</span>); + <span class="macro">assert_eq!</span>(LLVM_InitializeNativeAsmParser(), <span class="number">0</span>); + <span class="macro">assert_eq!</span>(LLVM_InitializeNativeAsmPrinter(), <span class="number">0</span>); } } -<span class="doccomment">/// Deallocate and destroy all "ManagedStatic" variables.</span> -<span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">shutdown</span>() { - <span class="kw">unsafe</span> { - <span class="ident">LLVMShutdown</span>(); +<span class="doccomment">/// Deallocate and destroy all "ManagedStatic" variables. +</span><span class="kw">pub fn </span>shutdown() { + <span class="kw">unsafe </span>{ + LLVMShutdown(); }; } </code></pre></div> -</section></div></main><div id="rustdoc-vars" data-root-path="../../../" data-current-crate="llvm_kaleidoscope_rs" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.63.0 (4b91a6ea7 2022-08-08)" ></div> -</body></html>
\ No newline at end of file +</section></div></main><div id="rustdoc-vars" data-root-path="../../../" data-current-crate="llvm_kaleidoscope_rs" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.65.0 (897e37553 2022-11-02)" ></div></body></html>
\ No newline at end of file diff --git a/src/llvm_kaleidoscope_rs/llvm/module.rs.html b/src/llvm_kaleidoscope_rs/llvm/module.rs.html index 99846f4..127ba39 100644 --- a/src/llvm_kaleidoscope_rs/llvm/module.rs.html +++ b/src/llvm_kaleidoscope_rs/llvm/module.rs.html @@ -1,10 +1,4 @@ -<!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="Source of the Rust file `src/llvm/module.rs`."><meta name="keywords" content="rust, rustlang, rust-lang"><title>module.rs - source</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" type="text/css" href="../../../normalize.css"><link rel="stylesheet" type="text/css" href="../../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../../ayu.css" disabled><link rel="stylesheet" type="text/css" href="../../../dark.css" disabled><link rel="stylesheet" type="text/css" href="../../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../../storage.js"></script><script defer src="../../../source-script.js"></script><script defer src="../../../source-files.js"></script><script defer src="../../../main.js"></script><noscript><link rel="stylesheet" href="../../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../../favicon.svg"></head><body class="rustdoc source"><!--[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">☰</button><a class="sidebar-logo" href="../../../llvm_kaleidoscope_rs/index.html"><div class="logo-container"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></div> - </a><h2 class="location"></h2> - </nav> - <nav class="sidebar"><a class="sidebar-logo" href="../../../llvm_kaleidoscope_rs/index.html"><div class="logo-container"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></div> - </a></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../../../llvm_kaleidoscope_rs/index.html"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></a><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><button type="button" id="help-button" title="help">?</button><div id="settings-menu" tabindex="-1"> - <a href="../../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../../wheel.svg"></a></div> - </div></form></nav></div><section id="main-content" class="content"><div class="example-wrap"><pre class="line-numbers"><span id="1">1</span> +<!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="Source of the Rust file `src/llvm/module.rs`."><meta name="keywords" content="rust, rustlang, rust-lang"><title>module.rs - source</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../../../normalize.css"><link rel="stylesheet" href="../../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../../../ayu.css" disabled><link rel="stylesheet" href="../../../dark.css" disabled><link rel="stylesheet" href="../../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../../storage.js"></script><script defer src="../../../source-script.js"></script><script defer src="../../../source-files.js"></script><script defer src="../../../main.js"></script><noscript><link rel="stylesheet" href="../../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../../favicon.svg"></head><body class="rustdoc source"><!--[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">☰</button><a class="sidebar-logo" href="../../../llvm_kaleidoscope_rs/index.html"><div class="logo-container"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></div></a><h2 class="location"></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../../../llvm_kaleidoscope_rs/index.html"><div class="logo-container"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></div></a></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../../../llvm_kaleidoscope_rs/index.html"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></a><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><button type="button">?</button></div><div id="settings-menu" tabindex="-1"><a href="../../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../../wheel.svg"></a></div></div></form></nav></div><section id="main-content" class="content"><div class="example-wrap"><pre class="line-numbers"><span id="1">1</span> <span id="2">2</span> <span id="3">3</span> <span id="4">4</span> @@ -214,216 +208,215 @@ <span id="208">208</span> <span id="209">209</span> <span id="210">210</span> -</pre><pre class="rust"><code><span class="kw">use</span> <span class="ident">llvm_sys</span>::{ - <span class="ident">core</span>::{ - <span class="ident">LLVMAddFunction</span>, <span class="ident">LLVMAppendBasicBlockInContext</span>, <span class="ident">LLVMCreateBasicBlockInContext</span>, - <span class="ident">LLVMDisposeModule</span>, <span class="ident">LLVMDoubleTypeInContext</span>, <span class="ident">LLVMDumpModule</span>, <span class="ident">LLVMGetNamedFunction</span>, - <span class="ident">LLVMModuleCreateWithNameInContext</span>, +</pre><pre class="rust"><code><span class="kw">use </span>llvm_sys::{ + core::{ + LLVMAddFunction, LLVMAppendBasicBlockInContext, LLVMCreateBasicBlockInContext, + LLVMDisposeModule, LLVMDoubleTypeInContext, LLVMDumpModule, LLVMGetNamedFunction, + LLVMModuleCreateWithNameInContext, }, - <span class="ident">orc2</span>::{ - <span class="ident">LLVMOrcCreateNewThreadSafeContext</span>, <span class="ident">LLVMOrcCreateNewThreadSafeModule</span>, - <span class="ident">LLVMOrcDisposeThreadSafeContext</span>, <span class="ident">LLVMOrcThreadSafeContextGetContext</span>, - <span class="ident">LLVMOrcThreadSafeContextRef</span>, <span class="ident">LLVMOrcThreadSafeModuleRef</span>, + orc2::{ + LLVMOrcCreateNewThreadSafeContext, LLVMOrcCreateNewThreadSafeModule, + LLVMOrcDisposeThreadSafeContext, LLVMOrcThreadSafeContextGetContext, + LLVMOrcThreadSafeContextRef, LLVMOrcThreadSafeModuleRef, }, - <span class="ident">prelude</span>::{<span class="ident">LLVMBool</span>, <span class="ident">LLVMContextRef</span>, <span class="ident">LLVMModuleRef</span>, <span class="ident">LLVMTypeRef</span>}, - <span class="ident">LLVMTypeKind</span>, + prelude::{LLVMBool, LLVMContextRef, LLVMModuleRef, LLVMTypeRef}, + LLVMTypeKind, }; -<span class="kw">use</span> <span class="ident">std::convert::TryFrom</span>; +<span class="kw">use </span>std::convert::TryFrom; -<span class="kw">use</span> <span class="kw">super</span>::{<span class="ident">BasicBlock</span>, <span class="ident">FnValue</span>, <span class="ident">Type</span>}; -<span class="kw">use</span> <span class="ident"><span class="kw">crate</span>::SmallCStr</span>; +<span class="kw">use super</span>::{BasicBlock, FnValue, Type}; +<span class="kw">use </span><span class="kw">crate</span>::SmallCStr; -<span class="comment">// Definition of LLVM C API functions using our `repr(transparent)` types.</span> -<span class="kw">extern</span> <span class="string">"C"</span> { - <span class="kw">fn</span> <span class="ident">LLVMFunctionType</span>( - <span class="ident">ReturnType</span>: <span class="ident">Type</span><span class="op"><</span><span class="lifetime">'_</span><span class="op">></span>, - <span class="ident">ParamTypes</span>: <span class="kw-2">*mut</span> <span class="ident">Type</span><span class="op"><</span><span class="lifetime">'_</span><span class="op">></span>, - <span class="ident">ParamCount</span>: <span class="ident">::libc::c_uint</span>, - <span class="ident">IsVarArg</span>: <span class="ident">LLVMBool</span>, - ) -> <span class="ident">LLVMTypeRef</span>; +<span class="comment">// Definition of LLVM C API functions using our `repr(transparent)` types. +</span><span class="kw">extern </span><span class="string">"C" </span>{ + <span class="kw">fn </span>LLVMFunctionType( + ReturnType: Type<<span class="lifetime">'_</span>>, + ParamTypes: <span class="kw-2">*mut </span>Type<<span class="lifetime">'_</span>>, + ParamCount: ::libc::c_uint, + IsVarArg: LLVMBool, + ) -> LLVMTypeRef; } -<span class="doccomment">/// Wrapper for a LLVM Module with its own LLVM Context.</span> -<span class="kw">pub</span> <span class="kw">struct</span> <span class="ident">Module</span> { - <span class="ident">tsctx</span>: <span class="ident">LLVMOrcThreadSafeContextRef</span>, - <span class="ident">ctx</span>: <span class="ident">LLVMContextRef</span>, - <span class="ident">module</span>: <span class="ident">LLVMModuleRef</span>, +<span class="doccomment">/// Wrapper for a LLVM Module with its own LLVM Context. +</span><span class="kw">pub struct </span>Module { + tsctx: LLVMOrcThreadSafeContextRef, + ctx: LLVMContextRef, + module: LLVMModuleRef, } -<span class="kw">impl</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> <span class="ident">Module</span> { - <span class="doccomment">/// Create a new Module instance.</span> - <span class="doccomment">///</span> - <span class="doccomment">/// # Panics</span> - <span class="doccomment">///</span> - <span class="doccomment">/// Panics if creating the context or the module fails.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">new</span>() -> <span class="self">Self</span> { - <span class="kw">let</span> (<span class="ident">tsctx</span>, <span class="ident">ctx</span>, <span class="ident">module</span>) <span class="op">=</span> <span class="kw">unsafe</span> { - <span class="comment">// We generate a thread safe context because we are going to jit this IR module and</span> - <span class="comment">// there is no method to create a thread safe context wrapper from an existing context</span> - <span class="comment">// reference (at the time of writing this).</span> - <span class="comment">//</span> - <span class="comment">// ThreadSafeContext has shared ownership (start with ref count 1).</span> - <span class="comment">// We must explicitly dispose our reference (dec ref count).</span> - <span class="kw">let</span> <span class="ident">tc</span> <span class="op">=</span> <span class="ident">LLVMOrcCreateNewThreadSafeContext</span>(); - <span class="macro">assert!</span>(<span class="op">!</span><span class="ident">tc</span>.<span class="ident">is_null</span>()); +<span class="kw">impl</span><<span class="lifetime">'llvm</span>> Module { + <span class="doccomment">/// Create a new Module instance. + /// + /// # Panics + /// + /// Panics if creating the context or the module fails. + </span><span class="kw">pub fn </span>new() -> <span class="self">Self </span>{ + <span class="kw">let </span>(tsctx, ctx, module) = <span class="kw">unsafe </span>{ + <span class="comment">// We generate a thread safe context because we are going to jit this IR module and + // there is no method to create a thread safe context wrapper from an existing context + // reference (at the time of writing this). + // + // ThreadSafeContext has shared ownership (start with ref count 1). + // We must explicitly dispose our reference (dec ref count). + </span><span class="kw">let </span>tc = LLVMOrcCreateNewThreadSafeContext(); + <span class="macro">assert!</span>(!tc.is_null()); - <span class="kw">let</span> <span class="ident">c</span> <span class="op">=</span> <span class="ident">LLVMOrcThreadSafeContextGetContext</span>(<span class="ident">tc</span>); - <span class="kw">let</span> <span class="ident">m</span> <span class="op">=</span> <span class="ident">LLVMModuleCreateWithNameInContext</span>(<span class="string">b"module\0"</span>.<span class="ident">as_ptr</span>().<span class="ident">cast</span>(), <span class="ident">c</span>); - <span class="macro">assert!</span>(<span class="op">!</span><span class="ident">c</span>.<span class="ident">is_null</span>() <span class="op">&&</span> <span class="op">!</span><span class="ident">m</span>.<span class="ident">is_null</span>()); - (<span class="ident">tc</span>, <span class="ident">c</span>, <span class="ident">m</span>) + <span class="kw">let </span>c = LLVMOrcThreadSafeContextGetContext(tc); + <span class="kw">let </span>m = LLVMModuleCreateWithNameInContext(<span class="string">b"module\0"</span>.as_ptr().cast(), c); + <span class="macro">assert!</span>(!c.is_null() && !m.is_null()); + (tc, c, m) }; - <span class="ident">Module</span> { <span class="ident">tsctx</span>, <span class="ident">ctx</span>, <span class="ident">module</span> } + Module { tsctx, ctx, module } } - <span class="doccomment">/// Get the raw LLVM context reference.</span> - <span class="attribute">#[<span class="ident">inline</span>]</span> - <span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn</span> <span class="ident">ctx</span>(<span class="kw-2">&</span><span class="self">self</span>) -> <span class="ident">LLVMContextRef</span> { - <span class="self">self</span>.<span class="ident">ctx</span> + <span class="doccomment">/// Get the raw LLVM context reference. + </span><span class="attribute">#[inline] + </span><span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn </span>ctx(<span class="kw-2">&</span><span class="self">self</span>) -> LLVMContextRef { + <span class="self">self</span>.ctx } - <span class="doccomment">/// Get the raw LLVM module reference.</span> - <span class="attribute">#[<span class="ident">inline</span>]</span> - <span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn</span> <span class="ident">module</span>(<span class="kw-2">&</span><span class="self">self</span>) -> <span class="ident">LLVMModuleRef</span> { - <span class="self">self</span>.<span class="ident">module</span> + <span class="doccomment">/// Get the raw LLVM module reference. + </span><span class="attribute">#[inline] + </span><span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn </span>module(<span class="kw-2">&</span><span class="self">self</span>) -> LLVMModuleRef { + <span class="self">self</span>.module } - <span class="doccomment">/// Consume the module and turn in into a raw LLVM ThreadSafeModule reference.</span> - <span class="doccomment">///</span> - <span class="doccomment">/// If ownership of the raw reference is not transferred (eg to the JIT), memory will be leaked</span> - <span class="doccomment">/// in case the reference is disposed explicitly with LLVMOrcDisposeThreadSafeModule.</span> - <span class="attribute">#[<span class="ident">inline</span>]</span> - <span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn</span> <span class="ident">into_raw_thread_safe_module</span>(<span class="kw-2">mut</span> <span class="self">self</span>) -> <span class="ident">LLVMOrcThreadSafeModuleRef</span> { - <span class="kw">let</span> <span class="ident">m</span> <span class="op">=</span> <span class="ident">std::mem::replace</span>(<span class="kw-2">&mut</span> <span class="self">self</span>.<span class="ident">module</span>, <span class="ident">std::ptr::null_mut</span>()); + <span class="doccomment">/// Consume the module and turn in into a raw LLVM ThreadSafeModule reference. + /// + /// If ownership of the raw reference is not transferred (eg to the JIT), memory will be leaked + /// in case the reference is disposed explicitly with LLVMOrcDisposeThreadSafeModule. + </span><span class="attribute">#[inline] + </span><span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn </span>into_raw_thread_safe_module(<span class="kw-2">mut </span><span class="self">self</span>) -> LLVMOrcThreadSafeModuleRef { + <span class="kw">let </span>m = std::mem::replace(<span class="kw-2">&mut </span><span class="self">self</span>.module, std::ptr::null_mut()); - <span class="comment">// ThreadSafeModule has unique ownership.</span> - <span class="comment">// Takes ownership of module and increments ThreadSafeContext ref count.</span> - <span class="comment">//</span> - <span class="comment">// We must not reference/dispose `m` after this call, but we need to dispose our `tsctx`</span> - <span class="comment">// reference.</span> - <span class="kw">let</span> <span class="ident">tm</span> <span class="op">=</span> <span class="kw">unsafe</span> { <span class="ident">LLVMOrcCreateNewThreadSafeModule</span>(<span class="ident">m</span>, <span class="self">self</span>.<span class="ident">tsctx</span>) }; - <span class="macro">assert!</span>(<span class="op">!</span><span class="ident">tm</span>.<span class="ident">is_null</span>()); + <span class="comment">// ThreadSafeModule has unique ownership. + // Takes ownership of module and increments ThreadSafeContext ref count. + // + // We must not reference/dispose `m` after this call, but we need to dispose our `tsctx` + // reference. + </span><span class="kw">let </span>tm = <span class="kw">unsafe </span>{ LLVMOrcCreateNewThreadSafeModule(m, <span class="self">self</span>.tsctx) }; + <span class="macro">assert!</span>(!tm.is_null()); - <span class="ident">tm</span> + tm } - <span class="doccomment">/// Dump LLVM IR emitted into the Module to stdout.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">dump</span>(<span class="kw-2">&</span><span class="self">self</span>) { - <span class="kw">unsafe</span> { <span class="ident">LLVMDumpModule</span>(<span class="self">self</span>.<span class="ident">module</span>) }; + <span class="doccomment">/// Dump LLVM IR emitted into the Module to stdout. + </span><span class="kw">pub fn </span>dump(<span class="kw-2">&</span><span class="self">self</span>) { + <span class="kw">unsafe </span>{ LLVMDumpModule(<span class="self">self</span>.module) }; } - <span class="doccomment">/// Get a type reference representing a `f64` float.</span> - <span class="doccomment">///</span> - <span class="doccomment">/// # Panics</span> - <span class="doccomment">///</span> - <span class="doccomment">/// Panics if LLVM API returns a `null` pointer.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">type_f64</span>(<span class="kw-2">&</span><span class="self">self</span>) -> <span class="ident">Type</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> { - <span class="kw">let</span> <span class="ident">type_ref</span> <span class="op">=</span> <span class="kw">unsafe</span> { <span class="ident">LLVMDoubleTypeInContext</span>(<span class="self">self</span>.<span class="ident">ctx</span>) }; - <span class="ident">Type::new</span>(<span class="ident">type_ref</span>) + <span class="doccomment">/// Get a type reference representing a `f64` float. + /// + /// # Panics + /// + /// Panics if LLVM API returns a `null` pointer. + </span><span class="kw">pub fn </span>type_f64(<span class="kw-2">&</span><span class="self">self</span>) -> Type<<span class="lifetime">'llvm</span>> { + <span class="kw">let </span>type_ref = <span class="kw">unsafe </span>{ LLVMDoubleTypeInContext(<span class="self">self</span>.ctx) }; + Type::new(type_ref) } - <span class="doccomment">/// Get a type reference representing a `fn(args) -> ret` function.</span> - <span class="doccomment">///</span> - <span class="doccomment">/// # Panics</span> - <span class="doccomment">///</span> - <span class="doccomment">/// Panics if LLVM API returns a `null` pointer.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">type_fn</span>(<span class="kw-2">&</span><span class="lifetime">'llvm</span> <span class="self">self</span>, <span class="ident">args</span>: <span class="kw-2">&mut</span> [<span class="ident">Type</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>], <span class="ident">ret</span>: <span class="ident">Type</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>) -> <span class="ident">Type</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> { - <span class="kw">let</span> <span class="ident">type_ref</span> <span class="op">=</span> <span class="kw">unsafe</span> { - <span class="ident">LLVMFunctionType</span>( - <span class="ident">ret</span>, - <span class="ident">args</span>.<span class="ident">as_mut_ptr</span>(), - <span class="ident">args</span>.<span class="ident">len</span>() <span class="kw">as</span> <span class="ident">libc::c_uint</span>, - <span class="number">0</span>, <span class="comment">/* IsVarArg */</span> - ) + <span class="doccomment">/// Get a type reference representing a `fn(args) -> ret` function. + /// + /// # Panics + /// + /// Panics if LLVM API returns a `null` pointer. + </span><span class="kw">pub fn </span>type_fn(<span class="kw-2">&</span><span class="lifetime">'llvm </span><span class="self">self</span>, args: <span class="kw-2">&mut </span>[Type<<span class="lifetime">'llvm</span>>], ret: Type<<span class="lifetime">'llvm</span>>) -> Type<<span class="lifetime">'llvm</span>> { + <span class="kw">let </span>type_ref = <span class="kw">unsafe </span>{ + LLVMFunctionType( + ret, + args.as_mut_ptr(), + args.len() <span class="kw">as </span>libc::c_uint, + <span class="number">0</span>, <span class="comment">/* IsVarArg */ + </span>) }; - <span class="ident">Type::new</span>(<span class="ident">type_ref</span>) + Type::new(type_ref) } - <span class="doccomment">/// Add a function with the given `name` and `fn_type` to the module and return a value</span> - <span class="doccomment">/// reference representing the function.</span> - <span class="doccomment">///</span> - <span class="doccomment">/// # Panics</span> - <span class="doccomment">///</span> - <span class="doccomment">/// Panics if LLVM API returns a `null` pointer or `name` could not be converted to a</span> - <span class="doccomment">/// [`SmallCStr`].</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">add_fn</span>(<span class="kw-2">&</span><span class="lifetime">'llvm</span> <span class="self">self</span>, <span class="ident">name</span>: <span class="kw-2">&</span><span class="ident">str</span>, <span class="ident">fn_type</span>: <span class="ident">Type</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>) -> <span class="ident">FnValue</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> { + <span class="doccomment">/// Add a function with the given `name` and `fn_type` to the module and return a value + /// reference representing the function. + /// + /// # Panics + /// + /// Panics if LLVM API returns a `null` pointer or `name` could not be converted to a + /// [`SmallCStr`]. + </span><span class="kw">pub fn </span>add_fn(<span class="kw-2">&</span><span class="lifetime">'llvm </span><span class="self">self</span>, name: <span class="kw-2">&</span>str, fn_type: Type<<span class="lifetime">'llvm</span>>) -> FnValue<<span class="lifetime">'llvm</span>> { <span class="macro">debug_assert_eq!</span>( - <span class="ident">fn_type</span>.<span class="ident">kind</span>(), - <span class="ident">LLVMTypeKind::LLVMFunctionTypeKind</span>, - <span class="string">"Expected a function type when adding a function!"</span> - ); + fn_type.kind(), + LLVMTypeKind::LLVMFunctionTypeKind, + <span class="string">"Expected a function type when adding a function!" + </span>); - <span class="kw">let</span> <span class="ident">name</span> <span class="op">=</span> <span class="ident">SmallCStr::try_from</span>(<span class="ident">name</span>) - .<span class="ident">expect</span>(<span class="string">"Failed to convert 'name' argument to small C string!"</span>); + <span class="kw">let </span>name = SmallCStr::try_from(name) + .expect(<span class="string">"Failed to convert 'name' argument to small C string!"</span>); - <span class="kw">let</span> <span class="ident">value_ref</span> <span class="op">=</span> <span class="kw">unsafe</span> { <span class="ident">LLVMAddFunction</span>(<span class="self">self</span>.<span class="ident">module</span>, <span class="ident">name</span>.<span class="ident">as_ptr</span>(), <span class="ident">fn_type</span>.<span class="ident">type_ref</span>()) }; - <span class="ident">FnValue::new</span>(<span class="ident">value_ref</span>) + <span class="kw">let </span>value_ref = <span class="kw">unsafe </span>{ LLVMAddFunction(<span class="self">self</span>.module, name.as_ptr(), fn_type.type_ref()) }; + FnValue::new(value_ref) } - <span class="doccomment">/// Get a function value reference to the function with the given `name` if it was previously</span> - <span class="doccomment">/// added to the module with [`add_fn`][Module::add_fn].</span> - <span class="doccomment">///</span> - <span class="doccomment">/// # Panics</span> - <span class="doccomment">///</span> - <span class="doccomment">/// Panics if `name` could not be converted to a [`SmallCStr`].</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">get_fn</span>(<span class="kw-2">&</span><span class="lifetime">'llvm</span> <span class="self">self</span>, <span class="ident">name</span>: <span class="kw-2">&</span><span class="ident">str</span>) -> <span class="prelude-ty">Option</span><span class="op"><</span><span class="ident">FnValue</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span><span class="op">></span> { - <span class="kw">let</span> <span class="ident">name</span> <span class="op">=</span> <span class="ident">SmallCStr::try_from</span>(<span class="ident">name</span>) - .<span class="ident">expect</span>(<span class="string">"Failed to convert 'name' argument to small C string!"</span>); + <span class="doccomment">/// Get a function value reference to the function with the given `name` if it was previously + /// added to the module with [`add_fn`][Module::add_fn]. + /// + /// # Panics + /// + /// Panics if `name` could not be converted to a [`SmallCStr`]. + </span><span class="kw">pub fn </span>get_fn(<span class="kw-2">&</span><span class="lifetime">'llvm </span><span class="self">self</span>, name: <span class="kw-2">&</span>str) -> <span class="prelude-ty">Option</span><FnValue<<span class="lifetime">'llvm</span>>> { + <span class="kw">let </span>name = SmallCStr::try_from(name) + .expect(<span class="string">"Failed to convert 'name' argument to small C string!"</span>); - <span class="kw">let</span> <span class="ident">value_ref</span> <span class="op">=</span> <span class="kw">unsafe</span> { <span class="ident">LLVMGetNamedFunction</span>(<span class="self">self</span>.<span class="ident">module</span>, <span class="ident">name</span>.<span class="ident">as_ptr</span>()) }; + <span class="kw">let </span>value_ref = <span class="kw">unsafe </span>{ LLVMGetNamedFunction(<span class="self">self</span>.module, name.as_ptr()) }; - (<span class="op">!</span><span class="ident">value_ref</span>.<span class="ident">is_null</span>()).<span class="ident">then</span>(<span class="op">|</span><span class="op">|</span> <span class="ident">FnValue::new</span>(<span class="ident">value_ref</span>)) + (!value_ref.is_null()).then(|| FnValue::new(value_ref)) } - <span class="doccomment">/// Append a Basic Block to the end of the function referenced by the value reference</span> - <span class="doccomment">/// `fn_value`.</span> - <span class="doccomment">///</span> - <span class="doccomment">/// # Panics</span> - <span class="doccomment">///</span> - <span class="doccomment">/// Panics if LLVM API returns a `null` pointer.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">append_basic_block</span>(<span class="kw-2">&</span><span class="lifetime">'llvm</span> <span class="self">self</span>, <span class="ident">fn_value</span>: <span class="ident">FnValue</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>) -> <span class="ident">BasicBlock</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> { - <span class="kw">let</span> <span class="ident">block</span> <span class="op">=</span> <span class="kw">unsafe</span> { - <span class="ident">LLVMAppendBasicBlockInContext</span>( - <span class="self">self</span>.<span class="ident">ctx</span>, - <span class="ident">fn_value</span>.<span class="ident">value_ref</span>(), - <span class="string">b"block\0"</span>.<span class="ident">as_ptr</span>().<span class="ident">cast</span>(), + <span class="doccomment">/// Append a Basic Block to the end of the function referenced by the value reference + /// `fn_value`. + /// + /// # Panics + /// + /// Panics if LLVM API returns a `null` pointer. + </span><span class="kw">pub fn </span>append_basic_block(<span class="kw-2">&</span><span class="lifetime">'llvm </span><span class="self">self</span>, fn_value: FnValue<<span class="lifetime">'llvm</span>>) -> BasicBlock<<span class="lifetime">'llvm</span>> { + <span class="kw">let </span>block = <span class="kw">unsafe </span>{ + LLVMAppendBasicBlockInContext( + <span class="self">self</span>.ctx, + fn_value.value_ref(), + <span class="string">b"block\0"</span>.as_ptr().cast(), ) }; - <span class="macro">assert!</span>(<span class="op">!</span><span class="ident">block</span>.<span class="ident">is_null</span>()); + <span class="macro">assert!</span>(!block.is_null()); - <span class="ident">BasicBlock::new</span>(<span class="ident">block</span>) + BasicBlock::new(block) } - <span class="doccomment">/// Create a free-standing Basic Block without adding it to a function.</span> - <span class="doccomment">/// This can be added to a function at a later point in time with</span> - <span class="doccomment">/// [`FnValue::append_basic_block`].</span> - <span class="doccomment">///</span> - <span class="doccomment">/// # Panics</span> - <span class="doccomment">///</span> - <span class="doccomment">/// Panics if LLVM API returns a `null` pointer.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">create_basic_block</span>(<span class="kw-2">&</span><span class="self">self</span>) -> <span class="ident">BasicBlock</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> { - <span class="kw">let</span> <span class="ident">block</span> <span class="op">=</span> <span class="kw">unsafe</span> { <span class="ident">LLVMCreateBasicBlockInContext</span>(<span class="self">self</span>.<span class="ident">ctx</span>, <span class="string">b"block\0"</span>.<span class="ident">as_ptr</span>().<span class="ident">cast</span>()) }; - <span class="macro">assert!</span>(<span class="op">!</span><span class="ident">block</span>.<span class="ident">is_null</span>()); + <span class="doccomment">/// Create a free-standing Basic Block without adding it to a function. + /// This can be added to a function at a later point in time with + /// [`FnValue::append_basic_block`]. + /// + /// # Panics + /// + /// Panics if LLVM API returns a `null` pointer. + </span><span class="kw">pub fn </span>create_basic_block(<span class="kw-2">&</span><span class="self">self</span>) -> BasicBlock<<span class="lifetime">'llvm</span>> { + <span class="kw">let </span>block = <span class="kw">unsafe </span>{ LLVMCreateBasicBlockInContext(<span class="self">self</span>.ctx, <span class="string">b"block\0"</span>.as_ptr().cast()) }; + <span class="macro">assert!</span>(!block.is_null()); - <span class="ident">BasicBlock::new</span>(<span class="ident">block</span>) + BasicBlock::new(block) } } -<span class="kw">impl</span> <span class="ident">Drop</span> <span class="kw">for</span> <span class="ident">Module</span> { - <span class="kw">fn</span> <span class="ident">drop</span>(<span class="kw-2">&mut</span> <span class="self">self</span>) { - <span class="kw">unsafe</span> { - <span class="comment">// In case we turned the module into a ThreadSafeModule, we must not dispose the module</span> - <span class="comment">// reference because ThreadSafeModule took ownership!</span> - <span class="kw">if</span> <span class="op">!</span><span class="self">self</span>.<span class="ident">module</span>.<span class="ident">is_null</span>() { - <span class="ident">LLVMDisposeModule</span>(<span class="self">self</span>.<span class="ident">module</span>); +<span class="kw">impl </span>Drop <span class="kw">for </span>Module { + <span class="kw">fn </span>drop(<span class="kw-2">&mut </span><span class="self">self</span>) { + <span class="kw">unsafe </span>{ + <span class="comment">// In case we turned the module into a ThreadSafeModule, we must not dispose the module + // reference because ThreadSafeModule took ownership! + </span><span class="kw">if </span>!<span class="self">self</span>.module.is_null() { + LLVMDisposeModule(<span class="self">self</span>.module); } - <span class="comment">// Dispose ThreadSafeContext reference (dec ref count) in any case.</span> - <span class="ident">LLVMOrcDisposeThreadSafeContext</span>(<span class="self">self</span>.<span class="ident">tsctx</span>); + <span class="comment">// Dispose ThreadSafeContext reference (dec ref count) in any case. + </span>LLVMOrcDisposeThreadSafeContext(<span class="self">self</span>.tsctx); } } } </code></pre></div> -</section></div></main><div id="rustdoc-vars" data-root-path="../../../" data-current-crate="llvm_kaleidoscope_rs" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.63.0 (4b91a6ea7 2022-08-08)" ></div> -</body></html>
\ No newline at end of file +</section></div></main><div id="rustdoc-vars" data-root-path="../../../" data-current-crate="llvm_kaleidoscope_rs" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.65.0 (897e37553 2022-11-02)" ></div></body></html>
\ No newline at end of file diff --git a/src/llvm_kaleidoscope_rs/llvm/pass_manager.rs.html b/src/llvm_kaleidoscope_rs/llvm/pass_manager.rs.html index ebf9b28..968856f 100644 --- a/src/llvm_kaleidoscope_rs/llvm/pass_manager.rs.html +++ b/src/llvm_kaleidoscope_rs/llvm/pass_manager.rs.html @@ -1,10 +1,4 @@ -<!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="Source of the Rust file `src/llvm/pass_manager.rs`."><meta name="keywords" content="rust, rustlang, rust-lang"><title>pass_manager.rs - source</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" type="text/css" href="../../../normalize.css"><link rel="stylesheet" type="text/css" href="../../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../../ayu.css" disabled><link rel="stylesheet" type="text/css" href="../../../dark.css" disabled><link rel="stylesheet" type="text/css" href="../../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../../storage.js"></script><script defer src="../../../source-script.js"></script><script defer src="../../../source-files.js"></script><script defer src="../../../main.js"></script><noscript><link rel="stylesheet" href="../../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../../favicon.svg"></head><body class="rustdoc source"><!--[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">☰</button><a class="sidebar-logo" href="../../../llvm_kaleidoscope_rs/index.html"><div class="logo-container"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></div> - </a><h2 class="location"></h2> - </nav> - <nav class="sidebar"><a class="sidebar-logo" href="../../../llvm_kaleidoscope_rs/index.html"><div class="logo-container"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></div> - </a></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../../../llvm_kaleidoscope_rs/index.html"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></a><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><button type="button" id="help-button" title="help">?</button><div id="settings-menu" tabindex="-1"> - <a href="../../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../../wheel.svg"></a></div> - </div></form></nav></div><section id="main-content" class="content"><div class="example-wrap"><pre class="line-numbers"><span id="1">1</span> +<!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="Source of the Rust file `src/llvm/pass_manager.rs`."><meta name="keywords" content="rust, rustlang, rust-lang"><title>pass_manager.rs - source</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../../../normalize.css"><link rel="stylesheet" href="../../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../../../ayu.css" disabled><link rel="stylesheet" href="../../../dark.css" disabled><link rel="stylesheet" href="../../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../../storage.js"></script><script defer src="../../../source-script.js"></script><script defer src="../../../source-files.js"></script><script defer src="../../../main.js"></script><noscript><link rel="stylesheet" href="../../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../../favicon.svg"></head><body class="rustdoc source"><!--[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">☰</button><a class="sidebar-logo" href="../../../llvm_kaleidoscope_rs/index.html"><div class="logo-container"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></div></a><h2 class="location"></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../../../llvm_kaleidoscope_rs/index.html"><div class="logo-container"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></div></a></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../../../llvm_kaleidoscope_rs/index.html"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></a><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><button type="button">?</button></div><div id="settings-menu" tabindex="-1"><a href="../../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../../wheel.svg"></a></div></div></form></nav></div><section id="main-content" class="content"><div class="example-wrap"><pre class="line-numbers"><span id="1">1</span> <span id="2">2</span> <span id="3">3</span> <span id="4">4</span> @@ -79,81 +73,80 @@ <span id="73">73</span> <span id="74">74</span> <span id="75">75</span> -</pre><pre class="rust"><code><span class="kw">use</span> <span class="ident">llvm_sys</span>::{ - <span class="ident">core</span>::{ - <span class="ident">LLVMCreateFunctionPassManagerForModule</span>, <span class="ident">LLVMDisposePassManager</span>, - <span class="ident">LLVMInitializeFunctionPassManager</span>, <span class="ident">LLVMRunFunctionPassManager</span>, +</pre><pre class="rust"><code><span class="kw">use </span>llvm_sys::{ + core::{ + LLVMCreateFunctionPassManagerForModule, LLVMDisposePassManager, + LLVMInitializeFunctionPassManager, LLVMRunFunctionPassManager, }, - <span class="ident">prelude::LLVMPassManagerRef</span>, - <span class="ident">transforms</span>::{ - <span class="ident">instcombine::LLVMAddInstructionCombiningPass</span>, - <span class="ident">scalar</span>::{<span class="ident">LLVMAddCFGSimplificationPass</span>, <span class="ident">LLVMAddNewGVNPass</span>, <span class="ident">LLVMAddReassociatePass</span>}, + prelude::LLVMPassManagerRef, + transforms::{ + instcombine::LLVMAddInstructionCombiningPass, + scalar::{LLVMAddCFGSimplificationPass, LLVMAddNewGVNPass, LLVMAddReassociatePass}, }, }; -<span class="kw">use</span> <span class="ident">std::marker::PhantomData</span>; +<span class="kw">use </span>std::marker::PhantomData; -<span class="kw">use</span> <span class="kw">super</span>::{<span class="ident">FnValue</span>, <span class="ident">Module</span>}; +<span class="kw">use super</span>::{FnValue, Module}; -<span class="doccomment">/// Wrapper for a LLVM Function PassManager (legacy).</span> -<span class="kw">pub</span> <span class="kw">struct</span> <span class="ident">FunctionPassManager</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> { - <span class="ident">fpm</span>: <span class="ident">LLVMPassManagerRef</span>, - <span class="ident">_ctx</span>: <span class="ident">PhantomData</span><span class="op"><</span><span class="kw-2">&</span><span class="lifetime">'llvm</span> ()<span class="op">></span>, +<span class="doccomment">/// Wrapper for a LLVM Function PassManager (legacy). +</span><span class="kw">pub struct </span>FunctionPassManager<<span class="lifetime">'llvm</span>> { + fpm: LLVMPassManagerRef, + _ctx: PhantomData<<span class="kw-2">&</span><span class="lifetime">'llvm </span>()>, } -<span class="kw">impl</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> <span class="ident">FunctionPassManager</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> { - <span class="doccomment">/// Create a new Function PassManager with the following optimization passes</span> - <span class="doccomment">/// - InstructionCombiningPass</span> - <span class="doccomment">/// - ReassociatePass</span> - <span class="doccomment">/// - NewGVNPass</span> - <span class="doccomment">/// - CFGSimplificationPass</span> - <span class="doccomment">///</span> - <span class="doccomment">/// The list of selected optimization passes is taken from the tutorial chapter [LLVM</span> - <span class="doccomment">/// Optimization Passes](https://llvm.org/docs/tutorial/MyFirstLanguageFrontend/LangImpl04.html#id3).</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">with_ctx</span>(<span class="ident">module</span>: <span class="kw-2">&</span><span class="lifetime">'llvm</span> <span class="ident">Module</span>) -> <span class="ident">FunctionPassManager</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> { - <span class="kw">let</span> <span class="ident">fpm</span> <span class="op">=</span> <span class="kw">unsafe</span> { - <span class="comment">// Borrows module reference.</span> - <span class="ident">LLVMCreateFunctionPassManagerForModule</span>(<span class="ident">module</span>.<span class="ident">module</span>()) +<span class="kw">impl</span><<span class="lifetime">'llvm</span>> FunctionPassManager<<span class="lifetime">'llvm</span>> { + <span class="doccomment">/// Create a new Function PassManager with the following optimization passes + /// - InstructionCombiningPass + /// - ReassociatePass + /// - NewGVNPass + /// - CFGSimplificationPass + /// + /// The list of selected optimization passes is taken from the tutorial chapter [LLVM + /// Optimization Passes](https://llvm.org/docs/tutorial/MyFirstLanguageFrontend/LangImpl04.html#id3). + </span><span class="kw">pub fn </span>with_ctx(module: <span class="kw-2">&</span><span class="lifetime">'llvm </span>Module) -> FunctionPassManager<<span class="lifetime">'llvm</span>> { + <span class="kw">let </span>fpm = <span class="kw">unsafe </span>{ + <span class="comment">// Borrows module reference. + </span>LLVMCreateFunctionPassManagerForModule(module.module()) }; - <span class="macro">assert!</span>(<span class="op">!</span><span class="ident">fpm</span>.<span class="ident">is_null</span>()); + <span class="macro">assert!</span>(!fpm.is_null()); - <span class="kw">unsafe</span> { - <span class="comment">// Do simple "peephole" optimizations and bit-twiddling optzns.</span> - <span class="ident">LLVMAddInstructionCombiningPass</span>(<span class="ident">fpm</span>); - <span class="comment">// Reassociate expressions.</span> - <span class="ident">LLVMAddReassociatePass</span>(<span class="ident">fpm</span>); - <span class="comment">// Eliminate Common SubExpressions.</span> - <span class="ident">LLVMAddNewGVNPass</span>(<span class="ident">fpm</span>); - <span class="comment">// Simplify the control flow graph (deleting unreachable blocks, etc).</span> - <span class="ident">LLVMAddCFGSimplificationPass</span>(<span class="ident">fpm</span>); + <span class="kw">unsafe </span>{ + <span class="comment">// Do simple "peephole" optimizations and bit-twiddling optzns. + </span>LLVMAddInstructionCombiningPass(fpm); + <span class="comment">// Reassociate expressions. + </span>LLVMAddReassociatePass(fpm); + <span class="comment">// Eliminate Common SubExpressions. + </span>LLVMAddNewGVNPass(fpm); + <span class="comment">// Simplify the control flow graph (deleting unreachable blocks, etc). + </span>LLVMAddCFGSimplificationPass(fpm); - <span class="kw">let</span> <span class="ident">fail</span> <span class="op">=</span> <span class="ident">LLVMInitializeFunctionPassManager</span>(<span class="ident">fpm</span>); - <span class="macro">assert_eq!</span>(<span class="ident">fail</span>, <span class="number">0</span>); + <span class="kw">let </span>fail = LLVMInitializeFunctionPassManager(fpm); + <span class="macro">assert_eq!</span>(fail, <span class="number">0</span>); } - <span class="ident">FunctionPassManager</span> { - <span class="ident">fpm</span>, - <span class="ident">_ctx</span>: <span class="ident">PhantomData</span>, + FunctionPassManager { + fpm, + _ctx: PhantomData, } } - <span class="doccomment">/// Run the optimization passes registered with the Function PassManager on the function</span> - <span class="doccomment">/// referenced by `fn_value`.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">run</span>(<span class="kw-2">&</span><span class="lifetime">'llvm</span> <span class="self">self</span>, <span class="ident">fn_value</span>: <span class="ident">FnValue</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>) { - <span class="kw">unsafe</span> { - <span class="comment">// Returns 1 if any of the passes modified the function, false otherwise.</span> - <span class="ident">LLVMRunFunctionPassManager</span>(<span class="self">self</span>.<span class="ident">fpm</span>, <span class="ident">fn_value</span>.<span class="ident">value_ref</span>()); + <span class="doccomment">/// Run the optimization passes registered with the Function PassManager on the function + /// referenced by `fn_value`. + </span><span class="kw">pub fn </span>run(<span class="kw-2">&</span><span class="lifetime">'llvm </span><span class="self">self</span>, fn_value: FnValue<<span class="lifetime">'llvm</span>>) { + <span class="kw">unsafe </span>{ + <span class="comment">// Returns 1 if any of the passes modified the function, false otherwise. + </span>LLVMRunFunctionPassManager(<span class="self">self</span>.fpm, fn_value.value_ref()); } } } -<span class="kw">impl</span> <span class="ident">Drop</span> <span class="kw">for</span> <span class="ident">FunctionPassManager</span><span class="op"><</span><span class="lifetime">'_</span><span class="op">></span> { - <span class="kw">fn</span> <span class="ident">drop</span>(<span class="kw-2">&mut</span> <span class="self">self</span>) { - <span class="kw">unsafe</span> { - <span class="ident">LLVMDisposePassManager</span>(<span class="self">self</span>.<span class="ident">fpm</span>); +<span class="kw">impl </span>Drop <span class="kw">for </span>FunctionPassManager<<span class="lifetime">'_</span>> { + <span class="kw">fn </span>drop(<span class="kw-2">&mut </span><span class="self">self</span>) { + <span class="kw">unsafe </span>{ + LLVMDisposePassManager(<span class="self">self</span>.fpm); } } } </code></pre></div> -</section></div></main><div id="rustdoc-vars" data-root-path="../../../" data-current-crate="llvm_kaleidoscope_rs" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.63.0 (4b91a6ea7 2022-08-08)" ></div> -</body></html>
\ No newline at end of file +</section></div></main><div id="rustdoc-vars" data-root-path="../../../" data-current-crate="llvm_kaleidoscope_rs" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.65.0 (897e37553 2022-11-02)" ></div></body></html>
\ No newline at end of file diff --git a/src/llvm_kaleidoscope_rs/llvm/type_.rs.html b/src/llvm_kaleidoscope_rs/llvm/type_.rs.html index 98daee4..7df4f4d 100644 --- a/src/llvm_kaleidoscope_rs/llvm/type_.rs.html +++ b/src/llvm_kaleidoscope_rs/llvm/type_.rs.html @@ -1,10 +1,4 @@ -<!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="Source of the Rust file `src/llvm/type_.rs`."><meta name="keywords" content="rust, rustlang, rust-lang"><title>type_.rs - source</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" type="text/css" href="../../../normalize.css"><link rel="stylesheet" type="text/css" href="../../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../../ayu.css" disabled><link rel="stylesheet" type="text/css" href="../../../dark.css" disabled><link rel="stylesheet" type="text/css" href="../../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../../storage.js"></script><script defer src="../../../source-script.js"></script><script defer src="../../../source-files.js"></script><script defer src="../../../main.js"></script><noscript><link rel="stylesheet" href="../../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../../favicon.svg"></head><body class="rustdoc source"><!--[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">☰</button><a class="sidebar-logo" href="../../../llvm_kaleidoscope_rs/index.html"><div class="logo-container"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></div> - </a><h2 class="location"></h2> - </nav> - <nav class="sidebar"><a class="sidebar-logo" href="../../../llvm_kaleidoscope_rs/index.html"><div class="logo-container"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></div> - </a></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../../../llvm_kaleidoscope_rs/index.html"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></a><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><button type="button" id="help-button" title="help">?</button><div id="settings-menu" tabindex="-1"> - <a href="../../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../../wheel.svg"></a></div> - </div></form></nav></div><section id="main-content" class="content"><div class="example-wrap"><pre class="line-numbers"><span id="1">1</span> +<!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="Source of the Rust file `src/llvm/type_.rs`."><meta name="keywords" content="rust, rustlang, rust-lang"><title>type_.rs - source</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../../../normalize.css"><link rel="stylesheet" href="../../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../../../ayu.css" disabled><link rel="stylesheet" href="../../../dark.css" disabled><link rel="stylesheet" href="../../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../../storage.js"></script><script defer src="../../../source-script.js"></script><script defer src="../../../source-files.js"></script><script defer src="../../../main.js"></script><noscript><link rel="stylesheet" href="../../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../../favicon.svg"></head><body class="rustdoc source"><!--[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">☰</button><a class="sidebar-logo" href="../../../llvm_kaleidoscope_rs/index.html"><div class="logo-container"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></div></a><h2 class="location"></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../../../llvm_kaleidoscope_rs/index.html"><div class="logo-container"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></div></a></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../../../llvm_kaleidoscope_rs/index.html"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></a><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><button type="button">?</button></div><div id="settings-menu" tabindex="-1"><a href="../../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../../wheel.svg"></a></div></div></form></nav></div><section id="main-content" class="content"><div class="example-wrap"><pre class="line-numbers"><span id="1">1</span> <span id="2">2</span> <span id="3">3</span> <span id="4">4</span> @@ -62,64 +56,63 @@ <span id="56">56</span> <span id="57">57</span> <span id="58">58</span> -</pre><pre class="rust"><code><span class="kw">use</span> <span class="ident">llvm_sys</span>::{ - <span class="ident">core</span>::{<span class="ident">LLVMConstReal</span>, <span class="ident">LLVMDumpType</span>, <span class="ident">LLVMGetTypeKind</span>}, - <span class="ident">prelude::LLVMTypeRef</span>, - <span class="ident">LLVMTypeKind</span>, +</pre><pre class="rust"><code><span class="kw">use </span>llvm_sys::{ + core::{LLVMConstReal, LLVMDumpType, LLVMGetTypeKind}, + prelude::LLVMTypeRef, + LLVMTypeKind, }; -<span class="kw">use</span> <span class="ident">std::marker::PhantomData</span>; +<span class="kw">use </span>std::marker::PhantomData; -<span class="kw">use</span> <span class="ident"><span class="kw">super</span>::Value</span>; +<span class="kw">use </span><span class="kw">super</span>::Value; -<span class="doccomment">/// Wrapper for a LLVM Type Reference.</span> -<span class="attribute">#[<span class="ident">derive</span>(<span class="ident">Copy</span>, <span class="ident">Clone</span>)]</span> -<span class="attribute">#[<span class="ident">repr</span>(<span class="ident">transparent</span>)]</span> -<span class="kw">pub</span> <span class="kw">struct</span> <span class="ident">Type</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>(<span class="ident">LLVMTypeRef</span>, <span class="ident">PhantomData</span><span class="op"><</span><span class="kw-2">&</span><span class="lifetime">'llvm</span> ()<span class="op">></span>); +<span class="doccomment">/// Wrapper for a LLVM Type Reference. +</span><span class="attribute">#[derive(Copy, Clone)] +#[repr(transparent)] +</span><span class="kw">pub struct </span>Type<<span class="lifetime">'llvm</span>>(LLVMTypeRef, PhantomData<<span class="kw-2">&</span><span class="lifetime">'llvm </span>()>); -<span class="kw">impl</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> <span class="ident">Type</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> { - <span class="doccomment">/// Create a new Type instance.</span> - <span class="doccomment">///</span> - <span class="doccomment">/// # Panics</span> - <span class="doccomment">///</span> - <span class="doccomment">/// Panics if `type_ref` is a null pointer.</span> - <span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn</span> <span class="ident">new</span>(<span class="ident">type_ref</span>: <span class="ident">LLVMTypeRef</span>) -> <span class="self">Self</span> { - <span class="macro">assert!</span>(<span class="op">!</span><span class="ident">type_ref</span>.<span class="ident">is_null</span>()); - <span class="ident">Type</span>(<span class="ident">type_ref</span>, <span class="ident">PhantomData</span>) +<span class="kw">impl</span><<span class="lifetime">'llvm</span>> Type<<span class="lifetime">'llvm</span>> { + <span class="doccomment">/// Create a new Type instance. + /// + /// # Panics + /// + /// Panics if `type_ref` is a null pointer. + </span><span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn </span>new(type_ref: LLVMTypeRef) -> <span class="self">Self </span>{ + <span class="macro">assert!</span>(!type_ref.is_null()); + Type(type_ref, PhantomData) } - <span class="doccomment">/// Get the raw LLVM type reference.</span> - <span class="attribute">#[<span class="ident">inline</span>]</span> - <span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn</span> <span class="ident">type_ref</span>(<span class="kw-2">&</span><span class="self">self</span>) -> <span class="ident">LLVMTypeRef</span> { - <span class="self">self</span>.<span class="number">0</span> - } + <span class="doccomment">/// Get the raw LLVM type reference. + </span><span class="attribute">#[inline] + </span><span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn </span>type_ref(<span class="kw-2">&</span><span class="self">self</span>) -> LLVMTypeRef { + <span class="self">self</span>.<span class="number">0 + </span>} - <span class="doccomment">/// Get the LLVM type kind for the given type reference.</span> - <span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn</span> <span class="ident">kind</span>(<span class="kw-2">&</span><span class="self">self</span>) -> <span class="ident">LLVMTypeKind</span> { - <span class="kw">unsafe</span> { <span class="ident">LLVMGetTypeKind</span>(<span class="self">self</span>.<span class="ident">type_ref</span>()) } + <span class="doccomment">/// Get the LLVM type kind for the given type reference. + </span><span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn </span>kind(<span class="kw-2">&</span><span class="self">self</span>) -> LLVMTypeKind { + <span class="kw">unsafe </span>{ LLVMGetTypeKind(<span class="self">self</span>.type_ref()) } } - <span class="doccomment">/// Dump the LLVM Type to stdout.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">dump</span>(<span class="kw-2">&</span><span class="self">self</span>) { - <span class="kw">unsafe</span> { <span class="ident">LLVMDumpType</span>(<span class="self">self</span>.<span class="ident">type_ref</span>()) }; + <span class="doccomment">/// Dump the LLVM Type to stdout. + </span><span class="kw">pub fn </span>dump(<span class="kw-2">&</span><span class="self">self</span>) { + <span class="kw">unsafe </span>{ LLVMDumpType(<span class="self">self</span>.type_ref()) }; } - <span class="doccomment">/// Get a value reference representing the const `f64` value.</span> - <span class="doccomment">///</span> - <span class="doccomment">/// # Panics</span> - <span class="doccomment">///</span> - <span class="doccomment">/// Panics if LLVM API returns a `null` pointer.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">const_f64</span>(<span class="self">self</span>, <span class="ident">n</span>: <span class="ident">f64</span>) -> <span class="ident">Value</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> { + <span class="doccomment">/// Get a value reference representing the const `f64` value. + /// + /// # Panics + /// + /// Panics if LLVM API returns a `null` pointer. + </span><span class="kw">pub fn </span>const_f64(<span class="self">self</span>, n: f64) -> Value<<span class="lifetime">'llvm</span>> { <span class="macro">debug_assert_eq!</span>( - <span class="self">self</span>.<span class="ident">kind</span>(), - <span class="ident">LLVMTypeKind::LLVMDoubleTypeKind</span>, - <span class="string">"Expected a double type when creating const f64 value!"</span> - ); + <span class="self">self</span>.kind(), + LLVMTypeKind::LLVMDoubleTypeKind, + <span class="string">"Expected a double type when creating const f64 value!" + </span>); - <span class="kw">let</span> <span class="ident">value_ref</span> <span class="op">=</span> <span class="kw">unsafe</span> { <span class="ident">LLVMConstReal</span>(<span class="self">self</span>.<span class="ident">type_ref</span>(), <span class="ident">n</span>) }; - <span class="ident">Value::new</span>(<span class="ident">value_ref</span>) + <span class="kw">let </span>value_ref = <span class="kw">unsafe </span>{ LLVMConstReal(<span class="self">self</span>.type_ref(), n) }; + Value::new(value_ref) } } </code></pre></div> -</section></div></main><div id="rustdoc-vars" data-root-path="../../../" data-current-crate="llvm_kaleidoscope_rs" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.63.0 (4b91a6ea7 2022-08-08)" ></div> -</body></html>
\ No newline at end of file +</section></div></main><div id="rustdoc-vars" data-root-path="../../../" data-current-crate="llvm_kaleidoscope_rs" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.65.0 (897e37553 2022-11-02)" ></div></body></html>
\ No newline at end of file diff --git a/src/llvm_kaleidoscope_rs/llvm/value.rs.html b/src/llvm_kaleidoscope_rs/llvm/value.rs.html index eaea9c3..102c957 100644 --- a/src/llvm_kaleidoscope_rs/llvm/value.rs.html +++ b/src/llvm_kaleidoscope_rs/llvm/value.rs.html @@ -1,10 +1,4 @@ -<!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="Source of the Rust file `src/llvm/value.rs`."><meta name="keywords" content="rust, rustlang, rust-lang"><title>value.rs - source</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" type="text/css" href="../../../normalize.css"><link rel="stylesheet" type="text/css" href="../../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../../ayu.css" disabled><link rel="stylesheet" type="text/css" href="../../../dark.css" disabled><link rel="stylesheet" type="text/css" href="../../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../../storage.js"></script><script defer src="../../../source-script.js"></script><script defer src="../../../source-files.js"></script><script defer src="../../../main.js"></script><noscript><link rel="stylesheet" href="../../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../../favicon.svg"></head><body class="rustdoc source"><!--[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">☰</button><a class="sidebar-logo" href="../../../llvm_kaleidoscope_rs/index.html"><div class="logo-container"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></div> - </a><h2 class="location"></h2> - </nav> - <nav class="sidebar"><a class="sidebar-logo" href="../../../llvm_kaleidoscope_rs/index.html"><div class="logo-container"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></div> - </a></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../../../llvm_kaleidoscope_rs/index.html"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></a><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><button type="button" id="help-button" title="help">?</button><div id="settings-menu" tabindex="-1"> - <a href="../../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../../wheel.svg"></a></div> - </div></form></nav></div><section id="main-content" class="content"><div class="example-wrap"><pre class="line-numbers"><span id="1">1</span> +<!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="Source of the Rust file `src/llvm/value.rs`."><meta name="keywords" content="rust, rustlang, rust-lang"><title>value.rs - source</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../../../normalize.css"><link rel="stylesheet" href="../../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../../../ayu.css" disabled><link rel="stylesheet" href="../../../dark.css" disabled><link rel="stylesheet" href="../../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../../storage.js"></script><script defer src="../../../source-script.js"></script><script defer src="../../../source-files.js"></script><script defer src="../../../main.js"></script><noscript><link rel="stylesheet" href="../../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../../favicon.svg"></head><body class="rustdoc source"><!--[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">☰</button><a class="sidebar-logo" href="../../../llvm_kaleidoscope_rs/index.html"><div class="logo-container"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></div></a><h2 class="location"></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../../../llvm_kaleidoscope_rs/index.html"><div class="logo-container"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></div></a></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../../../llvm_kaleidoscope_rs/index.html"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></a><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><button type="button">?</button></div><div id="settings-menu" tabindex="-1"><a href="../../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../../wheel.svg"></a></div></div></form></nav></div><section id="main-content" class="content"><div class="example-wrap"><pre class="line-numbers"><span id="1">1</span> <span id="2">2</span> <span id="3">3</span> <span id="4">4</span> @@ -241,243 +235,242 @@ <span id="235">235</span> <span id="236">236</span> <span id="237">237</span> -</pre><pre class="rust"><code><span class="attribute">#![<span class="ident">allow</span>(<span class="ident">unused</span>)]</span> - -<span class="kw">use</span> <span class="ident">llvm_sys</span>::{ - <span class="ident">analysis</span>::{<span class="ident">LLVMVerifierFailureAction</span>, <span class="ident">LLVMVerifyFunction</span>}, - <span class="ident">core</span>::{ - <span class="ident">LLVMAddIncoming</span>, <span class="ident">LLVMAppendExistingBasicBlock</span>, <span class="ident">LLVMCountBasicBlocks</span>, <span class="ident">LLVMCountParams</span>, - <span class="ident">LLVMDumpValue</span>, <span class="ident">LLVMGetParam</span>, <span class="ident">LLVMGetReturnType</span>, <span class="ident">LLVMGetValueKind</span>, <span class="ident">LLVMGetValueName2</span>, - <span class="ident">LLVMIsAFunction</span>, <span class="ident">LLVMIsAPHINode</span>, <span class="ident">LLVMSetValueName2</span>, <span class="ident">LLVMTypeOf</span>, +</pre><pre class="rust"><code><span class="attribute">#![allow(unused)] + +</span><span class="kw">use </span>llvm_sys::{ + analysis::{LLVMVerifierFailureAction, LLVMVerifyFunction}, + core::{ + LLVMAddIncoming, LLVMAppendExistingBasicBlock, LLVMCountBasicBlocks, LLVMCountParams, + LLVMDumpValue, LLVMGetParam, LLVMGetReturnType, LLVMGetValueKind, LLVMGetValueName2, + LLVMIsAFunction, LLVMIsAPHINode, LLVMSetValueName2, LLVMTypeOf, }, - <span class="ident">prelude::LLVMValueRef</span>, - <span class="ident">LLVMTypeKind</span>, <span class="ident">LLVMValueKind</span>, + prelude::LLVMValueRef, + LLVMTypeKind, LLVMValueKind, }; -<span class="kw">use</span> <span class="ident">std::ffi::CStr</span>; -<span class="kw">use</span> <span class="ident">std::marker::PhantomData</span>; -<span class="kw">use</span> <span class="ident">std::ops::Deref</span>; - -<span class="kw">use</span> <span class="ident"><span class="kw">super</span>::BasicBlock</span>; -<span class="kw">use</span> <span class="ident"><span class="kw">super</span>::Type</span>; - -<span class="doccomment">/// Wrapper for a LLVM Value Reference.</span> -<span class="attribute">#[<span class="ident">derive</span>(<span class="ident">Copy</span>, <span class="ident">Clone</span>)]</span> -<span class="attribute">#[<span class="ident">repr</span>(<span class="ident">transparent</span>)]</span> -<span class="kw">pub</span> <span class="kw">struct</span> <span class="ident">Value</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>(<span class="ident">LLVMValueRef</span>, <span class="ident">PhantomData</span><span class="op"><</span><span class="kw-2">&</span><span class="lifetime">'llvm</span> ()<span class="op">></span>); - -<span class="kw">impl</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> <span class="ident">Value</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> { - <span class="doccomment">/// Create a new Value instance.</span> - <span class="doccomment">///</span> - <span class="doccomment">/// # Panics</span> - <span class="doccomment">///</span> - <span class="doccomment">/// Panics if `value_ref` is a null pointer.</span> - <span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn</span> <span class="ident">new</span>(<span class="ident">value_ref</span>: <span class="ident">LLVMValueRef</span>) -> <span class="self">Self</span> { - <span class="macro">assert!</span>(<span class="op">!</span><span class="ident">value_ref</span>.<span class="ident">is_null</span>()); - <span class="ident">Value</span>(<span class="ident">value_ref</span>, <span class="ident">PhantomData</span>) +<span class="kw">use </span>std::ffi::CStr; +<span class="kw">use </span>std::marker::PhantomData; +<span class="kw">use </span>std::ops::Deref; + +<span class="kw">use </span><span class="kw">super</span>::BasicBlock; +<span class="kw">use </span><span class="kw">super</span>::Type; + +<span class="doccomment">/// Wrapper for a LLVM Value Reference. +</span><span class="attribute">#[derive(Copy, Clone)] +#[repr(transparent)] +</span><span class="kw">pub struct </span>Value<<span class="lifetime">'llvm</span>>(LLVMValueRef, PhantomData<<span class="kw-2">&</span><span class="lifetime">'llvm </span>()>); + +<span class="kw">impl</span><<span class="lifetime">'llvm</span>> Value<<span class="lifetime">'llvm</span>> { + <span class="doccomment">/// Create a new Value instance. + /// + /// # Panics + /// + /// Panics if `value_ref` is a null pointer. + </span><span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn </span>new(value_ref: LLVMValueRef) -> <span class="self">Self </span>{ + <span class="macro">assert!</span>(!value_ref.is_null()); + Value(value_ref, PhantomData) } - <span class="doccomment">/// Get the raw LLVM value reference.</span> - <span class="attribute">#[<span class="ident">inline</span>]</span> - <span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn</span> <span class="ident">value_ref</span>(<span class="kw-2">&</span><span class="self">self</span>) -> <span class="ident">LLVMValueRef</span> { - <span class="self">self</span>.<span class="number">0</span> - } + <span class="doccomment">/// Get the raw LLVM value reference. + </span><span class="attribute">#[inline] + </span><span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn </span>value_ref(<span class="kw-2">&</span><span class="self">self</span>) -> LLVMValueRef { + <span class="self">self</span>.<span class="number">0 + </span>} - <span class="doccomment">/// Get the LLVM value kind for the given value reference.</span> - <span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn</span> <span class="ident">kind</span>(<span class="kw-2">&</span><span class="self">self</span>) -> <span class="ident">LLVMValueKind</span> { - <span class="kw">unsafe</span> { <span class="ident">LLVMGetValueKind</span>(<span class="self">self</span>.<span class="ident">value_ref</span>()) } + <span class="doccomment">/// Get the LLVM value kind for the given value reference. + </span><span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn </span>kind(<span class="kw-2">&</span><span class="self">self</span>) -> LLVMValueKind { + <span class="kw">unsafe </span>{ LLVMGetValueKind(<span class="self">self</span>.value_ref()) } } - <span class="doccomment">/// Check if value is `function` type.</span> - <span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn</span> <span class="ident">is_function</span>(<span class="kw-2">&</span><span class="self">self</span>) -> <span class="ident">bool</span> { - <span class="kw">let</span> <span class="ident">cast</span> <span class="op">=</span> <span class="kw">unsafe</span> { <span class="ident">LLVMIsAFunction</span>(<span class="self">self</span>.<span class="ident">value_ref</span>()) }; - <span class="op">!</span><span class="ident">cast</span>.<span class="ident">is_null</span>() + <span class="doccomment">/// Check if value is `function` type. + </span><span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn </span>is_function(<span class="kw-2">&</span><span class="self">self</span>) -> bool { + <span class="kw">let </span>cast = <span class="kw">unsafe </span>{ LLVMIsAFunction(<span class="self">self</span>.value_ref()) }; + !cast.is_null() } - <span class="doccomment">/// Check if value is `phinode` type.</span> - <span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn</span> <span class="ident">is_phinode</span>(<span class="kw-2">&</span><span class="self">self</span>) -> <span class="ident">bool</span> { - <span class="kw">let</span> <span class="ident">cast</span> <span class="op">=</span> <span class="kw">unsafe</span> { <span class="ident">LLVMIsAPHINode</span>(<span class="self">self</span>.<span class="ident">value_ref</span>()) }; - <span class="op">!</span><span class="ident">cast</span>.<span class="ident">is_null</span>() + <span class="doccomment">/// Check if value is `phinode` type. + </span><span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn </span>is_phinode(<span class="kw-2">&</span><span class="self">self</span>) -> bool { + <span class="kw">let </span>cast = <span class="kw">unsafe </span>{ LLVMIsAPHINode(<span class="self">self</span>.value_ref()) }; + !cast.is_null() } - <span class="doccomment">/// Dump the LLVM Value to stdout.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">dump</span>(<span class="kw-2">&</span><span class="self">self</span>) { - <span class="kw">unsafe</span> { <span class="ident">LLVMDumpValue</span>(<span class="self">self</span>.<span class="ident">value_ref</span>()) }; + <span class="doccomment">/// Dump the LLVM Value to stdout. + </span><span class="kw">pub fn </span>dump(<span class="kw-2">&</span><span class="self">self</span>) { + <span class="kw">unsafe </span>{ LLVMDumpValue(<span class="self">self</span>.value_ref()) }; } - <span class="doccomment">/// Get a type reference representing for the given value reference.</span> - <span class="doccomment">///</span> - <span class="doccomment">/// # Panics</span> - <span class="doccomment">///</span> - <span class="doccomment">/// Panics if LLVM API returns a `null` pointer.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">type_of</span>(<span class="kw-2">&</span><span class="self">self</span>) -> <span class="ident">Type</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> { - <span class="kw">let</span> <span class="ident">type_ref</span> <span class="op">=</span> <span class="kw">unsafe</span> { <span class="ident">LLVMTypeOf</span>(<span class="self">self</span>.<span class="ident">value_ref</span>()) }; - <span class="ident">Type::new</span>(<span class="ident">type_ref</span>) + <span class="doccomment">/// Get a type reference representing for the given value reference. + /// + /// # Panics + /// + /// Panics if LLVM API returns a `null` pointer. + </span><span class="kw">pub fn </span>type_of(<span class="kw-2">&</span><span class="self">self</span>) -> Type<<span class="lifetime">'llvm</span>> { + <span class="kw">let </span>type_ref = <span class="kw">unsafe </span>{ LLVMTypeOf(<span class="self">self</span>.value_ref()) }; + Type::new(type_ref) } - <span class="doccomment">/// Set the name for the given value reference.</span> - <span class="doccomment">///</span> - <span class="doccomment">/// # Panics</span> - <span class="doccomment">///</span> - <span class="doccomment">/// Panics if LLVM API returns a `null` pointer.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">set_name</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">name</span>: <span class="kw-2">&</span><span class="ident">str</span>) { - <span class="kw">unsafe</span> { <span class="ident">LLVMSetValueName2</span>(<span class="self">self</span>.<span class="ident">value_ref</span>(), <span class="ident">name</span>.<span class="ident">as_ptr</span>().<span class="ident">cast</span>(), <span class="ident">name</span>.<span class="ident">len</span>()) }; + <span class="doccomment">/// Set the name for the given value reference. + /// + /// # Panics + /// + /// Panics if LLVM API returns a `null` pointer. + </span><span class="kw">pub fn </span>set_name(<span class="kw-2">&</span><span class="self">self</span>, name: <span class="kw-2">&</span>str) { + <span class="kw">unsafe </span>{ LLVMSetValueName2(<span class="self">self</span>.value_ref(), name.as_ptr().cast(), name.len()) }; } - <span class="doccomment">/// Get the name for the given value reference.</span> - <span class="doccomment">///</span> - <span class="doccomment">/// # Panics</span> - <span class="doccomment">///</span> - <span class="doccomment">/// Panics if LLVM API returns a `null` pointer.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">get_name</span>(<span class="kw-2">&</span><span class="self">self</span>) -> <span class="kw-2">&</span><span class="lifetime">'llvm</span> <span class="ident">str</span> { - <span class="kw">let</span> <span class="ident">name</span> <span class="op">=</span> <span class="kw">unsafe</span> { - <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">len</span>: <span class="ident">libc::size_t</span> <span class="op">=</span> <span class="number">0</span>; - <span class="kw">let</span> <span class="ident">name</span> <span class="op">=</span> <span class="ident">LLVMGetValueName2</span>(<span class="self">self</span>.<span class="number">0</span>, <span class="kw-2">&mut</span> <span class="ident">len</span> <span class="kw">as</span> <span class="kw">_</span>); - <span class="macro">assert!</span>(<span class="op">!</span><span class="ident">name</span>.<span class="ident">is_null</span>()); - - <span class="ident">CStr::from_ptr</span>(<span class="ident">name</span>) + <span class="doccomment">/// Get the name for the given value reference. + /// + /// # Panics + /// + /// Panics if LLVM API returns a `null` pointer. + </span><span class="kw">pub fn </span>get_name(<span class="kw-2">&</span><span class="self">self</span>) -> <span class="kw-2">&</span><span class="lifetime">'llvm </span>str { + <span class="kw">let </span>name = <span class="kw">unsafe </span>{ + <span class="kw">let </span><span class="kw-2">mut </span>len: libc::size_t = <span class="number">0</span>; + <span class="kw">let </span>name = LLVMGetValueName2(<span class="self">self</span>.<span class="number">0</span>, <span class="kw-2">&mut </span>len <span class="kw">as _</span>); + <span class="macro">assert!</span>(!name.is_null()); + + CStr::from_ptr(name) }; - <span class="comment">// TODO: Does this string live for the time of the LLVM context?!</span> - <span class="ident">name</span>.<span class="ident">to_str</span>() - .<span class="ident">expect</span>(<span class="string">"Expected valid UTF8 string from LLVM API"</span>) + <span class="comment">// TODO: Does this string live for the time of the LLVM context?! + </span>name.to_str() + .expect(<span class="string">"Expected valid UTF8 string from LLVM API"</span>) } - <span class="doccomment">/// Check if value is of `f64` type.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">is_f64</span>(<span class="kw-2">&</span><span class="self">self</span>) -> <span class="ident">bool</span> { - <span class="self">self</span>.<span class="ident">type_of</span>().<span class="ident">kind</span>() <span class="op">==</span> <span class="ident">LLVMTypeKind::LLVMDoubleTypeKind</span> + <span class="doccomment">/// Check if value is of `f64` type. + </span><span class="kw">pub fn </span>is_f64(<span class="kw-2">&</span><span class="self">self</span>) -> bool { + <span class="self">self</span>.type_of().kind() == LLVMTypeKind::LLVMDoubleTypeKind } - <span class="doccomment">/// Check if value is of integer type.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">is_int</span>(<span class="kw-2">&</span><span class="self">self</span>) -> <span class="ident">bool</span> { - <span class="self">self</span>.<span class="ident">type_of</span>().<span class="ident">kind</span>() <span class="op">==</span> <span class="ident">LLVMTypeKind::LLVMIntegerTypeKind</span> + <span class="doccomment">/// Check if value is of integer type. + </span><span class="kw">pub fn </span>is_int(<span class="kw-2">&</span><span class="self">self</span>) -> bool { + <span class="self">self</span>.type_of().kind() == LLVMTypeKind::LLVMIntegerTypeKind } } -<span class="doccomment">/// Wrapper for a LLVM Value Reference specialized for contexts where function values are needed.</span> -<span class="attribute">#[<span class="ident">derive</span>(<span class="ident">Copy</span>, <span class="ident">Clone</span>)]</span> -<span class="attribute">#[<span class="ident">repr</span>(<span class="ident">transparent</span>)]</span> -<span class="kw">pub</span> <span class="kw">struct</span> <span class="ident">FnValue</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>(<span class="ident">Value</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>); +<span class="doccomment">/// Wrapper for a LLVM Value Reference specialized for contexts where function values are needed. +</span><span class="attribute">#[derive(Copy, Clone)] +#[repr(transparent)] +</span><span class="kw">pub struct </span>FnValue<<span class="lifetime">'llvm</span>>(Value<<span class="lifetime">'llvm</span>>); -<span class="kw">impl</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> <span class="ident">Deref</span> <span class="kw">for</span> <span class="ident">FnValue</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> { - <span class="kw">type</span> <span class="ident">Target</span> <span class="op">=</span> <span class="ident">Value</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>; - <span class="kw">fn</span> <span class="ident">deref</span>(<span class="kw-2">&</span><span class="self">self</span>) -> <span class="kw-2">&</span><span class="ident"><span class="self">Self</span>::Target</span> { - <span class="kw-2">&</span><span class="self">self</span>.<span class="number">0</span> - } +<span class="kw">impl</span><<span class="lifetime">'llvm</span>> Deref <span class="kw">for </span>FnValue<<span class="lifetime">'llvm</span>> { + <span class="kw">type </span>Target = Value<<span class="lifetime">'llvm</span>>; + <span class="kw">fn </span>deref(<span class="kw-2">&</span><span class="self">self</span>) -> <span class="kw-2">&</span><span class="self">Self</span>::Target { + <span class="kw-2">&</span><span class="self">self</span>.<span class="number">0 + </span>} } -<span class="kw">impl</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> <span class="ident">FnValue</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> { - <span class="doccomment">/// Create a new FnValue instance.</span> - <span class="doccomment">///</span> - <span class="doccomment">/// # Panics</span> - <span class="doccomment">///</span> - <span class="doccomment">/// Panics if `value_ref` is a null pointer.</span> - <span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn</span> <span class="ident">new</span>(<span class="ident">value_ref</span>: <span class="ident">LLVMValueRef</span>) -> <span class="self">Self</span> { - <span class="kw">let</span> <span class="ident">value</span> <span class="op">=</span> <span class="ident">Value::new</span>(<span class="ident">value_ref</span>); +<span class="kw">impl</span><<span class="lifetime">'llvm</span>> FnValue<<span class="lifetime">'llvm</span>> { + <span class="doccomment">/// Create a new FnValue instance. + /// + /// # Panics + /// + /// Panics if `value_ref` is a null pointer. + </span><span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn </span>new(value_ref: LLVMValueRef) -> <span class="self">Self </span>{ + <span class="kw">let </span>value = Value::new(value_ref); <span class="macro">debug_assert!</span>( - <span class="ident">value</span>.<span class="ident">is_function</span>(), - <span class="string">"Expected a fn value when constructing FnValue!"</span> - ); + value.is_function(), + <span class="string">"Expected a fn value when constructing FnValue!" + </span>); - <span class="ident">FnValue</span>(<span class="ident">value</span>) + FnValue(value) } - <span class="doccomment">/// Get a type reference representing the return value of the given function value.</span> - <span class="doccomment">///</span> - <span class="doccomment">/// # Panics</span> - <span class="doccomment">///</span> - <span class="doccomment">/// Panics if LLVM API returns a `null` pointer.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">ret_type</span>(<span class="kw-2">&</span><span class="self">self</span>) -> <span class="ident">Type</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> { - <span class="kw">let</span> <span class="ident">type_ref</span> <span class="op">=</span> <span class="kw">unsafe</span> { <span class="ident">LLVMGetReturnType</span>(<span class="ident">LLVMTypeOf</span>(<span class="self">self</span>.<span class="ident">value_ref</span>())) }; - <span class="ident">Type::new</span>(<span class="ident">type_ref</span>) + <span class="doccomment">/// Get a type reference representing the return value of the given function value. + /// + /// # Panics + /// + /// Panics if LLVM API returns a `null` pointer. + </span><span class="kw">pub fn </span>ret_type(<span class="kw-2">&</span><span class="self">self</span>) -> Type<<span class="lifetime">'llvm</span>> { + <span class="kw">let </span>type_ref = <span class="kw">unsafe </span>{ LLVMGetReturnType(LLVMTypeOf(<span class="self">self</span>.value_ref())) }; + Type::new(type_ref) } - <span class="doccomment">/// Get the number of function arguments for the given function value.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">args</span>(<span class="kw-2">&</span><span class="self">self</span>) -> <span class="ident">usize</span> { - <span class="kw">unsafe</span> { <span class="ident">LLVMCountParams</span>(<span class="self">self</span>.<span class="ident">value_ref</span>()) <span class="kw">as</span> <span class="ident">usize</span> } + <span class="doccomment">/// Get the number of function arguments for the given function value. + </span><span class="kw">pub fn </span>args(<span class="kw-2">&</span><span class="self">self</span>) -> usize { + <span class="kw">unsafe </span>{ LLVMCountParams(<span class="self">self</span>.value_ref()) <span class="kw">as </span>usize } } - <span class="doccomment">/// Get a value reference for the function argument at index `idx`.</span> - <span class="doccomment">///</span> - <span class="doccomment">/// # Panics</span> - <span class="doccomment">///</span> - <span class="doccomment">/// Panics if LLVM API returns a `null` pointer or indexed out of bounds.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">arg</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">idx</span>: <span class="ident">usize</span>) -> <span class="ident">Value</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> { - <span class="macro">assert!</span>(<span class="ident">idx</span> <span class="op"><</span> <span class="self">self</span>.<span class="ident">args</span>()); + <span class="doccomment">/// Get a value reference for the function argument at index `idx`. + /// + /// # Panics + /// + /// Panics if LLVM API returns a `null` pointer or indexed out of bounds. + </span><span class="kw">pub fn </span>arg(<span class="kw-2">&</span><span class="self">self</span>, idx: usize) -> Value<<span class="lifetime">'llvm</span>> { + <span class="macro">assert!</span>(idx < <span class="self">self</span>.args()); - <span class="kw">let</span> <span class="ident">value_ref</span> <span class="op">=</span> <span class="kw">unsafe</span> { <span class="ident">LLVMGetParam</span>(<span class="self">self</span>.<span class="ident">value_ref</span>(), <span class="ident">idx</span> <span class="kw">as</span> <span class="ident">libc::c_uint</span>) }; - <span class="ident">Value::new</span>(<span class="ident">value_ref</span>) + <span class="kw">let </span>value_ref = <span class="kw">unsafe </span>{ LLVMGetParam(<span class="self">self</span>.value_ref(), idx <span class="kw">as </span>libc::c_uint) }; + Value::new(value_ref) } - <span class="doccomment">/// Get the number of Basic Blocks for the given function value.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">basic_blocks</span>(<span class="kw-2">&</span><span class="self">self</span>) -> <span class="ident">usize</span> { - <span class="kw">unsafe</span> { <span class="ident">LLVMCountBasicBlocks</span>(<span class="self">self</span>.<span class="ident">value_ref</span>()) <span class="kw">as</span> <span class="ident">usize</span> } + <span class="doccomment">/// Get the number of Basic Blocks for the given function value. + </span><span class="kw">pub fn </span>basic_blocks(<span class="kw-2">&</span><span class="self">self</span>) -> usize { + <span class="kw">unsafe </span>{ LLVMCountBasicBlocks(<span class="self">self</span>.value_ref()) <span class="kw">as </span>usize } } - <span class="doccomment">/// Append a Basic Block to the end of the function value.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">append_basic_block</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">bb</span>: <span class="ident">BasicBlock</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>) { - <span class="kw">unsafe</span> { - <span class="ident">LLVMAppendExistingBasicBlock</span>(<span class="self">self</span>.<span class="ident">value_ref</span>(), <span class="ident">bb</span>.<span class="ident">bb_ref</span>()); + <span class="doccomment">/// Append a Basic Block to the end of the function value. + </span><span class="kw">pub fn </span>append_basic_block(<span class="kw-2">&</span><span class="self">self</span>, bb: BasicBlock<<span class="lifetime">'llvm</span>>) { + <span class="kw">unsafe </span>{ + LLVMAppendExistingBasicBlock(<span class="self">self</span>.value_ref(), bb.bb_ref()); } } - <span class="doccomment">/// Verify that the given function is valid.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">verify</span>(<span class="kw-2">&</span><span class="self">self</span>) -> <span class="ident">bool</span> { - <span class="kw">unsafe</span> { - <span class="ident">LLVMVerifyFunction</span>( - <span class="self">self</span>.<span class="ident">value_ref</span>(), - <span class="ident">LLVMVerifierFailureAction::LLVMPrintMessageAction</span>, - ) <span class="op">==</span> <span class="number">0</span> - } + <span class="doccomment">/// Verify that the given function is valid. + </span><span class="kw">pub fn </span>verify(<span class="kw-2">&</span><span class="self">self</span>) -> bool { + <span class="kw">unsafe </span>{ + LLVMVerifyFunction( + <span class="self">self</span>.value_ref(), + LLVMVerifierFailureAction::LLVMPrintMessageAction, + ) == <span class="number">0 + </span>} } } -<span class="doccomment">/// Wrapper for a LLVM Value Reference specialized for contexts where phi values are needed.</span> -<span class="attribute">#[<span class="ident">derive</span>(<span class="ident">Copy</span>, <span class="ident">Clone</span>)]</span> -<span class="attribute">#[<span class="ident">repr</span>(<span class="ident">transparent</span>)]</span> -<span class="kw">pub</span> <span class="kw">struct</span> <span class="ident">PhiValue</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>(<span class="ident">Value</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>); +<span class="doccomment">/// Wrapper for a LLVM Value Reference specialized for contexts where phi values are needed. +</span><span class="attribute">#[derive(Copy, Clone)] +#[repr(transparent)] +</span><span class="kw">pub struct </span>PhiValue<<span class="lifetime">'llvm</span>>(Value<<span class="lifetime">'llvm</span>>); -<span class="kw">impl</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> <span class="ident">Deref</span> <span class="kw">for</span> <span class="ident">PhiValue</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> { - <span class="kw">type</span> <span class="ident">Target</span> <span class="op">=</span> <span class="ident">Value</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>; - <span class="kw">fn</span> <span class="ident">deref</span>(<span class="kw-2">&</span><span class="self">self</span>) -> <span class="kw-2">&</span><span class="ident"><span class="self">Self</span>::Target</span> { - <span class="kw-2">&</span><span class="self">self</span>.<span class="number">0</span> - } +<span class="kw">impl</span><<span class="lifetime">'llvm</span>> Deref <span class="kw">for </span>PhiValue<<span class="lifetime">'llvm</span>> { + <span class="kw">type </span>Target = Value<<span class="lifetime">'llvm</span>>; + <span class="kw">fn </span>deref(<span class="kw-2">&</span><span class="self">self</span>) -> <span class="kw-2">&</span><span class="self">Self</span>::Target { + <span class="kw-2">&</span><span class="self">self</span>.<span class="number">0 + </span>} } -<span class="kw">impl</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> <span class="ident">PhiValue</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span> { - <span class="doccomment">/// Create a new PhiValue instance.</span> - <span class="doccomment">///</span> - <span class="doccomment">/// # Panics</span> - <span class="doccomment">///</span> - <span class="doccomment">/// Panics if `value_ref` is a null pointer.</span> - <span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn</span> <span class="ident">new</span>(<span class="ident">value_ref</span>: <span class="ident">LLVMValueRef</span>) -> <span class="self">Self</span> { - <span class="kw">let</span> <span class="ident">value</span> <span class="op">=</span> <span class="ident">Value::new</span>(<span class="ident">value_ref</span>); +<span class="kw">impl</span><<span class="lifetime">'llvm</span>> PhiValue<<span class="lifetime">'llvm</span>> { + <span class="doccomment">/// Create a new PhiValue instance. + /// + /// # Panics + /// + /// Panics if `value_ref` is a null pointer. + </span><span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn </span>new(value_ref: LLVMValueRef) -> <span class="self">Self </span>{ + <span class="kw">let </span>value = Value::new(value_ref); <span class="macro">debug_assert!</span>( - <span class="ident">value</span>.<span class="ident">is_phinode</span>(), - <span class="string">"Expected a phinode value when constructing PhiValue!"</span> - ); + value.is_phinode(), + <span class="string">"Expected a phinode value when constructing PhiValue!" + </span>); - <span class="ident">PhiValue</span>(<span class="ident">value</span>) + PhiValue(value) } - <span class="doccomment">/// Add an incoming value to the end of a PHI list.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">add_incoming</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">ival</span>: <span class="ident">Value</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>, <span class="ident">ibb</span>: <span class="ident">BasicBlock</span><span class="op"><</span><span class="lifetime">'llvm</span><span class="op">></span>) { + <span class="doccomment">/// Add an incoming value to the end of a PHI list. + </span><span class="kw">pub fn </span>add_incoming(<span class="kw-2">&</span><span class="self">self</span>, ival: Value<<span class="lifetime">'llvm</span>>, ibb: BasicBlock<<span class="lifetime">'llvm</span>>) { <span class="macro">debug_assert_eq!</span>( - <span class="ident">ival</span>.<span class="ident">type_of</span>().<span class="ident">kind</span>(), - <span class="self">self</span>.<span class="ident">type_of</span>().<span class="ident">kind</span>(), - <span class="string">"Type of incoming phi value must be the same as the type used to build the phi node."</span> - ); - - <span class="kw">unsafe</span> { - <span class="ident">LLVMAddIncoming</span>( - <span class="self">self</span>.<span class="ident">value_ref</span>(), - <span class="kw-2">&mut</span> <span class="ident">ival</span>.<span class="ident">value_ref</span>() <span class="kw">as</span> <span class="kw">_</span>, - <span class="kw-2">&mut</span> <span class="ident">ibb</span>.<span class="ident">bb_ref</span>() <span class="kw">as</span> <span class="kw">_</span>, + ival.type_of().kind(), + <span class="self">self</span>.type_of().kind(), + <span class="string">"Type of incoming phi value must be the same as the type used to build the phi node." + </span>); + + <span class="kw">unsafe </span>{ + LLVMAddIncoming( + <span class="self">self</span>.value_ref(), + <span class="kw-2">&mut </span>ival.value_ref() <span class="kw">as _</span>, + <span class="kw-2">&mut </span>ibb.bb_ref() <span class="kw">as _</span>, <span class="number">1</span>, ); } } } </code></pre></div> -</section></div></main><div id="rustdoc-vars" data-root-path="../../../" data-current-crate="llvm_kaleidoscope_rs" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.63.0 (4b91a6ea7 2022-08-08)" ></div> -</body></html>
\ No newline at end of file +</section></div></main><div id="rustdoc-vars" data-root-path="../../../" data-current-crate="llvm_kaleidoscope_rs" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.65.0 (897e37553 2022-11-02)" ></div></body></html>
\ No newline at end of file |