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