https://github.com/llvm-hs/llvm-hs-tutor
A Haskell version of the llvm-tutor project using llvm-hs
https://github.com/llvm-hs/llvm-hs-tutor
Last synced: 4 months ago
JSON representation
A Haskell version of the llvm-tutor project using llvm-hs
- Host: GitHub
- URL: https://github.com/llvm-hs/llvm-hs-tutor
- Owner: llvm-hs
- License: bsd-3-clause
- Created: 2021-05-20T13:26:21.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-09-03T09:46:53.000Z (almost 4 years ago)
- Last Synced: 2025-01-13T08:31:38.403Z (5 months ago)
- Language: Haskell
- Size: 9.77 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# llvm-hs-tutor
A Haskell version of the
[llvm-tutor](https://github.com/banach-space/llvm-tutor) project using
[llvm-hs](https://github.com/llvm-hs), the Haskell LLVM bindings.## Overview
Working directly with LLVM in C++ is tedious, unsafe, and highly error-prone.
It is possible to write code that behaves like an out-of-source LLVM pass
directly in Haskell.The goal of this project is to showcase that LLVM can in fact be easy and fun to
work with. This is demonstrated through a collection of self-contained testable
passes which are implemented using idiomatic Haskell.## HelloWorld: Your First Haskell Pass
The HelloWorld pass in `app/HelloWorld.hs` demonstrates the basics of working
with LLVM from Haskell.### Development Environment
If you are using your system-wide installed version of LLVM, you should not
need to do any special setup. You can build the example passes by saying```
stack build
```If you have built LLVM from source, then you will need to tell stack where to
look for the LLVM tools (such as the `llvm-config` utility), and shared
libraries. The simplest way to do this is to prefix your stack commands like
so:```
LD_LIBRARY_PATH=$(realpath ../llvm-12.0.0-root/lib) PATH=$(realpath ../llvm-12.0.0-root/bin):$PATH stack build
```Before you can test the HelloWorld pass, you need to prepare an input file:
```
clang -S -emit-llvm inputs/input_for_hello.c -o input_for_hello.ll
```Run `HelloWorld` with stack like so:
```
stack exec -- helloworld input_for_hello.ll
Hello from: Name "foo"
number of arguments: 1
Hello from: Name "bar"
number of arguments: 2
Hello from: Name "fez"
number of arguments: 3
Hello from: Name "main"
number of arguments: 2
```