VIS

src/io/ioWriteSmv.c

Go to the documentation of this file.
00001 
00023 #include "ioInt.h"
00024 
00025 /*---------------------------------------------------------------------------*/
00026 /* Constant declarations                                                     */
00027 /*---------------------------------------------------------------------------*/
00028 
00029 
00030 /*---------------------------------------------------------------------------*/
00031 /* Type declarations                                                         */
00032 /*---------------------------------------------------------------------------*/
00033 
00034 
00035 /*---------------------------------------------------------------------------*/
00036 /* Stucture declarations                                                     */
00037 /*---------------------------------------------------------------------------*/
00038 
00039 
00040 /*---------------------------------------------------------------------------*/
00041 /* Variable declarations                                                     */
00042 /*---------------------------------------------------------------------------*/
00043 
00044 
00045 /*---------------------------------------------------------------------------*/
00046 /* Macro declarations                                                        */
00047 /*---------------------------------------------------------------------------*/
00048 
00049 
00052 /*---------------------------------------------------------------------------*/
00053 /* Static function prototypes                                                */
00054 /*---------------------------------------------------------------------------*/
00055 
00056 
00060 /*---------------------------------------------------------------------------*/
00061 /* Definition of exported functions                                          */
00062 /*---------------------------------------------------------------------------*/
00063 
00064 
00076 void
00077 Io_SmvPrintVar(
00078   FILE *fp,
00079   Var_Variable_t *var)
00080 {
00081   char * varname = Var_VariableReadName(var);
00082   int i;
00083 
00084   for(i=0; varname[i]; i++) {
00085     if(varname[i] == '<' || 
00086        varname[i] == '>' || 
00087        varname[i] == '*' || 
00088        varname[i] == '$') {
00089       fputc('_', fp);
00090     } else {
00091       fputc(varname[i], fp);
00092     }
00093   }
00094 }
00095 
00096 /*---------------------------------------------------------------------------*/
00097 /* Definition of internal functions                                          */
00098 /*---------------------------------------------------------------------------*/
00099 
00100 
00114 void
00115 IoSmvWrite(
00116   FILE *fp,
00117   Hrc_Manager_t *hmgr)
00118 { 
00119   char *rootModelName;
00120   Hrc_Model_t *model, *rootModel;
00121   Hrc_Node_t *currentNode;
00122   array_t *models;
00123   int i;
00124   boolean isRootModel;
00125   char *rootInstanceName, *instanceName;
00126   
00127   currentNode = Hrc_ManagerReadCurrentNode(hmgr);
00128   models = Hrc_ManagerObtainComponentModels(hmgr);
00129 
00130   rootModelName = Hrc_NodeReadModelName(currentNode);
00131   rootModel = Hrc_ManagerFindModelByName(hmgr,rootModelName);
00132   rootInstanceName = Hrc_NodeReadInstanceName(currentNode);
00133   assert(rootModel != NIL(Hrc_Model_t));
00134   
00135   for (i=0; i < array_n(models); i++){
00136     model = array_fetch(Hrc_Model_t *,models,i);
00137     isRootModel = (model == rootModel) ? TRUE : FALSE;
00138     instanceName = (isRootModel == TRUE) ? rootInstanceName : NIL(char);
00139     Hrc_ModelWriteSmv(fp,model,isRootModel,instanceName);
00140   }  
00141 
00142   array_free(models);
00143 }
00144 
00156 void
00157 IoSmvPrint(
00158   FILE *fp,
00159   Var_Variable_t *var)
00160 {
00161   int is_enum, range, i;
00162 
00163   is_enum = Var_VariableTestIsEnumerative(var);
00164   range = Var_VariableReadNumValues(var);
00165     
00166   if (is_enum == 1){
00167     if (range == 2){
00168       (void)fprintf(fp,"VAR %s : boolean;\n",Var_VariableReadName(var));
00169     }
00170     else {
00171       (void)fprintf(fp,"VAR %s : 0..%d;\n",Var_VariableReadName(var),range-1);
00172     }
00173   }
00174   else {
00175   /* variable var is symbolic */
00176     (void)fprintf(fp,"VAR %s : {",Var_VariableReadName(var));
00177     for (i=0; i < range; i++){
00178       if (i == (range-1))
00179         (void)fprintf(fp,"%s ",Var_VariableReadSymbolicValueFromIndex(var,i));
00180       else
00181         (void)fprintf(fp,"%s, ",Var_VariableReadSymbolicValueFromIndex(var,i));
00182     }
00183     (void)fprintf(fp,"};\n");
00184   }
00185 }
00186 
00199 void
00200 IoSmvPrintSpecial(
00201   FILE *fp,
00202   Var_Variable_t *var)
00203 {
00204   int is_enum, range, i;
00205 
00206   is_enum = Var_VariableTestIsEnumerative(var);
00207   range = Var_VariableReadNumValues(var);
00208     
00209   if (is_enum == 1){
00210     if (range == 2){
00211       (void)fprintf(fp,"VAR %s_bufin : boolean;\n",Var_VariableReadName(var));
00212     }
00213     else {
00214       (void)fprintf(fp,"VAR %s_bufin : 0..%d;\n",Var_VariableReadName(var),
00215                     range-1);
00216     }
00217   }
00218   else {
00219   /* variable var is symbolic */
00220     (void)fprintf(fp,"VAR %s_bufin : {",Var_VariableReadName(var));
00221     for (i=0; i < range; i++){
00222       if (i == (range-1)) 
00223         (void)fprintf(fp,"%s_bufin ",
00224                       Var_VariableReadSymbolicValueFromIndex(var,i));
00225       else
00226         (void)fprintf(fp,"%s_bufin, ",
00227                       Var_VariableReadSymbolicValueFromIndex(var,i));
00228     }
00229     (void)fprintf(fp,"};\n");
00230   }
00231 }