File: mangler

package info (click to toggle)
nhc98 1.16-15
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 62,544 kB
  • ctags: 103,012
  • sloc: ansic: 831,077; haskell: 60,111; java: 4,116; makefile: 3,045; sh: 2,183; cpp: 212
file content (49 lines) | stat: -rwxr-xr-x 1,156 bytes parent folder | download
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
#!/bin/sh
# Horrible mangler for keeping two forms of bytecode in sync.
# Should be applied to "newbytecode.h" to give "bytecode_o.h"

case $# in
  0) input=
     output= ;;
  1) input=$1
     output= ;;
  2) input=$1
     output=$2 ;;
  *) echo "`basename $0`: too many arguments"
     exit 1 ;;
esac

cat $input |\
  tail +4  |\
  sed -e "/^.*UNUSED_INSTRUCTIONS.*$/d" \
      -e "/^.*Case.*/d"	\
      -e "/^\\\\$/d" \
      -e "/^[ 	]*$/d" \
      -e "s/,[ 	]*\\\\$//" \
      -e "s/ ins(/\#define /" \
      -e "s/)//"	|\
  awk "BEGIN {i = 0} { print \$0, i; i += 1 }" - |\
  ( echo "#ifndef _BYTECODE_O_H_" ;
    echo "#define _BYTECODE_O_H_" ;
    echo; cat; echo;
    echo "#endif" ) |\
  ( if [ -z "$output" ]
    then cat
    else cat >$output
    fi )

# Explanation:
#    remove lines upto #define INSTRUCTION_LIST (tail +4)
#
#    remove all of defn UNUSED_INSTRUCTIONS
#    remove all blank lines with single trailing \
#    remove trailing ,[\t]*\
#
#    for all remaining lines change ins() into #define
#     and add numbering
#
#    finally add wrapper
#      #ifndef _BYTECODE_O_H_
#      #define _BYTECODE_O_H_
#      ...
#      #endif