patch-2.1.15 linux/net/802/pseudo/compile.awk

Next file: linux/net/802/pseudo/opcd2num.sed
Previous file: linux/net/802/pseudo/actionnm.h
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.14/linux/net/802/pseudo/compile.awk linux/net/802/pseudo/compile.awk
@@ -0,0 +1,57 @@
+# usage: cat pseudocode | sed -f act2num | awk -f compile.awk
+#
+#
+BEGIN { "date" | getline
+	today = $0
+	printf("\n/* this file generated on %s  */\n", today )
+	printf("\nstatic char pseudo_code [ ] = { \n" )
+	opl = 0			# op codes on the current line
+
+	opc = 0			# opcode counter
+	fpi = 0			# fill pointer for idx array
+}
+
+/^;/ { } 			# line starting with semicolon is comment 
+
+/^[A-Z]/ {			# start of a new action 
+	emit( 0 )
+	idx[ ++fpi ] = opc
+	name[ fpi ] = $1 
+	emit( $2 )
+}
+
+/^[\t ]/ { 
+        emit( $1 )
+}
+
+END {		
+	if ( opl > 8 ) {
+	    printf("\n")
+	}
+	printf("\t  0\n};\n\n")
+	printf("static short int pseudo_code_idx [ ] ={\n")
+	opl = 0
+	emit( 0 )
+	for( ii = 1; ii <= fpi; ii++ )
+	   emit( idx[ ii ] )
+	if ( opl > 8 ) {
+	    printf("\n")
+	}
+	printf("\t  0\n};\n\n")
+
+	printf("#define %-10s \t %3d \n", "NOP", 0 )
+	for( ii = 1; ii <= fpi; ii++ )
+	    printf("#define %-10s \t %3d \n", name[ ii ], ii )
+	printf("\n")
+}
+
+function emit( opcode ){	# Niclaus Wirth
+	if ( opl > 8 ) {
+	    printf("\n")
+	    opl = 0
+	}
+	opl = opl +1
+	printf("\t%4d,", opcode )
+	opc++
+}
+

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov