📄 writ_ifs.c
字号:
/*============================================================================FILE writ_ifs.cMEMBER OF process cmppCopyright 1991Georgia Tech Research CorporationAtlanta, Georgia 30332All Rights ReservedPROJECT A-8503AUTHORS 9/12/91 Bill KuhnMODIFICATIONS <date> <person name> <nature of modifications>SUMMARY This file contains functions used to write out the file "ifspec.c" based on information read from "ifspec.ifs", which is now held in structure 'ifs_table' passed to write_ifs_c_file().INTERFACES write_ifs_c_file()REFERENCED FILES None.NON-STANDARD FEATURES None.============================================================================*/#include <assert.h>#include <stdlib.h>#include <string.h>#include "cmpp.h"/* Local function prototypes */static void write_comment(FILE *fp, Ifs_Table_t *ifs_table);static void write_includes(FILE *fp);static void write_mPTable(FILE *fp, Ifs_Table_t *ifs_table);static void write_pTable(FILE *fp, Ifs_Table_t *ifs_table);static void write_conn_info(FILE *fp, Ifs_Table_t *ifs_table);static void write_param_info(FILE *fp, Ifs_Table_t *ifs_table);static void write_inst_var_info(FILE *fp, Ifs_Table_t *ifs_table);static void write_SPICEdev(FILE *fp, Ifs_Table_t *ifs_table);static char *data_type_to_str(Data_Type_t type);static char *port_type_to_str(Port_Type_t port);static char *dir_to_str(Dir_t dir);static char *value_to_str(Data_Type_t type, Value_t value);static char *no_value_to_str(void);static char *boolean_to_str(Boolean_t value);static char *integer_to_str(int value);static char *gen_port_type_str(Port_Type_t port);/* *********************************************************************** *//*write_ifs_c_fileFunction write_ifs_c_file is a top-level driver function forcreating a C file (ifspec.c) that defines the model InterfaceSpecification in a form usable by the simulator. The ifspec.coutput file is opened for writing, and then each of the followingfunctions is called in order to write the necessary statementsand data structures into the file: write_comment write_includes write_mPTable write_conn_info write_param_info write_inst_var_info write_SPICEdevThe output file is then closed.*/Status_t write_ifs_c_file( char *filename, /* File to write to */ Ifs_Table_t *ifs_table) /* Table of Interface Specification data */{ FILE *fp; /* File pointer */ char msg[MAX_PATH_LEN+257]; /* space for an error message */ int int_status; /* returned status from fclose */ /* Open the ifspec.c file for write access */ fp = fopen(filename, "w"); if(fp == NULL) { sprintf(msg, "ERROR - Can't create file: %s", filename); print_error(msg); return(ERROR); } /* Write out a comment section at the top of the file */ write_comment(fp, ifs_table); /* Put in the # includes */ write_includes(fp); /* Write the SPICE3 required XXXmPTable structure */ write_mPTable(fp, ifs_table); /* Write the SPICE3 required XXXpTable structure */ write_pTable(fp, ifs_table); /* Write out the connector table required for the code model element parser */ write_conn_info(fp, ifs_table); /* Write out the parameter table required for the code model element parser */ write_param_info(fp, ifs_table); /* Write out the instance variable table required for the code model element parser */ write_inst_var_info(fp, ifs_table); /* Write out the externally visible structure for this model */ write_SPICEdev(fp, ifs_table); /* Close the ifspec.c file and return */ int_status = fclose(fp); if(int_status == 0) return(OK); else return(ERROR);}/* *********************************************************************** *//*write_commentFunction write_comment places a comment at the top of theifspec.c file warning the user that this file is automaticallygenerated and should not be edited.*/static void write_comment( FILE *fp, /* File to write to */ Ifs_Table_t *ifs_table) /* Table of Interface Specification data */{ fprintf(fp, "\n"); fprintf(fp, "/*\n"); fprintf(fp, " * Structures for model: %s\n", ifs_table->name.model_name); fprintf(fp, " *\n"); fprintf(fp, " * Automatically generated by cmpp preprocessor\n"); fprintf(fp, " *\n"); fprintf(fp, " * !!! DO NOT EDIT !!!\n"); fprintf(fp, " *\n"); fprintf(fp, " */\n"); fprintf(fp, "\n");}/* *********************************************************************** *//*write_includesFunction write_includes writes the C header files required inifspec.c.*/static void write_includes( FILE *fp) /* File to write to */{ fprintf(fp, "\n"); fprintf(fp, "#include \"ngspice.h\" \n");/* fprintf(fp, "#include \"prefix.h\" \n");*/ fprintf(fp, "#include <stdio.h> \n"); fprintf(fp, "#include \"devdefs.h\" \n"); fprintf(fp, "#include \"ifsim.h\" \n"); fprintf(fp, "#include \"mifdefs.h\" \n"); fprintf(fp, "#include \"mifproto.h\" \n"); fprintf(fp, "#include \"mifparse.h\" \n");/* fprintf(fp, "#include \"suffix.h\" \n");*/ fprintf(fp, "\n");}/* *********************************************************************** *//*write_pTableFunction write_pTable writes the instance parameter informationusing SPICE's IFparm structure type. This table defines theparameters as output only variables using SPICE's ``OP'' macro. These instance parameters are derived from the InterfaceSpecification file's STATIC_VAR table and define the parametersthat can be queried using the SPICE 3C1 .save feature.*/static void write_pTable( FILE *fp, /* File to write to */ Ifs_Table_t *ifs_table) /* Table of Interface Specification data */{ int i; char str[80]; Boolean_t is_array; Data_Type_t type; /* Only write the pTable if there is something to put in it. */ /* Otherwise, we will put NULL in the SPICEdev structure in its slot */ if(ifs_table->num_inst_var == 0) return; /* Write the structure beginning */ fprintf(fp, "\n"); fprintf(fp, "static IFparm MIFpTable[] = {\n"); /* Write out an entry for each instance variable in the table */ /* Use the index of the element in the instance variable info array */ /* ADDED TO the number of parameters as the SPICE3 integer tag. */ for(i = 0; i < ifs_table->num_inst_var; i++) { /* Use the SPICE3 OP macro since instance vars are output-only */ fprintf(fp, " OP("); /* Put in the name of the parameter and the integer tag */ fprintf(fp, "\"%s\", ", ifs_table->inst_var[i].name); fprintf(fp, "%d, ", i + ifs_table->num_param); /* Format SPICE3 type according to parameter type field */ type = ifs_table->inst_var[i].type; is_array = ifs_table->inst_var[i].is_array; strcpy(str,""); if(is_array == TRUE) { strcat(str,"("); } if(type == BOOLEAN) { strcat(str,"IF_FLAG"); /* There is no BOOLEAN in SPICE3 */ } else if(type == INTEGER) { strcat(str,"IF_INTEGER"); } else if(type == REAL) { strcat(str,"IF_REAL"); } else if(type == COMPLEX) { strcat(str,"IF_COMPLEX"); } else if(type == STRING) { strcat(str,"IF_STRING"); } else if(type == POINTER) { strcat(str,"IF_STRING"); } else { print_error("INTERNAL ERROR - write_pTable() - Impossible data type."); } if(is_array == TRUE) { strcat(str,"|IF_VECTOR)"); } fprintf(fp, "%s, ", str); /* Put in the description string and finish this line off */ fprintf(fp, "\"%s\"", ifs_table->inst_var[i].description); fprintf(fp, "),\n"); } /* Finish off the structure */ fprintf(fp, "};\n"); fprintf(fp, "\n");}/* *********************************************************************** *//*write_mPTableFunction write_mPTable writes the model parameter informationusing SPICE's IFparm structure type. This table defines theparameters to be input/output variables using SPICE's ``IOP'' macroso that these variables can be set or queried from SPICE. Thesemodel parameters are derived from the Interface Specification'sPARAMETER table.*/static void write_mPTable( FILE *fp, /* File to write to */ Ifs_Table_t *ifs_table) /* Table of Interface Specification data */{ int i; char str[80]; Boolean_t is_array; Data_Type_t type; /* Only write the mPTable if there is something to put in it. */ /* Otherwise, we will put NULL in the SPICEdev structure in its slot */ if(ifs_table->num_param == 0) return; /* Write the structure beginning */ fprintf(fp, "\n"); fprintf(fp, "static IFparm MIFmPTable[] = {\n"); /* Write out an entry for each parameter in the table */ /* Use the index of the element in the parameter info array */ /* as the SPICE3 integer tag. */ for(i = 0; i < ifs_table->num_param; i++) { /* Use the SPICE3 IOP macro since model parameters are input/output */ fprintf(fp, " IOP("); /* Put in the name of the parameter and the integer tag */ fprintf(fp, "\"%s\", ", ifs_table->param[i].name); fprintf(fp, "%d, ", i); /* Format SPICE3 type according to parameter type field */ type = ifs_table->param[i].type; is_array = ifs_table->param[i].is_array; strcpy(str,""); if(is_array == TRUE) { strcat(str,"("); } if(type == BOOLEAN) { strcat(str,"IF_FLAG"); /* There is no BOOLEAN in SPICE3 */ } else if(type == INTEGER) { strcat(str,"IF_INTEGER"); } else if(type == REAL) { strcat(str,"IF_REAL"); } else if(type == COMPLEX) { strcat(str,"IF_COMPLEX"); } else if(type == STRING) { strcat(str,"IF_STRING"); } else { print_error("INTERNAL ERROR - write_mPTable() - Impossible data type."); } if(is_array == TRUE) { strcat(str,"|IF_VECTOR)"); } fprintf(fp, "%s, ", str); /* Put in the description string and finish this line off */ fprintf(fp, "\"%s\"", ifs_table->param[i].description); fprintf(fp, "),\n"); } /* Finish off the structure */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -