https://github.com/romch007/floc
Compiler for the Flo programming language
https://github.com/romch007/floc
compiler llvm rust
Last synced: 8 months ago
JSON representation
Compiler for the Flo programming language
- Host: GitHub
- URL: https://github.com/romch007/floc
- Owner: romch007
- License: mit
- Created: 2024-05-30T12:07:28.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-06-06T14:24:36.000Z (10 months ago)
- Last Synced: 2025-06-06T15:29:23.242Z (10 months ago)
- Topics: compiler, llvm, rust
- Language: Rust
- Homepage:
- Size: 271 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# floc
Compiler for the Flo programming language.
## The Flo programming language
The Flo programming language is an imperative and statically-typed language designed by [Florian Bridoux](https://webusers.i3s.unice.fr/~bridoux/) as part of the "Langages, Compilation et Automates" course at Polytech Nice Sophia. The final project of this course involves creating a compiler (in Python or C) that compiles Flo code to ARMv7. The code generation part of this project is rather simple and the compiled programs are unoptimized. I took the initiative to recreate the compiler in Rust, using LLVM to enable excellent run-time performance of programs and availability on a wide range of systems and architectures.
## How to build
What you need:
- Rust (at least 1.85.0)
- A C++ compiler
- LLVM 18.1
- libclang (usually included with clang)
### Building and running:
```bash
$ cargo build --release
```
(if you are building on Alpine Linux you need to run `RUSTFLAGS="-C target-feature=-crt-static" cargo b -r`)
```bash
$ target/release/floc[.exe] flo_examples/factorial.flo
```
Note: On Windows, make sure `link.exe` is available by installing Visual Studio with the "Desktop development with C++" workload.
### AUR
There is an AUR package called [floc-git](https://aur.archlinux.org/packages/floc-git) btw.
## Usage
Some cool stuff to do:
- Render the AST as a dot graph:
```bash
$ floc --emit-ast-as-dot flo_examples/prime.flo | dot -Tsvg > ast.svg
```
- Dump the generated LLVM IR:
```bash
$ floc --emit-ir flo_examples/prime.flo
```
- Dump the generated LLVM IR after optimization passes:
```bash
$ floc --emit-optimized-ir flo_examples/prime.flo
```
(use `--help` to get all available options)
## How to code in Flo
[Link to the reference](FLO_REFERENCE.md)
See some example programs [here](https://github.com/romch007/floc/tree/main/flo_examples)