X-Git-Url: https://git.lukelau.me/?p=kaleidoscope-hs.git;a=blobdiff_plain;f=Utils.hs;h=cd325a40b3c3c296549e0ea11ad9947b1c9d53a4;hp=2a83c3591276ea116a969301fd4f24ae772af949;hb=HEAD;hpb=38600a47841e2c5837b5693b32c35d2093864458 diff --git a/Utils.hs b/Utils.hs index 2a83c35..cd325a4 100644 --- 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