6 from contextlib
import contextmanager
9 def redirect_stdout(new_target
):
10 old_target
, sys
.stdout
= sys
.stdout
, new_target
14 sys
.stdout
= old_target
17 return "%s x" % random
.choice(['+', '+', '+', '-', '-', '|', '&', '^'])
19 def maybe_plus_x(expr
):
20 if random
.randint(0, 4) == 0:
21 return "(%s %s)" % (expr
, random_plus_x())
25 parser
= argparse
.ArgumentParser(formatter_class
= argparse
.ArgumentDefaultsHelpFormatter
)
26 parser
.add_argument('-S', '--seed', type = int, help = 'seed for PRNG')
27 parser
.add_argument('-c', '--count', type = int, default
= 100, help = 'number of test cases to generate')
28 args
= parser
.parse_args()
30 if args
.seed
is not None:
31 print("PRNG seed: %d" % args
.seed
)
32 random
.seed(args
.seed
)
34 for idx
in range(args
.count
):
35 with
open('temp/uut_%05d.v' % idx
, 'w') as f
:
36 with
redirect_stdout(f
):
37 if random
.choice(['bin', 'uni']) == 'bin':
38 print('module uut_%05d(a, b, c, d, x, s, y);' % (idx
))
40 random
.choice(['+', '-', '*', '/', '%']),
41 random
.choice(['<', '<=', '==', '!=', '===', '!==', '>=', '>' ]),
42 random
.choice(['<<', '>>', '<<<', '>>>']),
43 random
.choice(['|', '&', '^', '~^', '||', '&&']),
45 print(' input%s [%d:0] a;' % (random
.choice(['', ' signed']), random
.randint(0, 8)))
46 print(' input%s [%d:0] b;' % (random
.choice(['', ' signed']), random
.randint(0, 8)))
47 print(' input%s [%d:0] c;' % (random
.choice(['', ' signed']), random
.randint(0, 8)))
48 print(' input%s [%d:0] d;' % (random
.choice(['', ' signed']), random
.randint(0, 8)))
49 print(' input%s [%d:0] x;' % (random
.choice(['', ' signed']), random
.randint(0, 8)))
51 print(' output [%d:0] y;' % random
.randint(0, 8))
52 print(' assign y = (s ? %s(%s %s %s) : %s(%s %s %s))%s;' %
53 (random
.choice(['', '$signed', '$unsigned']), maybe_plus_x('a'), op
, maybe_plus_x('b'),
54 random
.choice(['', '$signed', '$unsigned']), maybe_plus_x('c'), op
, maybe_plus_x('d'),
55 random_plus_x() if random
.randint(0, 4) == 0 else ''))
58 print('module uut_%05d(a, b, x, s, y);' % (idx
))
59 op
= random
.choice(['~', '-', '!'])
60 print(' input%s [%d:0] a;' % (random
.choice(['', ' signed']), random
.randint(0, 8)))
61 print(' input%s [%d:0] b;' % (random
.choice(['', ' signed']), random
.randint(0, 8)))
62 print(' input%s [%d:0] x;' % (random
.choice(['', ' signed']), random
.randint(0, 8)))
64 print(' output [%d:0] y;' % random
.randint(0, 8))
65 print(' assign y = (s ? %s(%s%s) : %s(%s%s))%s;' %
66 (random
.choice(['', '$signed', '$unsigned']), op
, maybe_plus_x('a'),
67 random
.choice(['', '$signed', '$unsigned']), op
, maybe_plus_x('b'),
68 random_plus_x() if random
.randint(0, 4) == 0 else ''))
70 with
open('temp/uut_%05d.ys' % idx
, 'w') as f
:
71 with
redirect_stdout(f
):
72 print('read_verilog temp/uut_%05d.v' % idx
)
74 print('copy uut_%05d gold' % idx
)
75 print('rename uut_%05d gate' % idx
)
76 print('tee -a temp/all_share_log.txt log')
77 print('tee -a temp/all_share_log.txt log #job# uut_%05d' % idx
)
78 print('tee -a temp/all_share_log.txt wreduce')
79 print('tee -a temp/all_share_log.txt share -aggressive gate')
80 print('miter -equiv -flatten -ignore_gold_x -make_outputs -make_outcmp gold gate miter')
81 print('sat -set-def-inputs -verify -prove trigger 0 -show-inputs -show-outputs miter')