mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-22 09:45:41 +00:00
Bug 1426251 - Update wasmparser to version 0.4.11. r=jlast
MozReview-Commit-ID: ApiiWfO2T8I --HG-- extra : rebase_source : 03e0a46bb74cd4688720570421054c6323569ed0
This commit is contained in:
parent
3485cf6df8
commit
79f72acfbc
14
devtools/client/shared/vendor/WASMPARSER_UPGRADING
vendored
Normal file
14
devtools/client/shared/vendor/WASMPARSER_UPGRADING
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
# wasmparser version
|
||||
|
||||
Current vesion is: 0.4.11
|
||||
|
||||
# Upgrade process
|
||||
|
||||
1. Pull latest release from npm and extract WasmDis.js and WasmParser.js, e.g.
|
||||
|
||||
```
|
||||
curl https://registry.npmjs.org/wasmparser/-/wasmparser-0.4.11.tgz | tar -x --strip-components 2 package/dist/{WasmDis,WasmParser}.js
|
||||
```
|
||||
|
||||
2. Remove reference to source maps (last line)
|
||||
|
316
devtools/client/shared/vendor/WasmDis.js
vendored
316
devtools/client/shared/vendor/WasmDis.js
vendored
@ -67,6 +67,8 @@ function memoryAddressToString(address, code) {
|
||||
switch (code) {
|
||||
case 41 /* i64_load */:
|
||||
case 55 /* i64_store */:
|
||||
case 43 /* f64_load */:
|
||||
case 57 /* f64_store */:
|
||||
defaultAlignFlags = 3;
|
||||
break;
|
||||
case 40 /* i32_load */:
|
||||
@ -74,6 +76,8 @@ function memoryAddressToString(address, code) {
|
||||
case 53 /* i64_load32_u */:
|
||||
case 54 /* i32_store */:
|
||||
case 62 /* i64_store32 */:
|
||||
case 42 /* f32_load */:
|
||||
case 56 /* f32_store */:
|
||||
defaultAlignFlags = 2;
|
||||
break;
|
||||
case 46 /* i32_load16_s */:
|
||||
@ -94,7 +98,7 @@ function memoryAddressToString(address, code) {
|
||||
break;
|
||||
}
|
||||
if (address.flags == defaultAlignFlags)
|
||||
return !address.offset ? null : "offset=" + (address.offset | 0);
|
||||
return !address.offset ? null : "offset=" + address.offset;
|
||||
if (!address.offset)
|
||||
return "align=" + (1 << address.flags);
|
||||
return "offset=" + (address.offset | 0) + " align=" + (1 << address.flags);
|
||||
@ -141,7 +145,8 @@ var DefaultNameResolver = (function () {
|
||||
return '$table' + index;
|
||||
};
|
||||
DefaultNameResolver.prototype.getMemoryName = function (index, isRef) {
|
||||
return '$memory' + index;
|
||||
// TODO '$memory' + index;
|
||||
return isRef ? '' + index : "(;" + index + ";)";
|
||||
};
|
||||
DefaultNameResolver.prototype.getGlobalName = function (index, isRef) {
|
||||
return '$global' + index;
|
||||
@ -185,6 +190,69 @@ var NumericNameResolver = (function () {
|
||||
return NumericNameResolver;
|
||||
}());
|
||||
exports.NumericNameResolver = NumericNameResolver;
|
||||
var LineBuffer = (function () {
|
||||
function LineBuffer() {
|
||||
this._firstPart = '';
|
||||
this._secondPart = '';
|
||||
this._thirdPart = '';
|
||||
this._count = 0;
|
||||
}
|
||||
Object.defineProperty(LineBuffer.prototype, "length", {
|
||||
get: function () {
|
||||
switch (this._count) {
|
||||
case 0:
|
||||
return 0;
|
||||
case 1:
|
||||
return this._firstPart.length;
|
||||
case 2:
|
||||
return this._firstPart.length + this._secondPart.length;
|
||||
default:
|
||||
return this._firstPart.length +
|
||||
this._secondPart.length +
|
||||
this._thirdPart.length;
|
||||
}
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
LineBuffer.prototype.append = function (part) {
|
||||
switch (this._count) {
|
||||
case 0:
|
||||
this._firstPart = part;
|
||||
this._count = 1;
|
||||
break;
|
||||
case 1:
|
||||
this._secondPart = part;
|
||||
this._count = 2;
|
||||
break;
|
||||
case 2:
|
||||
this._thirdPart = part;
|
||||
this._count = 3;
|
||||
break;
|
||||
default:
|
||||
this._count = 1;
|
||||
this._firstPart = this._firstPart + this._secondPart +
|
||||
this._thirdPart + part;
|
||||
break;
|
||||
}
|
||||
};
|
||||
LineBuffer.prototype.finalize = function () {
|
||||
switch (this._count) {
|
||||
case 0:
|
||||
return '';
|
||||
case 1:
|
||||
this._count = 0;
|
||||
return this._firstPart;
|
||||
case 2:
|
||||
this._count = 0;
|
||||
return this._firstPart + this._secondPart;
|
||||
default:
|
||||
this._count = 0;
|
||||
return this._firstPart + this._secondPart + this._thirdPart;
|
||||
}
|
||||
};
|
||||
return LineBuffer;
|
||||
}());
|
||||
var LabelMode;
|
||||
(function (LabelMode) {
|
||||
LabelMode[LabelMode["Depth"] = 0] = "Depth";
|
||||
@ -195,7 +263,7 @@ var WasmDisassembler = (function () {
|
||||
function WasmDisassembler() {
|
||||
this._lines = [];
|
||||
this._offsets = [];
|
||||
this._buffer = [];
|
||||
this._buffer = new LineBuffer();
|
||||
this._indent = null;
|
||||
this._indentLevel = 0;
|
||||
this._addOffsets = false;
|
||||
@ -211,6 +279,7 @@ var WasmDisassembler = (function () {
|
||||
this._funcTypes = [];
|
||||
this._importCount = 0;
|
||||
this._globalCount = 0;
|
||||
this._memoryCount = 0;
|
||||
this._tableCount = 0;
|
||||
this._initExpression = [];
|
||||
this._backrefLabels = null;
|
||||
@ -253,24 +322,17 @@ var WasmDisassembler = (function () {
|
||||
configurable: true
|
||||
});
|
||||
WasmDisassembler.prototype.appendBuffer = function (s) {
|
||||
this._buffer.push(s);
|
||||
this._buffer.append(s);
|
||||
};
|
||||
WasmDisassembler.prototype.newLine = function () {
|
||||
if (this.addOffsets)
|
||||
this._offsets.push(this._currentPosition);
|
||||
if (this._buffer.length === 0) {
|
||||
this._lines.push('');
|
||||
return;
|
||||
}
|
||||
var line = this._buffer.length > 1 ? this._buffer.join('') : this._buffer[0];
|
||||
this._buffer.length = 0;
|
||||
this._lines.push(line);
|
||||
this._lines.push(this._buffer.finalize());
|
||||
};
|
||||
WasmDisassembler.prototype.printType = function (typeIndex) {
|
||||
WasmDisassembler.prototype.printFuncType = function (typeIndex) {
|
||||
var type = this._types[typeIndex];
|
||||
if (type.form !== -32 /* func */)
|
||||
throw new Error('NYI other function form');
|
||||
this.appendBuffer('(func');
|
||||
if (type.params.length > 0) {
|
||||
this.appendBuffer(' (param');
|
||||
for (var i = 0; i < type.params.length; i++) {
|
||||
@ -287,7 +349,6 @@ var WasmDisassembler = (function () {
|
||||
}
|
||||
this.appendBuffer(')');
|
||||
}
|
||||
this.appendBuffer(')');
|
||||
};
|
||||
WasmDisassembler.prototype.printString = function (b) {
|
||||
this.appendBuffer('\"');
|
||||
@ -323,85 +384,119 @@ var WasmDisassembler = (function () {
|
||||
return backrefLabel.label || '' + depth;
|
||||
};
|
||||
WasmDisassembler.prototype.printOperator = function (operator) {
|
||||
this.appendBuffer(getOperatorName(operator.code));
|
||||
if (operator.blockType !== undefined) {
|
||||
if (this._labelMode !== LabelMode.Depth) {
|
||||
var backrefLabel = {
|
||||
line: this._lines.length,
|
||||
position: this._buffer.reduce(function (acc, s) { return acc + s.length; }, 0),
|
||||
useLabel: false,
|
||||
label: null,
|
||||
};
|
||||
if (this._labelMode === LabelMode.Always) {
|
||||
backrefLabel.useLabel = true;
|
||||
backrefLabel.label = this._nameResolver.getLabel(this._labelIndex++);
|
||||
if (backrefLabel.label) {
|
||||
this.appendBuffer(' ');
|
||||
this.appendBuffer(backrefLabel.label);
|
||||
var code = operator.code;
|
||||
this.appendBuffer(getOperatorName(code));
|
||||
switch (code) {
|
||||
case 2 /* block */:
|
||||
case 3 /* loop */:
|
||||
case 4 /* if */:
|
||||
if (this._labelMode !== LabelMode.Depth) {
|
||||
var backrefLabel_1 = {
|
||||
line: this._lines.length,
|
||||
position: this._buffer.length,
|
||||
useLabel: false,
|
||||
label: null,
|
||||
};
|
||||
if (this._labelMode === LabelMode.Always) {
|
||||
backrefLabel_1.useLabel = true;
|
||||
backrefLabel_1.label = this._nameResolver.getLabel(this._labelIndex++);
|
||||
if (backrefLabel_1.label) {
|
||||
this.appendBuffer(' ');
|
||||
this.appendBuffer(backrefLabel_1.label);
|
||||
}
|
||||
}
|
||||
this._backrefLabels.push(backrefLabel_1);
|
||||
}
|
||||
this._backrefLabels.push(backrefLabel);
|
||||
}
|
||||
if (operator.blockType !== -64 /* empty_block_type */) {
|
||||
this.appendBuffer(' ');
|
||||
this.appendBuffer(typeToString(operator.blockType));
|
||||
}
|
||||
}
|
||||
if (operator.code === 11 /* end */ && this._labelMode !== LabelMode.Depth) {
|
||||
var backrefLabel = this._backrefLabels.pop();
|
||||
if (backrefLabel.label) {
|
||||
this.appendBuffer(' ');
|
||||
this.appendBuffer(backrefLabel.label);
|
||||
}
|
||||
}
|
||||
if (operator.localIndex !== undefined) {
|
||||
var paramName = this._nameResolver.getVariableName(this._funcIndex, operator.localIndex, true);
|
||||
this.appendBuffer(" " + paramName);
|
||||
}
|
||||
if (operator.funcIndex !== undefined) {
|
||||
var funcName = this._nameResolver.getFunctionName(operator.funcIndex, operator.funcIndex < this._importCount, true);
|
||||
this.appendBuffer(" " + funcName);
|
||||
}
|
||||
if (operator.typeIndex !== undefined) {
|
||||
var typeName = this._nameResolver.getTypeName(operator.typeIndex, true);
|
||||
this.appendBuffer(" " + typeName);
|
||||
}
|
||||
if (operator.literal !== undefined) {
|
||||
switch (operator.code) {
|
||||
case 65 /* i32_const */:
|
||||
this.appendBuffer(" " + operator.literal.toString());
|
||||
if (operator.blockType !== -64 /* empty_block_type */) {
|
||||
this.appendBuffer(' (result ');
|
||||
this.appendBuffer(typeToString(operator.blockType));
|
||||
this.appendBuffer(')');
|
||||
}
|
||||
break;
|
||||
case 11 /* end */:
|
||||
if (this._labelMode === LabelMode.Depth) {
|
||||
break;
|
||||
case 67 /* f32_const */:
|
||||
this.appendBuffer(" " + formatFloat32(operator.literal));
|
||||
break;
|
||||
case 68 /* f64_const */:
|
||||
this.appendBuffer(" " + formatFloat64(operator.literal));
|
||||
break;
|
||||
case 66 /* i64_const */:
|
||||
this.appendBuffer(" " + operator.literal.toDouble());
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (operator.memoryAddress !== undefined) {
|
||||
var memoryAddress = memoryAddressToString(operator.memoryAddress, operator.code);
|
||||
if (memoryAddress !== null) {
|
||||
}
|
||||
var backrefLabel = this._backrefLabels.pop();
|
||||
if (backrefLabel.label) {
|
||||
this.appendBuffer(' ');
|
||||
this.appendBuffer(backrefLabel.label);
|
||||
}
|
||||
break;
|
||||
case 12 /* br */:
|
||||
case 13 /* br_if */:
|
||||
this.appendBuffer(' ');
|
||||
this.appendBuffer(memoryAddress);
|
||||
}
|
||||
}
|
||||
if (operator.brDepth !== undefined) {
|
||||
this.appendBuffer(' ');
|
||||
this.appendBuffer(this.useLabel(operator.brDepth));
|
||||
}
|
||||
if (operator.brTable !== undefined) {
|
||||
for (var i = 0; i < operator.brTable.length; i++) {
|
||||
this.appendBuffer(' ');
|
||||
this.appendBuffer(this.useLabel(operator.brTable[i]));
|
||||
}
|
||||
}
|
||||
if (operator.globalIndex !== undefined) {
|
||||
var globalName = this._nameResolver.getGlobalName(operator.globalIndex, true);
|
||||
this.appendBuffer(" " + globalName);
|
||||
this.appendBuffer(this.useLabel(operator.brDepth));
|
||||
break;
|
||||
case 14 /* br_table */:
|
||||
for (var i = 0; i < operator.brTable.length; i++) {
|
||||
this.appendBuffer(' ');
|
||||
this.appendBuffer(this.useLabel(operator.brTable[i]));
|
||||
}
|
||||
break;
|
||||
case 16 /* call */:
|
||||
var funcName = this._nameResolver.getFunctionName(operator.funcIndex, operator.funcIndex < this._importCount, true);
|
||||
this.appendBuffer(" " + funcName);
|
||||
break;
|
||||
case 17 /* call_indirect */:
|
||||
var typeName = this._nameResolver.getTypeName(operator.typeIndex, true);
|
||||
this.appendBuffer(" " + typeName);
|
||||
break;
|
||||
case 32 /* get_local */:
|
||||
case 33 /* set_local */:
|
||||
case 34 /* tee_local */:
|
||||
var paramName = this._nameResolver.getVariableName(this._funcIndex, operator.localIndex, true);
|
||||
this.appendBuffer(" " + paramName);
|
||||
break;
|
||||
case 35 /* get_global */:
|
||||
case 36 /* set_global */:
|
||||
var globalName = this._nameResolver.getGlobalName(operator.globalIndex, true);
|
||||
this.appendBuffer(" " + globalName);
|
||||
break;
|
||||
case 40 /* i32_load */:
|
||||
case 41 /* i64_load */:
|
||||
case 42 /* f32_load */:
|
||||
case 43 /* f64_load */:
|
||||
case 44 /* i32_load8_s */:
|
||||
case 45 /* i32_load8_u */:
|
||||
case 46 /* i32_load16_s */:
|
||||
case 47 /* i32_load16_u */:
|
||||
case 48 /* i64_load8_s */:
|
||||
case 49 /* i64_load8_u */:
|
||||
case 50 /* i64_load16_s */:
|
||||
case 51 /* i64_load16_u */:
|
||||
case 52 /* i64_load32_s */:
|
||||
case 53 /* i64_load32_u */:
|
||||
case 54 /* i32_store */:
|
||||
case 55 /* i64_store */:
|
||||
case 56 /* f32_store */:
|
||||
case 57 /* f64_store */:
|
||||
case 58 /* i32_store8 */:
|
||||
case 59 /* i32_store16 */:
|
||||
case 60 /* i64_store8 */:
|
||||
case 61 /* i64_store16 */:
|
||||
case 62 /* i64_store32 */:
|
||||
var memoryAddress = memoryAddressToString(operator.memoryAddress, operator.code);
|
||||
if (memoryAddress !== null) {
|
||||
this.appendBuffer(' ');
|
||||
this.appendBuffer(memoryAddress);
|
||||
}
|
||||
break;
|
||||
case 63 /* current_memory */:
|
||||
case 64 /* grow_memory */:
|
||||
break;
|
||||
case 65 /* i32_const */:
|
||||
this.appendBuffer(" " + operator.literal.toString());
|
||||
break;
|
||||
case 66 /* i64_const */:
|
||||
this.appendBuffer(" " + operator.literal.toDouble());
|
||||
break;
|
||||
case 67 /* f32_const */:
|
||||
this.appendBuffer(" " + formatFloat32(operator.literal));
|
||||
break;
|
||||
case 68 /* f64_const */:
|
||||
this.appendBuffer(" " + formatFloat64(operator.literal));
|
||||
break;
|
||||
}
|
||||
};
|
||||
WasmDisassembler.prototype.printImportSource = function (info) {
|
||||
@ -524,7 +619,8 @@ var WasmDisassembler = (function () {
|
||||
break;
|
||||
case 15 /* MEMORY_SECTION_ENTRY */:
|
||||
var memoryInfo = reader.result;
|
||||
this.appendBuffer(" (memory " + memoryInfo.limits.initial);
|
||||
var memoryName = this._nameResolver.getMemoryName(this._memoryCount++, false);
|
||||
this.appendBuffer(" (memory " + memoryName + " " + memoryInfo.limits.initial);
|
||||
if (memoryInfo.limits.maximum !== undefined) {
|
||||
this.appendBuffer(" " + memoryInfo.limits.maximum);
|
||||
}
|
||||
@ -534,8 +630,7 @@ var WasmDisassembler = (function () {
|
||||
case 14 /* TABLE_SECTION_ENTRY */:
|
||||
var tableInfo = reader.result;
|
||||
var tableName = this._nameResolver.getTableName(this._tableCount++, false);
|
||||
// TODO use tableName
|
||||
this.appendBuffer(" (table " + limitsToString(tableInfo.limits) + " " + typeToString(tableInfo.elementType) + ")");
|
||||
this.appendBuffer(" (table " + tableName + " " + limitsToString(tableInfo.limits) + " " + typeToString(tableInfo.elementType) + ")");
|
||||
this.newLine();
|
||||
break;
|
||||
case 17 /* EXPORT_SECTION_ENTRY */:
|
||||
@ -545,15 +640,16 @@ var WasmDisassembler = (function () {
|
||||
this.appendBuffer(' ');
|
||||
switch (exportInfo.kind) {
|
||||
case 0 /* Function */:
|
||||
this.appendBuffer(this._nameResolver.getFunctionName(exportInfo.index, exportInfo.index < this._importCount, true));
|
||||
var funcName = this._nameResolver.getFunctionName(exportInfo.index, exportInfo.index < this._importCount, true);
|
||||
this.appendBuffer("(func " + funcName + ")");
|
||||
break;
|
||||
case 1 /* Table */:
|
||||
var tableName = this._nameResolver.getTableName(exportInfo.index, true);
|
||||
// TODO use tableName
|
||||
this.appendBuffer("(table " + exportInfo.index + ")");
|
||||
this.appendBuffer("(table " + tableName + ")");
|
||||
break;
|
||||
case 2 /* Memory */:
|
||||
this.appendBuffer("memory");
|
||||
var memoryName = this._nameResolver.getMemoryName(exportInfo.index, true);
|
||||
this.appendBuffer("(memory " + memoryName + ")");
|
||||
break;
|
||||
case 3 /* Global */:
|
||||
var globalName = this._nameResolver.getGlobalName(exportInfo.index, true);
|
||||
@ -567,39 +663,35 @@ var WasmDisassembler = (function () {
|
||||
break;
|
||||
case 12 /* IMPORT_SECTION_ENTRY */:
|
||||
var importInfo = reader.result;
|
||||
this.appendBuffer(' (import ');
|
||||
this.printImportSource(importInfo);
|
||||
switch (importInfo.kind) {
|
||||
case 0 /* Function */:
|
||||
this._importCount++;
|
||||
var funcName = this._nameResolver.getFunctionName(this._funcIndex++, true, false);
|
||||
this.appendBuffer(" (import " + funcName + " ");
|
||||
this.printImportSource(importInfo);
|
||||
this.appendBuffer(' ');
|
||||
this.printType(importInfo.funcTypeIndex);
|
||||
this.appendBuffer(" (func " + funcName);
|
||||
this.printFuncType(importInfo.funcTypeIndex);
|
||||
this.appendBuffer(')');
|
||||
break;
|
||||
case 1 /* Table */:
|
||||
var tableImportInfo = importInfo.type;
|
||||
var tableName = this._nameResolver.getTableName(this._tableCount++, false);
|
||||
this.appendBuffer(" (import " + tableName + " ");
|
||||
this.printImportSource(importInfo);
|
||||
this.appendBuffer(" (table " + limitsToString(tableImportInfo.limits) + " " + typeToString(tableImportInfo.elementType) + "))");
|
||||
this.appendBuffer(" (table " + tableName + " " + limitsToString(tableImportInfo.limits) + " " + typeToString(tableImportInfo.elementType) + ")");
|
||||
break;
|
||||
case 2 /* Memory */:
|
||||
var memoryImportInfo = importInfo.type;
|
||||
this.appendBuffer(' (import ');
|
||||
this.printImportSource(importInfo);
|
||||
this.appendBuffer(" (memory " + limitsToString(memoryImportInfo.limits) + "))");
|
||||
var memoryName = this._nameResolver.getMemoryName(this._memoryCount++, false);
|
||||
this.appendBuffer(" (memory " + memoryName + " " + limitsToString(memoryImportInfo.limits) + ")");
|
||||
break;
|
||||
case 3 /* Global */:
|
||||
var globalImportInfo = importInfo.type;
|
||||
var globalName = this._nameResolver.getGlobalName(this._globalCount++, false);
|
||||
this.appendBuffer(" (import " + globalName + " ");
|
||||
this.printImportSource(importInfo);
|
||||
this.appendBuffer(" (global " + globalTypeToString(globalImportInfo) + "))");
|
||||
this.appendBuffer(" (global " + globalName + " " + globalTypeToString(globalImportInfo) + ")");
|
||||
break;
|
||||
default:
|
||||
throw new Error("NYI other import types: " + importInfo.kind);
|
||||
}
|
||||
this.appendBuffer(')');
|
||||
this.newLine();
|
||||
break;
|
||||
case 33 /* BEGIN_ELEMENT_SECTION_ENTRY */:
|
||||
@ -631,9 +723,9 @@ var WasmDisassembler = (function () {
|
||||
var typeIndex = this._types.length;
|
||||
this._types.push(funcType);
|
||||
var typeName = this._nameResolver.getTypeName(typeIndex, false);
|
||||
this.appendBuffer(" (type " + typeName + " ");
|
||||
this.printType(typeIndex);
|
||||
this.appendBuffer(')');
|
||||
this.appendBuffer(" (type " + typeName + " (func");
|
||||
this.printFuncType(typeIndex);
|
||||
this.appendBuffer('))');
|
||||
this.newLine();
|
||||
break;
|
||||
case 22 /* START_SECTION_ENTRY */:
|
||||
|
Loading…
Reference in New Issue
Block a user