1 /* Copyright 2007, 2008 Free Software Foundation, Inc.
3 This file is part of the GNU opcodes library.
5 This library is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3, or (at your option)
10 It is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
13 License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
18 MA 02110-1301, USA. */
24 #include "libiberty.h"
26 #include "safe-ctype.h"
31 #define _(String) gettext (String)
33 static const char *program_name
= NULL
;
36 typedef struct initializer
42 static initializer cpu_flag_init
[] =
44 { "CPU_UNKNOWN_FLAGS",
46 { "CPU_GENERIC32_FLAGS",
47 "Cpu186|Cpu286|Cpu386" },
48 { "CPU_GENERIC64_FLAGS",
49 "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuP4|CpuMMX|CpuSSE|CpuSSE2|CpuLM" },
57 "Cpu186|Cpu286|Cpu386" },
59 "Cpu186|Cpu286|Cpu386|Cpu486" },
61 "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586" },
63 "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686" },
65 "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuMMX" },
67 "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuMMX|CpuSSE" },
69 "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuP4|CpuMMX|CpuSSE|CpuSSE2" },
71 "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuP4|CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuLM" },
73 "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuP4|CpuMMX|CpuSSE|CpuSSE2|CpuSSE3" },
75 "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuP4|CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuLM" },
77 "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|CpuK6|CpuMMX" },
79 "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|CpuK6|CpuMMX|Cpu3dnow" },
81 "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuK6|CpuMMX|Cpu3dnow|Cpu3dnowA" },
83 "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuK6|CpuK8|CpuMMX|Cpu3dnow|Cpu3dnowA|CpuSSE|CpuSSE2|CpuLM" },
84 { "CPU_AMDFAM10_FLAGS",
85 "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuK6|CpuK8|CpuMMX|Cpu3dnow|Cpu3dnowA|CpuSSE|CpuSSE2|CpuSSE3|CpuSSE4a|CpuABM|CpuLM" },
91 "CpuMMX|CpuSSE|CpuSSE2" },
93 "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3" },
95 "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3" },
97 "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1" },
99 "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2" },
107 "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2|CpuAES" },
108 { "CPU_PCLMUL_FLAGS",
109 "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2|CpuPCLMUL" },
111 "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2|CpuAVX|CpuFMA" },
118 { "CPU_3DNOWA_FLAGS",
119 "CpuMMX|Cpu3dnow|Cpu3dnowA" },
120 { "CPU_PADLOCK_FLAGS",
125 "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSE4a" },
129 "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSE4a|CpuABM|CpuSSE5"},
131 "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2|CpuAVX" },
134 static initializer operand_type_init
[] =
136 { "OPERAND_TYPE_NONE",
138 { "OPERAND_TYPE_REG8",
140 { "OPERAND_TYPE_REG16",
142 { "OPERAND_TYPE_REG32",
144 { "OPERAND_TYPE_REG64",
146 { "OPERAND_TYPE_IMM1",
148 { "OPERAND_TYPE_IMM8",
150 { "OPERAND_TYPE_IMM8S",
152 { "OPERAND_TYPE_IMM16",
154 { "OPERAND_TYPE_IMM32",
156 { "OPERAND_TYPE_IMM32S",
158 { "OPERAND_TYPE_IMM64",
160 { "OPERAND_TYPE_BASEINDEX",
162 { "OPERAND_TYPE_DISP8",
164 { "OPERAND_TYPE_DISP16",
166 { "OPERAND_TYPE_DISP32",
168 { "OPERAND_TYPE_DISP32S",
170 { "OPERAND_TYPE_DISP64",
172 { "OPERAND_TYPE_INOUTPORTREG",
174 { "OPERAND_TYPE_SHIFTCOUNT",
176 { "OPERAND_TYPE_CONTROL",
178 { "OPERAND_TYPE_TEST",
180 { "OPERAND_TYPE_DEBUG",
182 { "OPERAND_TYPE_FLOATREG",
184 { "OPERAND_TYPE_FLOATACC",
186 { "OPERAND_TYPE_SREG2",
188 { "OPERAND_TYPE_SREG3",
190 { "OPERAND_TYPE_ACC",
192 { "OPERAND_TYPE_JUMPABSOLUTE",
194 { "OPERAND_TYPE_REGMMX",
196 { "OPERAND_TYPE_REGXMM",
198 { "OPERAND_TYPE_REGYMM",
200 { "OPERAND_TYPE_ESSEG",
202 { "OPERAND_TYPE_ACC32",
204 { "OPERAND_TYPE_ACC64",
206 { "OPERAND_TYPE_INOUTPORTREG",
208 { "OPERAND_TYPE_REG16_INOUTPORTREG",
209 "Reg16|InOutPortReg" },
210 { "OPERAND_TYPE_DISP16_32",
212 { "OPERAND_TYPE_ANYDISP",
213 "Disp8|Disp16|Disp32|Disp32S|Disp64" },
214 { "OPERAND_TYPE_IMM16_32",
216 { "OPERAND_TYPE_IMM16_32S",
218 { "OPERAND_TYPE_IMM16_32_32S",
219 "Imm16|Imm32|Imm32S" },
220 { "OPERAND_TYPE_IMM32_32S_DISP32",
221 "Imm32|Imm32S|Disp32" },
222 { "OPERAND_TYPE_IMM64_DISP64",
224 { "OPERAND_TYPE_IMM32_32S_64_DISP32",
225 "Imm32|Imm32S|Imm64|Disp32" },
226 { "OPERAND_TYPE_IMM32_32S_64_DISP32_64",
227 "Imm32|Imm32S|Imm64|Disp32|Disp64" },
228 { "OPERAND_TYPE_VEX_IMM4",
232 typedef struct bitfield
239 #define BITFIELD(n) { n, 0, #n }
241 static bitfield cpu_flags
[] =
257 BITFIELD (CpuSSE4_1
),
258 BITFIELD (CpuSSE4_2
),
263 BITFIELD (Cpu3dnowA
),
264 BITFIELD (CpuPadLock
),
271 BITFIELD (CpuPCLMUL
),
279 BITFIELD (CpuUnused
),
283 static bitfield opcode_modifiers
[] =
288 BITFIELD (ShortForm
),
290 BITFIELD (JumpDword
),
292 BITFIELD (JumpInterSegment
),
299 BITFIELD (IgnoreSize
),
300 BITFIELD (DefaultSize
),
309 BITFIELD (RegKludge
),
310 BITFIELD (FirstXmm0
),
311 BITFIELD (Implicit1stXmm0
),
312 BITFIELD (ByteOkIntel
),
315 BITFIELD (AddrPrefixOp0
),
333 BITFIELD (Vex3Sources
),
334 BITFIELD (VexImmExt
),
338 BITFIELD (ATTMnemonic
),
339 BITFIELD (ATTSyntax
),
340 BITFIELD (IntelSyntax
),
343 static bitfield operand_types
[] =
360 BITFIELD (BaseIndex
),
366 BITFIELD (InOutPortReg
),
367 BITFIELD (ShiftCount
),
375 BITFIELD (JumpAbsolute
),
387 BITFIELD (Unspecified
),
396 static const char *filename
;
399 compare (const void *x
, const void *y
)
401 const bitfield
*xp
= (const bitfield
*) x
;
402 const bitfield
*yp
= (const bitfield
*) y
;
403 return xp
->position
- yp
->position
;
407 fail (const char *message
, ...)
411 va_start (args
, message
);
412 fprintf (stderr
, _("%s: Error: "), program_name
);
413 vfprintf (stderr
, message
, args
);
419 process_copyright (FILE *fp
)
421 fprintf (fp
, "/* This file is automatically generated by i386-gen. Do not edit! */\n\
422 /* Copyright 2007, 2008 Free Software Foundation, Inc.\n\
424 This file is part of the GNU opcodes library.\n\
426 This library is free software; you can redistribute it and/or modify\n\
427 it under the terms of the GNU General Public License as published by\n\
428 the Free Software Foundation; either version 3, or (at your option)\n\
429 any later version.\n\
431 It is distributed in the hope that it will be useful, but WITHOUT\n\
432 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\n\
433 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public\n\
434 License for more details.\n\
436 You should have received a copy of the GNU General Public License\n\
437 along with this program; if not, write to the Free Software\n\
438 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,\n\
439 MA 02110-1301, USA. */\n");
442 /* Remove leading white spaces. */
445 remove_leading_whitespaces (char *str
)
447 while (ISSPACE (*str
))
452 /* Remove trailing white spaces. */
455 remove_trailing_whitespaces (char *str
)
457 size_t last
= strlen (str
);
465 if (ISSPACE (str
[last
]))
473 /* Find next field separated by SEP and terminate it. Return a
474 pointer to the one after it. */
477 next_field (char *str
, char sep
, char **next
, char *last
)
481 p
= remove_leading_whitespaces (str
);
482 for (str
= p
; *str
!= sep
&& *str
!= '\0'; str
++);
485 remove_trailing_whitespaces (p
);
496 set_bitfield (const char *f
, bitfield
*array
, unsigned int size
)
500 if (strcmp (f
, "CpuSledgehammer") == 0)
502 else if (strcmp (f
, "Mmword") == 0)
504 else if (strcmp (f
, "Oword") == 0)
507 for (i
= 0; i
< size
; i
++)
508 if (strcasecmp (array
[i
].name
, f
) == 0)
514 fail (_("%s: %d: Unknown bitfield: %s\n"), filename
, lineno
, f
);
518 output_cpu_flags (FILE *table
, bitfield
*flags
, unsigned int size
,
519 int macro
, const char *comma
, const char *indent
)
523 fprintf (table
, "%s{ { ", indent
);
525 for (i
= 0; i
< size
- 1; i
++)
527 fprintf (table
, "%d, ", flags
[i
].value
);
528 if (((i
+ 1) % 20) == 0)
530 /* We need \\ for macro. */
532 fprintf (table
, " \\\n %s", indent
);
534 fprintf (table
, "\n %s", indent
);
538 fprintf (table
, "%d } }%s\n", flags
[i
].value
, comma
);
542 process_i386_cpu_flag (FILE *table
, char *flag
, int macro
,
543 const char *comma
, const char *indent
)
545 char *str
, *next
, *last
;
546 bitfield flags
[ARRAY_SIZE (cpu_flags
)];
548 /* Copy the default cpu flags. */
549 memcpy (flags
, cpu_flags
, sizeof (cpu_flags
));
551 if (strcasecmp (flag
, "unknown") == 0)
555 /* We turn on everything except for cpu64 in case of
556 CPU_UNKNOWN_FLAGS. */
557 for (i
= 0; i
< ARRAY_SIZE (flags
); i
++)
558 if (flags
[i
].position
!= Cpu64
)
561 else if (strcmp (flag
, "0"))
563 last
= flag
+ strlen (flag
);
564 for (next
= flag
; next
&& next
< last
; )
566 str
= next_field (next
, '|', &next
, last
);
568 set_bitfield (str
, flags
, ARRAY_SIZE (flags
));
572 output_cpu_flags (table
, flags
, ARRAY_SIZE (flags
), macro
,
577 output_opcode_modifier (FILE *table
, bitfield
*modifier
, unsigned int size
)
581 fprintf (table
, " { ");
583 for (i
= 0; i
< size
- 1; i
++)
585 fprintf (table
, "%d, ", modifier
[i
].value
);
586 if (((i
+ 1) % 20) == 0)
587 fprintf (table
, "\n ");
590 fprintf (table
, "%d },\n", modifier
[i
].value
);
594 process_i386_opcode_modifier (FILE *table
, char *mod
)
596 char *str
, *next
, *last
;
597 bitfield modifiers
[ARRAY_SIZE (opcode_modifiers
)];
599 /* Copy the default opcode modifier. */
600 memcpy (modifiers
, opcode_modifiers
, sizeof (modifiers
));
602 if (strcmp (mod
, "0"))
604 last
= mod
+ strlen (mod
);
605 for (next
= mod
; next
&& next
< last
; )
607 str
= next_field (next
, '|', &next
, last
);
609 set_bitfield (str
, modifiers
, ARRAY_SIZE (modifiers
));
612 output_opcode_modifier (table
, modifiers
, ARRAY_SIZE (modifiers
));
616 output_operand_type (FILE *table
, bitfield
*types
, unsigned int size
,
617 int macro
, const char *indent
)
621 fprintf (table
, "{ { ");
623 for (i
= 0; i
< size
- 1; i
++)
625 fprintf (table
, "%d, ", types
[i
].value
);
626 if (((i
+ 1) % 20) == 0)
628 /* We need \\ for macro. */
630 fprintf (table
, "\\\n%s", indent
);
632 fprintf (table
, "\n%s", indent
);
636 fprintf (table
, "%d } }", types
[i
].value
);
640 process_i386_operand_type (FILE *table
, char *op
, int macro
,
643 char *str
, *next
, *last
;
644 bitfield types
[ARRAY_SIZE (operand_types
)];
646 /* Copy the default operand type. */
647 memcpy (types
, operand_types
, sizeof (types
));
649 if (strcmp (op
, "0"))
651 last
= op
+ strlen (op
);
652 for (next
= op
; next
&& next
< last
; )
654 str
= next_field (next
, '|', &next
, last
);
656 set_bitfield (str
, types
, ARRAY_SIZE (types
));
659 output_operand_type (table
, types
, ARRAY_SIZE (types
), macro
,
664 output_i386_opcode (FILE *table
, const char *name
, char *str
,
668 char *operands
, *base_opcode
, *extension_opcode
, *opcode_length
;
669 char *cpu_flags
, *opcode_modifier
, *operand_types
[MAX_OPERANDS
];
671 /* Find number of operands. */
672 operands
= next_field (str
, ',', &str
, last
);
674 /* Find base_opcode. */
675 base_opcode
= next_field (str
, ',', &str
, last
);
677 /* Find extension_opcode. */
678 extension_opcode
= next_field (str
, ',', &str
, last
);
680 /* Find opcode_length. */
681 opcode_length
= next_field (str
, ',', &str
, last
);
683 /* Find cpu_flags. */
684 cpu_flags
= next_field (str
, ',', &str
, last
);
686 /* Find opcode_modifier. */
687 opcode_modifier
= next_field (str
, ',', &str
, last
);
689 /* Remove the first {. */
690 str
= remove_leading_whitespaces (str
);
693 str
= remove_leading_whitespaces (str
+ 1);
697 /* There are at least "X}". */
701 /* Remove trailing white spaces and }. */
705 if (ISSPACE (str
[i
]) || str
[i
] == '}')
714 /* Find operand_types. */
715 for (i
= 0; i
< ARRAY_SIZE (operand_types
); i
++)
719 operand_types
[i
] = NULL
;
723 operand_types
[i
] = next_field (str
, ',', &str
, last
);
724 if (*operand_types
[i
] == '0')
727 operand_types
[i
] = NULL
;
732 fprintf (table
, " { \"%s\", %s, %s, %s, %s,\n",
733 name
, operands
, base_opcode
, extension_opcode
,
736 process_i386_cpu_flag (table
, cpu_flags
, 0, ",", " ");
738 process_i386_opcode_modifier (table
, opcode_modifier
);
740 fprintf (table
, " { ");
742 for (i
= 0; i
< ARRAY_SIZE (operand_types
); i
++)
744 if (operand_types
[i
] == NULL
|| *operand_types
[i
] == '0')
747 process_i386_operand_type (table
, "0", 0, "\t ");
752 fprintf (table
, ",\n ");
754 process_i386_operand_type (table
, operand_types
[i
], 0,
757 fprintf (table
, " } },\n");
760 struct opcode_hash_entry
762 struct opcode_hash_entry
*next
;
767 /* Calculate the hash value of an opcode hash entry P. */
770 opcode_hash_hash (const void *p
)
772 struct opcode_hash_entry
*entry
= (struct opcode_hash_entry
*) p
;
773 return htab_hash_string (entry
->name
);
776 /* Compare a string Q against an opcode hash entry P. */
779 opcode_hash_eq (const void *p
, const void *q
)
781 struct opcode_hash_entry
*entry
= (struct opcode_hash_entry
*) p
;
782 const char *name
= (const char *) q
;
783 return strcmp (name
, entry
->name
) == 0;
787 process_i386_opcodes (FILE *table
)
792 char *str
, *p
, *last
, *name
;
793 struct opcode_hash_entry
**hash_slot
, **entry
, *next
;
794 htab_t opcode_hash_table
;
795 struct opcode_hash_entry
**opcode_array
;
796 unsigned int opcode_array_size
= 1024;
798 filename
= "i386-opc.tbl";
799 fp
= fopen (filename
, "r");
802 fail (_("can't find i386-opc.tbl for reading, errno = %s\n"),
806 opcode_array
= (struct opcode_hash_entry
**)
807 xmalloc (sizeof (*opcode_array
) * opcode_array_size
);
809 opcode_hash_table
= htab_create_alloc (16, opcode_hash_hash
,
810 opcode_hash_eq
, NULL
,
813 fprintf (table
, "\n/* i386 opcode table. */\n\n");
814 fprintf (table
, "const template i386_optab[] =\n{\n");
816 /* Put everything on opcode array. */
819 if (fgets (buf
, sizeof (buf
), fp
) == NULL
)
824 p
= remove_leading_whitespaces (buf
);
827 str
= strstr (p
, "//");
831 /* Remove trailing white spaces. */
832 remove_trailing_whitespaces (p
);
837 /* Ignore comments. */
845 last
= p
+ strlen (p
);
848 name
= next_field (p
, ',', &str
, last
);
850 /* Get the slot in hash table. */
851 hash_slot
= (struct opcode_hash_entry
**)
852 htab_find_slot_with_hash (opcode_hash_table
, name
,
853 htab_hash_string (name
),
856 if (*hash_slot
== NULL
)
858 /* It is the new one. Put it on opcode array. */
859 if (i
>= opcode_array_size
)
861 /* Grow the opcode array when needed. */
862 opcode_array_size
+= 1024;
863 opcode_array
= (struct opcode_hash_entry
**)
864 xrealloc (opcode_array
,
865 sizeof (*opcode_array
) * opcode_array_size
);
868 opcode_array
[i
] = (struct opcode_hash_entry
*)
869 xmalloc (sizeof (struct opcode_hash_entry
));
870 opcode_array
[i
]->next
= NULL
;
871 opcode_array
[i
]->name
= xstrdup (name
);
872 opcode_array
[i
]->opcode
= xstrdup (str
);
873 *hash_slot
= opcode_array
[i
];
878 /* Append it to the existing one. */
880 while ((*entry
) != NULL
)
881 entry
= &(*entry
)->next
;
882 *entry
= (struct opcode_hash_entry
*)
883 xmalloc (sizeof (struct opcode_hash_entry
));
884 (*entry
)->next
= NULL
;
885 (*entry
)->name
= (*hash_slot
)->name
;
886 (*entry
)->opcode
= xstrdup (str
);
890 /* Process opcode array. */
891 for (j
= 0; j
< i
; j
++)
893 for (next
= opcode_array
[j
]; next
; next
= next
->next
)
897 last
= str
+ strlen (str
);
898 output_i386_opcode (table
, name
, str
, last
);
904 fprintf (table
, " { NULL, 0, 0, 0, 0,\n");
906 process_i386_cpu_flag (table
, "0", 0, ",", " ");
908 process_i386_opcode_modifier (table
, "0");
910 fprintf (table
, " { ");
911 process_i386_operand_type (table
, "0", 0, "\t ");
912 fprintf (table
, " } }\n");
914 fprintf (table
, "};\n");
918 process_i386_registers (FILE *table
)
922 char *str
, *p
, *last
;
923 char *reg_name
, *reg_type
, *reg_flags
, *reg_num
;
924 char *dw2_32_num
, *dw2_64_num
;
926 filename
= "i386-reg.tbl";
927 fp
= fopen (filename
, "r");
929 fail (_("can't find i386-reg.tbl for reading, errno = %s\n"),
932 fprintf (table
, "\n/* i386 register table. */\n\n");
933 fprintf (table
, "const reg_entry i386_regtab[] =\n{\n");
937 if (fgets (buf
, sizeof (buf
), fp
) == NULL
)
942 p
= remove_leading_whitespaces (buf
);
945 str
= strstr (p
, "//");
949 /* Remove trailing white spaces. */
950 remove_trailing_whitespaces (p
);
955 fprintf (table
, "%s\n", p
);
963 last
= p
+ strlen (p
);
966 reg_name
= next_field (p
, ',', &str
, last
);
969 reg_type
= next_field (str
, ',', &str
, last
);
971 /* Find reg_flags. */
972 reg_flags
= next_field (str
, ',', &str
, last
);
975 reg_num
= next_field (str
, ',', &str
, last
);
977 fprintf (table
, " { \"%s\",\n ", reg_name
);
979 process_i386_operand_type (table
, reg_type
, 0, "\t");
981 /* Find 32-bit Dwarf2 register number. */
982 dw2_32_num
= next_field (str
, ',', &str
, last
);
984 /* Find 64-bit Dwarf2 register number. */
985 dw2_64_num
= next_field (str
, ',', &str
, last
);
987 fprintf (table
, ",\n %s, %s, { %s, %s } },\n",
988 reg_flags
, reg_num
, dw2_32_num
, dw2_64_num
);
993 fprintf (table
, "};\n");
995 fprintf (table
, "\nconst unsigned int i386_regtab_size = ARRAY_SIZE (i386_regtab);\n");
999 process_i386_initializers (void)
1002 FILE *fp
= fopen ("i386-init.h", "w");
1006 fail (_("can't create i386-init.h, errno = %s\n"),
1009 process_copyright (fp
);
1011 for (i
= 0; i
< ARRAY_SIZE (cpu_flag_init
); i
++)
1013 fprintf (fp
, "\n#define %s \\\n", cpu_flag_init
[i
].name
);
1014 init
= xstrdup (cpu_flag_init
[i
].init
);
1015 process_i386_cpu_flag (fp
, init
, 1, "", " ");
1019 for (i
= 0; i
< ARRAY_SIZE (operand_type_init
); i
++)
1021 fprintf (fp
, "\n\n#define %s \\\n ", operand_type_init
[i
].name
);
1022 init
= xstrdup (operand_type_init
[i
].init
);
1023 process_i386_operand_type (fp
, init
, 1, " ");
1031 /* Program options. */
1032 #define OPTION_SRCDIR 200
1034 struct option long_options
[] =
1036 {"srcdir", required_argument
, NULL
, OPTION_SRCDIR
},
1037 {"debug", no_argument
, NULL
, 'd'},
1038 {"version", no_argument
, NULL
, 'V'},
1039 {"help", no_argument
, NULL
, 'h'},
1040 {0, no_argument
, NULL
, 0}
1044 print_version (void)
1046 printf ("%s: version 1.0\n", program_name
);
1051 usage (FILE * stream
, int status
)
1053 fprintf (stream
, "Usage: %s [-V | --version] [-d | --debug] [--srcdir=dirname] [--help]\n",
1059 main (int argc
, char **argv
)
1061 extern int chdir (char *);
1062 char *srcdir
= NULL
;
1066 program_name
= *argv
;
1067 xmalloc_set_program_name (program_name
);
1069 while ((c
= getopt_long (argc
, argv
, "vVdh", long_options
, 0)) != EOF
)
1094 if (chdir (srcdir
) != 0)
1095 fail (_("unable to change directory to \"%s\", errno = %s\n"),
1096 srcdir
, xstrerror (errno
));
1098 /* Check the unused bitfield in i386_cpu_flags. */
1100 c
= CpuNumOfBits
- CpuMax
- 1;
1102 fail (_("%d unused bits in i386_cpu_flags.\n"), c
);
1105 /* Check the unused bitfield in i386_operand_type. */
1107 c
= OTNumOfBits
- OTMax
- 1;
1109 fail (_("%d unused bits in i386_operand_type.\n"), c
);
1112 qsort (cpu_flags
, ARRAY_SIZE (cpu_flags
), sizeof (cpu_flags
[0]),
1115 qsort (opcode_modifiers
, ARRAY_SIZE (opcode_modifiers
),
1116 sizeof (opcode_modifiers
[0]), compare
);
1118 qsort (operand_types
, ARRAY_SIZE (operand_types
),
1119 sizeof (operand_types
[0]), compare
);
1121 table
= fopen ("i386-tbl.h", "w");
1123 fail (_("can't create i386-tbl.h, errno = %s\n"),
1126 process_copyright (table
);
1128 process_i386_opcodes (table
);
1129 process_i386_registers (table
);
1130 process_i386_initializers ();