Skip to content

Commit

Permalink
Parse Verilog begin_keywords and end_keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
nickg committed Dec 18, 2024
1 parent 12f8f72 commit 017f950
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/lexer.l
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,8 @@ BEFORE ?i:before
<VLOG>"`timescale" { return tTIMESCALE; }
<VLOG>"`celldefine" { }
<VLOG>"`endcelldefine" { }
<VLOG>"`begin_keywords" { return tBEGINKEYWORDS; }
<VLOG>"`end_keywords" { return tENDKEYWORDS; }
<VLOG>"supply0" { return tSUPPLY0; }
<VLOG>"supply1" { return tSUPPLY1; }
<VLOG>"pulldown" { return tPULLDOWN; }
Expand Down
2 changes: 1 addition & 1 deletion src/scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ const char *token_str(token_t tok)
"enum", "tagged", "abort", "sync_abort", "async_abort", "before",
"before!", "before_", "before!_", "|->", "|=>", "next", "inf",
"repeat", "do", "endpoint", "<<", ">>", "<<<", ">>>", "task",
"endtask", "endfunction",
"endtask", "endfunction", "`begin_keywords", "`end_keywords"
};

if (tok >= 200 && tok - 200 < ARRAY_LEN(token_strs))
Expand Down
2 changes: 2 additions & 0 deletions src/scan.h
Original file line number Diff line number Diff line change
Expand Up @@ -414,5 +414,7 @@ bool is_scanned_as_psl(void);
#define tTASK 514
#define tENDTASK 515
#define tENDFUNCTION 516
#define tBEGINKEYWORDS 517
#define tENDKEYWORDS 518

#endif // _SCAN_H
32 changes: 31 additions & 1 deletion src/vlog/vlog-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -3631,6 +3631,27 @@ static void p_timescale_compiler_directive(void)
set_timescale(unit_value, unit_name, prec_value, prec_name, CURRENT_LOC);
}

static void p_keywords_directive(void)
{
// `begin_keywords "version_specifier"

BEGIN("keywords directive");

consume(tBEGINKEYWORDS);

consume(tSTRING);
free(state.last_lval.str);
}

static void p_endkeywords_directive(void)
{
// `end_keywords

BEGIN("endkeywords directive");

consume(tENDKEYWORDS);
}

static void p_directive_list(void)
{
BEGIN("directive list");
Expand All @@ -3640,6 +3661,12 @@ static void p_directive_list(void)
case tTIMESCALE:
p_timescale_compiler_directive();
break;
case tBEGINKEYWORDS:
p_keywords_directive();
break;
case tENDKEYWORDS:
p_endkeywords_directive();
break;
default:
return;
}
Expand All @@ -3655,9 +3682,12 @@ vlog_node_t vlog_parse(void)
if (peek() == tEOF)
return NULL;

p_directive_list();

make_new_arena();

p_directive_list();
if (peek() == tEOF)
return NULL;

return p_description();
}
Expand Down
4 changes: 4 additions & 0 deletions test/vlog/simple_sem.v
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ module bad_target (input d, output q, output reg r);
initial q <= 5; // Error

endmodule // bad_target

`begin_keywords "1800-2023"
`end_keywords
// End of file

0 comments on commit 017f950

Please sign in to comment.