1 |
3 |
gdevic |
#!/usr/bin/env python
|
2 |
|
|
#
|
3 |
|
|
# This script reads and parses selected Verilog and SystemVerilog modules
|
4 |
|
|
# and generates a set of Verilog include files for the control block.
|
5 |
|
|
#
|
6 |
|
|
#-------------------------------------------------------------------------------
|
7 |
|
|
# Copyright (C) 2014 Goran Devic
|
8 |
|
|
#
|
9 |
|
|
# This program is free software; you can redistribute it and/or modify it
|
10 |
|
|
# under the terms of the GNU General Public License as published by the Free
|
11 |
|
|
# Software Foundation; either version 2 of the License, or (at your option)
|
12 |
|
|
# any later version.
|
13 |
|
|
#
|
14 |
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
15 |
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
16 |
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
17 |
|
|
# more details.
|
18 |
|
|
#-------------------------------------------------------------------------------
|
19 |
|
|
import glob
|
20 |
|
|
import os
|
21 |
|
|
|
22 |
|
|
with open('../top-level-files.txt') as f:
|
23 |
|
|
files = f.read().splitlines()
|
24 |
|
|
|
25 |
|
|
# Create 2 files that should be included in the execution engine block:
|
26 |
|
|
# 1. A module arguments section
|
27 |
|
|
# 2. A file containing the code to initialize control wires to zero
|
28 |
|
|
with open('exec_module.i', 'w') as file1, open('exec_zero.i', 'w') as file0:
|
29 |
|
|
file1.write("// Automatically generated by genref.py\n")
|
30 |
|
|
file0.write("// Automatically generated by genref.py\n")
|
31 |
|
|
|
32 |
|
|
# Read and parse each file from the list of input files
|
33 |
|
|
for infile in files:
|
34 |
|
|
wires = []
|
35 |
|
|
if not os.path.isfile('../' + infile):
|
36 |
|
|
continue
|
37 |
|
|
with open('../' + infile, "r") as f:
|
38 |
|
|
for line in f:
|
39 |
|
|
info = line.split()
|
40 |
|
|
# input wire register case
|
41 |
|
|
if len(info)>2 and info[0]=="input" and info[1]=="wire" and info[2].startswith("ctl_"):
|
42 |
|
|
wires.append(info[2].translate(None, ';,'))
|
43 |
|
|
# input wire [1:0] bus case
|
44 |
|
|
if len(info)>3 and info[0]=="input" and info[1]=="wire" and info[2].startswith("[") and info[3].startswith("ctl_"):
|
45 |
|
|
wires.append(info[2] + " " + info[3].translate(None, ';,'))
|
46 |
|
|
|
47 |
|
|
if len(wires)>0:
|
48 |
|
|
with open('exec_module.i', 'a') as file1, open('exec_zero.i', 'a') as file0:
|
49 |
|
|
print "MODULE: " + infile
|
50 |
|
|
file0.write("\n// Module: " + infile + "\n")
|
51 |
|
|
file1.write("\n// Module: " + infile + "\n")
|
52 |
|
|
for wire in wires:
|
53 |
|
|
print " " + wire
|
54 |
|
|
file1.write("output logic " + wire + ",\n")
|
55 |
|
|
# To the exec include, write bus with the length field (if the wire is a bus)
|
56 |
|
|
# To the zero include, skip bus width field
|
57 |
|
|
if "[" in wire:
|
58 |
|
|
file0.write(wire.split()[1] + " = 0;\n")
|
59 |
|
|
else:
|
60 |
|
|
file0.write(wire + " = 0;\n")
|
61 |
|
|
|
62 |
|
|
# Touch a file that includes 'exec_module.i' and 'exec_zero.i' to ensure it will recompile correctly
|
63 |
|
|
os.utime("execute.sv", None)
|