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

Subversion Repositories plasma

[/] [plasma/] [trunk/] [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 336 rhoads
   (void)argc;
26
   (void)argv;
27 7 rhoads
 
28 16 rhoads
   printf("tracehex\n");
29
 
30 7 rhoads
   /* Reading trace.txt */
31
   file=fopen("trace.txt","r");
32
   if(file==NULL) {
33
      printf("Can't open file\n");
34
      return -1;
35
   }
36 16 rhoads
   line_store=(char*)malloc(LINE_SIZE);
37
   line_store[0]=' ';
38
   line=line_store+1;
39 7 rhoads
   buf=(char*)malloc(BUF_SIZE*2);
40 16 rhoads
   if(buf==NULL) {
41
      printf("Can't malloc!\n");
42
      return -1;
43
   }
44 7 rhoads
   ptr_out=buf+BUF_SIZE;
45
   bytes=fread(buf,1,BUF_SIZE-1,file);
46
   buf[bytes]=0;
47
   fclose(file);
48
 
49
   digits=0;
50
   value=0;
51
   isbinary=0;
52
   col=0;
53
   col_num=0;
54
   row=0;
55 80 rhoads
   line_start=ptr_out;
56
   source_start=buf;
57 7 rhoads
   for(ptr_in=strstr(buf,"=");*ptr_in;++ptr_in) {
58
      ++col;
59 80 rhoads
      if(drop_start==0&&*ptr_in==' ') {
60
         for(drop_start=3;drop_start<30;++drop_start) {
61
            if(ptr_in[drop_start]!=' ') {
62
               break;
63
            }
64
         }
65
         for(;drop_start<30;++drop_start) {
66
            if(ptr_in[drop_start]==' ') {
67
               break;
68
            }
69
         }
70
         drop_start-=2;
71
      }
72
      if(col<4) {
73 7 rhoads
         drop_char[col]=1;
74
         continue;
75
      }
76 80 rhoads
      if(drop_start<=col&&col<=drop_start+2) {
77
         drop_char[col]=1;
78
         continue;
79
      }
80
      if(col<drop_start) {
81
         *ptr_out++=*ptr_in;
82
         continue;
83
      }
84
 
85 7 rhoads
      /* convert binary number to hex */
86
      if(isbinary&&(*ptr_in=='0'||*ptr_in=='1')) {
87
         value=value*2+*ptr_in-'0';
88
         ++digits;
89
         drop_char[col_num++]=1;
90
      } else if(isbinary&&*ptr_in=='Z') {
91
         value=1000;
92
         ++digits;
93
         drop_char[col_num++]=1;
94 80 rhoads
      } else if(isbinary&&(*ptr_in=='U'||*ptr_in=='X')) {
95 7 rhoads
         value=10000;
96
         ++digits;
97
         drop_char[col_num++]=1;
98
      } else {
99
         if(*ptr_in=='\n') {
100
            col=0;
101
            isbinary=0;
102
            ++row;
103
         }
104
         if(isspace(*ptr_in)) {
105
            if(col>10) {
106
               isbinary=1;
107
               col_num=col;
108 16 rhoads
               for(digits_length=1;!isspace(ptr_in[digits_length]);++digits_length) ;
109
               --digits_length;
110 7 rhoads
            }
111
         } else {
112
            isbinary=0;
113
         }
114
         *ptr_out++=*ptr_in;
115
         digits=0;
116
         value=0;
117
      }
118
      /* convert every four binary digits to a hex digit */
119 16 rhoads
      if(digits&&(digits_length%4)==0) {
120 7 rhoads
         drop_char[--col_num]=0;
121
         if(value<100) {
122
            *ptr_out++=value<10?value+'0':value-10+'A';
123
         } else if(value<5000) {
124
            *ptr_out++='Z';
125
         } else {
126
            *ptr_out++='U';
127
         }
128
         digits=0;
129
         value=0;
130
      }
131 16 rhoads
      --digits_length;
132 7 rhoads
   }
133
   *ptr_out=0;
134
 
135
   /* now process the header */
136
   file=fopen("trace2.txt","w");
137
   col=0;
138
   line[0]=0;
139
   for(ptr_in=buf;*ptr_in;++ptr_in) {
140
      if(*ptr_in=='=') {
141
         break;
142
      }
143
      line[col++]=*ptr_in;
144
      if(*ptr_in=='\n') {
145
         line[col]=0;
146
         line_index=0;
147
         for(col_index=0;col_index<col;++col_index) {
148
            if(drop_char[col_index]) {
149
               back_count=0;
150
               while(line[line_index-back_count]!=' '&&back_count<10) {
151
                  ++back_count;
152
               }
153
               if(line[line_index-back_count-1]!=' ') {
154
                  --back_count;
155
               }
156
               strcpy(line+line_index-back_count,line+line_index-back_count+1);
157
            } else {
158
               ++line_index;
159
            }
160
         }
161
         fprintf(file,"%s",line);
162
         col=0;
163
      }
164
   }
165
   drop_cnt=0;
166
   for(col_index=13;col_index<sizeof(drop_char);++col_index) {
167
      if(drop_char[col_index]) {
168
         ++drop_cnt;
169
      }
170
   }
171
   fprintf(file,"%s",buf+BUF_SIZE+drop_cnt);
172
 
173
   fclose(file);
174 16 rhoads
   free(line_store);
175 7 rhoads
   free(buf);
176
   return 0;
177
}

powered by: WebSVN 2.1.0

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