> Well, I was working on the various pprMachOp's. In the old PprAbsC we
> can generate casts like "(void *)", because we could 
> distinguish NatP's.
> For example, in the old ppr we have:
> 
>         pprMachOp_for_C MO_NatU_to_NatP  = text "(void*)"
> 
> But now there seems to be no easy way to know when the 
> MachRep is really
> a pointer. Here is the casting machop:
> 
>         -- Conversions.  Some of these will be NOPs.
>         -- Floating-point conversions use the signed variant.
>         | MO_S_Conv MachRep{-from-} MachRep{-to-}     -- 
> signed conversion
>         | MO_U_Conv MachRep{-from-} MachRep{-to-}     -- 
> unsigned conversion
> 
> So at the moment I'm assuming the C backend isn't going to 
> generate any void*
> casts. But I'm not certain this is the case.

I hope you'll never need to know whether a value is a pointer or not.
This is one of the base assumptions in Cmm: we don't have separate
MachReps for pointers and non-pointers.

In order to generate correct C, you might have to cast things to pointer
types occasionally, such as just before dereferencing something, but
hopefully the context will tell you when this is necessary.  For
example, if you have an assignment

   R1 = Sp[3]

in Cmm this looks like (assuming wordRep == I32):

  CmmAssign (CmmReg (GlobalReg r1)) 
            (CmmLoad (CmmRegOff (GlobalReg sp) 12) I32)

so you could generate the following C:

   R1 = *(StgWord32 *)((StgWord32)Sp + 12);

or you could use more knowledge about the type of Sp in C: it has type
StgPtr, which is (StgWord *), and StgWord32 is the same as StgWord on
32-bit arch's:

   R1 = *(Sp + 3);

better still, we can emit this using C's array syntax:

   R1 = Sp[3];

Cheers,
        Simon
_______________________________________________
Cvs-ghc mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/cvs-ghc

Reply via email to