diff options
-rw-r--r-- | src/cpp_backend.c | 3 | ||||
-rw-r--r-- | src/flexdef.h | 1 | ||||
-rw-r--r-- | src/gen.c | 9 |
3 files changed, 9 insertions, 4 deletions
diff --git a/src/cpp_backend.c b/src/cpp_backend.c index c868749..5c208f7 100644 --- a/src/cpp_backend.c +++ b/src/cpp_backend.c @@ -627,5 +627,6 @@ struct flex_backend_t cpp_backend = { .trans_offset_type = cpp_trans_offset_type, .caseprefix = "case ", .fallthrough = NULL, - .endcase = "yyterminate();" + .endcase = "yyterminate();", + .c_like = 1, }; diff --git a/src/flexdef.h b/src/flexdef.h index 6bed71d..f8575a6 100644 --- a/src/flexdef.h +++ b/src/flexdef.h @@ -345,6 +345,7 @@ struct flex_backend_t { char *caseprefix; // Prefix of an arm in the language's case construct char *fallthrough; // Finish a case arm with this to fall through char *endcase; // What to ship after all EOF-state case arms + int c_like; // Will &yy_transition[%d]," produce a pointer table entry? }; extern bool gentables; @@ -1109,7 +1109,9 @@ void make_tables (void) backend->nultrans(fullspd); yynultrans_tbl = calloc(1, sizeof (struct yytbl_data)); yytbl_data_init (yynultrans_tbl, YYTD_ID_NUL_TRANS); - if (fullspd) + // Performance kludge for C. Gives a small improvement + // in table loading time. + if (fullspd && backend->c_like) yynultrans_tbl->td_flags |= YYTD_PTRANS; yynultrans_tbl->td_lolen = (flex_uint32_t) (lastdfa + 1); yynultrans_tbl->td_data = yynultrans_data = @@ -1117,13 +1119,14 @@ void make_tables (void) sizeof (flex_int32_t)); for (i = 1; i <= lastdfa; ++i) { - if (fullspd) { - // FIXME: dubious - pretty C-specific + if ((yynultrans_tbl->td_flags & YYTD_PTRANS) != 0) { + // Only works in very C-like languages out_dec (" &yy_transition[%d],\n", base[i]); yynultrans_data[i] = base[i]; } else { + // This will work anywhere mkdata (nultrans[i]); yynultrans_data[i] = nultrans[i]; } |