-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrom_gen.c
57 lines (45 loc) · 1005 Bytes
/
rom_gen.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
bool get_u32(uint32_t *res)
{
int i;
*res = 0;
for (i = 0; i < 4; ++i) {
int c = getchar();
if (c < 0) {
return (i > 0);
}
else {
*res += ((uint32_t)c) << (i * 8);
}
}
return true;
}
int main(int argc, char **argv)
{
uint32_t word;
int addr;
if (argc != 2) {
fprintf(stderr, "please specify rom name\n");
exit(-1);
}
printf("module %s(\n"
"input clk,\n"
"output reg [31:0] q,\n"
"input [29:0] addr);\n",
argv[1]);
printf("always @(posedge clk) begin\n");
printf("case (addr)\n");
addr = 0;
while (get_u32(&word)) {
printf(" 29'h%8x: q <= 32'h%08x;\n",
addr++, word);
}
printf(" default: q <= 32'd0;\n"
"endcase\n");
printf("end\n");
printf("endmodule\n");
return 0;
}