|
1 #! /bin/sh |
|
2 |
|
3 # |
|
4 # Copyright 2000-2005 Sun Microsystems, Inc. All Rights Reserved. |
|
5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
6 # |
|
7 # This code is free software; you can redistribute it and/or modify it |
|
8 # under the terms of the GNU General Public License version 2 only, as |
|
9 # published by the Free Software Foundation. Sun designates this |
|
10 # particular file as subject to the "Classpath" exception as provided |
|
11 # by Sun in the LICENSE file that accompanied this code. |
|
12 # |
|
13 # This code is distributed in the hope that it will be useful, but WITHOUT |
|
14 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 # version 2 for more details (a copy is included in the LICENSE file that |
|
17 # accompanied this code). |
|
18 # |
|
19 # You should have received a copy of the GNU General Public License version |
|
20 # 2 along with this work; if not, write to the Free Software Foundation, |
|
21 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
22 # |
|
23 # Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
24 # CA 95054 USA or visit www.sun.com if you need additional information or |
|
25 # have any questions. |
|
26 # |
|
27 |
|
28 # Generate concrete buffer classes |
|
29 |
|
30 # Required environment variables |
|
31 # NAWK SED SPP To invoke tools |
|
32 # TYPE Primitive type |
|
33 # SRC Source file |
|
34 # DST Destination file |
|
35 # |
|
36 # Optional environment variables |
|
37 # RW Mutability: R(ead only), W(ritable) |
|
38 # BO Byte order: B(ig), L(ittle), S(wapped), U(nswapped) |
|
39 # BIN Defined => generate binary-data access methods |
|
40 |
|
41 type=$TYPE |
|
42 rw=$RW |
|
43 rwkey=XX |
|
44 |
|
45 case $type in |
|
46 char) fulltype=character;; |
|
47 *) fulltype=$type;; |
|
48 esac |
|
49 |
|
50 case $type in |
|
51 byte) LBPV=0;; |
|
52 char | short) LBPV=1;; |
|
53 int | float) LBPV=2;; |
|
54 long | double) LBPV=3;; |
|
55 esac |
|
56 |
|
57 typesAndBits() { |
|
58 |
|
59 type="$1"; BO="$2" |
|
60 memtype=$type; swaptype=$type; frombits=; tobits= |
|
61 |
|
62 case $type in |
|
63 float) memtype=int |
|
64 if [ x$BO != xU ]; then |
|
65 swaptype=int |
|
66 fromBits=Float.intBitsToFloat |
|
67 toBits=Float.floatToRawIntBits |
|
68 fi;; |
|
69 double) memtype=long |
|
70 if [ x$BO != xU ]; then |
|
71 swaptype=long |
|
72 fromBits=Double.longBitsToDouble |
|
73 toBits=Double.doubleToRawLongBits |
|
74 fi;; |
|
75 esac |
|
76 |
|
77 echo memtype=$memtype swaptype=$swaptype fromBits=$fromBits toBits=$toBits |
|
78 |
|
79 echo $type $fulltype $memtype $swaptype \ |
|
80 | $NAWK '{ type = $1; fulltype = $2; memtype = $3; swaptype = $4; |
|
81 x = substr(type, 1, 1); |
|
82 Type = toupper(x) substr(type, 2); |
|
83 Fulltype = toupper(x) substr(fulltype, 2); |
|
84 Memtype = toupper(substr(memtype, 1, 1)) substr(memtype, 2); |
|
85 Swaptype = toupper(substr(swaptype, 1, 1)) substr(swaptype, 2); |
|
86 printf("Type=%s x=%s Fulltype=%s Memtype=%s Swaptype=%s ", |
|
87 Type, x, Fulltype, Memtype, Swaptype); }' |
|
88 |
|
89 echo "swap=`if [ x$BO = xS ]; then echo Bits.swap; fi`" |
|
90 |
|
91 } |
|
92 |
|
93 eval `typesAndBits $type $BO` |
|
94 |
|
95 a=`if [ $type = int ]; then echo an; else echo a; fi` |
|
96 A=`if [ $type = int ]; then echo An; else echo A; fi` |
|
97 |
|
98 if [ "x$rw" = xR ]; then rwkey=ro; else rwkey=rw; fi |
|
99 |
|
100 set -e |
|
101 |
|
102 $SPP <$SRC >$DST \ |
|
103 -K$type \ |
|
104 -Dtype=$type \ |
|
105 -DType=$Type \ |
|
106 -Dfulltype=$fulltype \ |
|
107 -DFulltype=$Fulltype \ |
|
108 -Dx=$x \ |
|
109 -Dmemtype=$memtype \ |
|
110 -DMemtype=$Memtype \ |
|
111 -DSwaptype=$Swaptype \ |
|
112 -DfromBits=$fromBits \ |
|
113 -DtoBits=$toBits \ |
|
114 -DLG_BYTES_PER_VALUE=$LBPV \ |
|
115 -DBYTES_PER_VALUE="(1 << $LBPV)" \ |
|
116 -DBO=$BO \ |
|
117 -Dswap=$swap \ |
|
118 -DRW=$rw \ |
|
119 -K$rwkey \ |
|
120 -Da=$a \ |
|
121 -DA=$A \ |
|
122 -Kbo$BO |
|
123 |
|
124 if [ $BIN ]; then |
|
125 |
|
126 genBinOps() { |
|
127 type="$1" |
|
128 Type=`echo $1 | $NAWK '{ print toupper(substr($1, 1, 1)) substr($1, 2) }'` |
|
129 fulltype="$2" |
|
130 LBPV="$3" |
|
131 nbytes="$4" |
|
132 nbytesButOne="$5" |
|
133 a=`if [ $type = int ]; then echo an; else echo a; fi` |
|
134 src=$6 |
|
135 eval `typesAndBits $type` |
|
136 $SPP <$src \ |
|
137 -Dtype=$type \ |
|
138 -DType=$Type \ |
|
139 -Dfulltype=$fulltype \ |
|
140 -Dmemtype=$memtype \ |
|
141 -DMemtype=$Memtype \ |
|
142 -DfromBits=$fromBits \ |
|
143 -DtoBits=$toBits \ |
|
144 -DLG_BYTES_PER_VALUE=$LBPV \ |
|
145 -DBYTES_PER_VALUE="(1 << $LBPV)" \ |
|
146 -Dnbytes=$nbytes \ |
|
147 -DnbytesButOne=$nbytesButOne \ |
|
148 -DRW=$rw \ |
|
149 -K$rwkey \ |
|
150 -Da=$a \ |
|
151 -be |
|
152 } |
|
153 |
|
154 mv $DST $DST.tmp |
|
155 sed -e '/#BIN/,$d' <$DST.tmp >$DST |
|
156 rm -f $DST.tmp |
|
157 binops=`dirname $SRC`/`basename $SRC .java`-bin.java |
|
158 genBinOps char character 1 two one $binops >>$DST |
|
159 genBinOps short short 1 two one $binops >>$DST |
|
160 genBinOps int integer 2 four three $binops >>$DST |
|
161 genBinOps long long 3 eight seven $binops >>$DST |
|
162 genBinOps float float 2 four three $binops >>$DST |
|
163 genBinOps double double 3 eight seven $binops >>$DST |
|
164 echo '}' >>$DST |
|
165 |
|
166 fi |