Skip to content

Commit

Permalink
Fixes for static library EmitC sample. (iree-org#7738)
Browse files Browse the repository at this point in the history

Co-authored-by: Ben Vanik <[email protected]>
  • Loading branch information
ScottTodd and benvanik authored Nov 24, 2021
1 parent 9928f89 commit 53d5090
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
3 changes: 3 additions & 0 deletions build_tools/cmake/iree_copts.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ iree_select_compiler_opts(IREE_DEFAULT_COPTS
# but it's better to not get spurious failures during LTCG.
# https://docs.microsoft.com/en-us/cpp/build/reference/bigobj-increase-number-of-sections-in-dot-obj-file
"/bigobj"

# Use the modern C preprocessor to more closely match standards/clang/gcc behavior.
"/Zc:preprocessor"
)

# Compiler diagnostics.
Expand Down
14 changes: 5 additions & 9 deletions iree/compiler/Dialect/VM/Target/C/CModuleTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ static LogicalResult buildModuleDescriptors(IREE::VM::ModuleOp &moduleOp,
auto printStringView = [](StringRef s) -> std::string {
// We can't use iree_make_string_view because function calls are not allowed
// for constant expressions in C.
// TODO(#7605): Switch to IREE_SVL. We can't use IREE_SVL today because it
// uses designated initializers, which cause issues when compiled as C++.
return ("{\"" + s + "\", " + std::to_string(s.size()) + "}").str();
};

// exports
SmallVector<IREE::VM::ExportOp, 4> exportOps(
moduleOp.getOps<IREE::VM::ExportOp>());
std::string exportName = moduleName + "_exports_";
output << "static const size_t " << exportName
<< "count_ = " << exportOps.size() << ";\n";
output << "static const iree_vm_native_export_descriptor_t " << exportName
<< "[] = {\n";
if (exportOps.empty()) {
Expand Down Expand Up @@ -183,8 +183,6 @@ static LogicalResult buildModuleDescriptors(IREE::VM::ModuleOp &moduleOp,
SmallVector<IREE::VM::ImportOp, 4> importOps(
moduleOp.getOps<IREE::VM::ImportOp>());
std::string importName = moduleName + "_imports_";
output << "static const size_t " << importName
<< "count_ = " << importOps.size() << ";\n";
output << "static const iree_vm_native_import_descriptor_t " << importName
<< "[] = {\n";
if (importOps.empty()) {
Expand All @@ -205,8 +203,6 @@ static LogicalResult buildModuleDescriptors(IREE::VM::ModuleOp &moduleOp,

// functions
std::string functionName = moduleName + "_funcs_";
output << "static const size_t " << functionName
<< "count_ = " << exportOps.size() << ";\n";
output << "static const iree_vm_native_function_ptr_t " << functionName
<< "[] = {\n";
if (exportOps.empty()) {
Expand Down Expand Up @@ -241,11 +237,11 @@ static LogicalResult buildModuleDescriptors(IREE::VM::ModuleOp &moduleOp,
output << "static const iree_vm_native_module_descriptor_t " << descriptorName
<< " = {\n"
<< printStringView(moduleName) << ",\n"
<< importName << "count_,\n"
<< importOps.size() << ",\n"
<< importName << ",\n"
<< exportName << "count_,\n"
<< exportOps.size() << ",\n"
<< exportName << ",\n"
<< functionName << "count_,\n"
<< exportOps.size() << ",\n"
<< functionName << ",\n"
<< "0,\n"
<< "NULL,\n"
Expand Down
2 changes: 2 additions & 0 deletions iree/vm/shims_emitc.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ EMITC_DEFINE_SHIMS((r, i, i), (r))
EMITC_DEFINE_SHIMS((r, i, i, i), (r))
EMITC_DEFINE_SHIMS((r, i, i, i), (v))
EMITC_DEFINE_SHIMS((r, r, i, i, i, i), (v))
EMITC_DEFINE_SHIMS((r, r, r, i, i, i), (v))
EMITC_DEFINE_SHIMS((r, r), (r))
EMITC_DEFINE_SHIMS((r, r), (v))
EMITC_DEFINE_SHIMS((r, r, r), (i, i))
Expand All @@ -309,5 +310,6 @@ EMITC_VLA_IMPORT((r, i), (r), (r))
EMITC_VLA_IMPORT((r, i, i), (i), (r))
EMITC_VLA_IMPORT((r, r, i), (i, r, i, i), (v))
EMITC_VLA_IMPORT((r, r, r), (r), (r))
EMITC_VLA_IMPORT((r, r, i, i), (i), (v))

#endif // IREE_VM_SHIMS_EMITC_H_

0 comments on commit 53d5090

Please sign in to comment.