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