Op.h 81 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693
  1. /*
  2. * Copyright (c) 2021-2023, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
  4. * Copyright (c) 2021, Gunnar Beutner <gbeutner@serenityos.org>
  5. *
  6. * SPDX-License-Identifier: BSD-2-Clause
  7. */
  8. #pragma once
  9. #include <AK/FixedArray.h>
  10. #include <AK/StdLibExtras.h>
  11. #include <LibCrypto/BigInt/SignedBigInteger.h>
  12. #include <LibJS/Bytecode/Builtins.h>
  13. #include <LibJS/Bytecode/IdentifierTable.h>
  14. #include <LibJS/Bytecode/Instruction.h>
  15. #include <LibJS/Bytecode/Label.h>
  16. #include <LibJS/Bytecode/Operand.h>
  17. #include <LibJS/Bytecode/RegexTable.h>
  18. #include <LibJS/Bytecode/Register.h>
  19. #include <LibJS/Bytecode/ScopedOperand.h>
  20. #include <LibJS/Bytecode/StringTable.h>
  21. #include <LibJS/Heap/Cell.h>
  22. #include <LibJS/Runtime/Environment.h>
  23. #include <LibJS/Runtime/Iterator.h>
  24. #include <LibJS/Runtime/Value.h>
  25. #include <LibJS/Runtime/ValueTraits.h>
  26. namespace JS {
  27. class FunctionExpression;
  28. }
  29. namespace JS::Bytecode::Op {
  30. class CreateRestParams final : public Instruction {
  31. public:
  32. CreateRestParams(Operand dst, u32 rest_index)
  33. : Instruction(Type::CreateRestParams)
  34. , m_dst(dst)
  35. , m_rest_index(rest_index)
  36. {
  37. }
  38. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  39. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  40. void visit_operands_impl(Function<void(Operand&)> visitor)
  41. {
  42. visitor(m_dst);
  43. }
  44. private:
  45. Operand m_dst;
  46. u32 m_rest_index;
  47. };
  48. class CreateArguments final : public Instruction {
  49. public:
  50. enum class Kind {
  51. Mapped,
  52. Unmapped,
  53. };
  54. CreateArguments(Optional<Operand> dst, Kind kind, bool is_immutable)
  55. : Instruction(Type::CreateArguments)
  56. , m_dst(dst)
  57. , m_kind(kind)
  58. , m_is_immutable(is_immutable)
  59. {
  60. }
  61. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  62. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  63. void visit_operands_impl(Function<void(Operand&)> visitor)
  64. {
  65. if (m_dst.has_value())
  66. visitor(m_dst.value());
  67. }
  68. private:
  69. Optional<Operand> m_dst;
  70. Kind m_kind;
  71. bool m_is_immutable { false };
  72. };
  73. class Mov final : public Instruction {
  74. public:
  75. Mov(Operand dst, Operand src)
  76. : Instruction(Type::Mov)
  77. , m_dst(dst)
  78. , m_src(src)
  79. {
  80. }
  81. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  82. void visit_operands_impl(Function<void(Operand&)> visitor)
  83. {
  84. visitor(m_dst);
  85. visitor(m_src);
  86. }
  87. Operand dst() const { return m_dst; }
  88. Operand src() const { return m_src; }
  89. private:
  90. Operand m_dst;
  91. Operand m_src;
  92. };
  93. #define JS_ENUMERATE_COMMON_BINARY_OPS_WITH_FAST_PATH(O) \
  94. O(Add, add) \
  95. O(BitwiseAnd, bitwise_and) \
  96. O(BitwiseOr, bitwise_or) \
  97. O(BitwiseXor, bitwise_xor) \
  98. O(GreaterThan, greater_than) \
  99. O(GreaterThanEquals, greater_than_equals) \
  100. O(LeftShift, left_shift) \
  101. O(LessThan, less_than) \
  102. O(LessThanEquals, less_than_equals) \
  103. O(Mul, mul) \
  104. O(RightShift, right_shift) \
  105. O(Sub, sub) \
  106. O(UnsignedRightShift, unsigned_right_shift)
  107. #define JS_ENUMERATE_COMMON_BINARY_OPS_WITHOUT_FAST_PATH(O) \
  108. O(Div, div) \
  109. O(Exp, exp) \
  110. O(Mod, mod) \
  111. O(In, in) \
  112. O(InstanceOf, instance_of) \
  113. O(LooselyInequals, loosely_inequals) \
  114. O(LooselyEquals, loosely_equals) \
  115. O(StrictlyInequals, strict_inequals) \
  116. O(StrictlyEquals, strict_equals)
  117. #define JS_DECLARE_COMMON_BINARY_OP(OpTitleCase, op_snake_case) \
  118. class OpTitleCase final : public Instruction { \
  119. public: \
  120. explicit OpTitleCase(Operand dst, Operand lhs, Operand rhs) \
  121. : Instruction(Type::OpTitleCase) \
  122. , m_dst(dst) \
  123. , m_lhs(lhs) \
  124. , m_rhs(rhs) \
  125. { \
  126. } \
  127. \
  128. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const; \
  129. ByteString to_byte_string_impl(Bytecode::Executable const&) const; \
  130. void visit_operands_impl(Function<void(Operand&)> visitor) \
  131. { \
  132. visitor(m_dst); \
  133. visitor(m_lhs); \
  134. visitor(m_rhs); \
  135. } \
  136. \
  137. Operand dst() const { return m_dst; } \
  138. Operand lhs() const { return m_lhs; } \
  139. Operand rhs() const { return m_rhs; } \
  140. \
  141. private: \
  142. Operand m_dst; \
  143. Operand m_lhs; \
  144. Operand m_rhs; \
  145. };
  146. JS_ENUMERATE_COMMON_BINARY_OPS_WITHOUT_FAST_PATH(JS_DECLARE_COMMON_BINARY_OP)
  147. JS_ENUMERATE_COMMON_BINARY_OPS_WITH_FAST_PATH(JS_DECLARE_COMMON_BINARY_OP)
  148. #undef JS_DECLARE_COMMON_BINARY_OP
  149. #define JS_ENUMERATE_COMMON_UNARY_OPS(O) \
  150. O(BitwiseNot, bitwise_not) \
  151. O(Not, not_) \
  152. O(UnaryPlus, unary_plus) \
  153. O(UnaryMinus, unary_minus) \
  154. O(Typeof, typeof_)
  155. #define JS_DECLARE_COMMON_UNARY_OP(OpTitleCase, op_snake_case) \
  156. class OpTitleCase final : public Instruction { \
  157. public: \
  158. OpTitleCase(Operand dst, Operand src) \
  159. : Instruction(Type::OpTitleCase) \
  160. , m_dst(dst) \
  161. , m_src(src) \
  162. { \
  163. } \
  164. \
  165. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const; \
  166. ByteString to_byte_string_impl(Bytecode::Executable const&) const; \
  167. void visit_operands_impl(Function<void(Operand&)> visitor) \
  168. { \
  169. visitor(m_dst); \
  170. visitor(m_src); \
  171. } \
  172. \
  173. Operand dst() const { return m_dst; } \
  174. Operand src() const { return m_src; } \
  175. \
  176. private: \
  177. Operand m_dst; \
  178. Operand m_src; \
  179. };
  180. JS_ENUMERATE_COMMON_UNARY_OPS(JS_DECLARE_COMMON_UNARY_OP)
  181. #undef JS_DECLARE_COMMON_UNARY_OP
  182. class NewObject final : public Instruction {
  183. public:
  184. explicit NewObject(Operand dst)
  185. : Instruction(Type::NewObject)
  186. , m_dst(dst)
  187. {
  188. }
  189. void execute_impl(Bytecode::Interpreter&) const;
  190. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  191. void visit_operands_impl(Function<void(Operand&)> visitor)
  192. {
  193. visitor(m_dst);
  194. }
  195. Operand dst() const { return m_dst; }
  196. private:
  197. Operand m_dst;
  198. };
  199. class NewRegExp final : public Instruction {
  200. public:
  201. NewRegExp(Operand dst, StringTableIndex source_index, StringTableIndex flags_index, RegexTableIndex regex_index)
  202. : Instruction(Type::NewRegExp)
  203. , m_dst(dst)
  204. , m_source_index(source_index)
  205. , m_flags_index(flags_index)
  206. , m_regex_index(regex_index)
  207. {
  208. }
  209. void execute_impl(Bytecode::Interpreter&) const;
  210. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  211. void visit_operands_impl(Function<void(Operand&)> visitor)
  212. {
  213. visitor(m_dst);
  214. }
  215. Operand dst() const { return m_dst; }
  216. StringTableIndex source_index() const { return m_source_index; }
  217. StringTableIndex flags_index() const { return m_flags_index; }
  218. RegexTableIndex regex_index() const { return m_regex_index; }
  219. private:
  220. Operand m_dst;
  221. StringTableIndex m_source_index;
  222. StringTableIndex m_flags_index;
  223. RegexTableIndex m_regex_index;
  224. };
  225. #define JS_ENUMERATE_NEW_BUILTIN_ERROR_OPS(O) \
  226. O(TypeError)
  227. #define JS_DECLARE_NEW_BUILTIN_ERROR_OP(ErrorName) \
  228. class New##ErrorName final : public Instruction { \
  229. public: \
  230. New##ErrorName(Operand dst, StringTableIndex error_string) \
  231. : Instruction(Type::New##ErrorName) \
  232. , m_dst(dst) \
  233. , m_error_string(error_string) \
  234. { \
  235. } \
  236. \
  237. void execute_impl(Bytecode::Interpreter&) const; \
  238. ByteString to_byte_string_impl(Bytecode::Executable const&) const; \
  239. void visit_operands_impl(Function<void(Operand&)> visitor) \
  240. { \
  241. visitor(m_dst); \
  242. } \
  243. \
  244. Operand dst() const { return m_dst; } \
  245. StringTableIndex error_string() const { return m_error_string; } \
  246. \
  247. private: \
  248. Operand m_dst; \
  249. StringTableIndex m_error_string; \
  250. };
  251. JS_ENUMERATE_NEW_BUILTIN_ERROR_OPS(JS_DECLARE_NEW_BUILTIN_ERROR_OP)
  252. #undef JS_DECLARE_NEW_BUILTIN_ERROR_OP
  253. // NOTE: This instruction is variable-width depending on the number of excluded names
  254. class CopyObjectExcludingProperties final : public Instruction {
  255. public:
  256. static constexpr bool IsVariableLength = true;
  257. CopyObjectExcludingProperties(Operand dst, Operand from_object, Vector<ScopedOperand> const& excluded_names)
  258. : Instruction(Type::CopyObjectExcludingProperties)
  259. , m_dst(dst)
  260. , m_from_object(from_object)
  261. , m_excluded_names_count(excluded_names.size())
  262. {
  263. for (size_t i = 0; i < m_excluded_names_count; i++)
  264. m_excluded_names[i] = excluded_names[i];
  265. }
  266. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  267. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  268. void visit_operands_impl(Function<void(Operand&)> visitor)
  269. {
  270. visitor(m_dst);
  271. visitor(m_from_object);
  272. for (size_t i = 0; i < m_excluded_names_count; i++)
  273. visitor(m_excluded_names[i]);
  274. }
  275. size_t length_impl() const
  276. {
  277. return round_up_to_power_of_two(alignof(void*), sizeof(*this) + sizeof(Operand) * m_excluded_names_count);
  278. }
  279. Operand dst() const { return m_dst; }
  280. Operand from_object() const { return m_from_object; }
  281. size_t excluded_names_count() const { return m_excluded_names_count; }
  282. Operand const* excluded_names() const { return m_excluded_names; }
  283. private:
  284. Operand m_dst;
  285. Operand m_from_object;
  286. size_t m_excluded_names_count { 0 };
  287. Operand m_excluded_names[];
  288. };
  289. // NOTE: This instruction is variable-width depending on the number of elements!
  290. class NewArray final : public Instruction {
  291. public:
  292. static constexpr bool IsVariableLength = true;
  293. explicit NewArray(Operand dst)
  294. : Instruction(Type::NewArray)
  295. , m_dst(dst)
  296. , m_element_count(0)
  297. {
  298. }
  299. NewArray(Operand dst, ReadonlySpan<ScopedOperand> elements)
  300. : Instruction(Type::NewArray)
  301. , m_dst(dst)
  302. , m_element_count(elements.size())
  303. {
  304. for (size_t i = 0; i < m_element_count; ++i)
  305. m_elements[i] = elements[i];
  306. }
  307. void execute_impl(Bytecode::Interpreter&) const;
  308. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  309. void visit_operands_impl(Function<void(Operand&)> visitor)
  310. {
  311. visitor(m_dst);
  312. for (size_t i = 0; i < m_element_count; i++)
  313. visitor(m_elements[i]);
  314. }
  315. Operand dst() const { return m_dst; }
  316. size_t length_impl() const
  317. {
  318. return round_up_to_power_of_two(alignof(void*), sizeof(*this) + sizeof(Operand) * m_element_count);
  319. }
  320. size_t element_count() const { return m_element_count; }
  321. private:
  322. Operand m_dst;
  323. size_t m_element_count { 0 };
  324. Operand m_elements[];
  325. };
  326. class NewPrimitiveArray final : public Instruction {
  327. public:
  328. static constexpr bool IsVariableLength = true;
  329. NewPrimitiveArray(Operand dst, ReadonlySpan<Value> elements)
  330. : Instruction(Type::NewPrimitiveArray)
  331. , m_dst(dst)
  332. , m_element_count(elements.size())
  333. {
  334. for (size_t i = 0; i < m_element_count; ++i)
  335. m_elements[i] = elements[i];
  336. }
  337. size_t length_impl() const
  338. {
  339. return round_up_to_power_of_two(alignof(void*), sizeof(*this) + sizeof(Value) * m_element_count);
  340. }
  341. void execute_impl(Bytecode::Interpreter&) const;
  342. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  343. void visit_operands_impl(Function<void(Operand&)> visitor)
  344. {
  345. visitor(m_dst);
  346. }
  347. Operand dst() const { return m_dst; }
  348. ReadonlySpan<Value> elements() const { return { m_elements, m_element_count }; }
  349. private:
  350. Operand m_dst;
  351. size_t m_element_count { 0 };
  352. Value m_elements[];
  353. };
  354. class AddPrivateName final : public Instruction {
  355. public:
  356. explicit AddPrivateName(IdentifierTableIndex name)
  357. : Instruction(Type::AddPrivateName)
  358. , m_name(name)
  359. {
  360. }
  361. void execute_impl(Bytecode::Interpreter&) const;
  362. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  363. private:
  364. IdentifierTableIndex m_name;
  365. };
  366. class ArrayAppend final : public Instruction {
  367. public:
  368. ArrayAppend(Operand dst, Operand src, bool is_spread)
  369. : Instruction(Type::ArrayAppend)
  370. , m_dst(dst)
  371. , m_src(src)
  372. , m_is_spread(is_spread)
  373. {
  374. }
  375. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  376. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  377. void visit_operands_impl(Function<void(Operand&)> visitor)
  378. {
  379. visitor(m_dst);
  380. visitor(m_src);
  381. }
  382. Operand dst() const { return m_dst; }
  383. Operand src() const { return m_src; }
  384. bool is_spread() const { return m_is_spread; }
  385. private:
  386. Operand m_dst;
  387. Operand m_src;
  388. bool m_is_spread = false;
  389. };
  390. class ImportCall final : public Instruction {
  391. public:
  392. ImportCall(Operand dst, Operand specifier, Operand options)
  393. : Instruction(Type::ImportCall)
  394. , m_dst(dst)
  395. , m_specifier(specifier)
  396. , m_options(options)
  397. {
  398. }
  399. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  400. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  401. void visit_operands_impl(Function<void(Operand&)> visitor)
  402. {
  403. visitor(m_dst);
  404. visitor(m_specifier);
  405. visitor(m_options);
  406. }
  407. Operand dst() const { return m_dst; }
  408. Operand specifier() const { return m_specifier; }
  409. Operand options() const { return m_options; }
  410. private:
  411. Operand m_dst;
  412. Operand m_specifier;
  413. Operand m_options;
  414. };
  415. class IteratorToArray final : public Instruction {
  416. public:
  417. explicit IteratorToArray(Operand dst, Operand iterator)
  418. : Instruction(Type::IteratorToArray)
  419. , m_dst(dst)
  420. , m_iterator(iterator)
  421. {
  422. }
  423. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  424. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  425. Operand dst() const { return m_dst; }
  426. Operand iterator() const { return m_iterator; }
  427. void visit_operands_impl(Function<void(Operand&)> visitor)
  428. {
  429. visitor(m_dst);
  430. visitor(m_iterator);
  431. }
  432. private:
  433. Operand m_dst;
  434. Operand m_iterator;
  435. };
  436. class ConcatString final : public Instruction {
  437. public:
  438. explicit ConcatString(Operand dst, Operand src)
  439. : Instruction(Type::ConcatString)
  440. , m_dst(dst)
  441. , m_src(src)
  442. {
  443. }
  444. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  445. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  446. Operand dst() const { return m_dst; }
  447. Operand src() const { return m_src; }
  448. void visit_operands_impl(Function<void(Operand&)> visitor)
  449. {
  450. visitor(m_dst);
  451. visitor(m_src);
  452. }
  453. private:
  454. Operand m_dst;
  455. Operand m_src;
  456. };
  457. enum class EnvironmentMode {
  458. Lexical,
  459. Var,
  460. };
  461. enum class BindingInitializationMode {
  462. Initialize,
  463. Set,
  464. };
  465. class CreateLexicalEnvironment final : public Instruction {
  466. public:
  467. explicit CreateLexicalEnvironment(u32 capacity = 0)
  468. : Instruction(Type::CreateLexicalEnvironment)
  469. , m_capacity(capacity)
  470. {
  471. }
  472. void execute_impl(Bytecode::Interpreter&) const;
  473. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  474. private:
  475. u32 m_capacity { 0 };
  476. };
  477. class CreateVariableEnvironment final : public Instruction {
  478. public:
  479. explicit CreateVariableEnvironment(u32 capacity = 0)
  480. : Instruction(Type::CreateVariableEnvironment)
  481. , m_capacity(capacity)
  482. {
  483. }
  484. void execute_impl(Bytecode::Interpreter&) const;
  485. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  486. private:
  487. u32 m_capacity { 0 };
  488. };
  489. class CreatePrivateEnvironment final : public Instruction {
  490. public:
  491. explicit CreatePrivateEnvironment()
  492. : Instruction(Type::CreatePrivateEnvironment)
  493. {
  494. }
  495. void execute_impl(Bytecode::Interpreter&) const;
  496. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  497. };
  498. class EnterObjectEnvironment final : public Instruction {
  499. public:
  500. explicit EnterObjectEnvironment(Operand object)
  501. : Instruction(Type::EnterObjectEnvironment)
  502. , m_object(object)
  503. {
  504. }
  505. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  506. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  507. Operand object() const { return m_object; }
  508. void visit_operands_impl(Function<void(Operand&)> visitor)
  509. {
  510. visitor(m_object);
  511. }
  512. private:
  513. Operand m_object;
  514. };
  515. class Catch final : public Instruction {
  516. public:
  517. explicit Catch(Operand dst)
  518. : Instruction(Type::Catch)
  519. , m_dst(dst)
  520. {
  521. }
  522. void execute_impl(Bytecode::Interpreter&) const;
  523. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  524. Operand dst() const { return m_dst; }
  525. void visit_operands_impl(Function<void(Operand&)> visitor)
  526. {
  527. visitor(m_dst);
  528. }
  529. private:
  530. Operand m_dst;
  531. };
  532. class LeaveFinally final : public Instruction {
  533. public:
  534. explicit LeaveFinally()
  535. : Instruction(Type::LeaveFinally)
  536. {
  537. }
  538. void execute_impl(Bytecode::Interpreter&) const;
  539. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  540. };
  541. class RestoreScheduledJump final : public Instruction {
  542. public:
  543. explicit RestoreScheduledJump()
  544. : Instruction(Type::RestoreScheduledJump)
  545. {
  546. }
  547. void execute_impl(Bytecode::Interpreter&) const;
  548. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  549. };
  550. class CreateVariable final : public Instruction {
  551. public:
  552. explicit CreateVariable(IdentifierTableIndex identifier, EnvironmentMode mode, bool is_immutable, bool is_global = false, bool is_strict = false)
  553. : Instruction(Type::CreateVariable)
  554. , m_identifier(identifier)
  555. , m_mode(mode)
  556. , m_is_immutable(is_immutable)
  557. , m_is_global(is_global)
  558. , m_is_strict(is_strict)
  559. {
  560. }
  561. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  562. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  563. IdentifierTableIndex identifier() const { return m_identifier; }
  564. EnvironmentMode mode() const { return m_mode; }
  565. bool is_immutable() const { return m_is_immutable; }
  566. bool is_global() const { return m_is_global; }
  567. bool is_strict() const { return m_is_strict; }
  568. private:
  569. IdentifierTableIndex m_identifier;
  570. EnvironmentMode m_mode;
  571. bool m_is_immutable : 4 { false };
  572. bool m_is_global : 4 { false };
  573. bool m_is_strict { false };
  574. };
  575. class InitializeLexicalBinding final : public Instruction {
  576. public:
  577. explicit InitializeLexicalBinding(IdentifierTableIndex identifier, Operand src)
  578. : Instruction(Type::InitializeLexicalBinding)
  579. , m_identifier(identifier)
  580. , m_src(src)
  581. {
  582. }
  583. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  584. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  585. void visit_operands_impl(Function<void(Operand&)> visitor)
  586. {
  587. visitor(m_src);
  588. }
  589. IdentifierTableIndex identifier() const { return m_identifier; }
  590. Operand src() const { return m_src; }
  591. private:
  592. IdentifierTableIndex m_identifier;
  593. Operand m_src;
  594. mutable EnvironmentCoordinate m_cache;
  595. };
  596. class InitializeVariableBinding final : public Instruction {
  597. public:
  598. explicit InitializeVariableBinding(IdentifierTableIndex identifier, Operand src)
  599. : Instruction(Type::InitializeVariableBinding)
  600. , m_identifier(identifier)
  601. , m_src(src)
  602. {
  603. }
  604. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  605. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  606. void visit_operands_impl(Function<void(Operand&)> visitor)
  607. {
  608. visitor(m_src);
  609. }
  610. IdentifierTableIndex identifier() const { return m_identifier; }
  611. Operand src() const { return m_src; }
  612. private:
  613. IdentifierTableIndex m_identifier;
  614. Operand m_src;
  615. mutable EnvironmentCoordinate m_cache;
  616. };
  617. class SetLexicalBinding final : public Instruction {
  618. public:
  619. explicit SetLexicalBinding(IdentifierTableIndex identifier, Operand src)
  620. : Instruction(Type::SetLexicalBinding)
  621. , m_identifier(identifier)
  622. , m_src(src)
  623. {
  624. }
  625. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  626. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  627. void visit_operands_impl(Function<void(Operand&)> visitor)
  628. {
  629. visitor(m_src);
  630. }
  631. IdentifierTableIndex identifier() const { return m_identifier; }
  632. Operand src() const { return m_src; }
  633. private:
  634. IdentifierTableIndex m_identifier;
  635. Operand m_src;
  636. mutable EnvironmentCoordinate m_cache;
  637. };
  638. class SetVariableBinding final : public Instruction {
  639. public:
  640. explicit SetVariableBinding(IdentifierTableIndex identifier, Operand src)
  641. : Instruction(Type::SetVariableBinding)
  642. , m_identifier(identifier)
  643. , m_src(src)
  644. {
  645. }
  646. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  647. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  648. void visit_operands_impl(Function<void(Operand&)> visitor)
  649. {
  650. visitor(m_src);
  651. }
  652. IdentifierTableIndex identifier() const { return m_identifier; }
  653. Operand src() const { return m_src; }
  654. private:
  655. IdentifierTableIndex m_identifier;
  656. Operand m_src;
  657. mutable EnvironmentCoordinate m_cache;
  658. };
  659. class SetArgument final : public Instruction {
  660. public:
  661. SetArgument(size_t index, Operand src)
  662. : Instruction(Type::SetArgument)
  663. , m_index(index)
  664. , m_src(src)
  665. {
  666. }
  667. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  668. void visit_operands_impl(Function<void(Operand&)> visitor)
  669. {
  670. visitor(m_src);
  671. }
  672. size_t index() const { return m_index; }
  673. Operand src() const { return m_src; }
  674. private:
  675. u32 m_index;
  676. Operand m_src;
  677. };
  678. class GetArgument final : public Instruction {
  679. public:
  680. GetArgument(Operand dst, size_t index)
  681. : Instruction(Type::GetArgument)
  682. , m_index(index)
  683. , m_dst(dst)
  684. {
  685. }
  686. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  687. void visit_operands_impl(Function<void(Operand&)> visitor)
  688. {
  689. visitor(m_dst);
  690. }
  691. u32 index() const { return m_index; }
  692. Operand dst() const { return m_dst; }
  693. private:
  694. u32 m_index;
  695. Operand m_dst;
  696. };
  697. class GetCalleeAndThisFromEnvironment final : public Instruction {
  698. public:
  699. explicit GetCalleeAndThisFromEnvironment(Operand callee, Operand this_value, IdentifierTableIndex identifier)
  700. : Instruction(Type::GetCalleeAndThisFromEnvironment)
  701. , m_identifier(identifier)
  702. , m_callee(callee)
  703. , m_this_value(this_value)
  704. {
  705. }
  706. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  707. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  708. void visit_operands_impl(Function<void(Operand&)> visitor)
  709. {
  710. visitor(m_callee);
  711. visitor(m_this_value);
  712. }
  713. IdentifierTableIndex identifier() const { return m_identifier; }
  714. Operand callee() const { return m_callee; }
  715. Operand this_() const { return m_this_value; }
  716. private:
  717. IdentifierTableIndex m_identifier;
  718. Operand m_callee;
  719. Operand m_this_value;
  720. mutable EnvironmentCoordinate m_cache;
  721. };
  722. class GetBinding final : public Instruction {
  723. public:
  724. explicit GetBinding(Operand dst, IdentifierTableIndex identifier)
  725. : Instruction(Type::GetBinding)
  726. , m_dst(dst)
  727. , m_identifier(identifier)
  728. {
  729. }
  730. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  731. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  732. Operand dst() const { return m_dst; }
  733. IdentifierTableIndex identifier() const { return m_identifier; }
  734. void visit_operands_impl(Function<void(Operand&)> visitor)
  735. {
  736. visitor(m_dst);
  737. }
  738. private:
  739. Operand m_dst;
  740. IdentifierTableIndex m_identifier;
  741. mutable EnvironmentCoordinate m_cache;
  742. };
  743. class GetGlobal final : public Instruction {
  744. public:
  745. GetGlobal(Operand dst, IdentifierTableIndex identifier, u32 cache_index)
  746. : Instruction(Type::GetGlobal)
  747. , m_dst(dst)
  748. , m_identifier(identifier)
  749. , m_cache_index(cache_index)
  750. {
  751. }
  752. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  753. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  754. Operand dst() const { return m_dst; }
  755. IdentifierTableIndex identifier() const { return m_identifier; }
  756. u32 cache_index() const { return m_cache_index; }
  757. void visit_operands_impl(Function<void(Operand&)> visitor)
  758. {
  759. visitor(m_dst);
  760. }
  761. private:
  762. Operand m_dst;
  763. IdentifierTableIndex m_identifier;
  764. u32 m_cache_index { 0 };
  765. };
  766. class DeleteVariable final : public Instruction {
  767. public:
  768. explicit DeleteVariable(Operand dst, IdentifierTableIndex identifier)
  769. : Instruction(Type::DeleteVariable)
  770. , m_dst(dst)
  771. , m_identifier(identifier)
  772. {
  773. }
  774. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  775. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  776. Operand dst() const { return m_dst; }
  777. IdentifierTableIndex identifier() const { return m_identifier; }
  778. void visit_operands_impl(Function<void(Operand&)> visitor)
  779. {
  780. visitor(m_dst);
  781. }
  782. private:
  783. Operand m_dst;
  784. IdentifierTableIndex m_identifier;
  785. };
  786. class GetById final : public Instruction {
  787. public:
  788. GetById(Operand dst, Operand base, IdentifierTableIndex property, Optional<IdentifierTableIndex> base_identifier, u32 cache_index)
  789. : Instruction(Type::GetById)
  790. , m_dst(dst)
  791. , m_base(base)
  792. , m_property(property)
  793. , m_base_identifier(move(base_identifier))
  794. , m_cache_index(cache_index)
  795. {
  796. }
  797. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  798. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  799. void visit_operands_impl(Function<void(Operand&)> visitor)
  800. {
  801. visitor(m_dst);
  802. visitor(m_base);
  803. }
  804. Operand dst() const { return m_dst; }
  805. Operand base() const { return m_base; }
  806. IdentifierTableIndex property() const { return m_property; }
  807. u32 cache_index() const { return m_cache_index; }
  808. private:
  809. Operand m_dst;
  810. Operand m_base;
  811. IdentifierTableIndex m_property;
  812. Optional<IdentifierTableIndex> m_base_identifier;
  813. u32 m_cache_index { 0 };
  814. };
  815. class GetByIdWithThis final : public Instruction {
  816. public:
  817. GetByIdWithThis(Operand dst, Operand base, IdentifierTableIndex property, Operand this_value, u32 cache_index)
  818. : Instruction(Type::GetByIdWithThis)
  819. , m_dst(dst)
  820. , m_base(base)
  821. , m_property(property)
  822. , m_this_value(this_value)
  823. , m_cache_index(cache_index)
  824. {
  825. }
  826. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  827. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  828. void visit_operands_impl(Function<void(Operand&)> visitor)
  829. {
  830. visitor(m_dst);
  831. visitor(m_base);
  832. visitor(m_this_value);
  833. }
  834. Operand dst() const { return m_dst; }
  835. Operand base() const { return m_base; }
  836. IdentifierTableIndex property() const { return m_property; }
  837. Operand this_value() const { return m_this_value; }
  838. u32 cache_index() const { return m_cache_index; }
  839. private:
  840. Operand m_dst;
  841. Operand m_base;
  842. IdentifierTableIndex m_property;
  843. Operand m_this_value;
  844. u32 m_cache_index { 0 };
  845. };
  846. class GetLength final : public Instruction {
  847. public:
  848. GetLength(Operand dst, Operand base, Optional<IdentifierTableIndex> base_identifier, u32 cache_index)
  849. : Instruction(Type::GetLength)
  850. , m_dst(dst)
  851. , m_base(base)
  852. , m_base_identifier(move(base_identifier))
  853. , m_cache_index(cache_index)
  854. {
  855. }
  856. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  857. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  858. void visit_operands_impl(Function<void(Operand&)> visitor)
  859. {
  860. visitor(m_dst);
  861. visitor(m_base);
  862. }
  863. Operand dst() const { return m_dst; }
  864. Operand base() const { return m_base; }
  865. u32 cache_index() const { return m_cache_index; }
  866. private:
  867. Operand m_dst;
  868. Operand m_base;
  869. Optional<IdentifierTableIndex> m_base_identifier;
  870. u32 m_cache_index { 0 };
  871. };
  872. class GetLengthWithThis final : public Instruction {
  873. public:
  874. GetLengthWithThis(Operand dst, Operand base, Operand this_value, u32 cache_index)
  875. : Instruction(Type::GetLengthWithThis)
  876. , m_dst(dst)
  877. , m_base(base)
  878. , m_this_value(this_value)
  879. , m_cache_index(cache_index)
  880. {
  881. }
  882. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  883. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  884. void visit_operands_impl(Function<void(Operand&)> visitor)
  885. {
  886. visitor(m_dst);
  887. visitor(m_base);
  888. visitor(m_this_value);
  889. }
  890. Operand dst() const { return m_dst; }
  891. Operand base() const { return m_base; }
  892. Operand this_value() const { return m_this_value; }
  893. u32 cache_index() const { return m_cache_index; }
  894. private:
  895. Operand m_dst;
  896. Operand m_base;
  897. Operand m_this_value;
  898. u32 m_cache_index { 0 };
  899. };
  900. class GetPrivateById final : public Instruction {
  901. public:
  902. explicit GetPrivateById(Operand dst, Operand base, IdentifierTableIndex property)
  903. : Instruction(Type::GetPrivateById)
  904. , m_dst(dst)
  905. , m_base(base)
  906. , m_property(property)
  907. {
  908. }
  909. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  910. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  911. void visit_operands_impl(Function<void(Operand&)> visitor)
  912. {
  913. visitor(m_dst);
  914. visitor(m_base);
  915. }
  916. Operand dst() const { return m_dst; }
  917. Operand base() const { return m_base; }
  918. IdentifierTableIndex property() const { return m_property; }
  919. private:
  920. Operand m_dst;
  921. Operand m_base;
  922. IdentifierTableIndex m_property;
  923. };
  924. class HasPrivateId final : public Instruction {
  925. public:
  926. HasPrivateId(Operand dst, Operand base, IdentifierTableIndex property)
  927. : Instruction(Type::HasPrivateId)
  928. , m_dst(dst)
  929. , m_base(base)
  930. , m_property(property)
  931. {
  932. }
  933. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  934. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  935. void visit_operands_impl(Function<void(Operand&)> visitor)
  936. {
  937. visitor(m_dst);
  938. visitor(m_base);
  939. }
  940. Operand dst() const { return m_dst; }
  941. Operand base() const { return m_base; }
  942. IdentifierTableIndex property() const { return m_property; }
  943. private:
  944. Operand m_dst;
  945. Operand m_base;
  946. IdentifierTableIndex m_property;
  947. };
  948. enum class PropertyKind {
  949. Getter,
  950. Setter,
  951. KeyValue,
  952. DirectKeyValue, // Used for Object expressions. Always sets an own property, never calls a setter.
  953. Spread,
  954. ProtoSetter,
  955. };
  956. class PutById final : public Instruction {
  957. public:
  958. explicit PutById(Operand base, IdentifierTableIndex property, Operand src, PropertyKind kind, u32 cache_index, Optional<IdentifierTableIndex> base_identifier = {})
  959. : Instruction(Type::PutById)
  960. , m_base(base)
  961. , m_property(property)
  962. , m_src(src)
  963. , m_kind(kind)
  964. , m_cache_index(cache_index)
  965. , m_base_identifier(move(base_identifier))
  966. {
  967. }
  968. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  969. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  970. void visit_operands_impl(Function<void(Operand&)> visitor)
  971. {
  972. visitor(m_base);
  973. visitor(m_src);
  974. }
  975. Operand base() const { return m_base; }
  976. IdentifierTableIndex property() const { return m_property; }
  977. Operand src() const { return m_src; }
  978. PropertyKind kind() const { return m_kind; }
  979. u32 cache_index() const { return m_cache_index; }
  980. private:
  981. Operand m_base;
  982. IdentifierTableIndex m_property;
  983. Operand m_src;
  984. PropertyKind m_kind;
  985. u32 m_cache_index { 0 };
  986. Optional<IdentifierTableIndex> m_base_identifier {};
  987. };
  988. class PutByIdWithThis final : public Instruction {
  989. public:
  990. PutByIdWithThis(Operand base, Operand this_value, IdentifierTableIndex property, Operand src, PropertyKind kind, u32 cache_index)
  991. : Instruction(Type::PutByIdWithThis)
  992. , m_base(base)
  993. , m_this_value(this_value)
  994. , m_property(property)
  995. , m_src(src)
  996. , m_kind(kind)
  997. , m_cache_index(cache_index)
  998. {
  999. }
  1000. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1001. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1002. void visit_operands_impl(Function<void(Operand&)> visitor)
  1003. {
  1004. visitor(m_base);
  1005. visitor(m_this_value);
  1006. visitor(m_src);
  1007. }
  1008. Operand base() const { return m_base; }
  1009. Operand this_value() const { return m_this_value; }
  1010. IdentifierTableIndex property() const { return m_property; }
  1011. Operand src() const { return m_src; }
  1012. PropertyKind kind() const { return m_kind; }
  1013. u32 cache_index() const { return m_cache_index; }
  1014. private:
  1015. Operand m_base;
  1016. Operand m_this_value;
  1017. IdentifierTableIndex m_property;
  1018. Operand m_src;
  1019. PropertyKind m_kind;
  1020. u32 m_cache_index { 0 };
  1021. };
  1022. class PutPrivateById final : public Instruction {
  1023. public:
  1024. explicit PutPrivateById(Operand base, IdentifierTableIndex property, Operand src, PropertyKind kind = PropertyKind::KeyValue)
  1025. : Instruction(Type::PutPrivateById)
  1026. , m_base(base)
  1027. , m_property(property)
  1028. , m_src(src)
  1029. , m_kind(kind)
  1030. {
  1031. }
  1032. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1033. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1034. void visit_operands_impl(Function<void(Operand&)> visitor)
  1035. {
  1036. visitor(m_base);
  1037. visitor(m_src);
  1038. }
  1039. Operand base() const { return m_base; }
  1040. IdentifierTableIndex property() const { return m_property; }
  1041. Operand src() const { return m_src; }
  1042. private:
  1043. Operand m_base;
  1044. IdentifierTableIndex m_property;
  1045. Operand m_src;
  1046. PropertyKind m_kind;
  1047. };
  1048. class DeleteById final : public Instruction {
  1049. public:
  1050. explicit DeleteById(Operand dst, Operand base, IdentifierTableIndex property)
  1051. : Instruction(Type::DeleteById)
  1052. , m_dst(dst)
  1053. , m_base(base)
  1054. , m_property(property)
  1055. {
  1056. }
  1057. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1058. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1059. void visit_operands_impl(Function<void(Operand&)> visitor)
  1060. {
  1061. visitor(m_dst);
  1062. visitor(m_base);
  1063. }
  1064. Operand dst() const { return m_dst; }
  1065. Operand base() const { return m_base; }
  1066. IdentifierTableIndex property() const { return m_property; }
  1067. private:
  1068. Operand m_dst;
  1069. Operand m_base;
  1070. IdentifierTableIndex m_property;
  1071. };
  1072. class DeleteByIdWithThis final : public Instruction {
  1073. public:
  1074. DeleteByIdWithThis(Operand dst, Operand base, Operand this_value, IdentifierTableIndex property)
  1075. : Instruction(Type::DeleteByIdWithThis)
  1076. , m_dst(dst)
  1077. , m_base(base)
  1078. , m_this_value(this_value)
  1079. , m_property(property)
  1080. {
  1081. }
  1082. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1083. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1084. void visit_operands_impl(Function<void(Operand&)> visitor)
  1085. {
  1086. visitor(m_dst);
  1087. visitor(m_base);
  1088. visitor(m_this_value);
  1089. }
  1090. Operand dst() const { return m_dst; }
  1091. Operand base() const { return m_base; }
  1092. Operand this_value() const { return m_this_value; }
  1093. IdentifierTableIndex property() const { return m_property; }
  1094. private:
  1095. Operand m_dst;
  1096. Operand m_base;
  1097. Operand m_this_value;
  1098. IdentifierTableIndex m_property;
  1099. };
  1100. class GetByValue final : public Instruction {
  1101. public:
  1102. GetByValue(Operand dst, Operand base, Operand property, Optional<IdentifierTableIndex> base_identifier = {})
  1103. : Instruction(Type::GetByValue)
  1104. , m_dst(dst)
  1105. , m_base(base)
  1106. , m_property(property)
  1107. , m_base_identifier(move(base_identifier))
  1108. {
  1109. }
  1110. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1111. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1112. void visit_operands_impl(Function<void(Operand&)> visitor)
  1113. {
  1114. visitor(m_dst);
  1115. visitor(m_base);
  1116. visitor(m_property);
  1117. }
  1118. Operand dst() const { return m_dst; }
  1119. Operand base() const { return m_base; }
  1120. Operand property() const { return m_property; }
  1121. Optional<DeprecatedFlyString const&> base_identifier(Bytecode::Interpreter const&) const;
  1122. private:
  1123. Operand m_dst;
  1124. Operand m_base;
  1125. Operand m_property;
  1126. Optional<IdentifierTableIndex> m_base_identifier;
  1127. };
  1128. class GetByValueWithThis final : public Instruction {
  1129. public:
  1130. GetByValueWithThis(Operand dst, Operand base, Operand property, Operand this_value)
  1131. : Instruction(Type::GetByValueWithThis)
  1132. , m_dst(dst)
  1133. , m_base(base)
  1134. , m_property(property)
  1135. , m_this_value(this_value)
  1136. {
  1137. }
  1138. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1139. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1140. void visit_operands_impl(Function<void(Operand&)> visitor)
  1141. {
  1142. visitor(m_dst);
  1143. visitor(m_base);
  1144. visitor(m_property);
  1145. visitor(m_this_value);
  1146. }
  1147. Operand dst() const { return m_dst; }
  1148. Operand base() const { return m_base; }
  1149. Operand property() const { return m_property; }
  1150. Operand this_value() const { return m_this_value; }
  1151. private:
  1152. Operand m_dst;
  1153. Operand m_base;
  1154. Operand m_property;
  1155. Operand m_this_value;
  1156. };
  1157. class PutByValue final : public Instruction {
  1158. public:
  1159. PutByValue(Operand base, Operand property, Operand src, PropertyKind kind = PropertyKind::KeyValue, Optional<IdentifierTableIndex> base_identifier = {})
  1160. : Instruction(Type::PutByValue)
  1161. , m_base(base)
  1162. , m_property(property)
  1163. , m_src(src)
  1164. , m_kind(kind)
  1165. , m_base_identifier(move(base_identifier))
  1166. {
  1167. }
  1168. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1169. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1170. void visit_operands_impl(Function<void(Operand&)> visitor)
  1171. {
  1172. visitor(m_base);
  1173. visitor(m_property);
  1174. visitor(m_src);
  1175. }
  1176. Operand base() const { return m_base; }
  1177. Operand property() const { return m_property; }
  1178. Operand src() const { return m_src; }
  1179. PropertyKind kind() const { return m_kind; }
  1180. private:
  1181. Operand m_base;
  1182. Operand m_property;
  1183. Operand m_src;
  1184. PropertyKind m_kind;
  1185. Optional<IdentifierTableIndex> m_base_identifier;
  1186. };
  1187. class PutByValueWithThis final : public Instruction {
  1188. public:
  1189. PutByValueWithThis(Operand base, Operand property, Operand this_value, Operand src, PropertyKind kind = PropertyKind::KeyValue)
  1190. : Instruction(Type::PutByValueWithThis)
  1191. , m_base(base)
  1192. , m_property(property)
  1193. , m_this_value(this_value)
  1194. , m_src(src)
  1195. , m_kind(kind)
  1196. {
  1197. }
  1198. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1199. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1200. void visit_operands_impl(Function<void(Operand&)> visitor)
  1201. {
  1202. visitor(m_base);
  1203. visitor(m_property);
  1204. visitor(m_this_value);
  1205. visitor(m_src);
  1206. }
  1207. Operand base() const { return m_base; }
  1208. Operand property() const { return m_property; }
  1209. Operand this_value() const { return m_this_value; }
  1210. Operand src() const { return m_src; }
  1211. PropertyKind kind() const { return m_kind; }
  1212. private:
  1213. Operand m_base;
  1214. Operand m_property;
  1215. Operand m_this_value;
  1216. Operand m_src;
  1217. PropertyKind m_kind;
  1218. };
  1219. class DeleteByValue final : public Instruction {
  1220. public:
  1221. DeleteByValue(Operand dst, Operand base, Operand property)
  1222. : Instruction(Type::DeleteByValue)
  1223. , m_dst(dst)
  1224. , m_base(base)
  1225. , m_property(property)
  1226. {
  1227. }
  1228. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1229. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1230. void visit_operands_impl(Function<void(Operand&)> visitor)
  1231. {
  1232. visitor(m_dst);
  1233. visitor(m_base);
  1234. visitor(m_property);
  1235. }
  1236. Operand dst() const { return m_dst; }
  1237. Operand base() const { return m_base; }
  1238. Operand property() const { return m_property; }
  1239. private:
  1240. Operand m_dst;
  1241. Operand m_base;
  1242. Operand m_property;
  1243. };
  1244. class DeleteByValueWithThis final : public Instruction {
  1245. public:
  1246. DeleteByValueWithThis(Operand dst, Operand base, Operand this_value, Operand property)
  1247. : Instruction(Type::DeleteByValueWithThis)
  1248. , m_dst(dst)
  1249. , m_base(base)
  1250. , m_this_value(this_value)
  1251. , m_property(property)
  1252. {
  1253. }
  1254. Operand dst() const { return m_dst; }
  1255. Operand base() const { return m_base; }
  1256. Operand this_value() const { return m_this_value; }
  1257. Operand property() const { return m_property; }
  1258. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1259. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1260. void visit_operands_impl(Function<void(Operand&)> visitor)
  1261. {
  1262. visitor(m_dst);
  1263. visitor(m_base);
  1264. visitor(m_this_value);
  1265. visitor(m_property);
  1266. }
  1267. private:
  1268. Operand m_dst;
  1269. Operand m_base;
  1270. Operand m_this_value;
  1271. Operand m_property;
  1272. };
  1273. class Jump final : public Instruction {
  1274. public:
  1275. constexpr static bool IsTerminator = true;
  1276. explicit Jump(Label target)
  1277. : Instruction(Type::Jump)
  1278. , m_target(target)
  1279. {
  1280. }
  1281. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1282. void visit_labels_impl(Function<void(Label&)> visitor)
  1283. {
  1284. visitor(m_target);
  1285. }
  1286. auto& target() const { return m_target; }
  1287. protected:
  1288. Label m_target;
  1289. };
  1290. class JumpIf final : public Instruction {
  1291. public:
  1292. constexpr static bool IsTerminator = true;
  1293. explicit JumpIf(Operand condition, Label true_target, Label false_target)
  1294. : Instruction(Type::JumpIf)
  1295. , m_condition(condition)
  1296. , m_true_target(true_target)
  1297. , m_false_target(false_target)
  1298. {
  1299. }
  1300. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1301. void visit_labels_impl(Function<void(Label&)> visitor)
  1302. {
  1303. visitor(m_true_target);
  1304. visitor(m_false_target);
  1305. }
  1306. void visit_operands_impl(Function<void(Operand&)> visitor)
  1307. {
  1308. visitor(m_condition);
  1309. }
  1310. Operand condition() const { return m_condition; }
  1311. auto& true_target() const { return m_true_target; }
  1312. auto& false_target() const { return m_false_target; }
  1313. private:
  1314. Operand m_condition;
  1315. Label m_true_target;
  1316. Label m_false_target;
  1317. };
  1318. class JumpTrue final : public Instruction {
  1319. public:
  1320. constexpr static bool IsTerminator = true;
  1321. explicit JumpTrue(Operand condition, Label target)
  1322. : Instruction(Type::JumpTrue)
  1323. , m_condition(condition)
  1324. , m_target(target)
  1325. {
  1326. }
  1327. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1328. void visit_labels_impl(Function<void(Label&)> visitor)
  1329. {
  1330. visitor(m_target);
  1331. }
  1332. void visit_operands_impl(Function<void(Operand&)> visitor)
  1333. {
  1334. visitor(m_condition);
  1335. }
  1336. Operand condition() const { return m_condition; }
  1337. auto& target() const { return m_target; }
  1338. private:
  1339. Operand m_condition;
  1340. Label m_target;
  1341. };
  1342. class JumpFalse final : public Instruction {
  1343. public:
  1344. constexpr static bool IsTerminator = true;
  1345. explicit JumpFalse(Operand condition, Label target)
  1346. : Instruction(Type::JumpFalse)
  1347. , m_condition(condition)
  1348. , m_target(target)
  1349. {
  1350. }
  1351. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1352. void visit_labels_impl(Function<void(Label&)> visitor)
  1353. {
  1354. visitor(m_target);
  1355. }
  1356. void visit_operands_impl(Function<void(Operand&)> visitor)
  1357. {
  1358. visitor(m_condition);
  1359. }
  1360. Operand condition() const { return m_condition; }
  1361. auto& target() const { return m_target; }
  1362. private:
  1363. Operand m_condition;
  1364. Label m_target;
  1365. };
  1366. #define JS_ENUMERATE_COMPARISON_OPS(X) \
  1367. X(LessThan, less_than, <) \
  1368. X(LessThanEquals, less_than_equals, <=) \
  1369. X(GreaterThan, greater_than, >) \
  1370. X(GreaterThanEquals, greater_than_equals, >=) \
  1371. X(LooselyEquals, loosely_equals, ==) \
  1372. X(LooselyInequals, loosely_inequals, !=) \
  1373. X(StrictlyEquals, strict_equals, ==) \
  1374. X(StrictlyInequals, strict_inequals, !=)
  1375. #define DECLARE_COMPARISON_OP(op_TitleCase, op_snake_case, numeric_operator) \
  1376. class Jump##op_TitleCase final : public Instruction { \
  1377. public: \
  1378. constexpr static bool IsTerminator = true; \
  1379. \
  1380. explicit Jump##op_TitleCase(Operand lhs, Operand rhs, Label true_target, Label false_target) \
  1381. : Instruction(Type::Jump##op_TitleCase) \
  1382. , m_lhs(lhs) \
  1383. , m_rhs(rhs) \
  1384. , m_true_target(true_target) \
  1385. , m_false_target(false_target) \
  1386. { \
  1387. } \
  1388. \
  1389. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const; \
  1390. ByteString to_byte_string_impl(Bytecode::Executable const&) const; \
  1391. void visit_labels_impl(Function<void(Label&)> visitor) \
  1392. { \
  1393. visitor(m_true_target); \
  1394. visitor(m_false_target); \
  1395. } \
  1396. void visit_operands_impl(Function<void(Operand&)> visitor) \
  1397. { \
  1398. visitor(m_lhs); \
  1399. visitor(m_rhs); \
  1400. } \
  1401. \
  1402. Operand lhs() const { return m_lhs; } \
  1403. Operand rhs() const { return m_rhs; } \
  1404. auto& true_target() const { return m_true_target; } \
  1405. auto& false_target() const { return m_false_target; } \
  1406. \
  1407. private: \
  1408. Operand m_lhs; \
  1409. Operand m_rhs; \
  1410. Label m_true_target; \
  1411. Label m_false_target; \
  1412. };
  1413. JS_ENUMERATE_COMPARISON_OPS(DECLARE_COMPARISON_OP)
  1414. class JumpNullish final : public Instruction {
  1415. public:
  1416. constexpr static bool IsTerminator = true;
  1417. explicit JumpNullish(Operand condition, Label true_target, Label false_target)
  1418. : Instruction(Type::JumpNullish)
  1419. , m_condition(condition)
  1420. , m_true_target(true_target)
  1421. , m_false_target(false_target)
  1422. {
  1423. }
  1424. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1425. void visit_labels_impl(Function<void(Label&)> visitor)
  1426. {
  1427. visitor(m_true_target);
  1428. visitor(m_false_target);
  1429. }
  1430. void visit_operands_impl(Function<void(Operand&)> visitor)
  1431. {
  1432. visitor(m_condition);
  1433. }
  1434. Operand condition() const { return m_condition; }
  1435. auto& true_target() const { return m_true_target; }
  1436. auto& false_target() const { return m_false_target; }
  1437. private:
  1438. Operand m_condition;
  1439. Label m_true_target;
  1440. Label m_false_target;
  1441. };
  1442. class JumpUndefined final : public Instruction {
  1443. public:
  1444. constexpr static bool IsTerminator = true;
  1445. explicit JumpUndefined(Operand condition, Label true_target, Label false_target)
  1446. : Instruction(Type::JumpUndefined)
  1447. , m_condition(condition)
  1448. , m_true_target(true_target)
  1449. , m_false_target(false_target)
  1450. {
  1451. }
  1452. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1453. void visit_labels_impl(Function<void(Label&)> visitor)
  1454. {
  1455. visitor(m_true_target);
  1456. visitor(m_false_target);
  1457. }
  1458. void visit_operands_impl(Function<void(Operand&)> visitor)
  1459. {
  1460. visitor(m_condition);
  1461. }
  1462. Operand condition() const { return m_condition; }
  1463. auto& true_target() const { return m_true_target; }
  1464. auto& false_target() const { return m_false_target; }
  1465. private:
  1466. Operand m_condition;
  1467. Label m_true_target;
  1468. Label m_false_target;
  1469. };
  1470. enum class CallType : u8 {
  1471. Call,
  1472. Construct,
  1473. DirectEval,
  1474. };
  1475. class Call final : public Instruction {
  1476. public:
  1477. static constexpr bool IsVariableLength = true;
  1478. Call(CallType type, Operand dst, Operand callee, Operand this_value, ReadonlySpan<ScopedOperand> arguments, Optional<StringTableIndex> expression_string = {}, Optional<Builtin> builtin = {})
  1479. : Instruction(Type::Call)
  1480. , m_dst(dst)
  1481. , m_callee(callee)
  1482. , m_this_value(this_value)
  1483. , m_argument_count(arguments.size())
  1484. , m_type(type)
  1485. , m_builtin(builtin)
  1486. , m_expression_string(expression_string)
  1487. {
  1488. for (size_t i = 0; i < arguments.size(); ++i)
  1489. m_arguments[i] = arguments[i];
  1490. }
  1491. size_t length_impl() const
  1492. {
  1493. return round_up_to_power_of_two(alignof(void*), sizeof(*this) + sizeof(Operand) * m_argument_count);
  1494. }
  1495. CallType call_type() const { return m_type; }
  1496. Operand dst() const { return m_dst; }
  1497. Operand callee() const { return m_callee; }
  1498. Operand this_value() const { return m_this_value; }
  1499. Optional<StringTableIndex> const& expression_string() const { return m_expression_string; }
  1500. u32 argument_count() const { return m_argument_count; }
  1501. Optional<Builtin> const& builtin() const { return m_builtin; }
  1502. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1503. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1504. void visit_operands_impl(Function<void(Operand&)> visitor)
  1505. {
  1506. visitor(m_dst);
  1507. visitor(m_callee);
  1508. visitor(m_this_value);
  1509. for (size_t i = 0; i < m_argument_count; i++)
  1510. visitor(m_arguments[i]);
  1511. }
  1512. private:
  1513. Operand m_dst;
  1514. Operand m_callee;
  1515. Operand m_this_value;
  1516. u32 m_argument_count { 0 };
  1517. CallType m_type;
  1518. Optional<Builtin> m_builtin;
  1519. Optional<StringTableIndex> m_expression_string;
  1520. Operand m_arguments[];
  1521. };
  1522. class CallWithArgumentArray final : public Instruction {
  1523. public:
  1524. CallWithArgumentArray(CallType type, Operand dst, Operand callee, Operand this_value, Operand arguments, Optional<StringTableIndex> expression_string = {})
  1525. : Instruction(Type::CallWithArgumentArray)
  1526. , m_dst(dst)
  1527. , m_callee(callee)
  1528. , m_this_value(this_value)
  1529. , m_arguments(arguments)
  1530. , m_type(type)
  1531. , m_expression_string(expression_string)
  1532. {
  1533. }
  1534. Operand dst() const { return m_dst; }
  1535. CallType call_type() const { return m_type; }
  1536. Operand callee() const { return m_callee; }
  1537. Operand this_value() const { return m_this_value; }
  1538. Operand arguments() const { return m_arguments; }
  1539. Optional<StringTableIndex> const& expression_string() const { return m_expression_string; }
  1540. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1541. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1542. void visit_operands_impl(Function<void(Operand&)> visitor)
  1543. {
  1544. visitor(m_dst);
  1545. visitor(m_callee);
  1546. visitor(m_this_value);
  1547. visitor(m_arguments);
  1548. }
  1549. private:
  1550. Operand m_dst;
  1551. Operand m_callee;
  1552. Operand m_this_value;
  1553. Operand m_arguments;
  1554. CallType m_type;
  1555. Optional<StringTableIndex> m_expression_string;
  1556. };
  1557. class SuperCallWithArgumentArray : public Instruction {
  1558. public:
  1559. explicit SuperCallWithArgumentArray(Operand dst, Operand arguments, bool is_synthetic)
  1560. : Instruction(Type::SuperCallWithArgumentArray)
  1561. , m_dst(dst)
  1562. , m_arguments(arguments)
  1563. , m_is_synthetic(is_synthetic)
  1564. {
  1565. }
  1566. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1567. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1568. void visit_operands_impl(Function<void(Operand&)> visitor)
  1569. {
  1570. visitor(m_dst);
  1571. visitor(m_arguments);
  1572. }
  1573. Operand dst() const { return m_dst; }
  1574. Operand arguments() const { return m_arguments; }
  1575. bool is_synthetic() const { return m_is_synthetic; }
  1576. private:
  1577. Operand m_dst;
  1578. Operand m_arguments;
  1579. bool m_is_synthetic;
  1580. };
  1581. class NewClass final : public Instruction {
  1582. public:
  1583. static constexpr bool IsVariableLength = true;
  1584. explicit NewClass(Operand dst, Optional<Operand> super_class, ClassExpression const& class_expression, Optional<IdentifierTableIndex> lhs_name, ReadonlySpan<Optional<ScopedOperand>> elements_keys)
  1585. : Instruction(Type::NewClass)
  1586. , m_dst(dst)
  1587. , m_super_class(super_class)
  1588. , m_class_expression(class_expression)
  1589. , m_lhs_name(lhs_name)
  1590. , m_element_keys_count(elements_keys.size())
  1591. {
  1592. for (size_t i = 0; i < m_element_keys_count; i++) {
  1593. if (elements_keys[i].has_value())
  1594. m_element_keys[i] = elements_keys[i]->operand();
  1595. }
  1596. }
  1597. size_t length_impl() const
  1598. {
  1599. return round_up_to_power_of_two(alignof(void*), sizeof(*this) + sizeof(Optional<Operand>) * m_element_keys_count);
  1600. }
  1601. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1602. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1603. void visit_operands_impl(Function<void(Operand&)> visitor)
  1604. {
  1605. visitor(m_dst);
  1606. if (m_super_class.has_value())
  1607. visitor(m_super_class.value());
  1608. for (size_t i = 0; i < m_element_keys_count; i++) {
  1609. if (m_element_keys[i].has_value())
  1610. visitor(m_element_keys[i].value());
  1611. }
  1612. }
  1613. Operand dst() const { return m_dst; }
  1614. Optional<Operand> const& super_class() const { return m_super_class; }
  1615. ClassExpression const& class_expression() const { return m_class_expression; }
  1616. Optional<IdentifierTableIndex> const& lhs_name() const { return m_lhs_name; }
  1617. private:
  1618. Operand m_dst;
  1619. Optional<Operand> m_super_class;
  1620. ClassExpression const& m_class_expression;
  1621. Optional<IdentifierTableIndex> m_lhs_name;
  1622. size_t m_element_keys_count { 0 };
  1623. Optional<Operand> m_element_keys[];
  1624. };
  1625. class NewFunction final : public Instruction {
  1626. public:
  1627. explicit NewFunction(Operand dst, FunctionNode const& function_node, Optional<IdentifierTableIndex> lhs_name, Optional<Operand> home_object = {})
  1628. : Instruction(Type::NewFunction)
  1629. , m_dst(dst)
  1630. , m_function_node(function_node)
  1631. , m_lhs_name(lhs_name)
  1632. , m_home_object(move(home_object))
  1633. {
  1634. }
  1635. void execute_impl(Bytecode::Interpreter&) const;
  1636. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1637. void visit_operands_impl(Function<void(Operand&)> visitor)
  1638. {
  1639. visitor(m_dst);
  1640. if (m_home_object.has_value())
  1641. visitor(m_home_object.value());
  1642. }
  1643. Operand dst() const { return m_dst; }
  1644. FunctionNode const& function_node() const { return m_function_node; }
  1645. Optional<IdentifierTableIndex> const& lhs_name() const { return m_lhs_name; }
  1646. Optional<Operand> const& home_object() const { return m_home_object; }
  1647. private:
  1648. Operand m_dst;
  1649. FunctionNode const& m_function_node;
  1650. Optional<IdentifierTableIndex> m_lhs_name;
  1651. Optional<Operand> m_home_object;
  1652. };
  1653. class BlockDeclarationInstantiation final : public Instruction {
  1654. public:
  1655. explicit BlockDeclarationInstantiation(ScopeNode const& scope_node)
  1656. : Instruction(Type::BlockDeclarationInstantiation)
  1657. , m_scope_node(scope_node)
  1658. {
  1659. }
  1660. void execute_impl(Bytecode::Interpreter&) const;
  1661. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1662. ScopeNode const& scope_node() const { return m_scope_node; }
  1663. private:
  1664. ScopeNode const& m_scope_node;
  1665. };
  1666. class Return final : public Instruction {
  1667. public:
  1668. constexpr static bool IsTerminator = true;
  1669. explicit Return(Optional<Operand> value = {})
  1670. : Instruction(Type::Return)
  1671. , m_value(value)
  1672. {
  1673. }
  1674. void execute_impl(Bytecode::Interpreter&) const;
  1675. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1676. void visit_operands_impl(Function<void(Operand&)> visitor)
  1677. {
  1678. if (m_value.has_value())
  1679. visitor(m_value.value());
  1680. }
  1681. Optional<Operand> const& value() const { return m_value; }
  1682. private:
  1683. Optional<Operand> m_value;
  1684. };
  1685. class Increment final : public Instruction {
  1686. public:
  1687. explicit Increment(Operand dst)
  1688. : Instruction(Type::Increment)
  1689. , m_dst(dst)
  1690. {
  1691. }
  1692. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1693. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1694. void visit_operands_impl(Function<void(Operand&)> visitor)
  1695. {
  1696. visitor(m_dst);
  1697. }
  1698. Operand dst() const { return m_dst; }
  1699. private:
  1700. Operand m_dst;
  1701. };
  1702. class PostfixIncrement final : public Instruction {
  1703. public:
  1704. explicit PostfixIncrement(Operand dst, Operand src)
  1705. : Instruction(Type::PostfixIncrement)
  1706. , m_dst(dst)
  1707. , m_src(src)
  1708. {
  1709. }
  1710. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1711. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1712. void visit_operands_impl(Function<void(Operand&)> visitor)
  1713. {
  1714. visitor(m_dst);
  1715. visitor(m_src);
  1716. }
  1717. Operand dst() const { return m_dst; }
  1718. Operand src() const { return m_src; }
  1719. private:
  1720. Operand m_dst;
  1721. Operand m_src;
  1722. };
  1723. class Decrement final : public Instruction {
  1724. public:
  1725. explicit Decrement(Operand dst)
  1726. : Instruction(Type::Decrement)
  1727. , m_dst(dst)
  1728. {
  1729. }
  1730. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1731. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1732. void visit_operands_impl(Function<void(Operand&)> visitor)
  1733. {
  1734. visitor(m_dst);
  1735. }
  1736. Operand dst() const { return m_dst; }
  1737. private:
  1738. Operand m_dst;
  1739. };
  1740. class PostfixDecrement final : public Instruction {
  1741. public:
  1742. explicit PostfixDecrement(Operand dst, Operand src)
  1743. : Instruction(Type::PostfixDecrement)
  1744. , m_dst(dst)
  1745. , m_src(src)
  1746. {
  1747. }
  1748. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1749. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1750. void visit_operands_impl(Function<void(Operand&)> visitor)
  1751. {
  1752. visitor(m_dst);
  1753. visitor(m_src);
  1754. }
  1755. Operand dst() const { return m_dst; }
  1756. Operand src() const { return m_src; }
  1757. private:
  1758. Operand m_dst;
  1759. Operand m_src;
  1760. };
  1761. class Throw final : public Instruction {
  1762. public:
  1763. constexpr static bool IsTerminator = true;
  1764. explicit Throw(Operand src)
  1765. : Instruction(Type::Throw)
  1766. , m_src(src)
  1767. {
  1768. }
  1769. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1770. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1771. void visit_operands_impl(Function<void(Operand&)> visitor)
  1772. {
  1773. visitor(m_src);
  1774. }
  1775. Operand src() const { return m_src; }
  1776. private:
  1777. Operand m_src;
  1778. };
  1779. class ThrowIfNotObject final : public Instruction {
  1780. public:
  1781. ThrowIfNotObject(Operand src)
  1782. : Instruction(Type::ThrowIfNotObject)
  1783. , m_src(src)
  1784. {
  1785. }
  1786. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1787. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1788. void visit_operands_impl(Function<void(Operand&)> visitor)
  1789. {
  1790. visitor(m_src);
  1791. }
  1792. Operand src() const { return m_src; }
  1793. private:
  1794. Operand m_src;
  1795. };
  1796. class ThrowIfNullish final : public Instruction {
  1797. public:
  1798. explicit ThrowIfNullish(Operand src)
  1799. : Instruction(Type::ThrowIfNullish)
  1800. , m_src(src)
  1801. {
  1802. }
  1803. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1804. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1805. void visit_operands_impl(Function<void(Operand&)> visitor)
  1806. {
  1807. visitor(m_src);
  1808. }
  1809. Operand src() const { return m_src; }
  1810. private:
  1811. Operand m_src;
  1812. };
  1813. class ThrowIfTDZ final : public Instruction {
  1814. public:
  1815. explicit ThrowIfTDZ(Operand src)
  1816. : Instruction(Type::ThrowIfTDZ)
  1817. , m_src(src)
  1818. {
  1819. }
  1820. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1821. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1822. void visit_operands_impl(Function<void(Operand&)> visitor)
  1823. {
  1824. visitor(m_src);
  1825. }
  1826. Operand src() const { return m_src; }
  1827. private:
  1828. Operand m_src;
  1829. };
  1830. class EnterUnwindContext final : public Instruction {
  1831. public:
  1832. constexpr static bool IsTerminator = true;
  1833. EnterUnwindContext(Label entry_point)
  1834. : Instruction(Type::EnterUnwindContext)
  1835. , m_entry_point(move(entry_point))
  1836. {
  1837. }
  1838. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1839. void visit_labels_impl(Function<void(Label&)> visitor)
  1840. {
  1841. visitor(m_entry_point);
  1842. }
  1843. auto& entry_point() const { return m_entry_point; }
  1844. private:
  1845. Label m_entry_point;
  1846. };
  1847. class ScheduleJump final : public Instruction {
  1848. public:
  1849. // Note: We use this instruction to tell the next `finally` block to
  1850. // continue execution with a specific break/continue target;
  1851. constexpr static bool IsTerminator = true;
  1852. ScheduleJump(Label target)
  1853. : Instruction(Type::ScheduleJump)
  1854. , m_target(target)
  1855. {
  1856. }
  1857. Label target() const { return m_target; }
  1858. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1859. void visit_labels_impl(Function<void(Label&)> visitor)
  1860. {
  1861. visitor(m_target);
  1862. }
  1863. private:
  1864. Label m_target;
  1865. };
  1866. class LeaveLexicalEnvironment final : public Instruction {
  1867. public:
  1868. LeaveLexicalEnvironment()
  1869. : Instruction(Type::LeaveLexicalEnvironment)
  1870. {
  1871. }
  1872. void execute_impl(Bytecode::Interpreter&) const;
  1873. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1874. };
  1875. class LeavePrivateEnvironment final : public Instruction {
  1876. public:
  1877. LeavePrivateEnvironment()
  1878. : Instruction(Type::LeavePrivateEnvironment)
  1879. {
  1880. }
  1881. void execute_impl(Bytecode::Interpreter&) const;
  1882. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1883. };
  1884. class LeaveUnwindContext final : public Instruction {
  1885. public:
  1886. LeaveUnwindContext()
  1887. : Instruction(Type::LeaveUnwindContext)
  1888. {
  1889. }
  1890. void execute_impl(Bytecode::Interpreter&) const;
  1891. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1892. };
  1893. class ContinuePendingUnwind final : public Instruction {
  1894. public:
  1895. constexpr static bool IsTerminator = true;
  1896. explicit ContinuePendingUnwind(Label resume_target)
  1897. : Instruction(Type::ContinuePendingUnwind)
  1898. , m_resume_target(resume_target)
  1899. {
  1900. }
  1901. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1902. void visit_labels_impl(Function<void(Label&)> visitor)
  1903. {
  1904. visitor(m_resume_target);
  1905. }
  1906. auto& resume_target() const { return m_resume_target; }
  1907. private:
  1908. Label m_resume_target;
  1909. };
  1910. class Yield final : public Instruction {
  1911. public:
  1912. constexpr static bool IsTerminator = true;
  1913. explicit Yield(Label continuation_label, Operand value)
  1914. : Instruction(Type::Yield)
  1915. , m_continuation_label(continuation_label)
  1916. , m_value(value)
  1917. {
  1918. }
  1919. explicit Yield(nullptr_t, Operand value)
  1920. : Instruction(Type::Yield)
  1921. , m_value(value)
  1922. {
  1923. }
  1924. void execute_impl(Bytecode::Interpreter&) const;
  1925. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1926. void visit_labels_impl(Function<void(Label&)> visitor)
  1927. {
  1928. if (m_continuation_label.has_value())
  1929. visitor(m_continuation_label.value());
  1930. }
  1931. void visit_operands_impl(Function<void(Operand&)> visitor)
  1932. {
  1933. visitor(m_value);
  1934. }
  1935. auto& continuation() const { return m_continuation_label; }
  1936. Operand value() const { return m_value; }
  1937. private:
  1938. Optional<Label> m_continuation_label;
  1939. Operand m_value;
  1940. };
  1941. class PrepareYield final : public Instruction {
  1942. public:
  1943. explicit PrepareYield(Operand dest, Operand value)
  1944. : Instruction(Type::PrepareYield)
  1945. , m_dest(dest)
  1946. , m_value(value)
  1947. {
  1948. }
  1949. void execute_impl(Bytecode::Interpreter&) const;
  1950. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1951. void visit_operands_impl(Function<void(Operand&)> visitor)
  1952. {
  1953. visitor(m_dest);
  1954. visitor(m_value);
  1955. }
  1956. Operand destination() const { return m_dest; }
  1957. Operand value() const { return m_value; }
  1958. private:
  1959. Operand m_dest;
  1960. Operand m_value;
  1961. };
  1962. class Await final : public Instruction {
  1963. public:
  1964. constexpr static bool IsTerminator = true;
  1965. explicit Await(Label continuation_label, Operand argument)
  1966. : Instruction(Type::Await)
  1967. , m_continuation_label(continuation_label)
  1968. , m_argument(argument)
  1969. {
  1970. }
  1971. void execute_impl(Bytecode::Interpreter&) const;
  1972. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1973. void visit_labels_impl(Function<void(Label&)> visitor)
  1974. {
  1975. visitor(m_continuation_label);
  1976. }
  1977. void visit_operands_impl(Function<void(Operand&)> visitor)
  1978. {
  1979. visitor(m_argument);
  1980. }
  1981. auto& continuation() const { return m_continuation_label; }
  1982. Operand argument() const { return m_argument; }
  1983. private:
  1984. Label m_continuation_label;
  1985. Operand m_argument;
  1986. };
  1987. class GetIterator final : public Instruction {
  1988. public:
  1989. GetIterator(Operand dst, Operand iterable, IteratorHint hint = IteratorHint::Sync)
  1990. : Instruction(Type::GetIterator)
  1991. , m_dst(dst)
  1992. , m_iterable(iterable)
  1993. , m_hint(hint)
  1994. {
  1995. }
  1996. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1997. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  1998. void visit_operands_impl(Function<void(Operand&)> visitor)
  1999. {
  2000. visitor(m_dst);
  2001. visitor(m_iterable);
  2002. }
  2003. Operand dst() const { return m_dst; }
  2004. Operand iterable() const { return m_iterable; }
  2005. IteratorHint hint() const { return m_hint; }
  2006. private:
  2007. Operand m_dst;
  2008. Operand m_iterable;
  2009. IteratorHint m_hint { IteratorHint::Sync };
  2010. };
  2011. class GetObjectFromIteratorRecord final : public Instruction {
  2012. public:
  2013. GetObjectFromIteratorRecord(Operand object, Operand iterator_record)
  2014. : Instruction(Type::GetObjectFromIteratorRecord)
  2015. , m_object(object)
  2016. , m_iterator_record(iterator_record)
  2017. {
  2018. }
  2019. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  2020. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2021. void visit_operands_impl(Function<void(Operand&)> visitor)
  2022. {
  2023. visitor(m_object);
  2024. visitor(m_iterator_record);
  2025. }
  2026. Operand object() const { return m_object; }
  2027. Operand iterator_record() const { return m_iterator_record; }
  2028. private:
  2029. Operand m_object;
  2030. Operand m_iterator_record;
  2031. };
  2032. class GetNextMethodFromIteratorRecord final : public Instruction {
  2033. public:
  2034. GetNextMethodFromIteratorRecord(Operand next_method, Operand iterator_record)
  2035. : Instruction(Type::GetNextMethodFromIteratorRecord)
  2036. , m_next_method(next_method)
  2037. , m_iterator_record(iterator_record)
  2038. {
  2039. }
  2040. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  2041. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2042. void visit_operands_impl(Function<void(Operand&)> visitor)
  2043. {
  2044. visitor(m_next_method);
  2045. visitor(m_iterator_record);
  2046. }
  2047. Operand next_method() const { return m_next_method; }
  2048. Operand iterator_record() const { return m_iterator_record; }
  2049. private:
  2050. Operand m_next_method;
  2051. Operand m_iterator_record;
  2052. };
  2053. class GetMethod final : public Instruction {
  2054. public:
  2055. GetMethod(Operand dst, Operand object, IdentifierTableIndex property)
  2056. : Instruction(Type::GetMethod)
  2057. , m_dst(dst)
  2058. , m_object(object)
  2059. , m_property(property)
  2060. {
  2061. }
  2062. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  2063. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2064. void visit_operands_impl(Function<void(Operand&)> visitor)
  2065. {
  2066. visitor(m_dst);
  2067. visitor(m_object);
  2068. }
  2069. Operand dst() const { return m_dst; }
  2070. Operand object() const { return m_object; }
  2071. IdentifierTableIndex property() const { return m_property; }
  2072. private:
  2073. Operand m_dst;
  2074. Operand m_object;
  2075. IdentifierTableIndex m_property;
  2076. };
  2077. class GetObjectPropertyIterator final : public Instruction {
  2078. public:
  2079. GetObjectPropertyIterator(Operand dst, Operand object)
  2080. : Instruction(Type::GetObjectPropertyIterator)
  2081. , m_dst(dst)
  2082. , m_object(object)
  2083. {
  2084. }
  2085. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  2086. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2087. void visit_operands_impl(Function<void(Operand&)> visitor)
  2088. {
  2089. visitor(m_dst);
  2090. visitor(m_object);
  2091. }
  2092. Operand dst() const { return m_dst; }
  2093. Operand object() const { return m_object; }
  2094. private:
  2095. Operand m_dst;
  2096. Operand m_object;
  2097. };
  2098. class IteratorClose final : public Instruction {
  2099. public:
  2100. IteratorClose(Operand iterator_record, Completion::Type completion_type, Optional<Value> completion_value)
  2101. : Instruction(Type::IteratorClose)
  2102. , m_iterator_record(iterator_record)
  2103. , m_completion_type(completion_type)
  2104. , m_completion_value(completion_value)
  2105. {
  2106. }
  2107. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  2108. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2109. void visit_operands_impl(Function<void(Operand&)> visitor)
  2110. {
  2111. visitor(m_iterator_record);
  2112. }
  2113. Operand iterator_record() const { return m_iterator_record; }
  2114. Completion::Type completion_type() const { return m_completion_type; }
  2115. Optional<Value> const& completion_value() const { return m_completion_value; }
  2116. private:
  2117. Operand m_iterator_record;
  2118. Completion::Type m_completion_type { Completion::Type::Normal };
  2119. Optional<Value> m_completion_value;
  2120. };
  2121. class AsyncIteratorClose final : public Instruction {
  2122. public:
  2123. AsyncIteratorClose(Operand iterator_record, Completion::Type completion_type, Optional<Value> completion_value)
  2124. : Instruction(Type::AsyncIteratorClose)
  2125. , m_iterator_record(iterator_record)
  2126. , m_completion_type(completion_type)
  2127. , m_completion_value(completion_value)
  2128. {
  2129. }
  2130. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  2131. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2132. void visit_operands_impl(Function<void(Operand&)> visitor)
  2133. {
  2134. visitor(m_iterator_record);
  2135. }
  2136. Operand iterator_record() const { return m_iterator_record; }
  2137. Completion::Type completion_type() const { return m_completion_type; }
  2138. Optional<Value> const& completion_value() const { return m_completion_value; }
  2139. private:
  2140. Operand m_iterator_record;
  2141. Completion::Type m_completion_type { Completion::Type::Normal };
  2142. Optional<Value> m_completion_value;
  2143. };
  2144. class IteratorNext final : public Instruction {
  2145. public:
  2146. IteratorNext(Operand dst, Operand iterator_record)
  2147. : Instruction(Type::IteratorNext)
  2148. , m_dst(dst)
  2149. , m_iterator_record(iterator_record)
  2150. {
  2151. }
  2152. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  2153. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2154. void visit_operands_impl(Function<void(Operand&)> visitor)
  2155. {
  2156. visitor(m_dst);
  2157. visitor(m_iterator_record);
  2158. }
  2159. Operand dst() const { return m_dst; }
  2160. Operand iterator_record() const { return m_iterator_record; }
  2161. private:
  2162. Operand m_dst;
  2163. Operand m_iterator_record;
  2164. };
  2165. class ResolveThisBinding final : public Instruction {
  2166. public:
  2167. ResolveThisBinding()
  2168. : Instruction(Type::ResolveThisBinding)
  2169. {
  2170. }
  2171. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  2172. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2173. void visit_operands_impl(Function<void(Operand&)>) { }
  2174. };
  2175. class ResolveSuperBase final : public Instruction {
  2176. public:
  2177. explicit ResolveSuperBase(Operand dst)
  2178. : Instruction(Type::ResolveSuperBase)
  2179. , m_dst(dst)
  2180. {
  2181. }
  2182. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  2183. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2184. void visit_operands_impl(Function<void(Operand&)> visitor)
  2185. {
  2186. visitor(m_dst);
  2187. }
  2188. Operand dst() const { return m_dst; }
  2189. private:
  2190. Operand m_dst;
  2191. };
  2192. class GetNewTarget final : public Instruction {
  2193. public:
  2194. explicit GetNewTarget(Operand dst)
  2195. : Instruction(Type::GetNewTarget)
  2196. , m_dst(dst)
  2197. {
  2198. }
  2199. void execute_impl(Bytecode::Interpreter&) const;
  2200. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2201. void visit_operands_impl(Function<void(Operand&)> visitor)
  2202. {
  2203. visitor(m_dst);
  2204. }
  2205. Operand dst() const { return m_dst; }
  2206. private:
  2207. Operand m_dst;
  2208. };
  2209. class GetImportMeta final : public Instruction {
  2210. public:
  2211. explicit GetImportMeta(Operand dst)
  2212. : Instruction(Type::GetImportMeta)
  2213. , m_dst(dst)
  2214. {
  2215. }
  2216. void execute_impl(Bytecode::Interpreter&) const;
  2217. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2218. void visit_operands_impl(Function<void(Operand&)> visitor)
  2219. {
  2220. visitor(m_dst);
  2221. }
  2222. Operand dst() const { return m_dst; }
  2223. private:
  2224. Operand m_dst;
  2225. };
  2226. class TypeofVariable final : public Instruction {
  2227. public:
  2228. TypeofVariable(Operand dst, IdentifierTableIndex identifier)
  2229. : Instruction(Type::TypeofVariable)
  2230. , m_dst(dst)
  2231. , m_identifier(identifier)
  2232. {
  2233. }
  2234. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  2235. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2236. void visit_operands_impl(Function<void(Operand&)> visitor)
  2237. {
  2238. visitor(m_dst);
  2239. }
  2240. Operand dst() const { return m_dst; }
  2241. IdentifierTableIndex identifier() const { return m_identifier; }
  2242. private:
  2243. Operand m_dst;
  2244. IdentifierTableIndex m_identifier;
  2245. };
  2246. class End final : public Instruction {
  2247. public:
  2248. constexpr static bool IsTerminator = true;
  2249. explicit End(Operand value)
  2250. : Instruction(Type::End)
  2251. , m_value(value)
  2252. {
  2253. }
  2254. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2255. void visit_operands_impl(Function<void(Operand&)> visitor)
  2256. {
  2257. visitor(m_value);
  2258. }
  2259. Operand value() const { return m_value; }
  2260. private:
  2261. Operand m_value;
  2262. };
  2263. class Dump final : public Instruction {
  2264. public:
  2265. explicit Dump(StringView text, Operand value)
  2266. : Instruction(Type::Dump)
  2267. , m_text(text)
  2268. , m_value(value)
  2269. {
  2270. }
  2271. void execute_impl(Bytecode::Interpreter&) const;
  2272. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2273. void visit_operands_impl(Function<void(Operand&)> visitor)
  2274. {
  2275. visitor(m_value);
  2276. }
  2277. private:
  2278. StringView m_text;
  2279. Operand m_value;
  2280. };
  2281. }