source: trip-planner-front/node_modules/@webassemblyjs/ast/esm/node-helpers.js@ bdd6491

Last change on this file since bdd6491 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.3 KB
Line 
1import { parse32F, parse64F, parse32I, parse64I, parseU32, isNanLiteral, isInfLiteral } from "@webassemblyjs/helper-numbers";
2import { longNumberLiteral, floatLiteral, numberLiteral, instr } from "./nodes";
3export function numberLiteralFromRaw(rawValue) {
4 var instructionType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "i32";
5 var original = rawValue; // Remove numeric separators _
6
7 if (typeof rawValue === "string") {
8 rawValue = rawValue.replace(/_/g, "");
9 }
10
11 if (typeof rawValue === "number") {
12 return numberLiteral(rawValue, String(original));
13 } else {
14 switch (instructionType) {
15 case "i32":
16 {
17 return numberLiteral(parse32I(rawValue), String(original));
18 }
19
20 case "u32":
21 {
22 return numberLiteral(parseU32(rawValue), String(original));
23 }
24
25 case "i64":
26 {
27 return longNumberLiteral(parse64I(rawValue), String(original));
28 }
29
30 case "f32":
31 {
32 return floatLiteral(parse32F(rawValue), isNanLiteral(rawValue), isInfLiteral(rawValue), String(original));
33 }
34 // f64
35
36 default:
37 {
38 return floatLiteral(parse64F(rawValue), isNanLiteral(rawValue), isInfLiteral(rawValue), String(original));
39 }
40 }
41 }
42}
43export function instruction(id) {
44 var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
45 var namedArgs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
46 return instr(id, undefined, args, namedArgs);
47}
48export function objectInstruction(id, object) {
49 var args = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
50 var namedArgs = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
51 return instr(id, object, args, namedArgs);
52}
53/**
54 * Decorators
55 */
56
57export function withLoc(n, end, start) {
58 var loc = {
59 start: start,
60 end: end
61 };
62 n.loc = loc;
63 return n;
64}
65export function withRaw(n, raw) {
66 n.raw = raw;
67 return n;
68}
69export function funcParam(valtype, id) {
70 return {
71 id: id,
72 valtype: valtype
73 };
74}
75export function indexLiteral(value) {
76 // $FlowIgnore
77 var x = numberLiteralFromRaw(value, "u32");
78 return x;
79}
80export function memIndexLiteral(value) {
81 // $FlowIgnore
82 var x = numberLiteralFromRaw(value, "u32");
83 return x;
84}
Note: See TracBrowser for help on using the repository browser.