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