In my low-level IR I have this:
function #cc_g() -> W
b0:
#an_f: int = 1
jump b2
b1:
return f_a
b2:
#cc_h: ??? = #builtin[print_int].0
f_a: () = #cc_h(#builtin[print_int], #an_f)
jump b1
The mapping of this to cranelift is very direct, blocks map 1-1, so the cranelift function looks like:
function u0:0() -> i64 system_v {
gv0 = symbol u1:0
gv1 = symbol u1:0
sig0 = (i64) -> i64 system_v
sig1 = (i64, i64) -> i64 system_v
fn0 = u0:0 sig0
block0:
v0 = iconst.i64 1
jump block2
Now at this point I get a panic while printing the next block, the error message just says "INVALID encountered". Any ideas what's wrong here?
I'm guessing that use of the variable f_a
in b1
is not quite correct (because it's declared in the next block), but I'm not sure
I noticed you are using declare_var
for every assignment: https://github.com/osa1/mincaml/blob/b8ef0a735cc5a88333f7aebaf89a5be062bebf03/src/codegen.rs#L299 If you can assign to the same variable multiple times, you should only call declare_var
once. For some reason there is no assertion about this though.
The problem here is likely that you used use_var
before the declare_var
call though. This means that during the use_var
call Cranelift thinks the type of the variable is INVALID
, which is not allowed.
You need to call declare_var
exactly once for a variable before you use either def_var
or use_var
.
The code could use a couple of assertions.
The problem here is likely that you used use_var before the declare_var call though
Ahh, you're probably right.
bjorn3 said:
The code could use a couple of assertions.
https://github.com/bytecodealliance/wasmtime/pull/1751
You were right about declarations -- I fixed the issue. Thanks!
Last updated: Nov 22 2024 at 16:03 UTC