gdb/testsuite: Reduce gdb.threads/threadcrash.exp reliance on libc symbols
[binutils-gdb.git] / sim / d10v / gencode.c
blob3a37bac62563f56a5070c690faf97028614b5d12
1 #include <stdio.h>
2 #include <ctype.h>
3 #include <limits.h>
4 #include <string.h>
5 #include "ansidecl.h"
6 #include "opcode/d10v.h"
8 static void write_header (void);
9 static void write_opcodes (void);
10 static void write_template (void);
12 int
13 main (int argc, char *argv[])
15 if ((argc > 1) && (strcmp (argv[1],"-h") == 0))
16 write_header();
17 else if ((argc > 1) && (strcmp (argv[1],"-t") == 0))
18 write_template ();
19 else
20 write_opcodes();
21 return 0;
25 static void
26 write_header (void)
28 struct d10v_opcode *opcode;
30 for (opcode = (struct d10v_opcode *)d10v_opcodes; opcode->name; opcode++)
31 if (opcode->format != OPCODE_FAKE)
32 printf ("void OP_%lX (SIM_DESC, SIM_CPU *);\t\t/* %s */\n", opcode->opcode, opcode->name);
36 /* write_template creates a file all required functions, ready */
37 /* to be filled out */
39 static void
40 write_template (void)
42 struct d10v_opcode *opcode;
43 int i,j;
45 printf ("#include \"d10v-sim.h\"\n");
46 printf ("#include \"simops.h\"\n");
48 for (opcode = (struct d10v_opcode *)d10v_opcodes; opcode->name; opcode++)
50 if (opcode->format != OPCODE_FAKE)
52 printf("/* %s */\nvoid\nOP_%lX ()\n{\n", opcode->name, opcode->opcode);
54 /* count operands */
55 j = 0;
56 for (i=0;i<6;i++)
58 int flags = d10v_operands[opcode->operands[i]].flags;
59 if ((flags & OPERAND_REG) || (flags & OPERAND_NUM) || (flags & OPERAND_ADDR))
60 j++;
62 switch (j)
64 case 0:
65 printf ("printf(\" %s\\n\");\n",opcode->name);
66 break;
67 case 1:
68 printf ("printf(\" %s\\t%%x\\n\",OP[0]);\n",opcode->name);
69 break;
70 case 2:
71 printf ("printf(\" %s\\t%%x,%%x\\n\",OP[0],OP[1]);\n",opcode->name);
72 break;
73 case 3:
74 printf ("printf(\" %s\\t%%x,%%x,%%x\\n\",OP[0],OP[1],OP[2]);\n",opcode->name);
75 break;
76 default:
77 fprintf (stderr,"Too many operands: %d\n",j);
79 printf ("}\n\n");
85 long Opcodes[512];
86 static int curop=0;
88 static void
89 check_opcodes( long op)
91 int i;
93 for (i=0;i<curop;i++)
94 if (Opcodes[i] == op)
95 fprintf(stderr,"DUPLICATE OPCODES: %lx\n", op);
98 static void
99 write_opcodes (void)
101 struct d10v_opcode *opcode;
102 int i, j;
104 /* write out opcode table */
105 printf ("#include \"sim-main.h\"\n");
106 printf ("#include \"d10v-sim.h\"\n");
107 printf ("#include \"simops.h\"\n\n");
108 printf ("struct simops Simops[] = {\n");
110 for (opcode = (struct d10v_opcode *)d10v_opcodes; opcode->name; opcode++)
112 if (opcode->format != OPCODE_FAKE)
114 printf (" { %ld,%d,%ld,%d,%d,%d,%d,OP_%lX,", opcode->opcode,
115 (opcode->format & LONG_OPCODE) ? 1 : 0, opcode->mask, opcode->format,
116 opcode->cycles, opcode->unit, opcode->exec_type, opcode->opcode);
118 /* REMOVE ME */
119 check_opcodes (opcode->opcode);
120 Opcodes[curop++] = opcode->opcode;
122 j = 0;
123 for (i=0;i<6;i++)
125 int flags = d10v_operands[opcode->operands[i]].flags;
126 if ((flags & OPERAND_REG) || (flags & OPERAND_NUM) || (flags & OPERAND_ADDR))
127 j++;
129 printf ("%d,",j);
131 j = 0;
132 for (i=0;i<6;i++)
134 int flags = d10v_operands[opcode->operands[i]].flags;
135 int shift = d10v_operands[opcode->operands[i]].shift;
136 if ((flags & OPERAND_REG) || (flags & OPERAND_NUM)|| (flags & OPERAND_ADDR))
138 if (j == 0)
139 printf ("{");
140 else
141 printf (", ");
142 if ((flags & OPERAND_REG) && (opcode->format == LONG_L))
143 shift += 15;
144 printf ("%d,%d,%d",shift,d10v_operands[opcode->operands[i]].bits,flags);
145 j = 1;
148 if (j)
149 printf ("}");
150 printf ("},\n");
153 printf ("{ 0,0,0,0,0,0,0,(void (*)())0,0,{0,0,0}},\n};\n");