Begin codegen
authorLuke Lau <luke_lau@icloud.com>
Sat, 18 May 2019 21:52:15 +0000 (22:52 +0100)
committerLuke Lau <luke_lau@icloud.com>
Sun, 19 May 2019 13:17:16 +0000 (14:17 +0100)
commit38600a47841e2c5837b5693b32c35d2093864458
treeaaadae83b84e3dafb5afc3b6f997b1baa48c589f
parent3ccccc6ab809fb87dd929855936895fb11479e27
Begin codegen

Now the fun begins.
You should start by installing the llvm-hs packages. This tutorial will
be keeping things "vanilla" by just installing the packages globally
rather than using a .cabal file.

$ cabal new-install --lib llvm-hs llvm-hs-pure llvm-hs-pretty --write-ghc-environment-files=always

The above command should be enough to install them, assuming you already
have LLVM installed correctly. (At the time of writing llvm-hs-pretty
needs to be installed from source for llvm-8.0:
https://github.com/llvm-hs/llvm-hs-pretty)

Like our parsing, our code generation is also monadic (this is a Haskell
tutorial). There are two monads that we can use: IRBuilder and
ModuleBuilder. The former is for LLVM IR instructions and the latter for
function definitions, constants and the like.

The original tutorial puts everything into one module, so we are going
to follow suit here. This makes things a bit hairy since now the repl
needs to take place inside of a ModuleBuilderT IO. In an effort to keep
our code as pure as possible, we've added a hoist function so that we
can keep our codegen code inside ModuleBuilder.

There's also a helper function to grab the most recent definition so
that we can print out similar to in the tutorial. This and hoist have
been tucked away into Util.hs.

So far we only generate code for numbers: But this now paves the way for
the rest of the code generation.
AST.hs
Main.hs
Utils.hs [new file with mode: 0644]