Skip to content

Commit

Permalink
Export symbol from DLL in test_jit (#2861)
Browse files Browse the repository at this point in the history
  • Loading branch information
apwojcik authored and causten committed Jun 26, 2024
1 parent 7e510bc commit 52a5c09
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions test/jit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

// NOLINTNEXTLINE
const std::string_view add_42_src = R"migraphx(
extern "C" int add(int x)
EXPORT extern "C" int add(int x)
{
return x+42;
}
Expand All @@ -43,28 +43,31 @@ const std::string_view preamble = R"migraphx(
)migraphx";

template <class F>
std::function<F> compile_function(std::string_view src, std::string_view symbol_name)
std::function<F> compile_function(std::string_view src, const std::string& symbol_name)
{
migraphx::src_compiler compiler;
compiler.flags.emplace_back("-std=c++14");
#ifndef _WIN32
compiler.flags.emplace_back("-fPIC");
compiler.flags.emplace_back("-DEXPORT=\"\"");
#else
compiler.flags.emplace_back("-DEXPORT=__declspec(dllexport)");
#endif
compiler.flags.emplace_back("-shared");
compiler.output = migraphx::make_shared_object_filename("simple");
migraphx::src_file f{"main.cpp", src};
auto image = compiler.compile({f});
return migraphx::dynamic_loader{image}.get_function<F>(std::string{symbol_name});
return migraphx::dynamic_loader{image}.get_function<F>(symbol_name);
}

template <class F>
std::function<F> compile_module(const migraphx::module& m)
{
migraphx::cpp_generator g;
g.fmap([](auto&& name) { return "std::" + name; });
g.create_function(g.generate_module(m).set_attributes({"extern \"C\""}));
g.create_function(g.generate_module(m).set_attributes({"EXPORT extern \"C\""}));

return compile_function<F>(preamble.data() + g.str(), m.name());
return compile_function<F>(g.str().insert(0, preamble), m.name());
}

TEST_CASE(simple_run)
Expand Down

0 comments on commit 52a5c09

Please sign in to comment.