Skip to content

Commit

Permalink
Fix incorrect serialization of bypass on channels.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 627545541
  • Loading branch information
grebe authored and copybara-github committed Apr 23, 2024
1 parent 9bc8116 commit ed8e7f1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
7 changes: 3 additions & 4 deletions xls/ir/channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,9 @@ std::string Channel::ToString() const {
const std::optional<FifoConfig>& fifo_config =
streaming_channel->fifo_config();
if (fifo_config.has_value()) {
absl::StrAppendFormat(&result, "fifo_depth=%d, ", fifo_config->depth);
if (!fifo_config->bypass) {
absl::StrAppend(&result, "bypass=true, ");
}
absl::StrAppendFormat(&result, "fifo_depth=%d, bypass=%s, ",
fifo_config->depth,
fifo_config->bypass ? "true" : "false");
}
}

Expand Down
33 changes: 32 additions & 1 deletion xls/ir/ir_parser_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1797,7 +1797,7 @@ block my_block(x: bits[32]) {

TEST(IrParserTest, ParseInstantiationWithChannel) {
constexpr std::string_view input = R"(package test
chan foo(bits[32], id=42, kind=streaming, ops=send_receive, flow_control=none, strictness=proven_mutually_exclusive, fifo_depth=0, metadata="""""")
chan foo(bits[32], id=42, kind=streaming, ops=send_receive, flow_control=none, strictness=proven_mutually_exclusive, fifo_depth=0, bypass=true, metadata="""""")
proc placeholder_channel_user(tok: token, init={}) {
recv_out: (token, bits[32]) = receive(tok, channel=foo, id=1)
Expand Down Expand Up @@ -1825,6 +1825,37 @@ block my_block(x: bits[32], y: bits[32]) {
ParsePackageAndCheckDump(input);
}

TEST(IrParserTest, ParseInstantiationWithNoBypassChannel) {
constexpr std::string_view input = R"(package test
chan foo(bits[32], id=42, kind=streaming, ops=send_receive, flow_control=none, strictness=proven_mutually_exclusive, fifo_depth=1, bypass=false, metadata="""""")
proc placeholder_channel_user(tok: token, init={}) {
recv_out: (token, bits[32]) = receive(tok, channel=foo, id=1)
recv_tok: token = tuple_index(recv_out, index=0, id=2)
recv_data: bits[32] = tuple_index(recv_out, index=1, id=3)
send_out: token = send(recv_tok, recv_data, channel=foo, id=4)
next (send_out)
}
block sub_block(in: bits[32], out: bits[32]) {
in: bits[32] = input_port(name=in, id=5)
zero: bits[32] = literal(value=0, id=6)
out: () = output_port(zero, name=out, id=7)
}
block my_block(x: bits[32], y: bits[32]) {
instantiation foo_inst(data_type=bits[32], depth=1, bypass=false, channel=foo, kind=fifo)
instantiation bar(block=sub_block, kind=block)
x: bits[32] = input_port(name=x, id=8)
x_in: () = instantiation_input(x, instantiation=bar, port_name=in, id=9)
x_out: bits[32] = instantiation_output(instantiation=bar, port_name=out, id=10)
y: () = output_port(x_out, name=y, id=11)
}
)";
ParsePackageAndCheckDump(input);
}


TEST(IrParserTest, ParseArrayIndex) {
const std::string input = R"(
fn foo(x: bits[32][6]) -> bits[32] {
Expand Down

0 comments on commit ed8e7f1

Please sign in to comment.