nodes.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.module = _module;
  6. exports.moduleMetadata = moduleMetadata;
  7. exports.moduleNameMetadata = moduleNameMetadata;
  8. exports.functionNameMetadata = functionNameMetadata;
  9. exports.localNameMetadata = localNameMetadata;
  10. exports.binaryModule = binaryModule;
  11. exports.quoteModule = quoteModule;
  12. exports.sectionMetadata = sectionMetadata;
  13. exports.loopInstruction = loopInstruction;
  14. exports.instr = instr;
  15. exports.ifInstruction = ifInstruction;
  16. exports.stringLiteral = stringLiteral;
  17. exports.numberLiteral = numberLiteral;
  18. exports.longNumberLiteral = longNumberLiteral;
  19. exports.floatLiteral = floatLiteral;
  20. exports.elem = elem;
  21. exports.indexInFuncSection = indexInFuncSection;
  22. exports.valtypeLiteral = valtypeLiteral;
  23. exports.typeInstruction = typeInstruction;
  24. exports.start = start;
  25. exports.globalType = globalType;
  26. exports.leadingComment = leadingComment;
  27. exports.blockComment = blockComment;
  28. exports.data = data;
  29. exports.global = global;
  30. exports.table = table;
  31. exports.memory = memory;
  32. exports.funcImportDescr = funcImportDescr;
  33. exports.moduleImport = moduleImport;
  34. exports.moduleExportDescr = moduleExportDescr;
  35. exports.moduleExport = moduleExport;
  36. exports.limit = limit;
  37. exports.signature = signature;
  38. exports.program = program;
  39. exports.identifier = identifier;
  40. exports.blockInstruction = blockInstruction;
  41. exports.callInstruction = callInstruction;
  42. exports.callIndirectInstruction = callIndirectInstruction;
  43. exports.byteArray = byteArray;
  44. exports.func = func;
  45. exports.nodeAndUnionTypes = exports.unionTypesMap = exports.assertFunc = exports.assertByteArray = exports.assertCallIndirectInstruction = exports.assertCallInstruction = exports.assertBlockInstruction = exports.assertIdentifier = exports.assertProgram = exports.assertSignature = exports.assertLimit = exports.assertModuleExport = exports.assertModuleExportDescr = exports.assertModuleImport = exports.assertFuncImportDescr = exports.assertMemory = exports.assertTable = exports.assertGlobal = exports.assertData = exports.assertBlockComment = exports.assertLeadingComment = exports.assertGlobalType = exports.assertStart = exports.assertTypeInstruction = exports.assertValtypeLiteral = exports.assertIndexInFuncSection = exports.assertElem = exports.assertFloatLiteral = exports.assertLongNumberLiteral = exports.assertNumberLiteral = exports.assertStringLiteral = exports.assertIfInstruction = exports.assertInstr = exports.assertLoopInstruction = exports.assertSectionMetadata = exports.assertQuoteModule = exports.assertBinaryModule = exports.assertLocalNameMetadata = exports.assertFunctionNameMetadata = exports.assertModuleNameMetadata = exports.assertModuleMetadata = exports.assertModule = exports.isImportDescr = exports.isNumericLiteral = exports.isExpression = exports.isInstruction = exports.isBlock = exports.isNode = exports.isFunc = exports.isByteArray = exports.isCallIndirectInstruction = exports.isCallInstruction = exports.isBlockInstruction = exports.isIdentifier = exports.isProgram = exports.isSignature = exports.isLimit = exports.isModuleExport = exports.isModuleExportDescr = exports.isModuleImport = exports.isFuncImportDescr = exports.isMemory = exports.isTable = exports.isGlobal = exports.isData = exports.isBlockComment = exports.isLeadingComment = exports.isGlobalType = exports.isStart = exports.isTypeInstruction = exports.isValtypeLiteral = exports.isIndexInFuncSection = exports.isElem = exports.isFloatLiteral = exports.isLongNumberLiteral = exports.isNumberLiteral = exports.isStringLiteral = exports.isIfInstruction = exports.isInstr = exports.isLoopInstruction = exports.isSectionMetadata = exports.isQuoteModule = exports.isBinaryModule = exports.isLocalNameMetadata = exports.isFunctionNameMetadata = exports.isModuleNameMetadata = exports.isModuleMetadata = exports.isModule = void 0;
  46. var _mamacro = require("mamacro");
  47. function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  48. function isTypeOf(t) {
  49. return function (n) {
  50. return n.type === t;
  51. };
  52. }
  53. function assertTypeOf(t) {
  54. return function (n) {
  55. return function () {
  56. if (!(n.type === t)) {
  57. throw new Error('n.type === t' + " error: " + (undefined || "unknown"));
  58. }
  59. }();
  60. };
  61. }
  62. function _module(id, fields, metadata) {
  63. if (id !== null && id !== undefined) {
  64. if (!(typeof id === "string")) {
  65. throw new Error('typeof id === "string"' + " error: " + (undefined || "unknown"));
  66. }
  67. }
  68. if (!(_typeof(fields) === "object" && typeof fields.length !== "undefined")) {
  69. throw new Error('typeof fields === "object" && typeof fields.length !== "undefined"' + " error: " + (undefined || "unknown"));
  70. }
  71. var node = {
  72. type: "Module",
  73. id: id,
  74. fields: fields
  75. };
  76. if (typeof metadata !== "undefined") {
  77. node.metadata = metadata;
  78. }
  79. return node;
  80. }
  81. function moduleMetadata(sections, functionNames, localNames) {
  82. if (!(_typeof(sections) === "object" && typeof sections.length !== "undefined")) {
  83. throw new Error('typeof sections === "object" && typeof sections.length !== "undefined"' + " error: " + (undefined || "unknown"));
  84. }
  85. if (functionNames !== null && functionNames !== undefined) {
  86. if (!(_typeof(functionNames) === "object" && typeof functionNames.length !== "undefined")) {
  87. throw new Error('typeof functionNames === "object" && typeof functionNames.length !== "undefined"' + " error: " + (undefined || "unknown"));
  88. }
  89. }
  90. if (localNames !== null && localNames !== undefined) {
  91. if (!(_typeof(localNames) === "object" && typeof localNames.length !== "undefined")) {
  92. throw new Error('typeof localNames === "object" && typeof localNames.length !== "undefined"' + " error: " + (undefined || "unknown"));
  93. }
  94. }
  95. var node = {
  96. type: "ModuleMetadata",
  97. sections: sections
  98. };
  99. if (typeof functionNames !== "undefined" && functionNames.length > 0) {
  100. node.functionNames = functionNames;
  101. }
  102. if (typeof localNames !== "undefined" && localNames.length > 0) {
  103. node.localNames = localNames;
  104. }
  105. return node;
  106. }
  107. function moduleNameMetadata(value) {
  108. if (!(typeof value === "string")) {
  109. throw new Error('typeof value === "string"' + " error: " + (undefined || "unknown"));
  110. }
  111. var node = {
  112. type: "ModuleNameMetadata",
  113. value: value
  114. };
  115. return node;
  116. }
  117. function functionNameMetadata(value, index) {
  118. if (!(typeof value === "string")) {
  119. throw new Error('typeof value === "string"' + " error: " + (undefined || "unknown"));
  120. }
  121. if (!(typeof index === "number")) {
  122. throw new Error('typeof index === "number"' + " error: " + (undefined || "unknown"));
  123. }
  124. var node = {
  125. type: "FunctionNameMetadata",
  126. value: value,
  127. index: index
  128. };
  129. return node;
  130. }
  131. function localNameMetadata(value, localIndex, functionIndex) {
  132. if (!(typeof value === "string")) {
  133. throw new Error('typeof value === "string"' + " error: " + (undefined || "unknown"));
  134. }
  135. if (!(typeof localIndex === "number")) {
  136. throw new Error('typeof localIndex === "number"' + " error: " + (undefined || "unknown"));
  137. }
  138. if (!(typeof functionIndex === "number")) {
  139. throw new Error('typeof functionIndex === "number"' + " error: " + (undefined || "unknown"));
  140. }
  141. var node = {
  142. type: "LocalNameMetadata",
  143. value: value,
  144. localIndex: localIndex,
  145. functionIndex: functionIndex
  146. };
  147. return node;
  148. }
  149. function binaryModule(id, blob) {
  150. if (id !== null && id !== undefined) {
  151. if (!(typeof id === "string")) {
  152. throw new Error('typeof id === "string"' + " error: " + (undefined || "unknown"));
  153. }
  154. }
  155. if (!(_typeof(blob) === "object" && typeof blob.length !== "undefined")) {
  156. throw new Error('typeof blob === "object" && typeof blob.length !== "undefined"' + " error: " + (undefined || "unknown"));
  157. }
  158. var node = {
  159. type: "BinaryModule",
  160. id: id,
  161. blob: blob
  162. };
  163. return node;
  164. }
  165. function quoteModule(id, string) {
  166. if (id !== null && id !== undefined) {
  167. if (!(typeof id === "string")) {
  168. throw new Error('typeof id === "string"' + " error: " + (undefined || "unknown"));
  169. }
  170. }
  171. if (!(_typeof(string) === "object" && typeof string.length !== "undefined")) {
  172. throw new Error('typeof string === "object" && typeof string.length !== "undefined"' + " error: " + (undefined || "unknown"));
  173. }
  174. var node = {
  175. type: "QuoteModule",
  176. id: id,
  177. string: string
  178. };
  179. return node;
  180. }
  181. function sectionMetadata(section, startOffset, size, vectorOfSize) {
  182. if (!(typeof startOffset === "number")) {
  183. throw new Error('typeof startOffset === "number"' + " error: " + (undefined || "unknown"));
  184. }
  185. var node = {
  186. type: "SectionMetadata",
  187. section: section,
  188. startOffset: startOffset,
  189. size: size,
  190. vectorOfSize: vectorOfSize
  191. };
  192. return node;
  193. }
  194. function loopInstruction(label, resulttype, instr) {
  195. if (!(_typeof(instr) === "object" && typeof instr.length !== "undefined")) {
  196. throw new Error('typeof instr === "object" && typeof instr.length !== "undefined"' + " error: " + (undefined || "unknown"));
  197. }
  198. var node = {
  199. type: "LoopInstruction",
  200. id: "loop",
  201. label: label,
  202. resulttype: resulttype,
  203. instr: instr
  204. };
  205. return node;
  206. }
  207. function instr(id, object, args, namedArgs) {
  208. if (!(typeof id === "string")) {
  209. throw new Error('typeof id === "string"' + " error: " + (undefined || "unknown"));
  210. }
  211. if (!(_typeof(args) === "object" && typeof args.length !== "undefined")) {
  212. throw new Error('typeof args === "object" && typeof args.length !== "undefined"' + " error: " + (undefined || "unknown"));
  213. }
  214. var node = {
  215. type: "Instr",
  216. id: id,
  217. args: args
  218. };
  219. if (typeof object !== "undefined") {
  220. node.object = object;
  221. }
  222. if (typeof namedArgs !== "undefined" && Object.keys(namedArgs).length !== 0) {
  223. node.namedArgs = namedArgs;
  224. }
  225. return node;
  226. }
  227. function ifInstruction(testLabel, test, result, consequent, alternate) {
  228. if (!(_typeof(test) === "object" && typeof test.length !== "undefined")) {
  229. throw new Error('typeof test === "object" && typeof test.length !== "undefined"' + " error: " + (undefined || "unknown"));
  230. }
  231. if (!(_typeof(consequent) === "object" && typeof consequent.length !== "undefined")) {
  232. throw new Error('typeof consequent === "object" && typeof consequent.length !== "undefined"' + " error: " + (undefined || "unknown"));
  233. }
  234. if (!(_typeof(alternate) === "object" && typeof alternate.length !== "undefined")) {
  235. throw new Error('typeof alternate === "object" && typeof alternate.length !== "undefined"' + " error: " + (undefined || "unknown"));
  236. }
  237. var node = {
  238. type: "IfInstruction",
  239. id: "if",
  240. testLabel: testLabel,
  241. test: test,
  242. result: result,
  243. consequent: consequent,
  244. alternate: alternate
  245. };
  246. return node;
  247. }
  248. function stringLiteral(value) {
  249. if (!(typeof value === "string")) {
  250. throw new Error('typeof value === "string"' + " error: " + (undefined || "unknown"));
  251. }
  252. var node = {
  253. type: "StringLiteral",
  254. value: value
  255. };
  256. return node;
  257. }
  258. function numberLiteral(value, raw) {
  259. if (!(typeof value === "number")) {
  260. throw new Error('typeof value === "number"' + " error: " + (undefined || "unknown"));
  261. }
  262. if (!(typeof raw === "string")) {
  263. throw new Error('typeof raw === "string"' + " error: " + (undefined || "unknown"));
  264. }
  265. var node = {
  266. type: "NumberLiteral",
  267. value: value,
  268. raw: raw
  269. };
  270. return node;
  271. }
  272. function longNumberLiteral(value, raw) {
  273. if (!(typeof raw === "string")) {
  274. throw new Error('typeof raw === "string"' + " error: " + (undefined || "unknown"));
  275. }
  276. var node = {
  277. type: "LongNumberLiteral",
  278. value: value,
  279. raw: raw
  280. };
  281. return node;
  282. }
  283. function floatLiteral(value, nan, inf, raw) {
  284. if (!(typeof value === "number")) {
  285. throw new Error('typeof value === "number"' + " error: " + (undefined || "unknown"));
  286. }
  287. if (nan !== null && nan !== undefined) {
  288. if (!(typeof nan === "boolean")) {
  289. throw new Error('typeof nan === "boolean"' + " error: " + (undefined || "unknown"));
  290. }
  291. }
  292. if (inf !== null && inf !== undefined) {
  293. if (!(typeof inf === "boolean")) {
  294. throw new Error('typeof inf === "boolean"' + " error: " + (undefined || "unknown"));
  295. }
  296. }
  297. if (!(typeof raw === "string")) {
  298. throw new Error('typeof raw === "string"' + " error: " + (undefined || "unknown"));
  299. }
  300. var node = {
  301. type: "FloatLiteral",
  302. value: value,
  303. raw: raw
  304. };
  305. if (nan === true) {
  306. node.nan = true;
  307. }
  308. if (inf === true) {
  309. node.inf = true;
  310. }
  311. return node;
  312. }
  313. function elem(table, offset, funcs) {
  314. if (!(_typeof(offset) === "object" && typeof offset.length !== "undefined")) {
  315. throw new Error('typeof offset === "object" && typeof offset.length !== "undefined"' + " error: " + (undefined || "unknown"));
  316. }
  317. if (!(_typeof(funcs) === "object" && typeof funcs.length !== "undefined")) {
  318. throw new Error('typeof funcs === "object" && typeof funcs.length !== "undefined"' + " error: " + (undefined || "unknown"));
  319. }
  320. var node = {
  321. type: "Elem",
  322. table: table,
  323. offset: offset,
  324. funcs: funcs
  325. };
  326. return node;
  327. }
  328. function indexInFuncSection(index) {
  329. var node = {
  330. type: "IndexInFuncSection",
  331. index: index
  332. };
  333. return node;
  334. }
  335. function valtypeLiteral(name) {
  336. var node = {
  337. type: "ValtypeLiteral",
  338. name: name
  339. };
  340. return node;
  341. }
  342. function typeInstruction(id, functype) {
  343. var node = {
  344. type: "TypeInstruction",
  345. id: id,
  346. functype: functype
  347. };
  348. return node;
  349. }
  350. function start(index) {
  351. var node = {
  352. type: "Start",
  353. index: index
  354. };
  355. return node;
  356. }
  357. function globalType(valtype, mutability) {
  358. var node = {
  359. type: "GlobalType",
  360. valtype: valtype,
  361. mutability: mutability
  362. };
  363. return node;
  364. }
  365. function leadingComment(value) {
  366. if (!(typeof value === "string")) {
  367. throw new Error('typeof value === "string"' + " error: " + (undefined || "unknown"));
  368. }
  369. var node = {
  370. type: "LeadingComment",
  371. value: value
  372. };
  373. return node;
  374. }
  375. function blockComment(value) {
  376. if (!(typeof value === "string")) {
  377. throw new Error('typeof value === "string"' + " error: " + (undefined || "unknown"));
  378. }
  379. var node = {
  380. type: "BlockComment",
  381. value: value
  382. };
  383. return node;
  384. }
  385. function data(memoryIndex, offset, init) {
  386. var node = {
  387. type: "Data",
  388. memoryIndex: memoryIndex,
  389. offset: offset,
  390. init: init
  391. };
  392. return node;
  393. }
  394. function global(globalType, init, name) {
  395. if (!(_typeof(init) === "object" && typeof init.length !== "undefined")) {
  396. throw new Error('typeof init === "object" && typeof init.length !== "undefined"' + " error: " + (undefined || "unknown"));
  397. }
  398. var node = {
  399. type: "Global",
  400. globalType: globalType,
  401. init: init,
  402. name: name
  403. };
  404. return node;
  405. }
  406. function table(elementType, limits, name, elements) {
  407. if (elements !== null && elements !== undefined) {
  408. if (!(_typeof(elements) === "object" && typeof elements.length !== "undefined")) {
  409. throw new Error('typeof elements === "object" && typeof elements.length !== "undefined"' + " error: " + (undefined || "unknown"));
  410. }
  411. }
  412. var node = {
  413. type: "Table",
  414. elementType: elementType,
  415. limits: limits,
  416. name: name
  417. };
  418. if (typeof elements !== "undefined" && elements.length > 0) {
  419. node.elements = elements;
  420. }
  421. return node;
  422. }
  423. function memory(limits, id) {
  424. var node = {
  425. type: "Memory",
  426. limits: limits,
  427. id: id
  428. };
  429. return node;
  430. }
  431. function funcImportDescr(id, signature) {
  432. var node = {
  433. type: "FuncImportDescr",
  434. id: id,
  435. signature: signature
  436. };
  437. return node;
  438. }
  439. function moduleImport(module, name, descr) {
  440. if (!(typeof module === "string")) {
  441. throw new Error('typeof module === "string"' + " error: " + (undefined || "unknown"));
  442. }
  443. if (!(typeof name === "string")) {
  444. throw new Error('typeof name === "string"' + " error: " + (undefined || "unknown"));
  445. }
  446. var node = {
  447. type: "ModuleImport",
  448. module: module,
  449. name: name,
  450. descr: descr
  451. };
  452. return node;
  453. }
  454. function moduleExportDescr(exportType, id) {
  455. var node = {
  456. type: "ModuleExportDescr",
  457. exportType: exportType,
  458. id: id
  459. };
  460. return node;
  461. }
  462. function moduleExport(name, descr) {
  463. if (!(typeof name === "string")) {
  464. throw new Error('typeof name === "string"' + " error: " + (undefined || "unknown"));
  465. }
  466. var node = {
  467. type: "ModuleExport",
  468. name: name,
  469. descr: descr
  470. };
  471. return node;
  472. }
  473. function limit(min, max) {
  474. if (!(typeof min === "number")) {
  475. throw new Error('typeof min === "number"' + " error: " + (undefined || "unknown"));
  476. }
  477. if (max !== null && max !== undefined) {
  478. if (!(typeof max === "number")) {
  479. throw new Error('typeof max === "number"' + " error: " + (undefined || "unknown"));
  480. }
  481. }
  482. var node = {
  483. type: "Limit",
  484. min: min
  485. };
  486. if (typeof max !== "undefined") {
  487. node.max = max;
  488. }
  489. return node;
  490. }
  491. function signature(params, results) {
  492. if (!(_typeof(params) === "object" && typeof params.length !== "undefined")) {
  493. throw new Error('typeof params === "object" && typeof params.length !== "undefined"' + " error: " + (undefined || "unknown"));
  494. }
  495. if (!(_typeof(results) === "object" && typeof results.length !== "undefined")) {
  496. throw new Error('typeof results === "object" && typeof results.length !== "undefined"' + " error: " + (undefined || "unknown"));
  497. }
  498. var node = {
  499. type: "Signature",
  500. params: params,
  501. results: results
  502. };
  503. return node;
  504. }
  505. function program(body) {
  506. if (!(_typeof(body) === "object" && typeof body.length !== "undefined")) {
  507. throw new Error('typeof body === "object" && typeof body.length !== "undefined"' + " error: " + (undefined || "unknown"));
  508. }
  509. var node = {
  510. type: "Program",
  511. body: body
  512. };
  513. return node;
  514. }
  515. function identifier(value, raw) {
  516. if (!(typeof value === "string")) {
  517. throw new Error('typeof value === "string"' + " error: " + (undefined || "unknown"));
  518. }
  519. if (raw !== null && raw !== undefined) {
  520. if (!(typeof raw === "string")) {
  521. throw new Error('typeof raw === "string"' + " error: " + (undefined || "unknown"));
  522. }
  523. }
  524. var node = {
  525. type: "Identifier",
  526. value: value
  527. };
  528. if (typeof raw !== "undefined") {
  529. node.raw = raw;
  530. }
  531. return node;
  532. }
  533. function blockInstruction(label, instr, result) {
  534. if (!(_typeof(instr) === "object" && typeof instr.length !== "undefined")) {
  535. throw new Error('typeof instr === "object" && typeof instr.length !== "undefined"' + " error: " + (undefined || "unknown"));
  536. }
  537. var node = {
  538. type: "BlockInstruction",
  539. id: "block",
  540. label: label,
  541. instr: instr,
  542. result: result
  543. };
  544. return node;
  545. }
  546. function callInstruction(index, instrArgs) {
  547. if (instrArgs !== null && instrArgs !== undefined) {
  548. if (!(_typeof(instrArgs) === "object" && typeof instrArgs.length !== "undefined")) {
  549. throw new Error('typeof instrArgs === "object" && typeof instrArgs.length !== "undefined"' + " error: " + (undefined || "unknown"));
  550. }
  551. }
  552. var node = {
  553. type: "CallInstruction",
  554. id: "call",
  555. index: index
  556. };
  557. if (typeof instrArgs !== "undefined" && instrArgs.length > 0) {
  558. node.instrArgs = instrArgs;
  559. }
  560. return node;
  561. }
  562. function callIndirectInstruction(signature, intrs) {
  563. if (intrs !== null && intrs !== undefined) {
  564. if (!(_typeof(intrs) === "object" && typeof intrs.length !== "undefined")) {
  565. throw new Error('typeof intrs === "object" && typeof intrs.length !== "undefined"' + " error: " + (undefined || "unknown"));
  566. }
  567. }
  568. var node = {
  569. type: "CallIndirectInstruction",
  570. id: "call_indirect",
  571. signature: signature
  572. };
  573. if (typeof intrs !== "undefined" && intrs.length > 0) {
  574. node.intrs = intrs;
  575. }
  576. return node;
  577. }
  578. function byteArray(values) {
  579. if (!(_typeof(values) === "object" && typeof values.length !== "undefined")) {
  580. throw new Error('typeof values === "object" && typeof values.length !== "undefined"' + " error: " + (undefined || "unknown"));
  581. }
  582. var node = {
  583. type: "ByteArray",
  584. values: values
  585. };
  586. return node;
  587. }
  588. function func(name, signature, body, isExternal, metadata) {
  589. if (!(_typeof(body) === "object" && typeof body.length !== "undefined")) {
  590. throw new Error('typeof body === "object" && typeof body.length !== "undefined"' + " error: " + (undefined || "unknown"));
  591. }
  592. if (isExternal !== null && isExternal !== undefined) {
  593. if (!(typeof isExternal === "boolean")) {
  594. throw new Error('typeof isExternal === "boolean"' + " error: " + (undefined || "unknown"));
  595. }
  596. }
  597. var node = {
  598. type: "Func",
  599. name: name,
  600. signature: signature,
  601. body: body
  602. };
  603. if (isExternal === true) {
  604. node.isExternal = true;
  605. }
  606. if (typeof metadata !== "undefined") {
  607. node.metadata = metadata;
  608. }
  609. return node;
  610. }
  611. var isModule = isTypeOf("Module");
  612. exports.isModule = isModule;
  613. var isModuleMetadata = isTypeOf("ModuleMetadata");
  614. exports.isModuleMetadata = isModuleMetadata;
  615. var isModuleNameMetadata = isTypeOf("ModuleNameMetadata");
  616. exports.isModuleNameMetadata = isModuleNameMetadata;
  617. var isFunctionNameMetadata = isTypeOf("FunctionNameMetadata");
  618. exports.isFunctionNameMetadata = isFunctionNameMetadata;
  619. var isLocalNameMetadata = isTypeOf("LocalNameMetadata");
  620. exports.isLocalNameMetadata = isLocalNameMetadata;
  621. var isBinaryModule = isTypeOf("BinaryModule");
  622. exports.isBinaryModule = isBinaryModule;
  623. var isQuoteModule = isTypeOf("QuoteModule");
  624. exports.isQuoteModule = isQuoteModule;
  625. var isSectionMetadata = isTypeOf("SectionMetadata");
  626. exports.isSectionMetadata = isSectionMetadata;
  627. var isLoopInstruction = isTypeOf("LoopInstruction");
  628. exports.isLoopInstruction = isLoopInstruction;
  629. var isInstr = isTypeOf("Instr");
  630. exports.isInstr = isInstr;
  631. var isIfInstruction = isTypeOf("IfInstruction");
  632. exports.isIfInstruction = isIfInstruction;
  633. var isStringLiteral = isTypeOf("StringLiteral");
  634. exports.isStringLiteral = isStringLiteral;
  635. var isNumberLiteral = isTypeOf("NumberLiteral");
  636. exports.isNumberLiteral = isNumberLiteral;
  637. var isLongNumberLiteral = isTypeOf("LongNumberLiteral");
  638. exports.isLongNumberLiteral = isLongNumberLiteral;
  639. var isFloatLiteral = isTypeOf("FloatLiteral");
  640. exports.isFloatLiteral = isFloatLiteral;
  641. var isElem = isTypeOf("Elem");
  642. exports.isElem = isElem;
  643. var isIndexInFuncSection = isTypeOf("IndexInFuncSection");
  644. exports.isIndexInFuncSection = isIndexInFuncSection;
  645. var isValtypeLiteral = isTypeOf("ValtypeLiteral");
  646. exports.isValtypeLiteral = isValtypeLiteral;
  647. var isTypeInstruction = isTypeOf("TypeInstruction");
  648. exports.isTypeInstruction = isTypeInstruction;
  649. var isStart = isTypeOf("Start");
  650. exports.isStart = isStart;
  651. var isGlobalType = isTypeOf("GlobalType");
  652. exports.isGlobalType = isGlobalType;
  653. var isLeadingComment = isTypeOf("LeadingComment");
  654. exports.isLeadingComment = isLeadingComment;
  655. var isBlockComment = isTypeOf("BlockComment");
  656. exports.isBlockComment = isBlockComment;
  657. var isData = isTypeOf("Data");
  658. exports.isData = isData;
  659. var isGlobal = isTypeOf("Global");
  660. exports.isGlobal = isGlobal;
  661. var isTable = isTypeOf("Table");
  662. exports.isTable = isTable;
  663. var isMemory = isTypeOf("Memory");
  664. exports.isMemory = isMemory;
  665. var isFuncImportDescr = isTypeOf("FuncImportDescr");
  666. exports.isFuncImportDescr = isFuncImportDescr;
  667. var isModuleImport = isTypeOf("ModuleImport");
  668. exports.isModuleImport = isModuleImport;
  669. var isModuleExportDescr = isTypeOf("ModuleExportDescr");
  670. exports.isModuleExportDescr = isModuleExportDescr;
  671. var isModuleExport = isTypeOf("ModuleExport");
  672. exports.isModuleExport = isModuleExport;
  673. var isLimit = isTypeOf("Limit");
  674. exports.isLimit = isLimit;
  675. var isSignature = isTypeOf("Signature");
  676. exports.isSignature = isSignature;
  677. var isProgram = isTypeOf("Program");
  678. exports.isProgram = isProgram;
  679. var isIdentifier = isTypeOf("Identifier");
  680. exports.isIdentifier = isIdentifier;
  681. var isBlockInstruction = isTypeOf("BlockInstruction");
  682. exports.isBlockInstruction = isBlockInstruction;
  683. var isCallInstruction = isTypeOf("CallInstruction");
  684. exports.isCallInstruction = isCallInstruction;
  685. var isCallIndirectInstruction = isTypeOf("CallIndirectInstruction");
  686. exports.isCallIndirectInstruction = isCallIndirectInstruction;
  687. var isByteArray = isTypeOf("ByteArray");
  688. exports.isByteArray = isByteArray;
  689. var isFunc = isTypeOf("Func");
  690. exports.isFunc = isFunc;
  691. var isNode = function isNode(node) {
  692. return isModule(node) || isModuleMetadata(node) || isModuleNameMetadata(node) || isFunctionNameMetadata(node) || isLocalNameMetadata(node) || isBinaryModule(node) || isQuoteModule(node) || isSectionMetadata(node) || isLoopInstruction(node) || isInstr(node) || isIfInstruction(node) || isStringLiteral(node) || isNumberLiteral(node) || isLongNumberLiteral(node) || isFloatLiteral(node) || isElem(node) || isIndexInFuncSection(node) || isValtypeLiteral(node) || isTypeInstruction(node) || isStart(node) || isGlobalType(node) || isLeadingComment(node) || isBlockComment(node) || isData(node) || isGlobal(node) || isTable(node) || isMemory(node) || isFuncImportDescr(node) || isModuleImport(node) || isModuleExportDescr(node) || isModuleExport(node) || isLimit(node) || isSignature(node) || isProgram(node) || isIdentifier(node) || isBlockInstruction(node) || isCallInstruction(node) || isCallIndirectInstruction(node) || isByteArray(node) || isFunc(node);
  693. };
  694. exports.isNode = isNode;
  695. var isBlock = function isBlock(node) {
  696. return isLoopInstruction(node) || isBlockInstruction(node) || isFunc(node);
  697. };
  698. exports.isBlock = isBlock;
  699. var isInstruction = function isInstruction(node) {
  700. return isLoopInstruction(node) || isInstr(node) || isIfInstruction(node) || isTypeInstruction(node) || isBlockInstruction(node) || isCallInstruction(node) || isCallIndirectInstruction(node);
  701. };
  702. exports.isInstruction = isInstruction;
  703. var isExpression = function isExpression(node) {
  704. return isInstr(node) || isStringLiteral(node) || isNumberLiteral(node) || isLongNumberLiteral(node) || isFloatLiteral(node) || isValtypeLiteral(node) || isIdentifier(node);
  705. };
  706. exports.isExpression = isExpression;
  707. var isNumericLiteral = function isNumericLiteral(node) {
  708. return isNumberLiteral(node) || isLongNumberLiteral(node) || isFloatLiteral(node);
  709. };
  710. exports.isNumericLiteral = isNumericLiteral;
  711. var isImportDescr = function isImportDescr(node) {
  712. return isGlobalType(node) || isTable(node) || isMemory(node) || isFuncImportDescr(node);
  713. };
  714. exports.isImportDescr = isImportDescr;
  715. var assertModule = assertTypeOf("Module");
  716. exports.assertModule = assertModule;
  717. var assertModuleMetadata = assertTypeOf("ModuleMetadata");
  718. exports.assertModuleMetadata = assertModuleMetadata;
  719. var assertModuleNameMetadata = assertTypeOf("ModuleNameMetadata");
  720. exports.assertModuleNameMetadata = assertModuleNameMetadata;
  721. var assertFunctionNameMetadata = assertTypeOf("FunctionNameMetadata");
  722. exports.assertFunctionNameMetadata = assertFunctionNameMetadata;
  723. var assertLocalNameMetadata = assertTypeOf("LocalNameMetadata");
  724. exports.assertLocalNameMetadata = assertLocalNameMetadata;
  725. var assertBinaryModule = assertTypeOf("BinaryModule");
  726. exports.assertBinaryModule = assertBinaryModule;
  727. var assertQuoteModule = assertTypeOf("QuoteModule");
  728. exports.assertQuoteModule = assertQuoteModule;
  729. var assertSectionMetadata = assertTypeOf("SectionMetadata");
  730. exports.assertSectionMetadata = assertSectionMetadata;
  731. var assertLoopInstruction = assertTypeOf("LoopInstruction");
  732. exports.assertLoopInstruction = assertLoopInstruction;
  733. var assertInstr = assertTypeOf("Instr");
  734. exports.assertInstr = assertInstr;
  735. var assertIfInstruction = assertTypeOf("IfInstruction");
  736. exports.assertIfInstruction = assertIfInstruction;
  737. var assertStringLiteral = assertTypeOf("StringLiteral");
  738. exports.assertStringLiteral = assertStringLiteral;
  739. var assertNumberLiteral = assertTypeOf("NumberLiteral");
  740. exports.assertNumberLiteral = assertNumberLiteral;
  741. var assertLongNumberLiteral = assertTypeOf("LongNumberLiteral");
  742. exports.assertLongNumberLiteral = assertLongNumberLiteral;
  743. var assertFloatLiteral = assertTypeOf("FloatLiteral");
  744. exports.assertFloatLiteral = assertFloatLiteral;
  745. var assertElem = assertTypeOf("Elem");
  746. exports.assertElem = assertElem;
  747. var assertIndexInFuncSection = assertTypeOf("IndexInFuncSection");
  748. exports.assertIndexInFuncSection = assertIndexInFuncSection;
  749. var assertValtypeLiteral = assertTypeOf("ValtypeLiteral");
  750. exports.assertValtypeLiteral = assertValtypeLiteral;
  751. var assertTypeInstruction = assertTypeOf("TypeInstruction");
  752. exports.assertTypeInstruction = assertTypeInstruction;
  753. var assertStart = assertTypeOf("Start");
  754. exports.assertStart = assertStart;
  755. var assertGlobalType = assertTypeOf("GlobalType");
  756. exports.assertGlobalType = assertGlobalType;
  757. var assertLeadingComment = assertTypeOf("LeadingComment");
  758. exports.assertLeadingComment = assertLeadingComment;
  759. var assertBlockComment = assertTypeOf("BlockComment");
  760. exports.assertBlockComment = assertBlockComment;
  761. var assertData = assertTypeOf("Data");
  762. exports.assertData = assertData;
  763. var assertGlobal = assertTypeOf("Global");
  764. exports.assertGlobal = assertGlobal;
  765. var assertTable = assertTypeOf("Table");
  766. exports.assertTable = assertTable;
  767. var assertMemory = assertTypeOf("Memory");
  768. exports.assertMemory = assertMemory;
  769. var assertFuncImportDescr = assertTypeOf("FuncImportDescr");
  770. exports.assertFuncImportDescr = assertFuncImportDescr;
  771. var assertModuleImport = assertTypeOf("ModuleImport");
  772. exports.assertModuleImport = assertModuleImport;
  773. var assertModuleExportDescr = assertTypeOf("ModuleExportDescr");
  774. exports.assertModuleExportDescr = assertModuleExportDescr;
  775. var assertModuleExport = assertTypeOf("ModuleExport");
  776. exports.assertModuleExport = assertModuleExport;
  777. var assertLimit = assertTypeOf("Limit");
  778. exports.assertLimit = assertLimit;
  779. var assertSignature = assertTypeOf("Signature");
  780. exports.assertSignature = assertSignature;
  781. var assertProgram = assertTypeOf("Program");
  782. exports.assertProgram = assertProgram;
  783. var assertIdentifier = assertTypeOf("Identifier");
  784. exports.assertIdentifier = assertIdentifier;
  785. var assertBlockInstruction = assertTypeOf("BlockInstruction");
  786. exports.assertBlockInstruction = assertBlockInstruction;
  787. var assertCallInstruction = assertTypeOf("CallInstruction");
  788. exports.assertCallInstruction = assertCallInstruction;
  789. var assertCallIndirectInstruction = assertTypeOf("CallIndirectInstruction");
  790. exports.assertCallIndirectInstruction = assertCallIndirectInstruction;
  791. var assertByteArray = assertTypeOf("ByteArray");
  792. exports.assertByteArray = assertByteArray;
  793. var assertFunc = assertTypeOf("Func");
  794. exports.assertFunc = assertFunc;
  795. var unionTypesMap = {
  796. Module: ["Node"],
  797. ModuleMetadata: ["Node"],
  798. ModuleNameMetadata: ["Node"],
  799. FunctionNameMetadata: ["Node"],
  800. LocalNameMetadata: ["Node"],
  801. BinaryModule: ["Node"],
  802. QuoteModule: ["Node"],
  803. SectionMetadata: ["Node"],
  804. LoopInstruction: ["Node", "Block", "Instruction"],
  805. Instr: ["Node", "Expression", "Instruction"],
  806. IfInstruction: ["Node", "Instruction"],
  807. StringLiteral: ["Node", "Expression"],
  808. NumberLiteral: ["Node", "NumericLiteral", "Expression"],
  809. LongNumberLiteral: ["Node", "NumericLiteral", "Expression"],
  810. FloatLiteral: ["Node", "NumericLiteral", "Expression"],
  811. Elem: ["Node"],
  812. IndexInFuncSection: ["Node"],
  813. ValtypeLiteral: ["Node", "Expression"],
  814. TypeInstruction: ["Node", "Instruction"],
  815. Start: ["Node"],
  816. GlobalType: ["Node", "ImportDescr"],
  817. LeadingComment: ["Node"],
  818. BlockComment: ["Node"],
  819. Data: ["Node"],
  820. Global: ["Node"],
  821. Table: ["Node", "ImportDescr"],
  822. Memory: ["Node", "ImportDescr"],
  823. FuncImportDescr: ["Node", "ImportDescr"],
  824. ModuleImport: ["Node"],
  825. ModuleExportDescr: ["Node"],
  826. ModuleExport: ["Node"],
  827. Limit: ["Node"],
  828. Signature: ["Node"],
  829. Program: ["Node"],
  830. Identifier: ["Node", "Expression"],
  831. BlockInstruction: ["Node", "Block", "Instruction"],
  832. CallInstruction: ["Node", "Instruction"],
  833. CallIndirectInstruction: ["Node", "Instruction"],
  834. ByteArray: ["Node"],
  835. Func: ["Node", "Block"]
  836. };
  837. exports.unionTypesMap = unionTypesMap;
  838. var nodeAndUnionTypes = ["Module", "ModuleMetadata", "ModuleNameMetadata", "FunctionNameMetadata", "LocalNameMetadata", "BinaryModule", "QuoteModule", "SectionMetadata", "LoopInstruction", "Instr", "IfInstruction", "StringLiteral", "NumberLiteral", "LongNumberLiteral", "FloatLiteral", "Elem", "IndexInFuncSection", "ValtypeLiteral", "TypeInstruction", "Start", "GlobalType", "LeadingComment", "BlockComment", "Data", "Global", "Table", "Memory", "FuncImportDescr", "ModuleImport", "ModuleExportDescr", "ModuleExport", "Limit", "Signature", "Program", "Identifier", "BlockInstruction", "CallInstruction", "CallIndirectInstruction", "ByteArray", "Func", "Node", "Block", "Instruction", "Expression", "NumericLiteral", "ImportDescr"];
  839. exports.nodeAndUnionTypes = nodeAndUnionTypes;