vx32

Local 9vx git repository for patches.
git clone git://r-36.net/vx32
Log | Files | Refs

gensym.awk (2508B)


      1 #
      2 # Copyright (c) 1994, 1998 University of Utah and the Flux Group.
      3 # All rights reserved.
      4 # 
      5 # This file is part of the Flux OSKit.  The OSKit is free software, also known
      6 # as "open source;" you can redistribute it and/or modify it under the terms
      7 # of the GNU General Public License (GPL), version 2, as published by the Free
      8 # Software Foundation (FSF).  To explore alternate licensing terms, contact
      9 # the University of Utah at csl-dist@cs.utah.edu or +1-801-585-3271.
     10 # 
     11 # The OSKit is distributed in the hope that it will be useful, but WITHOUT ANY
     12 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
     13 # FOR A PARTICULAR PURPOSE.  See the GPL for more details.  You should have
     14 # received a copy of the GPL along with the OSKit; see the file COPYING.  If
     15 # not, write to the FSF, 59 Temple Place #330, Boston, MA 02111-1307, USA.
     16 #
     17 
     18 # This awk program takes a `.sym' file and produces a `.c' file,
     19 # which can then be compiled to assembly language
     20 # and run through a magic sed transformation (see GNUmakerules),
     21 # to produce a `.h' file containing absolute numeric symbol definitions
     22 # suitable for inclusion in assembly language source files and such.
     23 # This way, convenient symbols can be defined based on structure offsets,
     24 # arbitrary C expressions including sizeof() expressions, etc.
     25 #
     26 # Since this mechanism doesn't depend on running a program
     27 # on the machine the code is to run on (the host machine),
     28 # things still work fine during cross-compilation.
     29 #
     30 
     31 BEGIN {
     32 	bogus_printed = "no"
     33 
     34 	# De-privatize all class members so we can take their offsets.
     35 	print "#define class struct";
     36 	print "#define private public";
     37 }
     38 
     39 # Start the bogus function just before the first sym directive,
     40 # so that any #includes higher in the file don't get stuffed inside it.
     41 /^[a-z]/ {
     42 	if (bogus_printed == "no")
     43 	{
     44 		print "void bogus() {";
     45 		bogus_printed = "yes";
     46 	}
     47 }
     48 
     49 # Take an arbitrarily complex C symbol or expression
     50 # and turn it into a simple #define'd constant symbol.
     51 /^expr/ {
     52 	printf "__asm (\"\\n#define %s mAgIc%%0\" : : \"i\" (%s));\n", $2, $3;
     53 }
     54 
     55 # Output a symbol defining the size of a C structure.
     56 /^size/ {
     57 	printf "__asm (\"\\n#define %s mAgIc%%0\" : : \"i\" (sizeof(struct %s)));\n",
     58 		$2, $3;
     59 }
     60 
     61 # Output a symbol defining the byte offset of an element of a C structure.
     62 /^offset/ {
     63 	printf "__asm (\"\\n#define %s mAgIc%%0\" : : \"i\" (&((struct %s*)0)->%s));\n",
     64 		$2, $3, $4;
     65 }
     66 
     67 # Copy through all preprocessor directives.
     68 /^#/ {
     69 	print
     70 }
     71 
     72 END {
     73 	print "}"
     74 }
     75