Skip to content

Commit

Permalink
* lib/timevar.c (get_time): Include children time.
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
akimd committed Aug 1, 2002
1 parent c6f1a33 commit 3325ddc
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 37 deletions.
1 change: 1 addition & 0 deletions .project
@@ -0,0 +1 @@
patch_list='Bison Patches <bison-patches@gnu.org>'
15 changes: 15 additions & 0 deletions ChangeLog
@@ -1,3 +1,18 @@
2002-08-01 Akim Demaille <akim@epita.fr>

* 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 <akim@epita.fr>

Separate parser tables computation and output.
Expand Down
9 changes: 6 additions & 3 deletions lib/timevar.c
Expand Up @@ -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;
Expand Down
32 changes: 30 additions & 2 deletions src/lalr.c
Expand Up @@ -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;


Expand Down Expand Up @@ -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);
}
26 changes: 7 additions & 19 deletions src/lalr.h
Expand Up @@ -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"
Expand All @@ -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. */

Expand All @@ -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_ */
5 changes: 5 additions & 0 deletions src/main.c
Expand Up @@ -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 ();
Expand Down
27 changes: 14 additions & 13 deletions src/tables.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}

Expand All @@ -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. */
Expand All @@ -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);
Expand All @@ -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);
}


Expand Down

0 comments on commit 3325ddc

Please sign in to comment.