小编R.M*_*mey的帖子

加载没有模块的源文件

我想通过我的程序传递一个文件并从中获取一个函数.

例如,我有一个文件,foo.py谁的位置直到运行时才知道(它将通过命令行传递给代码或类似的东西),可以在我的系统上的任何位置,如下所示:

def bar():
    return "foobar"
Run Code Online (Sandbox Code Playgroud)

如何让我的代码运行该函数bar

如果在运行时之前知道该位置,我可以这样做:

import sys
sys.path.append("path_to_foo")
import foo

foo.bar()
Run Code Online (Sandbox Code Playgroud)

我可以init.py在文件夹中创建一个文件,foo.py然后使用importlib或者imp看起来很麻烦.我不能用__import__我取ImportError: Import by filename is not supported.

python

4
推荐指数
1
解决办法
2045
查看次数

将参数传递给 Verilog 函数

我想将参数传递给函数并将其用作参数(例如选择位),但我不知道如何告诉函数此输入是常量。

例如,如果我想这样做:

assign foo = bar[MY_PARAM:0];
Run Code Online (Sandbox Code Playgroud)

我想写my_function这样我就可以做到这一点:

assign foo = my_function(bar, MY_PARAM);
Run Code Online (Sandbox Code Playgroud)

就我而言,我需要做更多的事情,只是选择位,但不要太多,并且我希望它适用于不同位宽度的输入。如果我只是想选择一点,我可以使用下面的函数,我希望有一个类似形式的解决方案,但我无法计算出语法:

function my_function;
  input [3:0] data, my_bit;
  begin
    my_function = data[my_bit];
  end
endfunction
Run Code Online (Sandbox Code Playgroud)

根据 Silicon1602 的回答,我需要的代码是:

virtual class myClass#(parameter LOCAL_PARAM);
  static function [LOCAL_PARAM:0] my_function;
    input [LOCAL_PARAM:0] data;
    begin
      my_function = data[LOCAL_PARAM:0];
    end
  endfunction
endclass
assign foo = myClass#(MY_PARAM)::my_function(bar);
Run Code Online (Sandbox Code Playgroud)

起初我忘记了这个[LOCAL_PARAM]部分,只是恢复了 1 位。

verilog system-verilog

4
推荐指数
2
解决办法
2万
查看次数

标签 统计

python ×1

system-verilog ×1

verilog ×1