<commit_before>import math
TOPNAME = 'top.sv'
F_INIT = 'init.txt'
INIT_FRMT = "hex"
WID_MEM = 16
DEPTH_MEM = 2048
COUNT = None


def main():
    import sys
    fname = sys.argv[1]
    width = sys.argv[2]
    depth = sys.argv[3]
    f_init = sys.argv[4]
    init_frmt = "hex"  # sys.argv[5]

    if type(width) is str:
        width = int(width)
    if type(depth) is str:
        depth = int(depth)

    write_topfile(
        fname=fname,
        wid_mem=width,
        depth_mem=depth,
        f_init=f_init,
        init_frmt=init_frmt
    )
    print('Wrote {} with init file {}'.format(fname, f_init))


def write_topfile(fname, wid_mem, f_init, depth_mem, init_frmt):
    addr_wid = int(math.log(depth_mem, 2))
    # print('{}'.format(addr_wid))
    with open(fname, 'w') as f:
        write_top_hdr(f=f, wid_mem=wid_mem, addr_wid=addr_wid)
        write_module(
            f=f,
            f_init=f_init,
            init_frmt=init_frmt,
            wid_mem=wid_mem,
            depth_mem=depth_mem
        )
        write_end(f, addr_wid)


def write_top_hdr(f, addr_wid, wid_mem=WID_MEM, dout_count=COUNT):
    module = 'module top(\n'
    module += 'input logic clk,\n'
    module += 'input logic[{}:0] raddr,\n'.format(addr_wid - 1)
    module += 'input logic[{}:0] waddr,\n'.format(addr_wid - 1)
    module += 'input logic [{}:0] din,\n'.format(wid_mem - 1)
    if dout_count is not None:
        for x in range(dout_count):
            module += 'output logic [{}:0] dout{},\n'.format(wid_mem - 1, x)
    else:
        module += 'output logic [{}:0] dout,\n'.format(wid_mem - 1)
    module += 'input logic reset);\n\n'
    f.write(module)


def write_module(
        f,
        f_init=F_INIT,
        init_frmt=INIT_FRMT,
        wid_mem=WID_MEM,
        depth_mem=DEPTH_MEM,
        suffix=None
):
    if init_frmt == "hex":
        init_frmt = 1
    else:
        init_frmt = 0

    modline = 'memory #('
    modline += '"{}", {}, {}, {}) '.format(
        f_init, init_frmt, wid_mem, depth_mem
    )
    if suffix is not None:
        modline += 'mem{} (\n'.format(suffix)
    else:
        modline += 'mem(\n'<commit_msg>Used updated yapf to reformat python code<commit_after>import math
TOPNAME = 'top.sv'
F_INIT = 'init.txt'
INIT_FRMT = "hex"
WID_MEM = 16
DEPTH_MEM = 2048
COUNT = None


def main():
    import sys
    fname = sys.argv[1]
    width = sys.argv[2]
    depth = sys.argv[3]
    f_init = sys.argv[4]
    init_frmt = "hex"  # sys.argv[5]

    if type(width) is str:
        width = int(width)
    if type(depth) is str:
        depth = int(depth)

    write_topfile(
        fname=fname,
        wid_mem=width,
        depth_mem=depth,
        f_init=f_init,
        init_frmt=init_frmt
    )
    print('Wrote {} with init file {}'.format(fname, f_init))


def write_topfile(fname, wid_mem, f_init, depth_mem, init_frmt):
    addr_wid = int(math.log(depth_mem, 2))
    # print('{}'.format(addr_wid))
    with open(fname, 'w') as f:
        write_top_hdr(f=f, wid_mem=wid_mem, addr_wid=addr_wid)
        write_module(
            f=f,
            f_init=f_init,
            init_frmt=init_frmt,
            wid_mem=wid_mem,
            depth_mem=depth_mem
        )
        write_end(f, addr_wid)


def write_top_hdr(f, addr_wid, wid_mem=WID_MEM, dout_count=COUNT):
    module = 'module top(\n'
    module += 'input logic clk,\n'
    module += 'input logic[{}:0] raddr,\n'.format(addr_wid - 1)
    module += 'input logic[{}:0] waddr,\n'.format(addr_wid - 1)
    module += 'input logic [{}:0] din,\n'.format(wid_mem - 1)
    if dout_count is not None:
        for x in range(dout_count):
            module += 'output logic [{}:0] dout{},\n'.format(wid_mem - 1, x)
    else:
        module += 'output logic [{}:0] dout,\n'.format(wid_mem - 1)
    module += 'input logic reset);\n\n'
    f.write(module)


def write_module(
    f,
    f_init=F_INIT,
    init_frmt=INIT_FRMT,
    wid_mem=WID_MEM,
    depth_mem=DEPTH_MEM,
    suffix=None
):
    if init_frmt == "hex":
        init_frmt = 1
    else:
        init_frmt = 0

    modline = 'memory #('
    modline += '"{}", {}, {}, {}) '.format(
        f_init, init_frmt, wid_mem, depth_mem
    )
    if suffix is not None:
        modline += 'mem{} (\n'.format(suffix)
    else:
        modline += 'mem(\n'
{'fraction_non_alphanumeric': 0.1452592246613732, 'fraction_numerical': 0.011209715086408221, 'mean_word_length': 2.364493322859387, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4077793', 'n_tokens_mistral': 1670, 'n_tokens_neox': 1629, 'n_words': 345}