Skip to content

Optimise the traversal iterators #144

@krcb197

Description

@krcb197

At the moment all the traversal iterators are generated explicitly, for example the following definition of a registers:

reg {
        default sw = rw;
        default hw = r;
        field { fieldwidth=8; } basicfield_h;
        field { fieldwidth=8; } basicfield_i;
        field { fieldwidth=8; } basicfield_j;
        field { fieldwidth=8; } basicfield_k;
    } basicreg_e;

results in the following code:

    @property
    def fields(self) -> Iterator[Union[FieldReadOnly, FieldWriteOnly,FieldReadWrite]]:
        """
        generator that produces has all the fields within the register
        """
        yield self.basicfield_h
        yield self.basicfield_i
        yield self.basicfield_j
        yield self.basicfield_k
        
        # Empty generator in case there are no children of this type
        if False: yield

    
    @property
    def readable_fields(self) -> Iterator[Union[FieldReadOnly, FieldReadWrite]]:
        """
        generator that produces has all the readable fields within the register
        """
        yield self.basicfield_h
        yield self.basicfield_i
        yield self.basicfield_j
        yield self.basicfield_k
        
        # Empty generator in case there are no children of this type
        if False: yield
    

    
    @property
    def writable_fields(self) -> Iterator[Union[FieldWriteOnly, FieldReadWrite]]:
        """
        generator that produces has all the writable fields within the register
        """
        yield self.basicfield_h
        yield self.basicfield_i
        yield self.basicfield_j
        yield self.basicfield_k
        
        # Empty generator in case there are no children of this type
        if False: yield

This could be improved by including code in the library to self-examine itself using vars and filter out the correct types

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions