yosys-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
share/generate.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 
3 from __future__ import division
4 from __future__ import print_function
5 
6 import sys
7 import random
8 from contextlib import contextmanager
9 
10 @contextmanager
11 def redirect_stdout(new_target):
12  old_target, sys.stdout = sys.stdout, new_target
13  try:
14  yield new_target
15  finally:
16  sys.stdout = old_target
17 
19  return "%s x" % random.choice(['+', '+', '+', '-', '-', '|', '&', '^'])
20 
21 def maybe_plus_x(expr):
22  if random.randint(0, 4) == 0:
23  return "(%s %s)" % (expr, random_plus_x())
24  else:
25  return expr
26 
27 for idx in range(100):
28  with file('temp/uut_%05d.v' % idx, 'w') as f, redirect_stdout(f):
29  if random.choice(['bin', 'uni']) == 'bin':
30  print('module uut_%05d(a, b, c, d, x, s, y);' % (idx))
31  op = random.choice([
32  random.choice(['+', '-', '*', '/', '%']),
33  random.choice(['<', '<=', '==', '!=', '===', '!==', '>=', '>' ]),
34  random.choice(['<<', '>>', '<<<', '>>>']),
35  random.choice(['|', '&', '^', '~^', '||', '&&']),
36  ])
37  print(' input%s [%d:0] a;' % (random.choice(['', ' signed']), random.randint(0, 8)))
38  print(' input%s [%d:0] b;' % (random.choice(['', ' signed']), random.randint(0, 8)))
39  print(' input%s [%d:0] c;' % (random.choice(['', ' signed']), random.randint(0, 8)))
40  print(' input%s [%d:0] d;' % (random.choice(['', ' signed']), random.randint(0, 8)))
41  print(' input%s [%d:0] x;' % (random.choice(['', ' signed']), random.randint(0, 8)))
42  print(' input s;')
43  print(' output [%d:0] y;' % random.randint(0, 8))
44  print(' assign y = (s ? %s(%s %s %s) : %s(%s %s %s))%s;' %
45  (random.choice(['', '$signed', '$unsigned']), maybe_plus_x('a'), op, maybe_plus_x('b'),
46  random.choice(['', '$signed', '$unsigned']), maybe_plus_x('c'), op, maybe_plus_x('d'),
47  random_plus_x() if random.randint(0, 4) == 0 else ''))
48  print('endmodule')
49  else:
50  print('module uut_%05d(a, b, x, s, y);' % (idx))
51  op = random.choice(['~', '-', '!'])
52  print(' input%s [%d:0] a;' % (random.choice(['', ' signed']), random.randint(0, 8)))
53  print(' input%s [%d:0] b;' % (random.choice(['', ' signed']), random.randint(0, 8)))
54  print(' input%s [%d:0] x;' % (random.choice(['', ' signed']), random.randint(0, 8)))
55  print(' input s;')
56  print(' output [%d:0] y;' % random.randint(0, 8))
57  print(' assign y = (s ? %s(%s%s) : %s(%s%s))%s;' %
58  (random.choice(['', '$signed', '$unsigned']), op, maybe_plus_x('a'),
59  random.choice(['', '$signed', '$unsigned']), op, maybe_plus_x('b'),
60  random_plus_x() if random.randint(0, 4) == 0 else ''))
61  print('endmodule')
62  with file('temp/uut_%05d.ys' % idx, 'w') as f, redirect_stdout(f):
63  print('read_verilog temp/uut_%05d.v' % idx)
64  print('proc;;')
65  print('copy uut_%05d gold' % idx)
66  print('rename uut_%05d gate' % idx)
67  print('tee -a temp/all_share_log.txt log')
68  print('tee -a temp/all_share_log.txt log #job# uut_%05d' % idx)
69  print('tee -a temp/all_share_log.txt wreduce')
70  print('tee -a temp/all_share_log.txt share -aggressive gate')
71  print('miter -equiv -flatten -ignore_gold_x -make_outputs -make_outcmp gold gate miter')
72  print('sat -set-def-inputs -verify -prove trigger 0 -show-inputs -show-outputs miter')
73 
def random_plus_x
def redirect_stdout
Definition: fsm/generate.py:14
def maybe_plus_x