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 3208 : class CodeAssemblerTester {
20 : public:
21 : // Test generating code for a stub. Assumes VoidDescriptor call interface.
22 108 : explicit CodeAssemblerTester(Isolate* isolate, const char* name = "test")
23 : : zone_(isolate->allocator(), ZONE_NAME),
24 : scope_(isolate),
25 : state_(isolate, &zone_, VoidDescriptor{}, Code::STUB, name,
26 432 : PoisoningMitigationLevel::kDontPoison) {}
27 :
28 : // Test generating code for a JS function (e.g. builtins).
29 808 : CodeAssemblerTester(Isolate* isolate, int parameter_count,
30 : Code::Kind kind = Code::BUILTIN,
31 : const char* name = "test")
32 : : zone_(isolate->allocator(), ZONE_NAME),
33 : scope_(isolate),
34 : state_(isolate, &zone_, parameter_count, kind, name,
35 2424 : PoisoningMitigationLevel::kDontPoison) {}
36 :
37 120 : CodeAssemblerTester(Isolate* isolate, Code::Kind kind,
38 : const char* name = "test")
39 : : zone_(isolate->allocator(), ZONE_NAME),
40 : scope_(isolate),
41 : state_(isolate, &zone_, 0, kind, name,
42 360 : PoisoningMitigationLevel::kDontPoison) {}
43 :
44 568 : CodeAssemblerTester(Isolate* isolate, CallDescriptor* call_descriptor,
45 : const char* name = "test")
46 : : zone_(isolate->allocator(), ZONE_NAME),
47 : scope_(isolate),
48 : state_(isolate, &zone_, call_descriptor, Code::STUB, name,
49 1704 : PoisoningMitigationLevel::kDontPoison, Builtins::kNoBuiltinId) {}
50 :
51 : CodeAssemblerState* state() { return &state_; }
52 :
53 : // Direct low-level access to the machine assembler, for testing only.
54 : RawMachineAssembler* raw_assembler_for_testing() {
55 : return state_.raw_assembler_.get();
56 : }
57 :
58 1572 : Handle<Code> GenerateCode() {
59 1572 : return GenerateCode(AssemblerOptions::Default(scope_.isolate()));
60 : }
61 :
62 1580 : Handle<Code> GenerateCode(const AssemblerOptions& options) {
63 1580 : if (state_.InsideBlock()) {
64 12 : CodeAssembler(&state_).Unreachable();
65 : }
66 1580 : return CodeAssembler::GenerateCode(&state_, options);
67 : }
68 :
69 : Handle<Code> GenerateCodeCloseAndEscape() {
70 984 : return scope_.CloseAndEscape(GenerateCode());
71 : }
72 :
73 : private:
74 : Zone zone_;
75 : HandleScope scope_;
76 : LocalContext context_;
77 : CodeAssemblerState state_;
78 : };
79 :
80 : } // namespace compiler
81 : } // namespace internal
82 : } // namespace v8
83 :
84 : #endif // V8_TEST_CCTEST_COMPILER_CODE_ASSEMBLER_TESTER_H_
|