File size: 741 Bytes
7df9186
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env python

import json
import os


def v2j(vfile):
    basename = os.path.basename(vfile)
    base = os.path.splitext(basename)[0]
    assert (basename.endswith('.v') or basename.endswith('.sv'))
    autofile = '/tmp/{}_auto.vh'.format(base)
    with open(autofile, 'w') as f:
        f.write('')
    jfile = '/tmp/{}.json'.format(base)
    yfile = '/tmp/yosys_v2j.ys'
    with open(yfile, "w") as f:
        f.write('read_verilog -sv -I/tmp {0}\n'
                'proc\n'
                'write_json {1}'.format(vfile, jfile))
    os.system('yosys -q {}'.format(yfile))
    with open(jfile, 'r') as f:
        return json.load(f)


if __name__ == "__main__":
    import sys
    assert (len(sys.argv) == 2)
    v2j(sys.argv[1])