Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pangoraw/wasmcompiler.jl
:jigsaw: it's just bytes
https://github.com/pangoraw/wasmcompiler.jl
Last synced: 26 days ago
JSON representation
:jigsaw: it's just bytes
- Host: GitHub
- URL: https://github.com/pangoraw/wasmcompiler.jl
- Owner: Pangoraw
- Created: 2023-06-02T20:58:45.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-10T18:35:06.000Z (about 2 months ago)
- Last Synced: 2024-09-10T20:56:52.006Z (about 2 months ago)
- Language: Julia
- Homepage:
- Size: 399 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# WasmCompiler.jl
This is essentially a rewrite of [Charlotte.jl](https://github.com/MikeInnes/Charlotte.jl) (a lot has changed since 2018, both in WebAssembly and Julia land) targeting the new WebAssembly proposals ([gc](https://github.com/WebAssembly/gc),[exceptions](https://github.com/WebAssembly/exception-handling),...).
## Example
```julia
julia> using WasmCompilerjulia> relu(x) = ifelse(x < zero(x), zero(x), x)
relu (generic function with 1 method)julia> @code_wasm relu(1f0)
(func $relu (param f32) (result f32)
(local i32 f32)
block
local.get 0
f32.const 0.0
f32.lt
local.set 1
f32.const 0.0
local.get 0
local.get 1
select
local.set 2
local.get 2
nop
return
end
unreachable
)julia> @code_wasm optimize=true relu(1f0)
(func $relu (param f32) (result f32)
(local i32)
local.get 0
f32.const 0.0
f32.lt
local.set 1
f32.const 0.0
local.get 0
local.get 1
select
)julia> @code_wasm mod=true sexpr=true optimize=true relu(1f0) # Use sexpr=true to display as WAST
(module
(func $relu (param f32) (result f32)
(local i32)
(local.set 1
(f32.lt
(local.get 0)
(f32.const 0.0)))
(select
(f32.const 0.0)
(local.get 0)
(local.get 1))
)
(export "relu" (func $relu)))julia> # with an extra optimizer effort we can move the cond local
@code_wasm optimize=2 sexpr=true relu(1f0)
(module
(func $relu (param f32) (result f32)
(select
(f32.const 0.0)
(local.get 0)
(f32.lt
(local.get 0)
(f32.const 0.0)))
)
(export "relu" (func $relu))
)
```## References
- https://webassembly.github.io/spec/core/
- https://developer.mozilla.org/en-US/docs/WebAssembly/Reference