https://github.com/bzar/wasm-intro
WASM examples
https://github.com/bzar/wasm-intro
Last synced: 3 months ago
JSON representation
WASM examples
- Host: GitHub
- URL: https://github.com/bzar/wasm-intro
- Owner: bzar
- License: mit
- Created: 2017-04-11T15:34:10.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-05-25T10:07:02.000Z (over 8 years ago)
- Last Synced: 2025-03-17T10:11:24.566Z (10 months ago)
- Language: C
- Homepage: https://bzar.github.io/wasm-intro
- Size: 41 KB
- Stars: 43
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-wasm - wasm-intro - Tiny WebAssembly Examples with LLVM/clang and C
README
# WASM-Intro
A scratchpad of stuff in WebAssembly. All examples are written for simplicity, not good code style nor performance. Please do not use anything here in important stuff.
Much of the toolchain is based on [yurydelendik's "Using WebAssembly in LLVM" gist](https://gist.github.com/yurydelendik/4eeff8248aeb14ce763e).
## Build environment
Run `make build` and `make install` in `tools`. This builds LLVM, clang, binaryen and WABT with correct stuff for WebAssembly compiling.
## Examples
Build by running `make` in each directory. Test using python3 by running `make serve` and browsing to localhost:8000.
To build intermediate results from the C -> WASM compilation, try `make main.s` and `make main.wat`
### Add
Simple function export example. Adds two numbers together and prints to console
### Import/Export
Same as Add, now with an added step of delegating the addition back to JavaScript.
### Memory
Poking an exported linear memory from JS and C.
### Strings
Manipulating JS strings in C.
### Malloc
Implementing a simple toy dynamic memory allocation scheme.
### Animation
Some canvas functions imported to WASM, shows bouncing particles.
### WebGL
Wraps a portion of WebGL API for importing to WASM, draws a moving triangle.
### Pong
Wraps a little more of WebGL API for importing to WASM, plays Pong.