Skip to content

Commit

Permalink
Lexer cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nickg committed Sep 15, 2024
1 parent b3587fe commit c1e3e48
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 98 deletions.
12 changes: 1 addition & 11 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,7 @@ esac
AX_GCC_FUNC_ATTRIBUTE([returns_nonnull])
AX_GCC_BUILTIN([__builtin_setjmp])

AC_ARG_ENABLE([sdf],
[AS_HELP_STRING([--enable-sdf], [SDF annotation support])],
[enable_sdf=$enableval],
[enable_sdf=no])

AS_IF([test x$enable_sdf = xyes],
[AC_DEFINE_UNQUOTED([ENABLE_SDF], [1], [SDF annotation enabled])])

AM_CONDITIONAL([ENABLE_SDF], [test x$enable_sdf = xyes])

AX_PROG_FLEX([], [AC_MSG_ERROR(Flex not found)])
AX_PROG_FLEX([], [AC_MSG_ERROR([Flex not found])])

case $host_os in
*cygwin*|msys*|mingw32*)
Expand Down
108 changes: 54 additions & 54 deletions src/lexer.l
Original file line number Diff line number Diff line change
Expand Up @@ -279,58 +279,58 @@ NONDET ?i:nondet
NONDET_V ?i:nondet_vector
UNION ?i:union

INTERCONNECT ?i:interconnect
DELAYFILE ?i:delayfile
SDFVERSION ?i:sdfversion
DESIGN ?i:design
DATE ?i:date
VENDOR ?i:vendor
PROGRAM ?i:program
VERSION ?i:version
DIVIDER ?i:divider
VOLTAGE ?i:voltage
TEMPERATURE ?i:temperature
TIMESCALE ?i:timescale
CELL ?i:cell
CELLTYPE ?i:celltype
INSTANCE ?i:instance
ABSOLUTE ?i:absolute
PATHPULSE ?i:pathpulse
PATHPULSEP ?i:pathpulsepercent
INCREMENT ?i:increment
IOPATH ?i:iopath
DELAY ?i:delay
SETUP ?i:setup
HOLD ?i:hold
SETUPHOLD ?i:setuphold
RECOVERY ?i:recovery
REMOVAL ?i:removal
RECREM ?i:recrem
WIDTH ?i:width
PERIOD ?i:period
SKEW ?i:skew
BIDIRSKEW ?i:bidirectskew
NOCHANGE ?i:nochange
NETDELAY ?i:netdelay
DEVICE ?i:device
COND ?i:cond
CONDELSE ?i:condelse
PATHCONSTRAINT ?i:PATHCONSTRAINT
PERIODCONSTRAINT ?i:PERIODCONSTRAINT
SUM ?i:SUM
DIFF ?i:DIFF
SKEWCONSTRAINT ?i:SKEWCONSTRAINT
ARRIVAL ?i:ARRIVAL
DEPARTURE ?i:DEPARTURE
SLACK ?i:SLACK
WAVEFORM ?i:WAVEFORM
NAME ?i:NAME
EXCEPTION ?i:EXCEPTION
TIMINGCHECK ?i:TIMINGCHECK
TIMINGENV ?i:TIMINGENV
RETAIN ?i:RETAIN
SCOND ?i:SCOND
CCOND ?i:CCOND
INTERCONNECT ?i:interconnect
DELAYFILE ?i:delayfile
SDFVERSION ?i:sdfversion
DESIGN ?i:design
DATE ?i:date
VENDOR ?i:vendor
PROGRAM ?i:program
VERSION ?i:version
DIVIDER ?i:divider
VOLTAGE ?i:voltage
TEMPERATURE ?i:temperature
TIMESCALE ?i:timescale
CELL ?i:cell
CELLTYPE ?i:celltype
INSTANCE ?i:instance
ABSOLUTE ?i:absolute
PATHPULSE ?i:pathpulse
PATHPULSEP ?i:pathpulsepercent
INCREMENT ?i:increment
IOPATH ?i:iopath
DELAY ?i:delay
SETUP ?i:setup
HOLD ?i:hold
SETUPHOLD ?i:setuphold
RECOVERY ?i:recovery
REMOVAL ?i:removal
RECREM ?i:recrem
WIDTH ?i:width
PERIOD ?i:period
SKEW ?i:skew
BIDIRSKEW ?i:bidirectskew
NOCHANGE ?i:nochange
NETDELAY ?i:netdelay
DEVICE ?i:device
COND ?i:cond
CONDELSE ?i:condelse
PATHCONSTRAINT ?i:PATHCONSTRAINT
PERIODCONSTRAINT ?i:PERIODCONSTRAINT
SUM ?i:SUM
DIFF ?i:DIFF
SKEWCONSTRAINT ?i:SKEWCONSTRAINT
ARRIVAL ?i:ARRIVAL
DEPARTURE ?i:DEPARTURE
SLACK ?i:SLACK
WAVEFORM ?i:WAVEFORM
NAME ?i:NAME
EXCEPTION ?i:EXCEPTION
TIMINGCHECK ?i:TIMINGCHECK
TIMINGENV ?i:TIMINGENV
RETAIN ?i:RETAIN
SCOND ?i:SCOND
CCOND ?i:CCOND

%%

Expand Down Expand Up @@ -749,8 +749,8 @@ CCOND ?i:CCOND
<SDF>{INTERCONNECT} { TOKEN(tINTERCONNECT); }
<SDF>{NETDELAY} { TOKEN(tNETDELAY); }
<SDF>{DEVICE} { TOKEN(tDEVICE); }
<SDF>{COND} { TOKEN(tCOND); }
<SDF>{CONDELSE} { TOKEN(tCONDELSE); }
<SDF>{COND} { TOKEN(tSDFCOND); }
<SDF>{CONDELSE} { TOKEN(tSDFCONDELSE); }
<SDF>{PATHCONSTRAINT} { TOKEN(tPATHCONSTR); }
<SDF>{PERIODCONSTRAINT} { TOKEN(tPERIODCONSTR); }
<SDF>{SUM} { TOKEN(tSUM); }
Expand Down
11 changes: 1 addition & 10 deletions src/nvc.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,7 @@ static int elaborate(int argc, char **argv, cmd_state_t *state)
{ "dump-vcode", optional_argument, 0, 'v' },
{ "cover", optional_argument, 0, 'c' },
{ "cover-spec", required_argument, 0, 's' },
#ifdef ENABLE_SDF
{ "sdf", required_argument, 0, 'f' },
#endif
{ "verbose", no_argument, 0, 'V' },
{ "no-save", no_argument, 0, 'N' },
{ "jit", no_argument, 0, 'j' },
Expand All @@ -376,10 +374,7 @@ static int elaborate(int argc, char **argv, cmd_state_t *state)

bool use_jit = DEFAULT_JIT, no_save = false;
cover_mask_t cover_mask = 0;
char *cover_spec_file = NULL;
#ifdef ENABLE_SDF
char *sdf_args = NULL;
#endif
char *cover_spec_file = NULL, *sdf_args = NULL;
int cover_array_limit = 0;
const int next_cmd = scan_cmd(2, argc, argv);
int c, index = 0;
Expand Down Expand Up @@ -420,11 +415,9 @@ static int elaborate(int argc, char **argv, cmd_state_t *state)
case 's':
cover_spec_file = optarg;
break;
#ifdef ENABLE_SDF
case 'f':
sdf_args = optarg;
break;
#endif
case 0:
// Set a flag
break;
Expand Down Expand Up @@ -458,12 +451,10 @@ static int elaborate(int argc, char **argv, cmd_state_t *state)
cover_load_spec_file(cover, cover_spec_file);
}

#ifdef ENABLE_SDF
if (sdf_args != NULL) {
// TODO: Pass min-max spec to underlying sdf_parse somehow
analyse_file(sdf_args, NULL, NULL);
}
#endif

if (state->registry != NULL) {
unit_registry_free(state->registry);
Expand Down
6 changes: 2 additions & 4 deletions src/scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ void input_from_buffer(const char *buf, size_t len, hdl_kind_t kind)
reset_vhdl_parser();
break;
case SOURCE_SDF:
#ifdef ENABLE_SDF
reset_sdf_parser();
#endif
break;
}
}
Expand Down Expand Up @@ -212,7 +210,7 @@ const char *token_str(token_t tok)
"period", "nochange", "cond", "scond", "ccond", "path constraint",
"period constraint", "sum", "diff", "skew constraint", "exception",
"name", "arrival", "departure", "slack", "waveform", "increment",
"absolute"
"absolute", "~&", "~|", "~^",
};
if (tok >= 500 && tok - 500 < ARRAY_LEN(sdf_token_strs))
return sdf_token_strs[tok - 500];
Expand Down Expand Up @@ -305,7 +303,7 @@ const char *pp_defines_get(const char *name)
return shash_get(pp_defines, name);
}

int pp_yylex(void)
static int pp_yylex(void)
{
const int tok = lookahead != -1 ? lookahead : yylex();
lookahead = -1;
Expand Down
4 changes: 0 additions & 4 deletions src/scan.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ void input_from_file(const char *file);
void input_from_buffer(const char *buf, size_t len, hdl_kind_t hdl);
hdl_kind_t source_kind(void);
token_t processed_yylex(void);
int pp_yylex(void);
const char *token_str(token_t tok);
void free_token(token_t tok, yylval_t *lval);

Expand Down Expand Up @@ -383,11 +382,8 @@ bool is_scanned_as_psl(void);
#define tWAVEFORM 549
#define tINCREMENT 550
#define tABSOLUTE 551

// SDF operator symbols
#define tTILDEAMP 552
#define tTILDEBAR 553
#define tTILDECARET 554


#endif // _SCAN_H
22 changes: 11 additions & 11 deletions src/sdf/sdf-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ static inline void _push_state(const rule_state_t *r)
static token_t peek_nth(int n)
{
while (((state.tokenq_head - state.tokenq_tail) & (TOKENQ_SIZE - 1)) < n) {
const token_t token = pp_yylex();
const token_t token = processed_yylex();

int next = (state.tokenq_head + 1) & (TOKENQ_SIZE - 1);
assert(next != state.tokenq_tail);
Expand Down Expand Up @@ -1482,9 +1482,9 @@ static void p_port_tchk(void)

BEGIN("port tcheck");

if (peek_nth(2) == tCOND) {
if (peek_nth(2) == tSDFCOND) {
consume(tLPAREN);
consume(tCOND);
consume(tSDFCOND);

if (scan(tSTRING))
p_qstring();
Expand Down Expand Up @@ -1614,11 +1614,11 @@ static void p_scond_or_ccond(sdf_cond_kind_t kind)
consume(tok); \
\
bool cond_seen = false; \
if (peek_nth(2) == tCOND) \
if (peek_nth(2) == tSDFCOND) \
cond_seen = true; \
p_port_tchk(); \
\
if (peek_nth(2) == tCOND) \
if (peek_nth(2) == tSDFCOND) \
cond_seen = true; \
p_port_tchk(); \
\
Expand All @@ -1637,7 +1637,7 @@ DEFINE_2P2RV_TCHK(p_setuphold_timing_check, "setuphold timing check", tSETUPHOLD
DEFINE_2P2RV_TCHK(p_recrem_timing_check, "recrem timing check", tRECREM, S_TCHECK_RECREM);

#define DEFINE_2P1V_TCHK(func_name, msg, tok, subkind) \
static void func_name(void) \
static void func_name(void) \
{ \
/* setup_timing_check ::= */ \
/* ( SETUP port_tchk port_tchk value ) */ \
Expand Down Expand Up @@ -1819,7 +1819,7 @@ static void p_condelse_def(void)
BEGIN("condelse def");

consume(tLPAREN);
consume(tCONDELSE);
consume(tSDFCONDELSE);

p_iopath_def();

Expand All @@ -1834,7 +1834,7 @@ static void p_cond_def(void)
BEGIN("cond def");

consume(tLPAREN);
consume(tCOND);
consume(tSDFCOND);

if (scan(tSTRING))
p_qstring();
Expand Down Expand Up @@ -1923,18 +1923,18 @@ static void p_deldef_list(sdf_flags_t flag)
BEGIN("deldef list");

int tok = peek_nth(2);
while (tok == tIOPATH || tok == tCOND || tok == tCONDELSE ||
while (tok == tIOPATH || tok == tSDFCOND || tok == tSDFCONDELSE ||
tok == tPORT || tok == tINTERCONNECT || tok == tNETDELAY ||
tok == tDEVICE) {

switch (tok) {
case tIOPATH:
p_iopath_def();
break;
case tCOND:
case tSDFCOND:
p_cond_def();
break;
case tCONDELSE:
case tSDFCONDELSE:
p_condelse_def();
break;
case tPORT:
Expand Down
2 changes: 1 addition & 1 deletion src/sdf/sdf-util.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (C) 2022 Nick Gasson
// Copyright (C) 2024 Nick Gasson
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion test/test_sdf.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (C) 2022-2023 Nick Gasson
// Copyright (C) 2022-2024 Nick Gasson
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 0 additions & 2 deletions test/unit_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ int main(int argc, char **argv)
#endif
nfail += RUN_TESTS(psl);
nfail += RUN_TESTS(vlog);
#ifdef ENABLE_SDF
nfail += RUN_TESTS(sdf);
#endif
#ifdef ENABLE_TCL
nfail += RUN_TESTS(shell);
#endif
Expand Down

0 comments on commit c1e3e48

Please sign in to comment.