diff --git a/xls/dslx/BUILD b/xls/dslx/BUILD index 7f97466d97..83f9f67c49 100644 --- a/xls/dslx/BUILD +++ b/xls/dslx/BUILD @@ -502,7 +502,7 @@ cc_library( cc_library( name = "default_dslx_stdlib_path", - srcs = ["default_dslx_stdlib_path.cc"], + srcs = ["default_dslx_stdlib_path.inc"], hdrs = ["default_dslx_stdlib_path.h"], ) diff --git a/xls/dslx/cpp_transpiler/cpp_transpiler_main.cc b/xls/dslx/cpp_transpiler/cpp_transpiler_main.cc index 1d75b2944e..0da87d8c06 100644 --- a/xls/dslx/cpp_transpiler/cpp_transpiler_main.cc +++ b/xls/dslx/cpp_transpiler/cpp_transpiler_main.cc @@ -43,7 +43,8 @@ ABSL_FLAG(std::string, namespaces, "", "Double-colon-delimited namespaces with which to wrap the " "generated code, e.g., \"my::namespace\" or " "\"::my::explicitly::top::level::namespace\"."); -ABSL_FLAG(std::string, dslx_stdlib_path, xls::kDefaultDslxStdlibPath, +ABSL_FLAG(std::string, dslx_stdlib_path, + std::string(xls::kDefaultDslxStdlibPath), "Path to DSLX standard library"); ABSL_FLAG(std::string, dslx_path, "", "Additional paths to search for modules (colon delimited)."); diff --git a/xls/dslx/default_dslx_stdlib_path.h b/xls/dslx/default_dslx_stdlib_path.h index 21a3a75907..6eafd4822c 100644 --- a/xls/dslx/default_dslx_stdlib_path.h +++ b/xls/dslx/default_dslx_stdlib_path.h @@ -15,10 +15,15 @@ #ifndef XLS_DSLX_DEFAULT_DSLX_STDLIB_PATH_H_ #define XLS_DSLX_DEFAULT_DSLX_STDLIB_PATH_H_ -namespace xls { +#include +#include -extern const char* kDefaultDslxStdlibPath; +#include "xls/dslx/default_dslx_stdlib_path.inc" -} // namespace xls +// Check that the included file defines ::xls::kDefaultDslxStdlibPath as a +// std::string_view. +static_assert(std::is_same_v< + std::string_view, + std::remove_cvref_t>); #endif // XLS_DSLX_DEFAULT_DSLX_STDLIB_PATH_H_ diff --git a/xls/dslx/default_dslx_stdlib_path.cc b/xls/dslx/default_dslx_stdlib_path.inc similarity index 86% rename from xls/dslx/default_dslx_stdlib_path.cc rename to xls/dslx/default_dslx_stdlib_path.inc index bcd8b637a7..11bdf99a5a 100644 --- a/xls/dslx/default_dslx_stdlib_path.cc +++ b/xls/dslx/default_dslx_stdlib_path.inc @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "xls/dslx/default_dslx_stdlib_path.h" +#include namespace xls { -const char* kDefaultDslxStdlibPath = "xls/dslx/stdlib"; +inline constexpr std::string_view kDefaultDslxStdlibPath = "xls/dslx/stdlib"; } // namespace xls diff --git a/xls/dslx/interpreter_main.cc b/xls/dslx/interpreter_main.cc index ac33898c05..ed237749eb 100644 --- a/xls/dslx/interpreter_main.cc +++ b/xls/dslx/interpreter_main.cc @@ -50,7 +50,8 @@ // LINT.IfChange ABSL_FLAG(std::string, dslx_path, "", "Additional paths to search for modules (colon delimited)."); -ABSL_FLAG(std::string, dslx_stdlib_path, xls::kDefaultDslxStdlibPath, +ABSL_FLAG(std::string, dslx_stdlib_path, + std::string(xls::kDefaultDslxStdlibPath), "Path to DSLX standard library directory."); ABSL_FLAG( std::string, format_preference, "", diff --git a/xls/dslx/ir_convert/ir_converter_main.cc b/xls/dslx/ir_convert/ir_converter_main.cc index 156887612d..9ef92fb878 100644 --- a/xls/dslx/ir_convert/ir_converter_main.cc +++ b/xls/dslx/ir_convert/ir_converter_main.cc @@ -49,7 +49,7 @@ ABSL_FLAG(std::string, top, "", "top entity in the generated IR. When not provided, all functions " "and procs are converted, there is no top entity defined in the " "generated IR."); -ABSL_FLAG(std::string, stdlib_path, xls::kDefaultDslxStdlibPath, +ABSL_FLAG(std::string, stdlib_path, std::string(xls::kDefaultDslxStdlibPath), "Path to DSLX standard library files."); ABSL_FLAG(std::string, dslx_path, "", "Additional paths to search for modules (colon delimited)."); diff --git a/xls/dslx/lsp/dslx_ls.cc b/xls/dslx/lsp/dslx_ls.cc index b2d95ab5ab..ebf6a1f368 100644 --- a/xls/dslx/lsp/dslx_ls.cc +++ b/xls/dslx/lsp/dslx_ls.cc @@ -44,7 +44,7 @@ #include "xls/dslx/default_dslx_stdlib_path.h" #include "xls/dslx/lsp/language_server_adapter.h" -ABSL_FLAG(std::string, stdlib_path, xls::kDefaultDslxStdlibPath, +ABSL_FLAG(std::string, stdlib_path, std::string(xls::kDefaultDslxStdlibPath), "Path to DSLX standard library files."); static constexpr char kDslxPath[] = "DSLX_PATH"; diff --git a/xls/dslx/prove_quickcheck_main.cc b/xls/dslx/prove_quickcheck_main.cc index 4fd9f45ae2..b40191f94b 100644 --- a/xls/dslx/prove_quickcheck_main.cc +++ b/xls/dslx/prove_quickcheck_main.cc @@ -42,7 +42,8 @@ ABSL_FLAG(std::string, dslx_path, "", "Additional paths to search for modules (colon delimited)."); -ABSL_FLAG(std::string, dslx_stdlib_path, xls::kDefaultDslxStdlibPath, +ABSL_FLAG(std::string, dslx_stdlib_path, + std::string(xls::kDefaultDslxStdlibPath), "Path to DSLX standard library directory."); ABSL_FLAG(std::string, test_filter, "", "Regexp that must be a full match of test name(s) to run."); diff --git a/xls/dslx/type_system/typecheck_main.cc b/xls/dslx/type_system/typecheck_main.cc index 4a63541265..11457e3538 100644 --- a/xls/dslx/type_system/typecheck_main.cc +++ b/xls/dslx/type_system/typecheck_main.cc @@ -42,7 +42,8 @@ ABSL_FLAG(std::string, dslx_path, "", "Additional paths to search for modules (colon delimited)."); -ABSL_FLAG(std::string, dslx_stdlib_path, xls::kDefaultDslxStdlibPath, +ABSL_FLAG(std::string, dslx_stdlib_path, + std::string(xls::kDefaultDslxStdlibPath), "Path to DSLX standard library"); ABSL_FLAG(std::string, output_path, "", "Path to dump the type information to as a protobin -- if not " diff --git a/xls/public/c_api_test.cc b/xls/public/c_api_test.cc index bf5d2e5035..a5f37ac895 100644 --- a/xls/public/c_api_test.cc +++ b/xls/public/c_api_test.cc @@ -38,9 +38,10 @@ TEST(XlsCApiTest, ConvertDslxToIrSimple) { const char* additional_search_paths[] = {}; char* error_out = nullptr; char* ir_out = nullptr; + std::string dslx_stdlib_path = std::string(xls::kDefaultDslxStdlibPath); bool ok = xls_convert_dslx_to_ir(kProgram.c_str(), "my_module.x", "my_module", - /*dslx_stdlib_path=*/xls::kDefaultDslxStdlibPath, + /*dslx_stdlib_path=*/dslx_stdlib_path.c_str(), additional_search_paths, 0, &error_out, &ir_out); absl::Cleanup free_cstrs([&] { @@ -67,10 +68,11 @@ TEST(XlsCApiTest, ConvertDslxToIrError) { xls_c_str_free(ir_out); }); + const std::string dslx_stdlib_path = std::string(xls::kDefaultDslxStdlibPath); bool ok = xls_convert_dslx_to_ir( kInvalidProgram.c_str(), "my_module.x", "my_module", - /*dslx_stdlib_path=*/xls::kDefaultDslxStdlibPath, additional_search_paths, - 0, &error_out, &ir_out); + /*dslx_stdlib_path=*/dslx_stdlib_path.c_str(), additional_search_paths, 0, + &error_out, &ir_out); ASSERT_FALSE(ok); // We should get an error and not get IR. @@ -92,9 +94,11 @@ TEST(XlsCApiTest, ConvertDslxPathToIr) { const char* additional_search_paths[] = {}; char* error_out = nullptr; char* ir_out = nullptr; + const std::string dslx_stdlib_path = std::string(xls::kDefaultDslxStdlibPath); bool ok = xls_convert_dslx_path_to_ir( - module_path.c_str(), /*dslx_stdlib_path=*/xls::kDefaultDslxStdlibPath, - additional_search_paths, 0, &error_out, &ir_out); + module_path.c_str(), + /*dslx_stdlib_path=*/dslx_stdlib_path.c_str(), additional_search_paths, 0, + &error_out, &ir_out); absl::Cleanup free_cstrs([&] { xls_c_str_free(error_out); @@ -274,9 +278,10 @@ TEST(XlsCApiTest, InterpretDslxFailFunction) { const char* additional_search_paths[] = {}; char* error = nullptr; char* ir = nullptr; + const std::string dslx_stdlib_path = std::string(xls::kDefaultDslxStdlibPath); ASSERT_TRUE( xls_convert_dslx_to_ir(kDslxModule.c_str(), "my_module.x", "my_module", - /*dslx_stdlib_path=*/xls::kDefaultDslxStdlibPath, + /*dslx_stdlib_path=*/dslx_stdlib_path.c_str(), additional_search_paths, 0, &error, &ir)) << error; diff --git a/xls/tools/eval_ir_main.cc b/xls/tools/eval_ir_main.cc index 49b3ff1841..e452083da7 100644 --- a/xls/tools/eval_ir_main.cc +++ b/xls/tools/eval_ir_main.cc @@ -183,7 +183,8 @@ ABSL_FLAG(std::string, input_validator_expr, "", ABSL_FLAG(std::string, input_validator_path, "", "Path to a file containing DSLX for an input validator as with " "the `--input_validator` flag."); -ABSL_FLAG(std::string, dslx_stdlib_path, xls::kDefaultDslxStdlibPath, +ABSL_FLAG(std::string, dslx_stdlib_path, + std::string(xls::kDefaultDslxStdlibPath), "Path to DSLX standard library"); ABSL_FLAG(std::string, dslx_path, "", "Additional paths to search for modules (colon delimited).");