Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1 | // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef TEST_CCTEST_INTERPRETER_BYTECODE_EXPECTATIONS_PRINTER_H_ |
| 6 | #define TEST_CCTEST_INTERPRETER_BYTECODE_EXPECTATIONS_PRINTER_H_ |
| 7 | |
| 8 | #include <iostream> |
| 9 | #include <string> |
| 10 | #include <vector> |
| 11 | |
| 12 | #include "src/interpreter/bytecodes.h" |
| 13 | #include "src/objects.h" |
| 14 | |
| 15 | namespace v8 { |
| 16 | |
| 17 | class Isolate; |
| 18 | |
| 19 | namespace internal { |
| 20 | namespace interpreter { |
| 21 | |
| 22 | class BytecodeArrayIterator; |
| 23 | |
| 24 | class BytecodeExpectationsPrinter final { |
| 25 | public: |
| 26 | enum class ConstantPoolType { |
| 27 | kUnknown, |
| 28 | kString, |
| 29 | kNumber, |
| 30 | kMixed, |
| 31 | }; |
| 32 | |
| 33 | BytecodeExpectationsPrinter(v8::Isolate* i, |
| 34 | ConstantPoolType t = ConstantPoolType::kMixed) |
| 35 | : isolate_(i), |
| 36 | const_pool_type_(t), |
| 37 | execute_(true), |
| 38 | wrap_(true), |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 39 | top_level_(false), |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 40 | test_function_name_(kDefaultTopFunctionName) {} |
| 41 | |
| 42 | void PrintExpectation(std::ostream& stream, // NOLINT |
| 43 | const std::string& snippet) const; |
| 44 | |
| 45 | void set_constant_pool_type(ConstantPoolType const_pool_type) { |
| 46 | const_pool_type_ = const_pool_type; |
| 47 | } |
| 48 | ConstantPoolType const_pool_type() const { return const_pool_type_; } |
| 49 | |
| 50 | void set_execute(bool execute) { execute_ = execute; } |
| 51 | bool execute() const { return execute_; } |
| 52 | |
| 53 | void set_wrap(bool wrap) { wrap_ = wrap; } |
| 54 | bool wrap() const { return wrap_; } |
| 55 | |
| 56 | void set_top_level(bool top_level) { top_level_ = top_level; } |
| 57 | bool top_level() const { return top_level_; } |
| 58 | |
| 59 | void set_test_function_name(const std::string& test_function_name) { |
| 60 | test_function_name_ = test_function_name; |
| 61 | } |
| 62 | std::string test_function_name() const { return test_function_name_; } |
| 63 | |
| 64 | private: |
| 65 | void PrintEscapedString(std::ostream& stream, // NOLINT |
| 66 | const std::string& string) const; |
| 67 | void PrintBytecodeOperand(std::ostream& stream, // NOLINT |
| 68 | const BytecodeArrayIterator& bytecode_iter, |
| 69 | const Bytecode& bytecode, int op_index, |
| 70 | int parameter_count) const; |
| 71 | void PrintBytecode(std::ostream& stream, // NOLINT |
| 72 | const BytecodeArrayIterator& bytecode_iter, |
| 73 | int parameter_count) const; |
| 74 | void PrintV8String(std::ostream& stream, // NOLINT |
| 75 | i::String* string) const; |
| 76 | void PrintConstant(std::ostream& stream, // NOLINT |
| 77 | i::Handle<i::Object> constant) const; |
| 78 | void PrintFrameSize(std::ostream& stream, // NOLINT |
| 79 | i::Handle<i::BytecodeArray> bytecode_array) const; |
| 80 | void PrintBytecodeSequence(std::ostream& stream, // NOLINT |
| 81 | i::Handle<i::BytecodeArray> bytecode_array) const; |
| 82 | void PrintConstantPool(std::ostream& stream, // NOLINT |
| 83 | i::FixedArray* constant_pool) const; |
| 84 | void PrintCodeSnippet(std::ostream& stream, // NOLINT |
| 85 | const std::string& body) const; |
| 86 | void PrintBytecodeArray(std::ostream& stream, // NOLINT |
| 87 | i::Handle<i::BytecodeArray> bytecode_array) const; |
| 88 | void PrintHandlers(std::ostream& stream, // NOLINT |
| 89 | i::Handle<i::BytecodeArray> bytecode_array) const; |
| 90 | |
| 91 | v8::Local<v8::String> V8StringFromUTF8(const char* data) const; |
| 92 | std::string WrapCodeInFunction(const char* function_name, |
| 93 | const std::string& function_body) const; |
| 94 | |
| 95 | v8::Local<v8::Script> Compile(const char* program) const; |
| 96 | void Run(v8::Local<v8::Script> script) const; |
| 97 | i::Handle<i::BytecodeArray> GetBytecodeArrayForGlobal( |
| 98 | const char* global_name) const; |
| 99 | i::Handle<v8::internal::BytecodeArray> GetBytecodeArrayForScript( |
| 100 | v8::Local<v8::Script> script) const; |
| 101 | |
| 102 | i::Isolate* i_isolate() const { |
| 103 | return reinterpret_cast<i::Isolate*>(isolate_); |
| 104 | } |
| 105 | |
| 106 | v8::Isolate* isolate_; |
| 107 | ConstantPoolType const_pool_type_; |
| 108 | bool execute_; |
| 109 | bool wrap_; |
| 110 | bool top_level_; |
| 111 | std::string test_function_name_; |
| 112 | |
| 113 | static const char* const kDefaultTopFunctionName; |
| 114 | }; |
| 115 | |
| 116 | } // namespace interpreter |
| 117 | } // namespace internal |
| 118 | } // namespace v8 |
| 119 | |
| 120 | #endif // TEST_CCTEST_INTERPRETER_BYTECODE_EXPECTATIONS_PRINTER_H_ |