Stream: cranelift

Topic: Operand Stack with FuncBuilder


view this post on Zulip Robin Lindner (Jul 24 2022 at 19:15):

How would you represent this operand stack in cranelift? (Has anybody wrote some JVM-Bytecode -> Cranelift Code)?
https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-6.html#jvms-6.5.bipush

view this post on Zulip Afonso Bordado (Jul 24 2022 at 19:20):

If you are trying to emulate a stack machine you can try looking at how wasmtime translates wasm to cranelift, which also emulates a stack machine.

I think they just keep track of the stack of values at translation time. See here the code for add

A standalone runtime for WebAssembly. Contribute to bytecodealliance/wasmtime development by creating an account on GitHub.
A standalone runtime for WebAssembly. Contribute to bytecodealliance/wasmtime development by creating an account on GitHub.
A standalone runtime for WebAssembly. Contribute to bytecodealliance/wasmtime development by creating an account on GitHub.

view this post on Zulip Robin Lindner (Jul 24 2022 at 19:51):

@Afonso Bordado Thank you.
Next question: How can I divide two values? FuncInstBuilder does not have idiv

view this post on Zulip Robin Lindner (Jul 24 2022 at 19:52):

same for and/or

view this post on Zulip Afonso Bordado (Jul 24 2022 at 20:22):

We have two instructions for division sdiv which divides two values as if they are signed integers and udiv which does the same but as if they are unsiged.

For bools we prefix instructions with a b, so you'll find those instructions as band and bor


Last updated: Dec 23 2024 at 12:05 UTC