[project @ 2002-12-11 15:36:20 by simonmar]
[ghc-hetmet.git] / ghc / compiler / parser / hschooks.c
1 /*
2 These routines customise the error messages
3 for various bits of the RTS.  They are linked
4 in instead of the defaults.
5 */
6
7 #include <string.h>
8
9 #if __GLASGOW_HASKELL__ >= 400
10 #include "../rts/Rts.h"
11 #else
12 #include "rtsdefs.h"
13 #endif
14
15 #if __GLASGOW_HASKELL__ >= 505
16 #include "../rts/Rts.h"
17 #include "../includes/RtsFlags.h"
18 #else
19 #include "Rts.h"
20 #include "RtsFlags.h"
21 #endif
22
23 #if __GLASGOW_HASKELL__ >= 502
24 #include "RtsFlags.h"
25 #endif
26
27 #if __GLASGOW_HASKELL__ >= 408
28 #include "HsFFI.h"
29 #endif
30
31 #ifdef HAVE_UNISTD_H
32 #include <unistd.h>
33 #endif
34
35 #if __GLASGOW_HASKELL__ >= 504
36
37 char *ghc_rts_opts = "-H8m -K8m";
38
39 #else
40
41 void
42 defaultsHook (void)
43 {
44 #if __GLASGOW_HASKELL__ >= 408
45     RtsFlags.GcFlags.heapSizeSuggestion = 6*1024*1024 / BLOCK_SIZE;
46     RtsFlags.GcFlags.maxStkSize         = 8*1024*1024 / sizeof(W_);
47 #endif
48 #if __GLASGOW_HASKELL__ >= 411
49     RtsFlags.GcFlags.giveStats = COLLECT_GC_STATS;
50     RtsFlags.GcFlags.statsFile = stderr;
51 #endif
52 }
53 #endif
54
55 void
56 enableTimingStats( void )       /* called from the driver */
57 {
58 #if __GLASGOW_HASKELL__ >= 505
59     RtsFlags.GcFlags.giveStats = ONELINE_GC_STATS;
60 #endif
61     /* ignored when bootstrapping with an older GHC */
62 }
63
64 void
65 setHeapSize( HsInt size )
66 {
67 #if __GLASGOW_HASKELL__ >= 408
68     RtsFlags.GcFlags.heapSizeSuggestion = size / BLOCK_SIZE;
69     if (RtsFlags.GcFlags.maxHeapSize != 0 &&
70         RtsFlags.GcFlags.heapSizeSuggestion > RtsFlags.GcFlags.maxHeapSize) {
71         RtsFlags.GcFlags.maxHeapSize = RtsFlags.GcFlags.heapSizeSuggestion;
72     }
73 #endif
74 }
75
76 void
77 PreTraceHook (long fd)
78 {
79     const char msg[]="\n";
80     write(fd,msg,sizeof(msg)-1);
81 }
82
83 void
84 PostTraceHook (long fd)
85 {
86 #if 0
87     const char msg[]="\n";
88     write(fd,msg,sizeof(msg)-1);
89 #endif
90 }
91
92 void
93 OutOfHeapHook (unsigned long request_size, unsigned long heap_size)
94   /* both in bytes */
95 {
96     fprintf(stderr, "GHC's heap exhausted;\nwhile trying to allocate %lu bytes in a %lu-byte heap;\nuse the `-H<size>' option to increase the total heap size.\n",
97         request_size,
98         heap_size);
99 }
100
101 void
102 StackOverflowHook (unsigned long stack_size)    /* in bytes */
103 {
104     fprintf(stderr, "GHC stack-space overflow: current size %ld bytes.\nUse the `-K<size>' option to increase it.\n", stack_size);
105 }
106
107 HsInt
108 ghc_strlen( HsAddr a )
109 {
110     return (strlen((char *)a));
111 }
112
113 HsInt
114 ghc_memcmp( HsAddr a1, HsAddr a2, HsInt len )
115 {
116     return (memcmp((char *)a1, a2, len));
117 }
118
119 HsInt
120 ghc_memcmp_off( HsAddr a1, HsInt i, HsAddr a2, HsInt len )
121 {
122     return (memcmp((char *)a1 + i, a2, len));
123 }