Skip to content

Conversation

Pangoraw
Copy link
Contributor

This uses WasmCompiler.jl for codegen instead of libbinaryen.

  • Rename and publish WasmCompiler.jl (any name ideas?)
  • Test GC stuff
  • Primitive error handling

Note

This is pretty much work in progress, expect very little to work.

But it can compile relu !

julia> using WebAssemblyCompiler, WasmCompiler

julia> relu(x) = ifelse(x < zero(x), zero(x), x)
relu (generic function with 1 method)

julia> compile((relu, Float32); optimize=true)
(module
  (func $relu (param i32 f32) (result f32)
    (local i32 f32)
    block
      local.get 1
      f32.const 0.0
      f32.lt
      local.set 2
      f32.const 0.0
      local.get 1
      local.get 2
      select
      local.set 3
      local.get 3
      return
      return
    end
    unreachable
  )
  (export "relu" (func $relu))
)

julia> instance = WasmCompiler.Interpreter.instantiate(open(WC.wread, "foo.wasm"  ));
       wasm_relu = WasmCompiler.Interpreter.exports(instance).relu
       wasm_relu(Int32(0), -1f0), wasm_relu(Int32(0), 10f0)
(Any[0.0f0], Any[10.0f0])

@tshort
Copy link
Owner

tshort commented Oct 5, 2024

Naming is tough, but I don't see anything wrong with WasmCompiler.jl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants