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

Subversion Repositories a-z80

[/] [a-z80/] [trunk/] [cpu/] [toplevel/] [genglobals.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 Z80 top-level 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 os
20
 
21
with open('../top-level-files.txt') as f:
22
    files = f.read().splitlines()
23
 
24
# Create a file that should be included in the top-level source
25 6 gdevic
with open('globals.vh', 'w') as file1:
26 3 gdevic
    file1.write("// Automatically generated by genglobals.py\n")
27
 
28
# Keep track of duplicated symbols across all files
29
globals = []
30
 
31
# Read and parse each file from the list of input files
32
for infile in files:
33
    wires = []
34
    if not os.path.isfile('../' + infile):
35
        continue
36
    with open('../' + infile, "r") as f:
37
        for line in f:
38
            info = line.split()
39 8 gdevic
            if len(info)>2:
40 3 gdevic
                # There can be only one driver for each signal so we read only the outputs
41 8 gdevic
                if info[0]=="output" and (info[1]=="wire" or info[1]=="reg" or info[1]=="logic"):
42 3 gdevic
                    # There are 2 cases: wires and buses
43
                    if info[2].startswith('['):
44 8 gdevic
                        wires.append(info[2] + ' ' + info[3].strip(';,'))
45 3 gdevic
                    else:
46 8 gdevic
                        wires.append(info[2].strip(';,'))
47 3 gdevic
 
48
    if len(wires)>0:
49 6 gdevic
        with open('globals.vh', 'a') as file1:
50 3 gdevic
            file1.write("\n// Module: " + infile + "\n")
51
            for wire in wires:
52
                # Everything in globals is a wire
53
                # (Can't use 'logic' since some buses are bidirectional)
54
                if wire in globals:
55
                    file1.write("// wire " + wire + "; (previously defined)\n")
56
                else:
57
                    file1.write("wire " + wire + ";\n")
58
                    globals.append(wire)
59
 
60 6 gdevic
# Touch files that include 'globals.vh' to ensure it will recompile correctly
61
os.utime("core.vh", None)
62 8 gdevic
os.utime("z80_top_direct_n.v", None)
63 3 gdevic
os.utime("z80_top_ifc_n.sv", None)

powered by: WebSVN 2.1.0

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