# 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
    28x
    28x
    28x

    28x
    29x

    29x
    29x
    3x

    26x
    26x

    7x

    6x

    13x

    26x

    26x

    29x

     // @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;