add: performance values for Lattice MachXO2
[zpu.git] / zpu / hdl / example / zpuromgen.c
blobfb8c4bacbbc26cdaf90e3c680fc46e943b709446
1 // zpuromgen.c
2 //
3 // Program to turn a binary file into a VHDL lookup table.
4 // by Adam Pierce
5 // 29-Feb-2008
6 //
7 // This software is free to use by anyone for any purpose.
8 //
10 #include <unistd.h>
11 #include <stdio.h>
13 typedef uint8_t BYTE;
15 main(int argc, char **argv)
17 BYTE opcode[4];
18 int fd;
19 int addr = 0;
20 ssize_t s;
22 // Check the user has given us an input file.
23 if(argc < 2)
25 printf("Usage: %s <binary_file>\n\n", argv[0]);
26 return 1;
29 // Open the input file.
30 fd = open(argv[1], 0);
31 if(fd == -1)
33 perror("File Open");
34 return 2;
37 while(1)
39 // Read 32 bits.
40 s = read(fd, opcode, 4);
41 if(s == -1)
43 perror("File read");
44 return 3;
47 if(s == 0)
48 break; // End of file.
50 // Output to STDOUT.
51 printf("%6d => x\"%02x%02x%02x%02x\",\n",
52 addr++, opcode[0], opcode[1],
53 opcode[2], opcode[3]);
56 close(fd);
57 return 0;