/* X-Midas Compatibility Definitions. These definitions are updated based
   on which version of X-Midas we are trying to be compatible with.

   The following can be specified with the compile command to determine
   which options are used:

   Three modes are used to support 64-bit vs 32-bit builds:
     Classic    - 32-bit build compatible with XM 3.8.x (default)
     32Bit      - 32-bit build compatible with XM 4.4.x (-D_32BIT)
     64Bit      - 64-bit build compatible with XM 4.4.x (-D_64BIT)

   How it all works...
     X-Midas defines M_PTR to be a 8-byte structure that holds a pointer (p)
     and is padded out to 8-bytes with a fill if the pointer is less than
     8-bytes long. This allows *most* Fortran code to be compiled independent
     of the pointer size, assuming that it uses this record.

     The M_PTR structure is NOT present in XM 3.8.x, rather an integer*4 is
     used to hold the pointer (XM 3.8.x is NOT compatible with 64-bit pointers).

     To allow XBC to work in all three modes (Classic, 32Bit, 64Bit) without a
     lot of #if's we define the following:

        M_POINTER       - Holds a pointer (internal use only)
        M_PTR           - Pointer structure (32Bit, 64Bit) or an int_u4 (Classic)
        H_PTR           - Identical to M_PTR (X-Midas does this for no apparent reason)
        M_PTR_T         - Pointer type, int_u8 (64Bit) or int_u4 (32Bit, Classic)

        GET_PTR(p)      - Gets the value of a pointer (p), for ANY architecture
        SET_PTR(p,v)    - Sets the value of pointer (p) to a given value (v), for ANY architecture

      Note: M_POINTER is separate from M_PTR to allow us to have code internal to XBC that
      uses the pointer structure even in Classic mode. Use of M_POINTER is restricted to
      files in the XBC option tree.

   @author  J. Czechowski IV
   @version $Id: xmcompat.h,v 1.9 2009/08/11 00:25:53 ntn Exp $
 */

#include "mtypes.h"
#ifndef XMCOMPAT_H_  /* Start of file */
#define XMCOMPAT_H_

#if defined(_64BIT)       /* 64Bit - XM 4.4.X compatible 64-bit */
  typedef M_PTR                 M_POINTER;
# define M_POINTER_T            M_PTR_T
# define GET_PTR(ptr)           ((ptr)->p)
# define SET_PTR(ptr,val)       ((ptr)->p = (M_POINTER_T)(val))


#elif defined(_32BIT)     /* 32 Bit - XM 4.4.X compatible 32-bit */
  typedef M_PTR                 M_POINTER;
# define M_POINTER_T            M_PTR_T
# define GET_PTR(ptr)           ((ptr)->p)
# define SET_PTR(ptr,val)       ((ptr)->p = (M_POINTER_T)(val))


#else                     /* Classic - XM 3.8.X compatible 32-bit */
  typedef int_u4                M_POINTER;
# define M_POINTER_T            M_PTR_T
# define GET_PTR(ptr)           (*ptr)
# define SET_PTR(ptr,val)       ((*ptr) = (M_POINTER_T)(val))

#endif

typedef M_PTR      H_PTR;

#endif /* End of file */
