From 783909e313969cf500337116b3b4d07301799d12 Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Tue, 2 Dec 2025 18:07:44 -0800 Subject: [PATCH] Verilog: introduce verilog_function_callt::is_system_function_call() To remove the duplication of the logic that detects system function/task identifiers, introduce a method that identifies system task/function call statements. --- src/verilog/verilog_expr.cpp | 15 ++++++++++++--- src/verilog/verilog_expr.h | 5 ++++- src/verilog/verilog_typecheck.cpp | 11 ++++------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/verilog/verilog_expr.cpp b/src/verilog/verilog_expr.cpp index 3727917a9..05431cd4d 100644 --- a/src/verilog/verilog_expr.cpp +++ b/src/verilog/verilog_expr.cpp @@ -50,11 +50,20 @@ typet verilog_declaratort::merged_type(const typet &declaration_type) const return result; } +static bool is_system_function_identifier(const exprt &function) +{ + return function.id() == ID_symbol && + has_prefix(id2string(to_symbol_expr(function).get_identifier()), "$"); +} + bool function_call_exprt::is_system_function_call() const { - return function().id() == ID_symbol && - has_prefix( - id2string(to_symbol_expr(function()).get_identifier()), "$"); + return is_system_function_identifier(function()); +} + +bool verilog_function_callt::is_system_function_call() const +{ + return is_system_function_identifier(function()); } void verilog_module_sourcet::show(std::ostream &out) const diff --git a/src/verilog/verilog_expr.h b/src/verilog/verilog_expr.h index f1b960086..213d48300 100644 --- a/src/verilog/verilog_expr.h +++ b/src/verilog/verilog_expr.h @@ -1413,6 +1413,7 @@ inline verilog_ift &to_verilog_if(exprt &expr) return static_cast(expr); } +/// task or function enable class verilog_function_callt:public verilog_statementt { public: @@ -1430,7 +1431,9 @@ class verilog_function_callt:public verilog_statementt { return op0(); } - + + bool is_system_function_call() const; + exprt::operandst &arguments() { return op1().operands(); diff --git a/src/verilog/verilog_typecheck.cpp b/src/verilog/verilog_typecheck.cpp index 95d00513d..52e52d136 100644 --- a/src/verilog/verilog_typecheck.cpp +++ b/src/verilog/verilog_typecheck.cpp @@ -869,17 +869,14 @@ Function: verilog_typecheckt::convert_function_call_or_task_enable void verilog_typecheckt::convert_function_call_or_task_enable( verilog_function_callt &statement) { - irep_idt base_name= - to_symbol_expr(statement.function()).get_identifier(); - - // We ignore everyting that starts with a '$', - // e.g., $display etc - - if(!base_name.empty() && base_name[0]=='$') + if(statement.is_system_function_call()) { + // we ignore all of these } else { + irep_idt base_name = to_symbol_expr(statement.function()).get_identifier(); + // look it up const irep_idt full_identifier = id2string(module_identifier) + "." + id2string(base_name);