Skip to content

aherrmann/simply_llvm

Repository files navigation

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 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:

$ nix-shell

Usage

Once the environment is set up you can enter an interactive GHCi session with either:

$ cabal repl
$ stack repl

and start exploring the code:

λ> 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:

λ> :load Example.hs
λ> ex5

Example programs in the language Simply are provided in simply_examples. You can compile and run them as follows:

$ cabal run simply simply_examples/factorial.simply factorial
$ ./factorial
$ ./factorial 5

You should have a look at the slides to get an overview over the code.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published