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.
This commit is contained in:
Akim Demaille
2019-01-27 20:28:13 +01:00
parent 7355a35e4b
commit 7fec997ecf
6 changed files with 5 additions and 13 deletions

View File

@@ -345,7 +345,6 @@ generate_states (void)
}
/* discard various storage */
closure_free ();
free_storage ();
/* Set up STATES. */

View File

@@ -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"

View File

@@ -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);

View File

@@ -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>");

View File

@@ -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);
}

View File

@@ -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);