]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - sim/common/gentmap.c
sim/common/gentmap.c: Include "string.h".
[thirdparty/binutils-gdb.git] / sim / common / gentmap.c
CommitLineData
c906108c
SS
1/* Generate targ-vals.h and targ-map.c. */
2
3#include <stdio.h>
09d96939 4#include <stdlib.h>
dc1d9d1f 5#include <string.h>
c906108c
SS
6
7struct tdefs {
8 char *symbol;
9 int value;
10};
11
12static struct tdefs sys_tdefs[] = {
13#define sys_defs
14#include "targ-vals.def"
15#undef sys_defs
16 { 0, 0 }
17};
18
19static struct tdefs errno_tdefs[] = {
20#define errno_defs
21#include "targ-vals.def"
22#undef errno_defs
23 { 0, 0 }
24};
25
26static struct tdefs open_tdefs[] = {
27#define open_defs
28#include "targ-vals.def"
29#undef open_defs
30 { 0, 0 }
31};
32
33static void
34gen_targ_vals_h ()
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
62static void
63gen_targ_map_c ()
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
a6ff997c 70 printf ("#include \"config.h\"\n");
c906108c
SS
71 printf ("#include <errno.h>\n");
72 printf ("#include <fcntl.h>\n");
73 printf ("#include \"ansidecl.h\"\n");
3c25f8c7 74 printf ("#include \"gdb/callback.h\"\n");
c906108c
SS
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
112int
113main (argc, argv)
114 int argc;
115 char *argv[];
116{
117 if (argc != 2)
118 abort ();
119
120 if (strcmp (argv[1], "-h") == 0)
121 gen_targ_vals_h ();
122 else if (strcmp (argv[1], "-c") == 0)
123 gen_targ_map_c ();
124 else
125 abort ();
126
127 exit (0);
128}