SwadicalRag / wasm2lua

wasm2lua: converting WASM into Lua
MIT License
194 stars 11 forks source link

Failing to convert seemingly simple C program #40

Open walksanatora opened 1 year ago

walksanatora commented 1 year ago

so I converted this TTS engine to WASM (so I could wask2kt to embed in minecraft) and wondered "I wonder. can I wasm2lua this to make it a lua program" but when I tried the wasm2lua transpiler crashed with

/usr/lib/node_modules/wasm2lua/resources/patches/decoder.js:651
        throw new _helperApiError.CompileError("Unexpected instruction: " + toHex(instructionByte));
        ^

CompileError: Unexpected instruction: 0xc0
    at parseInstructionBlock (/usr/lib/node_modules/wasm2lua/resources/patches/decoder.js:651:15)
    at parseInstructionBlock (/usr/lib/node_modules/wasm2lua/resources/patches/decoder.js:689:9)
    at parseInstructionBlock (/usr/lib/node_modules/wasm2lua/resources/patches/decoder.js:753:9)
    at parseInstructionBlock (/usr/lib/node_modules/wasm2lua/resources/patches/decoder.js:689:9)
    at parseInstructionBlock (/usr/lib/node_modules/wasm2lua/resources/patches/decoder.js:753:9)
    at parseInstructionBlock (/usr/lib/node_modules/wasm2lua/resources/patches/decoder.js:689:9)
    at parseInstructionBlock (/usr/lib/node_modules/wasm2lua/resources/patches/decoder.js:689:9)
    at parseInstructionBlock (/usr/lib/node_modules/wasm2lua/resources/patches/decoder.js:753:9)
    at parseCodeSection (/usr/lib/node_modules/wasm2lua/resources/patches/decoder.js:624:7)
    at parseSection (/usr/lib/node_modules/wasm2lua/resources/patches/decoder.js:1487:13)

Node.js v20.9.0

this appears to correlate to the i32.extend8_s opcode

ExeVirus commented 1 year ago

I'm trying to see if I can bring this codebase up to date, but the issue is most certainly that SwadicalRag monkey-patched pieces of wasm-parser. Looking at your error chain (as well as mine), notice the error results from patches/decoder.js. I'm also trying to use a CMake Build process for the tiny regex library using recent wasi-sdk on windows, so I'm on a whole different setup. At first I had issues with just building to wasm, but resolved those with conflicts with cmake versions, and some changes from size_t to unsigned long long in the bindings.cpp.

But, in spite of those changes, I'm still getting unknown opcode issues - so now i will be spinning up a Centos VM to see if I can get wasi-sdk to (1) build there and then (2) build a wasm-parsable .wasm module so wasm2lua can do it's thing. Will report back what I find....

walksanatora commented 1 year ago

In the meantime although not vanilla lua. If you want luajit/luau I use https://github.com/Rerumu/Wasynth And I have proposed then adding vanilla lua but they said that they are working on implementing proposals currently