[OpenBIOS] ANSI

Segher Boessenkool segher at chello.nl
Sun Jun 23 16:47:37 CEST 2002


> There was some discussion on this list on probing compiler
> features before actually using them instead of making vague assumptions
> on what version supports which feature.

I still prefer just requiring gcc-3 (although it currently works "fine"
with 2.95 as well) (except on some 64-bit targets).

> Instead of using a vast amount of autoconf/automake magic, I wrote a
> small perl script that calls the compiler with simple code fragments
> and analyzes these afterwards using nm.

Good :)  The autoevil suite is, well, evil ;)

> This way it is also
> usable when cross compiling. Basically the patch removes types.h
> as it will be autogenerated plus the already known ANSI fixes (mostly
> applying a regexp to change comment style)

Please keep types.h intact, and have it include an auto-types.h or
something like that.  Much easier if you want to bypass the automatic
stuff for whatever reason.

> The configuration script conf.pl also checks for available data types
> and chooses the needed ones to set up the internal structures.
> gcc's TI mode is probed and, if available and needed, it is used.
> 
> Any comments? ;)

Walkthrough :)  :


-CFLAGS = -Wall -W -std=gnu9x -g -O2 # -pg
+CFLAGS  = -Wall -std=gnu9x -g -O2 # -pg

Why remove -W ?  It's soooo useful :)

+CC     = gcc

I removed this for a reason ;)   Just   CC=gcc make   if you need it...

+NM     = nm -t bsd

Not all nm's are GNU nm.  Different nm's outputs are similar enough to
be parseable with a simple regexp.

-paflof.o paflof.s: paflof.c prim.code prep.h dict.xt
+paflof.o paflof.s: paflof.c prim.code prep.h types.h dict.xt

Ah yes, I forgot.  Thanks.

+$CC="gcc -std=gnu9x";
+$NM="nm";

Better just use sh's already-set variables for this.

+sub check_size
+{
+       my $what=shift;
+       my $attr=shift;
+       my $include=shift;
+       
+       # create .test.c file
+       open(F, ">.test.c");

Don't hide temporary files -- if you feel they clobber the source dir,
create them somewhere else (like, /tmp).

+# Check for restrict keyword.
+my $answer="no";
+print("\nChecking whether we can use the restrict keyword (C99)... ");
+print(I "\n#define __RESTRICT__ ");

The C compiler already defines __STDC_VERSION__ to 199901L or greater if
C99 features are supported.

-//#define DEBUG_STACKS
-

Don't remove this, please ;)  #undef it, if you want, but keep all compile-time
flags at the top op file :)

 #include <stdio.h>
 #include <stdlib.h>
+#define __USE_XOPEN_EXTENDED
 #include <unistd.h>
-#include <string.h>
+#define __USE_MISC
 #include <sys/mman.h>
+#include <string.h>
 #include <termios.h>
+#define __USE_POSIX
+#define __USE_POSIX199309
 #include <signal.h>
 #include <fcntl.h>

This isn't exactly making stuff more portable, now is it?

 struct interpreter {
-       cell *restrict data_stack;
-       cell *restrict return_stack;
-       cell *restrict dictionary;
-       char *restrict tib;
-       char *restrict pockets;
+       cell * __RESTRICT__ data_stack;
+       cell * __RESTRICT__ return_stack;
+       cell * __RESTRICT__ dictionary;
+       char * __RESTRICT__ tib;
+       char * __RESTRICT__ pockets;
        void *here;
 };

It would have been simpler had you done
#define restrict
if restrict isn't supported...

+#if 0
+       free(i->data_stack);
+       free(i->return_stack);
+       free(i->dictionary);
+#endif

#if 0  for commenting out code is evil, imho.


Well, I'll get to it.


Segher

-
To unsubscribe: send mail to majordomo at freiburg.linux.de
with 'unsubscribe openbios' in the body of the message
http://www.freiburg.linux.de/OpenBIOS/ - free your system..



More information about the openbios mailing list