Reputation: 31
I was trying to genrating verilog for the below program but it's throwing AssertionError. Is the corresponding verilog unroll "io.opcode := io.a + io.b" statement 5 times ? it would be very helpful if someone can tell how for loop is working.
val io = new Bundle {
val a = UInt(INPUT, 2)
val b = UInt(INPUT, 2)
val opcode = UInt(INPUT, 2)
val output = UInt(OUTPUT, 2)
}
for(j <- 0 to 4){
io.opcode := io.a + io.b
}
io.output := io.opcode
Upvotes: 1
Views: 94
Reputation: 3987
First, you "io.opcode" as an input, but you are assigning io.a + io.b
to it.
Second, your for loop is doing nothing. It's scala code, and you aren't using the "j" iterator variable anywhere, so this is what it expands to:
io.opcode := io.a + io.b
io.opcode := io.a + io.b
io.opcode := io.a + io.b
io.opcode := io.a + io.b
The semantics here is that the last writer wins, so the last statement of "io.opcode = io.a + io.b" would be the final value. In fact, the previous three statements mean nothing, so they would be pruned from the graph. Of course, io.opcode is actually an input so it won't generate the code you want (it should throw an error).
Upvotes: 2
Reputation: 351
The io.opcode field is an input so when you assign to it you receive an error.
Upvotes: 2