bscarlet / llvm-general

Rich LLVM bindings for Haskell (with transfer of LLVM IR to and from C++, detailed compilation pass control, etc.)
http://hackage.haskell.org/package/llvm-general
132 stars 38 forks source link

Support pretty-printing to LLVM assembly #204

Closed tibbe closed 7 years ago

tibbe commented 7 years ago

I frequently find myself wanting myself to print the LLVM AST in the human-readable LLVM assembly format. It is possible to pretty-print the AST in a Haskell source code format, and that's sometimes useful, but it would be easier to debug errors such as:

Assertion failed: (isValidElementType(EltTy) && "Invalid type for pointer element!"), function get, file /private/tmp/llvm@3.8-20170130-27399-1g3iurp/llvm-3.8.1.src/lib/IR/Type.cpp, line 684.

If you could pretty-print the LLVM assembly and tinker with it.

tibbe commented 7 years ago

An example of how this helps. The above error message is

llc-3.8: /tmp/test.ll:1:12: error: pointers to void are invalid - use i8* instead
define void* @id(void *x) {
           ^

if you run llc with the corresponding LLVM assembly. This is a considerably better error message for debugging.

cocreature commented 7 years ago

@tibbe Are you looking for something like withModuleFromAST ctx mod moduleLLVMAssembly? Otherwise, I don’t understand what you are asking for.

cocreature commented 7 years ago

I just realized you are probably looking for a way to pretty-print without lowering because lowering is the part causing the error. In that case https://github.com/sdiehl/llvm-pp might be what you are looking for.

tibbe commented 7 years ago

llvm-pp was what I was looking for. Thanks!