File tree 3 files changed +31
-0
lines changed
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 {
38
38
#undef DEFINE_TAG
39
39
};
40
40
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
+
41
55
/* *
42
56
* Convert a tag value to a string representation. If ET_ENABLE_ENUM_STRINGS is
43
57
* 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) {
37
37
EXPECT_STREQ (" Bool" , name.data ());
38
38
}
39
39
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
+
40
54
TEST (TagToString, TagNameBufferSize) {
41
55
// Validate that kTagNameBufferSize is large enough to hold the all tag
42
56
// strings without truncation.
Original file line number Diff line number Diff line change @@ -91,6 +91,9 @@ def define_common_targets():
91
91
deps = [
92
92
"//executorch/runtime/core:tag" ,
93
93
],
94
+ preprocessor_flags = [
95
+ "-DET_ENABLE_ENUM_STRINGS"
96
+ ],
94
97
)
95
98
96
99
if True in get_aten_mode_options ():
You can’t perform that action at this time.
0 commit comments