Begin codegen
[kaleidoscope-hs.git] / Utils.hs
1 {-|
2 Shoving away gross stuff into this one module.
3 -}
4 module Utils where
5
6 import Control.Monad.Trans.State
7 import Data.Functor.Identity
8 import LLVM.AST
9 import LLVM.IRBuilder.Module
10 import LLVM.IRBuilder.Internal.SnocList
11
12 mostRecentDef :: Monad m => ModuleBuilderT m Definition
13 mostRecentDef = last . getSnocList . builderDefs <$> liftModuleState get
14
15 hoist :: Monad m => ModuleBuilder a -> ModuleBuilderT m a
16 hoist m = ModuleBuilderT $ StateT $
17   return . runIdentity . runStateT (unModuleBuilderT m)