| 
									
										
										
										
											2021-06-03 10:46:30 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2021, Andreas Kling <kling@serenityos.org> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <AK/Forward.h>
 | 
					
						
							|  |  |  | #include <LibJS/Forward.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-07 15:12:43 +02:00
										 |  |  | #define ENUMERATE_BYTECODE_OPS(O) \
 | 
					
						
							|  |  |  |     O(Load)                       \ | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  |     O(LoadImmediate)              \ | 
					
						
							|  |  |  |     O(Store)                      \ | 
					
						
							| 
									
										
										
										
											2021-06-07 15:12:43 +02:00
										 |  |  |     O(Add)                        \ | 
					
						
							|  |  |  |     O(Sub)                        \ | 
					
						
							| 
									
										
										
										
											2021-06-07 19:17:20 +02:00
										 |  |  |     O(Mul)                        \ | 
					
						
							|  |  |  |     O(Div)                        \ | 
					
						
							| 
									
										
										
										
											2021-06-07 19:37:23 +02:00
										 |  |  |     O(Mod)                        \ | 
					
						
							|  |  |  |     O(Exp)                        \ | 
					
						
							| 
									
										
										
										
											2021-06-07 19:57:38 +02:00
										 |  |  |     O(GreaterThan)                \ | 
					
						
							|  |  |  |     O(GreaterThanEquals)          \ | 
					
						
							| 
									
										
										
										
											2021-06-07 15:12:43 +02:00
										 |  |  |     O(LessThan)                   \ | 
					
						
							| 
									
										
										
										
											2021-06-07 19:57:38 +02:00
										 |  |  |     O(LessThanEquals)             \ | 
					
						
							| 
									
										
										
										
											2021-06-07 15:12:43 +02:00
										 |  |  |     O(AbstractInequals)           \ | 
					
						
							|  |  |  |     O(AbstractEquals)             \ | 
					
						
							| 
									
										
										
										
											2021-06-07 19:39:47 +01:00
										 |  |  |     O(TypedInequals)              \ | 
					
						
							|  |  |  |     O(TypedEquals)                \ | 
					
						
							| 
									
										
										
										
											2021-06-08 07:59:25 +02:00
										 |  |  |     O(NewBigInt)                  \ | 
					
						
							| 
									
										
										
										
											2021-06-08 23:06:52 +02:00
										 |  |  |     O(NewArray)                   \ | 
					
						
							| 
									
										
										
										
											2021-06-07 15:12:43 +02:00
										 |  |  |     O(NewString)                  \ | 
					
						
							|  |  |  |     O(NewObject)                  \ | 
					
						
							|  |  |  |     O(GetVariable)                \ | 
					
						
							|  |  |  |     O(SetVariable)                \ | 
					
						
							|  |  |  |     O(PutById)                    \ | 
					
						
							|  |  |  |     O(GetById)                    \ | 
					
						
							| 
									
										
										
										
											2021-06-11 00:35:25 +02:00
										 |  |  |     O(PutByValue)                 \ | 
					
						
							|  |  |  |     O(GetByValue)                 \ | 
					
						
							| 
									
										
										
										
											2021-06-07 15:12:43 +02:00
										 |  |  |     O(Jump)                       \ | 
					
						
							| 
									
										
										
										
											2021-06-09 06:49:58 +04:30
										 |  |  |     O(JumpConditional)            \ | 
					
						
							|  |  |  |     O(JumpNullish)                \ | 
					
						
							| 
									
										
										
										
											2021-06-07 15:12:43 +02:00
										 |  |  |     O(Call)                       \ | 
					
						
							| 
									
										
										
										
											2021-06-10 00:49:23 +02:00
										 |  |  |     O(NewFunction)                \ | 
					
						
							| 
									
										
										
										
											2021-06-07 19:16:04 +01:00
										 |  |  |     O(Return)                     \ | 
					
						
							|  |  |  |     O(BitwiseAnd)                 \ | 
					
						
							|  |  |  |     O(BitwiseOr)                  \ | 
					
						
							| 
									
										
										
										
											2021-06-07 19:53:47 +01:00
										 |  |  |     O(BitwiseXor)                 \ | 
					
						
							|  |  |  |     O(BitwiseNot)                 \ | 
					
						
							|  |  |  |     O(Not)                        \ | 
					
						
							|  |  |  |     O(UnaryPlus)                  \ | 
					
						
							|  |  |  |     O(UnaryMinus)                 \ | 
					
						
							| 
									
										
										
										
											2021-06-07 20:14:12 +01:00
										 |  |  |     O(Typeof)                     \ | 
					
						
							|  |  |  |     O(LeftShift)                  \ | 
					
						
							|  |  |  |     O(RightShift)                 \ | 
					
						
							| 
									
										
										
										
											2021-06-07 21:13:37 +01:00
										 |  |  |     O(UnsignedRightShift)         \ | 
					
						
							| 
									
										
										
										
											2021-06-07 21:18:19 +01:00
										 |  |  |     O(In)                         \ | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  |     O(InstanceOf)                 \ | 
					
						
							| 
									
										
										
										
											2021-06-09 11:40:38 +02:00
										 |  |  |     O(ConcatString)               \ | 
					
						
							|  |  |  |     O(Increment)                  \ | 
					
						
							| 
									
										
										
										
											2021-06-09 18:18:56 +02:00
										 |  |  |     O(Decrement)                  \ | 
					
						
							| 
									
										
										
										
											2021-06-10 15:04:38 +02:00
										 |  |  |     O(Throw)                      \ | 
					
						
							| 
									
										
										
										
											2021-06-10 22:12:21 +02:00
										 |  |  |     O(PushLexicalEnvironment)     \ | 
					
						
							| 
									
										
										
										
											2021-06-14 09:37:35 +02:00
										 |  |  |     O(LoadArgument)               \ | 
					
						
							| 
									
										
										
										
											2021-06-10 15:04:38 +02:00
										 |  |  |     O(EnterUnwindContext)         \ | 
					
						
							|  |  |  |     O(LeaveUnwindContext)         \ | 
					
						
							| 
									
										
										
										
											2021-06-11 01:38:30 +04:30
										 |  |  |     O(ContinuePendingUnwind)      \ | 
					
						
							|  |  |  |     O(Yield) | 
					
						
							| 
									
										
										
										
											2021-06-07 15:12:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-03 10:46:30 +02:00
										 |  |  | namespace JS::Bytecode { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Instruction { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2021-06-09 06:49:58 +04:30
										 |  |  |     constexpr static bool IsTerminator = false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-07 15:12:43 +02:00
										 |  |  |     enum class Type { | 
					
						
							|  |  |  | #define __BYTECODE_OP(op) \
 | 
					
						
							|  |  |  |     op, | 
					
						
							|  |  |  |         ENUMERATE_BYTECODE_OPS(__BYTECODE_OP) | 
					
						
							|  |  |  | #undef __BYTECODE_OP
 | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-13 20:40:20 +04:30
										 |  |  |     bool is_terminator() const; | 
					
						
							| 
									
										
										
										
											2021-06-07 15:12:43 +02:00
										 |  |  |     Type type() const { return m_type; } | 
					
						
							|  |  |  |     size_t length() const; | 
					
						
							| 
									
										
										
										
											2021-06-09 10:02:01 +02:00
										 |  |  |     String to_string(Bytecode::Executable const&) const; | 
					
						
							| 
									
										
										
										
											2021-06-07 15:12:43 +02:00
										 |  |  |     void execute(Bytecode::Interpreter&) const; | 
					
						
							| 
									
										
										
										
											2021-06-13 20:40:20 +04:30
										 |  |  |     void replace_references(BasicBlock const&, BasicBlock const&); | 
					
						
							| 
									
										
										
										
											2021-06-07 15:12:43 +02:00
										 |  |  |     static void destroy(Instruction&); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  |     explicit Instruction(Type type) | 
					
						
							|  |  |  |         : m_type(type) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-06-03 10:46:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-07 15:12:43 +02:00
										 |  |  | private: | 
					
						
							|  |  |  |     Type m_type {}; | 
					
						
							| 
									
										
										
										
											2021-06-03 10:46:30 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |