1 1.10 uwe # $NetBSD: genlintstub.awk,v 1.10 2006/01/22 05:11:11 uwe 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.10 uwe # /* 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.10 uwe # Semicolon is optional. 49 1.1 perry # 50 1.1 perry # /* LINTSTUB: Var: type variable, variable; */ 51 1.1 perry # This is often appropriate for assembly bits that the rest of the 52 1.1 perry # kernel has declared as char * and such, like various bits of 53 1.1 perry # trampoline code. 54 1.1 perry # 55 1.4 perry # /* LINTSTUB: include foo */ 56 1.4 perry # Turns into a literal `#include foo' line in the source. Useful for 57 1.4 perry # making sure the stubs are checked against system prototypes like 58 1.4 perry # systm.h, cpu.h, etc., and to make sure that various types are 59 1.4 perry # properly declared. 60 1.4 perry # 61 1.2 perry # /* LINTSTUB: Ignore */ 62 1.2 perry # This is used as an indicator to humans (and possible future 63 1.2 perry # automatic tools) that the entry is only used internally by other .S 64 1.2 perry # files and does not need a stub. You want this so you know you 65 1.2 perry # haven't just forgotten to put a stub in for something and you are 66 1.2 perry # *deliberately* ignoring it. 67 1.1 perry 68 1.10 uwe # LINTSTUBs are also accepted inside multiline comments, e.g. 69 1.10 uwe # 70 1.10 uwe # /* 71 1.10 uwe # * LINTSTUB: include <foo> 72 1.10 uwe # * LINTSTUB: include "bar" 73 1.10 uwe # */ 74 1.10 uwe # 75 1.10 uwe # /* 76 1.10 uwe # * LINTSTUB: Func: type function(args) 77 1.10 uwe # * Some descriptive comment about the function. 78 1.10 uwe # */ 79 1.10 uwe 80 1.10 uwe BEGIN { 81 1.10 uwe printf "/* DO NOT EDIT! DO NOT EDIT! DO NOT EDIT! */\n"; 82 1.10 uwe printf "/* DO NOT EDIT! DO NOT EDIT! DO NOT EDIT! */\n"; 83 1.10 uwe printf "/* This file was automatically generated. */\n"; 84 1.10 uwe printf "/* see genlintstub.awk for details. */\n"; 85 1.10 uwe printf "/* This file was automatically generated. */\n"; 86 1.10 uwe printf "/* DO NOT EDIT! DO NOT EDIT! DO NOT EDIT! */\n"; 87 1.10 uwe printf "/* DO NOT EDIT! DO NOT EDIT! DO NOT EDIT! */\n"; 88 1.10 uwe printf "\n\n"; 89 1.10 uwe 90 1.10 uwe nerrors = 0; 91 1.10 uwe } 92 1.10 uwe 93 1.10 uwe function error(msg) { 94 1.10 uwe printf "ERROR:%d: %s: \"%s\"\n", NR, msg, $0 > "/dev/stderr"; 95 1.10 uwe ++nerrors; 96 1.10 uwe } 97 1.10 uwe 98 1.10 uwe END { 99 1.10 uwe if (nerrors > 0) 100 1.10 uwe exit 1; 101 1.10 uwe } 102 1.10 uwe 103 1.10 uwe 104 1.10 uwe # Check if $i contains semicolon or "*/" comment terminator. If it 105 1.10 uwe # does, strip them and the rest of the word away and return 1 to 106 1.10 uwe # signal that no more words on the line are to be processed. 107 1.10 uwe 108 1.10 uwe function process_word(i) { 109 1.10 uwe if ($i ~ /;/) { 110 1.10 uwe sub(";.*$", "", $i); 111 1.10 uwe return 1; 112 1.10 uwe } 113 1.10 uwe else if ($i ~ /\*\//) { 114 1.10 uwe sub("\\*\\/.*$", "", $i); 115 1.10 uwe return 1; 116 1.10 uwe } 117 1.10 uwe else if (i == NF) 118 1.10 uwe return 1; 119 1.10 uwe else 120 1.10 uwe return 0; 121 1.10 uwe } 122 1.10 uwe 123 1.10 uwe 124 1.10 uwe /^[\/ ]\* LINTSTUB: Func:/ { 125 1.10 uwe if (NF < 5) { 126 1.10 uwe error("bad 'Func' declaration"); 127 1.10 uwe next; 128 1.1 perry } 129 1.10 uwe if (($4 == "int") || ($4 == "long")) 130 1.10 uwe retflag = 1; 131 1.10 uwe else if ($4 == "void") 132 1.10 uwe retflag = 0; 133 1.10 uwe else { 134 1.10 uwe error("type is not int, long or void"); 135 1.5 perry next; 136 1.5 perry } 137 1.10 uwe printf "/* ARGSUSED */\n%s", $4; 138 1.10 uwe for (i = 5; i <= NF; ++i) { 139 1.10 uwe if (process_word(i)) { 140 1.10 uwe printf " %s\n", $i; 141 1.10 uwe break; 142 1.1 perry } 143 1.10 uwe else 144 1.10 uwe printf " %s", $i; 145 1.10 uwe } 146 1.10 uwe print "{"; 147 1.10 uwe if (retflag) 148 1.10 uwe print "\treturn(0);"; 149 1.10 uwe print "}\n"; 150 1.10 uwe next; 151 1.10 uwe } 152 1.10 uwe 153 1.10 uwe /^[\/ ]\* LINTSTUB: Var:/ { 154 1.10 uwe if (NF < 4) { 155 1.10 uwe error("bad 'Var' declaration"); 156 1.1 perry next; 157 1.1 perry } 158 1.10 uwe for (i = 4; i <= NF; ++i) { 159 1.10 uwe if (process_word(i)) { 160 1.10 uwe printf " %s;\n", $i; 161 1.10 uwe break; 162 1.1 perry } 163 1.10 uwe else 164 1.10 uwe printf " %s", $i; 165 1.1 perry } 166 1.10 uwe next; 167 1.10 uwe } 168 1.1 perry 169 1.10 uwe /^[\/ ]\* LINTSTUB: include[ \t]+/ { 170 1.10 uwe if (NF < 4) { 171 1.10 uwe error("bad 'include' directive"); 172 1.4 perry next; 173 1.1 perry } 174 1.10 uwe sub("\\*\\/.*$", "", $4); 175 1.10 uwe printf "#include %s\n", $4; 176 1.10 uwe next; 177 1.10 uwe } 178 1.10 uwe 179 1.10 uwe /^[\/ ]\* LINTSTUB: Empty($|[^_0-9A-Za-z])/ { 180 1.10 uwe printf "/* LINTED (empty translation unit) */\n"; 181 1.10 uwe next; 182 1.10 uwe } 183 1.10 uwe 184 1.10 uwe /^[\/ ]\* LINTSTUB: Ignore($|[^_0-9A-Za-z])/ { 185 1.10 uwe next; 186 1.10 uwe } 187 1.10 uwe 188 1.10 uwe /^[\/ ]\* LINTSTUBS:/ { 189 1.10 uwe error("LINTSTUB, not LINTSTUBS"); 190 1.10 uwe next; 191 1.10 uwe } 192 1.10 uwe 193 1.10 uwe /^[\/ ]\* LINTSTUB:/ { 194 1.10 uwe error("unrecognized"); 195 1.10 uwe next; 196 1.10 uwe } 197