# All files / src/utils debug.js

100% Statements 13/13
100% Branches 5/5
100% Functions 3/3
100% Lines 13/13

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    22x
    22x

    22x
    7x
    7x

    1681x

    1681x
    690x
    695x

    991x

    1681x
    1681x
    1681x

     // @flow
    import { sizeof } from 'wasm-types';
    import OutputStream from './output-stream';

    const _debug = (stream: OutputStream, begin: number = 0, end?: number) => {
      let pc = 0;
      return (
        stream.data
          .slice(begin, end)
          .map(({ type, value, debug }) => {
            const pcString = pc
              .toString(16)
              .padStart(8, '0')
              .padEnd(stream.data.length.toString().length + 1);
            let valueString;
            if (Array.isArray(value)) {
              valueString = value
                .map(v => v.toString(16))
                .join()
                .padStart(16);
            } else {
              valueString = value.toString(16).padStart(16);
            }
            const out = `${pcString}: ${valueString} ; ${debug}`;
            pc += sizeof[type] || value.length;
            return out;
          })
          .join('\n') + '\n ============ fin ============='
      );
    };

    export default _debug;