1 // ATTENTION: The code in this file is highly EXPERIMENTAL.
2 // Adventurous users should note that the APIs will probably change.
3 
4 #pragma once
5 
6 #include "onnx/common/ir.h"
7 #include "onnx/onnx_pb.h"
8 
9 namespace ONNX_NAMESPACE {
10 
11 class ConvertError final : public std::runtime_error {
12  public:
13   using std::runtime_error::runtime_error;
14 
ConvertError(const std::string & message)15   ConvertError(const std::string& message) : std::runtime_error(message) {}
16 
what()17   const char* what() const noexcept override {
18     if (!expanded_message_.empty()) {
19       return expanded_message_.c_str();
20     }
21     return std::runtime_error::what();
22   }
23 
AppendContext(const std::string & context)24   void AppendContext(const std::string& context) {
25     expanded_message_ = MakeString(
26         std::runtime_error::what(), "\n\n==> Context: ", context);
27   }
28 
29  private:
30   std::string expanded_message_;
31 };
32 
33 #define fail_convert(...) \
34   throw ConvertError(MakeString(__VA_ARGS__));
35 
36 void ExportModelProto(ModelProto* p_m, const std::shared_ptr<Graph>& g);
37 
38 std::unique_ptr<Graph> ImportModelProto(const ModelProto& mp);
39 
40 ModelProto PrepareOutput(const ModelProto& mp_in);
41 
42 void assertNonNull(std::shared_ptr<Graph> g);
43 } // namespace ONNX_NAMESPACE
44