a chisel problem about some value only read-only

39 views Asked by At

I don't get any errors during compilation, but when I try to run the code, it fails. I'm not sure why this error is happening. Previously, when I was writing an RCA(code in the under), I encountered a similar issue, but changing the coding style resolved it. I'm a beginner in Chisel, and I suspect it might be related to variables, but I couldn't find detailed explanations in the official documentation. I've looked for similar issues in other people's code, but I still can't understand it. I don't know why this is happening. Can someone please explain?

for example here,but i cant understand why this is ture

here is code

class ManchesterAdder(n: Int) extends Module {
  val io = IO(new Bundle {
    val a = Input(UInt(n.W))
    val b = Input(UInt(n.W))
    val cin = Input(UInt(1.W))
    val sum = Output(UInt(n.W))
    val cout = Output(UInt(1.W))
  })

  var chain = Module(new Manchestercarrychain(n))
  chain.io.cin := io.cin

  for (i <- s until < n) {
    chain.io.cin(i) := io.a(i) ^ io.b(i)
  }

  val sumReg = RegInit(o.U(n.W))
  val coutReg = RegInit(o.U(1.W))
  sumReg := chain.io.g(n - 1) ^ chain.io.p(n - 1)
  coutReg := chain.io.cout

  io.sum := sumReg
  io.cout := coutReg
}

here is error

[48/48] temp.run
Exception in thread "main" chisel3.packageschiselException: Cannot reassign to read-only ManchesterAdder.?: OpResultIBoc
at ... (
at adder.ManchesterAdder.SanonfunSnew$10(Manchester_Adder.scala:39.
at scala.collection.immutable.Range.foreach$mVcSsp(Range.scala:190
at adder.ManchesterAdder.<init>(Manchester-Adder.scala:38
at adder.generates.SanonfunSnew$10(generate .scala: 20)
at ... ()
... (stack trace trimmed to user code only. Rerun with .-full-stacktrace to see the full stack trace)
at
1 targets failed
temp.run subprocess failed
1

There are 1 answers

0
FabienM On

It's difficult to see exactly where is the error in stack trace you display because lines number doesn't match.

But this lines seems to be wrong :

  val sumReg = RegInit(o.U(n.W))
  val coutReg = RegInit(o.U(1.W))

The variable o does not appear to be declared in sources.

shouldn't it be 0?

  val sumReg = RegInit(0.U(n.W))
  val coutReg = RegInit(0.U(1.W))