File:  [DragonFly] / src / sys / tools / Attic / vnode_if.awk
Revision 1.1: download - view: text, annotated - select for diffs
Sat Nov 22 20:00:37 2003 UTC (10 years, 10 months ago) by asmodai
Branches: MAIN
CVS tags: HEAD
Add two more awk kernel build scripts from FreeBSD.

    1: #!/usr/bin/awk -f
    2: 
    3: #
    4: # Copyright (c) 1992, 1993
    5: #	The Regents of the University of California.  All rights reserved.
    6: #
    7: # Redistribution and use in source and binary forms, with or without
    8: # modification, are permitted provided that the following conditions
    9: # are met:
   10: # 1. Redistributions of source code must retain the above copyright
   11: #    notice, this list of conditions and the following disclaimer.
   12: # 2. Redistributions in binary form must reproduce the above copyright
   13: #    notice, this list of conditions and the following disclaimer in the
   14: #    documentation and/or other materials provided with the distribution.
   15: # 3. All advertising materials mentioning features or use of this software
   16: #    must display the following acknowledgement:
   17: #	This product includes software developed by the University of
   18: #	California, Berkeley and its contributors.
   19: # 4. Neither the name of the University nor the names of its contributors
   20: #    may be used to endorse or promote products derived from this software
   21: #    without specific prior written permission.
   22: #
   23: # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   24: # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   25: # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   26: # ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   27: # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   28: # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   29: # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   30: # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   31: # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   32: # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   33: # SUCH DAMAGE.
   34: #
   35: #	@(#)vnode_if.sh	8.1 (Berkeley) 6/10/93
   36: # $FreeBSD: src/sys/tools/vnode_if.awk,v 1.39 2003/06/22 21:20:06 truckman Exp $
   37: # $DragonFly: src/sys/tools/vnode_if.awk,v 1.1 2003/11/22 20:00:37 asmodai Exp $
   38: #
   39: # Script to produce VFS front-end sugar.
   40: #
   41: # usage: vnode_if.awk <srcfile> [-c | -h]
   42: #	(where <srcfile> is currently /sys/kern/vnode_if.src)
   43: #
   44: 
   45: function usage()
   46: {
   47: 	print "usage: vnode_if.awk <srcfile> [-c|-h]";
   48: 	exit 1;
   49: }
   50: 
   51: function die(msg, what)
   52: {
   53: 	printf msg "\n", what > "/dev/stderr";
   54: 	exit 1;
   55: }
   56: 
   57: function t_spc(type)
   58: {
   59: 	# Append a space if the type is not a pointer
   60: 	return (type ~ /\*$/) ? type : type " ";
   61: }
   62: 
   63: # These are just for convenience ...
   64: function printc(s) {print s > cfile;}
   65: function printh(s) {print s > hfile;}
   66: 
   67: function add_debug_code(name, arg, pos)
   68: {
   69: 	if (arg == "vpp")
   70: 		arg = "*vpp";
   71: 	if (lockdata[name, arg, pos] && (lockdata[name, arg, pos] != "-")) {
   72: 		if (arg ~ /^\*/) {
   73: 			printh("\tif ("substr(arg, 2)" != NULL) {");
   74: 		}
   75: 		printh("\tASSERT_VI_UNLOCKED("arg", \""uname"\");");
   76: 		# Add assertions for locking
   77: 		if (lockdata[name, arg, pos] == "L")
   78: 			printh("\tASSERT_VOP_LOCKED("arg", \""uname"\");");
   79: 		else if (lockdata[name, arg, pos] == "U")
   80: 			printh("\tASSERT_VOP_UNLOCKED("arg", \""uname"\");");
   81: 		else if (0) {
   82: 			# XXX More checks!
   83: 		}
   84: 		if (arg ~ /^\*/) {
   85: 			printh("\t}");
   86: 		}
   87: 	}
   88: }
   89: 
   90: function add_debug_pre(name)
   91: {
   92: 	if (lockdata[name, "pre"]) {
   93: 		printh("#ifdef	DEBUG_VFS_LOCKS");
   94: 		printh("\t"lockdata[name, "pre"]"(&a);");
   95: 		printh("#endif");
   96: 	}
   97: }
   98: 
   99: function add_debug_post(name)
  100: {
  101: 	if (lockdata[name, "post"]) {
  102: 		printh("#ifdef	DEBUG_VFS_LOCKS");
  103: 		printh("\t"lockdata[name, "post"]"(&a, rc);");
  104: 		printh("#endif");
  105: 	}
  106: }
  107: 
  108: function find_arg_with_type (type)
  109: {
  110: 	for (jj = 0; jj < numargs; jj++) {
  111: 		if (types[jj] == type) {
  112: 			return "VOPARG_OFFSETOF(struct " \
  113: 			    name "_args,a_" args[jj] ")";
  114: 		}
  115: 	}
  116: 
  117: 	return "VDESC_NO_OFFSET";
  118: }
  119: 
  120: BEGIN{
  121: 
  122: # Process the command line
  123: for (i = 1; i < ARGC; i++) {
  124: 	arg = ARGV[i];
  125: 	if (arg !~ /^-[ch]+$/ && arg !~ /\.src$/)
  126: 		usage();
  127: 	if (arg ~ /^-.*c/)
  128: 		cfile = "vnode_if.c";
  129: 	if (arg ~ /^-.*h/)
  130: 		hfile = "vnode_if.h";
  131: 	if (arg ~ /\.src$/)
  132: 		srcfile = arg;
  133: }
  134: ARGC = 1;
  135: 
  136: if (!cfile && !hfile)
  137: 	exit 0;
  138: 
  139: if (!srcfile)
  140: 	usage();
  141: 
  142: common_head = \
  143:     "/*\n" \
  144:     " * This file is produced automatically.\n" \
  145:     " * Do not modify anything in here by hand.\n" \
  146:     " *\n" \
  147:     " * Created from $FreeBSD$\n" \
  148:     " */\n" \
  149:     "\n";
  150: 
  151: if (hfile)
  152: 	printh(common_head "extern struct vnodeop_desc vop_default_desc;");
  153: 
  154: if (cfile) {
  155: 	printc(common_head \
  156: 	    "#include <sys/param.h>\n" \
  157: 	    "#include <sys/systm.h>\n" \
  158: 	    "#include <sys/vnode.h>\n" \
  159: 	    "\n" \
  160: 	    "struct vnodeop_desc vop_default_desc = {\n" \
  161: 	    "	1,\t\t\t/* special case, vop_default => 1 */\n" \
  162: 	    "	\"default\",\n" \
  163: 	    "	0,\n" \
  164: 	    "	NULL,\n" \
  165: 	    "	VDESC_NO_OFFSET,\n" \
  166: 	    "	VDESC_NO_OFFSET,\n" \
  167: 	    "	VDESC_NO_OFFSET,\n" \
  168: 	    "	VDESC_NO_OFFSET,\n" \
  169: 	    "	NULL,\n" \
  170: 	    "};\n");
  171: }
  172: 
  173: while ((getline < srcfile) > 0) {
  174: 	if (NF == 0)
  175: 		continue;
  176: 	if ($1 ~ /^#%/) {
  177: 		if (NF != 6  ||  $1 != "#%"  || \
  178: 		    $2 !~ /^[a-z]+$/  ||  $3 !~ /^[a-z]+$/  || \
  179: 		    $4 !~ /^.$/  ||  $5 !~ /^.$/  ||  $6 !~ /^.$/)
  180: 			continue;
  181: 		if ($3 == "vpp")
  182: 			$3 = "*vpp";
  183: 		lockdata["vop_" $2, $3, "Entry"] = $4;
  184: 		lockdata["vop_" $2, $3, "OK"]    = $5;
  185: 		lockdata["vop_" $2, $3, "Error"] = $6;			
  186: 		continue;
  187: 	}
  188: 
  189: 	if ($1 ~ /^#!/) {
  190: 		if (NF != 4 || $1 != "#!")
  191: 			continue;
  192: 		if ($3 != "pre" && $3 != "post")
  193: 			continue;
  194: 		lockdata["vop_" $2, $3] = $4;
  195: 		continue;
  196: 	}
  197: 	if ($1 ~ /^#/)
  198: 		continue;
  199: 
  200: 	# Get the function name.
  201: 	name = $1;
  202: 	uname = toupper(name);
  203: 
  204: 	# Start constructing a ktrpoint string
  205: 	ctrstr = "\"" uname;
  206: 	# Get the function arguments.
  207: 	for (numargs = 0; ; ++numargs) {
  208: 		if ((getline < srcfile) <= 0) {
  209: 			die("Unable to read through the arguments for \"%s\"",
  210: 			    name);
  211: 		}
  212: 		if ($1 ~ /^\};/)
  213: 			break;
  214: 
  215: 		# Delete comments, if any.
  216: 		gsub (/\/\*.*\*\//, "");
  217: 
  218: 		# Condense whitespace and delete leading/trailing space.
  219: 		gsub(/[[:space:]]+/, " ");
  220: 		sub(/^ /, "");
  221: 		sub(/ $/, "");
  222: 
  223: 		# Pick off direction.
  224: 		if ($1 != "INOUT" && $1 != "IN" && $1 != "OUT")
  225: 			die("No IN/OUT direction for \"%s\".", $0);
  226: 		dirs[numargs] = $1;
  227: 		sub(/^[A-Z]* /, "");
  228: 
  229: 		if ((reles[numargs] = $1) == "WILLRELE")
  230: 			sub(/^[A-Z]* /, "");
  231: 		else
  232: 			reles[numargs] = "WONTRELE";
  233: 
  234: 		# kill trailing ;
  235: 		if (sub(/;$/, "") < 1)
  236: 			die("Missing end-of-line ; in \"%s\".", $0);
  237: 
  238: 		# pick off variable name
  239: 		if ((argp = match($0, /[A-Za-z0-9_]+$/)) < 1)
  240: 			die("Missing var name \"a_foo\" in \"%s\".", $0);
  241: 		args[numargs] = substr($0, argp);
  242: 		$0 = substr($0, 1, argp - 1);
  243: 
  244: 		# what is left must be type
  245: 		# remove trailing space (if any)
  246: 		sub(/ $/, "");
  247: 		types[numargs] = $0;
  248: 
  249: 		# We can do a maximum of 6 arguments to CTR*
  250: 		if (numargs <= 6) {
  251: 			if (numargs == 0)
  252: 				ctrstr = ctrstr "(" args[numargs];
  253: 			else
  254: 				ctrstr = ctrstr ", " args[numargs];
  255: 			if (types[numargs] ~ /\*/)
  256: 				ctrstr = ctrstr " 0x%lX";
  257: 			else
  258: 				ctrstr = ctrstr " %ld";
  259: 		}
  260: 	}
  261: 	if (numargs > 6)
  262: 		ctrargs = 6;
  263: 	else
  264: 		ctrargs = numargs;
  265: 	ctrstr = "\tCTR" ctrargs "(KTR_VOP, " ctrstr ")\"";
  266: 	for (i = 0; i < ctrargs; ++i)
  267: 		ctrstr = ctrstr ", " args[i];
  268: 	ctrstr = ctrstr ");";
  269: 
  270: 	if (hfile) {
  271: 		# Print out the vop_F_args structure.
  272: 		printh("struct "name"_args {\n\tstruct vnodeop_desc *a_desc;");
  273: 		for (i = 0; i < numargs; ++i)
  274: 			printh("\t" t_spc(types[i]) "a_" args[i] ";");
  275: 		printh("};");
  276: 
  277: 		# Print out extern declaration.
  278: 		printh("extern struct vnodeop_desc " name "_desc;");
  279: 
  280: 		# Print out function.
  281: 		printh("static __inline int " uname "(");
  282: 		for (i = 0; i < numargs; ++i) {
  283: 			printh("\t" t_spc(types[i]) args[i] \
  284: 			    (i < numargs - 1 ? "," : ")"));
  285: 		}
  286: 		printh("{\n\tstruct " name "_args a;");
  287: 		printh("\tint rc;");
  288: 		printh("\ta.a_desc = VDESC(" name ");");
  289: 		for (i = 0; i < numargs; ++i)
  290: 			printh("\ta.a_" args[i] " = " args[i] ";");
  291: 		for (i = 0; i < numargs; ++i)
  292: 			add_debug_code(name, args[i], "Entry");
  293: 		add_debug_pre(name);
  294: 		printh("\trc = VCALL(" args[0] ", VOFFSET(" name "), &a);");
  295: 		printh(ctrstr);
  296: 		printh("if (rc == 0) {");
  297: 		for (i = 0; i < numargs; ++i)
  298: 			add_debug_code(name, args[i], "OK");
  299: 		printh("} else {");
  300: 		for (i = 0; i < numargs; ++i)
  301: 			add_debug_code(name, args[i], "Error");
  302: 		printh("}");
  303: 		add_debug_post(name);
  304: 		printh("\treturn (rc);\n}");
  305: 	}
  306: 
  307: 	if (cfile) {
  308: 		# Print out the vop_F_vp_offsets structure.  This all depends
  309: 		# on naming conventions and nothing else.
  310: 		printc("static int " name "_vp_offsets[] = {");
  311: 		# as a side effect, figure out the releflags
  312: 		releflags = "";
  313: 		vpnum = 0;
  314: 		for (i = 0; i < numargs; i++) {
  315: 			if (types[i] == "struct vnode *") {
  316: 				printc("\tVOPARG_OFFSETOF(struct " name \
  317: 				    "_args,a_" args[i] "),");
  318: 				if (reles[i] == "WILLRELE") {
  319: 					releflags = releflags \
  320: 					    "|VDESC_VP" vpnum "_WILLRELE";
  321: 				}
  322: 				vpnum++;
  323: 			}
  324: 		}
  325: 
  326: 		sub(/^\|/, "", releflags);
  327: 		printc("\tVDESC_NO_OFFSET");
  328: 		printc("};");
  329: 
  330: 		# Print out the vnodeop_desc structure.
  331: 		printc("struct vnodeop_desc " name "_desc = {");
  332: 		# offset
  333: 		printc("\t0,");
  334: 		# printable name
  335: 		printc("\t\"" name "\",");
  336: 		# flags
  337: 		vppwillrele = "";
  338: 		for (i = 0; i < numargs; i++) {
  339: 			if (types[i] == "struct vnode **" && \
  340: 			    reles[i] == "WILLRELE") {
  341: 				vppwillrele = "|VDESC_VPP_WILLRELE";
  342: 			}
  343: 		}
  344: 
  345: 		if (!releflags)
  346: 			releflags = "0";
  347: 		printc("\t" releflags vppwillrele ",");
  348: 
  349: 		# vp offsets
  350: 		printc("\t" name "_vp_offsets,");
  351: 		# vpp (if any)
  352: 		printc("\t" find_arg_with_type("struct vnode **") ",");
  353: 		# cred (if any)
  354: 		printc("\t" find_arg_with_type("struct ucred *") ",");
  355: 		# thread (if any)
  356: 		printc("\t" find_arg_with_type("struct thread *") ",");
  357: 		# componentname
  358: 		printc("\t" find_arg_with_type("struct componentname *") ",");
  359: 		# transport layer information
  360: 		printc("\tNULL,\n};\n");
  361: 	}
  362: }
  363:  
  364: if (hfile)
  365: 	close(hfile);
  366: if (cfile)
  367: 	close(cfile);
  368: close(srcfile);
  369: 
  370: exit 0;
  371: 
  372: }