# All files / src/generator native.js

100% Statements 16/16
100% Branches 9/9
100% Functions 2/2
100% Lines 16/16

    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
    24x
    24x
    24x

    24x
    23x

    23x
    23x
    1x

    22x
    22x

    5x

    6x

    11x

    22x

    22x

    23x

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

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

      const operation = node.value.split(".").pop();
      if (operation === "clz") {
        block.push({ kind: textMap[node.value], params: [] });
      } else {
        const alignment = (() => {
          switch (operation) {
            case "load8_s":
            case "load8_u":
            case "store8":
              return 0;
            case "load16_s":
            case "load16_u":
            case "store16":
              return 1;
            // "store32" as well
            default:
              return 2;
          }
        })();

        const params = [alignment, 0];

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

      return block;
    };

    export default generateNative;