# All files / src/generator native.js

100% Statements 13/13
100% Branches 2/2
100% Functions 1/1
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
    34
    35
    36
    37
    38
    39
    40
    23x
    23x
    23x

    23x

    23x
    27x

    27x

    27x
    5x

    22x

    22x

    22x

    27x

     // @flow
    import mergeBlock from './merge-block';
    import mapSyntax from './map-syntax';
    import { textMap } from '../emitter/opcode';
    import type { GeneratorType } from './flow/types';

    const alignCodes = {
      load8_s: 0,
      load8_u: 0,
      store8: 0,
      load16_s: 1,
      load16_u: 1,
      store16: 1,
      store32: 2,
      load32_s: 2,
      load32_u: 2,
      store: 2,
      load: 2,
    };

    const generateNative: GeneratorType = (node, parent) => {
      const block = node.params.map(mapSyntax(parent)).reduce(mergeBlock, []);

      const operation = node.value.split('.').pop();

      if (alignCodes[operation] == null) {
        block.push({ kind: textMap[node.value], params: [] });
      } else {
        const alignment = alignCodes[operation];

        const params = [alignment, 0];

        block.push({ kind: textMap[node.value], params });
      }

      return block;
    };

    export default generateNative;