Skip to content

Commit 6732c86

Browse files
authored
Merge pull request #1110 from diffblue/verilog-elsif
Verilog: `elsif
2 parents b33b4b8 + cb7d934 commit 6732c86

File tree

6 files changed

+52
-2
lines changed

6 files changed

+52
-2
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# EBMC 5.7
22

3+
* Verilog: `elsif preprocessor directive
4+
35
# EBMC 5.6
46

57
* SystemVerilog: [*] and [+] SVA operators
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
KNOWNBUG
1+
CORE
22
elsif1.v
3-
3+
--preprocess
4+
^IFDEF$
45
^EXIT=0$
56
^SIGNAL=0$
67
--
8+
^ELSIF$
79
--
810
The elsif directive is not implemented.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
`define X 1
22
`ifdef X
3+
IFDEF
34
`elsif Y
45
ELSIF
56
`endif
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
elsif2.v
3+
--preprocess
4+
^ELSIF$
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
^IFDEF$
9+
--
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
`define Y 1
2+
`ifdef X
3+
`elsif Y
4+
ELSIF
5+
`endif

src/verilog/verilog_preprocessor.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,37 @@ void verilog_preprocessort::directive()
551551
conditional.else_part=true;
552552
condition=conditional.get_cond();
553553
}
554+
else if(text == "elsif")
555+
{
556+
if(conditionals.empty())
557+
throw verilog_preprocessor_errort() << "`elsif without `ifdef/`ifndef";
558+
559+
// skip whitespace
560+
tokenizer().skip_ws();
561+
562+
// we expect an identifier
563+
const auto identifier_token = tokenizer().next_token();
564+
565+
if(!identifier_token.is_identifier())
566+
throw verilog_preprocessor_errort()
567+
<< "expecting an identifier after `elsif";
568+
569+
auto &identifier = identifier_token.text;
570+
571+
tokenizer().skip_until_eol();
572+
573+
bool defined = defines.find(identifier) != defines.end();
574+
575+
conditionalt &conditional = conditionals.back();
576+
577+
if(conditional.else_part)
578+
{
579+
throw verilog_preprocessor_errort() << "`elsif after `else";
580+
}
581+
582+
conditional.condition = defined;
583+
condition = conditional.get_cond();
584+
}
554585
else if(text=="endif")
555586
{
556587
if(conditionals.empty())

0 commit comments

Comments
 (0)