bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

closure: initialize it once for all


From: Akim Demaille
Subject: closure: initialize it once for all
Date: Mon, 28 Jan 2019 06:59:25 +0100

commit 7fec997ecf710b459c2d2b2fcb195b2130c32369
Author: Akim Demaille <address@hidden>
Date:   Sun Jan 27 20:28:13 2019 +0100

    closure: initialize it once for all
    
    The memory allocated by 'closure' (and some data such as 'fderives')
    is used to computed a state's full itemset from its core.  This is
    needed during the construction of the LR(0) automaton, and the memory
    is reclaimed immediately afterwards.
    
    Unfortunately the reports (graph, text, xml) also need this
    information when describing the states with their full itemsets.  As a
    consequence the memory was allocated again, fderives computed again
    too, and more --trace reports are generated which only duplicate what
    was already reported.
    
    Stop that.  It does mean that we release the memory later (hence the
    peak memory usage is higher now), but I don't think that's a problem
    today.
    
    * src/lr0.c (generate_states): Don't call closure_free.
    * src/state.c (states_free): Do it here.
    (for symmetry with closure_new which is called in generate_states).
    * src/print-graph.c, src/print-xml.c, src/print.c: You can now expect
    the closure module to be functional.

diff --git a/src/lr0.c b/src/lr0.c
index 48ec30c5..a54f1e15 100644
--- a/src/lr0.c
+++ b/src/lr0.c
@@ -345,7 +345,6 @@ generate_states (void)
     }
 
   /* discard various storage */
-  closure_free ();
   free_storage ();
 
   /* Set up STATES. */
diff --git a/src/main.c b/src/main.c
index 065540db..7704bef4 100644
--- a/src/main.c
+++ b/src/main.c
@@ -23,6 +23,7 @@
 
 #include <bitset.h>
 #include <bitset/stats.h>
+#include <closeout.h>
 #include <configmake.h>
 #include <progname.h>
 #include <quote.h>
@@ -30,7 +31,6 @@
 #include <relocatable.h> /* relocate2 */
 #include <timevar.h>
 
-#include "closeout.h"
 #include "complain.h"
 #include "conflicts.h"
 #include "derives.h"
diff --git a/src/print-graph.c b/src/print-graph.c
index a007ab7a..3e3b7230 100644
--- a/src/print-graph.c
+++ b/src/print-graph.c
@@ -184,10 +184,8 @@ print_graph (void)
   start_graph (fgraph);
 
   /* Output nodes and edges. */
-  closure_new (nritems);
   for (int i = 0; i < nstates; i++)
     print_state (states[i], fgraph);
-  closure_free ();
 
   finish_graph (fgraph);
   xfclose (fgraph);
diff --git a/src/print-xml.c b/src/print-xml.c
index cbaec8c7..29339844 100644
--- a/src/print-xml.c
+++ b/src/print-xml.c
@@ -517,7 +517,6 @@ print_xml (void)
   /* print grammar */
   print_grammar (out, level + 1);
 
-  closure_new (nritems);
   no_reduce_set =  bitset_create (ntokens, BITSET_FIXED);
 
   /* print automaton */
@@ -531,7 +530,6 @@ print_xml (void)
   xml_puts (out, level + 1, "</automaton>");
 
   bitset_free (no_reduce_set);
-  closure_free ();
 
   xml_puts (out, 0, "</bison-xml-report>");
 
diff --git a/src/print.c b/src/print.c
index 356fd62a..42adb1d7 100644
--- a/src/print.c
+++ b/src/print.c
@@ -507,17 +507,11 @@ print_results (void)
   print_terminal_symbols (out);
   print_nonterminal_symbols (out);
 
-  /* If the whole state item sets, not only the kernels, are wanted,
-     'closure' will be run, which needs memory allocation/deallocation.   */
-  if (report_flag & report_itemsets)
-    closure_new (nritems);
   /* Storage for print_reductions.  */
   no_reduce_set = bitset_create (ntokens, BITSET_FIXED);
   for (state_number i = 0; i < nstates; i++)
     print_state (out, states[i]);
   bitset_free (no_reduce_set);
-  if (report_flag & report_itemsets)
-    closure_free ();
 
   xfclose (out);
 }
diff --git a/src/state.c b/src/state.c
index 1b5bb396..18d3da8b 100644
--- a/src/state.c
+++ b/src/state.c
@@ -19,13 +19,15 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <config.h>
+#include "state.h"
+
 #include "system.h"
 
 #include <hash.h>
 
+#include "closure.h"
 #include "complain.h"
 #include "gram.h"
-#include "state.h"
 #include "print-xml.h"
 
 
@@ -443,6 +445,7 @@ state **states = NULL;
 void
 states_free (void)
 {
+  closure_free ();
   for (state_number i = 0; i < nstates; ++i)
     state_free (states[i]);
   free (states);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]