module LLVM.Extra.MemoryPrivate where

import qualified LLVM.Core as LLVM
import LLVM.Core (CodeGenFunction, Value, )

import Foreign.Ptr (Ptr, )


decomposeFromLoad ::
   LLVM.IsSized struct =>
   (Value (Ptr struct) -> CodeGenFunction r a) ->
   Value struct -> CodeGenFunction r a
decomposeFromLoad loadStruct struct = do
   ptr <- LLVM.alloca
   LLVM.store struct ptr
   loadStruct ptr

composeFromStore ::
   LLVM.IsSized struct =>
   (a -> Value (Ptr struct) -> CodeGenFunction r ()) ->
   a -> CodeGenFunction r (Value struct)
composeFromStore storeStruct x = do
   ptr <- LLVM.alloca
   storeStruct x ptr
   LLVM.load ptr
