OpenCores
URL https://opencores.org/ocsvn/plasma/plasma/trunk

Subversion Repositories plasma

[/] [plasma/] [tags/] [V3_0/] [tools/] [tracehex.c] - Blame information for rev 78

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 7 rhoads
/***********************************************************
2
| tracehex by Steve Rhoads 12/25/01
3
| This tool modifies trace files from the free VHDL simulator
4 16 rhoads
| http://www.symphonyeda.com/.
5 7 rhoads
| The binary numbers are converted to hex values.
6
************************************************************/
7
#include <stdio.h>
8
#include <stdlib.h>
9
#include <string.h>
10
#include <ctype.h>
11
 
12
#define BUF_SIZE (1024*1024)
13 16 rhoads
#define LINE_SIZE 10000
14 7 rhoads
 
15
char drop_char[10000];
16 16 rhoads
//char line[10000];
17 7 rhoads
 
18
int main(int argc, char *argv[])
19
{
20
   FILE *file;
21 16 rhoads
   char *buf,*ptr_in,*ptr_out,*line_store,*line;
22 7 rhoads
   int bytes,digits,value,isbinary,col,col_num,row,drop_cnt;
23 16 rhoads
   int col_index,line_index,back_count;
24
   int digits_length=0;
25 7 rhoads
   (void)argc,argv;
26
 
27 16 rhoads
   printf("tracehex\n");
28
 
29 7 rhoads
   /* Reading trace.txt */
30
   file=fopen("trace.txt","r");
31
   if(file==NULL) {
32
      printf("Can't open file\n");
33
      return -1;
34
   }
35 16 rhoads
   line_store=(char*)malloc(LINE_SIZE);
36
   line_store[0]=' ';
37
   line=line_store+1;
38 7 rhoads
   buf=(char*)malloc(BUF_SIZE*2);
39 16 rhoads
   if(buf==NULL) {
40
      printf("Can't malloc!\n");
41
      return -1;
42
   }
43 7 rhoads
   ptr_out=buf+BUF_SIZE;
44
   bytes=fread(buf,1,BUF_SIZE-1,file);
45
   buf[bytes]=0;
46
   fclose(file);
47
 
48
   digits=0;
49
   value=0;
50
   isbinary=0;
51
   col=0;
52
   col_num=0;
53
   row=0;
54
   for(ptr_in=strstr(buf,"=");*ptr_in;++ptr_in) {
55
      ++col;
56 78 rhoads
      if(col<4||col==12||col==13||col==14) {
57 7 rhoads
         drop_char[col]=1;
58
         continue;
59
      }
60
 
61
      /* convert binary number to hex */
62
      if(isbinary&&(*ptr_in=='0'||*ptr_in=='1')) {
63
         value=value*2+*ptr_in-'0';
64
         ++digits;
65
         drop_char[col_num++]=1;
66
      } else if(isbinary&&*ptr_in=='Z') {
67
         value=1000;
68
         ++digits;
69
         drop_char[col_num++]=1;
70
      } else if(isbinary&&*ptr_in=='U') {
71
         value=10000;
72
         ++digits;
73
         drop_char[col_num++]=1;
74
      } else {
75
         if(*ptr_in=='\n') {
76
            col=0;
77
            isbinary=0;
78
            ++row;
79
         }
80
         if(isspace(*ptr_in)) {
81
            if(col>10) {
82
               isbinary=1;
83
               col_num=col;
84 16 rhoads
               for(digits_length=1;!isspace(ptr_in[digits_length]);++digits_length) ;
85
               --digits_length;
86 7 rhoads
            }
87
         } else {
88
            isbinary=0;
89
         }
90
         *ptr_out++=*ptr_in;
91
         digits=0;
92
         value=0;
93
      }
94
      /* convert every four binary digits to a hex digit */
95 16 rhoads
      if(digits&&(digits_length%4)==0) {
96 7 rhoads
         drop_char[--col_num]=0;
97
         if(value<100) {
98
            *ptr_out++=value<10?value+'0':value-10+'A';
99
         } else if(value<5000) {
100
            *ptr_out++='Z';
101
         } else {
102
            *ptr_out++='U';
103
         }
104
         digits=0;
105
         value=0;
106
      }
107 16 rhoads
      --digits_length;
108 7 rhoads
   }
109
   *ptr_out=0;
110
 
111
   /* now process the header */
112
   file=fopen("trace2.txt","w");
113
   col=0;
114
   line[0]=0;
115
   for(ptr_in=buf;*ptr_in;++ptr_in) {
116
      if(*ptr_in=='=') {
117
         break;
118
      }
119
      line[col++]=*ptr_in;
120
      if(*ptr_in=='\n') {
121
         line[col]=0;
122
         line_index=0;
123
         for(col_index=0;col_index<col;++col_index) {
124
            if(drop_char[col_index]) {
125
               back_count=0;
126
               while(line[line_index-back_count]!=' '&&back_count<10) {
127
                  ++back_count;
128
               }
129
               if(line[line_index-back_count-1]!=' ') {
130
                  --back_count;
131
               }
132
               strcpy(line+line_index-back_count,line+line_index-back_count+1);
133
            } else {
134
               ++line_index;
135
            }
136
         }
137
         fprintf(file,"%s",line);
138
         col=0;
139
      }
140
   }
141
   drop_cnt=0;
142
   for(col_index=13;col_index<sizeof(drop_char);++col_index) {
143
      if(drop_char[col_index]) {
144
         ++drop_cnt;
145
      }
146
   }
147
   fprintf(file,"%s",buf+BUF_SIZE+drop_cnt);
148
 
149
   fclose(file);
150 16 rhoads
   free(line_store);
151 7 rhoads
   free(buf);
152
   return 0;
153
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.