Previous - Up - Next

6.2   Classes

Each Simics class implemented by a module must be registered with Simics. Remember that classes registered in a module should be listed in the MODULE_CLASSES variable in the module's Makefile. This allows Simics to automatically load the required modules when reading a configuration file.

Registering a class is done by creating and filling a class_data_t structure, and then call the function SIM_register_class with the new class name and the class_data_t structure that describes it. The members in the class_data_t structure are:

A function called when creating an instance of the class. This function will be described in objects below.
This function is called once new_instance has returned, and all attributes in a configuration have been set.
A string that should contain a description of the class.
The class kind tells Simics whether objects of this class should be saved when a checkpoint is created. Valid values are:

class instances will be saved as part of checkpoints (this is the default if kind is not given any value.)
class instances will never be saved.
is not used for the time being, and thus has the same meaning as Sim_Class_Kind_Pseudo.


In C/C++, registration of classes is usually done from within the mandatory init_local() function. The C definition of class_data_t and SIM_register_class() is the following:

typedef struct class_data {
        conf_object_t *(*new_instance)(parse_object_t *parse_obj);
        int            (*delete_instance)(conf_object_t *obj);
        void           (*finalize_instance)(conf_object_t *obj);
        const char      *description;
        class_kind_t     kind;
} class_data_t;

conf_class_t *
SIM_register_class(const char *name, class_data_t *class_data);

SIM_register_class() returns a pointer to a conf_class_t structure which is used internally by Simics to keep track of the class information. This pointer can be used when referring to the class in calls to other functions.

A simple init_local() initialization function could look like this:

        class_data_t cdata;
        conf_class_t *my_class;

        memset(&cdata, 0, sizeof(cdata));
        cdata.new_instance = my_new_instance;
        cdata.description = "This is my class";
        cdata.kind = Sim_Class_Kind_Session;

        my_class = SIM_register_class("my-class", &cdata);

        // Other initializations...


In Python, the registration is done when the global statements of the module are executed (at load time):

def new_instance(parse_obj):

def finalize_instance(obj):

class_data = class_data_t()
class_data.new_instance = new_instance
class_data.finalize_instance = finalize_instance
class_data.description = """
    A sample class used for documentation purposes only.""";
SIM_register_class("sample-doc-class", class_data)

Previous - Up - Next