根据配置值初始化类 [英] Initialize class depending on config value

查看:193
本文介绍了根据配置值初始化类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解如何初始化模块,具体取决于值。所以我有一个 config.extend 值,它将决定核心是否会实例化核心 ExtendedCore 模块。

I would like to find out how it is possible to initialize a Module, depending on a value. So I have a config.extend value which will decide if the core will instantiate of the Core or ExtendedCore module.

但是我收到错误value:=不是Sodor.core的成员。

However I am getting the error "value := is not a member of Sodor.core".

val extend = 1

val core = Module(new Core(data_address))

if(extend==1){
   core := Module(new ExtendedCore(data_address))
}

什么是根据语句初始化模块的正确方法,就像在这种情况下一样?
谢谢。

What is the proper way to intialize a Module depending on the statement, like in this case? Thanks.

推荐答案

:= 是连接运算符在Chisel。它用于连接电线和寄存器。你真正想做的是在精化时有条件地实例化不同的模块(即使用Scala构造而不是 Chisel结构)。

:= is the connection operator in Chisel. It is used for connecting Wires and Registers. What you really want to do is conditionally instantiate different Modules at elaboration time (ie. with Scala constructs not Chisel constructs).

尝试以下:

val extend = 1

val core = if (extend == 1) Module(new ExtendedCore(data_address))
           else Module(new Core(data_address))

这篇关于根据配置值初始化类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆