Find our JIT'ed function and run it
[kaleidoscope-hs.git] / Utils.hs
index 2a83c3591276ea116a969301fd4f24ae772af949..cd325a40b3c3c296549e0ea11ad9947b1c9d53a4 100644 (file)
--- a/Utils.hs
+++ b/Utils.hs
@@ -4,11 +4,26 @@ Shoving away gross stuff into this one module.
 module Utils where
 
 import Control.Monad.Trans.State
+import Data.ByteString.Short (ShortByteString)
 import Data.Functor.Identity
+import Data.List
 import LLVM.AST
 import LLVM.IRBuilder.Module
 import LLVM.IRBuilder.Internal.SnocList
 
+moduleSoFar :: MonadModuleBuilder m => ShortByteString -> m Module
+moduleSoFar nm = do
+  s <- liftModuleState get
+  let ds = getSnocList (builderDefs s)
+  return $ defaultModule { moduleName = nm, moduleDefinitions = ds }
+
+removeDef :: MonadModuleBuilder m => Definition -> m ()
+removeDef def = liftModuleState (modify update)
+  where
+    update (ModuleBuilderState defs typeDefs) =
+      let newDefs = SnocList (delete def (getSnocList defs))
+      in ModuleBuilderState newDefs typeDefs
+
 mostRecentDef :: Monad m => ModuleBuilderT m Definition
 mostRecentDef = last . getSnocList . builderDefs <$> liftModuleState get