/[dynamips]/trunk/insn_lookup.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/insn_lookup.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

upstream/dynamips-0.2.7/insn_lookup.c revision 10 by dpavlin, Sat Oct 6 16:29:14 2007 UTC upstream/dynamips-0.2.8-RC1/insn_lookup.c revision 11 by dpavlin, Sat Oct 6 16:33:40 2007 UTC
# Line 315  static void ilt_compile(insn_lookup_t *i Line 315  static void ilt_compile(insn_lookup_t *i
315  }  }
316    
317  /* Dump an instruction lookup table */  /* Dump an instruction lookup table */
318  static void ilt_dump(insn_lookup_t *ilt)  static int ilt_dump(char *table_name,insn_lookup_t *ilt)
319  {  {
320     rfc_array_t *rfct;     rfc_array_t *rfct;
321       char *filename;
322       FILE *fd;
323     int i,j;     int i,j;
324        
325     printf("ILT %p: nr_insn=%d, cbm_size=%d\n",ilt,ilt->nr_insn,ilt->cbm_size);     filename = dyn_sprintf("ilt_dump_%s_%s.txt",sw_version_tag,table_name);
326       assert(filename != NULL);
327    
328       fd = fopen(filename,"w");
329       assert(fd != NULL);
330      
331       fprintf(fd,"ILT %p: nr_insn=%d, cbm_size=%d\n",
332             ilt,ilt->nr_insn,ilt->cbm_size);
333    
334     for(i=0;i<RFC_ARRAY_NUMBER;i++) {     for(i=0;i<RFC_ARRAY_NUMBER;i++) {
335        rfct = ilt->rfct[i];        rfct = ilt->rfct[i];
336                
337          fprintf(fd,"RFCT %d: nr_elements=%d, nr_eqid=%d\n",
338                  i,rfct->nr_elements,rfct->nr_eqid);
339          
340        for(j=0;j<rfct->nr_elements;j++)        for(j=0;j<rfct->nr_elements;j++)
341           printf("  (0x%4.4x,0x%4.4x) = 0x%4.4x\n",i,j,rfct->eqID[j]);           fprintf(fd,"  (0x%4.4x,0x%4.4x) = 0x%4.4x\n",i,j,rfct->eqID[j]);
342     }     }
343      
344       fclose(fd);
345       return(0);
346  }  }
347    
348  /* Write the specified RFC array to disk */  /* Write the specified RFC array to disk */
# Line 338  static void ilt_store_rfct(FILE *fd,int Line 353  static void ilt_store_rfct(FILE *fd,int
353     fwrite(&rfct->nr_elements,sizeof(rfct->nr_elements),1,fd);     fwrite(&rfct->nr_elements,sizeof(rfct->nr_elements),1,fd);
354     fwrite(&rfct->nr_eqid,sizeof(rfct->nr_eqid),1,fd);     fwrite(&rfct->nr_eqid,sizeof(rfct->nr_eqid),1,fd);
355    
356     fwrite(rfct->eqID,rfct->nr_elements,sizeof(int),fd);     fwrite(rfct->eqID,sizeof(int),rfct->nr_elements,fd);
357  }  }
358    
359  /* Write the full instruction lookup table */  /* Write the full instruction lookup table */
# Line 363  static int ilt_load_rfct(FILE *fd,insn_l Line 378  static int ilt_load_rfct(FILE *fd,insn_l
378         (fread(&nr_elements,sizeof(nr_elements),1,fd) != 1) ||         (fread(&nr_elements,sizeof(nr_elements),1,fd) != 1) ||
379         (fread(&nr_eqid,sizeof(nr_eqid),1,fd) != 1))         (fread(&nr_eqid,sizeof(nr_eqid),1,fd) != 1))
380        return(-1);        return(-1);
381          
382     if ((id >= RFC_ARRAY_NUMBER) || (nr_elements > RFC_ARRAY_MAXSIZE))     if ((id >= RFC_ARRAY_NUMBER) || (nr_elements > RFC_ARRAY_MAXSIZE))
383        return(-1);        return(-1);
384    
# Line 376  static int ilt_load_rfct(FILE *fd,insn_l Line 391  static int ilt_load_rfct(FILE *fd,insn_l
391     memset(rfct,0,sizeof(*rfct));     memset(rfct,0,sizeof(*rfct));
392     rfct->nr_elements = nr_elements;     rfct->nr_elements = nr_elements;
393     rfct->nr_eqid = nr_eqid;     rfct->nr_eqid = nr_eqid;
394      
395     /* Read the equivalent ID array */     /* Read the equivalent ID array */
396     fread(rfct->eqID,rfct->nr_elements,sizeof(int),fd);     if (fread(rfct->eqID,sizeof(int),nr_elements,fd) != nr_elements) {
397          free(rfct);
398          return(-1);
399       }
400    
401     ilt->rfct[id] = rfct;     ilt->rfct[id] = rfct;
402     return(0);     return(0);
# Line 401  static int ilt_check_cached_table(insn_l Line 419  static int ilt_check_cached_table(insn_l
419  static insn_lookup_t *ilt_load_table(FILE *fd)  static insn_lookup_t *ilt_load_table(FILE *fd)
420  {  {
421     insn_lookup_t *ilt;     insn_lookup_t *ilt;
422       int i;
423      
424     if (!(ilt = malloc(sizeof(*ilt))))     if (!(ilt = malloc(sizeof(*ilt))))
425        return NULL;        return NULL;
426    
427     memset(ilt,0,sizeof(*ilt));     memset(ilt,0,sizeof(*ilt));
428       fseek(fd,0,SEEK_SET);
429    
430     while(!feof(fd)) {     for(i=0;i<RFC_ARRAY_NUMBER;i++) {
431        if (ilt_load_rfct(fd,ilt) == -1)        if (ilt_load_rfct(fd,ilt) == -1)
432           break;           return NULL;
433     }     }
434    
435     if (ilt_check_cached_table(ilt) == -1)     if (ilt_check_cached_table(ilt) == -1)
# Line 434  static insn_lookup_t *ilt_cache_load(cha Line 454  static insn_lookup_t *ilt_cache_load(cha
454     if (!(filename = ilt_build_filename(table_name)))     if (!(filename = ilt_build_filename(table_name)))
455        return NULL;        return NULL;
456    
457     if (!(fd = fopen(filename,"r"))) {     if (!(fd = fopen(filename,"rb"))) {
458        free(filename);        free(filename);
459        return NULL;        return NULL;
460     }     }
# Line 453  static int ilt_cache_store(char *table_n Line 473  static int ilt_cache_store(char *table_n
473     if (!(filename = ilt_build_filename(table_name)))     if (!(filename = ilt_build_filename(table_name)))
474        return(-1);        return(-1);
475    
476     if (!(fd = fopen(filename,"w"))) {     if (!(fd = fopen(filename,"wb"))) {
477        free(filename);        free(filename);
478        return(-1);        return(-1);
479     }     }
480    
481     ilt_store_table(fd,ilt);     ilt_store_table(fd,ilt);
482     fclose(fd);     fclose(fd);
483       free(filename);
484     return(0);     return(0);
485  }  }
486    

Legend:
Removed from v.10  
changed lines
  Added in v.11

  ViewVC Help
Powered by ViewVC 1.1.26