From 2d53219434762b267d8b7b50235aa8efc16e0c88 Mon Sep 17 00:00:00 2001 From: windclarion Date: Sun, 9 Aug 2020 22:00:53 +0800 Subject: [PATCH] [uTVM] fix crt building and running error (#6231) Signed-off-by: windclarion --- include/tvm/runtime/crt/module.h | 7 +++++++ src/support/str_escape.h | 4 +++- src/target/source/codegen_c_host.cc | 7 ++++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/include/tvm/runtime/crt/module.h b/include/tvm/runtime/crt/module.h index b825f6d55ed8b..2359025f6fe14 100644 --- a/include/tvm/runtime/crt/module.h +++ b/include/tvm/runtime/crt/module.h @@ -27,6 +27,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + /*! * \brief Module container of TVM. */ @@ -38,4 +42,7 @@ typedef struct TVMModule { /*! \brief Entry point for the system lib module. */ const TVMModule* TVMSystemLibEntryPoint(void); +#ifdef __cplusplus +} +#endif #endif // TVM_RUNTIME_CRT_MODULE_H_ diff --git a/src/support/str_escape.h b/src/support/str_escape.h index 4a927340467b5..a0558268dbfbf 100644 --- a/src/support/str_escape.h +++ b/src/support/str_escape.h @@ -65,7 +65,9 @@ inline std::string StrEscape(const char* data, size_t size, bool use_octal_escap break; default: if (use_octal_escape) { - stream << '0' + ((c >> 6) & 0x03) << '0' + ((c >> 3) & 0x07) << '0' + (c & 0x03); + stream << static_cast('0' + ((c >> 6) & 0x03)) + << static_cast('0' + ((c >> 3) & 0x07)) + << static_cast('0' + (c & 0x07)); } else { const char* hex_digits = "0123456789ABCDEF"; stream << 'x' << hex_digits[c >> 4] << hex_digits[c & 0xf]; diff --git a/src/target/source/codegen_c_host.cc b/src/target/source/codegen_c_host.cc index 3f1e3aaef933a..f4aa7281f1f9c 100644 --- a/src/target/source/codegen_c_host.cc +++ b/src/target/source/codegen_c_host.cc @@ -279,8 +279,9 @@ void CodeGenCHost::GenerateFuncRegistry() { decl_stream << "#include \n"; stream << "static TVMBackendPackedCFunc _tvm_func_array[] = {\n"; for (auto f : function_names_) { - stream << " " << f << ",\n"; + stream << " (TVMBackendPackedCFunc)" << f << ",\n"; } + stream << "};\n"; auto registry = target::GenerateFuncRegistryNames(function_names_); stream << "static const TVMFuncRegistry _tvm_func_registry = {\n" << " \"" << ::tvm::support::StrEscape(registry.data(), registry.size(), true) << "\"," @@ -290,10 +291,10 @@ void CodeGenCHost::GenerateFuncRegistry() { void CodeGenCHost::GenerateCrtSystemLib() { stream << "static const TVMModule _tvm_system_lib = {\n" - << " &system_lib_registry,\n" + << " &_tvm_func_registry,\n" << "};\n" << "const TVMModule* TVMSystemLibEntryPoint(void) {\n" - << " return &system_lib;\n" + << " return &_tvm_system_lib;\n" << "}\n"; }