[jhc] [BUG] Poke should use volatile.
john at repetae.net
Wed Mar 6 14:06:58 CET 2013
What do you mean by raw memory? I don't think the volatile should be
needed in general for C allocated variables, but perhaps you are
writing to hardware registers?
On Fri, Feb 22, 2013 at 5:11 AM, Kiwamu Okabe <kiwamu at gmail.com> wrote:
> I think poke function should use volatile on C language side.
> If not, the code created with jhc cannot write raw memory.
> diff --git a/src/C/FromGrin2.hs b/src/C/FromGrin2.hs
> index 46e1a08..d4508bd 100644
> --- a/src/C/FromGrin2.hs
> +++ b/src/C/FromGrin2.hs
> @@ -712,7 +712,7 @@ convertPrim p vs ty
> | (Poke t) <- p, [v,x] <- vs = do
> v' <- convertVal v
> x' <- convertVal x
> - return $ expressionRaw ("*((" <> (opTyToC' t) <+> "*)" <>
> (parens $ renderG v') <> text ") = " <> renderG x')
> + return $ expressionRaw ("*((volatile " <> (opTyToC' t) <+>
> "*)" <> (parens $ renderG v') <> text ") = " <> renderG x')
> | (AddrOf _ t) <- p,  <- vs = do
> rt <- convertTypes ty
> return . cast rt $ expressionRaw ('&':unpackPS t)
> I found it when use jhc to program Cortex-M3.
> Kiwamu Okabe
> jhc mailing list
> jhc at haskell.org
More information about the jhc