Op.h 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283
  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 CreateLexicalEnvironment final : public Instruction {
  331. public:
  332. explicit CreateLexicalEnvironment()
  333. : Instruction(Type::CreateLexicalEnvironment)
  334. {
  335. }
  336. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  337. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  338. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  339. void replace_references_impl(Register, Register) { }
  340. };
  341. class EnterObjectEnvironment final : public Instruction {
  342. public:
  343. explicit EnterObjectEnvironment()
  344. : Instruction(Type::EnterObjectEnvironment)
  345. {
  346. }
  347. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  348. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  349. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  350. void replace_references_impl(Register, Register) { }
  351. };
  352. class CreateVariable final : public Instruction {
  353. public:
  354. explicit CreateVariable(IdentifierTableIndex identifier, EnvironmentMode mode, bool is_immutable, bool is_global = false)
  355. : Instruction(Type::CreateVariable)
  356. , m_identifier(identifier)
  357. , m_mode(mode)
  358. , m_is_immutable(is_immutable)
  359. , m_is_global(is_global)
  360. {
  361. }
  362. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  363. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  364. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  365. void replace_references_impl(Register, Register) { }
  366. private:
  367. IdentifierTableIndex m_identifier;
  368. EnvironmentMode m_mode;
  369. bool m_is_immutable : 4 { false };
  370. bool m_is_global : 4 { false };
  371. };
  372. class SetVariable final : public Instruction {
  373. public:
  374. enum class InitializationMode {
  375. Initialize,
  376. Set,
  377. InitializeOrSet,
  378. };
  379. explicit SetVariable(IdentifierTableIndex identifier, InitializationMode initialization_mode = InitializationMode::Set, EnvironmentMode mode = EnvironmentMode::Lexical)
  380. : Instruction(Type::SetVariable)
  381. , m_identifier(identifier)
  382. , m_mode(mode)
  383. , m_initialization_mode(initialization_mode)
  384. {
  385. }
  386. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  387. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  388. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  389. void replace_references_impl(Register, Register) { }
  390. IdentifierTableIndex identifier() const { return m_identifier; }
  391. private:
  392. IdentifierTableIndex m_identifier;
  393. EnvironmentMode m_mode;
  394. InitializationMode m_initialization_mode { InitializationMode::Set };
  395. };
  396. class GetVariable final : public Instruction {
  397. public:
  398. explicit GetVariable(IdentifierTableIndex identifier)
  399. : Instruction(Type::GetVariable)
  400. , m_identifier(identifier)
  401. {
  402. }
  403. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  404. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  405. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  406. void replace_references_impl(Register, Register) { }
  407. IdentifierTableIndex identifier() const { return m_identifier; }
  408. private:
  409. IdentifierTableIndex m_identifier;
  410. Optional<EnvironmentCoordinate> mutable m_cached_environment_coordinate;
  411. };
  412. class DeleteVariable final : public Instruction {
  413. public:
  414. explicit DeleteVariable(IdentifierTableIndex identifier)
  415. : Instruction(Type::DeleteVariable)
  416. , m_identifier(identifier)
  417. {
  418. }
  419. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  420. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  421. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  422. void replace_references_impl(Register, Register) { }
  423. IdentifierTableIndex identifier() const { return m_identifier; }
  424. private:
  425. IdentifierTableIndex m_identifier;
  426. };
  427. class GetById final : public Instruction {
  428. public:
  429. explicit GetById(IdentifierTableIndex property)
  430. : Instruction(Type::GetById)
  431. , m_property(property)
  432. {
  433. }
  434. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  435. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  436. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  437. void replace_references_impl(Register, Register) { }
  438. private:
  439. IdentifierTableIndex m_property;
  440. };
  441. enum class PropertyKind {
  442. Getter,
  443. Setter,
  444. KeyValue,
  445. Spread,
  446. ProtoSetter,
  447. };
  448. class PutById final : public Instruction {
  449. public:
  450. explicit PutById(Register base, IdentifierTableIndex property, PropertyKind kind = PropertyKind::KeyValue)
  451. : Instruction(Type::PutById)
  452. , m_base(base)
  453. , m_property(property)
  454. , m_kind(kind)
  455. {
  456. }
  457. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  458. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  459. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  460. void replace_references_impl(Register from, Register to)
  461. {
  462. if (m_base == from)
  463. m_base = to;
  464. }
  465. private:
  466. Register m_base;
  467. IdentifierTableIndex m_property;
  468. PropertyKind m_kind;
  469. };
  470. class DeleteById final : public Instruction {
  471. public:
  472. explicit DeleteById(IdentifierTableIndex property)
  473. : Instruction(Type::DeleteById)
  474. , m_property(property)
  475. {
  476. }
  477. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  478. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  479. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  480. void replace_references_impl(Register, Register) { }
  481. private:
  482. IdentifierTableIndex m_property;
  483. };
  484. class GetByValue final : public Instruction {
  485. public:
  486. explicit GetByValue(Register base)
  487. : Instruction(Type::GetByValue)
  488. , m_base(base)
  489. {
  490. }
  491. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  492. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  493. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  494. void replace_references_impl(Register from, Register to)
  495. {
  496. if (m_base == from)
  497. m_base = to;
  498. }
  499. private:
  500. Register m_base;
  501. };
  502. class PutByValue final : public Instruction {
  503. public:
  504. PutByValue(Register base, Register property, PropertyKind kind = PropertyKind::KeyValue)
  505. : Instruction(Type::PutByValue)
  506. , m_base(base)
  507. , m_property(property)
  508. , m_kind(kind)
  509. {
  510. }
  511. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  512. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  513. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  514. void replace_references_impl(Register from, Register to)
  515. {
  516. if (m_base == from)
  517. m_base = to;
  518. }
  519. private:
  520. Register m_base;
  521. Register m_property;
  522. PropertyKind m_kind;
  523. };
  524. class DeleteByValue final : public Instruction {
  525. public:
  526. DeleteByValue(Register base)
  527. : Instruction(Type::DeleteByValue)
  528. , m_base(base)
  529. {
  530. }
  531. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  532. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  533. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  534. void replace_references_impl(Register from, Register to)
  535. {
  536. if (m_base == from)
  537. m_base = to;
  538. }
  539. private:
  540. Register m_base;
  541. };
  542. class Jump : public Instruction {
  543. public:
  544. constexpr static bool IsTerminator = true;
  545. explicit Jump(Type type, Optional<Label> taken_target = {}, Optional<Label> nontaken_target = {})
  546. : Instruction(type)
  547. , m_true_target(move(taken_target))
  548. , m_false_target(move(nontaken_target))
  549. {
  550. }
  551. explicit Jump(Optional<Label> taken_target = {}, Optional<Label> nontaken_target = {})
  552. : Instruction(Type::Jump)
  553. , m_true_target(move(taken_target))
  554. , m_false_target(move(nontaken_target))
  555. {
  556. }
  557. void set_targets(Optional<Label> true_target, Optional<Label> false_target)
  558. {
  559. m_true_target = move(true_target);
  560. m_false_target = move(false_target);
  561. }
  562. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  563. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  564. void replace_references_impl(BasicBlock const&, BasicBlock const&);
  565. void replace_references_impl(Register, Register) { }
  566. auto& true_target() const { return m_true_target; }
  567. auto& false_target() const { return m_false_target; }
  568. protected:
  569. Optional<Label> m_true_target;
  570. Optional<Label> m_false_target;
  571. };
  572. class JumpConditional final : public Jump {
  573. public:
  574. explicit JumpConditional(Optional<Label> true_target = {}, Optional<Label> false_target = {})
  575. : Jump(Type::JumpConditional, move(true_target), move(false_target))
  576. {
  577. }
  578. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  579. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  580. };
  581. class JumpNullish final : public Jump {
  582. public:
  583. explicit JumpNullish(Optional<Label> true_target = {}, Optional<Label> false_target = {})
  584. : Jump(Type::JumpNullish, move(true_target), move(false_target))
  585. {
  586. }
  587. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  588. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  589. };
  590. class JumpUndefined final : public Jump {
  591. public:
  592. explicit JumpUndefined(Optional<Label> true_target = {}, Optional<Label> false_target = {})
  593. : Jump(Type::JumpUndefined, move(true_target), move(false_target))
  594. {
  595. }
  596. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  597. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  598. };
  599. // NOTE: This instruction is variable-width depending on the number of arguments!
  600. class Call final : public Instruction {
  601. public:
  602. enum class CallType {
  603. Call,
  604. Construct,
  605. DirectEval,
  606. };
  607. Call(CallType type, Register callee, Register this_value, Optional<StringTableIndex> expression_string = {})
  608. : Instruction(Type::Call)
  609. , m_callee(callee)
  610. , m_this_value(this_value)
  611. , m_type(type)
  612. , m_expression_string(expression_string)
  613. {
  614. }
  615. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  616. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  617. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  618. void replace_references_impl(Register, Register);
  619. Completion throw_type_error_for_callee(Bytecode::Interpreter&, StringView callee_type) const;
  620. private:
  621. Register m_callee;
  622. Register m_this_value;
  623. CallType m_type;
  624. Optional<StringTableIndex> m_expression_string;
  625. };
  626. // NOTE: This instruction is variable-width depending on the number of arguments!
  627. class SuperCall : public Instruction {
  628. public:
  629. explicit SuperCall(bool is_synthetic)
  630. : Instruction(Type::SuperCall)
  631. , m_is_synthetic(is_synthetic)
  632. {
  633. }
  634. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  635. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  636. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  637. void replace_references_impl(Register, Register) { }
  638. private:
  639. bool m_is_synthetic;
  640. };
  641. class NewClass final : public Instruction {
  642. public:
  643. explicit NewClass(ClassExpression const& class_expression)
  644. : Instruction(Type::NewClass)
  645. , m_class_expression(class_expression)
  646. {
  647. }
  648. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  649. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  650. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  651. void replace_references_impl(Register, Register) { }
  652. private:
  653. ClassExpression const& m_class_expression;
  654. };
  655. class NewFunction final : public Instruction {
  656. public:
  657. explicit NewFunction(FunctionNode const& function_node, Optional<Register> home_object = {})
  658. : Instruction(Type::NewFunction)
  659. , m_function_node(function_node)
  660. , m_home_object(move(home_object))
  661. {
  662. }
  663. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  664. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  665. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  666. void replace_references_impl(Register, Register);
  667. private:
  668. FunctionNode const& m_function_node;
  669. Optional<Register> m_home_object;
  670. };
  671. class BlockDeclarationInstantiation final : public Instruction {
  672. public:
  673. explicit BlockDeclarationInstantiation(ScopeNode const& scope_node)
  674. : Instruction(Type::BlockDeclarationInstantiation)
  675. , m_scope_node(scope_node)
  676. {
  677. }
  678. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  679. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  680. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  681. void replace_references_impl(Register, Register) { }
  682. private:
  683. ScopeNode const& m_scope_node;
  684. };
  685. class Return final : public Instruction {
  686. public:
  687. constexpr static bool IsTerminator = true;
  688. Return()
  689. : Instruction(Type::Return)
  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 Increment final : public Instruction {
  698. public:
  699. Increment()
  700. : Instruction(Type::Increment)
  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 Decrement final : public Instruction {
  709. public:
  710. Decrement()
  711. : Instruction(Type::Decrement)
  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 ToNumeric final : public Instruction {
  720. public:
  721. ToNumeric()
  722. : Instruction(Type::ToNumeric)
  723. {
  724. }
  725. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  726. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  727. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  728. void replace_references_impl(Register, Register) { }
  729. };
  730. class Throw final : public Instruction {
  731. public:
  732. constexpr static bool IsTerminator = true;
  733. Throw()
  734. : Instruction(Type::Throw)
  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 ThrowIfNotObject final : public Instruction {
  743. public:
  744. ThrowIfNotObject()
  745. : Instruction(Type::ThrowIfNotObject)
  746. {
  747. }
  748. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  749. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  750. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  751. void replace_references_impl(Register, Register) { }
  752. };
  753. class EnterUnwindContext final : public Instruction {
  754. public:
  755. constexpr static bool IsTerminator = true;
  756. EnterUnwindContext(Label entry_point, Optional<Label> handler_target, Optional<Label> finalizer_target)
  757. : Instruction(Type::EnterUnwindContext)
  758. , m_entry_point(move(entry_point))
  759. , m_handler_target(move(handler_target))
  760. , m_finalizer_target(move(finalizer_target))
  761. {
  762. }
  763. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  764. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  765. void replace_references_impl(BasicBlock const&, BasicBlock const&);
  766. void replace_references_impl(Register, Register) { }
  767. auto& entry_point() const { return m_entry_point; }
  768. auto& handler_target() const { return m_handler_target; }
  769. auto& finalizer_target() const { return m_finalizer_target; }
  770. private:
  771. Label m_entry_point;
  772. Optional<Label> m_handler_target;
  773. Optional<Label> m_finalizer_target;
  774. };
  775. class ScheduleJump final : public Instruction {
  776. public:
  777. // Note: We use this instruction to tell the next `finally` block to
  778. // continue execution with a specific break/continue target;
  779. // FIXME: We currently don't clear the interpreter internal flag, when we change
  780. // the control-flow (`break`, `continue`) in a finally-block,
  781. // FIXME: .NET on x86_64 uses a call to the finally instead, which could make this
  782. // easier, at the cost of making control-flow changes (`break`, `continue`, `return`)
  783. // in the finally-block more difficult, but as stated above, those
  784. // aren't handled 100% correctly at the moment anyway
  785. // It might be worth investigating a similar mechanism
  786. constexpr static bool IsTerminator = true;
  787. ScheduleJump(Label target)
  788. : Instruction(Type::ScheduleJump)
  789. , m_target(target)
  790. {
  791. }
  792. Label target() const { return m_target; }
  793. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  794. void replace_references_impl(BasicBlock const& from, BasicBlock const& to)
  795. {
  796. if (&m_target.block() == &from)
  797. m_target = Label { to };
  798. }
  799. void replace_references_impl(Register, Register) { }
  800. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  801. private:
  802. Label m_target;
  803. };
  804. class LeaveLexicalEnvironment final : public Instruction {
  805. public:
  806. LeaveLexicalEnvironment()
  807. : Instruction(Type::LeaveLexicalEnvironment)
  808. {
  809. }
  810. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  811. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  812. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  813. void replace_references_impl(Register, Register) { }
  814. };
  815. class LeaveUnwindContext final : public Instruction {
  816. public:
  817. LeaveUnwindContext()
  818. : Instruction(Type::LeaveUnwindContext)
  819. {
  820. }
  821. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  822. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  823. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  824. void replace_references_impl(Register, Register) { }
  825. };
  826. class ContinuePendingUnwind final : public Instruction {
  827. public:
  828. constexpr static bool IsTerminator = true;
  829. explicit ContinuePendingUnwind(Label resume_target)
  830. : Instruction(Type::ContinuePendingUnwind)
  831. , m_resume_target(resume_target)
  832. {
  833. }
  834. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  835. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  836. void replace_references_impl(BasicBlock const&, BasicBlock const&);
  837. void replace_references_impl(Register, Register) { }
  838. auto& resume_target() const { return m_resume_target; }
  839. private:
  840. Label m_resume_target;
  841. };
  842. class Yield final : public Instruction {
  843. public:
  844. constexpr static bool IsTerminator = true;
  845. explicit Yield(Label continuation_label)
  846. : Instruction(Type::Yield)
  847. , m_continuation_label(continuation_label)
  848. {
  849. }
  850. explicit Yield(nullptr_t)
  851. : Instruction(Type::Yield)
  852. {
  853. }
  854. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  855. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  856. void replace_references_impl(BasicBlock const&, BasicBlock const&);
  857. void replace_references_impl(Register, Register) { }
  858. auto& continuation() const { return m_continuation_label; }
  859. private:
  860. Optional<Label> m_continuation_label;
  861. };
  862. class PushDeclarativeEnvironment final : public Instruction {
  863. public:
  864. explicit PushDeclarativeEnvironment(HashMap<u32, Variable> variables)
  865. : Instruction(Type::PushDeclarativeEnvironment)
  866. , m_variables(move(variables))
  867. {
  868. }
  869. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  870. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  871. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  872. void replace_references_impl(Register, Register) { }
  873. private:
  874. HashMap<u32, Variable> m_variables;
  875. };
  876. class GetIterator final : public Instruction {
  877. public:
  878. GetIterator()
  879. : Instruction(Type::GetIterator)
  880. {
  881. }
  882. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  883. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  884. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  885. void replace_references_impl(Register, Register) { }
  886. };
  887. class GetMethod final : public Instruction {
  888. public:
  889. GetMethod(IdentifierTableIndex property)
  890. : Instruction(Type::GetMethod)
  891. , m_property(property)
  892. {
  893. }
  894. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  895. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  896. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  897. void replace_references_impl(Register, Register) { }
  898. private:
  899. IdentifierTableIndex m_property;
  900. };
  901. class GetObjectPropertyIterator final : public Instruction {
  902. public:
  903. GetObjectPropertyIterator()
  904. : Instruction(Type::GetObjectPropertyIterator)
  905. {
  906. }
  907. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  908. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  909. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  910. void replace_references_impl(Register, Register) { }
  911. };
  912. class IteratorClose final : public Instruction {
  913. public:
  914. IteratorClose(Completion::Type completion_type, Optional<Value> completion_value)
  915. : Instruction(Type::IteratorClose)
  916. , m_completion_type(completion_type)
  917. , m_completion_value(completion_value)
  918. {
  919. }
  920. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  921. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  922. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  923. void replace_references_impl(Register, Register) { }
  924. private:
  925. Completion::Type m_completion_type { Completion::Type::Normal };
  926. Optional<Value> m_completion_value;
  927. };
  928. class IteratorNext final : public Instruction {
  929. public:
  930. IteratorNext()
  931. : Instruction(Type::IteratorNext)
  932. {
  933. }
  934. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  935. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  936. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  937. void replace_references_impl(Register, Register) { }
  938. };
  939. class IteratorResultDone final : public Instruction {
  940. public:
  941. IteratorResultDone()
  942. : Instruction(Type::IteratorResultDone)
  943. {
  944. }
  945. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  946. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  947. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  948. void replace_references_impl(Register, Register) { }
  949. };
  950. class IteratorResultValue final : public Instruction {
  951. public:
  952. IteratorResultValue()
  953. : Instruction(Type::IteratorResultValue)
  954. {
  955. }
  956. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  957. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  958. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  959. void replace_references_impl(Register, Register) { }
  960. };
  961. class ResolveThisBinding final : public Instruction {
  962. public:
  963. explicit ResolveThisBinding()
  964. : Instruction(Type::ResolveThisBinding)
  965. {
  966. }
  967. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  968. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  969. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  970. void replace_references_impl(Register, Register) { }
  971. };
  972. class ResolveSuperBase final : public Instruction {
  973. public:
  974. explicit ResolveSuperBase()
  975. : Instruction(Type::ResolveSuperBase)
  976. {
  977. }
  978. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  979. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  980. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  981. void replace_references_impl(Register, Register) { }
  982. };
  983. class GetNewTarget final : public Instruction {
  984. public:
  985. explicit GetNewTarget()
  986. : Instruction(Type::GetNewTarget)
  987. {
  988. }
  989. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  990. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  991. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  992. void replace_references_impl(Register, Register) { }
  993. };
  994. class TypeofVariable final : public Instruction {
  995. public:
  996. explicit TypeofVariable(IdentifierTableIndex identifier)
  997. : Instruction(Type::TypeofVariable)
  998. , m_identifier(identifier)
  999. {
  1000. }
  1001. ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
  1002. DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
  1003. void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
  1004. void replace_references_impl(Register, Register) { }
  1005. private:
  1006. IdentifierTableIndex m_identifier;
  1007. };
  1008. }
  1009. namespace JS::Bytecode {
  1010. ALWAYS_INLINE ThrowCompletionOr<void> Instruction::execute(Bytecode::Interpreter& interpreter) const
  1011. {
  1012. #define __BYTECODE_OP(op) \
  1013. case Instruction::Type::op: \
  1014. return static_cast<Bytecode::Op::op const&>(*this).execute_impl(interpreter);
  1015. switch (type()) {
  1016. ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
  1017. default:
  1018. VERIFY_NOT_REACHED();
  1019. }
  1020. #undef __BYTECODE_OP
  1021. }
  1022. ALWAYS_INLINE void Instruction::replace_references(BasicBlock const& from, BasicBlock const& to)
  1023. {
  1024. #define __BYTECODE_OP(op) \
  1025. case Instruction::Type::op: \
  1026. return static_cast<Bytecode::Op::op&>(*this).replace_references_impl(from, to);
  1027. switch (type()) {
  1028. ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
  1029. default:
  1030. VERIFY_NOT_REACHED();
  1031. }
  1032. #undef __BYTECODE_OP
  1033. }
  1034. ALWAYS_INLINE void Instruction::replace_references(Register from, Register to)
  1035. {
  1036. #define __BYTECODE_OP(op) \
  1037. case Instruction::Type::op: \
  1038. return static_cast<Bytecode::Op::op&>(*this).replace_references_impl(from, to);
  1039. switch (type()) {
  1040. ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
  1041. default:
  1042. VERIFY_NOT_REACHED();
  1043. }
  1044. #undef __BYTECODE_OP
  1045. }
  1046. ALWAYS_INLINE size_t Instruction::length() const
  1047. {
  1048. if (type() == Type::NewArray)
  1049. return round_up_to_power_of_two(static_cast<Op::NewArray const&>(*this).length_impl(), alignof(void*));
  1050. if (type() == Type::CopyObjectExcludingProperties)
  1051. return round_up_to_power_of_two(static_cast<Op::CopyObjectExcludingProperties const&>(*this).length_impl(), alignof(void*));
  1052. #define __BYTECODE_OP(op) \
  1053. case Type::op: \
  1054. return sizeof(Op::op);
  1055. switch (type()) {
  1056. ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
  1057. default:
  1058. VERIFY_NOT_REACHED();
  1059. }
  1060. #undef __BYTECODE_OP
  1061. }
  1062. ALWAYS_INLINE bool Instruction::is_terminator() const
  1063. {
  1064. #define __BYTECODE_OP(op) \
  1065. case Type::op: \
  1066. return Op::op::IsTerminator;
  1067. switch (type()) {
  1068. ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
  1069. default:
  1070. VERIFY_NOT_REACHED();
  1071. }
  1072. #undef __BYTECODE_OP
  1073. }
  1074. }