[project @ 2001-01-13 20:33:51 by qrczak]
[ghc-hetmet.git] / ghc / utils / hsc2hs / template-hsc.h
1 #if __GLASGOW_HASKELL__ && __GLASGOW_HASKELL__ < 409
2 #include <Rts.h>
3 #endif
4 #include <HsFFI.h>
5
6 #include <stddef.h>
7 #include <string.h>
8 #include <stdio.h>
9
10 #ifndef offsetof
11 #define offsetof(t, f) ((size_t) &((t *)0)->f)
12 #endif
13
14 #if __NHC__
15 #define hsc_line(line, file) \
16     printf ("# %d \"%s\"\n", line, file);
17 #else
18 #define hsc_line(line, file) \
19     printf ("{-# LINE %d \"%s\" #-}\n", line, file);
20 #endif
21
22 #define hsc_const(x)                        \
23     if ((x) < 0)                            \
24         printf ("%ld", (long)(x));          \
25     else                                    \
26         printf ("%lu", (unsigned long)(x));
27
28 #define hsc_const_str(x)                                          \
29     {                                                             \
30         const char *s = (x);                                      \
31         printf ("\"");                                            \
32         while (*s != '\0')                                        \
33         {                                                         \
34             if (*s == '"' || *s == '\\')                          \
35                 printf ("\\%c", *s);                              \
36             else if (*s >= 0x20 && *s <= 0x7E)                    \
37                 printf ("%c", *s);                                \
38             else                                                  \
39                 printf ("\\%d%s",                                 \
40                         (unsigned char) *s,                       \
41                         s[1] >= '0' && s[1] <= '9' ? "\\&" : ""); \
42             s++;                                                  \
43         }                                                         \
44         printf ("\"");                                            \
45     }
46
47 #define hsc_type(t)                                         \
48     if ((t)(int)(t)1.4 == (t)1.4)                           \
49         printf ("%s%d",                                     \
50                 (t)(-1) < (t)0 ? "Int" : "Word",            \
51                 sizeof (t) * 8);                            \
52     else                                                    \
53         printf ("%s",                                       \
54                 sizeof (t) >  sizeof (double) ? "LDouble" : \
55                 sizeof (t) == sizeof (double) ? "Double"  : \
56                 "Float");
57
58 #define hsc_peek(t, f) \
59     printf ("(\\hsc_ptr -> peekByteOff hsc_ptr %ld)", (long) offsetof (t, f));
60
61 #define hsc_poke(t, f) \
62     printf ("(\\hsc_ptr -> pokeByteOff hsc_ptr %ld)", (long) offsetof (t, f));
63
64 #define hsc_ptr(t, f) \
65     printf ("(\\hsc_ptr -> hsc_ptr `plusPtr` %ld)", (long) offsetof (t, f));
66