File tree Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,20 @@ enum class Tag : uint32_t {
3838#undef DEFINE_TAG
3939};
4040
41+ #if ET_ENABLE_ENUM_STRINGS
42+ inline const char * tag_to_string (Tag tag) {
43+ switch (tag) {
44+ #define CASE_TAG (x ) \
45+ case Tag::x: \
46+ return #x;
47+ EXECUTORCH_FORALL_TAGS (CASE_TAG)
48+ #undef CASE_TAG
49+ default :
50+ return " Unknown" ;
51+ }
52+ }
53+ #endif // ET_ENABLE_ENUM_STRINGS
54+
4155/* *
4256 * Convert a tag value to a string representation. If ET_ENABLE_ENUM_STRINGS is
4357 * set (it is on by default), this will return a string name (for example,
Original file line number Diff line number Diff line change @@ -37,6 +37,20 @@ TEST(TagToString, TagValues) {
3737 EXPECT_STREQ (" Bool" , name.data ());
3838}
3939
40+ TEST (TagToString, PrintTag) {
41+ const char * name = tag_to_string (Tag::Tensor);
42+ EXPECT_STREQ (" Tensor" , name);
43+
44+ name = tag_to_string (Tag::Int);
45+ EXPECT_STREQ (" Int" , name);
46+
47+ name = tag_to_string (Tag::Double);
48+ EXPECT_STREQ (" Double" , name);
49+
50+ name = tag_to_string (Tag::Bool);
51+ EXPECT_STREQ (" Bool" , name);
52+ }
53+
4054TEST (TagToString, TagNameBufferSize) {
4155 // Validate that kTagNameBufferSize is large enough to hold the all tag
4256 // strings without truncation.
Original file line number Diff line number Diff line change @@ -91,6 +91,9 @@ def define_common_targets():
9191 deps = [
9292 "//executorch/runtime/core:tag" ,
9393 ],
94+ preprocessor_flags = [
95+ "-DET_ENABLE_ENUM_STRINGS"
96+ ],
9497 )
9598
9699 if True in get_aten_mode_options ():
You can’t perform that action at this time.
0 commit comments