Skip to content

Commit

Permalink
Fix channel reference serialization in fifo instantiations.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 619694801
  • Loading branch information
grebe authored and copybara-github committed Mar 27, 2024
1 parent 9821e0e commit a4c2e54
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion xls/ir/instantiation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ absl::StatusOr<InstantiationPort> FifoInstantiation::GetOutputPort(
std::string FifoInstantiation::ToString() const {
std::string channel_str;
if (channel_name_.has_value()) {
channel_str = absl::StrFormat("channel=\"%s\", ", *channel_name_);
channel_str = absl::StrFormat("channel=%s, ", *channel_name_);
}

return absl::StrFormat(
Expand Down
30 changes: 30 additions & 0 deletions xls/ir/ir_parser_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1795,6 +1795,36 @@ block my_block(x: bits[32]) {
ParsePackageAndCheckDump(input);
}

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="""""")
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=0, bypass=true, 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 a4c2e54

Please sign in to comment.