Article View: comp.sys.sun
Article #8524Re: C++/sparc : problem with <stdarg.h>
From: Michael Joosten
Date: Wed, 12 Jun 1991 19:40
Date: Wed, 12 Jun 1991 19:40
160 lines
6197 bytes
6197 bytes
Well, there are two solutions:
1) Either you cope around the problem, as demonstrated in NIHCL (Class.c)
by renaming the last parameter before the ellipsis to
'__builtin_va_alist'
2) Or you do the Right Thing: Solve the problem. But this is
machine-dependent (better: RISC-dependent) and you have to patch the
cfront sources. I have done it one DECStation a year ago (cfront 1.2) and
for a Pyramid and a SPARC last month for cfront 2.0 .
Short Description:
The MIPS and Sun-SPARC compiler recognize their 'magic word'
(__builtin_va_alist for SPARC, va_alist for MIPS) and emit code to copy
the input window/registers into contigous memory, i.e. the stack, so that
va_arg could extract whatever it wants.
(Sorry, no diffs, I don't have the originals handy...)
First what AT&T forgot: Set the right preprocessor flags in CC. The
(undocumented, of course) variable 'Y' keeps the flags for the
preprocessor, while 'X' is responsible for the 'cc' flags. One should do
this for other machines, too !
Here are my adds in bin/CC:
Y="-Dsun -Dsparc -Dunix -D__BUILTIN_VA_ARG_INCR" # forgotten by AT&T... for SUN4
Don't forget to delete the statement 'Y=' in the block around line 65:
TMPDIR=${TMPDIR-"/usr/tmp"}
TEMPDIR=$TMPDIR/CC.$$
C= EE=0 FON= XON= O=
PON= R= SUF= X= Y= <------------ !!!
DASHR= PLUSI= STRIP=
Z= E=0 OF= P=
Now the changes for stargs:
-------------------------stdarg.h----------------------------------------------
..........
.........
#ifndef va_start
#ifdef pyr
typedef int va_buf[3];
typedef va_buf *va_list;
extern "C" {
extern void _vastart(va_list, char*);
extern char *_vaarg(va_list, int);
}
#define va_start(ap, parmN) {\
va_buf _va;\
_vastart(ap = (va_list)_va, (char *)&parmN + sizeof parmN)
#define va_end(ap) }
#define va_arg(ap, mode) *((mode *)_vaarg(ap, sizeof (mode)))
#else
typedef char *va_list;
#define va_end(ap)
#ifdef sparc
#define va_start(ap, parmN) \
(ap = ((char *) &(parmN) + (((sizeof (parmN) + \
sizeof (int) - 1) / sizeof (int)) * sizeof (int))))
#ifdef __BUILTIN_VA_ARG_INCR
# define va_arg(list,mode) ((mode*)__builtin_va_arg_incr((mode *)list))[0]
#else
# define va_arg(list,mode) ((mode *)(list += sizeof(mode)))[-1]
#endif
extern "C" void *__builtin_va_arg_incr(...);
#else
#ifdef u370
#define va_start(ap, parmN) ap =\
(char *) ((int)&parmN + 2*sizeof(parmN) - 1 & -sizeof(parmN))
#define va_arg(ap, mode) ((mode *)(ap = \
(char *) ((int)ap + 2*sizeof(mode) - 1 & -sizeof(mode))))[-1]
#else
#ifdef hp9000s800
#define va_start(ap, parmN) (ap = (char *)&parmN + sizeof(parmN),(void)va_arg(ap,int))
#define va_arg(ap, mode) ((mode *)(ap = (char *)((int)(ap-sizeof(mode)) & ~(sizeof(mode)-1))))[0]
#else
#define va_start(ap, parmN) ap = (char *)( &parmN+1 )
#define va_arg(ap, mode) ((mode *)(ap += sizeof(mode)))[-1]
#endif
#endif
#endif
#endif
...............
...............
-------------------------------------------------------------------------------
And now a patch for print2.c:
In method fct::dcl_print(), add/replace the following at the end:
.........
.........
else {
// print argument names followed by argument type declarations:
if (body && Cast==0) {
for (nn=at; nn;) {
nn->print();
if (nn=nn->n_list) puttok(CM); else break;
}
#ifdef pyr
if (nargs_known == ELLIPSIS) putstring(",__0va0,__0va1,_
_0va2,__0va3,__0va4,__0va5,__0va6,__0va7,__0va8,__0va9,__0va10,__0va11");
#endif
#ifdef mips
if (nargs_known == ELLIPSIS) {
putst(",va_alist) int va_alist;");
} else
#endif
#ifdef sparc
if (nargs_known == ELLIPSIS) {
putst(",__builtin_va_alist) int __builtin_va_ali
st;");
} else
#endif
putch(')');
}
else
putch(')');
}
}
-------------------------------------------------------------------------------
Good Luck Michael
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Michael Joosten | Tel. : (+49) (+) 5251-284 120 |
| CADLAB | Fax : (+49) (+) 5251-284 140 |
| Bahnhofstr. 32 | E-Mail: joost@cadlab.uucp |
| D-4790 Paderborn | joost@cadlab.cadlab.de |
| FRG | ...!uunet!unido!cadlab!joost |
| | Mass mail to: joost@pbinfo.uni-paderborn.de |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Michael Joosten | Tel. : (+49) (+) 5251-284 120 |
| CADLAB | Fax : (+49) (+) 5251-284 140 |
| Bahnhofstr. 32 | E-Mail: joost@cadlab.uucp |
| D-4790 Paderborn | joost@cadlab.cadlab.de |
| FRG | ...!uunet!unido!cadlab!joost |
| | Mass mail to: joost@pbinfo.uni-paderborn.de |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Technical Details
Message-ID:
<3789@brchh104.bnr.ca>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!cunews!bnrgate!brchh104!brchs1!bnr.ca!rice.edu!sun-spots-requestShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!cunews!bnrgate!brchh104!brchs1!bnr.ca!rice.edu!sun-spots-request From: joost@cadlab.de (Michael Joosten) Newsgroups: comp.sys.sun Subject: Re: C++/sparc : problem with <stdarg.h> Keywords: Source Message-ID: <3789@brchh104.bnr.ca> Date: 12 Jun 91 19:40:00 GMT Sender: news@brchh104.bnr.ca Organization: Sun-Spots Lines: 162 Approved: Sun-Spots@rice.edu X-Original-Date: 6 Jun 91 20:55:26 X-Sun-Spots-Digest: Volume 10, Issue 105, message 7 X-Note: Submissions: sun-spots@rice.edu, Admin: sun-spots-request@rice.edu