genlintstub.awk revision 1.4.2.2 1 # $NetBSD: genlintstub.awk,v 1.4.2.2 2001/06/21 20:06:43 nathanw 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, int or long. A return is faked up for ints and longs.
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: include foo */
51 # Turns into a literal `#include foo' line in the source. Useful for
52 # making sure the stubs are checked against system prototypes like
53 # systm.h, cpu.h, etc., and to make sure that various types are
54 # properly declared.
55 #
56 # /* LINTSTUB: Ignore */
57 # This is used as an indicator to humans (and possible future
58 # automatic tools) that the entry is only used internally by other .S
59 # files and does not need a stub. You want this so you know you
60 # haven't just forgotten to put a stub in for something and you are
61 # *deliberately* ignoring it.
62
63 BEGIN {
64 printf "/* DO NOT EDIT! DO NOT EDIT! DO NOT EDIT! */\n";
65 printf "/* DO NOT EDIT! DO NOT EDIT! DO NOT EDIT! */\n";
66 printf "/* This file was automatically generated. */\n";
67 printf "/* see genasmstub.awk for details. */\n";
68 printf "/* This file was automatically generated. */\n";
69 printf "/* DO NOT EDIT! DO NOT EDIT! DO NOT EDIT! */\n";
70 printf "/* DO NOT EDIT! DO NOT EDIT! DO NOT EDIT! */\n";
71 printf "\n\n";
72 }
73
74
75 /^\/\* LINTSTUB: Func:.*\)[ \t]*[;]?[ \t]+\*\/[ \t]*$/ {
76 if (($4 == "int") || ($4 == "long"))
77 retflag = 1;
78 else if ($4 == "void")
79 retflag = 0;
80 else {
81 printf "ERROR: %s: type is not int or void\n", $4 > "/dev/stderr";
82 exit 1;
83 }
84 print "/* ARGSUSED */";
85 for (i = 4; i < NF; i++) {
86 if (i != (NF - 1))
87 printf "%s ", $i;
88 else {
89 sub(";$", "", $i);
90 printf "%s\n", $i;
91 }
92 }
93 print "{";
94 if (retflag)
95 print "\treturn(0);"
96 print "}\n";
97 next;
98 }
99
100 /^\/\* LINTSTUB: Func:/ {
101 printf "ERROR: bad function declaration: %s\n", $0 > "/dev/stderr";
102 exit 1;
103 }
104
105 /^\/\* LINTSTUB: Var:.*[ \t]+\*\/[ \t]*$/ {
106 for (i = 4; i < NF; i++) {
107 if (i != (NF - 1))
108 printf "%s ", $i;
109 else {
110 gsub(";$", "", $i);
111 printf "%s;\n\n", $i;
112 }
113 }
114 next;
115 }
116
117 /^\/\* LINTSTUB: Var:/ {
118 printf "ERROR: bad variable declaration: %s\n", $0 > "/dev/stderr";
119 exit 1;
120 }
121
122 /^\/\* LINTSTUB: include[ \t]+.*\*\/[ \t]*$/ {
123 printf "#include %s\n", $4;
124 next;
125 }
126
127 /^\/\* LINTSTUB: Ignore.*\*\/[ \t]*$/ { next; }
128
129 /^\/\* LINTSTUB: Ignore/ {
130 printf "ERROR: bad ignore declaration: %s\n", $0 > "/dev/stderr";
131 exit 1;
132 }
133
134 /^\/\* LINTSTUBS:/ {
135 printf "ERROR: LINTSTUB, not LINTSTUBS: %s\n", $0 > "/dev/stderr";
136 exit 1;
137 }
138
139 /^\/\* LINTSTUB:/ {
140 printf "ERROR: bad declaration: %s\n", $0 > "/dev/stderr";
141 exit 1;
142 }
143