Find our JIT'ed function and run it
[kaleidoscope-hs.git] / Utils.hs
index 3bd3b37e01e54274cf4841b52e18d8d4b2cea97e..cd325a40b3c3c296549e0ea11ad9947b1c9d53a4 100644 (file)
--- a/Utils.hs
+++ b/Utils.hs
@@ -6,6 +6,7 @@ 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
@@ -16,6 +17,13 @@ moduleSoFar nm = do
   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