Skip to content

Commit

Permalink
SimulationTarget: don't allocate global std::string objects.
Browse files Browse the repository at this point in the history
... they have a non-trivial constructor. Use std::string_view
instead as they are wrapping constant strings from the .rodata
segment anyway. That also allows to make them constexpr.

Also use designated initializers for readability.

PiperOrigin-RevId: 676651162
  • Loading branch information
hzeller authored and copybara-github committed Sep 20, 2024
1 parent d621d95 commit b118c15
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
12 changes: 5 additions & 7 deletions xls/simulation/simulation_targets.inc
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,21 @@

// The default list of parameterizations of the test. Use with testing::ValuesIn
// in the INSTANTIATE_TEST_SUITE_P invocation.
const SimulationTarget kDefaultSimulationTargets[] = {
inline constexpr SimulationTarget kDefaultSimulationTargets[] = {
#if !defined(ABSL_HAVE_ADDRESS_SANITIZER) && \
!defined(ABSL_HAVE_MEMORY_SANITIZER)
// iverilog crashes with ASAN.
SimulationTarget{"iverilog",
/*use_system_verilog=*/false}
{.simulator = "iverilog", .use_system_verilog = false},
#endif
};

// Test parametameterization which fixes use_system_verilog to false, and is
// Test parameterization which fixes use_system_verilog to false, and is
// only parameterized on Verilog simulator. Use with testing::ValuesIn in the
// INSTANTIATE_TEST_SUITE_P invocation.
const SimulationTarget kVerilogOnlySimulationTargets[] = {
inline constexpr SimulationTarget kVerilogOnlySimulationTargets[] = {
#if !defined(ABSL_HAVE_ADDRESS_SANITIZER) && \
!defined(ABSL_HAVE_MEMORY_SANITIZER)
// iverilog crashes with ASAN.
SimulationTarget{"iverilog",
/*use_system_verilog=*/false}
{.simulator = "iverilog", .use_system_verilog = false},
#endif
};
2 changes: 1 addition & 1 deletion xls/simulation/verilog_test_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace verilog {
struct SimulationTarget {
// Name of the simulator (e.g., "iverilog"). This string is passed to
// xls::verilog::GetVerilogSimulator.
std::string simulator;
std::string_view simulator;
// Whether or not to use SystemVerilog.
bool use_system_verilog;
};
Expand Down

0 comments on commit b118c15

Please sign in to comment.