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

Subversion Repositories plasma

[/] [plasma/] [trunk/] [tools/] [tracehex.c] - Blame information for rev 7

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

powered by: WebSVN 2.1.0

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