Commit a814590c authored by sof's avatar sof
Browse files

[project @ 2003-11-12 17:27:00 by sof]

Tidy up a couple of unportable coding issues:

- conditionally use empty structs.
- use GNU attributes only if supported.
- 'long long' usage
- use of 'inline' in declarations and definitions.

Upshot of these changes is that MSVC is now capable of compiling
the non-.hc portions of the RTS.
parent eacd5715
/* -----------------------------------------------------------------------------
* $Id: Block.h,v 1.14 2003/09/23 15:38:35 simonmar Exp $
* $Id: Block.h,v 1.15 2003/11/12 17:27:00 sof Exp $
*
* (c) The GHC Team, 1998-1999
*
......@@ -82,7 +82,7 @@ typedef struct _bdescr {
/* Finding the block descriptor for a given block -------------------------- */
static inline bdescr *Bdescr(StgPtr p)
INLINE_HEADER bdescr *Bdescr(StgPtr p)
{
return (bdescr *)
((((W_)p & MBLOCK_MASK & ~BLOCK_MASK) >> (BLOCK_SHIFT-BDESCR_SHIFT))
......
/* ----------------------------------------------------------------------------
* $Id: ClosureMacros.h,v 1.37 2003/06/30 14:17:02 simonmar Exp $
* $Id: ClosureMacros.h,v 1.38 2003/11/12 17:27:00 sof Exp $
*
* (c) The GHC Team, 1998-1999
*
......@@ -70,7 +70,7 @@
#define RET_INFO_PTR_TO_STRUCT(info) ((StgRetInfoTable *)(info) - 1)
#define FUN_INFO_PTR_TO_STRUCT(info) ((StgFunInfoTable *)(info) - 1)
#define THUNK_INFO_PTR_TO_STRUCT(info) ((StgThunkInfoTable *)(info) - 1)
static __inline__ StgFunPtr get_entry(const StgInfoTable *itbl) {
INLINE_HEADER StgFunPtr get_entry(const StgInfoTable *itbl) {
return (StgFunPtr)(itbl+1);
}
#define itbl_to_fun_itbl(i) ((StgFunInfoTable *)(((StgInfoTable *)(i) + 1)) - 1)
......@@ -83,7 +83,7 @@ static __inline__ StgFunPtr get_entry(const StgInfoTable *itbl) {
#define RET_INFO_PTR_TO_STRUCT(info) ((StgRetInfoTable *)info)
#define FUN_INFO_PTR_TO_STRUCT(info) ((StgFunInfoTable *)info)
#define THUNK_INFO_PTR_TO_STRUCT(info) ((StgThunkInfoTable *)info)
static __inline__ StgFunPtr get_entry(const StgInfoTable *itbl) {
INLINE_HEADER StgFunPtr get_entry(const StgInfoTable *itbl) {
return itbl->entry;
}
#define itbl_to_fun_itbl(i) ((StgFunInfoTable *)(i))
......
/* ----------------------------------------------------------------------------
* $Id: InfoTables.h,v 1.29 2003/05/14 09:14:02 simonmar Exp $
* $Id: InfoTables.h,v 1.30 2003/11/12 17:27:00 sof Exp $
*
* (c) The GHC Team, 1998-2002
*
......@@ -85,9 +85,11 @@ typedef struct {
Ticky info
-------------------------------------------------------------------------- */
#if defined(SUPPORTS_EMPTY_STRUCTS)
typedef struct {
/* empty */
} StgTickyInfo;
#endif
/* -----------------------------------------------------------------------------
Debugging info
......@@ -101,9 +103,11 @@ typedef struct {
#else /* !DEBUG_CLOSURE */
typedef struct {
# if defined(SUPPORTS_EMPTY_STRUCTS)
typedef struct StgDebugInfo {
/* empty */
} StgDebugInfo;
# endif
#endif /* DEBUG_CLOSURE */
......@@ -249,10 +253,10 @@ typedef struct _StgInfoTable {
StgProfInfo prof;
#endif
#ifdef TICKY
StgTickyInfo ticky;
MAYBE_EMPTY_STRUCT(StgTickyInfo,ticky)
#endif
#ifdef DEBUG_CLOSURE
StgDebugInfo debug;
MAYBE_EMPTY_STRUCT(StgDebugInfo,debug)
#endif
StgClosureInfo layout; // closure layout info (one word)
......
/* -----------------------------------------------------------------------------
* $Id: PrimOps.h,v 1.106 2003/10/01 10:57:41 wolfgang Exp $
* $Id: PrimOps.h,v 1.107 2003/11/12 17:27:01 sof Exp $
*
* (c) The GHC Team, 1998-2000
*
......@@ -256,8 +256,7 @@ EXTFUN_RTS(catchzh_fast);
EXTFUN_RTS(raisezh_fast);
EXTFUN_RTS(raiseIOzh_fast);
extern void stg_exit(int n) __attribute__ ((noreturn));
extern void stg_exit(int n) GNU_ATTRIBUTE(__noreturn__);
/* -----------------------------------------------------------------------------
Stable Name / Stable Pointer PrimOps
......
/* -----------------------------------------------------------------------------
* $Id: Rts.h,v 1.22 2002/12/19 17:57:39 panne Exp $
* $Id: Rts.h,v 1.23 2003/11/12 17:27:03 sof Exp $
*
* (c) The GHC Team, 1998-1999
*
......@@ -96,12 +96,21 @@ extern void* GetFiberData ( void );
#define STG_UNUSED
#endif
#if defined(__GNUC__)
#define SUPPORTS_TYPEOF
#endif
/* -----------------------------------------------------------------------------
Useful macros and inline functions
-------------------------------------------------------------------------- */
#if defined(SUPPORTS_TYPEOF)
#define stg_min(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _a : _b; })
#define stg_max(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _b : _a; })
#else
#define stg_min(a,b) ((a) <= (b) ? (a) : (b))
#define stg_max(a,b) ((a) <= (b) ? (b) : (a))
#endif
/* -------------------------------------------------------------------------- */
......
......@@ -17,7 +17,13 @@ typedef unsigned long nat; /* at least 32 bits (like int) */
typedef unsigned int nat; /* at least 32 bits (like int) */
#endif
typedef unsigned long lnat; /* at least 32 bits */
#ifndef _MSC_VER
typedef unsigned long long ullong; /* at least 32 bits */
typedef long long llong;
#else
typedef unsigned __int64 ullong; /* at least 32 bits */
typedef __int64 llong;
#endif
/* ullong (64|128-bit) type: only include if needed (not ANSI) */
#if defined(__GNUC__)
......
/* -----------------------------------------------------------------------------
* $Id: SchedAPI.h,v 1.18 2003/09/21 22:20:53 wolfgang Exp $
* $Id: SchedAPI.h,v 1.19 2003/11/12 17:27:03 sof Exp $
*
* (c) The GHC Team 1998-2002
*
......@@ -34,12 +34,12 @@ extern void scheduleThread(StgTSO *tso);
extern SchedulerStatus scheduleWaitThread(StgTSO *tso, /*out*/HaskellObj* ret,
Capability *initialCapability);
static inline void pushClosure (StgTSO *tso, StgWord c) {
INLINE_HEADER void pushClosure (StgTSO *tso, StgWord c) {
tso->sp--;
tso->sp[0] = (W_) c;
}
static inline StgTSO *
INLINE_HEADER StgTSO *
createGenThread(nat stack_size, StgClosure *closure) {
StgTSO *t;
#if defined(GRAN)
......@@ -52,7 +52,7 @@ createGenThread(nat stack_size, StgClosure *closure) {
return t;
}
static inline StgTSO *
INLINE_HEADER StgTSO *
createIOThread(nat stack_size, StgClosure *closure) {
StgTSO *t;
#if defined(GRAN)
......@@ -72,7 +72,7 @@ createIOThread(nat stack_size, StgClosure *closure) {
* to whnf while we're at it.
*/
static inline StgTSO *
INLINE_HEADER StgTSO *
createStrictIOThread(nat stack_size, StgClosure *closure) {
StgTSO *t;
#if defined(GRAN)
......
/* -----------------------------------------------------------------------------
* $Id: Stable.h,v 1.14 2002/12/19 14:25:04 simonmar Exp $
* $Id: Stable.h,v 1.15 2003/11/12 17:27:03 sof Exp $
*
* (c) The GHC Team, 1998-2000
*
......@@ -41,17 +41,18 @@ extern DLL_IMPORT_RTS snEntry *stable_ptr_table;
extern void freeStablePtr(StgStablePtr sp);
#ifndef RTS_STABLE_C
#if defined(__GNUC__)
# ifndef RTS_STABLE_C
extern inline
#endif
# endif
StgPtr deRefStablePtr(StgStablePtr sp)
{
ASSERT(stable_ptr_table[(StgWord)sp].ref > 0);
return stable_ptr_table[(StgWord)sp].addr;
}
/* No deRefStableName, because the existence of a stable name doesn't
* guarantee the existence of the object itself.
*/
#else
/* No support for 'extern inline' */
extern StgPtr deRefStablePtr(StgStablePtr sp);
#endif
#endif
/* -----------------------------------------------------------------------------
* $Id: Stg.h,v 1.56 2003/09/21 13:22:01 igloo Exp $
* $Id: Stg.h,v 1.57 2003/11/12 17:27:04 sof Exp $
*
* (c) The GHC Team, 1998-1999
*
......@@ -82,6 +82,41 @@
# define LAZY_BLACKHOLING
#endif
#if defined(__GNUC__)
#define GNU_ATTRIBUTE(at) __attribute__((at))
#else
#define GNU_ATTRIBUTE(at)
#endif
/*
* Empty structures isn't supported by all, so to define
* empty structures, please protect the defn with an
* #if SUPPORTS_EMPTY_STRUCTS. Similarly for use,
* employ the macro MAYBE_EMPTY_STRUCT():
*
* MAYBE_EMPTY_STRUCT(structFoo, fieldName);
*/
#if SUPPORTS_EMPTY_STRUCTS
# define MAYBE_EMPTY_STRUCT(a,b) a b;
#else
# define MAYBE_EMPTY_STRUCT(a,b) /* empty */
#endif
/*
* 'Portable'
*/
#if defined(__GNUC__)
# define INLINE_HEADER static inline
# define INLINE_ME inline
# define STATIC_INLINE INLINE_HEADER
#elif defined(_MSC_VER)
# define INLINE_HEADER __inline static
# define INLINE_ME __inline
# define STATIC_INLINE INLINE_HEADER
#else
# error "Don't know how to inline functions with your C compiler."
#endif
/* TABLES_NEXT_TO_CODE says whether to assume that info tables are
* assumed to reside just before the code for a function.
*
......
/* -----------------------------------------------------------------------------
* $Id: StgMacros.h,v 1.56 2003/08/05 14:01:34 simonpj Exp $
* $Id: StgMacros.h,v 1.57 2003/11/12 17:27:04 sof Exp $
*
* (c) The GHC Team, 1998-1999
*
......@@ -483,24 +483,24 @@ EXTFUN_RTS(stg_gen_block);
guaranteed to be StgWord aligned.
-------------------------------------------------------------------------- */
static inline void ASSIGN_FLT (W_ [], StgFloat);
static inline StgFloat PK_FLT (W_ []);
INLINE_HEADER void ASSIGN_FLT (W_ [], StgFloat);
INLINE_HEADER StgFloat PK_FLT (W_ []);
#if ALIGNMENT_FLOAT <= ALIGNMENT_LONG
static inline void ASSIGN_FLT(W_ p_dest[], StgFloat src) { *(StgFloat *)p_dest = src; }
static inline StgFloat PK_FLT (W_ p_src[]) { return *(StgFloat *)p_src; }
INLINE_HEADER void ASSIGN_FLT(W_ p_dest[], StgFloat src) { *(StgFloat *)p_dest = src; }
INLINE_HEADER StgFloat PK_FLT (W_ p_src[]) { return *(StgFloat *)p_src; }
#else /* ALIGNMENT_FLOAT > ALIGNMENT_UNSIGNED_INT */
static inline void ASSIGN_FLT(W_ p_dest[], StgFloat src)
INLINE_HEADER void ASSIGN_FLT(W_ p_dest[], StgFloat src)
{
float_thing y;
y.f = src;
*p_dest = y.fu;
}
static inline StgFloat PK_FLT(W_ p_src[])
INLINE_HEADER StgFloat PK_FLT(W_ p_src[])
{
float_thing y;
y.fu = *p_src;
......@@ -511,11 +511,11 @@ static inline StgFloat PK_FLT(W_ p_src[])
#if ALIGNMENT_DOUBLE <= ALIGNMENT_LONG
static inline void ASSIGN_DBL (W_ [], StgDouble);
static inline StgDouble PK_DBL (W_ []);
INLINE_HEADER void ASSIGN_DBL (W_ [], StgDouble);
INLINE_HEADER StgDouble PK_DBL (W_ []);
static inline void ASSIGN_DBL(W_ p_dest[], StgDouble src) { *(StgDouble *)p_dest = src; }
static inline StgDouble PK_DBL (W_ p_src[]) { return *(StgDouble *)p_src; }
INLINE_HEADER void ASSIGN_DBL(W_ p_dest[], StgDouble src) { *(StgDouble *)p_dest = src; }
INLINE_HEADER StgDouble PK_DBL (W_ p_src[]) { return *(StgDouble *)p_src; }
#else /* ALIGNMENT_DOUBLE > ALIGNMENT_LONG */
......@@ -541,8 +541,8 @@ static inline StgDouble PK_DBL (W_ p_src[]) { return *(StgDou
#else /* ! sparc_TARGET_ARCH */
static inline void ASSIGN_DBL (W_ [], StgDouble);
static inline StgDouble PK_DBL (W_ []);
INLINE_HEADER void ASSIGN_DBL (W_ [], StgDouble);
INLINE_HEADER StgDouble PK_DBL (W_ []);
typedef struct
{ StgWord dhi;
......@@ -554,7 +554,7 @@ typedef union
unpacked_double du;
} double_thing;
static inline void ASSIGN_DBL(W_ p_dest[], StgDouble src)
INLINE_HEADER void ASSIGN_DBL(W_ p_dest[], StgDouble src)
{
double_thing y;
y.d = src;
......@@ -570,7 +570,7 @@ static inline void ASSIGN_DBL(W_ p_dest[], StgDouble src)
*(p_dest+1) = ((double_thing) src).du.dlo \
*/
static inline StgDouble PK_DBL(W_ p_src[])
INLINE_HEADER StgDouble PK_DBL(W_ p_src[])
{
double_thing y;
y.du.dhi = p_src[0];
......@@ -599,7 +599,7 @@ typedef union
unpacked_double_word wu;
} word64_thing;
static inline void ASSIGN_Word64(W_ p_dest[], StgWord64 src)
INLINE_HEADER void ASSIGN_Word64(W_ p_dest[], StgWord64 src)
{
word64_thing y;
y.w = src;
......@@ -607,7 +607,7 @@ static inline void ASSIGN_Word64(W_ p_dest[], StgWord64 src)
p_dest[1] = y.wu.dlo;
}
static inline StgWord64 PK_Word64(W_ p_src[])
INLINE_HEADER StgWord64 PK_Word64(W_ p_src[])
{
word64_thing y;
y.wu.dhi = p_src[0];
......@@ -615,7 +615,7 @@ static inline StgWord64 PK_Word64(W_ p_src[])
return(y.w);
}
static inline void ASSIGN_Int64(W_ p_dest[], StgInt64 src)
INLINE_HEADER void ASSIGN_Int64(W_ p_dest[], StgInt64 src)
{
int64_thing y;
y.i = src;
......@@ -623,7 +623,7 @@ static inline void ASSIGN_Int64(W_ p_dest[], StgInt64 src)
p_dest[1] = y.iu.dlo;
}
static inline StgInt64 PK_Int64(W_ p_src[])
INLINE_HEADER StgInt64 PK_Int64(W_ p_src[])
{
int64_thing y;
y.iu.dhi = p_src[0];
......@@ -633,22 +633,22 @@ static inline StgInt64 PK_Int64(W_ p_src[])
#elif SIZEOF_VOID_P == 8
static inline void ASSIGN_Word64(W_ p_dest[], StgWord64 src)
INLINE_HEADER void ASSIGN_Word64(W_ p_dest[], StgWord64 src)
{
p_dest[0] = src;
}
static inline StgWord64 PK_Word64(W_ p_src[])
INLINE_HEADER StgWord64 PK_Word64(W_ p_src[])
{
return p_src[0];
}
static inline void ASSIGN_Int64(W_ p_dest[], StgInt64 src)
INLINE_HEADER void ASSIGN_Int64(W_ p_dest[], StgInt64 src)
{
p_dest[0] = src;
}
static inline StgInt64 PK_Int64(W_ p_src[])
INLINE_HEADER StgInt64 PK_Int64(W_ p_src[])
{
return p_src[0];
}
......@@ -710,7 +710,7 @@ extern DLL_IMPORT_RTS const StgPolyInfoTable stg_catch_frame_info;
#if IN_STG_CODE
static __inline__ void
INLINE_HEADER void
SaveThreadState(void)
{
StgTSO *tso;
......@@ -732,7 +732,7 @@ SaveThreadState(void)
#endif
}
static __inline__ void
INLINE_HEADER void
LoadThreadState (void)
{
StgTSO *tso;
......
/* -----------------------------------------------------------------------------
* $Id: StgProf.h,v 1.16 2001/12/12 14:59:41 simonmar Exp $
* $Id: StgProf.h,v 1.17 2003/11/12 17:27:04 sof Exp $
*
* (c) The GHC Team, 1998
*
......@@ -20,7 +20,7 @@ typedef struct _CostCentre {
/* used for accumulating costs at the end of the run... */
unsigned long time_ticks;
unsigned long long mem_alloc;
ullong mem_alloc;
char is_caf;
......@@ -37,13 +37,14 @@ typedef struct _CostCentreStack {
unsigned int selected;
unsigned long long scc_count;
ullong scc_count;
unsigned long time_ticks;
unsigned long long mem_alloc;
ullong mem_alloc;
unsigned long inherited_ticks;
unsigned long long inherited_alloc;
ullong inherited_alloc;
CostCentre *root;
} CostCentreStack;
......
/* -----------------------------------------------------------------------------
* $Id: StgTypes.h,v 1.19 2002/12/11 15:36:39 simonmar Exp $
* $Id: StgTypes.h,v 1.20 2003/11/12 17:27:05 sof Exp $
*
* (c) The GHC Team, 1998-2000
*
......@@ -61,8 +61,13 @@ typedef unsigned int StgWord32;
#ifdef SUPPORT_LONG_LONGS
/* assume long long is 64 bits */
# ifndef _MSC_VER
typedef signed long long int StgInt64;
typedef unsigned long long int StgWord64;
# else
typedef __int64 StgInt64;
typedef unsigned __int64 StgWord64;
# endif
#elif SIZEOF_LONG == 8
typedef signed long StgInt64;
typedef unsigned long StgWord64;
......
/* -----------------------------------------------------------------------------
* $Id: TSO.h,v 1.32 2003/09/21 22:20:53 wolfgang Exp $
* $Id: TSO.h,v 1.33 2003/11/12 17:27:05 sof Exp $
*
* (c) The GHC Team, 1998-1999
*
......@@ -41,15 +41,21 @@ typedef struct {
CostCentreStack *CCCS; /* thread's current CCS */
} StgTSOProfInfo;
#else /* !PROFILING */
# if defined(SUPPORTS_EMPTY_STRUCTS)
typedef struct {
/* empty */
} StgTSOProfInfo;
# endif
#endif /* PROFILING */
#if defined(PAR)
typedef StgTSOStatBuf StgTSOParInfo;
#else /* !PAR */
# if defined(SUPPORTS_EMPTY_STRUCTS)
typedef struct {
/* empty */
} StgTSOParInfo;
# endif
#endif /* PAR */
#if defined(DIST)
......@@ -59,15 +65,21 @@ typedef struct {
StgInt revalSlot;
} StgTSODistInfo;
#else /* !DIST */
# if defined(SUPPORTS_EMPTY_STRUCTS)
typedef struct {
/* empty */
} StgTSODistInfo;
# endif
#endif /* DIST */
#if defined(GRAN)
typedef StgTSOStatBuf StgTSOGranInfo;
#else /* !GRAN */
# if defined(SUPPORTS_EMPTY_STRUCTS)
typedef struct {
/* empty */
} StgTSOGranInfo;
# endif
#endif /* GRAN */
......@@ -75,8 +87,11 @@ typedef struct {
typedef struct {
} StgTSOTickyInfo;
#else /* !TICKY_TICKY */
# if defined(SUPPORTS_EMPTY_STRUCTS)
typedef struct {
/* empty */
} StgTSOTickyInfo;
# endif
#endif /* TICKY_TICKY */
typedef enum {
......@@ -196,11 +211,11 @@ typedef struct StgTSO_ {
StgThreadID id;
int saved_errno;
StgTSOTickyInfo ticky;
StgTSOProfInfo prof;
StgTSOParInfo par;
StgTSOGranInfo gran;
StgTSODistInfo dist;
MAYBE_EMPTY_STRUCT(StgTSOTickyInfo,ticky)
MAYBE_EMPTY_STRUCT(StgTSOProfInfo,prof)
MAYBE_EMPTY_STRUCT(StgTSOParInfo,par)
MAYBE_EMPTY_STRUCT(StgTSOGranInfo,gran)
MAYBE_EMPTY_STRUCT(StgTSODistInfo,dist)
/* The thread stack... */
StgWord stack_size; /* stack size in *words* */
......
/* -----------------------------------------------------------------------------
* $Id: Updates.h,v 1.33 2003/07/28 16:05:38 simonmar Exp $
* $Id: Updates.h,v 1.34 2003/11/12 17:27:06 sof Exp $
*
* (c) The GHC Team, 1998-1999
*
......@@ -32,8 +32,9 @@
# define UPD_SPEC_IND(updclosure, ind_info, heapptr, and_then) \
UPD_PERM_IND(updclosure,heapptr); and_then
#else
# define SEMI ;
# define UPD_IND(updclosure, heapptr) \
UPD_REAL_IND(updclosure,&stg_IND_info,heapptr,)
UPD_REAL_IND(updclosure,&stg_IND_info,heapptr,SEMI)
# define UPD_SPEC_IND(updclosure, ind_info, heapptr, and_then) \
UPD_REAL_IND(updclosure,ind_info,heapptr,and_then)
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment