summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2020-10-05 15:03:03 -0400
committerEric S. Raymond <esr@thyrsus.com>2020-10-05 21:02:51 -0400
commit96e004a296edf2a6f6e0b60b3da6e5d8e09428de (patch)
tree54110a905ab9ba9bf892f8328254305357721631
parent64cf0328063cd97dec09536a8f2bb35ce7350ffe (diff)
downloadflex-git-96e004a296edf2a6f6e0b60b3da6e5d8e09428de.tar.gz
Macroize the yy_meta, gen_yy_trans and start_state_list methods.
Also macro-generate yydmap entry for the yymeta table. We're npw about 75% of the way through pushing all C syntax out of the method table. Permutes table order in the generated code. #64 in the retargeting patch series
-rw-r--r--src/cpp-flex.skl36
-rw-r--r--src/cpp_backend.c46
-rw-r--r--src/flexdef.h3
-rw-r--r--src/gen.c24
4 files changed, 52 insertions, 57 deletions
diff --git a/src/cpp-flex.skl b/src/cpp-flex.skl
index 43b9c20..a66e67d 100644
--- a/src/cpp-flex.skl
+++ b/src/cpp-flex.skl
@@ -893,6 +893,7 @@ static const M4_HOOK_FULLTABLE_TYPE * yy_accept = 0;
]])
m4_ifdef( [[M4_MODE_USEECS]],[[m4_dnl
+/* Character equivalence-class mapping */
m4_ifdef( [[M4_MODE_GENTABLES]],[[m4_dnl
static const YY_CHAR yy_ec[M4_HOOK_ECSTABLE_SIZE] =
{ 0,
@@ -903,6 +904,7 @@ static const YY_CHAR * yy_ec = 0;
]])
m4_ifdef( [[M4_MODE_DEBUG]],[[m4_dnl
+/* Rule to line-number mapping */
m4_ifdef( [[M4_MODE_GENTABLES]],[[m4_dnl
static const M4_HOOK_DEBUGTABLE_TYPE yy_rule_linenum[M4_HOOK_DEBUGTABLE_SIZE] =
{ 0,
@@ -912,6 +914,39 @@ static const M4_HOOK_DEBUGTABLE_TYPE * yy_rule_linenum = 0;
]])
]])
+m4_ifdef( [[M4_MODE_USEMECS]],[[m4_dnl
+/* Character meta-equivalence-class mappings */
+m4_ifdef( [[M4_MODE_GENTABLES]],[[m4_dnl
+static const YY_CHAR yy_meta[M4_HOOK_MECSTABLE_SIZE] =
+ { 0,
+M4_HOOK_MECSTABLE_BODY[[]]};
+]], [[
+static const YY_CHAR * yy_meta = 0;
+]])
+]])
+
+m4_ifdef( [[M4_HOOK_TRANSTABLE_SIZE]],[[m4_dnl
+/* The transition table */
+m4_ifdef( [[M4_MODE_GENTABLES]],[[m4_dnl
+static const struct yy_trans_info yy_transition[M4_HOOK_TRANSTABLE_SIZE] =
+ {
+M4_HOOK_TRANSTABLE_BODY[[]]};
+]], [[
+static const struct yy_trans_info *yy_transition = 0;
+]])
+]])
+
+m4_ifdef( [[M4_HOOK_STARTTABLE_SIZE]],[[m4_dnl
+/* Table of pointers to start states. */
+m4_ifdef( [[M4_MODE_GENTABLES]],[[m4_dnl
+static const struct yy_trans_info *yy_start_state_list[M4_HOOK_STARTTABLE_SIZE] =
+ {
+M4_HOOK_STARTTABLE_BODY[[]]};
+]], [[
+static const struct yy_trans_info **yy_start_state_list =0;
+]])
+]])
+
]])
m4_ifdef( [[M4_YY_NOT_IN_HEADER]],
@@ -1484,6 +1519,7 @@ static struct yytbl_dmap yydmap[] = {
m4_ifdef([[M4_MODE_FULLSPD]], [[ {YYTD_ID_START_STATE_LIST, (void**)&yy_start_state_list, sizeof(struct yy_trans_info*)},]])
m4_ifdef([[M4_MODE_YYLINENO]], [[ {YYTD_ID_RULE_CAN_MATCH_EOL, (void**)&yy_rule_can_match_eol, sizeof(flex_int32_t)},]])
m4_ifdef([[M4_MODE_USEECS]], [[ {YYTD_ID_EC, (void**)&yy_ec, sizeof(YY_CHAR)},]])
+m4_ifdef([[M4_MODE_USEMECS]], [[ {YYTD_ID_META, (void**)&yy_meta, sizeof(YY_CHAR)},]])
%tables-yydmap generated elements
{0,0,0}
};
diff --git a/src/cpp_backend.c b/src/cpp_backend.c
index 8446b71..6a02f1a 100644
--- a/src/cpp_backend.c
+++ b/src/cpp_backend.c
@@ -35,12 +35,11 @@
#include "flexdef.h"
#include "tables.h"
-/* These typedefs are only used for computing footprint sizes,
+/* This typedef is only used for computing footprint sizes,
* You need to make sure they match reality in the skeleton file to
* get accurate numbers, but they don't otherwise matter.
- * FIXME: This shiould go away when tFkex ships only macros.
+ * FIXME: This should go away when Flex ships only macros.
*/
-typedef char YY_CHAR;
struct yy_trans_info {int32_t yy_verify; int32_t yy_nxt;};
/* Helper functions */
@@ -67,13 +66,6 @@ static const char *cpp_get_state_decl (void)
: "static const yy_state_type * %s = 0;\n";
}
-static const char *cpp_get_yy_char_decl (void)
-{
- return (gentables)
- ? "static const YY_CHAR %s[%d] =\n { 0,\n"
- : "static const YY_CHAR * %s = 0;\n";
-}
-
/* Methods */
static const char *cpp_suffix (void)
@@ -122,27 +114,6 @@ static void cpp_mkctbl (size_t sz)
|| ctrl.long_align) ? "flex_int32_t" : "flex_int16_t");
}
-static size_t cpp_gen_yy_trans(size_t sz)
-// Table of verify for transition and offset to next state. (sic)
-{
- if (gentables)
- out_dec ("static const struct yy_trans_info yy_transition[%d] =\n {\n", sz);
- else
- outn ("static const struct yy_trans_info *yy_transition = 0;");
- return sz * sizeof(struct yy_trans_info);
-}
-
-static size_t cpp_start_state_list(size_t sz)
-// Start initializer for table of pointers to start state
-{
- /* Table of pointers to start states. */
- if (gentables)
- out_dec ("static const struct yy_trans_info *yy_start_state_list[%d] =\n", sz);
- else
- outn ("static const struct yy_trans_info **yy_start_state_list =0;");
- return sz * sizeof(struct yy_trans_info *);
-}
-
static void cpp_mkftbl(void)
// Make full table
{
@@ -174,16 +145,6 @@ static size_t cpp_gentabs_accept(size_t sz)
return sz * (ctrl.long_align ? sizeof(int32_t) : sizeof(int16_t));
}
-static size_t cpp_gentabs_yy_meta(size_t sz)
-// Generate yy_meta table initializer
-{
- out_str_dec (cpp_get_yy_char_decl (), "yy_meta", sz);
- buf_prints (&yydmap_buf,
- "\t{YYTD_ID_META, (void**)&yy_meta, sizeof(%s)},\n",
- "YY_CHAR");
- return sz * sizeof(YY_CHAR);
-}
-
static size_t cpp_gentabs_yy_base(size_t sz)
// Generate yy_meta base initializer
{
@@ -267,12 +228,9 @@ struct flex_backend_t cpp_backend = {
.skel = cpp_skel,
.ntod = cpp_ntod,
.mkctbl = cpp_mkctbl,
- .gen_yy_trans = cpp_gen_yy_trans,
- .start_state_list = cpp_start_state_list,
.mkftbl = cpp_mkftbl,
.gentabs_acclist = cpp_gentabs_acclist,
.gentabs_accept = cpp_gentabs_accept,
- .gentabs_yy_meta = cpp_gentabs_yy_meta,
.gentabs_yy_base = cpp_gentabs_yy_base,
.gentabs_yy_def = cpp_gentabs_yy_def,
.gentabs_yy_nxt = cpp_gentabs_yy_nxt,
diff --git a/src/flexdef.h b/src/flexdef.h
index 4e44ba5..87038ad 100644
--- a/src/flexdef.h
+++ b/src/flexdef.h
@@ -309,13 +309,10 @@ struct flex_backend_t {
// Flex table generation
void (*ntod)(size_t); // Generate nxt table initializer start (fulltbl mode)
void (*mkctbl)(size_t); // Make full-speed compressed table initializer start
- size_t (*gen_yy_trans)(size_t); // Table of verify for transition and offset to next state. (sic)
- size_t (*start_state_list)(size_t); // Start initializer for table of pointers to start states
void (*mkftbl)(); // Make full table serialization entry
size_t (*genftbl)(size_t); // Make full table initializer start
size_t (*gentabs_acclist)(size_t); // Generate accept list initializer start
size_t (*gentabs_accept)(size_t); // Generate accept table initializer start
- size_t (*gentabs_yy_meta)(size_t); // Generate yy_meta table initializer start
size_t (*gentabs_yy_base)(size_t); // Generate yy_base table initializer start
size_t (*gentabs_yy_def)(size_t); // Generate yy_def initializer start
size_t (*gentabs_yy_nxt)(size_t); // Generate yy_nxt initializer start
diff --git a/src/gen.c b/src/gen.c
index 7bd258b..e042a4f 100644
--- a/src/gen.c
+++ b/src/gen.c
@@ -248,7 +248,8 @@ void genctbl (void)
int end_of_buffer_action = num_rules + 1;
/* Table of verify for transition and offset to next state. */
- footprint += backend->gen_yy_trans(tblend + numecs + 1);
+ out_dec ("m4_define([[M4_HOOK_TRANSTABLE_SIZE]], [[%d]])", tblend + numecs + 1);
+ outn ("m4_define([[M4_HOOK_TRANSTABLE_BODY]], [[m4_dnl");
/* We want the transition to be represented as the offset to the
* next state, not the actual state number, which is what it currently
@@ -315,18 +316,19 @@ void genctbl (void)
transition_struct_out (chk[tblend + 1], nxt[tblend + 1]);
transition_struct_out (chk[tblend + 2], nxt[tblend + 2]);
- if (gentables)
- outn ("M4_HOOK_TABLE_CLOSER");
+ outn ("]])");
+ footprint += sizeof(struct yy_trans_info) * (tblend + numecs + 1);
- footprint += backend->start_state_list(lastsc * 2 + 1);
+ out_dec ("m4_define([[M4_HOOK_STARTTABLE_SIZE]], [[%d]])", lastsc * 2 + 1);
if (gentables) {
- outn ("M4_HOOK_TABLE_OPENER");
-
+ outn ("m4_define([[M4_HOOK_STARTTABLE_BODY]], [[m4_dnl");
for (i = 0; i <= lastsc * 2; ++i)
out_dec ("M4_HOOK_STATE_ENTRY_FORMAT(%d)", base[i]);
- dataend ("M4_HOOK_TABLE_CLOSER");
+ dataend (NULL);
+ outn("]])");
+ footprint += sizeof(struct yy_trans_info *) * (lastsc * 2 + 1);
}
if (ctrl.useecs)
@@ -681,8 +683,8 @@ void gentabs (void)
if (env.trace)
fputs (_("\n\nMeta-Equivalence Classes:\n"),
stderr);
-
- footprint += backend->gentabs_yy_meta(numecs + 1);
+ out_dec ("m4_define([[M4_HOOK_MECSTABLE_SIZE]], [[%d]])", numecs+1);
+ outn ("m4_define([[M4_HOOK_MECSTABLE_BODY]], [[");
for (i = 1; i <= numecs; ++i) {
if (env.trace)
@@ -693,7 +695,9 @@ void gentabs (void)
yymecs_data[i] = ABS (tecbck[i]);
}
- dataend ("M4_HOOK_TABLE_CLOSER");
+ dataend (NULL);
+ outn ("]])");
+ footprint += sizeof(YY_CHAR) * (numecs + 1);
if (tablesext) {
yytbl_data_compress (yymeta_tbl);
if (yytbl_data_fwrite (&tableswr, yymeta_tbl) < 0)