nodes.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925
  1. function _typeof(obj) { "@babel/helpers - typeof"; 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, shared) {
  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. if (shared !== null && shared !== undefined) {
  492. if (!(typeof shared === "boolean")) {
  493. throw new Error('typeof shared === "boolean"' + " error: " + ("Argument shared must be of type boolean, given: " + _typeof(shared) || "unknown"));
  494. }
  495. }
  496. var node = {
  497. type: "Limit",
  498. min: min
  499. };
  500. if (typeof max !== "undefined") {
  501. node.max = max;
  502. }
  503. if (shared === true) {
  504. node.shared = true;
  505. }
  506. return node;
  507. }
  508. export function signature(params, results) {
  509. if (!(_typeof(params) === "object" && typeof params.length !== "undefined")) {
  510. throw new Error('typeof params === "object" && typeof params.length !== "undefined"' + " error: " + (undefined || "unknown"));
  511. }
  512. if (!(_typeof(results) === "object" && typeof results.length !== "undefined")) {
  513. throw new Error('typeof results === "object" && typeof results.length !== "undefined"' + " error: " + (undefined || "unknown"));
  514. }
  515. var node = {
  516. type: "Signature",
  517. params: params,
  518. results: results
  519. };
  520. return node;
  521. }
  522. export function program(body) {
  523. if (!(_typeof(body) === "object" && typeof body.length !== "undefined")) {
  524. throw new Error('typeof body === "object" && typeof body.length !== "undefined"' + " error: " + (undefined || "unknown"));
  525. }
  526. var node = {
  527. type: "Program",
  528. body: body
  529. };
  530. return node;
  531. }
  532. export function identifier(value, raw) {
  533. if (!(typeof value === "string")) {
  534. throw new Error('typeof value === "string"' + " error: " + ("Argument value must be of type string, given: " + _typeof(value) || "unknown"));
  535. }
  536. if (raw !== null && raw !== undefined) {
  537. if (!(typeof raw === "string")) {
  538. throw new Error('typeof raw === "string"' + " error: " + ("Argument raw must be of type string, given: " + _typeof(raw) || "unknown"));
  539. }
  540. }
  541. var node = {
  542. type: "Identifier",
  543. value: value
  544. };
  545. if (typeof raw !== "undefined") {
  546. node.raw = raw;
  547. }
  548. return node;
  549. }
  550. export function blockInstruction(label, instr, result) {
  551. if (!(_typeof(instr) === "object" && typeof instr.length !== "undefined")) {
  552. throw new Error('typeof instr === "object" && typeof instr.length !== "undefined"' + " error: " + (undefined || "unknown"));
  553. }
  554. var node = {
  555. type: "BlockInstruction",
  556. id: "block",
  557. label: label,
  558. instr: instr,
  559. result: result
  560. };
  561. return node;
  562. }
  563. export function callInstruction(index, instrArgs, numeric) {
  564. if (instrArgs !== null && instrArgs !== undefined) {
  565. if (!(_typeof(instrArgs) === "object" && typeof instrArgs.length !== "undefined")) {
  566. throw new Error('typeof instrArgs === "object" && typeof instrArgs.length !== "undefined"' + " error: " + (undefined || "unknown"));
  567. }
  568. }
  569. var node = {
  570. type: "CallInstruction",
  571. id: "call",
  572. index: index
  573. };
  574. if (typeof instrArgs !== "undefined" && instrArgs.length > 0) {
  575. node.instrArgs = instrArgs;
  576. }
  577. if (typeof numeric !== "undefined") {
  578. node.numeric = numeric;
  579. }
  580. return node;
  581. }
  582. export function callIndirectInstruction(signature, intrs) {
  583. if (intrs !== null && intrs !== undefined) {
  584. if (!(_typeof(intrs) === "object" && typeof intrs.length !== "undefined")) {
  585. throw new Error('typeof intrs === "object" && typeof intrs.length !== "undefined"' + " error: " + (undefined || "unknown"));
  586. }
  587. }
  588. var node = {
  589. type: "CallIndirectInstruction",
  590. id: "call_indirect",
  591. signature: signature
  592. };
  593. if (typeof intrs !== "undefined" && intrs.length > 0) {
  594. node.intrs = intrs;
  595. }
  596. return node;
  597. }
  598. export function byteArray(values) {
  599. if (!(_typeof(values) === "object" && typeof values.length !== "undefined")) {
  600. throw new Error('typeof values === "object" && typeof values.length !== "undefined"' + " error: " + (undefined || "unknown"));
  601. }
  602. var node = {
  603. type: "ByteArray",
  604. values: values
  605. };
  606. return node;
  607. }
  608. export function func(name, signature, body, isExternal, metadata) {
  609. if (!(_typeof(body) === "object" && typeof body.length !== "undefined")) {
  610. throw new Error('typeof body === "object" && typeof body.length !== "undefined"' + " error: " + (undefined || "unknown"));
  611. }
  612. if (isExternal !== null && isExternal !== undefined) {
  613. if (!(typeof isExternal === "boolean")) {
  614. throw new Error('typeof isExternal === "boolean"' + " error: " + ("Argument isExternal must be of type boolean, given: " + _typeof(isExternal) || "unknown"));
  615. }
  616. }
  617. var node = {
  618. type: "Func",
  619. name: name,
  620. signature: signature,
  621. body: body
  622. };
  623. if (isExternal === true) {
  624. node.isExternal = true;
  625. }
  626. if (typeof metadata !== "undefined") {
  627. node.metadata = metadata;
  628. }
  629. return node;
  630. }
  631. export function internalBrUnless(target) {
  632. if (!(typeof target === "number")) {
  633. throw new Error('typeof target === "number"' + " error: " + ("Argument target must be of type number, given: " + _typeof(target) || "unknown"));
  634. }
  635. var node = {
  636. type: "InternalBrUnless",
  637. target: target
  638. };
  639. return node;
  640. }
  641. export function internalGoto(target) {
  642. if (!(typeof target === "number")) {
  643. throw new Error('typeof target === "number"' + " error: " + ("Argument target must be of type number, given: " + _typeof(target) || "unknown"));
  644. }
  645. var node = {
  646. type: "InternalGoto",
  647. target: target
  648. };
  649. return node;
  650. }
  651. export function internalCallExtern(target) {
  652. if (!(typeof target === "number")) {
  653. throw new Error('typeof target === "number"' + " error: " + ("Argument target must be of type number, given: " + _typeof(target) || "unknown"));
  654. }
  655. var node = {
  656. type: "InternalCallExtern",
  657. target: target
  658. };
  659. return node;
  660. }
  661. export function internalEndAndReturn() {
  662. var node = {
  663. type: "InternalEndAndReturn"
  664. };
  665. return node;
  666. }
  667. export var isModule = isTypeOf("Module");
  668. export var isModuleMetadata = isTypeOf("ModuleMetadata");
  669. export var isModuleNameMetadata = isTypeOf("ModuleNameMetadata");
  670. export var isFunctionNameMetadata = isTypeOf("FunctionNameMetadata");
  671. export var isLocalNameMetadata = isTypeOf("LocalNameMetadata");
  672. export var isBinaryModule = isTypeOf("BinaryModule");
  673. export var isQuoteModule = isTypeOf("QuoteModule");
  674. export var isSectionMetadata = isTypeOf("SectionMetadata");
  675. export var isProducersSectionMetadata = isTypeOf("ProducersSectionMetadata");
  676. export var isProducerMetadata = isTypeOf("ProducerMetadata");
  677. export var isProducerMetadataVersionedName = isTypeOf("ProducerMetadataVersionedName");
  678. export var isLoopInstruction = isTypeOf("LoopInstruction");
  679. export var isInstr = isTypeOf("Instr");
  680. export var isIfInstruction = isTypeOf("IfInstruction");
  681. export var isStringLiteral = isTypeOf("StringLiteral");
  682. export var isNumberLiteral = isTypeOf("NumberLiteral");
  683. export var isLongNumberLiteral = isTypeOf("LongNumberLiteral");
  684. export var isFloatLiteral = isTypeOf("FloatLiteral");
  685. export var isElem = isTypeOf("Elem");
  686. export var isIndexInFuncSection = isTypeOf("IndexInFuncSection");
  687. export var isValtypeLiteral = isTypeOf("ValtypeLiteral");
  688. export var isTypeInstruction = isTypeOf("TypeInstruction");
  689. export var isStart = isTypeOf("Start");
  690. export var isGlobalType = isTypeOf("GlobalType");
  691. export var isLeadingComment = isTypeOf("LeadingComment");
  692. export var isBlockComment = isTypeOf("BlockComment");
  693. export var isData = isTypeOf("Data");
  694. export var isGlobal = isTypeOf("Global");
  695. export var isTable = isTypeOf("Table");
  696. export var isMemory = isTypeOf("Memory");
  697. export var isFuncImportDescr = isTypeOf("FuncImportDescr");
  698. export var isModuleImport = isTypeOf("ModuleImport");
  699. export var isModuleExportDescr = isTypeOf("ModuleExportDescr");
  700. export var isModuleExport = isTypeOf("ModuleExport");
  701. export var isLimit = isTypeOf("Limit");
  702. export var isSignature = isTypeOf("Signature");
  703. export var isProgram = isTypeOf("Program");
  704. export var isIdentifier = isTypeOf("Identifier");
  705. export var isBlockInstruction = isTypeOf("BlockInstruction");
  706. export var isCallInstruction = isTypeOf("CallInstruction");
  707. export var isCallIndirectInstruction = isTypeOf("CallIndirectInstruction");
  708. export var isByteArray = isTypeOf("ByteArray");
  709. export var isFunc = isTypeOf("Func");
  710. export var isInternalBrUnless = isTypeOf("InternalBrUnless");
  711. export var isInternalGoto = isTypeOf("InternalGoto");
  712. export var isInternalCallExtern = isTypeOf("InternalCallExtern");
  713. export var isInternalEndAndReturn = isTypeOf("InternalEndAndReturn");
  714. export var isNode = function isNode(node) {
  715. 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);
  716. };
  717. export var isBlock = function isBlock(node) {
  718. return isLoopInstruction(node) || isBlockInstruction(node) || isFunc(node);
  719. };
  720. export var isInstruction = function isInstruction(node) {
  721. return isLoopInstruction(node) || isInstr(node) || isIfInstruction(node) || isTypeInstruction(node) || isBlockInstruction(node) || isCallInstruction(node) || isCallIndirectInstruction(node);
  722. };
  723. export var isExpression = function isExpression(node) {
  724. return isInstr(node) || isStringLiteral(node) || isNumberLiteral(node) || isLongNumberLiteral(node) || isFloatLiteral(node) || isValtypeLiteral(node) || isIdentifier(node);
  725. };
  726. export var isNumericLiteral = function isNumericLiteral(node) {
  727. return isNumberLiteral(node) || isLongNumberLiteral(node) || isFloatLiteral(node);
  728. };
  729. export var isImportDescr = function isImportDescr(node) {
  730. return isGlobalType(node) || isTable(node) || isMemory(node) || isFuncImportDescr(node);
  731. };
  732. export var isIntrinsic = function isIntrinsic(node) {
  733. return isInternalBrUnless(node) || isInternalGoto(node) || isInternalCallExtern(node) || isInternalEndAndReturn(node);
  734. };
  735. export var assertModule = assertTypeOf("Module");
  736. export var assertModuleMetadata = assertTypeOf("ModuleMetadata");
  737. export var assertModuleNameMetadata = assertTypeOf("ModuleNameMetadata");
  738. export var assertFunctionNameMetadata = assertTypeOf("FunctionNameMetadata");
  739. export var assertLocalNameMetadata = assertTypeOf("LocalNameMetadata");
  740. export var assertBinaryModule = assertTypeOf("BinaryModule");
  741. export var assertQuoteModule = assertTypeOf("QuoteModule");
  742. export var assertSectionMetadata = assertTypeOf("SectionMetadata");
  743. export var assertProducersSectionMetadata = assertTypeOf("ProducersSectionMetadata");
  744. export var assertProducerMetadata = assertTypeOf("ProducerMetadata");
  745. export var assertProducerMetadataVersionedName = assertTypeOf("ProducerMetadataVersionedName");
  746. export var assertLoopInstruction = assertTypeOf("LoopInstruction");
  747. export var assertInstr = assertTypeOf("Instr");
  748. export var assertIfInstruction = assertTypeOf("IfInstruction");
  749. export var assertStringLiteral = assertTypeOf("StringLiteral");
  750. export var assertNumberLiteral = assertTypeOf("NumberLiteral");
  751. export var assertLongNumberLiteral = assertTypeOf("LongNumberLiteral");
  752. export var assertFloatLiteral = assertTypeOf("FloatLiteral");
  753. export var assertElem = assertTypeOf("Elem");
  754. export var assertIndexInFuncSection = assertTypeOf("IndexInFuncSection");
  755. export var assertValtypeLiteral = assertTypeOf("ValtypeLiteral");
  756. export var assertTypeInstruction = assertTypeOf("TypeInstruction");
  757. export var assertStart = assertTypeOf("Start");
  758. export var assertGlobalType = assertTypeOf("GlobalType");
  759. export var assertLeadingComment = assertTypeOf("LeadingComment");
  760. export var assertBlockComment = assertTypeOf("BlockComment");
  761. export var assertData = assertTypeOf("Data");
  762. export var assertGlobal = assertTypeOf("Global");
  763. export var assertTable = assertTypeOf("Table");
  764. export var assertMemory = assertTypeOf("Memory");
  765. export var assertFuncImportDescr = assertTypeOf("FuncImportDescr");
  766. export var assertModuleImport = assertTypeOf("ModuleImport");
  767. export var assertModuleExportDescr = assertTypeOf("ModuleExportDescr");
  768. export var assertModuleExport = assertTypeOf("ModuleExport");
  769. export var assertLimit = assertTypeOf("Limit");
  770. export var assertSignature = assertTypeOf("Signature");
  771. export var assertProgram = assertTypeOf("Program");
  772. export var assertIdentifier = assertTypeOf("Identifier");
  773. export var assertBlockInstruction = assertTypeOf("BlockInstruction");
  774. export var assertCallInstruction = assertTypeOf("CallInstruction");
  775. export var assertCallIndirectInstruction = assertTypeOf("CallIndirectInstruction");
  776. export var assertByteArray = assertTypeOf("ByteArray");
  777. export var assertFunc = assertTypeOf("Func");
  778. export var assertInternalBrUnless = assertTypeOf("InternalBrUnless");
  779. export var assertInternalGoto = assertTypeOf("InternalGoto");
  780. export var assertInternalCallExtern = assertTypeOf("InternalCallExtern");
  781. export var assertInternalEndAndReturn = assertTypeOf("InternalEndAndReturn");
  782. export var unionTypesMap = {
  783. Module: ["Node"],
  784. ModuleMetadata: ["Node"],
  785. ModuleNameMetadata: ["Node"],
  786. FunctionNameMetadata: ["Node"],
  787. LocalNameMetadata: ["Node"],
  788. BinaryModule: ["Node"],
  789. QuoteModule: ["Node"],
  790. SectionMetadata: ["Node"],
  791. ProducersSectionMetadata: ["Node"],
  792. ProducerMetadata: ["Node"],
  793. ProducerMetadataVersionedName: ["Node"],
  794. LoopInstruction: ["Node", "Block", "Instruction"],
  795. Instr: ["Node", "Expression", "Instruction"],
  796. IfInstruction: ["Node", "Instruction"],
  797. StringLiteral: ["Node", "Expression"],
  798. NumberLiteral: ["Node", "NumericLiteral", "Expression"],
  799. LongNumberLiteral: ["Node", "NumericLiteral", "Expression"],
  800. FloatLiteral: ["Node", "NumericLiteral", "Expression"],
  801. Elem: ["Node"],
  802. IndexInFuncSection: ["Node"],
  803. ValtypeLiteral: ["Node", "Expression"],
  804. TypeInstruction: ["Node", "Instruction"],
  805. Start: ["Node"],
  806. GlobalType: ["Node", "ImportDescr"],
  807. LeadingComment: ["Node"],
  808. BlockComment: ["Node"],
  809. Data: ["Node"],
  810. Global: ["Node"],
  811. Table: ["Node", "ImportDescr"],
  812. Memory: ["Node", "ImportDescr"],
  813. FuncImportDescr: ["Node", "ImportDescr"],
  814. ModuleImport: ["Node"],
  815. ModuleExportDescr: ["Node"],
  816. ModuleExport: ["Node"],
  817. Limit: ["Node"],
  818. Signature: ["Node"],
  819. Program: ["Node"],
  820. Identifier: ["Node", "Expression"],
  821. BlockInstruction: ["Node", "Block", "Instruction"],
  822. CallInstruction: ["Node", "Instruction"],
  823. CallIndirectInstruction: ["Node", "Instruction"],
  824. ByteArray: ["Node"],
  825. Func: ["Node", "Block"],
  826. InternalBrUnless: ["Node", "Intrinsic"],
  827. InternalGoto: ["Node", "Intrinsic"],
  828. InternalCallExtern: ["Node", "Intrinsic"],
  829. InternalEndAndReturn: ["Node", "Intrinsic"]
  830. };
  831. 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"];