WebAssembly / binaryen

Optimizer and compiler/toolchain library for WebAssembly
Apache License 2.0
7.52k stars 745 forks source link

asm2wasm crah #60

Closed sletz closed 8 years ago

sletz commented 8 years ago

Crash with the following command :

bin/asm2wasm noise.js

for:

(i0 = 0; (((i0 | 0) < 2) | 0); i0 = (((i0 | 0) + 1) | 0)) { HEAP32[dsp + 0 + ((i0 | 0) << 2) >> 2] = 0;

Abort trap: 6

Noise.js file content is :

/* ------------------------------------------------------------ author: "Grame" copyright: "(c)GRAME 2009" license: "BSD" name: "Noise" version: "1.1" Code generated with Faust 2.0.a41 (http://faust.grame.fr) ------------------------------------------------------------ */

function mydspModule(global, foreign, buffer) {

'use asm';

var HEAP32 = new global.Int32Array(buffer);
var HEAPF32 = new global.Float32Array(buffer);

var imul = global.Math.imul;
var log = global.Math.log;

function fmodf(x, y) { x = +x; y = +y; return +(x % y); }
function log10f(a) { a = +a; return +(+log(a) / +log(10.)); }

function getNumInputs(dsp) {
    dsp = dsp | 0;
    return 0;
}

function getNumOutputs(dsp) {
    dsp = dsp | 0;
    return 1;
}

function classInit(dsp, samplingFreq) {
    dsp = dsp | 0;
    samplingFreq = samplingFreq | 0;

}

function instanceInit(dsp, samplingFreq) {
    dsp = dsp | 0;
    samplingFreq = samplingFreq | 0;
    var i0 = 0;
    HEAP32[dsp + 12 >> 2] = (samplingFreq | 0);
    HEAPF32[dsp + 8 >> 2] = +(0.);
    for (i0 = 0; (((i0 | 0) < 2) | 0); i0 = (((i0 | 0) + 1) | 0)) {
        HEAP32[dsp + 0 + ((i0 | 0) << 2) >> 2] = 0;

    }

}

function init(dsp, samplingFreq) {
    dsp = dsp | 0;
    samplingFreq = samplingFreq | 0;
    classInit(dsp, samplingFreq);
    instanceInit(dsp, samplingFreq);
}

function setValue(dsp, offset, value) {
    dsp = dsp | 0;
    offset = offset | 0;
    value = +value;
    HEAPF32[dsp + offset >> 2] = value;
}

function getValue(dsp, offset) {
    dsp = dsp | 0;
    offset = offset | 0;
    return +HEAPF32[dsp + offset >> 2];
}

function compute(dsp, count, inputs, outputs) {
    dsp = dsp | 0;
    count = count | 0;
    inputs = inputs | 0;
    outputs = outputs | 0;
    var output0 = 0;
    var fSlow0 = 0.;
    var i = 0;
    output0 = (HEAP32[outputs + (0 << 2) >> 2] | 0);
    fSlow0 = +(4.65661e-10 * +(+(HEAPF32[dsp + 8 >> 2])));
    for (i = 0; (((i | 0) < (count | 0)) | 0); i = (((i | 0) + 1) | 0)) {
        HEAP32[dsp + 0 + (0 << 2) >> 2] = ((12345 + (imul(1103515245, (HEAP32[dsp + 0 + (1 << 2) >> 2] | 0)) | 0)) | 0);
        HEAPF32[output0 + ((i | 0) << 2) >> 2] = +(+(+(fSlow0) * +((HEAP32[dsp + 0 + (0 << 2) >> 2] | 0))));
        HEAP32[dsp + 0 + (1 << 2) >> 2] = (HEAP32[dsp + 0 + (0 << 2) >> 2] | 0);

    }

}

return { getNumInputs : getNumInputs, getNumOutputs : getNumOutputs, classInit : classInit, instanceInit : instanceInit, init : init, setValue : setValue, getValue : getValue, compute : compute };

}

function getSizemydsp() { return 16; }

function getPathTablemydsp() {

var pathTable = [];
pathTable["/0x00/Volume"] = 8;
return pathTable;

}

function getJSONmydsp() { return "{ \"name\": \"Noise\", \"outputs\": \"1\", \"meta\": [ { \"author\": \"Grame\" }, { \"copyright\": \"(c)GRAME 2009\" }, { \"license\": \"BSD\" }, { \"name\": \"Noise\" }, { \"version\": \"1.1\" } ], \"ui\": [ { \"type\": \"vgroup\", \"label\": \"0x00\", \"items\": [ { \"type\": \"vslider\", \"label\": \"Volume\", \"address\": \"/0x00/Volume\", \"meta\": [ { \"style\": \"knob\" } ], \"init\": \"0\", \"min\": \"0\", \"max\": \"1\", \"step\": \"0.1\" } ] } ] } "; }

function metadatamydsp(m) { m.declare("author", "Grame"); m.declare("copyright", "(c)GRAME 2009"); m.declare("license", "BSD"); m.declare("name", "Noise"); m.declare("version", "1.1"); }

Crash log is :

bt

kripken commented 8 years ago

Perhaps try to escape your code with 4-backticks (`) before and after?

sletz commented 8 years ago

It seems that the "for loop" syntax is not handled in "parseAfterKeyword" (in parse.h file)

for (i0 = 0; (((i0 | 0) < 2) | 0); i0 = (((i0 | 0) + 1) | 0)) { HEAP32[dsp + 0 + ((i0 | 0) << 2) >> 2] = 0; }

kripken commented 8 years ago

Ok, that makes sense. We have support for parsing emscripten asm.js output, which is a subset of asm.js - it never uses for loops, for example. It should be easy to add this support though, if it would be useful.

sletz commented 8 years ago

Well, our code backend currently generates "for loop" yes.

kripken commented 8 years ago

Ah, out of curiosity, what code backend is this?

sletz commented 8 years ago

FAUST (Functional Audio Stream) functional programming language specifically designed for real-time audio signal processing and synthesis (see http://faust.grame.fr)

kripken commented 8 years ago

Interesting, thanks for the info.

Ok, I just added for-loop support. I didn't test it beyond a simple testcase (see the commit), so let me know if you hit any issues

sletz commented 8 years ago

Working now, thanks!

kripken commented 8 years ago

Great, thanks for confirming.

sletz commented 8 years ago

Well I found later on that the following generated JS code is not parsed correctly. Any chance it could also be fixed?

function getJSONmydsp() { return "{ \"name\": \"Noise\", \"outputs\": \"1\", \"meta\": [ { \"author\": \"Grame\" }, { \"copyright\": \"(c)GRAME 2009\" }, { \"license\": \"BSD\" }, { \"name\": \"Noise\" }, { \"version\": \"1.1\" } ], \"ui\": [ { \"type\": \"vgroup\", \"label\": \"0x00\", \"items\": [ { \"type\": \"vslider\", \"label\": \"Volume\", \"address\": \"/0x00/Volume\", \"meta\": [ { \"style\": \"knob\" } ], \"init\": \"0\", \"min\": \"0\", \"max\": \"1\", \"step\": \"0.1\" } ] } ] } "; }

kripken commented 8 years ago

That doesn't look like valid asm.js? It doesn't have arrays or strings.

Btw, please use escaping (4 backticks "`") to make code easier to read.

sletz commented 8 years ago

OK, this is additional pure JS code that our backend adds with the asm.js module. We can live without that�

Thanks.

Le 5 janv. 2016 � 18:25, Alon Zakai notifications@github.com a �crit :

That doesn't look like valid asm.js? It doesn't have arrays or strings.

Btw, please use escaping (4 backticks "`") to make code easier to read.

� Reply to this email directly or view it on GitHub.