1 /* s390-mkopc.c -- Generates opcode table out of s390-opc.txt
2 Copyright 2000, 2001 Free Software Foundation, Inc.
3 Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
5 This file is part of GDB, GAS, and the GNU binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 /* ARCHBITS_ESA and ARCH_ESAME correspond to the bit numbers defined
27 by s390_opcode_arch_val in include/opcode/s390.h:
28 ARCHBITS_ESAONLY = (1<<S390_OPCODE_ESA)
29 ARCHBITS_ESA = (1<<S390_OPCODE_ESA) + (1<<S390_OPCODE_ESAME)
30 ARCHBITS_ESA = (1<<S390_OPCODE_ESAME). */
31 #define ARCHBITS_ESAONLY 1
32 #define ARCHBITS_ESA 3
33 #define ARCHBITS_ESAME 2
40 unsigned long long sort_value
;
44 struct op_struct
*op_array
;
52 op_array
= malloc(max_ops
*sizeof(struct op_struct
));
57 * `insertOpcode': insert an op_struct into sorted opcode array
60 insertOpcode(char *opcode
, char *mnemonic
, char *format
, int archbits
)
63 unsigned long long sort_value
;
67 while (no_ops
>= max_ops
) {
69 op_array
= realloc(op_array
, max_ops
*sizeof(struct op_struct
));
73 for (ix
= 0; ix
< 16; ix
++) {
74 if (*str
>= '0' && *str
<= '9')
75 sort_value
= (sort_value
<< 4) + (*str
- '0');
76 else if (*str
>= 'a' && *str
<= 'f')
77 sort_value
= (sort_value
<< 4) + (*str
- 'a' + 10);
78 else if (*str
>= 'A' && *str
<= 'F')
79 sort_value
= (sort_value
<< 4) + (*str
- 'A' + 10);
86 sort_value
<<= 4*(16 - ix
);
88 for (ix
= 0; ix
< no_ops
; ix
++)
89 if (sort_value
> op_array
[ix
].sort_value
)
91 for (k
= no_ops
; k
> ix
; k
--)
92 op_array
[k
] = op_array
[k
-1];
93 strcpy(op_array
[ix
].opcode
, opcode
);
94 strcpy(op_array
[ix
].mnemonic
, mnemonic
);
95 strcpy(op_array
[ix
].format
, format
);
96 op_array
[ix
].sort_value
= sort_value
;
97 op_array
[ix
].no_nibbles
= no_nibbles
;
98 op_array
[ix
].archbits
= archbits
;
104 * `dumpTable': write opcode table
112 /* Write hash table entries (slots). */
113 printf("const struct s390_opcode s390_opcodes[] = {\n");
114 for (ix
= 0; ix
< no_ops
; ix
++) {
115 printf(" { \"%s\", ", op_array
[ix
].mnemonic
);
116 for (str
= op_array
[ix
].opcode
; *str
!= 0; str
++)
119 printf("OP%i(0x%sLL), ",
120 op_array
[ix
].no_nibbles
*4, op_array
[ix
].opcode
);
121 printf("MASK_%s, INSTR_%s, ",
122 op_array
[ix
].format
, op_array
[ix
].format
);
123 printf("%i}", op_array
[ix
].archbits
);
130 printf("const int s390_num_opcodes =\n");
131 printf(" sizeof (s390_opcodes) / sizeof (s390_opcodes[0]);\n\n");
138 char currentLine
[256];
141 /* Read opcode descriptions from `stdin'. For each mnemonic,
142 * make an entry into the opcode table.
144 while (fgets(currentLine
, sizeof(currentLine
), stdin
) != NULL
) {
148 char description
[64];
152 if (currentLine
[0] == '#')
154 memset(opcode
, 0, 8);
155 if (sscanf(currentLine
, "%15s %15s %15s \"%[^\"]\" %15s",
156 opcode
, mnemonic
, format
, description
, archtag
) == 5) {
157 if (strcmp(archtag
, "esaonly") == 0)
158 archbits
= ARCHBITS_ESAONLY
;
159 else if (strcmp(archtag
, "esa") == 0)
160 archbits
= ARCHBITS_ESA
;
161 else if (strcmp(archtag
, "esame") == 0)
162 archbits
= ARCHBITS_ESAME
;
165 insertOpcode(opcode
, mnemonic
, format
, archbits
);
167 fprintf(stderr
, "Couldn't scan line %s\n", currentLine
);
This page took 0.032078 seconds and 4 git commands to generate.