nodes.js 34 KB

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