I have the following Verilog modules, which I'm simulating with Icarus Verilog. It seems that the ternary operator doesn't work, or has a bug:
main module (i2c_app_tb.v)
`timescale 1ns/100ps
module i2c_app_tb;
wire t1;
wire [7:0] t2;
reg rst = 0;
reg clk = 0;
pullup(t1);
pullupdown_t1 pt1(t1, t2, rst, clk);
always #5 clk <= ~clk;
initial begin
$dumpfile("i2c_app_tb.vcd");
$dumpvars(1, i2c_app_tb);
rst <= 1;
#20 rst <= 0;
#300;
$finish;
end
wire _i0_reg;
assign _i0_reg = pt1.i0_reg;
endmodule
pullupdown_t1.v
module pullupdown_t1 (
inout wire i0,
inout wire [7:0] i1,
input rst,
input clk
);
reg i0_reg;
always @ (posedge clk or posedge rst) begin
if (rst) begin
i0_reg <= 0;
end else begin
i0_reg <= (i0_reg == 0 ? (1'bz) : 0);
end
end
assign i0 = i0_reg;
endmodule
When I simulate the above, I get:
However, if I replace
i0_reg <= (i0_reg == 0 ? (1'bz) : 0);
by
if (i0_reg == 0) begin
i0_reg <= 1'bz;
end else begin
i0_reg <= 0;
end
(which is equivalent), I get:
Am I missing something? Is this a bug?

