Skip to content

Structure Types

Structure Types.

A structure assembles multiple type, name, orientation pairs.

  • :any:StructItem - Struct item
  • :any:StructType - Standard Struct
  • :any:AAGlobalStructType - A public struct which fills up through all instances.
  • :any:DynamicStructType - A public struct which fills up per instance.

StructItem

Bases: Object

Struct NamedObject.

Parameters:

Name Type Description Default
name

Name of struct member

required
type_

Type of struct member

required

Other Parameters:

Name Type Description
orientation

Orientation of struct member. FWD by default

doc

Documentation Container

ifdef

IFDEF encapsulation

title property

title

Alias to doc.title.

descr property

descr

Alias to doc.descr.

comment property

comment

Alias to doc.comment.

BaseStructType

Bases: Dict, ACompositeType

Base Type for all Structs.

bits property

bits

Size in Bits.

is_connectable

is_connectable(other)

Check For Valid Connection To other.

AStructType

Bases: BaseStructType, Light

Base class for all structural types.

The protected method _build() should be used to build the type.

Definition of a struct:

import ucdp as u class BusType(u.AStructType): ... def _build(self) -> None: ... self._add('data', u.UintType(8)) ... self._add('valid', u.BitType()) ... self._add('accept', u.BitType(), orientation=u.BWD)

Usage of a Struct:

bus = BusType() bus BusType()

The structs behave like a dict, with elements hashed by name. But different to a regular dict, it returns items on pure iteration:

bus.keys() dict_keys(['data', 'valid', 'accept']) bus.values() dict_values([StructItem('data', UintType(8)), StructItem('valid', BitType()), ...]) bus.items() dict_items([('data', StructItem('data', UintType(8))), ('valid', StructItem(...]) bus['valid'] StructItem('valid', BitType()) bus.bits 10

Connections are only allowed to other :any:AStructType with the same key-value mapping. Default and isolation values are ignored.

BusType().is_connectable(BusType()) True

class Bus2Type(u.AStructType): ... def _build(self) -> None: ... self._add('data', u.UintType(8)) ... self._add('valid', u.BitType()) ... self._add('accept', u.BitType(), orientation=u.FWD) BusType().is_connectable(Bus2Type()) False

class Bus3Type(u.AStructType): ... def _build(self) -> None: ... self._add('data', u.UintType(8), title="title") ... self._add('valid', u.BitType(default=1)) ... self._add('accept', u.BitType(), orientation=u.BWD) BusType().is_connectable(Bus3Type()) True

Struct members can be filtered. A struct member is added if the filter function returns True on a given :any:StructItem as argument.

def myfilter(structitem): ... return "t" in structitem.name for item in BusType(filter_=myfilter).values(): item StructItem('data', UintType(8)) StructItem('accept', BitType(), orientation=BWD)

There are also these predefined filters:

for item in BusType(filter_=u.fwdfilter).values(): item StructItem('data', UintType(8)) StructItem('valid', BitType())

for item in BusType(filter_=u.bwdfilter).values(): item StructItem('accept', BitType(), orientation=BWD)

This works also with the new() method:

for item in BusType().new(filter_=u.fwdfilter).values(): item StructItem('data', UintType(8)) StructItem('valid', BitType())

model_post_init

model_post_init(__context)

Run Build.

AGlobalStructType

Bases: BaseStructType, Light

A singleton struct which can be filled outside _build and is shared between instances.

import ucdp as u class BusType(u.AGlobalStructType): ... pass bus = BusType() bus.add('data', u.UintType(8)) bus.add('valid', u.BitType()) bus = BusType() bus.add('accept', u.BitType(), orientation=u.BWD) tuple(bus) ('data', 'valid', 'accept')

This is forbidden on normal struct:

class BusType(u.AStructType): ... def _build(self) -> None: ... pass bus = BusType() bus._add('data', u.UintType(8)) Traceback (most recent call last): ... ucdp.exceptions.LockError: BusType(): Cannot add item 'data'.

add

add(name, type_, orientation=FWD, title=None, descr=None, comment=None, ifdef=None)

Add member name with type_ and orientation.

Parameters:

Name Type Description Default
name str

Name

required
type_ BaseType

Type

required
orientation Orientation

Orientation

FWD

Other Parameters:

Name Type Description
title str | None

Full Spoken Name.

descr str | None

Documentation Description.

comment str | None

Source Code Comment.

ifdef str | None

IFDEF encapsulation.

model_post_init

model_post_init(__context)

Run Build.

DynamicStructType

Bases: BaseStructType

A singleton struct which can be filled outside _build and is not shared between instances.

import ucdp as u class BusType(u.DynamicStructType): ... pass bus = BusType() bus.add('data', u.UintType(8)) bus.add('valid', u.BitType()) tuple(bus) ('data', 'valid') bus = BusType() bus.add('accept', u.BitType(), orientation=u.BWD) tuple(bus) ('accept',)

This is forbidden on normal struct:

class BusType(u.AStructType): ... def _build(self) -> None: ... pass bus = BusType() bus._add('data', u.UintType(8)) Traceback (most recent call last): ... ucdp.exceptions.LockError: BusType(): Cannot add item 'data'.

add

add(name, type_, orientation=FWD, title=None, descr=None, comment=None, ifdef=None)

Add member name with type_ and orientation.

Parameters:

Name Type Description Default
name str

Name

required
type_ BaseType

Type

required
orientation Orientation

Orientation

FWD

Other Parameters:

Name Type Description
title str | None

Full Spoken Name.

descr str | None

Documentation Description.

comment str | None

Source Code Comment.

ifdef str | None

IFDEF encapsulation.

model_post_init

model_post_init(__context)

Run Build.

fwdfilter

fwdfilter(structitem)

Filter For Forward Elements In Structs.

bwdfilter

bwdfilter(structitem)

Filter For Backward Elements In Structs.