1313#include " ../Plugins/PluginManager.hpp"
1414#include " ../System/TLSystem.hpp"
1515#include " ../PortGen/portgen_dynamic.hpp"
16+ #include " ../Events/TLSystemEvent.hpp"
1617
1718#include < verilated_fst_c.h>
1819
1920#if TLTEST_MEMORY == 1
2021#include " v3_memaxi.hpp"
2122#endif
2223
23-
2424static bool wave_enable = true ;
2525static uint64_t wave_begin = 0 ;
2626static uint64_t wave_end = 0 ;
@@ -104,24 +104,6 @@ inline static void V3EvalPosedge(uint64_t& time, VTestTop* top)
104104}
105105
106106
107- void V3Finalize ()
108- {
109- if (!initialized)
110- return ;
111-
112- if (!finalized)
113- {
114- TLFinalize (&tltest, &plugins);
115- finalized = true ;
116- }
117- }
118-
119- void V3SignalHandler (int signum)
120- {
121- V3Finalize ();
122- }
123-
124-
125107template <typename , typename = void >
126108struct has_port_time : std::false_type {};
127109
@@ -153,7 +135,7 @@ template<ConceptPortL2ToL1Hint T>
153135struct has_port_l2_to_l1_hint <T, void > : std::true_type {};
154136
155137template <ConceptPortL2ToL1Hint T>
156- typename std::enable_if<has_port_l2_to_l1_hint<T>::value>::type V3PullL2ToL1Hint (
138+ typename std::enable_if<has_port_l2_to_l1_hint<T>::value>::type V3PushL2ToL1Hint (
157139 T* top,
158140 uint8_t & valid,
159141 uint32_t & sourceId,
@@ -165,23 +147,70 @@ typename std::enable_if<has_port_l2_to_l1_hint<T>::value>::type V3PullL2ToL1Hint
165147}
166148
167149template <typename T>
168- typename std::enable_if<!has_port_l2_to_l1_hint<T>::value>::type V3PullL2ToL1Hint (
150+ typename std::enable_if<!has_port_l2_to_l1_hint<T>::value>::type V3PushL2ToL1Hint (
169151 T* top,
170152 uint8_t & valid,
171153 uint32_t & sourceId,
172154 uint8_t & isKeyword)
173155{ }
174156
175- void V3PullL2ToL1Hint (VTestTop* verilated, TLSequencer* tltest)
157+ void V3PushL2ToL1Hint (VTestTop* verilated, TLSequencer* tltest)
176158{
177159 auto & io = tltest->L2ToL1Hint (0 );
178160
179- V3PullL2ToL1Hint <VTestTop>(verilated,
161+ V3PushL2ToL1Hint <VTestTop>(verilated,
180162 io.valid ,
181163 io.sourceId ,
182164 io.isKeyword );
183165}
184166
167+ template <typename T>
168+ concept ConceptPortLogPerf = requires {
169+ { std::declval<T>().log_dump } -> std::convertible_to<uint8_t >;
170+ { std::declval<T>().log_clean } -> std::convertible_to<uint8_t >;
171+ };
172+
173+ template <typename , typename = void >
174+ struct has_port_log_perf : std::false_type {};
175+
176+ template <ConceptPortLogPerf T>
177+ struct has_port_log_perf <T, void > : std::true_type {};
178+
179+ template <ConceptPortLogPerf T>
180+ typename std::enable_if<has_port_log_perf<T>::value>::type V3PullLogPerf (
181+ T* top,
182+ uint8_t dump,
183+ uint8_t clean)
184+ {
185+ top->log_dump = dump;
186+ top->log_clean = clean;
187+ }
188+
189+ template <typename T>
190+ typename std::enable_if<!has_port_log_perf<T>::value>::type V3PullLogPerf (
191+ T* top,
192+ uint8_t dump,
193+ uint8_t clean)
194+ { }
195+
196+
197+ void V3Finalize ()
198+ {
199+ if (!initialized)
200+ return ;
201+
202+ if (!finalized)
203+ {
204+ TLFinalize (&tltest, &plugins);
205+ finalized = true ;
206+ }
207+ }
208+
209+ void V3SignalHandler (int signum)
210+ {
211+ V3Finalize ();
212+ }
213+
185214
186215int main (int argc, char **argv)
187216{
@@ -210,13 +239,30 @@ int main(int argc, char **argv)
210239 else
211240 std::cout << " [V3Main] \033 [31mNot accepting L2ToL1Hint from TestTop\033 [0m." << std::endl;
212241
242+ if constexpr (has_port_log_perf<VTestTop>::value)
243+ std::cout << " [V3Main] \033 [1;32mControlling Performance Logging of TestTop\033 [0m." << std::endl;
244+ else
245+ std::cout << " [V3Main] \033 [31mNot controlling Performance Logging of TestTop\033 [0m." << std::endl;
246+
213247 //
214248 Verilated::commandArgs (argc, argv);
215249
216250 // initialize TL-Test subsystem
217251 TLInitialize (&tltest, &plugins, [](TLLocalConfig&) -> void {});
218252 initialized = true ;
219253
254+ Gravity::RegisterListener (
255+ Gravity::MakeListener<TLSystemFinishEvent>(
256+ Gravity::StringAppender (" v3main.finish" ).ToString (),
257+ -1 ,
258+ [&time] (TLSystemFinishEvent& event) -> void {
259+
260+ std::ios_base::sync_with_stdio (true );
261+ V3PullLogPerf (top, 1 , 0 );
262+ }
263+ )
264+ );
265+
220266 // load PortGen component
221267# ifdef TLTEST_PORTGEN_DYNAMIC
222268 V3::PortGen::LoadDynamic (
@@ -267,6 +313,8 @@ int main(int argc, char **argv)
267313 fst->open (GetFstFileName ().c_str ());
268314 }
269315
316+ V3PullLogPerf (top, 0 , 0 );
317+
270318 V3Reset (time, top, 10 );
271319 V3PushTime (top, time);
272320
@@ -280,7 +328,7 @@ int main(int argc, char **argv)
280328 V3::PortGen::PushChannelB (top, tltest);
281329 V3::PortGen::PushChannelD (top, tltest);
282330
283- V3PullL2ToL1Hint (top, tltest);
331+ V3PushL2ToL1Hint (top, tltest);
284332
285333#if TLTEST_MEMORY == 1
286334 V3::Memory::PushChannelAW (top, tltest);
@@ -337,15 +385,22 @@ int main(int argc, char **argv)
337385 //
338386 int error = 0 ;
339387
388+ std::cerr << std::flush;
389+ std::cout << std::flush;
390+
340391 //
341392 if (tltest->IsFinished ())
342393 {
394+ TLSystemFinishedEvent ().Fire ();
395+
343396 LogInfo (" test_top" ,
344397 Append (" TL-Test TileLink subsystem FINISHED." )
345398 .EndLine ());
346399 }
347400 else if (tltest->IsFailed ())
348401 {
402+ TLSystemFailedEvent ().Fire ();
403+
349404 LogInfo (" test_top" ,
350405 Append (" TL-Test TileLink subsystem FAILED." )
351406 .EndLine ());
0 commit comments