I'm trying to learn chisel3, and I also try to be able to use implicit type conversion from Int to UInt in specific case.
Following is my code.
package VecTest
import chisel3._
import scala.language.implicitConversions
object VecTestMain extends App {
Driver.execute(args, () => new VecTest)
}
object VecTest {
implicit def int2UInt(x: Int) = new fromtIntToLiteral(x).U
}
class VecTest extends Module {
import VecTest._
val io = IO(new Bundle{
val in = Input(UInt(1.W))
val out = Output(UInt(8.W))
})
val v = VecInit(0x20, 0x30)
io.out := v(io.in)
}
I expected scala compiler will try to convert two values in VecInit from Int to UInt, but compiler reports error like below.
[error] /src/directory/this/code/VecTest/VecTest.scala:23:11: inferred type arguments [Int] do not conform to macro method apply's type parameter bounds [T <: chisel3.core.Data]
[error] val v = VecInit(0x20, 0x30)
[error] ^
[error] /src/directory/this/code/VecTest/VecTest.scala:23:19: type mismatch;
[error] found : Int(32)
[error] required: T
[error] val v = VecInit(0x20, 0x30)
[error] ^
[error] /src/directory/this/code/VecTest/VecTest.scala:23:25: type mismatch;
[error] found : Int(48)
[error] required: T
[error] val v = VecInit(0x20, 0x30)
[error] ^
[error] three errors found
First, I thougth compiler can not get int2UInt
(implicit type converter function in object VecTest
) because of out of scope. However, when I fixed the code like below, it will work.
val v = VecInit(int2UInt(0x20), int2UInt(0x30))
I also make a hypotheses that chisel3 already has a implicit type converter like my converter, but that is probably not correct.
Where is my misstakes?