]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - sim/common/gentmap.c
sim: nltvals: pull target open flags out into a dedicated source file
[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 "nltvals.def"
15 #undef sys_defs
16 { 0, 0 }
17 };
18
19 static void
20 gen_targ_vals_h (void)
21 {
22 struct tdefs *t;
23
24 printf ("/* Target header values needed by the simulator and gdb. */\n");
25 printf ("/* This file is machine generated by gentmap.c. */\n\n");
26
27 printf ("#ifndef TARG_VALS_H\n");
28 printf ("#define TARG_VALS_H\n\n");
29
30 printf ("/* syscall values */\n");
31 for (t = &sys_tdefs[0]; t->symbol; ++t)
32 printf ("#define TARGET_%s %d\n", t->symbol, t->value);
33 printf ("\n");
34
35 printf ("#endif /* TARG_VALS_H */\n");
36 }
37
38 static void
39 gen_targ_map_c (void)
40 {
41 struct tdefs *t;
42
43 printf ("/* Target value mapping utilities needed by the simulator and gdb. */\n");
44 printf ("/* This file is machine generated by gentmap.c. */\n\n");
45
46 printf ("#include \"defs.h\"\n");
47 printf ("#include \"ansidecl.h\"\n");
48 printf ("#include \"sim/callback.h\"\n");
49 printf ("#include \"targ-vals.h\"\n");
50 printf ("\n");
51
52 printf ("/* syscall mapping table */\n");
53 printf ("CB_TARGET_DEFS_MAP cb_init_syscall_map[] = {\n");
54 for (t = &sys_tdefs[0]; t->symbol; ++t)
55 {
56 printf ("#ifdef CB_%s\n", t->symbol);
57 /* Skip the "SYS_" prefix for the name. */
58 printf (" { \"%s\", CB_%s, TARGET_%s },\n", t->symbol + 4, t->symbol, t->symbol);
59 printf ("#endif\n");
60 }
61 printf (" { 0, -1, -1 }\n");
62 printf ("};\n\n");
63 }
64
65 int
66 main (int argc, char *argv[])
67 {
68 if (argc != 2)
69 abort ();
70
71 if (strcmp (argv[1], "-h") == 0)
72 gen_targ_vals_h ();
73 else if (strcmp (argv[1], "-c") == 0)
74 gen_targ_map_c ();
75 else
76 abort ();
77
78 exit (0);
79 }