3 # Copyright (C) 2007 The Android Open Source Project
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
19 # Use the file bytecodes.txt to generate code inside <file>, based on
20 # the directives found in that file:
22 # opcodes: static final ints for each opcode
23 # dops: static final objects for each opcode
24 # dops-init: initialization code for the "dops"
29 if [ "x$1" = "x" ]; then
30 echo "must specify a file"
34 # Set up prog to be the path of this script, including following symlinks,
35 # and set up progdir to be the fully-qualified pathname of its directory.
37 while [ -h "${prog}" ]; do
38 newProg=`/bin/ls -ld "${prog}"`
39 newProg=`expr "${newProg}" : ".* -> \(.*\)$"`
40 if expr "x${newProg}" : 'x/' >/dev/null; then
43 progdir=`dirname "${prog}"`
44 prog="${progdir}/${newProg}"
48 progdir=`dirname "${prog}"`
51 prog="${progdir}"/`basename "${prog}"`
54 bytecodeFile="$progdir/bytecode.txt"
56 awk -v "bytecodeFile=$bytecodeFile" '
64 if (index($0, consumeUntil) != 0) {
72 consumeUntil = "END(opcodes)";
75 for (i = 0; i < 256; i++) {
76 printf(" public static final int %s = 0x%s;\n",
77 uppername[i], hex[i]);
84 consumeUntil = "END(dops)";
87 for (i = 0; i < 256; i++) {
88 if (index(name[i], "unused") != 0) {
91 printf(" public static final Dop %s =\n" \
92 " new Dop(DalvOps.%s, DalvOps.%s,\n" \
93 " Form%s.THE_ONE, %s, \"%s\");\n\n",
94 uppername[i], uppername[i], family[i], format[i], hasres[i],
101 /BEGIN\(dops-init\)/ {
102 consumeUntil = "END(dops-init)";
105 for (i = 0; i < 256; i++) {
106 if (index(name[i], "unused") != 0) {
109 printf(" set(%s);\n", uppername[i]);
117 function readBytecodes(i, parts) {
118 for (i = 0; i < 256; i++) {
120 while (($0 == "") || (index($0, "#") != 0)) {
121 if ((getline <bytecodeFile) != 1) {
122 print "trouble reading bytecode file";
128 format[i] = parts[2];
129 hasres[i] = (parts[3] == "n") ? "false" : "true";
131 uppername[i] = toupper(parts[4]);
132 gsub("[---/]", "_", uppername[i]);
133 split(name[i], parts, "/");
134 family[i] = toupper(parts[1]);
135 gsub("-", "_", family[i]);
138 ' "$file" > "$tmpfile"
140 cp "$tmpfile" "$file"