This source file includes following definitions.
- family_write
- is_valid_ni_sig
- device_write
- main
1
2
3
4 #include <stdint.h>
5 #include <stdbool.h>
6 #include <stddef.h>
7 #include <errno.h>
8 #include <stdlib.h>
9
10 typedef uint8_t u8;
11 typedef uint16_t u16;
12 typedef int8_t s8;
13 #define __user
14 #define BIT(x) (1UL << (x))
15
16 #define NI_ROUTE_VALUE_EXTERNAL_CONVERSION 1
17
18 #include "../ni_route_values.c"
19 #include "../ni_device_routes.c"
20 #include "all_cfiles.c"
21
22 #include <stdio.h>
23
24 #define RVij(rv, src, dest) ((rv)->register_values[(dest)][(src)])
25
26
27
28
29
30
31
32
33
34
35
36
37 void family_write(const struct family_route_values *rv, FILE *fp)
38 {
39 fprintf(fp,
40 " \"%s\" : {\n"
41 " # dest -> {src0:val0, src1:val1, ...}\n"
42 , rv->family);
43 for (unsigned int dest = NI_NAMES_BASE;
44 dest < (NI_NAMES_BASE + NI_NUM_NAMES);
45 ++dest) {
46 unsigned int src = NI_NAMES_BASE;
47
48 for (; src < (NI_NAMES_BASE + NI_NUM_NAMES) &&
49 RVij(rv, B(src), B(dest)) == 0; ++src)
50 ;
51
52 if (src >= (NI_NAMES_BASE + NI_NUM_NAMES))
53 continue;
54
55 fprintf(fp, " %u : {\n", dest);
56 for (src = NI_NAMES_BASE; src < (NI_NAMES_BASE + NI_NUM_NAMES);
57 ++src) {
58 register_type r = RVij(rv, B(src), B(dest));
59 const char *M;
60
61 if (r == 0) {
62 continue;
63 } else if (MARKED_V(r)) {
64 M = "V";
65 } else if (MARKED_I(r)) {
66 M = "I";
67 } else if (MARKED_U(r)) {
68 M = "U";
69 } else {
70 fprintf(stderr,
71 "Invalid register marking %s[%u][%u] = %u\n",
72 rv->family, dest, src, r);
73 exit(1);
74 }
75
76 fprintf(fp, " %u : \"%s(%u)\",\n",
77 src, M, UNMARK(r));
78 }
79 fprintf(fp, " },\n");
80 }
81 fprintf(fp, " },\n\n");
82 }
83
84 bool is_valid_ni_sig(unsigned int sig)
85 {
86 return (sig >= NI_NAMES_BASE) && (sig < (NI_NAMES_BASE + NI_NUM_NAMES));
87 }
88
89
90
91
92
93
94
95
96
97
98
99
100 void device_write(const struct ni_device_routes *dR, FILE *fp)
101 {
102 fprintf(fp,
103 " \"%s\" : {\n"
104 " # dest -> [src0, src1, ...]\n"
105 , dR->device);
106
107 unsigned int i = 0;
108
109 while (dR->routes[i].dest != 0) {
110 if (!is_valid_ni_sig(dR->routes[i].dest)) {
111 fprintf(stderr,
112 "Invalid NI signal value [%u] for destination %s.[%u]\n",
113 dR->routes[i].dest, dR->device, i);
114 exit(1);
115 }
116
117 fprintf(fp, " %u : [", dR->routes[i].dest);
118
119 unsigned int j = 0;
120
121 while (dR->routes[i].src[j] != 0) {
122 if (!is_valid_ni_sig(dR->routes[i].src[j])) {
123 fprintf(stderr,
124 "Invalid NI signal value [%u] for source %s.[%u].[%u]\n",
125 dR->routes[i].src[j], dR->device, i, j);
126 exit(1);
127 }
128
129 fprintf(fp, "%u,", dR->routes[i].src[j]);
130
131 ++j;
132 }
133 fprintf(fp, "],\n");
134
135 ++i;
136 }
137 fprintf(fp, " },\n\n");
138 }
139
140 int main(void)
141 {
142 FILE *fp = fopen("ni_values.py", "w");
143
144
145 fprintf(fp, "ni_route_values = {\n");
146 for (int i = 0; ni_all_route_values[i]; ++i)
147 family_write(ni_all_route_values[i], fp);
148 fprintf(fp, "}\n\n");
149
150
151 fprintf(fp, "ni_device_routes = {\n");
152 for (int i = 0; ni_device_routes_list[i]; ++i)
153 device_write(ni_device_routes_list[i], fp);
154 fprintf(fp, "}\n");
155
156
157 fclose(fp);
158 return 0;
159 }