#!/bin/sh # version 2007.09.24 # D. J. Bernstein # Public domain. awk -F: ' function simplify(v) { if (v == 0) return 0 if (!(v in simplifymap)) { simplifynum += 1 simplifymap[v] = simplifynum } return simplifymap[v] } function handleinput(n) { if (n >= 0) return if (n in handleinputseen) return handleinputseen[n] = 1 if ((-n) % 4 == 1) { y[n] = 0 print "vertex:"simplify(n)":label:k"int((-n)/4)":" print "vertex:"simplify(n)":y:-"y[n]":" print "vertex:"simplify(n)":x:"int((-n)/4)":" } else if ((-n) % 4 == 2) { y[n] = 2 print "vertex:"simplify(n)":label:i"int((-n)/4)":" print "vertex:"simplify(n)":y:-"y[n]":" print "vertex:"simplify(n)":x:"int((-n)/4)":" } } { newy = 5 if (\$4 == "&" || \$4 == "^") { n = \$1 handleinput(\$5); if (newy <= y[\$5]) newy = y[\$5] + 1 handleinput(\$7); if (newy <= y[\$7]) newy = y[\$7] + 1 print "vertex:"simplify(n)":label:"\$4":" print "edge:"simplify(\$5)":"simplify(n)":"\$6":" print "edge:"simplify(\$7)":"simplify(n)":"\$8":" } else if (\$4 == "maj" || \$4 == "^^") { n = \$1 handleinput(\$5); if (newy <= y[\$5]) newy = y[\$5] + 1 handleinput(\$7); if (newy <= y[\$7]) newy = y[\$7] + 1 handleinput(\$9); if (newy <= y[\$9]) newy = y[\$9] + 1 print "vertex:"simplify(n)":label:"\$4":" print "edge:"simplify(\$5)":"simplify(n)":"\$6":" print "edge:"simplify(\$7)":"simplify(n)":"\$8":" print "edge:"simplify(\$9)":"simplify(n)":"\$10":" } else if (\$4 == "outputbit") { n = -(\$5 * 4 + 3) handleinput(\$1); if (newy <= y[\$1]) newy = y[\$1] + 1 print "vertex:"simplify(n)":label:o"\$5":" print "edge:"simplify(\$1)":"simplify(n)":"\$2":" } else { print "ERROR!!! "\$0 next } y[n] = newy x[newy] = x[newy] + 1 print "vertex:"simplify(n)":y:-"newy":" print "vertex:"simplify(n)":x:"x[newy]":" } '