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 #include "src/handles.h" | 5 #include "src/handles.h" |
6 #include "src/interface-descriptors.h" | 6 #include "src/interface-descriptors.h" |
7 #include "src/isolate.h" | 7 #include "src/isolate.h" |
8 #include "test/cctest/compiler/function-tester.h" | 8 #include "test/cctest/compiler/function-tester.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
11 namespace internal { | 11 namespace internal { |
12 namespace compiler { | 12 namespace compiler { |
13 | 13 |
14 class ZoneHolder { | 14 class ZoneHolder { |
15 public: | 15 public: |
16 explicit ZoneHolder(Isolate* isolate) | 16 explicit ZoneHolder(Isolate* isolate) |
17 : zone_(isolate->allocator(), ZONE_NAME) {} | 17 : held_zone_(isolate->allocator(), ZONE_NAME) {} |
18 Zone* zone() { return &zone_; } | 18 Zone* held_zone() { return &held_zone_; } |
19 | 19 |
20 private: | 20 private: |
21 Zone zone_; | 21 Zone held_zone_; |
22 }; | 22 }; |
23 | 23 |
24 // Inherit from ZoneHolder in order to create a zone that can be passed to | 24 // Inherit from ZoneHolder in order to create a zone that can be passed to |
25 // CodeAssembler base class constructor. | 25 // CodeAssembler base class constructor. |
26 template <typename CodeAssemblerT> | 26 template <typename CodeAssemblerT> |
27 class CodeAssemblerTesterImpl : private ZoneHolder, public CodeAssemblerT { | 27 class CodeAssemblerTesterImpl : private ZoneHolder, public CodeAssemblerT { |
28 public: | 28 public: |
29 // Test generating code for a stub. | 29 // Test generating code for a stub. |
30 CodeAssemblerTesterImpl(Isolate* isolate, | 30 CodeAssemblerTesterImpl(Isolate* isolate, |
31 const CallInterfaceDescriptor& descriptor) | 31 const CallInterfaceDescriptor& descriptor) |
32 : ZoneHolder(isolate), | 32 : ZoneHolder(isolate), |
33 CodeAssemblerT(isolate, ZoneHolder::zone(), descriptor, | 33 CodeAssemblerT(isolate, ZoneHolder::held_zone(), descriptor, |
34 Code::ComputeFlags(Code::STUB), "test"), | 34 Code::ComputeFlags(Code::STUB), "test"), |
35 scope_(isolate) {} | 35 scope_(isolate) {} |
36 | 36 |
37 // Test generating code for a JS function (e.g. builtins). | 37 // Test generating code for a JS function (e.g. builtins). |
38 CodeAssemblerTesterImpl(Isolate* isolate, int parameter_count, | 38 CodeAssemblerTesterImpl(Isolate* isolate, int parameter_count, |
39 Code::Kind kind = Code::FUNCTION) | 39 Code::Kind kind = Code::FUNCTION) |
40 : ZoneHolder(isolate), | 40 : ZoneHolder(isolate), |
41 CodeAssemblerT(isolate, ZoneHolder::zone(), parameter_count, | 41 CodeAssemblerT(isolate, ZoneHolder::held_zone(), parameter_count, |
42 Code::ComputeFlags(kind), "test"), | 42 Code::ComputeFlags(kind), "test"), |
43 scope_(isolate) {} | 43 scope_(isolate) {} |
44 | 44 |
45 // This constructor is intended to be used for creating code objects with | 45 // This constructor is intended to be used for creating code objects with |
46 // specific flags. | 46 // specific flags. |
47 CodeAssemblerTesterImpl(Isolate* isolate, Code::Flags flags) | 47 CodeAssemblerTesterImpl(Isolate* isolate, Code::Flags flags) |
48 : ZoneHolder(isolate), | 48 : ZoneHolder(isolate), |
49 CodeAssemblerT(isolate, ZoneHolder::zone(), 0, flags, "test"), | 49 CodeAssemblerT(isolate, ZoneHolder::held_zone(), 0, flags, "test"), |
50 scope_(isolate) {} | 50 scope_(isolate) {} |
51 | 51 |
52 Handle<Code> GenerateCodeCloseAndEscape() { | 52 Handle<Code> GenerateCodeCloseAndEscape() { |
53 return scope_.CloseAndEscape(CodeAssemblerT::GenerateCode()); | 53 return scope_.CloseAndEscape(CodeAssemblerT::GenerateCode()); |
54 } | 54 } |
55 | 55 |
56 private: | 56 private: |
57 HandleScope scope_; | 57 HandleScope scope_; |
58 LocalContext context_; | 58 LocalContext context_; |
59 }; | 59 }; |
60 | 60 |
61 } // namespace compiler | 61 } // namespace compiler |
62 } // namespace internal | 62 } // namespace internal |
63 } // namespace v8 | 63 } // namespace v8 |
OLD | NEW |