Skip to content

Commit

Permalink
Use SetTextProtoFile() for {Codegen,SchedulingOptions}FlagsProto
Browse files Browse the repository at this point in the history
This not only encapsulates writing the textproto into one function
call, but the implementation also adds the type information into
the textproto, making it simple to process with tools that don't
know the type beforehand.

PiperOrigin-RevId: 634064097
  • Loading branch information
hzeller authored and copybara-github committed May 15, 2024
1 parent 7997bef commit 5cf4feb
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 16 deletions.
4 changes: 0 additions & 4 deletions xls/tools/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,6 @@ cc_library(
deps = [
":scheduling_options_flags_cc_proto",
"//xls/common/file:filesystem",
"//xls/common/status:ret_check",
"//xls/common/status:status_macros",
"//xls/delay_model:delay_estimator",
"//xls/delay_model:delay_estimators",
Expand All @@ -996,7 +995,6 @@ cc_library(
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
"@com_google_protobuf//:protobuf",
],
)

Expand Down Expand Up @@ -1025,13 +1023,11 @@ cc_library(
deps = [
":codegen_flags_cc_proto",
"//xls/common/file:filesystem",
"//xls/common/status:ret_check",
"//xls/common/status:status_macros",
"@com_google_absl//absl/flags:flag",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings:str_format",
"@com_google_protobuf//:protobuf",
],
)

Expand Down
8 changes: 2 additions & 6 deletions xls/tools/codegen_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_format.h"
#include "google/protobuf/text_format.h"
#include "xls/common/file/filesystem.h"
#include "xls/common/status/ret_check.h"
#include "xls/common/status/status_macros.h"
#include "xls/tools/codegen_flags.pb.h"

Expand Down Expand Up @@ -276,10 +274,8 @@ absl::StatusOr<CodegenFlagsProto> GetCodegenFlags() {
absl::GetFlag(FLAGS_codegen_options_proto), &proto));
}
if (absl::GetFlag(FLAGS_codegen_options_used_textproto_file)) {
std::string out;
XLS_RET_CHECK(google::protobuf::TextFormat::PrintToString(proto, &out));
XLS_RETURN_IF_ERROR(SetFileContents(
*absl::GetFlag(FLAGS_codegen_options_used_textproto_file), out));
XLS_RETURN_IF_ERROR(SetTextProtoFile(
*absl::GetFlag(FLAGS_codegen_options_used_textproto_file), proto));
}
return proto;
}
Expand Down
8 changes: 2 additions & 6 deletions xls/tools/scheduling_options_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
#include "absl/strings/numbers.h"
#include "absl/strings/str_format.h"
#include "absl/strings/str_split.h"
#include "google/protobuf/text_format.h"
#include "xls/common/file/filesystem.h"
#include "xls/common/status/ret_check.h"
#include "xls/common/status/status_macros.h"
#include "xls/delay_model/delay_estimator.h"
#include "xls/delay_model/delay_estimators.h"
Expand Down Expand Up @@ -257,10 +255,8 @@ absl::StatusOr<SchedulingOptionsFlagsProto> GetSchedulingOptionsFlagsProto() {
absl::GetFlag(FLAGS_scheduling_options_proto), &proto));
}
if (absl::GetFlag(FLAGS_scheduling_options_used_textproto_file)) {
std::string out;
XLS_RET_CHECK(google::protobuf::TextFormat::PrintToString(proto, &out));
XLS_RETURN_IF_ERROR(SetFileContents(
*absl::GetFlag(FLAGS_scheduling_options_used_textproto_file), out));
XLS_RETURN_IF_ERROR(SetTextProtoFile(
*absl::GetFlag(FLAGS_scheduling_options_used_textproto_file), proto));
}
return proto;
}
Expand Down

0 comments on commit 5cf4feb

Please sign in to comment.