genlintstub.awk revision 1.4.2.2 1 1.4.2.2 nathanw # $NetBSD: genlintstub.awk,v 1.4.2.2 2001/06/21 20:06:43 nathanw Exp $
2 1.4.2.2 nathanw #
3 1.4.2.2 nathanw # Copyright 2001 Wasabi Systems, Inc.
4 1.4.2.2 nathanw # All rights reserved.
5 1.4.2.2 nathanw #
6 1.4.2.2 nathanw # Written by Perry E. Metzger for Wasabi Systems, Inc.
7 1.4.2.2 nathanw #
8 1.4.2.2 nathanw # Redistribution and use in source and binary forms, with or without
9 1.4.2.2 nathanw # modification, are permitted provided that the following conditions
10 1.4.2.2 nathanw # are met:
11 1.4.2.2 nathanw # 1. Redistributions of source code must retain the above copyright
12 1.4.2.2 nathanw # notice, this list of conditions and the following disclaimer.
13 1.4.2.2 nathanw # 2. Redistributions in binary form must reproduce the above copyright
14 1.4.2.2 nathanw # notice, this list of conditions and the following disclaimer in the
15 1.4.2.2 nathanw # documentation and/or other materials provided with the distribution.
16 1.4.2.2 nathanw # 3. All advertising materials mentioning features or use of this software
17 1.4.2.2 nathanw # must display the following acknowledgement:
18 1.4.2.2 nathanw # This product includes software developed for the NetBSD Project by
19 1.4.2.2 nathanw # Wasabi Systems, Inc.
20 1.4.2.2 nathanw # 4. The name of Wasabi Systems, Inc. may not be used to endorse
21 1.4.2.2 nathanw # or promote products derived from this software without specific prior
22 1.4.2.2 nathanw # written permission.
23 1.4.2.2 nathanw #
24 1.4.2.2 nathanw # THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
25 1.4.2.2 nathanw # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 1.4.2.2 nathanw # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27 1.4.2.2 nathanw # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
28 1.4.2.2 nathanw # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 1.4.2.2 nathanw # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 1.4.2.2 nathanw # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 1.4.2.2 nathanw # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 1.4.2.2 nathanw # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 1.4.2.2 nathanw # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 1.4.2.2 nathanw # POSSIBILITY OF SUCH DAMAGE.
35 1.4.2.2 nathanw #
36 1.4.2.2 nathanw
37 1.4.2.2 nathanw # This awk script is used by kernel Makefiles to construct C lint
38 1.4.2.2 nathanw # stubs automatically from properly formatted comments in .S files. In
39 1.4.2.2 nathanw # general, a .S file should have a special comment for anything with
40 1.4.2.2 nathanw # something like an ENTRY designation. The special formats are:
41 1.4.2.2 nathanw #
42 1.4.2.2 nathanw # /* LINTSTUB: Func: type function(args) */
43 1.4.2.2 nathanw # type must be void, int or long. A return is faked up for ints and longs.
44 1.4.2.2 nathanw #
45 1.4.2.2 nathanw # /* LINTSTUB: Var: type variable, variable; */
46 1.4.2.2 nathanw # This is often appropriate for assembly bits that the rest of the
47 1.4.2.2 nathanw # kernel has declared as char * and such, like various bits of
48 1.4.2.2 nathanw # trampoline code.
49 1.4.2.2 nathanw #
50 1.4.2.2 nathanw # /* LINTSTUB: include foo */
51 1.4.2.2 nathanw # Turns into a literal `#include foo' line in the source. Useful for
52 1.4.2.2 nathanw # making sure the stubs are checked against system prototypes like
53 1.4.2.2 nathanw # systm.h, cpu.h, etc., and to make sure that various types are
54 1.4.2.2 nathanw # properly declared.
55 1.4.2.2 nathanw #
56 1.4.2.2 nathanw # /* LINTSTUB: Ignore */
57 1.4.2.2 nathanw # This is used as an indicator to humans (and possible future
58 1.4.2.2 nathanw # automatic tools) that the entry is only used internally by other .S
59 1.4.2.2 nathanw # files and does not need a stub. You want this so you know you
60 1.4.2.2 nathanw # haven't just forgotten to put a stub in for something and you are
61 1.4.2.2 nathanw # *deliberately* ignoring it.
62 1.4.2.2 nathanw
63 1.4.2.2 nathanw BEGIN {
64 1.4.2.2 nathanw printf "/* DO NOT EDIT! DO NOT EDIT! DO NOT EDIT! */\n";
65 1.4.2.2 nathanw printf "/* DO NOT EDIT! DO NOT EDIT! DO NOT EDIT! */\n";
66 1.4.2.2 nathanw printf "/* This file was automatically generated. */\n";
67 1.4.2.2 nathanw printf "/* see genasmstub.awk for details. */\n";
68 1.4.2.2 nathanw printf "/* This file was automatically generated. */\n";
69 1.4.2.2 nathanw printf "/* DO NOT EDIT! DO NOT EDIT! DO NOT EDIT! */\n";
70 1.4.2.2 nathanw printf "/* DO NOT EDIT! DO NOT EDIT! DO NOT EDIT! */\n";
71 1.4.2.2 nathanw printf "\n\n";
72 1.4.2.2 nathanw }
73 1.4.2.2 nathanw
74 1.4.2.2 nathanw
75 1.4.2.2 nathanw /^\/\* LINTSTUB: Func:.*\)[ \t]*[;]?[ \t]+\*\/[ \t]*$/ {
76 1.4.2.2 nathanw if (($4 == "int") || ($4 == "long"))
77 1.4.2.2 nathanw retflag = 1;
78 1.4.2.2 nathanw else if ($4 == "void")
79 1.4.2.2 nathanw retflag = 0;
80 1.4.2.2 nathanw else {
81 1.4.2.2 nathanw printf "ERROR: %s: type is not int or void\n", $4 > "/dev/stderr";
82 1.4.2.2 nathanw exit 1;
83 1.4.2.2 nathanw }
84 1.4.2.2 nathanw print "/* ARGSUSED */";
85 1.4.2.2 nathanw for (i = 4; i < NF; i++) {
86 1.4.2.2 nathanw if (i != (NF - 1))
87 1.4.2.2 nathanw printf "%s ", $i;
88 1.4.2.2 nathanw else {
89 1.4.2.2 nathanw sub(";$", "", $i);
90 1.4.2.2 nathanw printf "%s\n", $i;
91 1.4.2.2 nathanw }
92 1.4.2.2 nathanw }
93 1.4.2.2 nathanw print "{";
94 1.4.2.2 nathanw if (retflag)
95 1.4.2.2 nathanw print "\treturn(0);"
96 1.4.2.2 nathanw print "}\n";
97 1.4.2.2 nathanw next;
98 1.4.2.2 nathanw }
99 1.4.2.2 nathanw
100 1.4.2.2 nathanw /^\/\* LINTSTUB: Func:/ {
101 1.4.2.2 nathanw printf "ERROR: bad function declaration: %s\n", $0 > "/dev/stderr";
102 1.4.2.2 nathanw exit 1;
103 1.4.2.2 nathanw }
104 1.4.2.2 nathanw
105 1.4.2.2 nathanw /^\/\* LINTSTUB: Var:.*[ \t]+\*\/[ \t]*$/ {
106 1.4.2.2 nathanw for (i = 4; i < NF; i++) {
107 1.4.2.2 nathanw if (i != (NF - 1))
108 1.4.2.2 nathanw printf "%s ", $i;
109 1.4.2.2 nathanw else {
110 1.4.2.2 nathanw gsub(";$", "", $i);
111 1.4.2.2 nathanw printf "%s;\n\n", $i;
112 1.4.2.2 nathanw }
113 1.4.2.2 nathanw }
114 1.4.2.2 nathanw next;
115 1.4.2.2 nathanw }
116 1.4.2.2 nathanw
117 1.4.2.2 nathanw /^\/\* LINTSTUB: Var:/ {
118 1.4.2.2 nathanw printf "ERROR: bad variable declaration: %s\n", $0 > "/dev/stderr";
119 1.4.2.2 nathanw exit 1;
120 1.4.2.2 nathanw }
121 1.4.2.2 nathanw
122 1.4.2.2 nathanw /^\/\* LINTSTUB: include[ \t]+.*\*\/[ \t]*$/ {
123 1.4.2.2 nathanw printf "#include %s\n", $4;
124 1.4.2.2 nathanw next;
125 1.4.2.2 nathanw }
126 1.4.2.2 nathanw
127 1.4.2.2 nathanw /^\/\* LINTSTUB: Ignore.*\*\/[ \t]*$/ { next; }
128 1.4.2.2 nathanw
129 1.4.2.2 nathanw /^\/\* LINTSTUB: Ignore/ {
130 1.4.2.2 nathanw printf "ERROR: bad ignore declaration: %s\n", $0 > "/dev/stderr";
131 1.4.2.2 nathanw exit 1;
132 1.4.2.2 nathanw }
133 1.4.2.2 nathanw
134 1.4.2.2 nathanw /^\/\* LINTSTUBS:/ {
135 1.4.2.2 nathanw printf "ERROR: LINTSTUB, not LINTSTUBS: %s\n", $0 > "/dev/stderr";
136 1.4.2.2 nathanw exit 1;
137 1.4.2.2 nathanw }
138 1.4.2.2 nathanw
139 1.4.2.2 nathanw /^\/\* LINTSTUB:/ {
140 1.4.2.2 nathanw printf "ERROR: bad declaration: %s\n", $0 > "/dev/stderr";
141 1.4.2.2 nathanw exit 1;
142 1.4.2.2 nathanw }
143