Skip to content

zitkat/kaleidoscope

 
 

Repository files navigation

A short guide to building a tiny programming language in Haskell with LLVM.

Stephen Diehl

updated by Tomáš Zítka

Haskell LLVM Tutorial

MIT License LLVM License

Read original materials by Stephen online:

Setup

You will need GHC 8.10 or newer as well as LLVM 9.0. For information on installing LLVM 9.0 on your platform of choice, take a look at the instructions posted by the llvm-hs maintainers.

With Haskell and LLVM in place, you can use Stack to install the necessary Haskell bindings and compile the source code from each chapter.

Building with Stack (Recommended)

$ stack build

You can then run the source code from each chapter (starting with chapter 2) as follows:

$ stack exec chapter2

or even load the chapter into GHCi repl

$ stack ghci kaleidoscope:exe:chapter2

Building with make

The source code for the example compiler of each chapter is included in the /src folder. With the dependencies installed globally, these can be built using the Makefile at the root level:

$ make chapter2
$ make chapter6

then

$ ./chapter6.exe

to run the REPL.

A smaller version of the code without the parser frontend can be found in the llvm-tutorial-standalone repository. The LLVM code generation technique is identical to chapter 6.

Editing

This is an open source project, patches and corrections always welcome.

The tutorial text in tutorial.md can be rendered using pandoc, use

$ cabal install pandoc

To generate the HTML page:

$ make tutorial.html

A standalone PDF can also be generated with:

$ make tutorial.pdf

License

Text is adapted from the LLVM tutorial and is subsequently licensed under the LLVM license.

The Haskell source files are released under the MIT license. Copyright (c) 2013-2020, Stephen Diehl, 2023 Tomáš Zítka

About

Haskell LLVM JIT Compiler Tutorial

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE-LLVM
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Haskell 94.4%
  • CSS 2.7%
  • Makefile 1.4%
  • C 1.1%
  • Other 0.4%