1 /* Copyright 2007, 2008, 2009
2 Free Software Foundation, Inc.
4 This file is part of the GNU opcodes library.
6 This library is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 It is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
25 #include "libiberty.h"
27 #include "safe-ctype.h"
32 #define _(String) gettext (String)
34 static const char *program_name
= NULL
;
37 typedef struct initializer
43 static initializer cpu_flag_init
[] =
45 { "CPU_UNKNOWN_FLAGS",
47 { "CPU_GENERIC32_FLAGS",
48 "Cpu186|Cpu286|Cpu386" },
49 { "CPU_GENERIC64_FLAGS",
50 "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuP4|CpuMMX|CpuSSE|CpuSSE2|CpuLM" },
58 "Cpu186|Cpu286|Cpu386" },
60 "Cpu186|Cpu286|Cpu386|Cpu486" },
62 "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586" },
64 "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686" },
66 "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuMMX" },
68 "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuMMX|CpuSSE" },
70 "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuP4|CpuMMX|CpuSSE|CpuSSE2" },
72 "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuP4|CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuLM" },
74 "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuP4|CpuMMX|CpuSSE|CpuSSE2|CpuSSE3" },
76 "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuP4|CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuLM" },
78 "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|CpuK6|CpuMMX" },
80 "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|CpuK6|CpuMMX|Cpu3dnow" },
82 "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuK6|CpuMMX|Cpu3dnow|Cpu3dnowA" },
84 "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuK6|CpuK8|CpuMMX|Cpu3dnow|Cpu3dnowA|CpuSSE|CpuSSE2|CpuRdtscp|CpuLM" },
85 { "CPU_AMDFAM10_FLAGS",
86 "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuK6|CpuK8|CpuMMX|Cpu3dnow|Cpu3dnowA|CpuSSE|CpuSSE2|CpuSSE3|CpuSSE4a|CpuABM|CpuRdtscp|CpuLM" },
92 "CpuMMX|CpuSSE|CpuSSE2" },
94 "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3" },
96 "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3" },
98 "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1" },
100 "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2" },
108 "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2|CpuAES" },
109 { "CPU_PCLMUL_FLAGS",
110 "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2|CpuPCLMUL" },
112 "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2|CpuAVX|CpuFMA" },
115 { "CPU_RDTSCP_FLAGS",
121 { "CPU_3DNOWA_FLAGS",
122 "CpuMMX|Cpu3dnow|Cpu3dnowA" },
123 { "CPU_PADLOCK_FLAGS",
128 "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSE4a" },
132 "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSE4a|CpuABM|CpuSSE5"},
134 "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2|CpuAVX" },
137 static initializer operand_type_init
[] =
139 { "OPERAND_TYPE_NONE",
141 { "OPERAND_TYPE_REG8",
143 { "OPERAND_TYPE_REG16",
145 { "OPERAND_TYPE_REG32",
147 { "OPERAND_TYPE_REG64",
149 { "OPERAND_TYPE_IMM1",
151 { "OPERAND_TYPE_IMM8",
153 { "OPERAND_TYPE_IMM8S",
155 { "OPERAND_TYPE_IMM16",
157 { "OPERAND_TYPE_IMM32",
159 { "OPERAND_TYPE_IMM32S",
161 { "OPERAND_TYPE_IMM64",
163 { "OPERAND_TYPE_BASEINDEX",
165 { "OPERAND_TYPE_DISP8",
167 { "OPERAND_TYPE_DISP16",
169 { "OPERAND_TYPE_DISP32",
171 { "OPERAND_TYPE_DISP32S",
173 { "OPERAND_TYPE_DISP64",
175 { "OPERAND_TYPE_INOUTPORTREG",
177 { "OPERAND_TYPE_SHIFTCOUNT",
179 { "OPERAND_TYPE_CONTROL",
181 { "OPERAND_TYPE_TEST",
183 { "OPERAND_TYPE_DEBUG",
185 { "OPERAND_TYPE_FLOATREG",
187 { "OPERAND_TYPE_FLOATACC",
189 { "OPERAND_TYPE_SREG2",
191 { "OPERAND_TYPE_SREG3",
193 { "OPERAND_TYPE_ACC",
195 { "OPERAND_TYPE_JUMPABSOLUTE",
197 { "OPERAND_TYPE_REGMMX",
199 { "OPERAND_TYPE_REGXMM",
201 { "OPERAND_TYPE_REGYMM",
203 { "OPERAND_TYPE_ESSEG",
205 { "OPERAND_TYPE_ACC32",
207 { "OPERAND_TYPE_ACC64",
209 { "OPERAND_TYPE_INOUTPORTREG",
211 { "OPERAND_TYPE_REG16_INOUTPORTREG",
212 "Reg16|InOutPortReg" },
213 { "OPERAND_TYPE_DISP16_32",
215 { "OPERAND_TYPE_ANYDISP",
216 "Disp8|Disp16|Disp32|Disp32S|Disp64" },
217 { "OPERAND_TYPE_IMM16_32",
219 { "OPERAND_TYPE_IMM16_32S",
221 { "OPERAND_TYPE_IMM16_32_32S",
222 "Imm16|Imm32|Imm32S" },
223 { "OPERAND_TYPE_IMM32_32S_DISP32",
224 "Imm32|Imm32S|Disp32" },
225 { "OPERAND_TYPE_IMM64_DISP64",
227 { "OPERAND_TYPE_IMM32_32S_64_DISP32",
228 "Imm32|Imm32S|Imm64|Disp32" },
229 { "OPERAND_TYPE_IMM32_32S_64_DISP32_64",
230 "Imm32|Imm32S|Imm64|Disp32|Disp64" },
231 { "OPERAND_TYPE_VEX_IMM4",
235 typedef struct bitfield
242 #define BITFIELD(n) { n, 0, #n }
244 static bitfield cpu_flags
[] =
260 BITFIELD (CpuSSE4_1
),
261 BITFIELD (CpuSSE4_2
),
266 BITFIELD (Cpu3dnowA
),
267 BITFIELD (CpuPadLock
),
274 BITFIELD (CpuPCLMUL
),
279 BITFIELD (CpuRdtscp
),
283 BITFIELD (CpuUnused
),
287 static bitfield opcode_modifiers
[] =
293 BITFIELD (ShortForm
),
295 BITFIELD (JumpDword
),
297 BITFIELD (JumpInterSegment
),
304 BITFIELD (IgnoreSize
),
305 BITFIELD (DefaultSize
),
314 BITFIELD (RegKludge
),
315 BITFIELD (FirstXmm0
),
316 BITFIELD (Implicit1stXmm0
),
317 BITFIELD (ByteOkIntel
),
320 BITFIELD (AddrPrefixOp0
),
338 BITFIELD (Vex3Sources
),
339 BITFIELD (VexImmExt
),
343 BITFIELD (ATTMnemonic
),
344 BITFIELD (ATTSyntax
),
345 BITFIELD (IntelSyntax
),
348 static bitfield operand_types
[] =
365 BITFIELD (BaseIndex
),
371 BITFIELD (InOutPortReg
),
372 BITFIELD (ShiftCount
),
380 BITFIELD (JumpAbsolute
),
392 BITFIELD (Unspecified
),
401 static const char *filename
;
404 compare (const void *x
, const void *y
)
406 const bitfield
*xp
= (const bitfield
*) x
;
407 const bitfield
*yp
= (const bitfield
*) y
;
408 return xp
->position
- yp
->position
;
412 fail (const char *message
, ...)
416 va_start (args
, message
);
417 fprintf (stderr
, _("%s: Error: "), program_name
);
418 vfprintf (stderr
, message
, args
);
424 process_copyright (FILE *fp
)
426 fprintf (fp
, "/* This file is automatically generated by i386-gen. Do not edit! */\n\
427 /* Copyright 2007, 2008, 2009\n\
428 Free Software Foundation, Inc.\n\
430 This file is part of the GNU opcodes library.\n\
432 This library is free software; you can redistribute it and/or modify\n\
433 it under the terms of the GNU General Public License as published by\n\
434 the Free Software Foundation; either version 3, or (at your option)\n\
435 any later version.\n\
437 It is distributed in the hope that it will be useful, but WITHOUT\n\
438 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\n\
439 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public\n\
440 License for more details.\n\
442 You should have received a copy of the GNU General Public License\n\
443 along with this program; if not, write to the Free Software\n\
444 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,\n\
445 MA 02110-1301, USA. */\n");
448 /* Remove leading white spaces. */
451 remove_leading_whitespaces (char *str
)
453 while (ISSPACE (*str
))
458 /* Remove trailing white spaces. */
461 remove_trailing_whitespaces (char *str
)
463 size_t last
= strlen (str
);
471 if (ISSPACE (str
[last
]))
479 /* Find next field separated by SEP and terminate it. Return a
480 pointer to the one after it. */
483 next_field (char *str
, char sep
, char **next
, char *last
)
487 p
= remove_leading_whitespaces (str
);
488 for (str
= p
; *str
!= sep
&& *str
!= '\0'; str
++);
491 remove_trailing_whitespaces (p
);
502 set_bitfield (const char *f
, bitfield
*array
, unsigned int size
)
506 if (strcmp (f
, "Mmword") == 0)
508 else if (strcmp (f
, "Oword") == 0)
511 for (i
= 0; i
< size
; i
++)
512 if (strcasecmp (array
[i
].name
, f
) == 0)
518 fail (_("%s: %d: Unknown bitfield: %s\n"), filename
, lineno
, f
);
522 output_cpu_flags (FILE *table
, bitfield
*flags
, unsigned int size
,
523 int macro
, const char *comma
, const char *indent
)
527 fprintf (table
, "%s{ { ", indent
);
529 for (i
= 0; i
< size
- 1; i
++)
531 fprintf (table
, "%d, ", flags
[i
].value
);
532 if (((i
+ 1) % 20) == 0)
534 /* We need \\ for macro. */
536 fprintf (table
, " \\\n %s", indent
);
538 fprintf (table
, "\n %s", indent
);
542 fprintf (table
, "%d } }%s\n", flags
[i
].value
, comma
);
546 process_i386_cpu_flag (FILE *table
, char *flag
, int macro
,
547 const char *comma
, const char *indent
)
549 char *str
, *next
, *last
;
550 bitfield flags
[ARRAY_SIZE (cpu_flags
)];
552 /* Copy the default cpu flags. */
553 memcpy (flags
, cpu_flags
, sizeof (cpu_flags
));
555 if (strcasecmp (flag
, "unknown") == 0)
559 /* We turn on everything except for cpu64 in case of
560 CPU_UNKNOWN_FLAGS. */
561 for (i
= 0; i
< ARRAY_SIZE (flags
); i
++)
562 if (flags
[i
].position
!= Cpu64
)
565 else if (strcmp (flag
, "0"))
567 last
= flag
+ strlen (flag
);
568 for (next
= flag
; next
&& next
< last
; )
570 str
= next_field (next
, '|', &next
, last
);
572 set_bitfield (str
, flags
, ARRAY_SIZE (flags
));
576 output_cpu_flags (table
, flags
, ARRAY_SIZE (flags
), macro
,
581 output_opcode_modifier (FILE *table
, bitfield
*modifier
, unsigned int size
)
585 fprintf (table
, " { ");
587 for (i
= 0; i
< size
- 1; i
++)
589 fprintf (table
, "%d, ", modifier
[i
].value
);
590 if (((i
+ 1) % 20) == 0)
591 fprintf (table
, "\n ");
594 fprintf (table
, "%d },\n", modifier
[i
].value
);
598 process_i386_opcode_modifier (FILE *table
, char *mod
)
600 char *str
, *next
, *last
;
601 bitfield modifiers
[ARRAY_SIZE (opcode_modifiers
)];
603 /* Copy the default opcode modifier. */
604 memcpy (modifiers
, opcode_modifiers
, sizeof (modifiers
));
606 if (strcmp (mod
, "0"))
608 last
= mod
+ strlen (mod
);
609 for (next
= mod
; next
&& next
< last
; )
611 str
= next_field (next
, '|', &next
, last
);
613 set_bitfield (str
, modifiers
, ARRAY_SIZE (modifiers
));
616 output_opcode_modifier (table
, modifiers
, ARRAY_SIZE (modifiers
));
620 output_operand_type (FILE *table
, bitfield
*types
, unsigned int size
,
621 int macro
, const char *indent
)
625 fprintf (table
, "{ { ");
627 for (i
= 0; i
< size
- 1; i
++)
629 fprintf (table
, "%d, ", types
[i
].value
);
630 if (((i
+ 1) % 20) == 0)
632 /* We need \\ for macro. */
634 fprintf (table
, "\\\n%s", indent
);
636 fprintf (table
, "\n%s", indent
);
640 fprintf (table
, "%d } }", types
[i
].value
);
644 process_i386_operand_type (FILE *table
, char *op
, int macro
,
647 char *str
, *next
, *last
;
648 bitfield types
[ARRAY_SIZE (operand_types
)];
650 /* Copy the default operand type. */
651 memcpy (types
, operand_types
, sizeof (types
));
653 if (strcmp (op
, "0"))
655 last
= op
+ strlen (op
);
656 for (next
= op
; next
&& next
< last
; )
658 str
= next_field (next
, '|', &next
, last
);
660 set_bitfield (str
, types
, ARRAY_SIZE (types
));
663 output_operand_type (table
, types
, ARRAY_SIZE (types
), macro
,
668 output_i386_opcode (FILE *table
, const char *name
, char *str
,
672 char *operands
, *base_opcode
, *extension_opcode
, *opcode_length
;
673 char *cpu_flags
, *opcode_modifier
, *operand_types
[MAX_OPERANDS
];
675 /* Find number of operands. */
676 operands
= next_field (str
, ',', &str
, last
);
678 /* Find base_opcode. */
679 base_opcode
= next_field (str
, ',', &str
, last
);
681 /* Find extension_opcode. */
682 extension_opcode
= next_field (str
, ',', &str
, last
);
684 /* Find opcode_length. */
685 opcode_length
= next_field (str
, ',', &str
, last
);
687 /* Find cpu_flags. */
688 cpu_flags
= next_field (str
, ',', &str
, last
);
690 /* Find opcode_modifier. */
691 opcode_modifier
= next_field (str
, ',', &str
, last
);
693 /* Remove the first {. */
694 str
= remove_leading_whitespaces (str
);
697 str
= remove_leading_whitespaces (str
+ 1);
701 /* There are at least "X}". */
705 /* Remove trailing white spaces and }. */
709 if (ISSPACE (str
[i
]) || str
[i
] == '}')
718 /* Find operand_types. */
719 for (i
= 0; i
< ARRAY_SIZE (operand_types
); i
++)
723 operand_types
[i
] = NULL
;
727 operand_types
[i
] = next_field (str
, ',', &str
, last
);
728 if (*operand_types
[i
] == '0')
731 operand_types
[i
] = NULL
;
736 fprintf (table
, " { \"%s\", %s, %s, %s, %s,\n",
737 name
, operands
, base_opcode
, extension_opcode
,
740 process_i386_cpu_flag (table
, cpu_flags
, 0, ",", " ");
742 process_i386_opcode_modifier (table
, opcode_modifier
);
744 fprintf (table
, " { ");
746 for (i
= 0; i
< ARRAY_SIZE (operand_types
); i
++)
748 if (operand_types
[i
] == NULL
|| *operand_types
[i
] == '0')
751 process_i386_operand_type (table
, "0", 0, "\t ");
756 fprintf (table
, ",\n ");
758 process_i386_operand_type (table
, operand_types
[i
], 0,
761 fprintf (table
, " } },\n");
764 struct opcode_hash_entry
766 struct opcode_hash_entry
*next
;
771 /* Calculate the hash value of an opcode hash entry P. */
774 opcode_hash_hash (const void *p
)
776 struct opcode_hash_entry
*entry
= (struct opcode_hash_entry
*) p
;
777 return htab_hash_string (entry
->name
);
780 /* Compare a string Q against an opcode hash entry P. */
783 opcode_hash_eq (const void *p
, const void *q
)
785 struct opcode_hash_entry
*entry
= (struct opcode_hash_entry
*) p
;
786 const char *name
= (const char *) q
;
787 return strcmp (name
, entry
->name
) == 0;
791 process_i386_opcodes (FILE *table
)
796 char *str
, *p
, *last
, *name
;
797 struct opcode_hash_entry
**hash_slot
, **entry
, *next
;
798 htab_t opcode_hash_table
;
799 struct opcode_hash_entry
**opcode_array
;
800 unsigned int opcode_array_size
= 1024;
802 filename
= "i386-opc.tbl";
803 fp
= fopen (filename
, "r");
806 fail (_("can't find i386-opc.tbl for reading, errno = %s\n"),
810 opcode_array
= (struct opcode_hash_entry
**)
811 xmalloc (sizeof (*opcode_array
) * opcode_array_size
);
813 opcode_hash_table
= htab_create_alloc (16, opcode_hash_hash
,
814 opcode_hash_eq
, NULL
,
817 fprintf (table
, "\n/* i386 opcode table. */\n\n");
818 fprintf (table
, "const template i386_optab[] =\n{\n");
820 /* Put everything on opcode array. */
823 if (fgets (buf
, sizeof (buf
), fp
) == NULL
)
828 p
= remove_leading_whitespaces (buf
);
831 str
= strstr (p
, "//");
835 /* Remove trailing white spaces. */
836 remove_trailing_whitespaces (p
);
841 /* Ignore comments. */
849 last
= p
+ strlen (p
);
852 name
= next_field (p
, ',', &str
, last
);
854 /* Get the slot in hash table. */
855 hash_slot
= (struct opcode_hash_entry
**)
856 htab_find_slot_with_hash (opcode_hash_table
, name
,
857 htab_hash_string (name
),
860 if (*hash_slot
== NULL
)
862 /* It is the new one. Put it on opcode array. */
863 if (i
>= opcode_array_size
)
865 /* Grow the opcode array when needed. */
866 opcode_array_size
+= 1024;
867 opcode_array
= (struct opcode_hash_entry
**)
868 xrealloc (opcode_array
,
869 sizeof (*opcode_array
) * opcode_array_size
);
872 opcode_array
[i
] = (struct opcode_hash_entry
*)
873 xmalloc (sizeof (struct opcode_hash_entry
));
874 opcode_array
[i
]->next
= NULL
;
875 opcode_array
[i
]->name
= xstrdup (name
);
876 opcode_array
[i
]->opcode
= xstrdup (str
);
877 *hash_slot
= opcode_array
[i
];
882 /* Append it to the existing one. */
884 while ((*entry
) != NULL
)
885 entry
= &(*entry
)->next
;
886 *entry
= (struct opcode_hash_entry
*)
887 xmalloc (sizeof (struct opcode_hash_entry
));
888 (*entry
)->next
= NULL
;
889 (*entry
)->name
= (*hash_slot
)->name
;
890 (*entry
)->opcode
= xstrdup (str
);
894 /* Process opcode array. */
895 for (j
= 0; j
< i
; j
++)
897 for (next
= opcode_array
[j
]; next
; next
= next
->next
)
901 last
= str
+ strlen (str
);
902 output_i386_opcode (table
, name
, str
, last
);
908 fprintf (table
, " { NULL, 0, 0, 0, 0,\n");
910 process_i386_cpu_flag (table
, "0", 0, ",", " ");
912 process_i386_opcode_modifier (table
, "0");
914 fprintf (table
, " { ");
915 process_i386_operand_type (table
, "0", 0, "\t ");
916 fprintf (table
, " } }\n");
918 fprintf (table
, "};\n");
922 process_i386_registers (FILE *table
)
926 char *str
, *p
, *last
;
927 char *reg_name
, *reg_type
, *reg_flags
, *reg_num
;
928 char *dw2_32_num
, *dw2_64_num
;
930 filename
= "i386-reg.tbl";
931 fp
= fopen (filename
, "r");
933 fail (_("can't find i386-reg.tbl for reading, errno = %s\n"),
936 fprintf (table
, "\n/* i386 register table. */\n\n");
937 fprintf (table
, "const reg_entry i386_regtab[] =\n{\n");
941 if (fgets (buf
, sizeof (buf
), fp
) == NULL
)
946 p
= remove_leading_whitespaces (buf
);
949 str
= strstr (p
, "//");
953 /* Remove trailing white spaces. */
954 remove_trailing_whitespaces (p
);
959 fprintf (table
, "%s\n", p
);
967 last
= p
+ strlen (p
);
970 reg_name
= next_field (p
, ',', &str
, last
);
973 reg_type
= next_field (str
, ',', &str
, last
);
975 /* Find reg_flags. */
976 reg_flags
= next_field (str
, ',', &str
, last
);
979 reg_num
= next_field (str
, ',', &str
, last
);
981 fprintf (table
, " { \"%s\",\n ", reg_name
);
983 process_i386_operand_type (table
, reg_type
, 0, "\t");
985 /* Find 32-bit Dwarf2 register number. */
986 dw2_32_num
= next_field (str
, ',', &str
, last
);
988 /* Find 64-bit Dwarf2 register number. */
989 dw2_64_num
= next_field (str
, ',', &str
, last
);
991 fprintf (table
, ",\n %s, %s, { %s, %s } },\n",
992 reg_flags
, reg_num
, dw2_32_num
, dw2_64_num
);
997 fprintf (table
, "};\n");
999 fprintf (table
, "\nconst unsigned int i386_regtab_size = ARRAY_SIZE (i386_regtab);\n");
1003 process_i386_initializers (void)
1006 FILE *fp
= fopen ("i386-init.h", "w");
1010 fail (_("can't create i386-init.h, errno = %s\n"),
1013 process_copyright (fp
);
1015 for (i
= 0; i
< ARRAY_SIZE (cpu_flag_init
); i
++)
1017 fprintf (fp
, "\n#define %s \\\n", cpu_flag_init
[i
].name
);
1018 init
= xstrdup (cpu_flag_init
[i
].init
);
1019 process_i386_cpu_flag (fp
, init
, 1, "", " ");
1023 for (i
= 0; i
< ARRAY_SIZE (operand_type_init
); i
++)
1025 fprintf (fp
, "\n\n#define %s \\\n ", operand_type_init
[i
].name
);
1026 init
= xstrdup (operand_type_init
[i
].init
);
1027 process_i386_operand_type (fp
, init
, 1, " ");
1035 /* Program options. */
1036 #define OPTION_SRCDIR 200
1038 struct option long_options
[] =
1040 {"srcdir", required_argument
, NULL
, OPTION_SRCDIR
},
1041 {"debug", no_argument
, NULL
, 'd'},
1042 {"version", no_argument
, NULL
, 'V'},
1043 {"help", no_argument
, NULL
, 'h'},
1044 {0, no_argument
, NULL
, 0}
1048 print_version (void)
1050 printf ("%s: version 1.0\n", program_name
);
1055 usage (FILE * stream
, int status
)
1057 fprintf (stream
, "Usage: %s [-V | --version] [-d | --debug] [--srcdir=dirname] [--help]\n",
1063 main (int argc
, char **argv
)
1065 extern int chdir (char *);
1066 char *srcdir
= NULL
;
1070 program_name
= *argv
;
1071 xmalloc_set_program_name (program_name
);
1073 while ((c
= getopt_long (argc
, argv
, "vVdh", long_options
, 0)) != EOF
)
1098 if (chdir (srcdir
) != 0)
1099 fail (_("unable to change directory to \"%s\", errno = %s\n"),
1100 srcdir
, xstrerror (errno
));
1102 /* Check the unused bitfield in i386_cpu_flags. */
1104 c
= CpuNumOfBits
- CpuMax
- 1;
1106 fail (_("%d unused bits in i386_cpu_flags.\n"), c
);
1109 /* Check the unused bitfield in i386_operand_type. */
1111 c
= OTNumOfBits
- OTMax
- 1;
1113 fail (_("%d unused bits in i386_operand_type.\n"), c
);
1116 qsort (cpu_flags
, ARRAY_SIZE (cpu_flags
), sizeof (cpu_flags
[0]),
1119 qsort (opcode_modifiers
, ARRAY_SIZE (opcode_modifiers
),
1120 sizeof (opcode_modifiers
[0]), compare
);
1122 qsort (operand_types
, ARRAY_SIZE (operand_types
),
1123 sizeof (operand_types
[0]), compare
);
1125 table
= fopen ("i386-tbl.h", "w");
1127 fail (_("can't create i386-tbl.h, errno = %s\n"),
1130 process_copyright (table
);
1132 process_i386_opcodes (table
);
1133 process_i386_registers (table
);
1134 process_i386_initializers ();