Skip to content
Browse files

Add unsafeGetElementPtr

  • Loading branch information...
1 parent b2d829a commit b7a95a6b83528478e09817bff5dc62965765fef6 @NathanHowell NathanHowell committed with NathanHowell
Showing with 16 additions and 1 deletion.
  1. +16 −1 LLVM/Core/Instructions.hs
View
17 LLVM/Core/Instructions.hs
@@ -34,7 +34,7 @@ module LLVM.Core.Instructions(
free,
load,
store,
- getElementPtr, getElementPtr0,
+ getElementPtr, getElementPtr0, unsafeGetElementPtr,
-- * Conversions
trunc, zext, sext,
fptrunc, fpext,
@@ -1158,6 +1158,21 @@ getElementPtr0 :: (GetElementPtr o i n) =>
Value (Ptr o) -> i -> CodeGenFunction r (Value (Ptr n))
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

0 comments on commit b7a95a6

Please sign in to comment.
Something went wrong with that request. Please try again.