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

Subversion Repositories a-z80

[/] [a-z80/] [trunk/] [cpu/] [toplevel/] [genglobals.py] - Diff between revs 6 and 8

Only display areas with differences | Details | Blame | View Log

Rev 6 Rev 8
#!/usr/bin/env python
#!/usr/bin/env python3
#
#
# This script reads and parses selected Verilog and SystemVerilog modules
# This script reads and parses selected Verilog and SystemVerilog modules
# and generates a set of Verilog include files for the Z80 top-level block.
# and generates a set of Verilog include files for the Z80 top-level block.
#
#
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#  Copyright (C) 2014  Goran Devic
#  Copyright (C) 2014  Goran Devic
#
#
#  This program is free software; you can redistribute it and/or modify it
#  This program is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by the Free
#  under the terms of the GNU General Public License as published by the Free
#  Software Foundation; either version 2 of the License, or (at your option)
#  Software Foundation; either version 2 of the License, or (at your option)
#  any later version.
#  any later version.
#
#
#  This program is distributed in the hope that it will be useful, but WITHOUT
#  This program is distributed in the hope that it will be useful, but WITHOUT
#  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
#  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
#  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
#  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
#  more details.
#  more details.
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
import os
import os
 
 
with open('../top-level-files.txt') as f:
with open('../top-level-files.txt') as f:
    files = f.read().splitlines()
    files = f.read().splitlines()
 
 
# Create a file that should be included in the top-level source
# Create a file that should be included in the top-level source
with open('globals.vh', 'w') as file1:
with open('globals.vh', 'w') as file1:
    file1.write("// Automatically generated by genglobals.py\n")
    file1.write("// Automatically generated by genglobals.py\n")
 
 
# Keep track of duplicated symbols across all files
# Keep track of duplicated symbols across all files
globals = []
globals = []
 
 
# Read and parse each file from the list of input files
# Read and parse each file from the list of input files
for infile in files:
for infile in files:
    wires = []
    wires = []
    if not os.path.isfile('../' + infile):
    if not os.path.isfile('../' + infile):
        continue
        continue
    with open('../' + infile, "r") as f:
    with open('../' + infile, "r") as f:
        for line in f:
        for line in f:
            info = line.split()
            info = line.split()
            if (len(info)>2):
            if len(info)>2:
                # There can be only one driver for each signal so we read only the outputs
                # There can be only one driver for each signal so we read only the outputs
                if (info[0]=="output") and (info[1]=="wire" or info[1]=="reg" or info[1]=="logic"):
                if info[0]=="output" and (info[1]=="wire" or info[1]=="reg" or info[1]=="logic"):
                    # There are 2 cases: wires and buses
                    # There are 2 cases: wires and buses
                    if info[2].startswith('['):
                    if info[2].startswith('['):
                        wires.append(info[2] + ' ' + info[3].translate(None, ';,'))
                        wires.append(info[2] + ' ' + info[3].strip(';,'))
                    else:
                    else:
                        wires.append(info[2].translate(None, ';,'))
                        wires.append(info[2].strip(';,'))
 
 
    if len(wires)>0:
    if len(wires)>0:
        with open('globals.vh', 'a') as file1:
        with open('globals.vh', 'a') as file1:
            file1.write("\n// Module: " + infile + "\n")
            file1.write("\n// Module: " + infile + "\n")
            for wire in wires:
            for wire in wires:
                # Everything in globals is a wire
                # Everything in globals is a wire
                # (Can't use 'logic' since some buses are bidirectional)
                # (Can't use 'logic' since some buses are bidirectional)
                if wire in globals:
                if wire in globals:
                    file1.write("// wire " + wire + "; (previously defined)\n")
                    file1.write("// wire " + wire + "; (previously defined)\n")
                else:
                else:
                    file1.write("wire " + wire + ";\n")
                    file1.write("wire " + wire + ";\n")
                    globals.append(wire)
                    globals.append(wire)
 
 
# Touch files that include 'globals.vh' to ensure it will recompile correctly
# Touch files that include 'globals.vh' to ensure it will recompile correctly
os.utime("core.vh", None)
os.utime("core.vh", None)
os.utime("z80_top_direct_n.sv", None)
os.utime("z80_top_direct_n.v", None)
os.utime("z80_top_ifc_n.sv", None)
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.