X-Git-Url: https://git.lukelau.me/?p=kaleidoscope-hs.git;a=blobdiff_plain;f=Utils.hs;fp=Utils.hs;h=3bd3b37e01e54274cf4841b52e18d8d4b2cea97e;hp=2a83c3591276ea116a969301fd4f24ae772af949;hb=e23b23071fc89fc8b73eee61cc06728c93375161;hpb=bdb5ef3da162c9a093c61d48d5deec8262943047 diff --git a/Utils.hs b/Utils.hs index 2a83c35..3bd3b37 100644 --- a/Utils.hs +++ b/Utils.hs @@ -4,11 +4,18 @@ 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 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 } + mostRecentDef :: Monad m => ModuleBuilderT m Definition mostRecentDef = last . getSnocList . builderDefs <$> liftModuleState get