cli blueprints
API Reference Manual  /  Python API  / 

simics

Name

simics — A Python framework for creating Simics classes.

Synopsis

Python

import simics

class simics.confclass

Synopsis

class simics.confclass(
    classname: 'str' = '',
    parent: "Optional['confclass']" = None,
    *,
    pseudo: 'bool' = False,
    doc: 'Optional[str]' = None,
    short_doc: 'Optional[str]' = None,
    register: 'Optional[bool]' = None,
    **kwd: 'Any'
)

Description

The class confclass is used to define and register a Simics class. The intended use is to create a confclass object as a class member in the custom Python class implementation used to implement the Simics class. The confclass instance also has specific namespace members that allows adding attributes and other other features (see below).

The class confclass is available either from confclass.confclass or from simics.confclass.

Arguments

classname
Set classname to the chosen Simics class name.
parent
To inherit from another Simics class created with confclass, set parent to the parent’s confclass instance.
pseudo
Set pseudo to True to make a Sim_Class_Kind_Pseudo class.
short_doc / doc
To document the class, set short_doc to a one-liner describing the class and set doc to a longer description text.
register
By default, the Simics class is registered when the Python class is created and bound. To prevent this automatic registration, set register to false. The Simics class can be registered by calling register on the confclass instance.

Custom conf_class_t callbacks

To override the conf_class_t callbacks, use these decorators:

Namespaces for Adding Features

attr
Add attribute name and call it to define an attribute.
command
Use <confclass>.command.info or <confclass>.command.status as decorator for the methods used to implement the info and status commands.
iface
Use <confclass>.<interface name><function name> as decorator on the method that implements the <function name> in the <interface name> interface.
o
Add a port object by appending the port object name and then call it.

Example

Here is a simple example of how to add a Simics class named class1 with attribute attr1 using the .attr namespace:

class Class1:
    cls = simics.confclass(classname="class1")
    cls.attr.attr1("i", default=1)

See Also

For more extensive tutorials on how to write custom Simics class with confclass, see section Modeling with Python (confclass) in Model Builder User's Guide.

simics.confclass.attr

Synopsis

simics.confclass.attr

Description

Namespace for adding attributes. Append a valid attribute name, and call (arguments below) it to create an attribute.

After the call, the namespace entry contains an object that has getter and setter properties that can be used to decorate custom attribute accessor functions.

If no custom getter or setter is provided, default accessors are automatically created. These default accessors read and write to the Python instance attribute with the same name as the Simics attribute (e.g., self.my_attr).

Arguments

attr_type
The Simics type string for the attribute (e.g., "i", "[i*]").
kind
The attribute kind (attr_attr_t). Default is Sim_Attr_Required.
optional
If True, makes the attribute optional.
pseudo
If True, makes the attribute a pseudo-attribute.
doc
The documentation string for the attribute.
default
The default value for the attribute.
read_only
If True, the attribute cannot be written to.
write_only
If True, the attribute cannot be read from.

The kind argument defaults to Sim_Attr_Required. It is modified by other arguments:

If read_only or write_only is True, pseudo must also be True, as attributes saved in checkpoints must be both readable and writable.

simics.confclass.command

Synopsis

simics.confclass.command

Description

Contains info and status properties that should be used as decorators on functions that works as info or status commands.

simics.confclass.deinit

Synopsis

simics.confclass.deinit

Description

Decorator for ‘deinit’ class method.

simics.confclass.event

Synopsis

simics.confclass.event

Description

Namespace for adding events. Append an event name and call it to declare an event. Use decorators on the resulting object to set callback, destroy, describe, get_value, and set_value.

simics.confclass.finalize

Synopsis

simics.confclass.finalize

Description

Decorator for ‘finalize’ class method.

simics.confclass.iface

Synopsis

simics.confclass.iface

Description

Namespace for adding interface implementations. Use the <confclass><interface name>.<function name> as decorator to decorate interface functions. The interface must be accessible from Python.

Example

In the below example, the signal interface is implemented by using cls.iface.signal.signal_raise and cls.iface.signal.signal_lower to decorate the custom interface functions signal_raise and signal_lower.

class MyDevice:
    cls = simics.confclass(classname="my_device")

    @cls.iface.signal.signal_raise
    def signal_raise(self):
        pass

    @cls.iface.signal.signal_lower
    def signal_lower(self):
        pass

simics.confclass.init

Synopsis

simics.confclass.init

Description

Decorator for ‘init’ class method.

simics.confclass.o

Synopsis

simics.confclass.o

Description

Namespace for adding port objects. Append a valid object name, possibly a hierarchy, and call add a port object.

Arguments

classname

If unset, a class name will be chosen based on the last item in the namespaced name. If classname is set to a string starting with a dot, the classname will be prefixed with the parent’s class name. In these two cases (unset or starting with a dot), the Python class will be the parent’s Python class, and a new confclass object will be returned.

It is also possible to specify an existing class name. In this case, the call will return None, and the port object’s Python class will be an instance of the existing class, if such exists.

desc

Optional string that describes the port object in the documentation of the parent object.

simics.confclass.objects_finalized

Synopsis

simics.confclass.objects_finalized

Description

Decorator for ‘objects_finalized’ class method.

class simics.CriticalErrors

Synopsis

class simics.CriticalErrors(errors, function=None)

Description

Represents critical errors caused by C code called from Python.

This exception is raised when returning to Python from a C function that directly or indirectly caused one or more serious, but recoverable, errors. Elaborate error descriptions are printed when the errors occur, but because of error recovery, the C function will be able to continue without being aware of the error.

A C function can cause more than one error; all these are combined into a single Python exception. The main purpose of the exception is to aid debugging, usually by providing a nice Python traceback.

class simics.pre_conf_object

Synopsis

class simics.pre_conf_object(
    object_or_class_name=None,
    class_name=None,
    build_id=None,
    /,
    **attrs
)

Description

A class for Simics configuration object to instantiate.

A class representing a future Simics configuration object named object_name, of class class_name. If object_name is None, a unique name will be generated.

The build_id of the object can be specified when using the pre_conf_object class during checkpoints update. Refer to Model Builder User's Guide for more information.

Future configuration attributes are set using normal Python class members:

a = pre_conf_object("test_object", "test-class")
a.value = 42

After using a pre_conf_object object to create a configuration object, the created object can be obtained by passing the pre_conf_object’s name member to SIM_get_object().

simics.pre_conf_object.classname

Synopsis

simics.pre_conf_object.classname

Description

classname

simics.pre_conf_object.name

Synopsis

simics.pre_conf_object.name

Description

object name

cli blueprints