diff --git a/runtime/executor/program.cpp b/runtime/executor/program.cpp index 404542151f2..14e0b83d8aa 100644 --- a/runtime/executor/program.cpp +++ b/runtime/executor/program.cpp @@ -373,6 +373,13 @@ Result Program::get_constant_buffer_data( } } +Result Program::get_named_data_map() const { + if (pte_data_map_.has_value()) { + return &pte_data_map_.value(); + } + return Error::NotFound; +} + Result Program::get_output_flattening_encoding( const char* method_name) const { auto plan = get_execution_plan(internal_program_, method_name); diff --git a/runtime/executor/program.h b/runtime/executor/program.h index 8bcb5fe4d97..e8f059b5873 100644 --- a/runtime/executor/program.h +++ b/runtime/executor/program.h @@ -107,6 +107,12 @@ class Program final { Result get_constant_buffer_data(size_t buffer_idx, size_t nbytes) const; + /** + * Get the named data map from the program. + * @return The named data map. + */ + Result get_named_data_map() const; + /** * Returns the number of methods in the program. */ diff --git a/runtime/executor/test/program_test.cpp b/runtime/executor/test/program_test.cpp index 80f91f1af6a..d82bfb50778 100644 --- a/runtime/executor/test/program_test.cpp +++ b/runtime/executor/test/program_test.cpp @@ -371,6 +371,18 @@ TEST_F(ProgramTest, getMethods) { EXPECT_EQ(strcmp(res2.get(), "forward2"), 0); } +TEST_F(ProgramTest, GetNamedDataMap_Fail) { + Result program = + Program::load(add_loader_.get(), kDefaultVerification); + ASSERT_EQ(program.error(), Error::Ok); + + // Get the named data map. Expect to fail, as add.pte does not have any + // named data segments. + Result named_data_map = + program->get_named_data_map(); + EXPECT_EQ(named_data_map.error(), Error::NotFound); +} + // Test that the deprecated Load method (capital 'L') still works. TEST_F(ProgramTest, DEPRECATEDLoad) { // Parse the Program from the data.