Commit | Line | Data |
---|---|---|
22c1c7dd JL |
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 | ||
9fca2fd3 JL |
7 | long Opcodes[512]; |
8 | static int curop=0; | |
9 | ||
22c1c7dd JL |
10 | int |
11 | main (argc, argv) | |
12 | int argc; | |
13 | char *argv[]; | |
14 | { | |
9fca2fd3 | 15 | if ((argc > 1) && (strcmp (argv[1], "-h") == 0)) |
22c1c7dd | 16 | write_header(); |
9fca2fd3 | 17 | else if ((argc > 1) && (strcmp (argv[1], "-t") == 0)) |
22c1c7dd JL |
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++) | |
9fca2fd3 JL |
31 | printf("void OP_%X PARAMS ((void));\t\t/* %s */\n", |
32 | opcode->opcode, opcode->name); | |
22c1c7dd JL |
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 | { | |
9fca2fd3 | 50 | printf("/* %s */\nvoid\nOP_%X ()\n{\n", opcode->name, opcode->opcode); |
22c1c7dd JL |
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: | |
9fca2fd3 | 64 | printf ("printf(\" %s\\n\");\n", opcode->name); |
22c1c7dd JL |
65 | break; |
66 | case 1: | |
9fca2fd3 | 67 | printf ("printf(\" %s\\t%%x\\n\", OP[0]);\n", opcode->name); |
22c1c7dd JL |
68 | break; |
69 | case 2: | |
9fca2fd3 JL |
70 | printf ("printf(\" %s\\t%%x,%%x\\n\",OP[0],OP[1]);\n", |
71 | opcode->name); | |
22c1c7dd JL |
72 | break; |
73 | case 3: | |
9fca2fd3 JL |
74 | printf ("printf(\" %s\\t%%x,%%x,%%x\\n\",OP[0],OP[1],OP[2]);\n", |
75 | opcode->name); | |
22c1c7dd JL |
76 | break; |
77 | default: | |
9fca2fd3 | 78 | fprintf (stderr,"Too many operands: %d\n", j); |
22c1c7dd JL |
79 | } |
80 | printf ("}\n\n"); | |
81 | } | |
82 | } | |
83 | ||
22c1c7dd JL |
84 | static void |
85 | write_opcodes () | |
86 | { | |
87 | struct v850_opcode *opcode; | |
88 | int i, j; | |
96851909 | 89 | int numops; |
22c1c7dd JL |
90 | |
91 | /* write out opcode table */ | |
92 | printf ("#include \"v850_sim.h\"\n"); | |
93 | printf ("#include \"simops.h\"\n\n"); | |
94 | printf ("struct simops Simops[] = {\n"); | |
95 | ||
96 | for (opcode = (struct v850_opcode *)v850_opcodes; opcode->name; opcode++) | |
97 | { | |
88777ce2 | 98 | printf (" { 0x%x,0x%x,OP_%X,", |
22c1c7dd JL |
99 | opcode->opcode, opcode->mask, opcode->opcode); |
100 | ||
22c1c7dd JL |
101 | Opcodes[curop++] = opcode->opcode; |
102 | ||
103 | /* count operands */ | |
104 | j = 0; | |
105 | for (i = 0; i < 6; i++) | |
106 | { | |
107 | int flags = v850_operands[opcode->operands[i]].flags; | |
108 | ||
109 | if (flags & (V850_OPERAND_REG | V850_OPERAND_SRG | V850_OPERAND_CC)) | |
110 | j++; | |
111 | } | |
112 | printf ("%d,{",j); | |
113 | ||
114 | j = 0; | |
96851909 | 115 | numops = 0; |
22c1c7dd JL |
116 | for (i = 0; i < 6; i++) |
117 | { | |
118 | int flags = v850_operands[opcode->operands[i]].flags; | |
119 | int shift = v850_operands[opcode->operands[i]].shift; | |
120 | ||
121 | if (flags & (V850_OPERAND_REG | V850_OPERAND_SRG | V850_OPERAND_CC)) | |
122 | { | |
123 | if (j) | |
124 | printf (", "); | |
9fca2fd3 JL |
125 | printf ("%d,%d,%d", shift, |
126 | v850_operands[opcode->operands[i]].bits,flags); | |
22c1c7dd | 127 | j = 1; |
96851909 | 128 | numops++; |
22c1c7dd JL |
129 | } |
130 | } | |
96851909 SG |
131 | |
132 | switch (numops) | |
133 | { | |
134 | case 0: | |
135 | printf ("0,0,0"); | |
136 | case 1: | |
137 | printf (",0,0,0"); | |
138 | } | |
139 | ||
22c1c7dd JL |
140 | printf ("}},\n"); |
141 | } | |
96851909 | 142 | printf ("{ 0,0,NULL,0,{0,0,0,0,0,0}},\n};\n"); |
22c1c7dd | 143 | } |