[comp.lang.c++] stdarg on sparc and PMAX; diffs for CC.c

keith@csli.Stanford.EDU (Keith Nishihara) (12/14/89)

steve@maths.warwick.ac.uk (Steve Rumsby) writes:
>Yes, it's possible to make it work. There are two things you need to do,
>one to the code itself, and one to the CC script (or to the output of
>CC -Fc before feeding to cc itself if you can't hack CC).

>1) To the code using stdargs:

>First, add this to the beginning, or in a header file that you include,
>or somewhere:
>#define	SA(x)	__builtin_va_alist
>Then change code like this:
>void
>foo(int x, char *SA(p), ...)
>{
>	va_list ap;
>	if(!SA(p))
>		return;
>	va_start(ap, SA(p));
>ie. change ALL occurances of the last named argument to SA(name).
>2) Changes to CC itself:
>   Cfront in going to mangle the __builtin_va_alist parameter name, so
>   we need to unmangle it again so that the C compiler gets to see it.
>   Do this to the output of cfront:
>	sed -e 's/__0__builtin_va_alist/__builtin_va_alist/g'

It should be noted that the same fix is required for Pmax
(Decstation 3100) users, except that __builtin_va_list is replaced
by `va_alist'.

For users of InterViews 2.6 CC.c driver, here are some diffs which
apply the filtering phase automatically after the translation phase.
Similar hacks could obviously be applied for other CC.c drivers.
Note that I am using cfront 1.2 - your name mangling might be different.

I use the following definition for my last known argument, in place of SA():
#define VAFIX(arg)      _vafix_

Neil/.		Neil%teleos.com@ai.sri.com	...decwrl!argosy!teleos!neil

*** CC.c	Tue Dec 12 13:56:08 1989
--- CC.c.old	Tue Dec 12 13:20:24 1989
***************
*** 63,70 ****
  String CC_munch = "nmunch";
  int CC_munch_relink = 0;
  
- boolean CC_fix_va = false;
- 
  #else
  
  boolean CC_gnu = false;
--- 63,68 ----
***************
*** 81,89 ****
  int CC_munch_relink = 1;
  #endif
  
- boolean CC_fix_va = true;
- String CC_fix_va_filter = "/bin/sed";
- 
  #endif
  
  #if defined(sgi)
--- 79,84 ----
***************
*** 166,172 ****
  
  extern String getenv();
  
! char fileName[FILENAMESIZE], filterName[FILENAMESIZE], fixName[FILENAMESIZE];
  char cppName[FILENAMESIZE], frontEndName[FILENAMESIZE];
  char destname[FILENAMESIZE];
  char objName[FILENAMESIZE];
--- 161,167 ----
  
  extern String getenv();
  
! char fileName[FILENAMESIZE], filterName[FILENAMESIZE];
  char cppName[FILENAMESIZE], frontEndName[FILENAMESIZE];
  char destname[FILENAMESIZE];
  char objName[FILENAMESIZE];
***************
*** 582,589 ****
  			CC_mv = v;
  		    } else if (opt("-CC_cp")) {
  			CC_cp = v;
- 		    } else if (opt("-CC_fix_va_filter")) {
- 			CC_fix_va_filter = v;
  		    } else if (opt("-CC_grep")) {
  			CC_grep = v;
  		    }
--- 577,582 ----
***************
*** 975,988 ****
      if (status != 0) {
  	return status;
      }
- 
-     if(CC_fix_va)
-     {
- 	status = FixVarargsPhase(frontEndName, tail);
- 	if(status != 0)
- 	    return status;
-     }
- 
      if (plusIflag && (!Fflag || suffixFlag)) {
  	status = FilterPhase(frontEndName, tail);
  	if (status != 0) {
--- 968,973 ----
***************
*** 1043,1076 ****
  	);
  	status = execute(CC_translator, commandv, in, frontEndDesc);
  	myclose(frontEndDesc);
-     }
-     return status;
- }
- 
- int FixVarargsPhase(fullPathName, tail)
- String fullPathName;
- String tail;
- {
-     int status;
-     int fixDesc;
- 
-     fixDesc = MakeTmpFile(fixName, "fix");
-     initexec(CC_fix_va_filter);
-     command = AddArg(command, "-e");
-     command = AddArg(command, "s/_au0__vafix_/va_alist/g");
-     command = AddArg(command, fullPathName);
-     status = execute(CC_fix_va_filter, commandv, fileno(stdin), fixDesc);
-     if(status != 0)
- 	Warning("Fix varargs phase error", nil);
-     else
-     {
- 	myclose(fixDesc);
- 	initexec("mv");
- 	command = AddArg(command, fixName);
- 	command = AddArg(command, frontEndName);
- 	status = execute(CC_mv, commandv, fileno(stdin), fileno(stdout));
- 	if(status != 0)
- 	    perror(status);
      }
      return status;
  }
--- 1028,1033 ----