⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mif_inp2.c

📁 ngspice又一个电子CAD仿真软件代码.功能更全
💻 C
📖 第 1 页 / 共 3 页
字号:
                return;            }            /* set the null flag to true */            fast[0]->conn[i]->is_null = MIF_TRUE;            fast[0]->conn[i]->size = 0;            /* eat the null token and continue to next connection */            next_token = MIFget_token(&line,&next_token_type);            continue;  /* iterate */        }        else {            /* set the null flag to false */            fast[0]->conn[i]->is_null = MIF_FALSE;        }        /* =====  process connection as appropriate for scalar or array  ====== */        if(! conn_info->is_array) {     /* a scalar connection - the simpler case */	    /*  If we get to there, next_token should hold a netname in the port netlist.  */            /*  First, do a couple of error checks */            if(next_token_type == MIF_LARRAY_TOK) {                LITERR("ERROR - Scalar connection expected, [ found");                printf("ERROR - Scalar connection expected, [ found.  Returning . . .");                return;            }            if(next_token_type == MIF_RARRAY_TOK) {                LITERR("ERROR - Unexpected ]");                printf("ERROR - Unexpected ].  Returning . . .");                return;            }            /* If all OK, get the port data into the instance struct */            /* allocating the port member of the instance struct as needed */	    /*  Note that MIFget_port eats next_token, and advances the &line pointer..  */            MIFget_port(ckt,                        tab,                        current,                        fast[0],                        &line,                        &next_token,                        &next_token_type,                        def_port_type,                        def_port_type_str,                        conn_info,                        i,                  /* connection index */                        0,                  /* port index for scalar connection */                        &status);            if(status == MIF_ERROR)                return;            fast[0]->conn[i]->size = 1;	    /* when we leave here, next_token should hold the next, unprocessed netname */        }        else {  /* ====== the connection is an array - much to be done ... ====== */	    /* At this point, the next_token should be a [ */            /* check for required leading array delim character [ and eat it if found */            if(next_token_type != MIF_LARRAY_TOK) {                LITERR("Missing [, an array connection was expected");                printf("Missing [, an array connection was expected.  Returning . . .");                return;            }            else  /* eat the [  */                next_token = MIFget_token(&line,&next_token_type);            /*------ get and process ports until ] is encountered ------*/            for(j = 0;                (next_token_type != MIF_RARRAY_TOK) &&                (*line != '\0');                j++) {                    /* First, do some error checks */                /* check for required leading array delim character */                if(next_token_type == MIF_LARRAY_TOK) {                    LITERR("ERROR - Unexpected [ - Arrays of arrays not allowed");                    printf("ERROR - Unexpected [ - Arrays of arrays not allowed.  Returning . . .");                    return;                }                /* If all OK, get the port nodes into the instance struct */                /* allocating the port member of the instance struct as needed */		/* Note that MIFget_port eats next_token and advances &line by one.  */                MIFget_port(ckt,                            tab,                            current,                            fast[0],                            &line,                            &next_token,                            &next_token_type,                            def_port_type,                            def_port_type_str,                            conn_info,                            i,                  /* connection index */                            j,                  /* port index */                            &status);                if(status == MIF_ERROR)                    return;            } /*------ end of for loop until ] is encountered ------*/	    /*  At this point, next_token should hold the next token after the 		port netnames.  This token should be a ].  */            /* make sure we exited because the end of the array connection               was reached.                                               	     */            if(*line == '\0') {                LITERR("Missing ] in array connection");                return;            }            /* record the number of ports found for this connection */            if(j < 1) {                LITERR("Array connection must have at least one port");                return;            }            fast[0]->conn[i]->size = j;	    /*  At this point, the next time we get_token, we should get a % or a net name.		We'll do that now, since when we enter the loop, we expect next_token		to hold the next unprocessed token.	    */	    next_token = MIFget_token(&line,&next_token_type);        }  /* ======  array connection processing   ====== */        /* be careful about putting stuff here, there is a 'continue' used */        /* in the processing of NULL connections above                     */	/*  At this point, next_token should hold the next unprocessed token.  */    } /******* for number of connections *******/    /* *********************** */    /*      Error Checks       */    /* *********************** */    /* check for too many connections */    /* At this point, we should have eaten all the net connections, and left       next_token holding the model name.  &line should be empty.    */    if(strcmp(next_token, model) != 0) {        LITERR("Too many connections -- expecting model name but encountered other tokens.");        return;    }    /* check connection constraints */    for(i = 0; i < DEVices[type]->DEVpublic.num_conn; i++) {        conn_info = &(DEVices[type]->DEVpublic.conn[i]);        if( (fast[0]->conn[i]->is_null) &&            (! conn_info->null_allowed) ) {            LITERR("Null found for connection where not allowed");            return;        }        if(conn_info->has_lower_bound) {            if(fast[0]->conn[i]->size < conn_info->lower_bound) {                LITERR("Too few ports in connection");                return;            }        }        if(conn_info->has_upper_bound) {            if(fast[0]->conn[i]->size > conn_info->upper_bound) {                LITERR("Too many ports in connection");                return;            }        }    }    /* check model parameter constraints */    /* some of these should probably be done in MIFgetMod() */    /* to prevent multiple error messages                   */    for(i = 0; i < DEVices[type]->DEVpublic.num_param; i++) {        param_info = &(DEVices[type]->DEVpublic.param[i]);        if(mdfast->param[i]->is_null) {            if(! param_info->has_default) {                LITERR("Parameter on model has no default");                return;            }            else if((param_info->is_array) && (! param_info->has_conn_ref)) {                LITERR("Defaulted array parameter must have associated array connection");                return;            }        }        if((! mdfast->param[i]->is_null) && (param_info->is_array)) {            if(param_info->has_conn_ref) {                if(fast[0]->conn[param_info->conn_ref]->size != fast[0]->param[i]->size) {                    LITERR("Array parameter size on model does not match connection size");                    return;                }            }        }    }}/* ********************************************************************* *//*MIFinit_instThis function initializes the code model specific elements of the inst struct.*/static void  MIFinit_inst(    MIFmodel *mdfast,       /* The model the instance is derived from */    MIFinstance *fast)      /* The instance to initialize */{    int  mod_type;  /* type of this model */    Mif_Conn_Info_t  *conn_info;    int     i;    /* get an index into the DEVices information structure */    mod_type = mdfast->MIFmodType;    /* allocate code model connector data in instance struct */    fast->num_conn = DEVices[mod_type]->DEVpublic.num_conn;    fast->conn = (void *) tmalloc(fast->num_conn * sizeof(void *));    for(i = 0; i < fast->num_conn; i++)        fast->conn[i] = (void *) tmalloc(sizeof(Mif_Conn_Data_t));    /* initialize code model connector data */    for(i = 0; i < fast->num_conn; i++) {        conn_info = &(DEVices[mod_type]->DEVpublic.conn[i]);        fast->conn[i]->name = conn_info->name;        fast->conn[i]->description = conn_info->description;        fast->conn[i]->is_null = MIF_TRUE;        fast->conn[i]->size = 0;        fast->conn[i]->port = NULL;        switch(conn_info->direction) {        case MIF_INOUT:            fast->conn[i]->is_input =  MIF_TRUE;            fast->conn[i]->is_output = MIF_TRUE;            break;        case MIF_IN:            fast->conn[i]->is_input =  MIF_TRUE;            fast->conn[i]->is_output = MIF_FALSE;            break;        case MIF_OUT:            fast->conn[i]->is_input =  MIF_FALSE;            fast->conn[i]->is_output = MIF_TRUE;            break;        default:            printf("\nERROR - Impossible direction type in MIFinit_inst\n");            exit(1);        }    }    /* allocate and copy instance variable data to the instance */    fast->num_inst_var = DEVices[mod_type]->DEVpublic.num_inst_var;    fast->inst_var = (void *) tmalloc(fast->num_inst_var * sizeof(void *));    for(i = 0; i < fast->num_inst_var; i++) {        fast->inst_var[i] = (void *) tmalloc(sizeof(Mif_Inst_Var_Data_t));        if(DEVices[mod_type]->DEVpublic.inst_var[i].is_array) {            fast->inst_var[i]->size = 0;            fast->inst_var[i]->element = NULL;            /* The code model allocates space for the data and sets the size */        }        else {            fast->inst_var[i]->size = 1;            fast->inst_var[i]->element = (void *) tmalloc(sizeof(Mif_Value_t));        }    }    /* copy model parameter data to the instance */    fast->num_param = mdfast->num_param;    fast->param = mdfast->param;    /* initialize any additional instance data */    fast->initialized = MIF_FALSE;    fast->analog = MIF_FALSE;    fast->event_driven = MIF_FALSE;    fast->inst_index = 0;}/* ********************************************************************* *//*MIFget_port_typeThis function gets the port type identifier and checks it for validity.  It alsoreplaces false default information in conn_info with the real info based uponthe discovered port type string.When we call it, we expect that the next token type (sent from above) 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -