Skip to content

Commit

Permalink
Merge pull request #44373 from neikeq/3.2-mono-wasm-m2n-hook
Browse files Browse the repository at this point in the history
[3.2] Mono: Make Godot provide its own WASM m2n trampolines
  • Loading branch information
akien-mga authored Dec 17, 2020
2 parents 9710a38 + 1a5e985 commit 80c9f2d
Show file tree
Hide file tree
Showing 15 changed files with 559 additions and 260 deletions.
3 changes: 2 additions & 1 deletion modules/mono/build_scripts/mono_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ def configure(env, env_mono):
env_mono.Append(CPPDEFINES=["_REENTRANT"])

if mono_static:
env.Append(LINKFLAGS=["-rdynamic"])
if not is_javascript:
env.Append(LINKFLAGS=["-rdynamic"])

mono_lib_file = os.path.join(mono_lib_path, "lib" + mono_lib + ".a")

Expand Down
71 changes: 14 additions & 57 deletions modules/mono/editor/bindings_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
#define C_METHOD_MONOARRAY_TO(m_type) C_NS_MONOMARSHAL "::mono_array_to_" #m_type
#define C_METHOD_MONOARRAY_FROM(m_type) C_NS_MONOMARSHAL "::" #m_type "_to_mono_array"

#define BINDINGS_GENERATOR_VERSION UINT32_C(11)
#define BINDINGS_GENERATOR_VERSION UINT32_C(13)

const char *BindingsGenerator::TypeInterface::DEFAULT_VARARG_C_IN("\t%0 %1_in = %1;\n");

Expand Down Expand Up @@ -1819,12 +1819,12 @@ Error BindingsGenerator::generate_glue(const String &p_output_dir) {

#define ADD_INTERNAL_CALL_REGISTRATION(m_icall) \
{ \
output.append("\tmono_add_internal_call("); \
output.append("\tGDMonoUtils::add_internal_call("); \
output.append("\"" BINDINGS_NAMESPACE "."); \
output.append(m_icall.editor_only ? BINDINGS_CLASS_NATIVECALLS_EDITOR : BINDINGS_CLASS_NATIVECALLS); \
output.append("::"); \
output.append(m_icall.name); \
output.append("\", (void*)"); \
output.append("\", "); \
output.append(m_icall.name); \
output.append(");\n"); \
}
Expand Down Expand Up @@ -2728,44 +2728,11 @@ void BindingsGenerator::_populate_builtin_type_interfaces() {
INSERT_INT_TYPE("sbyte", int8_t, int64_t);
INSERT_INT_TYPE("short", int16_t, int64_t);
INSERT_INT_TYPE("int", int32_t, int64_t);
INSERT_INT_TYPE("long", int64_t, int64_t);
INSERT_INT_TYPE("byte", uint8_t, int64_t);
INSERT_INT_TYPE("ushort", uint16_t, int64_t);
INSERT_INT_TYPE("uint", uint32_t, int64_t);

itype = TypeInterface::create_value_type(String("long"));
{
itype.c_out = "\treturn (%0)%1;\n";
itype.c_in = "\t%0 %1_in = (%0)*%1;\n";
itype.c_out = "\t*%3 = (%0)%1;\n";
itype.c_type = "int64_t";
itype.c_arg_in = "&%s_in";
}
itype.c_type_in = "int64_t*";
itype.c_type_out = "int64_t";
itype.im_type_in = "ref " + itype.name;
itype.im_type_out = "out " + itype.name;
itype.cs_in = "ref %0";
/* in cs_out, im_type_out (%3) includes the 'out ' part */
itype.cs_out = "%0(%1, %3 argRet); return (%2)argRet;";
itype.ret_as_byref_arg = true;
builtin_types.insert(itype.cname, itype);

itype = TypeInterface::create_value_type(String("ulong"));
{
itype.c_in = "\t%0 %1_in = (%0)*%1;\n";
itype.c_out = "\t*%3 = (%0)%1;\n";
itype.c_type = "int64_t";
itype.c_arg_in = "&%s_in";
}
itype.c_type_in = "uint64_t*";
itype.c_type_out = "uint64_t";
itype.im_type_in = "ref " + itype.name;
itype.im_type_out = "out " + itype.name;
itype.cs_in = "ref %0";
/* in cs_out, im_type_out (%3) includes the 'out ' part */
itype.cs_out = "%0(%1, %3 argRet); return (%2)argRet;";
itype.ret_as_byref_arg = true;
builtin_types.insert(itype.cname, itype);
INSERT_INT_TYPE("ulong", uint64_t, int64_t);
}

// Floating point types
Expand All @@ -2777,20 +2744,16 @@ void BindingsGenerator::_populate_builtin_type_interfaces() {
itype.proxy_name = "float";
{
// The expected type for 'float' in ptrcall is 'double'
itype.c_in = "\t%0 %1_in = (%0)*%1;\n";
itype.c_out = "\t*%3 = (%0)%1;\n";
itype.c_in = "\t%0 %1_in = (%0)%1;\n";
itype.c_out = "\treturn (%0)%1;\n";
itype.c_type = "double";
itype.c_type_in = "float*";
itype.c_type_in = "float";
itype.c_type_out = "float";
itype.c_arg_in = "&%s_in";
}
itype.cs_type = itype.proxy_name;
itype.im_type_in = "ref " + itype.proxy_name;
itype.im_type_out = "out " + itype.proxy_name;
itype.cs_in = "ref %0";
/* in cs_out, im_type_out (%3) includes the 'out ' part */
itype.cs_out = "%0(%1, %3 argRet); return (%2)argRet;";
itype.ret_as_byref_arg = true;
itype.im_type_in = itype.proxy_name;
itype.im_type_out = itype.proxy_name;
builtin_types.insert(itype.cname, itype);

// double
Expand All @@ -2799,20 +2762,14 @@ void BindingsGenerator::_populate_builtin_type_interfaces() {
itype.cname = itype.name;
itype.proxy_name = "double";
{
itype.c_in = "\t%0 %1_in = (%0)*%1;\n";
itype.c_out = "\t*%3 = (%0)%1;\n";
itype.c_type = "double";
itype.c_type_in = "double*";
itype.c_type_in = "double";
itype.c_type_out = "double";
itype.c_arg_in = "&%s_in";
itype.c_arg_in = "&%s";
}
itype.cs_type = itype.proxy_name;
itype.im_type_in = "ref " + itype.proxy_name;
itype.im_type_out = "out " + itype.proxy_name;
itype.cs_in = "ref %0";
/* in cs_out, im_type_out (%3) includes the 'out ' part */
itype.cs_out = "%0(%1, %3 argRet); return (%2)argRet;";
itype.ret_as_byref_arg = true;
itype.im_type_in = itype.proxy_name;
itype.im_type_out = itype.proxy_name;
builtin_types.insert(itype.cname, itype);
}

Expand Down
Loading

0 comments on commit 80c9f2d

Please sign in to comment.