Skip to content

Commit

Permalink
Descriptive error for returns from sub-block functions,
Browse files Browse the repository at this point in the history
which are not yet implemented.

PiperOrigin-RevId: 715065102
  • Loading branch information
Sean Purser-Haskell authored and copybara-github committed Jan 13, 2025
1 parent ae90a56 commit ea5127c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
5 changes: 5 additions & 0 deletions xls/contrib/xlscc/translator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,11 @@ absl::Status Translator::GenerateIR_SubBlockStub(
const FunctionInProgress& header) {
const xls::SourceInfo body_loc = GetLoc(*funcdecl);

if (!funcdecl->getReturnType()->isVoidType()) {
return absl::UnimplementedError(ErrorMessage(
body_loc, "Returns from sub-block functions are not yet supported."));
}

XLS_ASSIGN_OR_RETURN(std::optional<int64_t> depth_specified,
GetAnnotationWithNonNegativeIntegerParam(
*funcdecl, "hls_control_channel_depth", body_loc));
Expand Down
52 changes: 52 additions & 0 deletions xls/contrib/xlscc/unit_tests/translator_proc_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9177,6 +9177,58 @@ TEST_P(TranslatorProcTest, MultiBlockIRSim) {
}
}

TEST_P(TranslatorProcTest, MultiBlockReturn) {
const std::string content = R"(
#pragma hls_design block
bool block_a(__xls_channel<int, __xls_channel_dir_In>& in,
__xls_channel<int, __xls_channel_dir_InOut>& xfer) {
int a = in.read();
xfer.write(a + 1);
return a == 1;
}

#pragma hls_design block
void block_b(__xls_channel<int, __xls_channel_dir_Out>& out,
__xls_channel<int, __xls_channel_dir_InOut>& xfer) {
int b = xfer.read();
out.write(b * 10);
}

#pragma hls_top
void foo(__xls_channel<int, __xls_channel_dir_In>& in,
__xls_channel<int, __xls_channel_dir_Out>& out) {
static __xls_channel<int, __xls_channel_dir_InOut> xfer;
(void)block_a(in, xfer);
block_b(out, xfer);
}
)";

HLSBlock block_spec;
{
block_spec.set_name("foo");

HLSChannel* ch_in1 = block_spec.add_channels();
ch_in1->set_name("in");
ch_in1->set_is_input(true);
ch_in1->set_type(FIFO);

HLSChannel* ch_out = block_spec.add_channels();
ch_out->set_name("out");
ch_out->set_is_input(false);
ch_out->set_type(FIFO);
}

XLS_ASSERT_OK(ScanFile(content, /*clang_argv=*/{},
/*io_test_mode=*/false,
/*error_on_init_interval=*/false));
package_ = std::make_unique<xls::Package>("my_package");
ASSERT_THAT(
translator_->GenerateIR_Block(package_.get(), block_spec).status(),
absl_testing::StatusIs(
absl::StatusCode::kUnimplemented,
testing::HasSubstr("Returns from sub-block functions")));
}

} // namespace

} // namespace xlscc

0 comments on commit ea5127c

Please sign in to comment.