Skip to content

Commit

Permalink
Add unsafeGetElementPtr
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanHowell committed Jan 17, 2012
1 parent b2d829a commit b7a95a6
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion LLVM/Core/Instructions.hs
Expand Up @@ -34,7 +34,7 @@ module LLVM.Core.Instructions(
free, free,
load, load,
store, store,
getElementPtr, getElementPtr0, getElementPtr, getElementPtr0, unsafeGetElementPtr,
-- * Conversions -- * Conversions
trunc, zext, sext, trunc, zext, sext,
fptrunc, fpext, fptrunc, fpext,
Expand Down Expand Up @@ -1158,6 +1158,21 @@ getElementPtr0 :: (GetElementPtr o i n) =>
Value (Ptr o) -> i -> CodeGenFunction r (Value (Ptr n)) Value (Ptr o) -> i -> CodeGenFunction r (Value (Ptr n))
getElementPtr0 p i = getElementPtr p (0::Word32, i) getElementPtr0 p i = getElementPtr p (0::Word32, i)


-- | Call getelementptr directly with a list of indexes.
-- This is should be used only if the runtime type is not yet known.
-- If the indexes and return type are incorrect this function may segfault
-- in LLVMBuildGEP, or assert if debug assertions are enabled.
unsafeGetElementPtr :: forall o i n r . IsIndexArg i =>
Value (Ptr o) -> [i] -> CodeGenFunction r (Value (Ptr n))
unsafeGetElementPtr (Value ptr) i =
let ixl = map getArg i in
liftM Value $
withCurrentBuilder $ \ bldPtr ->
U.withArrayLen ixl $ \ idxLen idxPtr ->
U.withEmptyCString $
FFI.buildGEP bldPtr ptr idxPtr (fromIntegral idxLen)


-------------------------------------- --------------------------------------
{- {-
instance (IsConst a) => Show (ConstValue a) -- XXX instance (IsConst a) => Show (ConstValue a) -- XXX
Expand Down

0 comments on commit b7a95a6

Please sign in to comment.