Printer.cpp 28 KB

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