Line data Source code
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 V8_TEST_CCTEST_COMPILER_CODE_ASSEMBLER_TESTER_H_
6 : #define V8_TEST_CCTEST_COMPILER_CODE_ASSEMBLER_TESTER_H_
7 :
8 : #include "src/compiler/code-assembler.h"
9 : #include "src/compiler/raw-machine-assembler.h"
10 : #include "src/handles.h"
11 : #include "src/interface-descriptors.h"
12 : #include "src/isolate.h"
13 : #include "test/cctest/compiler/function-tester.h"
14 :
15 : namespace v8 {
16 : namespace internal {
17 : namespace compiler {
18 :
19 1668 : class CodeAssemblerTester {
20 : public:
21 : // Test generating code for a stub. Assumes VoidDescriptor call interface.
22 126 : explicit CodeAssemblerTester(Isolate* isolate)
23 : : zone_(isolate->allocator(), ZONE_NAME),
24 : scope_(isolate),
25 252 : state_(isolate, &zone_, VoidDescriptor(isolate), Code::STUB, "test") {}
26 :
27 : // Test generating code for a JS function (e.g. builtins).
28 510 : CodeAssemblerTester(Isolate* isolate, int parameter_count,
29 : Code::Kind kind = Code::BUILTIN)
30 : : zone_(isolate->allocator(), ZONE_NAME),
31 : scope_(isolate),
32 1020 : state_(isolate, &zone_, parameter_count, kind, "test") {}
33 :
34 180 : CodeAssemblerTester(Isolate* isolate, Code::Kind kind)
35 : : zone_(isolate->allocator(), ZONE_NAME),
36 : scope_(isolate),
37 360 : state_(isolate, &zone_, 0, kind, "test") {}
38 :
39 18 : CodeAssemblerTester(Isolate* isolate, CallDescriptor* call_descriptor)
40 : : zone_(isolate->allocator(), ZONE_NAME),
41 : scope_(isolate),
42 36 : state_(isolate, &zone_, call_descriptor, Code::STUB, "test") {}
43 :
44 : CodeAssemblerState* state() { return &state_; }
45 :
46 : // Direct low-level access to the machine assembler, for testing only.
47 : RawMachineAssembler* raw_assembler_for_testing() {
48 : return state_.raw_assembler_.get();
49 : }
50 :
51 798 : Handle<Code> GenerateCode() { return CodeAssembler::GenerateCode(&state_); }
52 :
53 216 : Handle<Code> GenerateCodeCloseAndEscape() {
54 216 : return scope_.CloseAndEscape(GenerateCode());
55 : }
56 :
57 : private:
58 : Zone zone_;
59 : HandleScope scope_;
60 : LocalContext context_;
61 : CodeAssemblerState state_;
62 : };
63 :
64 : } // namespace compiler
65 : } // namespace internal
66 : } // namespace v8
67 :
68 : #endif // V8_TEST_CCTEST_COMPILER_CODE_ASSEMBLER_TESTER_H_
|