Skip to content

Commit 7f99028

Browse files
committed
SystemVerilog: declarations in named blocks in tasks/functions
This fixes the identifier generated for declarations in named blocks in tasks and functions.
1 parent e6f0621 commit 7f99028

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

regression/verilog/functioncall/named_block1.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
CORE
22
named_block1.sv
33

44
^\[.*\] always main\.foo\(\) == 123: PROVED$

src/verilog/verilog_typecheck.cpp

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,11 @@ void verilog_typecheckt::convert_function_or_task(verilog_declt &decl)
273273
{
274274
irep_idt decl_class=decl.get_class();
275275

276-
const std::string identifier=
277-
id2string(module_identifier)+"."+
278-
id2string(decl.get_identifier());
276+
// the base name of the function/task
277+
auto base_name = decl.get_identifier();
278+
279+
const std::string identifier =
280+
id2string(module_identifier) + "." + id2string(base_name);
279281

280282
auto result=symbol_table.get_writeable(identifier);
281283

@@ -292,11 +294,18 @@ void verilog_typecheckt::convert_function_or_task(verilog_declt &decl)
292294

293295
function_or_task_name = symbol.name;
294296

297+
// function/tasks have an implicit named block with the name
298+
// of the function
299+
300+
named_blocks.push_back(id2string(base_name) + ".");
301+
295302
for(auto &inner_decl : decl.declarations())
296303
convert_decl(inner_decl);
297304

298305
convert_statement(decl.body());
299306

307+
named_blocks.pop_back();
308+
300309
function_or_task_name="";
301310

302311
symbol.value=decl.body();
@@ -336,6 +345,11 @@ exprt verilog_typecheckt::elaborate_constant_function_call(
336345

337346
function_or_task_name = function_symbol.name;
338347

348+
// function/tasks have an implicit named block with the name
349+
// of the function
350+
351+
named_blocks.push_back(id2string(function_symbol.base_name) + ".");
352+
339353
for(auto &inner_decl : decl.declarations())
340354
convert_decl(inner_decl);
341355

@@ -380,6 +394,8 @@ exprt verilog_typecheckt::elaborate_constant_function_call(
380394
// interpret it
381395
verilog_interpreter(decl.body());
382396

397+
named_blocks.pop_back();
398+
383399
function_or_task_name="";
384400

385401
// get return value
@@ -429,16 +445,9 @@ void verilog_typecheckt::convert_decl(verilog_declt &decl)
429445
named_block = named_blocks.back();
430446

431447
// fix the type and identifier
432-
irep_idt full_identifier;
433-
434-
if(!function_or_task_name.empty())
435-
full_identifier = id2string(function_or_task_name) + "." +
436-
id2string(named_block) +
437-
id2string(declarator.base_name());
438-
else
439-
full_identifier = id2string(module_identifier) + "." +
440-
id2string(named_block) +
441-
id2string(declarator.base_name());
448+
auto full_identifier = id2string(module_identifier) + "." +
449+
id2string(named_block) +
450+
id2string(declarator.base_name());
442451

443452
symbolt &symbol = symbol_table_lookup(full_identifier);
444453
declarator.type() = symbol.type;

0 commit comments

Comments
 (0)