Previous: , Up: Defining Instruction Class Sets   [Contents][Index]


4.2.3.6 Function Layout

A template for the event handler of an instruction class set:

static QSMM_INSTR_CLASS_SET(instr_class_set_name) {
    // TODO: declare (and possibly initialize) automatic variables used in
    //       a more than one "case" branch below.
    struct stack_frame_s *stack_frame_p=0;
        // structure "stack_frame_s" represents a user stack frame
    struct node_param_s *node_param_p;
        // structure "node_param_s" holds user parameters
        // associated with a node
    struct model_param_s *const model_param_p=qsmm_get_ptr(qsmm,0);
        // obtain model parameters specific to this model; a call
        // qsmm_set_ptr(qsmm,0,ptr_p) should have set a pointer ptr_p
        // addressing those parameters
    switch (qsmm_evt) {
        case QSMM_EVT_ENT_INIT:

            // Register instruction classes.
            QSMM_REG_INSTR_CLASS(meta_class_1);
            QSMM_REG_INSTR_CLASS(meta_class_2);
            // ...
            QSMM_REG_INSTR_CLASS_PARAM(meta_class_a,var_a);
            QSMM_REG_INSTR_CLASS_PARAM(meta_class_b,var_b);
            // ...

            qsmm_set_nstate_max(qsmm,__FUNCTION__,nstate);
                // set the maximum allowed and default number of
                // states for nodes belonging to this node class

            // Create the nodes.
            QSMM_NODE_CREATE(node1);
            QSMM_NODE_CREATE(node2);
            // ...
            QSMM_NODE_CREATE(nodeN);

            // Associate user parameters with created nodes. The pointers
            // ptr1, ptr2, ..., ptrN reference allocated and initialized
            // instances of "node_param_s" structure.
            qsmm_set_node_ptr(qsmm,node1,0,ptr1);
            qsmm_set_node_ptr(qsmm,node2,0,ptr2);
            // ...
            qsmm_set_node_ptr(qsmm,nodeN,0,ptrN);

            // TODO: initialize variables and allocate resources used by
            //       the instruction class set for all model runs.
            // TODO: perform other initialization procedures.
            break;
        case QSMM_EVT_ENT_DONE:
            // TODO: deallocate resources allocated on QSMM_EVT_ENT_INIT.
            break;
        case QSMM_EVT_ENGINE_INIT:

            // Load assembler programs into nodes.
            qsmm_node_asm(qsmm,node1,0,prg1,msglist);
            qsmm_node_asm(qsmm,node2,0,prg2,msglist);
            // ...
            qsmm_node_asm(qsmm,nodeN,0,prgN,msglist);

            // TODO: set the parameters of actors representing the
            //       environment state identification engine and
            //       instruction emitting engine.
            // TODO: initialize variables and allocate resources used by
            //       the instruction class set for a current model run.
            break;
        case QSMM_EVT_ENGINE_DONE:
            // TODO: accumulate statistics collected during a current model
            //       run and deallocate resources allocated on
            //       processing QSMM_EVT_ENGINE_INIT.
            break;
        case QSMM_EVT_NODE_ENTER:
            node_param_p=qsmm_get_node_ptr(qsmm,qsmm_node,0);
                // obtain the parameters of an executed node
            qsmm_get_stack_frame(qsmm,0,(void **) &stack_frame_p);
                // obtain a current frame of node call stack
            // TODO: initialize *stack_frame_p, possibly according to
            //       *node_param_p, *model_param_p, and the content of a
            //       structure addressed by qsmm_param_p.
            break;
        case QSMM_EVT_NODE_LEAVE:
            node_param_p=qsmm_get_node_ptr(qsmm,qsmm_node,0);
                // obtain the parameters of an executed node
            qsmm_get_stack_frame(qsmm,0,(void **) &stack_frame_p);
                // obtain a current frame of node call stack
            // TODO: set the content of a structure addressed by
            //       qsmm_param_p according to *stack_frame_p and,
            //       possibly, *node_param_p* and *model_param_p* and
            //       uninitialize *stack_frame_p.
            break;
    }
    return 0;
}

Previous: , Up: Defining Instruction Class Sets   [Contents][Index]