summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dfa.c8
-rw-r--r--flexdef.h3
-rw-r--r--gen.c36
-rw-r--r--main.c15
4 files changed, 42 insertions, 20 deletions
diff --git a/dfa.c b/dfa.c
index 7afd879..4016e85 100644
--- a/dfa.c
+++ b/dfa.c
@@ -526,12 +526,12 @@ void ntod()
*/
num_full_table_rows = numecs + 1;
- /* Declare it "short" because it's a real long-shot that that
- * won't be large enough.
+ /* Unless -a, declare it "short" because it's a real
+ * long-shot that that won't be large enough.
*/
- printf( "static const short yy_nxt[][%d] =\n {\n",
+ printf( "static const %s yy_nxt[][%d] =\n {\n",
/* '}' so vi doesn't get too confused */
- num_full_table_rows );
+ long_align ? "long" : "short", num_full_table_rows );
/* Generate 0 entries for state #0. */
for ( i = 0; i < num_full_table_rows; ++i )
diff --git a/flexdef.h b/flexdef.h
index 81a1fe1..028d516 100644
--- a/flexdef.h
+++ b/flexdef.h
@@ -321,6 +321,7 @@ extern struct hash_entry *ccltab[CCL_HASH_SIZE];
* listing backing-up states
* C_plus_plus - if true (i.e., -+ flag), generate a C++ scanner class;
* otherwise, a standard C scanner
+ * long_align - if true (-a flag), favor long-word alignment.
* yytext_is_array - if true (i.e., %array directive), then declare
* yytext as a array instead of a character pointer. Nice and inefficient.
* csize - size of character set for the scanner we're generating;
@@ -339,7 +340,7 @@ extern struct hash_entry *ccltab[CCL_HASH_SIZE];
extern int printstats, syntaxerror, eofseen, ddebug, trace, nowarn, spprdflt;
extern int interactive, caseins, useecs, fulltbl, usemecs;
extern int fullspd, gen_line_dirs, performance_report, backing_up_report;
-extern int C_plus_plus, yytext_is_array, csize;
+extern int C_plus_plus, long_align, yytext_is_array, csize;
extern int yymore_used, reject, real_reject, continued_action;
#define REALLY_NOT_DETERMINED 0
diff --git a/gen.c b/gen.c
index 164081b..d31ff93 100644
--- a/gen.c
+++ b/gen.c
@@ -397,7 +397,8 @@ void genftbl()
register int i;
int end_of_buffer_action = num_rules + 1;
- printf( C_short_decl, "yy_accept", lastdfa + 1 );
+ printf( long_align ? C_long_decl : C_short_decl,
+ "yy_accept", lastdfa + 1 );
dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action;
@@ -440,7 +441,7 @@ char *char_map;
"while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )" );
indent_up();
indent_puts( "{" );
- indent_puts( "yy_current_state = yy_def[yy_current_state];" );
+ indent_puts( "yy_current_state = (int) yy_def[yy_current_state];" );
if ( usemecs )
{
@@ -783,7 +784,8 @@ void gentabs()
accsiz[end_of_buffer_state] = 1;
dfaacc[end_of_buffer_state].dfaacc_set = EOB_accepting_list;
- printf( C_short_decl, "yy_acclist", max( numas, 1 ) + 1 );
+ printf( long_align ? C_long_decl : C_short_decl,
+ "yy_acclist", max( numas, 1 ) + 1 );
j = 1; /* index into "yy_acclist" array */
@@ -869,7 +871,7 @@ void gentabs()
*/
++k;
- printf( C_short_decl, "yy_accept", k );
+ printf( long_align ? C_long_decl : C_short_decl, "yy_accept", k );
for ( i = 1; i <= lastdfa; ++i )
{
@@ -917,7 +919,8 @@ void gentabs()
total_states = lastdfa + numtemps;
- printf( total_states >= MAX_SHORT ? C_long_decl : C_short_decl,
+ printf( (total_states >= MAX_SHORT || long_align) ?
+ C_long_decl : C_short_decl,
"yy_base", total_states + 1 );
for ( i = 1; i <= lastdfa; ++i )
@@ -951,7 +954,8 @@ void gentabs()
dataend();
- printf( total_states >= MAX_SHORT ? C_long_decl : C_short_decl,
+ printf( (total_states >= MAX_SHORT || long_align) ?
+ C_long_decl : C_short_decl,
"yy_def", total_states + 1 );
for ( i = 1; i <= total_states; ++i )
@@ -959,7 +963,8 @@ void gentabs()
dataend();
- printf( tblend >= MAX_SHORT ? C_long_decl : C_short_decl,
+ printf( (tblend >= MAX_SHORT || long_align) ?
+ C_long_decl : C_short_decl,
"yy_nxt", tblend + 1 );
for ( i = 1; i <= tblend; ++i )
@@ -972,7 +977,8 @@ void gentabs()
dataend();
- printf( tblend >= MAX_SHORT ? C_long_decl : C_short_decl,
+ printf( (tblend >= MAX_SHORT || long_align) ?
+ C_long_decl : C_short_decl,
"yy_chk", tblend + 1 );
for ( i = 1; i <= tblend; ++i )
@@ -1025,7 +1031,7 @@ void make_tables()
/* First, take care of YY_DO_BEFORE_ACTION depending on yymore
* being used.
*/
- set_indent( 2 );
+ set_indent( 1 );
if ( yymore_used )
{
@@ -1062,13 +1068,18 @@ void make_tables()
*/
int total_table_size = tblend + numecs + 1;
char *trans_offset_type =
- total_table_size >= MAX_SHORT ? "long" : "short";
+ (total_table_size >= MAX_SHORT || long_align) ?
+ "long" : "short";
set_indent( 0 );
indent_puts( "struct yy_trans_info" );
indent_up();
indent_puts( "{" ); /* } for vi */
- indent_puts( "short yy_verify;" );
+
+ if ( long_align )
+ indent_puts( "long yy_verify;" );
+ else
+ indent_puts( "short yy_verify;" );
/* In cases where its sister yy_verify *is* a "yes, there is
* a transition", yy_nxt is the offset (in records) to the
@@ -1125,7 +1136,8 @@ void make_tables()
indent_puts( "extern int yy_flex_debug;" );
indent_puts( "int yy_flex_debug = 1;\n" );
- printf( C_short_decl, "yy_rule_linenum", num_rules );
+ printf( long_align ? C_long_decl : C_short_decl,
+ "yy_rule_linenum", num_rules );
for ( i = 1; i < num_rules; ++i )
mkdata( rule_linenum[i] );
dataend();
diff --git a/main.c b/main.c
index de62516..c9104a6 100644
--- a/main.c
+++ b/main.c
@@ -52,7 +52,7 @@ void set_up_initial_allocations PROTO((void));
int printstats, syntaxerror, eofseen, ddebug, trace, nowarn, spprdflt;
int interactive, caseins, useecs, fulltbl, usemecs;
int fullspd, gen_line_dirs, performance_report, backing_up_report;
-int C_plus_plus, yytext_is_array, csize;
+int C_plus_plus, long_align, yytext_is_array, csize;
int yymore_used, reject, real_reject, continued_action;
int yymore_really_used, reject_really_used;
int datapos, dataline, linenum;
@@ -255,6 +255,8 @@ int exit_status;
if ( C_plus_plus )
putc( '+', stderr );
+ if ( long_align )
+ putc( 'a', stderr );
if ( backing_up_report )
putc( 'b', stderr );
if ( ddebug )
@@ -411,7 +413,7 @@ char **argv;
printstats = syntaxerror = trace = spprdflt = caseins = false;
C_plus_plus = backing_up_report = ddebug = fulltbl = fullspd = false;
- nowarn = yymore_used = continued_action = reject = false;
+ long_align = nowarn = yymore_used = continued_action = reject = false;
yytext_is_array = yymore_really_used = reject_really_used = false;
gen_line_dirs = usemecs = useecs = true;
performance_report = 0;
@@ -446,6 +448,10 @@ char **argv;
C_plus_plus = true;
break;
+ case 'a':
+ long_align = true;
+ break;
+
case 'B':
interactive = false;
interactive_given = true;
@@ -797,6 +803,7 @@ void readin()
{
if ( yytext_is_array )
{
+ puts( "\n#include <string.h>\n" );
puts( "extern char yytext[];\n" );
puts( "#ifndef YYLMAX" );
puts( "#define YYLMAX YY_READ_BUF_SIZE" );
@@ -877,10 +884,12 @@ void set_up_initial_allocations()
void usage()
{
fprintf( stderr,
- "%s [-bcdfhinpstvwBFILTV78+ -C[efmF] -Pprefix -Sskeleton] [file ...]\n",
+"%s [-abcdfhinpstvwBFILTV78+ -C[efmF] -Pprefix -Sskeleton] [file ...]\n",
program_name );
fprintf( stderr,
+ "\t-a trade off larger tables for better memory alignment\n" );
+ fprintf( stderr,
"\t-b generate backing-up information to lex.backup\n" );
fprintf( stderr, "\t-c do-nothing POSIX option\n" );
fprintf( stderr, "\t-d turn on debug mode in generated scanner\n" );