diff options
author | johannst <johannst@users.noreply.github.com> | 2024-12-19 17:29:34 +0000 |
---|---|---|
committer | johannst <johannst@users.noreply.github.com> | 2024-12-19 17:29:34 +0000 |
commit | 779f16ef901642de5012297734af0e20f36767cf (patch) | |
tree | d377b89970000afbc064c36a8238af04860b2c9f /src/add/add.rs.html | |
parent | ff6df70f5e8650a98fe076515a8c5b0c8885895c (diff) | |
download | juicebox-asm-779f16ef901642de5012297734af0e20f36767cf.tar.gz juicebox-asm-779f16ef901642de5012297734af0e20f36767cf.zip |
deploy: f76bf4e81d6b039007715ca0af3ad3a5d043367f
Diffstat (limited to 'src/add/add.rs.html')
-rw-r--r-- | src/add/add.rs.html | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/add/add.rs.html b/src/add/add.rs.html index 38058ec..580daa0 100644 --- a/src/add/add.rs.html +++ b/src/add/add.rs.html @@ -36,7 +36,8 @@ <a href="#35" id="35">35</a> <a href="#36" id="36">36</a> <a href="#37" id="37">37</a> -<a href="#38" id="38">38</a></pre></div><pre class="rust"><code><span class="doccomment">//! Add example. +<a href="#38" id="38">38</a> +<a href="#39" id="39">39</a></pre></div><pre class="rust"><code><span class="doccomment">//! Add example. //! //! Jit compile a function at runtime (generate native host code) which calls a function defined in //! the example based on the SystemV abi to demonstrate the [`juicebox_asm`] crate. @@ -65,11 +66,12 @@ asm.call(rax); asm.ret(); - <span class="kw">let </span>code = asm.into_code(); - std::fs::write(<span class="string">"jit.asm"</span>, <span class="kw-2">&</span>code).unwrap(); - <span class="kw">let </span><span class="kw-2">mut </span>rt = Runtime::new(); - <span class="kw">let </span>add42 = <span class="kw">unsafe </span>{ rt.add_code::<<span class="kw">extern </span><span class="string">"C" </span><span class="kw">fn</span>(u32) -> u32>(code) }; + <span class="kw">let </span>add42 = <span class="kw">unsafe </span>{ rt.add_code::<<span class="kw">extern </span><span class="string">"C" </span><span class="kw">fn</span>(u32) -> u32>(asm.into_code()) }; + + <span class="comment">// Write out JIT code for visualization. + // Disassemble for example with `ndisasm -b 64 jit.asm`. + </span>rt.dump(); <span class="kw">let </span>res = add42(<span class="number">5</span>); <span class="macro">assert_eq!</span>(res, <span class="number">47</span>); |