Previous: Setting the Number of Instruction Outcomes, Up: Defining Instruction Meta-classes [Contents][Index]
A template for the event handler of an instruction meta-class:
QSMM_INSTR_META_CLASS(instr_meta_class_name) { // TODO: declare (and possibly initialize) automatic variables used in // a more than one "case" branch below. struct ic_param_s ic_param; // structure "ic_param_s" is for holding the binary parameters of // an instruction class if (QSMM_HAS_INSTR_CLASS(qsmm_evt)) qsmm_get_eh_instr_param(qsmm,sizeof(ic_param),&ic_param); // fetch the binary parameters of an instruction class 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: // TODO: initialize variables and allocate resources used by // the instruction meta-class for all model runs. break;
case QSMM_EVT_ENT_DONE: // TODO: deallocate resources allocated on QSMM_EVT_ENT_INIT. break; case QSMM_EVT_INSTR_CLASS_INIT: qsmm_set_eh_instr_param_str_f(qsmm, fmt, ic_param.field, ...); // set the text parameters of an instruction class; // you may access the fields of *model_param_p for // model-specific information qsmm_set_eh_noutcome(qsmm,noutcome); // set the number of outcomes of this instruction class if // that number is not equal to 1 break;
case QSMM_EVT_INSTR_CLASS_DONE: // TODO: deallocate fields of "ic_param_s" (held in "ic_param") // allocated before a call to "qsmm_reg_instr_class_v2"; // deallocate resources allocated on // processing QSMM_EVT_INSTR_CLASS_INIT. break;
case QSMM_EVT_ENGINE_INIT: // TODO: initialize variables and allocate resources used by // the instruction meta-class for a current model run. break; case QSMM_EVT_ENGINE_DONE: // TODO: deallocate resources allocated on // processing QSMM_EVT_ENGINE_INIT. break; case QSMM_EVT_ACTIVATE: { struct stack_frame_s *stack_frame_p=0; // structure "stack_frame_s" is for holding a user frame of // node call stack qsmm_get_stack_frame(qsmm,0,(void **) &stack_frame_p); // obtain a current frame of node call stack // TODO: perform custom actions that affect a system or // environment and/or use parameters in *model_param_p, // *stack_frame_p, or "ic_param". qsmm_time_delta(qsmm,time_delta); // increment continuous time qsmm_spur_delta(qsmm,spur_type,spur_delta); // increment spur // qsmm_node_call_default(qsmm,node,param_p); // call another node with optional parameters qsmm_set_instr_outcome(qsmm,outcome); // set an instruction outcome if the instruction class has // multiple outcomes // OR: // qsmm_return_to_caller_node(qsmm); // return control to a node that called a current node // OR: // QSMM_TERMINATE(); // terminate model execution break; } } return 0; }