5 while IFS
=, read op wire
; do
8 done < <(sed 's/ -> /,/')
9 echo "found $count wires"
10 # Find wire $1, store its value in $val. Recursive.
15 if [[ call
-gt $
((count
**2)) ]]; then
16 echo "recursing too deep!"; exit 1
18 local a b vala valb mycall
20 echo "$indent$mycall: looking up wire/value $1 (${wires[$1]})"
22 if [[ ${cache[$1]+set} ]]; then
24 echo "${indent}cached: ${cache[$1]}"
28 case $1_${wires[$1]} in
30 *AND
*) read a ignore b
<<< "${wires[$1]}"
35 val
=$
((vala
& valb
));;
36 *OR
*) read a ignore b
<<< "${wires[$1]}"
41 val
=$
((vala | valb
));;
42 *NOT
*) read ignore a
<<< "${wires[$1]}"
45 val
=$
((~vala
& 0xffff));;
46 *LSHIFT
*) read a ignore b
<<< "${wires[$1]}"
49 val
=$
(((vala
<< b) & 0xffff));;
50 *RSHIFT*) read a ignore b <<< "${wires[$1]}"
54 *) get
${wires[$1]} ;;
57 printf "$indent$mycall: wire $1 contains 0x%x (%d)\n" "$val" "$val"
61 if [[ ${1:-a} == a
]]; then
62 echo "rewriting wire b"