OpenCores
URL https://opencores.org/ocsvn/ion/ion/trunk

Subversion Repositories ion

[/] [ion/] [trunk/] [src/] [bin2hdl.py] - Diff between revs 84 and 124

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 84 Rev 124
""" xcxcxc
"""
 
Builds VHDL file from a template by replacing tags with parameter values.
 
See the makefiles of the code samples included in project ION for usage
 
examples.
"""
"""
import sys
import sys
import getopt
import getopt
import math
import math
 
 
 
 
def usage():
def usage():
    print ""
    print ""
    print "usage:"
    print "usage:"
    print "python bin2hdl.py [arguments]\n"
    print "python bin2hdl.py [arguments]\n"
    print "Inserts data in VHDL template\n"
    print "Inserts data in VHDL template\n"
    print "ALL of the following arguments should be given, in any order:"
    print "ALL of the following arguments should be given, in any order:"
    print "{c|code} <filename>        Code binary image file name"
    print "{c|code} <filename>        Code binary image file name"
    print "{v|vhdl} <filename>        VHDL template"
    print "{v|vhdl} <filename>        VHDL template"
    print "{a|architecture} <name>    Name of target VHDL architecture"
    print "{a|architecture} <name>    Name of target VHDL architecture"
    print "{e|entity} <name>          Name of target VHDL entity"
    print "{e|entity} <name>          Name of target VHDL entity"
    print "{o|output} <filename>      Target VHDL file name"
    print "{o|output} <filename>      Target VHDL file name"
    print "code_size <number>         Size of bram memory in words (decimal)"
    print "code_size <number>         Size of bram memory in words (decimal)"
    print "data_size <number>         Size of data memory in words (decimal)"
    print "data_size <number>         Size of data memory in words (decimal)"
    print "flash_size <number>        Size of flash memory in words (decimal)"
    print "flash_size <number>        Size of flash memory in words (decimal)"
    print "(note the flash and xram info are used in simulation only)"
    print "(note the flash and xram info are used in simulation only)"
    print ""
    print ""
    print "Additionally, any of these arguments can be given:"
    print "Additionally, any of these arguments can be given:"
    print "{t|log_trigger} <number>   Fetch address that triggers file logging"
    print "{t|log_trigger} <number>   Fetch address that triggers file logging"
    print "{s|sim_len} <number>       Length of simulation in clock cycles"
    print "{s|sim_len} <number>       Length of simulation in clock cycles"
    print "{d|data} <filename>        Data binary image file name or 'empty'"
    print "{d|data} <filename>        Data binary image file name or 'empty'"
    print "{h|help}                   Display some help text and exit"
    print "{h|help}                   Display some help text and exit"
    print "{i|indent} <number>        Indentation in VHDL tables (decimal)"
    print "{i|indent} <number>        Indentation in VHDL tables (decimal)"
 
 
def help():
def help():
    print "\nPurpose:\n"
    print "\nPurpose:\n"
    print "Reads the code and data binary files and 'slices' them in byte"
    print "Reads the code and data binary files and 'slices' them in byte"
    print "columns."
    print "columns."
    print "The data columns are converted to VHDL strings and then inserted"
    print "The data columns are converted to VHDL strings and then inserted"
    print "into the vhdl template, in place of tags @code0@ .. @code3@ and "
    print "into the vhdl template, in place of tags @code0@ .. @code3@ and "
    print "@data0@ .. @data3@. Column 0 is LSB and column3 is MSB.\n"
    print "@data0@ .. @data3@. Column 0 is LSB and column3 is MSB.\n"
    print "Tags like @data31@ and @data20@ etc. can be used to initialize"
    print "Tags like @data31@ and @data20@ etc. can be used to initialize"
    print "memories in 16-bit buses, also split in byte columns.\n"
    print "memories in 16-bit buses, also split in byte columns.\n"
    print "Other template tags are replaced as follows:"
    print "Other template tags are replaced as follows:"
    print "@entity_name@         : Name of entity in target vhdl file"
    print "@entity_name@         : Name of entity in target vhdl file"
    print "@arch_name@           : Name of architecture in target vhdl file"
    print "@arch_name@           : Name of architecture in target vhdl file"
    print "@sim_len@             : Length of simulation in clock cycles"
    print "@sim_len@             : Length of simulation in clock cycles"
    print "@code_table_size@     : Size of code RAM block, in words"
    print "@code_table_size@     : Size of code RAM block, in words"
    print "@code_addr_size@      : ceil(Log2(@code_table_size@))"
    print "@code_addr_size@      : ceil(Log2(@code_table_size@))"
    print "@data_table_size@     : Size of data RAM block, in words"
    print "@data_table_size@     : Size of data RAM block, in words"
    print "@data_addr_size@      : ceil(Log2(@data_table_size@))"
    print "@data_addr_size@      : ceil(Log2(@data_table_size@))"
 
 
 
 
def build_vhdl_flash_table(flash, table_size, indent_size):
def build_vhdl_flash_table(flash, table_size, indent_size):
    # Build vhdl table for flash data
    # Build vhdl table for flash data
 
 
    # fill up empty table space with zeros
    # fill up empty table space with zeros
    if len(flash) < table_size*4:
    if len(flash) < table_size*4:
        flash = flash + '\0'*4*(table_size-len(flash)/4)
        flash = flash + '\0'*4*(table_size-len(flash)/4)
 
 
    num_words = len(flash)/4
    num_words = len(flash)/4
    remaining = num_words;
    remaining = num_words;
    col = 0
    col = 0
    vhdl_flash_string = "\n" + " "*indent_size
    vhdl_flash_string = "\n" + " "*indent_size
    for w in range(num_words):
    for w in range(num_words):
        b0 = ord(flash[w*4+0]);
        b0 = ord(flash[w*4+0]);
        b1 = ord(flash[w*4+1]);
        b1 = ord(flash[w*4+1]);
        b2 = ord(flash[w*4+2]);
        b2 = ord(flash[w*4+2]);
        b3 = ord(flash[w*4+3]);
        b3 = ord(flash[w*4+3]);
 
 
        if remaining > 1:
        if remaining > 1:
            item = "X\"%02X%02X%02X%02X\"," % (b0, b1, b2, b3)
            item = "X\"%02X%02X%02X%02X\"," % (b0, b1, b2, b3)
        else:
        else:
            item = "X\"%02X%02X%02X%02X\"" % (b0, b1, b2, b3)
            item = "X\"%02X%02X%02X%02X\"" % (b0, b1, b2, b3)
 
 
        remaining = remaining - 1
        remaining = remaining - 1
        col = col + 1
        col = col + 1
        if col == 4:
        if col == 4:
           col = 0
           col = 0
           item = item + "\n" + " "*indent_size
           item = item + "\n" + " "*indent_size
 
 
        vhdl_flash_string = vhdl_flash_string + item
        vhdl_flash_string = vhdl_flash_string + item
 
 
    return vhdl_flash_string
    return vhdl_flash_string
 
 
 
 
 
 
def build_vhdl_tables(code,table_size, indent_size):
def build_vhdl_tables(code,table_size, indent_size):
    # Build the four byte column tables. [0] is LSB, [3] is MSB
    # Build the four byte column tables. [0] is LSB, [3] is MSB
    # Useful only for BRAM and SRAM tables
    # Useful only for BRAM and SRAM tables
    tables = [[0 for i in range(table_size)] for i in range(4)]
    tables = [[0 for i in range(table_size)] for i in range(4)]
 
 
    # Separate binary data into byte columns
    # Separate binary data into byte columns
    # (here's where data endianess matters, we're assuming big endian)
    # (here's where data endianess matters, we're assuming big endian)
    byte = 0    # byte 0 is LSB, 3 is MSB
    byte = 0    # byte 0 is LSB, 3 is MSB
    index = 0   # index into column table    
    index = 0   # index into column table    
    for c in code:
    for c in code:
        #print str(ord(c)) + " " +  str(byte) + " " + str(index)
        #print str(ord(c)) + " " +  str(byte) + " " + str(index)
        tables[3-byte][index] = ord(c)
        tables[3-byte][index] = ord(c)
        #for k in tables:
        #for k in tables:
        #    print k[0:4]
        #    print k[0:4]
        byte = byte + 1
        byte = byte + 1
        if byte == 4:
        if byte == 4:
            byte = 0
            byte = 0
            index = index + 1
            index = index + 1
 
 
    # Write the data for each of the four column tables as a VHDL byte
    # Write the data for each of the four column tables as a VHDL byte
    # constant table.
    # constant table.
    vhdl_data_strings = [" "*indent_size]*7
    vhdl_data_strings = [" "*indent_size]*7
 
 
    for j in range(4):
    for j in range(4):
        col = 0
        col = 0
        word = len(tables[j])
        word = len(tables[j])
        for c in tables[j]:
        for c in tables[j]:
            word = word - 1
            word = word - 1
            if word > 0:
            if word > 0:
                item = "X\"%02X\"," % c
                item = "X\"%02X\"," % c
            else:
            else:
                item = "X\"%02X\"" % c
                item = "X\"%02X\"" % c
            col = col + 1
            col = col + 1
            if col == 8:
            if col == 8:
                col = 0
                col = 0
                item = item + "\n" + " "*indent_size
                item = item + "\n" + " "*indent_size
            vhdl_data_strings[j] = vhdl_data_strings[j] + item
            vhdl_data_strings[j] = vhdl_data_strings[j] + item
        vhdl_data_strings[j] = "\n" + vhdl_data_strings[j]
        vhdl_data_strings[j] = "\n" + vhdl_data_strings[j]
 
 
    # ok, now build init strings for 16-bit wide memories, split in 2 byte 
    # ok, now build init strings for 16-bit wide memories, split in 2 byte 
    # columns: an odd column with bytes 3:1 and an even column with bytes 2:0
    # columns: an odd column with bytes 3:1 and an even column with bytes 2:0
    byte_order = [3,1,2,0]
    byte_order = [3,1,2,0]
    for j in range(2):
    for j in range(2):
        col = 0
        col = 0
        word_count = len(tables[j*2])
        word_count = len(tables[j*2])
        for i in range(word_count):
        for i in range(word_count):
            w_high = tables[byte_order[j*2+0]][i]
            w_high = tables[byte_order[j*2+0]][i]
            w_low  = tables[byte_order[j*2+1]][i]
            w_low  = tables[byte_order[j*2+1]][i]
            word_count = word_count - 1
            word_count = word_count - 1
            if word_count > 0:
            if word_count > 0:
                item_h = "X\"%02X\"," % w_high
                item_h = "X\"%02X\"," % w_high
                item_l = "X\"%02X\"," % w_low
                item_l = "X\"%02X\"," % w_low
            else:
            else:
                item_h = "X\"%02X\"," % w_high
                item_h = "X\"%02X\"," % w_high
                item_l = "X\"%02X\"" % w_low
                item_l = "X\"%02X\"" % w_low
            item = item_h + item_l
            item = item_h + item_l
            col = col + 1
            col = col + 1
            if col == 4:
            if col == 4:
                col = 0
                col = 0
                item = item + "\n" + " "*indent_size
                item = item + "\n" + " "*indent_size
            vhdl_data_strings[4+j] = vhdl_data_strings[4+j] + item
            vhdl_data_strings[4+j] = vhdl_data_strings[4+j] + item
        vhdl_data_strings[4+j] = "\n" + vhdl_data_strings[4+j]
        vhdl_data_strings[4+j] = "\n" + vhdl_data_strings[4+j]
 
 
    # finally, build init strings for 32-bit wide memories not split into 
    # finally, build init strings for 32-bit wide memories not split into 
    # byte columns; useful for read-only 32-bit wide BRAMs
    # byte columns; useful for read-only 32-bit wide BRAMs
    byte_order = [3,2,1,0]
    byte_order = [3,2,1,0]
    col = 0
    col = 0
    word_count = len(tables[0])
    word_count = len(tables[0])
    for i in range(word_count):
    for i in range(word_count):
        w3 = tables[byte_order[0]][i]
        w3 = tables[byte_order[0]][i]
        w2 = tables[byte_order[1]][i]
        w2 = tables[byte_order[1]][i]
        w1 = tables[byte_order[2]][i]
        w1 = tables[byte_order[2]][i]
        w0 = tables[byte_order[3]][i]
        w0 = tables[byte_order[3]][i]
 
 
        word_count = word_count - 1
        word_count = word_count - 1
        if word_count > 0:
        if word_count > 0:
            item = "X\"%02X%02X%02X%02X\"," % (w3, w2, w1, w0)
            item = "X\"%02X%02X%02X%02X\"," % (w3, w2, w1, w0)
        else:
        else:
            item = "X\"%02X%02X%02X%02X\"" % (w3, w2, w1, w0)
            item = "X\"%02X%02X%02X%02X\"" % (w3, w2, w1, w0)
 
 
        col = col + 1
        col = col + 1
        if col == 4:
        if col == 4:
            col = 0
            col = 0
            item = item + "\n" + " "*indent_size
            item = item + "\n" + " "*indent_size
        vhdl_data_strings[6] = vhdl_data_strings[6] + item
        vhdl_data_strings[6] = vhdl_data_strings[6] + item
    vhdl_data_strings[6] = "\n" + vhdl_data_strings[6]
    vhdl_data_strings[6] = "\n" + vhdl_data_strings[6]
 
 
 
 
 
 
    return vhdl_data_strings
    return vhdl_data_strings
 
 
def main(argv):
def main(argv):
    code_filename = ""          # file with bram contents ('code')
    code_filename = ""          # file with bram contents ('code')
    data_filename = ""          # file with xram contents ('data')
    data_filename = ""          # file with xram contents ('data')
    flash_filename = ""         # file with flash contents ('flash')
    flash_filename = ""         # file with flash contents ('flash')
    vhdl_filename = ""          # name of vhdl template file
    vhdl_filename = ""          # name of vhdl template file
    entity_name = "mips_tb"     # name of vhdl entity to be generated
    entity_name = "mips_tb"     # name of vhdl entity to be generated
    arch_name = "testbench"     # name of vhdl architecture to be generated
    arch_name = "testbench"     # name of vhdl architecture to be generated
    target_filename = "tb.vhdl" # name of target vhdl file
    target_filename = "tb.vhdl" # name of target vhdl file
    indent = 4                  # indentation for table data, in spaces
    indent = 4                  # indentation for table data, in spaces
    code_table_size = -1        # size of VHDL table
    code_table_size = -1        # size of VHDL table
    data_table_size = -1        # size of VHDL table
    data_table_size = -1        # size of VHDL table
    flash_table_size = 32;      # default size of flash table in 32-bit words
    flash_table_size = 32;      # default size of flash table in 32-bit words
    log_trigger_addr = "X\"FFFFFFFF\"" # default log trigger address
    log_trigger_addr = "X\"FFFFFFFF\"" # default log trigger address
    flash = ['\0']*4*flash_table_size # default simulated flash
    flash = ['\0']*4*flash_table_size # default simulated flash
    bin_words = 0               # size of binary file in 32-bit words 
    bin_words = 0               # size of binary file in 32-bit words 
    simulation_length = 22000   # length of logic simulation in clock cycles
    simulation_length = 22000   # length of logic simulation in clock cycles
 
 
    #
    #
 
 
    try:
    try:
        opts, args = getopt.getopt(argv, "hc:d:v:a:e:o:i:s:f:t:",
        opts, args = getopt.getopt(argv, "hc:d:v:a:e:o:i:s:f:t:",
        ["help", "code=", "data=", "vhdl=", "architecture=",
        ["help", "code=", "data=", "vhdl=", "architecture=",
         "entity=", "output=", "indent=", "sim_len=", "flash=", "log_trigger=",
         "entity=", "output=", "indent=", "sim_len=", "flash=", "log_trigger=",
         "code_size=", "data_size=", "flash_size="])
         "code_size=", "data_size=", "flash_size="])
    except getopt.GetoptError, err:
    except getopt.GetoptError, err:
        print ""
        print ""
        print err
        print err
        usage()
        usage()
        sys.exit(2)
        sys.exit(2)
 
 
    # Parse coommand line parameters
    # Parse coommand line parameters
    for opt, arg in opts:
    for opt, arg in opts:
        if opt in ("-h", "--help"):
        if opt in ("-h", "--help"):
            usage()
            usage()
            help()
            help()
            exit(1)
            exit(1)
        if opt in ("-v", "--vhdl"):
        if opt in ("-v", "--vhdl"):
            vhdl_filename = arg
            vhdl_filename = arg
        elif opt in ("-o", "--output"):
        elif opt in ("-o", "--output"):
            target_filename = arg
            target_filename = arg
        elif opt in ("-c", "--code"):
        elif opt in ("-c", "--code"):
            code_filename = arg
            code_filename = arg
        elif opt in ("-d", "--data"):
        elif opt in ("-d", "--data"):
            data_filename = arg
            data_filename = arg
        elif opt in ("-f", "--flash"):
        elif opt in ("-f", "--flash"):
            flash_filename = arg
            flash_filename = arg
        elif opt in ("-a", "--architecture"):
        elif opt in ("-a", "--architecture"):
            arch_name = arg
            arch_name = arg
        elif opt in ("-e", "--entity"):
        elif opt in ("-e", "--entity"):
            entity_name = arg
            entity_name = arg
        elif opt in ("-i", "--indent"):
        elif opt in ("-i", "--indent"):
            indent = int(arg)
            indent = int(arg)
        elif opt in ("-t", "--log_trigger"):
        elif opt in ("-t", "--log_trigger"):
            log_trigger_addr = "X\"%08X\"" % (int(arg,16))
            log_trigger_addr = "X\"%08X\"" % (int(arg,16))
        elif opt in ("-s", "--sim_len"):
        elif opt in ("-s", "--sim_len"):
            simulation_length = int(arg)
            simulation_length = int(arg)
        elif opt == "--code_size":
        elif opt == "--code_size":
            code_table_size = int(arg)
            code_table_size = int(arg)
        elif opt == "--data_size":
        elif opt == "--data_size":
            data_table_size = int(arg)
            data_table_size = int(arg)
        elif opt == "--flash_size":
        elif opt == "--flash_size":
            flash_table_size = int(arg)
            flash_table_size = int(arg)
 
 
    # See if all mandatory options are there
    # See if all mandatory options are there
    if code_filename=="" or vhdl_filename=="" or \
    if code_filename=="" or vhdl_filename=="" or \
       code_table_size < 0 or data_table_size<0:
       code_table_size < 0 or data_table_size<0:
        print "Some mandatory parameter is missing\n"
        print "Some mandatory parameter is missing\n"
        usage()
        usage()
        sys.exit(2)
        sys.exit(2)
 
 
    #---------------------------------------------------------------------------    
    #---------------------------------------------------------------------------    
    # Read BRAM initialization file, if any
    # Read BRAM initialization file, if any
    try:
    try:
        fin = open(code_filename, "rb")
        fin = open(code_filename, "rb")
        code = fin.read()
        code = fin.read()
        fin.close()
        fin.close()
    except IOError:
    except IOError:
        print "Binary File %s not found" % code_filename
        print "Binary File %s not found" % code_filename
 
 
    # Make sure the code and data will fit in the tables
    # Make sure the code and data will fit in the tables
    bin_words = len(code) / 4
    bin_words = len(code) / 4
    if bin_words > code_table_size:
    if bin_words > code_table_size:
        print "Code does not fit table: " + str(bin_words) + " words,",
        print "Code does not fit table: " + str(bin_words) + " words,",
        print str(code_table_size) + " table entries"
        print str(code_table_size) + " table entries"
        sys.exit(1)
        sys.exit(1)
 
 
    # Build the VHDL strings for each slice of the BRAM tables
    # Build the VHDL strings for each slice of the BRAM tables
    vhdl_code_strings = build_vhdl_tables(code, code_table_size, indent)
    vhdl_code_strings = build_vhdl_tables(code, code_table_size, indent)
 
 
 
 
    #---------------------------------------------------------------------------
    #---------------------------------------------------------------------------
    # Read XRAM initialization file, if any.
    # Read XRAM initialization file, if any.
    if data_filename != "":
    if data_filename != "":
        if data_filename == "empty":
        if data_filename == "empty":
            data = []
            data = []
        else:
        else:
            try:
            try:
                fin = open(data_filename, "rb")
                fin = open(data_filename, "rb")
                data = fin.read()
                data = fin.read()
                fin.close()
                fin.close()
            except IOError:
            except IOError:
                print "Binary File %s not found" % data_filename
                print "Binary File %s not found" % data_filename
 
 
        # FIXME We're not checking for BSS size here, only .data (?)
        # FIXME We're not checking for BSS size here, only .data (?)
        bin_words = len(data) / 4
        bin_words = len(data) / 4
        if bin_words > data_table_size:
        if bin_words > data_table_size:
            print "Data does not fit table: " + str(bin_words) + " words,",
            print "Data does not fit table: " + str(bin_words) + " words,",
            print str(data_table_size) + " table entries"
            print str(data_table_size) + " table entries"
            sys.exit(1)
            sys.exit(1)
 
 
        vhdl_data_strings = build_vhdl_tables(data, data_table_size, indent)
        vhdl_data_strings = build_vhdl_tables(data, data_table_size, indent)
    else:
    else:
        # In case we didn't get a data binary, we will initialize any XRAM in
        # In case we didn't get a data binary, we will initialize any XRAM in
        # the template with zeros
        # the template with zeros
        vhdl_data_strings = (["(others => X\"00\")"]*4) + \
        vhdl_data_strings = (["(others => X\"00\")"]*4) + \
                            (["(others => X\"00\")"]*2) + \
                            (["(others => X\"00\")"]*2) + \
                            (["(others => X\"00000000\")"])
                            (["(others => X\"00000000\")"])
 
 
 
 
    #---------------------------------------------------------------------------
    #---------------------------------------------------------------------------
    # Read FLASH initialization file, if any 
    # Read FLASH initialization file, if any 
 
 
    if flash_filename != "":
    if flash_filename != "":
        if flash_filename == "empty":
        if flash_filename == "empty":
            flash = [0]*flash_table_size
            flash = [0]*flash_table_size
        else:
        else:
            try:
            try:
                fin = open(flash_filename, "rb")
                fin = open(flash_filename, "rb")
                flash = fin.read()
                flash = fin.read()
                fin.close()
                fin.close()
            except IOError:
            except IOError:
                print "Binary File %s not found" % flash_filename
                print "Binary File %s not found" % flash_filename
 
 
        # make sure file will fit simulated FLASH size
        # make sure file will fit simulated FLASH size
        bin_words = len(flash) / 4
        bin_words = len(flash) / 4
        if bin_words > flash_table_size:
        if bin_words > flash_table_size:
            print "Flash data does not fit table: " + str(bin_words) + " words,",
            print "Flash data does not fit table: " + str(bin_words) + " words,",
            print str(flash_table_size) + " table entries"
            print str(flash_table_size) + " table entries"
            sys.exit(1)
            sys.exit(1)
 
 
 
 
        # Build the VHDL strings for the simulated FLASH
        # Build the VHDL strings for the simulated FLASH
    vhdl_flash_string = build_vhdl_flash_table(flash, flash_table_size, indent)
    vhdl_flash_string = build_vhdl_flash_table(flash, flash_table_size, indent)
 
 
 
 
    #===========================================================================
    #===========================================================================
    # OK, we just read all binary files and built all VHDL memory initialization
    # OK, we just read all binary files and built all VHDL memory initialization
    # strings. Now start scanning the VHDL template, inserting data where needed
    # strings. Now start scanning the VHDL template, inserting data where needed
 
 
    # Read template file...
    # Read template file...
    fin = open(vhdl_filename, "r")
    fin = open(vhdl_filename, "r")
    vhdl_lines = fin.readlines()
    vhdl_lines = fin.readlines()
    fin.close()
    fin.close()
 
 
    # ...and build the keyword and replacement tables
    # ...and build the keyword and replacement tables
    keywords = ["@code0@","@code1@","@code2@","@code3@",
    keywords = ["@code0@","@code1@","@code2@","@code3@",
                "@code31@", "@code20@",
                "@code31@", "@code20@",
                "@code-32bit@",
                "@code-32bit@",
                "@data0@","@data1@","@data2@","@data3@",
                "@data0@","@data1@","@data2@","@data3@",
                "@data31@", "@data20@",
                "@data31@", "@data20@",
                "@data-32bit@",
                "@data-32bit@",
                "@flash@",
                "@flash@",
                "@entity_name@","@arch_name@",
                "@entity_name@","@arch_name@",
                "@sim_len@",
                "@sim_len@",
                "@xram_size@",
                "@xram_size@",
                "@code_table_size@","@code_addr_size@",
                "@code_table_size@","@code_addr_size@",
                "@data_table_size@","@data_addr_size@",
                "@data_table_size@","@data_addr_size@",
                "@prom_size@",
                "@prom_size@",
                "@log_trigger_addr@"];
                "@log_trigger_addr@"];
    replacement = vhdl_code_strings + vhdl_data_strings + \
    replacement = vhdl_code_strings + vhdl_data_strings + \
                 [vhdl_flash_string,
                 [vhdl_flash_string,
                  entity_name, arch_name,
                  entity_name, arch_name,
                  str(simulation_length),
                  str(simulation_length),
                  str(data_table_size),
                  str(data_table_size),
                  str(code_table_size),
                  str(code_table_size),
                  str(int(math.floor(math.log(code_table_size,2)))),
                  str(int(math.floor(math.log(code_table_size,2)))),
                  str(data_table_size),
                  str(data_table_size),
                  str(int(math.floor(math.log(data_table_size,2)))),
                  str(int(math.floor(math.log(data_table_size,2)))),
                  str(flash_table_size),
                  str(flash_table_size),
                  log_trigger_addr]
                  log_trigger_addr]
 
 
    # Now traverse the template lines replacing any keywords with the proper 
    # Now traverse the template lines replacing any keywords with the proper 
    # vhdl stuff we just built above.
    # vhdl stuff we just built above.
    output = ""
    output = ""
    for vhdl_line in vhdl_lines:
    for vhdl_line in vhdl_lines:
        temp = vhdl_line
        temp = vhdl_line
        for i in range(len(keywords)):
        for i in range(len(keywords)):
            if temp.rfind(keywords[i]) >= 0:
            if temp.rfind(keywords[i]) >= 0:
                temp = temp.replace(keywords[i], replacement[i])
                temp = temp.replace(keywords[i], replacement[i])
                # uncomment this break to check for ONE keyword per line only
                # uncomment this break to check for ONE keyword per line only
                #break
                #break
        output = output + temp
        output = output + temp
 
 
    try:
    try:
        fout = open(target_filename, "w")
        fout = open(target_filename, "w")
        fout.write(output)
        fout.write(output)
        fout.close()
        fout.close()
        print "Wrote VHDL file '%s'" % target_filename
        print "Wrote VHDL file '%s'" % target_filename
    except IOError:
    except IOError:
        print "Could not write to file %s" % target_filename
        print "Could not write to file %s" % target_filename
 
 
 
 
    sys.exit(0)
    sys.exit(0)
 
 
 
 
 
 
if __name__ == "__main__":
if __name__ == "__main__":
    main(sys.argv[1:])
    main(sys.argv[1:])
 
 
    sys.exit(0)
    sys.exit(0)
 
 
 
 

powered by: WebSVN 2.1.0

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