[6a3a178] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
---|
| 4 | value: true
|
---|
| 5 | });
|
---|
| 6 | exports.shrinkPaddedLEB128 = shrinkPaddedLEB128;
|
---|
| 7 |
|
---|
| 8 | var _ast = require("@webassemblyjs/ast");
|
---|
| 9 |
|
---|
| 10 | var _encoder = require("@webassemblyjs/wasm-gen/lib/encoder");
|
---|
| 11 |
|
---|
| 12 | var _helperBuffer = require("@webassemblyjs/helper-buffer");
|
---|
| 13 |
|
---|
| 14 | function shiftFollowingSections(ast, _ref, deltaInSizeEncoding) {
|
---|
| 15 | var section = _ref.section;
|
---|
| 16 | // Once we hit our section every that is after needs to be shifted by the delta
|
---|
| 17 | var encounteredSection = false;
|
---|
| 18 | (0, _ast.traverse)(ast, {
|
---|
| 19 | SectionMetadata: function SectionMetadata(path) {
|
---|
| 20 | if (path.node.section === section) {
|
---|
| 21 | encounteredSection = true;
|
---|
| 22 | return;
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | if (encounteredSection === true) {
|
---|
| 26 | (0, _ast.shiftSection)(ast, path.node, deltaInSizeEncoding);
|
---|
| 27 | }
|
---|
| 28 | }
|
---|
| 29 | });
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | function shrinkPaddedLEB128(ast, uint8Buffer) {
|
---|
| 33 | (0, _ast.traverse)(ast, {
|
---|
| 34 | SectionMetadata: function SectionMetadata(_ref2) {
|
---|
| 35 | var node = _ref2.node;
|
---|
| 36 |
|
---|
| 37 | /**
|
---|
| 38 | * Section size
|
---|
| 39 | */
|
---|
| 40 | {
|
---|
| 41 | var newu32Encoded = (0, _encoder.encodeU32)(node.size.value);
|
---|
| 42 | var newu32EncodedLen = newu32Encoded.length;
|
---|
| 43 | var start = node.size.loc.start.column;
|
---|
| 44 | var end = node.size.loc.end.column;
|
---|
| 45 | var oldu32EncodedLen = end - start;
|
---|
| 46 |
|
---|
| 47 | if (newu32EncodedLen !== oldu32EncodedLen) {
|
---|
| 48 | var deltaInSizeEncoding = oldu32EncodedLen - newu32EncodedLen;
|
---|
| 49 | uint8Buffer = (0, _helperBuffer.overrideBytesInBuffer)(uint8Buffer, start, end, newu32Encoded);
|
---|
| 50 | shiftFollowingSections(ast, node, -deltaInSizeEncoding);
|
---|
| 51 | }
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
| 54 | });
|
---|
| 55 | return uint8Buffer;
|
---|
| 56 | } |
---|