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 4

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
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 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
with open('globals.i', 'w') as file1:
26
    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
            if (len(info)>2):
40
                # There can be only one driver for each signal so we read only the outputs
41
                if (info[0]=="output") and (info[1]=="wire" or info[1]=="reg" or info[1]=="logic"):
42
                    # There are 2 cases: wires and buses
43
                    if info[2].startswith('['):
44
                        wires.append(info[2] + ' ' + info[3].translate(None, ';,'))
45
                    else:
46
                        wires.append(info[2].translate(None, ';,'))
47
 
48
    if len(wires)>0:
49
        with open('globals.i', 'a') as file1:
50
            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
# Touch files that include 'globals.i' to ensure it will recompile correctly
61
os.utime("core.i", None)
62
os.utime("z80_top_direct_n.sv", None)
63
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.