GHC new build system megapatch
[ghc-hetmet.git] / includes / Stg.h
index 1facd5f..2b2095f 100644 (file)
  */
 #ifndef IN_STG_CODE
 # define IN_STG_CODE 1
+
+// Turn on C99 for .hc code.  This gives us the INFINITY and NAN
+// constants from math.h, which we occasionally need to use in .hc (#1861)
+# define _ISOC99_SOURCE
 #endif
 
 #if IN_STG_CODE == 0
 #include "ghcconfig.h"
 #include "RtsConfig.h"
 
+/* The code generator calls the math functions directly in .hc code.
+   NB. after configuration stuff above, because this sets #defines
+   that depend on config info, such as __USE_FILE_OFFSET64 */
+#include <math.h>
+
 /* -----------------------------------------------------------------------------
    Useful definitions
    -------------------------------------------------------------------------- */
 #define BITS_PER_BYTE 8
 #define BITS_IN(x) (BITS_PER_BYTE * sizeof(x))
 
+/* Compute offsets of struct fields
+ */
+#define STG_FIELD_OFFSET(s_type, field) ((StgWord)&(((s_type*)0)->field))
+
 /*
  * 'Portable' inlining:
- * INLINE_HEADER is for inline functions in header files
+ * INLINE_HEADER is for inline functions in header files (macros)
  * STATIC_INLINE is for inline functions in source files
+ * EXTERN_INLINE is for functions that we want to inline sometimes 
+ * (we also compile a static version of the function; see Inlines.c)
  */
 #if defined(__GNUC__) || defined( __INTEL_COMPILER)
+
 # define INLINE_HEADER static inline
 # define INLINE_ME inline
 # define STATIC_INLINE INLINE_HEADER
+
+// The special "extern inline" behaviour is now only supported by gcc
+// when _GNUC_GNU_INLINE__ is defined, and you have to use
+// __attribute__((gnu_inline)).  So when we don't have this, we use
+// ordinary static inline.
+//
+// Apple's gcc defines __GNUC_GNU_INLINE__ without providing
+// gnu_inline, so we exclude MacOS X and fall through to the safe
+// version.
+//
+#if defined(__GNUC_GNU_INLINE__) && !defined(__APPLE__)
+#  if defined(KEEP_INLINES)
+#    define EXTERN_INLINE inline
+#  else
+#    define EXTERN_INLINE extern inline __attribute__((gnu_inline))
+#  endif
+#else
+#  if defined(KEEP_INLINES)
+#    define EXTERN_INLINE
+#  else
+#    define EXTERN_INLINE INLINE_HEADER
+#  endif
+#endif
+
 #elif defined(_MSC_VER)
+
 # define INLINE_HEADER __inline static
 # define INLINE_ME __inline
 # define STATIC_INLINE INLINE_HEADER
+
+# if defined(KEEP_INLINES)
+#  define EXTERN_INLINE __inline
+# else
+#  define EXTERN_INLINE __inline extern
+# endif
+
 #else
+
 # error "Don't know how to inline functions with your C compiler."
+
 #endif
 
+
 /*
  * GCC attributes
  */
 #define GNUC3_ATTRIBUTE(at)
 #endif
 
+#if __GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 3
+#define GNUC_ATTR_HOT __attribute__((hot))
+#else
+#define GNUC_ATTR_HOT /* nothing */
+#endif
+
 #define STG_UNUSED    GNUC3_ATTRIBUTE(__unused__)
 
 /* -----------------------------------------------------------------------------
@@ -148,7 +205,10 @@ typedef StgWord StgWordArray[];
 #include "StgDLL.h"
 #include "MachRegs.h"
 #include "Regs.h"
-#include "StgProf.h"  /* ToDo: separate out RTS-only stuff from here */
+
+#ifdef TICKY_TICKY
+#include "TickyCounters.h"
+#endif
 
 #if IN_STG_CODE
 /*
@@ -158,8 +218,7 @@ typedef StgWord StgWordArray[];
 #include "StgMiscClosures.h"
 #endif
 
-/* RTS external interface */
-#include "RtsExternal.h"
+#include "SMP.h" // write_barrier() inline is required 
 
 /* -----------------------------------------------------------------------------
    Moving Floats and Doubles