home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c221 / 6.ddi / MWHC.006 / Z < prev    next >
Encoding:
Text File  |  1992-12-09  |  8.4 KB  |  239 lines

  1. /*
  2.  *   stdarg.h -- ANSI 
  3.  *
  4.  *   Macros and type for functions the require variable
  5.  *   numbers of arguments.
  6.  *
  7.  *           Copyright (c) 1990, MetaWare Incorporated
  8.  */
  9.  
  10. #ifndef _STDARG_H
  11. #define _STDARG_H    
  12. #pragma push_align_members(64);
  13.  
  14. #ifdef __CPLUSPLUS__
  15. extern "C" {
  16. #endif
  17.  
  18. /*
  19.  * __vararg_char is used as a pseudonym for "char". The compiler would
  20.  * ordinarily warn about "misbehaviour" if an arbitrary pointer is cast 
  21.  * to or from (char *) at high optimization levels.
  22.  * To avoid this problem we use "__vararg_char" inplace of "char".
  23.  * The compiler special-cases the type (__vararg_char *) and doesn't put
  24.  * out the warning.
  25.  */
  26. typedef char __vararg_char;
  27.  
  28. #if _SPARC
  29. /************************************************************************
  30.  *                           SPARC varargs                              *
  31.  ************************************************************************/
  32. #   define __va_start(ap,parmN) (ap=(__vararg_char *)&parmN + sizeof(parmN))
  33. #   define va_start __va_start
  34. #   if __BUILTIN_VA_ARG_INCR
  35.        /* Sun's convention: */
  36. #      define va_arg(ap,type) ((type*)__builtin_va_arg_incr((type*)ap))[0]
  37. #   endif /* __BUILTIN_VA_ARG_INCR */
  38.  
  39. #elif _I860 && _860_ABI
  40. /************************************************************************
  41.  *                           i860 ABI varargs                            *
  42.  ************************************************************************/
  43.     /* Here, memoflo means the value of r28 at procedure entry. */
  44.     /* end_of_iregs is sp at procedure entry. */
  45. #if _NEW_ABI
  46. #define __TO_WORDS >> 2
  47. #define __ADJUST -(12+8)    /* 12 FP + 8 INT regs. */
  48. #else
  49. #define __TO_WORDS
  50. #define __ADJUST
  51. #endif
  52. #   define __va_start(ap,parm)                 \
  53.       {extern char _ADDRESS_OF_MEMOFLO_AREA[];     \
  54.        extern long _ADDRESS_OF_INT_END_AREA[];      \
  55.        extern int  _PARMBYTES_USEDI##parm[],     \
  56.                _PARMBYTES_USEDF##parm[],     \
  57.                _PARMBYTES_USEDM##parm[];     \
  58.       (ap).ireg_bytes = (int)_PARMBYTES_USEDI##parm __TO_WORDS,\
  59.       (ap).freg_bytes = (int)_PARMBYTES_USEDF##parm __TO_WORDS,\
  60.       (ap).mem_base = (void *)&parm,            \
  61.       (ap).mem_base = _ADDRESS_OF_MEMOFLO_AREA+    \
  62.             (int)_PARMBYTES_USEDM##parm;     \
  63.       (ap).end_of_iregs = _ADDRESS_OF_INT_END_AREA __ADJUST;    \
  64.       }
  65. #   ifndef _VA_LIST_DEFINED
  66. #   define _VA_LIST_DEFINED
  67.     typedef struct {
  68.     unsigned int ireg_bytes;/* How many int regs consumed 'til now? */
  69.     unsigned int freg_bytes;/* How many flt regs consumed 'til now? */
  70. #ifndef _NEW_ABI    
  71.     char *mem_base;         /* Address of overflow area. */
  72.     long *end_of_iregs;  /* End of where we stored int regs. */
  73. #else    
  74.     long *end_of_iregs;  /* End of where we stored int regs. */
  75.     char *mem_base;         /* Address of overflow area. */
  76. #endif  
  77.         } va_list;
  78. #   endif
  79. #   define va_arg(ap,type) \
  80.     (*(type*) _va_arg(&ap,sizeof(type),_INFO(type,0),_INFO(type,2)))
  81.     extern void *_va_arg(va_list *__V, unsigned __len, unsigned __align, int __type);
  82. #ifdef __OLD_VARARGS
  83. #define va_start(ap) {__va_start(ap,_va_alist); ap.ireg_bytes -= sizeof(int) __TO_WORDS;}
  84. #define va_alist _va_alist, ...
  85. #define va_dcl int _va_alist;
  86. #else
  87. #define va_start __va_start
  88. #endif
  89. #elif _I860 || _SGL    /* But NOT ABI */
  90. /************************************************************************
  91.  *                         i860 non-abi varargs                         *
  92.  *               Seagull chip as well                *
  93.  ************************************************************************/
  94.     /* Here, memoflo means the value of sp at procedure entry, */
  95.     /* since memoflo values are stored just above sp. */
  96. #   define __va_start(ap,parm)             \
  97.       {extern long _ADDRESS_OF_MEMOFLO_AREA[];     \
  98.        extern int  _PARMBYTES_USEDI##parm[],     \
  99.                _PARMBYTES_USEDF##parm[],     \
  100.                _PARMBYTES_USEDM##parm[];     \
  101.       (ap).ireg_bytes = (int)_PARMBYTES_USEDI##parm,\
  102.       (ap).freg_bytes = (int)_PARMBYTES_USEDF##parm,\
  103.       (ap).oflo_bytes = (int)_PARMBYTES_USEDM##parm,\
  104.       (ap).mem_base = (void *)&parm,        \
  105.       (ap).mem_base = _ADDRESS_OF_MEMOFLO_AREA;     \
  106.       }
  107. #   ifndef _VA_LIST_DEFINED
  108. #   define _VA_LIST_DEFINED
  109.     typedef struct {
  110.     unsigned int ireg_bytes;/* How many int regs consumed 'til now? */
  111.     unsigned int freg_bytes;/* How many flt regs consumed 'til now? */
  112.     long oflo_bytes;     /* How many bytes have been placed in memory 
  113.                             'til now? */
  114.     long *mem_base;      /* Address of memory oflo area. */
  115.         } va_list;
  116. #   endif
  117. #   define va_arg(ap,type) \
  118.     (*(type*) _va_arg(&ap,sizeof(type),_INFO(type,0),_INFO(type,1)))
  119.     extern void *_va_arg(va_list *__V, unsigned __len, unsigned __align, int __type);
  120. #ifdef __OLD_VARARGS
  121. #define va_start(ap) {__va_start(ap,_va_alist); \
  122.         ap.ireg_bytes -= sizeof(int); ap.freg_bytes -= sizeof(double);}
  123. #define va_alist _va_alist, ...
  124. #define va_dcl int _va_alist;
  125. #else
  126. #define va_start __va_start
  127. #endif
  128. #elif _NAM
  129. /************************************************************************
  130.  *                           _NAM varargs                               *
  131.  ************************************************************************/
  132. #   define __va_start(ap,parmN)\
  133.     (ap=(char *)&parmN + (sizeof(parmN)))
  134. #   define va_start __va_start
  135. #   ifndef _VA_LIST_DEFINED
  136. #   define _VA_LIST_DEFINED
  137.     typedef void *va_list;
  138. #   endif
  139. #   define va_arg(ap, type)\
  140.         ( *(type *) (\
  141.             (char *)(\
  142.                   ap = (char *)ap + sizeof(type)\
  143.                 ) - sizeof(type)\
  144.             )\
  145.     )
  146. #   define va_end(ap)
  147.  
  148. #elif _I386 || _VAX || _I286 || _I8086 || _HOBBIT_L
  149. /************************************************************************
  150.  *            Generic little-endian version 
  151.  ************************************************************************/
  152. #    define __va_start(ap,parmN) (ap=(__vararg_char *)&parmN + \
  153.     (sizeof(parmN)>sizeof(int)?sizeof(parmN):sizeof(int)))
  154. #    define va_start __va_start
  155. #else
  156. /************************************************************************
  157.  *            Generic big-endian version 
  158.  *            (short arguments are assumed right-aligned in a word)
  159.  ************************************************************************/
  160. #    define __va_start(ap,parmN) (ap=(__vararg_char *)&parmN + sizeof(parmN))
  161. #    define va_start __va_start
  162. #endif
  163.  
  164. #ifndef _VA_LIST_DEFINED
  165. #    define _VA_LIST_DEFINED
  166.      typedef void *va_list;
  167. #endif
  168.  
  169. #if _I386 || _VAX || _I286 || _I8086
  170. #   define va_arg(ap, type)\
  171.       ( *(type *) (\
  172.       (__vararg_char *)(\
  173.         ap = (__vararg_char *)ap + \
  174.         ((sizeof(type)+(sizeof(int)-1)) & ~(sizeof(int)-1))\
  175.           ) - ((sizeof(type)+sizeof(int)-1) & ~(sizeof(int)-1))\
  176.      )\
  177.       )
  178. #elif _HOBBIT
  179. #   if _HOBBIT_L
  180. #       define _NNVAARG (-1)  /* Never right align in little-endian */
  181. #   else
  182. #       define _NNVAARG 2 /* Right-align half-words in bit-endian */
  183. #   endif
  184.  
  185.    /* Alignment: doubles on 8-byte boundary, long-doubles on 16-byte boundary*/
  186.    /* Everything else on 4 byte boundary */
  187. #   define _WA_(type) (sizeof(type)==8?8:sizeof(type)==16?16:4)
  188.   /* Size of type as word-multiple*/
  189. #   define _WS_(type) (  (sizeof(type) + 3) & ~3  )
  190. #   define _ALIGN_(x,type) \
  191.     (_WA_(type) <= 4?\
  192.         (long)(x):\
  193.         ((long)(x) + _WA_(type)-1) & ~(_WA_(type)-1))
  194. #   define va_arg(ap, type)\
  195.       ( *(type *) (\
  196.               (__vararg_char *)(\
  197.              ap = (__vararg_char *)_ALIGN_(ap,type) + _WS_(type) \
  198.                       ) - _WS_(type)\
  199.             + (sizeof(type)<=_NNVAARG?4-sizeof(type):0)\
  200.              )\
  201.       )
  202.  
  203. #elif _R3000
  204. /************************************************************************
  205.  *                          MIPS R3000 varargs                          *
  206.  ************************************************************************/
  207. #   define va_arg(ap, type)\
  208.       ( (type *) (\
  209.               (__vararg_char *)(\
  210.                 ap = (__vararg_char *) ((((int)ap +\
  211.                (_INFO(type,0)<=4?3:7))&(_INFO(type,0)<=4?-4:-8))+\
  212.                sizeof(type) ) )\
  213.              )\
  214.       )[-1]
  215.  
  216. #elif !defined va_arg
  217. #   if _IBM370
  218. #       define _NNVAARG 3   /* Largest small struct that is right aligned. */
  219. #   else
  220. #       define _NNVAARG 2
  221. #   endif
  222. #   define va_arg(ap, type)\
  223.       ( *(type *) (\
  224.               (__vararg_char *)(\
  225.                 ap = (__vararg_char *)ap + ((sizeof(type) +3) &~3)\
  226.                   ) - ((sizeof(type) +3) &~3)\
  227.             + (sizeof(type)<=_NNVAARG?4-sizeof(type):0)\
  228.              )\
  229.       )
  230. #endif
  231.  
  232. #define va_end(ap)
  233.  
  234. #ifdef __CPLUSPLUS__
  235. }
  236. #endif
  237. #pragma pop_align_members();
  238. #endif /*_STDARG_H*/
  239.