From 3325ddc49c7b31f2670d03d1e3b59c2636650af3 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Thu, 1 Aug 2002 18:12:11 +0000 Subject: [PATCH] * lib/timevar.c (get_time): Include children time. * src/lalr.h (LA, LArule): Don't export them: used with the state_t. * src/lalr.c (LA, LArule): Static. * src/lalr.h, src/lalr.c (lalr_free): New. * src/main.c (main): Call it. * src/tables.c (pack_vector): Check whether loc is >= to the table_size, not >. (pack_tables): Don't free froms, tos, conflict_tos, and pos... (tables_generate): do it, since that's also it which allocates them. Don't free LA and LArule, main does. --- .project | 1 + ChangeLog | 15 +++++++++++++++ lib/timevar.c | 9 ++++++--- src/lalr.c | 32 ++++++++++++++++++++++++++++++-- src/lalr.h | 26 +++++++------------------- src/main.c | 5 +++++ src/tables.c | 27 ++++++++++++++------------- 7 files changed, 78 insertions(+), 37 deletions(-) create mode 100644 .project diff --git a/.project b/.project new file mode 100644 index 00000000..fdeea03e --- /dev/null +++ b/.project @@ -0,0 +1 @@ +patch_list='Bison Patches ' diff --git a/ChangeLog b/ChangeLog index 64264b7a..bfa1ed26 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2002-08-01 Akim Demaille + + * lib/timevar.c (get_time): Include children time. + * src/lalr.h (LA, LArule): Don't export them: used with the + state_t. + * src/lalr.c (LA, LArule): Static. + * src/lalr.h, src/lalr.c (lalr_free): New. + * src/main.c (main): Call it. + * src/tables.c (pack_vector): Check whether loc is >= to the + table_size, not >. + (pack_tables): Don't free froms, tos, conflict_tos, and pos... + (tables_generate): do it, since that's also it which allocates + them. + Don't free LA and LArule, main does. + 2002-07-31 Akim Demaille Separate parser tables computation and output. diff --git a/lib/timevar.c b/lib/timevar.c index 3cc38389..55fc45a4 100644 --- a/lib/timevar.c +++ b/lib/timevar.c @@ -207,15 +207,18 @@ get_time (now) { #ifdef USE_TIMES struct tms tms; - now->wall = times (&tms) * ticks_to_msec; - now->user = tms.tms_utime * ticks_to_msec; - now->sys = tms.tms_stime * ticks_to_msec; + now->wall = times (&tms) * ticks_to_msec; + now->user = (tms.tms_utime + tms.tms_cutime) * ticks_to_msec; + now->sys = (tms.tms_stime + tms.tms_cstime) * ticks_to_msec; #endif #ifdef USE_GETRUSAGE struct rusage rusage; getrusage (RUSAGE_SELF, &rusage); now->user = rusage.ru_utime.tv_sec + rusage.ru_utime.tv_usec * 1e-6; now->sys = rusage.ru_stime.tv_sec + rusage.ru_stime.tv_usec * 1e-6; + getrusage (RUSAGE_CHILDREN, &rusage); + now->user += rusage.ru_utime.tv_sec + rusage.ru_utime.tv_usec * 1e-6; + now->sys += rusage.ru_stime.tv_sec + rusage.ru_stime.tv_usec * 1e-6; #endif #ifdef USE_CLOCK now->user = clock () * clocks_to_msec; diff --git a/src/lalr.c b/src/lalr.c index b87cebb5..275c6ab7 100644 --- a/src/lalr.c +++ b/src/lalr.c @@ -52,8 +52,22 @@ typedef struct goto_list_s } goto_list_t; -rule_t **LArule = NULL; -bitsetv LA = NULL; +/* LARULE is a vector which records the rules that need lookahead in + various states. The elements of LARULE that apply to state S are + those from LOOKAHEADS[S] through LOOKAHEADS[S+1]-1. + + If LR is the length of LArule, then a number from 0 to LR-1 can + specify both a rule and a state where the rule might be applied. + */ + +static rule_t **LArule = NULL; + +/* LA is a LR by NTOKENS matrix of bits. LA[l, i] is 1 if the rule + LArule[l] is applicable in the appropriate state when the next + token is symbol i. If LA[l, i] and LA[l, j] are both 1 for i != j, + it is a conflict. */ + +static bitsetv LA = NULL; size_t nLA; @@ -460,3 +474,17 @@ lalr (void) if (trace_flag & trace_sets) lookaheads_print (stderr); } + + +void +lalr_free (void) +{ + state_number_t s; + for (s = 0; s < nstates; ++s) + { + states[s]->lookaheads = NULL; + states[s]->lookaheads_rule = NULL; + } + bitsetv_free (LA); + free (LArule); +} diff --git a/src/lalr.h b/src/lalr.h index 696bc98d..7edbbe8a 100644 --- a/src/lalr.h +++ b/src/lalr.h @@ -21,8 +21,8 @@ #ifndef LALR_H_ # define LALR_H_ -#include "bitset.h" -#include "bitsetv.h" +# include "bitset.h" +# include "bitsetv.h" /* Import the definition of CORE, TRANSITIONS and REDUCTIONS. */ # include "state.h" @@ -36,6 +36,11 @@ void lalr PARAMS ((void)); +/* Release the information related to lookaheads. Can be performed + once the action tables are computed. */ + +void lalr_free PARAMS ((void)); + /* lalr() builds these data structures. */ @@ -56,22 +61,5 @@ extern goto_number_t *goto_map; extern state_number_t *from_state; extern state_number_t *to_state; -/* LARULE is a vector which records the rules that need lookahead in - various states. The elements of LARULE that apply to state S are - those from LOOKAHEADS[S] through LOOKAHEADS[S+1]-1. - - If LR is the length of LArule, then a number from 0 to LR-1 can - specify both a rule and a state where the rule might be applied. - */ - -extern rule_t **LArule; - -/* LA is a LR by NTOKENS matrix of bits. LA[l, i] is 1 if the rule - LAruleno[l] is applicable in the appropriate state when the next - token is symbol i. If LA[l, i] and LA[l, j] are both 1 for i != j, - it is a conflict. */ - -extern bitsetv LA; - #endif /* !LALR_H_ */ diff --git a/src/main.c b/src/main.c index 6b73f9eb..b59e2978 100644 --- a/src/main.c +++ b/src/main.c @@ -137,6 +137,11 @@ main (int argc, char *argv[]) tables_generate (); timevar_pop (TV_ACTIONS); + /* Lookaheads are no longer needed. */ + timevar_push (TV_FREE); + lalr_free (); + timevar_pop (TV_FREE); + /* Output the tables and the parser to ftable. In file output. */ timevar_push (TV_PARSER); output (); diff --git a/src/tables.c b/src/tables.c index 91461b29..67e9abad 100644 --- a/src/tables.c +++ b/src/tables.c @@ -732,7 +732,7 @@ pack_vector (vector_number_t vector) for (k = 0; ok && k < t; k++) { loc = j + state_number_as_int (from[k]); - if (loc > (int) table_size) + if (loc >= (int) table_size) table_grow (loc); if (table[loc] != 0) @@ -839,16 +839,6 @@ pack_table (void) base_ninf = table_ninf_remap (base, nvectors, BASE_MIN); table_ninf = table_ninf_remap (table, high + 1, ACTION_MIN); - for (i = 0; i < nvectors; i++) - { - XFREE (froms[i]); - XFREE (tos[i]); - XFREE (conflict_tos[i]); - } - - free (froms); - free (tos); - free (conflict_tos); free (pos); } @@ -862,6 +852,8 @@ pack_table (void) void tables_generate (void) { + int i; + /* That's a poor way to make sure the sizes are properly corelated, in particular the signedness is not taking into account, but it's not useless. */ @@ -877,8 +869,6 @@ tables_generate (void) width = XCALLOC (base_t, nvectors); token_actions (); - bitsetv_free (LA); - free (LArule); goto_actions (); XFREE (goto_map + ntokens); @@ -892,6 +882,17 @@ tables_generate (void) free (tally); free (width); + + for (i = 0; i < nvectors; i++) + { + XFREE (froms[i]); + XFREE (tos[i]); + XFREE (conflict_tos[i]); + } + + free (froms); + free (tos); + free (conflict_tos); } -- 2.45.2