Пример #1
0
    def _parse_tables(report_str: str) -> Dict[str, str]:
        """Parse the tables from a fitter report

        Keys are the title of the table, values are the table body
        """

        hline = pp.lineStart() + pp.Word("+", "+-") + pp.lineEnd()

        title = (
            pp.lineStart()
            + ";"
            + pp.SkipTo(";")("title").setParseAction(pp.tokenMap(str.strip))
            + ";"
            + pp.lineEnd()
        )

        # Grab everything until the next horizontal line(s). Tables with
        # column headings will have a horizontal line after the headings and
        # at the end of the table. Odd tables without section headings will
        # only have a single horizontal line.
        data = pp.SkipTo(hline, failOn=pp.lineEnd() * 2, include=True)

        table = hline + title + pp.Combine(hline + data * (1, 2))("body")

        # Make line endings significant
        table.setWhitespaceChars(" \t")

        result = {t.title: t.body for t in table.searchString(report_str)}

        return result
Пример #2
0
    def _parse_map_tables(report_str: str) -> Dict[str, str]:
        """
        Parse the tables from a ISE map report.

        Keys are the title of the table, values are the table body.
        """

        # Capture the title from section headings like:
        #
        # Section 12 - Control Set Information
        # ------------------------------------

        title = (
            pp.lineStart()
            + "Section"
            + ppc.integer
            + "-"
            + pp.SkipTo(pp.lineEnd())("title").setParseAction(pp.tokenMap(str.strip))
            + pp.lineEnd()
        )

        sec_hline = pp.Suppress(pp.lineStart() + pp.Word("-") + pp.lineEnd() * (1,))

        # Table horizontal lines like
        # +-------------------------------+
        hline = pp.lineStart() + pp.Word("+", "+-") + pp.lineEnd()

        # Most tables will have the format
        # +-----------------------+
        # | Col 1 | Col 2 | Col 3 |
        # +-----------------------+
        # | D1    | D2    | D3    |
        # ...
        # +-----------------------+
        #
        # However "Control Set Information" appears to use horizontal lines to
        # separate clocks within the data section. Therefore, just grab
        # everything until a horizontal line followed by a blank line rather
        # than something more precise.

        table = pp.Combine(hline + pp.SkipTo(hline + pp.LineEnd(), include=True))(
            "body"
        )
        table_section = title + sec_hline + table

        # Make line endings significant
        table_section.setWhitespaceChars(" \t")

        result = {t.title: t.body for t in table_section.searchString(report_str)}

        return result
Пример #3
0
    def _parse_utilization_tables(util_str: str) -> Dict[str, str]:
        """
        Find all of the section titles and tables in a Vivado utilization report.

        These are returned as a dict with the section titles as keys and the table as the value.
        """

        # Find section headings, discarding the number and following horizontal
        # line. For example:
        #
        # 1.1 Summary of Registers by Type
        # --------------------------------

        sec_num = pp.Suppress(pp.lineStart() + pp.Word(pp.nums + "."))
        sec_title = sec_num + pp.SkipTo(
            pp.lineEnd())("title") + pp.lineEnd().suppress()

        # -------------------------------
        sec_hline = pp.Suppress(pp.lineStart() + pp.Word("-") + pp.lineEnd())
        sec_head = sec_title + sec_hline + pp.lineEnd().suppress()

        # Tables use horizontal lines with like the following to mark column
        # headings and the end of the table:
        #
        # +------+------+-------+

        table_hline = pp.lineStart() + pp.Word("+", "-+") + pp.lineEnd()

        # Tables may just be a header with no data rows, or a full header and
        # data rows, so there will be one or two more horizontal lines.

        data = pp.SkipTo(table_hline, failOn=pp.lineEnd() * 2, include=True)

        table = pp.Combine(table_hline + data * (1, 2))

        section = sec_head + table("table")

        # Make line endings significant
        section.setWhitespaceChars(" \t")

        table_dict = {
            x["title"]: x["table"]
            for x in section.searchString(util_str)
        }

        return table_dict
Пример #4
0
# C++ Syntax Description

import pyparsing as pp

from cpp_lang import *
from cpp_builders import *
from pp_utils import *

# comments need to be removed
comment = (pp.cStyleComment | pp.cppStyleComment)
preprocessor = pp.lineStart() + pp.Word('#', pp.alphas) + pp.SkipTo( pp.lineEnd() )
preprocessor.setWhitespaceChars(' \r\t')

identifier  = pp.Word( pp.alphas + '_', pp.alphanums + '_' )
persistency = pp.Keyword('static'  ).setParseAction( pp.replaceWith(TypeArgs.STATIC_TYPE)   )
volatility  = pp.Keyword('const'   ).setParseAction( pp.replaceWith(TypeArgs.CONST_TYPE )   ) \
            | pp.Keyword('volatile').setParseAction( pp.replaceWith(TypeArgs.VOLATILE_TYPE) )

reference = pp.Literal('*').setParseAction( pp.replaceWith(CppPointerTypeExpression.POINTER_VAR  ) ) \
          | pp.Literal('&').setParseAction( pp.replaceWith(CppPointerTypeExpression.REFERENCE_VAR) )

# member function on const object
const_function    = pp.Keyword('const'  ).setParseAction( pp.replaceWith(FunctionArgs.CONST_FUNCTION     ) )
virtual_function  = pp.Keyword('virtual').setParseAction( pp.replaceWith(FunctionArgs.VIRTUAL_FUNCTION   ) )
destructor_tag    = pp.Literal('~'      ).setParseAction( pp.replaceWith(FunctionArgs.DESTRUCTOR_FUNCTION) )
abstract_function = (pp.Literal('=') + pp.Literal('0')).setParseAction( pp.replaceWith(FunctionArgs.ABSTRACT_FUNCTION))
inline_function   = pp.Keyword('inline').setParseAction( pp.replaceWith(FunctionArgs.INLINE_FUNCTION) )

complex_type = pp.Keyword('class' ).setParseAction(pp.replaceWith(CppComplexTypeDefinition.CLASS )) \
             | pp.Keyword('struct').setParseAction(pp.replaceWith(CppComplexTypeDefinition.STRUCT)) \
             | pp.Keyword('union' ).setParseAction(pp.replaceWith(CppComplexTypeDefinition.UNION ))
Пример #5
0
    def _parse_timing_summary_tables(time_rpt: str):
        """
        Return tables from a Vivado timing summary report.

        This currently only handles basic tables such as "Design Timing
        Summary" and "Clock Summary". The more complex data in "Timing Details"
        such as worst paths, etc. isn't parsed.
        """

        # Make newlines widely significant but be careful not to effect others
        saved_whitespace = pp.ParserElement.DEFAULT_WHITE_CHARS
        pp.ParserElement.setDefaultWhitespaceChars(" \t")

        # Extract table title ("Clock Summary") from a section heading like:
        #
        # --------------------------------------------------------------
        # | Clock Summary
        # | -------------
        # --------------------------------------------------------------
        sec_hline = pp.lineStart() + pp.Word("-") + pp.lineEnd()
        sec_row_start = pp.lineStart() + pp.Literal("|").suppress()
        sec_title = (sec_row_start + pp.SkipTo(pp.lineEnd())("title") +
                     pp.lineEnd().suppress())
        sec_title_uline = sec_row_start + pp.Suppress(
            pp.Word("-") + pp.lineEnd())

        section_head = sec_hline + sec_title + sec_title_uline + sec_hline

        blank_line = pp.Suppress(pp.lineEnd() * 2)

        # Tables are headings followed by lines and then data.
        #
        # Clock  Waveform(ns)         Period(ns)      Frequency(MHz)
        # -----  ------------         ----------      --------------
        # clk    {0.000 2.500}        5.000           200.000

        # Match two or more groups of dashes to avoid matching long single
        # horizontal lines used elsewhere. Normally the spaces between the
        # groups of dashes would be consumed, so get them back with
        # originalTextFor(). It would be safer to anchor this to the start of
        # the line, but "Design Timing Summary" and perhaps others indent the
        # table for some reason

        table_hline = pp.originalTextFor(pp.Word("-") * (2, ) + pp.lineEnd())

        # Get any header rows above the horizontal lines
        table_head = pp.SkipTo(table_hline, failOn=blank_line)

        # Get everything from the horizontal lines to an empty line
        table_body = pp.SkipTo(blank_line)

        # The adjacent argument shouldn't be required but it doesn't match
        # anything without it. It seems like the newline at the end of the
        # heading row may not be getting included somehow.

        table = pp.Combine(table_head + table_hline + table_body,
                           adjacent=False)("table")

        section = section_head + pp.lineEnd().suppress() + table

        # Restore whitespace characters
        pp.ParserElement.setDefaultWhitespaceChars(saved_whitespace)

        table_dict = {
            x["title"]: x["table"]
            for x in section.searchString(time_rpt)
        }

        return table_dict