Printer.cpp 27 KB

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