genlintstub.awk revision 1.1 1 # $NetBSD: genlintstub.awk,v 1.1 2001/05/15 22:23:09 perry 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: Func: type function(args) */
43 # type must be void or int. A return is faked up for ints.
44 #
45 # /* LINTSTUB: Var: type variable, variable; */
46 # This is often appropriate for assembly bits that the rest of the
47 # kernel has declared as char * and such, like various bits of
48 # trampoline code.
49 #
50 # /* LINTSTUB: I */
51 # "I" is for "Ignore" -- this is used as an indicator to humans (and
52 # possible future automatic tools) that the entry is only used
53 # internally by other .S files and does not need a stub. You want this
54 # so you know you haven't just forgotten to put a stub in for
55 # something and you are *deliberately* ignoring it.
56
57 BEGIN {
58 printf "/* DO NOT EDIT! DO NOT EDIT! DO NOT EDIT! */\n";
59 printf "/* DO NOT EDIT! DO NOT EDIT! DO NOT EDIT! */\n";
60 printf "/* This file was automatically generated. */\n";
61 printf "/* see genasmstub.awk for details. */\n";
62 printf "/* This file was automatically generated. */\n";
63 printf "/* DO NOT EDIT! DO NOT EDIT! DO NOT EDIT! */\n";
64 printf "/* DO NOT EDIT! DO NOT EDIT! DO NOT EDIT! */\n";
65 # Do we really want this? I figure it will catch a lot
66 # of stuff early on (while processing the same file
67 # rather than in a later lint pass) and is thus worth it.
68 printf "\n#include <sys/systm.h>\n\n\n";
69 }
70
71
72 /^\/\* LINTSTUB: Func:.*\)[ \t]*[;]?[ \t]+\*\/[ \t]*$/ {
73 if ($4 == "int")
74 retflag = 1;
75 else if ($4 == "void")
76 retflag = 0;
77 else {
78 printf "ERROR: %s: type is not int or void\n", $4 > "/dev/stderr";
79 exit 1;
80 }
81 print "/* ARGSUSED */";
82 for (i = 4; i < NF; i++) {
83 if (i != (NF - 1))
84 printf "%s ", $i;
85 else {
86 sub(";$", "", $i);
87 printf "%s\n", $i;
88 }
89 }
90 print "{";
91 if (retflag)
92 print "\treturn(0);"
93 print "}\n";
94 next;
95 }
96
97 /^\/\* LINTSTUB: Func:/ {
98 printf "ERROR: bad function declaration: %s\n", $0 > "/dev/stderr";
99 exit 1;
100 }
101
102 /^\/\* LINTSTUB: Var:.*[ \t]+\*\/[ \t]*$/ {
103 for (i = 4; i < NF; i++) {
104 if (i != (NF - 1))
105 printf "%s ", $i;
106 else {
107 gsub(";$", "", $i);
108 printf "%s;\n\n", $i;
109 }
110 }
111 next;
112 }
113
114 /^\/\* LINTSTUB: Var:/ {
115 printf "ERROR: bad variable declaration: %s\n", $0 > "/dev/stderr";
116 exit 1;
117 }
118
119 /^\/\* LINTSTUB: I.*\*\/[ \t]*$/ { next; }
120
121 /^\/\* LINTSTUB: I/ {
122 printf "ERROR: bad ignore declaration: %s\n", $0 > "/dev/stderr";
123 exit 1;
124 }
125
126 /^\/\* LINTSTUBS:/ {
127 printf "ERROR: LINTSTUB, not LINTSTUBS: %s\n", $0 > "/dev/stderr";
128 exit 1;
129 }
130
131 /^\/\* LINTSTUB:/ {
132 printf "ERROR: bad declaration: %s\n", $0 > "/dev/stderr";
133 exit 1;
134 }
135