Printer.cpp 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  1. /*
  2. * Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/HashMap.h>
  7. #include <AK/TemporaryChange.h>
  8. #include <LibWasm/AbstractMachine/AbstractMachine.h>
  9. #include <LibWasm/Printer/Printer.h>
  10. namespace Wasm {
  11. struct Names {
  12. static HashMap<OpCode, String> instruction_names;
  13. static HashMap<String, OpCode> instructions_by_name;
  14. };
  15. String instruction_name(OpCode const& opcode)
  16. {
  17. return Names::instruction_names.get(opcode).value_or("<unknown>");
  18. }
  19. Optional<OpCode> instruction_from_name(StringView name)
  20. {
  21. if (Names::instructions_by_name.is_empty()) {
  22. for (auto& entry : Names::instruction_names)
  23. Names::instructions_by_name.set(entry.value, entry.key);
  24. }
  25. return Names::instructions_by_name.get(name);
  26. }
  27. void Printer::print_indent()
  28. {
  29. for (size_t i = 0; i < m_indent; ++i)
  30. m_stream.write_or_error(" "sv.bytes());
  31. }
  32. void Printer::print(Wasm::BlockType const& type)
  33. {
  34. print_indent();
  35. print("(type block ");
  36. switch (type.kind()) {
  37. case Wasm::BlockType::Kind::Index:
  38. print("index {})\n", type.type_index().value());
  39. return;
  40. case Wasm::BlockType::Kind::Type: {
  41. print("type\n");
  42. {
  43. TemporaryChange change { m_indent, m_indent + 1 };
  44. print(type.value_type());
  45. }
  46. print_indent();
  47. print(")\n");
  48. return;
  49. }
  50. case Wasm::BlockType::Kind ::Empty:
  51. print("empty)\n");
  52. return;
  53. }
  54. VERIFY_NOT_REACHED();
  55. }
  56. void Printer::print(Wasm::CodeSection const& section)
  57. {
  58. print_indent();
  59. print("(section code\n");
  60. {
  61. TemporaryChange change { m_indent, m_indent + 1 };
  62. for (auto& code : section.functions())
  63. print(code);
  64. }
  65. print_indent();
  66. print(")\n");
  67. }
  68. void Printer::print(Wasm::CodeSection::Code const& code)
  69. {
  70. print(code.func());
  71. }
  72. void Printer::print(Wasm::CustomSection const& section)
  73. {
  74. print_indent();
  75. print("(section custom\n");
  76. {
  77. TemporaryChange change { m_indent, m_indent + 1 };
  78. print_indent();
  79. print("(name `{}')\n", section.name());
  80. print_indent();
  81. print("(contents {} bytes)\n", section.contents().size());
  82. }
  83. print_indent();
  84. print(")\n");
  85. }
  86. void Printer::print(Wasm::DataCountSection const& section)
  87. {
  88. print_indent();
  89. print("(section data count\n");
  90. if (section.count().has_value()) {
  91. TemporaryChange change { m_indent, m_indent + 1 };
  92. print_indent();
  93. print("(count `{}')\n", *section.count());
  94. }
  95. print_indent();
  96. print(")\n");
  97. }
  98. void Printer::print(Wasm::DataSection const& section)
  99. {
  100. print_indent();
  101. print("(section data\n");
  102. {
  103. TemporaryChange change { m_indent, m_indent + 1 };
  104. for (auto& entry : section.data())
  105. print(entry);
  106. }
  107. print_indent();
  108. print(")\n");
  109. }
  110. void Printer::print(Wasm::DataSection::Data const& data)
  111. {
  112. print_indent();
  113. print("(data with value\n");
  114. {
  115. TemporaryChange change { m_indent, m_indent + 1 };
  116. data.value().visit(
  117. [this](DataSection::Data::Passive const& value) {
  118. print_indent();
  119. print("(passive init {}xu8 (", value.init.size());
  120. bool first = true;
  121. for (auto v : value.init) {
  122. if (first)
  123. print("{:x}", v);
  124. else
  125. print(" {:x}", v);
  126. first = false;
  127. }
  128. print(")\n");
  129. },
  130. [this](DataSection::Data::Active const& value) {
  131. print_indent();
  132. print("(active init {}xu8 (", value.init.size());
  133. bool first = true;
  134. for (auto v : value.init) {
  135. if (first)
  136. print("{:x}", v);
  137. else
  138. print(" {:x}", v);
  139. first = false;
  140. }
  141. print("\n");
  142. {
  143. TemporaryChange change { m_indent, m_indent + 1 };
  144. print_indent();
  145. print("(offset\n");
  146. {
  147. TemporaryChange change { m_indent, m_indent + 1 };
  148. print(value.offset);
  149. }
  150. print_indent();
  151. print(")\n");
  152. }
  153. {
  154. TemporaryChange change { m_indent, m_indent + 1 };
  155. print_indent();
  156. print("(index {})\n", value.index.value());
  157. }
  158. });
  159. }
  160. print_indent();
  161. print(")\n");
  162. }
  163. void Printer::print(Wasm::ElementSection const& section)
  164. {
  165. print_indent();
  166. print("(section element\n");
  167. {
  168. TemporaryChange change { m_indent, m_indent + 1 };
  169. for (auto& entry : section.segments())
  170. print(entry);
  171. }
  172. print_indent();
  173. print(")\n");
  174. }
  175. void Printer::print(Wasm::ElementSection::Element const& element)
  176. {
  177. print_indent();
  178. print("(element ");
  179. {
  180. TemporaryChange<size_t> change { m_indent, 0 };
  181. print(element.type);
  182. }
  183. {
  184. TemporaryChange change { m_indent, m_indent + 1 };
  185. print_indent();
  186. print("(init\n");
  187. {
  188. TemporaryChange change { m_indent, m_indent + 1 };
  189. for (auto& entry : element.init)
  190. print(entry);
  191. }
  192. print_indent();
  193. print(")\n");
  194. print_indent();
  195. print("(mode ");
  196. element.mode.visit(
  197. [this](ElementSection::Active const& active) {
  198. print("\n");
  199. {
  200. TemporaryChange change { m_indent, m_indent + 1 };
  201. print_indent();
  202. print("(active index {}\n", active.index.value());
  203. {
  204. print(active.expression);
  205. }
  206. print_indent();
  207. print(")\n");
  208. }
  209. print_indent();
  210. },
  211. [this](ElementSection::Passive const&) { print("passive"); },
  212. [this](ElementSection::Declarative const&) { print("declarative"); });
  213. print(")\n");
  214. }
  215. }
  216. void Printer::print(Wasm::ExportSection const& section)
  217. {
  218. print_indent();
  219. print("(section export\n");
  220. {
  221. TemporaryChange change { m_indent, m_indent + 1 };
  222. for (auto& entry : section.entries())
  223. print(entry);
  224. }
  225. print_indent();
  226. print(")\n");
  227. }
  228. void Printer::print(Wasm::ExportSection::Export const& entry)
  229. {
  230. print_indent();
  231. print("(export `{}' as\n", entry.name());
  232. {
  233. TemporaryChange change { m_indent, m_indent + 1 };
  234. print_indent();
  235. entry.description().visit(
  236. [this](FunctionIndex const& index) { print("(function index {})\n", index.value()); },
  237. [this](TableIndex const& index) { print("(table index {})\n", index.value()); },
  238. [this](MemoryIndex const& index) { print("(memory index {})\n", index.value()); },
  239. [this](GlobalIndex const& index) { print("(global index {})\n", index.value()); });
  240. }
  241. print_indent();
  242. print(")\n");
  243. }
  244. void Printer::print(Wasm::Expression const& expression)
  245. {
  246. TemporaryChange change { m_indent, m_indent + 1 };
  247. for (auto& instr : expression.instructions())
  248. print(instr);
  249. }
  250. void Printer::print(Wasm::CodeSection::Func const& func)
  251. {
  252. print_indent();
  253. print("(function\n");
  254. {
  255. TemporaryChange change { m_indent, m_indent + 1 };
  256. {
  257. print_indent();
  258. print("(locals\n");
  259. {
  260. TemporaryChange change { m_indent, m_indent + 1 };
  261. for (auto& locals : func.locals())
  262. print(locals);
  263. }
  264. print_indent();
  265. print(")\n");
  266. }
  267. print_indent();
  268. print("(body\n");
  269. print(func.body());
  270. print_indent();
  271. print(")\n");
  272. }
  273. print_indent();
  274. print(")\n");
  275. }
  276. void Printer::print(Wasm::FunctionSection const& section)
  277. {
  278. print_indent();
  279. print("(section function\n");
  280. {
  281. TemporaryChange change { m_indent, m_indent + 1 };
  282. for (auto& index : section.types()) {
  283. print_indent();
  284. print("(type index {})\n", index.value());
  285. }
  286. }
  287. print_indent();
  288. print(")\n");
  289. }
  290. void Printer::print(Wasm::FunctionType const& type)
  291. {
  292. print_indent();
  293. print("(type function\n");
  294. {
  295. TemporaryChange change { m_indent, m_indent + 1 };
  296. print_indent();
  297. print("(parameters\n");
  298. {
  299. TemporaryChange change { m_indent, m_indent + 1 };
  300. for (auto& param : type.parameters())
  301. print(param);
  302. }
  303. print_indent();
  304. print(")\n");
  305. }
  306. {
  307. TemporaryChange change { m_indent, m_indent + 1 };
  308. print_indent();
  309. print("(results\n");
  310. {
  311. TemporaryChange change { m_indent, m_indent + 1 };
  312. for (auto& type : type.results())
  313. print(type);
  314. }
  315. print_indent();
  316. print(")\n");
  317. }
  318. print_indent();
  319. print(")\n");
  320. }
  321. void Printer::print(Wasm::GlobalSection const& section)
  322. {
  323. print_indent();
  324. print("(section global\n");
  325. {
  326. TemporaryChange change { m_indent, m_indent + 1 };
  327. for (auto& entry : section.entries())
  328. print(entry);
  329. }
  330. print_indent();
  331. print(")\n");
  332. }
  333. void Printer::print(Wasm::GlobalSection::Global const& entry)
  334. {
  335. print_indent();
  336. print("(global\n");
  337. {
  338. TemporaryChange change { m_indent, m_indent + 1 };
  339. print_indent();
  340. print("(type\n");
  341. {
  342. TemporaryChange change { m_indent, m_indent + 1 };
  343. print(entry.type());
  344. }
  345. print_indent();
  346. print(")\n");
  347. }
  348. {
  349. TemporaryChange change { m_indent, m_indent + 1 };
  350. print_indent();
  351. print("(init\n");
  352. {
  353. TemporaryChange change { m_indent, m_indent + 1 };
  354. print(entry.expression());
  355. }
  356. print_indent();
  357. print(")\n");
  358. }
  359. print_indent();
  360. print(")\n");
  361. }
  362. void Printer::print(Wasm::GlobalType const& type)
  363. {
  364. print_indent();
  365. print("(type global {}mutable\n", type.is_mutable() ? "" : "im");
  366. {
  367. TemporaryChange change { m_indent, m_indent + 1 };
  368. print(type.type());
  369. }
  370. print_indent();
  371. print(")\n");
  372. }
  373. void Printer::print(Wasm::ImportSection const& section)
  374. {
  375. print_indent();
  376. print("(section import\n");
  377. {
  378. TemporaryChange change { m_indent, m_indent + 1 };
  379. for (auto& import : section.imports())
  380. print(import);
  381. }
  382. print_indent();
  383. print(")\n");
  384. }
  385. void Printer::print(Wasm::ImportSection::Import const& import)
  386. {
  387. print_indent();
  388. print("(import `{}' from `{}' as\n", import.name(), import.module());
  389. {
  390. TemporaryChange change { m_indent, m_indent + 1 };
  391. import.description().visit(
  392. [this](auto const& type) { print(type); },
  393. [this](TypeIndex const& index) {
  394. print_indent();
  395. print("(type index {})\n", index.value());
  396. });
  397. }
  398. print_indent();
  399. print(")\n");
  400. }
  401. void Printer::print(Wasm::Instruction const& instruction)
  402. {
  403. print_indent();
  404. print("({}", instruction_name(instruction.opcode()));
  405. if (instruction.arguments().has<u8>()) {
  406. print(")\n");
  407. } else {
  408. print(" ");
  409. instruction.arguments().visit(
  410. [&](BlockType const& type) { print(type); },
  411. [&](DataIndex const& index) { print("(data index {})", index.value()); },
  412. [&](ElementIndex const& index) { print("(element index {})", index.value()); },
  413. [&](FunctionIndex const& index) { print("(function index {})", index.value()); },
  414. [&](GlobalIndex const& index) { print("(global index {})", index.value()); },
  415. [&](LabelIndex const& index) { print("(label index {})", index.value()); },
  416. [&](LocalIndex const& index) { print("(local index {})", index.value()); },
  417. [&](TableIndex const& index) { print("(table index {})", index.value()); },
  418. [&](Instruction::IndirectCallArgs const& args) { print("(indirect (type index {}) (table index {}))", args.type.value(), args.table.value()); },
  419. [&](Instruction::MemoryArgument const& args) { print("(memory (align {}) (offset {}))", args.align, args.offset); },
  420. [&](Instruction::StructuredInstructionArgs const& args) {
  421. print("(structured\n");
  422. TemporaryChange change { m_indent, m_indent + 1 };
  423. print(args.block_type);
  424. print_indent();
  425. print("(else {}) (end {}))", args.else_ip.has_value() ? String::number(args.else_ip->value()) : "(none)", args.end_ip.value());
  426. },
  427. [&](Instruction::TableBranchArgs const& args) {
  428. print("(table_branch");
  429. for (auto& label : args.labels)
  430. print(" (label {})", label.value());
  431. print(" (label {}))", args.default_.value());
  432. },
  433. [&](Instruction::TableElementArgs const& args) { print("(table_element (table index {}) (element index {}))", args.table_index.value(), args.element_index.value()); },
  434. [&](Instruction::TableTableArgs const& args) { print("(table_table (table index {}) (table index {}))", args.lhs.value(), args.rhs.value()); },
  435. [&](ValueType const& type) { print(type); },
  436. [&](Vector<ValueType> const&) { print("(types...)"); },
  437. [&](auto const& value) { print("{}", value); });
  438. print(")\n");
  439. }
  440. }
  441. void Printer::print(Wasm::Limits const& limits)
  442. {
  443. print_indent();
  444. print("(limits min={}", limits.min());
  445. if (limits.max().has_value())
  446. print(" max={}", limits.max().value());
  447. else
  448. print(" unbounded");
  449. print(")\n");
  450. }
  451. void Printer::print(Wasm::Locals const& local)
  452. {
  453. print_indent();
  454. print("(local x{} of type\n", local.n());
  455. {
  456. TemporaryChange change { m_indent, m_indent + 1 };
  457. print(local.type());
  458. }
  459. print_indent();
  460. print(")\n");
  461. }
  462. void Printer::print(Wasm::MemorySection const& section)
  463. {
  464. print_indent();
  465. print("(section memory\n");
  466. {
  467. TemporaryChange change { m_indent, m_indent + 1 };
  468. for (auto& memory : section.memories())
  469. print(memory);
  470. }
  471. print_indent();
  472. print(")\n");
  473. }
  474. void Printer::print(Wasm::MemorySection::Memory const& memory)
  475. {
  476. print_indent();
  477. print("(memory\n");
  478. {
  479. TemporaryChange change { m_indent, m_indent + 1 };
  480. print(memory.type());
  481. }
  482. print_indent();
  483. print(")\n");
  484. }
  485. void Printer::print(Wasm::MemoryType const& type)
  486. {
  487. print_indent();
  488. print("(type memory\n");
  489. {
  490. TemporaryChange change { m_indent, m_indent + 1 };
  491. print(type.limits());
  492. }
  493. print_indent();
  494. print(")\n");
  495. }
  496. void Printer::print(Wasm::Module const& module)
  497. {
  498. print_indent();
  499. {
  500. TemporaryChange change { m_indent, m_indent + 1 };
  501. print("(module\n");
  502. for (auto& section : module.sections())
  503. section.visit([this](auto const& value) { print(value); });
  504. }
  505. print_indent();
  506. print(")\n");
  507. }
  508. void Printer::print(Wasm::Module::Function const& func)
  509. {
  510. print_indent();
  511. print("(function\n");
  512. {
  513. TemporaryChange change { m_indent, m_indent + 1 };
  514. {
  515. print_indent();
  516. print("(locals\n");
  517. {
  518. TemporaryChange change { m_indent, m_indent + 1 };
  519. for (auto& locals : func.locals())
  520. print(locals);
  521. }
  522. print_indent();
  523. print(")\n");
  524. }
  525. print_indent();
  526. print("(body\n");
  527. print(func.body());
  528. print_indent();
  529. print(")\n");
  530. }
  531. print_indent();
  532. print(")\n");
  533. }
  534. void Printer::print(Wasm::StartSection const& section)
  535. {
  536. print_indent();
  537. print("(section start\n");
  538. {
  539. TemporaryChange change { m_indent, m_indent + 1 };
  540. print(section.function());
  541. }
  542. print_indent();
  543. print(")\n");
  544. }
  545. void Printer::print(Wasm::StartSection::StartFunction const& function)
  546. {
  547. print_indent();
  548. print("(start function index {})\n", function.index().value());
  549. }
  550. void Printer::print(Wasm::TableSection const& section)
  551. {
  552. print_indent();
  553. print("(section table\n");
  554. {
  555. TemporaryChange change { m_indent, m_indent + 1 };
  556. for (auto& table : section.tables())
  557. print(table);
  558. }
  559. print_indent();
  560. print(")\n");
  561. }
  562. void Printer::print(Wasm::TableSection::Table const& table)
  563. {
  564. print_indent();
  565. print("(table\n");
  566. {
  567. TemporaryChange change { m_indent, m_indent + 1 };
  568. print(table.type());
  569. }
  570. print_indent();
  571. print(")\n");
  572. }
  573. void Printer::print(Wasm::TableType const& type)
  574. {
  575. print_indent();
  576. print("(type table min:{}", type.limits().min());
  577. if (type.limits().max().has_value())
  578. print(" max:{}", type.limits().max().value());
  579. print("\n");
  580. {
  581. TemporaryChange change { m_indent, m_indent + 1 };
  582. print(type.element_type());
  583. }
  584. print_indent();
  585. print(")\n");
  586. }
  587. void Printer::print(Wasm::TypeSection const& section)
  588. {
  589. print_indent();
  590. print("(section type\n");
  591. {
  592. TemporaryChange change { m_indent, m_indent + 1 };
  593. for (auto& type : section.types())
  594. print(type);
  595. }
  596. print_indent();
  597. print(")\n");
  598. }
  599. void Printer::print(Wasm::ValueType const& type)
  600. {
  601. print_indent();
  602. print("(type {})\n", ValueType::kind_name(type.kind()));
  603. }
  604. void Printer::print(Wasm::Value const& value)
  605. {
  606. print_indent();
  607. print("{} ", value.value().visit([&]<typename T>(T const& value) {
  608. if constexpr (IsSame<Wasm::Reference, T>)
  609. return String::formatted(
  610. "addr({})",
  611. value.ref().visit(
  612. [](Wasm::Reference::Null const&) { return String("null"); },
  613. [](auto const& ref) { return String::number(ref.address.value()); }));
  614. else
  615. return String::formatted("{}", value);
  616. }));
  617. TemporaryChange<size_t> change { m_indent, 0 };
  618. print(value.type());
  619. }
  620. void Printer::print(Wasm::Reference const& value)
  621. {
  622. print_indent();
  623. print(
  624. "addr({})\n",
  625. value.ref().visit(
  626. [](Wasm::Reference::Null const&) { return String("null"); },
  627. [](auto const& ref) { return String::number(ref.address.value()); }));
  628. }
  629. }
  630. HashMap<Wasm::OpCode, String> Wasm::Names::instruction_names {
  631. { Instructions::unreachable, "unreachable" },
  632. { Instructions::nop, "nop" },
  633. { Instructions::block, "block" },
  634. { Instructions::loop, "loop" },
  635. { Instructions::if_, "if" },
  636. { Instructions::br, "br" },
  637. { Instructions::br_if, "br.if" },
  638. { Instructions::br_table, "br.table" },
  639. { Instructions::return_, "return" },
  640. { Instructions::call, "call" },
  641. { Instructions::call_indirect, "call.indirect" },
  642. { Instructions::drop, "drop" },
  643. { Instructions::select, "select" },
  644. { Instructions::select_typed, "select.typed" },
  645. { Instructions::local_get, "local.get" },
  646. { Instructions::local_set, "local.set" },
  647. { Instructions::local_tee, "local.tee" },
  648. { Instructions::global_get, "global.get" },
  649. { Instructions::global_set, "global.set" },
  650. { Instructions::table_get, "table.get" },
  651. { Instructions::table_set, "table.set" },
  652. { Instructions::i32_load, "i32.load" },
  653. { Instructions::i64_load, "i64.load" },
  654. { Instructions::f32_load, "f32.load" },
  655. { Instructions::f64_load, "f64.load" },
  656. { Instructions::i32_load8_s, "i32.load8_s" },
  657. { Instructions::i32_load8_u, "i32.load8_u" },
  658. { Instructions::i32_load16_s, "i32.load16_s" },
  659. { Instructions::i32_load16_u, "i32.load16_u" },
  660. { Instructions::i64_load8_s, "i64.load8_s" },
  661. { Instructions::i64_load8_u, "i64.load8_u" },
  662. { Instructions::i64_load16_s, "i64.load16_s" },
  663. { Instructions::i64_load16_u, "i64.load16_u" },
  664. { Instructions::i64_load32_s, "i64.load32_s" },
  665. { Instructions::i64_load32_u, "i64.load32_u" },
  666. { Instructions::i32_store, "i32.store" },
  667. { Instructions::i64_store, "i64.store" },
  668. { Instructions::f32_store, "f32.store" },
  669. { Instructions::f64_store, "f64.store" },
  670. { Instructions::i32_store8, "i32.store8" },
  671. { Instructions::i32_store16, "i32.store16" },
  672. { Instructions::i64_store8, "i64.store8" },
  673. { Instructions::i64_store16, "i64.store16" },
  674. { Instructions::i64_store32, "i64.store32" },
  675. { Instructions::memory_size, "memory.size" },
  676. { Instructions::memory_grow, "memory.grow" },
  677. { Instructions::i32_const, "i32.const" },
  678. { Instructions::i64_const, "i64.const" },
  679. { Instructions::f32_const, "f32.const" },
  680. { Instructions::f64_const, "f64.const" },
  681. { Instructions::i32_eqz, "i32.eqz" },
  682. { Instructions::i32_eq, "i32.eq" },
  683. { Instructions::i32_ne, "i32.ne" },
  684. { Instructions::i32_lts, "i32.lts" },
  685. { Instructions::i32_ltu, "i32.ltu" },
  686. { Instructions::i32_gts, "i32.gts" },
  687. { Instructions::i32_gtu, "i32.gtu" },
  688. { Instructions::i32_les, "i32.les" },
  689. { Instructions::i32_leu, "i32.leu" },
  690. { Instructions::i32_ges, "i32.ges" },
  691. { Instructions::i32_geu, "i32.geu" },
  692. { Instructions::i64_eqz, "i64.eqz" },
  693. { Instructions::i64_eq, "i64.eq" },
  694. { Instructions::i64_ne, "i64.ne" },
  695. { Instructions::i64_lts, "i64.lts" },
  696. { Instructions::i64_ltu, "i64.ltu" },
  697. { Instructions::i64_gts, "i64.gts" },
  698. { Instructions::i64_gtu, "i64.gtu" },
  699. { Instructions::i64_les, "i64.les" },
  700. { Instructions::i64_leu, "i64.leu" },
  701. { Instructions::i64_ges, "i64.ges" },
  702. { Instructions::i64_geu, "i64.geu" },
  703. { Instructions::f32_eq, "f32.eq" },
  704. { Instructions::f32_ne, "f32.ne" },
  705. { Instructions::f32_lt, "f32.lt" },
  706. { Instructions::f32_gt, "f32.gt" },
  707. { Instructions::f32_le, "f32.le" },
  708. { Instructions::f32_ge, "f32.ge" },
  709. { Instructions::f64_eq, "f64.eq" },
  710. { Instructions::f64_ne, "f64.ne" },
  711. { Instructions::f64_lt, "f64.lt" },
  712. { Instructions::f64_gt, "f64.gt" },
  713. { Instructions::f64_le, "f64.le" },
  714. { Instructions::f64_ge, "f64.ge" },
  715. { Instructions::i32_clz, "i32.clz" },
  716. { Instructions::i32_ctz, "i32.ctz" },
  717. { Instructions::i32_popcnt, "i32.popcnt" },
  718. { Instructions::i32_add, "i32.add" },
  719. { Instructions::i32_sub, "i32.sub" },
  720. { Instructions::i32_mul, "i32.mul" },
  721. { Instructions::i32_divs, "i32.divs" },
  722. { Instructions::i32_divu, "i32.divu" },
  723. { Instructions::i32_rems, "i32.rems" },
  724. { Instructions::i32_remu, "i32.remu" },
  725. { Instructions::i32_and, "i32.and" },
  726. { Instructions::i32_or, "i32.or" },
  727. { Instructions::i32_xor, "i32.xor" },
  728. { Instructions::i32_shl, "i32.shl" },
  729. { Instructions::i32_shrs, "i32.shrs" },
  730. { Instructions::i32_shru, "i32.shru" },
  731. { Instructions::i32_rotl, "i32.rotl" },
  732. { Instructions::i32_rotr, "i32.rotr" },
  733. { Instructions::i64_clz, "i64.clz" },
  734. { Instructions::i64_ctz, "i64.ctz" },
  735. { Instructions::i64_popcnt, "i64.popcnt" },
  736. { Instructions::i64_add, "i64.add" },
  737. { Instructions::i64_sub, "i64.sub" },
  738. { Instructions::i64_mul, "i64.mul" },
  739. { Instructions::i64_divs, "i64.divs" },
  740. { Instructions::i64_divu, "i64.divu" },
  741. { Instructions::i64_rems, "i64.rems" },
  742. { Instructions::i64_remu, "i64.remu" },
  743. { Instructions::i64_and, "i64.and" },
  744. { Instructions::i64_or, "i64.or" },
  745. { Instructions::i64_xor, "i64.xor" },
  746. { Instructions::i64_shl, "i64.shl" },
  747. { Instructions::i64_shrs, "i64.shrs" },
  748. { Instructions::i64_shru, "i64.shru" },
  749. { Instructions::i64_rotl, "i64.rotl" },
  750. { Instructions::i64_rotr, "i64.rotr" },
  751. { Instructions::f32_abs, "f32.abs" },
  752. { Instructions::f32_neg, "f32.neg" },
  753. { Instructions::f32_ceil, "f32.ceil" },
  754. { Instructions::f32_floor, "f32.floor" },
  755. { Instructions::f32_trunc, "f32.trunc" },
  756. { Instructions::f32_nearest, "f32.nearest" },
  757. { Instructions::f32_sqrt, "f32.sqrt" },
  758. { Instructions::f32_add, "f32.add" },
  759. { Instructions::f32_sub, "f32.sub" },
  760. { Instructions::f32_mul, "f32.mul" },
  761. { Instructions::f32_div, "f32.div" },
  762. { Instructions::f32_min, "f32.min" },
  763. { Instructions::f32_max, "f32.max" },
  764. { Instructions::f32_copysign, "f32.copysign" },
  765. { Instructions::f64_abs, "f64.abs" },
  766. { Instructions::f64_neg, "f64.neg" },
  767. { Instructions::f64_ceil, "f64.ceil" },
  768. { Instructions::f64_floor, "f64.floor" },
  769. { Instructions::f64_trunc, "f64.trunc" },
  770. { Instructions::f64_nearest, "f64.nearest" },
  771. { Instructions::f64_sqrt, "f64.sqrt" },
  772. { Instructions::f64_add, "f64.add" },
  773. { Instructions::f64_sub, "f64.sub" },
  774. { Instructions::f64_mul, "f64.mul" },
  775. { Instructions::f64_div, "f64.div" },
  776. { Instructions::f64_min, "f64.min" },
  777. { Instructions::f64_max, "f64.max" },
  778. { Instructions::f64_copysign, "f64.copysign" },
  779. { Instructions::i32_wrap_i64, "i32.wrap_i64" },
  780. { Instructions::i32_trunc_sf32, "i32.trunc_sf32" },
  781. { Instructions::i32_trunc_uf32, "i32.trunc_uf32" },
  782. { Instructions::i32_trunc_sf64, "i32.trunc_sf64" },
  783. { Instructions::i32_trunc_uf64, "i32.trunc_uf64" },
  784. { Instructions::i64_extend_si32, "i64.extend_si32" },
  785. { Instructions::i64_extend_ui32, "i64.extend_ui32" },
  786. { Instructions::i64_trunc_sf32, "i64.trunc_sf32" },
  787. { Instructions::i64_trunc_uf32, "i64.trunc_uf32" },
  788. { Instructions::i64_trunc_sf64, "i64.trunc_sf64" },
  789. { Instructions::i64_trunc_uf64, "i64.trunc_uf64" },
  790. { Instructions::f32_convert_si32, "f32.convert_si32" },
  791. { Instructions::f32_convert_ui32, "f32.convert_ui32" },
  792. { Instructions::f32_convert_si64, "f32.convert_si64" },
  793. { Instructions::f32_convert_ui64, "f32.convert_ui64" },
  794. { Instructions::f32_demote_f64, "f32.demote_f64" },
  795. { Instructions::f64_convert_si32, "f64.convert_si32" },
  796. { Instructions::f64_convert_ui32, "f64.convert_ui32" },
  797. { Instructions::f64_convert_si64, "f64.convert_si64" },
  798. { Instructions::f64_convert_ui64, "f64.convert_ui64" },
  799. { Instructions::f64_promote_f32, "f64.promote_f32" },
  800. { Instructions::i32_reinterpret_f32, "i32.reinterpret_f32" },
  801. { Instructions::i64_reinterpret_f64, "i64.reinterpret_f64" },
  802. { Instructions::f32_reinterpret_i32, "f32.reinterpret_i32" },
  803. { Instructions::f64_reinterpret_i64, "f64.reinterpret_i64" },
  804. { Instructions::i32_extend8_s, "i32.extend8_s" },
  805. { Instructions::i32_extend16_s, "i32.extend16_s" },
  806. { Instructions::i64_extend8_s, "i64.extend8_s" },
  807. { Instructions::i64_extend16_s, "i64.extend16_s" },
  808. { Instructions::i64_extend32_s, "i64.extend32_s" },
  809. { Instructions::ref_null, "ref.null" },
  810. { Instructions::ref_is_null, "ref.is.null" },
  811. { Instructions::ref_func, "ref.func" },
  812. { Instructions::i32_trunc_sat_f32_s, "i32.trunc_sat_f32_s" },
  813. { Instructions::i32_trunc_sat_f32_u, "i32.trunc_sat_f32_u" },
  814. { Instructions::i32_trunc_sat_f64_s, "i32.trunc_sat_f64_s" },
  815. { Instructions::i32_trunc_sat_f64_u, "i32.trunc_sat_f64_u" },
  816. { Instructions::i64_trunc_sat_f32_s, "i64.trunc_sat_f32_s" },
  817. { Instructions::i64_trunc_sat_f32_u, "i64.trunc_sat_f32_u" },
  818. { Instructions::i64_trunc_sat_f64_s, "i64.trunc_sat_f64_s" },
  819. { Instructions::i64_trunc_sat_f64_u, "i64.trunc_sat_f64_u" },
  820. { Instructions::memory_init, "memory.init" },
  821. { Instructions::data_drop, "data.drop" },
  822. { Instructions::memory_copy, "memory.copy" },
  823. { Instructions::memory_fill, "memory.fill" },
  824. { Instructions::table_init, "table.init" },
  825. { Instructions::elem_drop, "elem.drop" },
  826. { Instructions::table_copy, "table.copy" },
  827. { Instructions::table_grow, "table.grow" },
  828. { Instructions::table_size, "table.size" },
  829. { Instructions::table_fill, "table.fill" },
  830. { Instructions::structured_else, "synthetic:else" },
  831. { Instructions::structured_end, "synthetic:end" },
  832. };
  833. HashMap<String, Wasm::OpCode> Wasm::Names::instructions_by_name;