Op.h 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274
  1. /*
  2. * Copyright (c) 2021, 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/StdLibExtras.h>
  10. #include <LibCrypto/BigInt/SignedBigInteger.h>
  11. #include <LibJS/Bytecode/IdentifierTable.h>
  12. #include <LibJS/Bytecode/Instruction.h>
  13. #include <LibJS/Bytecode/Label.h>
  14. #include <LibJS/Bytecode/Register.h>
  15. #include <LibJS/Bytecode/StringTable.h>
  16. #include <LibJS/Heap/Cell.h>
  17. #include <LibJS/Runtime/Environment.h>
  18. #include <LibJS/Runtime/EnvironmentCoordinate.h>
  19. #include <LibJS/Runtime/Value.h>
  20. #include <LibJS/Runtime/ValueTraits.h>
  21. namespace JS::Bytecode::Op {
  22. class Load final : public Instruction {
  23. public:
  24. explicit Load(Register src)
  25. : Instruction(Type::Load)
  26. , m_src(src)
  27. {
  28. }
  29. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  30. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  31. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  32. void replace_references_impl(Register from, Register to)
  33. {
  34. if (m_src == from)
  35. m_src = to;
  36. }
  37. private:
  38. Register m_src;
  39. };
  40. class LoadImmediate final : public Instruction {
  41. public:
  42. explicit LoadImmediate(Value value)
  43. : Instruction(Type::LoadImmediate)
  44. , m_value(value)
  45. {
  46. }
  47. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  48. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  49. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  50. void replace_references_impl(Register, Register) { }
  51. private:
  52. Value m_value;
  53. };
  54. class Store final : public Instruction {
  55. public:
  56. explicit Store(Register dst)
  57. : Instruction(Type::Store)
  58. , m_dst(dst)
  59. {
  60. }
  61. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  62. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  63. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  64. void replace_references_impl(Register, Register) { }
  65. Register dst() const { return m_dst; }
  66. private:
  67. Register m_dst;
  68. };
  69. #define JS_ENUMERATE_COMMON_BINARY_OPS(O) \
  70. O(Add, add) \
  71. O(Sub, sub) \
  72. O(Mul, mul) \
  73. O(Div, div) \
  74. O(Exp, exp) \
  75. O(Mod, mod) \
  76. O(In, in) \
  77. O(InstanceOf, instance_of) \
  78. O(GreaterThan, greater_than) \
  79. O(GreaterThanEquals, greater_than_equals) \
  80. O(LessThan, less_than) \
  81. O(LessThanEquals, less_than_equals) \
  82. O(LooselyInequals, abstract_inequals) \
  83. O(LooselyEquals, abstract_equals) \
  84. O(StrictlyInequals, typed_inequals) \
  85. O(StrictlyEquals, typed_equals) \
  86. O(BitwiseAnd, bitwise_and) \
  87. O(BitwiseOr, bitwise_or) \
  88. O(BitwiseXor, bitwise_xor) \
  89. O(LeftShift, left_shift) \
  90. O(RightShift, right_shift) \
  91. O(UnsignedRightShift, unsigned_right_shift)
  92. #define JS_DECLARE_COMMON_BINARY_OP(OpTitleCase, op_snake_case) \
  93. class OpTitleCase final : public Instruction { \
  94. public: \
  95. explicit OpTitleCase(Register lhs_reg) \
  96. : Instruction(Type::OpTitleCase) \
  97. , m_lhs_reg(lhs_reg) \
  98. { \
  99. } \
  100. \
  101. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const; \
  102. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const; \
  103. void replace_references_impl(BasicBlock const&, BasicBlock const&) \
  104. { \
  105. } \
  106. void replace_references_impl(Register from, Register to) \
  107. { \
  108. if (m_lhs_reg == from) \
  109. m_lhs_reg = to; \
  110. } \
  111. \
  112. private: \
  113. Register m_lhs_reg; \
  114. };
  115. JS_ENUMERATE_COMMON_BINARY_OPS(JS_DECLARE_COMMON_BINARY_OP)
  116. #undef JS_DECLARE_COMMON_BINARY_OP
  117. #define JS_ENUMERATE_COMMON_UNARY_OPS(O) \
  118. O(BitwiseNot, bitwise_not) \
  119. O(Not, not_) \
  120. O(UnaryPlus, unary_plus) \
  121. O(UnaryMinus, unary_minus) \
  122. O(Typeof, typeof_)
  123. #define JS_DECLARE_COMMON_UNARY_OP(OpTitleCase, op_snake_case) \
  124. class OpTitleCase final : public Instruction { \
  125. public: \
  126. OpTitleCase() \
  127. : Instruction(Type::OpTitleCase) \
  128. { \
  129. } \
  130. \
  131. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const; \
  132. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const; \
  133. void replace_references_impl(BasicBlock const&, BasicBlock const&) \
  134. { \
  135. } \
  136. void replace_references_impl(Register, Register) \
  137. { \
  138. } \
  139. };
  140. JS_ENUMERATE_COMMON_UNARY_OPS(JS_DECLARE_COMMON_UNARY_OP)
  141. #undef JS_DECLARE_COMMON_UNARY_OP
  142. class NewString final : public Instruction {
  143. public:
  144. explicit NewString(StringTableIndex string)
  145. : Instruction(Type::NewString)
  146. , m_string(string)
  147. {
  148. }
  149. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  150. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  151. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  152. void replace_references_impl(Register, Register) { }
  153. private:
  154. StringTableIndex m_string;
  155. };
  156. class NewObject final : public Instruction {
  157. public:
  158. NewObject()
  159. : Instruction(Type::NewObject)
  160. {
  161. }
  162. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  163. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  164. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  165. void replace_references_impl(Register, Register) { }
  166. };
  167. class NewRegExp final : public Instruction {
  168. public:
  169. NewRegExp(StringTableIndex source_index, StringTableIndex flags_index)
  170. : Instruction(Type::NewRegExp)
  171. , m_source_index(source_index)
  172. , m_flags_index(flags_index)
  173. {
  174. }
  175. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  176. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  177. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  178. void replace_references_impl(Register, Register) { }
  179. private:
  180. StringTableIndex m_source_index;
  181. StringTableIndex m_flags_index;
  182. };
  183. #define JS_ENUMERATE_NEW_BUILTIN_ERROR_OPS(O) \
  184. O(TypeError)
  185. #define JS_DECLARE_NEW_BUILTIN_ERROR_OP(ErrorName) \
  186. class New##ErrorName final : public Instruction { \
  187. public: \
  188. explicit New##ErrorName(StringTableIndex error_string) \
  189. : Instruction(Type::New##ErrorName) \
  190. , m_error_string(error_string) \
  191. { \
  192. } \
  193. \
  194. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const; \
  195. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const; \
  196. void replace_references_impl(BasicBlock const&, BasicBlock const&) \
  197. { \
  198. } \
  199. void replace_references_impl(Register, Register) \
  200. { \
  201. } \
  202. \
  203. private: \
  204. StringTableIndex m_error_string; \
  205. };
  206. JS_ENUMERATE_NEW_BUILTIN_ERROR_OPS(JS_DECLARE_NEW_BUILTIN_ERROR_OP)
  207. #undef JS_DECLARE_NEW_BUILTIN_ERROR_OP
  208. // NOTE: This instruction is variable-width depending on the number of excluded names
  209. class CopyObjectExcludingProperties final : public Instruction {
  210. public:
  211. CopyObjectExcludingProperties(Register from_object, Vector<Register> const& excluded_names)
  212. : Instruction(Type::CopyObjectExcludingProperties)
  213. , m_from_object(from_object)
  214. , m_excluded_names_count(excluded_names.size())
  215. {
  216. for (size_t i = 0; i < m_excluded_names_count; i++)
  217. m_excluded_names[i] = excluded_names[i];
  218. }
  219. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  220. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  221. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  222. void replace_references_impl(Register from, Register to);
  223. size_t length_impl() const { return sizeof(*this) + sizeof(Register) * m_excluded_names_count; }
  224. private:
  225. Register m_from_object;
  226. size_t m_excluded_names_count { 0 };
  227. Register m_excluded_names[];
  228. };
  229. class NewBigInt final : public Instruction {
  230. public:
  231. explicit NewBigInt(Crypto::SignedBigInteger bigint)
  232. : Instruction(Type::NewBigInt)
  233. , m_bigint(move(bigint))
  234. {
  235. }
  236. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  237. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  238. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  239. void replace_references_impl(Register, Register) { }
  240. private:
  241. Crypto::SignedBigInteger m_bigint;
  242. };
  243. // NOTE: This instruction is variable-width depending on the number of elements!
  244. class NewArray final : public Instruction {
  245. public:
  246. NewArray()
  247. : Instruction(Type::NewArray)
  248. , m_element_count(0)
  249. {
  250. }
  251. explicit NewArray(AK::Array<Register, 2> const& elements_range)
  252. : Instruction(Type::NewArray)
  253. , m_element_count(elements_range[1].index() - elements_range[0].index() + 1)
  254. {
  255. m_elements[0] = elements_range[0];
  256. m_elements[1] = elements_range[1];
  257. }
  258. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  259. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  260. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  261. // Note: The underlying element range shall never be changed item, by item
  262. // shifting it may be done in the future
  263. void replace_references_impl(Register from, Register) { VERIFY(!m_element_count || from.index() < start().index() || from.index() > end().index()); }
  264. size_t length_impl() const
  265. {
  266. return sizeof(*this) + sizeof(Register) * (m_element_count == 0 ? 0 : 2);
  267. }
  268. Register start() const
  269. {
  270. VERIFY(m_element_count);
  271. return m_elements[0];
  272. }
  273. Register end() const
  274. {
  275. VERIFY(m_element_count);
  276. return m_elements[1];
  277. }
  278. size_t element_count() const { return m_element_count; }
  279. private:
  280. size_t m_element_count { 0 };
  281. Register m_elements[];
  282. };
  283. class Append final : public Instruction {
  284. public:
  285. Append(Register lhs, bool is_spread)
  286. : Instruction(Type::Append)
  287. , m_lhs(lhs)
  288. , m_is_spread(is_spread)
  289. {
  290. }
  291. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  292. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  293. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  294. // Note: This should never do anything, the lhs should always be an array, that is currently being constructed
  295. void replace_references_impl(Register from, Register) { VERIFY(from != m_lhs); }
  296. private:
  297. Register m_lhs;
  298. bool m_is_spread = false;
  299. };
  300. class IteratorToArray final : public Instruction {
  301. public:
  302. IteratorToArray()
  303. : Instruction(Type::IteratorToArray)
  304. {
  305. }
  306. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  307. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  308. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  309. void replace_references_impl(Register, Register) { }
  310. };
  311. class ConcatString final : public Instruction {
  312. public:
  313. explicit ConcatString(Register lhs)
  314. : Instruction(Type::ConcatString)
  315. , m_lhs(lhs)
  316. {
  317. }
  318. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  319. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  320. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  321. // Note: lhs should always be a string in construction, so this should never do anything
  322. void replace_references_impl(Register from, Register) { VERIFY(from != m_lhs); }
  323. private:
  324. Register m_lhs;
  325. };
  326. enum class EnvironmentMode {
  327. Lexical,
  328. Var,
  329. };
  330. class CreateEnvironment final : public Instruction {
  331. public:
  332. explicit CreateEnvironment(EnvironmentMode mode)
  333. : Instruction(Type::CreateEnvironment)
  334. , m_mode(mode)
  335. {
  336. }
  337. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  338. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  339. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  340. void replace_references_impl(Register, Register) { }
  341. private:
  342. EnvironmentMode m_mode { EnvironmentMode::Lexical };
  343. };
  344. class EnterObjectEnvironment final : public Instruction {
  345. public:
  346. explicit EnterObjectEnvironment()
  347. : Instruction(Type::EnterObjectEnvironment)
  348. {
  349. }
  350. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  351. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  352. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  353. void replace_references_impl(Register, Register) { }
  354. };
  355. class CreateVariable final : public Instruction {
  356. public:
  357. explicit CreateVariable(IdentifierTableIndex identifier, EnvironmentMode mode, bool is_immutable, bool is_global = false)
  358. : Instruction(Type::CreateVariable)
  359. , m_identifier(identifier)
  360. , m_mode(mode)
  361. , m_is_immutable(is_immutable)
  362. , m_is_global(is_global)
  363. {
  364. }
  365. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  366. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  367. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  368. void replace_references_impl(Register, Register) { }
  369. private:
  370. IdentifierTableIndex m_identifier;
  371. EnvironmentMode m_mode;
  372. bool m_is_immutable : 4 { false };
  373. bool m_is_global : 4 { false };
  374. };
  375. class SetVariable final : public Instruction {
  376. public:
  377. enum class InitializationMode {
  378. Initialize,
  379. Set,
  380. InitializeOrSet,
  381. };
  382. explicit SetVariable(IdentifierTableIndex identifier, InitializationMode initialization_mode = InitializationMode::Set, EnvironmentMode mode = EnvironmentMode::Lexical)
  383. : Instruction(Type::SetVariable)
  384. , m_identifier(identifier)
  385. , m_mode(mode)
  386. , m_initialization_mode(initialization_mode)
  387. {
  388. }
  389. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  390. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  391. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  392. void replace_references_impl(Register, Register) { }
  393. IdentifierTableIndex identifier() const { return m_identifier; }
  394. private:
  395. IdentifierTableIndex m_identifier;
  396. EnvironmentMode m_mode;
  397. InitializationMode m_initialization_mode { InitializationMode::Set };
  398. };
  399. class GetVariable final : public Instruction {
  400. public:
  401. explicit GetVariable(IdentifierTableIndex identifier)
  402. : Instruction(Type::GetVariable)
  403. , m_identifier(identifier)
  404. {
  405. }
  406. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  407. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  408. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  409. void replace_references_impl(Register, Register) { }
  410. IdentifierTableIndex identifier() const { return m_identifier; }
  411. private:
  412. IdentifierTableIndex m_identifier;
  413. Optional<EnvironmentCoordinate> mutable m_cached_environment_coordinate;
  414. };
  415. class DeleteVariable final : public Instruction {
  416. public:
  417. explicit DeleteVariable(IdentifierTableIndex identifier)
  418. : Instruction(Type::DeleteVariable)
  419. , m_identifier(identifier)
  420. {
  421. }
  422. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  423. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  424. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  425. void replace_references_impl(Register, Register) { }
  426. IdentifierTableIndex identifier() const { return m_identifier; }
  427. private:
  428. IdentifierTableIndex m_identifier;
  429. };
  430. class GetById final : public Instruction {
  431. public:
  432. explicit GetById(IdentifierTableIndex property)
  433. : Instruction(Type::GetById)
  434. , m_property(property)
  435. {
  436. }
  437. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  438. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  439. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  440. void replace_references_impl(Register, Register) { }
  441. private:
  442. IdentifierTableIndex m_property;
  443. };
  444. enum class PropertyKind {
  445. Getter,
  446. Setter,
  447. KeyValue,
  448. Spread,
  449. ProtoSetter,
  450. };
  451. class PutById final : public Instruction {
  452. public:
  453. explicit PutById(Register base, IdentifierTableIndex property, PropertyKind kind = PropertyKind::KeyValue)
  454. : Instruction(Type::PutById)
  455. , m_base(base)
  456. , m_property(property)
  457. , m_kind(kind)
  458. {
  459. }
  460. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  461. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  462. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  463. void replace_references_impl(Register from, Register to)
  464. {
  465. if (m_base == from)
  466. m_base = to;
  467. }
  468. private:
  469. Register m_base;
  470. IdentifierTableIndex m_property;
  471. PropertyKind m_kind;
  472. };
  473. class DeleteById final : public Instruction {
  474. public:
  475. explicit DeleteById(IdentifierTableIndex property)
  476. : Instruction(Type::DeleteById)
  477. , m_property(property)
  478. {
  479. }
  480. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  481. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  482. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  483. void replace_references_impl(Register, Register) { }
  484. private:
  485. IdentifierTableIndex m_property;
  486. };
  487. class GetByValue final : public Instruction {
  488. public:
  489. explicit GetByValue(Register base)
  490. : Instruction(Type::GetByValue)
  491. , m_base(base)
  492. {
  493. }
  494. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  495. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  496. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  497. void replace_references_impl(Register from, Register to)
  498. {
  499. if (m_base == from)
  500. m_base = to;
  501. }
  502. private:
  503. Register m_base;
  504. };
  505. class PutByValue final : public Instruction {
  506. public:
  507. PutByValue(Register base, Register property, PropertyKind kind = PropertyKind::KeyValue)
  508. : Instruction(Type::PutByValue)
  509. , m_base(base)
  510. , m_property(property)
  511. , m_kind(kind)
  512. {
  513. }
  514. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  515. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  516. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  517. void replace_references_impl(Register from, Register to)
  518. {
  519. if (m_base == from)
  520. m_base = to;
  521. }
  522. private:
  523. Register m_base;
  524. Register m_property;
  525. PropertyKind m_kind;
  526. };
  527. class DeleteByValue final : public Instruction {
  528. public:
  529. DeleteByValue(Register base)
  530. : Instruction(Type::DeleteByValue)
  531. , m_base(base)
  532. {
  533. }
  534. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  535. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  536. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  537. void replace_references_impl(Register from, Register to)
  538. {
  539. if (m_base == from)
  540. m_base = to;
  541. }
  542. private:
  543. Register m_base;
  544. };
  545. class Jump : public Instruction {
  546. public:
  547. constexpr static bool IsTerminator = true;
  548. explicit Jump(Type type, Optional<Label> taken_target = {}, Optional<Label> nontaken_target = {})
  549. : Instruction(type)
  550. , m_true_target(move(taken_target))
  551. , m_false_target(move(nontaken_target))
  552. {
  553. }
  554. explicit Jump(Optional<Label> taken_target = {}, Optional<Label> nontaken_target = {})
  555. : Instruction(Type::Jump)
  556. , m_true_target(move(taken_target))
  557. , m_false_target(move(nontaken_target))
  558. {
  559. }
  560. void set_targets(Optional<Label> true_target, Optional<Label> false_target)
  561. {
  562. m_true_target = move(true_target);
  563. m_false_target = move(false_target);
  564. }
  565. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  566. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  567. void replace_references_impl(BasicBlock const&, BasicBlock const&);
  568. void replace_references_impl(Register, Register) { }
  569. auto& true_target() const { return m_true_target; }
  570. auto& false_target() const { return m_false_target; }
  571. protected:
  572. Optional<Label> m_true_target;
  573. Optional<Label> m_false_target;
  574. };
  575. class JumpConditional final : public Jump {
  576. public:
  577. explicit JumpConditional(Optional<Label> true_target = {}, Optional<Label> false_target = {})
  578. : Jump(Type::JumpConditional, move(true_target), move(false_target))
  579. {
  580. }
  581. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  582. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  583. };
  584. class JumpNullish final : public Jump {
  585. public:
  586. explicit JumpNullish(Optional<Label> true_target = {}, Optional<Label> false_target = {})
  587. : Jump(Type::JumpNullish, move(true_target), move(false_target))
  588. {
  589. }
  590. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  591. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  592. };
  593. class JumpUndefined final : public Jump {
  594. public:
  595. explicit JumpUndefined(Optional<Label> true_target = {}, Optional<Label> false_target = {})
  596. : Jump(Type::JumpUndefined, move(true_target), move(false_target))
  597. {
  598. }
  599. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  600. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  601. };
  602. // NOTE: This instruction is variable-width depending on the number of arguments!
  603. class Call final : public Instruction {
  604. public:
  605. enum class CallType {
  606. Call,
  607. Construct,
  608. DirectEval,
  609. };
  610. Call(CallType type, Register callee, Register this_value, Optional<StringTableIndex> expression_string = {})
  611. : Instruction(Type::Call)
  612. , m_callee(callee)
  613. , m_this_value(this_value)
  614. , m_type(type)
  615. , m_expression_string(expression_string)
  616. {
  617. }
  618. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  619. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  620. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  621. void replace_references_impl(Register, Register);
  622. Completion throw_type_error_for_callee(Bytecode::Interpreter&, StringView callee_type) const;
  623. private:
  624. Register m_callee;
  625. Register m_this_value;
  626. CallType m_type;
  627. Optional<StringTableIndex> m_expression_string;
  628. };
  629. // NOTE: This instruction is variable-width depending on the number of arguments!
  630. class SuperCall : public Instruction {
  631. public:
  632. explicit SuperCall(bool is_synthetic)
  633. : Instruction(Type::SuperCall)
  634. , m_is_synthetic(is_synthetic)
  635. {
  636. }
  637. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  638. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  639. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  640. void replace_references_impl(Register, Register) { }
  641. private:
  642. bool m_is_synthetic;
  643. };
  644. class NewClass final : public Instruction {
  645. public:
  646. explicit NewClass(ClassExpression const& class_expression)
  647. : Instruction(Type::NewClass)
  648. , m_class_expression(class_expression)
  649. {
  650. }
  651. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  652. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  653. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  654. void replace_references_impl(Register, Register) { }
  655. private:
  656. ClassExpression const& m_class_expression;
  657. };
  658. class NewFunction final : public Instruction {
  659. public:
  660. explicit NewFunction(FunctionNode const& function_node, Optional<Register> home_object = {})
  661. : Instruction(Type::NewFunction)
  662. , m_function_node(function_node)
  663. , m_home_object(move(home_object))
  664. {
  665. }
  666. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  667. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  668. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  669. void replace_references_impl(Register, Register);
  670. private:
  671. FunctionNode const& m_function_node;
  672. Optional<Register> m_home_object;
  673. };
  674. class Return final : public Instruction {
  675. public:
  676. constexpr static bool IsTerminator = true;
  677. Return()
  678. : Instruction(Type::Return)
  679. {
  680. }
  681. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  682. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  683. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  684. void replace_references_impl(Register, Register) { }
  685. };
  686. class Increment final : public Instruction {
  687. public:
  688. Increment()
  689. : Instruction(Type::Increment)
  690. {
  691. }
  692. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  693. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  694. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  695. void replace_references_impl(Register, Register) { }
  696. };
  697. class Decrement final : public Instruction {
  698. public:
  699. Decrement()
  700. : Instruction(Type::Decrement)
  701. {
  702. }
  703. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  704. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  705. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  706. void replace_references_impl(Register, Register) { }
  707. };
  708. class ToNumeric final : public Instruction {
  709. public:
  710. ToNumeric()
  711. : Instruction(Type::ToNumeric)
  712. {
  713. }
  714. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  715. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  716. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  717. void replace_references_impl(Register, Register) { }
  718. };
  719. class Throw final : public Instruction {
  720. public:
  721. constexpr static bool IsTerminator = true;
  722. Throw()
  723. : Instruction(Type::Throw)
  724. {
  725. }
  726. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  727. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  728. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  729. void replace_references_impl(Register, Register) { }
  730. };
  731. class ThrowIfNotObject final : public Instruction {
  732. public:
  733. ThrowIfNotObject()
  734. : Instruction(Type::ThrowIfNotObject)
  735. {
  736. }
  737. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  738. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  739. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  740. void replace_references_impl(Register, Register) { }
  741. };
  742. class EnterUnwindContext final : public Instruction {
  743. public:
  744. constexpr static bool IsTerminator = true;
  745. EnterUnwindContext(Label entry_point, Optional<Label> handler_target, Optional<Label> finalizer_target)
  746. : Instruction(Type::EnterUnwindContext)
  747. , m_entry_point(move(entry_point))
  748. , m_handler_target(move(handler_target))
  749. , m_finalizer_target(move(finalizer_target))
  750. {
  751. }
  752. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  753. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  754. void replace_references_impl(BasicBlock const&, BasicBlock const&);
  755. void replace_references_impl(Register, Register) { }
  756. auto& entry_point() const { return m_entry_point; }
  757. auto& handler_target() const { return m_handler_target; }
  758. auto& finalizer_target() const { return m_finalizer_target; }
  759. private:
  760. Label m_entry_point;
  761. Optional<Label> m_handler_target;
  762. Optional<Label> m_finalizer_target;
  763. };
  764. class ScheduleJump final : public Instruction {
  765. public:
  766. // Note: We use this instruction to tell the next `finally` block to
  767. // continue execution with a specific break/continue target;
  768. // FIXME: We currently don't clear the interpreter internal flag, when we change
  769. // the control-flow (`break`, `continue`) in a finally-block,
  770. // FIXME: .NET on x86_64 uses a call to the finally instead, which could make this
  771. // easier, at the cost of making control-flow changes (`break`, `continue`, `return`)
  772. // in the finally-block more difficult, but as stated above, those
  773. // aren't handled 100% correctly at the moment anyway
  774. // It might be worth investigating a similar mechanism
  775. constexpr static bool IsTerminator = true;
  776. ScheduleJump(Label target)
  777. : Instruction(Type::ScheduleJump)
  778. , m_target(target)
  779. {
  780. }
  781. Label target() const { return m_target; }
  782. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  783. void replace_references_impl(BasicBlock const& from, BasicBlock const& to)
  784. {
  785. if (&m_target.block() == &from)
  786. m_target = Label { to };
  787. }
  788. void replace_references_impl(Register, Register) { }
  789. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  790. private:
  791. Label m_target;
  792. };
  793. class LeaveEnvironment final : public Instruction {
  794. public:
  795. LeaveEnvironment(EnvironmentMode mode)
  796. : Instruction(Type::LeaveEnvironment)
  797. , m_mode(mode)
  798. {
  799. }
  800. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  801. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  802. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  803. void replace_references_impl(Register, Register) { }
  804. private:
  805. EnvironmentMode m_mode { EnvironmentMode::Lexical };
  806. };
  807. class LeaveUnwindContext final : public Instruction {
  808. public:
  809. LeaveUnwindContext()
  810. : Instruction(Type::LeaveUnwindContext)
  811. {
  812. }
  813. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  814. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  815. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  816. void replace_references_impl(Register, Register) { }
  817. };
  818. class ContinuePendingUnwind final : public Instruction {
  819. public:
  820. constexpr static bool IsTerminator = true;
  821. explicit ContinuePendingUnwind(Label resume_target)
  822. : Instruction(Type::ContinuePendingUnwind)
  823. , m_resume_target(resume_target)
  824. {
  825. }
  826. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  827. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  828. void replace_references_impl(BasicBlock const&, BasicBlock const&);
  829. void replace_references_impl(Register, Register) { }
  830. auto& resume_target() const { return m_resume_target; }
  831. private:
  832. Label m_resume_target;
  833. };
  834. class Yield final : public Instruction {
  835. public:
  836. constexpr static bool IsTerminator = true;
  837. explicit Yield(Label continuation_label)
  838. : Instruction(Type::Yield)
  839. , m_continuation_label(continuation_label)
  840. {
  841. }
  842. explicit Yield(nullptr_t)
  843. : Instruction(Type::Yield)
  844. {
  845. }
  846. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  847. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  848. void replace_references_impl(BasicBlock const&, BasicBlock const&);
  849. void replace_references_impl(Register, Register) { }
  850. auto& continuation() const { return m_continuation_label; }
  851. private:
  852. Optional<Label> m_continuation_label;
  853. };
  854. class PushDeclarativeEnvironment final : public Instruction {
  855. public:
  856. explicit PushDeclarativeEnvironment(HashMap<u32, Variable> variables)
  857. : Instruction(Type::PushDeclarativeEnvironment)
  858. , m_variables(move(variables))
  859. {
  860. }
  861. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  862. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  863. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  864. void replace_references_impl(Register, Register) { }
  865. private:
  866. HashMap<u32, Variable> m_variables;
  867. };
  868. class GetIterator final : public Instruction {
  869. public:
  870. GetIterator()
  871. : Instruction(Type::GetIterator)
  872. {
  873. }
  874. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  875. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  876. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  877. void replace_references_impl(Register, Register) { }
  878. };
  879. class GetMethod final : public Instruction {
  880. public:
  881. GetMethod(IdentifierTableIndex property)
  882. : Instruction(Type::GetMethod)
  883. , m_property(property)
  884. {
  885. }
  886. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  887. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  888. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  889. void replace_references_impl(Register, Register) { }
  890. private:
  891. IdentifierTableIndex m_property;
  892. };
  893. class GetObjectPropertyIterator final : public Instruction {
  894. public:
  895. GetObjectPropertyIterator()
  896. : Instruction(Type::GetObjectPropertyIterator)
  897. {
  898. }
  899. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  900. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  901. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  902. void replace_references_impl(Register, Register) { }
  903. };
  904. class IteratorClose final : public Instruction {
  905. public:
  906. IteratorClose(Completion::Type completion_type, Optional<Value> completion_value)
  907. : Instruction(Type::IteratorClose)
  908. , m_completion_type(completion_type)
  909. , m_completion_value(completion_value)
  910. {
  911. }
  912. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  913. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  914. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  915. void replace_references_impl(Register, Register) { }
  916. private:
  917. Completion::Type m_completion_type { Completion::Type::Normal };
  918. Optional<Value> m_completion_value;
  919. };
  920. class IteratorNext final : public Instruction {
  921. public:
  922. IteratorNext()
  923. : Instruction(Type::IteratorNext)
  924. {
  925. }
  926. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  927. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  928. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  929. void replace_references_impl(Register, Register) { }
  930. };
  931. class IteratorResultDone final : public Instruction {
  932. public:
  933. IteratorResultDone()
  934. : Instruction(Type::IteratorResultDone)
  935. {
  936. }
  937. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  938. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  939. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  940. void replace_references_impl(Register, Register) { }
  941. };
  942. class IteratorResultValue final : public Instruction {
  943. public:
  944. IteratorResultValue()
  945. : Instruction(Type::IteratorResultValue)
  946. {
  947. }
  948. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  949. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  950. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  951. void replace_references_impl(Register, Register) { }
  952. };
  953. class ResolveThisBinding final : public Instruction {
  954. public:
  955. explicit ResolveThisBinding()
  956. : Instruction(Type::ResolveThisBinding)
  957. {
  958. }
  959. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  960. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  961. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  962. void replace_references_impl(Register, Register) { }
  963. };
  964. class ResolveSuperBase final : public Instruction {
  965. public:
  966. explicit ResolveSuperBase()
  967. : Instruction(Type::ResolveSuperBase)
  968. {
  969. }
  970. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  971. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  972. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  973. void replace_references_impl(Register, Register) { }
  974. };
  975. class GetNewTarget final : public Instruction {
  976. public:
  977. explicit GetNewTarget()
  978. : Instruction(Type::GetNewTarget)
  979. {
  980. }
  981. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  982. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  983. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  984. void replace_references_impl(Register, Register) { }
  985. };
  986. class TypeofVariable final : public Instruction {
  987. public:
  988. explicit TypeofVariable(IdentifierTableIndex identifier)
  989. : Instruction(Type::TypeofVariable)
  990. , m_identifier(identifier)
  991. {
  992. }
  993. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  994. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  995. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  996. void replace_references_impl(Register, Register) { }
  997. private:
  998. IdentifierTableIndex m_identifier;
  999. };
  1000. }
  1001. namespace JS::Bytecode {
  1002. ALWAYS_INLINE ThrowCompletionOr<void> Instruction::execute(Bytecode::Interpreter& interpreter) const
  1003. {
  1004. #define __BYTECODE_OP(op) \
  1005. case Instruction::Type::op: \
  1006. return static_cast<Bytecode::Op::op const&>(*this).execute_impl(interpreter);
  1007. switch (type()) {
  1008. ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
  1009. default:
  1010. VERIFY_NOT_REACHED();
  1011. }
  1012. #undef __BYTECODE_OP
  1013. }
  1014. ALWAYS_INLINE void Instruction::replace_references(BasicBlock const& from, BasicBlock const& to)
  1015. {
  1016. #define __BYTECODE_OP(op) \
  1017. case Instruction::Type::op: \
  1018. return static_cast<Bytecode::Op::op&>(*this).replace_references_impl(from, to);
  1019. switch (type()) {
  1020. ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
  1021. default:
  1022. VERIFY_NOT_REACHED();
  1023. }
  1024. #undef __BYTECODE_OP
  1025. }
  1026. ALWAYS_INLINE void Instruction::replace_references(Register from, Register to)
  1027. {
  1028. #define __BYTECODE_OP(op) \
  1029. case Instruction::Type::op: \
  1030. return static_cast<Bytecode::Op::op&>(*this).replace_references_impl(from, to);
  1031. switch (type()) {
  1032. ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
  1033. default:
  1034. VERIFY_NOT_REACHED();
  1035. }
  1036. #undef __BYTECODE_OP
  1037. }
  1038. ALWAYS_INLINE size_t Instruction::length() const
  1039. {
  1040. if (type() == Type::NewArray)
  1041. return round_up_to_power_of_two(static_cast<Op::NewArray const&>(*this).length_impl(), alignof(void*));
  1042. if (type() == Type::CopyObjectExcludingProperties)
  1043. return round_up_to_power_of_two(static_cast<Op::CopyObjectExcludingProperties const&>(*this).length_impl(), alignof(void*));
  1044. #define __BYTECODE_OP(op) \
  1045. case Type::op: \
  1046. return sizeof(Op::op);
  1047. switch (type()) {
  1048. ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
  1049. default:
  1050. VERIFY_NOT_REACHED();
  1051. }
  1052. #undef __BYTECODE_OP
  1053. }
  1054. ALWAYS_INLINE bool Instruction::is_terminator() const
  1055. {
  1056. #define __BYTECODE_OP(op) \
  1057. case Type::op: \
  1058. return Op::op::IsTerminator;
  1059. switch (type()) {
  1060. ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
  1061. default:
  1062. VERIFY_NOT_REACHED();
  1063. }
  1064. #undef __BYTECODE_OP
  1065. }
  1066. }