3 from __future__
import division
4 from __future__
import print_function
8 from contextlib
import contextmanager
15 old_target, sys.stdout = sys.stdout, new_target
19 sys.stdout = old_target
22 c = random.choice([
'bin',
'uni',
'var',
'const'])
24 op = random.choice([
'+',
'-',
'*',
'<',
'<=',
'==',
'!=',
'>=',
'>',
'<<',
'>>',
'<<<',
'>>>',
'|',
'&',
'^',
'~^',
'||',
'&&'])
27 op = random.choice([
'+',
'-',
'~',
'|',
'&',
'^',
'~^',
'!',
'$signed',
'$unsigned'])
30 return random.choice(variables)
32 bits = random.randint(1, 32)
33 return "%d'd%s" % (bits, random.randint(0, 2**bits-1))
38 rst2 = random.choice([
False,
True])
40 print(
'module uut_%05d(clk, rst1, rst2, rst, a, b, c, x, y, z);' % (idx))
41 print(
' input clk, rst1, rst2;')
43 print(
' assign rst = rst1 || rst2;')
45 print(
'module uut_%05d(clk, rst, a, b, c, x, y, z);' % (idx))
46 print(
' input clk, rst;')
47 variables=[
'a',
'b',
'c',
'x',
'y',
'z']
48 print(
' input%s [%d:0] a;' % (random.choice([
'',
' signed']), random.randint(0, 31)))
49 print(
' input%s [%d:0] b;' % (random.choice([
'',
' signed']), random.randint(0, 31)))
50 print(
' input%s [%d:0] c;' % (random.choice([
'',
' signed']), random.randint(0, 31)))
51 print(
' output reg%s [%d:0] x;' % (random.choice([
'',
' signed']), random.randint(0, 31)))
52 print(
' output reg%s [%d:0] y;' % (random.choice([
'',
' signed']), random.randint(0, 31)))
53 print(
' output reg%s [%d:0] z;' % (random.choice([
'',
' signed']), random.randint(0, 31)))
54 state_bits = random.randint(5, 16);
55 print(
' %sreg [%d:0] state;' % (random.choice([
'',
'(* fsm_encoding = "one-hot" *)',
56 '(* fsm_encoding = "binary" *)']), state_bits-1))
58 for i
in range(random.randint(2, 10)):
59 n = random.randint(0, 2**state_bits-1)
62 print(
' always @(posedge clk) begin')
63 print(
' if (%s) begin' % (
'rst1' if rst2
else 'rst'))
64 print(
' x <= %d;' % random.randint(0, 2**31-1))
65 print(
' y <= %d;' % random.randint(0, 2**31-1))
66 print(
' z <= %d;' % random.randint(0, 2**31-1))
67 print(
' state <= %d;' % random.choice(states))
68 print(
' end else begin')
69 print(
' case (state)')
71 print(
' %d: begin' % state)
72 for var
in (
'x',
'y',
'z'):
74 next_states = states[:]
75 for i
in range(random.randint(0, len(states))):
76 next_state = random.choice(next_states)
77 next_states.remove(next_state)
78 print(
' if ((%s) %s (%s)) state <= %s;' % (
random_expr(variables),
79 random.choice([
'<',
'<=',
'>=',
'>']),
random_expr(variables), next_state))
83 print(
' if (rst2) begin')
87 print(
' state <= %d;' % random.choice(states))
94 print(
'read_verilog temp/uut_%05d.v' % idx)
95 print(
'proc;; rename uut_%05d gold' % idx)
96 print(
'verific -vlog2k temp/uut_%05d.v' % idx)
97 print(
'verific -import uut_%05d' % idx)
98 print(
'rename uut_%05d gate' % idx)
100 print(
'read_verilog temp/uut_%05d.v' % idx)
102 print(
'copy uut_%05d gold' % idx)
103 print(
'rename uut_%05d gate' % idx)
105 print(
'opt; wreduce; share%s; opt; fsm;;' % random.choice([
'',
' -aggressive']))
107 print(
'miter -equiv -flatten -ignore_gold_x -make_outputs -make_outcmp gold gate miter')
108 print(
'sat -verify-no-timeout -timeout 20 -seq 5 -set-at 1 %s_rst 1 -prove trigger 0 -prove-skip 1 -show-inputs -show-outputs miter' % (
'gold' if rst2
else 'in'))