Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/llvm-hs/llvm-hs-kaleidoscope
Kaleidoscope Tutorial using llvm-hs
https://github.com/llvm-hs/llvm-hs-kaleidoscope
haskell haskell-tutorial jit kaleidoscope llvm-hs
Last synced: about 1 month ago
JSON representation
Kaleidoscope Tutorial using llvm-hs
- Host: GitHub
- URL: https://github.com/llvm-hs/llvm-hs-kaleidoscope
- Owner: llvm-hs
- License: mit
- Created: 2017-01-20T09:31:38.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2021-05-20T11:07:05.000Z (over 3 years ago)
- Last Synced: 2023-08-21T19:57:53.113Z (over 1 year ago)
- Topics: haskell, haskell-tutorial, jit, kaleidoscope, llvm-hs
- Language: Haskell
- Homepage:
- Size: 34.2 KB
- Stars: 75
- Watchers: 15
- Forks: 16
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
llvm-tutorial-standalone
------------------------[![Build Status](https://travis-ci.org/llvm-hs/llvm-hs-kaleidoscope.svg)](https://travis-ci.org/llvm-hs/llvm-hs-kaleidoscope)
[![MIT License](http://img.shields.io/badge/license-mit-blue.svg)](https://github.com/sdiehl/llvm-tutorial-standalone/blob/master/LICENSE)A minimal LLVM builder. Basically the same code as the [Haskell Kaleidoscope
tutorial](http://www.stephendiehl.com/llvm/) uses but without going through a
frontend AST.If you want to roll a custom LLVM compiler backend this might be a good starting
point for the backend.Install
-------Check that your installed LLVM version is precisely 9.0.
```bash
$ llvm-config --version
9.0
```To build using stack:
```bash
$ stack build
$ stack exec main
```To build using cabal:
```bash
$ cabal new-build
```To run:
```bash
$ stack run
$ cabal run
Preprocessing executable 'standalone' for tutorial-0.2.0.0...
; ModuleID = 'my cool jit'define double @main() {
entry:
ret double 3.000000e+01
}Evaluated to: 30.0
```Usage
-----Code is split across
* [Codegen](https://github.com/llvm-hs/llvm-hs-kaleidoscope/blob/master/src/Codegen.hs)
* [JIT](https://github.com/llvm-hs/llvm-hs-kaleidoscope/blob/master/src/JIT.hs)
* [Main](https://github.com/llvm-hs/llvm-hs-kaleidoscope/blob/master/src/Main.hs)The main program will use the embedded LLVM Monad to define a small program
which will add two constants together.```haskell
initModule :: AST.Module
initModule = emptyModule "my cool jit"logic :: LLVM ()
logic = do
define double "main" [] $ \ptrToMain -> do
let a = cons $ C.Float (F.Double 10)
let b = cons $ C.Float (F.Double 20)
res <- fadd a b
ret resmain :: IO (AST.Module)
main = do
let ast = runLLVM initModule logic
runJIT ast
return ast
```This will generate and JIT compile into the following IR and use the LLVM
execution engine to JIT it to machine code.```llvm
; ModuleID = 'my cool jit'define double @main() {
entry:
%1 = fadd double 1.000000e+01, 2.000000e+01
ret double %1
}
```