fo = open('Encoder.dat', 'w')

fo.write('module Encoder(index, value);\n')
fo.write('\tparameter window_width = 3;\n')
fo.write('\tparameter full_win_bits = 4;\n')
fo.write('\tinput[window_width * window_width - 1 : 0] index;\n')
fo.write('\toutput[full_win_bits - 1 : 0] value;\n')
fo.write('\treg[full_win_bits - 1 : 0] reg_value;\n')
fo.write('\tassign value = reg_value;\n')
fo.write('\tgenerate\n')
fo.write('\t\tcase(window_width)\n')
for i in xrange(2, 16):
	fo.write('\t\t\t%d : \n' % (i))
	fo.write('\t\t\t\talways@(*) begin\n')
	fo.write('\t\t\t\t\tcase(index)\n')
	v = 1
	for j in xrange(i * i):
		fo.write('\t\t\t\t\t\t%d : reg_value <= %d;\n' % (v, j))
		v = 1 << (j + 1)
	fo.write('\t\t\t\t\t\tdefault: reg_value <= 0;\n')
	fo.write('\t\t\t\t\tendcase\n')
	fo.write('\t\t\t\tend\n')
fo.write('\t\t\tdefault : ;\n')
fo.write('\t\tendcase\n')
fo.write('\tendgenerate\n')
fo.write('endmodule\t')