Hello again! It seems that store
on r_ptr
here has been used wrong. It gives a SEGFAULT. Where am I wrong?
https://codeberg.org/farooqkz/wakegp/src/branch/master/src/compiler.rs#L159
https://codeberg.org/farooqkz/wakegp/src/branch/master/src/compiler.rs#L163
r_ptr
comes from the second argument of the function(see this and this). The offset is calculated by the index(r0
) multiplied by size of each element in the array(https://codeberg.org/farooqkz/wakegp/src/branch/master/src/compiler.rs#L188).
Thanks in advance!
The problem was that I had to map a memory and make it executable. I still have other questions. Should I ask here or open a new topic?
Asking here is fine. Won't get around to answering any questions today (CET) though.
I cannot find brnz
in the docs which is used here:
https://github.com/Rodrigodd/bf-compiler/blob/master/cranelift-jit/src/main.rs#L219
I basically doing an fcmp
, if it's true, there will be a jump, either backward or forward within the function(jump offsets are guarrented to be always inside my function). If it's false, there won't be any jump.
Furthermore, for forward jumps, how can I jump to an address which I've yet to write the instructions for? I mean if I don't have instructions yet, how do I get the jump address?
Edit: nvm this. There is an example in the bf compiler repository.
hmm it seems that repo is using an ancient version of cranelift :)
There is br_if
and br_table
. The first accepts arguments for both the true
and else/false
cases which does not match in my use case. The latter seems more like it, but I'm unsure if I can do backward jumps with it.
Clif ir uses basic blocks rather than extended basic blocks, so every branch instruction is always jumps to another block and must be the last instruction in the block. In the backend a jump to the block immediately following the current block will be optimized away though.
brz/brnz no longer exist and have been replaced by br_if when we moved from extended basic blocks to basic blocks.
Can you please post an example on how to use do a simple if else statement like in C with cranelift?
Here's an example of the use of brif
in Wasmtime's translation to CLIF: https://github.com/bytecodealliance/wasmtime/blob/66910067642ce2ddf5509845306508f89a24fc9e/crates/cranelift/src/func_environ.rs#L913
note the "continuation block" -- that's a common idiom, if you have what is logically a "one-way branch" (if condition, go somewhere else)
and note you can create blocks so you have their labels for targets before you fill them in
Thanks!
Last updated: Dec 23 2024 at 12:05 UTC