Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/deathlesz/brainfuck
Brainfuck parser, interpreter, JIT compiler and LLVM frontend all-in-one.
https://github.com/deathlesz/brainfuck
brainfuck compiler interpreter jit llvm
Last synced: about 2 months ago
JSON representation
Brainfuck parser, interpreter, JIT compiler and LLVM frontend all-in-one.
- Host: GitHub
- URL: https://github.com/deathlesz/brainfuck
- Owner: deathlesz
- License: apache-2.0
- Created: 2024-10-15T22:57:52.000Z (4 months ago)
- Default Branch: master
- Last Pushed: 2024-11-06T20:05:44.000Z (3 months ago)
- Last Synced: 2024-11-06T21:19:47.264Z (3 months ago)
- Topics: brainfuck, compiler, interpreter, jit, llvm
- Language: Rust
- Homepage:
- Size: 94.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# Brainfuck
An optimizing interpreter, JIT compiler and LLVM frontend all-in-one for [Brainfuck](https://brainfuck.org/brainfuck.html).
## InstallationI hate GitHub Actions, so you can only build it yourself. ¯\\\_(ツ)_/¯
### Building
- Clone this repository using `git`:
```sh
$ git clone https://github.com/deathlesz/brainfuck.git
```
- Build it using `cargo` in either debug or release mode
```sh
# For release mode
$ cargo build --release # to build all subprojects (interpreter, jit, llvm)
$ cargo build -p [project_name] --release # build specific subproject
# For debug mode, remove --release
```
- The compiled binary should be in `./target/release` or `./target/debug`.
- Alternatively, you can run the binary using `cargo run` with the same arguments as `cargo build`
## UsageAll subprojects except for parser are CLIs. `Interpreter` and `JIT` binaries have the same interface.
### `Interpreter/JIT`
```
Runs brainfuck using interpreter/JIT compiler.Usage: interpreter [SOURCE]
Arguments:
[SOURCE] Path to file with source codeOptions:
-h, --help Print help
-V, --version Print version
```
For example, `./interpreter src.b`.
### `LLVM`
```
Compiles brainfuck into object files/LLVM IR.Usage: llvm [OPTIONS] [SOURCE]
Arguments:
[SOURCE]
Path to file with source codeOptions:
-o, --output
Path to output file-t, --target
Target to compile for (e.g. x86_64-pc-linux-gnu)-f, --features
Features to enable (e.g. +sse2,+cx16,+sahf,-tbm). You can use 'native' to enable all features that current machine supports-r, --run
Use JIT compiler and run program-e, --emit
[default: object]Possible values:
- object: Emit object file
- llvm-ir: Emit generated LLVM IR
- assembly: Emit generated assembly-s, --safe
Enable bounds check on >/<. Can be really slow-O
Enable optimization passes-h, --help
Print help (see a summary with '-h')-V, --version
Print version
```
For example, `./llvm src.b`, `./llvm src.b -o out.o`, `./llvm src.b -e llvm-ir -o out.ll`, etc.
### Live mode
`Interpreter`, `JIT` and `LLVM` subprojects all have live mode. You can use it by running the binary without `SOURCE`. You'll be prompted with the following:
```
! Live mode. Press ^D to finish
```
You can enter any brainfuck code and then press Ctrl+D to interpret/compile it. You can also pipe files into live mode, e.g.
```sh
$ echo "+++++[->++++++++++<]>." | ./llvm -o out.ll -e llvm-ir -O
```
## Acknowledgements
- [Brainfuck archive](https://sange.fi/esoteric/brainfuck) by Jeff Johnston and Panu Kalliokoski
- [Some brainfuck fluff](https://brainfuck.org) by Daniel Cristofani
- And many other resources <3
## LicenseThis project is distributed under the terms of both the MIT license and the Apache License (Version 2.0).
See [LICENSE-APACHE](LICENSE-APACHE) and [LICENSE-MIT](LICENSE-MIT) for details.