--------------------------------------------------------------------------------
-- Working with Core

-- | Get the core AST of a Haskell file.
getCoreAst :: FilePath -> IO CoreModule
getCoreAst fp = do
  defaultErrorHandler defaultLogAction $ do
    runGhc (Just libdir) $ do
      dflags <- getSessionDynFlags
      let dflags' = foldl xopt_set dflags [Opt_Cpp,Opt_ImplicitPrelude,Opt_MagicHash]
      setSessionDynFlags dflags' { optLevel = 2 }
      cm <- compileToCoreSimplified fp
      return cm

--------------------------------------------------------------------------------
-- Printing

-- | Beautify the given JS.
getCoreAst :: FilePath -> IO CoreModule
getCoreAst fp = do
  defaultErrorHandler defaultLogAction $ do
    runGhc (Just libdir) $ do
      dflags <- getSessionDynFlags
      let dflags' = foldl xopt_set dflags [Opt_Cpp,Opt_ImplicitPrelude,Opt_MagicHash]
      setSessionDynFlags dflags' { optLevel = 2 }
      cm <- compileToCoreSimplified fp
      return cm

--------------------------------------------------------------------------------
-- Printing

-- | Beautify the given JS.
getCoreAst fp = do
  defaultErrorHandler defaultLogAction $ do
    runGhc (Just libdir) $ do
      dflags <- getSessionDynFlags
      let dflags' = foldl xopt_set dflags [Opt_Cpp,Opt_ImplicitPrelude,Opt_MagicHash]
      setSessionDynFlags dflags' { optLevel = 2 }
      cm <- compileToCoreSimplified fp
      return cm

--------------------------------------------------------------------------------
-- Printing

-- | Beautify the given JS.