Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
bos committed May 17, 2012
2 parents 1a8be89 + 75a831b commit bc6be8f
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions LLVM/Core/CodeGen.hs
Expand Up @@ -449,25 +449,35 @@ createStringNul s =
let (cstr, n) = U.constStringNul s
in string n cstr

withString ::
String ->
(forall n. (Nat n) => Global (Array n Word8) -> CodeGenModule a) ->
CodeGenModule a
withString s act =
let (cstr, n) = U.constString s
in reifyIntegral n (\tn ->
do arr <- string n cstr
act (fixArraySize tn arr))

withStringNul ::
String ->
(forall n. (Nat n) => Global (Array n Word8) -> CodeGenModule a) ->
CodeGenModule a
withStringNul s act =
let (cstr, n) = U.constStringNul s
in reifyIntegral n (\tn ->
do arr <- string n cstr
act (fixArraySize tn arr))
class WithString a where
withString :: String -> (forall n . Nat n => Global (Array n Word8) -> a) -> a
withStringNul :: String -> (forall n . Nat n => Global (Array n Word8) -> a) -> a

instance WithString (CodeGenModule a) where
withString s act =
let (cstr, n) = U.constString s
in reifyIntegral n (\tn ->
do arr <- string n cstr
act (fixArraySize tn arr))

withStringNul s act =
let (cstr, n) = U.constStringNul s
in reifyIntegral n (\tn ->
do arr <- string n cstr
act (fixArraySize tn arr))

instance WithString (CodeGenFunction r b) where
withString s act =
let (cstr, n) = U.constString s
in reifyIntegral n (\tn ->
do arr <- liftCodeGenModule $ string n cstr
act (fixArraySize tn arr))

withStringNul s act =
let (cstr, n) = U.constStringNul s
in reifyIntegral n (\tn ->
do arr <- liftCodeGenModule $ string n cstr
act (fixArraySize tn arr))

fixArraySize :: n -> Global (Array n a) -> Global (Array n a)
fixArraySize _ = id
Expand Down

0 comments on commit bc6be8f

Please sign in to comment.