diff options
author | Nick Clifton <nickc@redhat.com> | 2002-11-07 14:33:48 +0000 |
---|---|---|
committer | Nick Clifton <nickc@redhat.com> | 2002-11-07 14:33:48 +0000 |
commit | bde78a07b9f30f173df10eb779ce51284ee275c9 (patch) | |
tree | 1c50e89103d5d9344e64d08ff8227070bd072057 /opcodes/ia64-gen.c | |
parent | 415fe8c69be661835aded120948cc502566b5f29 (diff) | |
download | gdb-bde78a07b9f30f173df10eb779ce51284ee275c9.zip gdb-bde78a07b9f30f173df10eb779ce51284ee275c9.tar.gz gdb-bde78a07b9f30f173df10eb779ce51284ee275c9.tar.bz2 |
Convert ia64-gen to use getopt(). Add standard GNU options plus --srcdir.
Convert Makefile.am to pass --srcdir to ia64-gen. Fix compile time warnings.
Diffstat (limited to 'opcodes/ia64-gen.c')
-rw-r--r-- | opcodes/ia64-gen.c | 1206 |
1 files changed, 607 insertions, 599 deletions
diff --git a/opcodes/ia64-gen.c b/opcodes/ia64-gen.c index 6443c7c..f6bfda0 100644 --- a/opcodes/ia64-gen.c +++ b/opcodes/ia64-gen.c @@ -1,5 +1,5 @@ /* ia64-gen.c -- Generate a shrunk set of opcode tables - Copyright 1999, 2000, 2001 Free Software Foundation, Inc. + Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc. Written by Bob Manson, Cygnus Solutions, <manson@cygnus.com> This file is part of GDB, GAS, and the GNU binutils. @@ -30,16 +30,17 @@ required. The resource table is constructed based on some text dependency tables, - which are also easier to maintain than the final representation. - -*/ + which are also easier to maintain than the final representation. */ #include <stdio.h> +#include <stdarg.h> +#include <errno.h> #include "ansidecl.h" #include "libiberty.h" #include "safe-ctype.h" #include "sysdep.h" +#include "getopt.h" #include "ia64-opc.h" #include "ia64-opc-a.c" #include "ia64-opc-i.c" @@ -49,49 +50,54 @@ #include "ia64-opc-x.c" #include "ia64-opc-d.c" +#include <libintl.h> +#define _(String) gettext (String) + +const char * program_name = NULL; int debug = 0; #define tmalloc(X) (X *) xmalloc (sizeof (X)) /* The main opcode table entry. Each entry is a unique combination of name and flags (no two entries in the table compare as being equal - via opcodes_eq). */ + via opcodes_eq). */ struct main_entry { /* The base name of this opcode. The names of its completers are - appended to it to generate the full instruction name. */ + appended to it to generate the full instruction name. */ struct string_entry *name; /* The base opcode entry. Which one to use is a fairly arbitrary choice; - it uses the first one passed to add_opcode_entry. */ + it uses the first one passed to add_opcode_entry. */ struct ia64_opcode *opcode; - /* The list of completers that can be applied to this opcode. */ + /* The list of completers that can be applied to this opcode. */ struct completer_entry *completers; - /* Next entry in the chain. */ + /* Next entry in the chain. */ struct main_entry *next; - /* Index in the main table. */ + /* Index in the main table. */ int main_index; } *maintable, **ordered_table; + int otlen = 0; int ottotlen = 0; int opcode_count = 0; -/* The set of possible completers for an opcode. */ +/* The set of possible completers for an opcode. */ struct completer_entry { - /* This entry's index in the ia64_completer_table[] array. */ + /* This entry's index in the ia64_completer_table[] array. */ int num; - /* The name of the completer. */ + /* The name of the completer. */ struct string_entry *name; - /* This entry's parent. */ + /* This entry's parent. */ struct completer_entry *parent; /* Set if this is a terminal completer (occurs at the end of an - opcode). */ + opcode). */ int is_terminal; - /* An alternative completer. */ + /* An alternative completer. */ struct completer_entry *alternative; /* Additional completers that can be appended to this one. */ @@ -100,53 +106,53 @@ struct completer_entry /* Before compute_completer_bits () is invoked, this contains the actual instruction opcode for this combination of opcode and completers. Afterwards, it contains those bits that are different from its - parent opcode. */ + parent opcode. */ ia64_insn bits; /* Bits set to 1 correspond to those bits in this completer's opcode that are different from its parent completer's opcode (or from the base opcode if the entry is the root of the opcode's completer - list). This field is filled in by compute_completer_bits (). */ + list). This field is filled in by compute_completer_bits (). */ ia64_insn mask; - /* Index into the opcode dependency list, or -1 if none. */ + /* Index into the opcode dependency list, or -1 if none. */ int dependencies; /* Remember the order encountered in the opcode tables. */ int order; }; -/* One entry in the disassembler name table. */ +/* One entry in the disassembler name table. */ struct disent { - /* The index into the ia64_name_dis array for this entry. */ + /* The index into the ia64_name_dis array for this entry. */ int ournum; - /* The index into the main_table[] array. */ + /* The index into the main_table[] array. */ int insn; - /* The disassmbly priority of this entry. */ + /* The disassmbly priority of this entry. */ int priority; - /* The completer_index value for this entry. */ + /* The completer_index value for this entry. */ int completer_index; - /* How many other entries share this decode. */ + /* How many other entries share this decode. */ int nextcnt; - /* The next entry sharing the same decode. */ + /* The next entry sharing the same decode. */ struct disent *nexte; - /* The next entry in the name list. */ + /* The next entry in the name list. */ struct disent *next_ent; } *disinsntable = NULL; /* A state machine that will eventually be used to generate the - disassembler table. */ + disassembler table. */ struct bittree { struct disent *disent; - struct bittree *bits[3]; /* 0, 1, and X (don't care) */ + struct bittree *bits[3]; /* 0, 1, and X (don't care). */ int bits_to_skip; int skip_flag; } *bittree; @@ -154,62 +160,63 @@ struct bittree /* The string table contains all opcodes and completers sorted in alphabetical order. */ -/* One entry in the string table. */ +/* One entry in the string table. */ struct string_entry { - /* The index in the ia64_strings[] array for this entry. */ + /* The index in the ia64_strings[] array for this entry. */ int num; - /* And the string. */ + /* And the string. */ char *s; } **string_table = NULL; + int strtablen = 0; int strtabtotlen = 0; -/* resource dependency entries */ +/* Resource dependency entries. */ struct rdep { - char *name; /* resource name */ + char *name; /* Resource name. */ unsigned - mode:2, /* RAW, WAW, or WAR */ - semantics:3; /* dependency semantics */ - char *extra; /* additional semantics info */ + mode:2, /* RAW, WAW, or WAR. */ + semantics:3; /* Dependency semantics. */ + char *extra; /* Additional semantics info. */ int nchks; - int total_chks; /* total #of terminal insns */ - int *chks; /* insn classes which read (RAW), write - (WAW), or write (WAR) this rsrc */ - int *chknotes; /* dependency notes for each class */ + int total_chks; /* Total #of terminal insns. */ + int *chks; /* Insn classes which read (RAW), write + (WAW), or write (WAR) this rsrc. */ + int *chknotes; /* Dependency notes for each class. */ int nregs; - int total_regs; /* total #of terminal insns */ - int *regs; /* insn class which write (RAW), write2 - (WAW), or read (WAR) this rsrc */ - int *regnotes; /* dependency notes for each class */ + int total_regs; /* Total #of terminal insns. */ + int *regs; /* Insn class which write (RAW), write2 + (WAW), or read (WAR) this rsrc. */ + int *regnotes; /* Dependency notes for each class. */ - int waw_special; /* special WAW dependency note */ + int waw_special; /* Special WAW dependency note. */ } **rdeps = NULL; static int rdepslen = 0; static int rdepstotlen = 0; -/* array of all instruction classes */ +/* Array of all instruction classes. */ struct iclass { - char *name; /* instruction class name */ - int is_class; /* is a class, not a terminal */ + char *name; /* Instruction class name. */ + int is_class; /* Is a class, not a terminal. */ int nsubs; - int *subs; /* other classes within this class */ + int *subs; /* Other classes within this class. */ int nxsubs; - int xsubs[4]; /* exclusions */ - char *comment; /* optional comment */ - int note; /* optional note */ - int terminal_resolved; /* did we match this with anything? */ - int orphan; /* detect class orphans */ + int xsubs[4]; /* Exclusions. */ + char *comment; /* Optional comment. */ + int note; /* Optional note. */ + int terminal_resolved; /* Did we match this with anything? */ + int orphan; /* Detect class orphans. */ } **ics = NULL; static int iclen = 0; static int ictotlen = 0; -/* an opcode dependency (chk/reg pair of dependency lists) */ +/* An opcode dependency (chk/reg pair of dependency lists). */ struct opdep { int chk; /* index into dlists */ @@ -219,7 +226,7 @@ struct opdep static int opdeplen = 0; static int opdeptotlen = 0; -/* a generic list of dependencies w/notes encoded. these may be shared. */ +/* A generic list of dependencies w/notes encoded. These may be shared. */ struct deplist { int len; @@ -229,7 +236,81 @@ struct deplist static int dlistlen = 0; static int dlisttotlen = 0; -/* add NAME to the resource table, where TYPE is RAW or WAW */ + +static void fail (const char *, ...); +static void warn (const char *, ...); +static struct rdep * insert_resource (const char *, enum ia64_dependency_mode); +static int deplist_equals (struct deplist *, struct deplist *); +static short insert_deplist (int, unsigned short *); +static short insert_dependencies (int, unsigned short *, int, unsigned short *); +static void mark_used (struct iclass *, int); +static int fetch_insn_class (const char *, int); +static int sub_compare (const void *, const void *); +static void load_insn_classes (void); +static void parse_resource_users (const char *, int **, int *, int **); +static int parse_semantics (char *); +static void add_dep (const char *, const char *, const char *, int, int, char *, int); +static void load_depfile (const char *, enum ia64_dependency_mode); +static void load_dependencies (void); +static int irf_operand (int, const char *); +static int in_iclass_mov_x (struct ia64_opcode *, struct iclass *, const char *, const char *); +static int in_iclass (struct ia64_opcode *, struct iclass *, const char *, const char *, int *); +static int lookup_regindex (const char *, int); +static int lookup_specifier (const char *); +static void print_dependency_table (void); +static struct string_entry * insert_string (char *); +static void gen_dis_table (struct bittree *); +static void print_dis_table (void); +static void generate_disassembler (void); +static void print_string_table (void); +static int completer_entries_eq (struct completer_entry *, struct completer_entry *); +static struct completer_entry * insert_gclist (struct completer_entry *); +static int get_prefix_len (const char *); +static void compute_completer_bits (struct main_entry *, struct completer_entry *); +static void collapse_redundant_completers (void); +static int insert_opcode_dependencies (struct ia64_opcode *, struct completer_entry *); +static void insert_completer_entry (struct ia64_opcode *, struct main_entry *, int); +static void print_completer_entry (struct completer_entry *); +static void print_completer_table (void); +static int opcodes_eq (struct ia64_opcode *, struct ia64_opcode *); +static void add_opcode_entry (struct ia64_opcode *); +static void print_main_table (void); +static void shrink (struct ia64_opcode *); +static void print_version (void); +static void usage (FILE *, int); +static void finish_distable (void); +static void insert_bit_table_ent (struct bittree *, int, ia64_insn, ia64_insn, int, int, int); +static void add_dis_entry (struct bittree *, ia64_insn, ia64_insn, int, struct completer_entry *, int); +static void compact_distree (struct bittree *); +static struct bittree * make_bittree_entry (void); +static struct disent * add_dis_table_ent (struct disent *, int, int, int); + + +static void +fail (const char *message, ...) +{ + va_list args; + + va_start (args, message); + fprintf (stderr, _("%s: Error: "), program_name); + vfprintf (stderr, message, args); + va_end (args); + xexit (1); +} + +static void +warn (const char *message, ...) +{ + va_list args; + + va_start (args, message); + + fprintf (stderr, _("%s: Warning: "), program_name); + vfprintf (stderr, message, args); + va_end (args); +} + +/* Add NAME to the resource table, where TYPE is RAW or WAW. */ static struct rdep * insert_resource (const char *name, enum ia64_dependency_mode type) { @@ -248,7 +329,7 @@ insert_resource (const char *name, enum ia64_dependency_mode type) return rdeps[rdepslen++]; } -/* are the lists of dependency indexes equivalent? */ +/* Are the lists of dependency indexes equivalent? */ static int deplist_equals (struct deplist *d1, struct deplist *d2) { @@ -257,55 +338,48 @@ deplist_equals (struct deplist *d1, struct deplist *d2) if (d1->len != d2->len) return 0; - for (i=0;i < d1->len;i++) - { - if (d1->deps[i] != d2->deps[i]) - return 0; - } + for (i = 0; i < d1->len; i++) + if (d1->deps[i] != d2->deps[i]) + return 0; return 1; } -/* add the list of dependencies to the list of dependency lists */ +/* Add the list of dependencies to the list of dependency lists. */ static short -insert_deplist(int count, unsigned short *deps) +insert_deplist (int count, unsigned short *deps) { - /* sort the list, then see if an equivalent list exists already. - this results in a much smaller set of dependency lists - */ + /* Sort the list, then see if an equivalent list exists already. + this results in a much smaller set of dependency lists. */ struct deplist *list; char set[0x10000]; int i; - memset ((void *)set, 0, sizeof(set)); - for (i=0;i < count;i++) + memset ((void *)set, 0, sizeof (set)); + for (i = 0; i < count; i++) set[deps[i]] = 1; + count = 0; - for (i=0;i < (int)sizeof(set);i++) + for (i = 0; i < (int) sizeof (set); i++) if (set[i]) ++count; - list = tmalloc(struct deplist); + list = tmalloc (struct deplist); list->len = count; - list->deps = (unsigned short *)malloc (sizeof(unsigned short) * count); - for (i=0, count=0;i < (int)sizeof(set);i++) - { - if (set[i]) - { - list->deps[count++] = i; - } - } + list->deps = (unsigned short *) malloc (sizeof (unsigned short) * count); - /* does this list exist already? */ - for (i=0;i < dlistlen;i++) - { - if (deplist_equals (list, dlists[i])) - { - free (list->deps); - free (list); - return i; - } - } + for (i = 0, count = 0; i < (int) sizeof (set); i++) + if (set[i]) + list->deps[count++] = i; + + /* Does this list exist already? */ + for (i = 0; i < dlistlen; i++) + if (deplist_equals (list, dlists[i])) + { + free (list->deps); + free (list); + return i; + } if (dlistlen == dlisttotlen) { @@ -318,7 +392,7 @@ insert_deplist(int count, unsigned short *deps) return dlistlen++; } -/* add the given pair of dependency lists to the opcode dependency list */ +/* Add the given pair of dependency lists to the opcode dependency list. */ static short insert_dependencies (int nchks, unsigned short *chks, int nregs, unsigned short *regs) @@ -333,13 +407,12 @@ insert_dependencies (int nchks, unsigned short *chks, if (nchks > 0) chkind = insert_deplist (nchks, chks); - for (i=0;i < opdeplen;i++) - { - if (opdeps[i]->chk == chkind - && opdeps[i]->reg == regind) - return i; - } - pair = tmalloc(struct opdep); + for (i = 0; i < opdeplen; i++) + if (opdeps[i]->chk == chkind + && opdeps[i]->reg == regind) + return i; + + pair = tmalloc (struct opdep); pair->chk = chkind; pair->reg = regind; @@ -363,20 +436,17 @@ mark_used (struct iclass *ic, int clear_terminals) if (clear_terminals) ic->terminal_resolved = 1; - for (i=0;i < ic->nsubs;i++) - { - mark_used (ics[ic->subs[i]], clear_terminals); - } - for (i=0;i < ic->nxsubs;i++) - { - mark_used (ics[ic->xsubs[i]], clear_terminals); - } + for (i = 0; i < ic->nsubs; i++) + mark_used (ics[ic->subs[i]], clear_terminals); + + for (i = 0; i < ic->nxsubs; i++) + mark_used (ics[ic->xsubs[i]], clear_terminals); } -/* look up an instruction class; if CREATE make a new one if none found; - returns the index into the insn class array */ +/* Look up an instruction class; if CREATE make a new one if none found; + returns the index into the insn class array. */ static int -fetch_insn_class(const char *full_name, int create) +fetch_insn_class (const char *full_name, int create) { char *name; char *notestr; @@ -414,14 +484,14 @@ fetch_insn_class(const char *full_name, int create) if (notestr) { char *nextnotestr; + note = atoi (notestr + 1); if ((nextnotestr = strchr (notestr + 1, '+')) != NULL) { if (strcmp (notestr, "+1+13") == 0) note = 13; else if (!xsect || nextnotestr < xsect) - fprintf (stderr, "Warning: multiple note %s not handled\n", - notestr); + warn (_("multiple note %s not handled\n"), notestr); } } @@ -436,8 +506,8 @@ fetch_insn_class(const char *full_name, int create) *comment = 0; } - for (i=0;i < iclen;i++) - if (strcmp(name, ics[i]->name) == 0 + for (i = 0; i < iclen; i++) + if (strcmp (name, ics[i]->name) == 0 && ((comment == NULL && ics[i]->comment == NULL) || (comment != NULL && ics[i]->comment != NULL && strncmp (ics[i]->comment, comment, @@ -448,40 +518,44 @@ fetch_insn_class(const char *full_name, int create) if (!create) return -1; - /* doesn't exist, so make a new one */ + /* Doesn't exist, so make a new one. */ if (iclen == ictotlen) { ictotlen += 20; ics = (struct iclass **) - xrealloc(ics, (ictotlen)*sizeof(struct iclass *)); + xrealloc (ics, (ictotlen) * sizeof (struct iclass *)); } + ind = iclen++; - ics[ind] = tmalloc(struct iclass); - memset((void *)ics[ind], 0, sizeof(struct iclass)); - ics[ind]->name = xstrdup(name); + ics[ind] = tmalloc (struct iclass); + memset ((void *)ics[ind], 0, sizeof (struct iclass)); + ics[ind]->name = xstrdup (name); ics[ind]->is_class = is_class; ics[ind]->orphan = 1; if (comment) { ics[ind]->comment = xstrdup (comment + 1); - ics[ind]->comment[strlen(ics[ind]->comment)-1] = 0; + ics[ind]->comment[strlen (ics[ind]->comment)-1] = 0; } + if (notestr) ics[ind]->note = note; - /* if it's a composite class, there's a comment or note, look for an - existing class or terminal with the same name. */ + /* If it's a composite class, there's a comment or note, look for an + existing class or terminal with the same name. */ if ((xsect || comment || notestr) && is_class) { /* First, populate with the class we're based on. */ char *subname = name; + if (xsect) *xsect = 0; else if (comment) *comment = 0; else if (notestr) *notestr = 0; + ics[ind]->nsubs = 1; ics[ind]->subs = tmalloc(int); ics[ind]->subs[0] = fetch_insn_class (subname, 1);; @@ -490,6 +564,7 @@ fetch_insn_class(const char *full_name, int create) while (xsect) { char *subname = xsect + 1; + xsect = strchr (subname, '\\'); if (xsect) *xsect = 0; @@ -501,8 +576,8 @@ fetch_insn_class(const char *full_name, int create) return ind; } -/* for sorting a class's sub-class list only; make sure classes appear before - terminals */ +/* For sorting a class's sub-class list only; make sure classes appear before + terminals. */ static int sub_compare (const void *e1, const void *e2) { @@ -521,41 +596,39 @@ sub_compare (const void *e1, const void *e2) } static void -load_insn_classes() +load_insn_classes (void) { - FILE *fp = fopen("ia64-ic.tbl", "r"); + FILE *fp = fopen ("ia64-ic.tbl", "r"); char buf[2048]; - if (fp == NULL){ - fprintf (stderr, "Can't find ia64-ic.tbl for reading\n"); - exit(1); - } + if (fp == NULL) + fail (_("can't find ia64-ic.tbl for reading\n")); - /* discard first line */ + /* Discard first line. */ fgets (buf, sizeof(buf), fp); - while (!feof(fp)) + while (!feof (fp)) { int iclass; char *name; char *tmp; - if (fgets (buf, sizeof(buf), fp) == NULL) + if (fgets (buf, sizeof (buf), fp) == NULL) break; - while (ISSPACE (buf[strlen(buf)-1])) - buf[strlen(buf)-1] = '\0'; + while (ISSPACE (buf[strlen (buf) - 1])) + buf[strlen (buf) - 1] = '\0'; name = tmp = buf; while (*tmp != ';') { ++tmp; - if (tmp == buf + sizeof(buf)) + if (tmp == buf + sizeof (buf)) abort (); } *tmp++ = '\0'; - iclass = fetch_insn_class(name, 1); + iclass = fetch_insn_class (name, 1); ics[iclass]->is_class = 1; if (strcmp (name, "none") == 0) @@ -565,7 +638,7 @@ load_insn_classes() continue; } - /* for this class, record all sub-classes */ + /* For this class, record all sub-classes. */ while (*tmp) { char *subname; @@ -574,44 +647,43 @@ load_insn_classes() while (*tmp && ISSPACE (*tmp)) { ++tmp; - if (tmp == buf + sizeof(buf)) - abort(); + if (tmp == buf + sizeof (buf)) + abort (); } subname = tmp; while (*tmp && *tmp != ',') { ++tmp; - if (tmp == buf + sizeof(buf)) - abort(); + if (tmp == buf + sizeof (buf)) + abort (); } if (*tmp == ',') *tmp++ = '\0'; ics[iclass]->subs = (int *) - xrealloc((void *)ics[iclass]->subs, - (ics[iclass]->nsubs+1)*sizeof(int)); + xrealloc ((void *)ics[iclass]->subs, + (ics[iclass]->nsubs + 1) * sizeof (int)); - sub = fetch_insn_class(subname, 1); + sub = fetch_insn_class (subname, 1); ics[iclass]->subs = (int *) - xrealloc(ics[iclass]->subs, (ics[iclass]->nsubs+1)*sizeof(int)); + xrealloc (ics[iclass]->subs, (ics[iclass]->nsubs + 1) * sizeof (int)); ics[iclass]->subs[ics[iclass]->nsubs++] = sub; } - /* make sure classes come before terminals */ + + /* Make sure classes come before terminals. */ qsort ((void *)ics[iclass]->subs, ics[iclass]->nsubs, sizeof(int), sub_compare); } - fclose(fp); + fclose (fp); if (debug) - { - printf ("%d classes\n", iclen); - } + printf ("%d classes\n", iclen); } -/* extract the insn classes from the given line */ +/* Extract the insn classes from the given line. */ static void -parse_resource_users(ref, usersp, nusersp, notesp) - char *ref; +parse_resource_users (ref, usersp, nusersp, notesp) + const char *ref; int **usersp; int *nusersp; int **notesp; @@ -641,53 +713,49 @@ parse_resource_users(ref, usersp, nusersp, notesp) c = *tmp; *tmp++ = '\0'; - xsect = strchr(name, '\\'); - if ((notestr = strstr(name, "+")) != NULL) + xsect = strchr (name, '\\'); + if ((notestr = strstr (name, "+")) != NULL) { char *nextnotestr; + note = atoi (notestr + 1); if ((nextnotestr = strchr (notestr + 1, '+')) != NULL) { - /* note 13 always implies note 1 */ + /* Note 13 always implies note 1. */ if (strcmp (notestr, "+1+13") == 0) note = 13; else if (!xsect || nextnotestr < xsect) - fprintf (stderr, "Warning: multiple note %s not handled\n", - notestr); + warn (_("multiple note %s not handled\n"), notestr); } if (!xsect) *notestr = '\0'; } else note = 0; - + /* All classes are created when the insn class table is parsed; Individual instructions might not appear until the dependency tables are read. Only create new classes if it's *not* an insn class, or if it's a composite class (which wouldn't necessarily be in the IC - table). - */ - if (strncmp(name, "IC:", 3) != 0 || xsect != NULL) + table). */ + if (strncmp (name, "IC:", 3) != 0 || xsect != NULL) create = 1; - iclass = fetch_insn_class(name, create); + iclass = fetch_insn_class (name, create); if (iclass != -1) { users = (int *) - xrealloc ((void *)users,(count+1)*sizeof(int)); + xrealloc ((void *) users,(count + 1) * sizeof (int)); notes = (int *) - xrealloc ((void *)notes,(count+1)*sizeof(int)); + xrealloc ((void *) notes,(count + 1) * sizeof (int)); notes[count] = note; users[count++] = iclass; mark_used (ics[iclass], 0); } - else - { - if (debug) - printf("Class %s not found\n", name); - } + else if (debug) + printf("Class %s not found\n", name); } - /* update the return values */ + /* Update the return values. */ *usersp = users; *nusersp = count; *notesp = notes; @@ -723,10 +791,10 @@ add_dep (const char *name, const char *chk, const char *reg, struct rdep *rs; rs = insert_resource (name, mode); - parse_resource_users (chk, &rs->chks, &rs->nchks, - &rs->chknotes); - parse_resource_users (reg, &rs->regs, &rs->nregs, - &rs->regnotes); + + parse_resource_users (chk, &rs->chks, &rs->nchks, &rs->chknotes); + parse_resource_users (reg, &rs->regs, &rs->nregs, &rs->regnotes); + rs->semantics = semantics; rs->extra = extra; rs->waw_special = flag; @@ -735,16 +803,14 @@ add_dep (const char *name, const char *chk, const char *reg, static void load_depfile (const char *filename, enum ia64_dependency_mode mode) { - FILE *fp = fopen(filename, "r"); + FILE *fp = fopen (filename, "r"); char buf[1024]; - if (fp == NULL){ - fprintf (stderr, "Can't find %s for reading\n", filename); - exit(1); - } + if (fp == NULL) + fail (_("can't find %s for reading\n"), filename); - fgets(buf, sizeof(buf), fp); - while (!feof(fp)) + fgets (buf, sizeof(buf), fp); + while (!feof (fp)) { char *name, *tmp; int semantics; @@ -754,8 +820,8 @@ load_depfile (const char *filename, enum ia64_dependency_mode mode) if (fgets (buf, sizeof(buf), fp) == NULL) break; - while (ISSPACE (buf[strlen(buf)-1])) - buf[strlen(buf)-1] = '\0'; + while (ISSPACE (buf[strlen (buf) - 1])) + buf[strlen (buf) - 1] = '\0'; name = tmp = buf; while (*tmp != ';') @@ -783,7 +849,7 @@ load_depfile (const char *filename, enum ia64_dependency_mode mode) /* For WAW entries, if the chks and regs differ, we need to enter the entries in both positions so that the tables will be parsed properly, - without a lot of extra work */ + without a lot of extra work. */ if (mode == IA64_DV_WAW && strcmp (regp, chkp) != 0) { add_dep (name, chkp, regp, semantics, mode, extra, 0); @@ -794,21 +860,21 @@ load_depfile (const char *filename, enum ia64_dependency_mode mode) add_dep (name, chkp, regp, semantics, mode, extra, 0); } } - fclose(fp); + fclose (fp); } static void -load_dependencies() +load_dependencies (void) { load_depfile ("ia64-raw.tbl", IA64_DV_RAW); load_depfile ("ia64-waw.tbl", IA64_DV_WAW); load_depfile ("ia64-war.tbl", IA64_DV_WAR); if (debug) - printf ("%d RAW/WAW/WAR dependencies\n", rdepslen); + printf ("%d RAW/WAW/WAR dependencies\n", rdepslen); } -/* is the given operand an indirect register file operand? */ +/* Is the given operand an indirect register file operand? */ static int irf_operand (int op, const char *field) { @@ -832,8 +898,8 @@ irf_operand (int op, const char *field) } } -/* handle mov_ar, mov_br, mov_cr, mov_indirect, mov_ip, mov_pr, mov_psr, and - mov_um insn classes */ +/* Handle mov_ar, mov_br, mov_cr, mov_indirect, mov_ip, mov_pr, mov_psr, and + mov_um insn classes. */ static int in_iclass_mov_x (struct ia64_opcode *idesc, struct iclass *ic, const char *format, const char *field) @@ -947,11 +1013,10 @@ in_iclass_mov_x (struct ia64_opcode *idesc, struct iclass *ic, return 0; } - -/* is the given opcode in the given insn class? */ +/* Is the given opcode in the given insn class? */ static int -in_iclass(struct ia64_opcode *idesc, struct iclass *ic, - const char *format, const char *field, int *notep) +in_iclass (struct ia64_opcode *idesc, struct iclass *ic, + const char *format, const char *field, int *notep) { int i; int resolved = 0; @@ -960,15 +1025,14 @@ in_iclass(struct ia64_opcode *idesc, struct iclass *ic, { if (!strncmp (ic->comment, "Format", 6)) { - /* assume that the first format seen is the most restrictive, and - only keep a later one if it looks like it's more restrictive. */ + /* Assume that the first format seen is the most restrictive, and + only keep a later one if it looks like it's more restrictive. */ if (format) { if (strlen (ic->comment) < strlen (format)) { - fprintf (stderr, "Warning: most recent format '%s'\n" - "appears more restrictive than '%s'\n", - ic->comment, format); + warn (_("most recent format '%s'\nappears more restrictive than '%s'\n"), + ic->comment, format); format = ic->comment; } } @@ -978,15 +1042,15 @@ in_iclass(struct ia64_opcode *idesc, struct iclass *ic, else if (!strncmp (ic->comment, "Field", 5)) { if (field) - fprintf (stderr, "Overlapping field %s->%s\n", - ic->comment, field); + warn (_("overlapping field %s->%s\n"), + ic->comment, field); field = ic->comment; } } - /* an insn class matches anything that is the same followed by completers, + /* An insn class matches anything that is the same followed by completers, except when the absence and presence of completers constitutes different - instructions */ + instructions. */ if (ic->nsubs == 0 && ic->nxsubs == 0) { int is_mov = strncmp (idesc->name, "mov", 3) == 0; @@ -997,26 +1061,25 @@ in_iclass(struct ia64_opcode *idesc, struct iclass *ic, && (idesc->name[len] == '\0' || idesc->name[len] == '.')); - /* all break and nop variations must match exactly */ + /* All break and nop variations must match exactly. */ if (resolved && (strcmp (ic->name, "break") == 0 || strcmp (ic->name, "nop") == 0)) resolved = strcmp (ic->name, idesc->name) == 0; - /* assume restrictions in the FORMAT/FIELD negate resolution, - unless specifically allowed by clauses in this block */ + /* Assume restrictions in the FORMAT/FIELD negate resolution, + unless specifically allowed by clauses in this block. */ if (resolved && field) { - /* check Field(sf)==sN against opcode sN */ + /* Check Field(sf)==sN against opcode sN. */ if (strstr(field, "(sf)==") != NULL) { char *sf; + if ((sf = strstr (idesc->name, ".s")) != 0) - { - resolved = strcmp (sf + 1, strstr (field, "==") + 2) == 0; - } + resolved = strcmp (sf + 1, strstr (field, "==") + 2) == 0; } - /* check Field(lftype)==XXX */ + /* Check Field(lftype)==XXX. */ else if (strstr (field, "(lftype)") != NULL) { if (strstr (idesc->name, "fault") != NULL) @@ -1024,7 +1087,7 @@ in_iclass(struct ia64_opcode *idesc, struct iclass *ic, else resolved = strstr (field, "fault") == NULL; } - /* handle Field(ctype)==XXX */ + /* Handle Field(ctype)==XXX. */ else if (strstr (field, "(ctype)") != NULL) { if (strstr (idesc->name, "or.andcm")) @@ -1045,6 +1108,7 @@ in_iclass(struct ia64_opcode *idesc, struct iclass *ic, resolved = strcmp (field, "Field(ctype)==") == 0; } } + if (resolved && format) { if (strncmp (idesc->name, "dep", 3) == 0 @@ -1075,8 +1139,8 @@ in_iclass(struct ia64_opcode *idesc, struct iclass *ic, resolved = 0; } - /* misc brl variations ('.cond' is optional); - plain brl matches brl.cond */ + /* Misc brl variations ('.cond' is optional); + plain brl matches brl.cond. */ if (!resolved && (strcmp (idesc->name, "brl") == 0 || strncmp (idesc->name, "brl.", 4) == 0) @@ -1085,7 +1149,7 @@ in_iclass(struct ia64_opcode *idesc, struct iclass *ic, resolved = 1; } - /* misc br variations ('.cond' is optional) */ + /* Misc br variations ('.cond' is optional). */ if (!resolved && (strcmp (idesc->name, "br") == 0 || strncmp (idesc->name, "br.", 3) == 0) @@ -1100,81 +1164,77 @@ in_iclass(struct ia64_opcode *idesc, struct iclass *ic, resolved = 1; } - /* probe variations */ + /* probe variations. */ if (!resolved && strncmp (idesc->name, "probe", 5) == 0) { resolved = strcmp (ic->name, "probe") == 0 && !((strstr (idesc->name, "fault") != NULL) ^ (format && strstr (format, "M40") != NULL)); } - /* mov variations */ + + /* mov variations. */ if (!resolved && is_mov) { if (plain_mov) { - /* mov alias for fmerge */ + /* mov alias for fmerge. */ if (strcmp (ic->name, "fmerge") == 0) { resolved = idesc->operands[0] == IA64_OPND_F1 && idesc->operands[1] == IA64_OPND_F3; } - /* mov alias for adds (r3 or imm14) */ + /* mov alias for adds (r3 or imm14). */ else if (strcmp (ic->name, "adds") == 0) { resolved = (idesc->operands[0] == IA64_OPND_R1 && (idesc->operands[1] == IA64_OPND_R3 || (idesc->operands[1] == IA64_OPND_IMM14))); } - /* mov alias for addl */ + /* mov alias for addl. */ else if (strcmp (ic->name, "addl") == 0) { resolved = idesc->operands[0] == IA64_OPND_R1 && idesc->operands[1] == IA64_OPND_IMM22; } } - /* some variants of mov and mov.[im] */ + + /* Some variants of mov and mov.[im]. */ if (!resolved && strncmp (ic->name, "mov_", 4) == 0) - { - resolved = in_iclass_mov_x (idesc, ic, format, field); - } + resolved = in_iclass_mov_x (idesc, ic, format, field); } - /* keep track of this so we can flag any insn classes which aren't - mapped onto at least one real insn */ + /* Keep track of this so we can flag any insn classes which aren't + mapped onto at least one real insn. */ if (resolved) - { - ic->terminal_resolved = 1; - } + ic->terminal_resolved = 1; } - else for (i=0;i < ic->nsubs;i++) + else for (i = 0; i < ic->nsubs; i++) { - if (in_iclass(idesc, ics[ic->subs[i]], format, field, notep)) + if (in_iclass (idesc, ics[ic->subs[i]], format, field, notep)) { int j; - for (j=0;j < ic->nxsubs;j++) - { - if (in_iclass(idesc, ics[ic->xsubs[j]], NULL, NULL, NULL)) - return 0; - } + + for (j = 0; j < ic->nxsubs; j++) + if (in_iclass (idesc, ics[ic->xsubs[j]], NULL, NULL, NULL)) + return 0; + if (debug > 1) - printf ("%s is in IC %s\n", - idesc->name, ic->name); + printf ("%s is in IC %s\n", idesc->name, ic->name); + resolved = 1; break; } } - /* If it's in this IC, add the IC note (if any) to the insn */ + /* If it's in this IC, add the IC note (if any) to the insn. */ if (resolved) { if (ic->note && notep) { if (*notep && *notep != ic->note) - { - fprintf (stderr, "Warning: overwriting note %d with note %d" - "(IC:%s)\n", - *notep, ic->note, ic->name); - } + warn (_("overwriting note %d with note %d (IC:%s)\n"), + *notep, ic->note, ic->name); + *notep = ic->note; } } @@ -1355,8 +1415,8 @@ lookup_specifier (const char *name) if (strstr (name, "PR%, % in 16 ") != NULL) return IA64_RS_PRr; - fprintf (stderr, "Warning! Don't know how to specify %% dependency %s\n", - name); + warn (_("don't know how to specify %% dependency %s\n"), + name); } else if (strchr (name, '#')) { @@ -1377,8 +1437,8 @@ lookup_specifier (const char *name) if (strstr (name, "RR#") != NULL) return IA64_RS_RR; - fprintf (stderr, "Warning! Don't know how to specify # dependency %s\n", - name); + warn (_("Don't know how to specify # dependency %s\n"), + name); } else if (strncmp (name, "AR[FPSR]", 8) == 0) return IA64_RS_AR_FPSR; @@ -1402,7 +1462,7 @@ lookup_specifier (const char *name) return IA64_RS_ANY; } -void +static void print_dependency_table () { int i, j; @@ -1415,58 +1475,59 @@ print_dependency_table () { if (!ics[i]->nsubs) { - fprintf (stderr, "Warning: IC:%s", ics[i]->name); if (ics[i]->comment) - fprintf (stderr, "[%s]", ics[i]->comment); - fprintf (stderr, " has no terminals or sub-classes\n"); + warn (_("IC:%s [%s] has no terminals or sub-classes\n"), + ics[i]->name, ics[i]->comment); + else + warn (_("IC:%s has no terminals or sub-classes\n"), + ics[i]->name); } } else { if (!ics[i]->terminal_resolved && !ics[i]->orphan) { - fprintf(stderr, "Warning: no insns mapped directly to " - "terminal IC %s", ics[i]->name); if (ics[i]->comment) - fprintf(stderr, "[%s] ", ics[i]->comment); - fprintf(stderr, "\n"); + warn (_("no insns mapped directly to terminal IC %s [%s]"), + ics[i]->name, ics[i]->comment); + else + warn (_("no insns mapped directly to terminal IC %s\n"), + ics[i]->name); } } } - for (i=0;i < iclen;i++) + for (i = 0; i < iclen; i++) { if (ics[i]->orphan) { mark_used (ics[i], 1); - fprintf (stderr, "Warning: class %s is defined but not used\n", - ics[i]->name); + warn (_("class %s is defined but not used\n"), + ics[i]->name); } } - if (debug > 1) for (i=0;i < rdepslen;i++) - { - static const char *mode_str[] = { "RAW", "WAW", "WAR" }; - if (rdeps[i]->total_chks == 0) - { - fprintf (stderr, "Warning: rsrc %s (%s) has no chks%s\n", - rdeps[i]->name, mode_str[rdeps[i]->mode], - rdeps[i]->total_regs ? "" : " or regs"); - } - else if (rdeps[i]->total_regs == 0) - { - fprintf (stderr, "Warning: rsrc %s (%s) has no regs\n", - rdeps[i]->name, mode_str[rdeps[i]->mode]); - } - } + if (debug > 1) + for (i = 0; i < rdepslen; i++) + { + static const char *mode_str[] = { "RAW", "WAW", "WAR" }; + + if (rdeps[i]->total_chks == 0) + warn (_("Warning: rsrc %s (%s) has no chks%s\n"), + rdeps[i]->name, mode_str[rdeps[i]->mode], + rdeps[i]->total_regs ? "" : " or regs"); + else if (rdeps[i]->total_regs == 0) + warn (_("rsrc %s (%s) has no regs\n"), + rdeps[i]->name, mode_str[rdeps[i]->mode]); + } } - /* the dependencies themselves */ + /* The dependencies themselves. */ printf ("static const struct ia64_dependency\ndependencies[] = {\n"); - for (i=0;i < rdepslen;i++) + for (i = 0; i < rdepslen; i++) { /* '%', '#', AR[], CR[], or PSR. indicates we need to specify the actual - resource used */ + resource used. */ int specifier = lookup_specifier (rdeps[i]->name); int regindex = lookup_regindex (rdeps[i]->name, specifier); @@ -1481,7 +1542,7 @@ print_dependency_table () } printf ("};\n\n"); - /* and dependency lists */ + /* And dependency lists. */ for (i=0;i < dlistlen;i++) { int len = 2; @@ -1498,11 +1559,11 @@ print_dependency_table () printf ("\n};\n\n"); } - /* and opcode dependency list */ + /* And opcode dependency list. */ printf ("#define NELS(X) (sizeof(X)/sizeof(X[0]))\n"); printf ("static const struct ia64_opcode_dependency\n"); printf ("op_dependencies[] = {\n"); - for (i=0;i < opdeplen;i++) + for (i = 0; i < opdeplen; i++) { printf (" { "); if (opdeps[i]->chk == -1) @@ -1519,11 +1580,9 @@ print_dependency_table () } -/* Add STR to the string table. */ - +/* Add STR to the string table. */ static struct string_entry * -insert_string (str) - char *str; +insert_string (char *str) { int start = 0, end = strtablen; int i, x; @@ -1546,13 +1605,9 @@ insert_string (str) } if (strcmp (str, string_table[strtablen - 1]->s) > 0) - { - i = end; - } + i = end; else if (strcmp (str, string_table[0]->s) < 0) - { - i = 0; - } + i = 0; else { while (1) @@ -1561,52 +1616,43 @@ insert_string (str) i = (start + end) / 2; c = strcmp (str, string_table[i]->s); + if (c < 0) - { - end = i - 1; - } + end = i - 1; else if (c == 0) - { - return string_table[i]; - } + return string_table[i]; else - { - start = i + 1; - } + start = i + 1; + if (start > end) - { - break; - } + break; } } + for (; i > 0 && i < strtablen; i--) - { - if (strcmp (str, string_table[i - 1]->s) > 0) - { - break; - } - } + if (strcmp (str, string_table[i - 1]->s) > 0) + break; + for (; i < strtablen; i++) - { - if (strcmp (str, string_table[i]->s) < 0) - { - break; - } - } + if (strcmp (str, string_table[i]->s) < 0) + break; + for (x = strtablen - 1; x >= i; x--) { string_table[x + 1] = string_table[x]; string_table[x + 1]->num = x + 1; } + string_table[i] = tmalloc (struct string_entry); string_table[i]->s = xstrdup (str); string_table[i]->num = i; strtablen++; + return string_table[i]; } -struct bittree * -make_bittree_entry () +static struct bittree * +make_bittree_entry (void) { struct bittree *res = tmalloc (struct bittree); @@ -1618,8 +1664,9 @@ make_bittree_entry () res->bits_to_skip = 0; return res; } + -struct disent * +static struct disent * add_dis_table_ent (which, insn, order, completer_index) struct disent *which; int insn; @@ -1635,9 +1682,8 @@ add_dis_table_ent (which, insn, order, completer_index) ent->nextcnt++; while (ent->nexte != NULL) - { - ent = ent->nexte; - } + ent = ent->nexte; + ent = (ent->nexte = tmalloc (struct disent)); } else @@ -1661,7 +1707,7 @@ add_dis_table_ent (which, insn, order, completer_index) return which; } -void +static void finish_distable () { struct disent *ent = disinsntable; @@ -1675,7 +1721,7 @@ finish_distable () } } -void +static void insert_bit_table_ent (curr_ent, bit, opcode, mask, opcodenum, order, completer_index) struct bittree *curr_ent; @@ -1702,13 +1748,10 @@ insert_bit_table_ent (curr_ent, bit, opcode, mask, m = ((ia64_insn) 1) << bit; if (mask & m) - { - b = (opcode & m) ? 1 : 0; - } + b = (opcode & m) ? 1 : 0; else - { - b = 2; - } + b = 2; + next = curr_ent->bits[b]; if (next == NULL) { @@ -1719,7 +1762,7 @@ insert_bit_table_ent (curr_ent, bit, opcode, mask, completer_index); } -void +static void add_dis_entry (first, opcode, mask, opcodenum, ent, completer_index) struct bittree *first; ia64_insn opcode; @@ -1729,15 +1772,14 @@ add_dis_entry (first, opcode, mask, opcodenum, ent, completer_index) int completer_index; { if (completer_index & (1 << 20)) - { - abort (); - } + abort (); while (ent != NULL) { ia64_insn newopcode = (opcode & (~ ent->mask)) | ent->bits; add_dis_entry (first, newopcode, mask, opcodenum, ent->addl_entries, (completer_index << 1) | 1); + if (ent->is_terminal) { insert_bit_table_ent (bittree, 40, newopcode, mask, @@ -1749,8 +1791,8 @@ add_dis_entry (first, opcode, mask, opcodenum, ent, completer_index) } } -/* This optimization pass combines multiple "don't care" nodes. */ -void +/* This optimization pass combines multiple "don't care" nodes. */ +static void compact_distree (ent) struct bittree *ent; { @@ -1790,10 +1832,9 @@ compact_distree (ent) for (x = 0; x < 3; x++) { struct bittree *i = ent->bits[x]; + if (i != NULL) - { - compact_distree (i); - } + compact_distree (i); } } @@ -1803,7 +1844,7 @@ static int tot_insn_list_len = 0; /* Generate the disassembler state machine corresponding to the tree in ENT. */ -void +static void gen_dis_table (ent) struct bittree *ent; { @@ -1813,47 +1854,37 @@ gen_dis_table (ent) int totbits = bitsused; int needed_bytes; int zero_count = 0; - int zero_dest = 0; /* initialize this with 0 to keep gcc quiet... */ + int zero_dest = 0; /* Initialize this with 0 to keep gcc quiet... */ /* If this is a terminal entry, there's no point in skipping any - bits. */ + bits. */ if (ent->skip_flag && ent->bits[0] == NULL && ent->bits[1] == NULL && ent->bits[2] == NULL) { if (ent->disent == NULL) - { - abort (); - } + abort (); else - { - ent->skip_flag = 0; - } + ent->skip_flag = 0; } /* Calculate the amount of space needed for this entry, or at least - a conservatively large approximation. */ + a conservatively large approximation. */ if (ent->skip_flag) - { - totbits += 5; - } + totbits += 5; + for (x = 1; x < 3; x++) - { - if (ent->bits[x] != NULL) - { - totbits += 16; - } - } + if (ent->bits[x] != NULL) + totbits += 16; if (ent->disent != NULL) { if (ent->bits[2] != NULL) - { - abort (); - } + abort (); + totbits += 16; } - /* Now allocate the space. */ + /* Now allocate the space. */ needed_bytes = (totbits + 7) / 8; if ((needed_bytes + insn_list_len) > tot_insn_list_len) { @@ -1865,7 +1896,7 @@ gen_dis_table (ent) memset (insn_list + our_offset, 0, needed_bytes); /* Encode the skip entry by setting bit 6 set in the state op field, - and store the # of bits to skip immediately after. */ + and store the # of bits to skip immediately after. */ if (ent->skip_flag) { bitsused += 5; @@ -1878,8 +1909,7 @@ gen_dis_table (ent) && (ENT)->disent == NULL && (ENT)->skip_flag == 0) /* Store an "if (bit is zero)" instruction by setting bit 7 in the - state op field. */ - + state op field. */ if (ent->bits[0] != NULL) { struct bittree *nent = ent->bits[0]; @@ -1929,14 +1959,10 @@ gen_dis_table (ent) i = NULL; } else - { - idest = insn_list_len - our_offset; - } + idest = insn_list_len - our_offset; } else - { - idest = ent->disent->ournum; - } + idest = ent->disent->ournum; /* If the destination offset for the if (bit is 1) test is less than 256 bytes away, we can store it as 8-bits instead of 16; @@ -1946,8 +1972,7 @@ gen_dis_table (ent) Note that branchings within the table are relative, and there are no branches that branch past our instruction yet - so we do not need to adjust any other offsets. */ - + so we do not need to adjust any other offsets. */ if (x == 1) { if (idest <= 256) @@ -1965,9 +1990,7 @@ gen_dis_table (ent) idest--; } else - { - insn_list[our_offset] |= 0x20; - } + insn_list[our_offset] |= 0x20; } else { @@ -1996,74 +2019,58 @@ gen_dis_table (ent) idest &= ~32768; } else - { - insn_list[our_offset] |= 0x08; - } + insn_list[our_offset] |= 0x08; } + if (debug) { int id = idest; if (i == NULL) - { - id |= 32768; - } + id |= 32768; else if (! (id & 32768)) - { - id += our_offset; - } + id += our_offset; + if (x == 1) - { - printf ("%d: if (1) goto %d\n", our_offset, id); - } + printf ("%d: if (1) goto %d\n", our_offset, id); else - { - printf ("%d: try %d\n", our_offset, id); - } + printf ("%d: try %d\n", our_offset, id); } - /* Store the address of the entry being branched to. */ + /* Store the address of the entry being branched to. */ while (currbits >= 0) { char *byte = insn_list + our_offset + bitsused / 8; if (idest & (1 << currbits)) - { - *byte |= (1 << (7 - (bitsused % 8))); - } + *byte |= (1 << (7 - (bitsused % 8))); + bitsused++; currbits--; } - /* Now generate the states for the entry being branched to. */ + /* Now generate the states for the entry being branched to. */ if (i != NULL) - { - gen_dis_table (i); - } - + gen_dis_table (i); } } + if (debug) { if (ent->skip_flag) - { - printf ("%d: skipping %d\n", our_offset, ent->bits_to_skip); - } + printf ("%d: skipping %d\n", our_offset, ent->bits_to_skip); if (ent->bits[0] != NULL) - { - printf ("%d: if (0:%d) goto %d\n", our_offset, zero_count + 1, - zero_dest); - } + printf ("%d: if (0:%d) goto %d\n", our_offset, zero_count + 1, + zero_dest); } + if (bitsused != totbits) - { - abort (); - } + abort (); } -void -print_dis_table () +static void +print_dis_table (void) { int x; struct disent *cent = disinsntable; @@ -2072,9 +2079,8 @@ print_dis_table () for (x = 0; x < insn_list_len; x++) { if ((x > 0) && ((x % 12) == 0)) - { - printf ("\n"); - } + printf ("\n"); + printf ("0x%02x, ", insn_list[x]); } printf ("\n};\n\n"); @@ -2096,24 +2102,22 @@ print_dis_table () printf ("};\n\n"); } -void -generate_disassembler () +static void +generate_disassembler (void) { int i; bittree = make_bittree_entry (); - for (i=0; i < otlen;i++) + for (i = 0; i < otlen; i++) { struct main_entry *ptr = ordered_table[i]; if (ptr->opcode->type != IA64_TYPE_DYN) - { - add_dis_entry (bittree, - ptr->opcode->opcode, ptr->opcode->mask, - ptr->main_index, - ptr->completers, 1); - } + add_dis_entry (bittree, + ptr->opcode->opcode, ptr->opcode->mask, + ptr->main_index, + ptr->completers, 1); } compact_distree (bittree); @@ -2123,25 +2127,26 @@ generate_disassembler () print_dis_table (); } -void -print_string_table () +static void +print_string_table (void) { int x; char lbuf[80], buf[80]; int blen = 0; - printf ("static const char *ia64_strings[] = {\n"); + printf ("static const char * const ia64_strings[] = {\n"); lbuf[0] = '\0'; + for (x = 0; x < strtablen; x++) { int len; if (strlen (string_table[x]->s) > 75) - { - abort (); - } + abort (); + sprintf (buf, " \"%s\",", string_table[x]->s); len = strlen (buf); + if ((blen + len) > 75) { printf (" %s\n", lbuf); @@ -2151,10 +2156,10 @@ print_string_table () strcat (lbuf, buf); blen += len; } + if (blen > 0) - { - printf (" %s\n", lbuf); - } + printf (" %s\n", lbuf); + printf ("};\n\n"); } @@ -2162,9 +2167,9 @@ static struct completer_entry **glist; static int glistlen = 0; static int glisttotlen = 0; -/* If the completer trees ENT1 and ENT2 are equal, return 1. */ +/* If the completer trees ENT1 and ENT2 are equal, return 1. */ -int +static int completer_entries_eq (ent1, ent2) struct completer_entry *ent1, *ent2; { @@ -2176,25 +2181,23 @@ completer_entries_eq (ent1, ent2) || ent1->is_terminal != ent2->is_terminal || ent1->dependencies != ent2->dependencies || ent1->order != ent2->order) - { - return 0; - } + return 0; + if (! completer_entries_eq (ent1->addl_entries, ent2->addl_entries)) - { - return 0; - } + return 0; + ent1 = ent1->alternative; ent2 = ent2->alternative; } + return ent1 == ent2; } /* Insert ENT into the global list of completers and return it. If an equivalent entry (according to completer_entries_eq) already exists, - it is returned instead. */ -struct completer_entry * -insert_gclist (ent) - struct completer_entry *ent; + it is returned instead. */ +static struct completer_entry * +insert_gclist (struct completer_entry *ent) { if (ent != NULL) { @@ -2223,13 +2226,9 @@ insert_gclist (ent) } if (ent->name->num < glist[0]->name->num) - { - i = 0; - } + i = 0; else if (ent->name->num > glist[end - 1]->name->num) - { - i = end; - } + i = end; else { int c; @@ -2238,62 +2237,50 @@ insert_gclist (ent) { i = (start + end) / 2; c = ent->name->num - glist[i]->name->num; + if (c < 0) - { - end = i - 1; - } + end = i - 1; else if (c == 0) { while (i > 0 && ent->name->num == glist[i - 1]->name->num) - { - i--; - } + i--; + break; } else - { - start = i + 1; - } + start = i + 1; + if (start > end) - { - break; - } + break; } + if (c == 0) { while (i < glistlen) { if (ent->name->num != glist[i]->name->num) - { - break; - } + break; + if (completer_entries_eq (ent, glist[i])) - { - return glist[i]; - } + return glist[i]; + i++; } } } + for (; i > 0 && i < glistlen; i--) - { - if (ent->name->num >= glist[i - 1]->name->num) - { - break; - } - } + if (ent->name->num >= glist[i - 1]->name->num) + break; + for (; i < glistlen; i++) - { - if (ent->name->num < glist[i]->name->num) - { - break; - } - } + if (ent->name->num < glist[i]->name->num) + break; + for (x = glistlen - 1; x >= i; x--) - { - glist[x + 1] = glist[x]; - } + glist[x + 1] = glist[x]; + glist[i] = ent; glistlen++; } @@ -2307,19 +2294,13 @@ get_prefix_len (name) char *c; if (name[0] == '\0') - { - return 0; - } + return 0; c = strchr (name, '.'); if (c != NULL) - { - return c - name; - } + return c - name; else - { - return strlen (name); - } + return strlen (name); } static void @@ -2340,30 +2321,21 @@ compute_completer_bits (ment, ent) int x; while (p != NULL && ! p->is_terminal) - { - p = p->parent; - } + p = p->parent; if (p != NULL) - { - p_bits = p->bits; - } + p_bits = p->bits; else - { - p_bits = ment->opcode->opcode; - } + p_bits = ment->opcode->opcode; for (x = 0; x < 64; x++) { ia64_insn m = ((ia64_insn) 1) << x; + if ((p_bits & m) != (our_bits & m)) - { - mask |= m; - } + mask |= m; else - { - our_bits &= ~m; - } + our_bits &= ~m; } ent->bits = our_bits; ent->mask = mask; @@ -2379,9 +2351,9 @@ compute_completer_bits (ment, ent) } /* Find identical completer trees that are used in different - instructions and collapse their entries. */ -void -collapse_redundant_completers () + instructions and collapse their entries. */ +static void +collapse_redundant_completers (void) { struct main_entry *ptr; int x; @@ -2389,43 +2361,39 @@ collapse_redundant_completers () for (ptr = maintable; ptr != NULL; ptr = ptr->next) { if (ptr->completers == NULL) - { - abort (); - } + abort (); + compute_completer_bits (ptr, ptr->completers); ptr->completers = insert_gclist (ptr->completers); } /* The table has been finalized, now number the indexes. */ for (x = 0; x < glistlen; x++) - { - glist[x]->num = x; - } + glist[x]->num = x; } -/* attach two lists of dependencies to each opcode. +/* Attach two lists of dependencies to each opcode. 1) all resources which, when already marked in use, conflict with this opcode (chks) 2) all resources which must be marked in use when this opcode is used - (regs) -*/ -int + (regs). */ +static int insert_opcode_dependencies (opc, cmp) struct ia64_opcode *opc; struct completer_entry *cmp ATTRIBUTE_UNUSED; { - /* note all resources which point to this opcode. rfi has the most chks - (79) and cmpxchng has the most regs (54) so 100 here should be enough */ + /* Note all resources which point to this opcode. rfi has the most chks + (79) and cmpxchng has the most regs (54) so 100 here should be enough. */ int i; int nregs = 0; unsigned short regs[256]; int nchks = 0; unsigned short chks[256]; - /* flag insns for which no class matched; there should be none */ + /* Flag insns for which no class matched; there should be none. */ int no_class_found = 1; - for (i=0;i < rdepslen;i++) + for (i = 0; i < rdepslen; i++) { struct rdep *rs = rdeps[i]; int j; @@ -2441,21 +2409,19 @@ insert_opcode_dependencies (opc, cmp) if (in_iclass (opc, ics[rs->regs[j]], NULL, NULL, &ic_note)) { - /* We can ignore ic_note 11 for non PR resources */ + /* We can ignore ic_note 11 for non PR resources. */ if (ic_note == 11 && strncmp (rs->name, "PR", 2) != 0) ic_note = 0; if (ic_note != 0 && rs->regnotes[j] != 0 && ic_note != rs->regnotes[j] && !(ic_note == 11 && rs->regnotes[j] == 1)) - fprintf (stderr, "Warning: IC note %d in opcode %s (IC:%s)" - " conflicts with resource %s note %d\n", - ic_note, opc->name, ics[rs->regs[j]]->name, - rs->name, rs->regnotes[j]); + warn (_("IC note %d in opcode %s (IC:%s) conflicts with resource %s note %d\n"), + ic_note, opc->name, ics[rs->regs[j]]->name, + rs->name, rs->regnotes[j]); /* Instruction class notes override resource notes. So far, only note 11 applies to an IC instead of a resource, - and note 11 implies note 1. - */ + and note 11 implies note 1. */ if (ic_note) regs[nregs++] = RDEP(ic_note, i); else @@ -2464,23 +2430,23 @@ insert_opcode_dependencies (opc, cmp) ++rs->total_regs; } } - for (j=0;j < rs->nchks;j++) + + for (j = 0; j < rs->nchks; j++) { int ic_note = 0; if (in_iclass (opc, ics[rs->chks[j]], NULL, NULL, &ic_note)) { - /* We can ignore ic_note 11 for non PR resources */ + /* We can ignore ic_note 11 for non PR resources. */ if (ic_note == 11 && strncmp (rs->name, "PR", 2) != 0) ic_note = 0; if (ic_note != 0 && rs->chknotes[j] != 0 && ic_note != rs->chknotes[j] && !(ic_note == 11 && rs->chknotes[j] == 1)) - fprintf (stderr, "Warning: IC note %d for opcode %s (IC:%s)" - " conflicts with resource %s note %d\n", - ic_note, opc->name, ics[rs->chks[j]]->name, - rs->name, rs->chknotes[j]); + warn (_("IC note %d for opcode %s (IC:%s) conflicts with resource %s note %d\n"), + ic_note, opc->name, ics[rs->chks[j]]->name, + rs->name, rs->chknotes[j]); if (ic_note) chks[nchks++] = RDEP(ic_note, i); else @@ -2492,14 +2458,14 @@ insert_opcode_dependencies (opc, cmp) } if (no_class_found) - fprintf (stderr, "Warning: opcode %s has no class (ops %d %d %d)\n", - opc->name, - opc->operands[0], opc->operands[1], opc->operands[2]); + warn (_("opcode %s has no class (ops %d %d %d)\n"), + opc->name, + opc->operands[0], opc->operands[1], opc->operands[2]); return insert_dependencies (nchks, chks, nregs, regs); } -void +static void insert_completer_entry (opc, tabent, order) struct ia64_opcode *opc; struct main_entry *tabent; @@ -2511,15 +2477,13 @@ insert_completer_entry (opc, tabent, order) int at_end = 0; if (strlen (opc->name) > 128) - { - abort (); - } + abort (); + strcpy (pcopy, opc->name); prefix = pcopy + get_prefix_len (pcopy); + if (prefix[0] != '\0') - { - prefix++; - } + prefix++; while (! at_end) { @@ -2541,13 +2505,13 @@ insert_completer_entry (opc, tabent, order) break; } else - { - ptr = &((*ptr)->alternative); - } + ptr = &((*ptr)->alternative); } + if (need_new_ent) { struct completer_entry *nent = tmalloc (struct completer_entry); + nent->name = sent; nent->parent = parent; nent->addl_entries = NULL; @@ -2566,9 +2530,7 @@ insert_completer_entry (opc, tabent, order) } if ((*ptr)->is_terminal) - { - abort (); - } + abort (); (*ptr)->is_terminal = 1; (*ptr)->mask = (ia64_insn)-1; @@ -2577,7 +2539,7 @@ insert_completer_entry (opc, tabent, order) (*ptr)->order = order; } -void +static void print_completer_entry (ent) struct completer_entry *ent; { @@ -2592,10 +2554,9 @@ print_completer_entry (ent) mask = mask >> 1; bits = bits >> 1; } + if (bits & 0xffffffff00000000LL) - { - abort (); - } + abort (); } printf (" { 0x%x, 0x%x, %d, %d, %d, %d, %d, %d },\n", @@ -2609,20 +2570,18 @@ print_completer_entry (ent) ent->dependencies); } -void +static void print_completer_table () { int x; printf ("static const struct ia64_completer_table\ncompleter_table[] = {\n"); for (x = 0; x < glistlen; x++) - { - print_completer_entry (glist[x]); - } + print_completer_entry (glist[x]); printf ("};\n\n"); } -int +static int opcodes_eq (opc1, opc2) struct ia64_opcode *opc1; struct ia64_opcode *opc2; @@ -2633,26 +2592,22 @@ opcodes_eq (opc1, opc2) if ((opc1->mask != opc2->mask) || (opc1->type != opc2->type) || (opc1->num_outputs != opc2->num_outputs) || (opc1->flags != opc2->flags)) - { - return 0; - } + return 0; + for (x = 0; x < 5; x++) - { - if (opc1->operands[x] != opc2->operands[x]) - { - return 0; - } - } + if (opc1->operands[x] != opc2->operands[x]) + return 0; + plen1 = get_prefix_len (opc1->name); plen2 = get_prefix_len (opc2->name); + if (plen1 == plen2 && (memcmp (opc1->name, opc2->name, plen1) == 0)) - { - return 1; - } + return 1; + return 0; } -void +static void add_opcode_entry (opc) struct ia64_opcode *opc; { @@ -2662,9 +2617,8 @@ add_opcode_entry (opc) int found_it = 0; if (strlen (opc->name) > 128) - { - abort (); - } + abort (); + place = &maintable; strcpy (prefix, opc->name); prefix[get_prefix_len (prefix)] = '\0'; @@ -2672,7 +2626,7 @@ add_opcode_entry (opc) /* Walk the list of opcode table entries. If it's a new instruction, allocate and fill in a new entry. Note - the main table is alphabetical by opcode name. */ + the main table is alphabetical by opcode name. */ while (*place != NULL) { @@ -2683,9 +2637,8 @@ add_opcode_entry (opc) break; } if ((*place)->name->num > name->num) - { - break; - } + break; + place = &((*place)->next); } if (! found_it) @@ -2710,8 +2663,8 @@ add_opcode_entry (opc) insert_completer_entry (opc, *place, opcode_count++); } -void -print_main_table () +static void +print_main_table (void) { struct main_entry *ptr = maintable; int index = 0; @@ -2742,30 +2695,85 @@ print_main_table () printf ("};\n\n"); } -void +static void shrink (table) struct ia64_opcode *table; { int curr_opcode; for (curr_opcode = 0; table[curr_opcode].name != NULL; curr_opcode++) - { - add_opcode_entry (table + curr_opcode); - } + add_opcode_entry (table + curr_opcode); } + +/* Program options. */ +#define OPTION_SRCDIR 200 + +struct option long_options[] = +{ + {"srcdir", required_argument, NULL, OPTION_SRCDIR}, + {"debug", no_argument, NULL, 'd'}, + {"version", no_argument, NULL, 'V'}, + {"help", no_argument, NULL, 'h'}, + {0, no_argument, NULL, 0} +}; + +static void +print_version (void) +{ + printf ("%s: version 1.0\n", program_name); + xexit (0); +} + +static void +usage (FILE * stream, int status) +{ + fprintf (stream, "Usage: %s [-V | --version] [-d | --debug] [--srcdir=dirname] [--help]\n", + program_name); + xexit (status); +} + int -main (argc, argv) - int argc; - char **argv ATTRIBUTE_UNUSED; +main (int argc, char **argv) { - if (argc > 1) - { - debug = 1; - } + extern int chdir (char *); + char *srcdir = NULL; + int c; + + program_name = *argv; + xmalloc_set_program_name (program_name); + + while ((c = getopt_long (argc, argv, "vVdh", long_options, 0)) != EOF) + switch (c) + { + case OPTION_SRCDIR: + srcdir = optarg; + break; + case 'V': + case 'v': + print_version (); + break; + case 'd': + debug = 1; + break; + case 'h': + case '?': + usage (stderr, 0); + default: + case 0: + break; + } + + if (optind != argc) + usage (stdout, 1); + + if (srcdir != NULL) + if (chdir (srcdir) != 0) + fail (_("unable to change directory to \"%s\", errno = %s\n"), + srcdir, strerror (errno)); - load_insn_classes(); - load_dependencies(); + load_insn_classes (); + load_dependencies (); shrink (ia64_opcodes_a); shrink (ia64_opcodes_b); @@ -2777,7 +2785,7 @@ main (argc, argv) collapse_redundant_completers (); - printf ("/* This file is automatically generated by ia64-gen. Do not edit! */\n"); + printf ("/* This file is automatically generated by ia64-gen. Do not edit! */\n"); print_string_table (); print_dependency_table (); print_completer_table (); |