| 
									
										
										
										
											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-07-01 12:24:46 +02:00
										 |  |  | #define ENUMERATE_BYTECODE_OPS(O)    \
 | 
					
						
							|  |  |  |     O(Load)                          \ | 
					
						
							|  |  |  |     O(LoadImmediate)                 \ | 
					
						
							|  |  |  |     O(Store)                         \ | 
					
						
							|  |  |  |     O(Add)                           \ | 
					
						
							|  |  |  |     O(Sub)                           \ | 
					
						
							|  |  |  |     O(Mul)                           \ | 
					
						
							|  |  |  |     O(Div)                           \ | 
					
						
							|  |  |  |     O(Mod)                           \ | 
					
						
							|  |  |  |     O(Exp)                           \ | 
					
						
							|  |  |  |     O(GreaterThan)                   \ | 
					
						
							|  |  |  |     O(GreaterThanEquals)             \ | 
					
						
							|  |  |  |     O(LessThan)                      \ | 
					
						
							|  |  |  |     O(LessThanEquals)                \ | 
					
						
							| 
									
										
										
										
											2021-09-24 00:06:10 +02:00
										 |  |  |     O(LooselyInequals)               \ | 
					
						
							|  |  |  |     O(LooselyEquals)                 \ | 
					
						
							|  |  |  |     O(StrictlyInequals)              \ | 
					
						
							|  |  |  |     O(StrictlyEquals)                \ | 
					
						
							| 
									
										
										
										
											2021-07-01 12:24:46 +02:00
										 |  |  |     O(NewBigInt)                     \ | 
					
						
							|  |  |  |     O(NewArray)                      \ | 
					
						
							|  |  |  |     O(IteratorToArray)               \ | 
					
						
							|  |  |  |     O(NewString)                     \ | 
					
						
							|  |  |  |     O(NewObject)                     \ | 
					
						
							|  |  |  |     O(NewRegExp)                     \ | 
					
						
							|  |  |  |     O(CopyObjectExcludingProperties) \ | 
					
						
							|  |  |  |     O(GetVariable)                   \ | 
					
						
							|  |  |  |     O(SetVariable)                   \ | 
					
						
							|  |  |  |     O(PutById)                       \ | 
					
						
							|  |  |  |     O(GetById)                       \ | 
					
						
							|  |  |  |     O(PutByValue)                    \ | 
					
						
							|  |  |  |     O(GetByValue)                    \ | 
					
						
							|  |  |  |     O(Jump)                          \ | 
					
						
							|  |  |  |     O(JumpConditional)               \ | 
					
						
							|  |  |  |     O(JumpNullish)                   \ | 
					
						
							|  |  |  |     O(JumpUndefined)                 \ | 
					
						
							|  |  |  |     O(Call)                          \ | 
					
						
							|  |  |  |     O(NewFunction)                   \ | 
					
						
							|  |  |  |     O(Return)                        \ | 
					
						
							|  |  |  |     O(BitwiseAnd)                    \ | 
					
						
							|  |  |  |     O(BitwiseOr)                     \ | 
					
						
							|  |  |  |     O(BitwiseXor)                    \ | 
					
						
							|  |  |  |     O(BitwiseNot)                    \ | 
					
						
							|  |  |  |     O(Not)                           \ | 
					
						
							|  |  |  |     O(UnaryPlus)                     \ | 
					
						
							|  |  |  |     O(UnaryMinus)                    \ | 
					
						
							|  |  |  |     O(Typeof)                        \ | 
					
						
							|  |  |  |     O(LeftShift)                     \ | 
					
						
							|  |  |  |     O(RightShift)                    \ | 
					
						
							|  |  |  |     O(UnsignedRightShift)            \ | 
					
						
							|  |  |  |     O(In)                            \ | 
					
						
							|  |  |  |     O(InstanceOf)                    \ | 
					
						
							|  |  |  |     O(ConcatString)                  \ | 
					
						
							|  |  |  |     O(Increment)                     \ | 
					
						
							|  |  |  |     O(Decrement)                     \ | 
					
						
							|  |  |  |     O(Throw)                         \ | 
					
						
							|  |  |  |     O(PushDeclarativeEnvironment)    \ | 
					
						
							|  |  |  |     O(EnterUnwindContext)            \ | 
					
						
							|  |  |  |     O(LeaveUnwindContext)            \ | 
					
						
							|  |  |  |     O(ContinuePendingUnwind)         \ | 
					
						
							|  |  |  |     O(Yield)                         \ | 
					
						
							|  |  |  |     O(GetIterator)                   \ | 
					
						
							|  |  |  |     O(IteratorNext)                  \ | 
					
						
							|  |  |  |     O(IteratorResultDone)            \ | 
					
						
							| 
									
										
										
										
											2021-06-30 15:42:13 -03:00
										 |  |  |     O(IteratorResultValue)           \ | 
					
						
							|  |  |  |     O(NewClass) | 
					
						
							| 
									
										
										
										
											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
										 |  |  | }; | 
					
						
							|  |  |  | } |