有兴趣让某些Chisel2
代码在Chisel3
均衡范围内工作,我设法有Chisel2
凿教程示例,例如FullAdder
:
class FullAdder extends Module {
val io = new Bundle {
val a = UInt(INPUT, 1)
val b = UInt(INPUT, 1)
val cin = UInt(INPUT, 1)
val sum = UInt(OUTPUT, 1)
val cout = UInt(OUTPUT, 1)
}
// Generate the sum
val a_xor_b = io.a ^ io.b
io.sum := a_xor_b ^ io.cin
// Generate the carry
val a_and_b = io.a & io.b
val b_and_cin = io.b & io.cin
val a_and_cin = io.a & io.cin
io.cout := a_and_b | b_and_cin | a_and_cin
}
启动并运行命令:
>test:runMain examples.Launcher FullAdder
使用线条中包含的一些魔法灰尘:
import Chisel._
但是,我尝试在此示例中实例化FullAdder
(当然,添加import Chisel._
):
class Adder(val n:Int) extends Module {
val io = new Bundle {
val A = UInt(INPUT, n)
val B = UInt(INPUT, n)
val Cin = UInt(INPUT, 1)
val Sum = UInt(OUTPUT, n)
val Cout = UInt(OUTPUT, 1)
}
//create a vector of FullAdders
val FAs = Vec(n, Module(new FullAdder()).io)
val carry = Wire(Vec(n+1, UInt(width = 1)))
val sum = Wire(Vec(n, Bool()))
//first carry is the top level carry in
carry(0) := io.Cin
//wire up the ports of the full adders
for (i <- 0 until n) {
FAs(i).a := io.A(i)
FAs(i).b := io.B(i)
FAs(i).cin := carry(i)
carry(i+1) := FAs(i).cout
sum(i) := FAs(i).sum.toBool()
}
io.Sum := sum.toBits.toUInt()
io.Cout := carry(n)
}
我收到有关此行的错误:
io.Sum := sum.toBits.toUInt()
如下:
[error] /home/apaj/testing-learning-journey/learning-journey/src/main/scala/examples/Adder.scala:32: not enough arguments for method toUInt: (implicit compileOptions: chisel3.core.CompileOptions)chisel3.core.UInt.
[error] Unspecified value parameter compileOptions.
[error] io.Sum := sum.toBits.toUInt()
找到的信息here和here使我得出结论,我应该尝试使用asUInt()
代替toUInt()
。
然而,这导致以下输出到我的要求:
> test:run-main examples.Launcher Adder
[info] Running examples.Launcher Adder
Starting tutorial Adder
[info] [0.001] Elaborating design...
chisel3.core.Binding$ExpectedHardwareException: bits to be indexed 'chisel3.core.UInt@30' must be hardware, not a bare Chisel type
之后出现了很多类似Java的投诉,并以:
结束================================================================================
Errors: 1: in the following tutorials
Tutorial Adder: exception bits to be indexed 'chisel3.core.UInt@30' must be hardware, not a bare Chisel type
================================================================================
我能找到的唯一相关资源是bug report,但我真的不知道如何实现这个建议,我应该在哪里解决&#39; chisel3.core的问题。 UINT @ 30&#39;必须是硬件。
我想我错过了我应该导入的其他内容,以便在此上下文中启用asUInt()
的正确翻译,但我恐怕没有看到它。请尽可能提供帮助,或至少提供进一步阅读的指示 - 非常感谢,谢谢!
答案 0 :(得分:1)
我对Chisel2部分有点生疏,但我认为问题(在使用io.Sum := sum.asUInt()
后正确修复之后)是行
val FAs = Vec(n, Module(new FullAdder()).io)
这不是实例化Vec
的{{1}},而只是创建一个包含该类型元素的Vec。以下编译给我。它从一个实例化的FullAdders Seq创建Vec。
FullAdders
它试图消除像这样的代码消除了推动chisel3的一些不同的API。我希望这会有所帮助。