Skip to content

Commit

Permalink
Switch default backend to pretty printer
Browse files Browse the repository at this point in the history
Version 7 of llvm-hs crashed with this exception while the pretty printer worked
fine. This needs investigation but till then an alternative backend is good to
have.

```
olifant: EncodeException "Duplicate definition of local variable: Name \"_\"."
```
  • Loading branch information
jaseemabid committed Oct 13, 2018
1 parent 00ddf39 commit 90f8d00
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Olifant.cabal
Expand Up @@ -24,6 +24,7 @@ library
, bytestring
, containers
, llvm-hs
, llvm-hs-pretty
, llvm-hs-pure
, megaparsec
, mtl
Expand Down Expand Up @@ -59,6 +60,7 @@ test-suite Olifant-test
, base
, bytestring
, llvm-hs
, llvm-hs-pretty
, llvm-hs-pure
, megaparsec
, parsec
Expand Down
7 changes: 6 additions & 1 deletion src/Olifant/Gen.hs
Expand Up @@ -40,6 +40,7 @@ import LLVM.AST.Type
import LLVM.Context (withContext)
import LLVM.Module (moduleLLVMAssembly, withModuleFromAST)
import LLVM.PassManager
import LLVM.Pretty

-- | State of the complete program
data GenState = GenState
Expand Down Expand Up @@ -299,6 +300,10 @@ genm prog = execM (run prog) genState >>= return . mod
passes :: PassSetSpec
passes = defaultCuratedPassSetSpec {optLevel = Just 0}

-- | Generate native code with pretty printer
toLLVMPP :: Module -> IO Text
toLLVMPP modl = return $ toS $ ppllvm $ modl

-- | Generate native code with C++ FFI
toLLVM :: Module -> IO Text
toLLVM modl =
Expand All @@ -315,7 +320,7 @@ gen :: [Core] -> IO (Either Error Text)
gen ast =
case genm ast of
Left e -> return $ Left e
Right mod' -> toLLVM mod' >>= return . Right
Right mod' -> toLLVMPP mod' >>= return . Right

err :: Text -> Codegen a
err = throwError . GenError

0 comments on commit 90f8d00

Please sign in to comment.