1// Copyright 2014 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/ic/access-compiler.h"
6
7
8namespace v8 {
9namespace internal {
10
11
12Handle<Code> PropertyAccessCompiler::GetCodeWithFlags(Code::Flags flags,
13                                                      const char* name) {
14  // Create code object in the heap.
15  CodeDesc desc;
16  masm()->GetCode(&desc);
17  Handle<Code> code = factory()->NewCode(desc, flags, masm()->CodeObject());
18  if (code->IsCodeStubOrIC()) code->set_stub_key(CodeStub::NoCacheKey());
19#ifdef ENABLE_DISASSEMBLER
20  if (FLAG_print_code_stubs) {
21    CodeTracer::Scope trace_scope(isolate()->GetCodeTracer());
22    OFStream os(trace_scope.file());
23    code->Disassemble(name, os);
24  }
25#endif
26  return code;
27}
28
29
30Handle<Code> PropertyAccessCompiler::GetCodeWithFlags(Code::Flags flags,
31                                                      Handle<Name> name) {
32  return (FLAG_print_code_stubs && !name.is_null() && name->IsString())
33             ? GetCodeWithFlags(flags,
34                                Handle<String>::cast(name)->ToCString().get())
35             : GetCodeWithFlags(flags, NULL);
36}
37
38
39void PropertyAccessCompiler::TailCallBuiltin(MacroAssembler* masm,
40                                             Builtins::Name name) {
41  Handle<Code> code(masm->isolate()->builtins()->builtin(name));
42  GenerateTailCall(masm, code);
43}
44
45
46Register* PropertyAccessCompiler::GetCallingConvention(Code::Kind kind) {
47  if (kind == Code::LOAD_IC || kind == Code::KEYED_LOAD_IC) {
48    return load_calling_convention();
49  }
50  DCHECK(kind == Code::STORE_IC || kind == Code::KEYED_STORE_IC);
51  return store_calling_convention();
52}
53
54
55Register PropertyAccessCompiler::slot() const {
56  if (kind() == Code::LOAD_IC || kind() == Code::KEYED_LOAD_IC) {
57    return LoadDescriptor::SlotRegister();
58  }
59  DCHECK(kind() == Code::STORE_IC || kind() == Code::KEYED_STORE_IC);
60  return VectorStoreICDescriptor::SlotRegister();
61}
62
63
64Register PropertyAccessCompiler::vector() const {
65  if (kind() == Code::LOAD_IC || kind() == Code::KEYED_LOAD_IC) {
66    return LoadWithVectorDescriptor::VectorRegister();
67  }
68  DCHECK(kind() == Code::STORE_IC || kind() == Code::KEYED_STORE_IC);
69  return VectorStoreICDescriptor::VectorRegister();
70}
71}  // namespace internal
72}  // namespace v8
73