VI Simics API 33 Object Hierarchy
Model Builder User's Guide  /  VI Simics API  / 

32 Attributes

A Simics class can register attributes that will act as data members for all objects instantiated from this class. For Simics, an attribute is an abstraction, defined by its type and a pair of get()/set() functions. When an attribute is read (i.e., when the SIM_get_attribute() function is used on the object), the corresponding get() function is called. Likewise, when an attribute is written to, the set() function is executed. These functions can perform any kind of operation provided they return a value (for get()) or accept a value to be written (for set()).

Attributes have different types and properties. Let us here have a closer look at their definition.

32.1 Definition

In C and DML attribute values are represented by attr_value_t values. In Python, attributes are automatically converted to or from the corresponding Python type, so manipulating attributes is completely transparent:

Attribute TypePython Equivalent
InvalidRaise a SimExc_Attribute exception.
Stringstr (a Python string)
Integerint
Floatingfloat
Listlist
Datatuple of integers 0-255
NilNone
ObjectSimics conf_object_t reference.
Dictdict
Booleanbool

The attr_value_t values are manipulated with a set of accessor functions from C and DML, rather than by accessing its fields directly. For example:

// create an integer attribute
attr_value_t a = SIM_make_attr_uint64(4711);

// create a list attribute
attr_value_t l = SIM_alloc_attr_list(2);

// writing to the first element of l
SIM_attr_list_set_item(l, 0, SIM_make_attr_uint64(1));

// reading the second element of the list
int64 other = SIM_attr_integer(SIM_attr_list_item(l, 1));

A complete documentation of attributes related functions is provided in the API Reference Manual.

VI Simics API 33 Object Hierarchy