xspice, implement "CALLBACK"
Allow to register a callback function in the cfunc.mod files, which will be invoked in MIFdestroy. Usefull to "free" memory which has been allocated locally in a cfunc.mod file.
This commit is contained in:
parent
5f0f54761a
commit
58874cc65e
|
|
@ -366,6 +366,7 @@ struct Mif_Private {
|
|||
Mif_Param_Data_t **param; /* Information about each parameter */
|
||||
int num_inst_var; /* Number of instance variables */
|
||||
Mif_Inst_Var_Data_t **inst_var; /* Information about each inst variable */
|
||||
Mif_Callback_t *callback; /* Callback function */
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@ struct MIFinstance {
|
|||
Mif_Boolean_t event_driven; /* true if this inst is event-driven or hybrid type */
|
||||
|
||||
int inst_index; /* Index into inst_table in evt struct in ckt */
|
||||
Mif_Callback_t callback; /* instance callback function */
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -172,6 +172,15 @@ typedef enum {
|
|||
} Mif_Cntl_Src_Type_t;
|
||||
|
||||
|
||||
/*
|
||||
* The "reason" for a callback invocation
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
MIF_CB_DESTROY = 1, /* MIFdestroy has been invoked, its time to clean up */
|
||||
} Mif_Callback_Reason_t;
|
||||
|
||||
|
||||
/* ***************************************************************************** */
|
||||
|
||||
|
||||
|
|
@ -218,5 +227,7 @@ typedef struct Mif_Private Mif_Private_t;
|
|||
typedef struct MIFinstance MIFinstance;
|
||||
typedef struct MIFmodel MIFmodel;
|
||||
|
||||
typedef void (* Mif_Callback_t)(Mif_Private_t *, Mif_Callback_Reason_t);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -91,6 +91,7 @@ Z [0-9A-Za-z_]
|
|||
|
||||
ARGS {return TOK_ARGS;}
|
||||
INIT {return TOK_INIT;}
|
||||
CALLBACK {return TOK_CALLBACK;}
|
||||
ANALYSIS {return TOK_ANALYSIS;}
|
||||
NEW_TIMEPOINT {return TOK_NEW_TIMEPOINT;}
|
||||
CALL_TYPE {return TOK_CALL_TYPE;}
|
||||
|
|
|
|||
|
|
@ -336,6 +336,7 @@ static void append (char *str)
|
|||
|
||||
%token TOK_ARGS
|
||||
%token TOK_INIT
|
||||
%token TOK_CALLBACK
|
||||
%token TOK_ANALYSIS
|
||||
%token TOK_NEW_TIMEPOINT
|
||||
%token TOK_TIME
|
||||
|
|
@ -426,6 +427,8 @@ c_char : TOK_IDENTIFIER {fputs (mod_yytext, mod_yyout);}
|
|||
|
||||
macro : TOK_INIT
|
||||
{fprintf (mod_yyout, "mif_private->circuit.init");}
|
||||
| TOK_CALLBACK
|
||||
{fprintf (mod_yyout, "*(mif_private->callback)");}
|
||||
| TOK_ARGS
|
||||
{fprintf (mod_yyout, "Mif_Private_t *mif_private");}
|
||||
| TOK_ANALYSIS
|
||||
|
|
|
|||
|
|
@ -225,6 +225,7 @@ int EVTload(
|
|||
cm_data.param = inst->param;
|
||||
cm_data.num_inst_var = inst->num_inst_var;
|
||||
cm_data.inst_var = inst->inst_var;
|
||||
cm_data.callback = &(inst->callback);
|
||||
|
||||
|
||||
/* ******************* */
|
||||
|
|
|
|||
|
|
@ -652,6 +652,7 @@ static void MIFinit_inst(
|
|||
fast->analog = MIF_FALSE;
|
||||
fast->event_driven = MIF_FALSE;
|
||||
fast->inst_index = 0;
|
||||
fast->callback = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -89,6 +89,21 @@ MIFdelete(
|
|||
model = (MIFmodel *) inModel;
|
||||
fast = (MIFinstance **) inst;
|
||||
|
||||
if ((*fast)->callback) {
|
||||
Mif_Private_t cm_data;
|
||||
|
||||
/* Prepare the structure to be passed to the code model */
|
||||
cm_data.num_conn = (*fast)->num_conn;
|
||||
cm_data.conn = (*fast)->conn;
|
||||
cm_data.num_param = (*fast)->num_param;
|
||||
cm_data.param = (*fast)->param;
|
||||
cm_data.num_inst_var = (*fast)->num_inst_var;
|
||||
cm_data.inst_var = (*fast)->inst_var;
|
||||
cm_data.callback = &((*fast)->callback);
|
||||
|
||||
(*fast)->callback(&cm_data, MIF_CB_DESTROY);
|
||||
}
|
||||
|
||||
/*******************************************/
|
||||
/* Cut the instance out of the linked list */
|
||||
/*******************************************/
|
||||
|
|
|
|||
|
|
@ -437,6 +437,7 @@ MIFload(
|
|||
cm_data.param = here->param;
|
||||
cm_data.num_inst_var = here->num_inst_var;
|
||||
cm_data.inst_var = here->inst_var;
|
||||
cm_data.callback = &(here->callback);
|
||||
|
||||
/* Initialize the auto_partial flag to false */
|
||||
g_mif_info.auto_partial.local = MIF_FALSE;
|
||||
|
|
|
|||
Loading…
Reference in New Issue