[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/3] traces: provide a means to get short m4 traces
From: |
Akim Demaille |
Subject: |
[PATCH 2/3] traces: provide a means to get short m4 traces |
Date: |
Fri, 22 May 2020 20:31:54 +0200 |
Let --trace=m4-early dump all the logs from the start (as --trace=m4
used to do), and have --trace=m4 now start traces only when actually
working of the user's grammar.
Can make a big difference in the case of small inputs. E.g.
$ bison -S tests/testsuite.dir/001/input.m4 tests/testsuite.dir/001/input.y
--trace=m4 |& wc
3952 19446 251068
$ bison -S tests/testsuite.dir/001/input.m4 tests/testsuite.dir/001/input.y
--trace=m4-early |& wc
19491 131904 1830495
* data/skeletons/traceon.m4: New.
* src/getargs.h, src/getargs.c: Introduce --trace=m4-early.
* src/output.c (output_skeleton): Adjust for --trace=m4 and --trace=m4-early.
---
data/local.mk | 1 +
data/skeletons/traceon.m4 | 2 ++
src/getargs.c | 4 +++-
src/getargs.h | 11 ++++++-----
src/output.c | 13 +++++++------
5 files changed, 19 insertions(+), 12 deletions(-)
create mode 100644 data/skeletons/traceon.m4
diff --git a/data/local.mk b/data/local.mk
index 50efda39..21106451 100644
--- a/data/local.mk
+++ b/data/local.mk
@@ -34,6 +34,7 @@ dist_skeletons_DATA = \
data/skeletons/lalr1.java \
data/skeletons/location.cc \
data/skeletons/stack.hh \
+ data/skeletons/traceon.m4 \
data/skeletons/variant.hh \
data/skeletons/yacc.c
diff --git a/data/skeletons/traceon.m4 b/data/skeletons/traceon.m4
new file mode 100644
index 00000000..344d7d1c
--- /dev/null
+++ b/data/skeletons/traceon.m4
@@ -0,0 +1,2 @@
+dnl GNU M4 treats -dV in a position-independent manner.
+m4_debugmode(V)m4_traceon()dnl
diff --git a/src/getargs.c b/src/getargs.c
index 6f19a4ea..55884d34 100644
--- a/src/getargs.c
+++ b/src/getargs.c
@@ -257,7 +257,8 @@ static const argmatch_trace_doc argmatch_trace_docs[] =
{ "sets", "grammar sets: firsts, nullable etc." },
{ "muscles", "m4 definitions passed to the skeleton" },
{ "tools", "m4 invocation" },
- { "m4", "m4 traces" },
+ { "m4-early", "m4 traces starting from the start" },
+ { "m4", "m4 traces starting from the skeleton evaluation" },
{ "skeleton", "skeleton postprocessing" },
{ "time", "time consumption" },
{ "ielr", "IELR conversion" },
@@ -279,6 +280,7 @@ static const argmatch_trace_arg argmatch_trace_args[] =
{ "sets", trace_sets },
{ "muscles", trace_muscles },
{ "tools", trace_tools },
+ { "m4-early", trace_m4_early },
{ "m4", trace_m4 },
{ "skeleton", trace_skeleton },
{ "time", trace_time },
diff --git a/src/getargs.h b/src/getargs.h
index 39741926..c1629ab5 100644
--- a/src/getargs.h
+++ b/src/getargs.h
@@ -100,11 +100,12 @@ enum trace
trace_grammar = 1 << 7, /**< Reading, reducing the grammar. */
trace_time = 1 << 8, /**< Time consumption. */
trace_skeleton = 1 << 9, /**< Skeleton postprocessing. */
- trace_m4 = 1 << 10, /**< M4 traces. */
- trace_muscles = 1 << 11, /**< M4 definitions of the muscles. */
- trace_ielr = 1 << 12, /**< IELR conversion. */
- trace_closure = 1 << 13, /**< Input/output of closure(). */
- trace_locations = 1 << 14, /**< Full display of locations. */
+ trace_m4_early = 1 << 10, /**< M4 early traces. */
+ trace_m4 = 1 << 11, /**< M4 traces. */
+ trace_muscles = 1 << 12, /**< M4 definitions of the muscles. */
+ trace_ielr = 1 << 13, /**< IELR conversion. */
+ trace_closure = 1 << 14, /**< Input/output of closure(). */
+ trace_locations = 1 << 15, /**< Full display of locations. */
trace_all = ~0 /**< All of the above. */
};
/** What debug items bison displays during its run. */
diff --git a/src/output.c b/src/output.c
index 5bee092d..e63c3254 100644
--- a/src/output.c
+++ b/src/output.c
@@ -687,6 +687,7 @@ output_skeleton (void)
char *skeldir = xpath_join (datadir, "skeletons");
char *m4sugar = xpath_join (datadir, "m4sugar/m4sugar.m4");
char *m4bison = xpath_join (skeldir, "bison.m4");
+ char *traceon = xpath_join (skeldir, "traceon.m4");
char *skel = (IS_PATH_WITH_DIR (skeleton)
? xstrdup (skeleton)
: xpath_join (skeldir, skeleton));
@@ -701,7 +702,7 @@ output_skeleton (void)
int filter_fd[2];
pid_t pid;
{
- char const *argv[10];
+ char const *argv[11];
int i = 0;
argv[i++] = m4;
@@ -720,17 +721,16 @@ output_skeleton (void)
argv[i++] = "-I";
argv[i++] = datadir;
/* Some future version of GNU M4 (most likely 1.6) may treat the
- -dV in a position-dependent manner. Keep it as the first
- argument so that all files are traced.
-
- See the thread starting at
+ -dV in a position-dependent manner. See the thread starting at
<http://lists.gnu.org/archive/html/bug-bison/2008-07/msg00000.html>
for details. */
- if (trace_flag & trace_m4)
+ if (trace_flag & trace_m4_early)
argv[i++] = "-dV";
argv[i++] = m4sugar;
argv[i++] = "-";
argv[i++] = m4bison;
+ if (trace_flag & trace_m4)
+ argv[i++] = traceon;
argv[i++] = skel;
argv[i++] = NULL;
aver (i <= ARRAY_CARDINALITY (argv));
@@ -751,6 +751,7 @@ output_skeleton (void)
free (skeldir);
free (m4sugar);
free (m4bison);
+ free (traceon);
free (skel);
if (trace_flag & trace_muscles)
--
2.26.2