static void write_trace_next (void *arg, transition_info_t *ti, int *dst, int *cpy) { (void) cpy; write_trace_step_t *ctx = (write_trace_step_t*)arg; ti->por_proviso = 0; if (ctx->found) return; if (0 != memcmp(ctx->dst, dst, sizeof(int[ctx->env->N]))) return; ctx->found = 1; lts_write_edge (ctx->env->trace_handle, 0, &ctx->src_no, 0, &ctx->dst_no, ti->labels); }
static void default_push(lts_file_t src,lts_file_t dst){ if (SYSTEM(src)->ctx != SYSTEM(dst)->ctx) Abort("cannot copy between different contexts"); int me=HREme(SYSTEM(src)->ctx); lts_type_t ltstype=lts_file_get_type(src); int N1=lts_type_get_state_length(ltstype); int N2=lts_type_get_state_label_count(ltstype); int K=lts_type_get_edge_label_count(ltstype); int do_state; if (N1){ Print(infoLong,"vector length is %d",N1); do_state=1; } else { do_state=N2?1:0; N1=1; } int src_seg; uint32_t src_state[N1]; int dst_seg; uint32_t dst_state[N1]; uint32_t edge_labels[K]; if (me==0) { Print(infoLong,"copying initial states"); int count=0; while(lts_read_init(src,&src_seg,src_state)){ count++; lts_write_init(dst,src_seg,src_state); } Print(infoLong,"%d initial state(s)",count); } for(int i=0;i<lts_file_owned_count(src);i++){ src_seg=lts_file_owned(src,i); dst_seg=lts_file_owned(src,i); if (do_state) { Print(infoLong,"copying states of segment %d",src_seg); uint32_t state_labels[N2]; while(lts_read_state(src,&src_seg,src_state,state_labels)){ lts_write_state(dst,src_seg,src_state,state_labels); } } Print(infoLong,"copying edges of segment %d",src_seg); while(lts_read_edge(src,&src_seg,src_state,&dst_seg,dst_state,edge_labels)){ lts_write_edge(dst,src_seg,src_state,dst_seg,dst_state,edge_labels); } } Print(infoLong,"done"); }
static void ta_handle (void *arg, state_info_t *successor, transition_info_t *ti, int seen) { wctx_t *ctx = (wctx_t*) arg; ta_alg_shared_t *shared = (ta_alg_shared_t *) ctx->run->shared; alg_local_t *loc = ctx->local; ta_alg_local_t *ta_loc = (ta_alg_local_t *) ctx->local; ta_alg_global_t *sm = (ta_alg_global_t *) ctx->global; ta_loc->done = 0; ta_loc->subsumes = 0; // if a successor subsumes one in the set, it cannot be subsumed itself (see invariant paper) ta_loc->work = 0; ta_loc->added_at = LM_NULL_LOC; ta_loc->last = LM_NULL_LOC; ta_loc->successor = successor; lm_lock (shared->lmap, successor->ref); lm_loc_t last = lm_iterate (shared->lmap, successor->ref, ta_covered, ctx); if (!ta_loc->done) { last = (LM_NULL_LOC == ta_loc->last ? last : ta_loc->last); sm->lloc = lm_insert_from (shared->lmap, successor->ref, successor->lattice, TA_WAITING, &last); lm_unlock (shared->lmap, successor->ref); ta_loc->counters.inserts++; if (0) { // quite costly: flops if (ta_loc->work > 0) statistics_unrecord (&ta_loc->counters.lattice_ratio, ta_loc->work); statistics_record (&ta_loc->counters.lattice_ratio, ta_loc->work+1); } ta_queue_state (ctx, successor); ta_loc->counters.updates += LM_NULL_LOC != ta_loc->last; loc->counters.level_size++; } else { lm_unlock (shared->lmap, successor->ref); } action_detect (ctx, ti, successor); if (EXPECT_FALSE(loc->lts != NULL)) { int src = ctx->counters->explored; int *tgt = state_info_state (successor); int tgt_owner = ref_hash (successor->ref) % W; lts_write_edge (loc->lts, ctx->id, &src, tgt_owner, tgt, ti->labels); } ctx->counters->trans++; (void) seen; }
int main(int argc, char *argv[]){ char* files[2]; HREinitBegin(argv[0]); HREaddOptions(options,"Tool for transforming labeled transition systems\n\nOptions"); lts_lib_setup(); HREinitStart(&argc,&argv,1,2,files,"<input> [<output>]"); int me=HREme(HREglobal()); int peers=HREpeers(HREglobal()); if (peers>1) Abort("parallelizing this tool is future work");(void)me; string_set_t label_set=NULL; if (label_filter!=NULL){ label_set=SSMcreateSWPset(label_filter); } switch(task){ case Undefined: Abort("task unspecified"); case LTScopy: if (files[1]==NULL) Abort("second argument required for copy."); Print(infoShort,"streaming copy from %s to %s",files[0],files[1]); lts_file_t in=lts_file_open(files[0]); lts_type_t ltstype=lts_file_get_type(in); rd_seg=lts_file_get_segments(in); if (wr_seg==0) { wr_seg=rd_seg; } else { Abort("on-the-fly changing the number of segments is future work"); } lts_file_t out; if (label_set==NULL){ out=lts_file_create(files[1],ltstype,wr_seg,in); } else { out=lts_file_create_filter(files[1],ltstype,label_set,wr_seg,in); } int N=lts_type_get_type_count(ltstype); for(int i=0;i<N;i++){ char*name=lts_type_get_type(ltstype,i); switch(lts_type_get_format(ltstype,i)){ case LTStypeDirect: case LTStypeRange: Debug("integer type %s does not use tables",name); break; case LTStypeChunk: case LTStypeEnum: Debug("creating table for type %s",name); value_table_t tmp=chunk_table_create(NULL,name); Debug("set in %s",name); lts_file_set_table(in,i,tmp); Debug("set out %s",name); lts_file_set_table(out,i,tmp); break; } } lts_file_copy(in,out); lts_file_close(out); lts_file_close(in); break; case LTSrdwr: if (files[1]==NULL) Abort("second argument required for rdwr."); Print(infoShort,"loading from %s",files[0]); lts_t lts=lts_create(); lts_read(files[0],lts); if (encode) { Print(infoShort,"single edge label encoding"); lts=lts_encode_edge(lts); } if (bfs_reorder) { Print(infoShort,"reindexing LTS in BFS order"); lts_bfs_reorder(lts); } Print(infoShort,"storing in %s",files[1]); if(wr_seg==0) wr_seg=1; lts_write(files[1],lts,label_set,wr_seg); break; case LTSindex:{ if (peers>1) Abort("parallelizing this tool is future work"); if (files[1]==NULL) Abort("second argument required for index."); Print(infoShort,"opening %s",files[0]); lts_file_t in=lts_file_open(files[0]); lts_type_t ltstype=lts_file_get_type(in); int segments=lts_file_get_segments(in); lts_file_t settings=lts_get_template(in); if (lts_file_get_edge_owner(settings)!=SourceOwned) Abort("bad edge owner"); lts_file_set_dest_mode(settings,Index); lts_file_set_init_mode(settings,Index); Print(infoShort,"creating %s",files[1]); lts_file_t out=lts_file_create(files[1],ltstype,segments,settings); int N=lts_type_get_type_count(ltstype); for(int i=0;i<N;i++){ char*name=lts_type_get_type(ltstype,i); switch(lts_type_get_format(ltstype,i)){ case LTStypeDirect: case LTStypeRange: Debug("integer type %s does not use tables",name); break; case LTStypeChunk: case LTStypeEnum: Debug("creating table for type %s",name); value_table_t tmp=chunk_table_create(NULL,name); Debug("set in %s",name); lts_file_set_table(in,i,tmp); Debug("set out %s",name); lts_file_set_table(out,i,tmp); break; } } treedbs_t db[segments]; int SV=lts_type_get_state_length(ltstype); int SL=lts_type_get_state_label_count(ltstype); int K=lts_type_get_edge_label_count(ltstype); for(int i=0;i<segments;i++){ Print(info,"loading and copying states of segment %d",i); uint32_t state[SV]; uint32_t label[SL]; db[i]=TreeDBScreate(SV); int idx=0; while(lts_read_state(in,&i,state,label)){ int tmp=TreeFold(db[i],(int*)state); if (idx!=tmp){ Abort("unexpected index %u != %u",tmp,idx); } idx++; lts_write_state(out,i,(int*)state,label); } } Print(info,"converting initial states"); { uint32_t seg; uint32_t state[SV]; while(lts_read_init(in,(int*)&seg,state)){ int idx=TreeFold(db[seg],(int*)state); lts_write_init(out,seg,&idx); } } for(int i=0;i<segments;i++){ Print(info,"converting edges of segment %d",i); uint32_t src_state[1]; uint32_t dst_seg; uint32_t dst_state[SV]; uint32_t label[K]; while(lts_read_edge(in,&i,src_state,(int*)&dst_seg,dst_state,label)){ int idx=TreeFold(db[dst_seg],(int*)dst_state); lts_write_edge(out,i,src_state,dst_seg,&idx,label); } } lts_file_close(out); lts_file_close(in); } } Print(infoShort,"done"); HREexit(LTSMIN_EXIT_SUCCESS); }