int HREgreyboxCount(void*map){ return VTgetCount((value_table_t)map); }
static void lts_write_dir(archive_t archive,string_map_t map,lts_t lts,int segments){ if (map) arch_set_write_policy(archive,map); dir_info_t info=DIRinfoCreate(segments); int i,j; uint32_t k; char filename[1024]; stream_t output; stream_t *src_out; stream_t *lbl_out; stream_t *dst_out; if (lts->root_count !=1) Abort("LTS has %u initial states DIR requires 1",lts->root_count); lts_set_type(lts,LTS_BLOCK); info->label_tau=lts->tau; int type_no=lts_type_get_edge_label_typeno(lts->ltstype,0); switch(lts_type_get_format(lts->ltstype,type_no)){ case LTStypeChunk: case LTStypeEnum: break; default: Abort("DIR is limited to Chunk/Enum edge labels."); } info->label_count=VTgetCount(lts->values[type_no]); info->initial_seg=lts->root_list[0]%segments; info->initial_ofs=lts->root_list[0]/segments; output=arch_write(archive,"TermDB"); int last_idx = 0; table_iterator_t it = VTiterator (lts->values[type_no]); while (IThasNext(it)) { chunk label_c = ITnext (it); int idx = VTputChunk (lts->values[type_no], label_c); while (last_idx < idx) { // fill non-dense indices write_chunk (output, (chunk){0, ""}); last_idx++; } write_chunk (output, label_c); } DSclose(&output); src_out=(stream_t*)RTmalloc(segments*sizeof(stream_t)); lbl_out=(stream_t*)RTmalloc(segments*sizeof(stream_t)); dst_out=(stream_t*)RTmalloc(segments*sizeof(stream_t)); for(i=0;i<segments;i++) { for(j=0;j<segments;j++) { sprintf(filename,"src-%d-%d",i,j); src_out[j]=arch_write(archive,filename); sprintf(filename,"label-%d-%d",i,j); lbl_out[j]=arch_write(archive,filename); sprintf(filename,"dest-%d-%d",i,j); dst_out[j]=arch_write(archive,filename); } for(j=i;j<(int)lts->states;j+=segments){ for(k=lts->begin[j];k<lts->begin[j+1];k++){ int dseg=(lts->dest[k])%segments; info->transition_count[i][dseg]++; DSwriteU32(src_out[dseg],info->state_count[i]); DSwriteU32(lbl_out[dseg],lts->label[k]); DSwriteU32(dst_out[dseg],(lts->dest[k])/segments); } info->state_count[i]++; } for(j=0;j<segments;j++) { DSclose(&src_out[j]); DSclose(&lbl_out[j]); DSclose(&dst_out[j]); } } info->info="bsim2 output"; output=arch_write(archive,"info"); DIRinfoWrite(output,info); DSclose(&output); info->info=NULL; DIRinfoDestroy(info); }
static void write_close(lts_file_t file){ //if (file->init_count!=1) Abort("missing initial state"); in some cases no initial states makes sense! uint32_t pre_sum=0; for(int i=0;i<file->segments;i++) pre_sum+=file->state_perseg[i]; uint32_t tmp; for (int i=0;i<file->segments;i++){ tmp=lts_get_max_src_p1(file,i); if (tmp>file->state_perseg[i]) file->state_perseg[i]=tmp; tmp=lts_get_max_dst_p1(file,i); if (tmp>file->state_perseg[i]) file->state_perseg[i]=tmp; } file->state_count=0; for(int i=0;i<file->segments;i++) file->state_count+=file->state_perseg[i]; if (pre_sum && pre_sum!=file->state_count) { Abort("edges use unwritten states"); } uint32_t offset[file->segments]; offset[0]=0; for(int i=1;i<file->segments;i++) offset[i]=offset[i-1]+file->state_perseg[i-1]; uint32_t seg,ofs; for(uint32_t i=0;i<file->lts->root_count;i++){ seg=file->lts->root_list[i]%file->segments; ofs=file->lts->root_list[i]/file->segments; file->lts->root_list[i]=offset[seg]+ofs; } for(uint32_t i=0;i<file->edge_count;i++){ seg=file->lts->src[i]%file->segments; ofs=file->lts->src[i]/file->segments; file->lts->src[i]=offset[seg]+ofs; seg=file->lts->dest[i]%file->segments; ofs=file->lts->dest[i]/file->segments; file->lts->dest[i]=offset[seg]+ofs; } if (file->lts->properties){ uint32_t* temp=file->lts->properties; file->lts->properties=(uint32_t*)RTmalloc(file->state_count*sizeof(uint32_t)); for(int i=0;i<file->segments;i++){ for(uint32_t j=0;j<file->state_perseg[i];j++){ file->lts->properties[offset[i]+j]=temp[j*file->segments+i]; } } RTfree(temp); } lts_set_size(file->lts,file->init_count,file->state_count,file->edge_count); file->lts->tau=-1; if (lts_type_get_edge_label_count(file->lts->ltstype)==1 && strncmp(lts_type_get_edge_label_name(file->lts->ltstype,0),LTSMIN_EDGE_TYPE_ACTION_PREFIX,6)==0) { Print(infoShort,"action labeled, detecting silent step"); int tableno=lts_type_get_edge_label_typeno(file->lts->ltstype,0); value_table_t vt=file->lts->values[tableno]; int N=VTgetCount(vt); for(int i=0;i<N;i++){ chunk c=VTgetChunk(vt,i); if ( (c.len==strlen(LTSMIN_EDGE_VALUE_TAU) && strcmp(c.data,LTSMIN_EDGE_VALUE_TAU)==0) || (c.len==1 && strcmp(c.data,"i")==0) ) { Print(infoShort,"invisible label is %s",c.data); if (file->lts->tau>=0) Abort("two silent labels"); file->lts->tau=i; } } if (file->lts->tau<0) { Print(infoShort,"no silent label"); } } }