Ejemplo n.º 1
0
static void lts_read_dir(archive_t archive,lts_t lts){
    Print(infoShort,"opening info");
    stream_t input=arch_read(archive,"info");
    dir_info_t info=DIRinfoRead(input,1);
    DSclose(&input);
    int segments=info->segment_count;
    Print(infoShort,"got info for %d segments",segments);
    int offset[segments];
    offset[0]=0;
    for(int i=1;i<segments;i++){
        offset[i]=info->state_count[i-1]+offset[i-1];
    }
    int s_count=0;
    int t_count=0;
    for(int i=0;i<segments;i++){
        s_count+=info->state_count[i];
        for(int j=0;j<segments;j++){
            t_count+=info->transition_count[i][j];
        }
    }
    Print(infoShort,"counted %u states and %u transitions",s_count,t_count);
    lts_set_sig(lts,single_action_type());
    lts_set_type(lts,LTS_LIST);
    lts_set_size(lts,1,s_count,t_count);
    lts->root_list[0]=offset[info->initial_seg]+info->initial_ofs;
    lts->tau=info->label_tau;
    Print(infoShort,"getting %d labels from TermDB",info->label_count);
    input=arch_read(archive,"TermDB");
    int type_no=lts_type_get_edge_label_typeno(lts->ltstype,0);
    for(int i=0;i<info->label_count;i++){
        char *line=DSreadLN(input);
        int len=strlen(line);
        char data[len];
        chunk tmp_chunk=chunk_ld(len,data);
        string2chunk(line,&tmp_chunk);
        VTputAtChunk(lts->values[type_no], tmp_chunk, i);
    }
    DSclose(&input);
    Print(infoShort,"got labels");
    int t_offset=0;
    char filename[1024];
    for(int i=0;i<segments;i++){
        for(int j=0;j<segments;j++){
            sprintf(filename,"src-%d-%d",i,j);
            stream_t src=arch_read(archive,filename);
            sprintf(filename,"label-%d-%d",i,j);
            stream_t lbl=arch_read(archive,filename);
            sprintf(filename,"dest-%d-%d",i,j);
            stream_t dst=arch_read(archive,filename);
            for(int k=0;k<info->transition_count[i][j];k++){
                lts->src[t_offset]=offset[i]+DSreadU32(src);
                lts->label[t_offset]=DSreadU32(lbl);
                lts->dest[t_offset]=offset[j]+DSreadU32(dst);
                t_offset++;
            }
            DSclose(&src);
            DSclose(&lbl);
            DSclose(&dst);
        }
    }
    DIRinfoDestroy(info);
}
Ejemplo n.º 2
0
lts_type_t lts_type_deserialize(stream_t ds){
	lts_type_t t=lts_type_create();
	char version[1024];
	DSreadS(ds,version,1024);
	int has_format_info;
	if (strcmp(version,"lts signature 1.1")==0){
		has_format_info=1;
	} else if (strcmp(version,"lts signature 1.0")==0){
		has_format_info=0;
	} else {
		Abort("cannot deserialize %s",version);
	}
	uint32_t N=DSreadU32(ds);
	Warning(debug,"state length is %d",N);
	lts_type_set_state_length(t,N);
	for(uint32_t i=0;i<N;i++){
		char*x=DSreadSA(ds);
		if (strlen(x)) lts_type_set_state_name(t,i,x);
		RTfree(x);
		lts_type_set_state_typeno(t,i,DSreadU32(ds));
	}
	N=DSreadU32(ds);
	Warning(debug,"%d state labels",N);
	lts_type_set_state_label_count(t,N);
	for(uint32_t i=0;i<N;i++){
		char*x=DSreadSA(ds);
		if (strlen(x)) lts_type_set_state_label_name(t,i,x);
		RTfree(x);
		lts_type_set_state_label_typeno(t,i,DSreadU32(ds));
	}
	N=DSreadU32(ds);
	Warning(debug,"%d edge labels",N);
	lts_type_set_edge_label_count(t,N);
	for(uint32_t i=0;i<N;i++){
		char*x=DSreadSA(ds);
		if (strlen(x)) lts_type_set_edge_label_name(t,i,x);
		RTfree(x);
		lts_type_set_edge_label_typeno(t,i,DSreadU32(ds));
	}
	N=DSreadU32(ds);
	Warning(debug,"%d types",N);
	for(uint32_t i=0;i<N;i++){
		char*x=DSreadSA(ds);
		int tmp=lts_type_add_type(t,x,NULL);
		if (tmp!=(int)i) Abort("bad type add");
		RTfree(x);
		if (has_format_info) {
			x=DSreadSA(ds);
			if (strcmp(x,"direct")==0){
			    lts_type_set_format(t,i,LTStypeDirect);
			} else if (strcmp(x,"chunk")==0){
				lts_type_set_format(t,i,LTStypeChunk);
			} else if (strcmp(x,"enum")==0){
				lts_type_set_format(t,i,LTStypeEnum);
			} else {
			    int n=strlen(x);
			    if (x[0]=='[' && x[n-1]==']') {
			        int k=0;
			        while(k<n && x[k]!=',') k++;
			        if (k<n) {
			            lts_type_set_format(t,i,LTStypeRange);
			            lts_type_set_range(t,i,atoi(x+1),atoi(x+k+1));
			        }
			    }
				Abort("unsupported data format %s",x);
			}
			RTfree(x);
		} else {
		    lts_type_set_format(t,i,LTStypeChunk);
		}
	}
	return t;
}