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