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