4.2.3.6 Function Layout

Below there is a template for the event handler of an instruction class set. Its instruction classes use the node call stack. If instruction classes of an instruction class set do not use the node call stack, you can register the instruction class set without an event handler.

QSMM_INSTR_CLASS_SET(instr_class_set_name) {
    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 the parameters
    switch (mehcall->evt) {
        case QSMM_EVT_NODE_ENTER:
            node_param_p=qsmm_get_node_ptr(qsmm,mehcall->node,0);
                // obtain the parameters of an executed node; a call
                // qsmm_set_node_ptr(qsmm,node,0,ptr_p) should have set
                // a pointer ptr_p addressing the parameters
            qsmm_get_mehcall_stack_frame(
                mehcall, 0, (void **) &stack_frame_p);
                    // obtain a current user 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 mehcall->param_p.
            break;
        case QSMM_EVT_NODE_LEAVE:
            node_param_p=qsmm_get_node_ptr(qsmm,mehcall->node,0);
                // obtain the parameters of an executed node; a call
                // qsmm_set_node_ptr(qsmm,node,0,ptr_p) should have set
                // a pointer ptr_p addressing the parameters
            qsmm_get_mehcall_stack_frame(
                mehcall, 0, (void **) &stack_frame_p);
                    // obtain a current user frame of node call stack
            // TODO: set the content of a structure addressed by
            //       mehcall->param_p according to *stack_frame_p and,
            //       possibly, *node_param_p* and *model_param_p* and
            //       uninitialize *stack_frame_p.
            break;
        case QSMM_EVT_ENT_INIT:
        case QSMM_EVT_ENT_DONE:
        case QSMM_EVT_ENGINE_INIT:
        case QSMM_EVT_ENGINE_DONE:
            // TODO: optionally handle the events.
            break;
    }
    return 0;
}