diff --git a/tensorflow/compiler/mlir/lite/BUILD b/tensorflow/compiler/mlir/lite/BUILD index a9000158629..699ba21a334 100644 --- a/tensorflow/compiler/mlir/lite/BUILD +++ b/tensorflow/compiler/mlir/lite/BUILD @@ -364,7 +364,7 @@ cc_library( "flatbuffer_operator.h", ], deps = [ - "//tensorflow/compiler/mlir/lite:tensorflow_lite", + ":tensorflow_lite", "//tensorflow/compiler/mlir/tensorflow", "//tensorflow/lite/schema:schema_fbs", "@com_google_absl//absl/container:flat_hash_map", @@ -384,6 +384,20 @@ tf_native_cc_binary( ], ) +cc_library( + name = "emit_error_reporter", + srcs = [ + "emit_error_reporter.cc", + ], + hdrs = [ + "emit_error_reporter.h", + ], + deps = [ + "//tensorflow/lite/core/api", + "@local_config_mlir//:IR", + ], +) + cc_library( name = "flatbuffer_translate_lib", srcs = [ @@ -394,8 +408,8 @@ cc_library( ], deps = [ ":flatbuffer_tflite_operator_lib", - "//tensorflow/compiler/mlir/lite:tensorflow_lite", - "//tensorflow/compiler/mlir/lite:tensorflow_lite_dialect_registration", + ":tensorflow_lite", + ":tensorflow_lite_dialect_registration", "//tensorflow/compiler/mlir/tensorflow", "//tensorflow/compiler/mlir/tensorflow:convert_tensor", "//tensorflow/compiler/mlir/tensorflow:export_tf_dialect_op", diff --git a/tensorflow/compiler/mlir/lite/emit_error_reporter.cc b/tensorflow/compiler/mlir/lite/emit_error_reporter.cc new file mode 100644 index 00000000000..d280bec85f5 --- /dev/null +++ b/tensorflow/compiler/mlir/lite/emit_error_reporter.cc @@ -0,0 +1,27 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/compiler/mlir/lite/emit_error_reporter.h" + +namespace tflite { + +int EmitErrorReporter::Report(const char* format, va_list args) { + std::vector buf(1 + snprintf(nullptr, 0, format, args)); + std::vsnprintf(buf.data(), buf.size(), format, args); + module_.emitError() << std::string(buf.begin(), buf.end()); + return 0; +} + +} // namespace tflite diff --git a/tensorflow/compiler/mlir/lite/emit_error_reporter.h b/tensorflow/compiler/mlir/lite/emit_error_reporter.h new file mode 100644 index 00000000000..e32fa8d1b4e --- /dev/null +++ b/tensorflow/compiler/mlir/lite/emit_error_reporter.h @@ -0,0 +1,38 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_COMPILER_MLIR_LITE_EMIT_ERROR_REPORTER_H_ +#define TENSORFLOW_COMPILER_MLIR_LITE_EMIT_ERROR_REPORTER_H_ + +#include + +#include "mlir/IR/Module.h" // TF:local_config_mlir +#include "tensorflow/lite/core/api/error_reporter.h" + +namespace tflite { + +// Error reporter that reports errors via the module's emitError. +class EmitErrorReporter : public ErrorReporter { + public: + explicit EmitErrorReporter(mlir::Module module) : module_(module) {} + int Report(const char* format, va_list args) override; + + private: + mlir::Module module_; +}; + +} // namespace tflite + +#endif // TENSORFLOW_COMPILER_MLIR_LITE_EMIT_ERROR_REPORTER_H_