I managed to successfully get my JVM to compile the following Java code
public class Main {
public Main() {
}
public static int return_4() {
int var0 = 0;
for(int var1 = 0; var1 < 1024; ++var1) {
var0 += var1;
}
return var0;
}
}
into the following WASM code (represented in the text format for legibility because I don't think you can read raw wasm modules by eye and if you can you're cool)
(module
(type (;0;) (func (result i32)))
(type (;1;) (func))
(type (;2;) (func (param i32 i32)))
(func (;0;) (type 0) (result i32)
(local i32 i32 i32)
i32.const 0
local.set 0
i32.const 0
local.set 1
loop ;; label = @1
local.get 1
i32.const 1024
block (type 2) (param i32 i32) ;; label = @2
i32.ge_s
br_if 0 (;@2;)
local.get 0
local.get 1
i32.add
local.set 0
local.get 1
i32.const 1
i32.add
local.set 1
br 1 (;@1;)
end
end
local.get 0
return
)
(export "java" (func 0))
)
and when I run it with wasmtime I get
> 523776
