OpenCores
URL https://opencores.org/ocsvn/a-z80/a-z80/trunk

Subversion Repositories a-z80

[/] [a-z80/] [trunk/] [cpu/] [control/] [genref.py] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 gdevic
#!/usr/bin/env python3
2 3 gdevic
#
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 8 gdevic
# Create 2 files that should be included by the execution engine:
26
# 1. A file listing all control signals
27
# 2. A file containing statements initializing control signals to zero
28 6 gdevic
with open('exec_module.vh', 'w') as file1, open('exec_zero.vh', 'w') as file0:
29 3 gdevic
    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 8 gdevic
                wires.append(info[2].strip(';,'))
43
            # input wire bus case (ex. "[1:0]")
44 3 gdevic
            if len(info)>3 and info[0]=="input" and info[1]=="wire" and info[2].startswith("[") and info[3].startswith("ctl_"):
45 8 gdevic
                wires.append(info[2] + " " + info[3].strip(';,'))
46 3 gdevic
 
47
    if len(wires)>0:
48 6 gdevic
        with open('exec_module.vh', 'a') as file1, open('exec_zero.vh', 'a') as file0:
49 8 gdevic
            print ("MODULE:", infile)
50 3 gdevic
            file0.write("\n// Module: " + infile + "\n")
51
            file1.write("\n// Module: " + infile + "\n")
52
            for wire in wires:
53 8 gdevic
                print ("  ", wire)
54
                file1.write("output reg " + wire + ",\n")
55 3 gdevic
                if "[" in wire:
56
                    file0.write(wire.split()[1] + " = 0;\n")
57
                else:
58 8 gdevic
                    file0.write(wire + " = 0;\n")
59 3 gdevic
 
60 6 gdevic
# Touch a file that includes 'exec_module.vh' and 'exec_zero.vh' to ensure it will recompile correctly
61 8 gdevic
os.utime("execute.v", None)

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.