1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.numberLiteralFromRaw = numberLiteralFromRaw;
|
---|
7 | exports.instruction = instruction;
|
---|
8 | exports.objectInstruction = objectInstruction;
|
---|
9 | exports.withLoc = withLoc;
|
---|
10 | exports.withRaw = withRaw;
|
---|
11 | exports.funcParam = funcParam;
|
---|
12 | exports.indexLiteral = indexLiteral;
|
---|
13 | exports.memIndexLiteral = memIndexLiteral;
|
---|
14 |
|
---|
15 | var _helperNumbers = require("@webassemblyjs/helper-numbers");
|
---|
16 |
|
---|
17 | var _nodes = require("./nodes");
|
---|
18 |
|
---|
19 | function numberLiteralFromRaw(rawValue) {
|
---|
20 | var instructionType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "i32";
|
---|
21 | var original = rawValue; // Remove numeric separators _
|
---|
22 |
|
---|
23 | if (typeof rawValue === "string") {
|
---|
24 | rawValue = rawValue.replace(/_/g, "");
|
---|
25 | }
|
---|
26 |
|
---|
27 | if (typeof rawValue === "number") {
|
---|
28 | return (0, _nodes.numberLiteral)(rawValue, String(original));
|
---|
29 | } else {
|
---|
30 | switch (instructionType) {
|
---|
31 | case "i32":
|
---|
32 | {
|
---|
33 | return (0, _nodes.numberLiteral)((0, _helperNumbers.parse32I)(rawValue), String(original));
|
---|
34 | }
|
---|
35 |
|
---|
36 | case "u32":
|
---|
37 | {
|
---|
38 | return (0, _nodes.numberLiteral)((0, _helperNumbers.parseU32)(rawValue), String(original));
|
---|
39 | }
|
---|
40 |
|
---|
41 | case "i64":
|
---|
42 | {
|
---|
43 | return (0, _nodes.longNumberLiteral)((0, _helperNumbers.parse64I)(rawValue), String(original));
|
---|
44 | }
|
---|
45 |
|
---|
46 | case "f32":
|
---|
47 | {
|
---|
48 | return (0, _nodes.floatLiteral)((0, _helperNumbers.parse32F)(rawValue), (0, _helperNumbers.isNanLiteral)(rawValue), (0, _helperNumbers.isInfLiteral)(rawValue), String(original));
|
---|
49 | }
|
---|
50 | // f64
|
---|
51 |
|
---|
52 | default:
|
---|
53 | {
|
---|
54 | return (0, _nodes.floatLiteral)((0, _helperNumbers.parse64F)(rawValue), (0, _helperNumbers.isNanLiteral)(rawValue), (0, _helperNumbers.isInfLiteral)(rawValue), String(original));
|
---|
55 | }
|
---|
56 | }
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | function instruction(id) {
|
---|
61 | var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
---|
62 | var namedArgs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
---|
63 | return (0, _nodes.instr)(id, undefined, args, namedArgs);
|
---|
64 | }
|
---|
65 |
|
---|
66 | function objectInstruction(id, object) {
|
---|
67 | var args = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
---|
68 | var namedArgs = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
---|
69 | return (0, _nodes.instr)(id, object, args, namedArgs);
|
---|
70 | }
|
---|
71 | /**
|
---|
72 | * Decorators
|
---|
73 | */
|
---|
74 |
|
---|
75 |
|
---|
76 | function withLoc(n, end, start) {
|
---|
77 | var loc = {
|
---|
78 | start: start,
|
---|
79 | end: end
|
---|
80 | };
|
---|
81 | n.loc = loc;
|
---|
82 | return n;
|
---|
83 | }
|
---|
84 |
|
---|
85 | function withRaw(n, raw) {
|
---|
86 | n.raw = raw;
|
---|
87 | return n;
|
---|
88 | }
|
---|
89 |
|
---|
90 | function funcParam(valtype, id) {
|
---|
91 | return {
|
---|
92 | id: id,
|
---|
93 | valtype: valtype
|
---|
94 | };
|
---|
95 | }
|
---|
96 |
|
---|
97 | function indexLiteral(value) {
|
---|
98 | // $FlowIgnore
|
---|
99 | var x = numberLiteralFromRaw(value, "u32");
|
---|
100 | return x;
|
---|
101 | }
|
---|
102 |
|
---|
103 | function memIndexLiteral(value) {
|
---|
104 | // $FlowIgnore
|
---|
105 | var x = numberLiteralFromRaw(value, "u32");
|
---|
106 | return x;
|
---|
107 | } |
---|