summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2003-03-29 00:58:07 +0000
committerBruno Haible <bruno@clisp.org>2003-03-29 00:58:07 +0000
commite66e3563dd0f9370b298c35a0aefda2d8ed70691 (patch)
tree18479e91293c43d74604e662f7fcd2bab6c517f3 /src
parent85ac0f155c74890f63a179ba9a61cbd7d2a948c7 (diff)
downloadgperf-e66e3563dd0f9370b298c35a0aefda2d8ed70691.tar.gz
New option for position-independent code.
Diffstat (limited to 'src')
-rw-r--r--src/options.cc14
-rw-r--r--src/options.h5
-rw-r--r--src/output.cc13
3 files changed, 26 insertions, 6 deletions
diff --git a/src/options.cc b/src/options.cc
index 88dacf2..29d0b7b 100644
--- a/src/options.cc
+++ b/src/options.cc
@@ -66,7 +66,7 @@ static const char *const DEFAULT_DELIMITERS = ",";
void
Options::short_usage (FILE * stream) const
{
- fprintf (stream, "Usage: %s [-cCdDef[num]F<initializers>GhH<hashname>i<init>Ij<jump>k<keys>K<keyname>lL<language>m<num>nN<function name>ors<size>S<switches>tTvW<wordlistname>Z<class name>7] [input-file]\n"
+ fprintf (stream, "Usage: %s [-cCdDef[num]F<initializers>GhH<hashname>i<init>Ij<jump>k<keys>K<keyname>lL<language>m<num>nN<function name>oPrs<size>S<switches>tTvW<wordlistname>Z<class name>7] [input-file]\n"
"Try '%s --help' for more information.\n",
program_name, program_name);
}
@@ -159,6 +159,10 @@ Options::long_usage (FILE * stream) const
" global variable, rather than hiding it inside of the\n"
" lookup function (which is the default behavior).\n");
fprintf (stream,
+ " -P, --pic Optimize the generated table for inclusion in shared\n"
+ " libraries. This reduces the startup time of programs\n"
+ " using a shared library containing the generated code.\n");
+ fprintf (stream,
" -W, --word-array-name=NAME\n"
" Specify name of word list array. Default name is\n"
" 'wordlist'.\n");
@@ -631,6 +635,7 @@ static const struct option long_options[] =
{ "no-strlen", no_argument, NULL, 'n' },
{ "occurrence-sort", no_argument, NULL, 'o' },
{ "optimized-collision-resolution", no_argument, NULL, 'O' },
+ { "pic", no_argument, NULL, 'P' },
{ "random", no_argument, NULL, 'r' },
{ "size-multiple", required_argument, NULL, 's' },
{ "help", no_argument, NULL, 'h' },
@@ -650,7 +655,7 @@ Options::parse_options (int argc, char *argv[])
while ((option_char =
getopt_long (_argument_count, _argument_vector,
- "acCdDe:Ef:F:gGhH:i:Ij:k:K:lL:m:nN:oOprs:S:tTvW:Z:7",
+ "acCdDe:Ef:F:gGhH:i:Ij:k:K:lL:m:nN:oOpPrs:S:tTvW:Z:7",
long_options, NULL))
!= -1)
{
@@ -838,6 +843,11 @@ Options::parse_options (int argc, char *argv[])
break; /* Not needed any more. */
case 'p': /* Generated lookup function a pointer instead of int. */
break; /* This is now the default. */
+ case 'P': /* Optimize for position-independent code. */
+ {
+ _option_word |= SHAREDLIB;
+ break;
+ }
case 'r': /* Utilize randomness to initialize the associated values table. */
{
_option_word |= RANDOM;
diff --git a/src/options.h b/src/options.h
index 9d37201..2a9567b 100644
--- a/src/options.h
+++ b/src/options.h
@@ -95,7 +95,10 @@ enum Option_Type
INCLUDE = 1 << 18,
/* Assume 7-bit, not 8-bit, characters. */
- SEVENBIT = 1 << 19
+ SEVENBIT = 1 << 19,
+
+ /* Optimize for position-independent code. */
+ SHAREDLIB = 1 << 20
};
/* Class manager for gperf program Options. */
diff --git a/src/output.cc b/src/output.cc
index 20ca0bf..e898254 100644
--- a/src/output.cc
+++ b/src/output.cc
@@ -726,13 +726,14 @@ output_keyword_blank_entries (int count, const char *indent)
int columns;
if (option[TYPE])
{
- columns = 58 / (6 + strlen (option.get_initializer_suffix()));
+ columns = 58 / (4 + (option[SHAREDLIB] ? 8 : 2)
+ + strlen (option.get_initializer_suffix()));
if (columns == 0)
columns = 1;
}
else
{
- columns = 9;
+ columns = (option[SHAREDLIB] ? 4 : 9);
}
int column = 0;
for (int i = 0; i < count; i++)
@@ -749,9 +750,13 @@ output_keyword_blank_entries (int count, const char *indent)
printf (", ");
}
if (option[TYPE])
- printf ("{\"\"%s}", option.get_initializer_suffix());
+ printf ("{");
+ if (option[SHAREDLIB])
+ printf ("(char*)0");
else
printf ("\"\"");
+ if (option[TYPE])
+ printf ("%s}", option.get_initializer_suffix());
column++;
}
}
@@ -1362,6 +1367,8 @@ Output::output_lookup_function_body (const Output_Compare& comparison) const
printf (";\n\n"
"%*s if (",
indent, "");
+ if (option[SHAREDLIB])
+ printf ("s && ");
comparison.output_comparison (Output_Expr1 ("str"), Output_Expr1 ("s"));
printf (")\n"
"%*s return ",