File: compile.awk

package info (click to toggle)
kernel-source-2.4.14 2.4.14-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 139,160 kB
  • ctags: 428,423
  • sloc: ansic: 2,435,554; asm: 141,119; makefile: 8,258; sh: 3,099; perl: 2,561; yacc: 1,177; cpp: 755; tcl: 577; lex: 352; awk: 251; lisp: 218; sed: 72
file content (57 lines) | stat: -rw-r--r-- 1,074 bytes parent folder | download | duplicates (18)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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++
}