tqchen commented on a change in pull request #4657: [CodeGen] Generate blob use LLVM directly URL: https://github.com/apache/incubator-tvm/pull/4657#discussion_r364577848
########## File path: src/codegen/codegen.cc ########## @@ -211,5 +220,30 @@ std::string PackImportsToC(const runtime::Module& mod, bool system_lib) { << "#endif\n"; return os.str(); } + +runtime::Module PackImportsToLLVM(const runtime::Module& mod, + bool system_lib, + const std::string& target) { + std::string bin = SerializeModule(mod); + + std::ostringstream os; + uint64_t nbytes = bin.length(); + os << std::hex; + for (size_t i = 0; i < sizeof(nbytes); ++i) { + os << std::setfill('0') << std::setw(2) << ((nbytes >> (i * 8)) & 0xffUL); + } + for (size_t i = 0; i < bin.length(); ++i) { + int c = bin[i]; + os << std::setfill('0') << std::setw(2) << (c & 0xff); + } + + // Call codegen_blob to generate LLVM module + std::string codegen_f_name = "codegen.codegen_blob"; + // the codegen function. + const PackedFunc* codegen_f = runtime::Registry::Get(codegen_f_name); + CHECK(codegen_f != nullptr) << "codegen.codegen_blob is not presented."; + return (*codegen_f)(os.str(), system_lib, target); Review comment: Sorry I forget to mention you cannot pass std string because that will be treated as null terminate c str. Pass a ByteArray instead ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services