2222#include " absl/log/check.h"
2323#include " absl/log/log.h"
2424#include " absl/status/status.h"
25+ #include " absl/strings/str_cat.h"
2526#include " absl/strings/str_split.h"
2627#include " absl/types/span.h"
2728#include " xls/common/exit_status.h"
2829#include " xls/common/file/filesystem.h"
2930#include " xls/common/init_xls.h"
31+ #include " xls/common/status/ret_check.h"
3032#include " xls/common/status/status_macros.h"
3133#include " xls/dslx/cpp_transpiler/cpp_transpiler.h"
32- #include " xls/dslx/cpp_transpiler/cpp_type_generator.h"
3334#include " xls/dslx/create_import_data.h"
3435#include " xls/dslx/default_dslx_stdlib_path.h"
3536#include " xls/dslx/import_data.h"
4041ABSL_FLAG (std::vector<std::string>, include_headers, {}, " Include headers." );
4142ABSL_FLAG (std::string, output_header_path, " " ,
4243 " Path at which to write the generated header." );
43- ABSL_FLAG (std::string, output_source_path, " " ,
44- " Path at which to write the generated source." );
44+ ABSL_FLAG (std::string, output_source_path_prefix, " " ,
45+ " Path at which to write the generated sources (suffix of .<index>.cc "
46+ " will be added)." );
4547ABSL_FLAG (std::string, namespaces, " " ,
4648 " Double-colon-delimited namespaces with which to wrap the "
4749 " generated code, e.g., \" my::namespace\" (note: no leading `::`)." );
@@ -69,7 +71,7 @@ absl::Status RealMain(const std::filesystem::path& module_path,
6971 absl::Span<const std::filesystem::path> dslx_paths,
7072 absl::Span<const std::string> include_headers,
7173 std::string_view output_header_path,
72- std::string_view output_source_path ,
74+ std::string_view output_source_path_prefix ,
7375 std::string_view namespaces) {
7476 XLS_ASSIGN_OR_RETURN (std::string module_text, GetFileContents (module_path));
7577
@@ -81,12 +83,16 @@ absl::Status RealMain(const std::filesystem::path& module_path,
8183 ParseAndTypecheck (module_text, std::string (module_path),
8284 module_path.stem ().string (), &import_data));
8385 XLS_ASSIGN_OR_RETURN (
84- CppSource sources,
86+ CppSourceGroup sources,
8587 TranspileToCpp (module .module , &import_data, include_headers,
8688 output_header_path, std::string (namespaces)));
89+ XLS_RET_CHECK_GT (sources.source .size (), 0 );
8790
8891 XLS_RETURN_IF_ERROR (SetFileContents (output_header_path, sources.header ));
89- XLS_RETURN_IF_ERROR (SetFileContents (output_source_path, sources.source ));
92+ for (int i = 0 ; i < sources.source .size (); ++i) {
93+ XLS_RETURN_IF_ERROR (SetFileContents (
94+ absl::StrCat (output_source_path_prefix, i, " .cc" ), sources.source [i]));
95+ }
9096 return absl::OkStatus ();
9197}
9298
@@ -104,9 +110,10 @@ int main(int argc, char* argv[]) {
104110 std::string output_header_path = absl::GetFlag (FLAGS_output_header_path);
105111 QCHECK (!output_header_path.empty ())
106112 << " --output_header_path must be specified." ;
107- std::string output_source_path = absl::GetFlag (FLAGS_output_source_path);
108- QCHECK (!output_source_path.empty ())
109- << " --output_source_path must be specified." ;
113+ std::string output_source_path_prefix =
114+ absl::GetFlag (FLAGS_output_source_path_prefix);
115+ QCHECK (!output_source_path_prefix.empty ())
116+ << " --output_source_path_prefix must be specified." ;
110117
111118 std::string dslx_path = absl::GetFlag (FLAGS_dslx_path);
112119 std::vector<std::string> dslx_path_strs = absl::StrSplit (dslx_path, ' :' );
@@ -120,7 +127,7 @@ int main(int argc, char* argv[]) {
120127 return xls::ExitStatus (xls::dslx::RealMain (
121128 args[0 ], absl::GetFlag (FLAGS_dslx_stdlib_path), dslx_paths,
122129 absl::GetFlag (FLAGS_include_headers), output_header_path,
123- output_source_path , absl::GetFlag (FLAGS_namespaces)));
130+ output_source_path_prefix , absl::GetFlag (FLAGS_namespaces)));
124131
125132 return 0 ;
126133}
0 commit comments