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

Subversion Repositories plasma

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

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 80 rhoads
#define BUF_SIZE (1024*1024*4)
13 16 rhoads
#define LINE_SIZE 10000
14 7 rhoads
 
15
char drop_char[10000];
16
 
17
int main(int argc, char *argv[])
18
{
19
   FILE *file;
20 16 rhoads
   char *buf,*ptr_in,*ptr_out,*line_store,*line;
21 80 rhoads
   char *line_start,*source_start;
22 7 rhoads
   int bytes,digits,value,isbinary,col,col_num,row,drop_cnt;
23 80 rhoads
   int col_index,line_index,back_count,drop_start=0;
24 16 rhoads
   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 80 rhoads
   line_start=ptr_out;
55
   source_start=buf;
56 7 rhoads
   for(ptr_in=strstr(buf,"=");*ptr_in;++ptr_in) {
57
      ++col;
58 80 rhoads
      if(drop_start==0&&*ptr_in==' ') {
59
         for(drop_start=3;drop_start<30;++drop_start) {
60
            if(ptr_in[drop_start]!=' ') {
61
               break;
62
            }
63
         }
64
         for(;drop_start<30;++drop_start) {
65
            if(ptr_in[drop_start]==' ') {
66
               break;
67
            }
68
         }
69
         drop_start-=2;
70
      }
71
      if(col<4) {
72 7 rhoads
         drop_char[col]=1;
73
         continue;
74
      }
75 80 rhoads
      if(drop_start<=col&&col<=drop_start+2) {
76
         drop_char[col]=1;
77
         continue;
78
      }
79
      if(col<drop_start) {
80
         *ptr_out++=*ptr_in;
81
         continue;
82
      }
83
 
84 7 rhoads
      /* convert binary number to hex */
85
      if(isbinary&&(*ptr_in=='0'||*ptr_in=='1')) {
86
         value=value*2+*ptr_in-'0';
87
         ++digits;
88
         drop_char[col_num++]=1;
89
      } else if(isbinary&&*ptr_in=='Z') {
90
         value=1000;
91
         ++digits;
92
         drop_char[col_num++]=1;
93 80 rhoads
      } else if(isbinary&&(*ptr_in=='U'||*ptr_in=='X')) {
94 7 rhoads
         value=10000;
95
         ++digits;
96
         drop_char[col_num++]=1;
97
      } else {
98
         if(*ptr_in=='\n') {
99
            col=0;
100
            isbinary=0;
101
            ++row;
102
         }
103
         if(isspace(*ptr_in)) {
104
            if(col>10) {
105
               isbinary=1;
106
               col_num=col;
107 16 rhoads
               for(digits_length=1;!isspace(ptr_in[digits_length]);++digits_length) ;
108
               --digits_length;
109 7 rhoads
            }
110
         } else {
111
            isbinary=0;
112
         }
113
         *ptr_out++=*ptr_in;
114
         digits=0;
115
         value=0;
116
      }
117
      /* convert every four binary digits to a hex digit */
118 16 rhoads
      if(digits&&(digits_length%4)==0) {
119 7 rhoads
         drop_char[--col_num]=0;
120
         if(value<100) {
121
            *ptr_out++=value<10?value+'0':value-10+'A';
122
         } else if(value<5000) {
123
            *ptr_out++='Z';
124
         } else {
125
            *ptr_out++='U';
126
         }
127
         digits=0;
128
         value=0;
129
      }
130 16 rhoads
      --digits_length;
131 7 rhoads
   }
132
   *ptr_out=0;
133
 
134
   /* now process the header */
135
   file=fopen("trace2.txt","w");
136
   col=0;
137
   line[0]=0;
138
   for(ptr_in=buf;*ptr_in;++ptr_in) {
139
      if(*ptr_in=='=') {
140
         break;
141
      }
142
      line[col++]=*ptr_in;
143
      if(*ptr_in=='\n') {
144
         line[col]=0;
145
         line_index=0;
146
         for(col_index=0;col_index<col;++col_index) {
147
            if(drop_char[col_index]) {
148
               back_count=0;
149
               while(line[line_index-back_count]!=' '&&back_count<10) {
150
                  ++back_count;
151
               }
152
               if(line[line_index-back_count-1]!=' ') {
153
                  --back_count;
154
               }
155
               strcpy(line+line_index-back_count,line+line_index-back_count+1);
156
            } else {
157
               ++line_index;
158
            }
159
         }
160
         fprintf(file,"%s",line);
161
         col=0;
162
      }
163
   }
164
   drop_cnt=0;
165
   for(col_index=13;col_index<sizeof(drop_char);++col_index) {
166
      if(drop_char[col_index]) {
167
         ++drop_cnt;
168
      }
169
   }
170
   fprintf(file,"%s",buf+BUF_SIZE+drop_cnt);
171
 
172
   fclose(file);
173 16 rhoads
   free(line_store);
174 7 rhoads
   free(buf);
175
   return 0;
176
}

powered by: WebSVN 2.1.0

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