在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
12
返回列表 发新帖
楼主: uunn69

[讨论] systemverilog function task问题请教

[复制链接]
发表于 2018-8-9 16:01:06 | 显示全部楼层
c = a_function   ok
c = a_task         error
 楼主| 发表于 2018-8-9 16:12:38 | 显示全部楼层
 楼主| 发表于 2018-8-9 17:00:45 | 显示全部楼层


c = a_function   ok
c = a_task         error
e_epsh 发表于 2018-8-9 16:01




1,有一点点理解了,能再详细举个例子吗?2, 这种怎么理解?
function  my_agent::build_phase(uvm_phase phase);
   super.build_phase(phase);
   if (is_active == UVM_ACTIVE) begin
      sqr = my_sequencer::type_id::create("sqr", this);
      drv = my_driver::type_id::create("drv", this);
   end
   mon = my_monitor::type_id::create("mon", this);
endfunction
发表于 2018-8-10 09:19:41 | 显示全部楼层
如果声明为void,那么这个function是没有返回值的。所以你那个例子是没有返回值的(但是可以认为是返回一个void类型的名字为build_phase变量)。
如果不是void,那么如果function里面没有return语句,其返回值是与function同名的一个变量,该变量的类型就是你指定的返回类型;
function int add;
endfunction
上面函数是一个空函数,但是你可以用:
initial begin
int a = 2;
a = add();  
end
你会发现上面的操作是OK的,而且a的值是0;
这是因为,函数默认返回了一个叫add的int型变量。可以认为上面那个空函数实际等效于如下操作:
function int add;
int add; // 默认会有的操作,由于没有初始化值,所以为0
return add; // 没有return语句时的默认操作
endfunction
由于有return值, function可以看做一个表达式,但是task只能看做一个语句。output,inout这些可以用于传递参数,而return值决定了其能不能被看做一个表达式。
发表于 2018-8-10 11:28:56 | 显示全部楼层
给楼主一个建议,这种语法上的东西,最好查看一下标准,你的问题标准上已经很明确给出定义了。学习的时候看些书可以,但是遇到问题有疑惑的时候优先查标准

13.4.1 Return values and void functions
The function definition shall implicitly declare a variable, internal to the function, with the same name as the
function. This variable has the same type as the function return value. Function return values can be
specified in two ways, either by using a return statement or by assigning a value to the internal variable
with the same name as the function. For example:

function [15:0] myfunc1 (input [7:0] x,y);
    myfunc1 = x * y - 1; // return value assigned to function name
endfunction
function [15:0] myfunc2 (input [7:0] x,y);
    return x * y - 1; //return value is specified using return statement
endfunction

The return statement shall override any value assigned to the function name. When the return statement is
used, nonvoid functions shall specify an expression with the return.
 楼主| 发表于 2018-8-10 14:05:56 | 显示全部楼层


如果声明为void,那么这个function是没有返回值的。所以你那个例子是没有返回值的(但是可以认为是返回一个 ...
houxiangyun 发表于 2018-8-10 09:19




   懂了,感谢
发表于 2019-1-26 23:36:00 | 显示全部楼层
回复 6# zqq624723237


   学习了
发表于 2019-1-31 02:12:41 | 显示全部楼层
学习了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /1 下一条

×

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-6-14 00:15 , Processed in 0.029693 second(s), 7 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表