Skip to content

Commit

Permalink
Initial commit with support for wasi
Browse files Browse the repository at this point in the history
  • Loading branch information
crazystylus committed Jun 20, 2022
0 parents commit f72fc66
Show file tree
Hide file tree
Showing 10 changed files with 685 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/target
*.wasm
*.wasmu
*.out
264 changes: 264 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
authors = ["Kartik Sharma <[email protected]>"]
categories = ["compiler", "command-line-utilities"]
description = "A brainfuck compiler which compiles to raw wasm"
name = "brainfk-rs"
license = "MIT"
version = "0.1.0"
repository = "https://github.com/crazystylus/brainfk-rs.git"
edition = "2021"

[dependencies]
clap = { version = "3.2.2", features = ["derive"] }
wasm-encoder = "0.13"
wasmparser = "0.86.0"
7 changes: 7 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2021 crazystylus

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Brainfk -> WASM
## Introduction
This repo contains a brainfk compiler written in Rust which compiles code directly to wasm. Later the generated wasm file can be ran using wasmer.
### Install Wasmer Runtime
Follow this link to install wasmer-runtime
https://docs.wasmer.io/ecosystem/wasmer/getting-started

### Example
```shell
$ cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
Running `target/debug/brainfk-rs`
error: The following required arguments were not provided:
--target <TARGET>
<INPUT_FILE>
<OUTPUT_FILE>

USAGE:
brainfk-rs --target <TARGET> <INPUT_FILE> <OUTPUT_FILE>

For more information try --help

$ cargo run -- tests/files/hello.f hello.wasm --target wasi
Compiling brainfk-rs v0.1.0 (/root/Documents/brainfk-rs)
Finished dev [unoptimized + debuginfo] target(s) in 0.91s
Running `target/debug/brainfk-rs tests/files/hello.f abc.wasm --target wasi`

$ wasmer run hello.wasm
Hello World!
```
### Support
- [X] WASI (It uses STDIN and STDOUT)
- [ ] Browser

### TODO
- [ ] Memory access validation and growth
- [ ] Add support for JS/Browser
- [ ] Integrate with wasmer and support run & compile
- [ ] Add testing
Loading

0 comments on commit f72fc66

Please sign in to comment.