Op.h 81 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694
  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 TypeofBinding final : public Instruction {
  2227. public:
  2228. TypeofBinding(Operand dst, IdentifierTableIndex identifier)
  2229. : Instruction(Type::TypeofBinding)
  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. mutable EnvironmentCoordinate m_cache;
  2246. };
  2247. class End final : public Instruction {
  2248. public:
  2249. constexpr static bool IsTerminator = true;
  2250. explicit End(Operand value)
  2251. : Instruction(Type::End)
  2252. , m_value(value)
  2253. {
  2254. }
  2255. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2256. void visit_operands_impl(Function<void(Operand&)> visitor)
  2257. {
  2258. visitor(m_value);
  2259. }
  2260. Operand value() const { return m_value; }
  2261. private:
  2262. Operand m_value;
  2263. };
  2264. class Dump final : public Instruction {
  2265. public:
  2266. explicit Dump(StringView text, Operand value)
  2267. : Instruction(Type::Dump)
  2268. , m_text(text)
  2269. , m_value(value)
  2270. {
  2271. }
  2272. void execute_impl(Bytecode::Interpreter&) const;
  2273. ByteString to_byte_string_impl(Bytecode::Executable const&) const;
  2274. void visit_operands_impl(Function<void(Operand&)> visitor)
  2275. {
  2276. visitor(m_value);
  2277. }
  2278. private:
  2279. StringView m_text;
  2280. Operand m_value;
  2281. };
  2282. }