]> granicus.if.org Git - flex/commitdiff
Added -a option for long-align.
authorVern Paxson <vern@ee.lbl.gov>
Sat, 2 Oct 1993 13:37:14 +0000 (13:37 +0000)
committerVern Paxson <vern@ee.lbl.gov>
Sat, 2 Oct 1993 13:37:14 +0000 (13:37 +0000)
dfa.c
flexdef.h
gen.c
main.c

diff --git a/dfa.c b/dfa.c
index 7afd879f84538cc19d3a99bdd7f331b1225a4359..4016e85174e9e63e6e1fa9306b395a0cd67148b2 100644 (file)
--- 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 )
index 81a1fe1e75111f81a188849441f29a28491f674a..028d516288896982137ae8ef44afa261db45ce79 100644 (file)
--- 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 164081b9a99c3a7e7165f3d5f7be7eacee724fdb..d31ff936f045976242ef076fe0ae8275289b0964 100644 (file)
--- 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 de62516e1f138f46bbe0c2f3ddb4d9241d68f34f..c9104a6b780739961512328148428698cea5d75e 100644 (file)
--- 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,9 +884,11 @@ 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" );