@@ -44,79 +44,85 @@ std::ofstream tout(".z3-trace");
4444
4545static bool g_enable_all_trace_tags = false ;
4646
47- static bool s_tag_enabled[] = {
48- #define X (tag, tc, desc ) false ,
47+ inline unsigned tag2u (TraceTag tag) { return static_cast <unsigned >(tag); }
48+
49+ struct tag_info {
50+ bool is_enabled;
51+ bool is_class;
52+ TraceTag next;
53+ };
54+
55+ static tag_info s_tag_infos[] = {
56+ #define X (tag, tc, desc ) { false , false , TraceTag::tag },
4957#include " util/trace_tags.def"
5058#undef X
5159};
5260
5361
5462bool tag_enabled (TraceTag tag) {
55- return tag < TraceTag::Count && s_tag_enabled[ static_cast < unsigned > (tag)];
63+ return tag < TraceTag::Count && s_tag_infos[ tag2u (tag)]. is_enabled ;
5664}
5765
5866static void enable_tag (TraceTag tag) {
5967 if (tag < TraceTag::Count)
60- s_tag_enabled[ static_cast < unsigned > (tag)] = true ;
68+ s_tag_infos[ tag2u (tag)]. is_enabled = true ;
6169}
6270
6371static void disable_tag (TraceTag tag) {
6472 if (tag < TraceTag::Count)
65- s_tag_enabled[ static_cast < unsigned > (tag)] = false ;
73+ s_tag_infos[ tag2u (tag)]. is_enabled = false ;
6674}
6775
68-
69- void finalize_trace () {
70- }
71-
72- static const TraceTag* get_tag_classes () {
76+ static const tag_info* get_tag_infos () {
7377 static bool tag_class_init = false ; // ignore thread safety assuming TRACE is already under a lock.
7478 if (!tag_class_init) {
7579 // Arrays to track first and last tag in each class
7680 TraceTag first[static_cast <unsigned >(TraceTag::Count)];
7781 TraceTag last[static_cast <unsigned >(TraceTag::Count)];
78- for (unsigned i = 0 ; i < static_cast < unsigned > (TraceTag::Count); ++i)
82+ for (unsigned i = 0 ; i < tag2u (TraceTag::Count); ++i)
7983 first[i] = last[i] = TraceTag::Count;
8084
8185 // Link tags in each class
82- for (unsigned i = 0 ; i < static_cast < unsigned > (TraceTag::Count); ++i) {
86+ for (unsigned i = 0 ; i < tag2u (TraceTag::Count); ++i) {
8387 TraceTag tag = static_cast <TraceTag>(i);
8488 TraceTag tag_class = get_trace_tag_class (tag);
85- unsigned cls = static_cast <unsigned >(tag_class);
89+ s_tag_infos[tag2u (tag_class)].is_class = true ;
90+ unsigned cls = tag2u (tag_class);
8691 if (first[cls] == TraceTag::Count)
8792 first[cls] = tag;
8893 else
89- tag_classes[ static_cast < unsigned > (last[cls])] = tag;
94+ s_tag_infos[ tag2u (last[cls])]. next = tag;
9095 last[cls] = tag;
9196 }
9297 // Close the circular list for each class
93- for (unsigned cls = 0 ; cls < static_cast < unsigned > (TraceTag::Count); ++cls)
98+ for (unsigned cls = 0 ; cls < tag2u (TraceTag::Count); ++cls)
9499 if (last[cls] != TraceTag::Count && first[cls] != TraceTag::Count)
95- tag_classes[ static_cast < unsigned > (last[cls])] = first[cls];
100+ s_tag_infos[ tag2u (last[cls])]. next = first[cls];
96101
97102 tag_class_init = true ;
98103 }
99- return tag_classes ;
104+ return s_tag_infos ;
100105}
101106
102107
103108
104- void enable_trace (const char * tag) {
105- TraceTag tag_str = find_trace_tag_by_string (tag);
106- if (tag_str == TraceTag::Count)
109+ void enable_trace (const char * tag_str) {
110+ TraceTag tag = find_trace_tag_by_string (tag_str);
111+ if (tag == TraceTag::Count) {
112+ warning_msg (" trace tag '%s' does not exist" , tag_str);
107113 return ;
114+ }
108115
109- enable_tag (tag_str );
116+ enable_tag (tag );
110117
111- auto tag_class = get_trace_tag_class (tag_str);
112- if (tag_class != tag_str)
113- return ; // Only enable the tag if it is a class tag.
114- auto const & next_tag = get_tag_classes ();
118+ auto const & tag_infos = get_tag_infos ();
119+ if (!tag_infos[tag2u (tag)].is_class )
120+ return ;
115121
116- auto t = next_tag[ static_cast < unsigned >(tag_str)] ;
117- while (t != tag_str ) {
122+ auto t = tag_infos[ tag2u (tag)]. next ;
123+ while (t != tag ) {
118124 enable_tag (t);
119- t = next_tag[ static_cast < unsigned > (t)];
125+ t = tag_infos[ tag2u (t)]. next ;
120126 }
121127}
122128
0 commit comments