1 # $NetBSD: genlintstub.awk,v 1.9 2005/12/11 12:24:29 christos Exp $
3 # Copyright 2001 Wasabi Systems, Inc.
6 # Written by Perry E. Metzger for Wasabi Systems, Inc.
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
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
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.
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:
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.
46 # /* LINTSTUB: Func: type function(args); */
47 # type must be void, int or long. A return is faked up for ints and longs.
48 # Semicolon is optional.
50 # /* LINTSTUB: Var: type variable, variable; */
51 # This is often appropriate for assembly bits that the rest of the
52 # kernel has declared as char * and such, like various bits of
55 # /* LINTSTUB: include foo */
56 # Turns into a literal `#include foo' line in the source. Useful for
57 # making sure the stubs are checked against system prototypes like
58 # systm.h, cpu.h, etc., and to make sure that various types are
61 # /* LINTSTUB: Ignore */
62 # This is used as an indicator to humans (and possible future
63 # automatic tools) that the entry is only used internally by other .S
64 # files and does not need a stub. You want this so you know you
65 # haven't just forgotten to put a stub in for something and you are
66 # *deliberately* ignoring it.
68 # LINTSTUBs are also accepted inside multiline comments, e.g.
71 # * LINTSTUB: include <foo>
72 # * LINTSTUB: include "bar"
76 # * LINTSTUB: Func: type function(args)
77 # * Some descriptive comment about the function.
81 printf "/* DO NOT EDIT! DO NOT EDIT! DO NOT EDIT! */\n";
82 printf "/* DO NOT EDIT! DO NOT EDIT! DO NOT EDIT! */\n";
83 printf "/* This file was automatically generated. */\n";
84 printf "/* see genlintstub.awk for details. */\n";
85 printf "/* This file was automatically generated. */\n";
86 printf "/* DO NOT EDIT! DO NOT EDIT! DO NOT EDIT! */\n";
87 printf "/* DO NOT EDIT! DO NOT EDIT! DO NOT EDIT! */\n";
94 printf "ERROR:%d: %s: \"%s\"\n", NR, msg
, $
0 > "/dev/stderr";
104 # Check if $i contains semicolon or "*/" comment terminator. If it
105 # does, strip them and the rest of the word away and return 1 to
106 # signal that no more words on the line are to be processed.
108 function process_word
(i
) {
113 else if ($i ~
/\
*\
//) {
114 sub("\\*\\/.*$", "", $i
);
124 /^
[\
/ ]\
* LINTSTUB
: Func
:/ {
126 error
("bad 'Func' declaration");
129 if (($
4 ==
"int") || ($
4 ==
"long"))
131 else if ($
4 ==
"void")
134 error
("type is not int, long or void");
137 printf "/* ARGSUSED */\n%s", $
4;
138 for (i =
5; i
<=
NF; ++i
) {
139 if (process_word
(i
)) {
148 print "\treturn(0);";
153 /^
[\
/ ]\
* LINTSTUB
: Var
:/ {
155 error
("bad 'Var' declaration");
158 for (i =
4; i
<=
NF; ++i
) {
159 if (process_word
(i
)) {
169 /^
[\
/ ]\
* LINTSTUB
: include
[ \t]+/ {
171 error
("bad 'include' directive");
174 sub("\\*\\/.*$", "", $
4);
175 printf "#include %s\n", $
4;
179 /^
[\
/ ]\
* LINTSTUB
: Empty
($
|[^_0
-9A
-Za
-z
])/ {
180 printf "/* LINTED (empty translation unit) */\n";
184 /^
[\
/ ]\
* LINTSTUB
: Ignore
($
|[^_0
-9A
-Za
-z
])/ {
188 /^
[\
/ ]\
* LINTSTUBS
:/ {
189 error
("LINTSTUB, not LINTSTUBS");
193 /^
[\
/ ]\
* LINTSTUB
:/ {
194 error
("unrecognized");