summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorPeter Johnson <peter@tortall.net>2007-04-22 03:32:46 +0000
committerPeter Johnson <peter@tortall.net>2007-04-22 03:32:46 +0000
commit00473ca98171eb19615109f5a8512993da43a77a (patch)
treeff659c3a00f05562d7210683c8756303c7d02187 /tools
parent4238a7c5ce3b8853ecd1d9cf50eaa354f1038e7d (diff)
downloadyasm-00473ca98171eb19615109f5a8512993da43a77a.tar.gz
Bite the bullet and convert tabs to spaces. Previously yasm's source has
been using a mix of tabs and 4 spaces to indent; this looks horrible if tab size is ever not 8. While I debated converting to tab-only indentation that would have been a far higher impact to the source. svn path=/trunk/yasm/; revision=1825
Diffstat (limited to 'tools')
-rw-r--r--tools/gap/gap.c606
-rw-r--r--tools/gap/perfect.c276
-rw-r--r--tools/gap/perfect.h6
-rw-r--r--tools/xdf/xdfdump.c140
4 files changed, 514 insertions, 514 deletions
diff --git a/tools/gap/gap.c b/tools/gap/gap.c
index b9069f20..9aa80fcd 100644
--- a/tools/gap/gap.c
+++ b/tools/gap/gap.c
@@ -71,7 +71,7 @@ typedef enum {
} dir_type;
typedef struct {
- void (*parse_insn) (void); /* arch-specific parse_insn */
+ void (*parse_insn) (void); /* arch-specific parse_insn */
int multi_parser[NUM_DIRS]; /* whether it has an initial parser field */
} arch_handler;
@@ -124,9 +124,9 @@ dup_slist(slist *out, slist *in)
STAILQ_INIT(out);
STAILQ_FOREACH(sv, in, link) {
- sval *nsv = yasm_xmalloc(sizeof(sval));
- nsv->str = yasm__xstrdup(sv->str);
- STAILQ_INSERT_TAIL(out, nsv, link);
+ sval *nsv = yasm_xmalloc(sizeof(sval));
+ nsv->str = yasm__xstrdup(sv->str);
+ STAILQ_INSERT_TAIL(out, nsv, link);
}
}
@@ -147,16 +147,16 @@ get_dirs(dir_byp_list *byp, /*@null@*/ const char *parser)
dir_byp *db;
if (STAILQ_EMPTY(byp)) {
- report_error("PARSERS not yet specified");
- return NULL;
+ report_error("PARSERS not yet specified");
+ return NULL;
}
STAILQ_FOREACH(db, byp, link) {
- if ((!parser && !db->parser) ||
- (parser && db->parser && strcmp(parser, db->parser) == 0)) {
- found = &db->dirs;
- break;
- }
+ if ((!parser && !db->parser) ||
+ (parser && db->parser && strcmp(parser, db->parser) == 0)) {
+ found = &db->dirs;
+ break;
+ }
}
return found;
@@ -171,22 +171,22 @@ add_dir(dir_byp_list *byp, /*@null@*/ const char *parser, dir *d)
dir_list *found = get_dirs(byp, parser);
if (found) {
- STAILQ_INSERT_TAIL(found, d, link);
- return 0;
+ STAILQ_INSERT_TAIL(found, d, link);
+ return 0;
} else if (!parser) {
- /* Add separately to all */
- dir_byp *db;
- int first = 1;
- STAILQ_FOREACH(db, byp, link) {
- if (!first)
- d = dup_dir(d);
- first = 0;
- STAILQ_INSERT_TAIL(&db->dirs, d, link);
- }
- return 0;
+ /* Add separately to all */
+ dir_byp *db;
+ int first = 1;
+ STAILQ_FOREACH(db, byp, link) {
+ if (!first)
+ d = dup_dir(d);
+ first = 0;
+ STAILQ_INSERT_TAIL(&db->dirs, d, link);
+ }
+ return 0;
} else {
- report_error("parser not found");
- return 1;
+ report_error("parser not found");
+ return 1;
}
}
@@ -196,9 +196,9 @@ check_parser(dir_type type)
char *parser = NULL;
if (arch->multi_parser[type]) {
- parser = strtok(NULL, " \t\n");
- if (strcmp(parser, "-") == 0)
- parser = NULL;
+ parser = strtok(NULL, " \t\n");
+ if (strcmp(parser, "-") == 0)
+ parser = NULL;
}
return parser;
@@ -214,15 +214,15 @@ parse_args(slist *args)
tok = strtok(NULL, " \t\n");
if (!tok) {
- report_error("no args");
- return;
+ report_error("no args");
+ return;
}
while (tok) {
- sv = yasm_xmalloc(sizeof(sval));
- sv->str = yasm__xstrdup(tok);
- STAILQ_INSERT_TAIL(args, sv, link);
- tok = strtok(NULL, " \t\n");
+ sv = yasm_xmalloc(sizeof(sval));
+ sv->str = yasm__xstrdup(tok);
+ STAILQ_INSERT_TAIL(args, sv, link);
+ tok = strtok(NULL, " \t\n");
}
}
@@ -249,18 +249,18 @@ parse_arch(void)
char *tok = strtok(NULL, " \t\n");
if (!tok) {
- report_error("ARCH requires an operand");
- return;
+ report_error("ARCH requires an operand");
+ return;
}
for (i=0; i<sizeof(archs)/sizeof(archs[0]); i++) {
- if (strcmp(archs[i].name, tok) == 0) {
- found = 1;
- break;
- }
+ if (strcmp(archs[i].name, tok) == 0) {
+ found = 1;
+ break;
+ }
}
if (!found) {
- report_error("unrecognized ARCH");
- return;
+ report_error("unrecognized ARCH");
+ return;
}
arch = archs[i].arch;
@@ -273,65 +273,65 @@ parse_parsers(void)
char *tok;
if (!arch) {
- report_error("ARCH not specified before PARSERS");
- return;
+ report_error("ARCH not specified before PARSERS");
+ return;
}
tok = strtok(NULL, " \t\n");
if (!tok) {
- report_error("no PARSERS parameter");
- return;
+ report_error("no PARSERS parameter");
+ return;
}
while (tok) {
- /* Insert into each slist of slist if broken out by parser */
- if (arch->multi_parser[INSN] || arch->multi_parser[PREFIX]) {
- db = yasm_xmalloc(sizeof(dir_byp));
- db->parser = yasm__xstrdup(tok);
- STAILQ_INIT(&db->dirs);
-
- STAILQ_INSERT_TAIL(&insnprefix_byp, db, link);
- }
- if (arch->multi_parser[CPU] || arch->multi_parser[CPU_ALIAS] ||
- arch->multi_parser[CPU_FEATURE]) {
- db = yasm_xmalloc(sizeof(dir_byp));
- db->parser = yasm__xstrdup(tok);
- STAILQ_INIT(&db->dirs);
-
- STAILQ_INSERT_TAIL(&cpu_byp, db, link);
- }
- if (arch->multi_parser[TARGETMOD] || arch->multi_parser[REG] ||
- arch->multi_parser[REGGROUP] || arch->multi_parser[SEGREG]) {
- db = yasm_xmalloc(sizeof(dir_byp));
- db->parser = yasm__xstrdup(tok);
- STAILQ_INIT(&db->dirs);
-
- STAILQ_INSERT_TAIL(&regtmod_byp, db, link);
- }
- tok = strtok(NULL, " \t\n");
+ /* Insert into each slist of slist if broken out by parser */
+ if (arch->multi_parser[INSN] || arch->multi_parser[PREFIX]) {
+ db = yasm_xmalloc(sizeof(dir_byp));
+ db->parser = yasm__xstrdup(tok);
+ STAILQ_INIT(&db->dirs);
+
+ STAILQ_INSERT_TAIL(&insnprefix_byp, db, link);
+ }
+ if (arch->multi_parser[CPU] || arch->multi_parser[CPU_ALIAS] ||
+ arch->multi_parser[CPU_FEATURE]) {
+ db = yasm_xmalloc(sizeof(dir_byp));
+ db->parser = yasm__xstrdup(tok);
+ STAILQ_INIT(&db->dirs);
+
+ STAILQ_INSERT_TAIL(&cpu_byp, db, link);
+ }
+ if (arch->multi_parser[TARGETMOD] || arch->multi_parser[REG] ||
+ arch->multi_parser[REGGROUP] || arch->multi_parser[SEGREG]) {
+ db = yasm_xmalloc(sizeof(dir_byp));
+ db->parser = yasm__xstrdup(tok);
+ STAILQ_INIT(&db->dirs);
+
+ STAILQ_INSERT_TAIL(&regtmod_byp, db, link);
+ }
+ tok = strtok(NULL, " \t\n");
}
/* Add NULL (global) versions if not already created */
if (STAILQ_EMPTY(&insnprefix_byp)) {
- db = yasm_xmalloc(sizeof(dir_byp));
- db->parser = NULL;
- STAILQ_INIT(&db->dirs);
+ db = yasm_xmalloc(sizeof(dir_byp));
+ db->parser = NULL;
+ STAILQ_INIT(&db->dirs);
- STAILQ_INSERT_TAIL(&insnprefix_byp, db, link);
+ STAILQ_INSERT_TAIL(&insnprefix_byp, db, link);
}
if (STAILQ_EMPTY(&cpu_byp)) {
- db = yasm_xmalloc(sizeof(dir_byp));
- db->parser = NULL;
- STAILQ_INIT(&db->dirs);
+ db = yasm_xmalloc(sizeof(dir_byp));
+ db->parser = NULL;
+ STAILQ_INIT(&db->dirs);
- STAILQ_INSERT_TAIL(&cpu_byp, db, link);
+ STAILQ_INSERT_TAIL(&cpu_byp, db, link);
}
if (STAILQ_EMPTY(&regtmod_byp)) {
- db = yasm_xmalloc(sizeof(dir_byp));
- db->parser = NULL;
- STAILQ_INIT(&db->dirs);
+ db = yasm_xmalloc(sizeof(dir_byp));
+ db->parser = NULL;
+ STAILQ_INIT(&db->dirs);
- STAILQ_INSERT_TAIL(&regtmod_byp, db, link);
+ STAILQ_INSERT_TAIL(&regtmod_byp, db, link);
}
}
@@ -346,62 +346,62 @@ x86_parse_insn(void)
sval *sv;
if (!suffix) {
- report_error("INSN requires suffix");
- return;
+ report_error("INSN requires suffix");
+ return;
}
/* save the remainder of args */
parse_args(&args);
if (suffix[0] != '"') {
- /* Just one instruction to generate */
- sv = yasm_xmalloc(sizeof(sval));
- sv->str = yasm__xstrdup(suffix);
- STAILQ_INSERT_HEAD(&args, sv, link);
-
- d = yasm_xmalloc(sizeof(dir));
- d->name = yasm__xstrdup(bname);
- d->func = "INSN";
- d->args = args;
- add_dir(&insnprefix_byp, parser, d);
+ /* Just one instruction to generate */
+ sv = yasm_xmalloc(sizeof(sval));
+ sv->str = yasm__xstrdup(suffix);
+ STAILQ_INSERT_HEAD(&args, sv, link);
+
+ d = yasm_xmalloc(sizeof(dir));
+ d->name = yasm__xstrdup(bname);
+ d->func = "INSN";
+ d->args = args;
+ add_dir(&insnprefix_byp, parser, d);
} else {
- /* Need to generate with suffixes for gas */
- char *p;
- char sufstr[6];
- size_t bnamelen = strlen(bname);
+ /* Need to generate with suffixes for gas */
+ char *p;
+ char sufstr[6];
+ size_t bnamelen = strlen(bname);
- strcpy(sufstr, "SUF_X");
+ strcpy(sufstr, "SUF_X");
- for (p = &suffix[1]; *p != '"'; p++) {
- sufstr[4] = toupper(*p);
+ for (p = &suffix[1]; *p != '"'; p++) {
+ sufstr[4] = toupper(*p);
- d = yasm_xmalloc(sizeof(dir));
+ d = yasm_xmalloc(sizeof(dir));
- d->name = yasm_xmalloc(bnamelen+2);
- strcpy(d->name, bname);
- d->name[bnamelen] = tolower(*p);
- d->name[bnamelen+1] = '\0';
+ d->name = yasm_xmalloc(bnamelen+2);
+ strcpy(d->name, bname);
+ d->name[bnamelen] = tolower(*p);
+ d->name[bnamelen+1] = '\0';
- d->func = "INSN";
- dup_slist(&d->args, &args);
+ d->func = "INSN";
+ dup_slist(&d->args, &args);
- sv = yasm_xmalloc(sizeof(sval));
- sv->str = yasm__xstrdup(sufstr);
- STAILQ_INSERT_HEAD(&d->args, sv, link);
+ sv = yasm_xmalloc(sizeof(sval));
+ sv->str = yasm__xstrdup(sufstr);
+ STAILQ_INSERT_HEAD(&d->args, sv, link);
- add_dir(&insnprefix_byp, "gas", d);
- }
+ add_dir(&insnprefix_byp, "gas", d);
+ }
- /* And finally the version sans suffix */
- sv = yasm_xmalloc(sizeof(sval));
- sv->str = yasm__xstrdup("NONE");
- STAILQ_INSERT_HEAD(&args, sv, link);
+ /* And finally the version sans suffix */
+ sv = yasm_xmalloc(sizeof(sval));
+ sv->str = yasm__xstrdup("NONE");
+ STAILQ_INSERT_HEAD(&args, sv, link);
- d = yasm_xmalloc(sizeof(dir));
- d->name = yasm__xstrdup(bname);
- d->func = "INSN";
- d->args = args;
- add_dir(&insnprefix_byp, parser, d);
+ d = yasm_xmalloc(sizeof(dir));
+ d->name = yasm__xstrdup(bname);
+ d->func = "INSN";
+ d->args = args;
+ add_dir(&insnprefix_byp, parser, d);
}
}
@@ -409,8 +409,8 @@ static void
parse_insn(void)
{
if (!arch) {
- report_error("ARCH not defined prior to INSN");
- return;
+ report_error("ARCH not defined prior to INSN");
+ return;
}
arch->parse_insn();
}
@@ -434,17 +434,17 @@ parse_cpu_alias(void)
dir *aliasd, *d;
if (!alias) {
- report_error("CPU_ALIAS requires an operand");
- return;
+ report_error("CPU_ALIAS requires an operand");
+ return;
}
STAILQ_FOREACH(aliasd, dirs, link) {
- if (strcmp(aliasd->name, alias) == 0)
- break;
+ if (strcmp(aliasd->name, alias) == 0)
+ break;
}
if (!aliasd) {
- report_error("could not find `%s'", alias);
- return;
+ report_error("could not find `%s'", alias);
+ return;
}
d = yasm_xmalloc(sizeof(dir));
@@ -522,83 +522,83 @@ make_c_tab(
FILE *f,
const char *which,
const char *parser,
- bstuff *tab, /* table indexed by b */
- ub4 smax, /* range of scramble[] */
- ub4 blen, /* b in 0..blen-1, power of 2 */
- ub4 *scramble) /* used in final hash */
+ bstuff *tab, /* table indexed by b */
+ ub4 smax, /* range of scramble[] */
+ ub4 blen, /* b in 0..blen-1, power of 2 */
+ ub4 *scramble) /* used in final hash */
{
ub4 i;
/* table for the mapping for the perfect hash */
if (blen >= USE_SCRAMBLE) {
- /* A way to make the 1-byte values in tab bigger */
- if (smax > UB2MAXVAL+1) {
- fprintf(f, "static const unsigned long %s_", which);
- if (parser)
- fprintf(f, "%s_", parser);
- fprintf(f, "scramble[] = {\n");
- for (i=0; i<=UB1MAXVAL; i+=4)
- fprintf(f, "0x%.8lx, 0x%.8lx, 0x%.8lx, 0x%.8lx,\n",
- scramble[i+0], scramble[i+1], scramble[i+2], scramble[i+3]);
- } else {
- fprintf(f, "static const unsigned short %s_", which);
- if (parser)
- fprintf(f, "%s_", parser);
- fprintf(f, "scramble[] = {\n");
- for (i=0; i<=UB1MAXVAL; i+=8)
- fprintf(f,
+ /* A way to make the 1-byte values in tab bigger */
+ if (smax > UB2MAXVAL+1) {
+ fprintf(f, "static const unsigned long %s_", which);
+ if (parser)
+ fprintf(f, "%s_", parser);
+ fprintf(f, "scramble[] = {\n");
+ for (i=0; i<=UB1MAXVAL; i+=4)
+ fprintf(f, "0x%.8lx, 0x%.8lx, 0x%.8lx, 0x%.8lx,\n",
+ scramble[i+0], scramble[i+1], scramble[i+2], scramble[i+3]);
+ } else {
+ fprintf(f, "static const unsigned short %s_", which);
+ if (parser)
+ fprintf(f, "%s_", parser);
+ fprintf(f, "scramble[] = {\n");
+ for (i=0; i<=UB1MAXVAL; i+=8)
+ fprintf(f,
"0x%.4lx, 0x%.4lx, 0x%.4lx, 0x%.4lx, 0x%.4lx, 0x%.4lx, 0x%.4lx, 0x%.4lx,\n",
- scramble[i+0], scramble[i+1], scramble[i+2], scramble[i+3],
- scramble[i+4], scramble[i+5], scramble[i+6], scramble[i+7]);
- }
- fprintf(f, "};\n");
- fprintf(f, "\n");
+ scramble[i+0], scramble[i+1], scramble[i+2], scramble[i+3],
+ scramble[i+4], scramble[i+5], scramble[i+6], scramble[i+7]);
+ }
+ fprintf(f, "};\n");
+ fprintf(f, "\n");
}
if (blen > 0) {
- /* small adjustments to _a_ to make values distinct */
- if (smax <= UB1MAXVAL+1 || blen >= USE_SCRAMBLE)
- fprintf(f, "static const unsigned char %s_", which);
- else
- fprintf(f, "static const unsigned short %s_", which);
- if (parser)
- fprintf(f, "%s_", parser);
- fprintf(f, "tab[] = {\n");
-
- if (blen < 16) {
- for (i=0; i<blen; ++i)
- fprintf(f, "%3ld,", scramble[tab[i].val_b]);
- } else if (blen <= 1024) {
- for (i=0; i<blen; i+=16)
- fprintf(f, "%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,\n",
- scramble[tab[i+0].val_b], scramble[tab[i+1].val_b],
- scramble[tab[i+2].val_b], scramble[tab[i+3].val_b],
- scramble[tab[i+4].val_b], scramble[tab[i+5].val_b],
- scramble[tab[i+6].val_b], scramble[tab[i+7].val_b],
- scramble[tab[i+8].val_b], scramble[tab[i+9].val_b],
- scramble[tab[i+10].val_b], scramble[tab[i+11].val_b],
- scramble[tab[i+12].val_b], scramble[tab[i+13].val_b],
- scramble[tab[i+14].val_b], scramble[tab[i+15].val_b]);
- } else if (blen < USE_SCRAMBLE) {
- for (i=0; i<blen; i+=8)
- fprintf(f, "%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,\n",
- scramble[tab[i+0].val_b], scramble[tab[i+1].val_b],
- scramble[tab[i+2].val_b], scramble[tab[i+3].val_b],
- scramble[tab[i+4].val_b], scramble[tab[i+5].val_b],
- scramble[tab[i+6].val_b], scramble[tab[i+7].val_b]);
- } else {
- for (i=0; i<blen; i+=16)
- fprintf(f, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\n",
- tab[i+0].val_b, tab[i+1].val_b,
- tab[i+2].val_b, tab[i+3].val_b,
- tab[i+4].val_b, tab[i+5].val_b,
- tab[i+6].val_b, tab[i+7].val_b,
- tab[i+8].val_b, tab[i+9].val_b,
- tab[i+10].val_b, tab[i+11].val_b,
- tab[i+12].val_b, tab[i+13].val_b,
- tab[i+14].val_b, tab[i+15].val_b);
- }
- fprintf(f, "};\n");
- fprintf(f, "\n");
+ /* small adjustments to _a_ to make values distinct */
+ if (smax <= UB1MAXVAL+1 || blen >= USE_SCRAMBLE)
+ fprintf(f, "static const unsigned char %s_", which);
+ else
+ fprintf(f, "static const unsigned short %s_", which);
+ if (parser)
+ fprintf(f, "%s_", parser);
+ fprintf(f, "tab[] = {\n");
+
+ if (blen < 16) {
+ for (i=0; i<blen; ++i)
+ fprintf(f, "%3ld,", scramble[tab[i].val_b]);
+ } else if (blen <= 1024) {
+ for (i=0; i<blen; i+=16)
+ fprintf(f, "%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,\n",
+ scramble[tab[i+0].val_b], scramble[tab[i+1].val_b],
+ scramble[tab[i+2].val_b], scramble[tab[i+3].val_b],
+ scramble[tab[i+4].val_b], scramble[tab[i+5].val_b],
+ scramble[tab[i+6].val_b], scramble[tab[i+7].val_b],
+ scramble[tab[i+8].val_b], scramble[tab[i+9].val_b],
+ scramble[tab[i+10].val_b], scramble[tab[i+11].val_b],
+ scramble[tab[i+12].val_b], scramble[tab[i+13].val_b],
+ scramble[tab[i+14].val_b], scramble[tab[i+15].val_b]);
+ } else if (blen < USE_SCRAMBLE) {
+ for (i=0; i<blen; i+=8)
+ fprintf(f, "%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,\n",
+ scramble[tab[i+0].val_b], scramble[tab[i+1].val_b],
+ scramble[tab[i+2].val_b], scramble[tab[i+3].val_b],
+ scramble[tab[i+4].val_b], scramble[tab[i+5].val_b],
+ scramble[tab[i+6].val_b], scramble[tab[i+7].val_b]);
+ } else {
+ for (i=0; i<blen; i+=16)
+ fprintf(f, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\n",
+ tab[i+0].val_b, tab[i+1].val_b,
+ tab[i+2].val_b, tab[i+3].val_b,
+ tab[i+4].val_b, tab[i+5].val_b,
+ tab[i+6].val_b, tab[i+7].val_b,
+ tab[i+8].val_b, tab[i+9].val_b,
+ tab[i+10].val_b, tab[i+11].val_b,
+ tab[i+12].val_b, tab[i+13].val_b,
+ tab[i+14].val_b, tab[i+15].val_b);
+ }
+ fprintf(f, "};\n");
+ fprintf(f, "\n");
}
}
@@ -608,17 +608,17 @@ perfect_dir(FILE *out, const char *which, const char *parser, dir_list *dirs)
ub4 nkeys;
key *keys;
hashform form;
- bstuff *tab; /* table indexed by b */
- hstuff *tabh; /* table indexed by hash value */
- ub4 smax; /* scramble[] values in 0..smax-1, a power of 2 */
- ub4 alen; /* a in 0..alen-1, a power of 2 */
- ub4 blen; /* b in 0..blen-1, a power of 2 */
- ub4 salt; /* a parameter to the hash function */
- gencode final; /* code for final hash */
+ bstuff *tab; /* table indexed by b */
+ hstuff *tabh; /* table indexed by hash value */
+ ub4 smax; /* scramble[] values in 0..smax-1, a power of 2 */
+ ub4 alen; /* a in 0..alen-1, a power of 2 */
+ ub4 blen; /* b in 0..blen-1, a power of 2 */
+ ub4 salt; /* a parameter to the hash function */
+ gencode final; /* code for final hash */
ub4 i;
- ub4 scramble[SCRAMBLE_LEN]; /* used in final hash function */
- char buf[10][80]; /* buffer for generated code */
- char *buf2[10]; /* also for generated code */
+ ub4 scramble[SCRAMBLE_LEN]; /* used in final hash function */
+ char buf[10][80]; /* buffer for generated code */
+ char *buf2[10]; /* also for generated code */
int cpumode = strcmp(which, "cpu") == 0;
dir *d;
@@ -633,60 +633,60 @@ perfect_dir(FILE *out, const char *which, const char *parser, dir_list *dirs)
final.used = 0;
final.len = 10;
for (i=0; i<10; i++)
- final.line[i] = buf[i];
+ final.line[i] = buf[i];
/* build list of keys */
nkeys = 0;
keys = NULL;
STAILQ_FOREACH(d, dirs, link) {
- key *k = yasm_xmalloc(sizeof(key));
+ key *k = yasm_xmalloc(sizeof(key));
- k->name_k = yasm__xstrdup(d->name);
- k->len_k = (ub4)strlen(d->name);
- k->next_k = keys;
- keys = k;
- nkeys++;
+ k->name_k = yasm__xstrdup(d->name);
+ k->len_k = (ub4)strlen(d->name);
+ k->next_k = keys;
+ keys = k;
+ nkeys++;
}
/* find the hash */
findhash(&tab, &tabh, &alen, &blen, &salt, &final,
- scramble, &smax, keys, nkeys, &form);
+ scramble, &smax, keys, nkeys, &form);
/* output the dir table: this should loop up to smax for NORMAL_HP,
* or up to pakd.nkeys for MINIMAL_HP.
*/
fprintf(out, "static const %s_parse_data %s_", which, which);
if (parser)
- fprintf(out, "%s_", parser);
+ fprintf(out, "%s_", parser);
fprintf(out, "pd[%lu] = {\n", nkeys);
for (i=0; i<nkeys; i++) {
- if (tabh[i].key_h) {
- sval *sv;
- STAILQ_FOREACH(d, dirs, link) {
- if (strcmp(d->name, tabh[i].key_h->name_k) == 0)
- break;
- }
- if (!d) {
- report_error("internal error: could not find `%s'",
- tabh[i].key_h->name_k);
- break;
- }
- if (cpumode)
- fprintf(out, "{\"%s\",", d->name);
- else
- fprintf(out, "%s(\"%s\",", d->func, d->name);
- STAILQ_FOREACH(sv, &d->args, link) {
- fprintf(out, " %s", sv->str);
- if (STAILQ_NEXT(sv, link))
- fprintf(out, ",");
- }
- fprintf(out, cpumode ? "}" : ")");
- } else
- fprintf(out, " { NULL }");
-
- if (i < nkeys-1)
- fprintf(out, ",");
- fprintf(out, "\n");
+ if (tabh[i].key_h) {
+ sval *sv;
+ STAILQ_FOREACH(d, dirs, link) {
+ if (strcmp(d->name, tabh[i].key_h->name_k) == 0)
+ break;
+ }
+ if (!d) {
+ report_error("internal error: could not find `%s'",
+ tabh[i].key_h->name_k);
+ break;
+ }
+ if (cpumode)
+ fprintf(out, "{\"%s\",", d->name);
+ else
+ fprintf(out, "%s(\"%s\",", d->func, d->name);
+ STAILQ_FOREACH(sv, &d->args, link) {
+ fprintf(out, " %s", sv->str);
+ if (STAILQ_NEXT(sv, link))
+ fprintf(out, ",");
+ }
+ fprintf(out, cpumode ? "}" : ")");
+ } else
+ fprintf(out, " { NULL }");
+
+ if (i < nkeys-1)
+ fprintf(out, ",");
+ fprintf(out, "\n");
}
fprintf(out, "};\n");
@@ -696,20 +696,20 @@ perfect_dir(FILE *out, const char *which, const char *parser, dir_list *dirs)
/* The hash function */
fprintf(out, "#define tab %s_", which);
if (parser)
- fprintf(out, "%s_", parser);
+ fprintf(out, "%s_", parser);
fprintf(out, "tab\n");
fprintf(out, "static const %s_parse_data *\n%s_", which, which);
if (parser)
- fprintf(out, "%s_", parser);
+ fprintf(out, "%s_", parser);
fprintf(out, "find(const char *key, size_t len)\n");
fprintf(out, "{\n");
fprintf(out, " const %s_parse_data *ret;\n", which);
for (i=0; i<final.used; ++i)
- fprintf(out, final.line[i]);
+ fprintf(out, final.line[i]);
fprintf(out, " if (rsl >= %lu) return NULL;\n", nkeys);
fprintf(out, " ret = &%s_", which);
if (parser)
- fprintf(out, "%s_", parser);
+ fprintf(out, "%s_", parser);
fprintf(out, "pd[rsl];\n");
fprintf(out, " if (strcmp(key, ret->name) != 0) return NULL;\n");
fprintf(out, " return ret;\n");
@@ -729,26 +729,26 @@ static int get_line(FILE *in)
cur_line = next_line;
if (feof(in))
- return 0;
+ return 0;
while (p < &line[1023-128]) {
- if (!fgets(p, 128, in))
- return 1;
- next_line++;
- /* if continuation, strip out leading whitespace */
- if (p > line) {
- char *p2 = p;
- while (isspace(*p2)) p2++;
- if (p2 > p)
- memmove(p, p2, strlen(p2)+1);
- }
- while (*p) p++;
- if (p[-2] != '\\' || p[-1] != '\n') {
- if (p[-1] == '\n')
- p[-1] = '\0';
- return 1;
- }
- p -= 2;
+ if (!fgets(p, 128, in))
+ return 1;
+ next_line++;
+ /* if continuation, strip out leading whitespace */
+ if (p > line) {
+ char *p2 = p;
+ while (isspace(*p2)) p2++;
+ if (p2 > p)
+ memmove(p, p2, strlen(p2)+1);
+ }
+ while (*p) p++;
+ if (p[-2] != '\\' || p[-1] != '\n') {
+ if (p[-1] == '\n')
+ p[-1] = '\0';
+ return 1;
+ }
+ p -= 2;
}
return 0;
}
@@ -781,17 +781,17 @@ main(int argc, char *argv[])
dir_byp *db;
for (i=0; i<NUM_DIRS; i++)
- count[i] = 0;
+ count[i] = 0;
if (argc != 3) {
- fprintf(stderr, "Usage: gap <in> <out>\n");
- return EXIT_FAILURE;
+ fprintf(stderr, "Usage: gap <in> <out>\n");
+ return EXIT_FAILURE;
}
in = fopen(argv[1], "rt");
if (!in) {
- fprintf(stderr, "Could not open `%s' for reading\n", argv[1]);
- return EXIT_FAILURE;
+ fprintf(stderr, "Could not open `%s' for reading\n", argv[1]);
+ return EXIT_FAILURE;
}
STAILQ_INIT(&insnprefix_byp);
@@ -800,54 +800,54 @@ main(int argc, char *argv[])
/* Parse input file */
while (get_line(in)) {
- int found;
- /*printf("%s\n", line);*/
- tok = strtok(line, " \t\n");
- if (!tok)
- continue;
-
- /* Comments start with # as the first thing on a line */
- if (tok[0] == '#')
- continue;
-
- /* Look for directive */
- found = 0;
- for (i=0; i<sizeof(directives)/sizeof(directives[0]); i++) {
- if (strcmp(tok, directives[i].name) == 0) {
- count[directives[i].indx]++;
- directives[i].handler();
- found = 1;
- break;
- }
- }
- if (!found)
- report_error("unknown directive `%s'\n", tok);
+ int found;
+ /*printf("%s\n", line);*/
+ tok = strtok(line, " \t\n");
+ if (!tok)
+ continue;
+
+ /* Comments start with # as the first thing on a line */
+ if (tok[0] == '#')
+ continue;
+
+ /* Look for directive */
+ found = 0;
+ for (i=0; i<sizeof(directives)/sizeof(directives[0]); i++) {
+ if (strcmp(tok, directives[i].name) == 0) {
+ count[directives[i].indx]++;
+ directives[i].handler();
+ found = 1;
+ break;
+ }
+ }
+ if (!found)
+ report_error("unknown directive `%s'\n", tok);
}
/* Output some informational statistics */
printf("Directives read:\n");
for (i=0; i<sizeof(directives)/sizeof(directives[0]); i++)
- printf("\t%d\t%s\n", count[directives[i].indx], directives[i].name);
+ printf("\t%d\t%s\n", count[directives[i].indx], directives[i].name);
if (errors > 0)
- return EXIT_FAILURE;
+ return EXIT_FAILURE;
out = fopen(argv[2], "wt");
if (!out) {
- fprintf(stderr, "Could not open `%s' for writing\n", argv[2]);
- return EXIT_FAILURE;
+ fprintf(stderr, "Could not open `%s' for writing\n", argv[2]);
+ return EXIT_FAILURE;
}
/* Get perfect hashes for the three lists of directives */
STAILQ_FOREACH(db, &insnprefix_byp, link)
- perfect_dir(out, "insnprefix", db->parser, &db->dirs);
+ perfect_dir(out, "insnprefix", db->parser, &db->dirs);
STAILQ_FOREACH(db, &cpu_byp, link)
- perfect_dir(out, "cpu", db->parser, &db->dirs);
+ perfect_dir(out, "cpu", db->parser, &db->dirs);
STAILQ_FOREACH(db, &regtmod_byp, link)
- perfect_dir(out, "regtmod", db->parser, &db->dirs);
+ perfect_dir(out, "regtmod", db->parser, &db->dirs);
if (errors > 0)
- return EXIT_FAILURE;
+ return EXIT_FAILURE;
return EXIT_SUCCESS;
}
diff --git a/tools/gap/perfect.c b/tools/gap/perfect.c
index c56304f6..d1218040 100644
--- a/tools/gap/perfect.c
+++ b/tools/gap/perfect.c
@@ -122,10 +122,10 @@ static void checkdup(
{
case STRING_HT:
if ((key1->len_k == key2->len_k) &&
- !memcmp(key1->name_k, key2->name_k, (size_t)key1->len_k))
+ !memcmp(key1->name_k, key2->name_k, (size_t)key1->len_k))
{
fprintf(stderr, "perfect.c: Duplicates keys! %.*s\n",
- (int)key1->len_k, key1->name_k);
+ (int)key1->len_k, key1->name_k);
exit(EXIT_FAILURE);
}
break;
@@ -138,7 +138,7 @@ static void checkdup(
break;
case AB_HT:
fprintf(stderr, "perfect.c: Duplicate keys! %.8lx %.8lx\n",
- key1->a_k, key1->b_k);
+ key1->a_k, key1->b_k);
exit(EXIT_FAILURE);
break;
default:
@@ -171,15 +171,15 @@ static int inittab(
key *otherkey;
for (otherkey=tabb[mykey->b_k].list_b;
- otherkey;
- otherkey=otherkey->nextb_k)
+ otherkey;
+ otherkey=otherkey->nextb_k)
{
if (mykey->a_k == otherkey->a_k)
{
nocollision = FALSE;
- checkdup(mykey, otherkey, form);
- if (!complete)
- return FALSE;
+ checkdup(mykey, otherkey, form);
+ if (!complete)
+ return FALSE;
}
}
++tabb[mykey->b_k].listlen_b;
@@ -216,14 +216,14 @@ static void initnorm(
}
final->used = 4;
sprintf(final->line[0],
- " unsigned long i,state[CHECKSTATE],rsl;\n");
+ " unsigned long i,state[CHECKSTATE],rsl;\n");
sprintf(final->line[1],
- " for (i=0; i<CHECKSTATE; ++i) state[i]=0x%lx;\n",initlev);
+ " for (i=0; i<CHECKSTATE; ++i) state[i]=0x%lx;\n",initlev);
sprintf(final->line[2],
- " phash_checksum(key, len, state);\n");
+ " phash_checksum(key, len, state);\n");
sprintf(final->line[3],
- " rsl = ((state[0]&0x%lx)^scramble[tab[state[1]&0x%lx]]);\n",
- alen-1, blen-1);
+ " rsl = ((state[0]&0x%lx)^scramble[tab[state[1]&0x%lx]]);\n",
+ alen-1, blen-1);
}
else
{
@@ -238,7 +238,7 @@ static void initnorm(
}
final->used = 2;
sprintf(final->line[0],
- " unsigned long rsl, val = phash_lookup(key, len, 0x%lxUL);\n", initlev);
+ " unsigned long rsl, val = phash_lookup(key, len, 0x%lxUL);\n", initlev);
if (smax <= 1)
{
sprintf(final->line[1], " rsl = 0;\n");
@@ -246,12 +246,12 @@ static void initnorm(
else if (blen < USE_SCRAMBLE)
{
sprintf(final->line[1], " rsl = ((val>>%ld)^tab[val&0x%lx]);\n",
- UB4BITS-phash_log2(alen), blen-1);
+ UB4BITS-phash_log2(alen), blen-1);
}
else
{
sprintf(final->line[1], " rsl = ((val>>%ld)^scramble[tab[val&0x%lx]]);\n",
- UB4BITS-phash_log2(alen), blen-1);
+ UB4BITS-phash_log2(alen), blen-1);
}
}
}
@@ -293,12 +293,12 @@ static void initinl(
else if (blen < USE_SCRAMBLE)
{
sprintf(final->line[0], " unsigned long rsl = ((val & 0x%lx) ^ tab[val >> %ld]);\n",
- amask, UB4BITS-blog);
+ amask, UB4BITS-blog);
}
else
{
sprintf(final->line[0], " unsigned long rsl = ((val & 0x%lx) ^ scramble[tab[val >> %ld]]);\n",
- amask, UB4BITS-blog);
+ amask, UB4BITS-blog);
}
}
@@ -369,7 +369,7 @@ static void duplicates(
for (i=0; i<blen; ++i)
for (key1=tabb[i].list_b; key1; key1=key1->nextb_k)
for (key2=key1->nextb_k; key2; key2=key2->nextb_k)
- checkdup(key1, key2, form);
+ checkdup(key1, key2, form);
}
@@ -403,7 +403,7 @@ static int apply(
hash = mykey->a_k^stabb;
if (mykey == tabh[hash].key_h)
{ /* erase hash for all of child's siblings */
- tabh[hash].key_h = (key *)0;
+ tabh[hash].key_h = (key *)0;
}
}
@@ -417,13 +417,13 @@ static int apply(
hash = mykey->a_k^stabb;
if (rollback)
{
- if (parent == 0) continue; /* root never had a hash */
+ if (parent == 0) continue; /* root never had a hash */
}
else if (tabh[hash].key_h)
{
- /* very rare: roll back any changes */
- apply(tabb, tabh, tabq, blen, scramble, tail, TRUE);
- return FALSE; /* failure, collision */
+ /* very rare: roll back any changes */
+ apply(tabb, tabh, tabq, blen, scramble, tail, TRUE);
+ return FALSE; /* failure, collision */
}
tabh[hash].key_h = mykey;
}
@@ -489,26 +489,26 @@ static int augment(
for (mykey = myb->list_b; mykey; mykey=mykey->nextb_k)
{
- key *childkey;
- ub4 hash = mykey->a_k^scramble[i];
-
- if (hash >= highhash) break; /* out of bounds */
- childkey = tabh[hash].key_h;
-
- if (childkey)
- {
- bstuff *hitb = &tabb[childkey->b_k];
-
- if (childb)
- {
- if (childb != hitb) break; /* hit at most one child b */
- }
- else
- {
- childb = hitb; /* remember this as childb */
- if (childb->water_b == highwater) break; /* already explored */
- }
- }
+ key *childkey;
+ ub4 hash = mykey->a_k^scramble[i];
+
+ if (hash >= highhash) break; /* out of bounds */
+ childkey = tabh[hash].key_h;
+
+ if (childkey)
+ {
+ bstuff *hitb = &tabb[childkey->b_k];
+
+ if (childb)
+ {
+ if (childb != hitb) break; /* hit at most one child b */
+ }
+ else
+ {
+ childb = hitb; /* remember this as childb */
+ if (childb->water_b == highwater) break; /* already explored */
+ }
+ }
}
if (mykey) continue; /* myb with i has multiple collisions */
@@ -522,11 +522,11 @@ static int augment(
if (!childb)
{ /* found an *i* with no collisions? */
- /* try to apply the augmenting path */
- if (apply(tabb, tabh, tabq, blen, scramble, tail, FALSE))
- return TRUE; /* success, item was added to the perfect hash */
+ /* try to apply the augmenting path */
+ if (apply(tabb, tabh, tabq, blen, scramble, tail, FALSE))
+ return TRUE; /* success, item was added to the perfect hash */
- --tail; /* don't know how to handle such a child! */
+ --tail; /* don't know how to handle such a child! */
}
}
}
@@ -550,8 +550,8 @@ static int perfect(
/* clear any state from previous attempts */
memset((void *)tabh, 0,
- (size_t)(sizeof(hstuff)*
- ((form->perfect == MINIMAL_HP) ? nkeys : smax)));
+ (size_t)(sizeof(hstuff)*
+ ((form->perfect == MINIMAL_HP) ? nkeys : smax)));
memset((void *)tabq, 0, (size_t)(sizeof(qstuff)*(blen+1)));
for (maxkeys=0,i=0; i<blen; ++i)
@@ -562,12 +562,12 @@ static int perfect(
for (j=maxkeys; j>0; --j)
for (i=0; i<blen; ++i)
if (tabb[i].listlen_b == j)
- if (!augment(tabb, tabh, tabq, blen, scramble, smax, &tabb[i], nkeys,
- i+1, form))
- {
- printf("fail to map group of size %ld for tab size %ld\n", j, blen);
- return FALSE;
- }
+ if (!augment(tabb, tabh, tabq, blen, scramble, smax, &tabb[i], nkeys,
+ i+1, form))
+ {
+ printf("fail to map group of size %ld for tab size %ld\n", j, blen);
+ return FALSE;
+ }
/* Success! We found a perfect hash of all keys into 0..nkeys-1. */
return TRUE;
@@ -621,7 +621,7 @@ static void hash_ab(
*tabb = (bstuff *)yasm_xmalloc((size_t)(sizeof(bstuff)*(*blen)));
tabq = (qstuff *)yasm_xmalloc(sizeof(qstuff)*(*blen+1));
tabh = (hstuff *)yasm_xmalloc(sizeof(hstuff)*(form->perfect == MINIMAL_HP ?
- nkeys : *smax));
+ nkeys : *smax));
/* check that (a,b) are distinct and put them in tabb indexed by b */
(void)inittab(*tabb, *blen, keys, form, FALSE);
@@ -641,11 +641,11 @@ static void hash_ab(
*smax = *smax * 2;
scrambleinit(scramble, *smax);
tabh = (hstuff *)yasm_xmalloc(sizeof(hstuff)*(form->perfect == MINIMAL_HP ?
- nkeys : *smax));
+ nkeys : *smax));
if (!perfect(*tabb, tabh, tabq, *blen, *smax, scramble, nkeys, form))
{
- printf("fatal error: Cannot find perfect hash for user (A,B) pairs\n");
- exit(EXIT_FAILURE);
+ printf("fatal error: Cannot find perfect hash for user (A,B) pairs\n");
+ exit(EXIT_FAILURE);
}
}
}
@@ -736,10 +736,10 @@ static void initalen(
*blen = *smax; /* go for function speed not space */
else if (*smax/4 <= (1<<14))
*blen = ((nkeys <= *smax*0.56) ? *smax/32 :
- (nkeys <= *smax*0.74) ? *smax/16 : *smax/8);
+ (nkeys <= *smax*0.74) ? *smax/16 : *smax/8);
else
*blen = ((nkeys <= *smax*0.6) ? *smax/16 :
- (nkeys <= *smax*0.8) ? *smax/8 : *smax/4);
+ (nkeys <= *smax*0.8) ? *smax/8 : *smax/4);
if ((form->speed == FAST_HS) && (*blen < *smax/8))
*blen = *smax/8;
@@ -769,31 +769,31 @@ static void initalen(
case 17:
if (form->speed == FAST_HS)
{
- *alen = *smax/2;
- *blen = *smax/4;
+ *alen = *smax/2;
+ *blen = *smax/4;
}
else if (*smax/4 < USE_SCRAMBLE)
{
- *alen = ((nkeys <= *smax*0.52) ? *smax/8 : *smax/4);
- *blen = ((nkeys <= *smax*0.52) ? *smax/8 : *smax/4);
+ *alen = ((nkeys <= *smax*0.52) ? *smax/8 : *smax/4);
+ *blen = ((nkeys <= *smax*0.52) ? *smax/8 : *smax/4);
}
else
{
- *alen = ((nkeys <= *smax*(5.0/8.0)) ? *smax/8 :
- (nkeys <= *smax*(3.0/4.0)) ? *smax/4 : *smax/2);
- *blen = *smax/4; /* always give the small size a shot */
+ *alen = ((nkeys <= *smax*(5.0/8.0)) ? *smax/8 :
+ (nkeys <= *smax*(3.0/4.0)) ? *smax/4 : *smax/2);
+ *blen = *smax/4; /* always give the small size a shot */
}
break;
case 18:
if (form->speed == FAST_HS)
{
- *alen = *smax/2;
- *blen = *smax/2;
+ *alen = *smax/2;
+ *blen = *smax/2;
}
else
{
- *alen = *smax/8; /* never require the multiword hash */
- *blen = (nkeys <= *smax*(5.0/8.0)) ? *smax/4 : *smax/2;
+ *alen = *smax/8; /* never require the multiword hash */
+ *blen = (nkeys <= *smax*(5.0/8.0)) ? *smax/4 : *smax/2;
}
break;
case 19:
@@ -816,7 +816,7 @@ static void initalen(
*/
void findhash(
bstuff **tabb, /* output, tab[] of the perfect hash, length *blen */
- hstuff **tabh, /* output, table of keys indexed by hash value */
+ hstuff **tabh, /* output, table of keys indexed by hash value */
ub4 *alen, /* output, 0..alen-1 is range for a of (a,b) */
ub4 *blen, /* output, 0..blen-1 is range for b of (a,b) */
ub4 *salt, /* output, initializes initial hash */
@@ -837,7 +837,7 @@ void findhash(
if (form->hashtype == AB_HT)
{
hash_ab(tabb, alen, blen, salt, final,
- scramble, smax, keys, nkeys, form);
+ scramble, smax, keys, nkeys, form);
return;
}
@@ -853,7 +853,7 @@ void findhash(
*tabb = (bstuff *)yasm_xmalloc((size_t)(sizeof(bstuff)*(*blen)));
tabq = (qstuff *)yasm_xmalloc(sizeof(qstuff)*(*blen+1));
*tabh = (hstuff *)yasm_xmalloc(sizeof(hstuff)*(form->perfect == MINIMAL_HP ?
- nkeys : *smax));
+ nkeys : *smax));
/* Actually find the perfect hash */
*salt = 0;
@@ -865,7 +865,7 @@ void findhash(
/* Try to find distinct (A,B) for all keys */
rslinit = initkey(keys, nkeys, *tabb, *alen, *blen, *smax, trysalt,
- form, final);
+ form, final);
if (rslinit == 2)
{ /* initkey actually found a perfect hash, not just distinct (a,b) */
@@ -878,27 +878,27 @@ void findhash(
/* didn't find distinct (a,b) */
if (++bad_initkey >= RETRY_INITKEY)
{
- /* Try to put more bits in (A,B) to make distinct (A,B) more likely */
- if (*alen < maxalen)
- {
- *alen *= 2;
- }
- else if (*blen < *smax)
- {
- *blen *= 2;
- free(tabq);
- free(*tabb);
- *tabb = (bstuff *)yasm_xmalloc((size_t)(sizeof(bstuff)*(*blen)));
- tabq = (qstuff *)yasm_xmalloc((size_t)(sizeof(qstuff)*(*blen+1)));
- }
- else
- {
- duplicates(*tabb, *blen, keys, form); /* check for duplicates */
- printf("fatal error: Cannot perfect hash: cannot find distinct (A,B)\n");
- exit(EXIT_FAILURE);
- }
- bad_initkey = 0;
- bad_perfect = 0;
+ /* Try to put more bits in (A,B) to make distinct (A,B) more likely */
+ if (*alen < maxalen)
+ {
+ *alen *= 2;
+ }
+ else if (*blen < *smax)
+ {
+ *blen *= 2;
+ free(tabq);
+ free(*tabb);
+ *tabb = (bstuff *)yasm_xmalloc((size_t)(sizeof(bstuff)*(*blen)));
+ tabq = (qstuff *)yasm_xmalloc((size_t)(sizeof(qstuff)*(*blen+1)));
+ }
+ else
+ {
+ duplicates(*tabb, *blen, keys, form); /* check for duplicates */
+ printf("fatal error: Cannot perfect hash: cannot find distinct (A,B)\n");
+ exit(EXIT_FAILURE);
+ }
+ bad_initkey = 0;
+ bad_perfect = 0;
}
continue; /* two keys have same (a,b) pair */
}
@@ -909,23 +909,23 @@ void findhash(
if (!perfect(*tabb, *tabh, tabq, *blen, *smax, scramble, nkeys, form))
{
if ((form->hashtype != INT_HT && ++bad_perfect >= RETRY_PERFECT) ||
- (form->hashtype == INT_HT && ++bad_perfect >= RETRY_HEX))
+ (form->hashtype == INT_HT && ++bad_perfect >= RETRY_HEX))
{
- if (*blen < *smax)
- {
- *blen *= 2;
- free(*tabb);
- free(tabq);
- *tabb = (bstuff *)yasm_xmalloc((size_t)(sizeof(bstuff)*(*blen)));
- tabq = (qstuff *)yasm_xmalloc((size_t)(sizeof(qstuff)*(*blen+1)));
- --trysalt; /* we know this salt got distinct (A,B) */
- }
- else
- {
- printf("fatal error: Cannot perfect hash: cannot build tab[]\n");
- exit(EXIT_FAILURE);
- }
- bad_perfect = 0;
+ if (*blen < *smax)
+ {
+ *blen *= 2;
+ free(*tabb);
+ free(tabq);
+ *tabb = (bstuff *)yasm_xmalloc((size_t)(sizeof(bstuff)*(*blen)));
+ tabq = (qstuff *)yasm_xmalloc((size_t)(sizeof(qstuff)*(*blen+1)));
+ --trysalt; /* we know this salt got distinct (A,B) */
+ }
+ else
+ {
+ printf("fatal error: Cannot perfect hash: cannot build tab[]\n");
+ exit(EXIT_FAILURE);
+ }
+ bad_perfect = 0;
}
continue;
}
@@ -1045,37 +1045,37 @@ hashform *form; /* user directives */
else if (blen <= 1024)
{
for (i=0; i<blen; i+=16)
- fprintf(f, "%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,\n",
- scramble[tab[i+0].val_b], scramble[tab[i+1].val_b],
- scramble[tab[i+2].val_b], scramble[tab[i+3].val_b],
- scramble[tab[i+4].val_b], scramble[tab[i+5].val_b],
- scramble[tab[i+6].val_b], scramble[tab[i+7].val_b],
- scramble[tab[i+8].val_b], scramble[tab[i+9].val_b],
- scramble[tab[i+10].val_b], scramble[tab[i+11].val_b],
- scramble[tab[i+12].val_b], scramble[tab[i+13].val_b],
- scramble[tab[i+14].val_b], scramble[tab[i+15].val_b]);
+ fprintf(f, "%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,\n",
+ scramble[tab[i+0].val_b], scramble[tab[i+1].val_b],
+ scramble[tab[i+2].val_b], scramble[tab[i+3].val_b],
+ scramble[tab[i+4].val_b], scramble[tab[i+5].val_b],
+ scramble[tab[i+6].val_b], scramble[tab[i+7].val_b],
+ scramble[tab[i+8].val_b], scramble[tab[i+9].val_b],
+ scramble[tab[i+10].val_b], scramble[tab[i+11].val_b],
+ scramble[tab[i+12].val_b], scramble[tab[i+13].val_b],
+ scramble[tab[i+14].val_b], scramble[tab[i+15].val_b]);
}
else if (blen < USE_SCRAMBLE)
{
for (i=0; i<blen; i+=8)
- fprintf(f, "%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,\n",
- scramble[tab[i+0].val_b], scramble[tab[i+1].val_b],
- scramble[tab[i+2].val_b], scramble[tab[i+3].val_b],
- scramble[tab[i+4].val_b], scramble[tab[i+5].val_b],
- scramble[tab[i+6].val_b], scramble[tab[i+7].val_b]);
+ fprintf(f, "%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,\n",
+ scramble[tab[i+0].val_b], scramble[tab[i+1].val_b],
+ scramble[tab[i+2].val_b], scramble[tab[i+3].val_b],
+ scramble[tab[i+4].val_b], scramble[tab[i+5].val_b],
+ scramble[tab[i+6].val_b], scramble[tab[i+7].val_b]);
}
else
{
for (i=0; i<blen; i+=16)
- fprintf(f, "%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,\n",
- tab[i+0].val_b, tab[i+1].val_b,
- tab[i+2].val_b, tab[i+3].val_b,
- tab[i+4].val_b, tab[i+5].val_b,
- tab[i+6].val_b, tab[i+7].val_b,
- tab[i+8].val_b, tab[i+9].val_b,
- tab[i+10].val_b, tab[i+11].val_b,
- tab[i+12].val_b, tab[i+13].val_b,
- tab[i+14].val_b, tab[i+15].val_b);
+ fprintf(f, "%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,\n",
+ tab[i+0].val_b, tab[i+1].val_b,
+ tab[i+2].val_b, tab[i+3].val_b,
+ tab[i+4].val_b, tab[i+5].val_b,
+ tab[i+6].val_b, tab[i+7].val_b,
+ tab[i+8].val_b, tab[i+9].val_b,
+ tab[i+10].val_b, tab[i+11].val_b,
+ tab[i+12].val_b, tab[i+13].val_b,
+ tab[i+14].val_b, tab[i+15].val_b);
}
fprintf(f, "};\n");
fprintf(f, "\n");
@@ -1149,7 +1149,7 @@ hashform *form; /* user directives */
/* find the hash */
findhash(&tab, &alen, &blen, &salt, &final,
- scramble, &smax, keys, nkeys, form);
+ scramble, &smax, keys, nkeys, form);
/* generate the phash.c file */
make_c(tab, smax, blen, scramble, &final, form);
diff --git a/tools/gap/perfect.h b/tools/gap/perfect.h
index bfb60010..b78d943b 100644
--- a/tools/gap/perfect.h
+++ b/tools/gap/perfect.h
@@ -122,11 +122,11 @@ ub4 phash_log2(ub4 x);
/* Given the keys, scramble[], and hash mode, find the perfect hash */
void findhash(bstuff **tabb, hstuff **tabh, ub4 *alen, ub4 *blen, ub4 *salt,
- gencode *final, ub4 *scramble, ub4 *smax, key *keys, ub4 nkeys,
- hashform *form);
+ gencode *final, ub4 *scramble, ub4 *smax, key *keys, ub4 nkeys,
+ hashform *form);
/* private, but in a different file because it's excessively verbose */
int inithex(key *keys, ub4 nkeys, ub4 alen, ub4 blen, ub4 smax, ub4 salt,
- gencode *final, hashform *form);
+ gencode *final, hashform *form);
#endif /* PERFECT */
diff --git a/tools/xdf/xdfdump.c b/tools/xdf/xdfdump.c
index c970d7a1..e376636a 100644
--- a/tools/xdf/xdfdump.c
+++ b/tools/xdf/xdfdump.c
@@ -75,25 +75,25 @@ get_sect_name(u32 idx, FILE *f, size_t symtab_off, size_t secttab_off)
void
print_symbol(const SYMBOL_ENTRY *syment, FILE *f, size_t symtab_off,
- size_t secttab_off)
+ size_t secttab_off)
{
int first = 1;
printf("\tOffset=0x%08X Flags=", syment->e_sect_off);
if (syment->e_flags & XDF_SYM_EXTERN)
- printf("%sEXTERN", first-->0?"":"|");
+ printf("%sEXTERN", first-->0?"":"|");
if (syment->e_flags & XDF_SYM_GLOBAL)
- printf("%sGLOBAL", first-->0?"":"|");
+ printf("%sGLOBAL", first-->0?"":"|");
if (syment->e_flags & XDF_SYM_EQU)
- printf("%sEQU", first-->0?"":"|");
+ printf("%sEQU", first-->0?"":"|");
if (first>0)
- printf("None");
+ printf("None");
printf(" Name=`%s' Section=", get_syment_name(syment, f));
if ((long)syment->e_sect_idx < 0)
- printf("%d\n", syment->e_sect_idx);
+ printf("%d\n", syment->e_sect_idx);
else
- printf("`%s' (%d)\n",
- get_sect_name(syment->e_sect_idx, f, symtab_off, secttab_off),
- syment->e_sect_idx);
+ printf("`%s' (%d)\n",
+ get_sect_name(syment->e_sect_idx, f, symtab_off, secttab_off),
+ syment->e_sect_idx);
}
void
@@ -101,27 +101,27 @@ print_reloc(const RELOCATION_ENTRY *relocent, FILE *f, size_t symtab_off)
{
const char *type = "UNK";
switch (relocent->r_type) {
- case XDF_RELOC_REL:
- type = "REL";
- break;
- case XDF_RELOC_WRT:
- type = "WRT";
- break;
- case XDF_RELOC_RIP:
- type = "RIP";
- break;
- case XDF_RELOC_SEG:
- type = "SEG";
- break;
+ case XDF_RELOC_REL:
+ type = "REL";
+ break;
+ case XDF_RELOC_WRT:
+ type = "WRT";
+ break;
+ case XDF_RELOC_RIP:
+ type = "RIP";
+ break;
+ case XDF_RELOC_SEG:
+ type = "SEG";
+ break;
}
printf("\t Offset=0x%08X Type=%s Size=%d Shift=%d Target=`%s' (%d)",
- relocent->r_off, type, relocent->r_size, relocent->r_shift,
- get_sym_name(relocent->r_targ_idx, f, symtab_off),
- relocent->r_targ_idx);
+ relocent->r_off, type, relocent->r_size, relocent->r_shift,
+ get_sym_name(relocent->r_targ_idx, f, symtab_off),
+ relocent->r_targ_idx);
if (relocent->r_type == XDF_RELOC_WRT)
- printf(" Base=`%s' (%d)",
- get_sym_name(relocent->r_base_idx, f, symtab_off),
- relocent->r_base_idx);
+ printf(" Base=`%s' (%d)",
+ get_sym_name(relocent->r_base_idx, f, symtab_off),
+ relocent->r_base_idx);
printf("\n");
}
@@ -131,54 +131,54 @@ print_section(const SECTION_HEADER *secthead, FILE *f, size_t symtab_off)
int first = 1;
u32 i;
printf("Section `%s' (section name symtab %d):\n",
- get_sym_name(secthead->s_name_idx, f, symtab_off),
- secthead->s_name_idx);
+ get_sym_name(secthead->s_name_idx, f, symtab_off),
+ secthead->s_name_idx);
printf("\tPhysical Address=0x%016llX\n", secthead->s_addr);
printf("\tVirtual Address=0x%016llX\n", secthead->s_vaddr);
printf("\tAlign=%d\n", secthead->s_align);
printf("\tFlags=");
if (secthead->s_flags & XDF_SECT_ABSOLUTE)
- printf("%sABSOLUTE", first-->0?"":"|");
+ printf("%sABSOLUTE", first-->0?"":"|");
if (secthead->s_flags & XDF_SECT_FLAT)
- printf("%sFLAT", first-->0?"":"|");
+ printf("%sFLAT", first-->0?"":"|");
if (secthead->s_flags & XDF_SECT_BSS)
- printf("%sBSS", first-->0?"":"|");
+ printf("%sBSS", first-->0?"":"|");
if (secthead->s_flags & XDF_SECT_USE_16)
- printf("%sUSE16", first-->0?"":"|");
+ printf("%sUSE16", first-->0?"":"|");
if (secthead->s_flags & XDF_SECT_USE_32)
- printf("%sUSE32", first-->0?"":"|");
+ printf("%sUSE32", first-->0?"":"|");
if (secthead->s_flags & XDF_SECT_USE_64)
- printf("%sUSE64", first-->0?"":"|");
+ printf("%sUSE64", first-->0?"":"|");
if (first>0)
- printf("None");
+ printf("None");
printf("\n\tData Offset=0x%08X\n", secthead->s_data_off);
printf("\tData Size=%d\n", secthead->s_data_size);
if (!(secthead->s_flags & XDF_SECT_BSS) && secthead->s_data_size > 0) {
- printf("\tSection Data:");
- long oldpos = ftell(f);
- fseek(f, secthead->s_data_off, SEEK_SET);
- for (i=0; i<secthead->s_data_size; i++) {
- if (i % 16 == 0)
- printf("\n\t\t%08X:", i);
- if (i % 2 == 0)
- printf(" ");
- printf("%02X", fgetc(f));
- }
- printf("\n");
- fseek(f, oldpos, SEEK_SET);
+ printf("\tSection Data:");
+ long oldpos = ftell(f);
+ fseek(f, secthead->s_data_off, SEEK_SET);
+ for (i=0; i<secthead->s_data_size; i++) {
+ if (i % 16 == 0)
+ printf("\n\t\t%08X:", i);
+ if (i % 2 == 0)
+ printf(" ");
+ printf("%02X", fgetc(f));
+ }
+ printf("\n");
+ fseek(f, oldpos, SEEK_SET);
}
printf("\tReloc Table Offset=0x%08X\n", secthead->s_reltab_off);
printf("\tNum Relocs=%d\n", secthead->s_num_reloc);
if (secthead->s_num_reloc > 0) {
- printf("\tRelocations:\n");
- long oldpos = ftell(f);
- fseek(f, secthead->s_reltab_off, SEEK_SET);
- for (i=0; i<secthead->s_num_reloc; i++) {
- RELOCATION_ENTRY relocent;
- fread(&relocent, sizeof(relocent), 1, f);
- print_reloc(&relocent, f, symtab_off);
- }
- fseek(f, oldpos, SEEK_SET);
+ printf("\tRelocations:\n");
+ long oldpos = ftell(f);
+ fseek(f, secthead->s_reltab_off, SEEK_SET);
+ for (i=0; i<secthead->s_num_reloc; i++) {
+ RELOCATION_ENTRY relocent;
+ fread(&relocent, sizeof(relocent), 1, f);
+ print_reloc(&relocent, f, symtab_off);
+ }
+ fseek(f, oldpos, SEEK_SET);
}
}
@@ -191,37 +191,37 @@ main(int argc, char **argv)
u32 i;
if (argc != 2) {
- fprintf(stderr, "Usage: %s <xdf>\n", argv[0]);
- return EXIT_FAILURE;
+ fprintf(stderr, "Usage: %s <xdf>\n", argv[0]);
+ return EXIT_FAILURE;
}
f = fopen(argv[1], "rb");
if (!f) {
- fprintf(stderr, "Could not open `%s'\n", argv[1]);
- return EXIT_FAILURE;
+ fprintf(stderr, "Could not open `%s'\n", argv[1]);
+ return EXIT_FAILURE;
}
fread(&filehead, sizeof(filehead), 1, f);
if (filehead.f_magic != XDF_MAGIC) {
- fprintf(stderr, "Magic number mismatch (expected %08X, got %08X\n",
- XDF_MAGIC, filehead.f_magic);
- return EXIT_FAILURE;
+ fprintf(stderr, "Magic number mismatch (expected %08X, got %08X\n",
+ XDF_MAGIC, filehead.f_magic);
+ return EXIT_FAILURE;
}
print_file_header(&filehead);
symtab_off = sizeof(FILE_HEADER)+filehead.f_nsect*sizeof(SECTION_HEADER);
for (i=0; i<filehead.f_nsect; i++) {
- SECTION_HEADER secthead;
- fread(&secthead, sizeof(secthead), 1, f);
- print_section(&secthead, f, symtab_off);
+ SECTION_HEADER secthead;
+ fread(&secthead, sizeof(secthead), 1, f);
+ print_section(&secthead, f, symtab_off);
}
printf("Symbol Table:\n");
for (i=0; i<filehead.f_nsyms; i++) {
- SYMBOL_ENTRY syment;
- fread(&syment, sizeof(syment), 1, f);
- print_symbol(&syment, f, symtab_off, sizeof(FILE_HEADER));
+ SYMBOL_ENTRY syment;
+ fread(&syment, sizeof(syment), 1, f);
+ print_symbol(&syment, f, symtab_off, sizeof(FILE_HEADER));
}
return EXIT_SUCCESS;