Skip to content

Triple quote in name or desc field #169

@krcb197

Description

@krcb197

Whilst looking at the #167 issue, an interesting case was observed:

The following systemRDL code is legal:

field fieldtype {
        fieldwidth=1;
        };

addrmap reg_name_stress {

    reg {name="A register name \"\"\" this messes up the docstrings";
        fieldtype field_a;} reg_f;
  
};

This will result in the following auto-generated python code:

class reg_name_stress_reg_f_cls(RegReadWrite):
    """
    Class to represent a register in the register model

    +--------------+-------------------------------------------------------------------------+
    | SystemRDL    | Value                                                                   |
    | Field        |                                                                         |
    +==============+=========================================================================+
    | Name         | .. raw:: html                                                           |
    |              |                                                                         |
    |              |      A register name """ this messes up the docstrings                  |
    +--------------+-------------------------------------------------------------------------+
    """

    __slots__ : list[str] = ['__field_a']

    def __init__(self,
                 address: int,
                 width: int,
                 accesswidth: int,
                 logger_handle: str,
                 inst_name: str,
                 parent: Union[AddressMap,RegFile,MemoryReadWrite]):

        super().__init__(address=address,
                         width=width,
                         accesswidth=accesswidth,
                         logger_handle=logger_handle,
                         inst_name=inst_name,
                         parent=parent)

        # build the field attributes
        
        self.__field_a:fieldtype_0x0x1a3a343014_cls = fieldtype_0x0x1a3a343014_cls(
            parent_register=self,
            size_props=FieldSizeProps(
                width=1,
                lsb=0,
                msb=0,
                low=0,
                high=0),
            misc_props=FieldMiscProps(
                default=None,
                is_volatile=True),
            logger_handle=logger_handle+'.field_a',
            inst_name='field_a')

    @property
    def fields(self) -> Iterator[Union[FieldReadOnly, FieldWriteOnly,FieldReadWrite]]:
        """
        generator that produces has all the fields within the register
        """
        yield self.field_a
        
        # Empty generator in case there are no children of this type
        if False: yield
    # build the properties for the fields
    
    @property
    def field_a(self) -> fieldtype_0x0x1a3a343014_cls:
        """
        Property to access field_a field of the register

        
        """
        return self.__field_a

    @property
    def systemrdl_python_child_name_map(self) -> dict[str, str]:
        """
        In some cases systemRDL names need to be converted make them python safe, this dictionary
        is used to map the original systemRDL names to the names of the python attributes of this
        class

        Returns: dictionary whose key is the systemRDL names and value it the property name
        """
        return {
                
            'field_a':'field_a',
                
            }

The triple quote is propagated into the docstring, which results in in being terminated early.

The bug is somewhat similar to SystemRDL/PeakRDL-html#53

It may require a fix to be made in the compiler, as that may be the best place to address the problem in get_html_name and get_html_desc methods.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions