* gencode.c: Fix various indention & style problems.
[deliverable/binutils-gdb.git] / sim / v850 / gencode.c
1 #include "v850_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 long Opcodes[512];
8 static int curop=0;
9
10 int
11 main (argc, argv)
12 int argc;
13 char *argv[];
14 {
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;
22 }
23
24
25 static void
26 write_header ()
27 {
28 struct v850_opcode *opcode;
29
30 for (opcode = (struct v850_opcode *)v850_opcodes; opcode->name; opcode++)
31 printf("void OP_%X PARAMS ((void));\t\t/* %s */\n",
32 opcode->opcode, opcode->name);
33 }
34
35
36 /* write_template creates a file all required functions, ready */
37 /* to be filled out */
38
39 static void
40 write_template ()
41 {
42 struct v850_opcode *opcode;
43 int i,j;
44
45 printf ("#include \"v850_sim.h\"\n");
46 printf ("#include \"simops.h\"\n");
47
48 for (opcode = (struct v850_opcode *)v850_opcodes; opcode->name; opcode++)
49 {
50 printf("/* %s */\nvoid\nOP_%X ()\n{\n", opcode->name, opcode->opcode);
51
52 /* count operands */
53 j = 0;
54 for (i = 0; i < 6; i++)
55 {
56 int flags = v850_operands[opcode->operands[i]].flags;
57
58 if (flags & (V850_OPERAND_REG | V850_OPERAND_SRG | V850_OPERAND_CC))
59 j++;
60 }
61 switch (j)
62 {
63 case 0:
64 printf ("printf(\" %s\\n\");\n", opcode->name);
65 break;
66 case 1:
67 printf ("printf(\" %s\\t%%x\\n\", OP[0]);\n", opcode->name);
68 break;
69 case 2:
70 printf ("printf(\" %s\\t%%x,%%x\\n\",OP[0],OP[1]);\n",
71 opcode->name);
72 break;
73 case 3:
74 printf ("printf(\" %s\\t%%x,%%x,%%x\\n\",OP[0],OP[1],OP[2]);\n",
75 opcode->name);
76 break;
77 default:
78 fprintf (stderr,"Too many operands: %d\n", j);
79 }
80 printf ("}\n\n");
81 }
82 }
83
84 static void
85 write_opcodes ()
86 {
87 struct v850_opcode *opcode;
88 int i, j;
89
90 /* write out opcode table */
91 printf ("#include \"v850_sim.h\"\n");
92 printf ("#include \"simops.h\"\n\n");
93 printf ("struct simops Simops[] = {\n");
94
95 for (opcode = (struct v850_opcode *)v850_opcodes; opcode->name; opcode++)
96 {
97 printf (" { %ld,%ld,OP_%X,",
98 opcode->opcode, opcode->mask, opcode->opcode);
99
100 Opcodes[curop++] = opcode->opcode;
101
102 /* count operands */
103 j = 0;
104 for (i = 0; i < 6; i++)
105 {
106 int flags = v850_operands[opcode->operands[i]].flags;
107
108 if (flags & (V850_OPERAND_REG | V850_OPERAND_SRG | V850_OPERAND_CC))
109 j++;
110 }
111 printf ("%d,{",j);
112
113 j = 0;
114 for (i = 0; i < 6; i++)
115 {
116 int flags = v850_operands[opcode->operands[i]].flags;
117 int shift = v850_operands[opcode->operands[i]].shift;
118
119 if (flags & (V850_OPERAND_REG | V850_OPERAND_SRG | V850_OPERAND_CC))
120 {
121 if (j)
122 printf (", ");
123 printf ("%d,%d,%d", shift,
124 v850_operands[opcode->operands[i]].bits,flags);
125 j = 1;
126 }
127 }
128 printf ("}},\n");
129 }
130 printf ("{ 0,0,NULL,0,{ }},\n};\n");
131 }
This page took 0.03272 seconds and 5 git commands to generate.