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