https://github.com/aherrmann/simply_llvm
https://github.com/aherrmann/simply_llvm
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/aherrmann/simply_llvm
- Owner: aherrmann
- License: unlicense
- Created: 2016-11-24T17:47:53.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-07-02T16:05:49.000Z (almost 9 years ago)
- Last Synced: 2025-03-23T19:04:15.260Z (about 1 year ago)
- Language: Haskell
- Size: 101 KB
- Stars: 41
- Watchers: 6
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Simply LLVM
Compiling a simple functional language with LLVM and Haskell
Example code to the presentation given at the HaskellerZ Zurich Haskell meetup.
Ported to use the [`llvm-hs`](https://github.com/llvm-hs/llvm-hs)
LLVM Haskell bindings.
## Setup
If you have the Nix package manager installed on your machine,
then you just need to execute the following command in the top-level
directory of this repository:
``` sh
$ nix-shell
```
## Usage
Once the environment is set up you can enter an interactive GHCi session with either:
``` sh
$ cabal repl
$ stack repl
```
and start exploring the code:
``` hs
λ> ex01a_factorial & Surface.prettyPrint
λ> ex01a_factorial & Simply.typeCheck' & fmap Intermediate.fromSurface >>= prettyPrint
λ> ex01a_factorial & Simply.typeCheck' & fmap Intermediate.fromSurface & fmap LLVM.fromIntermediate >>= printLLVM
λ> ex01a_factorial & Simply.typeCheck' & fmap Intermediate.fromSurface & fmap LLVM.fromIntermediate >>= printLLVMOpt optInline
λ> ex01a_factorial & Simply.typeCheck' & fmap Intermediate.fromSurface & fmap LLVM.fromIntermediate >>= printAssemblyOpt optInline
λ> ex01b_factorial & Simply.typeCheck' & fmap Intermediate.fromSurface & fmap LLVM.fromIntermediate >>= exec [5]
```
The examples can be loaded by in the interactive session with:
``` sh
λ> :load Example.hs
λ> ex5
```
Example programs in the language *Simply* are provided in [`simply_examples`](simply_examples).
You can compile and run them as follows:
``` sh
$ cabal run simply simply_examples/factorial.simply factorial
$ ./factorial
$ ./factorial 5
```
You should have a look at the [slides](slides/slides.md)
to get an overview over the code.