Migrate cvs diff from fptools-assoc branch
[ghc-hetmet.git] / compiler / parser / cutils.c
1 /*
2 These utility routines are used various
3 places in the GHC library.
4 */
5
6 /* For GHC 4.08, we are relying on the fact that RtsFlags has
7  * compatible layout with the current version, because we're
8  * #including the current version of RtsFlags.h below.  4.08 didn't
9  * ship with its own RtsFlags.h, unfortunately.   For later GHC
10  * versions, we #include the correct RtsFlags.h.
11  */
12 #if __GLASGOW_HASKELL__ < 502
13 #include "../includes/Rts.h"
14 #include "../includes/RtsFlags.h"
15 #else
16 #include "Rts.h"
17 #include "RtsFlags.h"
18 #endif
19
20 #include "HsFFI.h"
21
22 #include <string.h>
23
24 #ifdef HAVE_UNISTD_H
25 #include <unistd.h>
26 #endif
27
28 /*
29 Calling 'strlen' and 'memcpy' directly gives problems with GCC's inliner,
30 and causes gcc to require too many registers on x84
31 */
32
33 HsInt
34 ghc_strlen( HsAddr a )
35 {
36     return (strlen((char *)a));
37 }
38
39 HsInt
40 ghc_memcmp( HsAddr a1, HsAddr a2, HsInt len )
41 {
42     return (memcmp((char *)a1, a2, len));
43 }
44
45 HsInt
46 ghc_memcmp_off( HsAddr a1, HsInt i, HsAddr a2, HsInt len )
47 {
48     return (memcmp((char *)a1 + i, a2, len));
49 }
50
51 void
52 enableTimingStats( void )       /* called from the driver */
53 {
54 #if __GLASGOW_HASKELL__ >= 411
55     RtsFlags.GcFlags.giveStats = ONELINE_GC_STATS;
56 #endif
57     /* ignored when bootstrapping with an older GHC */
58 }
59
60 void
61 setHeapSize( HsInt size )
62 {
63     RtsFlags.GcFlags.heapSizeSuggestion = size / BLOCK_SIZE;
64     if (RtsFlags.GcFlags.maxHeapSize != 0 &&
65         RtsFlags.GcFlags.heapSizeSuggestion > RtsFlags.GcFlags.maxHeapSize) {
66         RtsFlags.GcFlags.maxHeapSize = RtsFlags.GcFlags.heapSizeSuggestion;
67     }
68 }
69
70