code-assembler-tester.h 2.24 KB
Newer Older
1 2 3 4
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6 7
#ifndef V8_TEST_CCTEST_COMPILER_CODE_ASSEMBLER_TESTER_H_
#define V8_TEST_CCTEST_COMPILER_CODE_ASSEMBLER_TESTER_H_

8
#include "src/compiler/code-assembler.h"
9
#include "src/compiler/raw-machine-assembler.h"
10 11 12 13 14 15 16 17 18
#include "src/handles.h"
#include "src/interface-descriptors.h"
#include "src/isolate.h"
#include "test/cctest/compiler/function-tester.h"

namespace v8 {
namespace internal {
namespace compiler {

19
class CodeAssemblerTester {
20
 public:
21 22 23 24
  // Test generating code for a stub. Assumes VoidDescriptor call interface.
  explicit CodeAssemblerTester(Isolate* isolate)
      : zone_(isolate->allocator(), ZONE_NAME),
        scope_(isolate),
25
        state_(isolate, &zone_, VoidDescriptor(isolate), Code::STUB, "test") {}
26 27

  // Test generating code for a JS function (e.g. builtins).
28 29 30 31
  CodeAssemblerTester(Isolate* isolate, int parameter_count,
                      Code::Kind kind = Code::BUILTIN)
      : zone_(isolate->allocator(), ZONE_NAME),
        scope_(isolate),
32
        state_(isolate, &zone_, parameter_count, kind, "test") {}
33

34
  CodeAssemblerTester(Isolate* isolate, Code::Kind kind)
35 36
      : zone_(isolate->allocator(), ZONE_NAME),
        scope_(isolate),
37
        state_(isolate, &zone_, 0, kind, "test") {}
38

39 40
  CodeAssemblerTester(Isolate* isolate, CallDescriptor* call_descriptor,
                      const char* name = "test")
41 42
      : zone_(isolate->allocator(), ZONE_NAME),
        scope_(isolate),
43
        state_(isolate, &zone_, call_descriptor, Code::STUB, name, 0, -1) {}
44

45 46
  CodeAssemblerState* state() { return &state_; }

47 48 49 50 51
  // Direct low-level access to the machine assembler, for testing only.
  RawMachineAssembler* raw_assembler_for_testing() {
    return state_.raw_assembler_.get();
  }

52
  Handle<Code> GenerateCode() { return CodeAssembler::GenerateCode(&state_); }
53 54

  Handle<Code> GenerateCodeCloseAndEscape() {
55
    return scope_.CloseAndEscape(GenerateCode());
56 57 58
  }

 private:
59
  Zone zone_;
60 61
  HandleScope scope_;
  LocalContext context_;
62
  CodeAssemblerState state_;
63 64 65 66 67
};

}  // namespace compiler
}  // namespace internal
}  // namespace v8
68 69

#endif  // V8_TEST_CCTEST_COMPILER_CODE_ASSEMBLER_TESTER_H_