llvm-hs-pretty alternatives and similar packages
Based on the "Compiler" category.
Alternatively, view llvm-hs-pretty alternatives based on common mentions on social networks and blogs.
-
binaryen
DEPRECATED in favor of ghc wasm backend, see https://www.tweag.io/blog/2022-11-22-wasm-backend-merged-in-ghc -
accelerate
Embedded language for high-performance array computations -
pi-forall
A demo implementation of a simple dependently-typed language -
hyper-haskell-server
The strongly hyped Haskell interpreter. -
husk-scheme
A full implementation of the Scheme programming language for the Haskell Platform. -
hint
Runtime Haskell interpreter [Moved to: https://github.com/haskell-hint/hint] -
bound
Combinators for manipulating locally-nameless generalized de Bruijn terms -
accelerate-examples
Examples for the Accelerate language -
accelerate-cuda
DEPRECATED: Accelerate backend for NVIDIA GPUs -
lambdacube-compiler
LambdaCube 3D is a Haskell-like purely functional language for GPU. Try it out: -
CPL
An interpreter of Hagino's Categorical Programming Language (CPL). -
elm-street
:deciduous_tree: Crossing the road between Haskell and Elm -
haskell-to-elm
Generate Elm types, encoders, and decoders from Haskell types -
hLLVM
A library for analyzing and transforming LLVM (3.5) assembly codes -
unbound
Replib: generic programming & Unbound: generic treatment of binders -
accelerate-io
Read and write Accelerate arrays in various formats -
haskelm
Haskell to Elm translation using Template Haskell. Contains both a library and executable. -
accelerate-fft
FFT library for Haskell based on the embedded array language Accelerate -
lazyboy
An EDSL implemented in Haskell for programming the Nintendo Game Boy. -
elm-syntax
Library for generating Elm syntax from Haskell in a scope-safe way -
strict-ghc-plugin
Compiler plugin for making Haskell strict -
feldspar-compiler
This is the compiler for the Feldspar Language.
Clean code begins in your IDE with SonarLint
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of llvm-hs-pretty or a related project?
README
llvm-hs-pretty
A pretty printer for llvm-hs-pure
. Goal is to be able to pretty print a
sufficiently large subset of the LLVM AST from pure Haskell without having to go
through the C++ API.
Note: It is possible to construct llvm-hs-pure ASTs that are invalid ASTs and as such there is no meaningful way to print them. Always run the LLVM verifier on your AST to test it is sound. If you encounter incomplete pattern matches using this library you likely have constructed invalid IR.
Usage
There is a single function ppllvm
that maps a LLVM.AST.Module to a Text.
import LLVM.AST
import LLVM.Pretty (ppllvm)
ppllvm :: Module -> Text
Individual LLVM elements (constants, instructions) can be printed using the
the polymorphic ppll
function for any LLVM structure that implements the
PP
typeclass.
Tests
# This is only necessary for running the test suite
sudo apt-get install llvm-9-dev
The test suite currently consists of round tripping a LLVM IR from correct IR
outputted by the llc toolchain, parsing into llvm-hs AST and then printing it
back out and comparing it with the original textual form to see if the pretty
printer faithfully preserves the structure. The sample modules are in
tests/
.
Using stack:
$ stack build
$ stack test
Using cabal:
$ cabal run
$ cabal run -- tests/simple.ll
If you're using Nix then:
$ nix-shell
$ cabal run
Example
To try out the standalone example run:
$ stack repl
$ :load Example.hs
main
Consider the basic example LLVM module.
; ModuleID = 'example-llvm-module'
define i8 @f(i8 %x){
entry:
ret i8 %x
}
Using the LLVM.AST we construct the type and feed it to the pretty printer.
module Standalone where
-- Pretty Printer
import LLVM.Pretty (ppllvm)
-- AST
import qualified LLVM.AST as AST
import qualified LLVM.AST.Linkage as Linkage
import qualified LLVM.AST.Visibility as Visibility
import qualified LLVM.AST.CallingConvention as Convention
import Data.Text.Lazy.IO as TIO
astModule :: AST.Module
astModule = AST.Module
{ AST.moduleName = "example-llvm-module"
, AST.moduleDataLayout = Nothing
, AST.moduleTargetTriple = Nothing
, AST.moduleDefinitions =
[ AST.GlobalDefinition
(AST.Function
Linkage.External
Visibility.Default
Nothing
Convention.C
[]
(AST.IntegerType 8)
(AST.Name "f")
([AST.Parameter (AST.IntegerType 8) (AST.Name "x") []], False)
[]
Nothing
Nothing
0
Nothing
Nothing
[ AST.BasicBlock
(AST.Name "entry")
[]
(AST.Do
(AST.Ret
(Just
(AST.LocalReference
(AST.IntegerType 8)
(AST.Name "x")
)
)
[]
)
)
]
)
]
}
main :: IO ()
main = TIO.putStrLn (ppllvm astModule)
License
Released under the MIT License.
Copyright (c) 2014-2020, Stephen Diehl Copyright (c) 2015 Cedric Shock
*Note that all licence references and agreements mentioned in the llvm-hs-pretty README section above
are relevant to that project's source code only.