提交 9006d76b 编写于 作者: M Megvii Engine Team 提交者: Xu Xinran

fix(serialization): do not gate enum entries by macro

GitOrigin-RevId: aa27ecbf21e3ba74ef64a9cd0d0c34f80a64918c
上级 ad4928c9
......@@ -48,6 +48,13 @@ namespace mgb {
//! warn if result of a function is not used
#define MGB_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
#if __cplusplus >= 201703L || __clang_major__ >= 4
#define MGB_FALLTHRU [[fallthrough]];
#elif __GNUC__ >= 7
#define MGB_FALLTHRU __attribute__((fallthrough));
#else
#define MGB_FALLTHRU
#endif
/* ================ exception and assertion ================ */
......
......@@ -53,10 +53,11 @@ bool GraphDumper::should_remove_in_dump(cg::OperatorNodeBase *opr) {
std::unique_ptr<GraphDumper> GraphDumper::make(std::unique_ptr<OutputFile> file,
GraphDumpFormat format) {
switch (format) {
#if MGB_ENABLE_FBS_SERIALIZATION
case GraphDumpFormat::FLATBUFFERS:
#if MGB_ENABLE_FBS_SERIALIZATION
return make_fbs_dumper(std::move(file));
#endif
MGB_FALLTHRU
default:
mgb_throw(SerializationError,
"unsupported serialization format requested");
......@@ -66,10 +67,11 @@ std::unique_ptr<GraphDumper> GraphDumper::make(std::unique_ptr<OutputFile> file,
std::unique_ptr<GraphLoader> GraphLoader::make(std::unique_ptr<InputFile> file, GraphDumpFormat format) {
switch (format) {
#if MGB_ENABLE_FBS_SERIALIZATION
case GraphDumpFormat::FLATBUFFERS:
#if MGB_ENABLE_FBS_SERIALIZATION
return make_fbs_loader(std::move(file));
#endif
MGB_FALLTHRU
default:
mgb_throw(SerializationError,
"unsupported serialization format requested");
......
......@@ -29,9 +29,7 @@ struct OperatorParamTraits;
enum class SerializationFormat {
RAW_POD,
#if MGB_ENABLE_FBS_SERIALIZATION
FLATBUFFERS,
#endif
};
//! context for serializing a single operator
......@@ -162,12 +160,12 @@ void OprDumpContext::write_param(const Param& p) {
case SerializationFormat::RAW_POD:
static_cast<OprDumpContextRawPOD*>(this)->write_param(p);
break;
#if MGB_ENABLE_FBS_SERIALIZATION
case SerializationFormat::FLATBUFFERS:
#if MGB_ENABLE_FBS_SERIALIZATION
static_cast<OprDumpContextFlatBuffers*>(this)->write_param(
p, fbs::SupportFlatBuffersSerialization<Param>{});
break;
#endif
break;
}
}
......@@ -322,11 +320,13 @@ Param OprLoadContext::read_param() {
case SerializationFormat::RAW_POD:
return static_cast<OprLoadContextRawPOD*>(this)
->read_param<Param>();
#if MGB_ENABLE_FBS_SERIALIZATION
case SerializationFormat::FLATBUFFERS:
#if MGB_ENABLE_FBS_SERIALIZATION
return static_cast<OprLoadContextFlatBuffers*>(this)
->read_param<Param>(
fbs::SupportFlatBuffersSerialization<Param>{});
#else
mgb_trap();
#endif
}
mgb_assert(0);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册