xref: /XiangShan/tools/readmemh/gen-treadle-readmemh.c (revision b543b09fe259d66bc6815a12b33d14da14834c9f)
1 #include <stdio.h>
2 #include <assert.h>
3 #include <stdint.h>
4 
5 int main(int argc, char *argv[]) {
6   assert(argc == 3);
7 
8   FILE *in = fopen(argv[1], "rb");
9   assert(in != NULL);
10 
11   FILE *out = fopen(argv[2], "w");
12   assert(out != NULL);
13 
14   int i;
15   for (i = 0; i < 0x100000; i ++) {
16     fprintf(out, "00\n");
17   }
18 
19   uint8_t b;
20   int ret;
21   while ((ret = fread(&b, 1, 1, in)) != 0) {
22     fprintf(out, "%1x%1x\n", b >> 4, b & 0xf);
23   }
24 
25   fclose(in);
26   fclose(out);
27 
28   return 0;
29 }
30