Skip to content

Commit 3325ddc

Browse files
committed
* 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.
1 parent c6f1a33 commit 3325ddc

File tree

7 files changed

+78
-37
lines changed

7 files changed

+78
-37
lines changed

.project

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
patch_list='Bison Patches <bison-patches@gnu.org>'

ChangeLog

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
2002-08-01 Akim Demaille <[email protected]>
2+
3+
* lib/timevar.c (get_time): Include children time.
4+
* src/lalr.h (LA, LArule): Don't export them: used with the
5+
state_t.
6+
* src/lalr.c (LA, LArule): Static.
7+
* src/lalr.h, src/lalr.c (lalr_free): New.
8+
* src/main.c (main): Call it.
9+
* src/tables.c (pack_vector): Check whether loc is >= to the
10+
table_size, not >.
11+
(pack_tables): Don't free froms, tos, conflict_tos, and pos...
12+
(tables_generate): do it, since that's also it which allocates
13+
them.
14+
Don't free LA and LArule, main does.
15+
116
2002-07-31 Akim Demaille <[email protected]>
217

318
Separate parser tables computation and output.

lib/timevar.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,18 @@ get_time (now)
207207
{
208208
#ifdef USE_TIMES
209209
struct tms tms;
210-
now->wall = times (&tms) * ticks_to_msec;
211-
now->user = tms.tms_utime * ticks_to_msec;
212-
now->sys = tms.tms_stime * ticks_to_msec;
210+
now->wall = times (&tms) * ticks_to_msec;
211+
now->user = (tms.tms_utime + tms.tms_cutime) * ticks_to_msec;
212+
now->sys = (tms.tms_stime + tms.tms_cstime) * ticks_to_msec;
213213
#endif
214214
#ifdef USE_GETRUSAGE
215215
struct rusage rusage;
216216
getrusage (RUSAGE_SELF, &rusage);
217217
now->user = rusage.ru_utime.tv_sec + rusage.ru_utime.tv_usec * 1e-6;
218218
now->sys = rusage.ru_stime.tv_sec + rusage.ru_stime.tv_usec * 1e-6;
219+
getrusage (RUSAGE_CHILDREN, &rusage);
220+
now->user += rusage.ru_utime.tv_sec + rusage.ru_utime.tv_usec * 1e-6;
221+
now->sys += rusage.ru_stime.tv_sec + rusage.ru_stime.tv_usec * 1e-6;
219222
#endif
220223
#ifdef USE_CLOCK
221224
now->user = clock () * clocks_to_msec;

src/lalr.c

+30-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,22 @@ typedef struct goto_list_s
5252
} goto_list_t;
5353

5454

55-
rule_t **LArule = NULL;
56-
bitsetv LA = NULL;
55+
/* LARULE is a vector which records the rules that need lookahead in
56+
various states. The elements of LARULE that apply to state S are
57+
those from LOOKAHEADS[S] through LOOKAHEADS[S+1]-1.
58+
59+
If LR is the length of LArule, then a number from 0 to LR-1 can
60+
specify both a rule and a state where the rule might be applied.
61+
*/
62+
63+
static rule_t **LArule = NULL;
64+
65+
/* LA is a LR by NTOKENS matrix of bits. LA[l, i] is 1 if the rule
66+
LArule[l] is applicable in the appropriate state when the next
67+
token is symbol i. If LA[l, i] and LA[l, j] are both 1 for i != j,
68+
it is a conflict. */
69+
70+
static bitsetv LA = NULL;
5771
size_t nLA;
5872

5973

@@ -460,3 +474,17 @@ lalr (void)
460474
if (trace_flag & trace_sets)
461475
lookaheads_print (stderr);
462476
}
477+
478+
479+
void
480+
lalr_free (void)
481+
{
482+
state_number_t s;
483+
for (s = 0; s < nstates; ++s)
484+
{
485+
states[s]->lookaheads = NULL;
486+
states[s]->lookaheads_rule = NULL;
487+
}
488+
bitsetv_free (LA);
489+
free (LArule);
490+
}

src/lalr.h

+7-19
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
#ifndef LALR_H_
2222
# define LALR_H_
2323

24-
#include "bitset.h"
25-
#include "bitsetv.h"
24+
# include "bitset.h"
25+
# include "bitsetv.h"
2626

2727
/* Import the definition of CORE, TRANSITIONS and REDUCTIONS. */
2828
# include "state.h"
@@ -36,6 +36,11 @@
3636

3737
void lalr PARAMS ((void));
3838

39+
/* Release the information related to lookaheads. Can be performed
40+
once the action tables are computed. */
41+
42+
void lalr_free PARAMS ((void));
43+
3944

4045
/* lalr() builds these data structures. */
4146

@@ -56,22 +61,5 @@ extern goto_number_t *goto_map;
5661
extern state_number_t *from_state;
5762
extern state_number_t *to_state;
5863

59-
/* LARULE is a vector which records the rules that need lookahead in
60-
various states. The elements of LARULE that apply to state S are
61-
those from LOOKAHEADS[S] through LOOKAHEADS[S+1]-1.
62-
63-
If LR is the length of LArule, then a number from 0 to LR-1 can
64-
specify both a rule and a state where the rule might be applied.
65-
*/
66-
67-
extern rule_t **LArule;
68-
69-
/* LA is a LR by NTOKENS matrix of bits. LA[l, i] is 1 if the rule
70-
LAruleno[l] is applicable in the appropriate state when the next
71-
token is symbol i. If LA[l, i] and LA[l, j] are both 1 for i != j,
72-
it is a conflict. */
73-
74-
extern bitsetv LA;
75-
7664

7765
#endif /* !LALR_H_ */

src/main.c

+5
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ main (int argc, char *argv[])
137137
tables_generate ();
138138
timevar_pop (TV_ACTIONS);
139139

140+
/* Lookaheads are no longer needed. */
141+
timevar_push (TV_FREE);
142+
lalr_free ();
143+
timevar_pop (TV_FREE);
144+
140145
/* Output the tables and the parser to ftable. In file output. */
141146
timevar_push (TV_PARSER);
142147
output ();

src/tables.c

+14-13
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ pack_vector (vector_number_t vector)
732732
for (k = 0; ok && k < t; k++)
733733
{
734734
loc = j + state_number_as_int (from[k]);
735-
if (loc > (int) table_size)
735+
if (loc >= (int) table_size)
736736
table_grow (loc);
737737

738738
if (table[loc] != 0)
@@ -839,16 +839,6 @@ pack_table (void)
839839
base_ninf = table_ninf_remap (base, nvectors, BASE_MIN);
840840
table_ninf = table_ninf_remap (table, high + 1, ACTION_MIN);
841841

842-
for (i = 0; i < nvectors; i++)
843-
{
844-
XFREE (froms[i]);
845-
XFREE (tos[i]);
846-
XFREE (conflict_tos[i]);
847-
}
848-
849-
free (froms);
850-
free (tos);
851-
free (conflict_tos);
852842
free (pos);
853843
}
854844

@@ -862,6 +852,8 @@ pack_table (void)
862852
void
863853
tables_generate (void)
864854
{
855+
int i;
856+
865857
/* That's a poor way to make sure the sizes are properly corelated,
866858
in particular the signedness is not taking into account, but it's
867859
not useless. */
@@ -877,8 +869,6 @@ tables_generate (void)
877869
width = XCALLOC (base_t, nvectors);
878870

879871
token_actions ();
880-
bitsetv_free (LA);
881-
free (LArule);
882872

883873
goto_actions ();
884874
XFREE (goto_map + ntokens);
@@ -892,6 +882,17 @@ tables_generate (void)
892882

893883
free (tally);
894884
free (width);
885+
886+
for (i = 0; i < nvectors; i++)
887+
{
888+
XFREE (froms[i]);
889+
XFREE (tos[i]);
890+
XFREE (conflict_tos[i]);
891+
}
892+
893+
free (froms);
894+
free (tos);
895+
free (conflict_tos);
895896
}
896897

897898

0 commit comments

Comments
 (0)