]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - sim/common/gentmap.c
sim: convert some old prototypes
[thirdparty/binutils-gdb.git] / sim / common / gentmap.c
1 /* Generate targ-vals.h and targ-map.c. */
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6
7 struct tdefs {
8 char *symbol;
9 int value;
10 };
11
12 static struct tdefs sys_tdefs[] = {
13 #define sys_defs
14 #include "targ-vals.def"
15 #undef sys_defs
16 { 0, 0 }
17 };
18
19 static struct tdefs errno_tdefs[] = {
20 #define errno_defs
21 #include "targ-vals.def"
22 #undef errno_defs
23 { 0, 0 }
24 };
25
26 static struct tdefs open_tdefs[] = {
27 #define open_defs
28 #include "targ-vals.def"
29 #undef open_defs
30 { 0, 0 }
31 };
32
33 static void
34 gen_targ_vals_h (void)
35 {
36 struct tdefs *t;
37
38 printf ("/* Target header values needed by the simulator and gdb. */\n");
39 printf ("/* This file is machine generated by gentmap.c. */\n\n");
40
41 printf ("#ifndef TARG_VALS_H\n");
42 printf ("#define TARG_VALS_H\n\n");
43
44 printf ("/* syscall values */\n");
45 for (t = &sys_tdefs[0]; t->symbol; ++t)
46 printf ("#define TARGET_%s %d\n", t->symbol, t->value);
47 printf ("\n");
48
49 printf ("/* errno values */\n");
50 for (t = &errno_tdefs[0]; t->symbol; ++t)
51 printf ("#define TARGET_%s %d\n", t->symbol, t->value);
52 printf ("\n");
53
54 printf ("/* open flag values */\n");
55 for (t = &open_tdefs[0]; t->symbol; ++t)
56 printf ("#define TARGET_%s 0x%x\n", t->symbol, t->value);
57 printf ("\n");
58
59 printf ("#endif /* TARG_VALS_H */\n");
60 }
61
62 static void
63 gen_targ_map_c (void)
64 {
65 struct tdefs *t;
66
67 printf ("/* Target value mapping utilities needed by the simulator and gdb. */\n");
68 printf ("/* This file is machine generated by gentmap.c. */\n\n");
69
70 printf ("#include \"config.h\"\n");
71 printf ("#include <errno.h>\n");
72 printf ("#include <fcntl.h>\n");
73 printf ("#include \"ansidecl.h\"\n");
74 printf ("#include \"gdb/callback.h\"\n");
75 printf ("#include \"targ-vals.h\"\n");
76 printf ("\n");
77
78 printf ("/* syscall mapping table */\n");
79 printf ("CB_TARGET_DEFS_MAP cb_init_syscall_map[] = {\n");
80 for (t = &sys_tdefs[0]; t->symbol; ++t)
81 {
82 printf ("#ifdef CB_%s\n", t->symbol);
83 printf (" { CB_%s, TARGET_%s },\n", t->symbol, t->symbol);
84 printf ("#endif\n");
85 }
86 printf (" { -1, -1 }\n");
87 printf ("};\n\n");
88
89 printf ("/* errno mapping table */\n");
90 printf ("CB_TARGET_DEFS_MAP cb_init_errno_map[] = {\n");
91 for (t = &errno_tdefs[0]; t->symbol; ++t)
92 {
93 printf ("#ifdef %s\n", t->symbol);
94 printf (" { %s, TARGET_%s },\n", t->symbol, t->symbol);
95 printf ("#endif\n");
96 }
97 printf (" { 0, 0 }\n");
98 printf ("};\n\n");
99
100 printf ("/* open flags mapping table */\n");
101 printf ("CB_TARGET_DEFS_MAP cb_init_open_map[] = {\n");
102 for (t = &open_tdefs[0]; t->symbol; ++t)
103 {
104 printf ("#ifdef %s\n", t->symbol);
105 printf (" { %s, TARGET_%s },\n", t->symbol, t->symbol);
106 printf ("#endif\n");
107 }
108 printf (" { -1, -1 }\n");
109 printf ("};\n\n");
110 }
111
112 int
113 main (int argc, char *argv[])
114 {
115 if (argc != 2)
116 abort ();
117
118 if (strcmp (argv[1], "-h") == 0)
119 gen_targ_vals_h ();
120 else if (strcmp (argv[1], "-c") == 0)
121 gen_targ_map_c ();
122 else
123 abort ();
124
125 exit (0);
126 }