Skip to content

Verilog: `elsif #1110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# EBMC 5.7

* Verilog: `elsif preprocessor directive

# EBMC 5.6

* SystemVerilog: [*] and [+] SVA operators
Expand Down
6 changes: 4 additions & 2 deletions regression/verilog/preprocessor/elsif1.desc
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
KNOWNBUG
CORE
elsif1.v

--preprocess
^IFDEF$
^EXIT=0$
^SIGNAL=0$
--
^ELSIF$
--
The elsif directive is not implemented.
1 change: 1 addition & 0 deletions regression/verilog/preprocessor/elsif1.v
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
`define X 1
`ifdef X
IFDEF
`elsif Y
ELSIF
`endif
9 changes: 9 additions & 0 deletions regression/verilog/preprocessor/elsif2.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
elsif2.v
--preprocess
^ELSIF$
^EXIT=0$
^SIGNAL=0$
--
^IFDEF$
--
5 changes: 5 additions & 0 deletions regression/verilog/preprocessor/elsif2.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
`define Y 1
`ifdef X
`elsif Y
ELSIF
`endif
31 changes: 31 additions & 0 deletions src/verilog/verilog_preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,37 @@ void verilog_preprocessort::directive()
conditional.else_part=true;
condition=conditional.get_cond();
}
else if(text == "elsif")
{
if(conditionals.empty())
throw verilog_preprocessor_errort() << "`elsif without `ifdef/`ifndef";

// skip whitespace
tokenizer().skip_ws();

// we expect an identifier
const auto identifier_token = tokenizer().next_token();

if(!identifier_token.is_identifier())
throw verilog_preprocessor_errort()
<< "expecting an identifier after `elsif";

auto &identifier = identifier_token.text;

tokenizer().skip_until_eol();

bool defined = defines.find(identifier) != defines.end();

conditionalt &conditional = conditionals.back();

if(conditional.else_part)
{
throw verilog_preprocessor_errort() << "`elsif after `else";
}

conditional.condition = defined;
condition = conditional.get_cond();
}
else if(text=="endif")
{
if(conditionals.empty())
Expand Down
Loading