nodes.js 33 KB

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