Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiling with a C++ compiler ? #61

Closed
sletz opened this issue Jan 19, 2020 · 8 comments
Closed

Compiling with a C++ compiler ? #61

sletz opened this issue Jan 19, 2020 · 8 comments

Comments

@sletz
Copy link

sletz commented Jan 19, 2020

I get errors when compiling the "source" folder with a C++ compiler, here on macOS 10.13. Any plan to allow that?

@vshymanskyy
Copy link
Member

Work has been done to allow compiling with C++, but this is not used for some time already.
It should be a matter of a few fixes, howewer we do not plan to officially support it.

BTW, why do you need that?

@sletz
Copy link
Author

sletz commented Jan 19, 2020

I can live without, but it always simplify the build process.

@vshymanskyy
Copy link
Member

vshymanskyy commented Jan 19, 2020 via email

@sletz
Copy link
Author

sletz commented Jan 19, 2020

c++ -Ofast -march=native ../source/*.c -Dd_m3LogOutput=0 -c 
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
../source/m3_bind.c:148:12: error: no matching function for call to
      'FindAndLinkFunction'
    return FindAndLinkFunction (io_module, i_moduleName, i_functionName...
           ^~~~~~~~~~~~~~~~~~~
../source/m3_bind.c:85:11: note: candidate function not viable: no known
      conversion from 'M3RawCall' (aka 'const void *(*)(M3Runtime *, unsigned
      long long *, void *)') to 'voidptr_t' (aka 'const void *') for 5th
      argument; take the address of the argument with &
M3Result  FindAndLinkFunction      (IM3Module       io_module,
          ^
1 error generated.
../source/m3_compile.c:868:1: error: cannot jump from this goto statement to its
      label
_   (ReadLEB_u32 (& localIndex, & o->wasm, o->wasmEnd));
^
../source/m3_exception.h:17:72: note: expanded from macro '_'
  ...{ result = TRY; if (result) { EXCEPTION_PRINT; goto _catch; } }
                                                    ^
../source/m3_compile.c:870:8: note: jump bypasses variable initialization
    u8 type = o->typeStack [localIndex];
       ^
../source/m3_compile.c:1049:1: error: cannot jump from this goto statement to
      its label
_      (MoveStackTopToRegister (o));
^
../source/m3_exception.h:17:72: note: expanded from macro '_'
  ...{ result = TRY; if (result) { EXCEPTION_PRINT; goto _catch; } }
                                                    ^
../source/m3_compile.c:1051:9: note: jump bypasses variable initialization
    u32 numCodeLines = targetCount + 4; // 3 => IM3Operation + slot + ta...
        ^
../source/m3_compile.c:1043:1: error: cannot jump from this goto statement to
      its label
_   (Pop (o));
^
../source/m3_exception.h:17:72: note: expanded from macro '_'
  ...{ result = TRY; if (result) { EXCEPTION_PRINT; goto _catch; } }
                                                    ^
../source/m3_compile.c:1051:9: note: jump bypasses variable initialization
    u32 numCodeLines = targetCount + 4; // 3 => IM3Operation + slot + ta...
        ^
../source/m3_compile.c:1041:1: error: cannot jump from this goto statement to
      its label
_   (PreserveRegisterIfOccupied (o, c_m3Type_i64));         // move bran...
^
../source/m3_exception.h:17:72: note: expanded from macro '_'
  ...{ result = TRY; if (result) { EXCEPTION_PRINT; goto _catch; } }
                                                    ^
../source/m3_compile.c:1051:9: note: jump bypasses variable initialization
    u32 numCodeLines = targetCount + 4; // 3 => IM3Operation + slot + ta...
        ^
../source/m3_compile.c:1042:9: note: jump bypasses variable initialization
    u16 slot = GetStackTopSlotIndex (o);
        ^
../source/m3_compile.c:1039:1: error: cannot jump from this goto statement to
      its label
_   (ReadLEB_u32 (& targetCount, & o->wasm, o->wasmEnd));
^
../source/m3_exception.h:17:72: note: expanded from macro '_'
  ...{ result = TRY; if (result) { EXCEPTION_PRINT; goto _catch; } }
                                                    ^
../source/m3_compile.c:1051:9: note: jump bypasses variable initialization
    u32 numCodeLines = targetCount + 4; // 3 => IM3Operation + slot + ta...
        ^
../source/m3_compile.c:1042:9: note: jump bypasses variable initialization
    u16 slot = GetStackTopSlotIndex (o);
        ^
../source/m3_compile.c:1126:1: error: cannot jump from this goto statement to
      its label
_       (Pop (o));
^
../source/m3_exception.h:17:72: note: expanded from macro '_'
  ...{ result = TRY; if (result) { EXCEPTION_PRINT; goto _catch; } }
                                                    ^
../source/m3_compile.c:1129:9: note: jump bypasses variable initialization
    i32 numReturns = i_type->returnType ? 1 : 0;
        ^
../source/m3_compile.c:1125:1: error: cannot jump from this goto statement to
      its label
_       (CopyTopSlot (o, --argTop));
^
../source/m3_exception.h:17:72: note: expanded from macro '_'
  ...{ result = TRY; if (result) { EXCEPTION_PRINT; goto _catch; } }
                                                    ^
../source/m3_compile.c:1129:9: note: jump bypasses variable initialization
    i32 numReturns = i_type->returnType ? 1 : 0;
        ^
../source/m3_compile.c:1358:1: error: cannot jump from this goto statement to
      its label
_   (EmitTopSlotAndPop (o));
^
../source/m3_exception.h:17:72: note: expanded from macro '_'
  ...{ result = TRY; if (result) { EXCEPTION_PRINT; goto _catch; } }
                                                    ^
../source/m3_compile.c:1362:12: note: jump bypasses variable initialization
    pc_t * pc = (pc_t *) ReservePointer (o);
           ^
../source/m3_compile.c:1360:9: note: jump bypasses variable initialization
    i32 stackIndex = o->stackIndex;
        ^
../source/m3_compile.c:1357:1: error: cannot jump from this goto statement to
      its label
_   (EmitOp (o, op));
^
../source/m3_exception.h:17:72: note: expanded from macro '_'
  ...{ result = TRY; if (result) { EXCEPTION_PRINT; goto _catch; } }
                                                    ^
../source/m3_compile.c:1362:12: note: jump bypasses variable initialization
    pc_t * pc = (pc_t *) ReservePointer (o);
           ^
../source/m3_compile.c:1360:9: note: jump bypasses variable initialization
    i32 stackIndex = o->stackIndex;
        ^
../source/m3_compile.c:1353:1: error: cannot jump from this goto statement to
      its label
_   (PreserveArgsAndLocals (o));
^
../source/m3_exception.h:17:72: note: expanded from macro '_'
  ...{ result = TRY; if (result) { EXCEPTION_PRINT; goto _catch; } }
                                                    ^
../source/m3_compile.c:1362:12: note: jump bypasses variable initialization
    pc_t * pc = (pc_t *) ReservePointer (o);
           ^
../source/m3_compile.c:1360:9: note: jump bypasses variable initialization
    i32 stackIndex = o->stackIndex;
        ^
../source/m3_compile.c:1355:18: note: jump bypasses variable initialization
    IM3Operation op = IsStackTopInRegister (o) ? op_If_r : op_If_s;
                 ^
../source/m3_compile.c:1352:1: error: cannot jump from this goto statement to
      its label
_   (PreserveNonTopRegisters (o));
^
../source/m3_exception.h:17:72: note: expanded from macro '_'
  ...{ result = TRY; if (result) { EXCEPTION_PRINT; goto _catch; } }
                                                    ^
../source/m3_compile.c:1362:12: note: jump bypasses variable initialization
    pc_t * pc = (pc_t *) ReservePointer (o);
           ^
../source/m3_compile.c:1360:9: note: jump bypasses variable initialization
    i32 stackIndex = o->stackIndex;
        ^
../source/m3_compile.c:1355:18: note: jump bypasses variable initialization
    IM3Operation op = IsStackTopInRegister (o) ? op_If_r : op_If_s;
                 ^
../source/m3_compile.c:1602:1: error: cannot jump from this goto statement to
      its label
_   (ReadLEB_u32 (& memoryOffset, & o->wasm, o->wasmEnd));
^
../source/m3_exception.h:17:72: note: expanded from macro '_'
  ...{ result = TRY; if (result) { EXCEPTION_PRINT; goto _catch; } }
                                                    ^
../source/m3_compile.c:1604:22: note: jump bypasses variable initialization
    const M3OpInfo * op = & c_operations [i_opcode];
                     ^
../source/m3_compile.c:1601:1: error: cannot jump from this goto statement to
      its label
_   (ReadLEB_u32 (& alignHint, & o->wasm, o->wasmEnd));
^
../source/m3_exception.h:17:72: note: expanded from macro '_'
  ...{ result = TRY; if (result) { EXCEPTION_PRINT; goto _catch; } }
                                                    ^
../source/m3_compile.c:1604:22: note: jump bypasses variable initialization
    const M3OpInfo * op = & c_operations [i_opcode];
                     ^
13 errors generated.
../source/m3_emit.c:90:9: warning: cast to 'void *' from smaller integer type
      'i32' (aka 'int') [-Wint-to-void-pointer-cast]
        EmitWord (o->page, i_offset);
        ^
../source/m3_code.h:40:49: note: expanded from macro 'EmitWord'
#define EmitWord(page, val) EmitWord_impl(page, (void*)(val))
                                                ^

@vshymanskyy
Copy link
Member

Several comments here.

  1. Compiling with -Ofast will make the engine even faster, however can break floating point calculations. Use with great care.

  2. When compiling with C++, you can run into linking issues (due to different name mangling).

@sletz
Copy link
Author

sletz commented Jan 19, 2020

Yes, thanks, I know both of the issues.

I 'm trying wasm3 with Faust generated wasm code, see https://github.com/sletz/wasm3/tree/master/faust. It already works (slowly of course....), still working on adding math functions.

@vshymanskyy
Copy link
Member

You should be able to build as C++ now

@sletz
Copy link
Author

sletz commented Jan 19, 2020

Working, thanks.

BTW to implement the following function that links a given math function in the WASM module when it is actually used, I wrote:

void wasm3_dsp_factory::addFunction(const char* name, const char* type, ModuleFun fun)
{
    if (v_FindFunction(fModule, name)) {
        M3Result result = m3_LinkRawFunction(fModule, "env", name, type, fun);
        if (result) FATAL("addFunction: %s", result);
    }
}

So I needed to define (to be officially added in m3.h header ?) :

typedef const void* (ModuleFun) (IM3Runtime runtime, uint64_t* _sp, void* _mem);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants