[project @ 2005-02-16 10:50:23 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 /* For GHC 4.08, we are relying on the fact that RtsFlags has
10  * compatibile layout with the current version, because we're
11  * #including the current version of RtsFlags.h below.  4.08 didn't
12  * ship with its own RtsFlags.h, unfortunately.   For later GHC
13  * versions, we #include the correct RtsFlags.h.
14  */
15 #if __GLASGOW_HASKELL__ < 502
16 #include "../includes/Rts.h"
17 #include "../includes/RtsFlags.h"
18 #else
19 #include "Rts.h"
20 #include "RtsFlags.h"
21 #endif
22
23 #include "HsFFI.h"
24
25 #ifdef HAVE_UNISTD_H
26 #include <unistd.h>
27 #endif
28
29 void
30 defaultsHook (void)
31 {
32     RtsFlags.GcFlags.heapSizeSuggestion = 6*1024*1024 / BLOCK_SIZE;
33     RtsFlags.GcFlags.maxStkSize         = 8*1024*1024 / sizeof(W_);
34 #if __GLASGOW_HASKELL__ >= 411
35     /* GHC < 4.11 didn't have these */
36     RtsFlags.GcFlags.giveStats = COLLECT_GC_STATS;
37     RtsFlags.GcFlags.statsFile = stderr;
38 #endif
39 }
40
41 void
42 enableTimingStats( void )       /* called from the driver */
43 {
44 #if __GLASGOW_HASKELL__ >= 411
45     RtsFlags.GcFlags.giveStats = ONELINE_GC_STATS;
46 #endif
47     /* ignored when bootstrapping with an older GHC */
48 }
49
50 void
51 setHeapSize( HsInt size )
52 {
53     RtsFlags.GcFlags.heapSizeSuggestion = size / BLOCK_SIZE;
54     if (RtsFlags.GcFlags.maxHeapSize != 0 &&
55         RtsFlags.GcFlags.heapSizeSuggestion > RtsFlags.GcFlags.maxHeapSize) {
56         RtsFlags.GcFlags.maxHeapSize = RtsFlags.GcFlags.heapSizeSuggestion;
57     }
58 }
59
60 void
61 OutOfHeapHook (unsigned long request_size/* always zero these days */,
62                unsigned long heap_size)
63     /* both in bytes */
64 {
65     fprintf(stderr, "GHC's heap exhausted: current limit is %lu bytes;\nUse the `-M<size>' option to increase the total heap size.\n",
66         heap_size);
67 }
68
69 void
70 StackOverflowHook (unsigned long stack_size)    /* in bytes */
71 {
72     fprintf(stderr, "GHC stack-space overflow: current limit is %ld bytes.\nUse the `-K<size>' option to increase it.\n", stack_size);
73 }
74
75 HsInt
76 ghc_strlen( HsAddr a )
77 {
78     return (strlen((char *)a));
79 }
80
81 HsInt
82 ghc_memcmp( HsAddr a1, HsAddr a2, HsInt len )
83 {
84     return (memcmp((char *)a1, a2, len));
85 }
86
87 HsInt
88 ghc_memcmp_off( HsAddr a1, HsInt i, HsAddr a2, HsInt len )
89 {
90     return (memcmp((char *)a1 + i, a2, len));
91 }