Home | History | Annotate | Line # | Download | only in kern
genlintstub.awk revision 1.8.4.1
      1  1.8.4.1   yamt #	$NetBSD: genlintstub.awk,v 1.8.4.1 2006/06/21 15:09:37 yamt Exp $
      2      1.1  perry #
      3      1.1  perry # Copyright 2001 Wasabi Systems, Inc.
      4      1.1  perry # All rights reserved.
      5      1.1  perry #
      6      1.1  perry # Written by Perry E. Metzger for Wasabi Systems, Inc.
      7      1.1  perry #
      8      1.1  perry # Redistribution and use in source and binary forms, with or without
      9      1.1  perry # modification, are permitted provided that the following conditions
     10      1.1  perry # are met:
     11      1.1  perry # 1. Redistributions of source code must retain the above copyright
     12      1.1  perry #    notice, this list of conditions and the following disclaimer.
     13      1.1  perry # 2. Redistributions in binary form must reproduce the above copyright
     14      1.1  perry #    notice, this list of conditions and the following disclaimer in the
     15      1.1  perry #    documentation and/or other materials provided with the distribution.
     16      1.1  perry # 3. All advertising materials mentioning features or use of this software
     17      1.1  perry #    must display the following acknowledgement:
     18      1.1  perry #      This product includes software developed for the NetBSD Project by
     19      1.1  perry #      Wasabi Systems, Inc.
     20      1.1  perry # 4. The name of Wasabi Systems, Inc. may not be used to endorse
     21      1.1  perry #    or promote products derived from this software without specific prior
     22      1.1  perry #    written permission.
     23      1.1  perry #
     24      1.1  perry # THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     25      1.1  perry # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     26      1.1  perry # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     27      1.1  perry # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     28      1.1  perry # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     29      1.1  perry # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     30      1.1  perry # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     31      1.1  perry # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     32      1.1  perry # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     33      1.1  perry # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     34      1.1  perry # POSSIBILITY OF SUCH DAMAGE.
     35      1.1  perry #
     36      1.1  perry 
     37      1.1  perry # This awk script is used by kernel Makefiles to construct C lint
     38      1.1  perry # stubs automatically from properly formatted comments in .S files. In
     39      1.1  perry # general, a .S file should have a special comment for anything with
     40      1.1  perry # something like an ENTRY designation. The special formats are:
     41      1.1  perry #
     42      1.6  perry # /* LINTSTUB: Empty */
     43      1.5  perry # This is used as an indicator that the file contains no stubs at
     44      1.5  perry # all. It generates a /* LINTED */ comment to quiet lint.
     45      1.5  perry #
     46  1.8.4.1   yamt # /* LINTSTUB: Func: type function(args); */
     47      1.3  perry # type must be void, int or long. A return is faked up for ints and longs.
     48  1.8.4.1   yamt # Semicolon is optional.
     49      1.1  perry #
     50      1.1  perry # /* LINTSTUB: Var: type variable, variable; */
     51      1.1  perry # This is often appropriate for assembly bits that the rest of the
     52      1.1  perry # kernel has declared as char * and such, like various bits of
     53      1.1  perry # trampoline code.
     54      1.1  perry #
     55      1.4  perry # /* LINTSTUB: include foo */
     56      1.4  perry # Turns into a literal `#include foo' line in the source. Useful for
     57      1.4  perry # making sure the stubs are checked against system prototypes like
     58      1.4  perry # systm.h, cpu.h, etc., and to make sure that various types are
     59      1.4  perry # properly declared.
     60      1.4  perry #
     61      1.2  perry # /* LINTSTUB: Ignore */
     62      1.2  perry # This is used as an indicator to humans (and possible future
     63      1.2  perry # automatic tools) that the entry is only used internally by other .S
     64      1.2  perry # files and does not need a stub. You want this so you know you
     65      1.2  perry # haven't just forgotten to put a stub in for something and you are
     66      1.2  perry # *deliberately* ignoring it.
     67      1.1  perry 
     68  1.8.4.1   yamt # LINTSTUBs are also accepted inside multiline comments, e.g.
     69  1.8.4.1   yamt #
     70  1.8.4.1   yamt # /*
     71  1.8.4.1   yamt #  * LINTSTUB: include <foo>
     72  1.8.4.1   yamt #  * LINTSTUB: include "bar"
     73  1.8.4.1   yamt #  */
     74  1.8.4.1   yamt #
     75  1.8.4.1   yamt # /*
     76  1.8.4.1   yamt #  * LINTSTUB: Func: type function(args)
     77  1.8.4.1   yamt #  *    Some descriptive comment about the function.
     78  1.8.4.1   yamt #  */
     79  1.8.4.1   yamt 
     80  1.8.4.1   yamt BEGIN {
     81  1.8.4.1   yamt 	printf "/* DO NOT EDIT! DO NOT EDIT! DO NOT EDIT! */\n";
     82  1.8.4.1   yamt 	printf "/* DO NOT EDIT! DO NOT EDIT! DO NOT EDIT! */\n";
     83  1.8.4.1   yamt 	printf "/* This file was automatically generated. */\n";
     84  1.8.4.1   yamt 	printf "/* see genlintstub.awk for details.       */\n";
     85  1.8.4.1   yamt 	printf "/* This file was automatically generated. */\n";
     86  1.8.4.1   yamt 	printf "/* DO NOT EDIT! DO NOT EDIT! DO NOT EDIT! */\n";
     87  1.8.4.1   yamt 	printf "/* DO NOT EDIT! DO NOT EDIT! DO NOT EDIT! */\n";
     88  1.8.4.1   yamt 	printf "\n\n";
     89  1.8.4.1   yamt 
     90  1.8.4.1   yamt 	nerrors = 0;
     91  1.8.4.1   yamt }
     92  1.8.4.1   yamt 
     93  1.8.4.1   yamt function error(msg) {
     94  1.8.4.1   yamt 	printf "ERROR:%d: %s: \"%s\"\n", NR, msg, $0 > "/dev/stderr";
     95  1.8.4.1   yamt 	++nerrors;
     96  1.8.4.1   yamt }
     97  1.8.4.1   yamt 
     98  1.8.4.1   yamt END {
     99  1.8.4.1   yamt 	if (nerrors > 0)
    100  1.8.4.1   yamt 		exit 1;
    101  1.8.4.1   yamt }
    102  1.8.4.1   yamt 
    103  1.8.4.1   yamt 
    104  1.8.4.1   yamt # Check if $i contains semicolon or "*/" comment terminator.  If it
    105  1.8.4.1   yamt # does, strip them and the rest of the word away and return 1 to
    106  1.8.4.1   yamt # signal that no more words on the line are to be processed.
    107  1.8.4.1   yamt 
    108  1.8.4.1   yamt function process_word(i) {
    109  1.8.4.1   yamt 	if ($i ~ /;/) {
    110  1.8.4.1   yamt 		sub(";.*$", "", $i);
    111  1.8.4.1   yamt 		return 1;
    112  1.8.4.1   yamt 	}
    113  1.8.4.1   yamt 	else if ($i ~ /\*\//) {
    114  1.8.4.1   yamt 		sub("\\*\\/.*$", "", $i);
    115  1.8.4.1   yamt 		return 1;
    116  1.8.4.1   yamt 	}
    117  1.8.4.1   yamt 	else if (i == NF)
    118  1.8.4.1   yamt 		return 1;
    119  1.8.4.1   yamt 	else
    120  1.8.4.1   yamt 		return 0;
    121  1.8.4.1   yamt }
    122  1.8.4.1   yamt 
    123  1.8.4.1   yamt 
    124  1.8.4.1   yamt /^[\/ ]\* LINTSTUB: Func:/ {
    125  1.8.4.1   yamt 	if (NF < 5) {
    126  1.8.4.1   yamt 		error("bad 'Func' declaration");
    127      1.5  perry 		next;
    128      1.5  perry 	}
    129  1.8.4.1   yamt 	if (($4 == "int") || ($4 == "long"))
    130  1.8.4.1   yamt 		retflag = 1;
    131  1.8.4.1   yamt 	else if ($4 == "void")
    132  1.8.4.1   yamt 		retflag = 0;
    133  1.8.4.1   yamt 	else {
    134  1.8.4.1   yamt 		error("type is not int, long or void");
    135      1.1  perry 		next;
    136      1.1  perry 	}
    137  1.8.4.1   yamt 	printf "/* ARGSUSED */\n%s", $4;
    138  1.8.4.1   yamt 	for (i = 5; i <= NF; ++i) {
    139  1.8.4.1   yamt 		if (process_word(i)) {
    140  1.8.4.1   yamt 			printf " %s\n", $i;
    141  1.8.4.1   yamt 			break;
    142      1.1  perry 		}
    143  1.8.4.1   yamt 		else
    144  1.8.4.1   yamt 			printf " %s", $i;
    145      1.1  perry 	}
    146  1.8.4.1   yamt 	print "{";
    147  1.8.4.1   yamt 	if (retflag)
    148  1.8.4.1   yamt 		print "\treturn(0);";
    149  1.8.4.1   yamt 	print "}\n";
    150  1.8.4.1   yamt 	next;
    151  1.8.4.1   yamt }
    152  1.8.4.1   yamt 
    153  1.8.4.1   yamt /^[\/ ]\* LINTSTUB: Var:/ {
    154  1.8.4.1   yamt 	if (NF < 4) {
    155  1.8.4.1   yamt 		error("bad 'Var' declaration");
    156      1.4  perry 		next;
    157      1.1  perry 	}
    158  1.8.4.1   yamt 	for (i = 4; i <= NF; ++i) {
    159  1.8.4.1   yamt 		if (process_word(i)) {
    160  1.8.4.1   yamt 			printf " %s;\n", $i;
    161  1.8.4.1   yamt 			break;
    162  1.8.4.1   yamt 		}
    163  1.8.4.1   yamt 		else
    164  1.8.4.1   yamt 			printf " %s", $i;
    165      1.1  perry 	}
    166  1.8.4.1   yamt 	next;
    167  1.8.4.1   yamt }
    168      1.1  perry 
    169  1.8.4.1   yamt /^[\/ ]\* LINTSTUB: include[ \t]+/ {
    170  1.8.4.1   yamt 	if (NF < 4) {
    171  1.8.4.1   yamt 		error("bad 'include' directive");
    172  1.8.4.1   yamt 		next;
    173      1.1  perry 	}
    174  1.8.4.1   yamt 	sub("\\*\\/.*$", "", $4);
    175  1.8.4.1   yamt 	printf "#include %s\n", $4;
    176  1.8.4.1   yamt 	next;
    177  1.8.4.1   yamt }
    178  1.8.4.1   yamt 
    179  1.8.4.1   yamt /^[\/ ]\* LINTSTUB: Empty($|[^_0-9A-Za-z])/ {
    180  1.8.4.1   yamt 	printf "/* LINTED (empty translation unit) */\n";
    181  1.8.4.1   yamt 	next;
    182  1.8.4.1   yamt }
    183  1.8.4.1   yamt 
    184  1.8.4.1   yamt /^[\/ ]\* LINTSTUB: Ignore($|[^_0-9A-Za-z])/ {
    185  1.8.4.1   yamt 	next;
    186  1.8.4.1   yamt }
    187  1.8.4.1   yamt 
    188  1.8.4.1   yamt /^[\/ ]\* LINTSTUBS:/ {
    189  1.8.4.1   yamt 	error("LINTSTUB, not LINTSTUBS");
    190  1.8.4.1   yamt 	next;
    191  1.8.4.1   yamt }
    192  1.8.4.1   yamt 
    193  1.8.4.1   yamt /^[\/ ]\* LINTSTUB:/ {
    194  1.8.4.1   yamt 	error("unrecognized");
    195  1.8.4.1   yamt 	next;
    196  1.8.4.1   yamt }
    197