Exemplo n.º 1
0
def elaborate_entity(entity_name, workdir):
    """Elaborate source file (-e)
    """

    parameters = {
        'ghdl': 'ghdl -e -v',
        'synopsys': '--ieee=synopsys -fexplicit',
        'work': '--workdir="' + workdir + '"',
        'entity': entity_name,
    }
    elaborate_command = ' '.join(parameters.values())
    return run_console_command(elaborate_command)
Exemplo n.º 2
0
def analyze_file(file_path, workdir, additional_libs):
    """Analyze source file (-a)
    """

    additional_libs = ' -P ' + ' -P '.join(
        additional_libs) if additional_libs else ''
    parameters = {
        'ghdl': 'ghdl -a -v',
        'synopsys': '--ieee=synopsys -fexplicit',
        'work': '--workdir="' + workdir + '"',
        'libs': additional_libs,
        'file': '"' + file_path + '"',
    }
    analyze_command = ' '.join(parameters.values())
    return run_console_command(analyze_command)
Exemplo n.º 3
0
def dump_xml_file(file_path, workdir, additional_libs, output_file_path):
    """Generate a (large) XML representation of the VHDL code
    """

    additional_libs = ' -P ' + ' -P '.join(
        additional_libs) if additional_libs else ''
    output_file_path = abspath(output_file_path)
    parameters = {
        'ghdl': 'ghdl --file-to-xml -v',
        'synopsys': '--ieee=synopsys -fexplicit',
        'work': '--workdir="' + workdir + '"',
        'file': '"' + file_path + '"',
    }
    dump_xml_command = ' '.join(parameters.values())
    error, xml = run_console_command(dump_xml_command)
    if not error:
        save_txt(xml, output_file_path)
    return error, output_file_path
Exemplo n.º 4
0
def make_entity(entity_name, workdir, additional_libs, vhdl_standard='93c'):
    """Compile the imported files

    Requires previous import_file.
    """

    workdir = normpath(workdir)
    additional_libs = ' -P' + ' -P'.join(
        additional_libs) if additional_libs else ''
    parameters = {
        'ghdl': 'ghdl -m -v',
        'synopsys': '--ieee=synopsys -fexplicit',
        'standard': (' --std=' + str(vhdl_standard)) if vhdl_standard else '',
        'work': '--workdir="' + workdir + '"',
        'libs': additional_libs,
        'entity': entity_name,
    }
    make_command = ' '.join(parameters.values())
    return run_console_command(make_command) + (make_command, )
Exemplo n.º 5
0
def import_file(file_path, workdir, vhdl_standard='93c'):
    """Import and get the entity and architectures present in the file
    """

    file_path = normpath(file_path)
    workdir = normpath(workdir)
    parameters = {
        'ghdl': 'ghdl -i -v',
        'synopsys': '--ieee=synopsys -fexplicit',
        'standard': (' --std=' + str(vhdl_standard)) if vhdl_standard else '',
        'work': '--workdir="' + workdir + '"',
        'file': '"' + file_path + '"',
    }
    import_command = ' '.join(parameters.values())
    command_run_result = run_console_command(import_command)

    error = command_run_result[0]
    terminal_output = command_run_result[1]
    units_description = parse_included(terminal_output)
    return error, terminal_output, import_command, units_description
Exemplo n.º 6
0
def run_tb(testbench_name, workdir, run_time='1us', generate_waveform=True):
    """Run the desired testbench (-r)

    Provide the entity name in the testbench, not the file name.
    Requires previous (-a, -e) or (-i, -m).
    """

    workdir = normpath(workdir)
    parameters = {
        'ghdl': 'ghdl -r -v',
        'synopsys': '--ieee=synopsys -fexplicit',
        'work': '--workdir="' + workdir + '"',
        'testbench': testbench_name,
        'wave': ('--wave="' + join(workdir, (testbench_name + '.ghw')) + '"') \
                if generate_waveform \
                else '',
        'time': ('--stop-time=' + run_time) \
                if (run_time and not run_time == '0') \
                else '--no-run --disp-tree=port',
    }
    run_command = ' '.join(parameters.values())
    return run_console_command(run_command)
Exemplo n.º 7
0
def generate_cross_references_html(file_path,
                                   workdir,
                                   additional_libs,
                                   output_path=''):
    """Generate a navigable HTML tree of the provided files

    Requires previous make_entity.
    """

    additional_libs = ' -P ' + ' -P '.join(
        additional_libs) if additional_libs else ''
    output_path = abspath(output_path) if output_path else ''
    if not exists(output_path):
        mkdir(output_path)
    parameters = {
        'ghdl': 'ghdl --xref-html -v',
        'synopsys': '--ieee=synopsys -fexplicit',
        'work': '--workdir="' + workdir + '"',
        'format': '--format=css',
        'o': '-o ' + ('"' + output_path + '"') if output_path else '',
        'file': '"' + file_path + '"',
    }
    gen_cross_refs_command = ' '.join(parameters.values())
    return run_console_command(gen_cross_refs_command)
Exemplo n.º 8
0
def compile_vendor(vendor_name,
                   output_path,
                   vendor_install_path,
                   ghdl_install_path,
                   vhdl_standard='93c',
                   recompile=False,
                   verbose=False):
    """Compile vendor libraries

    For a list of supported libraries check your GHDL version.
    This should be run once in the system, the compiled result can be reused by
    pointing to the compiled output directory.
    """

    if vhdl_standard in ('93', '93c', 93):
        vhdl_standard = 'VHDL93'
    elif vhdl_standard in ('2008', '08', 2008, 8):
        vhdl_standard = 'VHDL2008'
    else:
        raise ValueError('Invalid VHDL standard. Valid values are 93, 2008')

    output_path_norm = abspath(output_path)
    if (not recompile) and get_dirs_containing_files(output_path_norm,
                                                     extension='.cf'):
        message = vendor_name + ' libraries found, not recompiling'
        if verbose:
            stdout.write(message + '\n')
        return 2, message
    else:
        if verbose:
            stdout.write('Compiling ' + vendor_name + ' libraries...\n')

    re_vend_srcs = compile(
        'SourceDirectories\[(?P<name>\w+)\]\s*=\s*"(?P<path>(\w|\/|\.)+)')

    with open(join(ghdl_install_path, 'lib/vendors/config.sh'),
              'r',
              encoding='utf-8') as settings_file:
        srcs_dir = {
            re_vend_srcs.search(line).group('name').lower():
            re_vend_srcs.search(line).group('path')
            for line in settings_file.readlines() if re_vend_srcs.search(line)
        }
    vendor_sources_dir = join(
        normpath(vendor_install_path),
        normpath(srcs_dir[vendor_name.lower().replace('-', '')]))

    OS = system()
    compile_vendor_command = \
        normpath( join( join(ghdl_install_path, 'lib/vendors'),
                        ('compile-' + vendor_name + ('.ps1' if OS == 'Windows' else '.sh')) ) ) + \
        ' -Source "' + vendor_sources_dir + '"' + \
        ' -' + vhdl_standard + \
        ' -SuppressWarnings' + \
        ' -Output "' + output_path_norm + '"' + \
        ' -All -GHDL "' + normpath( join(ghdl_install_path, 'bin') ) + '"'
    if OS == 'Windows':
        compile_vendor_command = 'powershell.exe -Command "' + compile_vendor_command + '"'

    if OS not in ('Windows', 'Linux', 'Darwin'):
        raise ValueError(
            'Automatic vendor libs compilation is only available in Linux, Mac and Windows'
        )

    return run_console_command(compile_vendor_command)