stdarg.h revision 139825
1139825Simp/*-
296317Sobrien * Copyright (c) 2002 David E. O'Brien.  All rights reserved.
380708Sjake * Copyright (c) 1992, 1993
480708Sjake *	The Regents of the University of California.  All rights reserved.
580708Sjake *
680708Sjake * This software was developed by the Computer Systems Engineering group
780708Sjake * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
880708Sjake * contributed to Berkeley.
980708Sjake *
1080708Sjake * All advertising materials mentioning features or use of this software
1180708Sjake * must display the following acknowledgement:
1280708Sjake *	This product includes software developed by the University of
1380708Sjake *	California, Lawrence Berkeley Laboratory.
1480708Sjake *
1580708Sjake * Redistribution and use in source and binary forms, with or without
1680708Sjake * modification, are permitted provided that the following conditions
1780708Sjake * are met:
1880708Sjake * 1. Redistributions of source code must retain the above copyright
1980708Sjake *    notice, this list of conditions and the following disclaimer.
2080708Sjake * 2. Redistributions in binary form must reproduce the above copyright
2180708Sjake *    notice, this list of conditions and the following disclaimer in the
2280708Sjake *    documentation and/or other materials provided with the distribution.
2380708Sjake *
2480708Sjake * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2580708Sjake * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2680708Sjake * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2780708Sjake * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2880708Sjake * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2980708Sjake * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3080708Sjake * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3180708Sjake * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3280708Sjake * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3380708Sjake * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3480708Sjake * SUCH DAMAGE.
3580708Sjake *
3696317Sobrien *	@(#)stdarg.h	8.2 (Berkeley) 9/27/93
3796317Sobrien *	$NetBSD: stdarg.h,v 1.11 2000/07/23 21:36:56 mycroft Exp $
3880708Sjake * $FreeBSD: head/sys/sparc64/include/stdarg.h 139825 2005-01-07 02:29:27Z imp $
3980708Sjake */
4080708Sjake
4180708Sjake#ifndef _MACHINE_STDARG_H_
4280708Sjake#define	_MACHINE_STDARG_H_
4380708Sjake
44104583Smike#include <sys/cdefs.h>
45102227Smike#include <sys/_types.h>
4680708Sjake
47104583Smike#ifndef _VA_LIST_DECLARED
48104583Smike#define	_VA_LIST_DECLARED
49102227Smiketypedef	__va_list	va_list;
50104583Smike#endif
5180708Sjake
5296317Sobrien#if defined(__GNUC__) && (__GNUC__ == 2 && __GNUC_MINOR__ > 95 || __GNUC__ >= 3)
5396317Sobrien
5480708Sjake#define	va_start(ap, last) \
5596317Sobrien	__builtin_stdarg_start((ap), (last))
5696317Sobrien
5796317Sobrien#define	va_arg(ap, type) \
5896317Sobrien	__builtin_va_arg((ap), type)
5996317Sobrien
60104583Smike#if __ISO_C_VISIBLE >= 1999
61103526Smike#define	va_copy(dest, src) \
62103526Smike	__builtin_va_copy((dest), (src))
63104583Smike#endif
64103526Smike
6596317Sobrien#define	va_end(ap) \
6696317Sobrien	__builtin_va_end(ap)
6796317Sobrien
6896317Sobrien#else	/* ! __GNUC__ post GCC 2.95 */
6996317Sobrien
7096317Sobrien#define	va_start(ap, last) \
7180708Sjake	(__builtin_next_arg(last), (ap) = (va_list)__builtin_saveregs())
7280708Sjake
7380708Sjake#define va_end(ap)
7480708Sjake
7580708Sjake#define	__va_arg8(ap, type) \
7680708Sjake	(*(type *)(void *)((ap) += 8, (ap) - 8))
7780708Sjake#define	__va_arg16(ap, type) \
7880708Sjake	(*(type *)(void *)((ap) = (va_list)(((unsigned long)(ap) + 31) & -16),\
7980708Sjake			   (ap) - 16))
8080708Sjake#define	__va_int(ap, type) \
8180708Sjake	(*(type *)(void *)((ap) += 8, (ap) - sizeof(type)))
8280708Sjake
8380708Sjake#define	__REAL_TYPE_CLASS	8
8480708Sjake#define	__RECORD_TYPE_CLASS	12
8580708Sjake#define va_arg(ap, type) \
8680708Sjake	(__builtin_classify_type(*(type *)0) == __REAL_TYPE_CLASS ?	\
8780708Sjake	 (__alignof__(type) == 16 ? __va_arg16(ap, type) :		\
8880708Sjake	  __va_arg8(ap, type)) :					\
8980708Sjake	 (__builtin_classify_type(*(type *)0) < __RECORD_TYPE_CLASS ?	\
9080708Sjake	  __va_int(ap, type) :						\
9180708Sjake	  (sizeof(type) <= 8 ? __va_arg8(ap, type) :			\
9280708Sjake	   (sizeof(type) <= 16 ? __va_arg16(ap, type) :			\
9380708Sjake	    *__va_arg8(ap, type *)))))
9480708Sjake
9596317Sobrien#endif /* __GNUC__ post GCC 2.95 */
9696317Sobrien
9780708Sjake#endif /* !_MACHINE_STDARG_H_ */
98