Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

definitions.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. var definitions = {};
  2. function defineType(typeName, metadata) {
  3. definitions[typeName] = metadata;
  4. }
  5. defineType("Module", {
  6. spec: {
  7. wasm: "https://webassembly.github.io/spec/core/binary/modules.html#binary-module",
  8. wat: "https://webassembly.github.io/spec/core/text/modules.html#text-module"
  9. },
  10. doc: "A module consists of a sequence of sections (termed fields in the text format).",
  11. unionType: ["Node"],
  12. fields: {
  13. id: {
  14. maybe: true,
  15. type: "string"
  16. },
  17. fields: {
  18. array: true,
  19. type: "Node"
  20. },
  21. metadata: {
  22. optional: true,
  23. type: "ModuleMetadata"
  24. }
  25. }
  26. });
  27. defineType("ModuleMetadata", {
  28. unionType: ["Node"],
  29. fields: {
  30. sections: {
  31. array: true,
  32. type: "SectionMetadata"
  33. },
  34. functionNames: {
  35. optional: true,
  36. array: true,
  37. type: "FunctionNameMetadata"
  38. },
  39. localNames: {
  40. optional: true,
  41. array: true,
  42. type: "ModuleMetadata"
  43. },
  44. producers: {
  45. optional: true,
  46. array: true,
  47. type: "ProducersSectionMetadata"
  48. }
  49. }
  50. });
  51. defineType("ModuleNameMetadata", {
  52. unionType: ["Node"],
  53. fields: {
  54. value: {
  55. type: "string"
  56. }
  57. }
  58. });
  59. defineType("FunctionNameMetadata", {
  60. unionType: ["Node"],
  61. fields: {
  62. value: {
  63. type: "string"
  64. },
  65. index: {
  66. type: "number"
  67. }
  68. }
  69. });
  70. defineType("LocalNameMetadata", {
  71. unionType: ["Node"],
  72. fields: {
  73. value: {
  74. type: "string"
  75. },
  76. localIndex: {
  77. type: "number"
  78. },
  79. functionIndex: {
  80. type: "number"
  81. }
  82. }
  83. });
  84. defineType("BinaryModule", {
  85. unionType: ["Node"],
  86. fields: {
  87. id: {
  88. maybe: true,
  89. type: "string"
  90. },
  91. blob: {
  92. array: true,
  93. type: "string"
  94. }
  95. }
  96. });
  97. defineType("QuoteModule", {
  98. unionType: ["Node"],
  99. fields: {
  100. id: {
  101. maybe: true,
  102. type: "string"
  103. },
  104. string: {
  105. array: true,
  106. type: "string"
  107. }
  108. }
  109. });
  110. defineType("SectionMetadata", {
  111. unionType: ["Node"],
  112. fields: {
  113. section: {
  114. type: "SectionName"
  115. },
  116. startOffset: {
  117. type: "number"
  118. },
  119. size: {
  120. type: "NumberLiteral"
  121. },
  122. vectorOfSize: {
  123. comment: "Size of the vector in the section (if any)",
  124. type: "NumberLiteral"
  125. }
  126. }
  127. });
  128. defineType("ProducersSectionMetadata", {
  129. unionType: ["Node"],
  130. fields: {
  131. producers: {
  132. array: true,
  133. type: "ProducerMetadata"
  134. }
  135. }
  136. });
  137. defineType("ProducerMetadata", {
  138. unionType: ["Node"],
  139. fields: {
  140. language: {
  141. type: "ProducerMetadataVersionedName",
  142. array: true
  143. },
  144. processedBy: {
  145. type: "ProducerMetadataVersionedName",
  146. array: true
  147. },
  148. sdk: {
  149. type: "ProducerMetadataVersionedName",
  150. array: true
  151. }
  152. }
  153. });
  154. defineType("ProducerMetadataVersionedName", {
  155. unionType: ["Node"],
  156. fields: {
  157. name: {
  158. type: "string"
  159. },
  160. version: {
  161. type: "string"
  162. }
  163. }
  164. });
  165. /*
  166. Instructions
  167. */
  168. defineType("LoopInstruction", {
  169. unionType: ["Node", "Block", "Instruction"],
  170. fields: {
  171. id: {
  172. constant: true,
  173. type: "string",
  174. value: "loop"
  175. },
  176. label: {
  177. maybe: true,
  178. type: "Identifier"
  179. },
  180. resulttype: {
  181. maybe: true,
  182. type: "Valtype"
  183. },
  184. instr: {
  185. array: true,
  186. type: "Instruction"
  187. }
  188. }
  189. });
  190. defineType("Instr", {
  191. unionType: ["Node", "Expression", "Instruction"],
  192. fields: {
  193. id: {
  194. type: "string"
  195. },
  196. object: {
  197. optional: true,
  198. type: "Valtype"
  199. },
  200. args: {
  201. array: true,
  202. type: "Expression"
  203. },
  204. namedArgs: {
  205. optional: true,
  206. type: "Object"
  207. }
  208. }
  209. });
  210. defineType("IfInstruction", {
  211. unionType: ["Node", "Instruction"],
  212. fields: {
  213. id: {
  214. constant: true,
  215. type: "string",
  216. value: "if"
  217. },
  218. testLabel: {
  219. comment: "only for WAST",
  220. type: "Identifier"
  221. },
  222. test: {
  223. array: true,
  224. type: "Instruction"
  225. },
  226. result: {
  227. maybe: true,
  228. type: "Valtype"
  229. },
  230. consequent: {
  231. array: true,
  232. type: "Instruction"
  233. },
  234. alternate: {
  235. array: true,
  236. type: "Instruction"
  237. }
  238. }
  239. });
  240. /*
  241. Concrete value types
  242. */
  243. defineType("StringLiteral", {
  244. unionType: ["Node", "Expression"],
  245. fields: {
  246. value: {
  247. type: "string"
  248. }
  249. }
  250. });
  251. defineType("NumberLiteral", {
  252. unionType: ["Node", "NumericLiteral", "Expression"],
  253. fields: {
  254. value: {
  255. type: "number"
  256. },
  257. raw: {
  258. type: "string"
  259. }
  260. }
  261. });
  262. defineType("LongNumberLiteral", {
  263. unionType: ["Node", "NumericLiteral", "Expression"],
  264. fields: {
  265. value: {
  266. type: "LongNumber"
  267. },
  268. raw: {
  269. type: "string"
  270. }
  271. }
  272. });
  273. defineType("FloatLiteral", {
  274. unionType: ["Node", "NumericLiteral", "Expression"],
  275. fields: {
  276. value: {
  277. type: "number"
  278. },
  279. nan: {
  280. optional: true,
  281. type: "boolean"
  282. },
  283. inf: {
  284. optional: true,
  285. type: "boolean"
  286. },
  287. raw: {
  288. type: "string"
  289. }
  290. }
  291. });
  292. defineType("Elem", {
  293. unionType: ["Node"],
  294. fields: {
  295. table: {
  296. type: "Index"
  297. },
  298. offset: {
  299. array: true,
  300. type: "Instruction"
  301. },
  302. funcs: {
  303. array: true,
  304. type: "Index"
  305. }
  306. }
  307. });
  308. defineType("IndexInFuncSection", {
  309. unionType: ["Node"],
  310. fields: {
  311. index: {
  312. type: "Index"
  313. }
  314. }
  315. });
  316. defineType("ValtypeLiteral", {
  317. unionType: ["Node", "Expression"],
  318. fields: {
  319. name: {
  320. type: "Valtype"
  321. }
  322. }
  323. });
  324. defineType("TypeInstruction", {
  325. unionType: ["Node", "Instruction"],
  326. fields: {
  327. id: {
  328. maybe: true,
  329. type: "Index"
  330. },
  331. functype: {
  332. type: "Signature"
  333. }
  334. }
  335. });
  336. defineType("Start", {
  337. unionType: ["Node"],
  338. fields: {
  339. index: {
  340. type: "Index"
  341. }
  342. }
  343. });
  344. defineType("GlobalType", {
  345. unionType: ["Node", "ImportDescr"],
  346. fields: {
  347. valtype: {
  348. type: "Valtype"
  349. },
  350. mutability: {
  351. type: "Mutability"
  352. }
  353. }
  354. });
  355. defineType("LeadingComment", {
  356. unionType: ["Node"],
  357. fields: {
  358. value: {
  359. type: "string"
  360. }
  361. }
  362. });
  363. defineType("BlockComment", {
  364. unionType: ["Node"],
  365. fields: {
  366. value: {
  367. type: "string"
  368. }
  369. }
  370. });
  371. defineType("Data", {
  372. unionType: ["Node"],
  373. fields: {
  374. memoryIndex: {
  375. type: "Memidx"
  376. },
  377. offset: {
  378. type: "Instruction"
  379. },
  380. init: {
  381. type: "ByteArray"
  382. }
  383. }
  384. });
  385. defineType("Global", {
  386. unionType: ["Node"],
  387. fields: {
  388. globalType: {
  389. type: "GlobalType"
  390. },
  391. init: {
  392. array: true,
  393. type: "Instruction"
  394. },
  395. name: {
  396. maybe: true,
  397. type: "Identifier"
  398. }
  399. }
  400. });
  401. defineType("Table", {
  402. unionType: ["Node", "ImportDescr"],
  403. fields: {
  404. elementType: {
  405. type: "TableElementType"
  406. },
  407. limits: {
  408. assertNodeType: true,
  409. type: "Limit"
  410. },
  411. name: {
  412. maybe: true,
  413. type: "Identifier"
  414. },
  415. elements: {
  416. array: true,
  417. optional: true,
  418. type: "Index"
  419. }
  420. }
  421. });
  422. defineType("Memory", {
  423. unionType: ["Node", "ImportDescr"],
  424. fields: {
  425. limits: {
  426. type: "Limit"
  427. },
  428. id: {
  429. maybe: true,
  430. type: "Index"
  431. }
  432. }
  433. });
  434. defineType("FuncImportDescr", {
  435. unionType: ["Node", "ImportDescr"],
  436. fields: {
  437. id: {
  438. type: "Identifier"
  439. },
  440. signature: {
  441. type: "Signature"
  442. }
  443. }
  444. });
  445. defineType("ModuleImport", {
  446. unionType: ["Node"],
  447. fields: {
  448. module: {
  449. type: "string"
  450. },
  451. name: {
  452. type: "string"
  453. },
  454. descr: {
  455. type: "ImportDescr"
  456. }
  457. }
  458. });
  459. defineType("ModuleExportDescr", {
  460. unionType: ["Node"],
  461. fields: {
  462. exportType: {
  463. type: "ExportDescrType"
  464. },
  465. id: {
  466. type: "Index"
  467. }
  468. }
  469. });
  470. defineType("ModuleExport", {
  471. unionType: ["Node"],
  472. fields: {
  473. name: {
  474. type: "string"
  475. },
  476. descr: {
  477. type: "ModuleExportDescr"
  478. }
  479. }
  480. });
  481. defineType("Limit", {
  482. unionType: ["Node"],
  483. fields: {
  484. min: {
  485. type: "number"
  486. },
  487. max: {
  488. optional: true,
  489. type: "number"
  490. }
  491. }
  492. });
  493. defineType("Signature", {
  494. unionType: ["Node"],
  495. fields: {
  496. params: {
  497. array: true,
  498. type: "FuncParam"
  499. },
  500. results: {
  501. array: true,
  502. type: "Valtype"
  503. }
  504. }
  505. });
  506. defineType("Program", {
  507. unionType: ["Node"],
  508. fields: {
  509. body: {
  510. array: true,
  511. type: "Node"
  512. }
  513. }
  514. });
  515. defineType("Identifier", {
  516. unionType: ["Node", "Expression"],
  517. fields: {
  518. value: {
  519. type: "string"
  520. },
  521. raw: {
  522. optional: true,
  523. type: "string"
  524. }
  525. }
  526. });
  527. defineType("BlockInstruction", {
  528. unionType: ["Node", "Block", "Instruction"],
  529. fields: {
  530. id: {
  531. constant: true,
  532. type: "string",
  533. value: "block"
  534. },
  535. label: {
  536. maybe: true,
  537. type: "Identifier"
  538. },
  539. instr: {
  540. array: true,
  541. type: "Instruction"
  542. },
  543. result: {
  544. maybe: true,
  545. type: "Valtype"
  546. }
  547. }
  548. });
  549. defineType("CallInstruction", {
  550. unionType: ["Node", "Instruction"],
  551. fields: {
  552. id: {
  553. constant: true,
  554. type: "string",
  555. value: "call"
  556. },
  557. index: {
  558. type: "Index"
  559. },
  560. instrArgs: {
  561. array: true,
  562. optional: true,
  563. type: "Expression"
  564. },
  565. numeric: {
  566. type: "Index",
  567. optional: true
  568. }
  569. }
  570. });
  571. defineType("CallIndirectInstruction", {
  572. unionType: ["Node", "Instruction"],
  573. fields: {
  574. id: {
  575. constant: true,
  576. type: "string",
  577. value: "call_indirect"
  578. },
  579. signature: {
  580. type: "SignatureOrTypeRef"
  581. },
  582. intrs: {
  583. array: true,
  584. optional: true,
  585. type: "Expression"
  586. }
  587. }
  588. });
  589. defineType("ByteArray", {
  590. unionType: ["Node"],
  591. fields: {
  592. values: {
  593. array: true,
  594. type: "Byte"
  595. }
  596. }
  597. });
  598. defineType("Func", {
  599. unionType: ["Node", "Block"],
  600. fields: {
  601. name: {
  602. maybe: true,
  603. type: "Index"
  604. },
  605. signature: {
  606. type: "SignatureOrTypeRef"
  607. },
  608. body: {
  609. array: true,
  610. type: "Instruction"
  611. },
  612. isExternal: {
  613. comment: "means that it has been imported from the outside js",
  614. optional: true,
  615. type: "boolean"
  616. },
  617. metadata: {
  618. optional: true,
  619. type: "FuncMetadata"
  620. }
  621. }
  622. });
  623. /**
  624. * Intrinsics
  625. */
  626. defineType("InternalBrUnless", {
  627. unionType: ["Node", "Intrinsic"],
  628. fields: {
  629. target: {
  630. type: "number"
  631. }
  632. }
  633. });
  634. defineType("InternalGoto", {
  635. unionType: ["Node", "Intrinsic"],
  636. fields: {
  637. target: {
  638. type: "number"
  639. }
  640. }
  641. });
  642. defineType("InternalCallExtern", {
  643. unionType: ["Node", "Intrinsic"],
  644. fields: {
  645. target: {
  646. type: "number"
  647. }
  648. }
  649. }); // function bodies are terminated by an `end` instruction but are missing a
  650. // return instruction
  651. //
  652. // Since we can't inject a new instruction we are injecting a new instruction.
  653. defineType("InternalEndAndReturn", {
  654. unionType: ["Node", "Intrinsic"],
  655. fields: {}
  656. });
  657. module.exports = definitions;