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|CpuClflush|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|CpuClflush|CpuMMX|CpuSSE|CpuSSE2" },
72 "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuClflush|CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuLM" },
74 "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuClflush|CpuMMX|CpuSSE|CpuSSE2|CpuSSE3" },
76 "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuClflush|CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuLM" },
78 "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuClflush|CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2|CpuRdtscp|CpuLM" },
80 "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|CpuSYSCALL|CpuMMX" },
82 "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|CpuSYSCALL|CpuMMX|Cpu3dnow" },
84 "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuSYSCALL|CpuMMX|Cpu3dnow|Cpu3dnowA" },
86 "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuSYSCALL|CpuRdtscp|CpuMMX|Cpu3dnow|Cpu3dnowA|CpuSSE|CpuSSE2|CpuLM" },
87 { "CPU_AMDFAM10_FLAGS",
88 "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuSYSCALL|CpuRdtscp|CpuMMX|Cpu3dnow|Cpu3dnowA|CpuSSE|CpuSSE2|CpuSSE3|CpuSSE4a|CpuABM|CpuLM" },
89 { "CPU_CLFLUSH_FLAGS",
91 { "CPU_SYSCALL_FLAGS",
98 "CpuMMX|CpuSSE|CpuSSE2" },
100 "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3" },
102 "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3" },
103 { "CPU_SSE4_1_FLAGS",
104 "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1" },
105 { "CPU_SSE4_2_FLAGS",
106 "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2" },
114 "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2|CpuAES" },
115 { "CPU_PCLMUL_FLAGS",
116 "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2|CpuPCLMUL" },
118 "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2|CpuAVX|CpuFMA" },
121 { "CPU_RDTSCP_FLAGS",
127 { "CPU_3DNOWA_FLAGS",
128 "CpuMMX|Cpu3dnow|Cpu3dnowA" },
129 { "CPU_PADLOCK_FLAGS",
134 "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSE4a" },
138 "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2|CpuAVX" },
141 static initializer operand_type_init
[] =
143 { "OPERAND_TYPE_NONE",
145 { "OPERAND_TYPE_REG8",
147 { "OPERAND_TYPE_REG16",
149 { "OPERAND_TYPE_REG32",
151 { "OPERAND_TYPE_REG64",
153 { "OPERAND_TYPE_IMM1",
155 { "OPERAND_TYPE_IMM8",
157 { "OPERAND_TYPE_IMM8S",
159 { "OPERAND_TYPE_IMM16",
161 { "OPERAND_TYPE_IMM32",
163 { "OPERAND_TYPE_IMM32S",
165 { "OPERAND_TYPE_IMM64",
167 { "OPERAND_TYPE_BASEINDEX",
169 { "OPERAND_TYPE_DISP8",
171 { "OPERAND_TYPE_DISP16",
173 { "OPERAND_TYPE_DISP32",
175 { "OPERAND_TYPE_DISP32S",
177 { "OPERAND_TYPE_DISP64",
179 { "OPERAND_TYPE_INOUTPORTREG",
181 { "OPERAND_TYPE_SHIFTCOUNT",
183 { "OPERAND_TYPE_CONTROL",
185 { "OPERAND_TYPE_TEST",
187 { "OPERAND_TYPE_DEBUG",
189 { "OPERAND_TYPE_FLOATREG",
191 { "OPERAND_TYPE_FLOATACC",
193 { "OPERAND_TYPE_SREG2",
195 { "OPERAND_TYPE_SREG3",
197 { "OPERAND_TYPE_ACC",
199 { "OPERAND_TYPE_JUMPABSOLUTE",
201 { "OPERAND_TYPE_REGMMX",
203 { "OPERAND_TYPE_REGXMM",
205 { "OPERAND_TYPE_REGYMM",
207 { "OPERAND_TYPE_ESSEG",
209 { "OPERAND_TYPE_ACC32",
211 { "OPERAND_TYPE_ACC64",
213 { "OPERAND_TYPE_INOUTPORTREG",
215 { "OPERAND_TYPE_REG16_INOUTPORTREG",
216 "Reg16|InOutPortReg" },
217 { "OPERAND_TYPE_DISP16_32",
219 { "OPERAND_TYPE_ANYDISP",
220 "Disp8|Disp16|Disp32|Disp32S|Disp64" },
221 { "OPERAND_TYPE_IMM16_32",
223 { "OPERAND_TYPE_IMM16_32S",
225 { "OPERAND_TYPE_IMM16_32_32S",
226 "Imm16|Imm32|Imm32S" },
227 { "OPERAND_TYPE_IMM32_32S_DISP32",
228 "Imm32|Imm32S|Disp32" },
229 { "OPERAND_TYPE_IMM64_DISP64",
231 { "OPERAND_TYPE_IMM32_32S_64_DISP32",
232 "Imm32|Imm32S|Imm64|Disp32" },
233 { "OPERAND_TYPE_IMM32_32S_64_DISP32_64",
234 "Imm32|Imm32S|Imm64|Disp32|Disp64" },
237 typedef struct bitfield
244 #define BITFIELD(n) { n, 0, #n }
246 static bitfield cpu_flags
[] =
254 BITFIELD (CpuClflush
),
255 BITFIELD (CpuSYSCALL
),
261 BITFIELD (CpuSSE4_1
),
262 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
),
335 BITFIELD (Vex3Sources
),
336 BITFIELD (VexImmExt
),
340 BITFIELD (ATTMnemonic
),
341 BITFIELD (ATTSyntax
),
342 BITFIELD (IntelSyntax
),
345 static bitfield operand_types
[] =
362 BITFIELD (BaseIndex
),
368 BITFIELD (InOutPortReg
),
369 BITFIELD (ShiftCount
),
377 BITFIELD (JumpAbsolute
),
389 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, 2009\n\
423 Free Software Foundation, Inc.\n\
425 This file is part of the GNU opcodes library.\n\
427 This library is free software; you can redistribute it and/or modify\n\
428 it under the terms of the GNU General Public License as published by\n\
429 the Free Software Foundation; either version 3, or (at your option)\n\
430 any later version.\n\
432 It is distributed in the hope that it will be useful, but WITHOUT\n\
433 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\n\
434 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public\n\
435 License for more details.\n\
437 You should have received a copy of the GNU General Public License\n\
438 along with this program; if not, write to the Free Software\n\
439 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,\n\
440 MA 02110-1301, USA. */\n");
443 /* Remove leading white spaces. */
446 remove_leading_whitespaces (char *str
)
448 while (ISSPACE (*str
))
453 /* Remove trailing white spaces. */
456 remove_trailing_whitespaces (char *str
)
458 size_t last
= strlen (str
);
466 if (ISSPACE (str
[last
]))
474 /* Find next field separated by SEP and terminate it. Return a
475 pointer to the one after it. */
478 next_field (char *str
, char sep
, char **next
, char *last
)
482 p
= remove_leading_whitespaces (str
);
483 for (str
= p
; *str
!= sep
&& *str
!= '\0'; str
++);
486 remove_trailing_whitespaces (p
);
497 set_bitfield (const char *f
, bitfield
*array
, unsigned int size
, int lineno
)
501 if (strcmp (f
, "Mmword") == 0)
503 else if (strcmp (f
, "Oword") == 0)
506 for (i
= 0; i
< size
; i
++)
507 if (strcasecmp (array
[i
].name
, f
) == 0)
514 fail (_("%s: %d: Unknown bitfield: %s\n"), filename
, lineno
, f
);
516 fail (_("Unknown bitfield: %s\n"), f
);
520 output_cpu_flags (FILE *table
, bitfield
*flags
, unsigned int size
,
521 int macro
, const char *comma
, const char *indent
)
525 fprintf (table
, "%s{ { ", indent
);
527 for (i
= 0; i
< size
- 1; i
++)
529 fprintf (table
, "%d, ", flags
[i
].value
);
530 if (((i
+ 1) % 20) == 0)
532 /* We need \\ for macro. */
534 fprintf (table
, " \\\n %s", indent
);
536 fprintf (table
, "\n %s", indent
);
540 fprintf (table
, "%d } }%s\n", flags
[i
].value
, comma
);
544 process_i386_cpu_flag (FILE *table
, char *flag
, int macro
,
545 const char *comma
, const char *indent
,
548 char *str
, *next
, *last
;
549 bitfield flags
[ARRAY_SIZE (cpu_flags
)];
551 /* Copy the default cpu flags. */
552 memcpy (flags
, cpu_flags
, sizeof (cpu_flags
));
554 if (strcasecmp (flag
, "unknown") == 0)
558 /* We turn on everything except for cpu64 in case of
559 CPU_UNKNOWN_FLAGS. */
560 for (i
= 0; i
< ARRAY_SIZE (flags
); i
++)
561 if (flags
[i
].position
!= Cpu64
)
564 else if (strcmp (flag
, "0"))
566 last
= flag
+ strlen (flag
);
567 for (next
= flag
; next
&& next
< last
; )
569 str
= next_field (next
, '|', &next
, last
);
571 set_bitfield (str
, flags
, ARRAY_SIZE (flags
), lineno
);
575 output_cpu_flags (table
, flags
, ARRAY_SIZE (flags
), macro
,
580 output_opcode_modifier (FILE *table
, bitfield
*modifier
, unsigned int size
)
584 fprintf (table
, " { ");
586 for (i
= 0; i
< size
- 1; i
++)
588 fprintf (table
, "%d, ", modifier
[i
].value
);
589 if (((i
+ 1) % 20) == 0)
590 fprintf (table
, "\n ");
593 fprintf (table
, "%d },\n", modifier
[i
].value
);
597 process_i386_opcode_modifier (FILE *table
, char *mod
, int lineno
)
599 char *str
, *next
, *last
;
600 bitfield modifiers
[ARRAY_SIZE (opcode_modifiers
)];
602 /* Copy the default opcode modifier. */
603 memcpy (modifiers
, opcode_modifiers
, sizeof (modifiers
));
605 if (strcmp (mod
, "0"))
607 last
= mod
+ strlen (mod
);
608 for (next
= mod
; next
&& next
< last
; )
610 str
= next_field (next
, '|', &next
, last
);
612 set_bitfield (str
, modifiers
, ARRAY_SIZE (modifiers
), lineno
);
615 output_opcode_modifier (table
, modifiers
, ARRAY_SIZE (modifiers
));
619 output_operand_type (FILE *table
, bitfield
*types
, unsigned int size
,
620 int macro
, const char *indent
)
624 fprintf (table
, "{ { ");
626 for (i
= 0; i
< size
- 1; i
++)
628 fprintf (table
, "%d, ", types
[i
].value
);
629 if (((i
+ 1) % 20) == 0)
631 /* We need \\ for macro. */
633 fprintf (table
, "\\\n%s", indent
);
635 fprintf (table
, "\n%s", indent
);
639 fprintf (table
, "%d } }", types
[i
].value
);
643 process_i386_operand_type (FILE *table
, char *op
, int macro
,
644 const char *indent
, int lineno
)
646 char *str
, *next
, *last
;
647 bitfield types
[ARRAY_SIZE (operand_types
)];
649 /* Copy the default operand type. */
650 memcpy (types
, operand_types
, sizeof (types
));
652 if (strcmp (op
, "0"))
654 last
= op
+ strlen (op
);
655 for (next
= op
; next
&& next
< last
; )
657 str
= next_field (next
, '|', &next
, last
);
659 set_bitfield (str
, types
, ARRAY_SIZE (types
), lineno
);
662 output_operand_type (table
, types
, ARRAY_SIZE (types
), macro
,
667 output_i386_opcode (FILE *table
, const char *name
, char *str
,
668 char *last
, int lineno
)
671 char *operands
, *base_opcode
, *extension_opcode
, *opcode_length
;
672 char *cpu_flags
, *opcode_modifier
, *operand_types
[MAX_OPERANDS
];
674 /* Find number of operands. */
675 operands
= next_field (str
, ',', &str
, last
);
677 /* Find base_opcode. */
678 base_opcode
= next_field (str
, ',', &str
, last
);
680 /* Find extension_opcode. */
681 extension_opcode
= next_field (str
, ',', &str
, last
);
683 /* Find opcode_length. */
684 opcode_length
= next_field (str
, ',', &str
, last
);
686 /* Find cpu_flags. */
687 cpu_flags
= next_field (str
, ',', &str
, last
);
689 /* Find opcode_modifier. */
690 opcode_modifier
= next_field (str
, ',', &str
, last
);
692 /* Remove the first {. */
693 str
= remove_leading_whitespaces (str
);
696 str
= remove_leading_whitespaces (str
+ 1);
700 /* There are at least "X}". */
704 /* Remove trailing white spaces and }. */
708 if (ISSPACE (str
[i
]) || str
[i
] == '}')
717 /* Find operand_types. */
718 for (i
= 0; i
< ARRAY_SIZE (operand_types
); i
++)
722 operand_types
[i
] = NULL
;
726 operand_types
[i
] = next_field (str
, ',', &str
, last
);
727 if (*operand_types
[i
] == '0')
730 operand_types
[i
] = NULL
;
735 fprintf (table
, " { \"%s\", %s, %s, %s, %s,\n",
736 name
, operands
, base_opcode
, extension_opcode
,
739 process_i386_cpu_flag (table
, cpu_flags
, 0, ",", " ", lineno
);
741 process_i386_opcode_modifier (table
, opcode_modifier
, lineno
);
743 fprintf (table
, " { ");
745 for (i
= 0; i
< ARRAY_SIZE (operand_types
); i
++)
747 if (operand_types
[i
] == NULL
|| *operand_types
[i
] == '0')
750 process_i386_operand_type (table
, "0", 0, "\t ", lineno
);
755 fprintf (table
, ",\n ");
757 process_i386_operand_type (table
, operand_types
[i
], 0,
760 fprintf (table
, " } },\n");
763 struct opcode_hash_entry
765 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;
803 filename
= "i386-opc.tbl";
804 fp
= fopen (filename
, "r");
807 fail (_("can't find i386-opc.tbl for reading, errno = %s\n"),
811 opcode_array
= (struct opcode_hash_entry
**)
812 xmalloc (sizeof (*opcode_array
) * opcode_array_size
);
814 opcode_hash_table
= htab_create_alloc (16, opcode_hash_hash
,
815 opcode_hash_eq
, NULL
,
818 fprintf (table
, "\n/* i386 opcode table. */\n\n");
819 fprintf (table
, "const template i386_optab[] =\n{\n");
821 /* Put everything on opcode array. */
824 if (fgets (buf
, sizeof (buf
), fp
) == NULL
)
829 p
= remove_leading_whitespaces (buf
);
832 str
= strstr (p
, "//");
836 /* Remove trailing white spaces. */
837 remove_trailing_whitespaces (p
);
842 /* Ignore comments. */
850 last
= p
+ strlen (p
);
853 name
= next_field (p
, ',', &str
, last
);
855 /* Get the slot in hash table. */
856 hash_slot
= (struct opcode_hash_entry
**)
857 htab_find_slot_with_hash (opcode_hash_table
, name
,
858 htab_hash_string (name
),
861 if (*hash_slot
== NULL
)
863 /* It is the new one. Put it on opcode array. */
864 if (i
>= opcode_array_size
)
866 /* Grow the opcode array when needed. */
867 opcode_array_size
+= 1024;
868 opcode_array
= (struct opcode_hash_entry
**)
869 xrealloc (opcode_array
,
870 sizeof (*opcode_array
) * opcode_array_size
);
873 opcode_array
[i
] = (struct opcode_hash_entry
*)
874 xmalloc (sizeof (struct opcode_hash_entry
));
875 opcode_array
[i
]->next
= NULL
;
876 opcode_array
[i
]->name
= xstrdup (name
);
877 opcode_array
[i
]->opcode
= xstrdup (str
);
878 opcode_array
[i
]->lineno
= lineno
;
879 *hash_slot
= opcode_array
[i
];
884 /* Append it to the existing one. */
886 while ((*entry
) != NULL
)
887 entry
= &(*entry
)->next
;
888 *entry
= (struct opcode_hash_entry
*)
889 xmalloc (sizeof (struct opcode_hash_entry
));
890 (*entry
)->next
= NULL
;
891 (*entry
)->name
= (*hash_slot
)->name
;
892 (*entry
)->opcode
= xstrdup (str
);
893 (*entry
)->lineno
= lineno
;
897 /* Process opcode array. */
898 for (j
= 0; j
< i
; j
++)
900 for (next
= opcode_array
[j
]; next
; next
= next
->next
)
904 lineno
= next
->lineno
;
905 last
= str
+ strlen (str
);
906 output_i386_opcode (table
, name
, str
, last
, lineno
);
912 fprintf (table
, " { NULL, 0, 0, 0, 0,\n");
914 process_i386_cpu_flag (table
, "0", 0, ",", " ", -1);
916 process_i386_opcode_modifier (table
, "0", -1);
918 fprintf (table
, " { ");
919 process_i386_operand_type (table
, "0", 0, "\t ", -1);
920 fprintf (table
, " } }\n");
922 fprintf (table
, "};\n");
926 process_i386_registers (FILE *table
)
930 char *str
, *p
, *last
;
931 char *reg_name
, *reg_type
, *reg_flags
, *reg_num
;
932 char *dw2_32_num
, *dw2_64_num
;
935 filename
= "i386-reg.tbl";
936 fp
= fopen (filename
, "r");
938 fail (_("can't find i386-reg.tbl for reading, errno = %s\n"),
941 fprintf (table
, "\n/* i386 register table. */\n\n");
942 fprintf (table
, "const reg_entry i386_regtab[] =\n{\n");
946 if (fgets (buf
, sizeof (buf
), fp
) == NULL
)
951 p
= remove_leading_whitespaces (buf
);
954 str
= strstr (p
, "//");
958 /* Remove trailing white spaces. */
959 remove_trailing_whitespaces (p
);
964 fprintf (table
, "%s\n", p
);
972 last
= p
+ strlen (p
);
975 reg_name
= next_field (p
, ',', &str
, last
);
978 reg_type
= next_field (str
, ',', &str
, last
);
980 /* Find reg_flags. */
981 reg_flags
= next_field (str
, ',', &str
, last
);
984 reg_num
= next_field (str
, ',', &str
, last
);
986 fprintf (table
, " { \"%s\",\n ", reg_name
);
988 process_i386_operand_type (table
, reg_type
, 0, "\t", lineno
);
990 /* Find 32-bit Dwarf2 register number. */
991 dw2_32_num
= next_field (str
, ',', &str
, last
);
993 /* Find 64-bit Dwarf2 register number. */
994 dw2_64_num
= next_field (str
, ',', &str
, last
);
996 fprintf (table
, ",\n %s, %s, { %s, %s } },\n",
997 reg_flags
, reg_num
, dw2_32_num
, dw2_64_num
);
1002 fprintf (table
, "};\n");
1004 fprintf (table
, "\nconst unsigned int i386_regtab_size = ARRAY_SIZE (i386_regtab);\n");
1008 process_i386_initializers (void)
1011 FILE *fp
= fopen ("i386-init.h", "w");
1015 fail (_("can't create i386-init.h, errno = %s\n"),
1018 process_copyright (fp
);
1020 for (i
= 0; i
< ARRAY_SIZE (cpu_flag_init
); i
++)
1022 fprintf (fp
, "\n#define %s \\\n", cpu_flag_init
[i
].name
);
1023 init
= xstrdup (cpu_flag_init
[i
].init
);
1024 process_i386_cpu_flag (fp
, init
, 1, "", " ", -1);
1028 for (i
= 0; i
< ARRAY_SIZE (operand_type_init
); i
++)
1030 fprintf (fp
, "\n\n#define %s \\\n ", operand_type_init
[i
].name
);
1031 init
= xstrdup (operand_type_init
[i
].init
);
1032 process_i386_operand_type (fp
, init
, 1, " ", -1);
1040 /* Program options. */
1041 #define OPTION_SRCDIR 200
1043 struct option long_options
[] =
1045 {"srcdir", required_argument
, NULL
, OPTION_SRCDIR
},
1046 {"debug", no_argument
, NULL
, 'd'},
1047 {"version", no_argument
, NULL
, 'V'},
1048 {"help", no_argument
, NULL
, 'h'},
1049 {0, no_argument
, NULL
, 0}
1053 print_version (void)
1055 printf ("%s: version 1.0\n", program_name
);
1060 usage (FILE * stream
, int status
)
1062 fprintf (stream
, "Usage: %s [-V | --version] [-d | --debug] [--srcdir=dirname] [--help]\n",
1068 main (int argc
, char **argv
)
1070 extern int chdir (char *);
1071 char *srcdir
= NULL
;
1075 program_name
= *argv
;
1076 xmalloc_set_program_name (program_name
);
1078 while ((c
= getopt_long (argc
, argv
, "vVdh", long_options
, 0)) != EOF
)
1103 if (chdir (srcdir
) != 0)
1104 fail (_("unable to change directory to \"%s\", errno = %s\n"),
1105 srcdir
, xstrerror (errno
));
1107 /* Check the unused bitfield in i386_cpu_flags. */
1109 c
= CpuNumOfBits
- CpuMax
- 1;
1111 fail (_("%d unused bits in i386_cpu_flags.\n"), c
);
1114 /* Check the unused bitfield in i386_operand_type. */
1116 c
= OTNumOfBits
- OTMax
- 1;
1118 fail (_("%d unused bits in i386_operand_type.\n"), c
);
1121 qsort (cpu_flags
, ARRAY_SIZE (cpu_flags
), sizeof (cpu_flags
[0]),
1124 qsort (opcode_modifiers
, ARRAY_SIZE (opcode_modifiers
),
1125 sizeof (opcode_modifiers
[0]), compare
);
1127 qsort (operand_types
, ARRAY_SIZE (operand_types
),
1128 sizeof (operand_types
[0]), compare
);
1130 table
= fopen ("i386-tbl.h", "w");
1132 fail (_("can't create i386-tbl.h, errno = %s\n"),
1135 process_copyright (table
);
1137 process_i386_opcodes (table
);
1138 process_i386_registers (table
);
1139 process_i386_initializers ();