* d10v_sim.h (SEXT56): Define.
[deliverable/binutils-gdb.git] / sim / d10v / gencode.c
1 #include "d10v_sim.h"
2
3 static void write_header PARAMS ((void));
4 static void write_opcodes PARAMS ((void));
5 static void write_template PARAMS ((void));
6
7 int
8 main (argc, argv)
9 int argc;
10 char *argv[];
11 {
12 if ((argc > 1) && (strcmp (argv[1],"-h") == 0))
13 write_header();
14 else if ((argc > 1) && (strcmp (argv[1],"-t") == 0))
15 write_template ();
16 else
17 write_opcodes();
18 return 0;
19 }
20
21
22 static void
23 write_header ()
24 {
25 struct d10v_opcode *opcode;
26
27 for (opcode = (struct d10v_opcode *)d10v_opcodes; opcode->name; opcode++)
28 if (opcode->format != OPCODE_FAKE)
29 printf("void OP_%X PARAMS ((void));\t\t/* %s */\n",opcode->opcode, opcode->name);
30 }
31
32
33 /* write_template creates a file all required functions, ready */
34 /* to be filled out */
35
36 static void
37 write_template ()
38 {
39 struct d10v_opcode *opcode;
40 int i,j;
41
42 printf ("#include \"d10v_sim.h\"\n");
43 printf ("#include \"simops.h\"\n");
44
45 for (opcode = (struct d10v_opcode *)d10v_opcodes; opcode->name; opcode++)
46 {
47 if (opcode->format != OPCODE_FAKE)
48 {
49 printf("/* %s */\nvoid\nOP_%X ()\n{\n",opcode->name,opcode->opcode);
50
51 /* count operands */
52 j = 0;
53 for (i=0;i<6;i++)
54 {
55 int flags = d10v_operands[opcode->operands[i]].flags;
56 if ((flags & OPERAND_REG) || (flags & OPERAND_NUM) || (flags & OPERAND_ADDR))
57 j++;
58 }
59 switch (j)
60 {
61 case 0:
62 printf ("printf(\" %s\\n\");\n",opcode->name);
63 break;
64 case 1:
65 printf ("printf(\" %s\\t%%x\\n\",OP[0]);\n",opcode->name);
66 break;
67 case 2:
68 printf ("printf(\" %s\\t%%x,%%x\\n\",OP[0],OP[1]);\n",opcode->name);
69 break;
70 case 3:
71 printf ("printf(\" %s\\t%%x,%%x,%%x\\n\",OP[0],OP[1],OP[2]);\n",opcode->name);
72 break;
73 default:
74 fprintf (stderr,"Too many operands: %d\n",j);
75 }
76 printf ("}\n\n");
77 }
78 }
79 }
80
81
82 long Opcodes[512];
83 static int curop=0;
84
85 check_opcodes( long op)
86 {
87 int i;
88
89 for (i=0;i<curop;i++)
90 if (Opcodes[i] == op)
91 fprintf(stderr,"DUPLICATE OPCODES: %x\n",op);
92 }
93
94
95 static void
96 write_opcodes ()
97 {
98 struct d10v_opcode *opcode;
99 int i, j;
100
101 /* write out opcode table */
102 printf ("#include \"d10v_sim.h\"\n");
103 printf ("#include \"simops.h\"\n\n");
104 printf ("struct simops Simops[] = {\n");
105
106 for (opcode = (struct d10v_opcode *)d10v_opcodes; opcode->name; opcode++)
107 {
108 if (opcode->format != OPCODE_FAKE)
109 {
110 printf (" { %ld,%d,%ld,%d,%d,%d,%d,OP_%X,", opcode->opcode,
111 (opcode->format & LONG_OPCODE) ? 1 : 0, opcode->mask, opcode->format,
112 opcode->cycles, opcode->unit, opcode->exec_type, opcode->opcode);
113
114 /* REMOVE ME */
115 check_opcodes (opcode->opcode);
116 Opcodes[curop++] = opcode->opcode;
117
118 j = 0;
119 for (i=0;i<6;i++)
120 {
121 int flags = d10v_operands[opcode->operands[i]].flags;
122 if ((flags & OPERAND_REG) || (flags & OPERAND_NUM) || (flags & OPERAND_ADDR))
123 j++;
124 }
125 printf ("%d,{",j);
126
127 j = 0;
128 for (i=0;i<6;i++)
129 {
130 int flags = d10v_operands[opcode->operands[i]].flags;
131 int shift = d10v_operands[opcode->operands[i]].shift;
132 if ((flags & OPERAND_REG) || (flags & OPERAND_NUM)|| (flags & OPERAND_ADDR))
133 {
134 if (j)
135 printf (", ");
136 if ((flags & OPERAND_REG) && (opcode->format == LONG_L))
137 shift += 15;
138 printf ("%d,%d,%d",shift,d10v_operands[opcode->operands[i]].bits,flags);
139 j = 1;
140 }
141 }
142 printf ("}},\n");
143 }
144 }
145 printf ("{ 0,0,0,0,0,0,NULL,0,{ }},\n};\n");
146 }
This page took 0.03269 seconds and 4 git commands to generate.